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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 63B41C433ED for ; Fri, 9 Apr 2021 12:45:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42547610CF for ; Fri, 9 Apr 2021 12:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbhDIMpm (ORCPT ); Fri, 9 Apr 2021 08:45:42 -0400 Received: from mga03.intel.com ([134.134.136.65]:32587 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbhDIMpl (ORCPT ); Fri, 9 Apr 2021 08:45:41 -0400 IronPort-SDR: uJw4RP0+BX4kZGyJaD5trBteKLIVeoLCFzKU2feL4my2HOiUycZYXARQ2/5qVuD9S2i8am/eS8 mJLoRdyERKuw== X-IronPort-AV: E=McAfee;i="6000,8403,9949"; a="193792940" X-IronPort-AV: E=Sophos;i="5.82,209,1613462400"; d="scan'208";a="193792940" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2021 05:45:28 -0700 IronPort-SDR: J94+ZmKkZJjSqlr6+lLmCF0kmDHnfTMyeqpMal5eYal2X3t1/7Vx23ZOjTVO5Gd4Jiz6cdcNwj ZkM2sWPffxmA== X-IronPort-AV: E=Sophos;i="5.82,209,1613462400"; d="scan'208";a="422714028" Received: from blu2-mobl3.ccr.corp.intel.com (HELO [10.254.211.245]) ([10.254.211.245]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2021 05:45:25 -0700 Cc: baolu.lu@linux.intel.com, Yi Liu , Raj Ashok , "Tian, Kevin" , Jason Gunthorpe , Dave Jiang , wangzhou1@hisilicon.com, zhangfei.gao@linaro.org, vkoul@kernel.org Subject: Re: [PATCH 2/2] iommu/sva: Remove mm parameter from SVA bind API To: Jacob Pan , LKML , iommu@lists.linux-foundation.org, Joerg Roedel , Jean-Philippe Brucker References: <1617901736-24788-1-git-send-email-jacob.jun.pan@linux.intel.com> <1617901736-24788-2-git-send-email-jacob.jun.pan@linux.intel.com> From: Lu Baolu Message-ID: Date: Fri, 9 Apr 2021 20:45:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <1617901736-24788-2-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2021/4/9 1:08, Jacob Pan wrote: > /** > * iommu_sva_alloc_pasid - Allocate a PASID for the mm > - * @mm: the mm > * @min: minimum PASID value (inclusive) > * @max: maximum PASID value (inclusive) > * > - * Try to allocate a PASID for this mm, or take a reference to the existing one > - * provided it fits within the [@min, @max] range. On success the PASID is > - * available in mm->pasid, and must be released with iommu_sva_free_pasid(). > + * Try to allocate a PASID for the current mm, or take a reference to the > + * existing one provided it fits within the [@min, @max] range. On success > + * the PASID is available in the current mm->pasid, and must be released with > + * iommu_sva_free_pasid(). > * @min must be greater than 0, because 0 indicates an unused mm->pasid. > * > * Returns 0 on success and < 0 on error. > */ > -int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) > +int iommu_sva_alloc_pasid(ioasid_t min, ioasid_t max) > { > int ret = 0; > ioasid_t pasid; > + struct mm_struct *mm; > > if (min == INVALID_IOASID || max == INVALID_IOASID || > min == 0 || max < min) > return -EINVAL; > > mutex_lock(&iommu_sva_lock); > + mm = get_task_mm(current); How could we allocate a supervisor PASID through iommu_sva_alloc_pasid() if we always use current->mm here? > + if (!mm) { > + ret = -EINVAL; > + goto out_unlock; > + } > if (mm->pasid) { > if (mm->pasid >= min && mm->pasid <= max) > ioasid_get(mm->pasid); > @@ -45,22 +51,32 @@ int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t max) > else > mm->pasid = pasid; > } > + mmput(mm); > +out_unlock: > mutex_unlock(&iommu_sva_lock); > return ret; > } > EXPORT_SYMBOL_GPL(iommu_sva_alloc_pasid); Best regards, baolu