qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init
@ 2025-07-17  2:39 Zhao Liu
  2025-07-17  4:27 ` Xiaoyao Li
  2025-07-17 10:30 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Zhao Liu @ 2025-07-17  2:39 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Zhao Liu, Paolo Abeni

In x86_cpu_post_initfn(), the initialization of x86_ext_save_areas[]
marks the unsupported xsave areas based on Host support.

This step must be done before accel_cpu_instance_init(), otherwise,
KVM's assertion on host xsave support would fail:

qemu-system-x86_64: ../target/i386/kvm/kvm-cpu.c:149:
kvm_cpu_xsave_init: Assertion `esa->size == eax' failed.

(on AMD EPYC 7302 16-Core Processor)

Move x86_ext_save_areas[] initialization to .instance_init and place it
before accel_cpu_instance_init().

Fixes: commit 5f158abef44c ("target/i386: move accel_cpu_instance_init to .instance_init")
Reported-by: Paolo Abeni <pabeni@redhat.com>
Tested-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 target/i386/cpu.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index da7d8dca633e..251d5760a0bd 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -9619,6 +9619,16 @@ static void x86_cpu_register_feature_bit_props(X86CPUClass *xcc,
 }
 
 static void x86_cpu_post_initfn(Object *obj)
+{
+#ifndef CONFIG_USER_ONLY
+    if (current_machine && current_machine->cgs) {
+        x86_confidential_guest_cpu_instance_init(
+            X86_CONFIDENTIAL_GUEST(current_machine->cgs), (CPU(obj)));
+    }
+#endif
+}
+
+static void x86_cpu_init_xsave(void)
 {
     static bool first = true;
     uint64_t supported_xcr0;
@@ -9639,13 +9649,6 @@ static void x86_cpu_post_initfn(Object *obj)
             }
         }
     }
-
-#ifndef CONFIG_USER_ONLY
-    if (current_machine && current_machine->cgs) {
-        x86_confidential_guest_cpu_instance_init(
-            X86_CONFIDENTIAL_GUEST(current_machine->cgs), (CPU(obj)));
-    }
-#endif
 }
 
 static void x86_cpu_init_default_topo(X86CPU *cpu)
@@ -9715,6 +9718,11 @@ static void x86_cpu_initfn(Object *obj)
         x86_cpu_load_model(cpu, xcc->model);
     }
 
+    /*
+     * accel's cpu_instance_init may have the xsave check,
+     * so x86_ext_save_areas[] must be initialized before this.
+     */
+    x86_cpu_init_xsave();
     accel_cpu_instance_init(CPU(obj));
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init
  2025-07-17  2:39 [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init Zhao Liu
@ 2025-07-17  4:27 ` Xiaoyao Li
  2025-07-17 10:30 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Xiaoyao Li @ 2025-07-17  4:27 UTC (permalink / raw)
  To: Zhao Liu, Paolo Bonzini; +Cc: qemu-devel, Paolo Abeni

On 7/17/2025 10:39 AM, Zhao Liu wrote:
> In x86_cpu_post_initfn(), the initialization of x86_ext_save_areas[]
> marks the unsupported xsave areas based on Host support.
> 
> This step must be done before accel_cpu_instance_init(), otherwise,
> KVM's assertion on host xsave support would fail:
> 
> qemu-system-x86_64: ../target/i386/kvm/kvm-cpu.c:149:
> kvm_cpu_xsave_init: Assertion `esa->size == eax' failed.
> 
> (on AMD EPYC 7302 16-Core Processor)
> 
> Move x86_ext_save_areas[] initialization to .instance_init and place it
> before accel_cpu_instance_init().
> 
> Fixes: commit 5f158abef44c ("target/i386: move accel_cpu_instance_init to .instance_init")
> Reported-by: Paolo Abeni <pabeni@redhat.com>
> Tested-by: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init
  2025-07-17  2:39 [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init Zhao Liu
  2025-07-17  4:27 ` Xiaoyao Li
@ 2025-07-17 10:30 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2025-07-17 10:30 UTC (permalink / raw)
  To: Zhao Liu; +Cc: qemu-devel, Paolo Abeni

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-17 10:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17  2:39 [PATCH for v10.1] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init Zhao Liu
2025-07-17  4:27 ` Xiaoyao Li
2025-07-17 10:30 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).