Skip to contentSkip to conversation

x86/sev: get the AP jump table address from secrets page

PATCH In review Michael Roth 2 participants 2 messages Apr 21, 2022 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 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")
[ mroth: improve error handling when ioremap()/memremap() return NULL ]
[ mroth: don't mix function calls with declarations ]

---
v2:
- add handling for memremap()/ioremap() failures (Boris)
- don't mix function calls with declarations (Boris)

 arch/x86/include/asm/sev.h            | 35 ++++++++++++
 arch/x86/kernel/sev.c                 | 76 ++++++++++++++++++---------
 drivers/virt/coco/sevguest/sevguest.h | 35 ------------
 3 files changed, 87 insertions(+), 59 deletions(-)
arch/x86/include/asm/sev.h +35 -0
index 9c2d33f1cfee..509a23c85fe8 100644
@@ -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 +52 -24

94 lines not on this page · raw message

drivers/virt/coco/sevguest/sevguest.h +0 -35
index d39bdd013765..21bda26fdb95 100644
@@ -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
maintainer
#1 lore raw
Quoted 12 lines · Michael Roth
arch/x86/kernel/sev.c +4 -0
index f01f4550e2c6..29b832c3f27f 100644
@@ -558,6 +558,55 @@ void noinstr __sev_es_nmi_complete(void)
 	__sev_put_ghcb(&state);
 }
 
+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));

WARNING: modpost: vmlinux.o(.text+0x58a1d): Section mismatch in reference from the function get_secrets_page() to the function .init.text:early_memremap() The function get_secrets_page() references
the function __init early_memremap().
This is often because get_secrets_page lacks a __init
annotation or the annotation of early_memremap is wrong.

WARNING: modpost: vmlinux.o(.text+0x58a3e): Section mismatch in reference from the function get_secrets_page() to the function .init.text:early_memunmap() The function get_secrets_page() references
the function __init early_memunmap().
This is often because get_secrets_page lacks a __init
annotation or the annotation of early_memunmap is wrong.

The previous caller was __init.

Seeing how the call chain starts at setup_real_mode() which is __init, I'm thinking all those functions down to and including get_secrets_page() should be __init too. And I'm guessing that should be a pre-patch and then this one ontop.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette