Skip to contentSkip to conversation

ppc/pnv: generate dtb after machine initialization is complete

PATCH Superseded Shivang Upadhyay 4 participants 7 messages Mar 24 – Mar 27

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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/

Cc Aditya Gupta <[email protected]>
Cc Harsh Prateek Bora <[email protected]>
Cc BALATON Zoltan <[email protected]>
Fixes a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
---
 hw/ppc/pnv.c         | 17 +++++++++++++----
 include/hw/ppc/pnv.h |  2 ++
 2 files changed, 15 insertions(+), 4 deletions(-)
hw/ppc/pnv.c +13 -4
index 7e54b6bc60..f13b2e3db8 100644
@@ -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
index 24f8843a40..90028f974d 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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_notifier hook.

[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]>
Fixes a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")

thanks
-- PMM

Tested-by on v1 1/1
#2 lore raw
In reply to Shivang Upadhyay
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_notifier hook.

[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]>
Fixes a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
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
index 7e54b6bc60..f13b2e3db8 100644
@@ -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
index 24f8843a40..90028f974d 100644
@@ -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
#3 lore raw
In reply to Shivang Upadhyay
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

#4 lore raw
Quoted 24 lines · Aditya Gupta

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>;
        >                       };
        >               };
        >       };
        >
Quoted 8 lines

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 ?

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

#5 lore raw
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 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

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 -- 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().)

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

#6 lore raw
In reply to Aditya Gupta
Quoted 29 lines · Aditya Gupta

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>;
	>                       };
	>               };
	>       };
	> 
Quoted 4 lines

This isn't handled at machine_init_done as '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.