lkml.org 
[lkml]   [2021]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC v16 1/9] iommu: Introduce attach/detach_pasid_table API
On Fri, Dec 10, 2021 at 08:56:56AM +0000, Tian, Kevin wrote:
> > So, something like vfio pci would implement three uAPI operations:
> > - Attach page table to RID
> > - Attach page table to PASID
> > - Attach page table to RID and all PASIDs
> > And here 'page table' is everything below the STE in SMMUv3
> >
> > While mdev can only support:
> > - Access emulated page table
> > - Attach page table to PASID
>
> mdev is a pci device from user p.o.v, having its vRID and vPASID. From
> this angle the uAPI is no different from vfio-pci (except the ARM one):

No, it isn't. The internal operation is completely different, and it
must call different iommufd APIs than vfio-pci does.

This is user visible - mdev can never be attached to an ARM user page
table, for instance.

For iommufd there is no vRID, vPASID or any confusing stuff like
that. You'll have an easier time if you stop thinking in these terms.

We probably end up with three iommufd calls:
int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id, unsigned int flags)
int iommufd_device_attach_pasid(struct iommufd_device *idev, u32 *pt_id, unsigned int flags, ioasid_t *pasid)
int iommufd_device_attach_sw_iommu(struct iommufd_device *idev, u32 pt_id);

And the uAPI from VFIO must map onto them.

vfio-pci:
- 'VFIO_SET_CONTAINER' does
iommufd_device_attach(idev, &pt_id, IOMMUFD_FULL_DEVICE);
# IOMMU specific if this captures PASIDs or cause them to fail,
# but IOMMUFD_FULL_DEVICE will prevent attaching any PASID
# later on all iommu's.

vfio-mdev:
- 'VFIO_SET_CONTAINER' does one of:
iommufd_device_attach_pasid(idev, &pt_id, IOMMUFD_ASSIGN_PASID, &pasid);
iommufd_device_attach_sw_iommu(idev, pt_id);

That is three of the cases.

Then we have new ioctls for the other cases:

vfio-pci:
- 'bind only the RID, so we can use PASID'
iommufd_device_attach(idev, &pt_id, 0);
- 'bind to a specific PASID'
iommufd_device_attach_pasid(idev, &pt_id, 0, &pasid);

vfio-mdev:
- 'like VFIO_SET_CONTAINER but bind to a specific PASID'
iommufd_device_attach_pasid(idev, &pt_id, 0, &pasid);

The iommu driver will block attachments that are incompatible, ie ARM
user page tables only work with:
iommufd_device_attach(idev, &pt_id, IOMMUFD_FULL_DEVICE)
all other calls fail.

How exactly we put all of this into new ioctls, I'm not sure, but it
does seem pretty clear this is what the iommufd kAPI will need to look
like to cover the cases we know about already.

As you can see, userpace needs to understand what mode it is operating
in. If it does IOMMUFD_FULL_DEVICE and manages PASID somehow in
userspace, or it doesn't and can use the iommufd_device_attach_pasid()
paths.

> Is modeling like above considered ambiguous?

You've skipped straight to the ioctls without designing the kernel API
to meet all the requirements :)

Jason

\
 
 \ /
  Last update: 2021-12-10 14:23    [W:0.176 / U:1.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site