Skip to content

Commit 1b5ef14

Browse files
committed
KVM: SVM: Add host SEV-ES save area structure into VMCB via a union
Incorporate the _host_ SEV-ES save area into the VMCB as a union with the legacy save area. The SEV-ES variant used to save/load host state is larger than the legacy save area, but resides at the same offset. Prefix the field with "host" to make it as obvious as possible that the SEV-ES variant in the VMCB is only ever used for host state. Guest state for SEV-ES VMs is stored in a completely separate page (VMSA), albeit with the same layout as the host state. Add a compile-time assert to ensure the VMCB layout is correct, i.e. that KVM's layout matches the architectural definitions. No functional change intended. Link: https://lore.kernel.org/r/20240802204511.352017-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 48547fe commit 1b5ef14

File tree

1 file changed

+15
-5
lines changed
  • arch/x86/include/asm

1 file changed

+15
-5
lines changed

arch/x86/include/asm/svm.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,20 @@ struct ghcb {
516516
u32 ghcb_usage;
517517
} __packed;
518518

519+
struct vmcb {
520+
struct vmcb_control_area control;
521+
union {
522+
struct vmcb_save_area save;
523+
524+
/*
525+
* For SEV-ES VMs, the save area in the VMCB is used only to
526+
* save/load host state. Guest state resides in a separate
527+
* page, the aptly named VM Save Area (VMSA), that is encrypted
528+
* with the guest's private key.
529+
*/
530+
struct sev_es_save_area host_sev_es_save;
531+
};
532+
} __packed;
519533

520534
#define EXPECTED_VMCB_SAVE_AREA_SIZE 744
521535
#define EXPECTED_GHCB_SAVE_AREA_SIZE 1032
@@ -532,6 +546,7 @@ static inline void __unused_size_checks(void)
532546
BUILD_BUG_ON(sizeof(struct ghcb_save_area) != EXPECTED_GHCB_SAVE_AREA_SIZE);
533547
BUILD_BUG_ON(sizeof(struct sev_es_save_area) != EXPECTED_SEV_ES_SAVE_AREA_SIZE);
534548
BUILD_BUG_ON(sizeof(struct vmcb_control_area) != EXPECTED_VMCB_CONTROL_AREA_SIZE);
549+
BUILD_BUG_ON(offsetof(struct vmcb, save) != EXPECTED_VMCB_CONTROL_AREA_SIZE);
535550
BUILD_BUG_ON(sizeof(struct ghcb) != EXPECTED_GHCB_SIZE);
536551

537552
/* Check offsets of reserved fields */
@@ -568,11 +583,6 @@ static inline void __unused_size_checks(void)
568583
BUILD_BUG_RESERVED_OFFSET(ghcb, 0xff0);
569584
}
570585

571-
struct vmcb {
572-
struct vmcb_control_area control;
573-
struct vmcb_save_area save;
574-
} __packed;
575-
576586
#define SVM_CPUID_FUNC 0x8000000a
577587

578588
#define SVM_SELECTOR_S_SHIFT 4

0 commit comments

Comments
 (0)