Message ID | 20230209043153.14964-7-yi.l.liu@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp122962wrn; Wed, 8 Feb 2023 20:35:55 -0800 (PST) X-Google-Smtp-Source: AK7set/C3qjk5WF7PrBtmB57AdL2ArcBciB9MTkiRzq4wuIL2wOohDmybphu93C1ZT1siZB2DyUh X-Received: by 2002:a17:902:db10:b0:199:2e77:fe16 with SMTP id m16-20020a170902db1000b001992e77fe16mr10957908plx.58.1675917355403; Wed, 08 Feb 2023 20:35:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675917355; cv=none; d=google.com; s=arc-20160816; b=ZajaULTajbTqV6vDRt6KYaki/eg3NevKQp85h46HSIK1I1XnF3yf9BJE9XRhy8zIpI oxBGNf+9f7rdNy0SzHaTmF/oi/qLh3asLZvLIeG3sAAUKYWME8YJw8k1FULxkZxF7tH/ DYwtHhE2kqEU5ooiQ7ngws9k/xoQD42jz6NgcBtPqiRqoMzwj0kIt0KxOiWeEX0XbxaB 34n1hFSR5gTUauha8a1kmfzkr76hJEoo76eyWZyJlVahgd5pzNFYCPwM7M2aMWTqk208 LspJQqa1UF9aTultJOH2545EieIstizBQSm/2MZLHSQHEbknnXtMt1W8JA1wcsh2mtGO Dmow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7h+dLYb8Ynk3pnVBuHtPB4/jrj1pbUcdWyK/tMZgXgY=; b=fZk0T/mVsozyR6sxApI9twxBbXoKrDUxrIKiHWT/Eop0IhoyBTxpkKZrB9/A4GPFaI h0n0/4bE3gJGx5NC4Xgaf1CW8HiUo81wPhLz/lDoGSqDgk6gmhXdfF5tMkNL3/v/ZZ2P LjKJ740iPSjjgdP1q8zEx6WgY5ZxlMtTTT8xAG239afqObpRBeizXk4DaHZlOOOmripW KeRhNbKJZJ8GVvIuNi3L+RJmsTU982mapOinjA4OBb8HpLkb5UKr7KBgWa9fBJPEb2WH 7NUM4eCehXPi1RczSGkKcFly0msYyOYZjChPEoKv+0csM9gngQh7nPA3g1/GT6s8Htsn VErQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nT9GYdMV; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a170902ecc500b001991e3b4f3asi761713plh.427.2023.02.08.20.35.34; Wed, 08 Feb 2023 20:35:55 -0800 (PST) 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=nT9GYdMV; 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 S230418AbjBIEfD (ORCPT <rfc822;gnulinuxfreebsd@gmail.com> + 99 others); Wed, 8 Feb 2023 23:35:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230257AbjBIEdt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Feb 2023 23:33:49 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53820457F1; Wed, 8 Feb 2023 20:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675917160; x=1707453160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RfT4R/xTBwZsk8AEoHLAHBvK4hYBuXf+5pIwXQ6TqQw=; b=nT9GYdMVpkOL5y2Y74N2jEJ8RvrkFcJM1Y2qgEtjSH4Z0dHdbpJOjceE uBCHDNZp7kWrkCJevRc/hwELompD/r2oaWKpsYc4wIYRHciLZfsUu5TVV U555ilUofG6ccxY/WnU9wM010fTrbKH1+R03S/QPEdriThmjK3lAsX5T7 h3Rae6Dix1aMQG3IKgcDAPE+P+PYhUcReREmZcIfbdQRrqicSUCJKPLiY 3owLTeviEMmljGKwM6XHb3j99YHeOVgE5zYic3gL8fXTnuG8z78t2K9Sd KSMnNSafmVVc8j4eMAbfR3uv+PQkQHNSXExkUEhe/rxljzE+UOQqB5XSj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="331298694" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="331298694" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2023 20:32:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10615"; a="669447517" X-IronPort-AV: E=Sophos;i="5.97,281,1669104000"; d="scan'208";a="669447517" Received: from 984fee00a4c6.jf.intel.com ([10.165.58.231]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2023 20:32:08 -0800 From: Yi Liu <yi.l.liu@intel.com> To: joro@8bytes.org, alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com, robin.murphy@arm.com Cc: cohuck@redhat.com, eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org, mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com, yi.l.liu@intel.com, yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com, shameerali.kolothum.thodi@huawei.com, lulu@redhat.com, suravee.suthikulpanit@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, baolu.lu@linux.intel.com Subject: [PATCH 06/17] iommufd/hw_pagetable: Use domain_alloc_user op for domain allocation Date: Wed, 8 Feb 2023 20:31:42 -0800 Message-Id: <20230209043153.14964-7-yi.l.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230209043153.14964-1-yi.l.liu@intel.com> References: <20230209043153.14964-1-yi.l.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757326716523914679?= X-GMAIL-MSGID: =?utf-8?q?1757326716523914679?= |
Series |
Add Intel VT-d nested translation
|
|
Commit Message
Yi Liu
Feb. 9, 2023, 4:31 a.m. UTC
This converts iommufd to use iommu_domain_alloc_user() for iommu_domain creation. Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> --- drivers/iommu/iommufd/hw_pagetable.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Comments
On 2/8/23 11:31 PM, Yi Liu wrote: > This converts iommufd to use iommu_domain_alloc_user() for iommu_domain > creation. > > Suggested-by: Jason Gunthorpe <jgg@nvidia.com> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> > Signed-off-by: Yi Liu <yi.l.liu@intel.com> > --- > drivers/iommu/iommufd/hw_pagetable.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c > index 43d473989a06..08d963ee38c7 100644 > --- a/drivers/iommu/iommufd/hw_pagetable.c > +++ b/drivers/iommu/iommufd/hw_pagetable.c > @@ -30,6 +30,7 @@ struct iommufd_hw_pagetable * > iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, > struct device *dev) > { > + const struct iommu_ops *ops; > struct iommufd_hw_pagetable *hwpt; > int rc; > > @@ -37,7 +38,13 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, > if (IS_ERR(hwpt)) > return hwpt; > > - hwpt->domain = iommu_domain_alloc(dev->bus); > + ops = dev_iommu_ops(dev); > + if (!ops || !ops->domain_alloc_user) { > + rc = -EOPNOTSUPP; > + goto out_abort; > + } Hi Yi, This seems to break the iommufd vfio container support for any iommu that hasn't implemented domain_alloc_user yet. I noticed it using vfio-pci on s390 with CONFIG_IOMMUFD=m CONFIG_IOMMUFD_VFIO_CONTAINER=y CONFIG_VFIO_GROUP=y Not sure if the intent is to make domain_alloc_user a hard requirement for using iommufd (if so then the commit description really should highlight that). Otherwise, conditionally calling iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user (instead of returning -EOPNOTSUPP) seems to restore the prior functionality for me. Thanks, Matt
On Thu, Feb 09, 2023 at 12:59:58PM -0500, Matthew Rosato wrote: > really should highlight that). Otherwise, conditionally calling > iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user (instead > of returning -EOPNOTSUPP) seems to restore the prior functionality > for me. Yes, that is right if the input user data is 0 length or full of 0s then we should call the normal driver function Jason
On Thu, Feb 09, 2023 at 02:36:49PM -0400, Jason Gunthorpe wrote: > On Thu, Feb 09, 2023 at 12:59:58PM -0500, Matthew Rosato wrote: > > really should highlight that). Otherwise, conditionally calling > > iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user (instead > > of returning -EOPNOTSUPP) seems to restore the prior functionality > > for me. > > Yes, that is right if the input user data is 0 length or full of 0s > then we should call the normal driver function Maybe I am wrong, yet I recall that doing ops->domain_alloc_user without a fallback was intentional to rule out drivers that don't support IOMMUFD? To be backward-compatible and concern about SMMU, we can opt in ops->domain_alloc_user upon availability and then add a fallback: if ((!ops || !ops->domain_alloc_user) && user_data) { rc = -EOPNOTSUPP; goto out_abort; } if (ops->domain_alloc_user) hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); else hwpt->domain = iommu_domain_alloc(dev->bus); if (!hwpt->domain) { rc = -ENOMEM; goto out_abort; } Yet, even by doing so, this series having the PATCH 07/17 that moves iopt_table_add_domain() would temporally break IOMMUFD on ARM platforms, until we add the ops->domain_alloc_user to SMMU drivers. Thanks Nic
On Thu, Feb 09, 2023 at 11:51:31AM -0800, Nicolin Chen wrote: > On Thu, Feb 09, 2023 at 02:36:49PM -0400, Jason Gunthorpe wrote: > > On Thu, Feb 09, 2023 at 12:59:58PM -0500, Matthew Rosato wrote: > > > really should highlight that). Otherwise, conditionally calling > > > iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user (instead > > > of returning -EOPNOTSUPP) seems to restore the prior functionality > > > for me. > > > > Yes, that is right if the input user data is 0 length or full of 0s > > then we should call the normal driver function > > Maybe I am wrong, yet I recall that doing ops->domain_alloc_user > without a fallback was intentional to rule out drivers that don't > support IOMMUFD? I think we moved away from that to the idea of using the dma_domain patch I suggested.. > To be backward-compatible and concern about SMMU, we can opt in > ops->domain_alloc_user upon availability and then add a fallback: > > if ((!ops || !ops->domain_alloc_user) && user_data) { > rc = -EOPNOTSUPP; > goto out_abort; > } > > if (ops->domain_alloc_user) > hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); > else > hwpt->domain = iommu_domain_alloc(dev->bus); > if (!hwpt->domain) { > rc = -ENOMEM; > goto out_abort; > } > > Yet, even by doing so, this series having the PATCH 07/17 that > moves iopt_table_add_domain() would temporally break IOMMUFD on > ARM platforms, until we add the ops->domain_alloc_user to SMMU > drivers. Drop patch 7 and 8 Change patch 12 so it has a unique flow to allocate and IOAS map a HWPT that does not try to share so much code with the existing flow. The HWPT flow should always just call allocate and then map with no effort to attach first. This will fail on ARM SMMU at this point, and that is fine. All the existing code should work exactly as it is now and not have any need to be changed. Where things when wrong was trying to share "__iommufd_hw_pagetable_alloc", I think. Don't try to consolidate at this point. Once all the drivers are updated then we could try to consolidate things. Jason
On Thu, Feb 09, 2023 at 04:39:37PM -0400, Jason Gunthorpe wrote: > On Thu, Feb 09, 2023 at 11:51:31AM -0800, Nicolin Chen wrote: > > On Thu, Feb 09, 2023 at 02:36:49PM -0400, Jason Gunthorpe wrote: > > > On Thu, Feb 09, 2023 at 12:59:58PM -0500, Matthew Rosato wrote: > > > > really should highlight that). Otherwise, conditionally calling > > > > iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user (instead > > > > of returning -EOPNOTSUPP) seems to restore the prior functionality > > > > for me. > > > > > > Yes, that is right if the input user data is 0 length or full of 0s > > > then we should call the normal driver function > > > > Maybe I am wrong, yet I recall that doing ops->domain_alloc_user > > without a fallback was intentional to rule out drivers that don't > > support IOMMUFD? > > I think we moved away from that to the idea of using the dma_domain > patch I suggested.. > > > To be backward-compatible and concern about SMMU, we can opt in > > ops->domain_alloc_user upon availability and then add a fallback: > > > > if ((!ops || !ops->domain_alloc_user) && user_data) { > > rc = -EOPNOTSUPP; > > goto out_abort; > > } > > > > if (ops->domain_alloc_user) > > hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); > > else > > hwpt->domain = iommu_domain_alloc(dev->bus); > > if (!hwpt->domain) { > > rc = -ENOMEM; > > goto out_abort; > > } > > > > Yet, even by doing so, this series having the PATCH 07/17 that > > moves iopt_table_add_domain() would temporally break IOMMUFD on > > ARM platforms, until we add the ops->domain_alloc_user to SMMU > > drivers. > > Drop patch 7 and 8 > > Change patch 12 so it has a unique flow to allocate and IOAS map a > HWPT that does not try to share so much code with the existing flow. > > The HWPT flow should always just call allocate and then map with no > effort to attach first. This will fail on ARM SMMU at this point, and > that is fine. > > All the existing code should work exactly as it is now and not have > any need to be changed. > > Where things when wrong was trying to share > "__iommufd_hw_pagetable_alloc", I think. > > Don't try to consolidate at this point. Once all the drivers are > updated then we could try to consolidate things. Yea, I think that's the only way out for now. Though I am not sure about other drivers yet, hopefully the SMMU driver(s) is the last one that we need to update... Thanks Nic
On Thu, Feb 09, 2023 at 02:22:26PM -0800, Nicolin Chen wrote: > Yea, I think that's the only way out for now. Though I am not > sure about other drivers yet, hopefully the SMMU driver(s) is > the last one that we need to update... I noticed apple dart had copy and pasted this from smmu, but I see that it needed it. Jason
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Friday, February 10, 2023 6:22 AM > > On Thu, Feb 09, 2023 at 04:39:37PM -0400, Jason Gunthorpe wrote: > > On Thu, Feb 09, 2023 at 11:51:31AM -0800, Nicolin Chen wrote: > > > On Thu, Feb 09, 2023 at 02:36:49PM -0400, Jason Gunthorpe wrote: > > > > On Thu, Feb 09, 2023 at 12:59:58PM -0500, Matthew Rosato wrote: > > > > > really should highlight that). Otherwise, conditionally calling > > > > > iommu_domain_alloc(dev->bus) when !ops->domain_alloc_user > (instead > > > > > of returning -EOPNOTSUPP) seems to restore the prior functionality > > > > > for me. > > > > > > > > Yes, that is right if the input user data is 0 length or full of 0s > > > > then we should call the normal driver function > > > > > > Maybe I am wrong, yet I recall that doing ops->domain_alloc_user > > > without a fallback was intentional to rule out drivers that don't > > > support IOMMUFD? > > > > I think we moved away from that to the idea of using the dma_domain > > patch I suggested.. > > > > > To be backward-compatible and concern about SMMU, we can opt in > > > ops->domain_alloc_user upon availability and then add a fallback: > > > > > > if ((!ops || !ops->domain_alloc_user) && user_data) { > > > rc = -EOPNOTSUPP; > > > goto out_abort; > > > } > > > > > > if (ops->domain_alloc_user) > > > hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); > > > else > > > hwpt->domain = iommu_domain_alloc(dev->bus); > > > if (!hwpt->domain) { > > > rc = -ENOMEM; > > > goto out_abort; > > > } > > > > > > Yet, even by doing so, this series having the PATCH 07/17 that > > > moves iopt_table_add_domain() would temporally break IOMMUFD on > > > ARM platforms, until we add the ops->domain_alloc_user to SMMU > > > drivers. > > > > Drop patch 7 and 8 > > > > Change patch 12 so it has a unique flow to allocate and IOAS map a > > HWPT that does not try to share so much code with the existing flow. > > > > The HWPT flow should always just call allocate and then map with no > > effort to attach first. This will fail on ARM SMMU at this point, and > > that is fine. Ok. this sounds iopt_table_add_domain() should still be called right after user hwpt is allocated instead of first device attached. > > > > All the existing code should work exactly as it is now and not have > > any need to be changed. > > > > Where things when wrong was trying to share > > "__iommufd_hw_pagetable_alloc", I think. > > Sure. > > Don't try to consolidate at this point. Once all the drivers are > > updated then we could try to consolidate things. > > Yea, I think that's the only way out for now. Though I am not > sure about other drivers yet, hopefully the SMMU driver(s) is > the last one that we need to update... 😊 hope it. Regards, Yi Liu
diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 43d473989a06..08d963ee38c7 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -30,6 +30,7 @@ struct iommufd_hw_pagetable * iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, struct device *dev) { + const struct iommu_ops *ops; struct iommufd_hw_pagetable *hwpt; int rc; @@ -37,7 +38,13 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, if (IS_ERR(hwpt)) return hwpt; - hwpt->domain = iommu_domain_alloc(dev->bus); + ops = dev_iommu_ops(dev); + if (!ops || !ops->domain_alloc_user) { + rc = -EOPNOTSUPP; + goto out_abort; + } + + hwpt->domain = ops->domain_alloc_user(dev, NULL, NULL); if (!hwpt->domain) { rc = -ENOMEM; goto out_abort;