qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Zhao Liu <zhao1.liu@intel.com>, Paolo Abeni <pabeni@redhat.com>,
	Xiaoyao Li <xiaoyao.li@intel.com>
Subject: [PULL 2/6] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init
Date: Thu, 17 Jul 2025 17:23:12 +0200	[thread overview]
Message-ID: <20250717152316.353049-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20250717152316.353049-1-pbonzini@redhat.com>

From: Zhao Liu <zhao1.liu@intel.com>

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>
Link: https://lore.kernel.org/r/20250717023933.2502109-1-zhao1.liu@intel.com
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.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 da7d8dca633..251d5760a0b 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.50.1



  parent reply	other threads:[~2025-07-17 18:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17 15:23 [PULL 0/6] Mostly target/i386 patches for QEMU 10.1 hard freeze Paolo Bonzini
2025-07-17 15:23 ` [PULL 1/6] target/i386: do not expose ARCH_CAPABILITIES on AMD CPU Paolo Bonzini
2025-07-18  7:21   ` Michael Tokarev
2025-07-18  8:09     ` Paolo Bonzini
2025-07-17 15:23 ` Paolo Bonzini [this message]
2025-07-17 15:23 ` [PULL 3/6] meson: re-generate scripts/meson-buildoptions.sh to fix IGVM entry Paolo Bonzini
2025-07-17 15:23 ` [PULL 4/6] target/i386: tdx: fix locking for interrupt injection Paolo Bonzini
2025-07-17 15:23 ` [PULL 5/6] i386/cpu: Cleanup host_cpu_max_instance_init() Paolo Bonzini
2025-07-17 15:23 ` [PULL 6/6] i386/tdx: Remove the redundant qemu_mutex_init(&tdx->lock) Paolo Bonzini
  -- strict thread matches above, loose matches on Subject: below --
2025-07-17 16:06 [PULL 0/6] Mostly target/i386 patches for QEMU 10.1 hard freeze Paolo Bonzini
2025-07-17 16:06 ` [PULL 2/6] i386/cpu: Move x86_ext_save_areas[] initialization to .instance_init Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250717152316.353049-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiaoyao.li@intel.com \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).