Skip to contentSkip to conversation

DMA operations by device when device is fake removed using PCI sysfs 'remove' interface

DISCUSSION Andrey Grodzovsky 2 participants 4 messages Apr 22, 2021 – Apr 27, 2021 PCI

lore
Share & tools
lore
#0 lore raw

Hi Bjorn, I am working on graceful device removal on PCI for our amdgppu driver. As part of it I am triggering device remove by writing echo 1 > /sys/bus/pci/drivers/amdgpu/xxxx:xx:xx.x/remove

Question - in case there is a DMA operation in flight while I hit the 'remove', is there a way to wait for completion of all the DMA operations of the device being removed ? Is PCI core taking care of this or is there an API we can use to do it in the driver's pci_remove callback ? We are concerned with possible system memory corruptions otherwise.

Andrey

#1 lore raw

Ping

Andrey

Quoted 6 lines · Andrey Grodzovsky

Hi Bjorn, I am working on graceful device removal on PCI for our amdgppu driver. As part of it I am triggering device remove by writing echo 1 > /sys/bus/pci/drivers/amdgpu/xxxx:xx:xx.x/remove

Question - in case there is a DMA operation in flight while I hit the 'remove', is there a way to wait for completion of all the DMA operations of the device being removed ? Is PCI core taking care of this or is there an API we can use to do it in the driver's pci_remove callback ? We are concerned with possible system memory corruptions otherwise.

Andrey

#2 lore raw
In reply to Andrey Grodzovsky
Quoted 9 lines · Andrey Grodzovsky

Hi Bjorn, I am working on graceful device removal on PCI for our amdgppu driver. As part of it I am triggering device remove by writing echo 1 > /sys/bus/pci/drivers/amdgpu/xxxx:xx:xx.x/remove

Question - in case there is a DMA operation in flight while I hit the 'remove', is there a way to wait for completion of all the DMA operations of the device being removed ? Is PCI core taking care of this
or is there an API we can use to do it in the driver's pci_remove callback ? We are concerned with possible system memory corruptions otherwise.

As far as I am aware, the PCI core does not wait for completion of DMA operations during remove.

The only generic way to do this that I can see would be to clear the Bus Master Enable bit and then wait on the PCIe Device Status Transactions Pending bit. Obviously that would only work for PCIe, not Conventional PCI. There is one driver that calls pci_wait_for_pending_transaction(), in ice_remove().

Bjorn

#3 lore raw
Quoted 11 lines · Bjorn Helgaas
Quoted 9 lines · Andrey Grodzovsky

Hi Bjorn, I am working on graceful device removal on PCI for our amdgppu driver. As part of it I am triggering device remove by writing echo 1 > /sys/bus/pci/drivers/amdgpu/xxxx:xx:xx.x/remove

Question - in case there is a DMA operation in flight while I hit the 'remove', is there a way to wait for completion of all the DMA operations of the device being removed ? Is PCI core taking care of this
or is there an API we can use to do it in the driver's pci_remove callback ? We are concerned with possible system memory corruptions otherwise.

Quoted 8 lines

As far as I am aware, the PCI core does not wait for completion of DMA operations during remove.

The only generic way to do this that I can see would be to clear the Bus Master Enable bit and then wait on the PCIe Device Status Transactions Pending bit. Obviously that would only work for PCIe, not Conventional PCI. There is one driver that calls pci_wait_for_pending_transaction(), in ice_remove().

It looks like they do the opposite in ice, they first call pci_wait_for_pending_transaction and then call pci_disable_device which is the one turning off Bus mastering. Are they wrong ?

Andrey

Quoted 3 lines

Bjorn