Lines Matching refs:ctxt
274 static int vc_fetch_insn_kernel(struct es_em_ctxt *ctxt, in vc_fetch_insn_kernel() argument
277 return copy_from_kernel_nofault(buffer, (unsigned char *)ctxt->regs->ip, MAX_INSN_SIZE); in vc_fetch_insn_kernel()
280 static enum es_result __vc_decode_user_insn(struct es_em_ctxt *ctxt) in __vc_decode_user_insn() argument
285 insn_bytes = insn_fetch_from_user_inatomic(ctxt->regs, buffer); in __vc_decode_user_insn()
288 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_user_insn()
289 ctxt->fi.error_code = X86_PF_INSTR | X86_PF_USER; in __vc_decode_user_insn()
290 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_user_insn()
294 ctxt->fi.vector = X86_TRAP_GP; in __vc_decode_user_insn()
295 ctxt->fi.error_code = 0; in __vc_decode_user_insn()
296 ctxt->fi.cr2 = 0; in __vc_decode_user_insn()
300 if (!insn_decode_from_regs(&ctxt->insn, ctxt->regs, buffer, insn_bytes)) in __vc_decode_user_insn()
303 if (ctxt->insn.immediate.got) in __vc_decode_user_insn()
309 static enum es_result __vc_decode_kern_insn(struct es_em_ctxt *ctxt) in __vc_decode_kern_insn() argument
314 res = vc_fetch_insn_kernel(ctxt, buffer); in __vc_decode_kern_insn()
316 ctxt->fi.vector = X86_TRAP_PF; in __vc_decode_kern_insn()
317 ctxt->fi.error_code = X86_PF_INSTR; in __vc_decode_kern_insn()
318 ctxt->fi.cr2 = ctxt->regs->ip; in __vc_decode_kern_insn()
322 ret = insn_decode(&ctxt->insn, buffer, MAX_INSN_SIZE, INSN_MODE_64); in __vc_decode_kern_insn()
329 static enum es_result vc_decode_insn(struct es_em_ctxt *ctxt) in vc_decode_insn() argument
331 if (user_mode(ctxt->regs)) in vc_decode_insn()
332 return __vc_decode_user_insn(ctxt); in vc_decode_insn()
334 return __vc_decode_kern_insn(ctxt); in vc_decode_insn()
337 static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, in vc_write_mem() argument
406 if (user_mode(ctxt->regs)) in vc_write_mem()
409 ctxt->fi.vector = X86_TRAP_PF; in vc_write_mem()
410 ctxt->fi.error_code = error_code; in vc_write_mem()
411 ctxt->fi.cr2 = (unsigned long)dst; in vc_write_mem()
416 static enum es_result vc_read_mem(struct es_em_ctxt *ctxt, in vc_read_mem() argument
484 if (user_mode(ctxt->regs)) in vc_read_mem()
487 ctxt->fi.vector = X86_TRAP_PF; in vc_read_mem()
488 ctxt->fi.error_code = error_code; in vc_read_mem()
489 ctxt->fi.cr2 = (unsigned long)src; in vc_read_mem()
494 static enum es_result vc_slow_virt_to_phys(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_slow_virt_to_phys() argument
507 ctxt->fi.vector = X86_TRAP_PF; in vc_slow_virt_to_phys()
508 ctxt->fi.cr2 = vaddr; in vc_slow_virt_to_phys()
509 ctxt->fi.error_code = 0; in vc_slow_virt_to_phys()
511 if (user_mode(ctxt->regs)) in vc_slow_virt_to_phys()
512 ctxt->fi.error_code |= X86_PF_USER; in vc_slow_virt_to_phys()
529 static enum es_result vc_ioio_check(struct es_em_ctxt *ctxt, u16 port, size_t size) in vc_ioio_check() argument
533 if (user_mode(ctxt->regs)) { in vc_ioio_check()
550 ctxt->fi.vector = X86_TRAP_GP; in vc_ioio_check()
551 ctxt->fi.error_code = 0; in vc_ioio_check()
1184 static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_msr() argument
1186 struct pt_regs *regs = ctxt->regs; in vc_handle_msr()
1191 exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; in vc_handle_msr()
1199 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_MSR, exit_info_1, 0); in vc_handle_msr()
1385 static void __init vc_early_forward_exception(struct es_em_ctxt *ctxt) in vc_early_forward_exception() argument
1387 int trapnr = ctxt->fi.vector; in vc_early_forward_exception()
1390 native_write_cr2(ctxt->fi.cr2); in vc_early_forward_exception()
1392 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_early_forward_exception()
1393 do_early_exception(ctxt->regs, trapnr); in vc_early_forward_exception()
1396 static long *vc_insn_get_rm(struct es_em_ctxt *ctxt) in vc_insn_get_rm() argument
1401 reg_array = (long *)ctxt->regs; in vc_insn_get_rm()
1402 offset = insn_get_modrm_rm_off(&ctxt->insn, ctxt->regs); in vc_insn_get_rm()
1411 static enum es_result vc_do_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt, in vc_do_mmio() argument
1420 ref = insn_get_addr_ref(&ctxt->insn, ctxt->regs); in vc_do_mmio()
1426 res = vc_slow_virt_to_phys(ghcb, ctxt, (unsigned long)ref, &paddr); in vc_do_mmio()
1429 ctxt->fi.error_code |= X86_PF_WRITE; in vc_do_mmio()
1440 return sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, exit_info_1, exit_info_2); in vc_do_mmio()
1462 static enum es_result vc_handle_mmio_movs(struct es_em_ctxt *ctxt, in vc_handle_mmio_movs() argument
1472 ds_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_DS); in vc_handle_mmio_movs()
1473 es_base = insn_get_seg_base(ctxt->regs, INAT_SEG_REG_ES); in vc_handle_mmio_movs()
1476 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_mmio_movs()
1477 ctxt->fi.error_code = 0; in vc_handle_mmio_movs()
1481 src = ds_base + (unsigned char *)ctxt->regs->si; in vc_handle_mmio_movs()
1482 dst = es_base + (unsigned char *)ctxt->regs->di; in vc_handle_mmio_movs()
1484 ret = vc_read_mem(ctxt, src, buffer, bytes); in vc_handle_mmio_movs()
1488 ret = vc_write_mem(ctxt, dst, buffer, bytes); in vc_handle_mmio_movs()
1492 if (ctxt->regs->flags & X86_EFLAGS_DF) in vc_handle_mmio_movs()
1497 ctxt->regs->si += off; in vc_handle_mmio_movs()
1498 ctxt->regs->di += off; in vc_handle_mmio_movs()
1500 rep = insn_has_rep_prefix(&ctxt->insn); in vc_handle_mmio_movs()
1502 ctxt->regs->cx -= 1; in vc_handle_mmio_movs()
1504 if (!rep || ctxt->regs->cx == 0) in vc_handle_mmio_movs()
1510 static enum es_result vc_handle_mmio(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_mmio() argument
1512 struct insn *insn = &ctxt->insn; in vc_handle_mmio()
1524 reg_data = insn_get_modrm_reg_ptr(insn, ctxt->regs); in vc_handle_mmio()
1529 if (user_mode(ctxt->regs)) in vc_handle_mmio()
1535 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1539 ret = vc_do_mmio(ghcb, ctxt, bytes, false); in vc_handle_mmio()
1542 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1553 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1562 ret = vc_do_mmio(ghcb, ctxt, bytes, true); in vc_handle_mmio()
1581 ret = vc_handle_mmio_movs(ctxt, bytes); in vc_handle_mmio()
1592 struct es_em_ctxt *ctxt) in vc_handle_dr7_write() argument
1595 long val, *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_write()
1608 ctxt->fi.vector = X86_TRAP_GP; in vc_handle_dr7_write()
1609 ctxt->fi.error_code = 0; in vc_handle_dr7_write()
1622 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WRITE_DR7, 0, 0); in vc_handle_dr7_write()
1633 struct es_em_ctxt *ctxt) in vc_handle_dr7_read() argument
1636 long *reg = vc_insn_get_rm(ctxt); in vc_handle_dr7_read()
1653 struct es_em_ctxt *ctxt) in vc_handle_wbinvd() argument
1655 return sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WBINVD, 0, 0); in vc_handle_wbinvd()
1658 static enum es_result vc_handle_rdpmc(struct ghcb *ghcb, struct es_em_ctxt *ctxt) in vc_handle_rdpmc() argument
1662 ghcb_set_rcx(ghcb, ctxt->regs->cx); in vc_handle_rdpmc()
1664 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_RDPMC, 0, 0); in vc_handle_rdpmc()
1671 ctxt->regs->ax = ghcb->save.rax; in vc_handle_rdpmc()
1672 ctxt->regs->dx = ghcb->save.rdx; in vc_handle_rdpmc()
1678 struct es_em_ctxt *ctxt) in vc_handle_monitor() argument
1688 struct es_em_ctxt *ctxt) in vc_handle_mwait() argument
1695 struct es_em_ctxt *ctxt) in vc_handle_vmmcall() argument
1699 ghcb_set_rax(ghcb, ctxt->regs->ax); in vc_handle_vmmcall()
1700 ghcb_set_cpl(ghcb, user_mode(ctxt->regs) ? 3 : 0); in vc_handle_vmmcall()
1703 x86_platform.hyper.sev_es_hcall_prepare(ghcb, ctxt->regs); in vc_handle_vmmcall()
1705 ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_VMMCALL, 0, 0); in vc_handle_vmmcall()
1712 ctxt->regs->ax = ghcb->save.rax; in vc_handle_vmmcall()
1720 !x86_platform.hyper.sev_es_hcall_finish(ghcb, ctxt->regs)) in vc_handle_vmmcall()
1727 struct es_em_ctxt *ctxt) in vc_handle_trap_ac() argument
1734 ctxt->fi.vector = X86_TRAP_AC; in vc_handle_trap_ac()
1735 ctxt->fi.error_code = 0; in vc_handle_trap_ac()
1739 static enum es_result vc_handle_exitcode(struct es_em_ctxt *ctxt, in vc_handle_exitcode() argument
1747 result = vc_handle_dr7_read(ghcb, ctxt); in vc_handle_exitcode()
1750 result = vc_handle_dr7_write(ghcb, ctxt); in vc_handle_exitcode()
1753 result = vc_handle_trap_ac(ghcb, ctxt); in vc_handle_exitcode()
1757 result = vc_handle_rdtsc(ghcb, ctxt, exit_code); in vc_handle_exitcode()
1760 result = vc_handle_rdpmc(ghcb, ctxt); in vc_handle_exitcode()
1767 result = vc_handle_cpuid(ghcb, ctxt); in vc_handle_exitcode()
1770 result = vc_handle_ioio(ghcb, ctxt); in vc_handle_exitcode()
1773 result = vc_handle_msr(ghcb, ctxt); in vc_handle_exitcode()
1776 result = vc_handle_vmmcall(ghcb, ctxt); in vc_handle_exitcode()
1779 result = vc_handle_wbinvd(ghcb, ctxt); in vc_handle_exitcode()
1782 result = vc_handle_monitor(ghcb, ctxt); in vc_handle_exitcode()
1785 result = vc_handle_mwait(ghcb, ctxt); in vc_handle_exitcode()
1788 result = vc_handle_mmio(ghcb, ctxt); in vc_handle_exitcode()
1800 static __always_inline void vc_forward_exception(struct es_em_ctxt *ctxt) in vc_forward_exception() argument
1802 long error_code = ctxt->fi.error_code; in vc_forward_exception()
1803 int trapnr = ctxt->fi.vector; in vc_forward_exception()
1805 ctxt->regs->orig_ax = ctxt->fi.error_code; in vc_forward_exception()
1809 exc_general_protection(ctxt->regs, error_code); in vc_forward_exception()
1812 exc_invalid_op(ctxt->regs); in vc_forward_exception()
1815 write_cr2(ctxt->fi.cr2); in vc_forward_exception()
1816 exc_page_fault(ctxt->regs, error_code); in vc_forward_exception()
1819 exc_alignment_check(ctxt->regs, error_code); in vc_forward_exception()
1850 struct es_em_ctxt ctxt; in vc_raw_handle_exception() local
1858 result = vc_init_em_ctxt(&ctxt, regs, error_code); in vc_raw_handle_exception()
1861 result = vc_handle_exitcode(&ctxt, ghcb, error_code); in vc_raw_handle_exception()
1868 vc_finish_insn(&ctxt); in vc_raw_handle_exception()
1886 vc_forward_exception(&ctxt); in vc_raw_handle_exception()
1993 struct es_em_ctxt ctxt; in handle_vc_boot_ghcb() local
1998 result = vc_init_em_ctxt(&ctxt, regs, exit_code); in handle_vc_boot_ghcb()
2000 result = vc_handle_exitcode(&ctxt, boot_ghcb, exit_code); in handle_vc_boot_ghcb()
2005 vc_finish_insn(&ctxt); in handle_vc_boot_ghcb()
2020 vc_early_forward_exception(&ctxt); in handle_vc_boot_ghcb()
2175 struct es_em_ctxt ctxt; in snp_issue_guest_request() local
2201 ret = sev_es_ghcb_hv_call(ghcb, &ctxt, exit_code, input->req_gpa, input->resp_gpa); in snp_issue_guest_request()