Hi Peter, On 3/25/21 4:33 PM, Peter Maydell wrote: > The 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. > > Signed-off-by: Peter Maydell <peter.mayd...@linaro.org> Reviewed-by: Eric Auger <eric.au...@redhat.com>
Thanks Eric > --- > hw/arm/virt.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/hw/arm/virt.c b/hw/arm/virt.c > index aa2bbd14e09..8625152a735 100644 > --- a/hw/arm/virt.c > +++ b/hw/arm/virt.c > @@ -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); > } >