arm: isolate and clean up dtb generation
v3 cover arm: isolate and clean up dtb generation
Changelog v2->v3:
* drop already merged patches
'arm: always start from first_cpu when registering loader cpu reset callback' 'ppc: e500: switch E500 based machines to full machine definition'
* add small not related cleanup
'arm: boot: set boot_info starting from first_cpu'
* add extra suggested patch
'make sure that we aren't overwriting mc->get_hotplug_handler by accident'
* make sure that dtb_limit initialized to 0
* drop stale comment
* drop not needed line movement
* drop not needed extra new line
Changelog v1->v2:
* drop "arm: reuse arm_boot_address_space() in armv7m_load_kernel()"
* move "arm: always start from first_cpu when registering loader cpu reset callback" at the begigning of series and rebase
* add "ppc: e500: switch E500 based machines to full machine definition" and rebase 4/5 on top of it
* fixup typo in virt_machine_get_hotpug_handler() name
* add doc comment to skip_dtb_autoload field
* 1-2/5 are queued in respective arm/ppc trees and are included for series completness so it would be easier to test, I expect series to go through arm tree
While working on cpu hotplug for mach-virt, I've noticed that DTB is generated incrementally across whole machvirt_init(). While it's fine for machines with static DTB, it won't really work in case of cpu hotplug and followed up reset since machine will load old DTB that doesn't account for hotplugged CPUs.
So I've set on a quest to consolidate DTB generation and make it reentrant so that on reset guest would see update DTB.
It's preliminary series which makes possible to call load_dtb() later outside of arm_load_kernel() and in process of it drops several machine_done notifiers, that were introduced to make plaform-bus-devices work. Hopefully it makes code easier to follow. It replaces machine_done notifiers with device hotplug framework to allow for dynamic sysbus devices mapping at the moment they are created instead of waiting for machine_done time and trying to juggle with notifiers order to do initialization in propper order.
Mostly 'make check' tested +
manually with "ppce500" machine type and eTSEC device (eTSEC is still initialized with the same IRQs as before series)
Igor Mammedov (5):
pc: simplify MachineClass::get_hotplug_handler handling
platform-bus-device: use device plug callback instead of machine_done
notifier
arm/boot: split load_dtb() from arm_load_kernel()
arm: boot: set boot_info starting from first_cpu
make sure that we aren't overwriting mc->get_hotplug_handler by
accident
hw/ppc/e500.h | 5 +++ include/hw/arm/arm.h | 45 +++++++++++++++------ include/hw/arm/sysbus-fdt.h | 37 ++++------------- include/hw/arm/virt.h | 1 + include/hw/i386/pc.h | 8 ---- include/hw/platform-bus.h | 4 +- hw/arm/boot.c | 74 ++++++++++------------------------ hw/arm/sysbus-fdt.c | 64 ++---------------------------- hw/arm/virt.c | 96 +++++++++++++++++++++++++++++---------------- hw/core/platform-bus.c | 29 +++----------- hw/i386/pc.c | 7 +--- hw/ppc/e500.c | 38 ++++++++---------- hw/ppc/e500plat.c | 32 +++++++++++++++ hw/ppc/spapr.c | 1 + hw/s390x/s390-virtio-ccw.c | 1 + 15 files changed, 193 insertions(+), 249 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/5 pc: simplify MachineClass::get_hotplug_handler handling
By default MachineClass::get_hotplug_handler is NULL and concrete board should set it to it's own handler.
Considering there isn't any default handler, drop saving empty MachineClass::get_hotplug_handler in child class and make PC code consistent with spapr/s390x boards.
We can bring this back when actual usecase surfaces and do it consistently across boards that use get_hotplug_handler().
--- include/hw/i386/pc.h | 8 -------- hw/i386/pc.c | 6 +----- 2 files changed, 1 insertion(+), 13 deletions(-)
include/hw/i386/pc.h +0 -8
@@ -84,10 +84,6 @@ struct PCMachineState {/** * PCMachineClass: * -* Methods: -* -* @get_hotplug_handler: pointer to parent class callback @get_hotplug_handler -* * Compat fields: * * @enforce_aligned_dimm: check that DIMM's address/size is aligned by
@@ -107,10 +103,6 @@ struct PCMachineClass {/*< public >*/ -/* Methods: */ - HotplugHandler *(*get_hotplug_handler)(MachineState *machine, - DeviceState *dev); -/* Device configuration: */ bool pci_enabled;bool kvmclock_enabled;
hw/i386/pc.c +1 -5
@@ -2056,15 +2056,12 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,static HotplugHandler *pc_get_hotpug_handler (MachineState *machine,DeviceState *dev) { -PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (machine); -if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) ||object_dynamic_cast (OBJECT (dev),TYPE_CPU )) {return HOTPLUG_HANDLER (machine); } -return pcmc->get_hotplug_handler ? - pcmc->get_hotplug_handler (machine, dev) :NULL ; +return NULL ; } static void
@@ -2344,7 +2341,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data)HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);NMIClass *nc =NMI_CLASS (oc); - pcmc->get_hotplug_handler = mc->get_hotplug_handler; pcmc->pci_enabled = true; pcmc->has_acpi_build = true; pcmc->rsdp_in_ram = true;
Signature · 1 line
2.7.4
PATCH v3 2/5 platform-bus-device: use device plug callback instead of machine_done notifier
In reply to Igor Mammedovplatform-bus were using machine_done notifier to get and map (assign irq/mmio resources) dynamically added sysbus devices after all '-device' options had been processed. That however creates non obvious dependencies on ordering of machine_done notifiers and requires carefull line juggling to keep it working. For example see comment above create_platform_bus() and 'straitforward' arm_load_kernel() had to converted to machine_done notifier and that lead to yet another machine_done notifier to keep it working arm_register_platform_bus_fdt_creator().
Instead of hiding resource assignment in platform-bus-device to magically initialize sysbus devices, use device plug callback and assign resources explicitly at board level at the moment each -device option is being processed.
That adds a bunch of machine declaration boiler plate to e500plat board, similar to ARM/x86 but gets rid of hidden machine_done notifier and would allow to remove the dependent notifiers in ARM code simplifying it and making code flow easier to follow.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
v2:
- don't save original MachineClass::get_hotplug_handler, just overwrite it. (there isn't any use case for chaining get_hotplug_handler() yet,
so keep things simple for now) (David Gibson <[email protected]>)
- s/hotpug/hotplug/ (Peter Maydell <[email protected]>)
- ppc: rebase on top (ppc: e500: switch E500 based machines to full machine definition)
v3:
- in virt_machine_device_plug_cb() check for vms->platform_bus_dev != NULL first before doing more expensive cast check to SYS_BUS_DEVICE
(Philippe Mathieu-Daudé <[email protected]>)
--- hw/ppc/e500.h | 5 +++++ include/hw/arm/virt.h | 1 + include/hw/platform-bus.h | 4 ++-- hw/arm/sysbus-fdt.c | 3 --- hw/arm/virt.c | 31 +++++++++++++++++++++++++++++++ hw/core/platform-bus.c | 29 +++++------------------------ hw/ppc/e500.c | 38 +++++++++++++++++--------------------- hw/ppc/e500plat.c | 31 +++++++++++++++++++++++++++++++ 8 files changed, 92 insertions(+), 50 deletions(-)
hw/ppc/e500.h +5 -0
@@ -2,11 +2,16 @@#define PPCE500_H #include "hw/boards.h" +#include "hw/platform-bus.h" typedef struct PPCE500MachineState {/*< private >*/ MachineState parent_obj; +/* points to instance of TYPE_PLATFORM_BUS_DEVICE if +* board supports dynamic sysbus devices +*/ +PlatformBusDevice *pbus_dev; }PPCE500MachineState ; typedef struct PPCE500MachineClass {
include/hw/arm/virt.h +1 -0
@@ -91,6 +91,7 @@ typedef struct { typedef struct { MachineState parent; Notifier machine_done; + DeviceState *platform_bus_dev; FWCfgState *fw_cfg; bool secure; bool highmem;
include/hw/platform-bus.h +2 -2
@@ -37,8 +37,6 @@ typedef struct PlatformBusDevice PlatformBusDevice;struct PlatformBusDevice {/*< private >*/ SysBusDevice parent_obj; -Notifier notifier; -bool done_gathering;/*< public >*/ uint32_t mmio_size;
@@ -54,4 +52,6 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus, SysBusDevice *sbdev,hwaddr platform_bus_get_mmio_addr (PlatformBusDevice *pbus,SysBusDevice *sbdev,int n); +void platform_bus_link_device (PlatformBusDevice *pbus,SysBusDevice *sbdev); +#endif /* HW_PLATFORM_BUS_H */
hw/arm/sysbus-fdt.c +0 -3
@@ -506,9 +506,6 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatformBusFDTParams *fdt_params) dev =qdev_find_recursive (sysbus_get_default (),TYPE_PLATFORM_BUS_DEVICE ); pbus =PLATFORM_BUS_DEVICE (dev); -/* We can only create dt nodes for dynamic devices when they're ready */ -assert (pbus->done_gathering); -PlatformBusFDTData data = { .fdt = fdt, .irq_start = irq_start,
hw/arm/virt.c +31 -0
@@ -1087,6 +1087,7 @@ static void create_platform_bus(VirtMachineState *vms, qemu_irq *pic)qdev_prop_set_uint32 (dev,"mmio_size" , platform_bus_params.platform_bus_size);qdev_init_nofail (dev); + vms->platform_bus_dev = dev; s =SYS_BUS_DEVICE (dev);for (i =0 ; i < platform_bus_params.platform_bus_num_irqs; i++) {
@@ -1536,9 +1537,33 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)return ms->possible_cpus; } +static void virt_machine_device_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (hotplug_dev); + +if (vms->platform_bus_dev) { +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +platform_bus_link_device (PLATFORM_BUS_DEVICE (vms->platform_bus_dev), +SYS_BUS_DEVICE (dev)); + } + } +} + +static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine, +DeviceState *dev) +{ +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +return HOTPLUG_HANDLER (machine); + } + +return NULL ; +} +static void virt_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); mc->init = machvirt_init;/* Start max_cpus at the maximum QEMU supports. We'll further restrict
@@ -1557,6 +1582,8 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; + mc->get_hotplug_handler = virt_machine_get_hotplug_handler; + hc->plug = virt_machine_device_plug_cb; }static const TypeInfo virt_machine_info = {
@@ -1566,6 +1593,10 @@ static const TypeInfo virt_machine_info = { .instance_size = sizeof(VirtMachineState), .class_size = sizeof(VirtMachineClass), .class_init = virt_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, };static void machvirt_machine_init (void )
hw/core/platform-bus.c +5 -24
@@ -103,7 +103,6 @@ static void plaform_bus_refresh_irqs(PlatformBusDevice *pbus) {bitmap_zero (pbus->used_irqs, pbus->num_irqs);foreach_dynamic_sysbus_device (platform_bus_count_irqs, pbus); - pbus->done_gathering = true; } static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,
@@ -163,12 +162,11 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, }/* -* For each sysbus device, look for unassigned IRQ lines as well as -* unassociated MMIO regions. Connect them to the platform bus if available. +* Look for unassigned IRQ lines as well as unassociated MMIO regions. +* Connect them to the platform bus if available. */ -static void link_sysbus_device (SysBusDevice *sbdev,void *opaque) +void platform_bus_link_device (PlatformBusDevice *pbus,SysBusDevice *sbdev) { -PlatformBusDevice *pbus = opaque;int i;for (i =0 ;sysbus_has_irq (sbdev, i); i++) {
@@ -180,19 +178,6 @@ static void link_sysbus_device(SysBusDevice *sbdev, void *opaque) } } -static void platform_bus_init_notify (Notifier *notifier,void *data) -{ -PlatformBusDevice *pb =container_of (notifier, PlatformBusDevice, notifier); - -/* -* Generate a bitmap of used IRQ lines, as the user might have specified -* them on the command line. -*/ -plaform_bus_refresh_irqs (pb); - -foreach_dynamic_sysbus_device (link_sysbus_device, pb); -} -static void platform_bus_realize (DeviceState *dev,Error **errp) {PlatformBusDevice *pbus;
@@ -211,12 +196,8 @@ static void platform_bus_realize(DeviceState *dev, Error **errp)sysbus_init_irq (d, &pbus->irqs[i]); } -/* -* Register notifier that allows us to gather dangling devices once the -* machine is completely assembled -*/ - pbus->notifier.notify = platform_bus_init_notify; -qemu_add_machine_init_done_notifier (&pbus->notifier); +/* some devices might be initialized before so update used IRQs map */ +plaform_bus_refresh_irqs (pbus); }static Property platform_bus_properties[] = {
hw/ppc/e500.c +17 -21
@@ -221,16 +221,15 @@ static void sysbus_device_create_devtree(SysBusDevice *sbdev, void *opaque) } } -static void platform_bus_create_devtree (const PPCE500MachineClass *pmc, +static void platform_bus_create_devtree (PPCE500MachineState *pms,void *fdt,const char *mpic) { +const PPCE500MachineClass *pmc =PPCE500_MACHINE_GET_CLASS (pms);gchar *node =g_strdup_printf ("/platform@%" PRIx64, pmc->platform_bus_base);const char platcomp[] ="qemu,platform\0simple-bus" ;uint64_t addr = pmc->platform_bus_base;uint64_t size = pmc->platform_bus_size;int irq_start = pmc->platform_bus_first_irq; -PlatformBusDevice *pbus; -DeviceState *dev;/* Create a /platform node that we can put all devices into */
@@ -245,22 +244,17 @@ static void platform_bus_create_devtree(const PPCE500MachineClass *pmc,qemu_fdt_setprop_phandle (fdt, node,"interrupt-parent" , mpic); - dev =qdev_find_recursive (sysbus_get_default (),TYPE_PLATFORM_BUS_DEVICE ); - pbus =PLATFORM_BUS_DEVICE (dev); - -/* We can only create dt nodes for dynamic devices when they're ready */ -if (pbus->done_gathering) { -PlatformDevtreeData data = { - .fdt = fdt, - .mpic = mpic, - .irq_start = irq_start, - .node = node, - .pbus = pbus, - }; +/* Create dt nodes for dynamic devices */ +PlatformDevtreeData data = { + .fdt = fdt, + .mpic = mpic, + .irq_start = irq_start, + .node = node, + .pbus = pms->pbus_dev, + }; -/* Loop through all dynamic sysbus devices and create nodes for them */ -foreach_dynamic_sysbus_device (sysbus_device_create_devtree, &data); - } +/* Loop through all dynamic sysbus devices and create nodes for them */ +foreach_dynamic_sysbus_device (sysbus_device_create_devtree, &data);g_free (node); }
@@ -527,8 +521,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,create_dt_mpc8xxx_gpio (fdt, soc, mpic); } -if (pmc->has_platform_bus) { -platform_bus_create_devtree (pmc, fdt, mpic); +if (pms->pbus_dev) { +platform_bus_create_devtree (pms, fdt, mpic); } pmc->fixup_devtree (fdt);
@@ -946,8 +940,9 @@ void ppce500_init(MachineState *machine)qdev_prop_set_uint32 (dev,"num_irqs" , pmc->platform_bus_num_irqs);qdev_prop_set_uint32 (dev,"mmio_size" , pmc->platform_bus_size);qdev_init_nofail (dev); - s =SYS_BUS_DEVICE (dev); + pms->pbus_dev =PLATFORM_BUS_DEVICE (dev); + s =SYS_BUS_DEVICE (pms->pbus_dev);for (i =0 ; i < pmc->platform_bus_num_irqs; i++) {int irqn = pmc->platform_bus_first_irq + i;sysbus_connect_irq (s, i,qdev_get_gpio_in (mpicdev, irqn));
@@ -1090,6 +1085,7 @@ static const TypeInfo ppce500_info = { .name = TYPE_PPCE500_MACHINE, .parent = TYPE_MACHINE, .abstract = true, + .instance_size = sizeof(PPCE500MachineState), .class_size = sizeof(PPCE500MachineClass), };
hw/ppc/e500plat.c +31 -0
@@ -43,13 +43,40 @@ static void e500plat_init(MachineState *machine)ppce500_init (machine); } +static void e500plat_machine_device_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +PPCE500MachineState *pms =PPCE500_MACHINE (hotplug_dev); + +if (pms->pbus_dev) { +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +platform_bus_link_device (pms->pbus_dev,SYS_BUS_DEVICE (dev)); + } + } +} + +static +HotplugHandler *e500plat_machine_get_hotpug_handler (MachineState *machine, +DeviceState *dev) +{ +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +return HOTPLUG_HANDLER (machine); + } + +return NULL ; +} +#define TYPE_E500PLAT_MACHINE MACHINE_TYPE_NAME("ppce500")static void e500plat_machine_class_init (ObjectClass *oc,void *data) {PPCE500MachineClass *pmc =PPCE500_MACHINE_CLASS (oc); +HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc); + mc->get_hotplug_handler = e500plat_machine_get_hotpug_handler; + hc->plug = e500plat_machine_device_plug_cb; + pmc->pci_first_slot =0x1 ; pmc->pci_nr_slots =PCI_SLOT_MAX -1 ; pmc->fixup_devtree = e500plat_fixup_devtree;
@@ -77,6 +104,10 @@ static const TypeInfo e500plat_info = { .name = TYPE_E500PLAT_MACHINE, .parent = TYPE_PPCE500_MACHINE, .class_init = e500plat_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + } };static void e500plat_register_types (void )
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH v3 2/5] platform-bus-device: use device plug callback instead of machine_done notifier
Quoted 39 lines · Igor Mammedov
platform-bus were using
machine_donenotifier to get and map (assign irq/mmio resources) dynamically added sysbus devices after all '-device' options had been processed. That however creates non obvious dependencies on ordering ofmachine_donenotifiers and requires carefull line juggling to keep it working. For example see comment abovecreate_platform_bus()and 'straitforward'arm_load_kernel()had to converted tomachine_donenotifier and that lead to yet anothermachine_donenotifier to keep it workingarm_register_platform_bus_fdt_creator().Instead of hiding resource assignment in platform-bus-device to magically initialize sysbus devices, use device plug callback and assign resources explicitly at board level at the moment each -device option is being processed.
That adds a bunch of machine declaration boiler plate to e500plat board, similar to ARM/x86 but gets rid of hidden
machine_donenotifier and would allow to remove the dependent notifiers in ARM code simplifying it and making code flow easier to follow.Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]v2:
- don't save originalMachineClass::get_hotplug_handler, just overwrite it. (there isn't any use case for chainingget_hotplug_handler()yet,
so keep things simple for now) (David Gibson <[email protected]>)
- s/hotpug/hotplug/ (Peter Maydell <[email protected]>)
- ppc: rebase on top (ppc: e500: switch E500 based machines to full machine definition)
v3:
- invirt_machine_device_plug_cb()check forvms->platform_bus_dev!= NULL first before doing more expensive cast check toSYS_BUS_DEVICE
(Philippe Mathieu-Daudé <[email protected]>)
Quoted 10 lines
--- hw/ppc/e500.h | 5 +++++ include/hw/arm/virt.h | 1 + include/hw/platform-bus.h | 4 ++-- hw/arm/sysbus-fdt.c | 3 --- hw/arm/virt.c | 31 +++++++++++++++++++++++++++++++ hw/core/platform-bus.c | 29 +++++------------------------ hw/ppc/e500.c | 38 +++++++++++++++++--------------------- hw/ppc/e500plat.c | 31 +++++++++++++++++++++++++++++++ 8 files changed, 92 insertions(+), 50 deletions(-)
ppc parts
Quoted 339 lines
hw/ppc/e500.h +5
-0@@ -2,11 +2,16 @@#define PPCE500_H #include "hw/boards.h" +#include "hw/platform-bus.h" typedef struct PPCE500MachineState {/*< private >*/ MachineState parent_obj; +/* points to instance of TYPE_PLATFORM_BUS_DEVICE if +* board supports dynamic sysbus devices +*/ +PlatformBusDevice *pbus_dev; }PPCE500MachineState ; typedef struct PPCE500MachineClass {include/hw/arm/virt.h +1
-0@@ -91,6 +91,7 @@ typedef struct { typedef struct { MachineState parent; Notifier machine_done; + DeviceState *platform_bus_dev; FWCfgState *fw_cfg; bool secure; bool highmem;include/hw/platform-bus.h +2
-2@@ -37,8 +37,6 @@ typedef struct PlatformBusDevice PlatformBusDevice;struct PlatformBusDevice {/*< private >*/ SysBusDevice parent_obj; -Notifier notifier; -bool done_gathering;/*< public >*/ uint32_t mmio_size;@@ -54,4 +52,6 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus, SysBusDevice *sbdev,hwaddr platform_bus_get_mmio_addr (PlatformBusDevice *pbus,SysBusDevice *sbdev,int n); +void platform_bus_link_device (PlatformBusDevice *pbus,SysBusDevice *sbdev); +#endif /* HW_PLATFORM_BUS_H */ hw/arm/sysbus-fdt.c +0
-3@@ -506,9 +506,6 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatformBusFDTParams *fdt_params) dev =qdev_find_recursive (sysbus_get_default (),TYPE_PLATFORM_BUS_DEVICE ); pbus =PLATFORM_BUS_DEVICE (dev); -/* We can only create dt nodes for dynamic devices when they're ready */ -assert (pbus->done_gathering); -PlatformBusFDTData data = { .fdt = fdt, .irq_start = irq_start,hw/arm/virt.c +31
-0@@ -1087,6 +1087,7 @@ static void create_platform_bus(VirtMachineState *vms, qemu_irq *pic)qdev_prop_set_uint32 (dev,"mmio_size" , platform_bus_params.platform_bus_size);qdev_init_nofail (dev); + vms->platform_bus_dev = dev; s =SYS_BUS_DEVICE (dev);for (i =0 ; i < platform_bus_params.platform_bus_num_irqs; i++) {@@ -1536,9 +1537,33 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)return ms->possible_cpus; } +static void virt_machine_device_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +VirtMachineState *vms =VIRT_MACHINE (hotplug_dev); + +if (vms->platform_bus_dev) { +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +platform_bus_link_device (PLATFORM_BUS_DEVICE (vms->platform_bus_dev), +SYS_BUS_DEVICE (dev)); + } + } +} + +static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine, +DeviceState *dev) +{ +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +return HOTPLUG_HANDLER (machine); + } + +return NULL ; +} +static void virt_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc); +HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); mc->init = machvirt_init;/* Start max_cpus at the maximum QEMU supports. We'll further restrict @@ -1557,6 +1582,8 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; + mc->get_hotplug_handler = virt_machine_get_hotplug_handler; + hc->plug = virt_machine_device_plug_cb; }static const TypeInfo virt_machine_info = {@@ -1566,6 +1593,10 @@ static const TypeInfo virt_machine_info = { .instance_size = sizeof(VirtMachineState), .class_size = sizeof(VirtMachineClass), .class_init = virt_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, };static void machvirt_machine_init (void )hw/core/platform-bus.c +5
-24@@ -103,7 +103,6 @@ static void plaform_bus_refresh_irqs(PlatformBusDevice *pbus) {bitmap_zero (pbus->used_irqs, pbus->num_irqs);foreach_dynamic_sysbus_device (platform_bus_count_irqs, pbus); - pbus->done_gathering = true; } static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,@@ -163,12 +162,11 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev, }/* -* For each sysbus device, look for unassigned IRQ lines as well as -* unassociated MMIO regions. Connect them to the platform bus if available. +* Look for unassigned IRQ lines as well as unassociated MMIO regions. +* Connect them to the platform bus if available. */ -static void link_sysbus_device (SysBusDevice *sbdev,void *opaque) +void platform_bus_link_device (PlatformBusDevice *pbus,SysBusDevice *sbdev) { -PlatformBusDevice *pbus = opaque;int i;for (i =0 ;sysbus_has_irq (sbdev, i); i++) {@@ -180,19 +178,6 @@ static void link_sysbus_device(SysBusDevice *sbdev, void *opaque) } } -static void platform_bus_init_notify (Notifier *notifier,void *data) -{ -PlatformBusDevice *pb =container_of (notifier, PlatformBusDevice, notifier); - -/* -* Generate a bitmap of used IRQ lines, as the user might have specified -* them on the command line. -*/ -plaform_bus_refresh_irqs (pb); - -foreach_dynamic_sysbus_device (link_sysbus_device, pb); -} -static void platform_bus_realize (DeviceState *dev,Error **errp) {PlatformBusDevice *pbus;@@ -211,12 +196,8 @@ static void platform_bus_realize(DeviceState *dev, Error **errp)sysbus_init_irq (d, &pbus->irqs[i]); } -/* -* Register notifier that allows us to gather dangling devices once the -* machine is completely assembled -*/ - pbus->notifier.notify = platform_bus_init_notify; -qemu_add_machine_init_done_notifier (&pbus->notifier); +/* some devices might be initialized before so update used IRQs map */ +plaform_bus_refresh_irqs (pbus); }static Property platform_bus_properties[] = {hw/ppc/e500.c +17
-21@@ -221,16 +221,15 @@ static void sysbus_device_create_devtree(SysBusDevice *sbdev, void *opaque) } } -static void platform_bus_create_devtree (const PPCE500MachineClass *pmc, +static void platform_bus_create_devtree (PPCE500MachineState *pms,void *fdt,const char *mpic) { +const PPCE500MachineClass *pmc =PPCE500_MACHINE_GET_CLASS (pms);gchar *node =g_strdup_printf ("/platform@%" PRIx64, pmc->platform_bus_base);const char platcomp[] ="qemu,platform\0simple-bus" ;uint64_t addr = pmc->platform_bus_base;uint64_t size = pmc->platform_bus_size;int irq_start = pmc->platform_bus_first_irq; -PlatformBusDevice *pbus; -DeviceState *dev;/* Create a /platform node that we can put all devices into */ @@ -245,22 +244,17 @@ static void platform_bus_create_devtree(const PPCE500MachineClass *pmc,qemu_fdt_setprop_phandle (fdt, node,"interrupt-parent" , mpic); - dev =qdev_find_recursive (sysbus_get_default (),TYPE_PLATFORM_BUS_DEVICE ); - pbus =PLATFORM_BUS_DEVICE (dev); - -/* We can only create dt nodes for dynamic devices when they're ready */ -if (pbus->done_gathering) { -PlatformDevtreeData data = { - .fdt = fdt, - .mpic = mpic, - .irq_start = irq_start, - .node = node, - .pbus = pbus, - }; +/* Create dt nodes for dynamic devices */ +PlatformDevtreeData data = { + .fdt = fdt, + .mpic = mpic, + .irq_start = irq_start, + .node = node, + .pbus = pms->pbus_dev, + }; -/* Loop through all dynamic sysbus devices and create nodes for them */ -foreach_dynamic_sysbus_device (sysbus_device_create_devtree, &data); - } +/* Loop through all dynamic sysbus devices and create nodes for them */ +foreach_dynamic_sysbus_device (sysbus_device_create_devtree, &data);g_free (node); }@@ -527,8 +521,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,create_dt_mpc8xxx_gpio (fdt, soc, mpic); } -if (pmc->has_platform_bus) { -platform_bus_create_devtree (pmc, fdt, mpic); +if (pms->pbus_dev) { +platform_bus_create_devtree (pms, fdt, mpic); } pmc->fixup_devtree (fdt);@@ -946,8 +940,9 @@ void ppce500_init(MachineState *machine)qdev_prop_set_uint32 (dev,"num_irqs" , pmc->platform_bus_num_irqs);qdev_prop_set_uint32 (dev,"mmio_size" , pmc->platform_bus_size);qdev_init_nofail (dev); - s =SYS_BUS_DEVICE (dev); + pms->pbus_dev =PLATFORM_BUS_DEVICE (dev); + s =SYS_BUS_DEVICE (pms->pbus_dev);for (i =0 ; i < pmc->platform_bus_num_irqs; i++) {int irqn = pmc->platform_bus_first_irq + i;sysbus_connect_irq (s, i,qdev_get_gpio_in (mpicdev, irqn));@@ -1090,6 +1085,7 @@ static const TypeInfo ppce500_info = { .name = TYPE_PPCE500_MACHINE, .parent = TYPE_MACHINE, .abstract = true, + .instance_size = sizeof(PPCE500MachineState), .class_size = sizeof(PPCE500MachineClass), };hw/ppc/e500plat.c +31
-0@@ -43,13 +43,40 @@ static void e500plat_init(MachineState *machine)ppce500_init (machine); } +static void e500plat_machine_device_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +PPCE500MachineState *pms =PPCE500_MACHINE (hotplug_dev); + +if (pms->pbus_dev) { +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +platform_bus_link_device (pms->pbus_dev,SYS_BUS_DEVICE (dev)); + } + } +} + +static +HotplugHandler *e500plat_machine_get_hotpug_handler (MachineState *machine, +DeviceState *dev) +{ +if (object_dynamic_cast (OBJECT (dev),TYPE_SYS_BUS_DEVICE )) { +return HOTPLUG_HANDLER (machine); + } + +return NULL ; +} +#define TYPE_E500PLAT_MACHINE MACHINE_TYPE_NAME("ppce500")static void e500plat_machine_class_init (ObjectClass *oc,void *data) {PPCE500MachineClass *pmc =PPCE500_MACHINE_CLASS (oc); +HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc); + mc->get_hotplug_handler = e500plat_machine_get_hotpug_handler; + hc->plug = e500plat_machine_device_plug_cb; + pmc->pci_first_slot =0x1 ; pmc->pci_nr_slots =PCI_SLOT_MAX -1 ; pmc->fixup_devtree = e500plat_fixup_devtree;@@ -77,6 +104,10 @@ static const TypeInfo e500plat_info = { .name = TYPE_E500PLAT_MACHINE, .parent = TYPE_PPCE500_MACHINE, .class_init = e500plat_machine_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + } };static void e500plat_register_types (void )
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
PATCH v3 3/5 arm/boot: split load_dtb() from arm_load_kernel()
In reply to Igor Mammedovload_dtb() depends on arm_load_kernel() to figure out place in RAM where it should be loaded, but it's not required for arm_load_kernel() to work. Sometimes it's neccesary for devices added with -device/device_add to be enumerated in DTB as well, which's lead to [1] and surrounding commits to add 2 more machine_done notifiers with non obvious ordering to make dynamic sysbus devices initialization happen in the right order.
However instead of moving whole arm_load_kernel() in to machine_done, it's sufficient to move only load_dtb() into virt_machine_done() notifier and remove ArmLoadKernelNotifier/ /PlatformBusFDTNotifierParams notifiers, which saves us ~90LOC and simplifies code flow quite a bit.
Later would allow to consolidate DTB generation within one function for 'mach-virt' board and make it reentrant so it could generate updated DTB in device hotplug secenarios.
While at it rename load_dtb() to arm_load_dtb() since it's public now.
Add additional field skip_dtb_autoload to struct arm_boot_info to allow manual DTB load later in mach-virt and to avoid touching all other boards to explicitly call arm_load_dtb().
1) (ac9d32e hw/arm/boot: arm_load_kernel implemented as a machine init done notifier)
---
v3:
* (Andrew Jones <[email protected]>)
- make sure that dtb_limit initialized to 0
- drop stale comment
- drop not needed line movement
- drop not needed extra new line
v2:
- fix rebase conflicts due to dropped
[PATCH for-2.13 1/4] arm: reuse arm_boot_address_space() in armv7m_load_kernel() - add doc comment to new skip_dtb_autoload field --- include/hw/arm/arm.h | 45 +++++++++++++++++++++------- include/hw/arm/sysbus-fdt.h | 37 +++++------------------ hw/arm/boot.c | 72 ++++++++++++--------------------------------- hw/arm/sysbus-fdt.c | 61 +++----------------------------------- hw/arm/virt.c | 64 +++++++++++++++++++--------------------- 5 files changed, 94 insertions(+), 185 deletions(-)
include/hw/arm/arm.h +34 -11
@@ -39,15 +39,6 @@ DeviceState *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq,*/ void armv7m_load_kernel (ARMCPU *cpu,const char *kernel_filename,int mem_size); -/* -* struct used as a parameter of the arm_load_kernel machine init -* done notifier -*/ -typedef struct { -Notifier notifier;/* actual notifier */ -ARMCPU *cpu;/* handle to the first cpu object */ -}ArmLoadKernelNotifier ; -/* arm_boot.c */ struct arm_boot_info {uint64_t ram_size;
@@ -56,6 +47,13 @@ struct arm_boot_info {const char *initrd_filename;const char *dtb_filename;hwaddr loader_start; +hwaddr dtb_start; +hwaddr dtb_limit; +/* If set to True, arm_load_kernel() will not load DTB. +* It allows board to load DTB manually later. +* (default: False) +*/ +bool skip_dtb_autoload;/* multicore boards that use the default secondary core boot functions * need to put the address of the secondary boot code, the boot reg, * and the GIC address in the next 3 values, respectively. boards that
@@ -94,8 +92,6 @@ struct arm_boot_info {* the user it should implement this hook. */ void (*modify_dtb)(const struct arm_boot_info *info,void *fdt); -/* machine init done notifier executing arm_load_dtb */ -ArmLoadKernelNotifier load_kernel_notifier;/* Used internally by arm_boot.c */ int is_linux;hwaddr initrd_start;
@@ -143,6 +139,33 @@ struct arm_boot_info {*/ void arm_load_kernel (ARMCPU *cpu,struct arm_boot_info *info); +AddressSpace *arm_boot_address_space (ARMCPU *cpu, +const struct arm_boot_info *info); + +/** +* arm_load_dtb() - load a device tree binary image into memory +* @addr: the address to load the image at +* @binfo: struct describing the boot environment +* @addr_limit: upper limit of the available memory area at @addr +* @as: address space to load image to +* +* Load a device tree supplied by the machine or by the user with the +* '-dtb' command line option, and put it at offset @addr in target +* memory. +* +* If @addr_limit contains a meaningful value (i.e., it is strictly greater +* than @addr), the device tree is only loaded if its size does not exceed +* the limit. +* +* Returns: the size of the device tree image on success, +* 0 if the image size exceeds the limit, +* -1 on errors. +* +* Note: Must not be called unless have_dtb(binfo) is true. +*/ +int arm_load_dtb (hwaddr addr,const struct arm_boot_info *binfo, +hwaddr addr_limit,AddressSpace *as); +/* Write a secure board setup routine with a dummy handler for SMCs */ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, const struct arm_boot_info *info,
include/hw/arm/sysbus-fdt.h +7 -30
@@ -24,37 +24,14 @@#ifndef HW_ARM_SYSBUS_FDT_H #define HW_ARM_SYSBUS_FDT_H -#include "hw/arm/arm.h" -#include "qemu-common.h" -#include "hw/sysbus.h" - -/* -* struct that contains dimensioning parameters of the platform bus -*/ -typedef struct { -hwaddr platform_bus_base;/* start address of the bus */ -hwaddr platform_bus_size;/* size of the bus */ -int platform_bus_first_irq;/* first hwirq assigned to the bus */ -int platform_bus_num_irqs;/* number of hwirq assigned to the bus */ -}ARMPlatformBusSystemParams ; - -/* -* struct that contains all relevant info to build the fdt nodes of -* platform bus and attached dynamic sysbus devices -* in the future might be augmented with additional info -* such as PHY, CLK handles ... -*/ -typedef struct { -const ARMPlatformBusSystemParams *system_params; -struct arm_boot_info *binfo; -const char *intc;/* parent interrupt controller name */ -}ARMPlatformBusFDTParams ; +#include "exec/hwaddr.h" /** -* arm_register_platform_bus_fdt_creator - register a machine init done -* notifier that creates the device tree nodes of the platform bus and -* associated dynamic sysbus devices +* platform_bus_add_all_fdt_nodes - create all the platform bus nodes +* +* builds the parent platform bus node and all the nodes of dynamic +* sysbus devices attached to it. */ -void arm_register_platform_bus_fdt_creator (ARMPlatformBusFDTParams *fdt_params); - +void platform_bus_add_all_fdt_nodes (void *fdt,const char *intc,hwaddr addr, +hwaddr bus_size,int irq_start);#endif
hw/arm/boot.c +19 -53
143 lines not on this page · raw message
hw/arm/sysbus-fdt.c +4 -57
90 lines not on this page · raw message
hw/arm/virt.c +30 -34
108 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 4/5 arm: boot: set boot_info starting from first_cpu
In reply to Igor Mammedoveven though nothing is currently broken, make sure that boot_info is set on all CPUs.
Ref:
"Message-ID: <CAFEAcA_NMWuA8WSs3cNeY6xX1kerO_uAcN_3=fK02BEhHJW86g@mail.gmail.com>"
--- hw/arm/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/boot.c +1 -1
@@ -1139,7 +1139,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } info->is_linux = is_linux; -for (cs =CPU (cpu); cs; cs =CPU_NEXT (cs)) { +for (cs = first_cpu; cs; cs =CPU_NEXT (cs)) {ARM_CPU (cs)->env.boot_info = info; }
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH v3 4/5] arm: boot: set boot_info starting from first_cpu
Quoted 5 lines · Igor Mammedov
even though nothing is currently broken, make sure that
boot_infois set on all CPUs.Ref:
"Message-ID: <CAFEAcA_NMWuA8WSs3cNeY6xX1kerO_uAcN_3=fK02BEhHJW86g@mail.gmail.com>"
Can you include the rationale in the commit message rather than just pointing to a message-id, please?
Quoted 3 lines
Signed-off-by Igor Mammedov <[email protected]>--
Otherwise
thanks
-- PMM
Re: [Qemu-arm] [PATCH v3 4/5] arm: boot: set boot_info starting from first_cpu
Quoted 9 lines · On Tue, 1 May 2018 13:19:12 +0100 Peter Maydell <[email protected]>…
Quoted 5 lines · Igor Mammedov
even though nothing is currently broken, make sure that
boot_infois set on all CPUs.Ref:
"Message-ID: <CAFEAcA_NMWuA8WSs3cNeY6xX1kerO_uAcN_3=fK02BEhHJW86g@mail.gmail.com>"Can you include the rationale in the commit message rather than just pointing to a message-id, please?
sure,
I'll post it reply here.
BTW: I'm expecting this being merged through ARM tree
Quoted 9 lines
Quoted 3 lines
Signed-off-by Igor Mammedov <[email protected]>Otherwise
Reviewed-by Peter Maydell <[email protected]>thanks
-- PMM
PATCH v4 4/5 arm: boot: set boot_info starting from first_cpu
In reply to Igor MammedovEven though nothing is currently broken (since all boards use first_cpu as boot cpu), make sure that boot_info is set on all CPUs.
If some board would like support heterogenuos setup (i.e. init boot_info on subset of CPUs) in future, it should add a reasonable API to do it, instead of starting assigning boot_info from some CPU and till the end of present CPUs list.
Ref:
"Message-ID: <CAFEAcA_NMWuA8WSs3cNeY6xX1kerO_uAcN_3=fK02BEhHJW86g@mail.gmail.com>"
--- hw/arm/boot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/boot.c +1 -1
@@ -1139,7 +1139,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) } info->is_linux = is_linux; -for (cs =CPU (cpu); cs; cs =CPU_NEXT (cs)) { +for (cs = first_cpu; cs; cs =CPU_NEXT (cs)) {ARM_CPU (cs)->env.boot_info = info; }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v4 4/5] arm: boot: set boot_info starting from first_cpu
Quoted 8 lines · Igor Mammedov
Even though nothing is currently broken (since all boards use
first_cpuas boot cpu), make sure thatboot_infois set on all CPUs.
If some board would like support heterogenuos setup (i.e. initboot_infoon subset of CPUs) in future, it should add a reasonable API to do it, instead of starting assigningboot_infofrom some CPU and till the end of present CPUs list.
It's a bit confusing to only send one patch rather than the whole set -- our automated patch application and testing tooling gets confused. I noticed this one by chance because I was skimming the commit log for v3 and noticed that it was missing this text. If the change had been in code rather than in the commit message I would probably not have picked it up...
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 4/5] arm: boot: set boot_info starting from first_cpu
Quoted 10 lines · On Thu, 3 May 2018 16:03:09 +0100 Peter Maydell <[email protected]>…
Quoted 8 lines · Igor Mammedov
Even though nothing is currently broken (since all boards use
first_cpuas boot cpu), make sure thatboot_infois set on all CPUs.
If some board would like support heterogenuos setup (i.e. initboot_infoon subset of CPUs) in future, it should add a reasonable API to do it, instead of starting assigningboot_infofrom some CPU and till the end of present CPUs list.
Quoted 6 lines
It's a bit confusing to only send one patch rather than the whole set -- our automated patch application and testing tooling gets confused. I noticed this one by chance because I was skimming the commit log for v3 and noticed that it was missing this text. If the change had been in code rather than in the commit message I would probably not have picked it up...
I wanted to not to spam too much list with respin of whole series for commit message fixup, sending fixed up vX as reply is usually ok for x86 trees but it's up to a maintainer preference. Next time for fixups, I'll respin whole series if it's intended to go via ARM tree.
Quoted 2 lines
thanks
-- PMM
PATCH v3 5/5 make sure that we aren't overwriting mc->get_hotplug_handler by accident
In reply to Igor Mammedov--- hw/arm/virt.c | 1 + hw/i386/pc.c | 1 + hw/ppc/e500plat.c | 1 + hw/ppc/spapr.c | 1 + hw/s390x/s390-virtio-ccw.c | 1 + 5 files changed, 5 insertions(+)
hw/arm/virt.c +1 -0
@@ -1578,6 +1578,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler; hc->plug = virt_machine_device_plug_cb; }
hw/i386/pc.c +1 -0
@@ -2355,6 +2355,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) pcmc->acpi_data_size =0x20000 +0x8000 ; pcmc->save_tsc_khz = true; pcmc->linuxboot_dma_enabled = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = pc_get_hotpug_handler; mc->cpu_index_to_instance_props = pc_cpu_index_to_props; mc->get_default_cpu_node_id = pc_get_default_cpu_node_id;
hw/ppc/e500plat.c +1 -0
@@ -74,6 +74,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data)HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc); +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = e500plat_machine_get_hotpug_handler; hc->plug = e500plat_machine_device_plug_cb;
hw/ppc/spapr.c +1 -0
@@ -3995,6 +3995,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->kvm_type = spapr_kvm_type;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_SPAPR_PCI_HOST_BRIDGE ); mc->pci_allow_0_address = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = spapr_get_hotplug_handler; hc->pre_plug = spapr_machine_device_pre_plug; hc->plug = spapr_machine_device_plug;
hw/s390x/s390-virtio-ccw.c +1 -0
@@ -476,6 +476,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->use_sclp =1 ; mc->max_cpus =S390_MAX_CPUS ; mc->has_hotpluggable_cpus = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = s390_get_hotplug_handler; mc->cpu_index_to_instance_props = s390_cpu_index_to_props; mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH v3 5/5] make sure that we aren't overwriting mc->get_hotplug_handler by accident
Quoted 2 lines · Igor Mammedov
Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Igor Mammedov <[email protected]>
Quoted 69 lines
--- hw/arm/virt.c | 1 + hw/i386/pc.c | 1 + hw/ppc/e500plat.c | 1 + hw/ppc/spapr.c | 1 + hw/s390x/s390-virtio-ccw.c | 1 + 5 files changed, 5 insertions(+)hw/arm/virt.c +1
-0@@ -1578,6 +1578,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler; hc->plug = virt_machine_device_plug_cb; }hw/i386/pc.c +1
-0@@ -2355,6 +2355,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) pcmc->acpi_data_size =0x20000 +0x8000 ; pcmc->save_tsc_khz = true; pcmc->linuxboot_dma_enabled = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = pc_get_hotpug_handler; mc->cpu_index_to_instance_props = pc_cpu_index_to_props; mc->get_default_cpu_node_id = pc_get_default_cpu_node_id;hw/ppc/e500plat.c +1
-0@@ -74,6 +74,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data)HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc);MachineClass *mc =MACHINE_CLASS (oc); +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = e500plat_machine_get_hotpug_handler; hc->plug = e500plat_machine_device_plug_cb;hw/ppc/spapr.c +1
-0@@ -3995,6 +3995,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->kvm_type = spapr_kvm_type;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_SPAPR_PCI_HOST_BRIDGE ); mc->pci_allow_0_address = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = spapr_get_hotplug_handler; hc->pre_plug = spapr_machine_device_pre_plug; hc->plug = spapr_machine_device_plug;hw/s390x/s390-virtio-ccw.c +1
-0@@ -476,6 +476,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) mc->use_sclp =1 ; mc->max_cpus =S390_MAX_CPUS ; mc->has_hotpluggable_cpus = true; +assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = s390_get_hotplug_handler; mc->cpu_index_to_instance_props = s390_cpu_index_to_props; mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
Peter Maydell
AppliedQuoted 9 lines · Igor Mammedov
Changelog
v2->v3:
* drop already merged patches
'arm: always start fromfirst_cpuwhen registering loader cpu reset callback' 'ppc: e500: switch E500 based machines to full machine definition'
* add small not related cleanup
'arm: boot: setboot_infostarting fromfirst_cpu'
* add extra suggested patch'make sure that we aren't overwriting mc->get_hotplug_handler by accident'
Quoted 16 lines
* make sure that
dtb_limitinitialized to 0
* drop stale comment
* drop not needed line movement
* drop not needed extra new line
Changelogv1->v2:
* drop "arm: reusearm_boot_address_space()inarmv7m_load_kernel()"
* move "arm: always start fromfirst_cpuwhen registering loader cpu reset callback" at the begigning of series and rebase
* add "ppc: e500: switch E500 based machines to full machine definition" and rebase 4/5 on top of it
* fixup typo invirt_machine_get_hotpug_handler()name
* add doc comment toskip_dtb_autoloadfield
* 1-2/5 are queued in respective arm/ppc trees and are included for series completness so it would be easier to test, I expect series to go through arm tree
Applied to target-arm.next, thanks.
-- PMM
Quoted 27 lines · Peter Maydell
Quoted 9 lines · Igor Mammedov
Changelog
v2->v3:
* drop already merged patches
'arm: always start fromfirst_cpuwhen registering loader cpu reset callback' 'ppc: e500: switch E500 based machines to full machine definition'
* add small not related cleanup
'arm: boot: setboot_infostarting fromfirst_cpu'
* add extra suggested patch'make sure that we aren't overwriting mc->get_hotplug_handler by accident'Quoted 16 lines
* make sure that
dtb_limitinitialized to 0
* drop stale comment
* drop not needed line movement
* drop not needed extra new line
Changelogv1->v2:
* drop "arm: reusearm_boot_address_space()inarmv7m_load_kernel()"
* move "arm: always start fromfirst_cpuwhen registering loader cpu reset callback" at the begigning of series and rebase
* add "ppc: e500: switch E500 based machines to full machine definition" and rebase 4/5 on top of it
* fixup typo invirt_machine_get_hotpug_handler()name
* add doc comment toskip_dtb_autoloadfield
* 1-2/5 are queued in respective arm/ppc trees and are included for series completness so it would be easier to test, I expect series to go through arm tree
Quoted 1 line
Applied to target-arm.next, thanks.
Doing further testing within target-arm.next shows that this series (and specifically patch 3/5) causes segfaults for the "no DTB provided" case.
$ gdb --args ./build/x86/arm-softmmu/qemu-system-arm -M vexpress-a15
-kernel /dev/null
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
[...]
(gdb) r
[...]
Thread 1 "qemu-system-arm" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ()
#1 0x000055555596565e in arm_load_dtb (addr=0, binfo=0x5555566dec00
<a15_daughterboard>, addr_limit=0, as=0x555556fa08a0) at
/home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/boot.c:515
#2 0x0000555555966d7f in arm_load_kernel (cpu=0x7ffff7fd6010,
info=0x5555566dec00 <a15_daughterboard>)
at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/boot.c:1156
#3 0x0000555555986f5b in vexpress_common_init (machine=0x555556e04060)
at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/arm/vexpress.c:707
#4 0x0000555555b10341 in machine_run_board_init (machine=0x555556e04060)
at /home/petmay01/linaro/qemu-from-laptop/qemu/hw/core/machine.c:829
#5 0x0000555555a4cbab in main (argc=5, argv=0x7fffffffe448,
envp=0x7fffffffe478)
at /home/petmay01/linaro/qemu-from-laptop/qemu/vl.c:4624arm_load_dtb() is trying to call the binfo->get_dtb() hook and is not handling the case where it is NULL (which it is on pretty much every board except "virt").
(You get a segfault with an actual guest kernel as well; I just used /dev/null here as an easy no-dependencies-required repro case.)
I've left patch 4 in target-arm.next as that was a standalone bugfix, but have dropped the rest of the series for now.
thanks
-- PMM
Quoted 34 lines · On Fri, 4 May 2018 17:28:55 +0100 Peter Maydell <[email protected]>…
Quoted 27 lines · Peter Maydell
Quoted 9 lines · Igor Mammedov
Changelog
v2->v3:
* drop already merged patches
'arm: always start fromfirst_cpuwhen registering loader cpu reset callback' 'ppc: e500: switch E500 based machines to full machine definition'
* add small not related cleanup
'arm: boot: setboot_infostarting fromfirst_cpu'
* add extra suggested patch'make sure that we aren't overwriting mc->get_hotplug_handler by accident'Quoted 16 lines
* make sure that
dtb_limitinitialized to 0
* drop stale comment
* drop not needed line movement
* drop not needed extra new line
Changelogv1->v2:
* drop "arm: reusearm_boot_address_space()inarmv7m_load_kernel()"
* move "arm: always start fromfirst_cpuwhen registering loader cpu reset callback" at the begigning of series and rebase
* add "ppc: e500: switch E500 based machines to full machine definition" and rebase 4/5 on top of it
* fixup typo invirt_machine_get_hotpug_handler()name
* add doc comment toskip_dtb_autoloadfield
* 1-2/5 are queued in respective arm/ppc trees and are included for series completness so it would be easier to test, I expect series to go through arm treeQuoted 1 line
Applied to target-arm.next, thanks.
Doing further testing within target-arm.next shows that this series (and specifically patch 3/5) causes segfaults for the "no DTB provided" case.
$ gdb --args ./build/x86/arm-softmmu/qemu-system-arm -M vexpress-a15
[...]
Quoted 9 lines
arm_load_dtb()is trying to call thebinfo->get_dtb()hook and is not handling the case where it is NULL (which it is on pretty much every board except "virt").(You get a segfault with an actual guest kernel as well; I just used
/dev/nullhere as an easy no-dependencies-required repro case.)I've left patch 4 in target-arm.next as that was a standalone bugfix, but have dropped the rest of the series for now.
Fix is really trivial, I've lost have_dtb() guard, while consolidating multiple load_dtb() calls into one.
I'll respin v4 shortly with fixed 3/5.
Quoted 2 lines
thanks
-- PMM