From nobody Mon Feb 9 05:32:17 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=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