mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Most of the SEV support code used to reside in a single C source file that was included in two places: the core kernel, and the decompressor. The code that is actually shared with the decompressor was moved into a separate, shared source file under startup/, on the basis that the decompressor also executes from the early 1:1 mapping of memory. However, while the elaborate #VC handling and instruction decoding that it involves is also performed by the decompressor, it does not actually occur in the core kernel at early boot, and therefore, does not need to be part of the confined early startup code. So split off the #VC handling code and move it back into arch/x86/coco where it came from, into another C source file that is included from both the decompressor and the core kernel. Code movement only - no functional change intended. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: Dionna Amalie Glaze <dionnaglaze@google.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kees Cook <keescook@chromium.org> Cc: Kevin Loughlin <kevinloughlin@google.com> Cc: Len Brown <len.brown@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: linux-efi@vger.kernel.org Link: https://lore.kernel.org/r/20250504095230.2932860-31-ardb+git@google.com
134 lines
2.7 KiB
C
134 lines
2.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "misc.h"
|
|
#include "sev.h"
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/string.h>
|
|
#include <asm/insn.h>
|
|
#include <asm/pgtable_types.h>
|
|
#include <asm/ptrace.h>
|
|
#include <asm/sev.h>
|
|
#include <asm/trapnr.h>
|
|
#include <asm/trap_pf.h>
|
|
#include <asm/fpu/xcr.h>
|
|
|
|
#define __BOOT_COMPRESSED
|
|
|
|
/* Basic instruction decoding support needed */
|
|
#include "../../lib/inat.c"
|
|
#include "../../lib/insn.c"
|
|
|
|
/*
|
|
* Copy a version of this function here - insn-eval.c can't be used in
|
|
* pre-decompression code.
|
|
*/
|
|
bool insn_has_rep_prefix(struct insn *insn)
|
|
{
|
|
insn_byte_t p;
|
|
int i;
|
|
|
|
insn_get_prefixes(insn);
|
|
|
|
for_each_insn_prefix(insn, i, p) {
|
|
if (p == 0xf2 || p == 0xf3)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)
|
|
{
|
|
char buffer[MAX_INSN_SIZE];
|
|
int ret;
|
|
|
|
memcpy(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);
|
|
|
|
ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64);
|
|
if (ret < 0)
|
|
return ES_DECODE_FAILED;
|
|
|
|
return ES_OK;
|
|
}
|
|
|
|
extern void sev_insn_decode_init(void) __alias(inat_init_tables);
|
|
|
|
/*
|
|
* Only a dummy for insn_get_seg_base() - Early boot-code is 64bit only and
|
|
* doesn't use segments.
|
|
*/
|
|
static unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)
|
|
{
|
|
return 0UL;
|
|
}
|
|
|
|
static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,
|
|
void *dst, char *buf, size_t size)
|
|
{
|
|
memcpy(dst, buf, size);
|
|
|
|
return ES_OK;
|
|
}
|
|
|
|
static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
|
|
void *src, char *buf, size_t size)
|
|
{
|
|
memcpy(buf, src, size);
|
|
|
|
return ES_OK;
|
|
}
|
|
|
|
static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t size)
|
|
{
|
|
return ES_OK;
|
|
}
|
|
|
|
static bool fault_in_kernel_space(unsigned long address)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#define sev_printk(fmt, ...)
|
|
|
|
#include "../../coco/sev/vc-shared.c"
|
|
|
|
void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
|
|
{
|
|
struct es_em_ctxt ctxt;
|
|
enum es_result result;
|
|
|
|
if (!boot_ghcb && !early_setup_ghcb())
|
|
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
|
|
|
|
vc_ghcb_invalidate(boot_ghcb);
|
|
result = vc_init_em_ctxt(&ctxt, regs, exit_code);
|
|
if (result != ES_OK)
|
|
goto finish;
|
|
|
|
result = vc_check_opcode_bytes(&ctxt, exit_code);
|
|
if (result != ES_OK)
|
|
goto finish;
|
|
|
|
switch (exit_code) {
|
|
case SVM_EXIT_RDTSC:
|
|
case SVM_EXIT_RDTSCP:
|
|
result = vc_handle_rdtsc(boot_ghcb, &ctxt, exit_code);
|
|
break;
|
|
case SVM_EXIT_IOIO:
|
|
result = vc_handle_ioio(boot_ghcb, &ctxt);
|
|
break;
|
|
case SVM_EXIT_CPUID:
|
|
result = vc_handle_cpuid(boot_ghcb, &ctxt);
|
|
break;
|
|
default:
|
|
result = ES_UNSUPPORTED;
|
|
break;
|
|
}
|
|
|
|
finish:
|
|
if (result == ES_OK)
|
|
vc_finish_insn(&ctxt);
|
|
else if (result != ES_RETRY)
|
|
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);
|
|
}
|