Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 3 Oct 2020 19:19:23 +0000 (12:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 3 Oct 2020 19:19:23 +0000 (12:19 -0700)
Pull kvm fixes from Paolo Bonzini:
 "Two bugfixes"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
  KVM: VMX: update PFEC_MASK/PFEC_MATCH together with PF intercept
  KVM: arm64: Restore missing ISB on nVHE __tlb_switch_to_guest

1  2 
arch/x86/kvm/vmx/vmx.c

diff --combined arch/x86/kvm/vmx/vmx.c
@@@ -794,6 -794,18 +794,18 @@@ void update_exception_bitmap(struct kvm
         */
        if (is_guest_mode(vcpu))
                eb |= get_vmcs12(vcpu)->exception_bitmap;
+         else {
+               /*
+                * If EPT is enabled, #PF is only trapped if MAXPHYADDR is mismatched
+                * between guest and host.  In that case we only care about present
+                * faults.  For vmcs02, however, PFEC_MASK and PFEC_MATCH are set in
+                * prepare_vmcs02_rare.
+                */
+               bool selective_pf_trap = enable_ept && (eb & (1u << PF_VECTOR));
+               int mask = selective_pf_trap ? PFERR_PRESENT_MASK : 0;
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, mask);
+               vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, mask);
+       }
  
        vmcs_write32(EXCEPTION_BITMAP, eb);
  }
@@@ -4355,16 -4367,6 +4367,6 @@@ static void init_vmcs(struct vcpu_vmx *
                vmx->pt_desc.guest.output_mask = 0x7F;
                vmcs_write64(GUEST_IA32_RTIT_CTL, 0);
        }
-       /*
-        * If EPT is enabled, #PF is only trapped if MAXPHYADDR is mismatched
-        * between guest and host.  In that case we only care about present
-        * faults.
-        */
-       if (enable_ept) {
-               vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, PFERR_PRESENT_MASK);
-               vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, PFERR_PRESENT_MASK);
-       }
  }
  
  static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
@@@ -4657,7 -4659,7 +4659,7 @@@ static bool rmode_exception(struct kvm_
                        vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
                if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
                        return false;
 -              /* fall through */
 +              fallthrough;
        case DB_VECTOR:
                return !(vcpu->guest_debug &
                        (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));
@@@ -4831,7 -4833,7 +4833,7 @@@ static int handle_exception_nmi(struct 
                }
                kvm_run->debug.arch.dr6 = dr6 | DR6_FIXED_1 | DR6_RTM;
                kvm_run->debug.arch.dr7 = vmcs_readl(GUEST_DR7);
 -              /* fall through */
 +              fallthrough;
        case BP_VECTOR:
                /*
                 * Update instruction length as we may reinject #BP from
@@@ -5261,7 -5263,7 +5263,7 @@@ static int handle_task_switch(struct kv
                                error_code =
                                        vmcs_read32(IDT_VECTORING_ERROR_CODE);
                        }
 -                      /* fall through */
 +                      fallthrough;
                case INTR_TYPE_SOFT_EXCEPTION:
                        kvm_clear_exception_queue(vcpu);
                        break;
@@@ -5614,7 -5616,7 +5616,7 @@@ static int handle_invpcid(struct kvm_vc
                 * keeping track of global entries in shadow page tables.
                 */
  
 -              /* fall-through */
 +              fallthrough;
        case INVPCID_TYPE_ALL_INCL_GLOBAL:
                kvm_mmu_unload(vcpu);
                return kvm_skip_emulated_instruction(vcpu);
@@@ -6583,7 -6585,7 +6585,7 @@@ static void __vmx_complete_interrupts(s
                break;
        case INTR_TYPE_SOFT_EXCEPTION:
                vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
 -              /* fall through */
 +              fallthrough;
        case INTR_TYPE_HARD_EXCEPTION:
                if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
                        u32 err = vmcs_read32(error_code_field);
                break;
        case INTR_TYPE_SOFT_INTR:
                vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
 -              /* fall through */
 +              fallthrough;
        case INTR_TYPE_EXT_INTR:
                kvm_queue_interrupt(vcpu, vector, type == INTR_TYPE_SOFT_INTR);
                break;