Re: [PATCH 2/6] iommu/vt-d: Implement hw_info for iommu capability query

From: Jason Gunthorpe
Date: Fri Feb 10 2023 - 19:15:58 EST


On Fri, Feb 10, 2023 at 03:44:10PM -0700, Alex Williamson wrote:
> On Wed, 8 Feb 2023 20:16:38 -0800
> Yi Liu <yi.l.liu@xxxxxxxxx> wrote:
>
> > From: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> >
> > To support nested translation in the userspace, it should check the
> > underlying hardware information for the capabilities.
> >
> > Add intel_iommu_hw_info() to report cap_reg and ecap_reg information.
> >
> > Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
> > Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx>
> > Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
> > Signed-off-by: Yi Sun <yi.y.sun@xxxxxxxxxxxxxxx>
> > ---
> > drivers/iommu/intel/iommu.c | 19 +++++++++++++++++++
> > drivers/iommu/intel/iommu.h | 1 +
> > include/uapi/linux/iommufd.h | 21 +++++++++++++++++++++
> > 3 files changed, 41 insertions(+)
> >
> > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
> > index 59df7e42fd53..929f600cc350 100644
> > --- a/drivers/iommu/intel/iommu.c
> > +++ b/drivers/iommu/intel/iommu.c
> > @@ -4760,8 +4760,26 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid)
> > intel_pasid_tear_down_entry(iommu, dev, pasid, false);
> > }
> >
> > +static void *intel_iommu_hw_info(struct device *dev, u32 *length)
> > +{
> > + struct device_domain_info *info = dev_iommu_priv_get(dev);
> > + struct intel_iommu *iommu = info->iommu;
> > + struct iommu_device_info_vtd *vtd;
> > +
> > + vtd = kzalloc(sizeof(*vtd), GFP_KERNEL);
> > + if (!vtd)
> > + return ERR_PTR(-ENOMEM);
> > +
> > + vtd->cap_reg = iommu->cap;
> > + vtd->ecap_reg = iommu->ecap;
>
> Just a friendly reminder that these registers are already exposed to
> userspace under /sys/class/iommu/ and each device has an iommu link
> back to their iommu device there.

I think in cases of mdevs w/ PASID (eg SIOV) it is not general to get
from vfio sysfs to the sysfs path for the iommu.

> This series doesn't really stand on its own without some discussion
> of why that interface is not sufficient for this use case.

IMHO I don't really like the idea of mixing iommufd with sysfs, it
should stand on its own.

In particular there is no generic way to go from a iommufd dev_id to
any sysfs path, userspace would need prior unique knowledge about the
subsystem that is being bound to iommufd first.

So, I think some of those explanations would be good in the commit
message?

I would also add explanation about what userspace is supposed to do
with these bits when it operates the nesting feature.

Jason