Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/vfio/pci/vfio_pci_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion drivers/vfio/pci/vfio_pci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions drivers/vfio/pci/vfio_pci_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion drivers/vfio/pci/vfio_pci_rdwr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down