vfio queue:

* Fixed endianness of VFIO device state packets
 * Improved IGD passthrough support with legacy mode
 * Improved build
 * Added support for old AMD GPUs (x550)
 * Updated property documentation
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEoPZlSPBIlev+awtgUaNDx8/77KEFAmfQfQcACgkQUaNDx8/7
 7KEUNw/+PjFpHrz5muQ8itkbyd36eJJdcxCl+9IPIWfnUfB582epkLcgvWyswGUo
 krFTregoRG0PKtgZDtv95owGtVJOgK6XYFadGHiYkvvsb41twOYsP7/SuI+KMiEv
 IDFLMvCTyorSIIoEF8i2EexfGPRV1VoWwvBoHgRRmYlzwzXnufjABpoZ0a25DTye
 DQ4yhSfqoIh1gOcdL9tPictnZg9OxKr2ePXNdrtymtEIhg3ZobD3Jd8J4WCcsfKT
 fxxBO5NsGgA8oM7i02fYN9kgMwqTnVhSAu1wq9PXsbrnNXam+trywAWSO6CjL+rV
 ++STWNSrRoHzuotRBr7BzrTpTFyQyfwBWqUT5L4NlhgXB3Xybk+M6Zj08Yva8pjE
 w78JQKvKp54gU34AWBW0/J6+u3v+iE8l1Eywx6xueF9Q+YSUDeW9B1LDdjFJryhF
 d8j3J+vuglbdsp05D+tVErf5cqFvFDfrjTkXkZNtmx7wky45XS9ZvNazYW1KI3f9
 bg8Wjb7ZujuvxpSjycPRZzdKa8kqSgSZg7fg91Wimiy1Iqe3SZVVWNchLYiPp8Dm
 nXMfOEpVHQZ1vzeo7dVWyxu9Y1ujgvUQy8kMa9q2W2S7HQ5Sna79n7eMVJxqZQ4G
 m0ETFToOcPPOnZBWgqNOSUlSQncFuIVgNTDvycQ9dMhGorYcBDI=
 =Vh0m
 -----END PGP SIGNATURE-----

Merge tag 'pull-vfio-20250311' of https://github.com/legoater/qemu into staging

vfio queue:

* Fixed endianness of VFIO device state packets
* Improved IGD passthrough support with legacy mode
* Improved build
* Added support for old AMD GPUs (x550)
* Updated property documentation

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEEoPZlSPBIlev+awtgUaNDx8/77KEFAmfQfQcACgkQUaNDx8/7
# 7KEUNw/+PjFpHrz5muQ8itkbyd36eJJdcxCl+9IPIWfnUfB582epkLcgvWyswGUo
# krFTregoRG0PKtgZDtv95owGtVJOgK6XYFadGHiYkvvsb41twOYsP7/SuI+KMiEv
# IDFLMvCTyorSIIoEF8i2EexfGPRV1VoWwvBoHgRRmYlzwzXnufjABpoZ0a25DTye
# DQ4yhSfqoIh1gOcdL9tPictnZg9OxKr2ePXNdrtymtEIhg3ZobD3Jd8J4WCcsfKT
# fxxBO5NsGgA8oM7i02fYN9kgMwqTnVhSAu1wq9PXsbrnNXam+trywAWSO6CjL+rV
# ++STWNSrRoHzuotRBr7BzrTpTFyQyfwBWqUT5L4NlhgXB3Xybk+M6Zj08Yva8pjE
# w78JQKvKp54gU34AWBW0/J6+u3v+iE8l1Eywx6xueF9Q+YSUDeW9B1LDdjFJryhF
# d8j3J+vuglbdsp05D+tVErf5cqFvFDfrjTkXkZNtmx7wky45XS9ZvNazYW1KI3f9
# bg8Wjb7ZujuvxpSjycPRZzdKa8kqSgSZg7fg91Wimiy1Iqe3SZVVWNchLYiPp8Dm
# nXMfOEpVHQZ1vzeo7dVWyxu9Y1ujgvUQy8kMa9q2W2S7HQ5Sna79n7eMVJxqZQ4G
# m0ETFToOcPPOnZBWgqNOSUlSQncFuIVgNTDvycQ9dMhGorYcBDI=
# =Vh0m
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 12 Mar 2025 02:12:23 HKT
# gpg:                using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1
# gpg: Good signature from "Cédric Le Goater <clg@redhat.com>" [full]
# gpg:                 aka "Cédric Le Goater <clg@kaod.org>" [full]
# Primary key fingerprint: A0F6 6548 F048 95EB FE6B  0B60 51A3 43C7 CFFB ECA1

* tag 'pull-vfio-20250311' of https://github.com/legoater/qemu: (21 commits)
  vfio/pci: Drop debug commentary from x-device-dirty-page-tracking
  vfio/pci-quirks: Exclude non-ioport BAR from ATI quirk
  hw/vfio: Compile display.c once
  hw/vfio: Compile iommufd.c once
  hw/vfio: Compile more objects once
  hw/vfio: Compile some common objects once
  hw/vfio/common: Get target page size using runtime helpers
  hw/vfio/common: Include missing 'system/tcg.h' header
  hw/vfio/spapr: Do not include <linux/kvm.h>
  system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h'
  vfio/migration: Use BE byte order for device state wire packets
  vfio/igd: Fix broken KVMGT OpRegion support
  vfio/igd: Introduce x-igd-lpc option for LPC bridge ID quirk
  vfio/igd: Handle x-igd-opregion option in config quirk
  vfio/igd: Decouple common quirks from legacy mode
  vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk
  vfio/pci: Add placeholder for device-specific config space quirks
  vfio/igd: Move LPC bridge initialization to a separate function
  vfio/igd: Consolidate OpRegion initialization into a single function
  vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size
  ...

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2025-03-13 10:35:12 +08:00
commit 74b3445378
14 changed files with 303 additions and 420 deletions

View File

@ -34,6 +34,7 @@
#include "kvm_ppc.h" #include "kvm_ppc.h"
#include "migration/vmstate.h" #include "migration/vmstate.h"
#include "system/tcg.h" #include "system/tcg.h"
#include "system/hostmem.h"
#include "hw/ppc/spapr.h" #include "hw/ppc/spapr.h"

View File

@ -41,6 +41,7 @@
#include "hw/s390x/tod.h" #include "hw/s390x/tod.h"
#include "system/system.h" #include "system/system.h"
#include "system/cpus.h" #include "system/cpus.h"
#include "system/hostmem.h"
#include "target/s390x/kvm/pv.h" #include "target/s390x/kvm/pv.h"
#include "migration/blocker.h" #include "migration/blocker.h"
#include "qapi/visitor.h" #include "qapi/visitor.h"

View File

@ -30,6 +30,7 @@
#include "exec/address-spaces.h" #include "exec/address-spaces.h"
#include "exec/memory.h" #include "exec/memory.h"
#include "exec/ram_addr.h" #include "exec/ram_addr.h"
#include "exec/target_page.h"
#include "hw/hw.h" #include "hw/hw.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
@ -42,6 +43,7 @@
#include "migration/misc.h" #include "migration/misc.h"
#include "migration/blocker.h" #include "migration/blocker.h"
#include "migration/qemu-file.h" #include "migration/qemu-file.h"
#include "system/tcg.h"
#include "system/tpm.h" #include "system/tpm.h"
VFIODeviceList vfio_device_list = VFIODeviceList vfio_device_list =
@ -392,13 +394,14 @@ static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer,
MemoryRegionSection *section) MemoryRegionSection *section)
{ {
RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr); RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr);
int target_page_size = qemu_target_page_size();
VFIORamDiscardListener *vrdl; VFIORamDiscardListener *vrdl;
/* Ignore some corner cases not relevant in practice. */ /* Ignore some corner cases not relevant in practice. */
g_assert(QEMU_IS_ALIGNED(section->offset_within_region, TARGET_PAGE_SIZE)); g_assert(QEMU_IS_ALIGNED(section->offset_within_region, target_page_size));
g_assert(QEMU_IS_ALIGNED(section->offset_within_address_space, g_assert(QEMU_IS_ALIGNED(section->offset_within_address_space,
TARGET_PAGE_SIZE)); target_page_size));
g_assert(QEMU_IS_ALIGNED(int128_get64(section->size), TARGET_PAGE_SIZE)); g_assert(QEMU_IS_ALIGNED(int128_get64(section->size), target_page_size));
vrdl = g_new0(VFIORamDiscardListener, 1); vrdl = g_new0(VFIORamDiscardListener, 1);
vrdl->bcontainer = bcontainer; vrdl->bcontainer = bcontainer;

View File

@ -15,6 +15,7 @@
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qmp/qerror.h" #include "qapi/qmp/qerror.h"
#include "hw/boards.h"
#include "hw/hw.h" #include "hw/hw.h"
#include "hw/nvram/fw_cfg.h" #include "hw/nvram/fw_cfg.h"
#include "pci.h" #include "pci.h"
@ -106,40 +107,15 @@ static int igd_gen(VFIOPCIDevice *vdev)
return -1; return -1;
} }
typedef struct VFIOIGDQuirk { #define IGD_ASLS 0xfc /* ASL Storage Register */
struct VFIOPCIDevice *vdev;
uint32_t index;
uint64_t bdsm;
} VFIOIGDQuirk;
#define IGD_GMCH 0x50 /* Graphics Control Register */ #define IGD_GMCH 0x50 /* Graphics Control Register */
#define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */
#define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */ #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */
#define IGD_GMCH_GEN6_GMS_SHIFT 3 /* SNB_GMCH in i915 */ #define IGD_GMCH_GEN6_GMS_SHIFT 3 /* SNB_GMCH in i915 */
#define IGD_GMCH_GEN6_GMS_MASK 0x1f #define IGD_GMCH_GEN6_GMS_MASK 0x1f
#define IGD_GMCH_GEN6_GGMS_SHIFT 8
#define IGD_GMCH_GEN6_GGMS_MASK 0x3
#define IGD_GMCH_GEN8_GMS_SHIFT 8 /* BDW_GMCH in i915 */ #define IGD_GMCH_GEN8_GMS_SHIFT 8 /* BDW_GMCH in i915 */
#define IGD_GMCH_GEN8_GMS_MASK 0xff #define IGD_GMCH_GEN8_GMS_MASK 0xff
#define IGD_GMCH_GEN8_GGMS_SHIFT 6
#define IGD_GMCH_GEN8_GGMS_MASK 0x3
static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch)
{
uint64_t ggms;
if (gen < 8) {
ggms = (gmch >> IGD_GMCH_GEN6_GGMS_SHIFT) & IGD_GMCH_GEN6_GGMS_MASK;
} else {
ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK;
if (ggms != 0) {
ggms = 1ULL << ggms;
}
}
return ggms * MiB;
}
static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch) static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch)
{ {
@ -164,6 +140,82 @@ static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch)
return 0; return 0;
} }
/*
* The OpRegion includes the Video BIOS Table, which seems important for
* telling the driver what sort of outputs it has. Without this, the device
* may work in the guest, but we may not get output. This also requires BIOS
* support to reserve and populate a section of guest memory sufficient for
* the table and to write the base address of that memory to the ASLS register
* of the IGD device.
*/
static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
struct vfio_region_info *info,
Error **errp)
{
int ret;
vdev->igd_opregion = g_malloc0(info->size);
ret = pread(vdev->vbasedev.fd, vdev->igd_opregion,
info->size, info->offset);
if (ret != info->size) {
error_setg(errp, "failed to read IGD OpRegion");
g_free(vdev->igd_opregion);
vdev->igd_opregion = NULL;
return false;
}
/*
* Provide fw_cfg with a copy of the OpRegion which the VM firmware is to
* allocate 32bit reserved memory for, copy these contents into, and write
* the reserved memory base address to the device ASLS register at 0xFC.
* Alignment of this reserved region seems flexible, but using a 4k page
* alignment seems to work well. This interface assumes a single IGD
* device, which may be at VM address 00:02.0 in legacy mode or another
* address in UPT mode.
*
* NB, there may be future use cases discovered where the VM should have
* direct interaction with the host OpRegion, in which case the write to
* the ASLS register would trigger MemoryRegion setup to enable that.
*/
fw_cfg_add_file(fw_cfg_find(), "etc/igd-opregion",
vdev->igd_opregion, info->size);
trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name);
pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
return true;
}
static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp)
{
g_autofree struct vfio_region_info *opregion = NULL;
int ret;
/* Hotplugging is not supported for opregion access */
if (vdev->pdev.qdev.hotplugged) {
error_setg(errp, "IGD OpRegion is not supported on hotplugged device");
return false;
}
ret = vfio_get_dev_region_info(&vdev->vbasedev,
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
if (ret) {
error_setg_errno(errp, -ret,
"Device does not supports IGD OpRegion feature");
return false;
}
if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) {
return false;
}
return true;
}
/* /*
* The rather short list of registers that we copy from the host devices. * The rather short list of registers that we copy from the host devices.
* The LPC/ISA bridge values are definitely needed to support the vBIOS, the * The LPC/ISA bridge values are definitely needed to support the vBIOS, the
@ -300,129 +352,72 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev,
return ret; return ret;
} }
/* static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
* IGD Gen8 and newer support up to 8MB for the GTT and use a 64bit PTE
* entry, older IGDs use 2MB and 32bit. Each PTE maps a 4k page. Therefore
* we either have 2M/4k * 4 = 2k or 8M/4k * 8 = 16k as the maximum iobar index
* for programming the GTT.
*
* See linux:include/drm/i915_drm.h for shift and mask values.
*/
static int vfio_igd_gtt_max(VFIOPCIDevice *vdev)
{ {
uint32_t gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); g_autofree struct vfio_region_info *host = NULL;
int gen = igd_gen(vdev); g_autofree struct vfio_region_info *lpc = NULL;
uint64_t ggms_size = igd_gtt_memory_size(gen, gmch); PCIDevice *lpc_bridge;
int ret;
return (ggms_size / (4 * KiB)) * (gen < 8 ? 4 : 8); /*
* Copying IDs or creating new devices are not supported on hotplug
*/
if (vdev->pdev.qdev.hotplugged) {
error_setg(errp, "IGD LPC is not supported on hotplugged device");
return false;
} }
/* /*
* The IGD ROM will make use of stolen memory (GGMS) for support of VESA modes. * We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that we
* Somehow the host stolen memory range is used for this, but how the ROM gets * can stuff host values into, so if there's already one there and it's not
* it is a mystery, perhaps it's hardcoded into the ROM. Thankfully though, it * one we can hack on, this quirk is no-go. Sorry Q35.
* reprograms the GTT through the IOBAR where we can trap it and transpose the
* programming to the VM allocated buffer. That buffer gets reserved by the VM
* firmware via the fw_cfg entry added below. Here we're just monitoring the
* IOBAR address and data registers to detect a write sequence targeting the
* GTTADR. This code is developed by observed behavior and doesn't have a
* direct spec reference, unfortunately.
*/ */
static uint64_t vfio_igd_quirk_data_read(void *opaque, lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
hwaddr addr, unsigned size) 0, PCI_DEVFN(0x1f, 0));
{ if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
VFIOIGDQuirk *igd = opaque; "vfio-pci-igd-lpc-bridge")) {
VFIOPCIDevice *vdev = igd->vdev; error_setg(errp,
"Cannot create LPC bridge due to existing device at 1f.0");
igd->index = ~0; return false;
return vfio_region_read(&vdev->bars[4].region, addr + 4, size);
} }
static void vfio_igd_quirk_data_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
{
VFIOIGDQuirk *igd = opaque;
VFIOPCIDevice *vdev = igd->vdev;
uint64_t val = data;
int gen = igd_gen(vdev);
/* /*
* Programming the GGMS starts at index 0x1 and uses every 4th index (ie. * Check whether we have all the vfio device specific regions to
* 0x1, 0x5, 0x9, 0xd,...). For pre-Gen8 each 4-byte write is a whole PTE * support LPC quirk (added in Linux v4.6).
* entry, with 0th bit enable set. For Gen8 and up, PTEs are 64bit, so
* entries 0x5 & 0xd are the high dword, in our case zero. Each PTE points
* to a 4k page, which we translate to a page from the VM allocated region,
* pointed to by the BDSM register. If this is not set, we fail.
*
* We trap writes to the full configured GTT size, but we typically only
* see the vBIOS writing up to (nearly) the 1MB barrier. In fact it often
* seems to miss the last entry for an even 1MB GTT. Doing a gratuitous
* write of that last entry does work, but is hopefully unnecessary since
* we clear the previous GTT on initialization.
*/ */
if ((igd->index % 4 == 1) && igd->index < vfio_igd_gtt_max(vdev)) { ret = vfio_get_dev_region_info(&vdev->vbasedev,
if (gen < 8 || (igd->index % 8 == 1)) { VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
uint64_t base; VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc);
if (ret) {
if (gen < 11) { error_setg(errp, "IGD LPC bridge access is not supported by kernel");
base = pci_get_long(vdev->pdev.config + IGD_BDSM); return false;
} else {
base = pci_get_quad(vdev->pdev.config + IGD_BDSM_GEN11);
}
if (!base) {
hw_error("vfio-igd: Guest attempted to program IGD GTT before "
"BIOS reserved stolen memory. Unsupported BIOS?");
} }
val = data - igd->bdsm + base; ret = vfio_get_dev_region_info(&vdev->vbasedev,
} else { VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
val = 0; /* upper 32bits of pte, we only enable below 4G PTEs */ VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host);
if (ret) {
error_setg(errp, "IGD host bridge access is not supported by kernel");
return false;
} }
trace_vfio_pci_igd_bar4_write(vdev->vbasedev.name, /* Create/modify LPC bridge */
igd->index, data, val); ret = vfio_pci_igd_lpc_init(vdev, lpc);
if (ret) {
error_setg(errp, "Failed to create/modify LPC bridge for IGD");
return false;
} }
vfio_region_write(&vdev->bars[4].region, addr + 4, val, size); /* Stuff some host values into the VM PCI host bridge */
ret = vfio_pci_igd_host_init(vdev, host);
igd->index = ~0; if (ret) {
error_setg(errp, "Failed to modify host bridge for IGD");
return false;
} }
static const MemoryRegionOps vfio_igd_data_quirk = { return true;
.read = vfio_igd_quirk_data_read,
.write = vfio_igd_quirk_data_write,
.endianness = DEVICE_LITTLE_ENDIAN,
};
static uint64_t vfio_igd_quirk_index_read(void *opaque,
hwaddr addr, unsigned size)
{
VFIOIGDQuirk *igd = opaque;
VFIOPCIDevice *vdev = igd->vdev;
igd->index = ~0;
return vfio_region_read(&vdev->bars[4].region, addr, size);
} }
static void vfio_igd_quirk_index_write(void *opaque, hwaddr addr,
uint64_t data, unsigned size)
{
VFIOIGDQuirk *igd = opaque;
VFIOPCIDevice *vdev = igd->vdev;
igd->index = data;
vfio_region_write(&vdev->bars[4].region, addr, data, size);
}
static const MemoryRegionOps vfio_igd_index_quirk = {
.read = vfio_igd_quirk_index_read,
.write = vfio_igd_quirk_index_write,
.endianness = DEVICE_LITTLE_ENDIAN,
};
#define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_GGC_MMIO_OFFSET 0x108040
#define IGD_BDSM_MMIO_OFFSET 0x1080C0 #define IGD_BDSM_MMIO_OFFSET 0x1080C0
@ -438,9 +433,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
* bus address. * bus address.
*/ */
if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
!vfio_is_vga(vdev) || nr != 0 || !vfio_is_vga(vdev) || nr != 0) {
&vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
0, PCI_DEVFN(0x2, 0))) {
return; return;
} }
@ -488,20 +481,13 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next); QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next);
} }
void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
{ {
g_autofree struct vfio_region_info *rom = NULL; int ret, gen;
g_autofree struct vfio_region_info *opregion = NULL; uint64_t gms_size;
g_autofree struct vfio_region_info *host = NULL;
g_autofree struct vfio_region_info *lpc = NULL;
VFIOQuirk *quirk;
VFIOIGDQuirk *igd;
PCIDevice *lpc_bridge;
int i, ret, gen;
uint64_t ggms_size, gms_size;
uint64_t *bdsm_size; uint64_t *bdsm_size;
uint32_t gmch; uint32_t gmch;
uint16_t cmd_orig, cmd; bool legacy_mode_enabled = false;
Error *err = NULL; Error *err = NULL;
/* /*
@ -510,24 +496,8 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
* PCI bus address. * PCI bus address.
*/ */
if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) || if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
!vfio_is_vga(vdev) || nr != 4 || !vfio_is_vga(vdev)) {
&vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev), return true;
0, PCI_DEVFN(0x2, 0))) {
return;
}
/*
* We need to create an LPC/ISA bridge at PCI bus address 00:1f.0 that we
* can stuff host values into, so if there's already one there and it's not
* one we can hack on, legacy mode is no-go. Sorry Q35.
*/
lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
0, PCI_DEVFN(0x1f, 0));
if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
"vfio-pci-igd-lpc-bridge")) {
error_report("IGD device %s cannot support legacy mode due to existing "
"devices at address 1f.0", vdev->vbasedev.name);
return;
} }
/* /*
@ -539,126 +509,77 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
if (gen == -1) { if (gen == -1) {
error_report("IGD device %s is unsupported in legacy mode, " error_report("IGD device %s is unsupported in legacy mode, "
"try SandyBridge or newer", vdev->vbasedev.name); "try SandyBridge or newer", vdev->vbasedev.name);
return; return true;
}
/*
* Most of what we're doing here is to enable the ROM to run, so if
* there's no ROM, there's no point in setting up this quirk.
* NB. We only seem to get BIOS ROMs, so a UEFI VM would need CSM support.
*/
ret = vfio_get_region_info(&vdev->vbasedev,
VFIO_PCI_ROM_REGION_INDEX, &rom);
if ((ret || !rom->size) && !vdev->pdev.romfile) {
error_report("IGD device %s has no ROM, legacy mode disabled",
vdev->vbasedev.name);
return;
}
/*
* Ignore the hotplug corner case, mark the ROM failed, we can't
* create the devices we need for legacy mode in the hotplug scenario.
*/
if (vdev->pdev.qdev.hotplugged) {
error_report("IGD device %s hotplugged, ROM disabled, "
"legacy mode disabled", vdev->vbasedev.name);
vdev->rom_read_failed = true;
return;
}
/*
* Check whether we have all the vfio device specific regions to
* support legacy mode (added in Linux v4.6). If not, bail.
*/
ret = vfio_get_dev_region_info(&vdev->vbasedev,
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
if (ret) {
error_report("IGD device %s does not support OpRegion access,"
"legacy mode disabled", vdev->vbasedev.name);
return;
}
ret = vfio_get_dev_region_info(&vdev->vbasedev,
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host);
if (ret) {
error_report("IGD device %s does not support host bridge access,"
"legacy mode disabled", vdev->vbasedev.name);
return;
}
ret = vfio_get_dev_region_info(&vdev->vbasedev,
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc);
if (ret) {
error_report("IGD device %s does not support LPC bridge access,"
"legacy mode disabled", vdev->vbasedev.name);
return;
} }
gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
/* /*
* If IGD VGA Disable is clear (expected) and VGA is not already enabled, * For backward compatibility, enable legacy mode when
* try to enable it. Probably shouldn't be using legacy mode without VGA, * - Machine type is i440fx (pc_piix)
* but also no point in us enabling VGA if disabled in hardware. * - IGD device is at guest BDF 00:02.0
* - Not manually disabled by x-igd-legacy-mode=off
*/
if ((vdev->igd_legacy_mode != ON_OFF_AUTO_OFF) &&
!strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") &&
(&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev),
0, PCI_DEVFN(0x2, 0)))) {
/*
* IGD legacy mode requires:
* - VBIOS in ROM BAR or file
* - VGA IO/MMIO ranges are claimed by IGD
* - OpRegion
* - Same LPC bridge and Host bridge VID/DID/SVID/SSID as host
*/
g_autofree struct vfio_region_info *rom = NULL;
legacy_mode_enabled = true;
info_report("IGD legacy mode enabled, "
"use x-igd-legacy-mode=off to disable it if unwanted.");
/*
* Most of what we're doing here is to enable the ROM to run, so if
* there's no ROM, there's no point in setting up this quirk.
* NB. We only seem to get BIOS ROMs, so UEFI VM would need CSM support.
*/
ret = vfio_get_region_info(&vdev->vbasedev,
VFIO_PCI_ROM_REGION_INDEX, &rom);
if ((ret || !rom->size) && !vdev->pdev.romfile) {
error_setg(&err, "Device has no ROM");
goto error;
}
/*
* If IGD VGA Disable is clear (expected) and VGA is not already
* enabled, try to enable it. Probably shouldn't be using legacy mode
* without VGA, but also no point in us enabling VGA if disabled in
* hardware.
*/ */
if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err)) { if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err)) {
error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); error_setg(&err, "Unable to enable VGA access");
error_report("IGD device %s failed to enable VGA access, " goto error;
"legacy mode disabled", vdev->vbasedev.name);
return;
} }
/* Create our LPC/ISA bridge */ /* Enable OpRegion and LPC bridge quirk */
ret = vfio_pci_igd_lpc_init(vdev, lpc); vdev->features |= VFIO_FEATURE_ENABLE_IGD_OPREGION;
if (ret) { vdev->features |= VFIO_FEATURE_ENABLE_IGD_LPC;
error_report("IGD device %s failed to create LPC bridge, " } else if (vdev->igd_legacy_mode == ON_OFF_AUTO_ON) {
"legacy mode disabled", vdev->vbasedev.name); error_setg(&err,
return; "Machine is not i440fx or assigned BDF is not 00:02.0");
} goto error;
/* Stuff some host values into the VM PCI host bridge */
ret = vfio_pci_igd_host_init(vdev, host);
if (ret) {
error_report("IGD device %s failed to modify host bridge, "
"legacy mode disabled", vdev->vbasedev.name);
return;
} }
/* Setup OpRegion access */ /* Setup OpRegion access */
if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) { if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
error_append_hint(&err, "IGD legacy mode disabled\n"); !vfio_pci_igd_setup_opregion(vdev, errp)) {
error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); goto error;
return;
} }
/* Setup our quirk to munge GTT addresses to the VM allocated buffer */ /* Setup LPC bridge / Host bridge PCI IDs */
quirk = vfio_quirk_alloc(2); if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) &&
igd = quirk->data = g_malloc0(sizeof(*igd)); !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) {
igd->vdev = vdev; goto error;
igd->index = ~0;
if (gen < 11) {
igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM, 4);
} else {
igd->bdsm = vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11, 4);
igd->bdsm |=
(uint64_t)vfio_pci_read_config(&vdev->pdev, IGD_BDSM_GEN11 + 4, 4) << 32;
} }
igd->bdsm &= ~((1 * MiB) - 1); /* 1MB aligned */
memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_index_quirk,
igd, "vfio-igd-index-quirk", 4);
memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
0, &quirk->mem[0], 1);
memory_region_init_io(&quirk->mem[1], OBJECT(vdev), &vfio_igd_data_quirk,
igd, "vfio-igd-data-quirk", 4);
memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
4, &quirk->mem[1], 1);
QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next);
/* /*
* Allow user to override dsm size using x-igd-gms option, in multiples of * Allow user to override dsm size using x-igd-gms option, in multiples of
@ -685,7 +606,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
} }
} }
ggms_size = igd_gtt_memory_size(gen, gmch);
gms_size = igd_stolen_memory_size(gen, gmch); gms_size = igd_stolen_memory_size(gen, gmch);
/* /*
@ -697,7 +617,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
* config offset 0x5C. * config offset 0x5C.
*/ */
bdsm_size = g_malloc(sizeof(*bdsm_size)); bdsm_size = g_malloc(sizeof(*bdsm_size));
*bdsm_size = cpu_to_le64(ggms_size + gms_size); *bdsm_size = cpu_to_le64(gms_size);
fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size", fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
bdsm_size, sizeof(*bdsm_size)); bdsm_size, sizeof(*bdsm_size));
@ -717,37 +637,46 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0); pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0);
} }
trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, (gms_size / MiB));
return true;
error:
/* /*
* This IOBAR gives us access to GTTADR, which allows us to write to * When legacy mode is implicity enabled, continue on error,
* the GTT itself. So let's go ahead and write zero to all the GTT * to keep compatibility
* entries to avoid spurious DMA faults. Be sure I/O access is enabled
* before talking to the device.
*/ */
if (pread(vdev->vbasedev.fd, &cmd_orig, sizeof(cmd_orig), if (legacy_mode_enabled && (vdev->igd_legacy_mode == ON_OFF_AUTO_AUTO)) {
vdev->config_offset + PCI_COMMAND) != sizeof(cmd_orig)) { error_report_err(err);
error_report("IGD device %s - failed to read PCI command register", error_report("IGD legacy mode disabled");
vdev->vbasedev.name); return true;
} }
cmd = cmd_orig | PCI_COMMAND_IO; error_propagate(errp, err);
return false;
if (pwrite(vdev->vbasedev.fd, &cmd, sizeof(cmd),
vdev->config_offset + PCI_COMMAND) != sizeof(cmd)) {
error_report("IGD device %s - failed to write PCI command register",
vdev->vbasedev.name);
} }
for (i = 1; i < vfio_igd_gtt_max(vdev); i += 4) { /*
vfio_region_write(&vdev->bars[4].region, 0, i, 4); * KVMGT/GVT-g vGPU exposes an emulated OpRegion. So far, users have to specify
vfio_region_write(&vdev->bars[4].region, 4, 0, 4); * x-igd-opregion=on to enable the access.
* TODO: Check VID/DID and enable opregion access automatically
*/
static bool vfio_pci_kvmgt_config_quirk(VFIOPCIDevice *vdev, Error **errp)
{
if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) &&
!vfio_pci_igd_setup_opregion(vdev, errp)) {
return false;
} }
if (pwrite(vdev->vbasedev.fd, &cmd_orig, sizeof(cmd_orig), return true;
vdev->config_offset + PCI_COMMAND) != sizeof(cmd_orig)) {
error_report("IGD device %s - failed to restore PCI command register",
vdev->vbasedev.name);
} }
trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
(ggms_size + gms_size) / MiB); {
/* KVMGT/GVT-g vGPU is exposed as mdev */
if (vdev->vbasedev.mdev) {
return vfio_pci_kvmgt_config_quirk(vdev, errp);
}
return vfio_pci_igd_config_quirk(vdev, errp);
} }

View File

@ -25,7 +25,6 @@
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "qemu/chardev_open.h" #include "qemu/chardev_open.h"
#include "pci.h" #include "pci.h"
#include "exec/ram_addr.h"
static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova, static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
ram_addr_t size, void *vaddr, bool readonly) ram_addr_t size, void *vaddr, bool readonly)

View File

@ -1,27 +1,32 @@
vfio_ss = ss.source_set() vfio_ss = ss.source_set()
vfio_ss.add(files( vfio_ss.add(files(
'helpers.c',
'common.c', 'common.c',
'container-base.c',
'container.c', 'container.c',
'migration.c',
'migration-multifd.c',
'cpr.c',
)) ))
vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c')) vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
'iommufd.c',
))
vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
'display.c',
'pci-quirks.c', 'pci-quirks.c',
'pci.c', 'pci.c',
)) ))
vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c')) vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c')) vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
vfio_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
vfio_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c')) vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c')) vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss) specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
system_ss.add(when: 'CONFIG_VFIO', if_true: files(
'helpers.c',
'container-base.c',
'migration.c',
'migration-multifd.c',
'cpr.c',
))
system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
'iommufd.c',
))
system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
'display.c',
))

View File

@ -13,6 +13,7 @@
#include "hw/vfio/vfio-common.h" #include "hw/vfio/vfio-common.h"
#include "migration/misc.h" #include "migration/misc.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qemu/bswap.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qemu/lockable.h" #include "qemu/lockable.h"
#include "qemu/main-loop.h" #include "qemu/main-loop.h"
@ -155,12 +156,16 @@ bool vfio_multifd_load_state_buffer(void *opaque, char *data, size_t data_size,
return false; return false;
} }
packet->version = be32_to_cpu(packet->version);
if (packet->version != VFIO_DEVICE_STATE_PACKET_VER_CURRENT) { if (packet->version != VFIO_DEVICE_STATE_PACKET_VER_CURRENT) {
error_setg(errp, "%s: packet has unknown version %" PRIu32, error_setg(errp, "%s: packet has unknown version %" PRIu32,
vbasedev->name, packet->version); vbasedev->name, packet->version);
return false; return false;
} }
packet->idx = be32_to_cpu(packet->idx);
packet->flags = be32_to_cpu(packet->flags);
if (packet->idx == UINT32_MAX) { if (packet->idx == UINT32_MAX) {
error_setg(errp, "%s: packet index is invalid", vbasedev->name); error_setg(errp, "%s: packet index is invalid", vbasedev->name);
return false; return false;
@ -558,9 +563,9 @@ vfio_save_complete_precopy_thread_config_state(VFIODevice *vbasedev,
packet_len = sizeof(*packet) + bioc->usage; packet_len = sizeof(*packet) + bioc->usage;
packet = g_malloc0(packet_len); packet = g_malloc0(packet_len);
packet->version = VFIO_DEVICE_STATE_PACKET_VER_CURRENT; packet->version = cpu_to_be32(VFIO_DEVICE_STATE_PACKET_VER_CURRENT);
packet->idx = idx; packet->idx = cpu_to_be32(idx);
packet->flags = VFIO_DEVICE_STATE_CONFIG_STATE; packet->flags = cpu_to_be32(VFIO_DEVICE_STATE_CONFIG_STATE);
memcpy(&packet->data, bioc->data, bioc->usage); memcpy(&packet->data, bioc->data, bioc->usage);
if (!multifd_queue_device_state(idstr, instance_id, if (!multifd_queue_device_state(idstr, instance_id,
@ -610,7 +615,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompletePrecopyThreadData *d,
} }
packet = g_malloc0(sizeof(*packet) + migration->data_buffer_size); packet = g_malloc0(sizeof(*packet) + migration->data_buffer_size);
packet->version = VFIO_DEVICE_STATE_PACKET_VER_CURRENT; packet->version = cpu_to_be32(VFIO_DEVICE_STATE_PACKET_VER_CURRENT);
for (idx = 0; ; idx++) { for (idx = 0; ; idx++) {
ssize_t data_size; ssize_t data_size;
@ -631,7 +636,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompletePrecopyThreadData *d,
break; break;
} }
packet->idx = idx; packet->idx = cpu_to_be32(idx);
packet_size = sizeof(*packet) + data_size; packet_size = sizeof(*packet) + data_size;
if (!multifd_queue_device_state(d->idstr, d->instance_id, if (!multifd_queue_device_state(d->idstr, d->instance_id,

View File

@ -27,7 +27,6 @@
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qapi-events-vfio.h" #include "qapi/qapi-events-vfio.h"
#include "exec/ramlist.h" #include "exec/ramlist.h"
#include "exec/ram_addr.h"
#include "pci.h" #include "pci.h"
#include "trace.h" #include "trace.h"
#include "hw/hw.h" #include "hw/hw.h"

View File

@ -403,7 +403,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vdev, int nr)
/* This windows doesn't seem to be used except by legacy VGA code */ /* This windows doesn't seem to be used except by legacy VGA code */
if (!vfio_pci_is(vdev, PCI_VENDOR_ID_ATI, PCI_ANY_ID) || if (!vfio_pci_is(vdev, PCI_VENDOR_ID_ATI, PCI_ANY_ID) ||
!vdev->vga || nr != 4) { !vdev->vga || nr != 4 || !vdev->bars[4].ioport) {
return; return;
} }
@ -1114,59 +1114,19 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr)
trace_vfio_quirk_rtl8168_probe(vdev->vbasedev.name); trace_vfio_quirk_rtl8168_probe(vdev->vbasedev.name);
} }
#define IGD_ASLS 0xfc /* ASL Storage Register */
/*
* The OpRegion includes the Video BIOS Table, which seems important for
* telling the driver what sort of outputs it has. Without this, the device
* may work in the guest, but we may not get output. This also requires BIOS
* support to reserve and populate a section of guest memory sufficient for
* the table and to write the base address of that memory to the ASLS register
* of the IGD device.
*/
bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
struct vfio_region_info *info, Error **errp)
{
int ret;
vdev->igd_opregion = g_malloc0(info->size);
ret = pread(vdev->vbasedev.fd, vdev->igd_opregion,
info->size, info->offset);
if (ret != info->size) {
error_setg(errp, "failed to read IGD OpRegion");
g_free(vdev->igd_opregion);
vdev->igd_opregion = NULL;
return false;
}
/*
* Provide fw_cfg with a copy of the OpRegion which the VM firmware is to
* allocate 32bit reserved memory for, copy these contents into, and write
* the reserved memory base address to the device ASLS register at 0xFC.
* Alignment of this reserved region seems flexible, but using a 4k page
* alignment seems to work well. This interface assumes a single IGD
* device, which may be at VM address 00:02.0 in legacy mode or another
* address in UPT mode.
*
* NB, there may be future use cases discovered where the VM should have
* direct interaction with the host OpRegion, in which case the write to
* the ASLS register would trigger MemoryRegion setup to enable that.
*/
fw_cfg_add_file(fw_cfg_find(), "etc/igd-opregion",
vdev->igd_opregion, info->size);
trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name);
pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
return true;
}
/* /*
* Common quirk probe entry points. * Common quirk probe entry points.
*/ */
bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp)
{
#ifdef CONFIG_VFIO_IGD
if (!vfio_probe_igd_config_quirk(vdev, errp)) {
return false;
}
#endif
return true;
}
void vfio_vga_quirk_setup(VFIOPCIDevice *vdev) void vfio_vga_quirk_setup(VFIOPCIDevice *vdev)
{ {
vfio_vga_probe_ati_3c3_quirk(vdev); vfio_vga_probe_ati_3c3_quirk(vdev);
@ -1215,7 +1175,6 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr)
vfio_probe_rtl8168_bar2_quirk(vdev, nr); vfio_probe_rtl8168_bar2_quirk(vdev, nr);
#ifdef CONFIG_VFIO_IGD #ifdef CONFIG_VFIO_IGD
vfio_probe_igd_bar0_quirk(vdev, nr); vfio_probe_igd_bar0_quirk(vdev, nr);
vfio_probe_igd_bar4_quirk(vdev, nr);
#endif #endif
} }

View File

@ -3128,6 +3128,10 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
goto out_unset_idev; goto out_unset_idev;
} }
if (!vfio_config_quirk_setup(vdev, errp)) {
goto out_unset_idev;
}
if (vdev->vga) { if (vdev->vga) {
vfio_vga_quirk_setup(vdev); vfio_vga_quirk_setup(vdev);
} }
@ -3136,31 +3140,6 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_bar_quirk_setup(vdev, i); vfio_bar_quirk_setup(vdev, i);
} }
if (!vdev->igd_opregion &&
vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) {
g_autofree struct vfio_region_info *opregion = NULL;
if (vdev->pdev.qdev.hotplugged) {
error_setg(errp,
"cannot support IGD OpRegion feature on hotplugged "
"device");
goto out_unset_idev;
}
ret = vfio_get_dev_region_info(vbasedev,
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
if (ret) {
error_setg_errno(errp, -ret,
"does not support requested IGD OpRegion feature");
goto out_unset_idev;
}
if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) {
goto out_unset_idev;
}
}
/* QEMU emulates all of MSI & MSIX */ /* QEMU emulates all of MSI & MSIX */
if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff, memset(vdev->emulated_config_bits + pdev->msix_cap, 0xff,
@ -3381,6 +3360,10 @@ static const Property vfio_pci_dev_properties[] = {
VFIO_FEATURE_ENABLE_REQ_BIT, true), VFIO_FEATURE_ENABLE_REQ_BIT, true),
DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features, DEFINE_PROP_BIT("x-igd-opregion", VFIOPCIDevice, features,
VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false),
DEFINE_PROP_BIT("x-igd-lpc", VFIOPCIDevice, features,
VFIO_FEATURE_ENABLE_IGD_LPC_BIT, false),
DEFINE_PROP_ON_OFF_AUTO("x-igd-legacy-mode", VFIOPCIDevice,
igd_legacy_mode, ON_OFF_AUTO_AUTO),
DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice,
vbasedev.enable_migration, ON_OFF_AUTO_AUTO), vbasedev.enable_migration, ON_OFF_AUTO_AUTO),
DEFINE_PROP("x-migration-multifd-transfer", VFIOPCIDevice, DEFINE_PROP("x-migration-multifd-transfer", VFIOPCIDevice,
@ -3549,7 +3532,7 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
object_class_property_set_description(klass, /* 9.1 */ object_class_property_set_description(klass, /* 9.1 */
"x-device-dirty-page-tracking", "x-device-dirty-page-tracking",
"Disable device dirty page tracking and use " "Disable device dirty page tracking and use "
"container-based dirty page tracking (DEBUG)"); "container-based dirty page tracking");
object_class_property_set_description(klass, /* 9.1 */ object_class_property_set_description(klass, /* 9.1 */
"migration-events", "migration-events",
"Emit VFIO migration QAPI event when a VFIO device " "Emit VFIO migration QAPI event when a VFIO device "

View File

@ -154,10 +154,14 @@ struct VFIOPCIDevice {
#define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2 #define VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT 2
#define VFIO_FEATURE_ENABLE_IGD_OPREGION \ #define VFIO_FEATURE_ENABLE_IGD_OPREGION \
(1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT) (1 << VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT)
#define VFIO_FEATURE_ENABLE_IGD_LPC_BIT 3
#define VFIO_FEATURE_ENABLE_IGD_LPC \
(1 << VFIO_FEATURE_ENABLE_IGD_LPC_BIT)
OnOffAuto display; OnOffAuto display;
uint32_t display_xres; uint32_t display_xres;
uint32_t display_yres; uint32_t display_yres;
int32_t bootindex; int32_t bootindex;
OnOffAuto igd_legacy_mode;
uint32_t igd_gms; uint32_t igd_gms;
OffAutoPCIBAR msix_relo; OffAutoPCIBAR msix_relo;
uint8_t nv_gpudirect_clique; uint8_t nv_gpudirect_clique;
@ -204,6 +208,7 @@ uint64_t vfio_vga_read(void *opaque, hwaddr addr, unsigned size);
void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned size); void vfio_vga_write(void *opaque, hwaddr addr, uint64_t data, unsigned size);
bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev); bool vfio_opt_rom_in_denylist(VFIOPCIDevice *vdev);
bool vfio_config_quirk_setup(VFIOPCIDevice *vdev, Error **errp);
void vfio_vga_quirk_setup(VFIOPCIDevice *vdev); void vfio_vga_quirk_setup(VFIOPCIDevice *vdev);
void vfio_vga_quirk_exit(VFIOPCIDevice *vdev); void vfio_vga_quirk_exit(VFIOPCIDevice *vdev);
void vfio_vga_quirk_finalize(VFIOPCIDevice *vdev); void vfio_vga_quirk_finalize(VFIOPCIDevice *vdev);
@ -215,7 +220,7 @@ bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp);
void vfio_quirk_reset(VFIOPCIDevice *vdev); void vfio_quirk_reset(VFIOPCIDevice *vdev);
VFIOQuirk *vfio_quirk_alloc(int nr_mem); VFIOQuirk *vfio_quirk_alloc(int nr_mem);
void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr); void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr);
void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr); bool vfio_probe_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp);
extern const PropertyInfo qdev_prop_nv_gpudirect_clique; extern const PropertyInfo qdev_prop_nv_gpudirect_clique;
@ -227,10 +232,6 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev,
bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp);
bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev,
struct vfio_region_info *info,
Error **errp);
void vfio_display_reset(VFIOPCIDevice *vdev); void vfio_display_reset(VFIOPCIDevice *vdev);
bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp);
void vfio_display_finalize(VFIOPCIDevice *vdev); void vfio_display_finalize(VFIOPCIDevice *vdev);

View File

@ -11,10 +11,8 @@
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/vfio.h> #include <linux/vfio.h>
#ifdef CONFIG_KVM
#include <linux/kvm.h>
#endif
#include "system/kvm.h" #include "system/kvm.h"
#include "system/hostmem.h"
#include "exec/address-spaces.h" #include "exec/address-spaces.h"
#include "hw/vfio/vfio-common.h" #include "hw/vfio/vfio-common.h"

View File

@ -102,9 +102,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
bool ramblock_is_pmem(RAMBlock *rb); bool ramblock_is_pmem(RAMBlock *rb);
long qemu_minrampagesize(void);
long qemu_maxrampagesize(void);
/** /**
* qemu_ram_alloc_from_file, * qemu_ram_alloc_from_file,
* qemu_ram_alloc_from_fd: Allocate a ram block from the specified backing * qemu_ram_alloc_from_fd: Allocate a ram block from the specified backing

View File

@ -93,4 +93,7 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev); size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
char *host_memory_backend_get_name(HostMemoryBackend *backend); char *host_memory_backend_get_name(HostMemoryBackend *backend);
long qemu_minrampagesize(void);
long qemu_maxrampagesize(void);
#endif #endif