ppc/pnv: generate dtb after machine initialization is complete
PATCH 1/1 ppc/pnv: generate dtb after machine initialization is complete
Currently, the machine dtb is generated in pnv_init(), before all devices are fully initialized. This can result in an incomplete dtb for the system, as seen in bug [1].
Fix this by deferring dtb generation until machine initialization is complete, using the machine_init_done_notifier hook.
[1] https://lore.kernel.org/all/20260323231612.GA2637687@ax162/
--- hw/ppc/pnv.c | 17 +++++++++++++---- include/hw/ppc/pnv.h | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-)
hw/ppc/pnv.c +13 -4
@@ -984,6 +984,17 @@ static uint64_t pnv_chip_get_ram_size(PnvMachineState *pnv, int chip_id)return chip_id ==0 ?1 * GiB :QEMU_ALIGN_DOWN (ram_per_chip,1 * MiB); } +static void pnv_machine_init_done (Notifier *notifier,void *data) +{ +PnvMachineState *pnv =container_of (notifier, PnvMachineState, machine_init_done); +MachineState *machine =MACHINE (pnv); + +if (!machine->fdt) { + machine->fdt =pnv_dt_create (machine); +_FDT ((fdt_pack (machine->fdt))); + } +} +static void pnv_init (MachineState *machine) {const char *bios_name = machine->firmware ?:FW_FILE_NAME ;
@@ -1244,10 +1255,8 @@ static void pnv_init(MachineState *machine) pmc->i2c_init (pnv); } -if (!machine->fdt) { - machine->fdt =pnv_dt_create (machine); -_FDT ((fdt_pack (machine->fdt))); - } + pnv->machine_init_done.notify = pnv_machine_init_done; +qemu_add_machine_init_done_notifier (&pnv->machine_init_done); }/*
include/hw/ppc/pnv.h +2 -0
@@ -111,6 +111,8 @@ struct PnvMachineState {bool big_core;bool lpar_per_core; + +Notifier machine_init_done; };PnvChip *pnv_get_chip (PnvMachineState *pnv,uint32_t chip_id);
Signature · 1 line
2.53.0
Quoted 10 lines · Shivang Upadhyay
Currently, the machine dtb is generated in
pnv_init(), before all devices are fully initialized. This can result in an incomplete dtb for the system, as seen in bug [1].Fix this by deferring dtb generation until machine initialization is complete, using the
machine_init_done_notifierhook.[1] https://lore.kernel.org/all/20260323231612.GA2637687@ax162/
Quoted 8 lines
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Cc BALATON Zoltan <[email protected]>Reported-by Nathan Chancellor <[email protected]>Suggested-by Peter Maydell <[email protected]>Fixes a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")Signed-off-by Shivang Upadhyay <[email protected]>
thanks
-- PMM
Quoted 9 lines · Shivang Upadhyay
Currently, the machine dtb is generated in
pnv_init(), before all devices are fully initialized. This can result in an incomplete dtb for the system, as seen in bug [1].Fix this by deferring dtb generation until machine initialization is complete, using the
machine_init_done_notifierhook.[1] https://lore.kernel.org/all/20260323231612.GA2637687@ax162/
Quoted 8 lines
Cc Aditya Gupta <[email protected]>Cc Harsh Prateek Bora <[email protected]>Cc BALATON Zoltan <[email protected]>Reported-by Nathan Chancellor <[email protected]>Suggested-by Peter Maydell <[email protected]>Fixes a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")Signed-off-by Shivang Upadhyay <[email protected]>
Quoted 56 lines
--- hw/ppc/pnv.c | 17 +++++++++++++---- include/hw/ppc/pnv.h | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-)hw/ppc/pnv.c +13
-4@@ -984,6 +984,17 @@ static uint64_t pnv_chip_get_ram_size(PnvMachineState *pnv, int chip_id)return chip_id ==0 ?1 * GiB :QEMU_ALIGN_DOWN (ram_per_chip,1 * MiB); } +static void pnv_machine_init_done (Notifier *notifier,void *data) +{ +PnvMachineState *pnv =container_of (notifier, PnvMachineState, machine_init_done); +MachineState *machine =MACHINE (pnv); + +if (!machine->fdt) { + machine->fdt =pnv_dt_create (machine); +_FDT ((fdt_pack (machine->fdt))); + } +} +static void pnv_init (MachineState *machine) {const char *bios_name = machine->firmware ?:FW_FILE_NAME ;@@ -1244,10 +1255,8 @@ static void pnv_init(MachineState *machine) pmc->i2c_init (pnv); } -if (!machine->fdt) { - machine->fdt =pnv_dt_create (machine); -_FDT ((fdt_pack (machine->fdt))); - } + pnv->machine_init_done.notify = pnv_machine_init_done; +qemu_add_machine_init_done_notifier (&pnv->machine_init_done); }/* include/hw/ppc/pnv.h +2
-0@@ -111,6 +111,8 @@ struct PnvMachineState {bool big_core;bool lpar_per_core; + +Notifier machine_init_done; };PnvChip *pnv_get_chip (PnvMachineState *pnv,uint32_t chip_id);Signature · 1 line
2.53.0
Quoted 19 lines · Shivang Upadhyay
<...snip...>
hw/ppc/pnv.c +11
-0+static void pnv_machine_init_done (Notifier *notifier,void *data) +{ +PnvMachineState *pnv =container_of (notifier, PnvMachineState, machine_init_done); +MachineState *machine =MACHINE (pnv); + +if (!machine->fdt) { + machine->fdt =pnv_dt_create (machine); +_FDT ((fdt_pack (machine->fdt))); + } +} +static void pnv_init (MachineState *machine) {const char *bios_name = machine->firmware ?:FW_FILE_NAME ;@@ -1244,10 +1255,8 @@ static void pnv_init(MachineState *machine) pmc->i2c_init (pnv); }
hw/ppc/pnv.c static void pnv_init(MachineState *machine) · line 1262
Quoted 10 lines
hw/ppc/pnv.c +2
-4-if (!machine->fdt) { - machine->fdt =pnv_dt_create (machine); -_FDT ((fdt_pack (machine->fdt))); - } + pnv->machine_init_done.notify = pnv_machine_init_done; +qemu_add_machine_init_done_notifier (&pnv->machine_init_done); }/*
Thanks for fixing it. Just adding few more info from what I see. OPAL was stuck at cec-power-down, since it expects an ipmi-bt device for shutdown to work in QEMU.
So, the issue was not directly due to missing BMC device, rather due to missing 'isa-ipmi-bt' device, which the patch does fix, and hence the issue is fixed.
But still the dts we have is different from what we should have at pnv_reset. Adding a pnv_dt_create at the end of pnv_reset, as it used to be before, gives me a 'bmc' node also in device tree.
$ diff /tmp/dts.machinedone /tmp/dts.pnvreset
16a17,33
> bmc {
>
> sensors {
> #size-cells = <0x00>;
> #address-cells = <0x01>;
>
> sensor@0 {
> ipmi-sensor-type = <0x23>;
> ipmi-entity-instance = <0x01>;
> ipmi-entity-id = <0x23>;
> ipmi-sensor-reading-type = <0x6f>;
> compatible = "ibm,ipmi-sensor";
> reg = <0x00>;
> };
> };
> };
> This isn't handled at machine_init_done as 'pnv->bmc' is not set at this time
Two ways to fix it:
1. Have pnv_dt_create in pnv_reset as well, like previously
2. Move the pnv_bmc_find code in pnv_reset to pnv_init
What do you say ?
include/hw/ppc/pnv.h struct PnvMachineState { · line 115
Quoted 8 lines
include/hw/ppc/pnv.h +2
-0@@ -111,6 +111,8 @@ struct PnvMachineState {bool big_core;bool lpar_per_core; + +Notifier machine_init_done;
One minor note, all other machines in qemu use 'machine_done' as the notifier name, but I am good with 'machine_init_done' also, as this makes more sense to me.
Thanks,
- Aditya G
Quoted 24 lines · Aditya Gupta
But still the dts we have is different from what we should have at
pnv_reset. Adding apnv_dt_createat the end ofpnv_reset, as it used to be before, gives me a 'bmc' node also in device tree.$ diff /tmp/dts.machinedone /tmp/dts.pnvreset 16a17,33 > bmc { > > sensors { > #size-cells = <0x00>; > #address-cells = <0x01>; > > sensor@0 { > ipmi-sensor-type = <0x23>; > ipmi-entity-instance = <0x01>; > ipmi-entity-id = <0x23>; > ipmi-sensor-reading-type = <0x6f>; > compatible = "ibm,ipmi-sensor"; > reg = <0x00>; > }; > }; > }; >
Quoted 8 lines
This isn't handled at
machine_init_doneas 'pnv->bmc' is not set at this timeTwo ways to fix it:
1. Havepnv_dt_createinpnv_resetas well, like previously
2. Move thepnv_bmc_findcode inpnv_resettopnv_initWhat do you say ?
My feeling would be that the pnv_bmc_find() handling should move to the machine-init-done notifier. (pnv_init() would be too early -- the pnv_bmc_find() code is looking for a device that has been added via the -device command line option, so it won't be there yet in pnv_init().)
-- PMM
Quoted 32 lines · Peter Maydell
Quoted 31 lines · Aditya Gupta
But still the dts we have is different from what we should have at
pnv_reset. Adding apnv_dt_createat the end ofpnv_reset, as it used to be before, gives me a 'bmc' node also in device tree.$ diff /tmp/dts.machinedone /tmp/dts.pnvreset 16a17,33 > bmc { > > sensors { > #size-cells = <0x00>; > #address-cells = <0x01>; > > sensor@0 { > ipmi-sensor-type = <0x23>; > ipmi-entity-instance = <0x01>; > ipmi-entity-id = <0x23>; > ipmi-sensor-reading-type = <0x6f>; > compatible = "ibm,ipmi-sensor"; > reg = <0x00>; > }; > }; > }; >This isn't handled at
machine_init_doneas 'pnv->bmc' is not set at this timeTwo ways to fix it:
1. Havepnv_dt_createinpnv_resetas well, like previously
2. Move thepnv_bmc_findcode inpnv_resettopnv_init
Quoted 7 lines
Quoted 1 line
What do you say ?
My feeling would be that the
pnv_bmc_find()handling should move to the machine-init-done notifier. (pnv_init()would be too early -- thepnv_bmc_find()code is looking for a device that has been added via the -device command line option, so it won't be there yet inpnv_init().)
thanks! agreed, pnv_bmc_find wouldn't work in pnv_init. moving it to machine-init-done seems okay. if shivang decides to move pnv_bmc_find this should be good
- Aditya G
Quoted 29 lines · Aditya Gupta
But still the dts we have is different from what we should have at
pnv_reset. Adding apnv_dt_createat the end ofpnv_reset, as it used to
be before, gives me a 'bmc' node also in device tree.$ diff /tmp/dts.machinedone /tmp/dts.pnvreset 16a17,33 > bmc { > > sensors { > #size-cells = <0x00>; > #address-cells = <0x01>; > > sensor@0 { > ipmi-sensor-type = <0x23>; > ipmi-entity-instance = <0x01>; > ipmi-entity-id = <0x23>; > ipmi-sensor-reading-type = <0x6f>; > compatible = "ibm,ipmi- sensor"; > reg = <0x00>; > }; > }; > }; >
Quoted 4 lines
This isn't handled at
machine_init_doneas 'pnv->bmc' is not set at this
time
Yea, that seems like a bug. Thanks for checking this. I think, ill move the pnv->bmc initialization to machine_init_done also. And send a v2.
~Shivang.