From nobody Sat Nov 15 05:39:09 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1755615597; cv=none; d=zohomail.com; s=zohoarc; b=hzpeWeFLD6GCCA9ylbbxo8/kMf5nZoLSHwF8fKsyECxcrSKIvNK/g5psusHB5HlYWUw6xbxhQ6J3nFJg8yU+r2iD/p/6fZtlofSKgeKX0dfjSlLRXswD5qg2GJvYlBqPDzx6dY05Ni/L4Mz1kDSodYUbTK/oBYCaUYZvtBB9LDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755615597; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=wNNOEDo3dHVHjTdM8enfD6wjCCrl2W7sz0MTL123G0g=; b=CAtmXE+xPAUI1jk64JD65dNP5zvmm05ZsNq83jVF13Hj5DFY2GYNJ7xMcXMBRu46cMdwXaU3A2S0kmqBcQk5jNOK57BT9caZy7EwX20o4HzjEsQL/r63Hw5fHe9RDkbSJ8ZLS6VyK7UUvAC0SzS676u2ynLlNUy+wqPqLVO90xI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755615597491550.8441333415984; Tue, 19 Aug 2025 07:59:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uoNoF-00084m-P1; Tue, 19 Aug 2025 10:59:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uoNnj-0007wn-Ml for qemu-devel@nongnu.org; Tue, 19 Aug 2025 10:59:07 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uoNnd-0002Lb-4m for qemu-devel@nongnu.org; Tue, 19 Aug 2025 10:59:03 -0400 Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c5t4s4W7mz14MfP; Tue, 19 Aug 2025 22:58:37 +0800 (CST) Received: from dggpemf200011.china.huawei.com (unknown [7.185.36.152]) by mail.maildlp.com (Postfix) with ESMTPS id 19204180B66; Tue, 19 Aug 2025 22:58:41 +0800 (CST) Received: from localhost (10.173.124.206) by dggpemf200011.china.huawei.com (7.185.36.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 19 Aug 2025 22:58:40 +0800 To: CC: , , , WangXin , Tuo Xie Subject: [PATCH] target/i386: Add support save/load exception error_code Date: Tue, 19 Aug 2025 22:58:34 +0800 Message-ID: <20250819145834.3998-1-wangxinxin.wang@huawei.com> X-Mailer: git-send-email 2.50.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.173.124.206] X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To dggpemf200011.china.huawei.com (7.185.36.152) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.187; envelope-from=wangxinxin.wang@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Wang Xin From: Wang Xin via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1755615598623116600 Content-Type: text/plain; charset="utf-8" From: WangXin 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 resum= e, 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 Signed-off-by: Tuo Xie diff --git a/target/i386/machine.c b/target/i386/machine.c index dd2dac1d44..45b7cea80a 100644 Reviewed-by: Zhao Liu --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -462,6 +462,24 @@ static const VMStateDescription vmstate_exception_info= =3D { } }; =20 +static bool cpu_errcode_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + + return cpu->env.has_error_code !=3D 0; +} + +static const VMStateDescription vmstate_error_code =3D { + .name =3D "cpu/error_code", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D cpu_errcode_needed, + .fields =3D (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 =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_exception_info, + &vmstate_error_code, &vmstate_async_pf_msr, &vmstate_async_pf_int_msr, &vmstate_pv_eoi_msr, --=20 2.43.0