[PATCH] hw/ppc/e500: Check for compatible CPU type instead of aborting ungracefully

Thomas Huth posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251015065742.1562288-1-thuth@redhat.com
Maintainers: Bernhard Beschow <shentey@gmail.com>
There is a newer version of this series
hw/ppc/e500.c | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] hw/ppc/e500: Check for compatible CPU type instead of aborting ungracefully
Posted by Thomas Huth 1 month ago
From: Thomas Huth <thuth@redhat.com>

When using the ppce500 machine with an embedded CPU type that has
the right MMU model, but is not part of the e500 CPU family, QEMU
currently aborts ungracefully:

 $ ./qemu-system-ppc -machine ppce500 -cpu e200z5 -nographic
 qemu-system-ppc: ../qemu/hw/core/gpio.c:108: qdev_get_gpio_in_named:
  Assertion `n >= 0 && n < gpio_list->num_in' failed.
 Aborted (core dumped)

The ppce500 machine expects a CPU with certain GPIO interrupt pins,
so let's check for a compatible model before we try to wire some
pins that don't exist.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3162
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/ppc/e500.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 723c97fad2e..d40b7a618db 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -20,6 +20,7 @@
 #include "qemu/guest-random.h"
 #include "exec/target_page.h"
 #include "qapi/error.h"
+#include "cpu-models.h"
 #include "e500.h"
 #include "e500-ccsr.h"
 #include "net/net.h"
@@ -947,6 +948,10 @@ void ppce500_init(MachineState *machine)
                          env->mmu_model);
             exit(1);
         }
+        if (!(POWERPC_CPU_GET_CLASS(cpu)->svr & POWERPC_SVR_E500)) {
+            error_report("This machine needs a CPU from the e500 family");
+            exit(1);
+        }
 
         /*
          * Secondary CPU starts in halted state for now. Needs to change
-- 
2.51.0
Re: [PATCH] hw/ppc/e500: Check for compatible CPU type instead of aborting ungracefully
Posted by BALATON Zoltan 1 month ago
On Wed, 15 Oct 2025, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
>
> When using the ppce500 machine with an embedded CPU type that has
> the right MMU model, but is not part of the e500 CPU family, QEMU
> currently aborts ungracefully:
>
> $ ./qemu-system-ppc -machine ppce500 -cpu e200z5 -nographic
> qemu-system-ppc: ../qemu/hw/core/gpio.c:108: qdev_get_gpio_in_named:
>  Assertion `n >= 0 && n < gpio_list->num_in' failed.
> Aborted (core dumped)
>
> The ppce500 machine expects a CPU with certain GPIO interrupt pins,
> so let's check for a compatible model before we try to wire some
> pins that don't exist.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3162
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> hw/ppc/e500.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index 723c97fad2e..d40b7a618db 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -20,6 +20,7 @@
> #include "qemu/guest-random.h"
> #include "exec/target_page.h"
> #include "qapi/error.h"
> +#include "cpu-models.h"
> #include "e500.h"
> #include "e500-ccsr.h"
> #include "net/net.h"
> @@ -947,6 +948,10 @@ void ppce500_init(MachineState *machine)
>                          env->mmu_model);
>             exit(1);
>         }

I think you can drop the mmu_model check above now becuase it's a no-op 
after the stricter check for e500 you added so no need to keep that 
separate error, the new check catches that too.

Regards,
BALATON Zoltan

> +        if (!(POWERPC_CPU_GET_CLASS(cpu)->svr & POWERPC_SVR_E500)) {
> +            error_report("This machine needs a CPU from the e500 family");
> +            exit(1);
> +        }
>
>         /*
>          * Secondary CPU starts in halted state for now. Needs to change
>
Re: [PATCH] hw/ppc/e500: Check for compatible CPU type instead of aborting ungracefully
Posted by Thomas Huth 1 month ago
On 15/10/2025 12.17, BALATON Zoltan wrote:
> On Wed, 15 Oct 2025, Thomas Huth wrote:
>> From: Thomas Huth <thuth@redhat.com>
>>
>> When using the ppce500 machine with an embedded CPU type that has
>> the right MMU model, but is not part of the e500 CPU family, QEMU
>> currently aborts ungracefully:
>>
>> $ ./qemu-system-ppc -machine ppce500 -cpu e200z5 -nographic
>> qemu-system-ppc: ../qemu/hw/core/gpio.c:108: qdev_get_gpio_in_named:
>>  Assertion `n >= 0 && n < gpio_list->num_in' failed.
>> Aborted (core dumped)
>>
>> The ppce500 machine expects a CPU with certain GPIO interrupt pins,
>> so let's check for a compatible model before we try to wire some
>> pins that don't exist.
>>
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3162
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> hw/ppc/e500.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
>> index 723c97fad2e..d40b7a618db 100644
>> --- a/hw/ppc/e500.c
>> +++ b/hw/ppc/e500.c
>> @@ -20,6 +20,7 @@
>> #include "qemu/guest-random.h"
>> #include "exec/target_page.h"
>> #include "qapi/error.h"
>> +#include "cpu-models.h"
>> #include "e500.h"
>> #include "e500-ccsr.h"
>> #include "net/net.h"
>> @@ -947,6 +948,10 @@ void ppce500_init(MachineState *machine)
>>                          env->mmu_model);
>>             exit(1);
>>         }
> 
> I think you can drop the mmu_model check above now becuase it's a no-op 
> after the stricter check for e500 you added so no need to keep that separate 
> error, the new check catches that too.

Right, good idea, I'll respin a v2...

  Thomas