Lines Matching defs:ctxt
102 #define emul_to_vcpu(ctxt) \
103 ((struct kvm_vcpu *)(ctxt)->vcpu)
353 static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt);
7377 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
7381 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7422 static int emulator_read_std(struct x86_emulate_ctxt *ctxt,
7426 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7467 static int emulator_write_std(struct x86_emulate_ctxt *ctxt, gva_t addr, void *val,
7471 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7665 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
7674 if (ctxt->gpa_available && emulator_can_use_gpa(ctxt) &&
7675 (addr & ~PAGE_MASK) == (ctxt->gpa_val & ~PAGE_MASK)) {
7676 gpa = ctxt->gpa_val;
7706 static int emulator_read_write(struct x86_emulate_ctxt *ctxt,
7712 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7733 if (ctxt->mode != X86EMUL_MODE_PROT64)
7760 static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
7766 return emulator_read_write(ctxt, addr, val, bytes,
7770 static int emulator_write_emulated(struct x86_emulate_ctxt *ctxt,
7776 return emulator_read_write(ctxt, addr, (void *)val, bytes,
7783 static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
7790 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7863 return emulator_write_emulated(ctxt, addr, new, bytes, exception);
7936 static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
7940 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
7964 static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
7968 return emulator_pio_out(emul_to_vcpu(ctxt), size, port, val, count);
7976 static void emulator_invlpg(struct x86_emulate_ctxt *ctxt, ulong address)
7978 kvm_mmu_invlpg(emul_to_vcpu(ctxt), address);
8008 static void emulator_wbinvd(struct x86_emulate_ctxt *ctxt)
8010 kvm_emulate_wbinvd_noskip(emul_to_vcpu(ctxt));
8013 static void emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr,
8016 kvm_get_dr(emul_to_vcpu(ctxt), dr, dest);
8019 static int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,
8023 return kvm_set_dr(emul_to_vcpu(ctxt), dr, value);
8031 static unsigned long emulator_get_cr(struct x86_emulate_ctxt *ctxt, int cr)
8033 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8060 static int emulator_set_cr(struct x86_emulate_ctxt *ctxt, int cr, ulong val)
8062 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8089 static int emulator_get_cpl(struct x86_emulate_ctxt *ctxt)
8091 return static_call(kvm_x86_get_cpl)(emul_to_vcpu(ctxt));
8094 static void emulator_get_gdt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
8096 static_call(kvm_x86_get_gdt)(emul_to_vcpu(ctxt), dt);
8099 static void emulator_get_idt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
8101 static_call(kvm_x86_get_idt)(emul_to_vcpu(ctxt), dt);
8104 static void emulator_set_gdt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
8106 static_call(kvm_x86_set_gdt)(emul_to_vcpu(ctxt), dt);
8109 static void emulator_set_idt(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt)
8111 static_call(kvm_x86_set_idt)(emul_to_vcpu(ctxt), dt);
8115 struct x86_emulate_ctxt *ctxt, int seg)
8117 return get_segment_base(emul_to_vcpu(ctxt), seg);
8120 static bool emulator_get_segment(struct x86_emulate_ctxt *ctxt, u16 *selector,
8126 kvm_get_segment(emul_to_vcpu(ctxt), &var, seg);
8156 static void emulator_set_segment(struct x86_emulate_ctxt *ctxt, u16 selector,
8160 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8186 static int emulator_get_msr_with_filter(struct x86_emulate_ctxt *ctxt,
8189 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8209 static int emulator_set_msr_with_filter(struct x86_emulate_ctxt *ctxt,
8212 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8232 static int emulator_get_msr(struct x86_emulate_ctxt *ctxt,
8235 return kvm_get_msr(emul_to_vcpu(ctxt), msr_index, pdata);
8238 static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt,
8241 if (kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc))
8246 static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt,
8249 return kvm_pmu_rdpmc(emul_to_vcpu(ctxt), pmc, pdata);
8252 static void emulator_halt(struct x86_emulate_ctxt *ctxt)
8254 emul_to_vcpu(ctxt)->arch.halt_request = 1;
8257 static int emulator_intercept(struct x86_emulate_ctxt *ctxt,
8261 return static_call(kvm_x86_check_intercept)(emul_to_vcpu(ctxt), info, stage,
8262 &ctxt->exception);
8265 static bool emulator_get_cpuid(struct x86_emulate_ctxt *ctxt,
8269 return kvm_cpuid(emul_to_vcpu(ctxt), eax, ebx, ecx, edx, exact_only);
8272 static bool emulator_guest_has_movbe(struct x86_emulate_ctxt *ctxt)
8274 return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_MOVBE);
8277 static bool emulator_guest_has_fxsr(struct x86_emulate_ctxt *ctxt)
8279 return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_FXSR);
8282 static bool emulator_guest_has_rdpid(struct x86_emulate_ctxt *ctxt)
8284 return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_RDPID);
8287 static ulong emulator_read_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg)
8289 return kvm_register_read_raw(emul_to_vcpu(ctxt), reg);
8292 static void emulator_write_gpr(struct x86_emulate_ctxt *ctxt, unsigned reg, ulong val)
8294 kvm_register_write_raw(emul_to_vcpu(ctxt), reg, val);
8297 static void emulator_set_nmi_mask(struct x86_emulate_ctxt *ctxt, bool masked)
8299 static_call(kvm_x86_set_nmi_mask)(emul_to_vcpu(ctxt), masked);
8302 static bool emulator_is_smm(struct x86_emulate_ctxt *ctxt)
8304 return is_smm(emul_to_vcpu(ctxt));
8307 static bool emulator_is_guest_mode(struct x86_emulate_ctxt *ctxt)
8309 return is_guest_mode(emul_to_vcpu(ctxt));
8313 static int emulator_leave_smm(struct x86_emulate_ctxt *ctxt)
8320 static void emulator_triple_fault(struct x86_emulate_ctxt *ctxt)
8322 kvm_make_request(KVM_REQ_TRIPLE_FAULT, emul_to_vcpu(ctxt));
8325 static int emulator_set_xcr(struct x86_emulate_ctxt *ctxt, u32 index, u64 xcr)
8327 return __kvm_set_xcr(emul_to_vcpu(ctxt), index, xcr);
8330 static void emulator_vm_bugged(struct x86_emulate_ctxt *ctxt)
8332 struct kvm *kvm = emul_to_vcpu(ctxt)->kvm;
8405 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8407 if (ctxt->exception.vector == PF_VECTOR)
8408 kvm_inject_emulated_page_fault(vcpu, &ctxt->exception);
8409 else if (ctxt->exception.error_code_valid)
8410 kvm_queue_exception_e(vcpu, ctxt->exception.vector,
8411 ctxt->exception.error_code);
8413 kvm_queue_exception(vcpu, ctxt->exception.vector);
8418 struct x86_emulate_ctxt *ctxt;
8420 ctxt = kmem_cache_zalloc(x86_emulator_cache, GFP_KERNEL_ACCOUNT);
8421 if (!ctxt) {
8426 ctxt->vcpu = vcpu;
8427 ctxt->ops = &emulate_ops;
8428 vcpu->arch.emulate_ctxt = ctxt;
8430 return ctxt;
8435 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8440 ctxt->gpa_available = false;
8441 ctxt->eflags = kvm_get_rflags(vcpu);
8442 ctxt->tf = (ctxt->eflags & X86_EFLAGS_TF) != 0;
8444 ctxt->eip = kvm_rip_read(vcpu);
8445 ctxt->mode = (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL :
8446 (ctxt->eflags & X86_EFLAGS_VM) ? X86EMUL_MODE_VM86 :
8450 ctxt->interruptibility = 0;
8451 ctxt->have_exception = false;
8452 ctxt->exception.vector = -1;
8453 ctxt->perm_ok = false;
8455 init_decode_cache(ctxt);
8461 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8466 ctxt->op_bytes = 2;
8467 ctxt->ad_bytes = 2;
8468 ctxt->_eip = ctxt->eip + inc_eip;
8469 ret = emulate_int_real(ctxt, irq);
8474 ctxt->eip = ctxt->_eip;
8475 kvm_rip_write(vcpu, ctxt->eip);
8476 kvm_set_rflags(vcpu, ctxt->eflags);
8534 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8536 prepare_emulation_failure_exit(vcpu, NULL, 0, ctxt->fetch.data,
8537 ctxt->fetch.end - ctxt->fetch.data);
8655 static bool retry_instruction(struct x86_emulate_ctxt *ctxt,
8658 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
8686 if (x86_page_table_writing_insn(ctxt))
8689 if (ctxt->eip == last_retry_eip && last_retry_addr == cr2_or_gpa)
8692 vcpu->arch.last_retry_eip = ctxt->eip;
8836 static bool is_vmware_backdoor_opcode(struct x86_emulate_ctxt *ctxt)
8838 switch (ctxt->opcode_len) {
8840 switch (ctxt->b) {
8857 switch (ctxt->b) {
8880 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8885 r = x86_decode_insn(ctxt, insn, insn_len, emulation_type);
8898 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
8929 if (ctxt->have_exception &&
8935 WARN_ON_ONCE(ctxt->exception.vector == UD_VECTOR ||
8936 exception_type(ctxt->exception.vector) == EXCPT_TRAP);
8945 !is_vmware_backdoor_opcode(ctxt)) {
8957 if (ctxt->mode != X86EMUL_MODE_PROT64)
8958 ctxt->eip = (u32)ctxt->_eip;
8960 ctxt->eip = ctxt->_eip;
8967 kvm_rip_write(vcpu, ctxt->eip);
8968 if (ctxt->eflags & X86_EFLAGS_RF)
8969 kvm_set_rflags(vcpu, ctxt->eflags & ~X86_EFLAGS_RF);
8973 if (retry_instruction(ctxt, cr2_or_gpa, emulation_type))
8980 emulator_invalidate_register_cache(ctxt);
8986 ctxt->exception.address = cr2_or_gpa;
8990 ctxt->gpa_available = true;
8991 ctxt->gpa_val = cr2_or_gpa;
8995 ctxt->exception.address = 0;
8998 r = x86_emulate_insn(ctxt);
9010 if (ctxt->have_exception) {
9042 toggle_interruptibility(vcpu, ctxt->interruptibility);
9050 if (!ctxt->have_exception ||
9051 exception_type(ctxt->exception.vector) == EXCPT_TRAP) {
9053 if (ctxt->is_branch)
9055 kvm_rip_write(vcpu, ctxt->eip);
9056 if (r && (ctxt->tf || (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)))
9059 __kvm_set_rflags(vcpu, ctxt->eflags);
9068 if (unlikely((ctxt->eflags & ~rflags) & X86_EFLAGS_IF))
9938 static int emulator_fix_hypercall(struct x86_emulate_ctxt *ctxt)
9940 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
9949 ctxt->exception.error_code_valid = false;
9950 ctxt->exception.vector = UD_VECTOR;
9951 ctxt->have_exception = true;
9957 return emulator_write_emulated(ctxt, rip, instruction, 3,
9958 &ctxt->exception);
11467 struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
11472 ret = emulator_task_switch(ctxt, tss_selector, idt_index, reason,
11481 kvm_rip_write(vcpu, ctxt->eip);
11482 kvm_set_rflags(vcpu, ctxt->eflags);