x86/vmx: Don't crash guests when there is no model-specific LBRs available
cover x86/vmx: Don't crash guests when there is no model-specific LBRs available
This is the minimum bodge required to stop guests crashing on Sapphire Rapids hardware.
Note that both Arch LBR and safely (in terms of migration) enumerating PDCM/MSR_PERF_CAPS depend on improved MSR levelling support which is still not yet complete.
i.e. We cannot do the second half (enumerating LBR_FORMAT=0x3f) yet because we'll make it more likely for VMs to crash in migrate.
Andrew Cooper (2):
x86/vmx: Calculate model-specific LBRs once at start of day x86/vmx: Support for CPUs without model-specific LBR
xen/arch/x86/hvm/vmx/vmx.c | 307 +++++++++++++++++++++++---------------------- 1 file changed, 155 insertions(+), 152 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 x86/vmx: Calculate model-specific LBRs once at start of day
There is no point repeating this calculation at runtime, especially as it is in the fallback path of the WRSMR/RDMSR handlers.
Move the infrastructure higher in vmx.c to avoid forward declarations, renaming last_branch_msr_get() to get_model_specific_lbr() to highlight that these are model-specific only.
No practical change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 276 +++++++++++++++++++++++---------------------- 1 file changed, 139 insertions(+), 137 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +139 -137
@@ -396,6 +396,142 @@ void vmx_pi_hooks_deassign(struct domain *d)domain_unpause (d); } +static const struct lbr_info { +u32 base, count; +} p4_lbr[] = { + {MSR_P4_LER_FROM_LIP ,1 }, + {MSR_P4_LER_TO_LIP ,1 }, + {MSR_P4_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, c2_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, nh_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sk_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_SKL_LASTBRANCH_0_FROM_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_TO_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_INFO ,NUM_MSR_SKL_LASTBRANCH }, + {0 ,0 } +}, at_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_SM_LBR_SELECT ,1 }, + {MSR_SM_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, gm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_SM_LBR_SELECT ,1 }, + {MSR_SM_LASTBRANCH_TOS ,1 }, + {MSR_GM_LASTBRANCH_0_FROM_IP ,NUM_MSR_GM_LASTBRANCH_FROM_TO }, + {MSR_GM_LASTBRANCH_0_TO_IP ,NUM_MSR_GM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}; +static const struct lbr_info *__ro_after_init model_specific_lbr; + +static const struct __init lbr_info *get_model_specific_lbr (void ) +{ +switch ( boot_cpu_data.x86 ) + { +case 6 : +switch ( boot_cpu_data.x86_model ) + { +/* Core2 Duo */ +case 0x0f : +/* Enhanced Core */ +case 0x17 : +/* Xeon 7400 */ +case 0x1d : +return c2_lbr; +/* Nehalem */ +case 0x1a :case 0x1e :case 0x1f :case 0x2e : +/* Westmere */ +case 0x25 :case 0x2c :case 0x2f : +/* Sandy Bridge */ +case 0x2a :case 0x2d : +/* Ivy Bridge */ +case 0x3a :case 0x3e : +/* Haswell */ +case 0x3c :case 0x3f :case 0x45 :case 0x46 : +/* Broadwell */ +case 0x3d :case 0x47 :case 0x4f :case 0x56 : +return nh_lbr; +/* Skylake */ +case 0x4e :case 0x5e : +/* Xeon Scalable */ +case 0x55 : +/* Cannon Lake */ +case 0x66 : +/* Goldmont Plus */ +case 0x7a : +/* Ice Lake */ +case 0x6a :case 0x6c :case 0x7d :case 0x7e : +/* Tiger Lake */ +case 0x8c :case 0x8d : +/* Tremont */ +case 0x86 : +/* Kaby Lake */ +case 0x8e :case 0x9e : +/* Comet Lake */ +case 0xa5 :case 0xa6 : +return sk_lbr; +/* Atom */ +case 0x1c :case 0x26 :case 0x27 :case 0x35 :case 0x36 : +return at_lbr; +/* Silvermont */ +case 0x37 :case 0x4a :case 0x4d :case 0x5a :case 0x5d : +/* Xeon Phi Knights Landing */ +case 0x57 : +/* Xeon Phi Knights Mill */ +case 0x85 : +/* Airmont */ +case 0x4c : +return sm_lbr; +/* Goldmont */ +case 0x5c :case 0x5f : +return gm_lbr; + } +break ; + +case 15 : +switch ( boot_cpu_data.x86_model ) + { +/* Pentium4/Xeon with em64t */ +case 3 :case 4 :case 6 : +return p4_lbr; + } +break ; + } + +return NULL ; +} + static int cf_check vmx_domain_initialise(struct domain *d) {static const struct arch_csw csw = {
@@ -2846,6 +2982,7 @@ const struct hvm_function_table * __init start_vmx(void) vmx_function_table.tsc_scaling.setup = vmx_setup_tsc_scaling; } + model_specific_lbr =get_model_specific_lbr ();lbr_tsx_fixup_check ();ler_to_fixup_check ();
@@ -2992,141 +3129,6 @@ static int vmx_cr_access(cr_access_qual_t qual)return X86EMUL_OKAY ; } -static const struct lbr_info { -u32 base, count; -} p4_lbr[] = { - {MSR_P4_LER_FROM_LIP ,1 }, - {MSR_P4_LER_TO_LIP ,1 }, - {MSR_P4_LASTBRANCH_TOS ,1 }, - {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, - {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, - {0 ,0 } -}, c2_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_C2_LASTBRANCH_TOS ,1 }, - {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, - {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, - {0 ,0 } -}, nh_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_NHL_LBR_SELECT ,1 }, - {MSR_NHL_LASTBRANCH_TOS ,1 }, - {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, - {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, - {0 ,0 } -}, sk_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_NHL_LBR_SELECT ,1 }, - {MSR_NHL_LASTBRANCH_TOS ,1 }, - {MSR_SKL_LASTBRANCH_0_FROM_IP ,NUM_MSR_SKL_LASTBRANCH }, - {MSR_SKL_LASTBRANCH_0_TO_IP ,NUM_MSR_SKL_LASTBRANCH }, - {MSR_SKL_LASTBRANCH_0_INFO ,NUM_MSR_SKL_LASTBRANCH }, - {0 ,0 } -}, at_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_C2_LASTBRANCH_TOS ,1 }, - {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, - {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, - {0 ,0 } -}, sm_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_SM_LBR_SELECT ,1 }, - {MSR_SM_LASTBRANCH_TOS ,1 }, - {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, - {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, - {0 ,0 } -}, gm_lbr[] = { - {MSR_IA32_LASTINTFROMIP ,1 }, - {MSR_IA32_LASTINTTOIP ,1 }, - {MSR_SM_LBR_SELECT ,1 }, - {MSR_SM_LASTBRANCH_TOS ,1 }, - {MSR_GM_LASTBRANCH_0_FROM_IP ,NUM_MSR_GM_LASTBRANCH_FROM_TO }, - {MSR_GM_LASTBRANCH_0_TO_IP ,NUM_MSR_GM_LASTBRANCH_FROM_TO }, - {0 ,0 } -}; - -static const struct lbr_info *last_branch_msr_get (void ) -{ -switch ( boot_cpu_data.x86 ) - { -case 6 : -switch ( boot_cpu_data.x86_model ) - { -/* Core2 Duo */ -case 0x0f : -/* Enhanced Core */ -case 0x17 : -/* Xeon 7400 */ -case 0x1d : -return c2_lbr; -/* Nehalem */ -case 0x1a :case 0x1e :case 0x1f :case 0x2e : -/* Westmere */ -case 0x25 :case 0x2c :case 0x2f : -/* Sandy Bridge */ -case 0x2a :case 0x2d : -/* Ivy Bridge */ -case 0x3a :case 0x3e : -/* Haswell */ -case 0x3c :case 0x3f :case 0x45 :case 0x46 : -/* Broadwell */ -case 0x3d :case 0x47 :case 0x4f :case 0x56 : -return nh_lbr; -/* Skylake */ -case 0x4e :case 0x5e : -/* Xeon Scalable */ -case 0x55 : -/* Cannon Lake */ -case 0x66 : -/* Goldmont Plus */ -case 0x7a : -/* Ice Lake */ -case 0x6a :case 0x6c :case 0x7d :case 0x7e : -/* Tiger Lake */ -case 0x8c :case 0x8d : -/* Tremont */ -case 0x86 : -/* Kaby Lake */ -case 0x8e :case 0x9e : -/* Comet Lake */ -case 0xa5 :case 0xa6 : -return sk_lbr; -/* Atom */ -case 0x1c :case 0x26 :case 0x27 :case 0x35 :case 0x36 : -return at_lbr; -/* Silvermont */ -case 0x37 :case 0x4a :case 0x4d :case 0x5a :case 0x5d : -/* Xeon Phi Knights Landing */ -case 0x57 : -/* Xeon Phi Knights Mill */ -case 0x85 : -/* Airmont */ -case 0x4c : -return sm_lbr; -/* Goldmont */ -case 0x5c :case 0x5f : -return gm_lbr; - } -break ; - -case 15 : -switch ( boot_cpu_data.x86_model ) - { -/* Pentium4/Xeon with em64t */ -case 3 :case 4 :case 6 : -return p4_lbr; - } -break ; - } - -return NULL ; -} -enum {LBR_FORMAT_32 =0x0 ,/* 32-bit record format */
@@ -3233,7 +3235,7 @@ static void __init ler_to_fixup_check(void)static int is_last_branch_msr (u32 ecx) { -const struct lbr_info *lbr =last_branch_msr_get (); +const struct lbr_info *lbr = model_specific_lbr;if ( lbr ==NULL )return 0 ;
@@ -3572,7 +3574,7 @@ static int cf_check vmx_msr_write_intercept(if ( !(v->arch.hvm.vmx.lbr_flags &LBR_MSRS_INSERTED ) && (msr_content &IA32_DEBUGCTLMSR_LBR ) ) { -const struct lbr_info *lbr =last_branch_msr_get (); +const struct lbr_info *lbr = model_specific_lbr;if (unlikely (!lbr) ) {
Signature · 1 line
2.11.0
Re: [PATCH 1/2] x86/vmx: Calculate model-specific LBRs once at start of day
Quoted 10 lines · Andrew Cooper
There is no point repeating this calculation at runtime, especially as it is in the fallback path of the WRSMR/RDMSR handlers.
Move the infrastructure higher in
vmx.cto avoid forward declarations, renaminglast_branch_msr_get()toget_model_specific_lbr()to highlight that these are model-specific only.No practical change.
Signed-off-by Andrew Cooper <[email protected]>
with one nit:
Quoted 56 lines
xen/arch/x86/hvm/vmx/vmx.c +50
-0@@ -396,6 +396,142 @@ void vmx_pi_hooks_deassign(struct domain *d)domain_unpause (d); } +static const struct lbr_info { +u32 base, count; +} p4_lbr[] = { + {MSR_P4_LER_FROM_LIP ,1 }, + {MSR_P4_LER_TO_LIP ,1 }, + {MSR_P4_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, c2_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, nh_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sk_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_SKL_LASTBRANCH_0_FROM_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_TO_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_INFO ,NUM_MSR_SKL_LASTBRANCH }, + {0 ,0 } +}, at_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_SM_LBR_SELECT ,1 }, + {MSR_SM_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, gm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 },
xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 458
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +10
-0+ { MSR_IA32_LASTINTTOIP, 1 }, + { MSR_SM_LBR_SELECT, 1 }, + { MSR_SM_LASTBRANCH_TOS, 1 }, + { MSR_GM_LASTBRANCH_0_FROM_IP, NUM_MSR_GM_LASTBRANCH_FROM_TO }, + { MSR_GM_LASTBRANCH_0_TO_IP, NUM_MSR_GM_LASTBRANCH_FROM_TO }, + { 0, 0 } +}; +static const struct lbr_info *__ro_after_init model_specific_lbr; + +static const struct __init lbr_info *get_model_specific_lbr (void )
Please move __init:
static const struct lbr_info *__init get_model_specific_lbr(void)
Jan
Re: [PATCH 1/2] x86/vmx: Calculate model-specific LBRs once at start of day
Quoted 82 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
There is no point repeating this calculation at runtime, especially as it is in the fallback path of the WRSMR/RDMSR handlers.
Move the infrastructure higher in
vmx.cto avoid forward declarations, renaminglast_branch_msr_get()toget_model_specific_lbr()to highlight that these are model-specific only.No practical change.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>with one nit:
Quoted 56 lines
xen/arch/x86/hvm/vmx/vmx.c +50
-0@@ -396,6 +396,142 @@ void vmx_pi_hooks_deassign(struct domain *d)domain_unpause (d); } +static const struct lbr_info { +u32 base, count; +} p4_lbr[] = { + {MSR_P4_LER_FROM_LIP ,1 }, + {MSR_P4_LER_TO_LIP ,1 }, + {MSR_P4_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, c2_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_C2_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, nh_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_P4_LASTBRANCH_0_FROM_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {MSR_P4_LASTBRANCH_0_TO_LIP ,NUM_MSR_P4_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sk_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_NHL_LBR_SELECT ,1 }, + {MSR_NHL_LASTBRANCH_TOS ,1 }, + {MSR_SKL_LASTBRANCH_0_FROM_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_TO_IP ,NUM_MSR_SKL_LASTBRANCH }, + {MSR_SKL_LASTBRANCH_0_INFO ,NUM_MSR_SKL_LASTBRANCH }, + {0 ,0 } +}, at_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_C2_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, sm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 }, + {MSR_IA32_LASTINTTOIP ,1 }, + {MSR_SM_LBR_SELECT ,1 }, + {MSR_SM_LASTBRANCH_TOS ,1 }, + {MSR_C2_LASTBRANCH_0_FROM_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {MSR_C2_LASTBRANCH_0_TO_IP ,NUM_MSR_ATOM_LASTBRANCH_FROM_TO }, + {0 ,0 } +}, gm_lbr[] = { + {MSR_IA32_LASTINTFROMIP ,1 },xen/arch/x86/hvm/vmx/vmx.c void vmx_pi_hooks_deassign(struct domain *d) · line 458
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +10
-0+ { MSR_IA32_LASTINTTOIP, 1 }, + { MSR_SM_LBR_SELECT, 1 }, + { MSR_SM_LASTBRANCH_TOS, 1 }, + { MSR_GM_LASTBRANCH_0_FROM_IP, NUM_MSR_GM_LASTBRANCH_FROM_TO }, + { MSR_GM_LASTBRANCH_0_TO_IP, NUM_MSR_GM_LASTBRANCH_FROM_TO }, + { 0, 0 } +}; +static const struct lbr_info *__ro_after_init model_specific_lbr; + +static const struct __init lbr_info *get_model_specific_lbr (void )Please move
__init:
Quoted 1 line
static const struct
lbr_info*__initget_model_specific_lbr(void)
Yeah, I noticed and fixed both style errors here. Also an extraneous space before __ro_after_init.
~Andrew
RE: [PATCH 1/2] x86/vmx: Calculate model-specific LBRs once at start of day
In reply to Andrew CooperQuoted 6 lines
From: Andrew Cooper <[email protected]>
Sent: Monday, January 9, 2023 8:08 PMThere is no point repeating this calculation at runtime, especially as it is in the fallback path of the WRSMR/RDMSR handlers.
Quoted 7 lines
Move the infrastructure higher in
vmx.cto avoid forward declarations, renaminglast_branch_msr_get()toget_model_specific_lbr()to highlight that these are model-specific only.No practical change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 2/2 x86/vmx: Support for CPUs without model-specific LBR
In reply to Andrew CooperIce Lake (server at least) has both Arch LBR and model-specific LBR. Sapphire Rapids does not have model-specific LBR at all. I.e. On SPR and later, model_specific_lbr will always be NULL, so we must make changes to avoid reliably hitting the domain_crash().
The Arch LBR spec states that CPUs without model-specific LBR implement MSR_DBG_CTL.LBR by discarding writes and always returning 0.
Do this for any CPU for which we lack model-specific LBR information.
Adjust the now-stale comment, now that the Arch LBR spec has created a way to signal "no model specific LBR" to guests.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +16 -15
@@ -3555,17 +3555,25 @@ static int cf_check vmx_msr_write_intercept( goto gp_fault;/* +* The Arch LBR spec (new in Ice Lake) states that CPUs with no +* model-specific LBRs implement MSR_DBG_CTL.LBR by discarding writes +* and always returning 0. +* +* Use this property in all cases where we don't know any +* model-specific LBR information, as it matches real hardware +* behaviour on post-Ice Lake systems. +*/ +if ( !model_specific_lbr ) + msr_content &= ~IA32_DEBUGCTLMSR_LBR ; + +/* * When a guest first enables LBR, arrange to save and restore the LBR * MSRs and allow the guest direct access. * -* MSR_DEBUGCTL and LBR has existed almost as long as MSRs have -* existed, and there is no architectural way to hide the feature, or -* fail the attempt to enable LBR. -* -* Unknown host LBR MSRs or hitting -ENOSPC with the guest load/save -* list are definitely hypervisor bugs, whereas -ENOMEM for allocating -* the load/save list is simply unlucky (and shouldn't occur with -* sensible management by the toolstack). +* Hitting -ENOSPC with the guest load/save list is definitely a +* hypervisor bug, whereas -ENOMEM for allocating the load/save list +* is simply unlucky (and shouldn't occur with sensible management by +* the toolstack). * * Either way, there is nothing we can do right now to recover, and * the guest won't execute correctly either. Simply crash the domain
@@ -3576,13 +3584,6 @@ static int cf_check vmx_msr_write_intercept( {const struct lbr_info *lbr = model_specific_lbr; -if (unlikely (!lbr) ) - { -gprintk (XENLOG_ERR ,"Unknown Host LBR MSRs\n" ); -domain_crash (v->domain); -return X86EMUL_OKAY ; - } -for ( ; lbr->count; lbr++ ) {unsigned int i;
Signature · 1 line
2.11.0
Re: [PATCH 2/2] x86/vmx: Support for CPUs without model-specific LBR
Quoted 8 lines · Andrew Cooper
Ice Lake (server at least) has both Arch LBR and model-specific LBR. Sapphire Rapids does not have model-specific LBR at all. I.e. On SPR and later,
model_specific_lbrwill always be NULL, so we must make changes to avoid reliably hitting thedomain_crash().The Arch LBR spec states that CPUs without model-specific LBR implement MSR_DBG_CTL.LBR by discarding writes and always returning 0.
Quoted 6 lines
Do this for any CPU for which we lack model-specific LBR information.
Adjust the now-stale comment, now that the Arch LBR spec has created a way to signal "no model specific LBR" to guests.
Signed-off-by Andrew Cooper <[email protected]>
RE: [PATCH 2/2] x86/vmx: Support for CPUs without model-specific LBR
In reply to Andrew CooperQuoted 11 lines
From: Andrew Cooper <[email protected]>
Sent: Monday, January 9, 2023 8:08 PMIce Lake (server at least) has both Arch LBR and model-specific LBR. Sapphire Rapids does not have model-specific LBR at all. I.e. On SPR and later,
model_specific_lbrwill always be NULL, so we must make changes to avoid reliably hitting thedomain_crash().The Arch LBR spec states that CPUs without model-specific LBR implement MSR_DBG_CTL.LBR by discarding writes and always returning 0.
Quoted 7 lines
Do this for any CPU for which we lack model-specific LBR information.
Adjust the now-stale comment, now that the Arch LBR spec has created a way to
signal "no model specific LBR" to guests.Signed-off-by Andrew Cooper <[email protected]>