From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431841; cv=none; d=zohomail.com; s=zohoarc; b=QWOy45pa8o8x9Leqj7ItpO10WSs5XeIZM5ROvZdQey9ew6mTDO0kth+kN+N6zibPyUyuWQ60J8JtKqG3IS9LeAr7wG7g3CaLOvr5a2xf6t7g0SxdzUeMA9WFRb4Jdg4TtwweT1z/FxgUs7ilpuwEHSuGajG54U6RCtFTrvT21C0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431841; 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=5/j6ZxrftOyz3emrpZwyWgWN8/qV4mYhJCydAqBVQsI=; b=bxymC1ZX7vdG8Rdigg2WiMg3mvOfhfinmSEUYnp2BUohahaczoYlDHoBZTDQvAIY4p8LBl6ARbvxCPN/Zni8pLriUdpxfaKWwqtr4p9XKHSMbFPQdlxOLob/M5Pjcc03pH/JwBUr6eSLpr657arI4Wro0wUrzBao51z5K9bkqb4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431841611537.7425195095244; Wed, 10 Dec 2025 21:44:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSj-0000ak-UX; Thu, 11 Dec 2025 00:43:39 -0500 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 1vTZSd-0000Yy-59 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:32 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSa-00019T-DP for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:30 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:26 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431808; x=1796967808; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i0sp4wj5rSSd6tZSRimjqOo45WUYte6rhpv/w5HY6HQ=; b=NlGZwKJ4+ebg2VbOHbrI68xwuI4ewsylm/61RYMeGF8E6qGMSOnk3N4O det9r0YNl9Zjbj4x8RKw9p1Gaglhw4NwKGaaZNG63G1fezhlPy3JItBAu sFR1Yg411LAjtK+9+2heno8guzfcnJ6VdVQrOKMd8xWbHmSSbyrpJmMrR Qn4vMRCe2M3EiqX7zzUQ6TenEN0VIXHrhsqI7SDlnLo8GvaunfX5iLvnz iNQqDU5I0ZHE8kbuyE/XrlBiJl7Eno8Q/hsmZ1uyTwxsx+4cPgK0XrUPr cddAyfWD2ILoqats9zRcxCPqF/OcAS2LCVAhZSkl17DgVhEN/nOogMS7u A==; X-CSE-ConnectionGUID: yzt/03oVT3qlkUxuxxqcvQ== X-CSE-MsgGUID: ibAh+wQ0S7O4bW+brjjsVw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409805" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409805" X-CSE-ConnectionGUID: XTydjJdvQC+i0WPNLn9j+Q== X-CSE-MsgGUID: OcA4TglsQvmUMI9O4GLkuQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227365989" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 01/22] i386/cpu: Clean up indent style of x86_ext_save_areas[] Date: Thu, 11 Dec 2025 14:07:40 +0800 Message-Id: <20251211060801.3600039-2-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431844100158500 Content-Type: text/plain; charset="utf-8" The indentation style in `x86_ext_save_areas[]` is extremely inconsistent. Clean it up to ensure a uniform style. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.c | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 641777578637..c598f09f3d50 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2028,38 +2028,46 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COU= NT] =3D { .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_XSAVE, .size =3D sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader), }, - [XSTATE_YMM_BIT] =3D - { .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_AVX, - .size =3D sizeof(XSaveAVX) }, - [XSTATE_BNDREGS_BIT] =3D - { .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, - .size =3D sizeof(XSaveBNDREG) }, - [XSTATE_BNDCSR_BIT] =3D - { .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, - .size =3D sizeof(XSaveBNDCSR) }, - [XSTATE_OPMASK_BIT] =3D - { .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, - .size =3D sizeof(XSaveOpmask) }, - [XSTATE_ZMM_Hi256_BIT] =3D - { .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, - .size =3D sizeof(XSaveZMM_Hi256) }, - [XSTATE_Hi16_ZMM_BIT] =3D - { .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, - .size =3D sizeof(XSaveHi16_ZMM) }, - [XSTATE_PKRU_BIT] =3D - { .feature =3D FEAT_7_0_ECX, .bits =3D CPUID_7_0_ECX_PKU, - .size =3D sizeof(XSavePKRU) }, + [XSTATE_YMM_BIT] =3D { + .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_AVX, + .size =3D sizeof(XSaveAVX), + }, + [XSTATE_BNDREGS_BIT] =3D { + .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, + .size =3D sizeof(XSaveBNDREG), + }, + [XSTATE_BNDCSR_BIT] =3D { + .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, + .size =3D sizeof(XSaveBNDCSR), + }, + [XSTATE_OPMASK_BIT] =3D { + .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, + .size =3D sizeof(XSaveOpmask), + }, + [XSTATE_ZMM_Hi256_BIT] =3D { + .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, + .size =3D sizeof(XSaveZMM_Hi256), + }, + [XSTATE_Hi16_ZMM_BIT] =3D { + .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, + .size =3D sizeof(XSaveHi16_ZMM), + }, + [XSTATE_PKRU_BIT] =3D { + .feature =3D FEAT_7_0_ECX, .bits =3D CPUID_7_0_ECX_PKU, + .size =3D sizeof(XSavePKRU), + }, [XSTATE_ARCH_LBR_BIT] =3D { - .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_ARCH_LBR, - .offset =3D 0 /*supervisor mode component, offset =3D 0 */, - .size =3D sizeof(XSavesArchLBR) }, + .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_ARCH_LBR, + .offset =3D 0 /*supervisor mode component, offset =3D 0 */, + .size =3D sizeof(XSavesArchLBR), + }, [XSTATE_XTILE_CFG_BIT] =3D { .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_AMX_TILE, .size =3D sizeof(XSaveXTILECFG), }, [XSTATE_XTILE_DATA_BIT] =3D { .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_AMX_TILE, - .size =3D sizeof(XSaveXTILEDATA) + .size =3D sizeof(XSaveXTILEDATA), }, }; =20 --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431894; cv=none; d=zohomail.com; s=zohoarc; b=CkNWFPP6atYPyBBORUHhJ6MB4Xi6TAwAGh/bUo7LWCM2Gy7SAzowyJ4yRYr4clSpFqple5xbIZd0p9HbFBcOsH8S0D9Ws4kkeVktKFgPUy6uv/FzPiyXEduMKF7M2iAko1EgVimnzpr34XgDvrgB5V0U2B9V87n6t+XoEZHT1ME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431894; 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=WdCmexeUzRLAZZT7Gg+7cTcbHe7BaI6dy+Yu6dvpniY=; b=CnlJP4ZxFJ7QuIn+z1uQQJFTsG9tRBrFSjVFUl/5DK5IJxsydQ/e+jVc4piQTLpQ6WLnaUdueGQxtjrrOGoe8lYaS6SmKsZvIGUiTpksgmS0BgSuJhC31jUYHOzpB/5Qg1KJaQbdE5uwbyAwKGwf4HwCaIMQeHSm2U1Qd/C/2mw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431894219299.8520980293074; Wed, 10 Dec 2025 21:44:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSn-0000bm-Pe; Thu, 11 Dec 2025 00:43:43 -0500 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 1vTZSe-0000Z2-Tx for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:32 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSd-00019T-9h for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:32 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:30 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431811; x=1796967811; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=enKcO38L6D4368mFk9WuGh+dSr2WFd6BUxl4+hq0Pz4=; b=fZjlOb0ULvP6QQDwvE+krmUBzBp10laUEJnBgOHQr2gYXBQvoXlOwiWn b4tKTDRAsGTk6TnMy6gWik6E2pc6f7iQvLEymXGUJ9bZNRB5xzrvif/0T ipHcSJnjAQzw7uQ6pbT0VPIiDLbpVGncjESeFBCRO70cMbkpizDN4qanI RarKX+830cKk6sC5aF9x5yWimW+sbyRetPOol7aJL0VzyPTiO7GG8I4a0 XxpTDs0H2dnsgIgIpxduSqjYXr0cA6QPz9BtCuYGEn5Nk75zz43lXoVQ9 5LND0LT4yHDrEAfobweqUYx0qfKaqd/mZjJftWboe1Nu133V/CyySDR+q Q==; X-CSE-ConnectionGUID: EoPYCSLJRG+6irgrz3AEFg== X-CSE-MsgGUID: oRXe6Q/FQWubV7D+VNNsNg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409813" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409813" X-CSE-ConnectionGUID: lrkqon5iRo2SDWa7Pj3FrA== X-CSE-MsgGUID: QXPI0j7ORYqGIEJCmadyVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227365997" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 02/22] i386/cpu: Clean up arch lbr xsave struct and comment Date: Thu, 11 Dec 2025 14:07:41 +0800 Message-Id: <20251211060801.3600039-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431895948158500 Content-Type: text/plain; charset="utf-8" Arch LBR state is area 15, not 19. Fix this comment. And considerring other areas don't mention user or supervisor state, for consistent style, remove "Supervisor mode" from its comment. Moreover, rename XSavesArchLBR to XSaveArchLBR since there's no need to emphasize XSAVES in naming; the XSAVE related structure is mainly used to represent memory layout. In addition, arch lbr specifies its offset of xsave component as 0. But this cannot help on anything. The offset of ExtSaveArea is initialized by accelerators (e.g., hvf_cpu_xsave_init(), kvm_cpu_xsave_init() and x86_tcg_cpu_xsave_init()), so explicitly setting the offset doesn't work and CPUID 0xD encoding has already ensure supervisor states won't have non-zero offsets. Drop the offset initialization and its comment from the xsave area of arch lbr. Tested-by: Farrah Chen Reviewed-by: Zide Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.c | 3 +-- target/i386/cpu.h | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c598f09f3d50..34a4c2410d03 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2058,8 +2058,7 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT= ] =3D { }, [XSTATE_ARCH_LBR_BIT] =3D { .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_ARCH_LBR, - .offset =3D 0 /*supervisor mode component, offset =3D 0 */, - .size =3D sizeof(XSavesArchLBR), + .size =3D sizeof(XSaveArchLBR), }, [XSTATE_XTILE_CFG_BIT] =3D { .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_AMX_TILE, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index cee1f692a1c3..c95b772719ce 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1747,15 +1747,15 @@ typedef struct { =20 #define ARCH_LBR_NR_ENTRIES 32 =20 -/* Ext. save area 19: Supervisor mode Arch LBR state */ -typedef struct XSavesArchLBR { +/* Ext. save area 15: Arch LBR state */ +typedef struct XSaveArchLBR { uint64_t lbr_ctl; uint64_t lbr_depth; uint64_t ler_from; uint64_t ler_to; uint64_t ler_info; LBREntry lbr_records[ARCH_LBR_NR_ENTRIES]; -} XSavesArchLBR; +} XSaveArchLBR; =20 QEMU_BUILD_BUG_ON(sizeof(XSaveAVX) !=3D 0x100); QEMU_BUILD_BUG_ON(sizeof(XSaveBNDREG) !=3D 0x40); @@ -1766,7 +1766,7 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveHi16_ZMM) !=3D 0x400); QEMU_BUILD_BUG_ON(sizeof(XSavePKRU) !=3D 0x8); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) !=3D 0x2000); -QEMU_BUILD_BUG_ON(sizeof(XSavesArchLBR) !=3D 0x328); +QEMU_BUILD_BUG_ON(sizeof(XSaveArchLBR) !=3D 0x328); =20 typedef struct ExtSaveArea { uint32_t feature, bits; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431976; cv=none; d=zohomail.com; s=zohoarc; b=NOWJIXOztm5GkCQIc/t+Mut3HCzCaPmp0g3Fz6oHMKCzPYkN2PxuAD4dupH4s7PIfPtbQt/vfygw7A2c28a0UOE8kLEaGZiuMkNOw0RX+CSYxuhDzQVjXzq7Tz8PX7+u6+D114YsoFjXxlXtNvd6TjkaaqsOjCW0yoSCGAwaOuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431976; 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=PUzGhMCpvvUskw3s8rD6Zmb9hqhqAJiEWIHCn2gTX10=; b=XFC2k2vBrNDkmu0Wp0b3dNnDSTu3BeeiZkVu1IB7YPAqvdGqVLh0/qd9cHQatYV7mXDcJ6wXsP5DiZxlY4+OjBOQ4fv3gqXAHWItLBu/VZ8509PBcf+sHvO0JbWjpsrxu7n+CJS9P7ab9pUARy+yS3cirXrTUUweZzcxXylgO8E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431976122700.0017146615901; Wed, 10 Dec 2025 21:46:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSr-0000bp-BH; Thu, 11 Dec 2025 00:43:47 -0500 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 1vTZSk-0000at-1z for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:39 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSh-0001IB-35 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:36 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:34 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431815; x=1796967815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8C3Jr7X1l8TpBRvZp6B109oTdbjj9lF4vCeG//3Doqk=; b=WfTEEBg3U535ck8+zVq/7O3Ai32Czy6dN6LpiKDKhdNKBDKqEHxjREuw VzCV287OR+Jp9hC/fDZxazaLr7OCcUOD9mD615FIVrE9XEqA0axiGHAXS SAOU+HT4ESrun/qd1OjojJWZ6mCI9uiaJf6VqXayPtIekgGfxMM3uq/JC lW1l16nM8D9xGNKewF96GU8UOzKFQq6vvvOV93dVH7tbn18Lwm6yRQ7M7 0ty/V1eywdxKPbBXWfENZeFF4KxND79Gnhtz4suW99LPPn4xqojkpBB1Q eXH1wK8JWVr07LOP6AFmz4cQE/kTac8LJMryfIb0tU98BBKi2Itx4B29n Q==; X-CSE-ConnectionGUID: 7UYUgmiET2C69zrscxTDyw== X-CSE-MsgGUID: jn37dFgMTLGV9EwrEcsxhA== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409822" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409822" X-CSE-ConnectionGUID: TdeHQIneQXyHdDxufozGQg== X-CSE-MsgGUID: r3+DuJGcS7ee4VCrh0dOGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366004" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 03/22] i386/cpu: Reorganize arch lbr structure definitions Date: Thu, 11 Dec 2025 14:07:42 +0800 Message-Id: <20251211060801.3600039-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431978236158500 Content-Type: text/plain; charset="utf-8" - Move ARCH_LBR_NR_ENTRIES macro and LBREntry definition before XSAVE areas definitions. - Reorder XSavesArchLBR (area 15) between XSavePKRU (area 9) and XSaveXTILECFG (area 17), and reorder the related QEMU_BUILD_BUG_ON check to keep the same ordering. This makes xsave structures to be organized together and makes them clearer. Tested-by: Farrah Chen Reviewed-by: Zide Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c95b772719ce..a183394eca7f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1652,6 +1652,14 @@ typedef struct { =20 #define NB_OPMASK_REGS 8 =20 +typedef struct { + uint64_t from; + uint64_t to; + uint64_t info; +} LBREntry; + +#define ARCH_LBR_NR_ENTRIES 32 + /* CPU can't have 0xFFFFFFFF APIC ID, use that value to distinguish * that APIC ID hasn't been set yet */ @@ -1729,24 +1737,6 @@ typedef struct XSavePKRU { uint32_t padding; } XSavePKRU; =20 -/* Ext. save area 17: AMX XTILECFG state */ -typedef struct XSaveXTILECFG { - uint8_t xtilecfg[64]; -} XSaveXTILECFG; - -/* Ext. save area 18: AMX XTILEDATA state */ -typedef struct XSaveXTILEDATA { - uint8_t xtiledata[8][1024]; -} XSaveXTILEDATA; - -typedef struct { - uint64_t from; - uint64_t to; - uint64_t info; -} LBREntry; - -#define ARCH_LBR_NR_ENTRIES 32 - /* Ext. save area 15: Arch LBR state */ typedef struct XSaveArchLBR { uint64_t lbr_ctl; @@ -1757,6 +1747,16 @@ typedef struct XSaveArchLBR { LBREntry lbr_records[ARCH_LBR_NR_ENTRIES]; } XSaveArchLBR; =20 +/* Ext. save area 17: AMX XTILECFG state */ +typedef struct XSaveXTILECFG { + uint8_t xtilecfg[64]; +} XSaveXTILECFG; + +/* Ext. save area 18: AMX XTILEDATA state */ +typedef struct XSaveXTILEDATA { + uint8_t xtiledata[8][1024]; +} XSaveXTILEDATA; + QEMU_BUILD_BUG_ON(sizeof(XSaveAVX) !=3D 0x100); QEMU_BUILD_BUG_ON(sizeof(XSaveBNDREG) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveBNDCSR) !=3D 0x40); @@ -1764,9 +1764,9 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveOpmask) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveZMM_Hi256) !=3D 0x200); QEMU_BUILD_BUG_ON(sizeof(XSaveHi16_ZMM) !=3D 0x400); QEMU_BUILD_BUG_ON(sizeof(XSavePKRU) !=3D 0x8); +QEMU_BUILD_BUG_ON(sizeof(XSaveArchLBR) !=3D 0x328); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) !=3D 0x2000); -QEMU_BUILD_BUG_ON(sizeof(XSaveArchLBR) !=3D 0x328); =20 typedef struct ExtSaveArea { uint32_t feature, bits; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431961; cv=none; d=zohomail.com; s=zohoarc; b=KpWUicCKjNnbgvHa/SkBQIqZ6PpVhZt//Hor0Fsez1k3CptDOn1pQVb4zD55dDk8MtQTs+dI3bV1I31HxExRa+EKwKH+rUyNSjxHfeWSmqeMOgo71wyWZ0PaRXn4f4T8uR3ZHyMB2SIhsMnoUmquJPf2Tj8nwB9EIhe8Nj68GOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431961; 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=0tU9+V787dNm0fhEtkpcCxtuX9fhDt2CVA9+pA5A4kM=; b=R6AWobwb8NKmefTWqUCUCd+ublXPIOJT9OcuVDYTZIbNzQ1y7eJjjQqAjnXVlwTZv+rQcvwCOM5PxW4so8WyAco1GwGjT6ZZ2V9NlbbBTaROQ3gkvGf/TaXHicY0b4ojs5tT3PX/OWqr27ys1el6wnRB4Lrn0GucFK1EO/kNCKo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431961829600.326918626078; Wed, 10 Dec 2025 21:46:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSt-0000d2-Rm; Thu, 11 Dec 2025 00:43:49 -0500 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 1vTZSm-0000bM-6T for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:41 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSk-0001IB-Be for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:39 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:37 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431818; x=1796967818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PTGXrrw5EFr5RFekmd6pZ60Tp1rqIf+SCDaoLH0Fads=; b=kaBwF71IbsVZcQK8IRAftmYnFUCwtkQFhBuqZy93LZMw3ocEifGUHPZI vpwAWb5fspdXL5hZWCdoGn7ztQEQ8AXBKxNFcLEtD/JdmCLf0Z920Y/+k RYXRjUTcQjh/7Mzy0SkCsQKDsFpC6wCi3l9ZZxIpIKwf7Giihu/qzDVXe 4twgbPjalYRGdR1uXRmwMGTcw4svjMumD8dePcYSdoPxAPCFNPAGAWr7S nPBy5pH2jT93S2gkrjWyCJi69wrcPzdfwyFq1BHYfVp+OD741Z3qe5P3c IioQYjqGtj2wRzC2rAiiQcnmK4ml+/Hyi0vHD3czFEF2TeEvA2mtgfFny g==; X-CSE-ConnectionGUID: cAeCogHZTOSi4rXBe7u/Wg== X-CSE-MsgGUID: Akp8UMgCQK2Ca7caDcPyuw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409831" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409831" X-CSE-ConnectionGUID: aVZtGk1PTIinO5yaJiDi9A== X-CSE-MsgGUID: efhx1L+pQ3GPGp04WADedQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366017" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 04/22] i386/cpu: Make ExtSaveArea store an array of dependencies Date: Thu, 11 Dec 2025 14:07:43 +0800 Message-Id: <20251211060801.3600039-5-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431962211158500 Content-Type: text/plain; charset="utf-8" Some XSAVE components depend on multiple features. For example, Opmask/ ZMM_Hi256/Hi16_ZMM depend on avx512f OR avx10, and for CET (which will be supported later), cet_u/cet_s will depend on shstk OR ibt. Although previously there's the special check for the dependencies of AVX512F OR AVX10 on their respective XSAVE components (in cpuid_has_xsave_feature()), to make the code more general and avoid adding more special cases, make ExtSaveArea store a features array instead of a single feature, so that it can describe multiple dependencies. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v3: - Add a FIXME in x86_cpu_feature_name() as the note to improve the case with multiple dependencies. --- target/i386/cpu.c | 78 ++++++++++++++++++++++++++++++++++------------- target/i386/cpu.h | 9 +++++- 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 34a4c2410d03..e495e6d9b21c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2020,53 +2020,77 @@ static const X86RegisterInfo32 x86_reg_info_32[CPU_= NB_REGS32] =3D { ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUNT] =3D { [XSTATE_FP_BIT] =3D { /* x87 FP state component is always enabled if XSAVE is supported = */ - .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_XSAVE, .size =3D sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader), + .features =3D { + { FEAT_1_ECX, CPUID_EXT_XSAVE }, + }, }, [XSTATE_SSE_BIT] =3D { /* SSE state component is always enabled if XSAVE is supported */ - .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_XSAVE, .size =3D sizeof(X86LegacyXSaveArea) + sizeof(X86XSaveHeader), + .features =3D { + { FEAT_1_ECX, CPUID_EXT_XSAVE }, + }, }, [XSTATE_YMM_BIT] =3D { - .feature =3D FEAT_1_ECX, .bits =3D CPUID_EXT_AVX, .size =3D sizeof(XSaveAVX), + .features =3D { + { FEAT_1_ECX, CPUID_EXT_AVX }, + }, }, [XSTATE_BNDREGS_BIT] =3D { - .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, .size =3D sizeof(XSaveBNDREG), + .features =3D { + { FEAT_7_0_EBX, CPUID_7_0_EBX_MPX }, + }, }, [XSTATE_BNDCSR_BIT] =3D { - .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_MPX, .size =3D sizeof(XSaveBNDCSR), + .features =3D { + { FEAT_7_0_EBX, CPUID_7_0_EBX_MPX }, + }, }, [XSTATE_OPMASK_BIT] =3D { - .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, .size =3D sizeof(XSaveOpmask), + .features =3D { + { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + }, }, [XSTATE_ZMM_Hi256_BIT] =3D { - .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, .size =3D sizeof(XSaveZMM_Hi256), + .features =3D { + { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + }, }, [XSTATE_Hi16_ZMM_BIT] =3D { - .feature =3D FEAT_7_0_EBX, .bits =3D CPUID_7_0_EBX_AVX512F, .size =3D sizeof(XSaveHi16_ZMM), + .features =3D { + { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + }, }, [XSTATE_PKRU_BIT] =3D { - .feature =3D FEAT_7_0_ECX, .bits =3D CPUID_7_0_ECX_PKU, .size =3D sizeof(XSavePKRU), + .features =3D { + { FEAT_7_0_ECX, CPUID_7_0_ECX_PKU }, + }, }, [XSTATE_ARCH_LBR_BIT] =3D { - .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_ARCH_LBR, .size =3D sizeof(XSaveArchLBR), + .features =3D { + { FEAT_7_0_EDX, CPUID_7_0_EDX_ARCH_LBR }, + }, }, [XSTATE_XTILE_CFG_BIT] =3D { - .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_AMX_TILE, .size =3D sizeof(XSaveXTILECFG), + .features =3D { + { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_TILE }, + }, }, [XSTATE_XTILE_DATA_BIT] =3D { - .feature =3D FEAT_7_0_EDX, .bits =3D CPUID_7_0_EDX_AMX_TILE, .size =3D sizeof(XSaveXTILEDATA), + .features =3D { + { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_TILE }, + }, }, }; =20 @@ -7131,16 +7155,24 @@ static inline void feat2prop(char *s) static const char *x86_cpu_feature_name(FeatureWord w, int bitnr) { const char *name; - /* XSAVE components are automatically enabled by other features, + /* + * XSAVE components are automatically enabled by other features, * so return the original feature name instead */ if (w =3D=3D FEAT_XSAVE_XCR0_LO || w =3D=3D FEAT_XSAVE_XCR0_HI) { int comp =3D (w =3D=3D FEAT_XSAVE_XCR0_HI) ? bitnr + 32 : bitnr; =20 - if (comp < ARRAY_SIZE(x86_ext_save_areas) && - x86_ext_save_areas[comp].bits) { - w =3D x86_ext_save_areas[comp].feature; - bitnr =3D ctz32(x86_ext_save_areas[comp].bits); + if (comp < ARRAY_SIZE(x86_ext_save_areas)) { + /* + * Present the first feature as the default. + * FIXME: select and present the one which is actually enabled + * among multiple dependencies. + */ + const FeatureMask *fm =3D &x86_ext_save_areas[comp].features[0= ]; + if (fm->mask) { + w =3D fm->index; + bitnr =3D ctz32(fm->mask); + } } } =20 @@ -8610,11 +8642,15 @@ static bool cpuid_has_xsave_feature(CPUX86State *en= v, const ExtSaveArea *esa) return false; } =20 - if (env->features[esa->feature] & esa->bits) { - return true; + for (int i =3D 0; i < ARRAY_SIZE(esa->features); i++) { + if (env->features[esa->features[i].index] & esa->features[i].mask)= { + return true; + } } - if (esa->feature =3D=3D FEAT_7_0_EBX && esa->bits =3D=3D CPUID_7_0_EBX= _AVX512F - && (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_AVX10)) { + + if (esa->features[0].index =3D=3D FEAT_7_0_EBX && + esa->features[0].mask =3D=3D CPUID_7_0_EBX_AVX512F && + (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_AVX10)) { return true; } =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a183394eca7f..3d74afc5a8e7 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1769,9 +1769,16 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) !=3D 0x2000); =20 typedef struct ExtSaveArea { - uint32_t feature, bits; uint32_t offset, size; uint32_t ecx; + /* + * The dependencies in the array work as OR relationships, which + * means having just one of those features is enough. + * + * At most two features are sharing the same xsave area. + * Number of features can be adjusted if necessary. + */ + const FeatureMask features[2]; } ExtSaveArea; =20 #define XSAVE_STATE_AREA_COUNT (XSTATE_XTILE_DATA_BIT + 1) --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431891; cv=none; d=zohomail.com; s=zohoarc; b=EyGgFxI083HBWfHH0J3Z1MtvkAUns3VM1jSRZ/788AnTjOz/m2B0fP+B6bmWFWllTk9rgRw24qeyGlf2NV/5OP5UVrwAbkXRbQFmjTtn6yKsFitlmvecaQS9wzpDvc8G+t18lakprSQ/Iz+3xyDpKTxfXQ7LpuKVqWujPA6NXGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431891; 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=mpjd3IN/CbKpYvCHLI1xNFlpe0FDQskwwDGf5I3GyS8=; b=fIezSlKKBWtLO3/F7DG/r5xRvAUmtqnqABvaA16Jnra3V6JV9N0E3xo1ShNqNzDkgDahVVepi+umZ4mBWd5v2ISOu7hq85Q1fGHA40u3pc0V6KT8Q+XzGrRjwgF4CH+8nH+Zz3tytNDsoVxBe+acpGErBfWCFW1vLi0o40e/qS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431891890539.9577339891975; Wed, 10 Dec 2025 21:44:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSx-0000dB-QL; Thu, 11 Dec 2025 00:43:51 -0500 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 1vTZSp-0000bo-Oj for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:45 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSo-0001OC-84 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:43 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:41 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431822; x=1796967822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c/VS1/2chdkAwU46yWRjXngVNYQ5YwGggg1BKVSm57Q=; b=Cxj4Ay6VeTDGMe8SmCJm857q/MgZ1Agmq28TYfvpVWW7/q9B1pWyetD0 GKft6KcDlQ8R8/aiTaNxQ7LZDNE44jjwKOxeSWYCWojLRkgvpKgi182ZS ptMilJRJN4zbE7JP+dzoHAHsaGeb9D3+kc0ULfQ2ufZaISY7O1hRuwty4 vEudsQN7queMNDa5kE49WEAsrIe9KOrwcV1S+WRktxBuPbjUUyLndzZDb C/Afc6n8de4kBqwO3/NNCiN1WDKRb6f5q2lIS/rzlzvYHcGiziz1F2rNA h/VTgramVtj/w48RMCulxWarDOMa5vRZlj8eB7yaRK0FoYJpK7/NWpr6M g==; X-CSE-ConnectionGUID: QEip/jjvTCaI7vZNBT8+Kg== X-CSE-MsgGUID: 6trea5+bQSiKGEdelfmcDg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409851" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409851" X-CSE-ConnectionGUID: LL4fL7cESH+fVaf4NISmLQ== X-CSE-MsgGUID: 5+6778LAS42EFOp529m5Bw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366032" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 05/22] i386/cpu: Add avx10 dependency for Opmask/ZMM_Hi256/Hi16_ZMM Date: Thu, 11 Dec 2025 14:07:44 +0800 Message-Id: <20251211060801.3600039-6-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431893893158500 Content-Type: text/plain; charset="utf-8" With feature array in ExtSaveArea, add avx10 as the second dependency for Opmask/ZMM_Hi256/Hi16_ZMM xsave components, and drop the special check in cpuid_has_xsave_feature(). Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e495e6d9b21c..70a282668f72 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2054,18 +2054,21 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COU= NT] =3D { .size =3D sizeof(XSaveOpmask), .features =3D { { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + { FEAT_7_1_EDX, CPUID_7_1_EDX_AVX10 }, }, }, [XSTATE_ZMM_Hi256_BIT] =3D { .size =3D sizeof(XSaveZMM_Hi256), .features =3D { { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + { FEAT_7_1_EDX, CPUID_7_1_EDX_AVX10 }, }, }, [XSTATE_Hi16_ZMM_BIT] =3D { .size =3D sizeof(XSaveHi16_ZMM), .features =3D { { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX512F }, + { FEAT_7_1_EDX, CPUID_7_1_EDX_AVX10 }, }, }, [XSTATE_PKRU_BIT] =3D { @@ -8648,12 +8651,6 @@ static bool cpuid_has_xsave_feature(CPUX86State *env= , const ExtSaveArea *esa) } } =20 - if (esa->features[0].index =3D=3D FEAT_7_0_EBX && - esa->features[0].mask =3D=3D CPUID_7_0_EBX_AVX512F && - (env->features[FEAT_7_1_EDX] & CPUID_7_1_EDX_AVX10)) { - return true; - } - return false; } =20 --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431922; cv=none; d=zohomail.com; s=zohoarc; b=HsTiRrl4+V14kI+zOCSJIhuoyzLdg2Di2IJl3Dc8DNdbfpiwn7dDAClfcmgV4wJrzjHgDpr2YckfXUFnSUZaOFQfzSAkOeHTJQxfjlYHMPANOeDpa9xJeluEseToQsUc9tdZ2j9//lqZVjHBhwf2dRKxS8/pzc1uZoC9T4Jm72Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431922; 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=OdZRsVnfjo4jkEoY99+KOqeN75zWi8IIm7tgIhrYI2A=; b=NFb7ZG0OVX2qBoTNgOIRl9aiBqLNEQOzRa055L7bcyfLkxC8YS82v455juFB6SeNjpzNQxhEICRKY1gtyotcNVS/f90P4gnRQW08eZTyxjW/2yY1gpeAq/W6ewjg2mecCMBqdpzWlWIwWSENIn/u5q48zfYkAizszYk9QwjeuIQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431922440740.9690071795408; Wed, 10 Dec 2025 21:45:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZSz-0000dc-DN; Thu, 11 Dec 2025 00:43:53 -0500 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 1vTZSs-0000cP-SW for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:47 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSr-0001OC-6f for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:46 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:44 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431825; x=1796967825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6oiSLxx2zin740/NCyRplOfAx3FyLNTrt2eo2NqNpGA=; b=GtbMjO2BzX3GvcqW+KxcykqZ8tmub/7rOla8axSe1NYhYnRIbdf6vzjR sWE/SijdRScw/U/l2URMaDjODLivnH/HyeHQjGJAoGJTKgFuDrw+g0elK 9qes9GBMy3tnuoxJ78EgFNQCHHXhjQpjnvaWhNjw8qaxqlhMvvu1obE0C adsWCbVqMgBv8iHmU3XHwWeNOWs7ZT7IhADOXh2r/i2MWqQ7HQ8rGOQq6 ll9vG0fKQKkcwLcAKJgDe2hGPkeMnRcBZjXkJl0/iNxY5ePceeIDOFU/p v576XLFxnSA3/gx2UTlWJNglNKhwdgO8Suf0mASlsyq5Uf0kN6NCVrkPx g==; X-CSE-ConnectionGUID: x3DmeCPuRGmu6nPjoyYPnA== X-CSE-MsgGUID: kdylc6qUS+qNsH6saEixKg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409861" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409861" X-CSE-ConnectionGUID: QhiEBwHTRwuV3cmxtIgpeA== X-CSE-MsgGUID: M4jIW4ehTxqoyGKyrI4PYQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366043" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 06/22] i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves Date: Thu, 11 Dec 2025 14:07:45 +0800 Message-Id: <20251211060801.3600039-7-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431924058158500 Content-Type: text/plain; charset="utf-8" The x86_ext_save_areas[] is expected to be well initialized by accelerators and its xstate detail information cannot be changed by user. So use x86_ext_save_areas[] to encode CPUID.0XD subleaves directly without other hardcoding & masking. And for arch LBR, KVM fills its xstate in x86_ext_save_areas[] via host_cpuid(). The info obtained this way matches what would be retrieved from x86_cpu_get_supported_cpuid() (since KVM just fills CPUID with the host xstate info directly anyway). So just use the initialized x86_ext_save_areas[] instead of calling x86_cpu_get_supported_cpuid(). Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v4: - Update commit meesage to explain x86_cpu_get_supported_cpuid() is not necessary. Changes Since v3: - New commit. --- target/i386/cpu.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 70a282668f72..f3bf7f892214 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8188,20 +8188,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } } else if (count =3D=3D 0xf && cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LB= R)) { - x86_cpu_get_supported_cpuid(0xD, count, eax, ebx, ecx, edx); + const ExtSaveArea *esa =3D &x86_ext_save_areas[count]; + + *eax =3D esa->size; + *ebx =3D esa->offset; + *ecx =3D esa->ecx; } else if (count < ARRAY_SIZE(x86_ext_save_areas)) { const ExtSaveArea *esa =3D &x86_ext_save_areas[count]; =20 - if (x86_cpu_xsave_xcr0_components(cpu) & (1ULL << count)) { - *eax =3D esa->size; - *ebx =3D esa->offset; - *ecx =3D esa->ecx & - (ESA_FEATURE_ALIGN64_MASK | ESA_FEATURE_XFD_MASK); - } else if (x86_cpu_xsave_xss_components(cpu) & (1ULL << count)= ) { - *eax =3D esa->size; - *ebx =3D 0; - *ecx =3D 1; - } + *eax =3D esa->size; + *ebx =3D esa->offset; + *ecx =3D esa->ecx; } break; } --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431861; cv=none; d=zohomail.com; s=zohoarc; b=RMN27ekqgsMqdhtaDjODi3DKBQThAMIz/Qe9YTtHmxl7JhAa04EI+HHDelsIpv5x7VdjIjQ26/Xb8MKRjDSpNt5NHinXv/ZhoWQ7LzqvQ8Nu8SMIagcOntesl56JlzJTwUmJhiQAcy+KZ7B9UmdUvuZHTJxW58nCG5xKELNnnAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431861; 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=P5wcunu9d78/LwsHw6sOWrfpOcjmxW2fI+PkiTG+cQE=; b=lFwf8U08yR4Uv7v97rq8lbwND1l1ZeMRA7RPGzA5sntuZlBjxEFcg/xioWGN/VlrDTaLT23+ffbCur/IQLu+tc0XsSxe6IhpFj9rqPU0jvaJpbUEycDFJ9DAvhYDZFUqvFv/ee12i6Quq12Tw355zNXg81vRMjs/SNMyh36XndI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431861786362.82673454726853; Wed, 10 Dec 2025 21:44:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZT1-0000dy-Vi; Thu, 11 Dec 2025 00:43:56 -0500 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 1vTZSw-0000dU-Iz for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:51 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSu-0001OC-VS for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:50 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:48 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431829; x=1796967829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OLmeyBkc275l2fFpoH7p7H8roBE/4ZOOO8W3RLBkAq8=; b=YSOir6SAX/fXwzZeXAcmcNgcQju8lM1/vuUKZkf4v6uES+skLHdANG+E AF8jOH0ziD63H60U5YOs0zCdVisLVfYfhA3ZJyO+CZPX68+Pp725v+BUZ bcVlyP7h9pNrnJ+T2LHf7Plb806NuvD/eokDNEKvcKd2SCYBASJA5KiNy kgl9BtnUPPTj8SdDVjI2DDK8OVg/V52XhThuFpqTW+6FkU5SMlZGI6etz /R+em0aqE26P+bG6Ypu1c0phJ/5lV5bqeCbicczjle1YxakcQ58egIkcN haJmHaFJkjHi2pMdADtFqkTTkNiizd2ZtjqMMinfn2ocesnCBoKiFtz5c A==; X-CSE-ConnectionGUID: y88N2/MTRZijTExYgRvVyg== X-CSE-MsgGUID: MhIGxJ1cRDChLwPVRxjTAw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409869" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409869" X-CSE-ConnectionGUID: 0mfNbpUGSmKzsAOP+ctacg== X-CSE-MsgGUID: vlX8I5qaT2qZyP9vFByNDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366054" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 07/22] i386/cpu: Reorganize dependency check for arch lbr state Date: Thu, 11 Dec 2025 14:07:46 +0800 Message-Id: <20251211060801.3600039-8-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431863828158500 Content-Type: text/plain; charset="utf-8" The arch lbr state has 2 dependencies: * Arch lbr feature bit (CPUID 0x7.0x0:EDX[bit 19]): This bit also depends on pmu property. Mask it off if pmu is disabled in x86_cpu_expand_features(), so that it is not needed to repeatedly check whether this bit is set as well as pmu is enabled. Note this doesn't need compat option, since even KVM hasn't support arch lbr yet. The supported xstate is constructed based such dependency in cpuid_has_xsave_feature(), so if pmu is disabled and arch lbr bit is masked off, then arch lbr state won't be included in supported xstates. Thus it's safe to drop the check on arch lbr bit in CPUID 0xD encoding. * XSAVES feature bit (CPUID 0xD.0x1.EAX[bit 3]): Arch lbr state is a supervisor state, which requires the XSAVES feature support. Enumerate supported supervisor state based on XSAVES feature bit in x86_cpu_enable_xsave_components(). Then it's safe to drop the check on XSAVES feature support during CPUID 0XD encoding. Suggested-by: Zide Chen Tested-by: Farrah Chen Reviewed-by: Zide Chen Signed-off-by: Zhao Liu --- target/i386/cpu.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f3bf7f892214..56b4c57969c1 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8179,20 +8179,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ebx =3D xsave_area_size(xstate, true); *ecx =3D env->features[FEAT_XSAVE_XSS_LO]; *edx =3D env->features[FEAT_XSAVE_XSS_HI]; - if (kvm_enabled() && cpu->enable_pmu && - (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LBR) && - (*eax & CPUID_XSAVE_XSAVES)) { - *ecx |=3D XSTATE_ARCH_LBR_MASK; - } else { - *ecx &=3D ~XSTATE_ARCH_LBR_MASK; - } - } else if (count =3D=3D 0xf && cpu->enable_pmu - && (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LB= R)) { - const ExtSaveArea *esa =3D &x86_ext_save_areas[count]; - - *eax =3D esa->size; - *ebx =3D esa->offset; - *ecx =3D esa->ecx; } else if (count < ARRAY_SIZE(x86_ext_save_areas)) { const ExtSaveArea *esa =3D &x86_ext_save_areas[count]; =20 @@ -8910,6 +8896,12 @@ static void x86_cpu_enable_xsave_components(X86CPU *= cpu) =20 mask =3D 0; for (i =3D 0; i < ARRAY_SIZE(x86_ext_save_areas); i++) { + /* Skip supervisor states if XSAVES is not supported. */ + if (CPUID_XSTATE_XSS_MASK & (1 << i) && + !(env->features[FEAT_XSAVE] & CPUID_XSAVE_XSAVES)) { + continue; + } + const ExtSaveArea *esa =3D &x86_ext_save_areas[i]; if (cpuid_has_xsave_feature(env, esa)) { mask |=3D (1ULL << i); @@ -9027,11 +9019,13 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **e= rrp) } } =20 - if (!cpu->pdcm_on_even_without_pmu) { + if (!cpu->enable_pmu) { /* PDCM is fixed1 bit for TDX */ - if (!cpu->enable_pmu && !is_tdx_vm()) { + if (!cpu->pdcm_on_even_without_pmu && !is_tdx_vm()) { env->features[FEAT_1_ECX] &=3D ~CPUID_EXT_PDCM; } + + env->features[FEAT_7_0_EDX] &=3D ~CPUID_7_0_EDX_ARCH_LBR; } =20 for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) { --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431929; cv=none; d=zohomail.com; s=zohoarc; b=H2Rix3TD8Xlt5lkl46QWS98NAFw2qov9Oo9oTekMPZ6lTtdRmlgchwMYFVdfgxtBY9R4H4C4WuJtnN8zJKeXqUK46B9sViHRaJR/BSn7wNUZ4WABDGlwu0tE3jAdaFKRoMqxRHEBOfDI9Io8OTBhRR5XSAIeMN0YajgSf16bqJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431929; 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=Q7MYSPfuteMbR0NRM6vi2wFhHczRB+QIjt0uOYRSZiw=; b=RUPivkiP6gNbLQRy1H/Kh6y5Nh31VMC6JmAF4iLfwsLHIdCebe2JRKyf21h7cKdUSsf3hxb7thSiUyvfKUL53i0SrlYg6LLjjAsAhnCqAu0PsiOodW9CP1BVba+9dsTlpOta/wmJ321zKDx4JRxCll9RjPLGtMxyIjBijHRCpgc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431929669643.8303387606578; Wed, 10 Dec 2025 21:45:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZT6-0000fE-NS; Thu, 11 Dec 2025 00:44:00 -0500 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 1vTZT0-0000e0-P4 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:55 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZSz-0001OC-51 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:54 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:52 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431833; x=1796967833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fJBFcQVoKmgeoUmwsBmvZdBtcnTJvhtd89N47vMSmQc=; b=jaC5OmT7DffCUReXu9G2D1kscOc9wBuvnjct0B57dvTpyJm5lYrds89Q 7WJherJSzMpwElt6lFb3JFMsfUTX/1oBbq8x76SduQs6gcDUFGaHRHfeI wyR57v7KU64CZp7/q9QIyms8Nqzd8vfoOpndkwYaioz727e9KUUYFc/IU sURDol72bd1xGr8mLJd3BRkV5ALJQhBBaT2kqV8N1ZSkFpVk9PxmJ3y4h MBk+83+TgS/FOU2/nDX+SrAa8xlCegrRjfG8W1F0yRUbJynLmzXlvNyJY mwMftL2rI2pwVKQltL/y2fIQw59W9b1VfQxV9TZ4+Yu94X/oi5kvQ2BeB w==; X-CSE-ConnectionGUID: z5OqIvHmQJKNH4rP6h/C6A== X-CSE-MsgGUID: 60Pdw4cHS1GNUQd7+CihAQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409877" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409877" X-CSE-ConnectionGUID: BS+knNYIRRygEl7jo6PxpQ== X-CSE-MsgGUID: ZnWECnVlTcGvVPdkV8+UkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366063" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 08/22] i386/cpu: Drop pmu check in CPUID 0x1C encoding Date: Thu, 11 Dec 2025 14:07:47 +0800 Message-Id: <20251211060801.3600039-9-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431930062158500 Content-Type: text/plain; charset="utf-8" Since CPUID_7_0_EDX_ARCH_LBR will be masked off if pmu is disabled, there's no need to check CPUID_7_0_EDX_ARCH_LBR feature with pmu. Tested-by: Farrah Chen Reviewed-by: Zide Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 56b4c57969c1..62769db3ebb7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8273,11 +8273,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, } break; } - case 0x1C: - if (cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_ED= X_ARCH_LBR)) { - x86_cpu_get_supported_cpuid(0x1C, 0, eax, ebx, ecx, edx); - *edx =3D 0; + case 0x1C: /* Last Branch Records Information Leaf */ + *eax =3D 0; + *ebx =3D 0; + *ecx =3D 0; + *edx =3D 0; + if (!(env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LBR)) { + break; } + x86_cpu_get_supported_cpuid(0x1C, 0, eax, ebx, ecx, edx); + *edx =3D 0; /* EDX is reserved. */ break; case 0x1D: { /* AMX TILE, for now hardcoded for Sapphire Rapids*/ --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431861; cv=none; d=zohomail.com; s=zohoarc; b=e/pZEotpLmEGpo/U2MX0zY0oeFlVy+AJ7RZ2/txo4LXULmE51Tx0tux30xCEpKGvukkJbsosnjRG87VUCg/2f8AMPj7vpyo+DEuDUqPNptv6V9QpggzcSBvqxbLfLYYJH2JRsyep6ktlTGWims8lBIDGm2t1XTA5P8HfpEVtwjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431861; 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=pEni8jH6EkIWUiwuddYLpAboZ+dT5+zVap9E2MaQQng=; b=USQWxqVsqRdiPV8r3mEG62gwUz43oOiUbOKZWeCGiRgTUxv7vY0bYvz8JQ2hIm38CJyE+qa2KeywAIqnmQVCd+hfbt22aQzQLTPa6AYHkMcHhy8XzwERZknqjbKVQf8k5TJA8gLt7Hm57yi7k62bnWQnCl76lCzHYIMg6aqDqkg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 176543186152838.40395297850944; Wed, 10 Dec 2025 21:44:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZT9-0000hp-4O; Thu, 11 Dec 2025 00:44:04 -0500 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 1vTZT3-0000ej-Lz for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:57 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZT2-0001OC-3z for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:43:57 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:43:55 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431836; x=1796967836; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FovsNeUNQb3Mbfo6UFh8WpHvsMB68L7Ws+8KaJE9y0g=; b=UcXA2q2DnkUyi8QH6Ak/HFJGCtmxdT42VKcmJb0wfqLrsHvxpkTX1qaH 6o80sZcW5P0jTOJt1TPMZWobr/sX6owSSwhX5Ak9+udRb4OoKpzftLQWk O9xoR0rL4QfRBK8U/SLUc72zL+8nKIcAw+YnHvBf8vTwU9VTatfOEXSyz 2i+eKQ3i6kyl+Q3dZUtbmonrAmzAUlHiau4fVIQkYJ+Jyi+Az/+odAmoP TVoOXFUAR/2dEQkKbxDM1jOfKH2vMKlpwgvMC7ACb8BVLCmy1/yITZHv3 EBaK5dWXUvfqvEHar1mWGyLcYMn8IznmUP21urzgTNwGWzziaHZn2yyuV g==; X-CSE-ConnectionGUID: WuFEFt9nQ5yCg6o1lcIkyg== X-CSE-MsgGUID: 3jAF0gsDTumRWijg5a4OUw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409887" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409887" X-CSE-ConnectionGUID: JHbUU9LCTeSpZFIdC6bKkw== X-CSE-MsgGUID: WwYbV4ehQbOgFCvOn3sbzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366081" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 09/22] i386/cpu: Fix supervisor xstate initialization Date: Thu, 11 Dec 2025 14:07:48 +0800 Message-Id: <20251211060801.3600039-10-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431861840158500 Content-Type: text/plain; charset="utf-8" From: Chao Gao Arch lbr is a supervisor xstate, but its area is not covered in x86_cpu_init_xsave(). Fix it by checking supported xss bitmap. In addition, drop the (uint64_t) type casts for supported_xcr0 since x86_cpu_get_supported_feature_word() returns uint64_t so that the cast is not needed. Then ensure line length is within 90 characters. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v3: - Fix shift for CXRO high 32 bits. --- target/i386/cpu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 62769db3ebb7..859cb889a37c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -9711,20 +9711,23 @@ static void x86_cpu_post_initfn(Object *obj) static void x86_cpu_init_xsave(void) { static bool first =3D true; - uint64_t supported_xcr0; + uint64_t supported_xcr0, supported_xss; int i; =20 if (first) { first =3D false; =20 supported_xcr0 =3D - ((uint64_t) x86_cpu_get_supported_feature_word(NULL, FEAT_XSAV= E_XCR0_HI) << 32) | + x86_cpu_get_supported_feature_word(NULL, FEAT_XSAVE_XCR0_HI) <= < 32 | x86_cpu_get_supported_feature_word(NULL, FEAT_XSAVE_XCR0_LO); + supported_xss =3D + x86_cpu_get_supported_feature_word(NULL, FEAT_XSAVE_XSS_HI) <<= 32 | + x86_cpu_get_supported_feature_word(NULL, FEAT_XSAVE_XSS_LO); =20 for (i =3D XSTATE_SSE_BIT + 1; i < XSAVE_STATE_AREA_COUNT; i++) { ExtSaveArea *esa =3D &x86_ext_save_areas[i]; =20 - if (!(supported_xcr0 & (1 << i))) { + if (!((supported_xcr0 | supported_xss) & (1 << i))) { esa->size =3D 0; } } --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431873; cv=none; d=zohomail.com; s=zohoarc; b=JWDMO9N95mFDQlDBqtdAIT9KGM1VDGDcqSHnXClWuqwY9xrpjLLIjnyFDOqNkB/65AM3PHwRln4U4HcOt3hc0fuwI25ue0wGiUM1kJBvdmdDqWAOyHZkdcrF7B7lTuaYxptrLov8KomoDlniskTwgsmOU9+XAtkVzlPdSDMU+ZQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431873; 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=YSxZKg8lClqWHFxhO5N1XmGwYJ+MlW1wyPxeMjFgAnk=; b=gBCGt8qgqp1+ccixcATtfhOqKXCcGBM6CmGRm07+6hucNo0C9zWe6Ki0zCqNKqG6v1PlEze1eKT5eBtHvbNsAwhkifVDFO1pzfZN5VX1QroPLRt9d7bH7gDvgGyI/uvOhlvvdT1vXpWhGbG0nXu11tn9tgTuRtLgZOsQ0ozb44Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431873404449.11570730473386; Wed, 10 Dec 2025 21:44:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTD-0000n2-SO; Thu, 11 Dec 2025 00:44:07 -0500 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 1vTZTB-0000j9-Vt for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:06 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTA-0001bl-8w for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:05 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:03 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:43:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431844; x=1796967844; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DZ3sfvrb+qc8GsNdFeIp7NVIUjHrM1Kf/7Vu9/XqA3o=; b=NoU0M0NXQt112mno62ojSJwj6qLi+/RQGhzZsZcW1d1I6GK7r12NHzIM fvzWAO5XkiZRwseP8OGX5QmTENxcFdPX1VaQXrkaUhmDm+otsZ0EITSW4 XpJFIO4VM/uJhNlVSSZoKseYdALt6YWaYfCBvgxSNOlv8i+YTVv4ZC6LH Cpx8DUToEuYqb1BqaBjRG6U/rxfJWKhpo0R31zuVEqK/sBqWsdVnyijFV z1UuQNstWhB/8HpTf/v2ogoqkkjfYFQa+HclHw1KfZ1lmRySZH/Ud8BpY mpMdEkbeMuGdCZfT/qKI93KqtZtbNHSnZ9ByiUQ4GXTzG9AtzlcuvpeBK Q==; X-CSE-ConnectionGUID: vPtfC1O8R+q1WSXW/6APMQ== X-CSE-MsgGUID: LTO+qNK1TuifJs93dH7Oww== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409903" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409903" X-CSE-ConnectionGUID: QoC2Q5C0S7m/fEn5mdfr1g== X-CSE-MsgGUID: FcG2oCBHSzGtD+rfLRUnwg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366094" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 10/22] i386/cpu: Add missing migratable xsave features Date: Thu, 11 Dec 2025 14:07:49 +0800 Message-Id: <20251211060801.3600039-11-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431873848158500 Content-Type: text/plain; charset="utf-8" Xtile-cfg & xtile-data are both user xstates. Their xstates are cached in X86CPUState, and there's a related vmsd "vmstate_amx_xtile", so that it's safe to mark them as migratable. Arch lbr xstate is a supervisor xstate, and it is save & load by saving & loading related arch lbr MSRs, which are cached in X86CPUState, and there's a related vmsd "vmstate_arch_lbr". So it should be migratable. PT is still unmigratable since KVM disabled it and there's no vmsd and no other emulation/simulation support. Note, though the migratable_flags get fixed, x86_cpu_enable_xsave_components() still overrides supported xstates bitmaps regardless the masking of migratable_flags. This is another issue, and would be fixed in follow-up refactoring. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v3: - Mark XSTATE_ARCH_LBR_MASK as migratable in FEAT_XSAVE_XSS_LO. - Add TODO comment. --- target/i386/cpu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 859cb889a37c..d2a89c03caec 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1484,6 +1484,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { .ecx =3D 1, .reg =3D R_ECX, }, + .migratable_flags =3D XSTATE_ARCH_LBR_MASK, }, [FEAT_XSAVE_XSS_HI] =3D { .type =3D CPUID_FEATURE_WORD, @@ -1522,7 +1523,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { .migratable_flags =3D XSTATE_FP_MASK | XSTATE_SSE_MASK | XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK | XSTATE_OPMASK_MASK | XSTATE_ZMM_Hi256_MASK | XSTATE_Hi16_ZMM_M= ASK | - XSTATE_PKRU_MASK, + XSTATE_PKRU_MASK | XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA_M= ASK, }, [FEAT_XSAVE_XCR0_HI] =3D { .type =3D CPUID_FEATURE_WORD, @@ -2154,8 +2155,13 @@ static uint64_t x86_cpu_get_migratable_flags(X86CPU = *cpu, FeatureWord w) for (i =3D 0; i < 64; i++) { uint64_t f =3D 1ULL << i; =20 - /* If the feature name is known, it is implicitly considered migra= table, - * unless it is explicitly set in unmigratable_flags */ + /* + * If the feature name is known, it is implicitly considered migra= table, + * unless it is explicitly set in unmigratable_flags. + * + * TODO: Make the behavior of x86_cpu_enable_xsave_components() al= ign + * with migratable_flags masking. + */ if ((wi->migratable_flags & f) || (wi->feat_names[i] && !(wi->unmigratable_flags & f))) { r |=3D f; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431876; cv=none; d=zohomail.com; s=zohoarc; b=Ap12dpiIL/JsYBBudGSjjYDiGc5UxG3vMJOQq6dY69JzdlDWDRa1pw+ZtguLehcAeU6EI1kxvonagB2Wc16poY1YO9YCntGVhFX059fghmlM+mvH18LWTBG6dB3JCnGLssCnH8zSdd3LAEIfC/EJD0jG5PDDtRuw15gQ82WYjUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431876; 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=xVN8y2P8CNNC4QXbHuG3rMr4NC4lwK4TShJCI4idMlg=; b=Uf3Xkty0htL2bWHjKP3//CQZDjJ2rzsu6NPK1UGiJCbF/ezAVETe6KLeTttoMyZxtBEGzP/0XHGDQtZTgkVB7PSfcQDpkHVoAewTOB1QmOve+6vR8sb2a8LR3m4uZVwtAth4twD6WpdgjAPWbVPFTYpv/ACoCk5oaT4/55aDbAw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431876500259.37812567853746; Wed, 10 Dec 2025 21:44:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTF-0000r5-AD; Thu, 11 Dec 2025 00:44:09 -0500 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 1vTZTE-0000nJ-4E for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:08 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTC-0001c0-2f for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:07 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:04 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431846; x=1796967846; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ei4jy82TLUyU3gpgqSjMGkn3ky3SGOs5VuaVHpOYPJ4=; b=azYqEno0w/D6L7bXGE9R4lb0CVvSFBgEG8lhad/N5ONbCgtV1ipW/0/6 52WKBkzwAOZmiL2yQSia7FkIbzdgBE3wVzYtDHKZ60RftQeQs5tmj14Rc 9S4QzYGov17hl4jDdN7hOfEnhXE7v9YtTYWnDX8QpJy+idqRHNz7ih2HB PsApKr90i8ayZkb0zvtzqAnqmFzFZ56YL5ZupU7eyATL6ETvN+Inv7CZf S8ynwMyoGsgu/zfYqFsebwqpW6LYOGUVQZ4PTbpp8HoeIzWHciRXnRjRd KrSygBjQ9K6VQwTKu3H31izt2WU9Peu5aHf3PjTqSsB+NRNu8l59IUSDF Q==; X-CSE-ConnectionGUID: ZjG6Lfk3TU6RVV4fGhvgtQ== X-CSE-MsgGUID: GL8ql4GDT26WAvb+xA2Emg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409909" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409909" X-CSE-ConnectionGUID: 8+jLiWf2TQGhwHoZq1oL4Q== X-CSE-MsgGUID: 6XziEBl/SISQy6TNmNeizQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366122" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu , Yang Weijiang Subject: [PATCH v5 11/22] i386/cpu: Enable xsave support for CET states Date: Thu, 11 Dec 2025 14:07:50 +0800 Message-Id: <20251211060801.3600039-12-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431878012158500 Content-Type: text/plain; charset="utf-8" From: Yang Weijiang Add CET_U/S bits in xstate area and report support in xstate feature mask. MSR_XSS[bit 11] corresponds to CET user mode states. MSR_XSS[bit 12] corresponds to CET supervisor mode states. CET Shadow Stack(SHSTK) and Indirect Branch Tracking(IBT) features are enumerated via CPUID.(EAX=3D07H,ECX=3D0H):ECX[7] and EDX[20] respectively, two features share the same state bits in XSS, so if either of the features is enabled, set CET_U and CET_S bits together. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Yang Weijiang Co-developed-by: Chao Gao Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v2: - Rename XSavesCETU/XSavesCETS to XSaveCETU/XSaveCETS. - Refine the comments. - Drop ".offset =3D 0" and its comment. - Re-describe xstate dependencies via features array. - Drop "cet-u" & "cet-s" enumeration from FEAT_XSAVE_XSS_LO's feat_name array sicne currently xsave doesn't use named features. --- target/i386/cpu.c | 14 ++++++++++++++ target/i386/cpu.h | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d2a89c03caec..4d29e784061c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2078,6 +2078,20 @@ ExtSaveArea x86_ext_save_areas[XSAVE_STATE_AREA_COUN= T] =3D { { FEAT_7_0_ECX, CPUID_7_0_ECX_PKU }, }, }, + [XSTATE_CET_U_BIT] =3D { + .size =3D sizeof(XSaveCETU), + .features =3D { + { FEAT_7_0_ECX, CPUID_7_0_ECX_CET_SHSTK }, + { FEAT_7_0_EDX, CPUID_7_0_EDX_CET_IBT }, + }, + }, + [XSTATE_CET_S_BIT] =3D { + .size =3D sizeof(XSaveCETS), + .features =3D { + { FEAT_7_0_ECX, CPUID_7_0_ECX_CET_SHSTK }, + { FEAT_7_0_EDX, CPUID_7_0_EDX_CET_IBT }, + }, + }, [XSTATE_ARCH_LBR_BIT] =3D { .size =3D sizeof(XSaveArchLBR), .features =3D { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 3d74afc5a8e7..bc3296a3c6f0 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -589,6 +589,8 @@ typedef enum X86Seg { #define XSTATE_Hi16_ZMM_BIT 7 #define XSTATE_PT_BIT 8 #define XSTATE_PKRU_BIT 9 +#define XSTATE_CET_U_BIT 11 +#define XSTATE_CET_S_BIT 12 #define XSTATE_ARCH_LBR_BIT 15 #define XSTATE_XTILE_CFG_BIT 17 #define XSTATE_XTILE_DATA_BIT 18 @@ -603,6 +605,8 @@ typedef enum X86Seg { #define XSTATE_Hi16_ZMM_MASK (1ULL << XSTATE_Hi16_ZMM_BIT) #define XSTATE_PT_MASK (1ULL << XSTATE_PT_BIT) #define XSTATE_PKRU_MASK (1ULL << XSTATE_PKRU_BIT) +#define XSTATE_CET_U_MASK (1ULL << XSTATE_CET_U_BIT) +#define XSTATE_CET_S_MASK (1ULL << XSTATE_CET_S_BIT) #define XSTATE_ARCH_LBR_MASK (1ULL << XSTATE_ARCH_LBR_BIT) #define XSTATE_XTILE_CFG_MASK (1ULL << XSTATE_XTILE_CFG_BIT) #define XSTATE_XTILE_DATA_MASK (1ULL << XSTATE_XTILE_DATA_BIT) @@ -625,7 +629,8 @@ typedef enum X86Seg { XSTATE_XTILE_CFG_MASK | XSTATE_XTILE_DATA= _MASK) =20 /* CPUID feature bits available in XSS */ -#define CPUID_XSTATE_XSS_MASK (XSTATE_ARCH_LBR_MASK) +#define CPUID_XSTATE_XSS_MASK (XSTATE_ARCH_LBR_MASK | XSTATE_CET_U_MASK = | \ + XSTATE_CET_S_MASK) =20 #define CPUID_XSTATE_MASK (CPUID_XSTATE_XCR0_MASK | CPUID_XSTATE_XSS= _MASK) =20 @@ -904,6 +909,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu= , FeatureWord w); #define CPUID_7_0_ECX_WAITPKG (1U << 5) /* Additional AVX-512 Vector Byte Manipulation Instruction */ #define CPUID_7_0_ECX_AVX512_VBMI2 (1U << 6) +/* Control-flow enforcement technology: shadow stack */ +#define CPUID_7_0_ECX_CET_SHSTK (1U << 7) /* Galois Field New Instructions */ #define CPUID_7_0_ECX_GFNI (1U << 8) /* Vector AES Instructions */ @@ -951,6 +958,8 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu= , FeatureWord w); #define CPUID_7_0_EDX_TSX_LDTRK (1U << 16) /* Architectural LBRs */ #define CPUID_7_0_EDX_ARCH_LBR (1U << 19) +/* Control-flow enforcement technology: indirect branch tracking */ +#define CPUID_7_0_EDX_CET_IBT (1U << 20) /* AMX_BF16 instruction */ #define CPUID_7_0_EDX_AMX_BF16 (1U << 22) /* AVX512_FP16 instruction */ @@ -1737,6 +1746,19 @@ typedef struct XSavePKRU { uint32_t padding; } XSavePKRU; =20 +/* Ext. save area 11: CET_U state */ +typedef struct XSaveCETU { + uint64_t u_cet; + uint64_t pl3_ssp; +} XSaveCETU; + +/* Ext. save area 12: CET_S state */ +typedef struct XSaveCETS { + uint64_t pl0_ssp; + uint64_t pl1_ssp; + uint64_t pl2_ssp; +} XSaveCETS; + /* Ext. save area 15: Arch LBR state */ typedef struct XSaveArchLBR { uint64_t lbr_ctl; @@ -1764,6 +1786,8 @@ QEMU_BUILD_BUG_ON(sizeof(XSaveOpmask) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveZMM_Hi256) !=3D 0x200); QEMU_BUILD_BUG_ON(sizeof(XSaveHi16_ZMM) !=3D 0x400); QEMU_BUILD_BUG_ON(sizeof(XSavePKRU) !=3D 0x8); +QEMU_BUILD_BUG_ON(sizeof(XSaveCETU) !=3D 0x10); +QEMU_BUILD_BUG_ON(sizeof(XSaveCETS) !=3D 0x18); QEMU_BUILD_BUG_ON(sizeof(XSaveArchLBR) !=3D 0x328); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILECFG) !=3D 0x40); QEMU_BUILD_BUG_ON(sizeof(XSaveXTILEDATA) !=3D 0x2000); --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431914; cv=none; d=zohomail.com; s=zohoarc; b=mt1F9si67sWiUh2ruMOmh51j6JqTBtWThiaA8LX6ztMs3UT8k3zEdFjTr+MaqGWRQUqDy9Q7Kznb9xou+culg/qc5cWo5VlCchpuTJ16awkADy0PFLeA/vfop1q2e+nK4ogOWfafDlMxmzvSH70PJthjSoTQ0KVDffSA3pYFFXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431914; 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=lSs+LFb729bbKyi1RLZNaTZ8PaiBH/MmKVnd9pASqxU=; b=YcJuFC6zvGIETi2C3Wg1LXFx0wvULM3aIKFL/oz3b3BbA0RoRAqOOh0xtfGqFfKFfh4DsR/fLS+1Lv9P6JPu8JpREze8cCAAr+WOduxu179ina/fRw0rz7I2EmFlDQkiD1mBPnz+m+Dp1zN9e0iKvc5fyi+HoDUKx0Zw8QSofJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431914591414.42185716823303; Wed, 10 Dec 2025 21:45:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTJ-0001AU-Jh; Thu, 11 Dec 2025 00:44:13 -0500 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 1vTZTH-0000zj-Dv for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:11 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTF-0001ci-KV for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:11 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:08 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431850; x=1796967850; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XBfZRaZRr3MF7syASa2Eo8ym4g4biHCF5wgZ3TpjGi4=; b=A36ZM067l7jBOcGwtI5ZhcazmLuXWiABcpRLf85aIYww2jCxvu/g1TYq huP9oupcbGdrN4qXqhAynpG6NkuNpbuaCYpGvnwaHZD+pVfR3obd4Sw7q Qn2Tml8ll67fsququSI2kuKJ3OmOBnXLZ41WP//N65U0XTe2DrcayUKrL hBsHXW2l3/A0ams2xkdhs/TIHXsaCRrR68f3uN68vtlDKrRrEez/SZnJH 44Frdo4fFrRJGgFHaTKqZH2cTZ5WAvan5uEdWs4BOAe1oE1yIz613cjIn RyyKIfIVHYSecw4B01rA+uCW1+kXWRhQOa5ZYTanvslJ10v8C0Vd+oIS6 Q==; X-CSE-ConnectionGUID: hCuP8Zr1TgumQq5EvnnGCw== X-CSE-MsgGUID: j2Dli/ELRNyzg1KF4KrJDg== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409916" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409916" X-CSE-ConnectionGUID: zOZVpKb9Q+u3AvIjrui/zQ== X-CSE-MsgGUID: /Wl5Veo2RUiIE03N9MjU7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366130" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 12/22] i386/cpu: Add CET support in CR4 Date: Thu, 11 Dec 2025 14:07:51 +0800 Message-Id: <20251211060801.3600039-13-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431916000158500 Content-Type: text/plain; charset="utf-8" CR4.CET bit (bit 23) is as master enable for CET. Check and adjust CR4.CET bit based on CET CPUIDs. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v3: - Reorder CR4_RESERVED_MASK. --- target/i386/cpu.h | 9 +++++++-- target/i386/helper.c | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index bc3296a3c6f0..a1ff2ceb0c38 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -257,6 +257,7 @@ typedef enum X86Seg { #define CR4_SMEP_MASK (1U << 20) #define CR4_SMAP_MASK (1U << 21) #define CR4_PKE_MASK (1U << 22) +#define CR4_CET_MASK (1U << 23) #define CR4_PKS_MASK (1U << 24) #define CR4_LAM_SUP_MASK (1U << 28) =20 @@ -273,8 +274,8 @@ typedef enum X86Seg { | CR4_OSFXSR_MASK | CR4_OSXMMEXCPT_MASK | CR4_UMIP_MASK \ | CR4_LA57_MASK \ | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \ - | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_M= ASK \ - | CR4_LAM_SUP_MASK | CR4_FRED_MASK)) + | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_CET_M= ASK \ + | CR4_PKS_MASK | CR4_LAM_SUP_MASK | CR4_FRED_MASK)) =20 #define DR6_BD (1 << 13) #define DR6_BS (1 << 14) @@ -2948,6 +2949,10 @@ static inline uint64_t cr4_reserved_bits(CPUX86State= *env) if (!(env->features[FEAT_7_1_EAX] & CPUID_7_1_EAX_FRED)) { reserved_bits |=3D CR4_FRED_MASK; } + if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK) && + !(env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_CET_IBT)) { + reserved_bits |=3D CR4_CET_MASK; + } return reserved_bits; } =20 diff --git a/target/i386/helper.c b/target/i386/helper.c index 72b2e195a31e..3f179c6c11f8 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -232,6 +232,18 @@ void cpu_x86_update_cr4(CPUX86State *env, uint32_t new= _cr4) new_cr4 &=3D ~CR4_LAM_SUP_MASK; } =20 + /* + * In fact, "CR4.CET can be set only if CR0.WP is set, and it must be + * clear before CR0.WP can be cleared". However, here we only check + * CR4.CET based on the supported CPUID CET bit, without checking the + * dependency on CR4.WP - the latter need to be determined by the + * underlying accelerators. + */ + if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK) && + !(env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_CET_IBT)) { + new_cr4 &=3D ~CR4_CET_MASK; + } + env->cr[4] =3D new_cr4; env->hflags =3D hflags; =20 --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431941; cv=none; d=zohomail.com; s=zohoarc; b=gbUnfMuNEZfd66pei9oAS5m0g5rd6Wsk/dnPCqk+4FUh64eSGzFFtG17vWungfvrBA7paPy2nKANk0aVDsgOO1gmaELSkZWppA4VZk0Ysuln9CkkeXLswrGXIefkjWSa1S3YhEWCvI3Ld+AM2jIPHrDkKparllbV2QZImsjC/Dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431941; 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=+U9t5OUslCvieEkQxKkzFFASLzANpjkYLalLi6zBIwE=; b=iXBmILhVItKXaeC0OcJdmuNBWTLeaDvC6UT1STT79nNYCOZP06koCxs6XFzcXz1wqRK40ubmPqQiuzAmJthpMVYpOKF/SEJzMkEd9bSX8s3kQ19jVvR4z47uSL/0/Q0ri7v42kA/5C1hlTkcTc0zgSDIefIeuGAPG1PNqxGGiVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431941950419.375656835075; Wed, 10 Dec 2025 21:45:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTO-0001Xm-GA; Thu, 11 Dec 2025 00:44:18 -0500 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 1vTZTM-0001Pf-RS for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:16 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTK-0001ci-WB for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:16 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:14 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431855; x=1796967855; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MoFwaE7HCu9hCP09pscNetCaYn3cG1uOpKDAv/wkIAM=; b=YC77eOqTB4pEHMYk6TJ1PsTA8My/Gz4gYfFvpK9CznI7a11qADPBCklu MtHEo8vXsxa7WGuyg6eMn6IRrab9wK00NWNL46OV29xZQ/bBXBvam+BSd lu73Mtzy1suIVeI4pE2u8+OcO8bpEQzJwrIWoQ/LhfKPTqC/QuTnPkQj2 VpP+xMsbcv182pO9oTA+BfsZT9oYnEUf8qWyNZBwDszOXTifeqJkI0glD SfZqEatJHvnMjQ7JEOmE4DMs8gZxmP7Yvcq2v23YFE8HimUJgbb3GgrwE 4wmcKJvrEE1BhIswli6mLUw1mi2mN8IB3Jj8rXhGuWnVVj61bMm+QpAj3 Q==; X-CSE-ConnectionGUID: qfFx4TlOTdWYX2DF7eljMw== X-CSE-MsgGUID: ue/u0YZ4RteHnGOnXYZQTA== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409920" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409920" X-CSE-ConnectionGUID: SviPlzvqQHKVfZiY+MWIxA== X-CSE-MsgGUID: tDQ4DGX+RY2hBQ0RgCnhHw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366140" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 13/22] i386/cpu: Save/restore SSP0 MSR for FRED Date: Thu, 11 Dec 2025 14:07:52 +0800 Message-Id: <20251211060801.3600039-14-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431942251158500 Content-Type: text/plain; charset="utf-8" From: "Xin Li (Intel)" Both FRED and CET shadow stack define the MSR MSR_IA32_PL0_SSP (aka MSR_IA32_FRED_SSP0 in FRED spec). MSR_IA32_PL0_SSP is a FRED SSP MSR, so that if a processor doesn't support CET shadow stack, FRED transitions won't use MSR_IA32_PL0_SSP, but this MSR would still be accessible using MSR-access instructions (e.g., RDMSR, WRMSR). Therefore, save/restore SSP0 MSR for FRED. Tested-by: Farrah Chen Signed-off-by: Xin Li (Intel) Signed-off-by: Zhao Liu --- Changes Since v3: - New commit. --- target/i386/cpu.h | 6 ++++++ target/i386/kvm/kvm.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index a1ff2ceb0c38..84e5cf0ab0c1 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -554,6 +554,9 @@ typedef enum X86Seg { #define MSR_IA32_FRED_SSP3 0x000001d3 /* Stack level 3 = shadow stack pointer in ring 0 */ #define MSR_IA32_FRED_CONFIG 0x000001d4 /* FRED Entrypoin= t and interrupt stack level */ =20 +/* FRED and CET MSR */ +#define MSR_IA32_PL0_SSP 0x000006a4 /* ring-0 shadow = stack pointer (aka MSR_IA32_FRED_SSP0 for FRED) */ + #define MSR_IA32_BNDCFGS 0x00000d90 #define MSR_IA32_XSS 0x00000da0 #define MSR_IA32_UMWAIT_CONTROL 0xe1 @@ -1970,6 +1973,9 @@ typedef struct CPUArchState { uint64_t fred_config; #endif =20 + /* MSR used for both FRED and CET (SHSTK) */ + uint64_t pl0_ssp; + uint64_t tsc_adjust; uint64_t tsc_deadline; uint64_t tsc_aux; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 60c798113823..00fead0827ed 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4008,6 +4008,11 @@ static int kvm_put_msrs(X86CPU *cpu, KvmPutState lev= el) kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP2, env->fred_ssp2); kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP3, env->fred_ssp3); kvm_msr_entry_add(cpu, MSR_IA32_FRED_CONFIG, env->fred_config); + /* + * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if + * CET shadow stack is not supported. + */ + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, env->pl0_ssp); } } #endif @@ -4495,6 +4500,11 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP2, 0); kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP3, 0); kvm_msr_entry_add(cpu, MSR_IA32_FRED_CONFIG, 0); + /* + * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if + * CET shadow stack is not supported. + */ + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, 0); } } #endif @@ -4746,6 +4756,9 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_FRED_CONFIG: env->fred_config =3D msrs[i].data; break; + case MSR_IA32_PL0_SSP: /* aka MSR_IA32_FRED_SSP0 */ + env->pl0_ssp =3D msrs[i].data; + break; #endif case MSR_IA32_TSC: env->tsc =3D msrs[i].data; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431984; cv=none; d=zohomail.com; s=zohoarc; b=l6h8hC/SgabgNc94Ms6i0h8aDjFPyM5aDqFfB8JaOZ87SQtkSURVpGvYPCo+jaION1P/MS2w04rxrlQVfuK4doLcXvr+56fVsiC4vLiPsqsCB8QZzyu1BAw0YY5WEt3numack1cl0PRfJ3VaImoUem+NX60JeaF6WgV02LastjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431984; 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=No2JfYfS4IhoghbKDuW0cnielZ4pTwyIT9GftTq1nXo=; b=ST0/YpEQzOSMzAWJ+RXQTxf/2CbI6VJu7QhLZN0a16E1itYKRRHNiepc/LPVMIWgBE9qsPHmKjp+YIxmQogwacOCYrb2XFi7g8++9cGp7myLruPWj04U0aeZmZ5Cra45xlCcMrEx5yTBUXwKpSiIEVN+5RqDYYQ/OTkybn1r4lg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431984038673.927232713705; Wed, 10 Dec 2025 21:46:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTR-0001lU-Gp; Thu, 11 Dec 2025 00:44:21 -0500 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 1vTZTQ-0001gH-L6 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:20 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTO-0001ci-JL for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:20 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:18 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431859; x=1796967859; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sBpe2qGYGh44L7Eww11sVA8mfktkl9T4AxGNbJqJsBY=; b=Z6IWhPQK4zBWlxhsBAFcG/of7JwpxydHvVRip55PlGLrNU/xGW72+kGs yzk2F4nCOx9cYKDRUcJtKXo1f9rGn3X5NucDZhYgTtCy+wC29oMsEZuqG qLbPisfe824XoCrNF+EeiJbM4x//KklO+O6WEHzmvRh1e3zLdo/qQFesq urMqgEyGy/sHUllVJ1ljrqWrlMq0ruKwc1FUrlnhRP3DvkCV2G5D0rles V3/axk0wA3FoXwxeWTYRy/IAzF+wNb5D/GumHjN23FR+gt3BFgIBXlqAR 233EFYliNObhAx98n/aJa65i/Cehabb8bLAH2Qoluc4UYO+0skhPVCRil w==; X-CSE-ConnectionGUID: VTToXWP4SoSQFwgOfY6D+g== X-CSE-MsgGUID: dKda5JmETtKmp9NcXEAOvQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409931" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409931" X-CSE-ConnectionGUID: JXba38jmSKaDSEbZkeS9aQ== X-CSE-MsgGUID: d10Ru7jKQViwJMMUSinCOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366157" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu , Yang Weijiang Subject: [PATCH v5 14/22] i386/kvm: Add save/restore support for CET MSRs Date: Thu, 11 Dec 2025 14:07:53 +0800 Message-Id: <20251211060801.3600039-15-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431984400158500 Content-Type: text/plain; charset="utf-8" From: Yang Weijiang CET (architectural) MSRs include: MSR_IA32_U_CET - user mode CET control bits. MSR_IA32_S_CET - supervisor mode CET control bits. MSR_IA32_PL{0,1,2,3}_SSP - linear addresses of SSPs for user/kernel modes. MSR_IA32_INT_SSP_TAB - linear address of interrupt SSP table Since FRED also needs to save/restore MSR_IA32_PL0_SSP, to avoid duplicate operations, make FRED only save/restore MSR_IA32_PL0_SSP when CET-SHSTK is not enumerated. And considerring MSR_IA32_SSP_TBL_ADDR is only presented on 64 bit processor, wrap it with TARGET_X86_64 macro. For other MSRs, add save/restore support directly. Tested-by: Farrah Chen Suggested-by: Xin Li (Intel) Signed-off-by: Yang Weijiang Co-developed-by: Chao Gao Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v3: - Make FRED only save/restore MSR_IA32_PL0_SSP when CET-SHSTK isn't enumerated. - Wrap MSR_IA32_INT_SSP_TAB with TARGET_X86_64 since it's a x86_64-specific MSR. Changes Since v2: - Rename MSR_IA32_SSP_TBL_ADDR to MSR_IA32_INT_SSP_TAB. - Rename X86CPUState.ssp_table_addr to X86CPUState.int_ssp_table. - Drop X86CPUStete.guest_ssp since it is not used in current commit. - Do not check CET-S & CET-U xtates when get/set MSTs since CET is XSAVE-managed feature but is not XSAVE-enabled. --- target/i386/cpu.h | 26 ++++++++++--- target/i386/kvm/kvm.c | 91 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 98 insertions(+), 19 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 84e5cf0ab0c1..37cc218bf3a5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -543,7 +543,7 @@ typedef enum X86Seg { #define MSR_IA32_XFD 0x000001c4 #define MSR_IA32_XFD_ERR 0x000001c5 =20 -/* FRED MSRs */ +/* FRED MSRs (MSR_IA32_FRED_SSP0 is defined as MSR_IA32_PL0_SSP in CET MSR= s) */ #define MSR_IA32_FRED_RSP0 0x000001cc /* Stack level 0 = regular stack pointer */ #define MSR_IA32_FRED_RSP1 0x000001cd /* Stack level 1 = regular stack pointer */ #define MSR_IA32_FRED_RSP2 0x000001ce /* Stack level 2 = regular stack pointer */ @@ -554,9 +554,6 @@ typedef enum X86Seg { #define MSR_IA32_FRED_SSP3 0x000001d3 /* Stack level 3 = shadow stack pointer in ring 0 */ #define MSR_IA32_FRED_CONFIG 0x000001d4 /* FRED Entrypoin= t and interrupt stack level */ =20 -/* FRED and CET MSR */ -#define MSR_IA32_PL0_SSP 0x000006a4 /* ring-0 shadow = stack pointer (aka MSR_IA32_FRED_SSP0 for FRED) */ - #define MSR_IA32_BNDCFGS 0x00000d90 #define MSR_IA32_XSS 0x00000da0 #define MSR_IA32_UMWAIT_CONTROL 0xe1 @@ -583,6 +580,15 @@ typedef enum X86Seg { #define MSR_APIC_START 0x00000800 #define MSR_APIC_END 0x000008ff =20 +/* CET MSRs */ +#define MSR_IA32_U_CET 0x000006a0 /* user mode cet = */ +#define MSR_IA32_S_CET 0x000006a2 /* kernel mode ce= t */ +#define MSR_IA32_PL0_SSP 0x000006a4 /* ring-0 shadow = stack pointer */ +#define MSR_IA32_PL1_SSP 0x000006a5 /* ring-1 shadow = stack pointer */ +#define MSR_IA32_PL2_SSP 0x000006a6 /* ring-2 shadow = stack pointer */ +#define MSR_IA32_PL3_SSP 0x000006a7 /* ring-3 shadow = stack pointer */ +#define MSR_IA32_INT_SSP_TAB 0x000006a8 /* exception shad= ow stack table */ + #define XSTATE_FP_BIT 0 #define XSTATE_SSE_BIT 1 #define XSTATE_YMM_BIT 2 @@ -1973,8 +1979,16 @@ typedef struct CPUArchState { uint64_t fred_config; #endif =20 - /* MSR used for both FRED and CET (SHSTK) */ - uint64_t pl0_ssp; + /* CET MSRs */ + uint64_t u_cet; + uint64_t s_cet; + uint64_t pl0_ssp; /* also used for FRED */ + uint64_t pl1_ssp; + uint64_t pl2_ssp; + uint64_t pl3_ssp; +#ifdef TARGET_X86_64 + uint64_t int_ssp_table; +#endif =20 uint64_t tsc_adjust; uint64_t tsc_deadline; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 00fead0827ed..4eb58ca19d79 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4008,11 +4008,14 @@ static int kvm_put_msrs(X86CPU *cpu, KvmPutState le= vel) kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP2, env->fred_ssp2); kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP3, env->fred_ssp3); kvm_msr_entry_add(cpu, MSR_IA32_FRED_CONFIG, env->fred_config); - /* - * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if - * CET shadow stack is not supported. - */ - kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, env->pl0_ssp); + + if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK)) { + /* + * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if + * CET shadow stack is not supported. + */ + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, env->pl0_ssp); + } } } #endif @@ -4266,6 +4269,26 @@ static int kvm_put_msrs(X86CPU *cpu, KvmPutState lev= el) } } =20 + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK || + env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_CET_IBT) { + kvm_msr_entry_add(cpu, MSR_IA32_U_CET, env->u_cet); + kvm_msr_entry_add(cpu, MSR_IA32_S_CET, env->s_cet); + + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK) { + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, env->pl0_ssp); + kvm_msr_entry_add(cpu, MSR_IA32_PL1_SSP, env->pl1_ssp); + kvm_msr_entry_add(cpu, MSR_IA32_PL2_SSP, env->pl2_ssp); + kvm_msr_entry_add(cpu, MSR_IA32_PL3_SSP, env->pl3_ssp); + +#ifdef TARGET_X86_64 + if (lm_capable_kernel) { + kvm_msr_entry_add(cpu, MSR_IA32_INT_SSP_TAB, + env->int_ssp_table); + } +#endif + } + } + return kvm_buf_set_msrs(cpu); } =20 @@ -4500,11 +4523,14 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP2, 0); kvm_msr_entry_add(cpu, MSR_IA32_FRED_SSP3, 0); kvm_msr_entry_add(cpu, MSR_IA32_FRED_CONFIG, 0); - /* - * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if - * CET shadow stack is not supported. - */ - kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, 0); + + if (!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK)) { + /* + * Aka MSR_IA32_FRED_SSP0. This MSR is accessible even if + * CET shadow stack is not supported. + */ + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, 0); + } } } #endif @@ -4662,6 +4688,25 @@ static int kvm_get_msrs(X86CPU *cpu) } } =20 + if (env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK || + env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_CET_IBT) { + kvm_msr_entry_add(cpu, MSR_IA32_U_CET, 0); + kvm_msr_entry_add(cpu, MSR_IA32_S_CET, 0); + + if (env->features[FEAT_7_0_EDX] & CPUID_7_0_ECX_CET_SHSTK) { + kvm_msr_entry_add(cpu, MSR_IA32_PL0_SSP, 0); + kvm_msr_entry_add(cpu, MSR_IA32_PL1_SSP, 0); + kvm_msr_entry_add(cpu, MSR_IA32_PL2_SSP, 0); + kvm_msr_entry_add(cpu, MSR_IA32_PL3_SSP, 0); + +#ifdef TARGET_X86_64 + if (lm_capable_kernel) { + kvm_msr_entry_add(cpu, MSR_IA32_INT_SSP_TAB, 0); + } +#endif + } + } + ret =3D kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, cpu->kvm_msr_buf); if (ret < 0) { return ret; @@ -4756,9 +4801,6 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_IA32_FRED_CONFIG: env->fred_config =3D msrs[i].data; break; - case MSR_IA32_PL0_SSP: /* aka MSR_IA32_FRED_SSP0 */ - env->pl0_ssp =3D msrs[i].data; - break; #endif case MSR_IA32_TSC: env->tsc =3D msrs[i].data; @@ -5012,6 +5054,29 @@ static int kvm_get_msrs(X86CPU *cpu) case MSR_ARCH_LBR_INFO_0 ... MSR_ARCH_LBR_INFO_0 + 31: env->lbr_records[index - MSR_ARCH_LBR_INFO_0].info =3D msrs[i]= .data; break; + case MSR_IA32_U_CET: + env->u_cet =3D msrs[i].data; + break; + case MSR_IA32_S_CET: + env->s_cet =3D msrs[i].data; + break; + case MSR_IA32_PL0_SSP: /* aka MSR_IA32_FRED_SSP0 */ + env->pl0_ssp =3D msrs[i].data; + break; + case MSR_IA32_PL1_SSP: + env->pl1_ssp =3D msrs[i].data; + break; + case MSR_IA32_PL2_SSP: + env->pl2_ssp =3D msrs[i].data; + break; + case MSR_IA32_PL3_SSP: + env->pl3_ssp =3D msrs[i].data; + break; +#ifdef TARGET_X86_64 + case MSR_IA32_INT_SSP_TAB: + env->int_ssp_table =3D msrs[i].data; + break; +#endif case MSR_K7_HWCR: env->msr_hwcr =3D msrs[i].data; break; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431937; cv=none; d=zohomail.com; s=zohoarc; b=I4uWQw3AoIcsGEBwjuWsp+Xb/xM0bBZED2pbovngBSvCB8EFgjn09xwYE3Z3S7qZB83pRceYnRBA8SAMBsBAZdw7ZL5Upexa0veZvUi+mlYW9qw12Kr9TD4bf4CFR6EurmIA5HCpwLdm4KF1I3pgA8De8r/q7jSwTRf/9S0YvFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431937; 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=D6lWke5SAvVJHqmMLzD/S3WKCfCEaIa50hrk8YYUctU=; b=TPKZgSo6d+RO0WmTVmTQBb1GkdgHwzFgqyy6otYlCSCSLacPK369ZmnMP8qBQjaf2u/oqiCkhv4v/UeOrMaUCPiV+QXKeyHXzlArEoOcrg+00PPz+Pa+CnH6ZmyP+wmvaVtxQ/DuPWlh7M6CYqWdNtKUOrcA4pf5VfT++8auG/I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431937367733.4633599843888; Wed, 10 Dec 2025 21:45:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTW-0001xI-3O; Thu, 11 Dec 2025 00:44:26 -0500 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 1vTZTU-0001sv-DL for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:24 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTS-0001ci-Hn for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:24 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:22 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:18 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431863; x=1796967863; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x0PXAqnx+JyOHSOJTK7j77gOmPTGVLtFdsCoGZuQvp8=; b=BcPGqumFAIML4nopnGAqZZsv5/mgqR4rJ3snOUablxmIjEpai+J2H4+2 0Mr8e6lnBTtCeJJlUh5nP5vzvd5G5FYoutce+x9FzZP2d/O9cw57vyoac n+9aF1v1+xld8RawRzTL41cpn9CgQoJHnHE5tueodDqFLcgBwKWJpkC4U 3Q6aN9xRGU0T+UaWL0GZac49GoAOx8sMsfiRA6Qo8NsVf0D9m4HcwXg7Z K93GB8gwB36pkNOPQn9pveHlPBR1jKLrnO6rpCobekD9nnY+HwmW84AhC QdXPWXqUbVayDjcGgE7WgSMJBz/J32WWFM1WkCE3gyM+EgJ0lQjXWZVDD Q==; X-CSE-ConnectionGUID: 0+OQqHm0TFC4bPMP0rrH0A== X-CSE-MsgGUID: evE1vRvDRJada4Lp9jwPKQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409940" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409940" X-CSE-ConnectionGUID: cj8B2o9eQB+/BzxTAyCSjg== X-CSE-MsgGUID: aBTCTJaRSy2pG/QtWwlXYQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366179" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu , Yang Weijiang Subject: [PATCH v5 15/22] i386/kvm: Add save/restore support for KVM_REG_GUEST_SSP Date: Thu, 11 Dec 2025 14:07:54 +0800 Message-Id: <20251211060801.3600039-16-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431938136158500 Content-Type: text/plain; charset="utf-8" From: Yang Weijiang CET provides a new architectural register, shadow stack pointer (SSP), which cannot be directly encoded as a source, destination or memory operand in instructions. But Intel VMCS & VMCB provide fields to save/load guest & host's ssp. It's necessary to save & restore Guest's ssp before & after migration. To support this, KVM implements Guest's SSP as a special KVM internal register - KVM_REG_GUEST_SSP, and allows QEMU to save & load it via KVM_GET_ONE_REG/KVM_SET_ONE_REG. Cache KVM_REG_GUEST_SSP in X86CPUState. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Yang Weijiang Co-developed-by: Chao Gao Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- target/i386/cpu.h | 3 ++- target/i386/kvm/kvm.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 37cc218bf3a5..458775daaa3e 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1979,7 +1979,7 @@ typedef struct CPUArchState { uint64_t fred_config; #endif =20 - /* CET MSRs */ + /* CET MSRs and register */ uint64_t u_cet; uint64_t s_cet; uint64_t pl0_ssp; /* also used for FRED */ @@ -1989,6 +1989,7 @@ typedef struct CPUArchState { #ifdef TARGET_X86_64 uint64_t int_ssp_table; #endif + uint64_t guest_ssp; =20 uint64_t tsc_adjust; uint64_t tsc_deadline; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4eb58ca19d79..1ebe20f7fb57 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4292,6 +4292,35 @@ static int kvm_put_msrs(X86CPU *cpu, KvmPutState lev= el) return kvm_buf_set_msrs(cpu); } =20 +static int kvm_put_kvm_regs(X86CPU *cpu) +{ + CPUX86State *env =3D &cpu->env; + int ret; + + if ((env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK)) { + ret =3D kvm_set_one_reg(CPU(cpu), KVM_X86_REG_KVM(KVM_REG_GUEST_SS= P), + &env->guest_ssp); + if (ret) { + return ret; + } + } + return 0; +} + +static int kvm_get_kvm_regs(X86CPU *cpu) +{ + CPUX86State *env =3D &cpu->env; + int ret; + + if ((env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK)) { + ret =3D kvm_get_one_reg(CPU(cpu), KVM_X86_REG_KVM(KVM_REG_GUEST_SS= P), + &env->guest_ssp); + if (ret) { + return ret; + } + } + return 0; +} =20 static int kvm_get_xsave(X86CPU *cpu) { @@ -5445,6 +5474,11 @@ int kvm_arch_put_registers(CPUState *cpu, KvmPutStat= e level, Error **errp) error_setg_errno(errp, -ret, "Failed to set MSRs"); return ret; } + ret =3D kvm_put_kvm_regs(x86_cpu); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to set KVM type registers"); + return ret; + } ret =3D kvm_put_vcpu_events(x86_cpu, level); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to set vCPU events"); @@ -5517,6 +5551,11 @@ int kvm_arch_get_registers(CPUState *cs, Error **err= p) error_setg_errno(errp, -ret, "Failed to get MSRs"); goto out; } + ret =3D kvm_get_kvm_regs(cpu); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to get KVM type registers"); + goto out; + } ret =3D kvm_get_apic(cpu); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to get APIC"); --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431897; cv=none; d=zohomail.com; s=zohoarc; b=Mcjj5Hfw1iFbEuGMvM1j7Ke707WdoGuS4hXUkGIvQQZ9gHZq2/SI3s5zdoPTdpV9JYzbLBRJiuR1Y1A27cVnbDk4SJ6b/lvhpquhGBoKpWUNiT7oX68ezCFuqfZ9PR9OOWaOgqB//6bCrft3EN+yBFR0DSZ3Ua7aU4w+h17YcVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431897; 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=j8xzBzX6dQZUYjDSoR1z+v7uY4+B+H3jE3NTgnrA6/4=; b=WtiWZXcsCcUmicqzhvtW+95BYV4Q5QUpwU+dXlzmYrZMHHK0tKqWkrpA/iyu5hOI7By/46sW1qDajYfosga4IR10rQIbnpnABChh2eaPOGyq4NLMBo44UVVPWC08L6yg/B3xBsnjY9ATJWe600Vs0uYZZr3D8mSTTOo+9xHDItA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431897286836.5443099023478; Wed, 10 Dec 2025 21:44:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTj-0003Am-Td; Thu, 11 Dec 2025 00:44:39 -0500 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 1vTZTh-00031X-S2 for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:37 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTg-0001ci-6X for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:37 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:25 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431876; x=1796967876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H43GacNZ74LpZvq1iBt7jAREOYz4e8zAxG+jaXrh3os=; b=eg2BcUsMfcX/5V53tx8sBrrCdEiVJ/daO8m4OWB2FeyC0AZJoclKsA3K UB4JomgViTzc5t+k6YnwymSd35N1jhc17Pgjl5DSai522AHVkT3aZNBpM 3j1uWhiT/KtcxhQ3ssuf1tYTuPzT/ioB0AMZiydkBWmJ9duakTGVySQ1Y MOnSq13E5y+q5KzpVDHuQhOyo/zRXdqTWJ+ienXRt6nGa78WgHTNM3KSa zfal8TM9KrBMjzfgkg3xCnRCCmoQaMZB18cxOSJyD5PgvKl6LKsHxoxtt HC6bsxYO02z/LIn07/99DxXzYpTZD3cFjmH/bBxMIrXQqnkQ6r1dn9Zy4 Q==; X-CSE-ConnectionGUID: xtiq2RGWST6uK34JoggZsw== X-CSE-MsgGUID: RsjDjNX2Stm6O3Gi532mWw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409947" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409947" X-CSE-ConnectionGUID: Fml8hIaRRhG2ftMfKKQcAQ== X-CSE-MsgGUID: XfpiWL36QduylJDRnqf97A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366193" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 16/22] i386/cpu: Migrate MSR_IA32_PL0_SSP for FRED and CET-SHSTK Date: Thu, 11 Dec 2025 14:07:55 +0800 Message-Id: <20251211060801.3600039-17-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431897914158500 Content-Type: text/plain; charset="utf-8" From: "Xin Li (Intel)" Both FRED and CET-SHSTK need MSR_IA32_PL0_SSP, so add the vmstate for this MSR. When CET-SHSTK is not supported, MSR_IA32_PL0_SSP keeps accessible, but its value doesn't take effect. Therefore, treat this vmstate as a subsection rather than a fix for the previous FRED vmstate. Tested-by: Farrah Chen Signed-off-by: Xin Li (Intel) Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v4: - Check if pl0_ssp is used instead of checking CPUIDs. Changes Since v3: - New commit. --- target/i386/machine.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/target/i386/machine.c b/target/i386/machine.c index 45b7cea80aa7..bf13f7f0f66e 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1668,6 +1668,28 @@ static const VMStateDescription vmstate_triple_fault= =3D { } }; =20 +static bool pl0_ssp_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + + /* + * CPUID_7_1_EAX_FRED and CPUID_7_0_ECX_CET_SHSTK are checked because + * if all of these bits are zero and the MSR will not be settable. + */ + return !!(cpu->env.pl0_ssp); +} + +static const VMStateDescription vmstate_pl0_ssp =3D { + .name =3D "cpu/msr_pl0_ssp", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D pl0_ssp_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT64(env.pl0_ssp, X86CPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_x86_cpu =3D { .name =3D "cpu", .version_id =3D 12, @@ -1817,6 +1839,7 @@ const VMStateDescription vmstate_x86_cpu =3D { #endif &vmstate_arch_lbr, &vmstate_triple_fault, + &vmstate_pl0_ssp, NULL } }; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431913; cv=none; d=zohomail.com; s=zohoarc; b=JGR6sE6BWiM/HO/VqpQUPG1UC3b0sXdX2ZFjk+EeE2RvfaxAPJsScB1K+W3BjmO9UYqOh+qYwNHSNBnMXYLXKTa+qZoGkgWxxb4B5LZO1vrITyWWIhFYgduRt3Sz07ZlvkQRrX+qI+46rvHNpeOcjh9B1fhw6DtOmn9tyPOvqLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431913; 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=qHaF88xWg9n7Lz/rAaGYp1BQvO++tg1xAArEaIF0qGk=; b=HY7VNlSWhylF/OU4mKj0khhferEy2c5HzqoFvi0jqldqqe5S2svRoE79PGtpuQMkMSrfORK7kzpGjDg4ckhinN6TGopKfixO0SWldQ6GTw501VrpfrJlD9yB3kD0bDk+FYQViIC6e+QUFr+ObCKFxjWEz5Cv9m1RALXhb+yXMY4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431913510684.5352281454698; Wed, 10 Dec 2025 21:45:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTp-0003dw-Ip; Thu, 11 Dec 2025 00:44:45 -0500 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 1vTZTn-0003Q5-1T for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:43 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTl-0001fN-4z for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:42 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:29 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:25 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431881; x=1796967881; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+ZmFX9Wa38QCyJDA999eLfSD8lk8eMMUymD4mrIN4hM=; b=F7jjHCdkfLCsa/JQD134aSVwaAs4DtQyS7C7EwCgwGBn7ptPYxfYL9Gr Zh5jWdkLubssaZp57uYJ/z8bjQykzLlLHouf3KqXXLDbv8zpf7GannItH zKOox1P9cv/FUQh0P288vX1GKfp1TqMZjxzAZYGT0IW+epB667cH9ui07 C8OeUpKhw5gJqKzi38ZiVF4qy2TuuVGiWUHtrVwrbbj7ikOLygrXximJw G+2qtImd2iJCMnhzVAzzpYBnz/vBbTWcKLDhcn8nhI2MWtZ/nT53RjMM5 xNlVOVzBwR6CmMcAcQI0epAG0YHOQntgL1mhPAZOQQTQICk88zeW+4XWn A==; X-CSE-ConnectionGUID: p88gV2iRT1+mInG3STmkVQ== X-CSE-MsgGUID: /3panwXDRH+qvCvwrFSuIw== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409960" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409960" X-CSE-ConnectionGUID: TS62/0xTR5a67qTvb29dgA== X-CSE-MsgGUID: MGBlX1B5Q6qEzhBLIXLPYg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366216" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu , Yang Weijiang Subject: [PATCH v5 17/22] i386/machine: Add vmstate for cet-shstk and cet-ibt Date: Thu, 11 Dec 2025 14:07:56 +0800 Message-Id: <20251211060801.3600039-18-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431914006158500 Content-Type: text/plain; charset="utf-8" From: Yang Weijiang Add vmstates for cet-shstk and cet-ibt Tested-by: Farrah Chen Signed-off-by: Yang Weijiang Co-developed-by: Chao Gao Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v3: - Rename vmstate_ss to vmstate_shstk. - Split pl0_ssp into a seperate vmstate in another patch. Changes Since v2: - Split a subsection "vmstate_ss" since shstk is user-configurable. --- target/i386/machine.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/target/i386/machine.c b/target/i386/machine.c index bf13f7f0f66e..57a968c30db3 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1690,6 +1690,57 @@ static const VMStateDescription vmstate_pl0_ssp =3D { } }; =20 +static bool shstk_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + CPUX86State *env =3D &cpu->env; + + return !!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK); +} + +static const VMStateDescription vmstate_shstk =3D { + .name =3D "cpu/cet_shstk", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D shstk_needed, + .fields =3D (VMStateField[]) { + /* pl0_ssp has been covered by vmstate_pl0_ssp. */ + VMSTATE_UINT64(env.pl1_ssp, X86CPU), + VMSTATE_UINT64(env.pl2_ssp, X86CPU), + VMSTATE_UINT64(env.pl3_ssp, X86CPU), +#ifdef TARGET_X86_64 + VMSTATE_UINT64(env.int_ssp_table, X86CPU), +#endif + VMSTATE_UINT64(env.guest_ssp, X86CPU), + VMSTATE_END_OF_LIST() + } +}; + +static bool cet_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + CPUX86State *env =3D &cpu->env; + + return !!((env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK) || + (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_CET_IBT)); +} + +static const VMStateDescription vmstate_cet =3D { + .name =3D "cpu/cet", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D cet_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(env.u_cet, X86CPU), + VMSTATE_UINT64(env.s_cet, X86CPU), + VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_shstk, + NULL, + }, +}; + const VMStateDescription vmstate_x86_cpu =3D { .name =3D "cpu", .version_id =3D 12, @@ -1840,6 +1891,7 @@ const VMStateDescription vmstate_x86_cpu =3D { &vmstate_arch_lbr, &vmstate_triple_fault, &vmstate_pl0_ssp, + &vmstate_cet, NULL } }; --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431925; cv=none; d=zohomail.com; s=zohoarc; b=A6E+VSHtiIn41LKlhPpN8Dq6HjcYJXwgc7Fbla4u7xIeu97pD2gH6szly10YzN3q2bvHKREy+gCOJWEr0FGo7nxZUYZxPj7bXjYrfeUGQO0oZzmAlULgn4BExe+lrdQKX9MeqXxAj5CrnyXImXShhYCULu9k1MXxpLF+NNL0Bv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431925; 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=wN+Op1ZCK6uuLNUjIoLF8EIONDzIAXmZKb4cf0oWC6U=; b=UpOR2RHDoXiM0o07WT9rbdKmy4WaMnrDyw+0raF6aTcWL/Jvan4v8ALBPr+wzT0GgMEI0uuhlt/v29RTtUSGHPi937IzixRK4hh6qIYnyrwUgn2gTL1RDNpxX4/l1o7YIZapkyyZxBv5l0UWSbLhFIevvWLh0e1+CwVbgmUUDxQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431925796475.53009306375793; Wed, 10 Dec 2025 21:45:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTs-0003tR-P6; Thu, 11 Dec 2025 00:44:48 -0500 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 1vTZTq-0003iR-7C for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:46 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTo-0001fx-Ak for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:45 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:33 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431884; x=1796967884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kMqBy7CxyEmFl74t7tv9rzwXuI+1Gc0Y9duW9Lw4FqE=; b=T2+EuGd/VLUrfCbp4elzBvM+WDtnU+qCO43o6Eo09XK39mt3eDarcJh2 ISlqKnbU67fCR7SQDhcLx4/ccfGuVCruyORAjJmCuoldALPhRmw96266y 1tGK2D8VvIcuzCe98nXS+FjJ0oemkoXvhGF4HKpzPbgyRKcvqpJ34UGPS oGfVljmV06A9RGPlEWtuw7zACSWVmrjEGE2D6bW62CqCCCm+e+0mhiN4o v9qXHueV+MDj66r6V2eTolcGKnw2Q0T53pEjb3v4SQgn8+p6z4Y5/DWe5 DbMQuKWkq7ArNLlIYRrzWfWPAYifLVyIWgiSaN6UAjvblqIIUjz3/3uvw g==; X-CSE-ConnectionGUID: TUycfa8CQjSfeSBAfiuBpw== X-CSE-MsgGUID: ludb8ejVS/O8x9WflE1Sng== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409970" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409970" X-CSE-ConnectionGUID: npxRuo/bQYKxhgAEhk0r1A== X-CSE-MsgGUID: ULbuviDXShSRvC/7+CTZXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366231" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 18/22] i386/cpu: Mark cet-u & cet-s xstates as migratable Date: Thu, 11 Dec 2025 14:07:57 +0800 Message-Id: <20251211060801.3600039-19-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431926061158500 Content-Type: text/plain; charset="utf-8" Cet-u and cet-s are supervisor xstates. Their states are saved/loaded by saving/loading related CET MSRs. And there're the "vmstate_cet" and "vmstate_pl0_ssp" to migrate these MSRs. Thus, it's safe to mark them as migratable. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v3: - Add the flags in FEAT_XSAVE_XSS_LO. --- target/i386/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4d29e784061c..848e3ccbb8e3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1484,7 +1484,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { .ecx =3D 1, .reg =3D R_ECX, }, - .migratable_flags =3D XSTATE_ARCH_LBR_MASK, + .migratable_flags =3D XSTATE_CET_U_MASK | XSTATE_CET_S_MASK | + XSTATE_ARCH_LBR_MASK, }, [FEAT_XSAVE_XSS_HI] =3D { .type =3D CPUID_FEATURE_WORD, --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431977; cv=none; d=zohomail.com; s=zohoarc; b=SNJbZ3p1g3eJvzWL9Bhc/gQja58HM0JYo39LgjJBMHCOOOGcOOw6SpLTtiDy+GNCJSX1sAaruZOgBMUtAjlIf5Jv/8+2Z/jLzyeN3dCnrWNbRb9WHNLXfZya3CTl3f2xcPrpCUGHbcdJVsUxgJnaPoaqFk9wHul8mGc1gb5B6So= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431977; 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=TDudMgDehLGaLwPSPJo8ifDGRF74/NhCVWTTlrExTJ8=; b=h8juzIYQDPTk8Yk15/P2F+TpEcdoH/NIkwbbjsQhFx/wRxxos4Tz04UQfh4IID/lBrHe9cx9LjQ8j9/Z/oSg4ZDnyO/aXdXHzguUN4SyBbCL7PJoYZ8LSAwpubW8x6Z/J8l0UArZkrF2aEZfPExt+iVcxuKn3CZ85cgJ3G664Lg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 17654319773021010.1779197323499; Wed, 10 Dec 2025 21:46:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZTy-0004Qn-Ri; Thu, 11 Dec 2025 00:44:55 -0500 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 1vTZTv-00047Y-1L for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:51 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTs-0001ci-BM for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:50 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:37 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431888; x=1796967888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=brSRWQQoU+/m4EjgoQyL/jMEqcgttetYwa4KBBkORE0=; b=DeL6e/OVbApqAXrPzHeybAaZPTqdBGgbCtzdjxcsWgDOdUFe3ALbgeew 9fUFkDvCIp90RGgSyEK/a1HaUWrmGdrQmH6jVhjTzUU4xMMcPT0ZeVCzu 5OdC/pHrvRGFa8VvYKrfki6Vqnt4F3CHXRw1qOCXqqhVeaqoqy4EgmvdY SkkBuAJml5jOgn2PiOIed4piqu3L/+Uf97UkZao1EcumCllFUArSXBoih MhoZieGg1bZwyEC18n3fIXs824zxJSWM/nHBr2zr3NPigmbboMfO72TaK rVlxHu3B8tLDLy3wLS1/RBJ/PHTO96Ydnio/geXjBa+HLJSmD1fjI54ua w==; X-CSE-ConnectionGUID: Q0BFhHXkSpW54NcmwTtYYw== X-CSE-MsgGUID: U+0pQXuJR+CBsmmt97lWog== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409984" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409984" X-CSE-ConnectionGUID: XcAvGjRBRhCJVz03oE7SDA== X-CSE-MsgGUID: LhDvip1NRY6zuYtSzH8OEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366237" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu , Yang Weijiang Subject: [PATCH v5 19/22] i386/cpu: Advertise CET related flags in feature words Date: Thu, 11 Dec 2025 14:07:58 +0800 Message-Id: <20251211060801.3600039-20-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431978246158501 Content-Type: text/plain; charset="utf-8" From: Yang Weijiang Add SHSTK and IBT flags in feature words with entry/exit control flags. CET SHSTK and IBT feature are enumerated via CPUID(EAX=3D7,ECX=3D0) ECX[bit 7] and EDX[bit 20]. CET states load/restore at vmentry/ vmexit are controlled by VMX_ENTRY_CTLS[bit 20] and VMX_EXIT_CTLS[bit 28]. Enable these flags so that KVM can enumerate the features properly. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Yang Weijiang Co-developed-by: Chao Gao Signed-off-by: Chao Gao Co-developed-by: Zhao Liu Signed-off-by: Zhao Liu --- Changes Since v2: - Rename "shstk"/"ibt" to "cet-ss"/"cet-ibt" to match feature names in SDM & APM. - Rename "vmx-exit-save-cet-ctl"/"vmx-entry-load-cet-ctl" to "vmx-exit-save-cet"/"vmx-entry-load-cet". - Define the feature mask macro for easier double check. --- target/i386/cpu.c | 8 ++++---- target/i386/cpu.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 848e3ccbb8e3..a65fd4111c31 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1221,7 +1221,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { .type =3D CPUID_FEATURE_WORD, .feat_names =3D { NULL, "avx512vbmi", "umip", "pku", - NULL /* ospke */, "waitpkg", "avx512vbmi2", NULL, + NULL /* ospke */, "waitpkg", "avx512vbmi2", "cet-ss", "gfni", "vaes", "vpclmulqdq", "avx512vnni", "avx512bitalg", NULL, "avx512-vpopcntdq", NULL, "la57", NULL, NULL, NULL, @@ -1244,7 +1244,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { "avx512-vp2intersect", NULL, "md-clear", NULL, NULL, NULL, "serialize", NULL, "tsx-ldtrk", NULL, NULL /* pconfig */, "arch-lbr", - NULL, NULL, "amx-bf16", "avx512-fp16", + "cet-ibt", NULL, "amx-bf16", "avx512-fp16", "amx-tile", "amx-int8", "spec-ctrl", "stibp", "flush-l1d", "arch-capabilities", "core-capability", "ssbd", }, @@ -1666,7 +1666,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { "vmx-exit-save-efer", "vmx-exit-load-efer", "vmx-exit-save-preemption-timer", "vmx-exit-clear-bndcfgs", NULL, "vmx-exit-clear-rtit-ctl", NULL, NULL, - NULL, "vmx-exit-load-pkrs", NULL, "vmx-exit-secondary-ctls", + "vmx-exit-save-cet", "vmx-exit-load-pkrs", NULL, "vmx-exit-sec= ondary-ctls", }, .msr =3D { .index =3D MSR_IA32_VMX_TRUE_EXIT_CTLS, @@ -1681,7 +1681,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { NULL, "vmx-entry-ia32e-mode", NULL, NULL, NULL, "vmx-entry-load-perf-global-ctrl", "vmx-entry-load-pat",= "vmx-entry-load-efer", "vmx-entry-load-bndcfgs", NULL, "vmx-entry-load-rtit-ctl", NUL= L, - NULL, NULL, "vmx-entry-load-pkrs", "vmx-entry-load-fred", + "vmx-entry-load-cet", NULL, "vmx-entry-load-pkrs", "vmx-entry-= load-fred", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 458775daaa3e..33350602edd3 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1370,6 +1370,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *c= pu, FeatureWord w); #define VMX_VM_EXIT_CLEAR_BNDCFGS 0x00800000 #define VMX_VM_EXIT_PT_CONCEAL_PIP 0x01000000 #define VMX_VM_EXIT_CLEAR_IA32_RTIT_CTL 0x02000000 +#define VMX_VM_EXIT_SAVE_CET 0x10000000 #define VMX_VM_EXIT_LOAD_IA32_PKRS 0x20000000 #define VMX_VM_EXIT_ACTIVATE_SECONDARY_CONTROLS 0x80000000 =20 @@ -1383,6 +1384,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *c= pu, FeatureWord w); #define VMX_VM_ENTRY_LOAD_BNDCFGS 0x00010000 #define VMX_VM_ENTRY_PT_CONCEAL_PIP 0x00020000 #define VMX_VM_ENTRY_LOAD_IA32_RTIT_CTL 0x00040000 +#define VMX_VM_ENTRY_LOAD_CET 0x00100000 #define VMX_VM_ENTRY_LOAD_IA32_PKRS 0x00400000 =20 /* Supported Hyper-V Enlightenments */ --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431934; cv=none; d=zohomail.com; s=zohoarc; b=cSFxijH3YIbmQk3+zjjnYXcYgwLTxFNBla9bdRrrqcZVQvQqA4m7n2j9JrnULLeV1TjIiCX2rR0HGKPi590ok00M4ZC3RCFmXTAM/BxWp38kEkekR0Op2kH/y4spxp6cOsCBhSAIq2R4KYMgQojccIqvGEq/JcKT6CGLGs9DX+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431934; 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=1sUmYbGftPzTDZFwVsuKAJ1xDohAX3isFJrDvVBL9YY=; b=Wv/Zn3MZo8b6KEPhZjsTOgLnz6TmpXKqZgYfODW9HPFXa+xAdbLmQbp1D+7cif2Vm8vodr8GhMhgOH48ayQFV1qtedHKkgcgq1dBmFNTmq7etV6XlW/bCGfedIp4M+uRyDcf7T6E1qd0RBMFwah1l/fV8RMMmrioVqHeEICR9nM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431934867938.8839858288333; Wed, 10 Dec 2025 21:45:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZU3-0004YG-9j; Thu, 11 Dec 2025 00:44:59 -0500 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 1vTZTz-0004U4-Ek for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:55 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZTx-0001fN-CQ for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:55 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:41 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431893; x=1796967893; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3n7M74aqCkbEbKfoKd8BocgrGmHYDsrLyL1GwMNnx9I=; b=jnpNCcdMO+8wcTUHfb+kRLC+YZQI3N/zkvK3IUK9JCeRe95Wf1d+LxW4 +9fa+FGg+wtlHCNcPZrOsNPxeeF8N6Pj/fWsElLfbpX3g1mHUcxtvCXFd 9qXdxRuVI/6dax1rmrNfemoUYw5BiFHG4SyPbRy5biuPlflcCyCc3XlFz JxDaKuMq25wkKTGz6gTZ8d2DXvBgDBVbraUYYj8qVLWCRNRFfpclrjaSh 9/wWdOnpx6h39l6F3f3wM/1+fwAzi74bGHQOCZOFeRg3KqX9Q4OM8ypDN ZmnU5GbWYYx5zrvwi9OZhvEcvHu2dTGQTUZp8Oykil8EjmXMDBLaakD85 g==; X-CSE-ConnectionGUID: eDa1dgcnT9inuU2OMN6dKw== X-CSE-MsgGUID: mXAqOGR9TFOeh48orWcMFA== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66409996" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66409996" X-CSE-ConnectionGUID: To8OqnNtTYG1g9TZoEtznA== X-CSE-MsgGUID: kSE9/iCvSb6AEMrKXA5BMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366241" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 20/22] i386/cpu: Enable cet-ss & cet-ibt for supported CPU models Date: Thu, 11 Dec 2025 14:07:59 +0800 Message-Id: <20251211060801.3600039-21-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431936132158500 Content-Type: text/plain; charset="utf-8" Add new versioned CPU models for Sapphire Rapids, Sierra Forest, Granite Rapids and Clearwater Forest, to enable shadow stack and indirect branch tracking. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/cpu.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a65fd4111c31..84adfaf99dc8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5166,6 +5166,17 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ }, } }, + { + .version =3D 5, + .note =3D "with cet-ss and cet-ibt", + .props =3D (PropValue[]) { + { "cet-ss", "on" }, + { "cet-ibt", "on" }, + { "vmx-exit-save-cet", "on" }, + { "vmx-entry-load-cet", "on" }, + { /* end of list */ }, + } + }, { /* end of list */ } } }, @@ -5328,6 +5339,17 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ }, } }, + { + .version =3D 4, + .note =3D "with cet-ss and cet-ibt", + .props =3D (PropValue[]) { + { "cet-ss", "on" }, + { "cet-ibt", "on" }, + { "vmx-exit-save-cet", "on" }, + { "vmx-entry-load-cet", "on" }, + { /* end of list */ }, + } + }, { /* end of list */ }, }, }, @@ -5482,6 +5504,17 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { { /* end of list */ }, } }, + { + .version =3D 4, + .note =3D "with cet-ss and cet-ibt", + .props =3D (PropValue[]) { + { "cet-ss", "on" }, + { "cet-ibt", "on" }, + { "vmx-exit-save-cet", "on" }, + { "vmx-entry-load-cet", "on" }, + { /* end of list */ }, + } + }, { /* end of list */ }, }, }, @@ -5617,6 +5650,17 @@ static const X86CPUDefinition builtin_x86_defs[] =3D= { .model_id =3D "Intel Xeon Processor (ClearwaterForest)", .versions =3D (X86CPUVersionDefinition[]) { { .version =3D 1 }, + { + .version =3D 2, + .note =3D "with cet-ss and cet-ibt", + .props =3D (PropValue[]) { + { "cet-ss", "on" }, + { "cet-ibt", "on" }, + { "vmx-exit-save-cet", "on" }, + { "vmx-entry-load-cet", "on" }, + { /* end of list */ }, + } + }, { /* end of list */ }, }, }, --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431932; cv=none; d=zohomail.com; s=zohoarc; b=kmSDqklArRz1n32To2qSRDM7wmI+4mqiuJxO3LoeygiLZDQ1BuEcW/n49loAWUnx94JfIYALiJFvpKqEuB/T+gxddltJ80KQSL/kxmRdDpnMiiBkcWgm27ea4WdINHm53lArPbDhhR/HOTs7cUuxdpUvg2ynlj5NiQyoyDo4kBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431932; 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=xHr7cSSa9+n87vztJiLPo9bOdrrRQmkaUs5gAmZb8p0=; b=hzVEAxSm8CStZNlDoCmS7PnyssNmnUxrK811bGTU+m7yRJ97hjDA3T5XchVQc3C4p9hPoqldlqkYvpuVKhGh3Ka+VXqs61YrAxSBkKGvxSZJjru/04SC1mi5Fxxx/pamC45eIOyVJVBy2K+5gCuzTHOcCLEQmT2p4T5Uo7rnYt8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 17654319328465.481161682981451; Wed, 10 Dec 2025 21:45:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZUE-0004mm-3B; Thu, 11 Dec 2025 00:45:13 -0500 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 1vTZU2-0004Xv-Gk for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:58 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZU0-0001fx-Si for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:44:58 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:44 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:40 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431897; x=1796967897; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=66V7PYFxiVOdYw2D3BJVJJrWu9A0DxDp2SevYe43bMs=; b=mCg0ZM23+cI+Ls8wrsloNZeKX8U0+Yq25ZAF0aO3uPIegCuZ6mWYHlkz x3Q/TwUBC86HIaxf3oGWaN8bdigtjn4lKjNToO8BPVuNW9+uAbJId4095 ZDJhJ2xC3hkWC3oyWvbhsHwdu/dvLv+0sO2XqQNk5PFR7yMIUlYUrdTmH rz3OQEIceM9CE1U+Dg0Xyvjiov3MJYo7qQplB28ahOugWg7TKCI62zy/z zLXZYERAUdmxmS9x80+6G4qvDFXcmcooR8+fxc2s+YCbEQ6zcP2NiNq02 fAdWYaoTk9lsiBgTk9BMKGT8BVwH3YZJupmLJrIrvh8ZeFSvlu1X92jEr w==; X-CSE-ConnectionGUID: PUwwd5fPREW042ZPx2oIPw== X-CSE-MsgGUID: tsNgyZQIR8ymJYv+9WlmcQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66410007" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66410007" X-CSE-ConnectionGUID: nIgW2W65SVa9JIbke47dJw== X-CSE-MsgGUID: C7AtQXv+TOe0QXht/vYLUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366244" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 21/22] i386/tdx: Fix missing spaces in tdx_xfam_deps[] Date: Thu, 11 Dec 2025 14:08:00 +0800 Message-Id: <20251211060801.3600039-22-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431934184158500 Content-Type: text/plain; charset="utf-8" The checkpatch.pl always complains: "ERROR: space required after that close brace '}'". Fix this issue. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Zhao Liu --- target/i386/kvm/tdx.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index dbf0fa2c9180..a3444623657f 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -520,15 +520,15 @@ typedef struct TdxXFAMDep { * supported. */ TdxXFAMDep tdx_xfam_deps[] =3D { - { XSTATE_YMM_BIT, { FEAT_1_ECX, CPUID_EXT_FMA }}, - { XSTATE_YMM_BIT, { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX2 }}, - { XSTATE_OPMASK_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_AVX512_VBMI}}, - { XSTATE_OPMASK_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AVX512_FP16}}, - { XSTATE_PT_BIT, { FEAT_7_0_EBX, CPUID_7_0_EBX_INTEL_PT}}, - { XSTATE_PKRU_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_PKU}}, - { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_BF16 }}, - { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_TILE }}, - { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_INT8 }}, + { XSTATE_YMM_BIT, { FEAT_1_ECX, CPUID_EXT_FMA } }, + { XSTATE_YMM_BIT, { FEAT_7_0_EBX, CPUID_7_0_EBX_AVX2 } }, + { XSTATE_OPMASK_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_AVX512_VBMI } }, + { XSTATE_OPMASK_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AVX512_FP16 } }, + { XSTATE_PT_BIT, { FEAT_7_0_EBX, CPUID_7_0_EBX_INTEL_PT } }, + { XSTATE_PKRU_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_PKU } }, + { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_BF16 } }, + { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_TILE } }, + { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_INT8 } }, }; =20 static struct kvm_cpuid_entry2 *find_in_supported_entry(uint32_t function, --=20 2.34.1 From nobody Mon Feb 9 10:59:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1765431956; cv=none; d=zohomail.com; s=zohoarc; b=XvhenwB5XHXu9+3+ScjTjhwpVa4r8gByM2hqeqm+WmnX9PAhGKxC7Hd7550WafKKUISEX3QNpGyIGrSQXCT5A7w7qkTxc4Lxr9QkqQ7EHIzwqucfS1YeZpERgZY9cBmpAeAcS5OXDRWEoUf4ArTcrvOc4AY4Nw0osC+qci4RGHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765431956; 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=3KuFr/I06FoF/zL7mVZBcRbBSgaewAIt0dBWbiqdx8U=; b=MTT4mLeDJp14LTiLAmKiXVdTC//1NvI8sRqYqqm02lvP0PYNFxGx1yGemr2as1+2GBQ1PtMsCPhta/XzOjkGlXVLQ5ivFlZ3qecPpQyUTbrI8xTm8WNoiuyJ+gRh18hwuNs/MOsDVX1Txh5XGJlPRBXauHRGEn/WinOSQCP2uB4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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 1765431956565767.9654538223273; Wed, 10 Dec 2025 21:45:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTZUR-0005BC-Cc; Thu, 11 Dec 2025 00:45:23 -0500 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 1vTZU7-0004k6-3o for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:45:03 -0500 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vTZU5-0001ci-BS for qemu-devel@nongnu.org; Thu, 11 Dec 2025 00:45:02 -0500 Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:44:48 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa002.jf.intel.com with ESMTP; 10 Dec 2025 21:44:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765431901; x=1796967901; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0uF8jj575zYxVcWmkztmsgjmlH5SFSks+bBKxFEAv3A=; b=NEsXGvmc/A+DgMj0wOX5tLuU3Vab32ONrPp5oFZ/KkgZjTcxsTcFW5x5 e16wma0Xr96RW4zhCxplrguzQNqVW9zKDUm6muspKJA6CcjRnDiGW57zi PHSRaeaXBiYotTL0MdfnUZbjbJNYveYOpFp6tZ0soEPXGoLhL+1EmaS0+ 9nJlW7hg9SutW0xwnIQ/RjRUayNkqPb3Xox/cqv8UFy/X065lzpsqw1sx 9DfKxjtVh+v1FlUL4eozmrdKeCRA0kutcWkFFlgFPL5EQwF9HnfyUxvjV RZobycvXhTH3MvNtxYa30wJZVRhGGjx8RCKM3Tyu3TEtvxTCf0e9Soa78 A==; X-CSE-ConnectionGUID: d8MCDKTgRxKS8YiKLyU1pw== X-CSE-MsgGUID: +F877dGCTS+PJkVTcf/2oQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="66410017" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="66410017" X-CSE-ConnectionGUID: R+WptcuRQoWiK19k3FqoBQ== X-CSE-MsgGUID: LYgSZ0qYRROV8ROnrBh0cQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="227366269" From: Zhao Liu To: Paolo Bonzini , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Chao Gao , Xin Li , John Allen , Babu Moger , Mathias Krause , Dapeng Mi , Zide Chen , Xiaoyao Li , Chenyi Qiang , Farrah Chen , Zhao Liu Subject: [PATCH v5 22/22] i386/tdx: Add CET SHSTK/IBT into the supported CPUID by XFAM Date: Thu, 11 Dec 2025 14:08:01 +0800 Message-Id: <20251211060801.3600039-23-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251211060801.3600039-1-zhao1.liu@intel.com> References: <20251211060801.3600039-1-zhao1.liu@intel.com> 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=192.198.163.19; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1765431958128158500 Content-Type: text/plain; charset="utf-8" From: Chenyi Qiang So that it can be configured in TD guest. And considerring CET_U and CET_S bits are always same in supported XFAM reported by TDX module, i.e., either 00 or 11. So, only need to choose one of them. Tested-by: Farrah Chen Reviewed-by: Xiaoyao Li Signed-off-by: Chenyi Qiang Signed-off-by: Zhao Liu --- Changes Since v3: - Refine the commit message. --- target/i386/kvm/tdx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index a3444623657f..01619857685b 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -526,6 +526,8 @@ TdxXFAMDep tdx_xfam_deps[] =3D { { XSTATE_OPMASK_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AVX512_FP16 } }, { XSTATE_PT_BIT, { FEAT_7_0_EBX, CPUID_7_0_EBX_INTEL_PT } }, { XSTATE_PKRU_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_PKU } }, + { XSTATE_CET_U_BIT, { FEAT_7_0_ECX, CPUID_7_0_ECX_CET_SHSTK } }, + { XSTATE_CET_U_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_CET_IBT } }, { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_BF16 } }, { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_TILE } }, { XSTATE_XTILE_CFG_BIT, { FEAT_7_0_EDX, CPUID_7_0_EDX_AMX_INT8 } }, --=20 2.34.1