Skip to content

Commit 87294bd

Browse files
codomaniasuryasaimadhu
authored andcommitted
x86/compressed: Register GHCB memory when SEV-SNP is active
The SEV-SNP guest is required by the GHCB spec to register the GHCB's Guest Physical Address (GPA). This is because the hypervisor may prefer that a guest use a consistent and/or specific GPA for the GHCB associated with a vCPU. For more information, see the GHCB specification section "GHCB GPA Registration". If hypervisor can not work with the guest provided GPA then terminate the guest boot. Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Venu Busireddy <venu.busireddy@oracle.com> Link: https://lore.kernel.org/r/20220307213356.2797205-17-brijesh.singh@amd.com
1 parent 4f9c403 commit 87294bd

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

arch/x86/boot/compressed/sev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ static bool early_setup_ghcb(void)
175175
/* Initialize lookup tables for the instruction decoder */
176176
inat_init_tables();
177177

178+
/* SNP guest requires the GHCB GPA must be registered */
179+
if (sev_snp_enabled())
180+
snp_register_ghcb_early(__pa(&boot_ghcb_page));
181+
178182
return true;
179183
}
180184

arch/x86/include/asm/sev-common.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@
5757
#define GHCB_MSR_AP_RESET_HOLD_REQ 0x006
5858
#define GHCB_MSR_AP_RESET_HOLD_RESP 0x007
5959

60+
/* GHCB GPA Register */
61+
#define GHCB_MSR_REG_GPA_REQ 0x012
62+
#define GHCB_MSR_REG_GPA_REQ_VAL(v) \
63+
/* GHCBData[63:12] */ \
64+
(((u64)((v) & GENMASK_ULL(51, 0)) << 12) | \
65+
/* GHCBData[11:0] */ \
66+
GHCB_MSR_REG_GPA_REQ)
67+
68+
#define GHCB_MSR_REG_GPA_RESP 0x013
69+
#define GHCB_MSR_REG_GPA_RESP_VAL(v) \
70+
/* GHCBData[63:12] */ \
71+
(((u64)(v) & GENMASK_ULL(63, 12)) >> 12)
72+
6073
/*
6174
* SNP Page State Change Operation
6275
*

arch/x86/kernel/sev-shared.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ static u64 get_hv_features(void)
6868
return GHCB_MSR_HV_FT_RESP_VAL(val);
6969
}
7070

71+
static void __maybe_unused snp_register_ghcb_early(unsigned long paddr)
72+
{
73+
unsigned long pfn = paddr >> PAGE_SHIFT;
74+
u64 val;
75+
76+
sev_es_wr_ghcb_msr(GHCB_MSR_REG_GPA_REQ_VAL(pfn));
77+
VMGEXIT();
78+
79+
val = sev_es_rd_ghcb_msr();
80+
81+
/* If the response GPA is not ours then abort the guest */
82+
if ((GHCB_RESP_CODE(val) != GHCB_MSR_REG_GPA_RESP) ||
83+
(GHCB_MSR_REG_GPA_RESP_VAL(val) != pfn))
84+
sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_REGISTER);
85+
}
86+
7187
static bool sev_es_negotiate_protocol(void)
7288
{
7389
u64 val;

0 commit comments

Comments
 (0)