[PATCH] vfio/pci: Do not clear PCI_COMMAND_INTX_DISABLE in pre_reset

Victor Zhao posted 1 patch 1 month, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251219092634.3176885-1-Victor.Zhao@amd.com
Maintainers: Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>
hw/vfio/pci.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
[PATCH] vfio/pci: Do not clear PCI_COMMAND_INTX_DISABLE in pre_reset
Posted by Victor Zhao 1 month, 3 weeks ago
When vfio_pci_pre_reset() disables MSI/MSI-X, the device may fall back
to INTx mode. The code then clears PCI_COMMAND_INTX_DISABLE, allowing
the device to assert INTx. Since interrupt handlers have already been
removed, this causes unhandled interrupts and kernel "nobody cared"
warnings.

Fix by not clearing PCI_COMMAND_INTX_DISABLE. The device reset will
restore it to default state.

Cc: qemu-stable@nongnu.org
Signed-off-by: Victor Zhao <Victor.Zhao@amd.com>
---
 hw/vfio/pci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b46b1305a7..1681134cf2 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2616,13 +2616,9 @@ void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
 
     vfio_disable_interrupts(vdev);
 
-    /*
-     * Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master.
-     * Also put INTx Disable in known state.
-     */
+    /* Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master. */
     cmd = vfio_pci_read_config(pdev, PCI_COMMAND, 2);
-    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
-             PCI_COMMAND_INTX_DISABLE);
+    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
     vfio_pci_write_config(pdev, PCI_COMMAND, cmd, 2);
 
     /* Make sure the device is in D0 */
-- 
2.25.1
Re: [PATCH] vfio/pci: Do not clear PCI_COMMAND_INTX_DISABLE in pre_reset
Posted by Alex Williamson 3 weeks, 5 days ago
On Fri, 19 Dec 2025 17:26:34 +0800
Victor Zhao <Victor.Zhao@amd.com> wrote:

> When vfio_pci_pre_reset() disables MSI/MSI-X, the device may fall back
> to INTx mode. The code then clears PCI_COMMAND_INTX_DISABLE, allowing
> the device to assert INTx. Since interrupt handlers have already been
> removed, this causes unhandled interrupts and kernel "nobody cared"
> warnings.

Is there a bug report to go along with this?

> Fix by not clearing PCI_COMMAND_INTX_DISABLE. The device reset will
> restore it to default state.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Victor Zhao <Victor.Zhao@amd.com>
> ---
>  hw/vfio/pci.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index b46b1305a7..1681134cf2 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2616,13 +2616,9 @@ void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
>  
>      vfio_disable_interrupts(vdev);
>  
> -    /*
> -     * Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master.
> -     * Also put INTx Disable in known state.
> -     */
> +    /* Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master. */
>      cmd = vfio_pci_read_config(pdev, PCI_COMMAND, 2);
> -    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
> -             PCI_COMMAND_INTX_DISABLE);
> +    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
>      vfio_pci_write_config(pdev, PCI_COMMAND, cmd, 2);
>  
>      /* Make sure the device is in D0 */


I think the key here was the "known state", where the PCI spec defines
that INTX_DISABLE should be clear after reset.  If we don't touch it,
the set bit will be saved and restored around reset.  However, the first
thing we do in post-reset is to configure INTx, and I think this
results in INTX_DISABLE being cleared such that the post-reset state
seen by the VM is consistent to the spec.  Do you confirm?  It might be
worthwhile to expand the comment in that regard.  Thanks,

Alex
Re: [PATCH] vfio/pci: Do not clear PCI_COMMAND_INTX_DISABLE in pre_reset
Posted by Cédric Le Goater 1 month, 2 weeks ago
Hello,

On 12/19/25 10:26, Victor Zhao wrote:
> When vfio_pci_pre_reset() disables MSI/MSI-X, the device may fall back
> to INTx mode. The code then clears PCI_COMMAND_INTX_DISABLE, allowing
> the device to assert INTx. Since interrupt handlers have already been
> removed, this causes unhandled interrupts and kernel "nobody cared"
> warnings.

Could you tell us which device you are using ?

> Fix by not clearing PCI_COMMAND_INTX_DISABLE. The device reset will
> restore it to default state.

INTx disable is a complex topic. It is checked and set in different
places in the kernel too to avoid spurious interrupts. The DisINTx
default value should be 0, like for IO, MEM and MASTER  though.

But some device have broken support: commit 450744051d20 ("vfio/pci:
Hide broken INTx support from user") and routine
pci_intx_mask_supported(). I lack the historical background.


Alex,

What's your opinion ?

Thanks,

C.


> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Victor Zhao <Victor.Zhao@amd.com>
> ---
>   hw/vfio/pci.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index b46b1305a7..1681134cf2 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2616,13 +2616,9 @@ void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
>   
>       vfio_disable_interrupts(vdev);
>   
> -    /*
> -     * Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master.
> -     * Also put INTx Disable in known state.
> -     */
> +    /* Stop any ongoing DMA by disconnecting I/O, MMIO, and bus master. */
>       cmd = vfio_pci_read_config(pdev, PCI_COMMAND, 2);
> -    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER |
> -             PCI_COMMAND_INTX_DISABLE);
> +    cmd &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
>       vfio_pci_write_config(pdev, PCI_COMMAND, cmd, 2);
>   
>       /* Make sure the device is in D0 */