From nobody Sat Sep 6 16:57:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1756974009; cv=none; d=zohomail.com; s=zohoarc; b=bAHslsxWhlmS2MwHulKl8j+qJAddefHGxwJCKULfijLjCsvznGmUorkttNez9GbZlfLC/zLf68cMOMbL8utqzKDWrSoWcjzsO+IvZsVR4Mnh8Rd7J2jSZNpncCAVMyJEQ25DLNzupWE2V3w3YqgRH/X1xBc1hS33etFccczyIOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756974009; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BNEGVA0a3lSomvk/RYtnyV9U8MhQRFndjMqEzv6fEMo=; b=h6yLN1hr9gAgI+IA/DWlSLH3tb0r2vPviw3cysKuXMexuZSWN27LPcS35LKt4qSGkcpM9QZKlUSW0zLnQVyJ0FeXbajH2Qe7NS5keBhvJWmoae9twUcoZwy3lwc/cYjbOyioibpERX79XjCxSpX992he1WypOk7ShWcIofKQMhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 175697400981299.83917671848326; Thu, 4 Sep 2025 01:20:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uu54H-0005tj-0C; Thu, 04 Sep 2025 04:11:41 -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 1uu54F-0005se-87 for qemu-devel@nongnu.org; Thu, 04 Sep 2025 04:11:39 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uu549-0003vk-3n for qemu-devel@nongnu.org; Thu, 04 Sep 2025 04:11:38 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-6188b5ad681so1148827a12.0 for ; Thu, 04 Sep 2025 01:11:32 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-61cfc5575dcsm13745805a12.49.2025.09.04.01.11.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 01:11:29 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4CE8D5F900; Thu, 04 Sep 2025 09:11:28 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756973491; x=1757578291; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BNEGVA0a3lSomvk/RYtnyV9U8MhQRFndjMqEzv6fEMo=; b=B5L2x+xNWWu/ohVHcXzYS6SoLd49RKD9rv9CHikeDtt2hXBIrk8r+rflRrfvcXmsEq /7xkFVW+HjZMfVrxhWN5CccdHnXtsu3XjrP6Y/zb7TEAQHLsZgUoWXR1mMHPsOy6IkKw 5MVoW/w9uwiPUdlsNf8m36Jm5zTJdYM0GCC1z7T11gXv8LpmIoN+53hvfO8DP0ppe+ZR KKWHYmaMzBKwsd8JnCdSEr4oPfKTccTFEinPm5jsEpbQyibNKYvm0nRCsUroGFbOK/Yq QjyVbnVjpM89OShLMhXaFngbxVTe0LoFkOxZGtAhUv7Yig3gwGtW042M0O5mWalf3ZNf nQpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756973491; x=1757578291; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BNEGVA0a3lSomvk/RYtnyV9U8MhQRFndjMqEzv6fEMo=; b=sQ3b/+p31Mb9Ay5i9CBxWiBNfd3IxMduU1GOy/rdJJ52AtLrai19kaa4/BupYQe34M dSoT1zzpA5Il/ALbqMb9JOjRpAexEPQehs9a+ACTySqY2vlvH7nfMUmFFtiRNq2dafDB oce4Lb307SGgzxcFVAmlWJ5ZvQ8+YjgZRL2O0hGAwZNJQQ6E1zhOAnlca8S3CHeHjPO5 aKaq6zKH2m11lulFvwIHY7Kxknmi3iUojENaQPIKe8mg2hwNezh13FKBxmxi3XjmKJJ7 DM7CHU5mn4XqUKLYLgQ01zF5/yIsAG1kcMx2Nfv/Bd6FBHhbKZuRwnplZRmH5RwxFjRn KrZQ== X-Gm-Message-State: AOJu0YyBQw5qQt9VvebGL1Z5AInMF7ng1UrgsZuWA0BVhy61MCNYGY/v P9EsGmW8ZD4L69XW+UpNFLmdoBDlUZO8M4FIDycNHl8gaDGf5pkHeNitLFAURnNjmpY= X-Gm-Gg: ASbGnct+gflVV0WSxrYENGSyRYIUWOIWge136YSD3IUKyyOiInbomuhcVNNiOKvAMoU uRb+YlmloBdNskVF2Qmth2s9thfoQIIZiIunSEH5La2WrSLLFiVoltaN8jPXfxHNHCMSF645nSK 88UgDEyzNKHPF4y09E2j0ZOEKDJIN2Ah8y8fh1II382f2WLGo1rRSZzUDTaNpyFpPW8dhClkpDj lMy8GNzPzhgYQ5SbkTYPlt9d8sX0tVAmuh1tsRpKl/gP3aqXpDjpyvfOQumQFp7FSQpcBnnLAjW fUI5Q+rXkw4E53XghfgInhn9dFMkwyQtf7JsTj0heJ+vwhOJp9jPRwdAqxE5hk69qC1lE09KH62 0wU2kmQChWCmbw7rOrwTGQgL1H5tg+Bmj9g== X-Google-Smtp-Source: AGHT+IHexK94NPWoWCrwjuk3gIAjHKSuKZUcH35FtgtMhup7hPhQojKoYZ1y3LzApeF9bdhKrTjgdQ== X-Received: by 2002:a05:6402:1e8c:b0:620:894c:656c with SMTP id 4fb4d7f45d1cf-620894c7c6fmr28663a12.29.1756973490788; Thu, 04 Sep 2025 01:11:30 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Reinoud Zandijk , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Huacai Chen , Zhao Liu , Paolo Bonzini , Alistair Francis , qemu-arm@nongnu.org, Fam Zheng , Helge Deller , Matthew Rosato , Fabiano Rosas , qemu-rust@nongnu.org, Bibo Mao , qemu-riscv@nongnu.org, Thanos Makatos , Liu Zhiwei , Riku Voipio , Cameron Esfahani , Alexander Graf , Laurent Vivier , Harsh Prateek Bora , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-ppc@nongnu.org, Stafford Horne , Sunil Muthuswamy , Jagannathan Raman , Igor Mammedov , Brian Cain , Phil Dennis-Jordan , devel@lists.libvirt.org, Mads Ynddal , Elena Ufimtseva , Peter Xu , Jason Herne , Michael Rolnik , Weiwei Li , Laurent Vivier , Ilya Leoshkevich , qemu-block@nongnu.org, Peter Maydell , Kostiantyn Kostiuk , Kyle Evans , David Hildenbrand , "Edgar E. Iglesias" , Warner Losh , Daniel Henrique Barboza , John Snow , Yoshinori Sato , Aleksandar Rikalo , Alistair Francis , Marcelo Tosatti , Yonggang Luo , Radoslaw Biernacki , Artyom Tarasenko , Yanan Wang , Eduardo Habkost , Aurelien Jarno , Richard Henderson , qemu-s390x@nongnu.org, Alex Williamson , "Michael S. Tsirkin" , Ani Sinha , Roman Bolshakov , Manos Pitsidianakis , Chinmay Rath , Thomas Huth , Cleber Rosa , kvm@vger.kernel.org, Song Gao , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Halil Pasic , Eric Farman , Palmer Dabbelt , Leif Lindholm , Christian Borntraeger , Michael Roth , Mauro Carvalho Chehab , Jiaxun Yang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Mark Cave-Ayland , Marcel Apfelbaum , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Nicholas Piggin , John Levon , Xin Wang Subject: [PATCH v2 001/281] target/i386: Add support for save/load of exception error code Date: Thu, 4 Sep 2025 09:06:35 +0100 Message-ID: <20250904081128.1942269-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250904081128.1942269-1-alex.bennee@linaro.org> References: <20250904081128.1942269-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1756974012128124100 Content-Type: text/plain; charset="utf-8" From: Xin Wang 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 Link: https://lore.kernel.org/r/20250819145834.3998-1-wangxinxin.wang@huawe= i.com Signed-off-by: Paolo Bonzini --- 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= =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.47.2