From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CC7AC433E2 for ; Thu, 17 Sep 2020 14:37:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 84AF9221E3 for ; Thu, 17 Sep 2020 14:37:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QGCPcwui" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84AF9221E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D18776B0003; Thu, 17 Sep 2020 10:37:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC5EC6B0055; Thu, 17 Sep 2020 10:37:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8E956B005A; Thu, 17 Sep 2020 10:37:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id 9F4646B0003 for ; Thu, 17 Sep 2020 10:37:13 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 537A533CD for ; Thu, 17 Sep 2020 14:37:13 +0000 (UTC) X-FDA: 77272805946.30.key44_591770e27123 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 36557180B3C85 for ; Thu, 17 Sep 2020 14:37:13 +0000 (UTC) X-HE-Tag: key44_591770e27123 X-Filterd-Recvd-Size: 5417 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 14:37:12 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id g4so2346772wrs.5 for ; Thu, 17 Sep 2020 07:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=M9gS3287S0Kty1lGdTSSCUjtzHa87iOilMiBEXqgZIk=; b=QGCPcwui9PV57DotV3CplBVPzt42u0IkvemUt457Qhs+LHjck33+OGWcTqa7LtXO0s uHHrZ8JPmk/b3rEnq+fLJgP1/p0jClEJKL/0bsdwJYEEsIyIEt4nui+gvDAR3XyQsz5R rYStTHVP08VBv6suUBEyMYVR1py/TW9AB3eV8cGsVTCM3x1sCxMgxbEukBjucM9bF8Vc agHj56m1MLiCSLkt03Pg+BnW8t0jw10/OXMzqMroJqy6WJIMBWcaR0MG7sGor9XlAtTJ kqKSL1SPepJb0Sj/FoNlcwaem1AXE2zzX6y79ne5wrBbFML0KNC5iq2EsK2lD7r2xUsl 3CVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=M9gS3287S0Kty1lGdTSSCUjtzHa87iOilMiBEXqgZIk=; b=M7GV7sE8rRM5ubSCtLbv6FDO9zaqOl9C9drAH1+6H4zBSvEXxOIsYBvE4nHFeLJDcu T3gtg1l9JjF/N/+gdsOqAKmnFeOItVPAWoVDiCsAhgQs3DMsmS85LNMCweNrYkdIwrBV NIQxOVVW69sx9X2fGIwgvdlw3qLGtQ2NVsMUBoyjQeJsHNr2z4C6vc4zFBPG8ebJW5hG E8GVeaUFupaXMVnVzv9/sEPLSBeOHQ4gh0MPI6GSjVQPliGG23iCt7zee9sDSjB9kx83 H0FtblFrYBadZHnpTpHKZX5ilh1mlF08bgVIWGm8Ay7L+eOIJOH9efoyS5x7PkJcH3ED iGsA== X-Gm-Message-State: AOAM530OqBLyXAJTU9HmDplNZs/GICiQGVdwKBTBXF2OcN8SgGKDQ+MI XC9bBPKry0hNw9CYCYnRNiQyJg== X-Google-Smtp-Source: ABdhPJy+rAGuUfzGgur2eYJh6s3fwt8jTwpxbS/gPLgICs9OoxIliDD0/uDvO6wDOciThy3TNN1RmQ== X-Received: by 2002:a5d:56cd:: with SMTP id m13mr32002851wrw.261.1600353431301; Thu, 17 Sep 2020 07:37:11 -0700 (PDT) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id p11sm10707199wma.11.2020.09.17.07.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 07:37:10 -0700 (PDT) Date: Thu, 17 Sep 2020 16:36:51 +0200 From: Jean-Philippe Brucker To: Auger Eric Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, fenghua.yu@intel.com, catalin.marinas@arm.com, robin.murphy@arm.com, zhengxiang9@huawei.com, zhangfei.gao@linaro.org, will@kernel.org Subject: Re: [PATCH RESEND v9 03/13] iommu/sva: Add PASID helpers Message-ID: <20200917143651.GB134903@myrica> References: <20200817171558.325917-1-jean-philippe@linaro.org> <20200817171558.325917-4-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 36557180B3C85 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 08, 2020 at 09:45:02AM +0200, Auger Eric wrote: > > +int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) > > +{ > > + int ret = 0; > > + ioasid_t pasid; > > + > > + if (min == INVALID_IOASID || max == INVALID_IOASID || > > + min == 0 || max < min) > you may add a comment explaining why min == 0 is forbidden. Right, I'll add to the function doc "@min must be greater than 0 because 0 indicates an unused mm->pasid." > > + return -EINVAL; > > + > > + mutex_lock(&iommu_sva_lock); > > + if (mm->pasid) { > > + if (mm->pasid >= min && mm->pasid <= max) > > + ioasid_get(mm->pasid); > > + else > > + ret = -EOVERFLOW; > > + } else { > > + pasid = ioasid_alloc(&iommu_sva_pasid, min, max, mm); > > + if (pasid == INVALID_IOASID) > > + ret = -ENOMEM; > > + else > > + mm->pasid = pasid; > > + } > > + mutex_unlock(&iommu_sva_lock); > > + return ret; > > +} > > +EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid); > > + > > +/** > > + * iommu_sva_free_pasid - Release the mm's PASID > > + * @mm: the mm. > > + * > > + * Drop one reference to a PASID allocated with iommu_sva_alloc_pasid() > > + */ > > +void iommu_sva_free_pasid(struct mm_struct *mm) > > +{ > > + mutex_lock(&iommu_sva_lock); > > + if (ioasid_put(mm->pasid)) > > + mm->pasid = 0; > ditto: 0 versus INVALID_IOASID > > + mutex_unlock(&iommu_sva_lock); > > +} > > +EXPORT_SYMBOL_GPL(iommu_sva_free_pasid); > > + > > +/* ioasid wants a void * argument */ > shouldn't it be: > ioasid_find getter() requires a void *arg? Ok Thanks, Jean > > +static bool __mmget_not_zero(void *mm) > > +{ > > + return mmget_not_zero(mm); > > +} > > + > > +/** > > + * iommu_sva_find() - Find mm associated to the given PASID > > + * @pasid: Process Address Space ID assigned to the mm > > + * > > + * On success a reference to the mm is taken, and must be released with mmput(). > > + * > > + * Returns the mm corresponding to this PASID, or an error if not found. > > + */ > > +struct mm_struct *iommu_sva_find(ioasid_t pasid) > > +{ > > + return ioasid_find(&iommu_sva_pasid, pasid, __mmget_not_zero); > > +} > > +EXPORT_SYMBOL_GPL(iommu_sva_find); > > > Thanks > > Eric >