Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 26 Apr 2015 20:06:22 +0000 (13:06 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 26 Apr 2015 20:06:22 +0000 (13:06 -0700)
Pull second batch of KVM changes from Paolo Bonzini:
 "This mostly includes the PPC changes for 4.1, which this time cover
  Book3S HV only (debugging aids, minor performance improvements and
  some cleanups).  But there are also bug fixes and small cleanups for
  ARM, x86 and s390.

  The task_migration_notifier revert and real fix is still pending
  review, but I'll send it as soon as possible after -rc1"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (29 commits)
  KVM: arm/arm64: check IRQ number on userland injection
  KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi
  KVM: VMX: Preserve host CR4.MCE value while in guest mode.
  KVM: PPC: Book3S HV: Use msgsnd for signalling threads on POWER8
  KVM: PPC: Book3S HV: Translate kvmhv_commence_exit to C
  KVM: PPC: Book3S HV: Streamline guest entry and exit
  KVM: PPC: Book3S HV: Use bitmap of active threads rather than count
  KVM: PPC: Book3S HV: Use decrementer to wake napping threads
  KVM: PPC: Book3S HV: Don't wake thread with no vcpu on guest IPI
  KVM: PPC: Book3S HV: Get rid of vcore nap_count and n_woken
  KVM: PPC: Book3S HV: Move vcore preemption point up into kvmppc_run_vcpu
  KVM: PPC: Book3S HV: Minor cleanups
  KVM: PPC: Book3S HV: Simplify handling of VCPUs that need a VPA update
  KVM: PPC: Book3S HV: Accumulate timing information for real-mode code
  KVM: PPC: Book3S HV: Create debugfs file for each guest's HPT
  KVM: PPC: Book3S HV: Add ICP real mode counters
  KVM: PPC: Book3S HV: Move virtual mode ICP functions to real-mode
  KVM: PPC: Book3S HV: Convert ICS mutex lock to spin lock
  KVM: PPC: Book3S HV: Add guest->host real mode completion counters
  KVM: PPC: Book3S HV: Add helpers for lock/unlock hpte
  ...

1  2 
arch/powerpc/include/asm/kvm_book3s.h
arch/powerpc/include/asm/kvm_book3s_64.h
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/powerpc.c

index 993090422690c748eeb9f272918724d0bc164e9f,578e550f937b418598c952d76f525cea6cce3497..b91e74a817d89742355e547c61b9ce36a243f11b
@@@ -106,6 -106,10 +106,6 @@@ struct kvmppc_vcpu_book3s 
        spinlock_t mmu_lock;
  };
  
 -#define CONTEXT_HOST          0
 -#define CONTEXT_GUEST         1
 -#define CONTEXT_GUEST_END     2
 -
  #define VSID_REAL     0x07ffffffffc00000ULL
  #define VSID_BAT      0x07ffffffffb00000ULL
  #define VSID_64K      0x0800000000000000ULL
@@@ -288,6 -292,9 +288,9 @@@ static inline bool kvmppc_supports_magi
        return !is_kvmppc_hv_enabled(vcpu->kvm);
  }
  
+ extern int kvmppc_h_logical_ci_load(struct kvm_vcpu *vcpu);
+ extern int kvmppc_h_logical_ci_store(struct kvm_vcpu *vcpu);
  /* Magic register values loaded into r3 and r4 before the 'sc' assembly
   * instruction for the OSI hypercalls */
  #define OSI_SC_MAGIC_R3                       0x113724FA
index 14619a59ec09b9ad93840803b9ff73e6b94ba53d,2b84e485a1815794b598bca98d0ac5ea6da28040..7ae407941be2741cbf4e3eec4df0da273a80d823
@@@ -85,6 -85,20 +85,20 @@@ static inline long try_lock_hpte(__be6
        return old == 0;
  }
  
+ static inline void unlock_hpte(__be64 *hpte, unsigned long hpte_v)
+ {
+       hpte_v &= ~HPTE_V_HVLOCK;
+       asm volatile(PPC_RELEASE_BARRIER "" : : : "memory");
+       hpte[0] = cpu_to_be64(hpte_v);
+ }
+ /* Without barrier */
+ static inline void __unlock_hpte(__be64 *hpte, unsigned long hpte_v)
+ {
+       hpte_v &= ~HPTE_V_HVLOCK;
+       hpte[0] = cpu_to_be64(hpte_v);
+ }
  static inline int __hpte_actual_psize(unsigned int lp, int psize)
  {
        int i, shift;
@@@ -290,11 -304,11 +304,11 @@@ static inline pte_t kvmppc_read_update_
        pte_t old_pte, new_pte = __pte(0);
  
        while (1) {
 -              old_pte = pte_val(*ptep);
 +              old_pte = *ptep;
                /*
                 * wait until _PAGE_BUSY is clear then set it atomically
                 */
 -              if (unlikely(old_pte & _PAGE_BUSY)) {
 +              if (unlikely(pte_val(old_pte) & _PAGE_BUSY)) {
                        cpu_relax();
                        continue;
                }
                        return __pte(0);
  #endif
                /* If pte is not present return None */
 -              if (unlikely(!(old_pte & _PAGE_PRESENT)))
 +              if (unlikely(!(pte_val(old_pte) & _PAGE_PRESENT)))
                        return __pte(0);
  
                new_pte = pte_mkyoung(old_pte);
                if (writing && pte_write(old_pte))
                        new_pte = pte_mkdirty(new_pte);
  
 -              if (old_pte == __cmpxchg_u64((unsigned long *)ptep, old_pte,
 -                                           new_pte))
 +              if (pte_val(old_pte) == __cmpxchg_u64((unsigned long *)ptep,
 +                                                    pte_val(old_pte),
 +                                                    pte_val(new_pte))) {
                        break;
 +              }
        }
        return new_pte;
  }
@@@ -337,7 -349,7 +351,7 @@@ static inline bool hpte_read_permission
  {
        if (key)
                return PP_RWRX <= pp && pp <= PP_RXRX;
 -      return 1;
 +      return true;
  }
  
  static inline bool hpte_write_permission(unsigned long pp, unsigned long key)
@@@ -375,7 -387,7 +389,7 @@@ static inline bool slot_is_aligned(stru
        unsigned long mask = (pagesize >> PAGE_SHIFT) - 1;
  
        if (pagesize <= PAGE_SIZE)
 -              return 1;
 +              return true;
        return !(memslot->base_gfn & mask) && !(memslot->npages & mask);
  }
  
@@@ -424,6 -436,10 +438,10 @@@ static inline struct kvm_memslots *kvm_
        return rcu_dereference_raw_notrace(kvm->memslots);
  }
  
+ extern void kvmppc_mmu_debugfs_init(struct kvm *kvm);
+ extern void kvmhv_rm_send_ipi(int cpu);
  #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  
  #endif /* __ASM_KVM_BOOK3S_64_H__ */
index c610961720c72aa075ee808f3f49044bb3664e5b,d67a83830bd1c04333e8087bb03b1ec52a034a16..a193a13cf08bf1dd40a51e393aeeab4456ce42b0
@@@ -227,10 -227,8 +227,8 @@@ struct kvm_arch 
        unsigned long host_sdr1;
        int tlbie_lock;
        unsigned long lpcr;
-       unsigned long rmor;
-       struct kvm_rma_info *rma;
        unsigned long vrma_slb_v;
-       int rma_setup_done;
+       int hpte_setup_done;
        u32 hpt_order;
        atomic_t vcpus_running;
        u32 online_vcores;
        atomic_t hpte_mod_interest;
        cpumask_t need_tlb_flush;
        int hpt_cma_alloc;
+       struct dentry *debugfs_dir;
+       struct dentry *htab_dentry;
  #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
  #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
        struct mutex hpt_mutex;
  
  /*
   * Struct for a virtual core.
-  * Note: entry_exit_count combines an entry count in the bottom 8 bits
-  * and an exit count in the next 8 bits.  This is so that we can
-  * atomically increment the entry count iff the exit count is 0
-  * without taking the lock.
+  * Note: entry_exit_map combines a bitmap of threads that have entered
+  * in the bottom 8 bits and a bitmap of threads that have exited in the
+  * next 8 bits.  This is so that we can atomically set the entry bit
+  * iff the exit map is 0 without taking a lock.
   */
  struct kvmppc_vcore {
        int n_runnable;
-       int n_busy;
        int num_threads;
-       int entry_exit_count;
-       int n_woken;
-       int nap_count;
+       int entry_exit_map;
        int napping_threads;
        int first_vcpuid;
        u16 pcpu;
        ulong conferring_threads;
  };
  
- #define VCORE_ENTRY_COUNT(vc) ((vc)->entry_exit_count & 0xff)
- #define VCORE_EXIT_COUNT(vc)  ((vc)->entry_exit_count >> 8)
+ #define VCORE_ENTRY_MAP(vc)   ((vc)->entry_exit_map & 0xff)
+ #define VCORE_EXIT_MAP(vc)    ((vc)->entry_exit_map >> 8)
+ #define VCORE_IS_EXITING(vc)  (VCORE_EXIT_MAP(vc) != 0)
  
  /* Values for vcore_state */
  #define VCORE_INACTIVE        0
  #define VCORE_SLEEPING        1
- #define VCORE_STARTING        2
+ #define VCORE_PREEMPT 2
  #define VCORE_RUNNING 3
  #define VCORE_EXITING 4
  
@@@ -368,6 -366,14 +366,14 @@@ struct kvmppc_slb 
        u8 base_page_size;      /* MMU_PAGE_xxx */
  };
  
+ /* Struct used to accumulate timing information in HV real mode code */
+ struct kvmhv_tb_accumulator {
+       u64     seqcount;       /* used to synchronize access, also count * 2 */
+       u64     tb_total;       /* total time in timebase ticks */
+       u64     tb_min;         /* min time */
+       u64     tb_max;         /* max time */
+ };
  # ifdef CONFIG_PPC_FSL_BOOK3E
  #define KVMPPC_BOOKE_IAC_NUM  2
  #define KVMPPC_BOOKE_DAC_NUM  2
@@@ -585,7 -591,7 +591,7 @@@ struct kvm_vcpu_arch 
        pgd_t *pgdir;
  
        u8 io_gpr; /* GPR used as IO source/target */
 -      u8 mmio_is_bigendian;
 +      u8 mmio_host_swabbed;
        u8 mmio_sign_extend;
        u8 osi_needed;
        u8 osi_enabled;
  
        u32 emul_inst;
  #endif
+ #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
+       struct kvmhv_tb_accumulator *cur_activity;      /* What we're timing */
+       u64     cur_tb_start;                   /* when it started */
+       struct kvmhv_tb_accumulator rm_entry;   /* real-mode entry code */
+       struct kvmhv_tb_accumulator rm_intr;    /* real-mode intr handling */
+       struct kvmhv_tb_accumulator rm_exit;    /* real-mode exit code */
+       struct kvmhv_tb_accumulator guest_time; /* guest execution */
+       struct kvmhv_tb_accumulator cede_time;  /* time napping inside guest */
+       struct dentry *debugfs_dir;
+       struct dentry *debugfs_timings;
+ #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
  };
  
  #define VCPU_FPR(vcpu, i)     (vcpu)->arch.fp.fpr[i][TS_FPROFFSET]
index 91bbc845ac6654d994010ae847fd5ec977be0698,55a4763d6d115d38877eac0871b3ba21e4fa65c4..ac3ddf115f3d852db205c72e79f2b592c6ef9e99
@@@ -529,6 -529,9 +529,9 @@@ int kvm_vm_ioctl_check_extension(struc
        case KVM_CAP_PPC_RMA:
                r = 0;
                break;
+       case KVM_CAP_PPC_HWRNG:
+               r = kvmppc_hwrng_present();
+               break;
  #endif
        case KVM_CAP_SYNC_MMU:
  #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
@@@ -720,7 -723,7 +723,7 @@@ static void kvmppc_complete_mmio_load(s
                return;
        }
  
 -      if (vcpu->arch.mmio_is_bigendian) {
 +      if (!vcpu->arch.mmio_host_swabbed) {
                switch (run->mmio.len) {
                case 8: gpr = *(u64 *)run->mmio.data; break;
                case 4: gpr = *(u32 *)run->mmio.data; break;
                case 1: gpr = *(u8 *)run->mmio.data; break;
                }
        } else {
 -              /* Convert BE data from userland back to LE. */
                switch (run->mmio.len) {
 -              case 4: gpr = ld_le32((u32 *)run->mmio.data); break;
 -              case 2: gpr = ld_le16((u16 *)run->mmio.data); break;
 +              case 8: gpr = swab64(*(u64 *)run->mmio.data); break;
 +              case 4: gpr = swab32(*(u32 *)run->mmio.data); break;
 +              case 2: gpr = swab16(*(u16 *)run->mmio.data); break;
                case 1: gpr = *(u8 *)run->mmio.data; break;
                }
        }
@@@ -780,13 -783,14 +783,13 @@@ int kvmppc_handle_load(struct kvm_run *
                       int is_default_endian)
  {
        int idx, ret;
 -      int is_bigendian;
 +      bool host_swabbed;
  
 +      /* Pity C doesn't have a logical XOR operator */
        if (kvmppc_need_byteswap(vcpu)) {
 -              /* Default endianness is "little endian". */
 -              is_bigendian = !is_default_endian;
 +              host_swabbed = is_default_endian;
        } else {
 -              /* Default endianness is "big endian". */
 -              is_bigendian = is_default_endian;
 +              host_swabbed = !is_default_endian;
        }
  
        if (bytes > sizeof(run->mmio.data)) {
        run->mmio.is_write = 0;
  
        vcpu->arch.io_gpr = rt;
 -      vcpu->arch.mmio_is_bigendian = is_bigendian;
 +      vcpu->arch.mmio_host_swabbed = host_swabbed;
        vcpu->mmio_needed = 1;
        vcpu->mmio_is_write = 0;
        vcpu->arch.mmio_sign_extend = 0;
@@@ -839,13 -843,14 +842,13 @@@ int kvmppc_handle_store(struct kvm_run 
  {
        void *data = run->mmio.data;
        int idx, ret;
 -      int is_bigendian;
 +      bool host_swabbed;
  
 +      /* Pity C doesn't have a logical XOR operator */
        if (kvmppc_need_byteswap(vcpu)) {
 -              /* Default endianness is "little endian". */
 -              is_bigendian = !is_default_endian;
 +              host_swabbed = is_default_endian;
        } else {
 -              /* Default endianness is "big endian". */
 -              is_bigendian = is_default_endian;
 +              host_swabbed = !is_default_endian;
        }
  
        if (bytes > sizeof(run->mmio.data)) {
        vcpu->mmio_is_write = 1;
  
        /* Store the value at the lowest bytes in 'data'. */
 -      if (is_bigendian) {
 +      if (!host_swabbed) {
                switch (bytes) {
                case 8: *(u64 *)data = val; break;
                case 4: *(u32 *)data = val; break;
                case 1: *(u8  *)data = val; break;
                }
        } else {
 -              /* Store LE value into 'data'. */
                switch (bytes) {
 -              case 4: st_le32(data, val); break;
 -              case 2: st_le16(data, val); break;
 -              case 1: *(u8 *)data = val; break;
 +              case 8: *(u64 *)data = swab64(val); break;
 +              case 4: *(u32 *)data = swab32(val); break;
 +              case 2: *(u16 *)data = swab16(val); break;
 +              case 1: *(u8  *)data = val; break;
                }
        }