Unprotect a page if #PF happens during NMI injection.
PATCH 1/10 Unprotect a page if #PF happens during NMI injection.
It is done for exception and interrupt already.
--- arch/x86/kvm/svm.c | 3 +-- arch/x86/kvm/vmx.c | 2 +- arch/x86/kvm/x86.h | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-)
arch/x86/kvm/svm.c +1 -2
@@ -1102,8 +1102,7 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)if (npt_enabled)svm_flush_tlb (&svm->vcpu);else { -if (svm->vcpu.arch.interrupt.pending || - svm->vcpu.arch.exception.pending) +if (kvm_event_needs_reinjection (&svm->vcpu))kvm_mmu_unprotect_page_virt (&svm->vcpu, fault_address); }return kvm_mmu_page_fault (&svm->vcpu, fault_address, error_code);
arch/x86/kvm/vmx.c +1 -1
@@ -2599,7 +2599,7 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) cr2 =vmcs_readl (EXIT_QUALIFICATION );KVMTRACE_3D (PAGE_FAULT , vcpu, error_code, (u32 )cr2, (u32)((u64 )cr2 >>32 ), handler); -if (vcpu->arch.interrupt.pending || vcpu->arch.exception.pending) +if (kvm_event_needs_reinjection (vcpu))kvm_mmu_unprotect_page_virt (vcpu, cr2);return kvm_mmu_page_fault (vcpu, cr2, error_code); }
arch/x86/kvm/x86.h +6 -0
@@ -30,4 +30,10 @@ static inline u8 kvm_pop_irq(struct kvm_vcpu *vcpu)clear_bit (word_index, &vcpu->arch.irq_summary); return irq; } + +static inline bool kvm_event_needs_reinjection (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending || + vcpu->arch.nmi_injected; +}#endif
Signature · 1 line
1.6.2.1
PATCH 2/10 Do not allow interrupt injection from userspace if there is a pending event.
--- arch/x86/kvm/x86.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +3 -2
@@ -3093,8 +3093,9 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu, kvm_run->ready_for_interrupt_injection =1 ; else kvm_run->ready_for_interrupt_injection = - (kvm_arch_interrupt_allowed (vcpu) && - !kvm_cpu_has_interrupt (vcpu)); +kvm_arch_interrupt_allowed (vcpu) && + !kvm_cpu_has_interrupt (vcpu) && + !kvm_event_needs_reinjection (vcpu); }static void vapic_enter (struct kvm_vcpu *vcpu)
Signature · 1 line
1.6.2.1
PATCH 3/10 Remove irq_pending bitmap
In reply to Gleb NatapovOnly one interrupt vector can be injected from userspace irqchip at any given time so no need to store it in a bitmap. Put it into interrupt queue directly.
--- arch/x86/include/asm/kvm_host.h | 2 -- arch/x86/kvm/irq.c | 4 ++-- arch/x86/kvm/x86.c | 38 +++++++++++--------------------------- arch/x86/kvm/x86.h | 12 ------------ 4 files changed, 13 insertions(+), 43 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -2
@@ -266,8 +266,6 @@ struct kvm_mmu {struct kvm_vcpu_arch {u64 host_tsc; -unsigned long irq_summary;/* bit vector: 1 per word in irq_pending */ - DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);/* * rip and regs accesses must go through * kvm_{register,rip}_{read,write} functions.
arch/x86/kvm/irq.c +2 -2
@@ -50,7 +50,7 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)struct kvm_pic *s;if (!irqchip_in_kernel (v->kvm)) -return v->arch.irq_summary; +return v->arch.interrupt.pending;if (kvm_apic_has_interrupt (v) ==-1 ) {/* LAPIC */ if (kvm_apic_accept_pic_intr (v)) {
@@ -72,7 +72,7 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)int vector;if (!irqchip_in_kernel (v->kvm)) -return kvm_pop_irq (v); +return v->arch.interrupt.nr; vector =kvm_get_apic_interrupt (v);/* APIC */ if (vector ==-1 ) {
arch/x86/kvm/x86.c +11 -27
@@ -1437,8 +1437,7 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,return -ENXIO ;vcpu_load (vcpu); -set_bit (irq->irq, vcpu->arch.irq_pending); -set_bit (irq->irq /BITS_PER_LONG , &vcpu->arch.irq_summary); +kvm_queue_interrupt (vcpu, irq->irq);vcpu_put (vcpu);
@@ -3571,12 +3570,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, sregs->efer = vcpu->arch.shadow_efer; sregs->apic_base =kvm_get_apic_base (vcpu); -if (irqchip_in_kernel (vcpu->kvm)) -memset (sregs->interrupt_bitmap,0 , -sizeof sregs->interrupt_bitmap); -else -memcpy (sregs->interrupt_bitmap, vcpu->arch.irq_pending, -sizeof sregs->interrupt_bitmap); +memset (sregs->interrupt_bitmap,0 ,sizeof sregs->interrupt_bitmap);if (vcpu->arch.interrupt.pending) set_bit(vcpu->arch.interrupt.nr,
@@ -4046,7 +4040,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) {int mmu_reset_needed =0 ; -int i, pending_vec, max_bits; +int pending_vec, max_bits;struct descriptor_table dt;vcpu_load (vcpu);
@@ -4088,24 +4082,14 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,if (mmu_reset_needed)kvm_mmu_reset_context (vcpu); -if (!irqchip_in_kernel (vcpu->kvm)) { -memcpy (vcpu->arch.irq_pending, sregs->interrupt_bitmap, -sizeof vcpu->arch.irq_pending); - vcpu->arch.irq_summary =0 ; -for (i =0 ; i <ARRAY_SIZE (vcpu->arch.irq_pending); ++i) -if (vcpu->arch.irq_pending[i]) -__set_bit (i, &vcpu->arch.irq_summary); - }else { - max_bits = (sizeof sregs->interrupt_bitmap) <<3 ; - pending_vec =find_first_bit ( - (const unsigned long *)sregs->interrupt_bitmap, - max_bits); -/* Only pending external irq is handled here */ -if (pending_vec < max_bits) { -kvm_queue_interrupt (vcpu, pending_vec); -pr_debug ("Set back pending irq %d\n" , pending_vec); - } -kvm_pic_clear_isr_ack (vcpu->kvm); + max_bits = (sizeof sregs->interrupt_bitmap) <<3 ; + pending_vec =find_first_bit ( + (const unsigned long *)sregs->interrupt_bitmap, max_bits); +if (pending_vec < max_bits) { +kvm_queue_interrupt (vcpu, pending_vec); +pr_debug ("Set back pending irq %d\n" , pending_vec); +if (irqchip_in_kernel (vcpu->kvm)) +kvm_pic_clear_isr_ack (vcpu->kvm); }kvm_set_segment (vcpu, &sregs->cs,VCPU_SREG_CS );
arch/x86/kvm/x86.h +0 -12
@@ -19,18 +19,6 @@ static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu) vcpu->arch.interrupt.pending = false; } -static inline u8 kvm_pop_irq (struct kvm_vcpu *vcpu) -{ -int word_index =__ffs (vcpu->arch.irq_summary); -int bit_index =__ffs (vcpu->arch.irq_pending[word_index]); -int irq = word_index *BITS_PER_LONG + bit_index; - -clear_bit (bit_index, &vcpu->arch.irq_pending[word_index]); -if (!vcpu->arch.irq_pending[word_index]) -clear_bit (word_index, &vcpu->arch.irq_summary); -return irq; -} -static inline bool kvm_event_needs_reinjection (struct kvm_vcpu *vcpu) { return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending ||
Signature · 1 line
1.6.2.1
PATCH 4/10 skip_emulated_instruction() decode an instruction if size is not known
In reply to Gleb Natapov--- arch/x86/kvm/svm.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/kvm/svm.c +5 -6
@@ -207,7 +207,9 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)struct vcpu_svm *svm =to_svm (vcpu);if (!svm->next_rip) { -printk (KERN_DEBUG "%s: NOP\n" , __func__); +if (emulate_instruction (vcpu, vcpu->run,0 ,0 ,EMULTYPE_SKIP ) != +EMULATE_DONE ) +printk (KERN_DEBUG "%s: NOP\n" , __func__);return ; }if (svm->next_rip -kvm_rip_read (vcpu) >MAX_INST_SIZE )
@@ -1848,11 +1850,8 @@ static int task_switch_interception(struct vcpu_svm *svm,if (reason !=TASK_SWITCH_GATE || int_type ==SVM_EXITINTINFO_TYPE_SOFT || (int_type ==SVM_EXITINTINFO_TYPE_EXEPT && - (int_vec ==OF_VECTOR || int_vec ==BP_VECTOR ))) { -if (emulate_instruction (&svm->vcpu, kvm_run,0 ,0 , -EMULTYPE_SKIP ) !=EMULATE_DONE ) -return 0 ; - } + (int_vec ==OF_VECTOR || int_vec ==BP_VECTOR ))) +skip_emulated_instruction (&svm->vcpu);return kvm_task_switch (&svm->vcpu, tss_selector, reason); }
Signature · 1 line
1.6.2.1
PATCH 5/10 Do not re-execute INTn instruction.
In reply to Gleb NatapovRe-inject event instead. This is what Intel suggest. Also use correct instruction length when re-injecting soft fault/interrupt.
--- arch/x86/include/asm/kvm_host.h | 5 ++++- arch/x86/kvm/svm.c | 8 ++++---- arch/x86/kvm/vmx.c | 32 +++++++++++++++++++++++++------- arch/x86/kvm/x86.c | 11 ++++++----- arch/x86/kvm/x86.h | 9 ++++++++- 5 files changed, 47 insertions(+), 18 deletions(-)
arch/x86/include/asm/kvm_host.h +4 -1
@@ -319,6 +319,8 @@ struct kvm_vcpu_arch {struct kvm_pio_request pio;void *pio_data; +u8 event_exit_inst_len; +struct kvm_queued_exception {bool pending;bool has_error_code;
@@ -328,6 +330,7 @@ struct kvm_vcpu_arch {struct kvm_queued_interrupt {bool pending; +bool soft;u8 nr; } interrupt;
@@ -509,7 +512,7 @@ struct kvm_x86_ops {void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);void (*patch_hypercall)(struct kvm_vcpu *vcpu,unsigned char *hypercall_addr); -void (*set_irq)(struct kvm_vcpu *vcpu,int vec); +void (*set_irq)(struct kvm_vcpu *vcpu);void (*set_nmi)(struct kvm_vcpu *vcpu);void (*queue_exception)(struct kvm_vcpu *vcpu,unsigned nr,bool has_error_code,u32 error_code);
arch/x86/kvm/svm.c +4 -4
@@ -2296,13 +2296,13 @@ static void svm_queue_irq(struct kvm_vcpu *vcpu, unsigned nr)SVM_EVTINJ_VALID |SVM_EVTINJ_TYPE_INTR ; } -static void svm_set_irq (struct kvm_vcpu *vcpu,int irq) +static void svm_set_irq (struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu);nested_svm_intr (svm); -svm_queue_irq (vcpu, irq); +svm_queue_irq (vcpu, vcpu->arch.interrupt.nr); }static void update_cr8_intercept (struct kvm_vcpu *vcpu,int tpr,int irr)
@@ -2404,7 +2404,7 @@ static void svm_complete_interrupts(struct vcpu_svm *svm)case SVM_EXITINTINFO_TYPE_EXEPT :/* In case of software exception do not reinject an exception vector, but re-execute and instruction instead */ -if (vector ==BP_VECTOR || vector ==OF_VECTOR ) +if (kvm_exception_is_soft (vector))break ;if (exitintinfo &SVM_EXITINTINFO_VALID_ERR ) {u32 err = svm->vmcb->control.exit_int_info_err;
@@ -2414,7 +2414,7 @@ static void svm_complete_interrupts(struct vcpu_svm *svm)kvm_queue_exception (&svm->vcpu, vector);break ;case SVM_EXITINTINFO_TYPE_INTR : -kvm_queue_interrupt (&svm->vcpu, vector); +kvm_queue_interrupt (&svm->vcpu, vector, false);break ;default :break ;
arch/x86/kvm/vmx.c +25 -7
@@ -779,8 +779,9 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,return ; } -if (nr ==BP_VECTOR || nr ==OF_VECTOR ) { -vmcs_write32 (VM_ENTRY_INSTRUCTION_LEN ,1 ); +if (kvm_exception_is_soft (nr)) { +vmcs_write32 (VM_ENTRY_INSTRUCTION_LEN , + vmx->vcpu.arch.event_exit_inst_len); intr_info |=INTR_TYPE_SOFT_EXCEPTION ; }else intr_info |=INTR_TYPE_HARD_EXCEPTION ;
@@ -2429,9 +2430,11 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu)vmcs_write32 (CPU_BASED_VM_EXEC_CONTROL , cpu_based_vm_exec_control); } -static void vmx_inject_irq (struct kvm_vcpu *vcpu,int irq) +static void vmx_inject_irq (struct kvm_vcpu *vcpu) {struct vcpu_vmx *vmx =to_vmx (vcpu); +uint32_t intr; +int irq = vcpu->arch.interrupt.nr;KVMTRACE_1D (INJ_VIRQ , vcpu, (u32 )irq, handler);
@@ -2446,8 +2449,14 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)kvm_rip_write (vcpu, vmx->rmode.irq.rip -1 );return ; } -vmcs_write32 (VM_ENTRY_INTR_INFO_FIELD , - irq |INTR_TYPE_EXT_INTR |INTR_INFO_VALID_MASK ); + intr = irq |INTR_INFO_VALID_MASK ; +if (vcpu->arch.interrupt.soft) { + intr |=INTR_TYPE_SOFT_INTR ; +vmcs_write32 (VM_ENTRY_INSTRUCTION_LEN , + vmx->vcpu.arch.event_exit_inst_len); + }else + intr |=INTR_TYPE_EXT_INTR ; +vmcs_write32 (VM_ENTRY_INTR_INFO_FIELD , intr); }static void vmx_inject_nmi (struct kvm_vcpu *vcpu)
@@ -3008,6 +3017,7 @@ static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) GUEST_INTR_STATE_NMI);break ;case INTR_TYPE_EXT_INTR : +case INTR_TYPE_SOFT_INTR :kvm_clear_interrupt_queue (vcpu);break ;case INTR_TYPE_HARD_EXCEPTION :
@@ -3279,16 +3289,24 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)vmcs_clear_bits (GUEST_INTERRUPTIBILITY_INFO ,GUEST_INTR_STATE_NMI );break ; -case INTR_TYPE_HARD_EXCEPTION :case INTR_TYPE_SOFT_EXCEPTION : + vmx->vcpu.arch.event_exit_inst_len = +vmcs_read32 (VM_EXIT_INSTRUCTION_LEN ); +/* fall through */ +case INTR_TYPE_HARD_EXCEPTION :if (idt_vectoring_info &VECTORING_INFO_DELIVER_CODE_MASK ) {u32 err =vmcs_read32 (IDT_VECTORING_ERROR_CODE );kvm_queue_exception_e (&vmx->vcpu, vector, err); }else kvm_queue_exception (&vmx->vcpu, vector);break ; +case INTR_TYPE_SOFT_INTR : + vmx->vcpu.arch.event_exit_inst_len = +vmcs_read32 (VM_EXIT_INSTRUCTION_LEN ); +/* fall through */ case INTR_TYPE_EXT_INTR : -kvm_queue_interrupt (&vmx->vcpu, vector); +kvm_queue_interrupt (&vmx->vcpu, vector, + type ==INTR_TYPE_SOFT_INTR );break ;default :break ;
arch/x86/kvm/x86.c +6 -5
@@ -1437,7 +1437,7 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,return -ENXIO ;vcpu_load (vcpu); -kvm_queue_interrupt (vcpu, irq->irq); +kvm_queue_interrupt (vcpu, irq->irq, false);vcpu_put (vcpu);
@@ -3149,7 +3149,7 @@ static void inject_irq(struct kvm_vcpu *vcpu) }if (vcpu->arch.interrupt.pending) { - kvm_x86_ops->set_irq (vcpu, vcpu->arch.interrupt.nr); + kvm_x86_ops->set_irq (vcpu);return ; }
@@ -3162,8 +3162,9 @@ static void inject_irq(struct kvm_vcpu *vcpu) } }else if (kvm_cpu_has_interrupt (vcpu)) {if (kvm_x86_ops->interrupt_allowed (vcpu)) { -kvm_queue_interrupt (vcpu,kvm_cpu_get_interrupt (vcpu)); - kvm_x86_ops->set_irq (vcpu, vcpu->arch.interrupt.nr); +kvm_queue_interrupt (vcpu,kvm_cpu_get_interrupt (vcpu), + false); + kvm_x86_ops->set_irq (vcpu); } } }
@@ -4086,7 +4087,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, pending_vec =find_first_bit ( (const unsigned long *)sregs->interrupt_bitmap, max_bits);if (pending_vec < max_bits) { -kvm_queue_interrupt (vcpu, pending_vec); +kvm_queue_interrupt (vcpu, pending_vec, false);pr_debug ("Set back pending irq %d\n" , pending_vec);if (irqchip_in_kernel (vcpu->kvm))kvm_pic_clear_isr_ack (vcpu->kvm);
arch/x86/kvm/x86.h +8 -1
@@ -8,9 +8,11 @@ static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu) vcpu->arch.exception.pending = false; } -static inline void kvm_queue_interrupt (struct kvm_vcpu *vcpu,u8 vector) +static inline void kvm_queue_interrupt (struct kvm_vcpu *vcpu,u8 vector, +bool soft) { vcpu->arch.interrupt.pending = true; + vcpu->arch.interrupt.soft = soft; vcpu->arch.interrupt.nr = vector; }
@@ -24,4 +26,9 @@ static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending || vcpu->arch.nmi_injected; } + +static inline bool kvm_exception_is_soft (unsigned int nr) +{ +return (nr ==BP_VECTOR ) || (nr ==OF_VECTOR ); +}#endif
Signature · 1 line
1.6.2.1
PATCH 6/10 IRQ/NMI window should always be requested.
In reply to Gleb NatapovCurrently they are not requested if there is pending exception.
--- arch/x86/kvm/x86.c | 30 ++++++++++++------------------ 1 files changed, 12 insertions(+), 18 deletions(-)
arch/x86/kvm/x86.c +12 -18
@@ -3140,8 +3140,11 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu) kvm_x86_ops->update_cr8_intercept (vcpu, tpr, max_irr); } -static void inject_irq (struct kvm_vcpu *vcpu) +static void inject_pending_irq (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) { +if (vcpu->guest_debug &KVM_GUESTDBG_SINGLESTEP ) + kvm_x86_ops->drop_interrupt_shadow (vcpu); +/* try to reinject previous events if any */ if (vcpu->arch.nmi_injected) { kvm_x86_ops->set_nmi (vcpu);
@@ -3169,26 +3172,11 @@ static void inject_irq(struct kvm_vcpu *vcpu) } } -static void inject_pending_irq (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) -{ -bool req_int_win = !irqchip_in_kernel (vcpu->kvm) && - kvm_run->request_interrupt_window; - -if (vcpu->guest_debug &KVM_GUESTDBG_SINGLESTEP ) - kvm_x86_ops->drop_interrupt_shadow (vcpu); - -inject_irq (vcpu); - -/* enable NMI/IRQ window open exits if needed */ -if (vcpu->arch.nmi_pending) - kvm_x86_ops->enable_nmi_window (vcpu); -else if (kvm_cpu_has_interrupt (vcpu) || req_int_win) - kvm_x86_ops->enable_irq_window (vcpu); -} -static int vcpu_enter_guest (struct kvm_vcpu *vcpu,struct kvm_run *kvm_run) {int r; +bool req_int_win = !irqchip_in_kernel (vcpu->kvm) && + kvm_run->request_interrupt_window;if (vcpu->requests)if (test_and_clear_bit (KVM_REQ_MMU_RELOAD , &vcpu->requests))
@@ -3242,6 +3230,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)else inject_pending_irq (vcpu, kvm_run); +/* enable NMI/IRQ window open exits if needed */ +if (vcpu->arch.nmi_pending) + kvm_x86_ops->enable_nmi_window (vcpu); +else if (kvm_cpu_has_interrupt (vcpu) || req_int_win) + kvm_x86_ops->enable_irq_window (vcpu); +if (kvm_lapic_enabled (vcpu)) {if (!vcpu->arch.apic->vapic_addr)update_cr8_intercept (vcpu);
Signature · 1 line
1.6.2.1
PATCH 7/10 inject NMI after IRET from a previous NMI, not before.
In reply to Gleb NatapovIf NMI is received during handling of another NMI it should be injected immediately after IRET from previous NMI handler, but SVM intercept IRET before instruction execution so we can't inject pending NMI at this point and there is not way to request exit when NMI window opens. This patch fix SVM code to open NMI window after IRET by single stepping over IRET instruction.
--- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm.c | 62 +++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 12 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -358,6 +358,7 @@ struct kvm_vcpu_arch {unsigned int time_offset;struct page *time_page; +bool singlestep;/* guest is single stepped by KVM */ bool nmi_pending;bool nmi_injected;
@@ -771,6 +772,7 @@ enum {#define HF_HIF_MASK (1 << 1)#define HF_VINTR_MASK (1 << 2)#define HF_NMI_MASK (1 << 3) +#define HF_IRET_MASK (1 << 4)/* * Hardware virtualization extension instructions may fault if a
arch/x86/kvm/svm.c +50 -12
106 lines not on this page · raw message
Signature · 1 line
1.6.2.1
PATCH 8/10 Do not migrate pending software interrupts.
In reply to Gleb NatapovINTn will be re-executed after migration. If we wanted to migrate pending software interrupt we would need to migrate interrupt type and instruction length too, but we do not have all required info on SVM, so SVM->VMX migration would need to re-execute INTn anyway. To make it simple never migrate pending soft interrupt.
--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
@@ -3567,7 +3567,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,memset (sregs->interrupt_bitmap,0 ,sizeof sregs->interrupt_bitmap); -if (vcpu->arch.interrupt.pending) +if (vcpu->arch.interrupt.pending && !vcpu->arch.interrupt.soft)set_bit (vcpu->arch.interrupt.nr, (unsigned long *)sregs->interrupt_bitmap);
Signature · 1 line
1.6.2.1
PATCH 9/10 Disable CR8 intercept if tpr patching is active.
In reply to Gleb Natapov--- arch/x86/kvm/x86.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
arch/x86/kvm/x86.c +6 -5
@@ -3130,7 +3130,10 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu)if (!kvm_x86_ops->update_cr8_intercept)return ; - max_irr =kvm_lapic_find_highest_irr (vcpu); +if (!vcpu->arch.apic->vapic_addr) + max_irr =kvm_lapic_find_highest_irr (vcpu); +else + max_irr =-1 ;if (max_irr !=-1 ) max_irr >>=4 ;
@@ -3237,10 +3240,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) kvm_x86_ops->enable_irq_window (vcpu);if (kvm_lapic_enabled (vcpu)) { -if (!vcpu->arch.apic->vapic_addr) -update_cr8_intercept (vcpu); -else -kvm_lapic_sync_to_vapic (vcpu); +update_cr8_intercept (vcpu); +kvm_lapic_sync_to_vapic (vcpu); }up_read (&vcpu->kvm->slots_lock);
Signature · 1 line
1.6.2.1
PATCH 10/10 Move "exit due to NMI" handling into vmx_complete_interrupts()
In reply to Gleb NatapovTo save us one reading of VM_EXIT_INTR_INFO.
--- arch/x86/kvm/vmx.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
arch/x86/kvm/vmx.c +10 -10
@@ -3245,8 +3245,17 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)int type;bool idtv_info_valid; - idtv_info_valid = idt_vectoring_info &VECTORING_INFO_VALID_MASK ; exit_intr_info =vmcs_read32 (VM_EXIT_INTR_INFO ); + +/* We need to handle NMIs before interrupts are enabled */ +if ((exit_intr_info &INTR_INFO_INTR_TYPE_MASK ) ==INTR_TYPE_NMI_INTR && + (exit_intr_info &INTR_INFO_VALID_MASK )) { +KVMTRACE_0D (NMI , vmx->vcpu, handler); + asm("int $2" ); + } + + idtv_info_valid = idt_vectoring_info &VECTORING_INFO_VALID_MASK ; +if (cpu_has_virtual_nmis ()) { unblock_nmi = (exit_intr_info &INTR_INFO_UNBLOCK_NMI ) !=0 ; vector = exit_intr_info &INTR_INFO_VECTOR_MASK ;
@@ -3474,15 +3483,6 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) asm("mov %0, %%ds; mov %0, %%es" : :"r" (__USER_DS)); vmx->launched =1 ; - intr_info =vmcs_read32 (VM_EXIT_INTR_INFO ); - -/* We need to handle NMIs before interrupts are enabled */ -if ((intr_info &INTR_INFO_INTR_TYPE_MASK ) ==INTR_TYPE_NMI_INTR && - (intr_info &INTR_INFO_VALID_MASK )) { -KVMTRACE_0D (NMI , vcpu, handler); - asm("int $2" ); - } -vmx_complete_interrupts (vmx); }
Signature · 1 line
1.6.2.1
Avi Kivity
AppliedQuoted 2 lines · Gleb Natapov
It is done for exception and interrupt already.
Applied, thanks.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.