Lines Matching refs:ctxt

260 static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt,  in vc_fetch_insn_kernel()  argument
263 return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE); in vc_fetch_insn_kernel()
266 static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt) in __vc_decode_user_insn() argument
271 insn_bytes = insn_fetch_from_user_inatomic(ctxt->regs, buffer); in __vc_decode_user_insn()
274 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_user_insn()
275 ctxt->fi.error_code = X86_PF_INSTR | X86_PF_USER; in __vc_decode_user_insn()
276 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_user_insn()
280 ctxt->fi.vector = X86_TRAP_GP; in __vc_decode_user_insn()
281 ctxt->fi.error_code = 0; in __vc_decode_user_insn()
282 ctxt->fi.cr2 = 0; in __vc_decode_user_insn()
286 if (!insn_decode_from_regs(&ctxt->insn, ctxt->regs, buffer, insn_bytes)) in __vc_decode_user_insn()
289 if (ctxt->insn.immediate.got) in __vc_decode_user_insn()
295 static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) in __vc_decode_kern_insn() argument
300 res = vc_fetch_insn_kernel(ctxt, buffer); in __vc_decode_kern_insn()
302 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_kern_insn()
303 ctxt->fi.error_code = X86_PF_INSTR; in __vc_decode_kern_insn()
304 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_kern_insn()
308 ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64); in __vc_decode_kern_insn()
315 static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) in vc_decode_insn() argument
317 if (user_mode(ctxt->regs)) in vc_decode_insn()
318 return __vc_decode_user_insn(ctxt); in vc_decode_insn()
320 return __vc_decode_kern_insn(ctxt); in vc_decode_insn()
323 static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, in vc_write_mem() argument
392 if (user_mode(ctxt->regs)) in vc_write_mem()
395 ctxt->fi.vector = X86_TRAP_PF; in vc_write_mem()
396 ctxt->fi.error_code = error_code; in vc_write_mem()
397 ctxt->fi.cr2 = (unsigned long)dst; in vc_write_mem()
402 static enum es_result vc_read_mem(struct es_em_ctxt *ctxt, in vc_read_mem() argument
470 if (user_mode(ctxt->regs)) in vc_read_mem()
473 ctxt->fi.vector = X86_TRAP_PF; in vc_read_mem()
474 ctxt->fi.error_code = error_code; in vc_read_mem()
475 ctxt->fi.cr2 = (unsigned long)src; in vc_read_mem()
480 static enum es_result vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_slow_virt_to_phys() argument
493 ctxt->fi.vector = X86_TRAP_PF; in vc_slow_virt_to_phys()
494 ctxt->fi.cr2 = vaddr; in vc_slow_virt_to_phys()
495 ctxt->fi.error_code = 0; in vc_slow_virt_to_phys()
497 if (user_mode(ctxt->regs)) in vc_slow_virt_to_phys()
498 ctxt->fi.error_code |= X86_PF_USER; in vc_slow_virt_to_phys()
762 struct es_em_ctxt ctxt; in vmgexit_psc() local
801 ret = sev_es_ghcb_hv_call(ghcb, &ctxt, SVM_VMGEXIT_PSC, 0, 0); in vmgexit_psc()
1212 static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_msr() argument
1214 struct pt_regs *regs = ctxt->regs; in vc_handle_msr()
1219 exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; in vc_handle_msr()
1227 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, exit_info_1, 0); in vc_handle_msr()
1411 static void __init vc_early_forward_exception(struct es_em_ctxt *ctxt) in vc_early_forward_exception() argument
1413 int trapnr = ctxt->fi.vector; in vc_early_forward_exception()
1416 native_write_cr2(ctxt->fi.cr2); in vc_early_forward_exception()
1418 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_early_forward_exception()
1419 do_early_exception(ctxt->regs, trapnr); in vc_early_forward_exception()
1422 static long *vc_insn_get_rm(struct es_em_ctxt *ctxt) in vc_insn_get_rm() argument
1427 reg_array = (long *)ctxt->regs; in vc_insn_get_rm()
1428 offset = insn_get_modrm_rm_off(&ctxt->insn, ctxt->regs); in vc_insn_get_rm()
1437 static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_do_mmio() argument
1446 ref = insn_get_addr_ref(&ctxt->insn, ctxt->regs); in vc_do_mmio()
1452 res = vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr); in vc_do_mmio()
1455 ctxt->fi.error_code |= X86_PF_WRITE; in vc_do_mmio()
1466 return sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, exit_info_1, exit_info_2); in vc_do_mmio()
1488 static enum es_result vc_handle_mmio_movs(struct es_em_ctxt *ctxt, in vc_handle_mmio_movs() argument
1498 ds_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_DS); in vc_handle_mmio_movs()
1499 es_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_ES); in vc_handle_mmio_movs()
1502 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_mmio_movs()
1503 ctxt->fi.error_code = 0; in vc_handle_mmio_movs()
1507 src = ds_base + (unsigned char *)ctxt->regs->si; in vc_handle_mmio_movs()
1508 dst = es_base + (unsigned char *)ctxt->regs->di; in vc_handle_mmio_movs()
1510 ret = vc_read_mem(ctxt, src, buffer, bytes); in vc_handle_mmio_movs()
1514 ret = vc_write_mem(ctxt, dst, buffer, bytes); in vc_handle_mmio_movs()
1518 if (ctxt->regs->flags & X86_EFLAGS_DF) in vc_handle_mmio_movs()
1523 ctxt->regs->si += off; in vc_handle_mmio_movs()
1524 ctxt->regs->di += off; in vc_handle_mmio_movs()
1526 rep = insn_has_rep_prefix(&ctxt->insn); in vc_handle_mmio_movs()
1528 ctxt->regs->cx -= 1; in vc_handle_mmio_movs()
1530 if (!rep || ctxt->regs->cx == 0) in vc_handle_mmio_movs()
1536 static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_mmio() argument
1538 struct insn *insn = &ctxt->insn; in vc_handle_mmio()
1550 reg_data = insn_get_modrm_reg_ptr(insn, ctxt->regs); in vc_handle_mmio()
1558 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1562 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1565 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1576 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1585 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1604 ret = vc_handle_mmio_movs(ctxt, bytes); in vc_handle_mmio()
1615 struct es_em_ctxt *ctxt) in vc_handle_dr7_write() argument
1618 long val, *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_write()
1628 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_dr7_write()
1629 ctxt->fi.error_code = 0; in vc_handle_dr7_write()
1642 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WRITE_DR7, 0, 0); in vc_handle_dr7_write()
1653 struct es_em_ctxt *ctxt) in vc_handle_dr7_read() argument
1656 long *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_read()
1670 struct es_em_ctxt *ctxt) in vc_handle_wbinvd() argument
1672 return sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WBINVD, 0, 0); in vc_handle_wbinvd()
1675 static enum es_result vc_handle_rdpmc(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_rdpmc() argument
1679 ghcb_set_rcx(ghcb, ctxt->regs->cx); in vc_handle_rdpmc()
1681 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_RDPMC, 0, 0); in vc_handle_rdpmc()
1688 ctxt->regs->ax = ghcb->save.rax; in vc_handle_rdpmc()
1689 ctxt->regs->dx = ghcb->save.rdx; in vc_handle_rdpmc()
1695 struct es_em_ctxt *ctxt) in vc_handle_monitor() argument
1705 struct es_em_ctxt *ctxt) in vc_handle_mwait() argument
1712 struct es_em_ctxt *ctxt) in vc_handle_vmmcall() argument
1716 ghcb_set_rax(ghcb, ctxt->regs->ax); in vc_handle_vmmcall()
1717 ghcb_set_cpl(ghcb, user_mode(ctxt->regs) ? 3 : 0); in vc_handle_vmmcall()
1720 x86_platform.hyper.sev_es_hcall_prepare(ghcb, ctxt->regs); in vc_handle_vmmcall()
1722 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_VMMCALL, 0, 0); in vc_handle_vmmcall()
1729 ctxt->regs->ax = ghcb->save.rax; in vc_handle_vmmcall()
1737 !x86_platform.hyper.sev_es_hcall_finish(ghcb, ctxt->regs)) in vc_handle_vmmcall()
1744 struct es_em_ctxt *ctxt) in vc_handle_trap_ac() argument
1751 ctxt->fi.vector = X86_TRAP_AC; in vc_handle_trap_ac()
1752 ctxt->fi.error_code = 0; in vc_handle_trap_ac()
1756 static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, in vc_handle_exitcode() argument
1764 result = vc_handle_dr7_read(ghcb, ctxt); in vc_handle_exitcode()
1767 result = vc_handle_dr7_write(ghcb, ctxt); in vc_handle_exitcode()
1770 result = vc_handle_trap_ac(ghcb, ctxt); in vc_handle_exitcode()
1774 result = vc_handle_rdtsc(ghcb, ctxt, exit_code); in vc_handle_exitcode()
1777 result = vc_handle_rdpmc(ghcb, ctxt); in vc_handle_exitcode()
1784 result = vc_handle_cpuid(ghcb, ctxt); in vc_handle_exitcode()
1787 result = vc_handle_ioio(ghcb, ctxt); in vc_handle_exitcode()
1790 result = vc_handle_msr(ghcb, ctxt); in vc_handle_exitcode()
1793 result = vc_handle_vmmcall(ghcb, ctxt); in vc_handle_exitcode()
1796 result = vc_handle_wbinvd(ghcb, ctxt); in vc_handle_exitcode()
1799 result = vc_handle_monitor(ghcb, ctxt); in vc_handle_exitcode()
1802 result = vc_handle_mwait(ghcb, ctxt); in vc_handle_exitcode()
1805 result = vc_handle_mmio(ghcb, ctxt); in vc_handle_exitcode()
1817 static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) in vc_forward_exception() argument
1819 long error_code = ctxt->fi.error_code; in vc_forward_exception()
1820 int trapnr = ctxt->fi.vector; in vc_forward_exception()
1822 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_forward_exception()
1826 exc_general_protection(ctxt->regs, error_code); in vc_forward_exception()
1829 exc_invalid_op(ctxt->regs); in vc_forward_exception()
1832 write_cr2(ctxt->fi.cr2); in vc_forward_exception()
1833 exc_page_fault(ctxt->regs, error_code); in vc_forward_exception()
1836 exc_alignment_check(ctxt->regs, error_code); in vc_forward_exception()
1867 struct es_em_ctxt ctxt; in vc_raw_handle_exception() local
1875 result = vc_init_em_ctxt(&ctxt, regs, error_code); in vc_raw_handle_exception()
1878 result = vc_handle_exitcode(&ctxt, ghcb, error_code); in vc_raw_handle_exception()
1885 vc_finish_insn(&ctxt); in vc_raw_handle_exception()
1903 vc_forward_exception(&ctxt); in vc_raw_handle_exception()
2010 struct es_em_ctxt ctxt; in handle_vc_boot_ghcb() local
2015 result = vc_init_em_ctxt(&ctxt, regs, exit_code); in handle_vc_boot_ghcb()
2017 result = vc_handle_exitcode(&ctxt, boot_ghcb, exit_code); in handle_vc_boot_ghcb()
2022 vc_finish_insn(&ctxt); in handle_vc_boot_ghcb()
2037 vc_early_forward_exception(&ctxt); in handle_vc_boot_ghcb()
2181 struct es_em_ctxt ctxt; in snp_issue_guest_request() local
2211 ret = sev_es_ghcb_hv_call(ghcb, &ctxt, exit_code, input->req_gpa, input->resp_gpa); in snp_issue_guest_request()