From nobody Thu Nov 20 12:28:16 2025 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=1763436134; cv=none; d=zohomail.com; s=zohoarc; b=G8Ot7drCiFB8/PVfReXrckH2BIeyYmMK3/w8xWksI4UbM7ki5C2oZ60supvdq10An7cuSmR77naQRRM52WxqLX1Xx2NrrnOl0TA41gyh9Fq6qOSFAb+t98iAXVSjQj2eAOFKg8fW4sX/Se2koj72SQf6eXlo3XKRD/Axi2OXnd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436134; 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=V0XjDKbm+KMe2dj3Jbqhd1yQxpqAy4CZfVzLixv3T4CXe01/kWBCQ7YXMnaSdsblROMtler4ZFli6/bl3TLx5O6FP5jqPtMAdMgp2RsZS0pYfc73oiGtZ8BpWvfFeJKmGhbYLkIdz8nU/hMpiU74h81c1gw5kk7ULsnu5/O4ONw= 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 1763436134283518.8924206462176; Mon, 17 Nov 2025 19:22:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGa-0001I7-2X; Mon, 17 Nov 2025 22:20:28 -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 1vLCGY-0001Hb-09 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:26 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGV-0004Cj-8f for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:25 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:20 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:17 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436023; x=1794972023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i0sp4wj5rSSd6tZSRimjqOo45WUYte6rhpv/w5HY6HQ=; b=lb0yskbOws2sNFWwuBV4EKMjF8DfnjT0oNl/Ewj6vhAKayzYnUhZiVt5 BtXvfkrU5J8pRADbvNyZz3xN/qKuPdETCuLvqpjvYS1W8cyRYa1d9nUT/ s9pVkB1zsyZv3AEJ1AAWWFZ4DTmpb2tOMHvsTIOf8hEIf++ld7RTcXXkV bRAfi95/w6jM/caBslBcp5B6DTZkQnhY/UlejpSBFOWGh62gNK9W+cokB IL5Vw1M0J0mhL4LZ+tKMc+7ectLQH6EinG7qrm7jtr8oDcvn6KlBM16cN m6Fx8cUXX65RNeHl2B3ZgK+44hkLpZ1SDAzd0FZQzqsOM4sX7AA2nwy57 A==; X-CSE-ConnectionGUID: OErsOu7nSvu+H9dpra4KTg== X-CSE-MsgGUID: 6dUPJkIIT12ZjsKnyIakng== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053725" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053725" X-CSE-ConnectionGUID: jryimD4CS16MurwiigIJLg== X-CSE-MsgGUID: P4zwZAEkRfKOyfaRWxrCAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537132" 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 v4 01/23] i386/cpu: Clean up indent style of x86_ext_save_areas[] Date: Tue, 18 Nov 2025 11:42:09 +0800 Message-Id: <20251118034231.704240-2-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436135259158500 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 Thu Nov 20 12:28:16 2025 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=1763436111; cv=none; d=zohomail.com; s=zohoarc; b=RFkxuYdln8e8B4jhGdwZ7A923l4vsssXfCt42MRs3TXAFO1Ebwo7l+H78vtYSl3fZ6T+ClAYRl6B77aq8Zgw8ZarlXre6XcauzqCVf5Im9pVLDVbtRJZDec07NCf9eqarllRzzMwnQJeSsV/gLNlysebyayNKEdZgFV6GNRCGS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436111; 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=NMnf4XAxVRK7K3X4bvDr1bncz9bgF1baNqNOmhSD5W3yPbNhsbKFwA+8efKX2zcODfnXQjZDpXAlDTWb/TrsvMMSJTh9OPbaSEtnoAFaiTF/uAG+oZx0m4YhLOjaf2uzHUhfUvBjgEPGWonsoNV0PoYsm0sPTmXIlYHcF4KvPPU= 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 1763436111259129.90637151813735; Mon, 17 Nov 2025 19:21:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGa-0001IB-Gh; Mon, 17 Nov 2025 22:20:28 -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 1vLCGY-0001Hy-Rm for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:26 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGX-0004Cz-5k for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:26 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:24 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436025; x=1794972025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=enKcO38L6D4368mFk9WuGh+dSr2WFd6BUxl4+hq0Pz4=; b=HBYI7k617H5oqeSL+lNSk0IluxoOiDBM11bws3uZxZkzXCgZ2tdWyZE9 RQok+joCbGAN9B8ixY0PPfe6YFpVE/ra8Qf2KZmkclnP5uG+0ROxq3bq9 S6ftAuY/b7SmBR3+uWFbQGe6BPTYaOvzCim5TaZn5EZUHuKE9AlPNM1eB BmLKtwQg4AX80dQ68Qht+RIjk/miK0315m0/pFVGGogvxcV0LK5ul4wNr HwuIyqGVuyw+YkW0rpP8wcuchlD/8vp9foZKaP1r7hcwVfFU0yi/LUDlo 2WjR/Vlrw+eQuPwaKCRUFAf7dCxEQ1nl7Yw/+8yl8zUwWD3mVZ1feblvr A==; X-CSE-ConnectionGUID: Q+H5fnxbTAeqfgqICsKk2g== X-CSE-MsgGUID: 08VedOSbTBGX86aKV1QSYw== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053738" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053738" X-CSE-ConnectionGUID: KloAmZodSrWOopC6xpWqrg== X-CSE-MsgGUID: B3BIwUb5Rsuu6KBSN/t8IA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537139" 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 v4 02/23] i386/cpu: Clean up arch lbr xsave struct and comment Date: Tue, 18 Nov 2025 11:42:10 +0800 Message-Id: <20251118034231.704240-3-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436112015153000 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 Thu Nov 20 12:28:16 2025 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=1763436127; cv=none; d=zohomail.com; s=zohoarc; b=Oa7dPXQvUMi6WPcXEoQ804vGaD44Ao9qjMRlwbxw0EWeCVO0In1jW2yuV0CejtWejSwYotSq03EKIcObL0tZskCTxAngtlc7T5MLzNzFnqEwNV6OJKLDvEu5pKFMiO+hDopjKmOCTVxJrCJsHoy5tNRyT5Wxcjyl6oY25D0Gl8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436127; 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=EPUT+Gqjs06mbn1iS8UuBfRIKO/LJMPAJzg2YoV5QeF5efPYYl2e3lhIFPWfmspbOjU8n0ILLadvD3LFP/LsBNLE6JmAe0VTHhpMrM0yiaAtEhcXfyjAW5AxWAcDYZ8s6pHLBn1UQCUfcjCLYvyts3dTtbZwmxYun0h88c6StXU= 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 1763436127157389.2329793950006; Mon, 17 Nov 2025 19:22:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGd-0001JB-1V; Mon, 17 Nov 2025 22:20:31 -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 1vLCGb-0001J1-R1 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:29 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGa-0004Cz-1V for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:29 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:28 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436028; x=1794972028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8C3Jr7X1l8TpBRvZp6B109oTdbjj9lF4vCeG//3Doqk=; b=kEdLMrBMgV8Wl7Pi2m/fAj66XwZIPxWolo2sON9V+tDALvwQvQq9S7vD ljORfvixVzYjQtnOIaH+9M0Msy0R9cNacY/PvrVeWH3PYEEd1S4JTy4ek AFct1XjfLSIQYQz7aPeYkoqAjITAn+ImSto/0xVWlktnKpMVB8BDjhvRX 6XMNEvkaxHAhQN9yWOk4STIyAQ/Fo8xtUh2ZyIAz50JRxstTDSNlqn6Lt fvr7icn6RYe1zGaWLKNWJ6fmrBjeQRyMvbJ4VL4niXfcChtZ2LMy4z48/ 7nQLUzlxlFTxl/vPGa2U7EBr39vo15X0uUap+oEEhFySqZzua+IKb2Yuw g==; X-CSE-ConnectionGUID: 10uLzF/mSoujAzA401JzDg== X-CSE-MsgGUID: MSP4xc5BQJqTfnxG6ZM1LA== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053745" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053745" X-CSE-ConnectionGUID: uSrAk/myTAuRrbqhnqyNbg== X-CSE-MsgGUID: dL83uZetQhGlRy+SVpzJBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537149" 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 v4 03/23] i386/cpu: Reorganize arch lbr structure definitions Date: Tue, 18 Nov 2025 11:42:11 +0800 Message-Id: <20251118034231.704240-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436128176153000 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 Thu Nov 20 12:28:16 2025 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=1763436103; cv=none; d=zohomail.com; s=zohoarc; b=arQeGnriixQOLxr225R+zLi8HM1ccfP0J2nU0dZeMvja42Ep6PgRi9RLf15GsMRRVpcmaQuMFp0sltbcP/hxRYE8EadEm7ouX5XObDcD1tbA9cU9Onqk9k2oP10jI458fk03+6ttsS39xf50UIuLDHypyh2ZL8IQAN//xmJL9FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436103; 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=P+cFfzRNWly4f7pY+2bauuqWCXDBAQRczDDMeKVRkXzo9g2NhqUZ1T5J5Y36PYtWVyLQ90e62Mohqhs6LQ64NA6sadtZ9UgDWdQhI6Gn+qe6wap8qYI54pE64Fx/jf4x1dxGnhZkgyGjwxfib9wAuJ68sOGLSOICs/43NbGvYHM= 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 176343610312999.46584806622934; Mon, 17 Nov 2025 19:21:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGh-0001Jg-VV; Mon, 17 Nov 2025 22:20:36 -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 1vLCGf-0001JV-UC for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:34 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGd-0004Cz-L5 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:33 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:31 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436032; x=1794972032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PTGXrrw5EFr5RFekmd6pZ60Tp1rqIf+SCDaoLH0Fads=; b=I9a07cVWSVpikSnxx6O7SD+DtQXMQMjywomNI6gZmAvU+6gDN1KGQGOV tI/HFU/RnDjT4DAaY+CxxbJxTiQVrFxI0WhClYuzYnApXIE2RRzxQVnNP /HFPWCZbONxfPEWbF6s4ioUfTjSUhi1u38NmvF3mgmt25bKMoLvU0A0AE SED7eUreDiJxOhLKAJsIkIqfPfh84Bt8cRNtm46ntrwGtDUUDdxKWaHXJ inNTkEGFrqLwJsultLmk40Z0Y8L7nhIb/WO2rTbCe8fsDZ+3nWlS5GUlL dbA81iiHH5WTV67E80kaSSCS/p5EsB4uxipGsznOhrqOi/lg0Jy6rvyl7 g==; X-CSE-ConnectionGUID: hZXb9FqlRWy0ZrFmXsCqeg== X-CSE-MsgGUID: 5xLIp/MxRH+6RaEL1SCgvg== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053756" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053756" X-CSE-ConnectionGUID: Mah8EjOFTXmwtcXgSH5jwg== X-CSE-MsgGUID: 5Yzn1qr5Qpu8suvzbt1oXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537159" 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 v4 04/23] i386/cpu: Make ExtSaveArea store an array of dependencies Date: Tue, 18 Nov 2025 11:42:12 +0800 Message-Id: <20251118034231.704240-5-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436105351158500 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 Thu Nov 20 12:28:16 2025 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=1763436068; cv=none; d=zohomail.com; s=zohoarc; b=oGutwP3EdK110kUmU17sqg+jl299/9Dgn+28A6X39ZF+5g+MwfJ4gP2tOn2TGxAfoh/BIWwN40eHzflLmXfUHg2+Y6tljEtcLsVL2Ug6Ro59MmbD3VVobTnPre1DD69Ef/RK5h7lwXkNXVrCBZhGK5VJzDtMcHk11LGcTwKoZ3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436068; 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=HOj1B2hywOyxQGOoL58cGh7E9TrsLubVCwWkkYR19/rtUm9X11XOrA159CCJv8mnARWsseJf+HkahmGShx2QlPllkygCp0Jb6zJqtUxrNu/W2H7wQGPOLpwLfOiLvEkoGStRwWzGtsC2RwksfMjfNPTCTwta60dxbFLMZT6jffs= 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 1763436068986345.05153598899267; Mon, 17 Nov 2025 19:21:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGk-0001KG-Ig; Mon, 17 Nov 2025 22:20:38 -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 1vLCGi-0001Jv-KE for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:36 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGg-0004Cz-VH for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:36 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:34 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436035; x=1794972035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c/VS1/2chdkAwU46yWRjXngVNYQ5YwGggg1BKVSm57Q=; b=PE74lcJ61nzG6wCsObaOQj2uALLMwp7uXZr087i1vHzARdblHzxCVj0S V6wihAGsUdpbE7DCmHairXtMI9qaohXRBkDuFYq50khMUO4wkqW007lax EArPz9XlL9K1LpvV9uDGqxW8AacrMCNDJ9gfEeFD+ULRNPcBpnALD/Bwi ooBknLQkTn7d+egyZmqMnVzO2BEyG2J9TEtS/FHKIzk/8Tj4Fk6v5u17C 2+JpibM3JZN3D4MfhsOgf6C5HnIXD+ArD4uCGBaUgTt6nmNBwTEPO1Vk+ 4xLCoASqhi7dOEwBvwuPkOwbdixKU7MXWjY+7hYlCnvDRdr8YkvWF9LVF A==; X-CSE-ConnectionGUID: 99dnE949Rnage0cqfqp3rQ== X-CSE-MsgGUID: /Zrdn6x7T0u1zUW4pfm6PQ== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053767" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053767" X-CSE-ConnectionGUID: tY2UtiO5SReuvQs52PsQQw== X-CSE-MsgGUID: 6S7lQ1wKSUGghZcA7lHJdQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537165" 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 v4 05/23] i386/cpu: Add avx10 dependency for Opmask/ZMM_Hi256/Hi16_ZMM Date: Tue, 18 Nov 2025 11:42:13 +0800 Message-Id: <20251118034231.704240-6-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436071906153000 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 Thu Nov 20 12:28:16 2025 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=1763436071; cv=none; d=zohomail.com; s=zohoarc; b=DnvxdnTeFPXSohFFem8X7tHevS3p67ACs0u9GuW4Kzilfzn0USI7N3JrWbzlkKJZ20IV38dCgVMItbL/SMWQ+2n8Ei7Qe1l+4vui5zhJfFg+7J7ues+96kq12BgeyNTKoeycD7IjUNgo5+12rp9HUADdrcRYvKGA2KQCaIKlAqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436071; 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=JvucY/hK+xVYgzuQpndfGR15wrS4ewEub/tr3loU0SM=; b=MNBWPkHi9yophS4bpJW8zFCsqk8+KbxQzRlpcHk9YLHua0CKx2byOLIv4Yp5iKa6HbAqrB4tfRTblfZE8801wk5sTLA1cRRGRJzEEUyEQmsIccbkPjDSXM7YAxeoupcEEKCVAtdA5Z4mhVj32cPKe/umiHvl1AhjWIhAcStCDWs= 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 1763436071562819.2723863263458; Mon, 17 Nov 2025 19:21:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGp-0001L9-23; Mon, 17 Nov 2025 22:20: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 1vLCGm-0001Kf-GO for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:40 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGk-0004Cz-Ey for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:40 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:38 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436039; x=1794972039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=itRs9sDLTa1KpZpW5WfGEJxQx/1ikIuO3q3OzD0yhqQ=; b=V75okEjy3q5bmUGMeLMMkajCYUMqvhJAURW54iPsoWATZVvTj6LaVyHW UAqknduuOiDJvnxYCTM+HUmalqOR1KD090+matzIkggfPZFGFcE/Y3VYc qPOoC9lIwevXaS+xLHvL4QUFnyW58vDZcZJ8lQyHTwmtmcuu7Y7MYTemD K1f70PNh5fBenz74mlFFdt93rbj4YF6KlAkKSzKPkqiWX2AWQcrgZrrYS y92XHVb7qaFuyjLFdDzER8IPkmSeNZFvrXBdekmhRKvRIRNPE2EzwMAQ1 ddmeiL7mfPLFSuowP1U7wgl7ORnPoQ0ityjAYKyEBRQ313IGi2sDUd1Jt g==; X-CSE-ConnectionGUID: 1IaNTNTXQs6UEVI+hO7j9w== X-CSE-MsgGUID: ZEDydnCPTPWs7HUG1wGsjw== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053779" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053779" X-CSE-ConnectionGUID: +RhnrtYQTviyFlq2NTlZug== X-CSE-MsgGUID: 2T4g6T12T0uBMeJ7MFDFzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537175" 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 v4 06/23] i386/kvm: Initialize x86_ext_save_areas[] based on KVM support Date: Tue, 18 Nov 2025 11:42:14 +0800 Message-Id: <20251118034231.704240-7-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436074062158500 Content-Type: text/plain; charset="utf-8" At present, in KVM, x86_ext_save_areas[] is initialized based on Host CPUIDs. Except AMX xstates, both user & supervisor xstates have their information exposed in KVM_GET_SUPPORTED_CPUID. Therefore, their entries in x86_ext_save_areas[] should be filled based on KVM support. For AMX xstates (XFEATURE_MASK_XTILE_DATA and XFEATURE_MASK_XTILE_CFG), KVM doesn't report their details before they (mainly XSTATE_XTILE_DATA_MASK) get permission on host. But this happens within the function kvm_request_xsave_components(), after the current initialization. So still fill AMX entries with Host CPUIDs. In addition, drop a check: "if (eax !=3D 0)" when assert the assert the size of xstate. In fact, this check is incorrect, since any valid xstate should have non-zero size of xstate area. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- Changes Since v3: - New commit. --- target/i386/cpu.h | 3 +++ target/i386/kvm/kvm-cpu.c | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 3d74afc5a8e7..f065527757c4 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -609,6 +609,9 @@ typedef enum X86Seg { =20 #define XSTATE_DYNAMIC_MASK (XSTATE_XTILE_DATA_MASK) =20 +#define XSTATE_XTILE_MASK (XSTATE_XTILE_DATA_MASK | \ + XSTATE_XTILE_CFG_MASK) + #define ESA_FEATURE_ALIGN64_BIT 1 #define ESA_FEATURE_XFD_BIT 2 =20 diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 9c25b5583955..2e2d47d2948a 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -136,7 +136,7 @@ static void kvm_cpu_max_instance_init(X86CPU *cpu) static void kvm_cpu_xsave_init(void) { static bool first =3D true; - uint32_t eax, ebx, ecx, edx; + uint32_t eax, ebx, ecx, unused; int i; =20 if (!first) { @@ -154,12 +154,23 @@ static void kvm_cpu_xsave_init(void) if (!esa->size) { continue; } - host_cpuid(0xd, i, &eax, &ebx, &ecx, &edx); - if (eax !=3D 0) { - assert(esa->size =3D=3D eax); - esa->offset =3D ebx; - esa->ecx =3D ecx; + + /* + * AMX xstates are supported in KVM_GET_SUPPORTED_CPUID only when + * XSTATE_XTILE_DATA_MASK gets guest permission in + * kvm_request_xsave_components(). + */ + if (!((1 << i) & XSTATE_XTILE_MASK)) { + eax =3D kvm_arch_get_supported_cpuid(kvm_state, 0xd, i, R_EAX); + ebx =3D kvm_arch_get_supported_cpuid(kvm_state, 0xd, i, R_EBX); + ecx =3D kvm_arch_get_supported_cpuid(kvm_state, 0xd, i, R_ECX); + } else { + host_cpuid(0xd, i, &eax, &ebx, &ecx, &unused); } + + assert(esa->size =3D=3D eax); + esa->offset =3D ebx; + esa->ecx =3D ecx; } } =20 --=20 2.34.1 From nobody Thu Nov 20 12:28:16 2025 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=1763436262; cv=none; d=zohomail.com; s=zohoarc; b=XPkiR3WoZuuL3R/z2p6yQZfBzFmi2WvtGeco66Ydo48NfIrWUSCz+0oAZpch+Ziiuatt9YhYzZfYIcFYPpx4mqPZ38YhhJvXQOk3sxs18r/Q+nqDPBXKZviP/eFZoQT/4VrTAMCgjS/5eTlpddQhZsJ4lc1BAhG1BacA4msTzzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436262; 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=eeknXWsTAo786c0Hy/hYUkVb34qIj0x1XqWT1xjxy9Y=; b=HOYKALhdM5fJmYbO2fNMBq0VaaV1jnfW2kRuK29nJdvQ4rWDjtIYFHXGzo+GiMl+c7lCY9iH2byT69+WdJTwNV/Vx7rSa4lCrFZg+qVsxCRy9G6Zf9LjG5qiEXzYkvfTE/Z626Wi5trvsX+Qa9JvXMD1N06kl1noLmuptoxxQ28= 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 1763436262498737.2076978886557; Mon, 17 Nov 2025 19:24:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGr-0001Lt-IL; Mon, 17 Nov 2025 22:20: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 1vLCGp-0001LH-U3 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:43 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGn-0004Cz-Nx for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:43 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:41 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:38 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436042; x=1794972042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sPgQ6HV3cQvKboeym46NGXGdw3g89C4CiandiaMUJkA=; b=P8+39O4Ay6JNSCijwWHTAm42jS3ic4VwuUWAHmVBrWJbmTtX13WOaymt J3H23HX30+goA3i5kbFdlluLAMurkImE6/A1WKE87NFCod43PNAXFAnSI qltTPFht8EqTUjRGGFXel8LI/v+QRN58V5ZHMkvnF+wMYunscAIpLWscD bHOrXXH0LcZCHQlTroiDjEVKih5XRe4wmSYkmyeGbbgLliLl+gdWG2RPz JbvO9QoVLuT4CgPX1qXoiASrh/6ISToVj6w91W4XokXmRPr7DYJo6HeoU m6MYEjGztriYsYq0nSpEXusv7zz6vcM9nyyfkioQSgTjPp67dRaBHzzZT A==; X-CSE-ConnectionGUID: Rs5vC99oRSO6wpKaJlbB2Q== X-CSE-MsgGUID: pKYyFWH8T+KzqTht2sp9JA== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053788" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053788" X-CSE-ConnectionGUID: hPrQoh4mR9CkxfFu66VihQ== X-CSE-MsgGUID: kMHQ5/8FR7iaD6GvwOPUqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537178" 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 v4 07/23] i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves Date: Tue, 18 Nov 2025 11:42:15 +0800 Message-Id: <20251118034231.704240-8-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436263336158500 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 case, since its entry in x86_ext_save_areas[] has been initialized based KVM support in kvm_cpu_xsave_init(), so use x86_ext_save_areas[] for encoding. Tested-by: Farrah Chen Signed-off-by: Zhao Liu --- 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 Thu Nov 20 12:28:16 2025 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=1763436229; cv=none; d=zohomail.com; s=zohoarc; b=bCKpc+xhrjmYCW0Zaw7t1edXSNbyoezFj8y6q7uuPrgvefpIFazjb4vEAXxI49lldsKqb4Sq60Skugq3uMF1E3wKU9GllzSz/B9Ygn1Nb/ES39fwPFxumcWXjndamU+SieYQRS601uKOCLEmXLrrmrgGhswLErRWAWKOifNQxdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436229; 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=ELOlCKsfLKe6ucR5swLeTLeUlH1StZeAin4Xbjl+0Mc73442n7QdmTIfLHJ/GNEv8uR4ljV82FFJ9W00dlwWscwQxAJC4GnHuvKM429reu7eO1rg5cwEnvMpNqw3ZWjKDs9gbEF2QbykNFZjA8px4XMbFUKl/tUtv8SGKZduP7I= 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 1763436229812333.41692807857714; Mon, 17 Nov 2025 19:23:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGu-0001MP-PR; Mon, 17 Nov 2025 22:20: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 1vLCGt-0001M9-Dg for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:47 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGr-0004Cz-7D for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:47 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:45 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436045; x=1794972045; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OLmeyBkc275l2fFpoH7p7H8roBE/4ZOOO8W3RLBkAq8=; b=h+Ed/YxuN62bhgFRgihQIQeq3gu9DMd6LzVz//AqensgbEWbatv4GDrN OGuGfRLje50OCYw81vm5AngD1E65aaCBwAPArmlDjwdt7DsFkwBw8jLgu R316Tqb/yvQxVqrMsewKrnGZozetQ4uP7zWwtQYfQLdaqDeK+RMtqbKJ3 XDpMrc/CNfaQiouV/Nide++I/eoZykAK5heeSAgqWLCf2uoI7CJ27sPhc sWhs4pPmeQ3LGmSZWSOZ8MW1Jq66ii/J20wqEjnSgkvVGG5PvQQ+jXOFk 6PIH+hTqj9UVFq5JviThhvbxT4zTqSUqokO5nj7b3Mefzdkn3XQ8pqLJR w==; X-CSE-ConnectionGUID: Rd2jTk4JSY2YOmHk7PZAwA== X-CSE-MsgGUID: WEZgORb9RQiQuklp5xbo2Q== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053796" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053796" X-CSE-ConnectionGUID: rsUv9q5nRhqTvG/ZYEl54Q== X-CSE-MsgGUID: NHwk3NPIQHuy7ij2VwlLlg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537181" 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 v4 08/23] i386/cpu: Reorganize dependency check for arch lbr state Date: Tue, 18 Nov 2025 11:42:16 +0800 Message-Id: <20251118034231.704240-9-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436231314158500 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 Thu Nov 20 12:28:16 2025 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=1763436235; cv=none; d=zohomail.com; s=zohoarc; b=Yenx/TpKuuvZE0BYCVHQjiY/aSsgj5eb0sY4MIW2j86lkChXETS2yWQc3JPZ+EpDkNG9/jRvHIkBdKfjlgqpCVEpEOP1f3CGK+OxeCrLPoaTrO/IW1cvMXsfxkjQIytgbABl2BuaSCSf3bPJ+ApR+RdUgMROi5mvtC9RlvX8TZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436235; 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=R6p8VgRYFScBNvkhBFTACL3w9C68Czfy9H1gQgyTTRfz45QHiX5J4w/hjYhOo4+bGEEwT7prEnbd0ZsG4XHNqVF7wnSeMEaCgCvdghujrx5UFWWPLytHQu1hsNCUVPVxT4b8KtxjQCf3p7/Q6hAykUv+odVfKCe4AYj+lGXCt7Q= 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 1763436235346545.3873715215818; Mon, 17 Nov 2025 19:23:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCGx-0001NP-Le; Mon, 17 Nov 2025 22:20: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 1vLCGw-0001Mt-2r for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:50 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGu-0004Cz-HF for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:49 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:48 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436049; x=1794972049; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fJBFcQVoKmgeoUmwsBmvZdBtcnTJvhtd89N47vMSmQc=; b=HUd3JsPOFNOuXqDwm3fJhSJMBJ4Zh9QaIPsbfXMjIEZO6yB7e+XCsBWE fVU2MNxmpkjtH0eUD/2HRhYzEsHafszX/dMhK1QIaJ8JZHDcWfl/blxOh cFs4LFVD5mXM1s9boPnLKKXLIv2AGA4Lly16wdkPIiLz/kurhFyfryz0d 1S6ZmCUjWxoGP+gZpm5cBzdXL9QBY538YaJjMOo+a17/anM2GieMKyIgm iscA8ojv15M37BiHoGwpjzmKZ6oo2oD4/lLKuxZPhVhpFYh85C3cNlkss Dkc623r7iI/k9wWjdl62qOJ1n8/NWQZENHMQ1CMa/Zu5i+IPckwVquPpM A==; X-CSE-ConnectionGUID: UfClem4FQGWxqAirqGUnYQ== X-CSE-MsgGUID: 5OOFnSklSeaQx2L0vDxL/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053809" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053809" X-CSE-ConnectionGUID: eNy4ULW9SyW1mjd4plv9QQ== X-CSE-MsgGUID: VpWYT4o1RpyXQV4OX8Lw4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537190" 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 v4 09/23] i386/cpu: Drop pmu check in CPUID 0x1C encoding Date: Tue, 18 Nov 2025 11:42:17 +0800 Message-Id: <20251118034231.704240-10-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436237287158500 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 Thu Nov 20 12:28:16 2025 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=1763436098; cv=none; d=zohomail.com; s=zohoarc; b=YVMcS2XsCZvVhFG06Rklx4ggLGNfeMzK1OaabnJsr05WkM11sc/bLXOOJ9rS4mE/n5fjz+2cF+nZebDQaTGS/SiKF7jMCnV+esdHA50lIsNTqCRLFiYrcbD3FIbRb7VW031rcqcUeGGFTx5J8xMrGMEv/SerYXvROSta7mkbmgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436098; 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=Kdvxhs4tl2cgTHaoyq3NU0C92C53tYdQydWmgfHtIzDD0eFEOuNfn+EghGd83wX+HsHMIl3BEPhWnx8ZzytzDfHPbLYKtjhIIDGlsa5S7PRUMY4SWNtRQToJYuaoUA1VWqhSv/OGqgsdloFZQSrZHjpdEZrf8HDR2rlTS9S/RJ0= 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 1763436098885797.3485394403785; Mon, 17 Nov 2025 19:21:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCH7-0001OL-1Y; Mon, 17 Nov 2025 22:21:01 -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 1vLCGz-0001NR-EY for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:53 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCGx-0004Cz-Qv for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:53 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:51 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436052; x=1794972052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FovsNeUNQb3Mbfo6UFh8WpHvsMB68L7Ws+8KaJE9y0g=; b=Pxrr1iw0b1+/xeE/YDHWf1KFkxXzobbVSDrX8Oqr9IR/LM3HDHvCwfA5 MObrDBOMUqUJAL4JqvcQpUnljq5c7AslXAPWFiM3W1nxfQM53Vuax1xOl jvApm4+mip5NkWGYqxufW+Q0Fm5EmQFJ3AL/LIJCGm7QoLcHSk2viCfMn /2jKpxGfYT5UCt17WhqFA/HdoN+IKWCKAFETWcGwWt2CTox+zuZwm4PrQ 5BK+vicL2Hfg8p0ZJ+Gjfzvzl4DkqUj513X/On88eBMVzpRwDu1jS4t6N yfQMfoRi0WOod7uyxWKcm8DXPEdFSj9rHQyL8cKAcNuqw1Q9l4gFRzDpn g==; X-CSE-ConnectionGUID: pAysUjvcRPCNBQezdLNG3Q== X-CSE-MsgGUID: ZGcS6X8WRY6PJy7TJn47jA== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053822" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053822" X-CSE-ConnectionGUID: jt3zLP1qQDOpCq+K7ZLdlg== X-CSE-MsgGUID: xkS3xGu6QFSU7K/EdFT2kw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537198" 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 v4 10/23] i386/cpu: Fix supervisor xstate initialization Date: Tue, 18 Nov 2025 11:42:18 +0800 Message-Id: <20251118034231.704240-11-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436099673153000 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 Thu Nov 20 12:28:16 2025 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=1763436123; cv=none; d=zohomail.com; s=zohoarc; b=E3Uf6heplfItQw3h+pyZcUm1rd04G3FIv3FZBMH8pHi13RueHzHhJKJUb0d+8GJpABd4H3sh5MZvjBMxT6lHWZHVj4/eOuUI+2nYv0d5nZ0p0hgves76c57ISGCDnCv2O4cgBSXVGxkcOn1myMhh6Q7rBZInV9WkRSJ9dBb8GO8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436123; 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=XYs18VfzwDPlhLisPW0wJN9Ma9G4p+sBVEnQBX2cYp74QRCjNSTQRMEwf52srxp+1hOp6F32ExX7rnCi/jfM3abVfgQd7afXp3boPcSrz3Vue4iMMZ6FXOAd0KOlMl7AO0yipMNQRKuW5sa7mqi0kkHmdC1UFpaw3lJZ7mUuEGA= 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 176343612334297.87591058101214; Mon, 17 Nov 2025 19:22:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCH7-0001OW-Jy; Mon, 17 Nov 2025 22:21:01 -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 1vLCH3-0001O0-30 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:00 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCH1-0004Cz-EU for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:20:56 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:55 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436056; x=1794972056; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DZ3sfvrb+qc8GsNdFeIp7NVIUjHrM1Kf/7Vu9/XqA3o=; b=W2ahBRBBynuw7ALBlK0v74Wjr9YrYGf0j7YaqWnQvQXejXzyUvEu9WQw EHKNaisSO3FaaCdZxCbS0i15V23h7lLyAdwBsI+Ft33wkydUUfQnf58Bq QDvkycJehcI4ztM3OBmfRfTOV6IvuMmlzf9MShSzGM84gztMd0AEqqDkF O8P1b8Sq1kqfaPLc++4BjfXvrXYTy6UZv+L5mC/WyoHJ32WRZB0IfxqOM l3ciM4KK3YWZzq/TztO+EM4bOAsGWN3isRQ4fwIQXepcpoCKXgqSkTQ8F M7Rbrf9JdFESZZ0klmcBPRm/xvmsXspF2yTTHrKlX2if/dhBg6IsuzfZ+ w==; X-CSE-ConnectionGUID: sAu5HJOwQKCE5rdggdxgag== X-CSE-MsgGUID: SkxfnEksTiuV++QUx0ak7w== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053836" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053836" X-CSE-ConnectionGUID: ERNT0Nx1ThaAhGyQlfd4jA== X-CSE-MsgGUID: LxvIqZGURLCoPlJQgObojA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537207" 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 v4 11/23] i386/cpu: Add missing migratable xsave features Date: Tue, 18 Nov 2025 11:42:19 +0800 Message-Id: <20251118034231.704240-12-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436124393153000 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 Thu Nov 20 12:28:16 2025 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=1763436084; cv=none; d=zohomail.com; s=zohoarc; b=g2fYr8voinbXz1nGx9KBq4jX8x1CT/+QtiLgpDYGf1ST01AMZ6VnxGU9Ogq7Ptlh6PgMn1jEwiXz3Izsu5cg4d0kU88du4e+yp/mmXo72l81qmml2OLHYd0OHFo3leD0eBAs7Maijw0BxpVePuW1VyBmX1J17c1bXLH7NttbLBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436084; 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=h2u+WSk22OUTSrQr42COL4cy4Qx9z5pUUBmI9wetwnI=; b=A5kJ544Q/QIwywocXzijfX3tWjYRcNlbx66AHk9Q4pSZhsn8u5hyhkE4y2aMQ3VB7f5vMBF2h4N5B+EB5nHQRcwoLkBQIMDJv8/VY8CgpbYFNJ0ZuKqEz0OioT8YwDLpthSA1LT2rqfwjRO/zBmyf+vxylBhlZ3jt9TGMJmwohk= 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 1763436084759270.8519141167736; Mon, 17 Nov 2025 19:21:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCHB-0001P8-LC; Mon, 17 Nov 2025 22:21:05 -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 1vLCH7-0001OM-5D for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:01 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCH5-0004Cz-9X for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:00 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:20:59 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436059; x=1794972059; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NHn+nG8NE3ybLMhwAmk/PNwzcXZNoyi5s9vO5Z2x3JQ=; b=JoUlpIcN5G/VwJsFQXBhlkrHca3ig7JL1Umb2s11ZJaMlMpt+OCCNPwA e+V8Fjdc/xNYn2CYDcH2wKflgN+DlobaTPnOogNpVQQR8B8SeA4Db6k9Q 8S/zOKFF+yDbBK2sFl9S6662wl7ZD46QKaVFXEH6YyjNLYfrScFj+TSfb +akdz9s7s89pP0ZFKTsuOSBr74j/OQWh/VYWZ2gVJFRXphW51UQF9u20v i5e0guVKQ5kmPkxAWx8erkYR+LhdlflHzmCtlfRhTVux+3VQ6bXpXBWEU wWKOjaLKn+QPPZHW1LLUFU/Isha0EkthRmdS1NMDBSbuGV4dFk37pXMi2 g==; X-CSE-ConnectionGUID: T8chlvusT+KYUOpbNjiE+w== X-CSE-MsgGUID: PN2oaqnmSP6iB1zJK9JCEA== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053849" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053849" X-CSE-ConnectionGUID: h1k8TwFyQp6SD4kV0kCFIQ== X-CSE-MsgGUID: hiQMhN89QNyYVm2dziwisg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537215" 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 v4 12/23] i386/cpu: Enable xsave support for CET states Date: Tue, 18 Nov 2025 11:42:20 +0800 Message-Id: <20251118034231.704240-13-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436087724153000 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 f065527757c4..bfc38830e29e 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) @@ -628,7 +632,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 @@ -907,6 +912,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 */ @@ -954,6 +961,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 */ @@ -1740,6 +1749,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; @@ -1767,6 +1789,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 Thu Nov 20 12:28:16 2025 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=1763436105; cv=none; d=zohomail.com; s=zohoarc; b=X551TA4n2oPZcFMvh5qMlx2PdFe5zgTDiYqa0GcNCBkGkpoLiOmm/MokF4DlnFr6xr5pMkEf2WU12JXlubd4u8BTkhza8zbhOhPna8rBSca49q9Wk99k4TY6wqmUKQFi6aCOMtOtXx3D6TddTa17wjN3RtQH8wFh/GnFtHhWYr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436105; 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=bODGXK8O2thATTqXtU0TiwJVQmxaowL3KL3gBEKhlGg=; b=Yfzt2zqFwqHs3NyqRKf+fXUDpPjx1kr51YFBi/j3x7fsaLEL+I57UymcKKf6JgZHQQVZqH9/6BTVU/xq2b5doEeduSgzcnItYeQfI+lpLGWjHvvzxv/xhrAVDr9hfEVNJ7LOzrUlT2cPcm6XsDD3lZR4VF3yGPtm3zDeXaKnm/g= 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 1763436105185100.43234878385545; Mon, 17 Nov 2025 19:21:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCHD-0001Pn-6B; Mon, 17 Nov 2025 22:21: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 1vLCHA-0001PJ-F9 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:05 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCH8-0004Cz-MO for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:04 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:02 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:20:58 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436063; x=1794972063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FtN3GnlS9XpEdZZ5ADMYto6Z66Ic1LkzQp5aPpZOx4E=; b=TmDZ2ixuM3LcZh4GxrdKY8jpFz43vZoXJj69PbA5sLDYQbwb/ht/5Pza 2DieS8i4fMfUQ3EXsr+x8jKTH3cMcoLpUyrr8AfIJUw3wga6YfYSs43Ls Ndx/xOsY2PR5cVwnRwDypQXyh9atiz2ayZmjNN4Qg2M1Feo/c5ObGqJIL oDta0gWa7DHNK7RW6QokCwucNqLkPz4nmrzTecVogH0zUd46dtAyZEG5W RRu80mP0lyTsgBfLsefiMGSHPuSChMvCdSRoBr4hWRSQPaejvojLiVCCz 7XGzlyFpSkkqqLFA6727ew82cT/Ktm6fjYDIW9b/XPgjkZi3KJwxAbFIa w==; X-CSE-ConnectionGUID: SBVBUFz6TS2RqKAcfaq4hg== X-CSE-MsgGUID: WxjvInN8SRmuWyVgqsL/JQ== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053859" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053859" X-CSE-ConnectionGUID: EsWihIMhRZG0T8NjBlfN/A== X-CSE-MsgGUID: 9jIsDCHTR1CiHx3n6juJ2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537237" 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 v4 13/23] i386/cpu: Add CET support in CR4 Date: Tue, 18 Nov 2025 11:42:21 +0800 Message-Id: <20251118034231.704240-14-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436107134158500 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 bfc38830e29e..f4cb1dc49b71 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) @@ -2951,6 +2952,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 Thu Nov 20 12:28:16 2025 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=1763436137; cv=none; d=zohomail.com; s=zohoarc; b=E9lSTAZIgvLdooRKS1eqcxHgLjrMDxXS2mBcnWvoUycsGRgWOvFf6CCW44ZHE8Utoym2UxeCjoiU79R5/m4QrrgDrhFzdUamb+zoFAoFW1IJT9dx6hdg9jdanSGsvwl+sqa7mpNZ5dU4VOHGJJIGDamGdXx0ES0ZCygbQxLgbmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436137; 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=Xsb4Ri3wPprMRd+6k0DO+yO7Gmns6Z135f1fDdpYayY=; b=nJp9AIEWpjPWBHRmacQfd6kD6wFbrug2qmqrMb+Dz23H4hFGhAw5DQldTbsrswW/X72ys/8jOyddR7XmjtOklF3JWKkl3x0xQ0iMao82u3GGq21MX9Y9gkhOIf2CZQPHqmIPpv38iR6YTvRyIVGEPsHuXWgIWYsui94+FOdox80= 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 1763436137201371.3334382779602; Mon, 17 Nov 2025 19:22:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCHp-0002BF-E4; Mon, 17 Nov 2025 22:21:46 -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 1vLCHe-00021G-Uy for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:35 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHM-0004Cz-KG for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:30 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:06 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:02 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436077; x=1794972077; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EiFQ+knKkDk9BKUUUsyAcXreteNsFUSkKVPkud90lxo=; b=UtcjFdgqkFQYTDoMlaAM+t/nUT2zUSbWs5WpkrhOKWXcRfzKNi2JLgCt KxMgN2hThcq4zmkVelCtPqFODqEZz2Ak81bip16Szq9BZpN2xCclACGV9 +YfcLNRjdP1zBMSTsLJwj2ZHalJ/Z/9nnm3cSaLhbwQmHy47JLaBanDMp PkbyHjIwTCYq61tFkaiJ4FLb3q+zCJVGXNWzd8c6G66gqhMZ3224QqljK vb3RwbhjYBSrKnRJ3wwH+1gPqabRkVjNG81cJLH/AJtHJ0ekDCoQErg7T L16zLpFkhD5iH6vWFxgdvMM6rZk+n/S0SPrzdrvUuiqRhx+45DbqtyUUU w==; X-CSE-ConnectionGUID: +LGeZI7lT8ePneWJcCXpFQ== X-CSE-MsgGUID: Nn3CKpX1SeamBX98dKo8XQ== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053871" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053871" X-CSE-ConnectionGUID: 56zVilAaRvSGRUFQ32iv+Q== X-CSE-MsgGUID: 8QnPUr7LRKGCdFHene0yNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537272" 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 v4 14/23] i386/cpu: Save/restore SSP0 MSR for FRED Date: Tue, 18 Nov 2025 11:42:22 +0800 Message-Id: <20251118034231.704240-15-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436139137158500 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 f4cb1dc49b71..0432af1769d2 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 @@ -1973,6 +1976,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 Thu Nov 20 12:28:16 2025 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=1763436115; cv=none; d=zohomail.com; s=zohoarc; b=jFJV7C4OyA+eHZ4Xey5nRA5mH0LoiFTdrIyaside3H2mZE0Wl2Hk4WICjEUmRvdYCpwwyQAG/XQWCeSEkzuayyBgky7RLYvL0X+6LkoCDcYaOY44icoNvpmyzUlsaLPwqA4MS1PFBu2GyWPfp5HJrfDGtoomVMBDxjOy0KcW3o4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436115; 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=d6zsexi6Ikz4QPnP6GLh6RCpJx7oYOjJu2zsW4l4Q2Q=; b=GWewIg3PA49ALQHudqwsLOCQaHVNeJztZ32zUMdKUncuD6V6MzzhImL9nU5fSU4nUpqMhcpyuS8ILvj54C4jYq0SzV7CZ9h0rXl/T/9MqtnbQzZYUx5y+/0SjQGmuS5TjW3L4UbipoYbOuzA013ogADd+F6dR6DGnbDuElyTi94= 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 1763436115091728.013207340134; Mon, 17 Nov 2025 19:21:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCHw-0002gX-NK; Mon, 17 Nov 2025 22:21:52 -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 1vLCHq-0002JB-D7 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:47 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHa-0004HZ-Jm for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:37 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:10 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436091; x=1794972091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OT9yXKg8cGU4vWhy5aN4ndDqiEVed8ea36SkVfyMMTw=; b=bp0Ubenk1v0XESjWV7kowGOSJzm0pQmVqyv+bo5isip+d74dgQqUl1GF TqehXT7ZWevq2Gni6YvpeeFI6kNnWYlFcp2MxVIAJhwK5GWbU/C7A/wUP k7OmUHr/GLk8m2rOU1VHbXn3EhjBD4uNXp2KvUStmMhm3+6n6jjminzDk 9uU3gm32L+sY9eWJJu46r960Vn8XyRI04179aTPQh36dpgCFs1JAiwa2F lJfqQZT6cI5Xx4tH5xNlCJFCrqN8ARiwdi7UkyowhD+qoLxZUR7krvDqk E4QvuXBrx6jc4JECd5Sedorr3VvguWVvYXD2kGH5hPWacMovMV83UbVuQ A==; X-CSE-ConnectionGUID: xrS2irVRQ6mIYTVYK+daeA== X-CSE-MsgGUID: 9+1Etd+2TSiOYBvZxaKp5w== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053886" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053886" X-CSE-ConnectionGUID: z3MWa+37RL2HVBKD4nv5tA== X-CSE-MsgGUID: cwPmblDqQneNRq0+Oxn7fQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537295" 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 v4 15/23] i386/kvm: Add save/restore support for CET MSRs Date: Tue, 18 Nov 2025 11:42:23 +0800 Message-Id: <20251118034231.704240-16-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436116156153000 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 0432af1769d2..661b798da4d0 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 @@ -1976,8 +1982,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 Thu Nov 20 12:28:16 2025 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=1763436248; cv=none; d=zohomail.com; s=zohoarc; b=gmy7/9eg4iRMAjkGGeQD01BMk8QltOu/wC5Z+vSEFb6HoLeKN6lM0Z6kMjIPkJ7ATSzJky+bTV/E63ivyMfkYNYWLoiovepNR9txaOzevZBcDnmo616FzRa/TQgL7PP5Zd6MwjE/vSdM+Np/EsKkvMGY2u2s+AwA8bm7i7lGVK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436248; 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=lklZnhl1Oeg20qazs2HlQjrEZ300GzrFMyaEF5lsNZw=; b=K49wKPShv/gidXXcmV9268hFF/5UcW0QWVHtc7HGTDdigdYH4WYlvSSgk+SJgMjW9V1g0mSN8P7yF7PILK+UeojtiIniAlSe5YEu1zxoKmOJKQjYNUy8/ohso2RBmH3mWANnqxyvOgjLzSD6gMdV/8Gzp0cHEzinHzpmZFw6a/o= 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 1763436248588149.06172587407752; Mon, 17 Nov 2025 19:24:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCHu-0002VT-TX; Mon, 17 Nov 2025 22:21: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 1vLCHg-00028H-Qm for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:38 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHa-0004Hi-8Z for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:36 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:13 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436090; x=1794972090; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Y+10AA8RxhybijSx1coYUp7NV9ph4l57Sz0FOZYoxA=; b=VRSkfmDzg43ALX/g1Mc7AcrMIn6/AsRSPAdu5K0qzSQN68uHGqCA26EZ y5vvRZM7E7Hgd8/Bq3E6VUK265A6qNCOItaYwq5oyJOeI5G1kDgATnfeZ fZFfYjLMuG1AtXX9zZep5n2DdNcXGLDcWg4gJJXniNMkefST/gv2ujqLS SZtwXmEGk3JtHItqi1AyQKPz8GkdOf8X4OFe5kghWS2u+LBwkFezioSWO ruugsjcfoVLDo0UD+/DK55DkURqbB5rEy5Wh1RLmAJ3y9/wjmqE/G86mD kjCEgNiqTf6xcVAjK/ZTS40+Ub6R0ay23UP1DjM8XBwPO1EMXz2NE2es5 w==; X-CSE-ConnectionGUID: H4VjBGFrSMywJmUse5gJdw== X-CSE-MsgGUID: dXIE0Al1QgilbWbdajXfIA== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053896" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053896" X-CSE-ConnectionGUID: 2j+ZZLwKShGHa6BNPVxORA== X-CSE-MsgGUID: qs9qdH5nQLGfGnDJ/i30Rg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537320" 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 v4 16/23] i386/kvm: Add save/restore support for KVM_REG_GUEST_SSP Date: Tue, 18 Nov 2025 11:42:24 +0800 Message-Id: <20251118034231.704240-17-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436249288158500 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 661b798da4d0..c4412012c780 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1982,7 +1982,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 */ @@ -1992,6 +1992,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 Thu Nov 20 12:28:16 2025 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=1763436175; cv=none; d=zohomail.com; s=zohoarc; b=F5GWw/OozOg1+9PBzeAWb8UZPQYQkqnnGd+MSz3TZWToGcx+K5cSRIwa5bQEFfx7hK+nO4hGM5j0h+MIes6vTwyhTofe/S2fyhu5PeX5PtOqlmaTBcluTCkfs4nBv/cnYXESJ6gYH4Ag7ueb8Amf7ZgpoEQDMGjA+19oGHg6j5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436175; 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=ahi9QdQNMkWUm9xlUOk+SNJNnOkN06AoIylYu7NQQPY=; b=VrH7L5QDyo7ZvUhBWMpGmWwq2rNfZWD92SxZem0DgE6FtNSE9fApRb1u3vmW6FKSueu6Kbp8yCxOl7VOviTKtRc/HuLh5Jbqc5aTTOGKCOASNnexzkq4qGWArHhD0dnmroY46ZPDsYNMp05O/AfsiP1e//4NnndOem9Wt/6yEK0= 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 1763436175761729.8014515116753; Mon, 17 Nov 2025 19:22:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCI3-00033B-NT; Mon, 17 Nov 2025 22:21: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 1vLCHr-0002TU-PR for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:47 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHg-0004Cz-Lw for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:38 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:17 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436097; x=1794972097; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lnoh54IK1xdUE7ReHUApDtVaHR1nAbgq/jys15IExB8=; b=cu2ivq/oCFaaMEMv0+dhcbvozQ7qwV4cK8wnfvYABuT/aU88arbDd4oV 0pn+AL8gPfjSLsOFCbhvYciraGmt73DhMd3/Fn7TunOMz0uc/he/NS0Zv 1n6LSR0ImLRF3vY+rgCOYp5DUZv2kYanbzimRFscf+K20RZ5AqCRfl2kd jrYp1rEXm3EjLtQosP7izyKuREZJIiF08tMl6YSSwwbfU6DlcFcaX+KUg ybWMpILbErTHsT4YlUtS5ZR7n8p4Ce+FuHfZzRsrsqhACFTr1K1paajZc 9gdwFUDJS2npgs/Cs4nIAEDomP7Z3MVszIh37nqhOTv7QpaUz16hfBjmp Q==; X-CSE-ConnectionGUID: NpqbyXXLTMaMkPmekE21+Q== X-CSE-MsgGUID: +EmHwkvJTr6Wxo5bCgklUg== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053905" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053905" X-CSE-ConnectionGUID: 2sxYWs5mSRKM+l9YBIWrPA== X-CSE-MsgGUID: ocOj5Iz7TNGxnJo70sxTfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537340" 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 v4 17/23] i386/cpu: Migrate MSR_IA32_PL0_SSP for FRED and CET-SHSTK Date: Tue, 18 Nov 2025 11:42:25 +0800 Message-Id: <20251118034231.704240-18-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436177222158500 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 v3: - New commit. --- target/i386/machine.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/target/i386/machine.c b/target/i386/machine.c index 45b7cea80aa7..0a756573b6cd 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1668,6 +1668,31 @@ static const VMStateDescription vmstate_triple_fault= =3D { } }; =20 +static bool pl0_ssp_needed(void *opaque) +{ + X86CPU *cpu =3D opaque; + CPUX86State *env =3D &cpu->env; + +#ifdef TARGET_X86_64 + if (env->features[FEAT_7_1_EAX] & CPUID_7_1_EAX_FRED) { + return true; + } +#endif + + return !!(env->features[FEAT_7_0_ECX] & CPUID_7_0_ECX_CET_SHSTK); +} + +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 +1842,7 @@ const VMStateDescription vmstate_x86_cpu =3D { #endif &vmstate_arch_lbr, &vmstate_triple_fault, + &vmstate_pl0_ssp, NULL } }; --=20 2.34.1 From nobody Thu Nov 20 12:28:16 2025 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=1763436260; cv=none; d=zohomail.com; s=zohoarc; b=NjGDojtGMoWZdu1NPUi/DR9VqD5pNCjyxTthnCjNAobM6TKJNB6OhliWylz6v/NEYE1LoBpiG05pIB8igRLg8ymlvMN2WiZzi5X13Rx1N5Y94VZXaRPdwPbjbBDq0s6AqUZP+H6uTk0/mtjTtSVXqkVZV4dWVjqL/0mcaGwPJvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436260; 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=9pE6X8yCo4PJ2UN563SPsdHGQXsktq9bV/O6lFXkMBc=; b=UxBZyooXFvsVoXqGr0UU090OpRo219fGZxJ+ez/lIK2zMzcnH2zYPGHk2ySQkwnkn4wbpkTqvBZKKyhsnEpNTBdchlEQutPDwpscRgxpGAopqO9iSSM6UgADeGoqTpKAFtk5sxqAmqIcvJT4TwTwW6UYeyJnOwcaL6aWmSpC2xI= 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 1763436260026845.5498454496427; Mon, 17 Nov 2025 19:24:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCI1-00030X-Lo; Mon, 17 Nov 2025 22:21:57 -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 1vLCHu-0002Z8-Kn for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:50 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHj-0004Hi-4M for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:49 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:20 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:16 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436099; x=1794972099; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jyuv1slaPKAV+w4F0aJEddngoY9lcGquMMXzXgXMpc4=; b=Z2gB9UB8gUsIKJjFVKkw2G1eCWZ+MRV5JoXYg4af6bwYppktLIzQxT8J Hsf5Yi2NovoyxO9fHYNJGtCrhLrz/aap8sz7xnHvwjtrj6GHPDB3+NfEG 7tjXFhxNeIGRKip98dA2cADoNR2wQ/myquvnlAbrNpJH9lk3siG50506p SC54D4cqTKfeLDfAVWh7V/jHdfC9WAOmueuB+yDv+pbfFrHxYhwkkpgGf 2juGOQzw/Ft5vRaBFMVH6fporSWDXlRbZOKWZ45tn3MaNzYhb+QogS238 Pp9Bdks4bbn6miHYCshvtas6yvzPnjoPmoEg2F6wwphU+3+Jfu2GihJLk A==; X-CSE-ConnectionGUID: J4DdENNSQJKueD2QpO/wnA== X-CSE-MsgGUID: 7pSl7GDESKmjd4wLkyVpEw== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053912" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053912" X-CSE-ConnectionGUID: bpQZXi/8Q6qs4/MvhT6veg== X-CSE-MsgGUID: UuyFg7lLR/GWc64cBHO2ew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537350" 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 v4 18/23] i386/machine: Add vmstate for cet-shstk and cet-ibt Date: Tue, 18 Nov 2025 11:42:26 +0800 Message-Id: <20251118034231.704240-19-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436261741153000 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 0a756573b6cd..265388f1fd36 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1693,6 +1693,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, @@ -1843,6 +1894,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 Thu Nov 20 12:28:16 2025 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=1763436219; cv=none; d=zohomail.com; s=zohoarc; b=WJ5oYL/ohjMWWrIK4+H/xvDcvEj/rPLBS/h4pJReQkwk2YSEaWpF8qQXUZuSGWseRRR0HML6dpvtXhKRy2z6Rv0ZIzoV3xRoMqxi2+g1FI8ou1uNvXIsHWYsJyln4OUmykudNerqMUw3La6kcitVDfEL3S5yYBmifYA2GcS84m4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436219; 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=lQmNCB1QpznE0oVqdltcgZQCd+e5tL9gd6bW4/nT6SBwfV+Z7v0cRtsbSZeOBpTqxe2HoIGzkBq9KHaNQoCAPlutBsfnmwB1h7CqL7JWk4vv/Cjl39iInR1xJuR8mm+EjaU5xRbb+46TCFHLrS4GIvGR/j69oHixU07TwRSl3eI= 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 1763436219648403.9543705056785; Mon, 17 Nov 2025 19:23:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCIB-0003Xc-A5; Mon, 17 Nov 2025 22:22: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 1vLCHu-0002Zs-Ma for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:50 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHr-0004HZ-Ik for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:50 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:24 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:20 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436108; x=1794972108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kMqBy7CxyEmFl74t7tv9rzwXuI+1Gc0Y9duW9Lw4FqE=; b=BQlUOqi1JZdRuog4W78vEAGO5svvQa5w6bl+jv4uAvAmyE/AgdlzGKAH HmFJ5PIhA2i10LimTzGpUQpgWjBi+ZRyCKPvuDhteAiWWoLTAvz7kkU/p 8/M2BJxpofZV9UJbSVsYZAVqZFhiSP5kjE50bHV4FSpKiyTBKD9Q1FD02 al2qesee1xJQCMoJLLIUoTiMxKFLHvDCuD58Yw2BUVE62I0Ef5YX/Di9D J6OyTiuRdLjcSJVzrE9BdEx77GBqGnKP0qBYuUkPBh6t+03jhoEN/GApr kvds6FB4guCnlpwmnATXdNPZzvsKqf8AEczXNklN1VlC7t/CV0MM+h+uC A==; X-CSE-ConnectionGUID: XStaM3ruQYmnHfFF6SnVKw== X-CSE-MsgGUID: 1lSe30PmQnmbN+peWpBhvw== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053924" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053924" X-CSE-ConnectionGUID: lvZ5Y8FHQ4O9xXAhUCWG6g== X-CSE-MsgGUID: yMxHwHelT1Wult8IrPLcng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537366" 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 v4 19/23] i386/cpu: Mark cet-u & cet-s xstates as migratable Date: Tue, 18 Nov 2025 11:42:27 +0800 Message-Id: <20251118034231.704240-20-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436221171153000 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 Thu Nov 20 12:28:16 2025 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=1763436248; cv=none; d=zohomail.com; s=zohoarc; b=FR0lydVwVxcjhs5gEUPggcsYvy0jjiyHsIx2s5rUZfzY3WIwRNb6eMeU3r9Muu5rwbfV84COITSRqV/Xrr1OdcAJNJrwsUqzK3ztz2zBWWzXoD35LyDVtFlj2Y5XcxzohA8mGdDeEdLseraFuFPzFJH3vvwImAhX7J0cHK/a+M4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436248; 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=PjPcp8gAubsZ+jRgOxH0WlCdPFTFbKfmxHk2jm94R64=; b=QMHk6fjd/BOPzrC48J2evVUrTbab6wQRCggeuGxdG5VJav6pj/O1+NcvHEevJSA9SwLYWFH/L7hB3tys8/KvM3KGcGd0/Tu6dC3oGfO98KLT/BZQo5GXwrJhYgnJ4m2/XUOG6Dc2awAyeeubc1/LQ+YWYTFvtn7ekdFY6M+V6es= 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 1763436248155177.5518176416789; Mon, 17 Nov 2025 19:24:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCIE-0003pX-9x; Mon, 17 Nov 2025 22:22:10 -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 1vLCHv-0002cm-7b for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:51 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCHs-0004Cz-5F for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:21:50 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:28 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436108; x=1794972108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4vj3rkIIm3fua4GI9Ec2JhmAZvhM0BpAu+/cVsnfP9Q=; b=QoQ8YdrlxJ0aQN3wjpjEuVGCkd5VJNWu98yFuEjaAoZOTcrTdXzjvzje NcPSskzzYUCsj5hJKP3nlpF0MYzi8nP/Npw0ARB+TObrHT8OjZbE56+MN 0P1y0a2IcwuErUb12eYP2kRXq5jeODQtzyL6STd6bVilItWKdqacwgW83 LT6LH+vqj3IuxsjVWdfS4zOOK07MlAdHZlYTezuI9Dm6uL0grxdUxmsHb hh6D9ydIfutBCXpXIIKgA8AaKuRHA3vLZ2k5zwL5LQ1X/XZZmfIo4Z1XS iTeeC4DkBMamEb2asfy39MWXeV8h9777b/f8P0d3Ex8JdPy7nYsx25/Aa Q==; X-CSE-ConnectionGUID: opVDdUQAS8WSTPO+SwirDQ== X-CSE-MsgGUID: 1GVmT9jnRY+URHr7Kk4Swg== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053931" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053931" X-CSE-ConnectionGUID: xCTmfrJJTi2+2N0h9sQ0dg== X-CSE-MsgGUID: 3QO/yUuuQHKPVb9FKysCmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537395" 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 v4 20/23] i386/cpu: Advertise CET related flags in feature words Date: Tue, 18 Nov 2025 11:42:28 +0800 Message-Id: <20251118034231.704240-21-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436249586153000 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 c4412012c780..d8bdf342f98d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1373,6 +1373,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 @@ -1386,6 +1387,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 Thu Nov 20 12:28:16 2025 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=1763436238; cv=none; d=zohomail.com; s=zohoarc; b=UtwcgxIFohoyGH5iJHtKwnP6j9zUCZD5P0lZDv875kt87HGRpDOhtS/N6sQX1dsouS/hfl8fxrJ6R+T0rLfk0LI1cZOLkcMmxShkUCVKc7Xd/J8UIdMsI1Be54apsmM37/otG3745FBjg3MtRF6HgM8hQoDB3CVWIbWWF96/dfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436238; 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=K7ZMtBiio1fs9dyAn+ieDVLT05BJCqrlt/8jHOSxnRuVcS/a8dKKTYE32c+oaUKXEq5mvnRZpQw3xykz7FBqQaiXi0jAzGPx2apLWYeDE56Ue+wlt/AOrLhB9jta+JMZj8TnAlOcXPyycEPXni55zqNEqFCaUhhl2CNG3tSDPo4= 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 1763436238121977.89763214339; Mon, 17 Nov 2025 19:23:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCIH-00048I-NU; Mon, 17 Nov 2025 22:22: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 1vLCI6-0003Lx-WD for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:03 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCI5-0004Hi-40 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:02 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:31 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436121; x=1794972121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3n7M74aqCkbEbKfoKd8BocgrGmHYDsrLyL1GwMNnx9I=; b=lJ7C0Kg+fohBxbZgY1+OAXTMcPpBm/SS6ScRH4KZMSStMcffDo/YYKTi omHZ1yp5Uf2u4GeLm36KuIEs+i/ofPQW1qs7I4kCNa2nWUQ/7o1PhbZ4S vUaiN+K/yGEnJGyM+kqvEhYSLa7jb/dKzh4tQ/DnvhyN8gNpeZYpQ6MaK X6cUW3bOiv8wZEJqqsJw/68g0Y5DynFW4G/TCP7Rl2pVD/9nUbp7LAdLP Wpi9ZOldIZ9UsDknN24Qpzb9BGsdVhzazy9127ip+Plk8/lGn6xg2ZiJc QhpWLvCMe0GaBTQECyRMg3SQDQg8qU9Ikx6YrxTCCaD6QBWzlYCLg2gGD w==; X-CSE-ConnectionGUID: KyUPKYTQQhqBhTMGD31jNA== X-CSE-MsgGUID: J87WIvKJQjORo26u3JkzmQ== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053938" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053938" X-CSE-ConnectionGUID: dWUJl04IQ1Wf6hyxk9tglg== X-CSE-MsgGUID: dCgs5ufoR1mpahbrR5ykWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537425" 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 v4 21/23] i386/cpu: Enable cet-ss & cet-ibt for supported CPU models Date: Tue, 18 Nov 2025 11:42:29 +0800 Message-Id: <20251118034231.704240-22-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436239414153000 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 Thu Nov 20 12:28:16 2025 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=1763436175; cv=none; d=zohomail.com; s=zohoarc; b=XU+p1ZSMxmnHJkfd5OVB4+OvggoAXySaFOwbdz08gdIBB/rxtziFJ9/n7hoGUhKZp/HizG/xAiUlr73Mlhbfd9RToy6f4LGmU9wAxJVz0mmSNGY01x3ZVT8S7yJzkl/ZufkO016TxZPUHa00lfR6wcNtIXLHewsZZ5obVtMCv14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436175; 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=gCsD+oqTthqOW6yPOuwSnswfMFuC91Z4vE4gRNr0044xd3ChIXXkumq1V+dITDGvd2hjV7qfJthOrJYxHu81be9e7bnc2JYuYE2mCnhfsavfrGAj1JSyyKW5zZ1/tpQErEfC4ZG/CNPE1ckKtQRcHjaVczlJ5irY9IpnkaOau1M= 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 17634361757321019.6256537991339; Mon, 17 Nov 2025 19:22:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCIB-0003an-E7; Mon, 17 Nov 2025 22:22: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 1vLCI7-0003MN-E3 for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:03 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCI5-0004HZ-8a for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:03 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:34 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436121; x=1794972121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=66V7PYFxiVOdYw2D3BJVJJrWu9A0DxDp2SevYe43bMs=; b=OgpYHDKGD/7en5LhjvXIPBtK3Tk6V/isnwNSXa+mfgEic1ZsXVCvTqnV EIShg1HcU+yeNa4EfuvTanVWBXuf/yUxmRDfHqBFRvDxD5WQaImgqBOLm 7z18Z4BH02t+lxH1WxGq3D0PAHHvzAknM2ngKlVyfbbmpfYMpjiaV6L2a 7fK82FzihYZtTGqB3KWBY7kGIApzRiLDwQ3Xll9r/RIzxycPGoHKrngEY NIbxmafVwpBiywNQTSj6FsxGn+s4PnXBCbxm4VhgfIu6n3YyrBLsO2KdC 1k6CtKtIOocwOOEUz6/lm0jH3V99SqoOtRB/hHvT6Qc0XTh2AEz4LGKHg A==; X-CSE-ConnectionGUID: l78VG6O/SRenW8V6v9oorg== X-CSE-MsgGUID: yr7vWyUnTka2hjnDdHFbZQ== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053948" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053948" X-CSE-ConnectionGUID: pYx4leSJShWS0hVvZmi9HA== X-CSE-MsgGUID: F5fPrCt3Q4mRi0lGD39H3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537452" 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 v4 22/23] i386/tdx: Fix missing spaces in tdx_xfam_deps[] Date: Tue, 18 Nov 2025 11:42:30 +0800 Message-Id: <20251118034231.704240-23-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436177196158500 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 Thu Nov 20 12:28:16 2025 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=1763436236; cv=none; d=zohomail.com; s=zohoarc; b=ABZm4IJr8AWgg1pQSrps+tbFDXz7qQ4s4iwKyUmoqaQMVUcz+v+Gm4URFvb7dYRRmtJAs58BesxUnZiO75HLKzfxlMx38RAtvbGPMR+QqWsPUQgcedUMKbiCv375i8xWMyu77zlxPwzesjkhSTVlk/k7K+LuJ3MeZmJe5YpGTaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763436236; 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=nlsm/MUbGc1tC+4tv1fGI5Ol/GrGdArsz63egO7nMRYWcxHoeZHioMATnJs8uXqN0TpYjuB9gRzZcBJxz27E6246y28SRd04vkH0nMjAEov98y3GmQeHm+WJ45fkhPirO5tagG9rMslonuonRs0zXeLzxY0ofPz/XpOGRdtkB8I= 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 1763436236410956.789667169454; Mon, 17 Nov 2025 19:23:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vLCIJ-0004Kp-FC; Mon, 17 Nov 2025 22:22:15 -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 1vLCI7-0003MO-GO for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:03 -0500 Received: from mgamail.intel.com ([192.198.163.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vLCI5-0004Cz-IH for qemu-devel@nongnu.org; Mon, 17 Nov 2025 22:22:03 -0500 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2025 19:21:38 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by fmviesa001.fm.intel.com with ESMTP; 17 Nov 2025 19:21:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763436122; x=1794972122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0uF8jj575zYxVcWmkztmsgjmlH5SFSks+bBKxFEAv3A=; b=SXnw1JtrEcGiLRdoMWu2BvGRpA4jIpY31CecQSdToh5VmEG/o3P4pUOn iFGO4Hxs71FF0EnKWxBltgMexaM8xet/+HzDuhfcJJnRTtt8sOpewJSPj CpFF2a/vI3OJYlKl9P4U3weElci8CnJCO1Ds3zYRlw81QqQcWBFqTx4mk U7PD7cKBxODCt7tRFdQ+hodZw24jgB+1viDOJpUIgNMihrS34RY8w1I0U BhdDSKQ1xxN8gWV+lIf0gihbXOChTTJAuGS4AhIhxP0d/czzQHuS5UwPG 5Y1yMctBneAyfbPx2j34CDW3CUH5pe8ppkxxZ69tBah7GYDDmG1O8z7FH w==; X-CSE-ConnectionGUID: 1SjSTyZBTG6kD8RhhaZtHQ== X-CSE-MsgGUID: 6GNDG37XSZi9TeGDOe2qHw== X-IronPort-AV: E=McAfee;i="6800,10657,11616"; a="68053959" X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="68053959" X-CSE-ConnectionGUID: yAf05xPZRri5ON25CMKy6A== X-CSE-MsgGUID: YjWtQHYSQQGvzBGxuphx5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,313,1754982000"; d="scan'208";a="221537478" 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 v4 23/23] i386/tdx: Add CET SHSTK/IBT into the supported CPUID by XFAM Date: Tue, 18 Nov 2025 11:42:31 +0800 Message-Id: <20251118034231.704240-24-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251118034231.704240-1-zhao1.liu@intel.com> References: <20251118034231.704240-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.13; 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: 1763436237295158500 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