x86.c (5603effb8295ada8419408d038a34ca89d658229) x86.c (6dcf7316e05eccded11fc640813c8a8879f271a6)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * derived from drivers/kvm/kvm_main.c
6 *
7 * Copyright (C) 2006 Qumranet, Inc.
8 * Copyright (C) 2008 Qumranet, Inc.

--- 4418 unchanged lines hidden (view full) ---

4427 case KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM:
4428 case KVM_CAP_SREGS2:
4429 case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
4430 case KVM_CAP_VCPU_ATTRIBUTES:
4431 case KVM_CAP_SYS_ATTRIBUTES:
4432 case KVM_CAP_VAPIC:
4433 case KVM_CAP_ENABLE_CAP:
4434 case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES:
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * derived from drivers/kvm/kvm_main.c
6 *
7 * Copyright (C) 2006 Qumranet, Inc.
8 * Copyright (C) 2008 Qumranet, Inc.

--- 4418 unchanged lines hidden (view full) ---

4427 case KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM:
4428 case KVM_CAP_SREGS2:
4429 case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
4430 case KVM_CAP_VCPU_ATTRIBUTES:
4431 case KVM_CAP_SYS_ATTRIBUTES:
4432 case KVM_CAP_VAPIC:
4433 case KVM_CAP_ENABLE_CAP:
4434 case KVM_CAP_VM_DISABLE_NX_HUGE_PAGES:
4435 case KVM_CAP_IRQFD_RESAMPLE:
4436 r = 1;
4437 break;
4438 case KVM_CAP_EXIT_HYPERCALL:
4439 r = KVM_EXIT_HYPERCALL_VALID_MASK;
4440 break;
4441 case KVM_CAP_SET_GUEST_DEBUG2:
4442 return KVM_GUESTDBG_VALID_MASK;
4443#ifdef CONFIG_KVM_XEN

--- 4455 unchanged lines hidden (view full) ---

8899 if (reexecute_instruction(vcpu, cr2_or_gpa, write_fault_to_spt,
8900 emulation_type))
8901 return 1;
8902
8903 return handle_emulation_failure(vcpu, emulation_type);
8904 }
8905
8906 if (ctxt->have_exception) {
4435 r = 1;
4436 break;
4437 case KVM_CAP_EXIT_HYPERCALL:
4438 r = KVM_EXIT_HYPERCALL_VALID_MASK;
4439 break;
4440 case KVM_CAP_SET_GUEST_DEBUG2:
4441 return KVM_GUESTDBG_VALID_MASK;
4442#ifdef CONFIG_KVM_XEN

--- 4455 unchanged lines hidden (view full) ---

8898 if (reexecute_instruction(vcpu, cr2_or_gpa, write_fault_to_spt,
8899 emulation_type))
8900 return 1;
8901
8902 return handle_emulation_failure(vcpu, emulation_type);
8903 }
8904
8905 if (ctxt->have_exception) {
8907 WARN_ON_ONCE(vcpu->mmio_needed && !vcpu->mmio_is_write);
8908 vcpu->mmio_needed = false;
8909 r = 1;
8910 inject_emulated_exception(vcpu);
8911 } else if (vcpu->arch.pio.count) {
8912 if (!vcpu->arch.pio.in) {
8913 /* FIXME: return into emulator if single-stepping. */
8914 vcpu->arch.pio.count = 0;
8915 } else {
8916 writeback = false;

--- 884 unchanged lines hidden (view full) ---

9801 break;
9802 }
9803
9804 vcpu->run->exit_reason = KVM_EXIT_HYPERCALL;
9805 vcpu->run->hypercall.nr = KVM_HC_MAP_GPA_RANGE;
9806 vcpu->run->hypercall.args[0] = gpa;
9807 vcpu->run->hypercall.args[1] = npages;
9808 vcpu->run->hypercall.args[2] = attrs;
8906 r = 1;
8907 inject_emulated_exception(vcpu);
8908 } else if (vcpu->arch.pio.count) {
8909 if (!vcpu->arch.pio.in) {
8910 /* FIXME: return into emulator if single-stepping. */
8911 vcpu->arch.pio.count = 0;
8912 } else {
8913 writeback = false;

--- 884 unchanged lines hidden (view full) ---

9798 break;
9799 }
9800
9801 vcpu->run->exit_reason = KVM_EXIT_HYPERCALL;
9802 vcpu->run->hypercall.nr = KVM_HC_MAP_GPA_RANGE;
9803 vcpu->run->hypercall.args[0] = gpa;
9804 vcpu->run->hypercall.args[1] = npages;
9805 vcpu->run->hypercall.args[2] = attrs;
9809 vcpu->run->hypercall.longmode = op_64_bit;
9806 vcpu->run->hypercall.flags = 0;
9807 if (op_64_bit)
9808 vcpu->run->hypercall.flags |= KVM_EXIT_HYPERCALL_LONG_MODE;
9809
9810 WARN_ON_ONCE(vcpu->run->hypercall.flags & KVM_EXIT_HYPERCALL_MBZ);
9810 vcpu->arch.complete_userspace_io = complete_hypercall_exit;
9811 return 0;
9812 }
9813 default:
9814 ret = -KVM_ENOSYS;
9815 break;
9816 }
9817out:

--- 86 unchanged lines hidden (view full) ---

9904 return 1;
9905 }
9906
9907 return kvm_x86_ops.nested_ops->check_events(vcpu);
9908}
9909
9910static void kvm_inject_exception(struct kvm_vcpu *vcpu)
9911{
9811 vcpu->arch.complete_userspace_io = complete_hypercall_exit;
9812 return 0;
9813 }
9814 default:
9815 ret = -KVM_ENOSYS;
9816 break;
9817 }
9818out:

--- 86 unchanged lines hidden (view full) ---

9905 return 1;
9906 }
9907
9908 return kvm_x86_ops.nested_ops->check_events(vcpu);
9909}
9910
9911static void kvm_inject_exception(struct kvm_vcpu *vcpu)
9912{
9912 /*
9913 * Suppress the error code if the vCPU is in Real Mode, as Real Mode
9914 * exceptions don't report error codes. The presence of an error code
9915 * is carried with the exception and only stripped when the exception
9916 * is injected as intercepted #PF VM-Exits for AMD's Paged Real Mode do
9917 * report an error code despite the CPU being in Real Mode.
9918 */
9919 vcpu->arch.exception.has_error_code &= is_protmode(vcpu);
9920
9921 trace_kvm_inj_exception(vcpu->arch.exception.vector,
9922 vcpu->arch.exception.has_error_code,
9923 vcpu->arch.exception.error_code,
9924 vcpu->arch.exception.injected);
9925
9913 trace_kvm_inj_exception(vcpu->arch.exception.vector,
9914 vcpu->arch.exception.has_error_code,
9915 vcpu->arch.exception.error_code,
9916 vcpu->arch.exception.injected);
9917
9918 if (vcpu->arch.exception.error_code && !is_protmode(vcpu))
9919 vcpu->arch.exception.error_code = false;
9926 static_call(kvm_x86_inject_exception)(vcpu);
9927}
9928
9929/*
9930 * Check for any event (interrupt or exception) that is ready to be injected,
9931 * and if there is at least one event, inject the event with the highest
9932 * priority. This handles both "pending" events, i.e. events that have never
9933 * been injected into the guest, and "injected" events, i.e. events that were

--- 3633 unchanged lines hidden ---
9920 static_call(kvm_x86_inject_exception)(vcpu);
9921}
9922
9923/*
9924 * Check for any event (interrupt or exception) that is ready to be injected,
9925 * and if there is at least one event, inject the event with the highest
9926 * priority. This handles both "pending" events, i.e. events that have never
9927 * been injected into the guest, and "injected" events, i.e. events that were

--- 3633 unchanged lines hidden ---