Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3667068iog; Mon, 27 Jun 2022 23:28:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQlTlylKXcBwNC4/XlLEsIlKhMp6d/8HtttFXZG/DJFS0ba0wMUE3Qwd2OxJr18/JccMHL X-Received: by 2002:aa7:c84d:0:b0:431:4226:70c9 with SMTP id g13-20020aa7c84d000000b00431422670c9mr21413706edt.51.1656397731846; Mon, 27 Jun 2022 23:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397731; cv=none; d=google.com; s=arc-20160816; b=a0Ti+ykPmKV/LjNWu6/4lYBHJj87oe9BY72nus8G6tT0EvZuO5aVVfHWmWrAYpos5E MYmOqneZpYLClgGDlT7lcRo17Ky2YqWKWzztuYJ9WGOOscYgAf/+HxRbPExXOr+vOdzP 2a+x+iQAHO//KSvplbje0I6vREGbvYxDYeKYDqqEIl0qQZgXHVdrnt95t4BhCKYr/JJi Po8UvC3kQ7Jp7Wkhn0VHEOAVc4R+b2d/KoXTjLiKSahxUFiaB24pYbLE703PzwzO+GAh 8ZztDaGv1hSCzVx0LkfF+CHsiVzCnIpveuQkgh7Tt7CtZrPqMVFqIEE92w+9FEosyrZ6 4NCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=1h7yN1jlbrxy+gkAtHzLjz6JdhgLNuhz8wY0OAlbfPE=; b=v9grtr6B5DOeIhv/FxrHP3oaviuWEuEKGamt/JRiNfFqCdvdOiPkx5ddlS3a6PjJza SFrq9R9pp6CuYe6IbOJtKEdV1C/Wrs1qbjbMj2kCMqWZ9eZs6bw+vkas/1ID2teRcq9v f3CMi+HFap3ciI3jyg2fbusiFrX6P5iY2fKlwI+M4dS/E+1kZO72DCqY1eAR/t+/zohR MI7ddzJzSBndZNnF6Rqu5PRjln6MTt+1thrmsdMMYruM8901diTpFhgWQ4kOgU2x78kL pOkAq21j6CdVtcw08/NN/4HtKcKhpuFkNWqXj1+RZxEkbxy2qm14An1/b62sH29pghIJ PD5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FmBSpysH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a056402270e00b0043578c6395fsi1576468edd.593.2022.06.27.23.28.26; Mon, 27 Jun 2022 23:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FmBSpysH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239520AbiF1F47 (ORCPT + 99 others); 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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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