[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6b4b8924-c0a7-58ab-f282-93d019cd0b96@amd.com>
Date: Mon, 23 Jun 2025 08:57:20 -0500
From: Tom Lendacky <thomas.lendacky@....com>
To: Gerd Hoffmann <kraxel@...hat.com>, linux-coco@...ts.linux.dev
Cc: kvm@...r.kernel.org, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/2] x86/sev/vc: fix efi runtime instruction emulation
On 6/2/25 05:50, Gerd Hoffmann wrote:
> 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").
>
> Signed-off-by: Gerd Hoffmann <kraxel@...hat.com>
> ---
> arch/x86/coco/sev/vc-handle.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c
> index 0989d98da130..01c78182da88 100644
> --- a/arch/x86/coco/sev/vc-handle.c
> +++ b/arch/x86/coco/sev/vc-handle.c
> @@ -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>
> @@ -180,7 +181,7 @@ static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt)
>
> static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
> {
> - if (user_mode(ctxt->regs))
> + if (user_mode(ctxt->regs) || current->active_mm == &efi_mm)
A comment before this would be good. Something like:
/*
* User instruction decoding is also required for the EFI runtime. Even
* though 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.
*/
Might be too verbose, but that's the general idea.
Thanks,
Tom
> return __vc_decode_user_insn(ctxt);
> else
> return __vc_decode_kern_insn(ctxt);
Powered by blists - more mailing lists