public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Yi Liu <yi.l.liu@intel.com>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>,
	"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>,
	"eric.auger@redhat.com" <eric.auger@redhat.com>,
	"nicolinc@nvidia.com" <nicolinc@nvidia.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"chao.p.peng@linux.intel.com" <chao.p.peng@linux.intel.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"Duan, Zhenzhong" <zhenzhong.duan@intel.com>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH v3 1/7] iommu: Introduce a replace API for device pasid
Date: Fri, 16 Aug 2024 10:02:02 -0300	[thread overview]
Message-ID: <20240816130202.GB2032816@nvidia.com> (raw)
In-Reply-To: <1a825f1b-be9d-4de1-948a-be0cce3175be@intel.com>

On Fri, Aug 16, 2024 at 05:43:18PM +0800, Yi Liu wrote:
> On 2024/7/18 16:27, Tian, Kevin wrote:
> > > From: Liu, Yi L <yi.l.liu@intel.com>
> > > Sent: Friday, June 28, 2024 5:06 PM
> > > 
> > > @@ -3289,7 +3290,20 @@ static int __iommu_set_group_pasid(struct
> > > iommu_domain *domain,
> > > 
> > >   		if (device == last_gdev)
> > >   			break;
> > > -		ops->remove_dev_pasid(device->dev, pasid, domain);
> > > +		/* If no old domain, undo the succeeded devices/pasid */
> > > +		if (!old) {
> > > +			ops->remove_dev_pasid(device->dev, pasid, domain);
> > > +			continue;
> > > +		}
> > > +
> > > +		/*
> > > +		 * Rollback the succeeded devices/pasid to the old domain.
> > > +		 * And it is a driver bug to fail attaching with a previously
> > > +		 * good domain.
> > > +		 */
> > > +		if (WARN_ON(old->ops->set_dev_pasid(old, device->dev,
> > > +						    pasid, domain)))
> > > +			ops->remove_dev_pasid(device->dev, pasid, domain);
> > 
> > I wonder whether @remove_dev_pasid() can be replaced by having
> > blocking_domain support @set_dev_pasid?
> 
> how about your thought, @Jason?

I think we talked about doing that once before, I forget why it was
not done. Maybe there was an issue?

But it seems worth trying.

I would like to see set_dev_pasid pass in the old domain first:

	int (*set_dev_pasid)(struct iommu_domain *new_domain,
                             struct iommu_domain *old_domain,
                             struct device *dev,
			     ioasid_t pasid);

Replace includes the old_domain as an argument and it is necessary
information..

A quick try on SMMUv3 seems reasonable:

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 9bc50bded5af72..f512bfe5cd202c 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2931,13 +2931,12 @@ int arm_smmu_set_pasid(struct arm_smmu_master *master,
        return ret;
 }
 
-static void arm_smmu_remove_dev_pasid(struct device *dev, ioasid_t pasid,
-                                     struct iommu_domain *domain)
+static void arm_smmu_blocking_set_dev_pasid(struct iommu_domain *new_domain,
+                                           struct iommu_domain *old_domain,
+                                           struct device *dev, ioasid_t pasid)
 {
        struct arm_smmu_master *master = dev_iommu_priv_get(dev);
-       struct arm_smmu_domain *smmu_domain;
-
-       smmu_domain = to_smmu_domain(domain);
+       struct arm_smmu_domain *smmu_domain = to_smmu_domain(old_domain);
 
        mutex_lock(&arm_smmu_asid_lock);
        arm_smmu_clear_cd(master, pasid);
@@ -3039,6 +3038,7 @@ static int arm_smmu_attach_dev_blocked(struct iommu_domain *domain,
 
 static const struct iommu_domain_ops arm_smmu_blocked_ops = {
        .attach_dev = arm_smmu_attach_dev_blocked,
+       .set_dev_pasid = arm_smmu_blocked_set_dev_pasid,
 };
 
 static struct iommu_domain arm_smmu_blocked_domain = {
@@ -3487,7 +3487,6 @@ static struct iommu_ops arm_smmu_ops = {
        .device_group           = arm_smmu_device_group,
        .of_xlate               = arm_smmu_of_xlate,
        .get_resv_regions       = arm_smmu_get_resv_regions,
-       .remove_dev_pasid       = arm_smmu_remove_dev_pasid,
        .dev_enable_feat        = arm_smmu_dev_enable_feature,
        .dev_disable_feat       = arm_smmu_dev_disable_feature,
        .page_response          = arm_smmu_page_response,

Jason

  reply	other threads:[~2024-08-16 13:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-28  9:05 [PATCH v3 0/7] iommufd support pasid attach/replace Yi Liu
2024-06-28  9:05 ` [PATCH v3 1/7] iommu: Introduce a replace API for device pasid Yi Liu
2024-07-18  8:27   ` Tian, Kevin
2024-08-16  9:43     ` Yi Liu
2024-08-16 13:02       ` Jason Gunthorpe [this message]
2024-09-06  4:21         ` Yi Liu
2024-09-06  4:33           ` Baolu Lu
2024-09-06  5:57             ` Yi Liu
2024-06-28  9:05 ` [PATCH v3 2/7] iommufd: Pass pasid through the device attach/replace path Yi Liu
2024-06-28  9:05 ` [PATCH v3 3/7] iommufd: Support attach/replace hwpt per pasid Yi Liu
2024-06-28  9:05 ` [PATCH v3 4/7] iommufd/selftest: Add set_dev_pasid and remove_dev_pasid in mock iommu Yi Liu
2024-06-28  9:05 ` [PATCH v3 5/7] iommufd/selftest: Add a helper to get test device Yi Liu
2024-06-28  9:05 ` [PATCH v3 6/7] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2024-06-28  9:05 ` [PATCH v3 7/7] iommufd/selftest: Add coverage for iommufd " Yi Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240816130202.GB2032816@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=eric.auger@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=robin.murphy@arm.com \
    --cc=yi.l.liu@intel.com \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox