Re: [PATCH v4 03/13] PCI: pci_stub: Suppress kernel DMA ownership auto-claiming

From: Lu Baolu
Date: Thu Dec 30 2021 - 20:59:46 EST


On 12/31/21 9:10 AM, Lu Baolu wrote:

On 12/31/21 8:40 AM, Jason Gunthorpe wrote:
On Thu, Dec 30, 2021 at 04:24:14PM -0600, Bjorn Helgaas wrote:

I was speculating that maybe the DMA ownership claiming must be done
*before* the driver's .probe() method?

This is correct.

If DMA ownership could be claimed by the .probe() method, we
wouldn't need the new flag in struct device_driver.

The other requirement is that every existing driver must claim
ownership, so pushing this into the device driver's probe op would
require revising almost every driver in Linux...

In effect the new flag indicates if the driver will do the DMA
ownership claim in it's probe, or should use the default claim the
core code does.

In almost every case a driver should do a claim. A driver like
pci-stub, or a bridge, that doesn't actually operate MMIO on the
device would be the exception.

We still need to call iommu_device_use_dma_api() in bus dma_configure()
callback. But we can call iommu_device_unuse_dma_api() in the .probe()
of vfio (and vfio-approved) drivers, so that we don't need the new flag
anymore.

Oh, wait. I didn't think about the hot-plug case. If we call
iommu_device_use_dma_api() in bus dma_configure() anyway, we can't bind
any (no matter vfio or none-vfio) driver to a device if it's group has
already been assigned to user space. It seems that we can't omit this
flag.

Best regards,
baolu