Don't treat all sysbus devices as hotpluggable
cover Don't treat all sysbus devices as hotpluggable
On the two machines which have the "platform bus" (ppc e500 and arm virt) we currently treat all TYPE_SYS_BUS_DEVICE devices as being hotpluggable in the device callbacks, and try to plug those devices into the platform bus. This is far too broad, because only a handful of devices are actually valid to plug into the platform bus. Moreover, if a device which is pluggable for some other reason (like a PCI device) happens to use a sysbus device internally as part of its implementation, the hotplug callback will incorrectly grab that sysbus device, probably resulting in an assertion failure.
Mostly PCI devices don't use sysbus devices internally, so the only case we've encountered so far is the not-valid-anyway
qemu-system-ppc64 -M ppce500 -device macio-oldworld
but we might create more in future.
This series restricts hotpluggability of sysbus devices on these platforms to those devices which are on the dynamic sysbus whitelist (which we were maintaining anyway). With it, the above ppc commandline stops asserting and instead fails cleanly with
qemu-system-ppc64: Device heathrow is not supported by this machine yet.
Patch 1 is an API doc improvement while I was in the header file anyway.
thanks
-- PMM
Peter Maydell (4):
include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev()
machine: Provide a function to check the dynamic sysbus whitelist hw/arm/virt: Only try to add valid dynamic sysbus devices to platform
bus
hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to
platform bus
include/hw/boards.h | 38 ++++++++++++++++++++++++++++++++++++++ hw/arm/virt.c | 8 ++++++-- hw/core/machine.c | 21 ++++++++++++++++----- hw/ppc/e500plat.c | 8 ++++++-- 4 files changed, 66 insertions(+), 9 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/4 include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev()
The function machine_class_allow_dynamic_sysbus_dev() is currently undocumented; add a doc comment.
--- include/hw/boards.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/hw/boards.h +14 -0
@@ -36,7 +36,21 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp); +/** +* machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices +* @mc: Machine class +* @type: type to whitelist (should be a subtype of TYPE_SYS_BUS_DEVICE) +* +* Add the QOM type @type to the list of devices of which are subtypes +* of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically +* created (eg by the user on the command line with -device). +* By default if the user tries to create any devices on the command line +* that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message; +* for the special cases which are permitted for this machine model, the +* machine model class init code must call this function to whitelist them. +*/ void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type); +/* * Checks that backend isn't used, preps it for exclusive usage and * returns migratable MemoryRegion provided by backend.
Signature · 1 line
2.20.1
Re: [PATCH for-6.0 1/4] include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev()
Hi Peter,
Quoted 13 lines · Peter Maydell
The function
machine_class_allow_dynamic_sysbus_dev()is currently undocumented; add a doc comment.Signed-off-by Peter Maydell <[email protected]>--- include/hw/boards.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/hw/boards.h +0
-0
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 40
Quoted 5 lines
include/hw/boards.h +2
-0@@ -36,7 +36,21 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp); +/** +* machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
nit: s/of valid devices/of dynamically instantiable sysbus devices ?
Quoted 7 lines
include/hw/boards.h +6
-0+* @mc: Machine class +* @type: type to whitelist (should be a subtype of TYPE_SYS_BUS_DEVICE) +* +* Add the QOM type @type to the list of devices of which are subtypes +* of TYPE_SYS_BUS_DEVICE but which are still permitted to be dynamically +* created (eg by the user on the command line with -device).
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 56
Quoted 10 lines
include/hw/boards.h +6
-0+* By default if the user tries to create any devices on the command line +* that are subtypes of TYPE_SYS_BUS_DEVICE they will get an error message; +* for the special cases which are permitted for this machine model, the +* machine model class init code must call this function to whitelist them. +*/ void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type); +/* * Checks that backend isn't used, preps it for exclusive usage and * returns migratable MemoryRegion provided by backend.
Besides
Thanks
Eric
Re: [PATCH for-6.0 1/4] include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev()
Quoted 20 lines · Auger Eric
Hi Peter,
Quoted 16 lines · Peter Maydell
The function
machine_class_allow_dynamic_sysbus_dev()is currently undocumented; add a doc comment.Signed-off-by Peter Maydell <[email protected]>--- include/hw/boards.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/hw/boards.h +0
-0@@ -36,7 +36,21 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp);
Quoted 3 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 40
Quoted 2 lines
include/hw/boards.h +2
-0+/** +* machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices nit: s/of valid devices/of dynamically instantiable sysbus devices ?
I was trying to keep the summary line to be one line, which doesn't give much space for nuance with a function name this long...
-- PMM
Re: [PATCH for-6.0 1/4] include/hw/boards.h: Document machine_class_allow_dynamic_sysbus_dev()
Hi Peter,
Quoted 21 lines · Peter Maydell
Quoted 20 lines · Auger Eric
Hi Peter,
Quoted 16 lines · Peter Maydell
The function
machine_class_allow_dynamic_sysbus_dev()is currently undocumented; add a doc comment.Signed-off-by Peter Maydell <[email protected]>--- include/hw/boards.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/hw/boards.h +0
-0@@ -36,7 +36,21 @@ void machine_set_cpu_numa_node(MachineState *machine,const CpuInstanceProperties *props, Error **errp);
Quoted 6 lines
Quoted 3 lines
include/hw/boards.h void machine_set_cpu_numa_node(MachineState *machine, · line 40
Quoted 2 lines
include/hw/boards.h +2
-0+/** +* machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices nit: s/of valid devices/of dynamically instantiable sysbus devices ?
I was trying to keep the summary line to be one line, which doesn't give much space for nuance with a function name this long...
OK no worries
Thanks
Eric
Quoted 4 lines
-- PMM
PATCH 2/4 machine: Provide a function to check the dynamic sysbus whitelist
In reply to Peter MaydellProvide a new function dynamic_sysbus_dev_allowed() which checks the per-machine whitelist of dynamic sysbus devices and returns a boolean result indicating whether the device is whitelisted. We can use this in the implementation of validate_sysbus_device(), but we will also need it so that machine hotplug callbacks can validate devices rather than assuming that any sysbus device might be hotpluggable into the platform bus.
--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 21 ++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-)
include/hw/boards.h +24 -0
@@ -51,6 +51,30 @@ void machine_set_cpu_numa_node(MachineState *machine,*/ void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type); +/** +* device_is_dynamic_sysbus: test whether device is a dynamic sysbus device +* @mc: Machine class +* @dev: device to check +* +* Returns: true if @dev is a sysbus device on the machine's whitelist +* of dynamically pluggable sysbus devices; otherwise false. +* +* This function checks whether @dev is a valid dynamic sysbus device, +* by first confirming that it is a sysbus device and then checking it +* against the whitelist of permitted dynamic sysbus devices which has +* been set up by the machine using machine_class_allow_dynamic_sysbus_dev(). +* +* It is valid to call this with something that is not a subclass of +* TYPE_SYS_BUS_DEVICE; the function will return false in this case. +* This allows hotplug callback functions to be written as: +* if (device_is_dynamic_sysbus(mc, dev)) { +* handle dynamic sysbus case; +* } else if (some other kind of hotplug) { +* handle that; +* } +*/ +bool device_is_dynamic_sysbus (MachineClass *mc,DeviceState *dev); +/* * Checks that backend isn't used, preps it for exclusive usage and * returns migratable MemoryRegion provided by backend.
hw/core/machine.c +16 -5
@@ -529,20 +529,31 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type)); } -static void validate_sysbus_device (SysBusDevice *sbdev,void *opaque) +bool device_is_dynamic_sysbus (MachineClass *mc,DeviceState *dev) { -MachineState *machine = opaque; -MachineClass *mc =MACHINE_GET_CLASS (machine);bool allowed = false;strList *wl; +Object *obj =OBJECT (dev); + +if (!object_dynamic_cast (obj,TYPE_SYS_BUS_DEVICE )) { +return false; + }for (wl = mc->allowed_dynamic_sysbus_devices; !allowed && wl; wl = wl->next) { - allowed |= !!object_dynamic_cast (OBJECT (sbdev), wl->value); + allowed |= !!object_dynamic_cast (obj, wl->value); } -if (!allowed) { +return allowed; +} + +static void validate_sysbus_device (SysBusDevice *sbdev,void *opaque) +{ +MachineState *machine = opaque; +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (!device_is_dynamic_sysbus (mc,DEVICE (sbdev))) {error_report ("Option '-device %s' cannot be handled by this machine" ,object_class_get_name (object_get_class (OBJECT (sbdev))));exit (1 );
Signature · 1 line
2.20.1
Re: [PATCH for-6.0 2/4] machine: Provide a function to check the dynamic sysbus whitelist
Hi Peter,
Quoted 9 lines · Peter Maydell
Provide a new function
dynamic_sysbus_dev_allowed()which checks the per-machine whitelist of dynamic sysbus devices and returns a boolean result indicating whether the device is whitelisted. We can use this in the implementation ofvalidate_sysbus_device(), but we will also need it so that machine hotplug callbacks can validate devices rather than assuming that any sysbus device might be hotpluggable into the platform bus.Signed-off-by Peter Maydell <[email protected]>
Thanks
Eric
Quoted 82 lines
--- include/hw/boards.h | 24 ++++++++++++++++++++++++ hw/core/machine.c | 21 ++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-)include/hw/boards.h +24
-0@@ -51,6 +51,30 @@ void machine_set_cpu_numa_node(MachineState *machine,*/ void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type); +/** +* device_is_dynamic_sysbus: test whether device is a dynamic sysbus device +* @mc: Machine class +* @dev: device to check +* +* Returns: true if @dev is a sysbus device on the machine's whitelist +* of dynamically pluggable sysbus devices; otherwise false. +* +* This function checks whether @dev is a valid dynamic sysbus device, +* by first confirming that it is a sysbus device and then checking it +* against the whitelist of permitted dynamic sysbus devices which has +* been set up by the machine using machine_class_allow_dynamic_sysbus_dev(). +* +* It is valid to call this with something that is not a subclass of +* TYPE_SYS_BUS_DEVICE; the function will return false in this case. +* This allows hotplug callback functions to be written as: +* if (device_is_dynamic_sysbus(mc, dev)) { +* handle dynamic sysbus case; +* } else if (some other kind of hotplug) { +* handle that; +* } +*/ +bool device_is_dynamic_sysbus (MachineClass *mc,DeviceState *dev); +/* * Checks that backend isn't used, preps it for exclusive usage and * returns migratable MemoryRegion provided by backend. hw/core/machine.c +16
-5@@ -529,20 +529,31 @@ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)QAPI_LIST_PREPEND (mc->allowed_dynamic_sysbus_devices,g_strdup (type)); } -static void validate_sysbus_device (SysBusDevice *sbdev,void *opaque) +bool device_is_dynamic_sysbus (MachineClass *mc,DeviceState *dev) { -MachineState *machine = opaque; -MachineClass *mc =MACHINE_GET_CLASS (machine);bool allowed = false;strList *wl; +Object *obj =OBJECT (dev); + +if (!object_dynamic_cast (obj,TYPE_SYS_BUS_DEVICE )) { +return false; + }for (wl = mc->allowed_dynamic_sysbus_devices; !allowed && wl; wl = wl->next) { - allowed |= !!object_dynamic_cast (OBJECT (sbdev), wl->value); + allowed |= !!object_dynamic_cast (obj, wl->value); } -if (!allowed) { +return allowed; +} + +static void validate_sysbus_device (SysBusDevice *sbdev,void *opaque) +{ +MachineState *machine = opaque; +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (!device_is_dynamic_sysbus (mc,DEVICE (sbdev))) {error_report ("Option '-device %s' cannot be handled by this machine" ,object_class_get_name (object_get_class (OBJECT (sbdev))));exit (1 );
PATCH 3/4 hw/arm/virt: Only try to add valid dynamic sysbus devices to platform bus
In reply to Peter MaydellThe virt machine device plug callback currently calls platform_bus_link_device() for any sysbus device. This is overly broad, because platform_bus_link_device() will unconditionally grab the IRQs and MMIOs of the device it is passed, whether it was intended for the platform bus or not. Restrict hotpluggability of sysbus devices to only those devices on the dynamic sysbus whitelist.
We were mostly getting away with this because the board creates the platform bus as the last device it creates, and so the hotplug callback did not do anything for all the sysbus devices created by the board itself. However if the user plugged in a device which itself uses a sysbus device internally we would have mishandled this and probably asserted.
--- hw/arm/virt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/virt.c +6 -2
@@ -2443,7 +2443,9 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,VirtMachineState *vms =VIRT_MACHINE (hotplug_dev);if (vms->platform_bus_dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (vms); + +if (device_is_dynamic_sysbus (mc, dev)) {platform_bus_link_device (PLATFORM_BUS_DEVICE (vms->platform_bus_dev),SYS_BUS_DEVICE (dev)); }
@@ -2527,7 +2529,9 @@ static void virt_machine_device_unplug_cb(HotplugHandler *hotplug_dev,static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine,DeviceState *dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE ) || +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev) || (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ))) {return HOTPLUG_HANDLER (machine); }
Signature · 1 line
2.20.1
Re: [PATCH for-6.0 3/4] hw/arm/virt: Only try to add valid dynamic sysbus devices to platform bus
Hi Peter,
Quoted 7 lines · Peter Maydell
The virt machine device plug callback currently calls
platform_bus_link_device()for any sysbus device. This is overly broad, becauseplatform_bus_link_device()will unconditionally grab the IRQs and MMIOs of the device it is passed, whether it was intended for the platform bus or not. Restrict hotpluggability of sysbus devices to only those devices on the dynamic sysbus whitelist.
Quoted 8 lines
We were mostly getting away with this because the board creates the platform bus as the last device it creates, and so the hotplug callback did not do anything for all the sysbus devices created by the board itself. However if the user plugged in a device which itself uses a sysbus device internally we would have mishandled this and probably asserted.
Signed-off-by Peter Maydell <[email protected]>
Thanks
Eric
Quoted 31 lines
--- hw/arm/virt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/arm/virt.c +6
-2@@ -2443,7 +2443,9 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,VirtMachineState *vms =VIRT_MACHINE (hotplug_dev);if (vms->platform_bus_dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (vms); + +if (device_is_dynamic_sysbus (mc, dev)) {platform_bus_link_device (PLATFORM_BUS_DEVICE (vms->platform_bus_dev),SYS_BUS_DEVICE (dev)); }@@ -2527,7 +2529,9 @@ static void virt_machine_device_unplug_cb(HotplugHandler *hotplug_dev,static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine,DeviceState *dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE ) || +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev) || (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ))) {return HOTPLUG_HANDLER (machine); }
PATCH 4/4 hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to platform bus
In reply to Peter MaydellThe e500plat machine device plug callback currently calls platform_bus_link_device() for any sysbus device. This is overly broad, because platform_bus_link_device() will unconditionally grab the IRQs and MMIOs of the device it is passed, whether it was intended for the platform bus or not. Restrict hotpluggability of sysbus devices to only those devices on the dynamic sysbus whitelist.
We were mostly getting away with this because the board creates the platform bus as the last device it creates, and so the hotplug callback did not do anything for all the sysbus devices created by the board itself. However if the user plugged in a device which itself uses a sysbus device internally we would have mishandled this and probably asserted. An example of this is:
qemu-system-ppc64 -M ppce500 -device macio-oldworld
This isn't a sensible command because the macio-oldworld device is really specific to the 'g3beige' machine, but we now fail with a reasonable error message rather than asserting:
qemu-system-ppc64: Device heathrow is not supported by this machine yet.
--- hw/ppc/e500plat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/ppc/e500plat.c +6 -2
@@ -48,7 +48,9 @@ static void e500plat_machine_device_plug_cb(HotplugHandler *hotplug_dev,PPCE500MachineState *pms =PPCE500_MACHINE (hotplug_dev);if (pms->pbus_dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (pms); + +if (device_is_dynamic_sysbus (mc, dev)) {platform_bus_link_device (pms->pbus_dev,SYS_BUS_DEVICE (dev)); } }
@@ -58,7 +60,9 @@ staticHotplugHandler *e500plat_machine_get_hotpug_handler (MachineState *machine,DeviceState *dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev)) {return HOTPLUG_HANDLER (machine); }
Signature · 1 line
2.20.1
Re: [PATCH for-6.0 4/4] hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to platform bus
Quoted 15 lines · Peter Maydell
The e500plat machine device plug callback currently calls
platform_bus_link_device()for any sysbus device. This is overly broad, becauseplatform_bus_link_device()will unconditionally grab the IRQs and MMIOs of the device it is passed, whether it was intended for the platform bus or not. Restrict hotpluggability of sysbus devices to only those devices on the dynamic sysbus whitelist.We were mostly getting away with this because the board creates the platform bus as the last device it creates, and so the hotplug callback did not do anything for all the sysbus devices created by the board itself. However if the user plugged in a device which itself uses a sysbus device internally we would have mishandled this and probably asserted. An example of this is:
qemu-system-ppc64 -M ppce500 -device macio-oldworld
Quoted 6 lines
This isn't a sensible command because the macio-oldworld device is really specific to the 'g3beige' machine, but we now fail with a reasonable error message rather than asserting:
qemu-system-ppc64: Device heathrow is not supported by this machine yet.Signed-off-by Peter Maydell <[email protected]>
Quoted 30 lines
--- hw/ppc/e500plat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/ppc/e500plat.c +6
-2@@ -48,7 +48,9 @@ static void e500plat_machine_device_plug_cb(HotplugHandler *hotplug_dev,PPCE500MachineState *pms =PPCE500_MACHINE (hotplug_dev);if (pms->pbus_dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (pms); + +if (device_is_dynamic_sysbus (mc, dev)) {platform_bus_link_device (pms->pbus_dev,SYS_BUS_DEVICE (dev)); } }@@ -58,7 +60,9 @@ staticHotplugHandler *e500plat_machine_get_hotpug_handler (MachineState *machine,DeviceState *dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev)) {return HOTPLUG_HANDLER (machine); }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH for-6.0 4/4] hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to platform bus
In reply to Peter MaydellQuoted 15 lines · Peter Maydell
The e500plat machine device plug callback currently calls
platform_bus_link_device()for any sysbus device. This is overly broad, becauseplatform_bus_link_device()will unconditionally grab the IRQs and MMIOs of the device it is passed, whether it was intended for the platform bus or not. Restrict hotpluggability of sysbus devices to only those devices on the dynamic sysbus whitelist.We were mostly getting away with this because the board creates the platform bus as the last device it creates, and so the hotplug callback did not do anything for all the sysbus devices created by the board itself. However if the user plugged in a device which itself uses a sysbus device internally we would have mishandled this and probably asserted. An example of this is:
qemu-system-ppc64 -M ppce500 -device macio-oldworld
Quoted 6 lines
This isn't a sensible command because the macio-oldworld device is really specific to the 'g3beige' machine, but we now fail with a reasonable error message rather than asserting:
qemu-system-ppc64: Device heathrow is not supported by this machine yet.Signed-off-by Peter Maydell <[email protected]>
Eric
Quoted 31 lines
--- hw/ppc/e500plat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/ppc/e500plat.c +6
-2@@ -48,7 +48,9 @@ static void e500plat_machine_device_plug_cb(HotplugHandler *hotplug_dev,PPCE500MachineState *pms =PPCE500_MACHINE (hotplug_dev);if (pms->pbus_dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (pms); + +if (device_is_dynamic_sysbus (mc, dev)) {platform_bus_link_device (pms->pbus_dev,SYS_BUS_DEVICE (dev)); } }@@ -58,7 +60,9 @@ staticHotplugHandler *e500plat_machine_get_hotpug_handler (MachineState *machine,DeviceState *dev) { -if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev)) {return HOTPLUG_HANDLER (machine); }
Quoted 10 lines · Peter Maydell
On the two machines which have the "platform bus" (ppc e500 and arm virt) we currently treat all
TYPE_SYS_BUS_DEVICEdevices as being hotpluggable in the device callbacks, and try to plug those devices into the platform bus. This is far too broad, because only a handful of devices are actually valid to plug into the platform bus. Moreover, if a device which is pluggable for some other reason (like a PCI device) happens to use a sysbus device internally as part of its implementation, the hotplug callback will incorrectly grab that sysbus device, probably resulting in an assertion failure.
Quoted 7 lines
Mostly PCI devices don't use sysbus devices internally, so the only case we've encountered so far is the not-valid-anyway
qemu-system-ppc64 -M ppce500 -device macio-oldworld
but we might create more in future.This series restricts hotpluggability of sysbus devices on these platforms to those devices which are on the dynamic sysbus whitelist
s/whitelist/allowlist/g ?
Quoted 6 lines
include/hw/boards.h: Documentmachine_class_allow_dynamic_sysbus_dev()
machine: Provide a function to check the dynamic sysbus whitelist hw/arm/virt: Only try to add valid dynamic sysbus devices to platform
bus
hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to
platform bus
Otherwise,
r~
Quoted 35 lines · Peter Maydell
On the two machines which have the "platform bus" (ppc e500 and arm virt) we currently treat all
TYPE_SYS_BUS_DEVICEdevices as being hotpluggable in the device callbacks, and try to plug those devices into the platform bus. This is far too broad, because only a handful of devices are actually valid to plug into the platform bus. Moreover, if a device which is pluggable for some other reason (like a PCI device) happens to use a sysbus device internally as part of its implementation, the hotplug callback will incorrectly grab that sysbus device, probably resulting in an assertion failure.Mostly PCI devices don't use sysbus devices internally, so the only case we've encountered so far is the not-valid-anyway
qemu-system-ppc64 -M ppce500 -device macio-oldworld
but we might create more in future.This series restricts hotpluggability of sysbus devices on these platforms to those devices which are on the dynamic sysbus whitelist (which we were maintaining anyway). With it, the above ppc commandline stops asserting and instead fails cleanly with
qemu-system-ppc64: Device heathrow is not supported by this machine yet.Patch 1 is an API doc improvement while I was in the header file anyway.
thanks
-- PMMPeter Maydell (4):
include/hw/boards.h: Documentmachine_class_allow_dynamic_sysbus_dev()
machine: Provide a function to check the dynamic sysbus whitelist hw/arm/virt: Only try to add valid dynamic sysbus devices to platform
bus
hw/ppc/e500plat: Only try to add valid dynamic sysbus devices to
platform bus
Quoted 5 lines
include/hw/boards.h | 38 ++++++++++++++++++++++++++++++++++++++ hw/arm/virt.c | 8 ++++++-- hw/core/machine.c | 21 ++++++++++++++++----- hw/ppc/e500plat.c | 8 ++++++-- 4 files changed, 66 insertions(+), 9 deletions(-)
Looks good to me having been poking around the code earlier today so:
ATB,
Mark.
Quoted 10 lines · Peter Maydell
On the two machines which have the "platform bus" (ppc e500 and arm virt) we currently treat all
TYPE_SYS_BUS_DEVICEdevices as being hotpluggable in the device callbacks, and try to plug those devices into the platform bus. This is far too broad, because only a handful of devices are actually valid to plug into the platform bus. Moreover, if a device which is pluggable for some other reason (like a PCI device) happens to use a sysbus device internally as part of its implementation, the hotplug callback will incorrectly grab that sysbus device, probably resulting in an assertion failure.
I'm taking this into target-arm.next for 6.0 (with minor commit message and comment text tweaks to use 'allowlist' as suggested by rth).
thanks
-- PMM