qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Xin Wang <wangxinxin.wang@huawei.com>
Subject: [PULL 01/14] target/i386: Add support for save/load of exception error code
Date: Wed, 27 Aug 2025 20:25:19 +0200	[thread overview]
Message-ID: <20250827182533.854476-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20250827182533.854476-1-pbonzini@redhat.com>

From: Xin Wang <wangxinxin.wang@huawei.com>

For now, qemu save/load CPU exception info(such as exception_nr and
has_error_code), while the exception error_code is ignored. This will
cause the dest hypervisor reinject a vCPU exception with error_code(0),
potentially causing a guest kernel panic.

For instance, if src VM stopped with an user-mode write #PF (error_code 6),
the dest hypervisor will reinject an #PF with error_code(0) when vCPU resume,
then guest kernel panic as:
  BUG: unable to handle page fault for address: 00007f80319cb010
  #PF: supervisor read access in user mode
  #PF: error_code(0x0000) - not-present page
  RIP: 0033:0x40115d

To fix it, support save/load exception error_code.

Signed-off-by: Xin Wang <wangxinxin.wang@huawei.com>
Link: https://lore.kernel.org/r/20250819145834.3998-1-wangxinxin.wang@huawei.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/machine.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/target/i386/machine.c b/target/i386/machine.c
index dd2dac1d443..45b7cea80aa 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -462,6 +462,24 @@ static const VMStateDescription vmstate_exception_info = {
     }
 };
 
+static bool cpu_errcode_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+
+    return cpu->env.has_error_code != 0;
+}
+
+static const VMStateDescription vmstate_error_code = {
+    .name = "cpu/error_code",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = cpu_errcode_needed,
+    .fields = (const VMStateField[]) {
+        VMSTATE_INT32(env.error_code, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 /* Poll control MSR enabled by default */
 static bool poll_control_msr_needed(void *opaque)
 {
@@ -1746,6 +1764,7 @@ const VMStateDescription vmstate_x86_cpu = {
     },
     .subsections = (const VMStateDescription * const []) {
         &vmstate_exception_info,
+        &vmstate_error_code,
         &vmstate_async_pf_msr,
         &vmstate_async_pf_int_msr,
         &vmstate_pv_eoi_msr,
-- 
2.51.0



  reply	other threads:[~2025-08-27 18:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 18:25 [PULL 00/14] QEMU patches for 2025-08-27 Paolo Bonzini
2025-08-27 18:25 ` Paolo Bonzini [this message]
2025-08-27 18:25 ` [PULL 02/14] scripts/minikconf.py: fix invalid attribute access Paolo Bonzini
2025-08-27 18:25 ` [PULL 03/14] scripts/minikconf.py: s/Error/KconfigParserError Paolo Bonzini
2025-08-27 18:25 ` [PULL 04/14] python: mkvenv: fix messages printed by mkvenv Paolo Bonzini
2025-08-27 18:25 ` [PULL 05/14] MAINTAINERS: add a few more files to "Top Level Makefile and configure" Paolo Bonzini
2025-08-27 18:25 ` [PULL 06/14] x86/loader: Don't update kernel header for CoCo VMs Paolo Bonzini
2025-08-27 18:25 ` [PULL 07/14] i386/tcg/svm: fix incorrect canonicalization Paolo Bonzini
2025-08-27 18:25 ` [PULL 08/14] kvm/kvm-all: make kvm_park/unpark_vcpu local to kvm-all.c Paolo Bonzini
2025-08-27 18:25 ` [PULL 09/14] rust: disable borrow_as_ptr warning Paolo Bonzini
2025-08-27 18:25 ` [PULL 10/14] rust: qemu-api-macros: support matching more than one error Paolo Bonzini
2025-08-27 18:25 ` [PULL 11/14] subprojects: update proc-macro2 and syn Paolo Bonzini
2025-08-27 18:25 ` [PULL 12/14] rust/qemu-api-macros: make derive(Object) friendly when missing parent Paolo Bonzini
2025-08-27 18:25 ` [PULL 13/14] rust: declare self as qemu_api for proc-macros Paolo Bonzini
2025-08-27 18:25 ` [PULL 14/14] rust: move dependencies to rust/Cargo.toml Paolo Bonzini
2025-08-27 22:50 ` [PULL 00/14] QEMU patches for 2025-08-27 Richard Henderson

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=20250827182533.854476-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=wangxinxin.wang@huawei.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).