[PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested

Nicolin Chen posted 13 patches 1 month ago
There is a newer version of this series
[PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested
Posted by Nicolin Chen 1 month ago
A vIOMMU-based hwpt_nested requires a cache invalidation op too, either
using the one in iommu_domain_ops or the one in viommu_ops. Enforce that
upon the allocated hwpt_nested.

Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/iommufd/hw_pagetable.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
index 1df5d40c93df..fd260a67b82c 100644
--- a/drivers/iommu/iommufd/hw_pagetable.c
+++ b/drivers/iommu/iommufd/hw_pagetable.c
@@ -302,7 +302,9 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
 	}
 	hwpt->domain->owner = viommu->iommu_dev->ops;
 
-	if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
+	if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED ||
+			 (!viommu->ops->cache_invalidate &&
+			  !hwpt->domain->ops->cache_invalidate_user))) {
 		rc = -EINVAL;
 		goto out_abort;
 	}
-- 
2.43.0
Re: [PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested
Posted by Jason Gunthorpe 3 weeks, 5 days ago
On Fri, Oct 25, 2024 at 04:50:33PM -0700, Nicolin Chen wrote:
> A vIOMMU-based hwpt_nested requires a cache invalidation op too, either
> using the one in iommu_domain_ops or the one in viommu_ops. Enforce that
> upon the allocated hwpt_nested.
> 
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
>  drivers/iommu/iommufd/hw_pagetable.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason
RE: [PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested
Posted by Tian, Kevin 3 weeks, 6 days ago
> From: Nicolin Chen <nicolinc@nvidia.com>
> Sent: Saturday, October 26, 2024 7:51 AM
> 
> @@ -302,7 +302,9 @@ iommufd_viommu_alloc_hwpt_nested(struct
> iommufd_viommu *viommu, u32 flags,
>  	}
>  	hwpt->domain->owner = viommu->iommu_dev->ops;
> 
> -	if (WARN_ON_ONCE(hwpt->domain->type !=
> IOMMU_DOMAIN_NESTED)) {
> +	if (WARN_ON_ONCE(hwpt->domain->type !=
> IOMMU_DOMAIN_NESTED ||
> +			 (!viommu->ops->cache_invalidate &&
> +			  !hwpt->domain->ops->cache_invalidate_user))) {
>  		rc = -EINVAL;
>  		goto out_abort;
>  	}

According to patch5, cache invalidate in viommu only uses
viommu->ops->cache_invalidate. Is here intended to allow
nested hwpt created via viommu to still support the old
method?
Re: [PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested
Posted by Jason Gunthorpe 3 weeks, 5 days ago
On Tue, Oct 29, 2024 at 08:22:43AM +0000, Tian, Kevin wrote:
> > From: Nicolin Chen <nicolinc@nvidia.com>
> > Sent: Saturday, October 26, 2024 7:51 AM
> > 
> > @@ -302,7 +302,9 @@ iommufd_viommu_alloc_hwpt_nested(struct
> > iommufd_viommu *viommu, u32 flags,
> >  	}
> >  	hwpt->domain->owner = viommu->iommu_dev->ops;
> > 
> > -	if (WARN_ON_ONCE(hwpt->domain->type !=
> > IOMMU_DOMAIN_NESTED)) {
> > +	if (WARN_ON_ONCE(hwpt->domain->type !=
> > IOMMU_DOMAIN_NESTED ||
> > +			 (!viommu->ops->cache_invalidate &&
> > +			  !hwpt->domain->ops->cache_invalidate_user))) {
> >  		rc = -EINVAL;
> >  		goto out_abort;
> >  	}
> 
> According to patch5, cache invalidate in viommu only uses
> viommu->ops->cache_invalidate. Is here intended to allow
> nested hwpt created via viommu to still support the old
> method?

I think that is reasonable?

Jason
RE: [PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested
Posted by Tian, Kevin 3 weeks, 5 days ago
> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Wednesday, October 30, 2024 12:05 AM
> 
> On Tue, Oct 29, 2024 at 08:22:43AM +0000, Tian, Kevin wrote:
> > > From: Nicolin Chen <nicolinc@nvidia.com>
> > > Sent: Saturday, October 26, 2024 7:51 AM
> > >
> > > @@ -302,7 +302,9 @@ iommufd_viommu_alloc_hwpt_nested(struct
> > > iommufd_viommu *viommu, u32 flags,
> > >  	}
> > >  	hwpt->domain->owner = viommu->iommu_dev->ops;
> > >
> > > -	if (WARN_ON_ONCE(hwpt->domain->type !=
> > > IOMMU_DOMAIN_NESTED)) {
> > > +	if (WARN_ON_ONCE(hwpt->domain->type !=
> > > IOMMU_DOMAIN_NESTED ||
> > > +			 (!viommu->ops->cache_invalidate &&
> > > +			  !hwpt->domain->ops->cache_invalidate_user))) {
> > >  		rc = -EINVAL;
> > >  		goto out_abort;
> > >  	}
> >
> > According to patch5, cache invalidate in viommu only uses
> > viommu->ops->cache_invalidate. Is here intended to allow
> > nested hwpt created via viommu to still support the old
> > method?
> 
> I think that is reasonable?
> 

Yes, just want to confirm.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>