When a guest gives a passthrough device back (ppt_unassign_device()) or asks for an FLR (ppt_reset_device()), memory decoding is turned off in the command register before ppt_teardown_msix() runs. Tearing down an MSI-X vector masks it: pci_teardown_intr() calls pci_mask_msix(), which reads and writes the vector control word in the MSI-X table, and that table lives in a memory BAR. With MEMEN clear the device answers the read with an Unsupported Request.
On most systems the CPU then reads all ones and nothing shows. On platforms with firmware-first error handling the UR completion is fatal: on an HPE ProLiant DX360 Gen10 with its Smart Array E208i-a passed through, every stop of the guest ended in an uncorrectable machine check in the IIO and a reset of the whole host.
Turn off only bus mastering first, which stops DMA, tear down MSI and MSI-X while the device still decodes memory, and only then turn off decoding before the reset. Linux's vfio does it in the same order (interrupts torn down, pci_clear_master(), then the reset).
Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Sponsored by: keelos.dev