From: Neeraj Upadhyay The upcoming AMD FRED (Flexible Return and Event Delivery) feature introduces several new fields to the VMCB save area. These fields include FRED-specific stack pointers (fred_rsp[0-3], fred_ssp[1-3]), stack level tracking (fred_stklvls), and configuration (fred_config). Ensure that a vCPU starts with a clean and valid FRED state on capable hardware. Also update the size of save areas of VMCB. Signed-off-by: Neeraj Upadhyay Co-developed-by: Shivansh Dhiman Signed-off-by: Shivansh Dhiman Reviewed-by: Nikunj A Dadhania --- arch/x86/include/asm/svm.h | 33 ++++++++++++++++++++++++++++++--- arch/x86/kvm/svm/svm.c | 10 ++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 17f6c3fedeee..a42ed39aa8fb 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -165,7 +165,10 @@ struct __attribute__ ((__packed__)) vmcb_control_area { u8 reserved_9[22]; u64 allowed_sev_features; /* Offset 0x138 */ u64 guest_sev_features; /* Offset 0x140 */ - u8 reserved_10[664]; + u8 reserved_10[40]; + u64 exit_int_data; /* Offset 0x170 */ + u64 event_inj_data; + u8 reserved_11[608]; /* * Offset 0x3e0, 32 bytes reserved * for use by hypervisor/software. @@ -360,6 +363,18 @@ struct vmcb_save_area { u64 last_excp_to; u8 reserved_0x298[72]; u64 spec_ctrl; /* Guest version of SPEC_CTRL at 0x2E0 */ + u8 reserved_0x2e8[448]; + u64 guest_exit_int_data; /* GUEST_EXITINTDATA 0x4A8 */ + u64 guest_event_inj_data; + u64 fred_rsp0; + u64 fred_rsp1; + u64 fred_rsp2; + u64 fred_rsp3; + u64 fred_stklvls; + u64 fred_ssp1; + u64 fred_ssp2; + u64 fred_ssp3; + u64 fred_config; } __packed; /* Save area definition for SEV-ES and SEV-SNP guests */ @@ -472,6 +487,18 @@ struct sev_es_save_area { u8 fpreg_x87[80]; u8 fpreg_xmm[256]; u8 fpreg_ymm[256]; + u8 reserved_0x670[568]; + u64 guest_exit_int_data; /* GUEST_EXITINTDATA 0x8A8 */ + u64 guest_event_inj_data; + u64 fred_rsp0; + u64 fred_rsp1; + u64 fred_rsp2; + u64 fred_rsp3; + u64 fred_stklvls; + u64 fred_ssp1; + u64 fred_ssp2; + u64 fred_ssp3; + u64 fred_config; } __packed; struct ghcb_save_area { @@ -542,9 +569,9 @@ struct vmcb { }; } __packed; -#define EXPECTED_VMCB_SAVE_AREA_SIZE 744 +#define EXPECTED_VMCB_SAVE_AREA_SIZE 1280 #define EXPECTED_GHCB_SAVE_AREA_SIZE 1032 -#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 1648 +#define EXPECTED_SEV_ES_SAVE_AREA_SIZE 2304 #define EXPECTED_VMCB_CONTROL_AREA_SIZE 1024 #define EXPECTED_GHCB_SIZE PAGE_SIZE diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f4ccb3e66635..5cec971a1f5a 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1110,6 +1110,16 @@ static void init_vmcb(struct kvm_vcpu *vcpu, bool init_event) save->idtr.base = 0; save->idtr.limit = 0xffff; + save->fred_rsp0 = 0; + save->fred_rsp1 = 0; + save->fred_rsp2 = 0; + save->fred_rsp3 = 0; + save->fred_stklvls = 0; + save->fred_ssp1 = 0; + save->fred_ssp2 = 0; + save->fred_ssp3 = 0; + save->fred_config = 0; + init_sys_seg(&save->ldtr, SEG_TYPE_LDT); init_sys_seg(&save->tr, SEG_TYPE_BUSY_TSS16); -- 2.43.0