Skip to content

Commit 7b22e04

Browse files
kraxelbp3tk0v
authored andcommitted
x86/sev/vc: Fix EFI runtime instruction emulation
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 <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Pankaj Gupta <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent 040ed57 commit 7b22e04

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arch/x86/coco/sev/vc-handle.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/mm.h>
1818
#include <linux/io.h>
1919
#include <linux/psp-sev.h>
20+
#include <linux/efi.h>
2021
#include <uapi/linux/sev-guest.h>
2122

2223
#include <asm/init.h>
@@ -178,9 +179,15 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt)
178179
return ES_OK;
179180
}
180181

182+
/*
183+
* User instruction decoding is also required for the EFI runtime. Even though
184+
* the EFI runtime is running in kernel mode, it uses special EFI virtual
185+
* address mappings that require the use of efi_mm to properly address and
186+
* decode.
187+
*/
181188
static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
182189
{
183-
if (user_mode(ctxt->regs))
190+
if (user_mode(ctxt->regs) || mm_is_efi(current->active_mm))
184191
return __vc_decode_user_insn(ctxt);
185192
else
186193
return __vc_decode_kern_insn(ctxt);

0 commit comments

Comments
 (0)