Merge tag 'kvm-arm-fixes-for-v4.19-v2' of git://git.kernel.org/pub/scm/linux/kernel...
authorRadim Krčmář <rkrcmar@redhat.com>
Fri, 7 Sep 2018 16:38:25 +0000 (18:38 +0200)
committerRadim Krčmář <rkrcmar@redhat.com>
Fri, 7 Sep 2018 16:38:25 +0000 (18:38 +0200)
Fixes for KVM/ARM for Linux v4.19 v2:

 - Fix a VFP corruption in 32-bit guest
 - Add missing cache invalidation for CoW pages
 - Two small cleanups

1  2 
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/mmu.c

index e12916e7c2fbb06942af5971f98688c3b351e75d,e6a33420b8712e8d98d01e7c67383d8a8ce2b3df..3ad10f634d4c3fe2ce71996355ddf38ca4e465c0
@@@ -1237,12 -1237,19 +1237,12 @@@ enum emulation_result 
  #define EMULTYPE_NO_DECODE        (1 << 0)
  #define EMULTYPE_TRAP_UD          (1 << 1)
  #define EMULTYPE_SKIP             (1 << 2)
 -#define EMULTYPE_RETRY                    (1 << 3)
 -#define EMULTYPE_NO_REEXECUTE     (1 << 4)
 -#define EMULTYPE_NO_UD_ON_FAIL            (1 << 5)
 -#define EMULTYPE_VMWARE                   (1 << 6)
 -int x86_emulate_instruction(struct kvm_vcpu *vcpu, unsigned long cr2,
 -                          int emulation_type, void *insn, int insn_len);
 -
 -static inline int emulate_instruction(struct kvm_vcpu *vcpu,
 -                      int emulation_type)
 -{
 -      return x86_emulate_instruction(vcpu, 0,
 -                      emulation_type | EMULTYPE_NO_REEXECUTE, NULL, 0);
 -}
 +#define EMULTYPE_ALLOW_RETRY      (1 << 3)
 +#define EMULTYPE_NO_UD_ON_FAIL            (1 << 4)
 +#define EMULTYPE_VMWARE                   (1 << 5)
 +int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type);
 +int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu,
 +                                      void *insn, int insn_len);
  
  void kvm_enable_efer_bits(u64);
  bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer);
@@@ -1443,7 -1450,6 +1443,6 @@@ asmlinkage void kvm_spurious_fault(void
        ____kvm_handle_fault_on_reboot(insn, "")
  
  #define KVM_ARCH_WANT_MMU_NOTIFIER
- int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
  int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end);
  int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
  int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
diff --combined arch/x86/kvm/mmu.c
index f7e83b1e0eb27eb8b8e0b9093bb23826539cb2de,d440154e8938ccf9dfb8c6749475cea4085d199a..e24ea7067373af69d258c46995007b0446a69fdc
@@@ -1853,11 -1853,6 +1853,6 @@@ static int kvm_handle_hva(struct kvm *k
        return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler);
  }
  
- int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
- {
-       return kvm_handle_hva(kvm, hva, 0, kvm_unmap_rmapp);
- }
  int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long end)
  {
        return kvm_handle_hva_range(kvm, start, end, 0, kvm_unmap_rmapp);
@@@ -5217,7 -5212,7 +5212,7 @@@ static int make_mmu_pages_available(str
  int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u64 error_code,
                       void *insn, int insn_len)
  {
 -      int r, emulation_type = EMULTYPE_RETRY;
 +      int r, emulation_type = 0;
        enum emulation_result er;
        bool direct = vcpu->arch.mmu.direct_map;
  
        r = RET_PF_INVALID;
        if (unlikely(error_code & PFERR_RSVD_MASK)) {
                r = handle_mmio_page_fault(vcpu, cr2, direct);
 -              if (r == RET_PF_EMULATE) {
 -                      emulation_type = 0;
 +              if (r == RET_PF_EMULATE)
                        goto emulate;
 -              }
        }
  
        if (r == RET_PF_INVALID) {
                return 1;
        }
  
 -      if (mmio_info_in_cache(vcpu, cr2, direct))
 -              emulation_type = 0;
 +      /*
 +       * vcpu->arch.mmu.page_fault returned RET_PF_EMULATE, but we can still
 +       * optimistically try to just unprotect the page and let the processor
 +       * re-execute the instruction that caused the page fault.  Do not allow
 +       * retrying MMIO emulation, as it's not only pointless but could also
 +       * cause us to enter an infinite loop because the processor will keep
 +       * faulting on the non-existent MMIO address.  Retrying an instruction
 +       * from a nested guest is also pointless and dangerous as we are only
 +       * explicitly shadowing L1's page tables, i.e. unprotecting something
 +       * for L1 isn't going to magically fix whatever issue cause L2 to fail.
 +       */
 +      if (!mmio_info_in_cache(vcpu, cr2, direct) && !is_guest_mode(vcpu))
 +              emulation_type = EMULTYPE_ALLOW_RETRY;
  emulate:
        /*
         * On AMD platforms, under certain conditions insn_len may be zero on #NPF.