Re: [PATCH v7 12/12] iommu: Improve iopf_queue_flush_dev()

From: Jason Gunthorpe
Date: Mon Dec 04 2023 - 08:12:18 EST


On Mon, Dec 04, 2023 at 09:32:37AM +0800, Baolu Lu wrote:

> >
> > I know that is why it does, but it doesn't explain at all why.
> >
> > > 1. Clears the pasid translation entry. Thus, all subsequent DMA
> > > transactions (translation requests, translated requests or page
> > > requests) targeting the iommu domain will be blocked.
> > >
> > > 2. Waits until all pending page requests for the device's PASID have
> > > been reported to upper layers via the iommu_report_device_fault().
> > > However, this does not guarantee that all page requests have been
> > > responded.
> > >
> > > 3. Free all partial page requests for this pasid since the page request
> > > response is only needed for a complete request group. There's no
> > > action required for the page requests which are not last of a request
> > > group.
> >
> > But we expect the last to come eventually since everything should be
> > grouped properly, so why bother doing this?
> >
> > Indeed if 2 worked, how is this even possible to have partials?
>
> Step 1 clears the pasid table entry, hence all subsequent page requests
> are blocked (hardware auto-respond the request but not put it in the
> queue).

OK, that part makes sense, but it should be clearly documented that is
why this stuff is going on with the partial list.

"We have to clear the parial list as the new domain may not generate a
SW visible LAST. If it does generate a SW visible last then we simply
incompletely fault it and restart the device which will fix things on
retry"

> > Requests simply have to continue to be acked, it doesn't matter if
> > they are acked against the wrong domain because the device will simply
> > re-issue them..
>
> Ah! I start to get your point now.
>
> Even a page fault response is postponed to a new address space, which
> possibly be another address space or hardware blocking state, the
> hardware just retries.
>
> As long as we flushes all caches (IOTLB and device TLB) during switching,
> the mappings of the old domain won't leak. So it's safe to keep page
> requests there.
>
> Do I get you correctly?

Yes

It seems much simpler to me than trying to make this synchronous and
it is compatible with hitless replace of a PASID.

The lifetime and locking rules are also far more understandable

Jason