On 02.01.2025 09:45, Tu Dinh wrote: > --- a/xen/arch/x86/cpu-policy.c > +++ b/xen/arch/x86/cpu-policy.c > @@ -190,6 +190,16 @@ static void sanitise_featureset(uint32_t *fs) > } > } > > +static void recalculate_arch_lbr(struct cpu_policy *p) > +{ > + if ( p->basic.max_leaf < 0x1c || > + !(cpu_policy_xstates(&host_cpu_policy) & X86_XSS_LBR) ||
A reference to the host policy looks questionable here. If you ... > + p->basic.lbr_1Ca.supported_depths == 0) > + p->feat.arch_lbr = 0; > + if ( !p->feat.arch_lbr ) > + p->basic.raw[0x1c] = EMPTY_LEAF; > +} > + > static void recalculate_xstate(struct cpu_policy *p) > { > uint64_t xstates = XSTATE_FP_SSE; > @@ -219,6 +229,9 @@ static void recalculate_xstate(struct cpu_policy *p) > if ( p->feat.amx_tile ) > xstates |= X86_XCR0_TILE_CFG | X86_XCR0_TILE_DATA; > > + if ( p->feat.arch_lbr ) > + xstates |= X86_XSS_LBR; > + > /* Subleaf 0 */ > p->xstate.max_size = > xstate_uncompressed_size(xstates & ~XSTATE_XSAVES_ONLY); > @@ -271,6 +284,8 @@ static void recalculate_misc(struct cpu_policy *p) > > p->basic.raw[0xc] = EMPTY_LEAF; > > + zero_leaves(p->basic.raw, 0xe, 0x1b); > + > p->extd.e1d &= ~CPUID_COMMON_1D_FEATURES; > > /* Most of Power/RAS hidden from guests. */ > @@ -630,6 +645,7 @@ static void __init calculate_pv_max_policy(void) > > sanitise_featureset(fs); > x86_cpu_featureset_to_policy(fs, p); > + recalculate_arch_lbr(p); > recalculate_xstate(p); ... flipped the order of these calls, couldn't you use the respective bit from the correct policy? Then again you need p->feat.arch_lbr to actually set X86_XSS_LBR. Still the aspect in recalculate_arch_lbr() wants sorting somehow. Jan