]> www.infradead.org Git - linux-platform-drivers-x86.git/commitdiff
x86/sev: Allow non-VMPL0 execution when an SVSM is present
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 5 Jun 2024 15:18:56 +0000 (10:18 -0500)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 17 Jun 2024 18:42:58 +0000 (20:42 +0200)
To allow execution at a level other than VMPL0, an SVSM must be present.
Allow the SEV-SNP guest to continue booting if an SVSM is detected and
the hypervisor supports the SVSM feature as indicated in the GHCB
hypervisor features bitmap.

  [ bp: Massage a bit. ]

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/2ce7cf281cce1d0cba88f3f576687ef75dc3c953.1717600736.git.thomas.lendacky@amd.com
arch/x86/boot/compressed/sev.c
arch/x86/include/asm/sev-common.h
arch/x86/kernel/sev.c

index ce941a9890f8e1865433c8fff52e2b63c2ef2b83..697057250faa56b418f1424bdd23f9dda5d6ba01 100644 (file)
@@ -610,11 +610,15 @@ void sev_enable(struct boot_params *bp)
         * features.
         */
        if (sev_status & MSR_AMD64_SEV_SNP_ENABLED) {
-               if (!(get_hv_features() & GHCB_HV_FT_SNP))
+               u64 hv_features;
+               int ret;
+
+               hv_features = get_hv_features();
+               if (!(hv_features & GHCB_HV_FT_SNP))
                        sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
 
                /*
-                * Enforce running at VMPL0.
+                * Enforce running at VMPL0 or with an SVSM.
                 *
                 * Use RMPADJUST (see the rmpadjust() function for a description of
                 * what the instruction does) to update the VMPL1 permissions of a
@@ -623,7 +627,14 @@ void sev_enable(struct boot_params *bp)
                 * only ever run at a single VMPL level so permission mask changes of a
                 * lesser-privileged VMPL are a don't-care.
                 */
-               if (rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1))
+               ret = rmpadjust((unsigned long)&boot_ghcb_page, RMP_PG_SIZE_4K, 1);
+
+               /*
+                * Running at VMPL0 is not required if an SVSM is present and the hypervisor
+                * supports the required SVSM GHCB events.
+                */
+               if (ret &&
+                   !(snp_vmpl && (hv_features & GHCB_HV_FT_SNP_MULTI_VMPL)))
                        sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_NOT_VMPL0);
        }
 
index 78a4c25119da6abe9d387c87b7e85f0597419fa5..e90d403f2068b6f0e0a0680f28e7ce1f062fc036 100644 (file)
@@ -122,6 +122,7 @@ enum psc_op {
 
 #define GHCB_HV_FT_SNP                 BIT_ULL(0)
 #define GHCB_HV_FT_SNP_AP_CREATION     BIT_ULL(1)
+#define GHCB_HV_FT_SNP_MULTI_VMPL      BIT_ULL(5)
 
 /*
  * SNP Page State Change NAE event
index 53ac3e0fc92a4853019057985dd8a00d7a5e93cf..726d9df505e71089c6fd49101b730d4079c036d5 100644 (file)
@@ -2352,23 +2352,27 @@ static void dump_cpuid_table(void)
  * expected, but that initialization happens too early in boot to print any
  * sort of indicator, and there's not really any other good place to do it,
  * so do it here.
+ *
+ * If running as an SNP guest, report the current VM privilege level (VMPL).
  */
-static int __init report_cpuid_table(void)
+static int __init report_snp_info(void)
 {
        const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
 
-       if (!cpuid_table->count)
-               return 0;
+       if (cpuid_table->count) {
+               pr_info("Using SNP CPUID table, %d entries present.\n",
+                       cpuid_table->count);
 
-       pr_info("Using SNP CPUID table, %d entries present.\n",
-               cpuid_table->count);
+               if (sev_cfg.debug)
+                       dump_cpuid_table();
+       }
 
-       if (sev_cfg.debug)
-               dump_cpuid_table();
+       if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP))
+               pr_info("SNP running at VMPL%u.\n", snp_vmpl);
 
        return 0;
 }
-arch_initcall(report_cpuid_table);
+arch_initcall(report_snp_info);
 
 static int __init init_sev_config(char *str)
 {