Commit 5cf2126389 for qemu.org

commit 5cf21263896f650c8b7e87915c07c78f73d8e271
Author: Eric Auger <eric.auger@redhat.com>
Date:   Fri Oct 30 14:13:17 2026 +0100

    target/arm: Directly store cpu probe failure error

    In case *_arm_host_cpu_features() fails, we currently
    record that state in cpu->host_cpu_probe_failed to later
    report the error on realize().

    Replace the boolean by an error handle to allow
    more relevant error reports.

    Signed-off-by: Eric Auger <eric.auger@redhat.com>
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Message-id: 20261030131406.461599-10-eric.auger@redhat.com
    Suggested-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index b9e4734de8..c484c40a7e 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1740,6 +1740,10 @@ static void arm_cpu_finalizefn(Object *obj)

     g_hash_table_destroy(cpu->cp_regs);

+    if (cpu->host_cpu_probe_err) {
+        error_free(cpu->host_cpu_probe_err);
+    }
+
     QLIST_FOREACH_SAFE(hook, &cpu->pre_el_change_hooks, node, next) {
         QLIST_REMOVE(hook, node);
         g_free(hook);
@@ -1842,12 +1846,14 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
      * then it's possible that might have failed in the initfn, but
      * this is the first point where we can report it.
      */
-    if (cpu->host_cpu_probe_failed) {
+    if (cpu->host_cpu_probe_err) {
         if (!kvm_enabled() && !hvf_enabled() && !whpx_enabled()) {
             error_setg(errp, "The 'host' CPU type can only be used with KVM, HVF or WHPX");
+            error_free(cpu->host_cpu_probe_err);
         } else {
-            error_setg(errp, "Failed to retrieve host CPU features");
+            error_propagate(errp, cpu->host_cpu_probe_err);
         }
+        cpu->host_cpu_probe_err = NULL;
         return;
     }

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 5c5f551dac..dae79539b5 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1075,10 +1075,11 @@ struct ArchCPU {
     /* Uniprocessor system with MP extensions */
     bool mp_is_up;

-    /* True if we tried kvm_arm_host_cpu_features() during CPU instance_init
+    /*
+     * Set if we tried *_set_cpu_features_from_host() during CPU instance_init
      * and the probe failed (so we need to report the error in realize)
      */
-    bool host_cpu_probe_failed;
+    Error *host_cpu_probe_err;

     /* QOM property to indicate we should use the back-compat CNTFRQ default */
     bool backcompat_cntfrq;
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 34a7f4636a..4334ff866d 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1299,7 +1299,8 @@ void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
              * We can't report this error yet, so flag that we need to
              * in arm_cpu_realizefn().
              */
-            cpu->host_cpu_probe_failed = true;
+            error_setg(&cpu->host_cpu_probe_err,
+                       "failed to retrieve host CPU features");
             return;
         }
     }
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index b4b20c5dc2..f9c7577460 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -538,7 +538,8 @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu)
          * We can't report this error yet, so flag that we need to
          * in arm_cpu_realizefn().
          */
-        cpu->host_cpu_probe_failed = true;
+        error_setg(&cpu->host_cpu_probe_err,
+                   "failed to retrieve host CPU features");
         return;
     }

diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c
index 024d18df04..ded42c980b 100644
--- a/target/arm/whpx/whpx-all.c
+++ b/target/arm/whpx/whpx-all.c
@@ -767,7 +767,8 @@ void whpx_arm_set_cpu_features_from_host(ARMCPU *cpu)
              * We can't report this error yet, so flag that we need to
              * in arm_cpu_realizefn().
              */
-            cpu->host_cpu_probe_failed = true;
+            error_setg(&cpu->host_cpu_probe_err,
+                      "failed to retrieve host CPU features");
             return;
         }
     }