xen: fix build without pci passthrough
PATCH v5 1/1 xen: fix build without pci passthrough
From: Anthony PERARD <[email protected]>
Xen PCI passthrough support may not be available and thus the global variable "has_igd_gfx_passthru" might be compiled out. Common code should not access it in that case.
Unfortunately, we can't use CONFIG_XEN_PCI_PASSTHROUGH directly in xen-common.c so this patch instead move access to the has_igd_gfx_passthru variable via function and those functions are also implemented as stubs. The stubs will be used when QEMU is built without passthrough support.
Now, when one will want to enable igd-passthru via the -machine property, they will get an error message if QEMU is built without passthrough support.
Message-Id: <[email protected]>
--- accel/xen/xen-all.c | 4 ++-- hw/Makefile.objs | 2 +- hw/i386/pc_piix.c | 2 +- hw/xen/Makefile.objs | 3 ++- hw/xen/xen_pt.c | 12 +++++++++++- hw/xen/xen_pt.h | 6 ++++-- hw/xen/xen_pt_stub.c | 22 ++++++++++++++++++++++ 7 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 hw/xen/xen_pt_stub.c
accel/xen/xen-all.c +2 -2
@@ -137,12 +137,12 @@ static void xen_change_state_handler(void *opaque, int running,static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) { -return has_igd_gfx_passthru; +return xen_igd_gfx_pt_enabled (); }static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) { - has_igd_gfx_passthru = value; +xen_igd_gfx_pt_set (value, errp); }static void xen_setup_post (MachineState *ms,AccelState *accel)
hw/Makefile.objs +1 -1
@@ -35,7 +35,7 @@ devices-dirs-y += usb/ devices-dirs-$(CONFIG_VFIO) += vfio/ devices-dirs-y += virtio/ devices-dirs-y += watchdog/ -devices-dirs-y += xen/ +devices-dirs-$(CONFIG_XEN) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_NUBUS) += nubus/ devices-dirs-y += semihosting/
hw/i386/pc_piix.c +1 -1
@@ -377,7 +377,7 @@ static void pc_init_isa(MachineState *machine)#ifdef CONFIG_XEN static void pc_xen_hvm_init_pci (MachineState *machine) { -const char *pci_type = has_igd_gfx_passthru ? +const char *pci_type =xen_igd_gfx_pt_enabled () ?TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE :TYPE_I440FX_PCI_DEVICE ; pc_init1(machine,
hw/xen/Makefile.objs +2 -1
@@ -1,6 +1,7 @@ # xen backend driver support -common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o +common-obj-y += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_load_rom.o +obj-$(call $(lnot, $(CONFIG_XEN_PCI_PASSTHROUGH))) += xen_pt_stub.o
hw/xen/xen_pt.c +11 -1
@@ -65,7 +65,17 @@#include "qemu/range.h" #include "exec/address-spaces.h" -bool has_igd_gfx_passthru; +static bool has_igd_gfx_passthru; + +bool xen_igd_gfx_pt_enabled (void ) +{ +return has_igd_gfx_passthru; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +}#define XEN_PT_NR_IRQS (256)static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS ] = {0 };
hw/xen/xen_pt.h +4 -2
@@ -5,6 +5,9 @@#include "hw/pci/pci.h" #include "xen-host-pci-device.h" +bool xen_igd_gfx_pt_enabled (void ); +void xen_igd_gfx_pt_set (bool value,Error **errp); + void xen_pt_log(const PCIDevice *d, const char *f, ...) GCC_FMT_ATTR(2, 3); #define XEN_PT_ERR(d, _f, _a...) xen_pt_log(d, "%s: Error: "_f, __func__, ##_a)
@@ -322,10 +325,9 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); -extern bool has_igd_gfx_passthru;static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (has_igd_gfx_passthru +return (xen_igd_gfx_pt_enabled () && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }int xen_pt_register_vga_regions (XenHostPCIDevice *dev);
hw/xen/xen_pt_stub.c new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2020 Citrix Systems UK Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/xen/xen_pt.h" +#include "qapi/error.h" + +bool xen_igd_gfx_pt_enabled (void ) +{ +return false; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ +if (value) { +error_setg (errp,"Xen PCI passthrough support not built in" ); + } +}
Signature · 1 line
2.26.2
hw/xen/Makefile.objs line 7
Quoted 13 lines · Paolo Bonzini
hw/xen/Makefile.objs +2
-1@@ -1,6 +1,7 @@ # xen backend driver support -common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o +common-obj-y += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_load_rom.o +obj-$(call $(lnot, $(CONFIG_XEN_PCI_PASSTHROUGH))) += xen_pt_stub.o
With this instead been spelled:
obj-$(call lnot,$(CONFIG_XEN_PCI_PASSTHROUGH)) += xen_pt_stub.o
I think the other changes are fine.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 16 lines · Paolo Bonzini
From: Anthony PERARD <[email protected]>
Xen PCI passthrough support may not be available and thus the global variable "
has_igd_gfx_passthru" might be compiled out. Common code should not access it in that case.Unfortunately, we can't use
CONFIG_XEN_PCI_PASSTHROUGHdirectly inxen-common.cso this patch instead move access to thehas_igd_gfx_passthruvariable via function and those functions are also implemented as stubs. The stubs will be used when QEMU is built without passthrough support.Now, when one will want to enable igd-passthru via the -machine property, they will get an error message if QEMU is built without passthrough support.
Quoted 5 lines
Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Reported-by Roger Pau Monné <[email protected]>Signed-off-by Anthony PERARD <[email protected]>Message-Id: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
Hi Paul,
Can I backport this patch to qemu-xen-4.14? It allows to build qemu without pci passthrough support which seems to be important for FreeBSD as PT with QEMU is only available on Linux.
(There's a fix to the patch that I would backport as well. "xen:
Actually fix build without passthrough")
Thanks.
Quoted 150 lines
--- accel/xen/xen-all.c | 4 ++-- hw/Makefile.objs | 2 +- hw/i386/pc_piix.c | 2 +- hw/xen/Makefile.objs | 3 ++- hw/xen/xen_pt.c | 12 +++++++++++- hw/xen/xen_pt.h | 6 ++++-- hw/xen/xen_pt_stub.c | 22 ++++++++++++++++++++++ 7 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 hw/xen/xen_pt_stub.caccel/xen/xen-all.c +2
-2@@ -137,12 +137,12 @@ static void xen_change_state_handler(void *opaque, int running,static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) { -return has_igd_gfx_passthru; +return xen_igd_gfx_pt_enabled (); }static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) { - has_igd_gfx_passthru = value; +xen_igd_gfx_pt_set (value, errp); }static void xen_setup_post (MachineState *ms,AccelState *accel)hw/Makefile.objs +1
-1@@ -35,7 +35,7 @@ devices-dirs-y += usb/ devices-dirs-$(CONFIG_VFIO) += vfio/ devices-dirs-y += virtio/ devices-dirs-y += watchdog/ -devices-dirs-y += xen/ +devices-dirs-$(CONFIG_XEN) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_NUBUS) += nubus/ devices-dirs-y += semihosting/hw/i386/pc_piix.c +1
-1@@ -377,7 +377,7 @@ static void pc_init_isa(MachineState *machine)#ifdef CONFIG_XEN static void pc_xen_hvm_init_pci (MachineState *machine) { -const char *pci_type = has_igd_gfx_passthru ? +const char *pci_type =xen_igd_gfx_pt_enabled () ?TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE :TYPE_I440FX_PCI_DEVICE ; pc_init1(machine,hw/xen/Makefile.objs +2
-1@@ -1,6 +1,7 @@ # xen backend driver support -common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o +common-obj-y += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_load_rom.o +obj-$(call $(lnot, $(CONFIG_XEN_PCI_PASSTHROUGH))) += xen_pt_stub.ohw/xen/xen_pt.c +11
-1@@ -65,7 +65,17 @@#include "qemu/range.h" #include "exec/address-spaces.h" -bool has_igd_gfx_passthru; +static bool has_igd_gfx_passthru; + +bool xen_igd_gfx_pt_enabled (void ) +{ +return has_igd_gfx_passthru; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +}#define XEN_PT_NR_IRQS (256)static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS ] = {0 };hw/xen/xen_pt.h +4
-2@@ -5,6 +5,9 @@#include "hw/pci/pci.h" #include "xen-host-pci-device.h" +bool xen_igd_gfx_pt_enabled (void ); +void xen_igd_gfx_pt_set (bool value,Error **errp); + void xen_pt_log(const PCIDevice *d, const char *f, ...) GCC_FMT_ATTR(2, 3); #define XEN_PT_ERR(d, _f, _a...) xen_pt_log(d, "%s: Error: "_f, __func__, ##_a)@@ -322,10 +325,9 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); -extern bool has_igd_gfx_passthru;static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (has_igd_gfx_passthru +return (xen_igd_gfx_pt_enabled () && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }int xen_pt_register_vga_regions (XenHostPCIDevice *dev);hw/xen/xen_pt_stub.c new file +22
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2020 Citrix Systems UK Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/xen/xen_pt.h" +#include "qapi/error.h" + +bool xen_igd_gfx_pt_enabled (void ) +{ +return false; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ +if (value) { +error_setg (errp,"Xen PCI passthrough support not built in" ); + } +}Signature · 1 line
2.26.2
Signature · 1 line
Anthony PERARD
Quoted 4 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Anthony PERARD
Sent: 02 July 2020 15:26
To: Paul Durrant <[email protected]>
Emails to this address are probably going to /dev/null by now :-)
Quoted 28 lines
Cc: [email protected]; Roger Pau Monné <[email protected]>
Subject: Re: [PATCH v5] xen: fix build without pci passthroughQuoted 16 lines · Paolo Bonzini
From: Anthony PERARD <[email protected]>
Xen PCI passthrough support may not be available and thus the global variable "
has_igd_gfx_passthru" might be compiled out. Common code should not access it in that case.Unfortunately, we can't use
CONFIG_XEN_PCI_PASSTHROUGHdirectly inxen-common.cso this patch instead move access to thehas_igd_gfx_passthruvariable via function and those functions are also implemented as stubs. The stubs will be used when QEMU is built without passthrough support.Now, when one will want to enable igd-passthru via the -machine property, they will get an error message if QEMU is built without passthrough support.
Quoted 5 lines
Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Reported-by Roger Pau Monné <[email protected]>Signed-off-by Anthony PERARD <[email protected]>Message-Id: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>Hi Paul,
Quoted 8 lines
Can I backport this patch to qemu-xen-4.14? It allows to build qemu without pci passthrough support which seems to be important for FreeBSD as PT with QEMU is only available on Linux.
(There's a fix to the patch that I would backport as well. "xen:
Actually fix build without passthrough")Thanks.
I have no objection to make this fix for 4.14.
Cheers,
Paul
Quoted 156 lines
Quoted 62 lines
--- accel/xen/xen-all.c | 4 ++-- hw/Makefile.objs | 2 +- hw/i386/pc_piix.c | 2 +- hw/xen/Makefile.objs | 3 ++- hw/xen/xen_pt.c | 12 +++++++++++- hw/xen/xen_pt.h | 6 ++++-- hw/xen/xen_pt_stub.c | 22 ++++++++++++++++++++++ 7 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 hw/xen/xen_pt_stub.caccel/xen/xen-all.c +2
-2@@ -137,12 +137,12 @@ static void xen_change_state_handler(void *opaque, int running,static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) { -return has_igd_gfx_passthru; +return xen_igd_gfx_pt_enabled (); }static void xen_set_igd_gfx_passthru (Object *obj,bool value,Error **errp) { - has_igd_gfx_passthru = value; +xen_igd_gfx_pt_set (value, errp); }static void xen_setup_post (MachineState *ms,AccelState *accel)hw/Makefile.objs +1
-1@@ -35,7 +35,7 @@ devices-dirs-y += usb/ devices-dirs-$(CONFIG_VFIO) += vfio/ devices-dirs-y += virtio/ devices-dirs-y += watchdog/ -devices-dirs-y += xen/ +devices-dirs-$(CONFIG_XEN) += xen/ devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_NUBUS) += nubus/ devices-dirs-y += semihosting/hw/i386/pc_piix.c +1
-1@@ -377,7 +377,7 @@ static void pc_init_isa(MachineState *machine)#ifdef CONFIG_XEN static void pc_xen_hvm_init_pci (MachineState *machine) { -const char *pci_type = has_igd_gfx_passthru ? +const char *pci_type =xen_igd_gfx_pt_enabled () ?TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE :TYPE_I440FX_PCI_DEVICE ; pc_init1(machine,hw/xen/Makefile.objs +0
-0hw/xen/Makefile.objs line 2
Quoted 2 lines
hw/xen/Makefile.objs +0
-1@@ -1,6 +1,7 @@ # xen backend driver support -common-obj-$(CONFIG_XEN) += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o
hw/xen/Makefile.objs line 2
Quoted 1 line
hw/xen/Makefile.objs +1
-0+common-obj-y += xen-legacy-backend.o xen_devconfig.o xen_pvdev.o xen-bus.o xen-bus-helper.o xen-backend.o
Quoted 83 lines
hw/xen/Makefile.objs +1
-0obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_graphics.o xen_pt_msi.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_load_rom.o +obj-$(call $(lnot, $(CONFIG_XEN_PCI_PASSTHROUGH))) += xen_pt_stub.ohw/xen/xen_pt.c +11
-1@@ -65,7 +65,17 @@#include "qemu/range.h" #include "exec/address-spaces.h" -bool has_igd_gfx_passthru; +static bool has_igd_gfx_passthru; + +bool xen_igd_gfx_pt_enabled (void ) +{ +return has_igd_gfx_passthru; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ + has_igd_gfx_passthru = value; +}#define XEN_PT_NR_IRQS (256)static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS ] = {0 };hw/xen/xen_pt.h +4
-2@@ -5,6 +5,9 @@#include "hw/pci/pci.h" #include "xen-host-pci-device.h" +bool xen_igd_gfx_pt_enabled (void ); +void xen_igd_gfx_pt_set (bool value,Error **errp); + void xen_pt_log(const PCIDevice *d, const char *f, ...) GCC_FMT_ATTR(2, 3); #define XEN_PT_ERR(d, _f, _a...) xen_pt_log(d, "%s: Error: "_f, __func__, ##_a)@@ -322,10 +325,9 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); -extern bool has_igd_gfx_passthru;static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { -return (has_igd_gfx_passthru +return (xen_igd_gfx_pt_enabled () && ((dev->class_code >>0x8 ) ==PCI_CLASS_DISPLAY_VGA )); }int xen_pt_register_vga_regions (XenHostPCIDevice *dev);hw/xen/xen_pt_stub.c new file +22
-1@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2020 Citrix Systems UK Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "hw/xen/xen_pt.h" +#include "qapi/error.h" + +bool xen_igd_gfx_pt_enabled (void ) +{ +return false; +} + +void xen_igd_gfx_pt_set (bool value,Error **errp) +{ +if (value) { +error_setg (errp,"Xen PCI passthrough support not built in" ); + } +} --Quoted 3 lines
2.26.2
--
Anthony PERARD