Add the LBRv2 fields to the SEV-ES VMSA save area and treat LBRv2 as always active for SEV-ES+ guests, which run with LBR virtualization mandatorily enabled and keep DBG_EXTN_CFG in the encrypted VMSA. Signed-off-by: Shivansh Dhiman --- Changes in v2: * New patch. --- arch/x86/include/asm/svm.h | 12 +++++++++--- arch/x86/kvm/svm/svm.c | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index fb42c6806655..0473e38e33bc 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -446,7 +446,8 @@ struct sev_es_save_area { u64 br_to; u64 last_excp_from; u64 last_excp_to; - u8 reserved_0x298[80]; + u64 dbg_extn_cfg; + u8 reserved_0x2a0[72]; u32 pkru; u32 tsc_aux; u64 tsc_scale; @@ -495,6 +496,11 @@ struct sev_es_save_area { u8 fpreg_x87[80]; u8 fpreg_xmm[256]; u8 fpreg_ymm[256]; + struct { + u64 lbr_stack_from; + u64 lbr_stack_to; + } __packed lbr[16]; + u64 lbr_select; } __packed; struct ghcb_save_area { @@ -567,7 +573,7 @@ struct vmcb { #define EXPECTED_VMCB_SAVE_AREA_SIZE 1912 #define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 -#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648 +#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1912 #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024 #define EXPECTED_GHCB_SIZE PAGE_SIZE @@ -598,7 +604,7 @@ static inline void __unused_size_checks(void) BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0xd8); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x1c0); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x248); - BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x298); + BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x2a0); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x300); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x320); BUILD_BUG_RESERVED_OFFSET(sev_es_save_area, 0x380); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index ea7535ccc3fe..d5656e047dad 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -761,8 +761,19 @@ static bool svm_lbrv2_supported(struct kvm_vcpu *vcpu) static bool svm_lbrv2_active(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); - return svm_lbrv2_supported(vcpu) && - (svm->vmcb->save.dbg_extn_cfg & DBG_EXTN_CFG_LBRV2EN); + + if (!svm_lbrv2_supported(vcpu)) + return false; + + /* + * SEV-ES+ guests run with LBR virtualization mandatorily enabled and + * keep DBG_EXTN_CFG in the encrypted VMSA, so KVM can't observe + * LBRV2EN; treat LBRv2 as always active. + */ + if (is_sev_es_guest(vcpu)) + return true; + + return svm->vmcb->save.dbg_extn_cfg & DBG_EXTN_CFG_LBRV2EN; } static void svm_recalc_lbrv2_msr_intercepts(struct kvm_vcpu *vcpu) -- 2.43.0