2023-10-24 15:00:24

by Yi Liu

[permalink] [raw]
Subject: [PATCH] iommu/vt-d: Enhance capability check for nested parent domain allocation

This adds the scalable mode check before allocating the nested parent domain
as checking nested capability is not enough. User may turn off scalable mode
which also means no nested support even if the hardware supports it.

Fixes: c97d1b20d383 ("iommu/vt-d: Add domain_alloc_user op")
Signed-off-by: Yi Liu <[email protected]>
---
v1: Based on Joao's dirty page tracking v6 https://github.com/jpemartins/linux/commits/iommufd-v6
---
drivers/iommu/intel/iommu.c | 2 +-
drivers/iommu/intel/iommu.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index eb92a201cc0b..65f46f1347e6 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4090,7 +4090,7 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags)
if (!iommu)
return ERR_PTR(-ENODEV);

- if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ecap_nest(iommu->ecap))
+ if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !nested_supported(iommu))
return ERR_PTR(-EOPNOTSUPP);

dirty_tracking = (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING);
diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h
index 3bb569146229..cc7301579773 100644
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -544,6 +544,8 @@ enum {
ecap_pasid((iommu)->ecap))
#define ssads_supported(iommu) (sm_supported(iommu) && \
ecap_slads((iommu)->ecap))
+#define nested_supported(iommu) (sm_supported(iommu) && \
+ ecap_nest((iommu)->ecap))

struct pasid_entry;
struct pasid_state_entry;
--
2.34.1


2023-10-25 01:14:17

by Lu Baolu

[permalink] [raw]
Subject: Re: [PATCH] iommu/vt-d: Enhance capability check for nested parent domain allocation

On 10/24/23 11:00 PM, Yi Liu wrote:
> This adds the scalable mode check before allocating the nested parent domain
> as checking nested capability is not enough. User may turn off scalable mode
> which also means no nested support even if the hardware supports it.
>
> Fixes: c97d1b20d383 ("iommu/vt-d: Add domain_alloc_user op")
> Signed-off-by: Yi Liu <[email protected]>
> ---
> v1: Based on Joao's dirty page tracking v6 https://github.com/jpemartins/linux/commits/iommufd-v6
> ---
> drivers/iommu/intel/iommu.c | 2 +-
> drivers/iommu/intel/iommu.h | 2 ++
> 2 files changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Lu Baolu <[email protected]>

Hi Jason,

Given that this fixes a commit in the iommufd tree, can you please pick
this fix as well?

Best regards,
baolu

2023-10-25 07:41:08

by Tian, Kevin

[permalink] [raw]
Subject: RE: [PATCH] iommu/vt-d: Enhance capability check for nested parent domain allocation

> From: Liu, Yi L <[email protected]>
> Sent: Tuesday, October 24, 2023 11:00 PM
>
> This adds the scalable mode check before allocating the nested parent
> domain
> as checking nested capability is not enough. User may turn off scalable mode
> which also means no nested support even if the hardware supports it.
>
> Fixes: c97d1b20d383 ("iommu/vt-d: Add domain_alloc_user op")
> Signed-off-by: Yi Liu <[email protected]>

Reviewed-by: Kevin Tian <[email protected]>

2023-10-25 11:34:08

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH] iommu/vt-d: Enhance capability check for nested parent domain allocation

On Wed, Oct 25, 2023 at 09:10:08AM +0800, Baolu Lu wrote:
> On 10/24/23 11:00 PM, Yi Liu wrote:
> > This adds the scalable mode check before allocating the nested parent domain
> > as checking nested capability is not enough. User may turn off scalable mode
> > which also means no nested support even if the hardware supports it.
> >
> > Fixes: c97d1b20d383 ("iommu/vt-d: Add domain_alloc_user op")
> > Signed-off-by: Yi Liu <[email protected]>
> > ---
> > v1: Based on Joao's dirty page tracking v6 https://github.com/jpemartins/linux/commits/iommufd-v6
> > ---
> > drivers/iommu/intel/iommu.c | 2 +-
> > drivers/iommu/intel/iommu.h | 2 ++
> > 2 files changed, 3 insertions(+), 1 deletion(-)
>
> Reviewed-by: Lu Baolu <[email protected]>
>
> Hi Jason,
>
> Given that this fixes a commit in the iommufd tree, can you please pick
> this fix as well?

Done

Thanks
Jason