xen: fix build without pci passthrough
PATCH 1/1 xen: fix build without pci passthrough
has_igd_gfx_passthru is only available when QEMU is built with CONFIG_XEN_PCI_PASSTHROUGH, and hence shouldn't be used in common code without checking if it's available.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: [email protected]
--- hw/xen/xen-common.c | 4 ++++ hw/xen/xen_pt.h | 7 +++++++ 2 files changed, 11 insertions(+)
hw/xen/xen-common.c +4 -0
@@ -127,6 +127,7 @@ static void xen_change_state_handler(void *opaque, int running, } } +#ifdef CONFIG_XEN_PCI_PASSTHROUGH static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) {return has_igd_gfx_passthru;
@@ -136,6 +137,7 @@ static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) { has_igd_gfx_passthru = value; } +#endif static void xen_setup_post (MachineState *ms,AccelState *accel) {
@@ -197,11 +199,13 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); +#ifdef CONFIG_XEN_PCI_PASSTHROUGH object_class_property_add_bool (oc,"igd-passthru" , xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, &error_abort);object_class_property_set_description (oc,"igd-passthru" ,"Set on/off to enable/disable igd passthrou" , &error_abort); +#endif }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")
hw/xen/xen_pt.h +7 -0
@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H +#include "qemu/osdep.h" #include "hw/xen/xen_common.h" #include "hw/pci/pci.h" #include "xen-host-pci-device.h"
@@ -322,7 +323,13 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); + +#ifdef CONFIG_XEN_PCI_PASSTHROUGH extern bool has_igd_gfx_passthru; +#else +# define has_igd_gfx_passthru false +#endif +static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { return (has_igd_gfx_passthru
Signature · 1 line
2.26.2
Hi Roger,
Quoted 6 lines · Roger Pau Monne
has_igd_gfx_passthruis only available when QEMU is built withCONFIG_XEN_PCI_PASSTHROUGH, and hence shouldn't be used in common code without checking if it's available.Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Signed-off-by Roger Pau Monné <[email protected]>
See Kconfig fix suggested here:
https://www.mail-archive.com/[email protected]/msg61844.html
Quoted 71 lines
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: [email protected]--- hw/xen/xen-common.c | 4 ++++ hw/xen/xen_pt.h | 7 +++++++ 2 files changed, 11 insertions(+)hw/xen/xen-common.c +4
-0@@ -127,6 +127,7 @@ static void xen_change_state_handler(void *opaque, int running, } } +#ifdef CONFIG_XEN_PCI_PASSTHROUGH static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) {return has_igd_gfx_passthru;@@ -136,6 +137,7 @@ static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) { has_igd_gfx_passthru = value; } +#endif static void xen_setup_post (MachineState *ms,AccelState *accel) {@@ -197,11 +199,13 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); +#ifdef CONFIG_XEN_PCI_PASSTHROUGH object_class_property_add_bool (oc,"igd-passthru" , xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, &error_abort);object_class_property_set_description (oc,"igd-passthru" ,"Set on/off to enable/disable igd passthrou" , &error_abort); +#endif }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")hw/xen/xen_pt.h +7
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H +#include "qemu/osdep.h" #include "hw/xen/xen_common.h" #include "hw/pci/pci.h" #include "xen-host-pci-device.h" @@ -322,7 +323,13 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); + +#ifdef CONFIG_XEN_PCI_PASSTHROUGH extern bool has_igd_gfx_passthru; +#else +# define has_igd_gfx_passthru false +#endif +static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { return (has_igd_gfx_passthru
Quoted 7 lines · Philippe Mathieu-Daudé
Hi Roger,
Quoted 4 lines · Roger Pau Monne
has_igd_gfx_passthruis only available when QEMU is built withCONFIG_XEN_PCI_PASSTHROUGH, and hence shouldn't be used in common code without checking if it's available.
Quoted 5 lines
Quoted 2 lines
Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Signed-off-by Roger Pau Monné <[email protected]>See
Kconfigfix suggested here:
https://www.mail-archive.com/[email protected]/msg61844.html
Having it available on Kconfig is indeed fine, but this still needs some kind of configure checks AFAIK, as it's only available on Linux.
I'm certainly missing some context, but whether XEN_IGD_PASSTHROUGH gets defined on Kconfig or not shouldn't really matter for this patch, as we would still need to gate the code properly so it's not build when PCI passthrough (or whatever name the option has) is not enabled?
Thanks, Roger.
Ping?
Quoted 79 lines · Roger Pau Monne
has_igd_gfx_passthruis only available when QEMU is built withCONFIG_XEN_PCI_PASSTHROUGH, and hence shouldn't be used in common code without checking if it's available.Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: [email protected]--- hw/xen/xen-common.c | 4 ++++ hw/xen/xen_pt.h | 7 +++++++ 2 files changed, 11 insertions(+)hw/xen/xen-common.c +4
-0@@ -127,6 +127,7 @@ static void xen_change_state_handler(void *opaque, int running, } } +#ifdef CONFIG_XEN_PCI_PASSTHROUGH static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) {return has_igd_gfx_passthru;@@ -136,6 +137,7 @@ static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) { has_igd_gfx_passthru = value; } +#endif static void xen_setup_post (MachineState *ms,AccelState *accel) {@@ -197,11 +199,13 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); +#ifdef CONFIG_XEN_PCI_PASSTHROUGH object_class_property_add_bool (oc,"igd-passthru" , xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, &error_abort);object_class_property_set_description (oc,"igd-passthru" ,"Set on/off to enable/disable igd passthrou" , &error_abort); +#endif }#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")hw/xen/xen_pt.h +7
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H +#include "qemu/osdep.h" #include "hw/xen/xen_common.h" #include "hw/pci/pci.h" #include "xen-host-pci-device.h" @@ -322,7 +323,13 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); + +#ifdef CONFIG_XEN_PCI_PASSTHROUGH extern bool has_igd_gfx_passthru; +#else +# define has_igd_gfx_passthru false +#endif +static inline bool is_igd_vga_passthrough (XenHostPCIDevice *dev) { return (has_igd_gfx_passthruSignature · 1 line
2.26.2
Quoted 37 lines · Roger Pau Monne
has_igd_gfx_passthruis only available when QEMU is built withCONFIG_XEN_PCI_PASSTHROUGH, and hence shouldn't be used in common code without checking if it's available.Fixes 46472d82322d0 ('xen: convert "-machine igd-passthru" to an accelerator property')Signed-off-by Roger Pau Monné <[email protected]>---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: [email protected]--- hw/xen/xen-common.c | 4 ++++ hw/xen/xen_pt.h | 7 +++++++ 2 files changed, 11 insertions(+)hw/xen/xen-common.c +2
-0@@ -127,6 +127,7 @@ static void xen_change_state_handler(void *opaque, int running, } } +#ifdef CONFIG_XEN_PCI_PASSTHROUGH static bool xen_get_igd_gfx_passthru (Object *obj,Error **errp) {return has_igd_gfx_passthru;@@ -136,6 +137,7 @@ static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) { has_igd_gfx_passthru = value; } +#endif static void xen_setup_post (MachineState *ms,AccelState *accel) {
hw/xen/xen-common.c static void xen_accel_class_init(ObjectClass *oc, void *data) · line 208
Quoted 10 lines
hw/xen/xen-common.c +2
-0@@ -197,11 +199,13 @@ static void xen_accel_class_init(ObjectClass *oc, void *data)compat_props_add (ac->compat_props, compat,G_N_ELEMENTS (compat)); +#ifdef CONFIG_XEN_PCI_PASSTHROUGH object_class_property_add_bool (oc,"igd-passthru" , xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, &error_abort);object_class_property_set_description (oc,"igd-passthru" ,"Set on/off to enable/disable igd passthrou" , &error_abort); +#endif
It might not be a good idea to have the presence of class property depending on what is built-in. Instead, I think it would be better to return an error when QEMU is built without xen_pt and a user is trying to enable it. That can be done by calling by calling error_setg(errp, "nop") in xen_set_igd_gfx_passthru().
hw/xen/xen_pt.h line 4
Quoted 12 lines
hw/xen/xen-common.c +0
-0}#define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen")hw/xen/xen_pt.h +1
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H +#include "qemu/osdep.h"
Why do you need osdep?
hw/xen/xen_pt.h extern void *pci_assign_dev_load_option_rom(PCIDevice *dev, · line 331
Quoted 13 lines
hw/xen/xen_pt.h +5
-0#include "hw/xen/xen_common.h" #include "hw/pci/pci.h" #include "xen-host-pci-device.h" @@ -322,7 +323,13 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); + +#ifdef CONFIG_XEN_PCI_PASSTHROUGH extern bool has_igd_gfx_passthru; +#else +# define has_igd_gfx_passthru false +#endif
I don't quite like the use of define here. Could you introduce a function that return a bool instead? And defining that function in hw/xen/xen.h like xen_enabled() would be fine I think.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Roger Pau Monne
hw/xen/xen_pt.h +0
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H
Quoted 3 lines
hw/xen/xen_pt.h line 4
Quoted 1 line
hw/xen/xen_pt.h +1
-0+#include "qemu/osdep.h" Why do you need osdep?
For CONFIG_XEN_PCI_PASSTHROUGH IIRC.
Quoted 10 lines
Quoted 10 lines
hw/xen/xen_pt.h +2
-0#include "hw/xen/xen_common.h" #include "hw/pci/pci.h" #include "xen-host-pci-device.h" @@ -322,7 +323,13 @@ extern void *pci_assign_dev_load_option_rom(PCIDevice *dev,unsigned int domain, unsigned int bus, unsigned int slot, unsigned int function); + +#ifdef CONFIG_XEN_PCI_PASSTHROUGH
Quoted 8 lines
hw/xen/xen_pt.h extern void *pci_assign_dev_load_option_rom(PCIDevice *dev, · line 331
Quoted 4 lines
hw/xen/xen_pt.h +3
-0extern bool has_igd_gfx_passthru; +#else +# define has_igd_gfx_passthru false +#endif I don't quite like the use of define here. Could you introduce a function that return a bool instead? And defining that function in
hw/xen/xen.hlikexen_enabled()would be fine I think.
But has_igd_gfx_passthru is defined in xen_pt.c which is only compiled if CONFIG_XEN_PCI_PASSTHROUGH is defined, yet the variable is set from xen-common.c. I think the former is fine, an any attempt to set has_igd_gfx_passthru without CONFIG_XEN_PCI_PASSTHROUGH will result in a compile error which is easier to catch?
Thanks, Roger.
Quoted 11 lines · Roger Pau Monné
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Roger Pau Monne
hw/xen/xen_pt.h +0
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H
Quoted 5 lines
Quoted 3 lines
hw/xen/xen_pt.h line 4
Quoted 1 line
hw/xen/xen_pt.h +1
-0+#include "qemu/osdep.h" Why do you need osdep?
For
CONFIG_XEN_PCI_PASSTHROUGHIIRC.
All .c files should always include osdep as the first include in the file, and .h files should never include osdep (we note this in CODING_STYLE.rst).
If you added this #include to fix a compile issue that would suggest that there's a .c file somewhere that's missing the mandatory osdep include. I did a quick eyeball of all the files that include xen_pt.h, though, and none of them are missing the osdep include. So I think you should be able to simply drop the osdep include here. If that produces an error, let us know what fails and we can work out what's gone wrong.
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 11 lines · Roger Pau Monné
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Roger Pau Monne
hw/xen/xen_pt.h +0
-0@@ -1,6 +1,7 @@#ifndef XEN_PT_H #define XEN_PT_H Quoted 5 lines
Quoted 3 lines
hw/xen/xen_pt.h line 4
Quoted 1 line
hw/xen/xen_pt.h +1
-0+#include "qemu/osdep.h" Why do you need osdep?
For
CONFIG_XEN_PCI_PASSTHROUGHIIRC.All .c files should always include osdep as the first include in the file, and .h files should never include osdep (we note this in
CODING_STYLE.rst).
Quoted 7 lines
If you added this #include to fix a compile issue that would suggest that there's a .c file somewhere that's missing the mandatory osdep include. I did a quick eyeball of all the files that include
xen_pt.h, though, and none of them are missing the osdep include. So I think you should be able to simply drop the osdep include here. If that produces an error, let us know what fails and we can work out what's gone wrong.
My bad, didn't know about this rule and just looked up where CONFIG_XEN_PCI_PASSTHROUGH was defined in order to include it. Will remove in v2.
Thanks, Roger.