vmx.c (9ddb236f13594b34a12dacf69a5adca7a1aef35e) vmx.c (00089c048eb4a8250325efb32a2724fd0da68cce)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * This module enables machines with Intel VT-x extensions to run virtual
6 * machines without emulation or binary translation.
7 *
8 * Copyright (C) 2006 Qumranet, Inc.
9 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
10 *
11 * Authors:
12 * Avi Kivity <avi@qumranet.com>
13 * Yaniv Kamay <yaniv@qumranet.com>
14 */
15
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * This module enables machines with Intel VT-x extensions to run virtual
6 * machines without emulation or binary translation.
7 *
8 * Copyright (C) 2006 Qumranet, Inc.
9 * Copyright 2010 Red Hat, Inc. and/or its affiliates.
10 *
11 * Authors:
12 * Avi Kivity <avi@qumranet.com>
13 * Yaniv Kamay <yaniv@qumranet.com>
14 */
15
16#include <linux/frame.h>
17#include <linux/highmem.h>
18#include <linux/hrtimer.h>
19#include <linux/kernel.h>
20#include <linux/kvm_host.h>
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/mod_devicetable.h>
24#include <linux/mm.h>
16#include <linux/highmem.h>
17#include <linux/hrtimer.h>
18#include <linux/kernel.h>
19#include <linux/kvm_host.h>
20#include <linux/module.h>
21#include <linux/moduleparam.h>
22#include <linux/mod_devicetable.h>
23#include <linux/mm.h>
24#include <linux/objtool.h>
25#include <linux/sched.h>
26#include <linux/sched/smt.h>
27#include <linux/slab.h>
28#include <linux/tboot.h>
29#include <linux/trace_events.h>
30#include <linux/entry-kvm.h>
31
32#include <asm/apic.h>

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

4649 /*
4650 * Update instruction length as we may reinject the exception
4651 * from user space while in guest debugging mode.
4652 */
4653 to_vmx(vcpu)->vcpu.arch.event_exit_inst_len =
4654 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
4655 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
4656 return false;
25#include <linux/sched.h>
26#include <linux/sched/smt.h>
27#include <linux/slab.h>
28#include <linux/tboot.h>
29#include <linux/trace_events.h>
30#include <linux/entry-kvm.h>
31
32#include <asm/apic.h>

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

4649 /*
4650 * Update instruction length as we may reinject the exception
4651 * from user space while in guest debugging mode.
4652 */
4653 to_vmx(vcpu)->vcpu.arch.event_exit_inst_len =
4654 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
4655 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
4656 return false;
4657 /* fall through */
4657 fallthrough;
4658 case DB_VECTOR:
4659 return !(vcpu->guest_debug &
4660 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));
4661 case DE_VECTOR:
4662 case OF_VECTOR:
4663 case BR_VECTOR:
4664 case UD_VECTOR:
4665 case DF_VECTOR:

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

4822 if (is_icebp(intr_info))
4823 WARN_ON(!skip_emulated_instruction(vcpu));
4824
4825 kvm_queue_exception_p(vcpu, DB_VECTOR, dr6);
4826 return 1;
4827 }
4828 kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1 | DR6_RTM;
4829 kvm_run->debug.arch.dr7 = vmcs_readl(GUEST_DR7);
4658 case DB_VECTOR:
4659 return !(vcpu->guest_debug &
4660 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));
4661 case DE_VECTOR:
4662 case OF_VECTOR:
4663 case BR_VECTOR:
4664 case UD_VECTOR:
4665 case DF_VECTOR:

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

4822 if (is_icebp(intr_info))
4823 WARN_ON(!skip_emulated_instruction(vcpu));
4824
4825 kvm_queue_exception_p(vcpu, DB_VECTOR, dr6);
4826 return 1;
4827 }
4828 kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1 | DR6_RTM;
4829 kvm_run->debug.arch.dr7 = vmcs_readl(GUEST_DR7);
4830 /* fall through */
4830 fallthrough;
4831 case BP_VECTOR:
4832 /*
4833 * Update instruction length as we may reinject #BP from
4834 * user space while in guest debugging mode. Reading it for
4835 * #DB as well causes no harm, it is not used in that case.
4836 */
4837 vmx->vcpu.arch.event_exit_inst_len =
4838 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);

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

5252 break;
5253 case INTR_TYPE_HARD_EXCEPTION:
5254 if (vmx->idt_vectoring_info &
5255 VECTORING_INFO_DELIVER_CODE_MASK) {
5256 has_error_code = true;
5257 error_code =
5258 vmcs_read32(IDT_VECTORING_ERROR_CODE);
5259 }
4831 case BP_VECTOR:
4832 /*
4833 * Update instruction length as we may reinject #BP from
4834 * user space while in guest debugging mode. Reading it for
4835 * #DB as well causes no harm, it is not used in that case.
4836 */
4837 vmx->vcpu.arch.event_exit_inst_len =
4838 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);

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

5252 break;
5253 case INTR_TYPE_HARD_EXCEPTION:
5254 if (vmx->idt_vectoring_info &
5255 VECTORING_INFO_DELIVER_CODE_MASK) {
5256 has_error_code = true;
5257 error_code =
5258 vmcs_read32(IDT_VECTORING_ERROR_CODE);
5259 }
5260 /* fall through */
5260 fallthrough;
5261 case INTR_TYPE_SOFT_EXCEPTION:
5262 kvm_clear_exception_queue(vcpu);
5263 break;
5264 default:
5265 break;
5266 }
5267 }
5268 tss_selector = exit_qualification;

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

5605 case INVPCID_TYPE_ALL_NON_GLOBAL:
5606 /*
5607 * Currently, KVM doesn't mark global entries in the shadow
5608 * page tables, so a non-global flush just degenerates to a
5609 * global flush. If needed, we could optimize this later by
5610 * keeping track of global entries in shadow page tables.
5611 */
5612
5261 case INTR_TYPE_SOFT_EXCEPTION:
5262 kvm_clear_exception_queue(vcpu);
5263 break;
5264 default:
5265 break;
5266 }
5267 }
5268 tss_selector = exit_qualification;

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

5605 case INVPCID_TYPE_ALL_NON_GLOBAL:
5606 /*
5607 * Currently, KVM doesn't mark global entries in the shadow
5608 * page tables, so a non-global flush just degenerates to a
5609 * global flush. If needed, we could optimize this later by
5610 * keeping track of global entries in shadow page tables.
5611 */
5612
5613 /* fall-through */
5613 fallthrough;
5614 case INVPCID_TYPE_ALL_INCL_GLOBAL:
5615 kvm_mmu_unload(vcpu);
5616 return kvm_skip_emulated_instruction(vcpu);
5617
5618 default:
5619 BUG(); /* We have already checked above that type <= 3 */
5620 }
5621}

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

6573 * SDM 3: 27.7.1.2 (September 2008)
6574 * Clear bit "block by NMI" before VM entry if a NMI
6575 * delivery faulted.
6576 */
6577 vmx_set_nmi_mask(vcpu, false);
6578 break;
6579 case INTR_TYPE_SOFT_EXCEPTION:
6580 vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
5614 case INVPCID_TYPE_ALL_INCL_GLOBAL:
5615 kvm_mmu_unload(vcpu);
5616 return kvm_skip_emulated_instruction(vcpu);
5617
5618 default:
5619 BUG(); /* We have already checked above that type <= 3 */
5620 }
5621}

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

6573 * SDM 3: 27.7.1.2 (September 2008)
6574 * Clear bit "block by NMI" before VM entry if a NMI
6575 * delivery faulted.
6576 */
6577 vmx_set_nmi_mask(vcpu, false);
6578 break;
6579 case INTR_TYPE_SOFT_EXCEPTION:
6580 vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
6581 /* fall through */
6581 fallthrough;
6582 case INTR_TYPE_HARD_EXCEPTION:
6583 if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
6584 u32 err = vmcs_read32(error_code_field);
6585 kvm_requeue_exception_e(vcpu, vector, err);
6586 } else
6587 kvm_requeue_exception(vcpu, vector);
6588 break;
6589 case INTR_TYPE_SOFT_INTR:
6590 vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
6582 case INTR_TYPE_HARD_EXCEPTION:
6583 if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
6584 u32 err = vmcs_read32(error_code_field);
6585 kvm_requeue_exception_e(vcpu, vector, err);
6586 } else
6587 kvm_requeue_exception(vcpu, vector);
6588 break;
6589 case INTR_TYPE_SOFT_INTR:
6590 vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
6591 /* fall through */
6591 fallthrough;
6592 case INTR_TYPE_EXT_INTR:
6593 kvm_queue_interrupt(vcpu, vector, type == INTR_TYPE_SOFT_INTR);
6594 break;
6595 default:
6596 break;
6597 }
6598}
6599

--- 1716 unchanged lines hidden ---
6592 case INTR_TYPE_EXT_INTR:
6593 kvm_queue_interrupt(vcpu, vector, type == INTR_TYPE_SOFT_INTR);
6594 break;
6595 default:
6596 break;
6597 }
6598}
6599

--- 1716 unchanged lines hidden ---