• Home
  • Raw
  • Download

Lines Matching refs:ctxt

230 static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,  in vc_fetch_insn_kernel()  argument
233 return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE); in vc_fetch_insn_kernel()
236 static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt) in __vc_decode_user_insn() argument
241 insn_bytes = insn_fetch_from_user_inatomic(ctxt->regs, buffer); in __vc_decode_user_insn()
244 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_user_insn()
245 ctxt->fi.error_code = X86_PF_INSTR | X86_PF_USER; in __vc_decode_user_insn()
246 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_user_insn()
250 ctxt->fi.vector = X86_TRAP_GP; in __vc_decode_user_insn()
251 ctxt->fi.error_code = 0; in __vc_decode_user_insn()
252 ctxt->fi.cr2 = 0; in __vc_decode_user_insn()
256 if (!insn_decode_from_regs(&ctxt->insn, ctxt->regs, buffer, insn_bytes)) in __vc_decode_user_insn()
259 if (ctxt->insn.immediate.got) in __vc_decode_user_insn()
265 static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) in __vc_decode_kern_insn() argument
270 res = vc_fetch_insn_kernel(ctxt, buffer); in __vc_decode_kern_insn()
272 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_kern_insn()
273 ctxt->fi.error_code = X86_PF_INSTR; in __vc_decode_kern_insn()
274 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_kern_insn()
278 ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64); in __vc_decode_kern_insn()
285 static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) in vc_decode_insn() argument
287 if (user_mode(ctxt->regs)) in vc_decode_insn()
288 return __vc_decode_user_insn(ctxt); in vc_decode_insn()
290 return __vc_decode_kern_insn(ctxt); in vc_decode_insn()
293 static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, in vc_write_mem() argument
362 if (user_mode(ctxt->regs)) in vc_write_mem()
365 ctxt->fi.vector = X86_TRAP_PF; in vc_write_mem()
366 ctxt->fi.error_code = error_code; in vc_write_mem()
367 ctxt->fi.cr2 = (unsigned long)dst; in vc_write_mem()
372 static enum es_result vc_read_mem(struct es_em_ctxt *ctxt, in vc_read_mem() argument
440 if (user_mode(ctxt->regs)) in vc_read_mem()
443 ctxt->fi.vector = X86_TRAP_PF; in vc_read_mem()
444 ctxt->fi.error_code = error_code; in vc_read_mem()
445 ctxt->fi.cr2 = (unsigned long)src; in vc_read_mem()
450 static enum es_result vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_slow_virt_to_phys() argument
463 ctxt->fi.vector = X86_TRAP_PF; in vc_slow_virt_to_phys()
464 ctxt->fi.cr2 = vaddr; in vc_slow_virt_to_phys()
465 ctxt->fi.error_code = 0; in vc_slow_virt_to_phys()
467 if (user_mode(ctxt->regs)) in vc_slow_virt_to_phys()
468 ctxt->fi.error_code |= X86_PF_USER; in vc_slow_virt_to_phys()
485 static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t size) in vc_ioio_check() argument
489 if (user_mode(ctxt->regs)) { in vc_ioio_check()
506 ctxt->fi.vector = X86_TRAP_GP; in vc_ioio_check()
507 ctxt->fi.error_code = 0; in vc_ioio_check()
653 static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_msr() argument
655 struct pt_regs *regs = ctxt->regs; in vc_handle_msr()
660 exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; in vc_handle_msr()
668 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, exit_info_1, 0); in vc_handle_msr()
815 static void __init vc_early_forward_exception(struct es_em_ctxt *ctxt) in vc_early_forward_exception() argument
817 int trapnr = ctxt->fi.vector; in vc_early_forward_exception()
820 native_write_cr2(ctxt->fi.cr2); in vc_early_forward_exception()
822 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_early_forward_exception()
823 do_early_exception(ctxt->regs, trapnr); in vc_early_forward_exception()
826 static long *vc_insn_get_reg(struct es_em_ctxt *ctxt) in vc_insn_get_reg() argument
831 reg_array = (long *)ctxt->regs; in vc_insn_get_reg()
832 offset = insn_get_modrm_reg_off(&ctxt->insn, ctxt->regs); in vc_insn_get_reg()
842 static long *vc_insn_get_rm(struct es_em_ctxt *ctxt) in vc_insn_get_rm() argument
847 reg_array = (long *)ctxt->regs; in vc_insn_get_rm()
848 offset = insn_get_modrm_rm_off(&ctxt->insn, ctxt->regs); in vc_insn_get_rm()
857 static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_do_mmio() argument
866 ref = insn_get_addr_ref(&ctxt->insn, ctxt->regs); in vc_do_mmio()
872 res = vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr); in vc_do_mmio()
875 ctxt->fi.error_code |= X86_PF_WRITE; in vc_do_mmio()
886 return sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, exit_info_1, exit_info_2); in vc_do_mmio()
890 struct es_em_ctxt *ctxt) in vc_handle_mmio_twobyte_ops() argument
892 struct insn *insn = &ctxt->insn; in vc_handle_mmio_twobyte_ops()
907 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio_twobyte_ops()
912 reg_data = vc_insn_get_reg(ctxt); in vc_handle_mmio_twobyte_ops()
929 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio_twobyte_ops()
934 reg_data = vc_insn_get_reg(ctxt); in vc_handle_mmio_twobyte_ops()
978 static enum es_result vc_handle_mmio_movs(struct es_em_ctxt *ctxt, in vc_handle_mmio_movs() argument
988 ds_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_DS); in vc_handle_mmio_movs()
989 es_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_ES); in vc_handle_mmio_movs()
992 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_mmio_movs()
993 ctxt->fi.error_code = 0; in vc_handle_mmio_movs()
997 src = ds_base + (unsigned char *)ctxt->regs->si; in vc_handle_mmio_movs()
998 dst = es_base + (unsigned char *)ctxt->regs->di; in vc_handle_mmio_movs()
1000 ret = vc_read_mem(ctxt, src, buffer, bytes); in vc_handle_mmio_movs()
1004 ret = vc_write_mem(ctxt, dst, buffer, bytes); in vc_handle_mmio_movs()
1008 if (ctxt->regs->flags & X86_EFLAGS_DF) in vc_handle_mmio_movs()
1013 ctxt->regs->si += off; in vc_handle_mmio_movs()
1014 ctxt->regs->di += off; in vc_handle_mmio_movs()
1016 rep = insn_has_rep_prefix(&ctxt->insn); in vc_handle_mmio_movs()
1018 ctxt->regs->cx -= 1; in vc_handle_mmio_movs()
1020 if (!rep || ctxt->regs->cx == 0) in vc_handle_mmio_movs()
1027 struct es_em_ctxt *ctxt) in vc_handle_mmio() argument
1029 struct insn *insn = &ctxt->insn; in vc_handle_mmio()
1034 if (user_mode(ctxt->regs)) in vc_handle_mmio()
1046 reg_data = vc_insn_get_reg(ctxt); in vc_handle_mmio()
1052 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1064 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1075 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1079 reg_data = vc_insn_get_reg(ctxt); in vc_handle_mmio()
1098 ret = vc_handle_mmio_movs(ctxt, bytes); in vc_handle_mmio()
1102 ret = vc_handle_mmio_twobyte_ops(ghcb, ctxt); in vc_handle_mmio()
1112 struct es_em_ctxt *ctxt) in vc_handle_dr7_write() argument
1115 long val, *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_write()
1125 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_dr7_write()
1126 ctxt->fi.error_code = 0; in vc_handle_dr7_write()
1139 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WRITE_DR7, 0, 0); in vc_handle_dr7_write()
1150 struct es_em_ctxt *ctxt) in vc_handle_dr7_read() argument
1153 long *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_read()
1167 struct es_em_ctxt *ctxt) in vc_handle_wbinvd() argument
1169 return sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WBINVD, 0, 0); in vc_handle_wbinvd()
1172 static enum es_result vc_handle_rdpmc(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_rdpmc() argument
1176 ghcb_set_rcx(ghcb, ctxt->regs->cx); in vc_handle_rdpmc()
1178 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_RDPMC, 0, 0); in vc_handle_rdpmc()
1185 ctxt->regs->ax = ghcb->save.rax; in vc_handle_rdpmc()
1186 ctxt->regs->dx = ghcb->save.rdx; in vc_handle_rdpmc()
1192 struct es_em_ctxt *ctxt) in vc_handle_monitor() argument
1202 struct es_em_ctxt *ctxt) in vc_handle_mwait() argument
1209 struct es_em_ctxt *ctxt) in vc_handle_vmmcall() argument
1213 ghcb_set_rax(ghcb, ctxt->regs->ax); in vc_handle_vmmcall()
1214 ghcb_set_cpl(ghcb, user_mode(ctxt->regs) ? 3 : 0); in vc_handle_vmmcall()
1217 x86_platform.hyper.sev_es_hcall_prepare(ghcb, ctxt->regs); in vc_handle_vmmcall()
1219 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_VMMCALL, 0, 0); in vc_handle_vmmcall()
1226 ctxt->regs->ax = ghcb->save.rax; in vc_handle_vmmcall()
1234 !x86_platform.hyper.sev_es_hcall_finish(ghcb, ctxt->regs)) in vc_handle_vmmcall()
1241 struct es_em_ctxt *ctxt) in vc_handle_trap_ac() argument
1248 ctxt->fi.vector = X86_TRAP_AC; in vc_handle_trap_ac()
1249 ctxt->fi.error_code = 0; in vc_handle_trap_ac()
1253 static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, in vc_handle_exitcode() argument
1261 result = vc_handle_dr7_read(ghcb, ctxt); in vc_handle_exitcode()
1264 result = vc_handle_dr7_write(ghcb, ctxt); in vc_handle_exitcode()
1267 result = vc_handle_trap_ac(ghcb, ctxt); in vc_handle_exitcode()
1271 result = vc_handle_rdtsc(ghcb, ctxt, exit_code); in vc_handle_exitcode()
1274 result = vc_handle_rdpmc(ghcb, ctxt); in vc_handle_exitcode()
1281 result = vc_handle_cpuid(ghcb, ctxt); in vc_handle_exitcode()
1284 result = vc_handle_ioio(ghcb, ctxt); in vc_handle_exitcode()
1287 result = vc_handle_msr(ghcb, ctxt); in vc_handle_exitcode()
1290 result = vc_handle_vmmcall(ghcb, ctxt); in vc_handle_exitcode()
1293 result = vc_handle_wbinvd(ghcb, ctxt); in vc_handle_exitcode()
1296 result = vc_handle_monitor(ghcb, ctxt); in vc_handle_exitcode()
1299 result = vc_handle_mwait(ghcb, ctxt); in vc_handle_exitcode()
1302 result = vc_handle_mmio(ghcb, ctxt); in vc_handle_exitcode()
1314 static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) in vc_forward_exception() argument
1316 long error_code = ctxt->fi.error_code; in vc_forward_exception()
1317 int trapnr = ctxt->fi.vector; in vc_forward_exception()
1319 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_forward_exception()
1323 exc_general_protection(ctxt->regs, error_code); in vc_forward_exception()
1326 exc_invalid_op(ctxt->regs); in vc_forward_exception()
1329 write_cr2(ctxt->fi.cr2); in vc_forward_exception()
1330 exc_page_fault(ctxt->regs, error_code); in vc_forward_exception()
1333 exc_alignment_check(ctxt->regs, error_code); in vc_forward_exception()
1351 struct es_em_ctxt ctxt; in vc_raw_handle_exception() local
1359 result = vc_init_em_ctxt(&ctxt, regs, error_code); in vc_raw_handle_exception()
1362 result = vc_handle_exitcode(&ctxt, ghcb, error_code); in vc_raw_handle_exception()
1369 vc_finish_insn(&ctxt); in vc_raw_handle_exception()
1387 vc_forward_exception(&ctxt); in vc_raw_handle_exception()
1494 struct es_em_ctxt ctxt; in handle_vc_boot_ghcb() local
1503 result = vc_init_em_ctxt(&ctxt, regs, exit_code); in handle_vc_boot_ghcb()
1505 result = vc_handle_exitcode(&ctxt, boot_ghcb, exit_code); in handle_vc_boot_ghcb()
1510 vc_finish_insn(&ctxt); in handle_vc_boot_ghcb()
1525 vc_early_forward_exception(&ctxt); in handle_vc_boot_ghcb()