Skip to contentSkip to conversation

target/arm: defer max-v8 initializer selection until CPU creation

PATCH In review Yonggang Luo 3 participants 13 messages Oct 13 – Oct 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: defer max-v8 initializer selection until CPU creation

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +13 -4
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)
Signature · 1 line
2.55.0.windows.3
#1 lore raw
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64); /* and fix other call sites */
And arm_cpu_register could take a new parameter, to set TypeInfo.is_available with the callback passed in.

@Peter: do you have a preference on this? I'm fine with having current patch and delay further changes to arm_cpu_register until we have proper heterogeneous support if you prefer.

Regards,
Pierrick

#2 lore raw
Quoted 49 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64); /* and fix other call sites */
And arm_cpu_register could take a new parameter, to set TypeInfo.is_available with the callback passed in.

Quoted 3 lines

@Peter: do you have a preference on this? I'm fine with having current patch and delay further changes to arm_cpu_register until we have proper heterogeneous support if you prefer.

Only a small number of patches needed other than machines in this way to get a usable
qemu-system. I've posted all patches(other than machine related) that required to
select the target inside select_machine.

The branch is at
https://gitlab.com/lygstate-qemu/qemu/-/tree/machine-targets?ref_type=heads

The whole series is small enough, and I tested to start alpine with

    "qemu-system",
    "-M", "aarch64-virt",
    "-cpu", "cortex-a72",
    "-smp", "2",
    "-m", "2048",
    "-bios", "edk2-aarch64-code.fd",
    "-drive", "`"file=/iso/$diskFileName,if=virtio,format=raw`"",
    "-netdev", "user,id=net0,hostfwd=tcp::$($SshPort)-:22",
    "-device", "virtio-net-pci,netdev=net0",
    "-device", "virtio-gpu-pci",
    "-device", "usb-ehci",
    "-device", "usb-kbd",
    "-device", "usb-tablet",
    "-spice", "addr=0.0.0.0,port=$SpicePort,disable-ticketing=on",
    "-serial", "mon:stdio",
    "-display", "none"

Looks better now:)

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#3 lore raw
In reply to Pierrick Bouvier
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
 target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
 #endif
 }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
 static void cpu_max_v8_register_type(void)
 {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
     };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
 }
 type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 10 lines

/* and fix other call sites */
And arm_cpu_register could take a new parameter, to set TypeInfo.is_available with the callback passed in.

@Peter: do you have a preference on this? I'm fine with having current patch and delay further changes to arm_cpu_register until we have proper heterogeneous support if you prefer.

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#4 lore raw
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

Regards,
Pierrick

#5 lore raw
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.
I'll post those two patches for a look

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#6 lore raw
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said, we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Regards,
Pierrick

#7 lore raw
Quoted 86 lines · Pierrick Bouvier
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

Quoted 6 lines

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said, we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Hi Peter, what's your suggest about this?

Quoted 3 lines

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#8 lore raw
Quoted 89 lines · Yonggang Luo
Quoted 86 lines · Pierrick Bouvier
Quoted 83 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

Quoted 8 lines
Quoted 6 lines

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said, we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Hi Peter, what's your suggest about this?

I don't really have a preference here as I haven't been following the heterogenous work that closely. I'm happy to go with whatever Pierrick / Philippe think makes sense.

-- PMM

#9 lore raw
Quoted 95 lines · Peter Maydell
Quoted 94 lines · Yonggang Luo
Quoted 91 lines · Pierrick Bouvier
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said, we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I'll let Peter say what he thinks about this.

Hi Peter, what's your suggest about this?

I don't really have a preference here as I haven't been following the heterogenous work that closely. I'm happy to go with whatever Pierrick / Philippe think makes sense.

Ok. In this case Yonggang, let's go with two max types, each with on init function, and using is_available to register the right one.

Regards,
Pierrick

#10 lore raw

On Wed, Oct 28, 2026 at 1:44 AM Pierrick Bouvier

Quoted 101 lines · <[email protected]> wrote:
Quoted 99 lines · Peter Maydell
Quoted 97 lines · Yonggang Luo
Quoted 86 lines · Pierrick Bouvier
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

Quoted 6 lines

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said, we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Hi Peter, what's your suggest about this?

Quoted 7 lines
Quoted 4 lines

I don't really have a preference here as I haven't been following the heterogenous work that closely. I'm happy to go with whatever Pierrick / Philippe think makes sense.

Ok. In this case Yonggang, let's go with two max types, each with on init function, and using is_available to register the right one.

Good, now I somewhat know how to do it in two max types now. I'll try to prototype
the idea first

Quoted 3 lines

Regards,
Pierrick

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

#11 lore raw
In reply to Pierrick Bouvier
Quoted 80 lines · Pierrick Bouvier
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 8 lines
Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said,

I am not sure what heterogeneous would be, currently max_v8_tcg_initfn is called for
both target_aarch64/target_arm, and call aarch64_max_v8_tcg_initfn/aarch32_max_v8_tcg_initfn
depends on if (target_aarch64()); so basically, when call to
max_v8_tcg_initfn, the target
is selected even under heterogeneous mode. would under heterogeneous mode, target_info() is a
thread local data, if that's true, I think the current PATCH is enough, we do not need two different
QOM-type-name for CPU .name = "max-v8",

Quoted 7 lines

we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Regards,
Pierrick

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#12 lore raw
Quoted 91 lines · Yonggang Luo
Quoted 80 lines · Pierrick Bouvier
Quoted 78 lines · Yonggang Luo
Quoted 65 lines · Pierrick Bouvier
Quoted 56 lines · Yonggang Luo
Quoted 43 lines · Pierrick Bouvier
Quoted 27 lines · Yonggang Luo

This is for avoid "max-v8" qom name conflict in multi-target qemu

---
  target/arm/tcg/cpu-max-v8.c | 17 +++++++++++++----
  1 file changed, 13 insertions(+), 4 deletions(-)
target/arm/tcg/cpu-max-v8.c +9 -1
index 65f851f2006..d7323ab431c 100644
@@ -119,12 +119,21 @@ void aarch32_max_v8_tcg_initfn(Object *obj)
  #endif
  }
 
+static void max_v8_tcg_initfn(Object *obj)
+{
+    if (target_aarch64()) {
+        aarch64_max_v8_tcg_initfn(obj);
+    } else {
+        aarch32_max_v8_tcg_initfn(obj);
+    }
+}
+
  static void cpu_max_v8_register_type(void)
  {
-    static const ARMCPUInfo max_v8[2] = {

target/arm/tcg/cpu-max-v8.c void aarch32_max_v8_tcg_initfn(Object *obj) · line 139

Quoted 10 lines
target/arm/tcg/cpu-max-v8.c +4 -3
-        { .name = "max-v8", .initfn = aarch32_max_v8_tcg_initfn },
-        { .name = "max-v8", .initfn = aarch64_max_v8_tcg_initfn },
+    static const ARMCPUInfo max_v8 = {
+        .name = "max-v8",
+        .initfn = max_v8_tcg_initfn,
      };
-    arm_cpu_register(&max_v8[target_aarch64()]);
+    arm_cpu_register(&max_v8);
  }
  type_init(cpu_max_v8_register_type)

It works for the current need, but will require further changes for heterogeneous emulation. A more versatile solution could be:

Quoted 2 lines

arm_cpu_register(&aarch32_max_v8, target_arm); arm_cpu_register(&aarch64_max_v8, target_aarch64);

And another way to handle it is like x86. it's comes with two variant for

#ifdef TARGET_X86_64
#define TYPE_X86_CPU "x86_64-cpu"
#else
#define TYPE_X86_CPU "i386-cpu"
#endif

Quoted 6 lines

This also solves this issue, which looks more straightforward. no need .targets magic for CPU.
Anyway, maybe the best way is to merge "x86_64-cpu" and "i386-cpu" into a single cpu type and
add .targets magic? When I am trying to get x86 works, faced this issue

Quoted 6 lines

This solves including i386 or x86_64, but not including both at the same time. Same goes for arm vs aarch64.

You can take a look at git history in target/arm, to see which kind of changes we did to make arm and aarch64 targets linkable. You'll notice most of the work was to remove (a lot of) #ifdef TARGET_X.

See it
SHA-1: ec7e5a90fea996f04ea24e81b680a87bc975354a
* target/arm: Remove TYPE_AARCH64_CPU

Quoted 8 lines
Quoted 5 lines

So I am just doing just the reverse direction, I am fixes x86_64 in a way that register both "x86_64-cpu" "i386-cpu" variants, though this way seems more suitable
for your heterogeneous emulation, but we need to register everything(CPUs) twice.

We'll have to register this twice anyway for heterogeneous, I don't see any other solution to have both accessible at the same time. That said,

Quoted 12 lines

I am not sure what heterogeneous would be, currently max_v8_tcg_initfn is called for
both target_aarch64/target_arm, and call aarch64_max_v8_tcg_initfn/aarch32_max_v8_tcg_initfn
depends on if (target_aarch64()); so basically, when call to
max_v8_tcg_initfn, the target
is selected even under heterogeneous mode. would under heterogeneous mode, target_info() is a
thread local data, if that's true, I think the current PATCH is enough, we do not need two different
QOM-type-name for CPU .name = "max-v8",

initfn is called through arm_cpu_instance_init from main QEMU thread, not from vcpu, thus why I insist to have two distinct types.

Quoted 10 lines
Quoted 7 lines

we are not yet there, and current patch solves the actual problem of having QOM types registered twice.

I'll let Peter say what he thinks about this.

Regards,
Pierrick