iommu/s390: Make attach succeed even if the device is in error state
authorNiklas Schnelle <schnelle@linux.ibm.com>
Wed, 9 Nov 2022 14:28:59 +0000 (15:28 +0100)
committerJoerg Roedel <jroedel@suse.de>
Sat, 19 Nov 2022 09:28:15 +0000 (10:28 +0100)
commit59bbf596791b89c7f88fdcac29dfc39c1221d25d
treeff25e8550704eadf0a53c2b6fbc118efa951cfd6
parentf3cc4f874efa8d5b10ebd9dc8702cd25b9e536a3
iommu/s390: Make attach succeed even if the device is in error state

If a zPCI device is in the error state while switching IOMMU domains
zpci_register_ioat() will fail and we would end up with the device not
attached to any domain. In this state since zdev->dma_table == NULL
a reset via zpci_hot_reset_device() would wrongfully re-initialize the
device for DMA API usage using zpci_dma_init_device(). As automatic
recovery is currently disabled while attached to an IOMMU domain this
only affects slot resets triggered through other means but will affect
automatic recovery once we switch to using dma-iommu.

Additionally with that switch common code expects attaching to the
default domain to always work so zpci_register_ioat() should only fail
if there is no chance to recover anyway, e.g. if the device has been
unplugged.

Improve the robustness of attach by specifically looking at the status
returned by zpci_mod_fc() to determine if the device is unavailable and
in this case simply ignore the error. Once the device is reset
zpci_hot_reset_device() will then correctly set the domain's DMA
translation tables.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>
Link: https://lore.kernel.org/r/20221109142903.4080275-2-schnelle@linux.ibm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
arch/s390/include/asm/pci.h
arch/s390/kvm/pci.c
arch/s390/pci/pci.c
arch/s390/pci/pci_dma.c
drivers/iommu/s390-iommu.c