Re: [PATCH v2 1/2] iommu/virtio: Make use of ops->iotlb_sync_map

From: Baolu Lu
Date: Sun Sep 24 2023 - 22:51:43 EST


On 9/23/23 7:33 AM, Jason Gunthorpe wrote:
On Fri, Sep 22, 2023 at 07:07:40PM +0100, Robin Murphy wrote:

virtio isn't setting ops->pgsize_bitmap for the sake of direct mappings
either; it sets it once it's discovered any instance, since apparently it's
assuming that all instances must support identical page sizes, and thus once
it's seen one it can work "normally" per the core code's assumptions. It's
also I think the only driver which has a "finalise" bodge but*can* still
properly support map-before-attach, by virtue of having to replay mappings
to every new endpoint anyway.
Well it can't quite do that since it doesn't know the geometry - it
all is sort of guessing and hoping it doesn't explode on replay. If it
knows the geometry it wouldn't need finalize...

The ultimate solution to this problem seems to be to add device pointer
to the parameter of ops->domain_alloc. So once the domain is allocated,
it is fully initialized. Attaching this domain to a device that is not
compatible will return -EINVAL, then the caller has to allocate a new
domain for this device.

I feel that this is not an AMD specific problem, other iommu drivers
will also encounter the similar problem sooner or later.

Best regards,
baolu