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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A866C433EF for ; Tue, 28 Jun 2022 05:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244493AbiF1F47 (ORCPT ); Tue, 28 Jun 2022 01:56:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiF1F4x (ORCPT ); Tue, 28 Jun 2022 01:56:53 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71F812872D for ; Mon, 27 Jun 2022 22:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656395812; x=1687931812; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=jkkFnV1SzLceUSN26FhY9YeMuVcIqRLbH9OTJaJLTP8=; b=FmBSpysHTDqBKTfU5nGFU5R3kuqZMFBqgO/xt2EIH7BBuQyHMDv87m/e /iMYyKAMs0jbVoS0K6q66s+V53CCgZlALiHp3EJOMKYv0MTNGERHKSp72 CAzXSASl6KtVj6wqk2oYt4TQgDwlt3kgd8apDY+ddVAH7c4ijIZ27RkVB z4nkrXLrmCL0TF/EFV1L3Ct5gDfuv8MK8vGk4nD0kj3sNUm1sgCTLKoVC Nrd7AsRkUuG+Y4CacpeH0vOD3bbhjr7fTJ3IlJg2jnHom53W+ki7NwYh9 UXt3s4gjcc19SY77R+6ZVtxILnmAZGwc9ZmBfe1SLO55QVPK7EA2afs5R A==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="307121855" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="307121855" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 22:53:46 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="646762122" Received: from ltang11-mobl1.ccr.corp.intel.com (HELO [10.249.169.64]) ([10.249.169.64]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 22:53:37 -0700 Message-ID: <543603e3-9d08-59ee-01f2-8dd6e7c73a15@linux.intel.com> Date: Tue, 28 Jun 2022 13:53:35 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Cc: baolu.lu@linux.intel.com, Eric Auger , "Liu, Yi L" , "Pan, Jacob jun" , "iommu@lists.linux-foundation.org" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v9 07/11] iommu/sva: Refactoring iommu_sva_bind/unbind_device() Content-Language: en-US To: "Tian, Kevin" , Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , "Raj, Ashok" , Will Deacon , Robin Murphy , Jean-Philippe Brucker , "Jiang, Dave" , Vinod Koul References: <20220621144353.17547-1-baolu.lu@linux.intel.com> <20220621144353.17547-8-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/6/27 18:14, Tian, Kevin wrote: >> From: Lu Baolu >> Sent: Tuesday, June 21, 2022 10:44 PM >> +struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct >> mm_struct *mm) >> +{ >> + struct iommu_domain *domain; >> + ioasid_t max_pasids; >> + int ret = -EINVAL; >> + >> + /* Allocate mm->pasid if necessary. */ > > this comment is for iommu_sva_alloc_pasid() Updated. > >> + max_pasids = dev->iommu->max_pasids; >> + if (!max_pasids) >> + return ERR_PTR(-EOPNOTSUPP); >> + >> + ret = iommu_sva_alloc_pasid(mm, 1, max_pasids - 1); >> + if (ret) >> + return ERR_PTR(ret); >> + > > > ... >> +void iommu_sva_unbind_device(struct iommu_sva *handle) >> +{ >> + struct device *dev = handle->dev; >> + struct iommu_domain *domain = >> + container_of(handle, struct iommu_domain, bond); >> + ioasid_t pasid = iommu_sva_get_pasid(handle); >> + >> + mutex_lock(&iommu_sva_lock); >> + if (refcount_dec_and_test(&domain->bond.users)) { >> + iommu_detach_device_pasid(domain, dev, pasid); >> + iommu_domain_free(domain); >> + } >> + mutex_unlock(&iommu_sva_lock); >> +} >> +EXPORT_SYMBOL_GPL(iommu_sva_unbind_device); >> + >> +u32 iommu_sva_get_pasid(struct iommu_sva *handle) >> +{ >> + struct iommu_domain *domain = >> + container_of(handle, struct iommu_domain, bond); >> + >> + return domain->mm->pasid; >> +} >> +EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); > > Looks this is only used by unbind_device. Just open code it. It's part of current IOMMU/SVA interfaces for the device drivers, and has been used in various drivers. $ git grep iommu_sva_get_pasid drivers/dma/idxd/cdev.c: pasid = iommu_sva_get_pasid(sva); drivers/iommu/iommu-sva-lib.c: ioasid_t pasid = iommu_sva_get_pasid(handle); drivers/iommu/iommu-sva-lib.c:u32 iommu_sva_get_pasid(struct iommu_sva *handle) drivers/iommu/iommu-sva-lib.c:EXPORT_SYMBOL_GPL(iommu_sva_get_pasid); drivers/misc/uacce/uacce.c: pasid = iommu_sva_get_pasid(handle); include/linux/iommu.h:u32 iommu_sva_get_pasid(struct iommu_sva *handle); include/linux/iommu.h:static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle) Or, I missed anything? Best regards, baolu