Fix hotplug of PCI passthrought device on Xen
v4 cover Fix hotplug of PCI passthrought device on Xen
Adding PCI passthrough before the guest start works fine (broken in 2.9 but now fixed), but hotplug does not work anymore.
Anthony PERARD (3):
hw/acpi: Limit hotplug to root bus on legacy mode hw/acpi: Move acpi_set_pci_info to pcihp
Revert "ACPI: don't call acpi_pcihp_device_plug_cb on xen"
hw/acpi/pcihp.c | 40 +++++++++++++++++++++++++++++++++++++++- hw/acpi/piix4.c | 11 +++-------- hw/i386/acpi-build.c | 32 -------------------------------- stubs/Makefile.objs | 1 + stubs/pci-host-piix.c | 6 ++++++ 5 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 stubs/pci-host-piix.c
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 1/3 hw/acpi: Limit hotplug to root bus on legacy mode
---
New patch in V3
--- hw/acpi/pcihp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/pcihp.c +1 -1
@@ -273,7 +273,7 @@ static void pci_write(void *opaque, hwaddr addr, uint64_t data, addr, data);break ;case PCI_SEL_BASE : - s->hotplug_select = data; + s->hotplug_select = s->legacy_piix ?ACPI_PCIHP_BSEL_DEFAULT : data;ACPI_PCIHP_DPRINTF ("pcisel write %" HWADDR_PRIx" <== %" PRIu64"\n" , addr, data);default :
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 2/3 hw/acpi: Move acpi_set_pci_info to pcihp
In reply to Anthony PERARDHW part of ACPI PCI hotplug in QEMU depends on ACPI_PCIHP_PROP_BSEL being set on a PCI bus that supports ACPI hotplug. It should work regardless of the source of ACPI tables (QEMU generator/legacy SeaBIOS/Xen). So move ACPI_PCIHP_PROP_BSEL initialization into HW ACPI implementation part from QEMU's ACPI table generator.
To do PCI passthrough with Xen, the property ACPI_PCIHP_PROP_BSEL needs to be set, but this was done only when ACPI tables are built which is not needed for a Xen guest. The need for the property starts with commit "pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice" (f0c9d64a68b776374ec4732424a3e27753ce37b6).
Adding find_i440fx into stubs so that mips-softmmu target can be built.
---
Changes in V4:
- call acpi_set_pci_info only once
- Add a stub of find_i440fx (for mips_softmmu target)
Changes in V3:
- move acpi_set_pci_info to pcihp instead
Changes in V2:
- check for acpi_enabled before calling acpi_set_pci_info.
- set the property on the root bus only.
--- hw/acpi/pcihp.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 32 -------------------------------- stubs/Makefile.objs | 1 + stubs/pci-host-piix.c | 6 ++++++ 4 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 stubs/pci-host-piix.c
hw/acpi/pcihp.c +38 -0
@@ -75,6 +75,43 @@ static int acpi_pcihp_get_bsel(PCIBus *bus) } } +/* Assign BSEL property to all buses. In the future, this can be changed +* to only assign to buses that support hotplug. +*/ +static void *acpi_set_bsel (PCIBus *bus,void *opaque) +{ +unsigned *bsel_alloc = opaque; +unsigned *bus_bsel; + +if (qbus_is_hotpluggable (BUS (bus))) { + bus_bsel =g_malloc (sizeof *bus_bsel); + + *bus_bsel = (*bsel_alloc)++; +object_property_add_uint32_ptr (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , + bus_bsel, &error_abort); + } + +return bsel_alloc; +} + +static void acpi_set_pci_info (void ) +{ +static bool bsel_is_set; +PCIBus *bus; +unsigned bsel_alloc =ACPI_PCIHP_BSEL_DEFAULT ; + +if (bsel_is_set) { +return ; + } + bsel_is_set = true; + + bus =find_i440fx ();/* TODO: Q35 support */ +if (bus) { +/* Scan all PCI buses. Set property to enable acpi based hotplug. */ +pci_for_each_bus_depth_first (bus, acpi_set_bsel,NULL , &bsel_alloc); + } +} +static void acpi_pcihp_test_hotplug_bus (PCIBus *bus,void *opaque) {AcpiPciHpFind *find = opaque;
@@ -177,6 +214,7 @@ static void acpi_pcihp_update(AcpiPciHpState *s)void acpi_pcihp_reset (AcpiPciHpState *s) { +acpi_set_pci_info ();acpi_pcihp_update (s); }
hw/i386/acpi-build.c +0 -32
@@ -493,36 +493,6 @@ build_madt(GArray *table_data, BIOSLinker *linker, PCMachineState *pcms) table_data->len - madt_start, 1, NULL, NULL); } -/* Assign BSEL property to all buses. In the future, this can be changed -* to only assign to buses that support hotplug. -*/ -static void *acpi_set_bsel (PCIBus *bus,void *opaque) -{ -unsigned *bsel_alloc = opaque; -unsigned *bus_bsel; - -if (qbus_is_hotpluggable (BUS (bus))) { - bus_bsel =g_malloc (sizeof *bus_bsel); - - *bus_bsel = (*bsel_alloc)++; -object_property_add_uint32_ptr (OBJECT (bus),ACPI_PCIHP_PROP_BSEL , - bus_bsel, &error_abort); - } - -return bsel_alloc; -} - -static void acpi_set_pci_info (void ) -{ -PCIBus *bus =find_i440fx ();/* TODO: Q35 support */ -unsigned bsel_alloc =ACPI_PCIHP_BSEL_DEFAULT ; - -if (bus) { -/* Scan all PCI buses. Set property to enable acpi based hotplug. */ -pci_for_each_bus_depth_first (bus, acpi_set_bsel,NULL , &bsel_alloc); - } -} -static void build_append_pcihp_notify_entry (Aml *method,int slot) {Aml *if_ctx;
@@ -2888,8 +2858,6 @@ void acpi_setup(void) build_state =g_malloc0 (sizeof *build_state); -acpi_set_pci_info (); -acpi_build_tables_init (&tables);acpi_build (&tables,MACHINE (pcms));
stubs/Makefile.objs +1 -0
@@ -40,3 +40,4 @@ stub-obj-y += pc_madt_cpu_entry.o stub-obj-y += vmgenid.o stub-obj-y += xen-common.o stub-obj-y += xen-hvm.o +stub-obj-y += pci-host-piix.o
stubs/pci-host-piix.c new file +6 -0
@@ -0,0 +1,6 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +PCIBus *find_i440fx (void ) +{ +return NULL ; +}
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v4 3/3 Revert "ACPI: don't call acpi_pcihp_device_plug_cb on xen"
In reply to Anthony PERARDThis reverts commit 153eba4726dfa1bdfc31d1fe973b2a61b9035492.
This patch prevents PCI passthrough hotplug on Xen. Even if the Xen tool stack prepares its own ACPI tables, we still rely on QEMU for hotplug ACPI notifications.
The original issue is fixed by the two previous patch:
hw/acpi: Limit hotplug to root bus on legacy mode hw/acpi: Move acpi_set_pci_info to pcihp
---
CC: Stefano Stabellini <[email protected]>
CC: Bruce Rogers <[email protected]>
--- hw/acpi/piix4.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
hw/acpi/piix4.c +3 -8
@@ -385,10 +385,7 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, dev, errp); } }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -if (!xen_enabled ()) { -acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, - errp); - } +acpi_pcihp_device_plug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {if (s->cpu_hotplug_legacy) {legacy_acpi_cpu_plug_cb (hotplug_dev, &s->gpe_cpu, dev, errp);
@@ -411,10 +408,8 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,acpi_memory_unplug_request_cb (hotplug_dev, &s->acpi_memory_hotplug, dev, errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { -if (!xen_enabled ()) { -acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, - errp); - } +acpi_pcihp_device_unplug_cb (hotplug_dev, &s->acpi_pci_hotplug, dev, + errp); }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU ) && !s->cpu_hotplug_legacy) {acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp_state, dev, errp);
Signature · 7 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel