From 97d24636b8a611c0f2d7265b4772d5e4a899b569 Mon Sep 17 00:00:00 2001 From: eriknordmark Date: Tue, 10 Nov 2026 11:59:03 +0100 Subject: [PATCH] vfio/pci: Expose setup ROM only for display devices Since e021e6cbfb5a ("vfio/pci: Expose setup ROM at ROM bar when needed") vfio-pci exposes the firmware-provided ROM copy (pdev->rom) at the ROM BAR of any device without a ROM BAR resource. Platform UEFI also hands over legacy PXE ROMs for onboard NICs that have no ROM BAR of their own, e.g. Intel's Boot Agent GE for the I210 on a Supermicro X10SDV. That image is shared across Intel GbE parts and its PCIR names 8086:1521. QEMU's vfio ROM loader rewrites a mismatched device ID to the device's own (1533) and stores the checksum correction in ROM byte 6, which in this ROM is the far return ending its init entry. A SeaBIOS guest given the NIC then crashes in the ROM's init with a KVM internal error. QEMU 9.1 through current master do this, so limit the fallback to display-class devices. Signed-off-by: eriknordmark Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VyjigXVFZhuUg5LiRSVwsj --- drivers/vfio/pci/vfio_pci_config.c | 2 +- drivers/vfio/pci/vfio_pci_core.c | 2 +- drivers/vfio/pci/vfio_pci_priv.h | 13 +++++++++++++ drivers/vfio/pci/vfio_pci_rdwr.c | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 1050bd7fd7ce..3fb59b43c0c8 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -511,7 +511,7 @@ static void vfio_bar_fixup(struct vfio_pci_core_device *vdev) mask = ~(pci_resource_len(pdev, PCI_ROM_RESOURCE) - 1); mask |= PCI_ROM_ADDRESS_ENABLE; *vbar &= cpu_to_le32((u32)mask); - } else if (pdev->rom && pdev->romlen) { + } else if (vfio_pci_has_setup_rom(pdev)) { mask = ~(roundup_pow_of_two(pdev->romlen) - 1); mask |= PCI_ROM_ADDRESS_ENABLE; *vbar &= cpu_to_le32((u32)mask); diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index a807a678277c..67e5c56353f6 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1101,7 +1101,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, pci_unmap_rom(pdev, io); } vfio_pci_memory_unlock_and_restore(vdev, cmd); - } else if (pdev->rom && pdev->romlen) { + } else if (vfio_pci_has_setup_rom(pdev)) { info.flags = VFIO_REGION_INFO_FLAG_READ; /* Report BAR size as power of two. */ info.size = roundup_pow_of_two(pdev->romlen); diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index 97d992c06322..2c1ee4215e96 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -111,4 +111,17 @@ static inline bool vfio_pci_is_vga(struct pci_dev *pdev) return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; } +/* + * vfio_pci_has_setup_rom - whether to expose the firmware-provided ROM copy + * (pdev->rom) at the ROM BAR of a device that has no ROM BAR resource. + * Limited to display devices: platform firmware also hands over legacy PXE + * ROMs for NICs without a ROM BAR of their own (e.g. Intel I210), and SeaBIOS + * guests crash executing them. + */ +static inline bool vfio_pci_has_setup_rom(struct pci_dev *pdev) +{ + return pdev->rom && pdev->romlen && + (pdev->class >> 16) == PCI_BASE_CLASS_DISPLAY; +} + #endif diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index 25380b7dfe18..bb9c28e53470 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -238,7 +238,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, if (pci_resource_start(pdev, bar)) end = pci_resource_len(pdev, bar); - else if (bar == PCI_ROM_RESOURCE && pdev->rom && pdev->romlen) + else if (bar == PCI_ROM_RESOURCE && vfio_pci_has_setup_rom(pdev)) end = roundup_pow_of_two(pdev->romlen); else return -EINVAL;