x86/sev: get the AP jump table address from secrets page
PATCH 1/1 x86/sev: get the AP jump table address from secrets page
From: Brijesh Singh <[email protected]>
The GHCB specification section 2.7 states that when SEV-SNP is enabled, a hypervisor must provide the AP jump table physical address through the SNP secrets pages.
Fixes 0afb6b660a6b ("x86/sev: Use SEV-SNP AP creation to start secondary CPUs")
Signed-off-by Brijesh Singh <[email protected]>
Signed-off-by Michael Roth <[email protected]>
--- arch/x86/include/asm/sev.h | 35 ++++++++++++++ arch/x86/kernel/sev.c | 70 ++++++++++++++++++--------- drivers/virt/coco/sevguest/sevguest.h | 35 -------------- 3 files changed, 81 insertions(+), 59 deletions(-)
arch/x86/include/asm/sev.h +35 -0
@@ -99,6 +99,41 @@ struct snp_guest_platform_data {u64 secrets_gpa; }; +/* +* The secrets page contains 96-bytes of reserved field that can be used by +* the guest OS. The guest OS uses the area to save the message sequence +* number for each VMPCK. +* +* See the GHCB spec section Secret page layout for the format for this area. +*/ +struct secrets_os_area { +u32 msg_seqno_0; +u32 msg_seqno_1; +u32 msg_seqno_2; +u32 msg_seqno_3; +u64 ap_jump_table_pa; +u8 rsvd[40 ]; +u8 guest_usage[32 ]; +} __packed; + +#define VMPCK_KEY_LEN 32 + +/* See the SNP spec version 0.9 for secrets page format */ +struct snp_secrets_page_layout { +u32 version; +u32 imien :1 , + rsvd1 :31 ; +u32 fms; +u32 rsvd2; +u8 gosvw[16 ]; +u8 vmpck0[VMPCK_KEY_LEN ]; +u8 vmpck1[VMPCK_KEY_LEN ]; +u8 vmpck2[VMPCK_KEY_LEN ]; +u8 vmpck3[VMPCK_KEY_LEN ]; +struct secrets_os_area os_area; +u8 rsvd3[3840 ]; +} __packed; +#ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key;extern void __sev_es_ist_enter (struct pt_regs *regs);
arch/x86/kernel/sev.c +46 -24
88 lines not on this page · raw message
drivers/virt/coco/sevguest/sevguest.h +0 -35
@@ -60,39 +60,4 @@ struct snp_guest_msg { u8 payload[4000]; } __packed; -/* -* The secrets page contains 96-bytes of reserved field that can be used by -* the guest OS. The guest OS uses the area to save the message sequence -* number for each VMPCK. -* -* See the GHCB spec section Secret page layout for the format for this area. -*/ -struct secrets_os_area { -u32 msg_seqno_0; -u32 msg_seqno_1; -u32 msg_seqno_2; -u32 msg_seqno_3; -u64 ap_jump_table_pa; -u8 rsvd[40 ]; -u8 guest_usage[32 ]; -} __packed; - -#define VMPCK_KEY_LEN 32 - -/* See the SNP spec version 0.9 for secrets page format */ -struct snp_secrets_page_layout { -u32 version; -u32 imien :1 , - rsvd1 :31 ; -u32 fms; -u32 rsvd2; -u8 gosvw[16 ]; -u8 vmpck0[VMPCK_KEY_LEN ]; -u8 vmpck1[VMPCK_KEY_LEN ]; -u8 vmpck2[VMPCK_KEY_LEN ]; -u8 vmpck3[VMPCK_KEY_LEN ]; -struct secrets_os_area os_area; -u8 rsvd3[3840 ]; -} __packed; -#endif /* __VIRT_SEVGUEST_H__ */
Signature · 1 line
2.25.1
Borislav Petkov
maintainerQuoted 4 lines · Michael Roth
arch/x86/kernel/sev.c +4
-0+static u64 get_secrets_page (void ) +{ +u64 pa_data = boot_params.cc_blob_address; +struct cc_blob_sev_info info;
arch/x86/kernel/sev.c void noinstr __sev_es_nmi_complete(void) · line 574
Quoted 10 lines
arch/x86/kernel/sev.c +10
-0+void *map; + +/* +* The CC blob contains the address of the secrets page, check if the +* blob is present. +*/ +if (!pa_data) +return 0 ; + + map =early_memremap (pa_data,sizeof (info));
That function can return NULL so you need to handle it.
Quoted 5 lines
arch/x86/kernel/sev.c +5
-0+memcpy (&info, map,sizeof (info)); +early_memunmap (map,sizeof (info)); + +/* smoke-test the secrets page passed */ +if (!info.secrets_phys || info.secrets_len !=PAGE_SIZE )
arch/x86/kernel/sev.c void noinstr __sev_es_nmi_complete(void) · line 589
Quoted 10 lines
arch/x86/kernel/sev.c +10
-0+return 0 ; + +return info.secrets_phys; +} + +static u64 get_snp_jump_table_addr (void ) +{ +struct snp_secrets_page_layout *layout; +u64 pa =get_secrets_page (); +u64 addr;
Please don't hide the function call in the local variables declaration but do this instead:
struct snp_secrets_page_layout *layout;
u64 pa, addr;
pa = get_secrets_page();
if (!pa)
return 0;Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette