Path: blob/master/arch/x86/boot/compressed/sev-handle-vc.c
26481 views
// SPDX-License-Identifier: GPL-2.012#include "misc.h"3#include "sev.h"45#include <linux/kernel.h>6#include <linux/string.h>7#include <asm/insn.h>8#include <asm/pgtable_types.h>9#include <asm/ptrace.h>10#include <asm/sev.h>11#include <asm/trapnr.h>12#include <asm/trap_pf.h>13#include <asm/fpu/xcr.h>1415#define __BOOT_COMPRESSED1617/* Basic instruction decoding support needed */18#include "../../lib/inat.c"19#include "../../lib/insn.c"2021/*22* Copy a version of this function here - insn-eval.c can't be used in23* pre-decompression code.24*/25bool insn_has_rep_prefix(struct insn *insn)26{27insn_byte_t p;28int i;2930insn_get_prefixes(insn);3132for_each_insn_prefix(insn, i, p) {33if (p == 0xf2 || p == 0xf3)34return true;35}3637return false;38}3940enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)41{42char buffer[MAX_INSN_SIZE];43int ret;4445memcpy(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);4647ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64);48if (ret < 0)49return ES_DECODE_FAILED;5051return ES_OK;52}5354extern void sev_insn_decode_init(void) __alias(inat_init_tables);5556/*57* Only a dummy for insn_get_seg_base() - Early boot-code is 64bit only and58* doesn't use segments.59*/60static unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)61{62return 0UL;63}6465static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,66void *dst, char *buf, size_t size)67{68memcpy(dst, buf, size);6970return ES_OK;71}7273static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,74void *src, char *buf, size_t size)75{76memcpy(buf, src, size);7778return ES_OK;79}8081static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t size)82{83return ES_OK;84}8586static bool fault_in_kernel_space(unsigned long address)87{88return false;89}9091#define sev_printk(fmt, ...)9293#include "../../coco/sev/vc-shared.c"9495void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)96{97struct es_em_ctxt ctxt;98enum es_result result;99100if (!boot_ghcb && !early_setup_ghcb())101sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);102103vc_ghcb_invalidate(boot_ghcb);104result = vc_init_em_ctxt(&ctxt, regs, exit_code);105if (result != ES_OK)106goto finish;107108result = vc_check_opcode_bytes(&ctxt, exit_code);109if (result != ES_OK)110goto finish;111112switch (exit_code) {113case SVM_EXIT_RDTSC:114case SVM_EXIT_RDTSCP:115result = vc_handle_rdtsc(boot_ghcb, &ctxt, exit_code);116break;117case SVM_EXIT_IOIO:118result = vc_handle_ioio(boot_ghcb, &ctxt);119break;120case SVM_EXIT_CPUID:121result = vc_handle_cpuid(boot_ghcb, &ctxt);122break;123default:124result = ES_UNSUPPORTED;125break;126}127128finish:129if (result == ES_OK)130vc_finish_insn(&ctxt);131else if (result != ES_RETRY)132sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);133}134135136