Path: blob/master/arch/x86/boot/compressed/sev-handle-vc.c
29271 views
// SPDX-License-Identifier: GPL-2.012#include "misc.h"3#include "error.h"4#include "sev.h"56#include <linux/kernel.h>7#include <linux/string.h>8#include <asm/insn.h>9#include <asm/pgtable_types.h>10#include <asm/ptrace.h>11#include <asm/sev.h>12#include <asm/trapnr.h>13#include <asm/trap_pf.h>14#include <asm/fpu/xcr.h>1516#define __BOOT_COMPRESSED17#undef __init18#define __init1920/* Basic instruction decoding support needed */21#include "../../lib/inat.c"22#include "../../lib/insn.c"2324/*25* Copy a version of this function here - insn-eval.c can't be used in26* pre-decompression code.27*/28bool insn_has_rep_prefix(struct insn *insn)29{30insn_byte_t p;31int i;3233insn_get_prefixes(insn);3435for_each_insn_prefix(insn, i, p) {36if (p == 0xf2 || p == 0xf3)37return true;38}3940return false;41}4243enum es_result vc_decode_insn(struct es_em_ctxt *ctxt)44{45char buffer[MAX_INSN_SIZE];46int ret;4748memcpy(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE);4950ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64);51if (ret < 0)52return ES_DECODE_FAILED;5354return ES_OK;55}5657extern void sev_insn_decode_init(void) __alias(inat_init_tables);5859/*60* Only a dummy for insn_get_seg_base() - Early boot-code is 64bit only and61* doesn't use segments.62*/63static unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)64{65return 0UL;66}6768static enum es_result vc_write_mem(struct es_em_ctxt *ctxt,69void *dst, char *buf, size_t size)70{71memcpy(dst, buf, size);7273return ES_OK;74}7576static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,77void *src, char *buf, size_t size)78{79memcpy(buf, src, size);8081return ES_OK;82}8384static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t size)85{86return ES_OK;87}8889static bool fault_in_kernel_space(unsigned long address)90{91return false;92}9394#define sev_printk(fmt, ...)9596#include "../../coco/sev/vc-shared.c"9798void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)99{100struct es_em_ctxt ctxt;101enum es_result result;102103if (!boot_ghcb && !early_setup_ghcb())104sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);105106vc_ghcb_invalidate(boot_ghcb);107result = vc_init_em_ctxt(&ctxt, regs, exit_code);108if (result != ES_OK)109goto finish;110111result = vc_check_opcode_bytes(&ctxt, exit_code);112if (result != ES_OK)113goto finish;114115switch (exit_code) {116case SVM_EXIT_RDTSC:117case SVM_EXIT_RDTSCP:118result = vc_handle_rdtsc(boot_ghcb, &ctxt, exit_code);119break;120case SVM_EXIT_IOIO:121result = vc_handle_ioio(boot_ghcb, &ctxt);122break;123case SVM_EXIT_CPUID:124result = vc_handle_cpuid(boot_ghcb, &ctxt);125break;126default:127result = ES_UNSUPPORTED;128break;129}130131finish:132if (result == ES_OK)133vc_finish_insn(&ctxt);134else if (result != ES_RETRY)135sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SEV_ES_GEN_REQ);136}137138139