Skip to contentSkip to conversation

nosnp sev command line support

PATCH Superseded Pavan Kumar Paluri 2 participants 7 messages Sep 30, 2024 – Oct 1, 2024

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover nosnp sev command line support

Provide "nosnp" boot option via "sev=nosnp" kernel command line to prevent SEV-SNP[1] capable host kernel from enabling SEV-SNP and initializing Reverse Map Table (RMP) [1].

On providing sev=nosnp via kernel command line:
cat /sys/module/kvm_amd/parameters/sev_snp should be "N".

This patchset is based on tip/master.

Reference:
[1] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/programmer-references/24593.pdf

Changelog:
=========
v4->v5:
* Move __read_mostly attribute to place where sev_cfg is declared (Tom)

v3->v4:
* Remove an irrelevant header (Boris)
* Rebase on latest tip/master
* Link: https://lore.kernel.org/all/[email protected]/

Pavan Kumar Paluri (2):
x86, KVM:SVM: Move sev specific parsing into arch/x86/virt/svm x86 KVM:SVM: Provide "nosnp" boot option for sev kernel command line

 .../arch/x86/x86_64/boot-options.rst          |  3 ++
 arch/x86/coco/sev/core.c                      | 44 -------------------
 arch/x86/include/asm/sev-common.h             | 29 ++++++++++++
 arch/x86/virt/svm/Makefile                    |  1 +
 arch/x86/virt/svm/cmdline.c                   | 39 ++++++++++++++++
 5 files changed, 72 insertions(+), 44 deletions(-)
 create mode 100644 arch/x86/virt/svm/cmdline.c

base-commit: d1b8f40d000887720e0c123c382d75e7fbb75cb6

Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/2 x86, KVM:SVM: Move sev specific parsing into arch/x86/virt/svm

Move SEV specific kernel command line option parsing support from arch/x86/coco/sev/core.c to arch/x86/virt/svm/cmdline.c so that both host and guest related SEV command line options can be supported.

No functional changes intended.

---
 arch/x86/coco/sev/core.c          | 44 -------------------------------
 arch/x86/include/asm/sev-common.h | 29 ++++++++++++++++++++
 arch/x86/virt/svm/Makefile        |  1 +
 arch/x86/virt/svm/cmdline.c       | 32 ++++++++++++++++++++++
 4 files changed, 62 insertions(+), 44 deletions(-)
 create mode 100644 arch/x86/virt/svm/cmdline.c
arch/x86/coco/sev/core.c +0 -44
index de1df0cb45da..ff19e805e7a1 100644
@@ -141,33 +141,6 @@ static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa);
 static DEFINE_PER_CPU(struct svsm_ca *, svsm_caa);
 static DEFINE_PER_CPU(u64, svsm_caa_pa);
 
-struct sev_config {
-	__u64 debug		: 1,
-
-	      /*
-	       * Indicates when the per-CPU GHCB has been created and registered
-	       * and thus can be used by the BSP instead of the early boot GHCB.
-	       *
-	       * For APs, the per-CPU GHCB is created before they are started
-	       * and registered upon startup, so this flag can be used globally
-	       * for the BSP and APs.
-	       */
-	      ghcbs_initialized	: 1,
-
-	      /*
-	       * Indicates when the per-CPU SVSM CA is to be used instead of the
-	       * boot SVSM CA.
-	       *
-	       * For APs, the per-CPU SVSM CA is created as part of the AP
-	       * bringup, so this flag can be used globally for the BSP and APs.
-	       */
-	      use_cas		: 1,
-
-	      __reserved	: 61;
-};
-
-static struct sev_config sev_cfg __read_mostly;
-
 static __always_inline bool on_vc_stack(struct pt_regs *regs)
 {
 	unsigned long sp = regs->sp;
@@ -2374,23 +2347,6 @@ static int __init report_snp_info(void)
 }
 arch_initcall(report_snp_info);
 
-static int __init init_sev_config(char *str)
-{
-	char *s;
-
-	while ((s = strsep(&str, ","))) {
-		if (!strcmp(s, "debug")) {
-			sev_cfg.debug = true;
-			continue;
-		}
-
-		pr_info("SEV command-line option '%s' was not recognized\n", s);
-	}
-
-	return 1;
-}
-__setup("sev=", init_sev_config);
-
 static void update_attest_input(struct svsm_call *call, struct svsm_attest_call *input)
 {
 	/* If (new) lengths have been returned, propagate them up */
arch/x86/include/asm/sev-common.h +29 -0
index 98726c2b04f8..9e36e8dcc997 100644
@@ -8,6 +8,8 @@
 #ifndef __ASM_X86_SEV_COMMON_H
 #define __ASM_X86_SEV_COMMON_H
 
+#include <asm/cache.h>
+
 #define GHCB_MSR_INFO_POS		0
 #define GHCB_DATA_LOW			12
 #define GHCB_MSR_INFO_MASK		(BIT_ULL(GHCB_DATA_LOW) - 1)
@@ -220,4 +222,31 @@ struct snp_psc_desc {
 #define GHCB_ERR_INVALID_INPUT		5
 #define GHCB_ERR_INVALID_EVENT		6
 
+struct sev_config {
+	__u64 debug		: 1,
+
+	      /*
+	       * Indicates when the per-CPU GHCB has been created and registered
+	       * and thus can be used by the BSP instead of the early boot GHCB.
+	       *
+	       * For APs, the per-CPU GHCB is created before they are started
+	       * and registered upon startup, so this flag can be used globally
+	       * for the BSP and APs.
+	       */
+	      ghcbs_initialized	: 1,
+
+	      /*
+	       * Indicates when the per-CPU SVSM CA is to be used instead of the
+	       * boot SVSM CA.
+	       *
+	       * For APs, the per-CPU SVSM CA is created as part of the AP
+	       * bringup, so this flag can be used globally for the BSP and APs.
+	       */
+	      use_cas		: 1,
+
+	      __reserved	: 61;
+};
+
+extern struct sev_config sev_cfg;
+
 #endif
arch/x86/virt/svm/Makefile +1 -0
index ef2a31bdcc70..eca6d71355fa 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_KVM_AMD_SEV) += sev.o
+obj-$(CONFIG_CPU_SUP_AMD) += cmdline.o
arch/x86/virt/svm/cmdline.c new file +32 -0
new file mode 100644
index 000000000000..9640507342e0
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD SVM-SEV command line parsing support
+ *
+ * Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc.
+ *
+ * Author: Michael Roth <[email protected]>
+ */
+
+#include <linux/string.h>
+#include <linux/printk.h>
+
+#include <asm/sev-common.h>
+
+struct sev_config sev_cfg __read_mostly;
+
+static int __init init_sev_config(char *str)
+{
+	char *s;
+
+	while ((s = strsep(&str, ","))) {
+		if (!strcmp(s, "debug")) {
+			sev_cfg.debug = true;
+			continue;
+		}
+
+		pr_info("SEV command-line option '%s' was not recognized\n", s);
+	}
+
+	return 1;
+}
+__setup("sev=", init_sev_config);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 2/2 x86 KVM:SVM: Provide "nosnp" boot option for sev kernel command line

In reply to Pavan Kumar Paluri

Provide a "nosnp" kernel command line option to prevent enabling of the RMP and SEV-SNP features in the host/hypervisor. Not initializing the RMP removes system overhead associated with RMP checks.

---
 Documentation/arch/x86/x86_64/boot-options.rst | 3 +++
 arch/x86/virt/svm/cmdline.c                    | 7 +++++++
 2 files changed, 10 insertions(+)
Documentation/arch/x86/x86_64/boot-options.rst +3 -0
index 98d4805f0823..7ae6d882ea52 100644
@@ -305,3 +305,6 @@ The available options are:
 
    debug
      Enable debug messages.
+
+   nosnp
+     Do not enable SEV-SNP (applies to host/hypervisor only).
arch/x86/virt/svm/cmdline.c +7 -0
index 9640507342e0..313415d6f53f 100644
@@ -11,6 +11,7 @@
 #include <linux/printk.h>
 
 #include <asm/sev-common.h>
+#include <asm/cpufeature.h>
 
 struct sev_config sev_cfg __read_mostly;
 
@@ -24,6 +25,12 @@ static int __init init_sev_config(char *str)
 			continue;
 		}
 
+		if (!strcmp(s, "nosnp")) {
+			setup_clear_cpu_cap(X86_FEATURE_SEV_SNP);
+			cc_platform_clear(CC_ATTR_HOST_SEV_SNP);
+			continue;
+		}
+
 		pr_info("SEV command-line option '%s' was not recognized\n", s);
 	}
 
Signature · 1 line
2.34.1
#3 lore raw
In reply to Pavan Kumar Paluri
Quoted 6 lines · Pavan Kumar Paluri

Provide "nosnp" boot option via "sev=nosnp" kernel command line to prevent SEV-SNP[1] capable host kernel from enabling SEV-SNP and initializing Reverse Map Table (RMP) [1].

On providing sev=nosnp via kernel command line:
cat /sys/module/kvm_amd/parameters/sev_snp should be "N".

I don't see any mention in the changelog, cover letter or Documentation/ about why someone would want to do this.

I assume it's because of performance (walking the RMP table is non-zero cost).

The BIOS allocates the RMP table, right? So this option presumably gets the performance back, but not the memory. That's probably also worth mentioning ... somewhere.

#4 lore raw

Hello Dave,

Quoted 11 lines · Dave Hansen
Quoted 6 lines · Pavan Kumar Paluri

Provide "nosnp" boot option via "sev=nosnp" kernel command line to prevent SEV-SNP[1] capable host kernel from enabling SEV-SNP and initializing Reverse Map Table (RMP) [1].

On providing sev=nosnp via kernel command line:
cat /sys/module/kvm_amd/parameters/sev_snp should be "N".

I don't see any mention in the changelog, cover letter or Documentation/ about why someone would want to do this.

Quoted 6 lines

I assume it's because of performance (walking the RMP table is non-zero cost).

The BIOS allocates the RMP table, right? So this option presumably gets the performance back, but not the memory. That's probably also worth mentioning ... somewhere.

Yes, that is correct. RMP is BIOS-allocated, so there is a performance gain but not memory.

Besides, having a 'nosnp' command line option would benefit customers to be able to set the BIOS option to allocate RMP, but not actually enable it just yet. This way, they can avoid overhead incurred from RMP checks, for when they do not want to run SEV-SNP guests.

I will include this information in the cover-letter.

Thanks,
Pavan

#5 lore raw
Quoted 1 line · PavanKumar

I will include this information in the cover-letter.

... and the documentation for the command-line, please

#6 lore raw
Quoted 4 lines · Dave Hansen
Quoted 1 line · PavanKumar

I will include this information in the cover-letter.

... and the documentation for the command-line, please

Sure.

Thanks,
Pavan