]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/sev/vc: Fix EFI runtime instruction emulation
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 26 Jun 2025 11:40:11 +0000 (13:40 +0200)
committerBorislav Petkov (AMD) <bp@alien8.de>
Fri, 27 Jun 2025 11:53:12 +0000 (13:53 +0200)
In case efi_mm is active go use the userspace instruction decoder which
supports fetching instructions from active_mm.  This is needed to make
instruction emulation work for EFI runtime code, so it can use CPUID and
RDMSR.

EFI runtime code uses the CPUID instruction to gather information about
the environment it is running in, such as SEV being enabled or not, and
choose (if needed) the SEV code path for ioport access.

EFI runtime code uses the RDMSR instruction to get the location of the
CAA page (see SVSM spec, section 4.2 - "Post Boot").

The big picture behind this is that the kernel needs to be able to
properly handle #VC exceptions that come from EFI runtime services.
Since EFI runtime services have a special page table mapping for the EFI
virtual address space, the efi_mm context must be used when decoding
instructions during #VC handling.

  [ bp: Massage. ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Link: https://lore.kernel.org/20250626114014.373748-2-kraxel@redhat.com
arch/x86/coco/sev/vc-handle.c

index 0989d98da1303ee4aa623ab9bed89cb6e030858e..faf1fce89ed478753bbc62cf6a1da1c8c6b65f42 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 #include <linux/io.h>
 #include <linux/psp-sev.h>
+#include <linux/efi.h>
 #include <uapi/linux/sev-guest.h>
 
 #include <asm/init.h>
@@ -178,9 +179,15 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt)
                return ES_OK;
 }
 
+/*
+ * User instruction decoding is also required for the EFI runtime. Even though
+ * the EFI runtime is running in kernel mode, it uses special EFI virtual
+ * address mappings that require the use of efi_mm to properly address and
+ * decode.
+ */
 static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
 {
-       if (user_mode(ctxt->regs))
+       if (user_mode(ctxt->regs) || mm_is_efi(current->active_mm))
                return __vc_decode_user_insn(ctxt);
        else
                return __vc_decode_kern_insn(ctxt);