From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231099; cv=none; d=zohomail.com; s=zohoarc; b=abbKbZ6XDqts3YlVOAKJGvQwX6uc2csvnkq/qcWy13hqrgr8ipv/QcFWOP4tuEvHm+NCR9KF9k6fRcKzNj9F3ILY1o/g0OnGyBfiQbM3i32Mm7t2VMq/ER3z95wVig3SJ23VTTCO8eWmA4mU5ujXqeCpDcITSNbdpEstrEF5mb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231099; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=esa002n+umgb+uuAEw0alWBlRbDUr7KFNDpQLc54GuA=; b=X8/86Nqb8NAXNtUWRQe5z5jnFrnQlSzq9TtBfXTEWNI6FEcF0zu6/5lZifOUWDdna4YwcLYWmA5qESVoWSjuy1bHbvCq6sxs9YbCQKQm8+wBqzBDV/JZy7woaZQaZ489ynvOxPiQ/sNFks8VciS+e6P99a4msqxVr56gZAKuLzw= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231098480114.11610426509742; Mon, 9 Nov 2026 05:31:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSx-0004fb-5l; Mon, 09 Nov 2026 08:31:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSY-0004cz-SI for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:58 -0500 Received: from st-2001g-snip6-11.eps.apple.com ([2a01:b747:3001:206::47] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPST-0004YD-6L for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:53 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id 1A6BC1801375; Mon, 09 Nov 2026 13:30:39 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id 10D3C1800E34; Mon, 09 Nov 2026 13:30:38 +0000 (UTC) X-ICL-RepId: 01a1c080-f7c3-77c6-89e6-9e888da8e987 X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpZHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231041; x=1825767041; bh=esa002n+umgb+uuAEw0alWBlRbDUr7KFNDpQLc54GuA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=HgI1xsXVIrEBRUMQLivdTvfgUU7PTuDQES98hXfUq//UWzMenXPuKSRWqOnNxMgwtegM5UsGLqNAsl9Wob8cJBGrmV33fiK/JPEMsCtGiDlVsxB4Fq0U/P8KFw4Na9saUicS9fQXuPMsrGisVeBACdQeH8O7bJjN4yBYRjC20MzAgoEtqIPXQVQrkaWtpcbsA51PTLl3hQyCaWTRn9ARIP02MICAimInYKYo0ngjZYQybYFvW9VpUtUG+LUwdW9XbgmvqALjET/6Alk4FGRKQPmiRpwvzc9J/r5FyI8ZJ+PB/0Zq5NCCgS6uZjHLNEih0NMaPtQRTCkdtwoZyvTQUg== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , Doug Cook Subject: [PULL 1/7] target/i386/whpx: fix VMX capability MSR values Date: Mon, 9 Nov 2026 06:30:29 -0700 Message-ID: <20261109133035.7985-2-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 3WckQtNHb1SXuUH6yxWRevFreVE0plJq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfXzfFJWFVPuMwz 8J7ejLvTAdzNzdyfsXI0DCnQ5MMSjWG8XgINJVjJ+ZioIJhkuXM7t0IuvbrcCDpcd+plOjL2E/l rb/a5JYBR4qSOllxf4/2Xfh9pwpRgKv8tqh8QyMBhzHcEJe2SjECIPWai12v/Vk1OLfQia8V/w8 MsHy69PgWS4tdIPn4XnTYz/S/ufm4XQij7ZdE8daMV6Mo1iee7rVpDMPpxmLkua7LV4l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5q0y0mEgBfvr3Q13H8fTduExxjhGdm2q9 heNJOGmnIrTdsohFyuZZ+VWzlV+MFeQJuM8SrBSx+GhHSe5vLfPi623ZsCRl09uMmWUQWA == 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::47; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231101418158500 Content-Type: text/plain; charset="utf-8" From: Doug Cook whpx_get_supported_msr_feature() had two bugs in how it reports the VMX control MSRs: - MSR_IA32_VMX_TRUE_PINBASED_CTLS and MSR_IA32_VMX_TRUE_PROCBASED_CTLS were queried using the non-TRUE capability codes (WHvCapabilityCodeVmxPinbasedCtls and WHvCapabilityCodeVmxProcbasedCtls). - For PROCBASED_CTLS2 and the four TRUE_* control MSRs, the raw allowed-0/allowed-1 pair was returned. The feature-word code expects only the bits that may be 1 but are not required to be 1. Apply the same transformation as kvm_arch_get_supported_msr_feature(); make_vmx_msr_value() adds the must-be-one bits back afterwards. As a result, with +vmx QEMU treated many VMX features the host does support (secondary controls, EPT, VPID, MSR bitmaps, ...) as missing, warned about each of them, and dropped them from the CPU model. The guest itself reads the VMX MSRs from the hypervisor, not from QEMU, so this did not change what the guest saw. Signed-off-by: Doug Cook Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index e3e672dcd1..3312dd8593 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -1452,10 +1452,10 @@ uint64_t whpx_get_supported_msr_feature(uint32_t in= dex) cap =3D WHvCapabilityCodeVmxEptVpidCap; break; case MSR_IA32_VMX_TRUE_PINBASED_CTLS: - cap =3D WHvCapabilityCodeVmxPinbasedCtls; + cap =3D WHvCapabilityCodeVmxTruePinbasedCtls; break; case MSR_IA32_VMX_TRUE_PROCBASED_CTLS: - cap =3D WHvCapabilityCodeVmxProcbasedCtls; + cap =3D WHvCapabilityCodeVmxTrueProcbasedCtls; break; case MSR_IA32_VMX_TRUE_ENTRY_CTLS: cap =3D WHvCapabilityCodeVmxTrueEntryCtls; @@ -1474,6 +1474,31 @@ uint64_t whpx_get_supported_msr_feature(uint32_t ind= ex) if (FAILED(hr)) { return 0; } + + switch (index) { + case MSR_IA32_VMX_PROCBASED_CTLS2: + case MSR_IA32_VMX_TRUE_PINBASED_CTLS: + case MSR_IA32_VMX_TRUE_PROCBASED_CTLS: + case MSR_IA32_VMX_TRUE_ENTRY_CTLS: + case MSR_IA32_VMX_TRUE_EXIT_CTLS: { + /* + * These MSRs hold the allowed-0 settings in the low half and = the + * allowed-1 settings in the high half. QEMU's feature words = want + * only the bits that can be one but do not have to be one, so + * apply the same transformation as + * kvm_arch_get_supported_msr_feature(); make_vmx_msr_value() + * restores the must-be-one bits later. + */ + uint32_t must_be_one =3D (uint32_t)val; + uint32_t can_be_one =3D (uint32_t)(val >> 32); + + val =3D can_be_one & ~must_be_one; + break; + } + default: + break; + } + return val; } return 0; --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231148; cv=none; d=zohomail.com; s=zohoarc; b=kz0uhIduRfeRsJwRhc+l2eFB2oh/A3dqv/t3Iqpcx1PUAtTvLLUC088awgf8Ol7o4tqyO/ug7XoLE6CJlHGY4oOsZJWBLMGc/h/0RTXlSvYGAlvL9gpD+l1vwwGNA5ivrtnN5TUAhLpci20mK/nazmKnSSanjB4Nj31xY2iSP1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231148; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=h06E3zBebDGKkNiR0+MMIDzb/mlZpYU2o+KvSJo9YoI=; b=AMzPfOJ5ppuSO1h2ySMoGjjOWj+KHCwVwqob9RnpZmP0HMW3XFQMnNuZrVmr6AGdOiVol4Bv0AkUYu6LRg/Ux5zbImUlHYaEth2VxPoi0zPHnDlEJBykuyelKCfg2LEhrcysVX9ItSADdGr/1qe0tvlziHfM/dCnK85ejURc0iU= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231148845677.4383165102034; Mon, 9 Nov 2026 05:32:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSr-0004eJ-K7; Mon, 09 Nov 2026 08:31:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSX-0004cy-8C for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:58 -0500 Received: from st-2001h-snip6-3.eps.apple.com ([2a01:b747:3001:206::53] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPST-0004Ye-6k for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:52 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id E7F141800147; Mon, 09 Nov 2026 13:30:40 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id A3F821800128; Mon, 09 Nov 2026 13:30:39 +0000 (UTC) X-ICL-RepId: 01a1c080-fb4b-79ff-808b-e75625beb4db X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpYHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231043; x=1825767043; bh=h06E3zBebDGKkNiR0+MMIDzb/mlZpYU2o+KvSJo9YoI=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=KEQM8Qwy5CrvG/b1CLOAE5anYXHfGo3rlkg6fOv7Jc1jRchWfK67fNeojAWieLunjkdNyk4OKr+a2zdiZGnrERYKqGPyK6jpk/V5VApPq/hAXykq3C1eCQ5nJo66cMZZw3PPcxz5vRyAIDFZa04aQSIrRDr7WE2lpx5yG7mv9MqM21zACJLaiIty1JmVuw/Je5sJj1XRJiBptHfotZEc8TsWZduZPnQkTeLGVkVo/IaciYLm+pUoqad3ZIBSVtKD2zbMHhmb65oigB82JPwq0OYke6kdY7rV/glfU+T4Z0zsJbIL5mCw1l3Jd7NyRbrwlgJfnWLLZ6baM9MCRHXQPw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , "Doug Cook (WINDOWS)" Subject: [PULL 2/7] target/i386/whpx: whpx_get_xsave_state error handling Date: Mon, 9 Nov 2026 06:30:30 -0700 Message-ID: <20261109133035.7985-3-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: osuTtvIFSquNkYai71ZtPVBQpEhcrfBm X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfX/7DsGqPwg32s Q9m25D9pcUXabLw+jkz9udz7GE2vxOiWs4Ciogd9yhQftOIyY2R8yhYT1qYfRLxajvGjfJuYU6J KK+xi666lbM9GhQBKmx7/pLEO9ZRBW223dzW+JHoOVQN8aklf/671xIqfo1W3AnJuKBqTxlPAWo QJks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dbJDgXRiaUG1maAL9DWe0z7PAXEvXob kwWUM851n5HdxtEytFS6pZzyHVluGMajqFeCgPttESXuclzQEDINQAbwgY4G3FT35wOCNq mo7iJWyoecLBmYaQifvXAx8W1VdLsvwCKaK6p4vpm4j2P1YicNXWL2TY+DkrgmI/9de+bS w= 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::53; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231150392158500 Content-Type: text/plain; charset="utf-8" From: "Doug Cook (WINDOWS)" Several problems with error handling in whpx_get_xsave_state: - Does not handle WHV_E_INSUFFICIENT_BUFFER, which occurs frequently in practice for XSAVE state. - Does not free xsavec_buf when an error occurs. - Error message and return code use errno where they should use hr. Fixes: cfaa3b6c9597 ("whpx: xsave support") Signed-off-by: Doug Cook Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- include/system/whpx-internal.h | 5 ++- target/i386/whpx/whpx-all.c | 73 +++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/include/system/whpx-internal.h b/include/system/whpx-internal.h index c295c5a529..b15f3d8faf 100644 --- a/include/system/whpx-internal.h +++ b/include/system/whpx-internal.h @@ -58,8 +58,9 @@ void whpx_apic_get(APICCommonState *s); =20 #define WHV_E_UNKNOWN_CAPABILITY 0x80370300L =20 -/* This should eventually come from the Windows SDK */ -#define WHV_E_UNKNOWN_PROPERTY 0x80370302 +/* These should eventually come from the Windows SDK */ +#define WHV_E_INSUFFICIENT_BUFFER 0x80370301L +#define WHV_E_UNKNOWN_PROPERTY 0x80370302L =20 #define LIST_WINHVPLATFORM_FUNCTIONS(X) \ X(HRESULT, WHvGetCapability, (WHV_CAPABILITY_CODE CapabilityCode, VOID* = CapabilityBuffer, UINT32 CapabilityBufferSizeInBytes, UINT32* WrittenSizeIn= Bytes)) \ diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 3312dd8593..f5f5c3b462 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -442,8 +442,8 @@ static int whpx_set_xsave_state(const CPUState *cpu) =20 qemu_vfree(xsavec_buf); if (FAILED(hr)) { - error_report("WHPX: Failed to get virtual processor context, hr=3D= %08lx", - hr); + error_report("WHPX: Failed to set xsave state, hr=3D%08lx", hr); + return -EIO; } =20 return 0; @@ -809,9 +809,28 @@ static void whpx_get_legacy_fp_registers(CPUState *cpu= , WHPXStateLevel level) idx +=3D 1; } =20 -static int whpx_get_xsave_state(CPUState *cpu) +static HRESULT whpx_get_xsave_state_buffer(const CPUState *cpu, void *buf, + size_t buf_len, + UINT32 *bytes_written) { struct whpx_state *whpx =3D &whpx_global; + + if (!whpx_is_legacy_os()) { + return whp_dispatch.WHvGetVirtualProcessorState( + whpx->partition, cpu->cpu_index, + WHvVirtualProcessorStateTypeXsaveState, + buf, + buf_len, bytes_written); + } else { + return whp_dispatch.WHvGetVirtualProcessorXsaveState( + whpx->partition, cpu->cpu_index, + buf, + buf_len, bytes_written); + } +} + +static int whpx_get_xsave_state(CPUState *cpu) +{ X86CPU *x86cpu =3D X86_CPU(cpu); CPUX86State *env =3D &x86cpu->env; int ret; @@ -824,27 +843,43 @@ static int whpx_get_xsave_state(CPUState *cpu) xsavec_buf =3D qemu_memalign(page, xsavec_buf_len); memset(xsavec_buf, 0, xsavec_buf_len); =20 - if (!whpx_is_legacy_os()) { - hr =3D whp_dispatch.WHvGetVirtualProcessorState( - whpx->partition, cpu->cpu_index, - WHvVirtualProcessorStateTypeXsaveState, - xsavec_buf, - xsavec_buf_len, &bytes_written); - } else { - hr =3D whp_dispatch.WHvGetVirtualProcessorXsaveState( - whpx->partition, cpu->cpu_index, - xsavec_buf, - xsavec_buf_len, &bytes_written); + bytes_written =3D 0; + hr =3D whpx_get_xsave_state_buffer(cpu, xsavec_buf, xsavec_buf_len, + &bytes_written); + + /* + * whpx_get_xsave_max_len() returns the size of user state components + * enabled in XCR0. The hypervisor returns an XSAVES image, which also + * contains the supervisor state, so the whpx_get_xsave_max_len() size + * may be too small. + */ + if (hr =3D=3D WHV_E_INSUFFICIENT_BUFFER && bytes_written > xsavec_buf_= len) { + qemu_vfree(xsavec_buf); + xsavec_buf_len =3D bytes_written; + xsavec_buf =3D qemu_memalign(page, xsavec_buf_len); + memset(xsavec_buf, 0, xsavec_buf_len); + + bytes_written =3D 0; + hr =3D whpx_get_xsave_state_buffer(cpu, xsavec_buf, xsavec_buf_len, + &bytes_written); } - if (FAILED(hr) || bytes_written =3D=3D 0) { - error_report("failed to get xsave state: %s", strerror(errno)); - return -errno; + + if (FAILED(hr)) { + error_report("WHPX: Failed to get xsave state, hr=3D%08lx", hr); + qemu_vfree(xsavec_buf); + return -EIO; + } + + if (bytes_written =3D=3D 0) { + error_report("WHPX: Failed to get xsave state, no data returned"); + qemu_vfree(xsavec_buf); + return -EIO; } =20 - ret =3D decompact_xsave_area(xsavec_buf, xsavec_buf_len, env); + ret =3D decompact_xsave_area(xsavec_buf, bytes_written, env); qemu_vfree(xsavec_buf); if (ret < 0) { - error_report("failed to decompact xsave area"); + error_report("WHPX: Failed to decompact xsave area"); return ret; } x86_cpu_xrstor_all_areas(x86cpu, env->xsave_buf, env->xsave_buf_len); --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231096; cv=none; d=zohomail.com; s=zohoarc; b=A7NApi30c5q+KWx0nk2l1aFmQlH3dtzH21sxxqrMeizZhaIFya8vfHcow5zdVTgqAWubligaRXTxaHpTkMG/fOby7sDTAOF6Nr+OmhfgFLTvSdcqn0TlfA6hiAcIyvNZvs5Zti+pJLwUv4qOBIdomEdMYGSE72gdJYBeadxTwDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231096; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+gjfLSupQTIdyPGJix0uhYCN1wpSeNy8Pp3gpd3XAmc=; b=AcsR8duO7ZtS+wwD/tYtA0hh5Jpzjwuw4hb25SgJAWrMD7SDEm7LowcjpaChLgJARrRXGo33/x7WCs4lRoAK+Jb+Bz9jU6vwK1/712uYwgo8zUhDJzEbkt3Hz51ARm0X80xl/sZUDOodgEaszCNmdMJbrn16jyObU5TSlFBQ/dI= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231096042360.6998575143033; Mon, 9 Nov 2026 05:31:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSt-0004em-TI; Mon, 09 Nov 2026 08:31:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSX-0004cw-3J for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:58 -0500 Received: from st-2001a-snip6-11.eps.apple.com ([2a01:b747:3001:206::b] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPST-0004YN-6L for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:52 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id 2C1451801947; Mon, 09 Nov 2026 13:30:40 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id 4438C1801356; Mon, 09 Nov 2026 13:30:40 +0000 (UTC) X-ICL-RepId: 01a1c080-fc79-7203-94df-3c614f3728a9 X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpfHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231042; x=1825767042; bh=+gjfLSupQTIdyPGJix0uhYCN1wpSeNy8Pp3gpd3XAmc=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=tOAC6HNIKGFBoMazjbqbpx+w0I5JHFnPABpja+fmvKvGa7lTourvOe0tResXL+tkgAiUE+9aCYtpM9jemR5LCaLR64c7wwwGsPEGPIVRJ9cis+e0s7SloWAyDQufk6YmO4IFAXTwO+i17nksJSkNAK23XtaDYy8BPQgiKu8myEDcxBywKwR5zaC/yjLEV0kDJkAaufNhmVNqsBLlpb2YX/RshBNvaRJoThDcIU+KUD6VymXd66zbErfo76MKsOHw8uwxdb3XfFGC8aZuDl9MsdbRE7kXXTSoN81fusemu5vw8znF/Ce25fVFcip5ncNhwk3fJLiNnRCsYvpNDrdzMQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , Boden Randin Subject: [PULL 3/7] whpx: i386: avoid updating hflags for vmexits Date: Mon, 9 Nov 2026 06:30:31 -0700 Message-ID: <20261109133035.7985-4-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: jEa09K_xPzRrxhIYcC43r-IZAdAshfth X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfXzHonwojC9TBU 7aksJ3p1KUpql6Y0NuuGEh3RxnqtqDH/bvEAy3CO016RjFZFfKXRhRQu1St4a7kJi0qEeYOca71 1ooX/vnE/rBowNGVWm6APpMRWd9+t4ZMNz4OpkqImLLMlMVh4NF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G3 GPR70s5DvZktaRlnYNitj+uSIkY3bMWQpUeFHnyLu/QpBnzZdVvqZeAYWT/C/IYF31cF/N 3SnRQ21UxpcLRmbvFcqdrUvLRfci0YDLhqYlFFTKMOCFCjrpPLTESwZNPnaKX9Ug2BNXoM ZP3YCZd+sH00gPlXlrhMHjMnP1jiE0twBSmH/ueH4CEyVtqE8zWTvKx7kUcjoA6PUZlBe1 mBOmo7nWLn3uhV 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::b; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231099880158500 Content-Type: text/plain; charset="utf-8" From: Boden Randin whpx_get_registers_for_vmexit only refreshes GPRs, RIP and RFLAGS. x86_update_hflags() depends on state not refreshed here, while the code using the fast runtime state does not depend on the hflags it recomputes. Signed-off-by: Boden Randin Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index f5f5c3b462..fd3b2acb58 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -744,8 +744,6 @@ static void whpx_get_registers_for_vmexit(CPUState *cpu= , WHPXStateLevel level) rflags_to_lflags(env); =20 assert(idx =3D=3D RTL_NUMBER_OF(whpx_register_names_for_vmexit)); - - x86_update_hflags(env); } =20 static void whpx_get_legacy_fp_registers(CPUState *cpu, WHPXStateLevel lev= el) --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231133; cv=none; d=zohomail.com; s=zohoarc; b=cxaWPTbyMiTNYcistlO0mtrsAqPFLsaSn8BPAM2i3BDqmmVb76Bi3kzOf8lWpXp2X/BrEW9XQirj3e1bYtnKFJXN02LHh98Hf2rW/U/PvyMdVDmqAD74C9c1+ZF3Aq2G6kKdL9PwkPdHJwNz+jaeOMqhF5nGjdsy9YZIjlgUlag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231133; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+S++io4VssG+rPTlzHX32ycxfzct3zUCdoQhTzuuREU=; b=bAq8+ZikSEFeye/514sMR2lOjkcvsxs6rOH+79AXTz6nk1AlpYDL/3X7oQn97YOq6et5dxbUHrEbPlceP3zq0cYurFJFn47SSO1JdXtm15lw8jyJyccEIDNKXa4gBdLlx9suKjElxkZy2e5ei3uyaLo2eySErqe9TO4AgqnuN/o= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231132927951.8159333839718; Mon, 9 Nov 2026 05:32:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPT7-0004hS-5C; Mon, 09 Nov 2026 08:31:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSc-0004dl-UI for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:59 -0500 Received: from st-2001b-snip6-11.eps.apple.com ([2a01:b747:3001:206::15] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSY-0004Zy-LF for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:57 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id 342671801362; Mon, 09 Nov 2026 13:30:41 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id D925E180196E; Mon, 09 Nov 2026 13:30:40 +0000 (UTC) X-ICL-RepId: 01a1c081-0023-77f7-926b-03e3e9828551 X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpeHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231045; x=1825767045; bh=+S++io4VssG+rPTlzHX32ycxfzct3zUCdoQhTzuuREU=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=OLjmhE87EJuA2IxTXZUkO2dl0TzyGXtfWQJWar9sBfRPlJqaUxFreyYlhZd+cJWp7kUv8bYz6zr04VfNrlblj16KNvrrN1Q0BIVzGMWFmVPYXa/KGtZUcE4wcMF270l2qyFB4O6oUsCT5x9CrAlFy7fxn73uHqJw7xsCtLrLqCEoztB/6F6YEnshdur1D50g8Es6R9fUN4xY4AVXJzC4dpmogOoOmx30NOZ2BlWC1pKKgnTKzpWKRn5OIgYpmvnwapWTZ3y1ROSYKdE4ZaXEVM7dCriowob7qoyJl9QTU6YOQYwM1kWAu3zTEHKNV+wbCXfGfucYvkiv3TMAxH0eIw== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , "Doug Cook (WINDOWS)" Subject: [PULL 4/7] target/i386/whpx: handle processor reset Date: Mon, 9 Nov 2026 06:30:32 -0700 Message-ID: <20261109133035.7985-5-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: Ol3aB5SxrWp76yC9kJlORhdYEpvGP5Lh X-Authority-Info-Out: v=2.4 cv=ZbUQ98VA c=1 s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iIHg3rytUlh9MYK27qNpFrtMWUdspd I1/w4Qg5EFb2JKke+PuOg4he1afGB+z4F9NIgSchKIB8XyNGPFMG5J3kjwESPDfLgah5QY PA5tCBnIZ/ni/q5MxIAGC/EqhT0iEvtgCoVB8iHdYJHbB03FS8GU31T4UavAgX9G5curiV jEoTQf3dLcHT1G393YK1acLiwzOeoqRTMHbvnGx8Al/0Yubal2ayxa99rzW2snkKGN4HwU onF1QQOAyC3GHdd9i6AoeA9xinp3KOL+tMSCyW+PgEeeioSC7wN8DKE3ivHaIXRUhKs1Ym 7QLhysz8pwQpQKXIT+JG2IlMycJk5wyOF0NS0gePAP1a5zDFrwn1nhOjKgKO6o1U+9CqeS 1Q 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::15; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231136058158500 Content-Type: text/plain; charset="utf-8" From: "Doug Cook (WINDOWS)" WHPX is not properly handling processor reset: - Does not reset partition, so several registers (e.g. Hypercall, GuestOsId) carry values forward as "Locked" into the next session. - Does not clear hypervisor-managed TSC deadline (live-lock). - Does not re-arm the wait-for-SIPI trigger, so all CPUs start running immediately after reset. Some firmware may tolerate this, but OVMF does not. Typical result is that boot hangs or ends in triple-fault, e.g. qemu-system-x86_64: WHPX: Unexpected VP exit code 4 After this patch, I am able to boot to Windows desktop, reset, and boot back to Windows desktop. Tried many times in sequence with no problems. Used several different reset mechanisms (OS shutdown menu, external "reset", watchdog reset) with no problems. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2402 Signed-off-by: Doug Cook Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index fd3b2acb58..366de31273 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -528,6 +528,35 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel = level) =20 assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); =20 + /* Assumes that cpu_synchronize_all_post_reset() runs cpu 0 first. */ + if (level =3D=3D WHPX_LEVEL_RESET_STATE && cpu->cpu_index =3D=3D 0) { + hr =3D whp_dispatch.WHvResetPartition(whpx->partition); + if (FAILED(hr)) { + error_report("WHPX: Failed to reset partition, hr=3D%08lx", hr= ); + } + } + + /* Reset hypervisor-owned TSC deadline. */ + if (level =3D=3D WHPX_LEVEL_RESET_STATE) { + WHV_REGISTER_VALUE tsc_deadline =3D {}; + + whpx_set_reg(cpu, WHvX64RegisterTscDeadline, tsc_deadline); + } + + /* + * Re-arm partition's wait-for-SIPI state. + * whpx_vcpu_run() ignores cpu->halted, depends on SIPI for this. + * This must follow WHvResetPartition. + */ + if (level =3D=3D WHPX_LEVEL_RESET_STATE && whpx_irqchip_in_kernel()) { + WHV_REGISTER_VALUE activity =3D {}; + + whpx_get_reg(cpu, WHvRegisterInternalActivityState, &activity); + activity.InternalActivity.StartupSuspend =3D !cpu_is_bsp(x86_cpu); + activity.InternalActivity.HaltSuspend =3D 0; + whpx_set_reg(cpu, WHvRegisterInternalActivityState, activity); + } + /* * Following MSRs have side effects on the guest or are too heavy for * runtime. Limit them to full state update. --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231154; cv=none; d=zohomail.com; s=zohoarc; b=WzZ5hsjBpiYwlhDfNYw1IzfR0uAWS5CF+aZKzSP98a4kXu2jvoOaTJt96tha8Ruq67tbDZ3uJsYwIT7u7FmxkPfGpMxsqeJI1j+xooyk9WZBTK2Zaitsg4JAWLH9saFLIVaoDOgD1g4DXodIci2CFktbYqANf81Mf3MkhBQk5Pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231154; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bTKVivCfk0zPNIlppSC60Pkf3PjbfcopsoBtzEoeVMA=; b=PhX54UopSKGcyiS47DQpxmacUkOPqfsBg4emHh15+xiIgaq55dWr5ay+QUmkvT0UKrUkXr1KD1eXTMbBj5vCHxzkwROw6BpH9tIOlFENtwxGBTR1WYeAkgm6yUVDaZc4IQkIzjbTY2aB04lNnscjcG2Ap+mE1iItLxn8ZK9rXZM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231153910101.74785012427935; Mon, 9 Nov 2026 05:32:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSr-0004eI-Jh; Mon, 09 Nov 2026 08:31:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSY-0004d1-Ss for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:58 -0500 Received: from st-2001b-snip6-3.eps.apple.com ([2a01:b747:3001:206::17] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPST-0004Yq-6l for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:54 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id 768CA1801356; Mon, 09 Nov 2026 13:30:42 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id 6B3F2180137F; Mon, 09 Nov 2026 13:30:41 +0000 (UTC) X-ICL-RepId: 01a1c081-014b-76bc-8536-f723b27e3540 X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpdHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231044; x=1825767044; bh=bTKVivCfk0zPNIlppSC60Pkf3PjbfcopsoBtzEoeVMA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=YTATMwcdJk0Fz0cqnaIA3eHba0p/Z9oDRcnE8EsmPcnBSWRGSUea6YH5gyzI4/3Y6Mv+c4I+2PLrBwFiHVJpXcaP4WS9RHPKUz7v8B4j0Em61hblaAWQFQspfH3BGZozy50ijTDpz4powzWL3dLFP7PTLA2/W14fVtyFUC85HHdRdmkD2Gt1akrKmFi1MKFpHYYh/HPhh9R78pwL4Xn/b74/GwDUXjKjny0pNge4JDXhemhUVoI5KTLuglAeYP/qfUIz8krIAjFCEVfV0nwUn5EMqVJJ0Yx3lCG6g0jTJPJinX6+KSjyT70p23v4EZ1kb+SRf+5CT5wEFQslQvyY0Q== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , Kostas Chatzikokolakis Subject: [PULL 5/7] whpx: i386: forward the dynamic EBX of CPUID[0xD] sub-leaves 0 and 1, not 1 and 2 Date: Mon, 9 Nov 2026 06:30:33 -0700 Message-ID: <20261109133035.7985-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfX/8ZOgpmcqnTz cTMvd0/U2m5r5HkqgzKSrxwhe+mJekRz0SeHI+nWiMv8ZV96nfKEDfpS51tIZgFEhvbRcqw0ljK FGwHn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sry69fbgl4nYO6RYnWKV9YjV6gHgHz/0h08vD+Axj2q4vbAsgMGxFe6Mr r/31b8Z+q9JILhqnRaEJ17L25EcYsSAmiBLXcRd48HRE+JpJUEFzOvaXsadaXxnbBlI69M C58LyNb/Zrxr130agAhnjoSHNlRUn55Pjv1lYIB9nDozw72GtAYYiYL7C9NLi3okFnAmig xVmbePA0IB/cXs5bC5MjG0pPdHGCMDB5tZhPO8D1axE3Ud2MpL7Zo+I85oXDcXGgmjV2vR a28riSyOZFvPBZFV2dqA3yEmldn5IkZaVG4w905IiWSwxhXy6IGV0apIkIIYo7D+/XayR+ MALTAO8AmHLyJXN8c82oYjQ7mrPj0xi5qvYgW9OWwmQdejog== 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::17; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231156309158500 Content-Type: text/plain; charset="utf-8" From: Kostas Chatzikokolakis CPUID[0xD,0].EBX is the size of the XSAVE area for the guest's current XCR0, and CPUID[0xD,1].EBX the size for XCR0 | IA32_XSS: those are the two values that depend on guest state. For sub-leaf 2 and up, EBX is the component's offset in the standard format, a constant. whpx_vcpu_run() forwards Hyper-V's DefaultResultRbx for sub-leaves 1 and 2 instead. Sub-leaf 2 is harmless: QEMU's own offset was read from Hyper-V at vCPU init. Sub-leaf 0 is not: QEMU computes it from env->xcr0, which WHPX refreshes only in whpx_get_registers(), never on a CPUID exit, so after the guest's XSETBV the leaf still reports the size for the reset XCR0, 576 bytes. A Linux guest on a host without XSAVES takes that as its kernel XSAVE size, fails the consistency check against the size it computed from the component offsets, disables XSAVE and panics on the fallback path: XSAVE consistency problem: size 832 !=3D kernel_size 576 WARNING: CPU: 0 PID: 0 at arch/x86/kernel/fpu/xstate.c:638 fpu__init_syst= em_xstate x86/fpu: XSAVE disabled BUG: kernel NULL pointer dereference, address: 0000000000000010 RIP: 0010:fpstate_reset+0x1a/0x90 Kernel panic - not syncing: Attempted to kill the idle task! Every CPU model with XSAVE is affected there (-cpu max, Haswell, SandyBridge); models without it (Westmere, Nehalem, qemu64) boot. A host with XSAVES boots because Linux takes the compacted size from sub-leaf 1, which is forwarded; sub-leaf 0 is stale there too. Reproduced on an Intel Core i5-4440 (Haswell) under Windows 11 Home build 26300 with QEMU 11.1.2 (the code is unchanged on master), guest Linux 6.18. With this patch the guest enables xstate 0x7 at 832 bytes and boots with -cpu max. An AMD Ryzen 9 7900X under build 26100, not affected before, still boots with the patch, enabling 0xe7 (compacted, 2432 bytes). Fixes: 79b3cb1f0145 ("whpx: i386: introduce proper cpuid support") Signed-off-by: Kostas Chatzikokolakis Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index 366de31273..e14fce74d6 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2706,10 +2706,14 @@ int whpx_vcpu_run(CPUState *cpu) } } =20 - /* CPUID[0xD,{1,2}].EBX are dynamic depending on guest feature= s. */ + /* + * CPUID[0xD,{0,1}].EBX are dynamic: the XSAVE area size for t= he + * guest's current XCR0, resp. XCR0 | IA32_XSS. For sub-leaf >= =3D 2, + * EBX is the component's fixed offset, which QEMU already rep= orts. + */ if (vcpu->exit_ctx.CpuidAccess.Rax =3D=3D 0xd) { - if (vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 1 - || vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 2) { + if (vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 0 + || vcpu->exit_ctx.CpuidAccess.Rcx =3D=3D 1) { reg_values[4].Reg64 =3D vcpu->exit_ctx.CpuidAccess.Def= aultResultRbx; } } --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231138; cv=none; d=zohomail.com; s=zohoarc; b=mSuF7pLK9LlWiVHQB4TQEXISEzcU3IK2gOp0hgn12fZUUCLPdwMDWe5lwWE15jJhC8xV10m6jkToqXWyKspAMQSwm/y7/7RNyUIKasqhgFlE2ftD+GHR9G7TuX93mrQDkbpNXZ0DSl7M+7kCNOn6p+NB5CYKsViRJ7cD3qWTs9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231138; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SJsiKhxQGi4n2J2TRm6+9Ts2Kj0gCyIqXjJEDLbcS3I=; b=iCnJ9wsVppolCWXpKfB3zcbAmIrRhu60dB8cjo07XwczLQ/gw8jFpauZ4X8J8QoEeazs4RnO9Acyy5kbmQ5Jg6jFVTcPh9G7E/52w85uhPA9P6029fGGNtL7XLpNqrLfpDaplk2S3RZvebgRd5PVO3caloqu59ZCDia0UOJuUko= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231138829395.4180200880421; Mon, 9 Nov 2026 05:32:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSz-0004gQ-Ud; Mon, 09 Nov 2026 08:31:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSg-0004dx-Bw for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:31:03 -0500 Received: from st-2001k-snip6-5.eps.apple.com ([2a01:b747:3001:206::6a] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSY-0004a8-Lg for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:59 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id 4A56C1800E2C; Mon, 09 Nov 2026 13:30:42 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id 0AE851801958; Mon, 09 Nov 2026 13:30:41 +0000 (UTC) X-ICL-RepId: 01a1c081-041a-75c8-b748-7fd9a90d55f6 X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpcHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231047; x=1825767047; bh=SJsiKhxQGi4n2J2TRm6+9Ts2Kj0gCyIqXjJEDLbcS3I=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=JeVmhYB5qzVsZ39PuNUezFauG3rvK8ffJqahOQQQ/PiB1E36UB8boLX2569djv8xWvcCn3kWzoLuJZDfWXUFSZi5kdClbTVwmAHM9jFbMnULsMVhSI5WgbSTlwwo4FxQ21fGKcIkdQVrho1ux4BIiFIka4byIIAum53Beg9fHswvoKSCoS/PSZ0KtnwV9fKNUCBChserZ7tmLGI22P03wlZ1bk7Ojv2Nj4FMBWe+o1dDf51qsG58zV0zewdJp7yNw+XVTaS6DWgYIfS/ZHHwIl/xiC0gvpNvbvSNpK0nW8XP0DY+ADVc/Z3kDV8K6SBbn3UdqtQcTm+l86+eWabB8w== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , Akshey Taneja Subject: [PULL 6/7] whpx: i386: do not require ProcessorFeaturesBanks on legacy Windows Date: Mon, 9 Nov 2026 06:30:34 -0700 Message-ID: <20261109133035.7985-7-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=UuJu9uwB c=1 sm=1 tr=0 ts=6af1cb05 cx=c_apl:c_pps:t_out a=oyWFxbOnq+dmhQrAPgaJYA==:117 a=oyWFxbOnq+dmhQrAPgaJYA==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=pGLkceISAAAA:8 a=gf5HlC0yx7l-uUfkWeAA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfX6fZXKLrDKEub slmOnvBpZ0UNnG1G5u+4HfAQBXK/3igedU3eHlOkSoUr9K+m8Nub/15tfCXsBwMJA1Vbf220ogI /8FSia0HY01RfjhJedRbKxDFcIf+qKnILFFccww4meH/H1eQwLIfZeueAaw44CcsIFrNmxqb1SZ fVQxYyxv/n/c6vocPn6+4eF7teqfAxJCm7Hbk3ZDvFIlVQxQhNuWb5qoePzdb0LuJjjA9xsJrrP t1jCw93iLe3YBNjBVjQSGbKbZzbXvyB3x5a5fAL867auz89f2hjxLohZt0NIDNM36qLJSVjbkai KjPKu5oQ2r+ZQMK/JDptd+CtHv/Jkvk7Re0YYbF7300DVPQqrLD/yz3YO9/MsU= X-Proofpoint-ORIG-GUID: T1IgJx4qWJYbgSG0603754CVaCLZ6M7a X-Proofpoint-GUID: T1IgJx4qWJYbgSG0603754CVaCLZ6M7a X-JNJ: AAAAAAABk588P7BcAcVLH/dZSf3cZ70gPGEXjw8ELwR65TAU/zqCMbIm0oBmmF7hJ9ulOR UYy8p+49cn1YHLq1P3KxQgS52bOLjiD0yvVAHTKUkiOsa6wqQmPmkJwHy4Fkb0UxYHAkfi 39TPDjYKQxz3hOMBxqkfLkO1KFZbfJkD9dyIjlGauUmhfud0h4wLCGB4yrbDYP2TXUPi4j LO0Dz9J7wWQw+RKfuSMy3mANZ1fJ+WFLx3ndPnqUf4xoJubmwrtyGAaYmlruJauvcbaHVa 4AEGAOF2b9b0YjNzNauAtqV2AnY72ZvkTJRCvAHdBeWgIefm/1lRaXBh/+WE/DzDC9w1iP tpMAuFbcquL4ZKpjGyuhM/kzUMwV6y3kOGwkzCVWlgD4v1b+aruWRrg4XTndoeOkkLz/9V mcCoPKXtSrDVCgxbTD1KWC4I2mGHA4RSUkHz56npESUJGJhUdBUuO4aAJSGuLf4fooknwY SAT/7hVaFCM85vq49Rk2XOuEA+FwlwRLfFUCYDJt6dX7ZlFJ7fY7rtGcKZ0uAY9kPgXuQx YGnZyxxe7ho5WDuQMz6eeYYkRUsCKwngfkw/jAhcrPtyZtmSDxAn28lkaKT13TK6V++1Sq QPTakKPE1d0k8CiBGl4u+vu3LqvjTHDuEiV/cM2x056fE2LFgHpgE082UI7DLCcmNpxUof YsAW+CTdqQc1MYLn5MOd1wh/mddhgXwVafTX9oQvcvyY6UgC6jMkZDd0d/Sf0AaAx6j5hp 2ABlBpxDiBwa23vxWncvLC9T04LXo= 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::6a; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231140118158500 Content-Type: text/plain; charset="utf-8" From: Akshey Taneja WHvCapabilityCodeProcessorFeaturesBanks and the matching partition property are implemented starting from Windows 10 version 20H1. On earlier Windows 10 releases, the capability query returns WHV_E_UNKNOWN_CAPABILITY (0x80370300) and whpx_accel_init() aborts with -ENOSPC, reported to the user as "failed to initialize whpx: No space left on device". This regressed older Windows 10 releases in 8b87283ce4 ("whpx: i386: enable all supported host features"). Fall back to the original single-bank WHvCapabilityCodeProcessorFeatures on legacy hosts and skip the corresponding SetPartitionProperty, which restores the pre-8b87283ce4 behaviour there. Reported on Windows 10 Enterprise LTSC (version 1809, build 17763) Signed-off-by: Akshey Taneja [Editing patch for reflecting the availability of this API, which is available in Windows 10 version 2004 onwards] Reviewed-by: Mohamed Mediouni Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 61 +++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index e14fce74d6..b386368f1d 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -3245,13 +3245,34 @@ int whpx_accel_init(AccelState *as, MachineState *m= s) memset(&processor_features, 0, sizeof(WHV_PROCESSOR_FEATURES_BANKS)); processor_features.BanksCount =3D 2; =20 - hr =3D whp_dispatch.WHvGetCapability( - WHvCapabilityCodeProcessorFeaturesBanks, &processor_features, - sizeof(WHV_PROCESSOR_FEATURES_BANKS), &whpx_cap_size); - if (FAILED(hr)) { - error_report("WHPX: Failed to get processor features, hr=3D%08lx",= hr); - ret =3D -ENOSPC; - goto error; + if (whpx_is_legacy_os()) { + /* + * WHvCapabilityCodeProcessorFeaturesBanks is implemented starting + * from Windows 10 version 20H2 (19041). Fall back to the single-b= ank + * capability on earlier Windows 10 releases. + */ + WHV_PROCESSOR_FEATURES legacy_features =3D {0}; + + processor_features.BanksCount =3D 1; + hr =3D whp_dispatch.WHvGetCapability( + WHvCapabilityCodeProcessorFeatures, &legacy_features, + sizeof(legacy_features), &whpx_cap_size); + if (FAILED(hr)) { + warn_report("WHPX: Failed to get legacy processor features," + " hr=3D%08lx", hr); + } else { + processor_features.Bank0 =3D legacy_features; + } + } else { + hr =3D whp_dispatch.WHvGetCapability( + WHvCapabilityCodeProcessorFeaturesBanks, &processor_features, + sizeof(WHV_PROCESSOR_FEATURES_BANKS), &whpx_cap_size); + if (FAILED(hr)) { + error_report("WHPX: Failed to get processor features," + " hr=3D%08lx", hr); + ret =3D -ENOSPC; + goto error; + } } =20 whpx_rdtsc_cap =3D processor_features.Bank0.RdtscpSupport; @@ -3298,15 +3319,23 @@ int whpx_accel_init(AccelState *as, MachineState *m= s) } } =20 - hr =3D whp_dispatch.WHvSetPartitionProperty( - whpx->partition, - WHvPartitionPropertyCodeProcessorFeaturesBanks, - &processor_features, - sizeof(WHV_PROCESSOR_FEATURES_BANKS)); - if (FAILED(hr)) { - error_report("WHPX: Failed to set processor features, hr=3D%08lx",= hr); - ret =3D -EINVAL; - goto error; + /* + * The matching partition property is available on Windows 10 version + * 20H2 (19041). and later. Rely on the whpx_is_legacy_os() check to + * enable this code only on Server 2022 or Windows 11. + */ + if (!whpx_is_legacy_os()) { + hr =3D whp_dispatch.WHvSetPartitionProperty( + whpx->partition, + WHvPartitionPropertyCodeProcessorFeaturesBanks, + &processor_features, + sizeof(WHV_PROCESSOR_FEATURES_BANKS)); + if (FAILED(hr)) { + error_report("WHPX: Failed to set processor features," + " hr=3D%08lx", hr); + ret =3D -EINVAL; + goto error; + } } =20 =20 --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:34:10 2026 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=reject dis=none) header.from=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1794231151; cv=none; d=zohomail.com; s=zohoarc; b=PP+rHp+ZAl6vIBDTysKuVzFALWzx+izJfv/cdnWUME8Y3epEWDn0NBpQnUO1+BB7o/uQEWEqJPQroBE/SVPcRY4uKufBNkYME4ioKLVNCQl0/FegaCIGri86UXK+xUyK4V/17q9tOXa3g1G9peX+6xPzJOzJmDXmSTJ8ie01RDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794231151; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wmPIzf1jg2PnIDoQSl7uyALTt38GJaFl9tv4frcQEJA=; b=E8h5024HOxZk2At8CQQUPDmq2vhsor2QkRH1A7zGN7sv6QznQok8hPNWFLykSe8os23SB2r0H4dxBjy4rKaRYp4nGb7IOdT7Y3w48tSzbeBKp2GZfUxggc9tQexlIPXt0HvR2IQdRLe2XA+CEtKVjuqDVEbYLxD+x9PJU/CgFU0= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794231151445118.93844648631818; Mon, 9 Nov 2026 05:32:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQPSt-0004el-Qo; Mon, 09 Nov 2026 08:31:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSb-0004dB-09 for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:58 -0500 Received: from st-2001l-snip6-11.eps.apple.com ([2a01:b747:3001:206::79] helo=outbound.st.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQPSX-0004Zz-K2 for qemu-devel@nongnu.org; Mon, 09 Nov 2026 08:30:55 -0500 Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPS id A740D1800E3A; Mon, 09 Nov 2026 13:30:43 +0000 (UTC) Received: from localhost.localdomain (unknown [17.156.216.30]) by p00-icloudmta-asmtp-us-east-1a-100-percent-10 (Postfix) with ESMTPSA id A4A9B180137A; Mon, 09 Nov 2026 13:30:42 +0000 (UTC) X-ICL-RepId: 01a1c081-0619-7353-a8cb-fc76f51df67f X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQtIBUMGWgReC0wHQwJZEhVdRV4CXwpfFV04RgNHGVcUUBtHDFUHV15fChMLU1ZHHkkKVgleCEYRWxRWQ1EZEgJaRQdNXw5eHwQXRhlVBEceXVZAGRkCURxWDVdDVARfUEkMQVBsWgBHF0gdXRlZb1BdHA4YWRtAFV0RUBlWCV4VFx5BTVoCVk0FSgNfAVoDQABJAF4HWAdeDkELWBpTHx1WEFIAUg9yBVcIQQhTAlEEWBpfCBkNQE4ZDEodUlZRBUoMXABoD10dWBFd Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1794231046; x=1825767046; bh=wmPIzf1jg2PnIDoQSl7uyALTt38GJaFl9tv4frcQEJA=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=yZujYE0cvNvipRst2syejENR+zWLBv4CHQddf3b5jhOYw3Txo4XOyVe1ubJEyYZ0I3EBtIsoBNmA0lJvKLWn8V8pMV0dfsZDwLt+z+e7YKKAyPeBCggL1sG5ngrV05q9OFBbL3RgZpAHZopGCAEOeSqIeVV114ZmBXs+/pi88/DLnvbtG+H7et67qYtSFqlmkfv+vF/PvnKB7R2dAqfTE+1FKujum6cpZXfhGxfoWcI+lL6+aohOF6wacRHPsmXYjqbyiQ9i3oZ1HLTXgP1Og6v6QM4xt6/Zdd6l3R1czodFPO8L3dl82qjVcLFRa1dyl4n8rA9tq6nus30QkF/yrA== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Pedro Barbuda , Mohamed Mediouni , Akshey Taneja Subject: [PULL 7/7] whpx: i386: fall back to xAPIC when the MSR exit bitmap is unavailable Date: Mon, 9 Nov 2026 06:30:35 -0700 Message-ID: <20261109133035.7985-8-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261109133035.7985-1-mohamed@unpredictable.fr> References: <20261109133035.7985-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: TM57wAsEUFrJMw3Uh2wbS1oBoVIkcRhL X-Authority-Info-Out: v=2.4 cv=dP+rWeZb c=1 sm=1 tr=0 ts=6af1cb03 cx=c_apl:c_pps:t_out a=oyWFxbOnq+dmhQrAPgaJYA==:117 a=oyWFxbOnq+dmhQrAPgaJYA==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=pGLkceISAAAA:8 a=LzqnFUZUDoiWbgQmKAQA:9 X-Proofpoint-ORIG-GUID: TM57wAsEUFrJMw3Uh2wbS1oBoVIkcRhL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA5MDA1MyBTYWx0ZWRfXzAlsqSERl9P/ bj4YIB3KIvxHkK7CIyKV5c+cvebaH81q3j+3sr5rPIAsBGDPx57YcHLzkl/+DAmnEO/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g53VjkghEw87B1Yrw= 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a01:b747:3001:206::79; envelope-from=mohamed@unpredictable.fr; helo=outbound.st.icloud.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, SPF_HELO_PASS=-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: qemu development 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 @unpredictable.fr) X-ZM-MESSAGEID: 1794231152378158500 Content-Type: text/plain; charset="utf-8" From: Akshey Taneja WHvPartitionPropertyCodeX64MsrExitBitmap is not implemented on Windows 10 version 1809 and earlier, where WHvSetPartitionProperty() returns WHV_E_UNKNOWN_PROPERTY (0x80370302) and whpx_accel_init() aborts with -EINVAL. QEMU started requesting it in ba1bda25b7 ("whpx: i386: x2apic emul= ation"). Treating the failure as non-fatal is not sufficient on its own: whpx_default_props unconditionally enables x2apic, and x2APIC is reached through MSRs, so without MSR exits the userspace LAPIC never observes the guest's APIC accesses and the guest hangs immediately after the firmware hands over. Observed as a black screen with an Ubuntu 24.04 guest that otherwise boots in about 40 seconds. Record whether the MSR exit bitmap was accepted and, when it was not, apply x2apic=3Doff so the guest uses the MMIO based xAPIC, which is still intercepted normally. Reported on Windows 10 Enterprise LTSC version 1809 (build 17763) Signed-off-by: Akshey Taneja [Patch edited, version 1903 is the first release of Windows 10 with this AP= I] Signed-off-by: Mohamed Mediouni --- target/i386/whpx/whpx-all.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index b386368f1d..df1c772eb3 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -57,6 +57,7 @@ #define HV_X64_MSR_GUEST_IDLE 0x400000f0 =20 static bool is_modern_os =3D true; +static bool whpx_msr_exits_available =3D true; =20 static const WHV_REGISTER_NAME whpx_register_names[] =3D { =20 @@ -2981,6 +2982,16 @@ static PropValue whpx_default_props[] =3D { { NULL, NULL }, }; =20 +/* + * x2APIC is reached through MSRs, so emulating it in userspace requires t= he + * MSR exit bitmap. Hosts without that property must fall back to xAPIC, + * which is MMIO based and therefore still intercepted. + */ +static PropValue whpx_no_msr_exit_props[] =3D { + { "x2apic", "off" }, + { NULL, NULL }, +}; + =20 void whpx_cpu_instance_init(CPUState *cs) { @@ -2988,7 +2999,8 @@ void whpx_cpu_instance_init(CPUState *cs) X86CPUClass *xcc =3D X86_CPU_GET_CLASS(cpu); =20 host_cpu_instance_init(cpu); - x86_cpu_apply_props(cpu, whpx_default_props); + x86_cpu_apply_props(cpu, whpx_msr_exits_available ? whpx_default_props + : whpx_no_msr_exit_p= rops); =20 if (xcc->max_features) { whpx_cpu_max_instance_init(cpu); @@ -3396,10 +3408,20 @@ int whpx_accel_init(AccelState *as, MachineState *m= s) WHvPartitionPropertyCodeX64MsrExitBitmap, &prop, sizeof(WHV_PARTITION_PROPERTY)); + /* + * Earlier Windows 10 releases not implement this property. + * It is implemented starting from Windows 10 version 1903 (18362). + */ if (FAILED(hr)) { - error_report("WHPX: Failed to set MSR exit bitmap, hr=3D%08lx", hr= ); - ret =3D -EINVAL; - goto error; + if (hr =3D=3D WHV_E_UNKNOWN_PROPERTY) { + whpx_msr_exits_available =3D false; + warn_report("WHPX: MSR exit bitmap unsupported on this Windows= " + "version, falling back to xAPIC"); + } else { + error_report("WHPX: Failed to set MSR exit bitmap, hr=3D%08lx"= , hr); + ret =3D -EINVAL; + goto error; + } } =20 hr =3D whp_dispatch.WHvSetPartitionProperty( --=20 2.54.0 (Apple Git-157)