[PATCH v2] ppc/pnv: generate dtb after machine initialization is complete

Shivang Upadhyay posted 1 patch 6 days, 1 hour ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260327124136.983955-1-shivangu@linux.ibm.com
Maintainers: Nicholas Piggin <npiggin@gmail.com>, Aditya Gupta <adityag@linux.ibm.com>, Glenn Miles <milesg@linux.ibm.com>
hw/ppc/pnv.c         | 58 +++++++++++++++++++++++++-------------------
include/hw/ppc/pnv.h |  2 ++
2 files changed, 35 insertions(+), 25 deletions(-)
[PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Shivang Upadhyay 6 days, 1 hour ago
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 <adityag@linux.ibm.com>
Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
Cc: BALATON Zoltan <balaton@eik.bme.hu>
Cc: qemu-stable@nongnu.org
Reported-by: Nathan Chancellor <nathan@kernel.org>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Fixes: a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>

---
Changes:

v2:
* moved pnv->bmc initialization to pnv_machine_init_done.

v1:
* https://lore.kernel.org/all/20260324135026.247418-1-shivangu@linux.ibm.com/
---
 hw/ppc/pnv.c         | 58 +++++++++++++++++++++++++-------------------
 include/hw/ppc/pnv.h |  2 ++
 2 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 7e54b6bc60..524563dcfc 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -748,31 +748,10 @@ static void pnv_powerdown_notify(Notifier *n, void *opaque)
 
 static void pnv_reset(MachineState *machine, ResetType type)
 {
-    PnvMachineState *pnv = PNV_MACHINE(machine);
-    IPMIBmc *bmc;
     void *fdt;
 
     qemu_devices_reset(type);
 
-    /*
-     * The machine should provide by default an internal BMC simulator.
-     * If not, try to use the BMC device that was provided on the command
-     * line.
-     */
-    bmc = pnv_bmc_find(&error_fatal);
-    if (!pnv->bmc) {
-        if (!bmc) {
-            if (!qtest_enabled()) {
-                warn_report("machine has no BMC device. Use '-device "
-                            "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
-                            "to define one");
-            }
-        } else {
-            pnv_bmc_set_pnor(bmc, pnv->pnor);
-            pnv->bmc = bmc;
-        }
-    }
-
     fdt = machine->fdt;
     cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt));
 }
@@ -984,6 +963,37 @@ 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);
+    IPMIBmc *bmc;
+
+    /*
+     * The machine should provide by default an internal BMC simulator.
+     * If not, try to use the BMC device that was provided on the command
+     * line.
+     */
+    bmc = pnv_bmc_find(&error_fatal);
+    if (!pnv->bmc) {
+        if (!bmc) {
+            if (!qtest_enabled()) {
+                warn_report("machine has no BMC device. Use '-device "
+                            "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
+                            "to define one");
+            }
+        } else {
+            pnv_bmc_set_pnor(bmc, pnv->pnor);
+            pnv->bmc = bmc;
+        }
+    }
+
+    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 +1254,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);
 }
 
 /*
diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
index 24f8843a40..90028f974d 100644
--- a/include/hw/ppc/pnv.h
+++ b/include/hw/ppc/pnv.h
@@ -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);
-- 
2.53.0
Re: [PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Philippe Mathieu-Daudé 2 days ago
On 27/3/26 13:41, Shivang Upadhyay wrote:
> 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 <adityag@linux.ibm.com>
> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Cc: qemu-stable@nongnu.org
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Fixes: a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
> Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>
> 
> ---
> Changes:
> 
> v2:
> * moved pnv->bmc initialization to pnv_machine_init_done.
> 
> v1:
> * https://lore.kernel.org/all/20260324135026.247418-1-shivangu@linux.ibm.com/
> ---
>   hw/ppc/pnv.c         | 58 +++++++++++++++++++++++++-------------------
>   include/hw/ppc/pnv.h |  2 ++
>   2 files changed, 35 insertions(+), 25 deletions(-)

Queued via hw-misc tree, thanks.
Re: [PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Aditya Gupta 4 days, 7 hours ago
On 27/03/26 18:11, Shivang Upadhyay wrote:

> 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 <adityag@linux.ibm.com>
> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Cc: qemu-stable@nongnu.org
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Fixes: a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
> Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>
>
> ---
> Changes:
>
> v2:
> * moved pnv->bmc initialization to pnv_machine_init_done.
>
> v1:
> * https://lore.kernel.org/all/20260324135026.247418-1-shivangu@linux.ibm.com/
> ---
>   hw/ppc/pnv.c         | 58 +++++++++++++++++++++++++-------------------
>   include/hw/ppc/pnv.h |  2 ++
>   2 files changed, 35 insertions(+), 25 deletions(-)


Reviewed-by: Aditya Gupta <adityag@linux.ibm.com>


Thanks,

- Aditya G
Re: [PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Nathan Chancellor 5 days, 21 hours ago
On Fri, Mar 27, 2026 at 06:11:36PM +0530, Shivang Upadhyay wrote:
> 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 <adityag@linux.ibm.com>
> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Cc: qemu-stable@nongnu.org
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Fixes: a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
> Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>

This still works for me.

Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
> Changes:
> 
> v2:
> * moved pnv->bmc initialization to pnv_machine_init_done.
> 
> v1:
> * https://lore.kernel.org/all/20260324135026.247418-1-shivangu@linux.ibm.com/
> ---
>  hw/ppc/pnv.c         | 58 +++++++++++++++++++++++++-------------------
>  include/hw/ppc/pnv.h |  2 ++
>  2 files changed, 35 insertions(+), 25 deletions(-)
> 
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index 7e54b6bc60..524563dcfc 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -748,31 +748,10 @@ static void pnv_powerdown_notify(Notifier *n, void *opaque)
>  
>  static void pnv_reset(MachineState *machine, ResetType type)
>  {
> -    PnvMachineState *pnv = PNV_MACHINE(machine);
> -    IPMIBmc *bmc;
>      void *fdt;
>  
>      qemu_devices_reset(type);
>  
> -    /*
> -     * The machine should provide by default an internal BMC simulator.
> -     * If not, try to use the BMC device that was provided on the command
> -     * line.
> -     */
> -    bmc = pnv_bmc_find(&error_fatal);
> -    if (!pnv->bmc) {
> -        if (!bmc) {
> -            if (!qtest_enabled()) {
> -                warn_report("machine has no BMC device. Use '-device "
> -                            "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
> -                            "to define one");
> -            }
> -        } else {
> -            pnv_bmc_set_pnor(bmc, pnv->pnor);
> -            pnv->bmc = bmc;
> -        }
> -    }
> -
>      fdt = machine->fdt;
>      cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt));
>  }
> @@ -984,6 +963,37 @@ 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);
> +    IPMIBmc *bmc;
> +
> +    /*
> +     * The machine should provide by default an internal BMC simulator.
> +     * If not, try to use the BMC device that was provided on the command
> +     * line.
> +     */
> +    bmc = pnv_bmc_find(&error_fatal);
> +    if (!pnv->bmc) {
> +        if (!bmc) {
> +            if (!qtest_enabled()) {
> +                warn_report("machine has no BMC device. Use '-device "
> +                            "ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10' "
> +                            "to define one");
> +            }
> +        } else {
> +            pnv_bmc_set_pnor(bmc, pnv->pnor);
> +            pnv->bmc = bmc;
> +        }
> +    }
> +
> +    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 +1254,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);
>  }
>  
>  /*
> diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h
> index 24f8843a40..90028f974d 100644
> --- a/include/hw/ppc/pnv.h
> +++ b/include/hw/ppc/pnv.h
> @@ -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);
> -- 
> 2.53.0
>
Re: [PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Peter Maydell 6 days, 1 hour ago
On Fri, 27 Mar 2026 at 12:42, Shivang Upadhyay <shivangu@linux.ibm.com> wrote:
>
> 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 <adityag@linux.ibm.com>
> Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Cc: qemu-stable@nongnu.org
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Fixes: a16d4c2f162a86d ("ppc/pnv: fix dumpdtb option")
> Signed-off-by: Shivang Upadhyay <shivangu@linux.ibm.com>
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Re: [PATCH v2] ppc/pnv: generate dtb after machine initialization is complete
Posted by Shivang Upadhyay 5 days, 22 hours ago
On Fri, 2026-03-27 at 12:54 +0000, Peter Maydell wrote:
> 
> 
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Thanks Peter.

~Shivang.