From nobody Sat Feb 7 07:31:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1619102789; cv=none; d=zohomail.com; s=zohoarc; b=dACp24+og7UW48BSyfuRIe5NhRnUg6jrKtJzJ29WfwKoIBaDaEuNSFYXLtwNe4Ln794siUZaT5yO0aATsVOP3cifVE7pjpStujHpazGi09LBwB2Tlp7cjL+9fQo7X1PhIlmtm47gBrEi0l8g4yBaWHFs+Al/mutt0Yjc+FGnVZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619102789; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=An8uS4tiRtP4/sbgEQt0pyfRbcGoO31aNLmWWP5xbQA=; b=DR2UDV/GAOmF1WrFMHmCD4q4Drpf22OiIU9eErrcBoieM449G+aZhlRL7vMIePBRYmTqwniJnkPiG4oC2i640re5T5dxBQP7XAZEur4dJJfxkHZKmW+fg0j0cO7XNtEp4EM25+CvZJ6aP40w6L9pNXRHidtfWi0m/GLqkBIJJLg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1619102789849179.81832634695422; Thu, 22 Apr 2021 07:46:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.115477.220332 (Exim 4.92) (envelope-from ) id 1lZaan-0003cF-0Q; Thu, 22 Apr 2021 14:46:09 +0000 Received: by outflank-mailman (output) from mailman id 115477.220332; Thu, 22 Apr 2021 14:46:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZaam-0003c7-T9; Thu, 22 Apr 2021 14:46:08 +0000 Received: by outflank-mailman (input) for mailman id 115477; Thu, 22 Apr 2021 14:46:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZaal-0003by-Dq for xen-devel@lists.xenproject.org; Thu, 22 Apr 2021 14:46:07 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7510d6b9-c9d6-452b-8276-fd93c860d96b; Thu, 22 Apr 2021 14:46:06 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C29FFB17E; Thu, 22 Apr 2021 14:46:04 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7510d6b9-c9d6-452b-8276-fd93c860d96b X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619102765; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=An8uS4tiRtP4/sbgEQt0pyfRbcGoO31aNLmWWP5xbQA=; b=RHpqN6AfeNvotXMtggLmtrwRJFzTm9kPYOHay69KJMOu7snitOqnhn3sDLMno1eEAcV2q2 /3d4bT4qMFzioUQyGUN1CqMPEPgYf4jhHymhMeqlQxwNj6TXfQf51I+ZPCTxg8oodVJNOP /AavWkJfhkERLV2Laihp0RZq0UV/4rQ= Subject: [PATCH v3 05/22] x86/xstate: drop xstate_offsets[] and xstate_sizes[] From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <322de6db-e01f-0b57-5777-5d94a13c441a@suse.com> Message-ID: <434705ef-1c34-581d-b956-2322b4413232@suse.com> Date: Thu, 22 Apr 2021 16:45:58 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <322de6db-e01f-0b57-5777-5d94a13c441a@suse.com> Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" They're redundant with respective fields from the raw CPUID policy; no need to keep two copies of the same data. This also breaks recalculate_xstate()'s dependency on xstate_init(), allowing host CPUID policy calculation to be moved together with that of the raw one (which a subsequent change will require anyway). Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -498,6 +498,8 @@ void identify_cpu(struct cpuinfo_x86 *c) } =20 /* Now the feature flags better reflect actual CPU features! */ + if (c =3D=3D &boot_cpu_data) + init_host_cpuid(); =20 xstate_init(c); =20 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -170,32 +170,32 @@ static void recalculate_xstate(struct cp { xstates |=3D X86_XCR0_YMM; xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_YMM_POS] + - xstate_sizes[X86_XCR0_YMM_POS]); + xstate_offset(X86_XCR0_YMM_POS) + + xstate_size(X86_XCR0_YMM_POS)); } =20 if ( p->feat.mpx ) { xstates |=3D X86_XCR0_BNDREGS | X86_XCR0_BNDCSR; xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_BNDCSR_POS] + - xstate_sizes[X86_XCR0_BNDCSR_POS]); + xstate_offset(X86_XCR0_BNDCSR_POS) + + xstate_size(X86_XCR0_BNDCSR_POS)); } =20 if ( p->feat.avx512f ) { xstates |=3D X86_XCR0_OPMASK | X86_XCR0_ZMM | X86_XCR0_HI_ZMM; xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_HI_ZMM_POS] + - xstate_sizes[X86_XCR0_HI_ZMM_POS]); + xstate_offset(X86_XCR0_HI_ZMM_POS) + + xstate_size(X86_XCR0_HI_ZMM_POS)); } =20 if ( p->feat.pku ) { xstates |=3D X86_XCR0_PKRU; xstate_size =3D max(xstate_size, - xstate_offsets[X86_XCR0_PKRU_POS] + - xstate_sizes[X86_XCR0_PKRU_POS]); + xstate_offset(X86_XCR0_PKRU_POS) + + xstate_size(X86_XCR0_PKRU_POS)); } =20 p->xstate.max_size =3D xstate_size; @@ -218,8 +218,8 @@ static void recalculate_xstate(struct cp if ( !(xstates & curr_xstate) ) continue; =20 - p->xstate.comp[i].size =3D xstate_sizes[i]; - p->xstate.comp[i].offset =3D xstate_offsets[i]; + p->xstate.comp[i].size =3D xstate_size(i); + p->xstate.comp[i].offset =3D xstate_offset(i); p->xstate.comp[i].xss =3D curr_xstate & XSTATE_XSAVES_ONLY; p->xstate.comp[i].align =3D curr_xstate & xstate_align; } @@ -531,10 +531,16 @@ static void __init calculate_hvm_def_pol x86_cpuid_policy_shrink_max_leaves(p); } =20 -void __init init_guest_cpuid(void) +void __init init_host_cpuid(void) { calculate_raw_policy(); calculate_host_policy(); +} + +void __init init_guest_cpuid(void) +{ + /* Do this a 2nd time to account for setup_{clear,force}_cpu_cap() use= s. */ + calculate_host_policy(); =20 if ( IS_ENABLED(CONFIG_PV) ) { --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -26,8 +27,6 @@ static u32 __read_mostly xsave_cntxt_siz /* A 64-bit bitmask of the XSAVE/XRSTOR features supported by processor. */ u64 __read_mostly xfeature_mask; =20 -unsigned int *__read_mostly xstate_offsets; -unsigned int *__read_mostly xstate_sizes; u64 __read_mostly xstate_align; static unsigned int __read_mostly xstate_features; =20 @@ -93,34 +92,19 @@ static int setup_xstate_features(bool bs unsigned int leaf, eax, ebx, ecx, edx; =20 if ( bsp ) - { xstate_features =3D flsl(xfeature_mask); - xstate_offsets =3D xzalloc_array(unsigned int, xstate_features); - if ( !xstate_offsets ) - return -ENOMEM; - - xstate_sizes =3D xzalloc_array(unsigned int, xstate_features); - if ( !xstate_sizes ) - return -ENOMEM; - } =20 for ( leaf =3D 2; leaf < xstate_features; leaf++ ) { - if ( bsp ) - { - cpuid_count(XSTATE_CPUID, leaf, &xstate_sizes[leaf], - &xstate_offsets[leaf], &ecx, &edx); - if ( ecx & XSTATE_ALIGN64 ) - __set_bit(leaf, &xstate_align); - } + cpuid_count(XSTATE_CPUID, leaf, &eax, + &ebx, &ecx, &edx); + BUG_ON(eax !=3D xstate_size(leaf)); + BUG_ON(ebx !=3D xstate_offset(leaf)); + + if ( bsp && (ecx & XSTATE_ALIGN64) ) + __set_bit(leaf, &xstate_align); else - { - cpuid_count(XSTATE_CPUID, leaf, &eax, - &ebx, &ecx, &edx); - BUG_ON(eax !=3D xstate_sizes[leaf]); - BUG_ON(ebx !=3D xstate_offsets[leaf]); BUG_ON(!(ecx & XSTATE_ALIGN64) !=3D !test_bit(leaf, &xstate_al= ign)); - } } =20 return 0; @@ -150,7 +134,7 @@ static void setup_xstate_comp(uint16_t * if ( test_bit(i, &xstate_align) ) offset =3D ROUNDUP(offset, 64); comp_offsets[i] =3D offset; - offset +=3D xstate_sizes[i]; + offset +=3D xstate_size(i); } } ASSERT(offset <=3D xsave_cntxt_size); @@ -213,10 +197,10 @@ void expand_xsave_states(struct vcpu *v, * comp_offsets[] information, something is very broken. */ BUG_ON(!comp_offsets[index]); - BUG_ON((xstate_offsets[index] + xstate_sizes[index]) > size); + BUG_ON((xstate_offset(index) + xstate_size(index)) > size); =20 - memcpy(dest + xstate_offsets[index], src + comp_offsets[index], - xstate_sizes[index]); + memcpy(dest + xstate_offset(index), src + comp_offsets[index], + xstate_size(index)); =20 valid &=3D ~feature; } @@ -279,10 +263,10 @@ void compress_xsave_states(struct vcpu * * comp_offset[] information, something is very broken. */ BUG_ON(!comp_offsets[index]); - BUG_ON((xstate_offsets[index] + xstate_sizes[index]) > size); + BUG_ON((xstate_offset(index) + xstate_size(index)) > size); =20 - memcpy(dest + comp_offsets[index], src + xstate_offsets[index], - xstate_sizes[index]); + memcpy(dest + comp_offsets[index], src + xstate_offset(index), + xstate_size(index)); =20 valid &=3D ~feature; } @@ -516,8 +500,8 @@ int xstate_alloc_save_area(struct vcpu * unsigned int i; =20 for ( size =3D 0, i =3D 2; i < xstate_features; ++i ) - if ( size < xstate_sizes[i] ) - size =3D xstate_sizes[i]; + if ( size < xstate_size(i) ) + size =3D xstate_size(i); size +=3D XSTATE_AREA_MIN_SIZE; } =20 @@ -559,9 +543,9 @@ int xstate_update_save_area(struct vcpu for ( size =3D old =3D XSTATE_AREA_MIN_SIZE, i =3D 2; i < xstate_featu= res; ++i ) { if ( xcr0_max & (1ul << i) ) - size =3D max(size, xstate_offsets[i] + xstate_sizes[i]); + size =3D max(size, xstate_offset(i) + xstate_size(i)); if ( v->arch.xcr0_accum & (1ul << i) ) - old =3D max(old, xstate_offsets[i] + xstate_sizes[i]); + old =3D max(old, xstate_offset(i) + xstate_size(i)); } =20 save_area =3D _xvrealloc(v->arch.xsave_area, size, __alignof(*save_are= a)); @@ -819,7 +803,7 @@ uint64_t read_bndcfgu(void) : "=3Dm" (*xstate) : "a" (X86_XCR0_BNDCSR), "d" (0), "D" (xstate) ); =20 - bndcsr =3D (void *)xstate + xstate_offsets[X86_XCR0_BNDCSR_POS]; + bndcsr =3D (void *)xstate + xstate_offset(X86_XCR0_BNDCSR_POS); } =20 if ( cr0 & X86_CR0_TS ) --- a/xen/include/asm-x86/cpuid.h +++ b/xen/include/asm-x86/cpuid.h @@ -16,6 +16,7 @@ extern const uint32_t known_features[FSCAPINTS]; extern const uint32_t special_features[FSCAPINTS]; =20 +void init_host_cpuid(void); void init_guest_cpuid(void); =20 /* --- a/xen/include/asm-x86/xstate.h +++ b/xen/include/asm-x86/xstate.h @@ -44,8 +44,9 @@ extern uint32_t mxcsr_mask; =20 extern u64 xfeature_mask; extern u64 xstate_align; -extern unsigned int *xstate_offsets; -extern unsigned int *xstate_sizes; + +#define xstate_offset(n) (raw_cpuid_policy.xstate.comp[n].offset) +#define xstate_size(n) (raw_cpuid_policy.xstate.comp[n].size) =20 /* extended state save area */ struct __attribute__((aligned (64))) xsave_struct