mirror_qemu/hw/i386
Chuck Zmudzinski 6bebd3f818 xen/pt: reserve PCI slot 2 for Intel igd-passthru
Intel specifies that the Intel IGD must occupy slot 2 on the PCI bus,
as noted in docs/igd-assign.txt in the Qemu source code.

Currently, when the xl toolstack is used to configure a Xen HVM guest with
Intel IGD passthrough to the guest with the Qemu upstream device model,
a Qemu emulated PCI device will occupy slot 2 and the Intel IGD will occupy
a different slot. This problem often prevents the guest from booting.

The only available workarounds are not good: Configure Xen HVM guests to
use the old and no longer maintained Qemu traditional device model
available from xenbits.xen.org which does reserve slot 2 for the Intel
IGD or use the "pc" machine type instead of the "xenfv" machine type and
add the xen platform device at slot 3 using a command line option
instead of patching qemu to fix the "xenfv" machine type directly. The
second workaround causes some degredation in startup performance such as
a longer boot time and reduced resolution of the grub menu that is
displayed on the monitor. This patch avoids that reduced startup
performance when using the Qemu upstream device model for Xen HVM guests
configured with the igd-passthru=on option.

To implement this feature in the Qemu upstream device model for Xen HVM
guests, introduce the following new functions, types, and macros:

* XEN_PT_DEVICE_CLASS declaration, based on the existing TYPE_XEN_PT_DEVICE
* XEN_PT_DEVICE_GET_CLASS macro helper function for XEN_PT_DEVICE_CLASS
* typedef XenPTQdevRealize function pointer
* XEN_PCI_IGD_SLOT_MASK, the value of slot_reserved_mask to reserve slot 2
* xen_igd_reserve_slot and xen_igd_clear_slot functions

Michael Tsirkin:
* Introduce XEN_PCI_IGD_DOMAIN, XEN_PCI_IGD_BUS, XEN_PCI_IGD_DEV, and
  XEN_PCI_IGD_FN - use them to compute the value of XEN_PCI_IGD_SLOT_MASK

The new xen_igd_reserve_slot function uses the existing slot_reserved_mask
member of PCIBus to reserve PCI slot 2 for Xen HVM guests configured using
the xl toolstack with the gfx_passthru option enabled, which sets the
igd-passthru=on option to Qemu for the Xen HVM machine type.

The new xen_igd_reserve_slot function also needs to be implemented in
hw/xen/xen_pt_stub.c to prevent FTBFS during the link stage for the case
when Qemu is configured with --enable-xen and --disable-xen-pci-passthrough,
in which case it does nothing.

The new xen_igd_clear_slot function overrides qdev->realize of the parent
PCI device class to enable the Intel IGD to occupy slot 2 on the PCI bus
since slot 2 was reserved by xen_igd_reserve_slot when the PCI bus was
created in hw/i386/pc_piix.c for the case when igd-passthru=on.

Move the call to xen_host_pci_device_get, and the associated error
handling, from xen_pt_realize to the new xen_igd_clear_slot function to
initialize the device class and vendor values which enables the checks for
the Intel IGD to succeed. The verification that the host device is an
Intel IGD to be passed through is done by checking the domain, bus, slot,
and function values as well as by checking that gfx_passthru is enabled,
the device class is VGA, and the device vendor in Intel.

Signed-off-by: Chuck Zmudzinski <brchuckz@aol.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Message-Id: <b1b4a21fe9a600b1322742dda55a40e9961daa57.1674346505.git.brchuckz@aol.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
(cherry picked from commit 4f67543bb8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2023-05-18 21:09:59 +03:00
..
kvm i386/kvm: Replace abs64() with uabs64() from host-utils 2021-09-29 19:37:38 +10:00
xen hw/i386/xen/xen-hvm: Inline xen_piix_pci_write_config_client() and remove it 2022-06-29 00:24:59 +02:00
Kconfig hw/i386/pc: Allow instantiating a virtio-iommu device 2021-11-01 18:49:10 -04:00
acpi-build.c hw/i386/acpi-build: Resolve north rather than south bridges 2022-11-07 14:08:17 -05:00
acpi-build.h hw/acpi/ich9: Enable ACPI PCI hot-plug 2021-07-16 04:33:35 -04:00
acpi-common.c acpi: x86: madt: use build_append_int_noprefix() API to compose MADT table 2021-10-05 17:30:57 -04:00
acpi-common.h misc: Correct relative include path 2021-06-05 21:10:42 +02:00
acpi-microvm.c hw/acpi/microvm: turn on 8042 bit in FADT boot architecture flags if present 2022-03-07 17:43:14 -05:00
acpi-microvm.h microvm/acpi: add minimal acpi support 2020-09-17 14:16:19 +02:00
amd_iommu.c hw/i386/amd_iommu: Fix IOMMU event log encoding errors 2022-05-16 16:15:40 -04:00
amd_iommu.h Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
e820_memory_layout.c hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
e820_memory_layout.h hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
fw_cfg.c hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
fw_cfg.h hw/i386/e820: remove legacy reserved entries for e820 2022-11-02 06:56:31 -04:00
generic_event_device_x86.c acpi: ged: add x86 device variant. 2020-09-17 14:16:19 +02:00
intel_iommu.c intel-iommu: fail DEVIOTLB_UNMAP without dt mode 2023-03-29 10:20:04 +03:00
intel_iommu_internal.h intel-iommu: PASID support 2022-11-07 14:08:17 -05:00
kvmvapic.c Do not include cpu.h if it's not really necessary 2021-05-02 17:24:51 +02:00
meson.build microvm: add device tree support. 2021-11-02 17:24:17 +01:00
microvm-dt.c hw/rtc/mc146818rtc: QOM'ify io_base offset 2022-06-11 11:44:50 +02:00
microvm-dt.h microvm: add device tree support. 2021-11-02 17:24:17 +01:00
microvm.c Revert "hw/i386: pass RNG seed via setup_data entry" 2023-03-29 10:20:04 +03:00
multiboot.c hw/i386/multiboot: Avoid dynamic stack allocation 2022-09-22 16:38:28 +01:00
multiboot.h target/i386: use DMA-enabled multiboot ROM for new-enough QEMU machine types 2021-11-02 15:57:27 +01:00
pc.c Revert "hw/i386: pass RNG seed via setup_data entry" 2023-03-29 10:20:04 +03:00
pc_piix.c xen/pt: reserve PCI slot 2 for Intel igd-passthru 2023-05-18 21:09:59 +03:00
pc_q35.c Revert "hw/i386: pass RNG seed via setup_data entry" 2023-03-29 10:20:04 +03:00
pc_sysfw.c i386: factor out x86_firmware_configure() 2022-04-27 07:51:01 +02:00
pc_sysfw_ovmf-stubs.c hw/i386: Introduce X86_FW_OVMF Kconfig symbol 2021-07-14 22:28:58 +02:00
pc_sysfw_ovmf.c hw/i386: Replace magic number with field length calculation 2022-03-06 05:08:23 -05:00
port92.c Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
sgx-epc.c Mark remaining global TypeInfo instances as const 2022-02-21 13:30:20 +00:00
sgx-stub.c numa: Enable numa for SGX EPC sections 2021-12-10 09:47:18 +01:00
sgx.c hw/i386: add 4g boundary start to X86MachineState 2022-07-26 10:40:58 -04:00
trace-events intel-iommu: PASID support 2022-11-07 14:08:17 -05:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vmmouse.c hw/i386/vmmouse: Require 'i8042' property to be set 2021-12-18 10:57:37 +01:00
vmport.c Do not include cpu.h if it's not really necessary 2021-05-02 17:24:51 +02:00
x86-iommu-stub.c hw/i386/pc: Remove x86_iommu_get_type() 2021-11-01 18:49:10 -04:00
x86-iommu.c hw/i386/pc: Move IOMMU singleton into PCMachineState 2021-11-01 18:49:10 -04:00
x86.c Revert "hw/i386: pass RNG seed via setup_data entry" 2023-03-29 10:20:04 +03:00