Re: [PATCH 1/1] kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access migration.

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 04:09, Tang Chen ha scritto:
 Hi Paolo, 
 
 I'm not sure if this patch is following your comment. Please review.
 And all the other comments are followed. If this patch is OK, I'll 
 send v8 soon.
 
 Thanks.
 
 We are handling L1 and L2 share one apic access page situation when 
 migrating
 apic access page. We should do some handling when migration happens in the
 following situations:
 
1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
   vmcs in the next L1-L2 entry.
 
2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
   L0-L1 entry and L2's vmcs in the next L1-L2 entry.
 
3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
   L0-L2 entry and L1's vmcs in the next L2-L1 exit.
 
 This patch force a L1-L0 exit or L2-L0 exit when shared apic access page is
 migrated using mmu notifier. Since apic access page is only used on intel x86,
 this is arch specific code.
 ---
  arch/arm/include/asm/kvm_host.h |  6 ++
  arch/arm64/include/asm/kvm_host.h   |  6 ++
  arch/ia64/include/asm/kvm_host.h|  8 
  arch/mips/include/asm/kvm_host.h|  7 +++
  arch/powerpc/include/asm/kvm_host.h |  6 ++
  arch/s390/include/asm/kvm_host.h|  9 +
  arch/x86/include/asm/kvm_host.h |  2 ++
  arch/x86/kvm/x86.c  | 11 +++
  virt/kvm/kvm_main.c |  3 +++
  9 files changed, 58 insertions(+)
 
 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
 index 6dfb404..79bbf7d 100644
 --- a/arch/arm/include/asm/kvm_host.h
 +++ b/arch/arm/include/asm/kvm_host.h
 @@ -182,6 +182,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
 unsigned long hva)
   return 0;
  }
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
 diff --git a/arch/arm64/include/asm/kvm_host.h 
 b/arch/arm64/include/asm/kvm_host.h
 index e10c45a..ee89fad 100644
 --- a/arch/arm64/include/asm/kvm_host.h
 +++ b/arch/arm64/include/asm/kvm_host.h
 @@ -192,6 +192,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
 unsigned long hva)
   return 0;
  }
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
 diff --git a/arch/ia64/include/asm/kvm_host.h 
 b/arch/ia64/include/asm/kvm_host.h
 index db95f57..326ac55 100644
 --- a/arch/ia64/include/asm/kvm_host.h
 +++ b/arch/ia64/include/asm/kvm_host.h
 @@ -574,6 +574,14 @@ static inline struct kvm_pt_regs *vcpu_regs(struct 
 kvm_vcpu *v)
   return (struct kvm_pt_regs *) ((unsigned long) v + KVM_STK_OFFSET) - 1;
  }
  
 +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
 +
  typedef int kvm_vmm_entry(void);
  typedef void kvm_tramp_entry(union context *host, union context *guest);
  
 diff --git a/arch/mips/include/asm/kvm_host.h 
 b/arch/mips/include/asm/kvm_host.h
 index 7a3fc67..c392705 100644
 --- a/arch/mips/include/asm/kvm_host.h
 +++ b/arch/mips/include/asm/kvm_host.h
 @@ -767,5 +767,12 @@ extern int kvm_mips_trans_mtc0(uint32_t inst, uint32_t 
 *opc,
  extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu);
  extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
  
 +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
  
  #endif /* __MIPS_KVM_HOST_H__ */
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index 98d9dd5..c16a573 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -61,6 +61,12 @@ extern int kvm_age_hva(struct kvm *kvm, unsigned long hva);
  extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
  extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +
  #define HPTEG_CACHE_NUM  (1  15)
  #define HPTEG_HASH_BITS_PTE  13
  #define HPTEG_HASH_BITS_PTE_LONG 12
 diff --git a/arch/s390/include/asm/kvm_host.h 
 b/arch/s390/include/asm/kvm_host.h
 index 773bef7..693290f 100644
 

Re: [PATCH v4] kvm: Fix page ageing bugs

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 04:27, Wanpeng Li ha scritto:
 Hi Andres,
 On Mon, Sep 22, 2014 at 02:54:42PM -0700, Andres Lagar-Cavilla wrote:
 1. We were calling clear_flush_young_notify in unmap_one, but we are
 within an mmu notifier invalidate range scope. The spte exists no more
 (due to range_start) and the accessed bit info has already been
 propagated (due to kvm_pfn_set_accessed). Simply call
 clear_flush_young.

 2. We clear_flush_young on a primary MMU PMD, but this may be mapped
 as a collection of PTEs by the secondary MMU (e.g. during log-dirty).
 This required expanding the interface of the clear_flush_young mmu
 notifier, so a lot of code has been trivially touched.

 3. In the absence of shadow_accessed_mask (e.g. EPT A bit), we emulate
 the access bit by blowing the spte. This requires proper synchronizing
 with MMU notifier consumers, like every other removal of spte's does.

 [...]
 ---
 +BUG_ON(!shadow_accessed_mask);

  for (sptep = rmap_get_first(*rmapp, iter); sptep;
   sptep = rmap_get_next(iter)) {
 +struct kvm_mmu_page *sp;
 +gfn_t gfn;
  BUG_ON(!is_shadow_present_pte(*sptep));
 +/* From spte to gfn. */
 +sp = page_header(__pa(sptep));
 +gfn = kvm_mmu_page_get_gfn(sp, sptep - sp-spt);

  if (*sptep  shadow_accessed_mask) {
  young = 1;
  clear_bit((ffs(shadow_accessed_mask) - 1),
   (unsigned long *)sptep);
  }
 +trace_kvm_age_page(gfn, slot, young);
 
 IIUC, all the rmapps in this for loop are against the same gfn which
 results in the above trace point dump the message duplicated.

You're right; Andres's patch [PATCH] kvm/x86/mmu: Pass gfn and level to
rmapp callback helps avoiding that.

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access migration.

2014-09-24 Thread Jan Kiszka
On 2014-09-24 04:09, Tang Chen wrote:
 Hi Paolo, 
 
 I'm not sure if this patch is following your comment. Please review.
 And all the other comments are followed. If this patch is OK, I'll 
 send v8 soon.
 
 Thanks.
 
 We are handling L1 and L2 share one apic access page situation when 
 migrating
 apic access page. We should do some handling when migration happens in the
 following situations:
 
1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
   vmcs in the next L1-L2 entry.
 
2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
   L0-L1 entry and L2's vmcs in the next L1-L2 entry.
 
3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
   L0-L2 entry and L1's vmcs in the next L2-L1 exit.
 
 This patch force a L1-L0 exit or L2-L0 exit when shared apic access page is
 migrated using mmu notifier. Since apic access page is only used on intel x86,
 this is arch specific code.
 ---
  arch/arm/include/asm/kvm_host.h |  6 ++
  arch/arm64/include/asm/kvm_host.h   |  6 ++
  arch/ia64/include/asm/kvm_host.h|  8 
  arch/mips/include/asm/kvm_host.h|  7 +++
  arch/powerpc/include/asm/kvm_host.h |  6 ++
  arch/s390/include/asm/kvm_host.h|  9 +
  arch/x86/include/asm/kvm_host.h |  2 ++
  arch/x86/kvm/x86.c  | 11 +++
  virt/kvm/kvm_main.c |  3 +++
  9 files changed, 58 insertions(+)
 
 diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
 index 6dfb404..79bbf7d 100644
 --- a/arch/arm/include/asm/kvm_host.h
 +++ b/arch/arm/include/asm/kvm_host.h
 @@ -182,6 +182,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
 unsigned long hva)
   return 0;
  }
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;

Redundant return, more cases below.

Jan

 +}
 +
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
 diff --git a/arch/arm64/include/asm/kvm_host.h 
 b/arch/arm64/include/asm/kvm_host.h
 index e10c45a..ee89fad 100644
 --- a/arch/arm64/include/asm/kvm_host.h
 +++ b/arch/arm64/include/asm/kvm_host.h
 @@ -192,6 +192,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
 unsigned long hva)
   return 0;
  }
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
 diff --git a/arch/ia64/include/asm/kvm_host.h 
 b/arch/ia64/include/asm/kvm_host.h
 index db95f57..326ac55 100644
 --- a/arch/ia64/include/asm/kvm_host.h
 +++ b/arch/ia64/include/asm/kvm_host.h
 @@ -574,6 +574,14 @@ static inline struct kvm_pt_regs *vcpu_regs(struct 
 kvm_vcpu *v)
   return (struct kvm_pt_regs *) ((unsigned long) v + KVM_STK_OFFSET) - 1;
  }
  
 +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
 +
  typedef int kvm_vmm_entry(void);
  typedef void kvm_tramp_entry(union context *host, union context *guest);
  
 diff --git a/arch/mips/include/asm/kvm_host.h 
 b/arch/mips/include/asm/kvm_host.h
 index 7a3fc67..c392705 100644
 --- a/arch/mips/include/asm/kvm_host.h
 +++ b/arch/mips/include/asm/kvm_host.h
 @@ -767,5 +767,12 @@ extern int kvm_mips_trans_mtc0(uint32_t inst, uint32_t 
 *opc,
  extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu);
  extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
  
 +#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
  
  #endif /* __MIPS_KVM_HOST_H__ */
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index 98d9dd5..c16a573 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -61,6 +61,12 @@ extern int kvm_age_hva(struct kvm *kvm, unsigned long hva);
  extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
  extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  
 +static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
 +  unsigned long address)
 +{
 + return;
 +}
 +
  #define HPTEG_CACHE_NUM  (1  15)
  #define HPTEG_HASH_BITS_PTE  13
  #define HPTEG_HASH_BITS_PTE_LONG 12
 diff --git a/arch/s390/include/asm/kvm_host.h 
 

Re: [PATCH v4] kvm: Fix page ageing bugs

2014-09-24 Thread Wanpeng Li

Hi Paolo,
于 9/24/14, 3:04 PM, Paolo Bonzini 写道:

Il 24/09/2014 04:27, Wanpeng Li ha scritto:

Hi Andres,
On Mon, Sep 22, 2014 at 02:54:42PM -0700, Andres Lagar-Cavilla wrote:

1. We were calling clear_flush_young_notify in unmap_one, but we are
within an mmu notifier invalidate range scope. The spte exists no more
(due to range_start) and the accessed bit info has already been
propagated (due to kvm_pfn_set_accessed). Simply call
clear_flush_young.

2. We clear_flush_young on a primary MMU PMD, but this may be mapped
as a collection of PTEs by the secondary MMU (e.g. during log-dirty).
This required expanding the interface of the clear_flush_young mmu
notifier, so a lot of code has been trivially touched.

3. In the absence of shadow_accessed_mask (e.g. EPT A bit), we emulate
the access bit by blowing the spte. This requires proper synchronizing
with MMU notifier consumers, like every other removal of spte's does.


[...]

---
+   BUG_ON(!shadow_accessed_mask);

for (sptep = rmap_get_first(*rmapp, iter); sptep;
 sptep = rmap_get_next(iter)) {
+   struct kvm_mmu_page *sp;
+   gfn_t gfn;
BUG_ON(!is_shadow_present_pte(*sptep));
+   /* From spte to gfn. */
+   sp = page_header(__pa(sptep));
+   gfn = kvm_mmu_page_get_gfn(sp, sptep - sp-spt);

if (*sptep  shadow_accessed_mask) {
young = 1;
clear_bit((ffs(shadow_accessed_mask) - 1),
 (unsigned long *)sptep);
}
+   trace_kvm_age_page(gfn, slot, young);

IIUC, all the rmapps in this for loop are against the same gfn which
results in the above trace point dump the message duplicated.

You're right; Andres's patch [PATCH] kvm/x86/mmu: Pass gfn and level to
rmapp callback helps avoiding that.


From Andres's patch [PATCH] kvm/x86/mmu: Pass gfn and level to rmapp 
callback


@@ -1410,25 +1421,20 @@ static int kvm_age_rmapp(struct kvm *kvm, 
unsigned long *rmapp,


for (sptep = rmap_get_first(*rmapp, iter); sptep;
sptep = rmap_get_next(iter)) {
- struct kvm_mmu_page *sp;
- gfn_t gfn;
BUG_ON(!is_shadow_present_pte(*sptep));
- /* From spte to gfn. */
- sp = page_header(__pa(sptep));
- gfn = kvm_mmu_page_get_gfn(sp, sptep - sp-spt);
-
if (*sptep  shadow_accessed_mask) {
young = 1;
clear_bit((ffs(shadow_accessed_mask) - 1),
(unsigned long *)sptep);
}
- trace_kvm_age_page(gfn, slot, young);
+ trace_kvm_age_page(gfn, level, slot, young);
}
return young;
}


This trace point still dup duplicated message for the same gfn in the 
for loop.


Regards,
Wanpeng Li



Paolo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/1] kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access migration.

2014-09-24 Thread Tang Chen


On 09/24/2014 03:08 PM, Jan Kiszka wrote:

On 2014-09-24 04:09, Tang Chen wrote:

Hi Paolo,

I'm not sure if this patch is following your comment. Please review.
And all the other comments are followed. If this patch is OK, I'll
send v8 soon.

Thanks.

We are handling L1 and L2 share one apic access page situation when migrating
apic access page. We should do some handling when migration happens in the
following situations:

1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
   vmcs in the next L1-L2 entry.

2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
   L0-L1 entry and L2's vmcs in the next L1-L2 entry.

3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
   L0-L2 entry and L1's vmcs in the next L2-L1 exit.

This patch force a L1-L0 exit or L2-L0 exit when shared apic access page is
migrated using mmu notifier. Since apic access page is only used on intel x86,
this is arch specific code.
---
  arch/arm/include/asm/kvm_host.h |  6 ++
  arch/arm64/include/asm/kvm_host.h   |  6 ++
  arch/ia64/include/asm/kvm_host.h|  8 
  arch/mips/include/asm/kvm_host.h|  7 +++
  arch/powerpc/include/asm/kvm_host.h |  6 ++
  arch/s390/include/asm/kvm_host.h|  9 +
  arch/x86/include/asm/kvm_host.h |  2 ++
  arch/x86/kvm/x86.c  | 11 +++
  virt/kvm/kvm_main.c |  3 +++
  9 files changed, 58 insertions(+)

diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 6dfb404..79bbf7d 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -182,6 +182,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
unsigned long hva)
return 0;
  }
  
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,

+unsigned long address)
+{
+   return;

Redundant return, more cases below.


OK, will remove it. Thanks.



Jan


+}
+
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h

index e10c45a..ee89fad 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -192,6 +192,12 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
unsigned long hva)
return 0;
  }
  
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,

+unsigned long address)
+{
+   return;
+}
+
  struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
  struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
  
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h

index db95f57..326ac55 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -574,6 +574,14 @@ static inline struct kvm_pt_regs *vcpu_regs(struct 
kvm_vcpu *v)
return (struct kvm_pt_regs *) ((unsigned long) v + KVM_STK_OFFSET) - 1;
  }
  
+#ifdef KVM_ARCH_WANT_MMU_NOTIFIER

+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+   return;
+}
+#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
+
  typedef int kvm_vmm_entry(void);
  typedef void kvm_tramp_entry(union context *host, union context *guest);
  
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h

index 7a3fc67..c392705 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -767,5 +767,12 @@ extern int kvm_mips_trans_mtc0(uint32_t inst, uint32_t 
*opc,
  extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu);
  extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
  
+#ifdef KVM_ARCH_WANT_MMU_NOTIFIER

+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+   return;
+}
+#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
  
  #endif /* __MIPS_KVM_HOST_H__ */

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 98d9dd5..c16a573 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -61,6 +61,12 @@ extern int kvm_age_hva(struct kvm *kvm, unsigned long hva);
  extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
  extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
  
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,

+unsigned long address)
+{
+   return;
+}
+
  #define HPTEG_CACHE_NUM   (1  15)
  #define HPTEG_HASH_BITS_PTE   13
  #define HPTEG_HASH_BITS_PTE_LONG  12
diff --git a/arch/s390/include/asm/kvm_host.h 

[PATCH v8 0/8] kvm, mem-hotplug: Do not pin ept identity pagetable and apic access page.

2014-09-24 Thread Tang Chen
ept identity pagetable and apic access page in kvm are pinned in memory.
As a result, they cannot be migrated/hot-removed.

But actually they don't need to be pinned in memory.

[For ept identity page]
Just do not pin it. When it is migrated, guest will be able to find the
new page in the next ept violation.

[For apic access page]
The hpa of apic access page is stored in VMCS APIC_ACCESS_ADDR pointer.
When apic access page is migrated, we update VMCS APIC_ACCESS_ADDR pointer
for each vcpu in addition.

This patch-set is based on Linux 3.17.0-rc5.

NOTE: Tested with -cpu xxx,-x2apic option.
  But since nested vm pins some other pages in memory, if user uses nested
  vm, memory hot-remove will not work.

Change log v7-v8:
1. Patch 1/9~3/9 were applied to kvm/queue by Paolo Bonzini 
pbonz...@redhat.com.
   Just resend them, no changes.
2. Removed previous patch 4/9, which added unnecessary hook 
has_secondary_apic_access().
3. Set kvm_x86_ops-set_apic_access_page_addr to NULL when hardware had no 
flexpriority
   functionality which actually exists only on x86. 
4. Moved declaration of kvm_arch_mmu_notifier_invalidate_page() to 
arch/*/include/asm/kvm_host.h.
5. Removed useless set_apic_access_page_addr() hook for svm.

Tang Chen (8):
  kvm: Use APIC_DEFAULT_PHYS_BASE macro as the apic access page address.
  kvm: Remove ept_identity_pagetable from struct kvm_arch.
  kvm: Make init_rmode_identity_map() return 0 on success.
  kvm, mem-hotplug: Reload L1's apic access page in vcpu_enter_guest().
  kvm: Rename make_all_cpus_request() to kvm_make_all_cpus_request() and
make it non-static.
  kvm, mem-hotplug: Reload L1's apic access page on migration when L2 is
running.
  kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access
migration.
  kvm, mem-hotplug: Unpin and remove kvm_arch-apic_access_page.

 arch/arm/include/asm/kvm_host.h |   5 ++
 arch/arm64/include/asm/kvm_host.h   |   5 ++
 arch/ia64/include/asm/kvm_host.h|   7 ++
 arch/mips/include/asm/kvm_host.h|   6 ++
 arch/powerpc/include/asm/kvm_host.h |   5 ++
 arch/s390/include/asm/kvm_host.h|   8 +++
 arch/x86/include/asm/kvm_host.h |   7 +-
 arch/x86/kvm/svm.c  |   3 +-
 arch/x86/kvm/vmx.c  | 130 
 arch/x86/kvm/x86.c  |  45 +++--
 include/linux/kvm_host.h|   2 +
 virt/kvm/kvm_main.c |  13 ++--
 12 files changed, 180 insertions(+), 56 deletions(-)

-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 6/8] kvm, mem-hotplug: Reload L1's apic access page on migration when L2 is running.

2014-09-24 Thread Tang Chen
We are handling L1 and L2 share one apic access page situation when migrating
apic access page. We should do some handling when migration happens in the
following situations:

   1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
  vmcs in the next L1-L2 entry.

   2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
  L0-L1 entry and L2's vmcs in the next L1-L2 entry.

   3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
  L0-L2 entry and L1's vmcs in the next L2-L1 exit.

This patch handles 3).

In L0-L2 entry, L2's vmcs will be updated in prepare_vmcs02() called by
nested_vm_run(). So we need to do nothing.

In L2-L1 exit, this patch requests apic access page reload in L2-L1 vmexit.

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/vmx.c  | 6 ++
 arch/x86/kvm/x86.c  | 3 ++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 582cd0f..66480fd 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1046,6 +1046,7 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
 int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
 int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
 void kvm_vcpu_reset(struct kvm_vcpu *vcpu);
+void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu);
 
 void kvm_define_shared_msr(unsigned index, u32 msr);
 void kvm_set_shared_msr(unsigned index, u64 val, u64 mask);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 1411bab..40bb9fc 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -8826,6 +8826,12 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 
exit_reason,
}
 
/*
+* We are now running in L2, mmu_notifier will force to reload the
+* page's hpa for L2 vmcs. Need to reload it for L1 before entering L1.
+*/
+   kvm_vcpu_reload_apic_access_page(vcpu);
+
+   /*
 * Exiting from L2 to L1, we're now back to L1 which thinks it just
 * finished a VMLAUNCH or VMRESUME instruction, so we need to set the
 * success or failure flag accordingly.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1f0c99a..c064ca6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5989,7 +5989,7 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
kvm_apic_update_tmr(vcpu, tmr);
 }
 
-static void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
+void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
 {
/*
 * If platform doesn't have 2nd exec virtualize apic access affinity,
@@ -6009,6 +6009,7 @@ static void kvm_vcpu_reload_apic_access_page(struct 
kvm_vcpu *vcpu)
kvm_x86_ops-set_apic_access_page_addr(vcpu,
page_to_phys(vcpu-kvm-arch.apic_access_page));
 }
+EXPORT_SYMBOL_GPL(kvm_vcpu_reload_apic_access_page);
 
 /*
  * Returns 1 to let __vcpu_run() continue the guest execution loop without
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 8/8] kvm, mem-hotplug: Unpin and remove kvm_arch-apic_access_page.

2014-09-24 Thread Tang Chen
To make apic access page migratable, we do not pin it in memory now.
When it is migrated, we should reload its physical address for all
vmcses. But when we tried to do this, all vcpu will access
kvm_arch-apic_access_page without any locking. This is not safe.

Actually, we do not need kvm_arch-apic_access_page anymore. Since
apic access page is not pinned in memory now, we can remove
kvm_arch-apic_access_page. When we need to write its physical address
into vmcs, use gfn_to_page() to get its page struct, which will also
pin it. And unpin it after then.

Suggested-by: Gleb Natapov g...@kernel.org
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 arch/x86/include/asm/kvm_host.h |  2 +-
 arch/x86/kvm/vmx.c  | 17 ++---
 arch/x86/kvm/x86.c  | 16 ++--
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 408b944..e27e1f9 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -576,7 +576,7 @@ struct kvm_arch {
struct kvm_apic_map *apic_map;
 
unsigned int tss_addr;
-   struct page *apic_access_page;
+   bool apic_access_page_done;
 
gpa_t wall_clock;
 
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 40bb9fc..4069075 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4010,7 +4010,7 @@ static int alloc_apic_access_page(struct kvm *kvm)
int r = 0;
 
mutex_lock(kvm-slots_lock);
-   if (kvm-arch.apic_access_page)
+   if (kvm-arch.apic_access_page_done)
goto out;
kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
@@ -4026,7 +4026,12 @@ static int alloc_apic_access_page(struct kvm *kvm)
goto out;
}
 
-   kvm-arch.apic_access_page = page;
+   /*
+* Do not pin apic access page in memory so that memory hotplug
+* process is able to migrate it.
+*/
+   put_page(page);
+   kvm-arch.apic_access_page_done = true;
 out:
mutex_unlock(kvm-slots_lock);
return r;
@@ -4541,9 +4546,8 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu)
vmcs_write32(TPR_THRESHOLD, 0);
}
 
-   if (vm_need_virtualize_apic_accesses(vmx-vcpu.kvm))
-   vmcs_write64(APIC_ACCESS_ADDR,
-
page_to_phys(vmx-vcpu.kvm-arch.apic_access_page));
+   /* Reload apic access page in case it was migrated. */
+   kvm_vcpu_reload_apic_access_page(vcpu);
 
if (vmx_vm_has_apicv(vcpu-kvm))
memset(vmx-pi_desc, 0, sizeof(struct pi_desc));
@@ -8026,8 +8030,7 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct 
vmcs12 *vmcs12)
} else if (vm_need_virtualize_apic_accesses(vmx-vcpu.kvm)) {
exec_control |=
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
-   vmcs_write64(APIC_ACCESS_ADDR,
-   page_to_phys(vcpu-kvm-arch.apic_access_page));
+   kvm_vcpu_reload_apic_access_page(vcpu);
}
 
vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e042ef6..f7cbc36 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5991,6 +5991,8 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
 
 void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu *vcpu)
 {
+   struct page *page = NULL;
+
/*
 * If platform doesn't have 2nd exec virtualize apic access affinity,
 * set_apic_access_page_addr() will be set to NULL in hardware_setup(),
@@ -6004,10 +6006,14 @@ void kvm_vcpu_reload_apic_access_page(struct kvm_vcpu 
*vcpu)
 * migrated, GUP will wait till the migrate entry is replaced
 * with the new pte entry pointing to the new page.
 */
-   vcpu-kvm-arch.apic_access_page = gfn_to_page(vcpu-kvm,
-   APIC_DEFAULT_PHYS_BASE  PAGE_SHIFT);
-   kvm_x86_ops-set_apic_access_page_addr(vcpu,
-   page_to_phys(vcpu-kvm-arch.apic_access_page));
+   page = gfn_to_page(vcpu-kvm, APIC_DEFAULT_PHYS_BASE  PAGE_SHIFT);
+   kvm_x86_ops-set_apic_access_page_addr(vcpu, page_to_phys(page));
+
+   /*
+* Do not pin apic access page in memory so that memory hotplug
+* process is able to migrate it.
+*/
+   put_page(page);
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_reload_apic_access_page);
 
@@ -7272,8 +7278,6 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
kfree(kvm-arch.vpic);
kfree(kvm-arch.vioapic);
kvm_free_vcpus(kvm);
-   if (kvm-arch.apic_access_page)
-   put_page(kvm-arch.apic_access_page);
kfree(rcu_dereference_check(kvm-arch.apic_map, 1));
 }
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body 

[PATCH v8 7/8] kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access migration.

2014-09-24 Thread Tang Chen
We are handling L1 and L2 share one apic access page situation when migrating
apic access page. We should do some handling when migration happens in the
following situations:

   1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
  vmcs in the next L1-L2 entry.

   2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
  L0-L1 entry and L2's vmcs in the next L1-L2 entry.

   3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
  L0-L2 entry and L1's vmcs in the next L2-L1 exit.

This patch force a L1-L0 exit or L2-L0 exit when shared apic access page is
migrated using mmu notifier. Since apic access page is only used on intel x86,
this is arch specific code.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 arch/arm/include/asm/kvm_host.h |  5 +
 arch/arm64/include/asm/kvm_host.h   |  5 +
 arch/ia64/include/asm/kvm_host.h|  7 +++
 arch/mips/include/asm/kvm_host.h|  6 ++
 arch/powerpc/include/asm/kvm_host.h |  5 +
 arch/s390/include/asm/kvm_host.h|  8 
 arch/x86/include/asm/kvm_host.h |  2 ++
 arch/x86/kvm/x86.c  | 11 +++
 virt/kvm/kvm_main.c |  3 +++
 9 files changed, 52 insertions(+)

diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 6dfb404..f5b3f53 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -182,6 +182,11 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
unsigned long hva)
return 0;
 }
 
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+}
+
 struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
 struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
 
diff --git a/arch/arm64/include/asm/kvm_host.h 
b/arch/arm64/include/asm/kvm_host.h
index e10c45a..594873a 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -192,6 +192,11 @@ static inline int kvm_test_age_hva(struct kvm *kvm, 
unsigned long hva)
return 0;
 }
 
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+}
+
 struct kvm_vcpu *kvm_arm_get_running_vcpu(void);
 struct kvm_vcpu __percpu **kvm_get_running_vcpus(void);
 
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index db95f57..282e71f 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -574,6 +574,13 @@ static inline struct kvm_pt_regs *vcpu_regs(struct 
kvm_vcpu *v)
return (struct kvm_pt_regs *) ((unsigned long) v + KVM_STK_OFFSET) - 1;
 }
 
+#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+}
+#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
+
 typedef int kvm_vmm_entry(void);
 typedef void kvm_tramp_entry(union context *host, union context *guest);
 
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index 7a3fc67..4826d29 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -767,5 +767,11 @@ extern int kvm_mips_trans_mtc0(uint32_t inst, uint32_t 
*opc,
 extern void kvm_mips_dump_stats(struct kvm_vcpu *vcpu);
 extern unsigned long kvm_mips_get_ramsize(struct kvm *kvm);
 
+#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+}
+#endif /* KVM_ARCH_WANT_MMU_NOTIFIER */
 
 #endif /* __MIPS_KVM_HOST_H__ */
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 98d9dd5..e40402d 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -61,6 +61,11 @@ extern int kvm_age_hva(struct kvm *kvm, unsigned long hva);
 extern int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
 extern void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
 
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+unsigned long address)
+{
+}
+
 #define HPTEG_CACHE_NUM(1  15)
 #define HPTEG_HASH_BITS_PTE13
 #define HPTEG_HASH_BITS_PTE_LONG   12
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 773bef7..e4d6708 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -450,4 +450,12 @@ void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
 
 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
 extern char sie_exit;
+
+#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
+static inline void kvm_arch_mmu_notifier_invalidate_page(struct kvm *kvm,
+

[PATCH v8 4/8] kvm, mem-hotplug: Reload L1's apic access page in vcpu_enter_guest().

2014-09-24 Thread Tang Chen
We wants to migrate apic access page pinned by guest (L1 and L2) to make memory
hotplug available.

There are two situations need to be handled for apic access page used by L2 vm:
1. L1 prepares a separate apic access page for L2.

   L2 pins a lot of pages in memory. Even if we can migrate apic access page,
   memory hotplug is not available when L2 is running. So do not handle this
   now. Migrate L1's apic access page only.

2. L1 and L2 share one apic access page.

   Since we will migrate L1's apic access page, we should do some handling when
   migration happens in the following situations:

   1) when L0 is running: Update L1's vmcs in the next L0-L1 entry and L2's
  vmcs in the next L1-L2 entry.

   2) when L1 is running: Force a L1-L0 exit, update L1's vmcs in the next
  L0-L1 entry and L2's vmcs in the next L1-L2 entry.

   3) when L2 is running: Force a L2-L0 exit, update L2's vmcs in the next
  L0-L2 entry and L1's vmcs in the next L2-L1 exit.

This patch handles 1) and 2).

Since we don't handle L1 ans L2 have separate apic access pages situation,
when we update vmcs, we need to check if we are in L2 and if L1 prepares an
non-shared apic access page for L2. We do this in 
vmx_set_apic_access_page_addr()
when trying to set new apic access page's hpa like this:

   if (!is_guest_mode(vcpu) ||
   !(vmx-nested.current_vmcs12-secondary_vm_exec_control 
 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 arch/x86/include/asm/kvm_host.h |  1 +
 arch/x86/kvm/vmx.c  | 39 ++-
 arch/x86/kvm/x86.c  | 23 +++
 include/linux/kvm_host.h|  1 +
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 35171c7..582cd0f 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -739,6 +739,7 @@ struct kvm_x86_ops {
void (*hwapic_isr_update)(struct kvm *kvm, int isr);
void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
void (*set_virtual_x2apic_mode)(struct kvm_vcpu *vcpu, bool set);
+   void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu, hpa_t hpa);
void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector);
void (*sync_pir_to_irr)(struct kvm_vcpu *vcpu);
int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 72a0470..1411bab 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3108,9 +3108,17 @@ static __init int hardware_setup(void)
if (!cpu_has_vmx_unrestricted_guest())
enable_unrestricted_guest = 0;
 
-   if (!cpu_has_vmx_flexpriority())
+   if (!cpu_has_vmx_flexpriority()) {
flexpriority_enabled = 0;
 
+   /*
+* set_apic_access_page_addr() is used to reload apic access
+* page in case it is migrated for memory hotplug reason. If
+* platform doesn't have this affinity, no need to handle it.
+*/
+   kvm_x86_ops-set_apic_access_page_addr = NULL;
+   }
+
if (!cpu_has_vmx_tpr_shadow())
kvm_x86_ops-update_cr8_intercept = NULL;
 
@@ -7090,6 +7098,34 @@ static void vmx_set_virtual_x2apic_mode(struct kvm_vcpu 
*vcpu, bool set)
vmx_set_msr_bitmap(vcpu);
 }
 
+static void vmx_set_apic_access_page_addr(struct kvm_vcpu *vcpu, hpa_t hpa)
+{
+   struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+   /*
+* This function is used to reload apic access page in case it is
+* migrated for memory hotplug reason. And only L1 and L2 share the
+* same apic access page situation is handled.
+*
+* 1) If vcpu is not in guest mode (in L1), reload the page for L1.
+*And L2's page will be reloaded in the next L1-L2 entry by
+*prepare_vmcs02().
+*
+* 2) If vcpu is in guest mode (in L2), but L1 didn't not prepare an
+*apic access page for L2 (current_vmcs12-secondary_vm_exec_control
+*does not have SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES bit set),
+*reload the page for L2.
+*And L1's page will be reloaded in the next L2-L1 exit.
+*
+* 3) Otherwise, do nothing. L2's specific apic access page is still
+*pinned in memory, and not hotpluggable.
+*/
+   if (!is_guest_mode(vcpu) ||
+   !(vmx-nested.current_vmcs12-secondary_vm_exec_control 
+ SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))
+   vmcs_write64(APIC_ACCESS_ADDR, hpa);
+}
+
 static void vmx_hwapic_isr_update(struct kvm *kvm, int isr)
 {
u16 status;
@@ -8909,6 +8945,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
.enable_irq_window = enable_irq_window,
.update_cr8_intercept = 

[PATCH v8 2/8] kvm: Remove ept_identity_pagetable from struct kvm_arch.

2014-09-24 Thread Tang Chen
kvm_arch-ept_identity_pagetable holds the ept identity pagetable page. But
it is never used to refer to the page at all.

In vcpu initialization, it indicates two things:
1. indicates if ept page is allocated
2. indicates if a memory slot for identity page is initialized

Actually, kvm_arch-ept_identity_pagetable_done is enough to tell if the ept
identity pagetable is initialized. So we can remove ept_identity_pagetable.

NOTE: In the original code, ept identity pagetable page is pinned in memroy.
  As a result, it cannot be migrated/hot-removed. After this patch, since
  kvm_arch-ept_identity_pagetable is removed, ept identity pagetable page
  is no longer pinned in memory. And it can be migrated/hot-removed.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
Reviewed-by: Gleb Natapov g...@kernel.org
---
 arch/x86/include/asm/kvm_host.h |  1 -
 arch/x86/kvm/vmx.c  | 47 +++--
 arch/x86/kvm/x86.c  |  2 --
 3 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 7c492ed..35171c7 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -580,7 +580,6 @@ struct kvm_arch {
 
gpa_t wall_clock;
 
-   struct page *ept_identity_pagetable;
bool ept_identity_pagetable_done;
gpa_t ept_identity_map_addr;
 
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4b80ead..4fb84ad 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -743,6 +743,7 @@ static u32 vmx_segment_access_rights(struct kvm_segment 
*var);
 static void vmx_sync_pir_to_irr_dummy(struct kvm_vcpu *vcpu);
 static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx);
 static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx);
+static int alloc_identity_pagetable(struct kvm *kvm);
 
 static DEFINE_PER_CPU(struct vmcs *, vmxarea);
 static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -3938,21 +3939,27 @@ out:
 
 static int init_rmode_identity_map(struct kvm *kvm)
 {
-   int i, idx, r, ret;
+   int i, idx, r, ret = 0;
pfn_t identity_map_pfn;
u32 tmp;
 
if (!enable_ept)
return 1;
-   if (unlikely(!kvm-arch.ept_identity_pagetable)) {
-   printk(KERN_ERR EPT: identity-mapping pagetable 
-   haven't been allocated!\n);
-   return 0;
+
+   /* Protect kvm-arch.ept_identity_pagetable_done. */
+   mutex_lock(kvm-slots_lock);
+
+   if (likely(kvm-arch.ept_identity_pagetable_done)) {
+   ret = 1;
+   goto out2;
}
-   if (likely(kvm-arch.ept_identity_pagetable_done))
-   return 1;
-   ret = 0;
+
identity_map_pfn = kvm-arch.ept_identity_map_addr  PAGE_SHIFT;
+
+   r = alloc_identity_pagetable(kvm);
+   if (r)
+   goto out2;
+
idx = srcu_read_lock(kvm-srcu);
r = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
if (r  0)
@@ -3970,6 +3977,9 @@ static int init_rmode_identity_map(struct kvm *kvm)
ret = 1;
 out:
srcu_read_unlock(kvm-srcu, idx);
+
+out2:
+   mutex_unlock(kvm-slots_lock);
return ret;
 }
 
@@ -4019,31 +4029,20 @@ out:
 
 static int alloc_identity_pagetable(struct kvm *kvm)
 {
-   struct page *page;
+   /* Called with kvm-slots_lock held. */
+
struct kvm_userspace_memory_region kvm_userspace_mem;
int r = 0;
 
-   mutex_lock(kvm-slots_lock);
-   if (kvm-arch.ept_identity_pagetable)
-   goto out;
+   BUG_ON(kvm-arch.ept_identity_pagetable_done);
+
kvm_userspace_mem.slot = IDENTITY_PAGETABLE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
kvm_userspace_mem.guest_phys_addr =
kvm-arch.ept_identity_map_addr;
kvm_userspace_mem.memory_size = PAGE_SIZE;
r = __kvm_set_memory_region(kvm, kvm_userspace_mem);
-   if (r)
-   goto out;
-
-   page = gfn_to_page(kvm, kvm-arch.ept_identity_map_addr  PAGE_SHIFT);
-   if (is_error_page(page)) {
-   r = -EFAULT;
-   goto out;
-   }
 
-   kvm-arch.ept_identity_pagetable = page;
-out:
-   mutex_unlock(kvm-slots_lock);
return r;
 }
 
@@ -7643,8 +7642,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, 
unsigned int id)
kvm-arch.ept_identity_map_addr =
VMX_EPT_IDENTITY_PAGETABLE_ADDR;
err = -ENOMEM;
-   if (alloc_identity_pagetable(kvm) != 0)
-   goto free_vmcs;
if (!init_rmode_identity_map(kvm))
goto free_vmcs;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8f1e22d..e05bd58 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7239,8 +7239,6 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
kvm_free_vcpus(kvm);
if 

[PATCH v8 5/8] kvm: Rename make_all_cpus_request() to kvm_make_all_cpus_request() and make it non-static.

2014-09-24 Thread Tang Chen
Since different architectures need different handling, we will add some arch 
specific
code later. The code may need to make cpu requests outside kvm_main.c, so make 
it
non-static and rename it to kvm_make_all_cpus_request().

Reviewed-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 include/linux/kvm_host.h |  1 +
 virt/kvm/kvm_main.c  | 10 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c23236a..73de13c 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -580,6 +580,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm);
 void kvm_reload_remote_mmus(struct kvm *kvm);
 void kvm_make_mclock_inprogress_request(struct kvm *kvm);
 void kvm_make_scan_ioapic_request(struct kvm *kvm);
+bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req);
 
 long kvm_arch_dev_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 33712fb..0f8b6f6 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -152,7 +152,7 @@ static void ack_flush(void *_completed)
 {
 }
 
-static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
+bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req)
 {
int i, cpu, me;
cpumask_var_t cpus;
@@ -189,7 +189,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
long dirty_count = kvm-tlbs_dirty;
 
smp_mb();
-   if (make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
+   if (kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
++kvm-stat.remote_tlb_flush;
cmpxchg(kvm-tlbs_dirty, dirty_count, 0);
 }
@@ -197,17 +197,17 @@ EXPORT_SYMBOL_GPL(kvm_flush_remote_tlbs);
 
 void kvm_reload_remote_mmus(struct kvm *kvm)
 {
-   make_all_cpus_request(kvm, KVM_REQ_MMU_RELOAD);
+   kvm_make_all_cpus_request(kvm, KVM_REQ_MMU_RELOAD);
 }
 
 void kvm_make_mclock_inprogress_request(struct kvm *kvm)
 {
-   make_all_cpus_request(kvm, KVM_REQ_MCLOCK_INPROGRESS);
+   kvm_make_all_cpus_request(kvm, KVM_REQ_MCLOCK_INPROGRESS);
 }
 
 void kvm_make_scan_ioapic_request(struct kvm *kvm)
 {
-   make_all_cpus_request(kvm, KVM_REQ_SCAN_IOAPIC);
+   kvm_make_all_cpus_request(kvm, KVM_REQ_SCAN_IOAPIC);
 }
 
 int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 3/8] kvm: Make init_rmode_identity_map() return 0 on success.

2014-09-24 Thread Tang Chen
In init_rmode_identity_map(), there two variables indicating the return
value, r and ret, and it return 0 on error, 1 on success. The function
is only called by vmx_create_vcpu(), and r is redundant.

This patch removes the redundant variable r, and make init_rmode_identity_map()
return 0 on success, -errno on failure.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 arch/x86/kvm/vmx.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 4fb84ad..72a0470 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3939,45 +3939,42 @@ out:
 
 static int init_rmode_identity_map(struct kvm *kvm)
 {
-   int i, idx, r, ret = 0;
+   int i, idx, ret = 0;
pfn_t identity_map_pfn;
u32 tmp;
 
if (!enable_ept)
-   return 1;
+   return 0;
 
/* Protect kvm-arch.ept_identity_pagetable_done. */
mutex_lock(kvm-slots_lock);
 
-   if (likely(kvm-arch.ept_identity_pagetable_done)) {
-   ret = 1;
+   if (likely(kvm-arch.ept_identity_pagetable_done))
goto out2;
-   }
 
identity_map_pfn = kvm-arch.ept_identity_map_addr  PAGE_SHIFT;
 
-   r = alloc_identity_pagetable(kvm);
-   if (r)
+   ret = alloc_identity_pagetable(kvm);
+   if (ret)
goto out2;
 
idx = srcu_read_lock(kvm-srcu);
-   r = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
-   if (r  0)
+   ret = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
+   if (ret)
goto out;
/* Set up identity-mapping pagetable for EPT in real mode */
for (i = 0; i  PT32_ENT_PER_PAGE; i++) {
tmp = (i  22) + (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |
_PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_PSE);
-   r = kvm_write_guest_page(kvm, identity_map_pfn,
+   ret = kvm_write_guest_page(kvm, identity_map_pfn,
tmp, i * sizeof(tmp), sizeof(tmp));
-   if (r  0)
+   if (ret)
goto out;
}
kvm-arch.ept_identity_pagetable_done = true;
-   ret = 1;
+
 out:
srcu_read_unlock(kvm-srcu, idx);
-
 out2:
mutex_unlock(kvm-slots_lock);
return ret;
@@ -7604,11 +7601,13 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm 
*kvm, unsigned int id)
if (err)
goto free_vcpu;
 
+   /* Set err to -ENOMEM to handle memory allocation error. */
+   err = -ENOMEM;
+
vmx-guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
BUILD_BUG_ON(ARRAY_SIZE(vmx_msr_index) * sizeof(vmx-guest_msrs[0])
  PAGE_SIZE);
 
-   err = -ENOMEM;
if (!vmx-guest_msrs) {
goto uninit_vcpu;
}
@@ -7641,8 +7640,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, 
unsigned int id)
if (!kvm-arch.ept_identity_map_addr)
kvm-arch.ept_identity_map_addr =
VMX_EPT_IDENTITY_PAGETABLE_ADDR;
-   err = -ENOMEM;
-   if (!init_rmode_identity_map(kvm))
+   err = init_rmode_identity_map(kvm);
+   if (err  0)
goto free_vmcs;
}
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/8] kvm: Use APIC_DEFAULT_PHYS_BASE macro as the apic access page address.

2014-09-24 Thread Tang Chen
We have APIC_DEFAULT_PHYS_BASE defined as 0xfee0, which is also the address 
of
apic access page. So use this macro.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
Reviewed-by: Gleb Natapov g...@kernel.org
---
 arch/x86/kvm/svm.c | 3 ++-
 arch/x86/kvm/vmx.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ddf7427..1d941ad 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1257,7 +1257,8 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, 
unsigned int id)
svm-asid_generation = 0;
init_vmcb(svm);
 
-   svm-vcpu.arch.apic_base = 0xfee0 | MSR_IA32_APICBASE_ENABLE;
+   svm-vcpu.arch.apic_base = APIC_DEFAULT_PHYS_BASE |
+  MSR_IA32_APICBASE_ENABLE;
if (kvm_vcpu_is_bsp(svm-vcpu))
svm-vcpu.arch.apic_base |= MSR_IA32_APICBASE_BSP;
 
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index bfe11cf..4b80ead 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3999,13 +3999,13 @@ static int alloc_apic_access_page(struct kvm *kvm)
goto out;
kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
-   kvm_userspace_mem.guest_phys_addr = 0xfee0ULL;
+   kvm_userspace_mem.guest_phys_addr = APIC_DEFAULT_PHYS_BASE;
kvm_userspace_mem.memory_size = PAGE_SIZE;
r = __kvm_set_memory_region(kvm, kvm_userspace_mem);
if (r)
goto out;
 
-   page = gfn_to_page(kvm, 0xfee00);
+   page = gfn_to_page(kvm, APIC_DEFAULT_PHYS_BASE  PAGE_SHIFT);
if (is_error_page(page)) {
r = -EFAULT;
goto out;
@@ -4477,7 +4477,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu)
 
vmx-vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val();
kvm_set_cr8(vmx-vcpu, 0);
-   apic_base_msr.data = 0xfee0 | MSR_IA32_APICBASE_ENABLE;
+   apic_base_msr.data = APIC_DEFAULT_PHYS_BASE | MSR_IA32_APICBASE_ENABLE;
if (kvm_vcpu_is_bsp(vmx-vcpu))
apic_base_msr.data |= MSR_IA32_APICBASE_BSP;
apic_base_msr.host_initiated = true;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 0/8] kvm, mem-hotplug: Do not pin ept identity pagetable and apic access page.

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 09:57, Tang Chen ha scritto:
 ept identity pagetable and apic access page in kvm are pinned in memory.
 As a result, they cannot be migrated/hot-removed.
 
 But actually they don't need to be pinned in memory.
 
 [For ept identity page]
 Just do not pin it. When it is migrated, guest will be able to find the
 new page in the next ept violation.
 
 [For apic access page]
 The hpa of apic access page is stored in VMCS APIC_ACCESS_ADDR pointer.
 When apic access page is migrated, we update VMCS APIC_ACCESS_ADDR pointer
 for each vcpu in addition.
 
 This patch-set is based on Linux 3.17.0-rc5.
 
 NOTE: Tested with -cpu xxx,-x2apic option.
   But since nested vm pins some other pages in memory, if user uses nested
   vm, memory hot-remove will not work.
 
 Change log v7-v8:
 1. Patch 1/9~3/9 were applied to kvm/queue by Paolo Bonzini 
 pbonz...@redhat.com.
Just resend them, no changes.
 2. Removed previous patch 4/9, which added unnecessary hook 
 has_secondary_apic_access().
 3. Set kvm_x86_ops-set_apic_access_page_addr to NULL when hardware had no 
 flexpriority
functionality which actually exists only on x86. 
 4. Moved declaration of kvm_arch_mmu_notifier_invalidate_page() to 
 arch/*/include/asm/kvm_host.h.
 5. Removed useless set_apic_access_page_addr() hook for svm.
 
 Tang Chen (8):
   kvm: Use APIC_DEFAULT_PHYS_BASE macro as the apic access page address.
   kvm: Remove ept_identity_pagetable from struct kvm_arch.
   kvm: Make init_rmode_identity_map() return 0 on success.
   kvm, mem-hotplug: Reload L1's apic access page in vcpu_enter_guest().
   kvm: Rename make_all_cpus_request() to kvm_make_all_cpus_request() and
 make it non-static.
   kvm, mem-hotplug: Reload L1's apic access page on migration when L2 is
 running.
   kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access
 migration.
   kvm, mem-hotplug: Unpin and remove kvm_arch-apic_access_page.
 
  arch/arm/include/asm/kvm_host.h |   5 ++
  arch/arm64/include/asm/kvm_host.h   |   5 ++
  arch/ia64/include/asm/kvm_host.h|   7 ++
  arch/mips/include/asm/kvm_host.h|   6 ++
  arch/powerpc/include/asm/kvm_host.h |   5 ++
  arch/s390/include/asm/kvm_host.h|   8 +++
  arch/x86/include/asm/kvm_host.h |   7 +-
  arch/x86/kvm/svm.c  |   3 +-
  arch/x86/kvm/vmx.c  | 130 
 
  arch/x86/kvm/x86.c  |  45 +++--
  include/linux/kvm_host.h|   2 +
  virt/kvm/kvm_main.c |  13 ++--
  12 files changed, 180 insertions(+), 56 deletions(-)
 

Thanks for your persistence!  The patches look good, I'll test them and
apply to kvm/queue.

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] [next-20140923] KVM: Remove KVM_VFIO

2014-09-24 Thread Paul Bolle
There are no checks for CONFIG_KVM_VFIO and nothing depends on KVM_VFIO.
Setting KVM_VFIO has no effect. Remove that Kconfig symbol.

Signed-off-by: Paul Bolle pebo...@tiscali.nl
---
I choose not to mention commit 80ce1639727e (KVM: VFIO: register
kvm_device_ops dynamically) as references to linux-next commits might
go stale and only confuse future readers.

Done on top of next-21040923. Tested with git grep only.

 arch/x86/kvm/Kconfig | 1 -
 virt/kvm/Kconfig | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index f9d16ff56c6b..178d872734b1 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -39,7 +39,6 @@ config KVM
select PERF_EVENTS
select HAVE_KVM_MSI
select HAVE_KVM_CPU_RELAX_INTERCEPT
-   select KVM_VFIO
---help---
  Support hosting fully virtualized guest machines using hardware
  virtualization extensions.  You will need a fairly recent
diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig
index fc0c5e603eb4..1f5ebc4693c3 100644
--- a/virt/kvm/Kconfig
+++ b/virt/kvm/Kconfig
@@ -34,6 +34,3 @@ config HAVE_KVM_MSI
 
 config HAVE_KVM_CPU_RELAX_INTERCEPT
bool
-
-config KVM_VFIO
-   bool
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 0/8] kvm, mem-hotplug: Do not pin ept identity pagetable and apic access page.

2014-09-24 Thread Tang Chen


On 09/24/2014 04:20 PM, Paolo Bonzini wrote:

Il 24/09/2014 09:57, Tang Chen ha scritto:

ept identity pagetable and apic access page in kvm are pinned in memory.
As a result, they cannot be migrated/hot-removed.

But actually they don't need to be pinned in memory.

[For ept identity page]
Just do not pin it. When it is migrated, guest will be able to find the
new page in the next ept violation.

[For apic access page]
The hpa of apic access page is stored in VMCS APIC_ACCESS_ADDR pointer.
When apic access page is migrated, we update VMCS APIC_ACCESS_ADDR pointer
for each vcpu in addition.

This patch-set is based on Linux 3.17.0-rc5.

NOTE: Tested with -cpu xxx,-x2apic option.
   But since nested vm pins some other pages in memory, if user uses nested
   vm, memory hot-remove will not work.

Change log v7-v8:
1. Patch 1/9~3/9 were applied to kvm/queue by Paolo Bonzini 
pbonz...@redhat.com.
Just resend them, no changes.
2. Removed previous patch 4/9, which added unnecessary hook 
has_secondary_apic_access().
3. Set kvm_x86_ops-set_apic_access_page_addr to NULL when hardware had no 
flexpriority
functionality which actually exists only on x86.
4. Moved declaration of kvm_arch_mmu_notifier_invalidate_page() to 
arch/*/include/asm/kvm_host.h.
5. Removed useless set_apic_access_page_addr() hook for svm.

Tang Chen (8):
   kvm: Use APIC_DEFAULT_PHYS_BASE macro as the apic access page address.
   kvm: Remove ept_identity_pagetable from struct kvm_arch.
   kvm: Make init_rmode_identity_map() return 0 on success.
   kvm, mem-hotplug: Reload L1's apic access page in vcpu_enter_guest().
   kvm: Rename make_all_cpus_request() to kvm_make_all_cpus_request() and
 make it non-static.
   kvm, mem-hotplug: Reload L1's apic access page on migration when L2 is
 running.
   kvm, mem-hotplug: Add arch specific mmu notifier to handle apic access
 migration.
   kvm, mem-hotplug: Unpin and remove kvm_arch-apic_access_page.

  arch/arm/include/asm/kvm_host.h |   5 ++
  arch/arm64/include/asm/kvm_host.h   |   5 ++
  arch/ia64/include/asm/kvm_host.h|   7 ++
  arch/mips/include/asm/kvm_host.h|   6 ++
  arch/powerpc/include/asm/kvm_host.h |   5 ++
  arch/s390/include/asm/kvm_host.h|   8 +++
  arch/x86/include/asm/kvm_host.h |   7 +-
  arch/x86/kvm/svm.c  |   3 +-
  arch/x86/kvm/vmx.c  | 130 
  arch/x86/kvm/x86.c  |  45 +++--
  include/linux/kvm_host.h|   2 +
  virt/kvm/kvm_main.c |  13 ++--
  12 files changed, 180 insertions(+), 56 deletions(-)


Thanks for your persistence!  The patches look good, I'll test them and
apply to kvm/queue.


Sure, thank you very much. :)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] kvm: Fix page ageing bugs

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 09:20, Wanpeng Li ha scritto:
 
 This trace point still dup duplicated message for the same gfn in the
 for loop.

Yes, but the gfn argument lets you take it out again.

Note that having the duplicated trace would make sense if you included
the accessed bit for each spte, instead of just the young variable.

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Using physical disks in a VM

2014-09-24 Thread Stefan Hajnoczi
On Tue, Sep 23, 2014 at 06:54:48PM +, Boylan, Ross wrote:
 I have a couple of SATA disks (software RAID on some partitions) with a 
 system that has become unreliable on them.  I plan to add more disks and 
 install a new system on them (Debian wheezy).  I will still need to run 
 things on the old OS (simultaneously running the new OS) to migrate.
 
 Is there a way I can use the 2 old physical disks in a VM?  How?
 
 Searching suggests that I can't simply say -hda /dev/sdc.  There are some 
 references to using virtio, but it isn't clear to me if this would enable me 
 to use the physical disk as is.

In some cases you can simply point QEMU at /dev/sdc and it will boot
without a hitch.

However, it depends on the guest operating system.  Windows is fussy
about hardware changes and may refuse to boot.  Modern Linux distros
tend to be okay.

Booting from a pre-existing physical disk works best when the hardware
changes that the guest sees are minimal.  Even in a Linux guest there
could be a problem if /etc/fstab uses device names like /dev/sda instead
of disk labels because the device name could change if the hardware
changes (e.g. virtio disks are named /dev/vda).

If you are familiar with moving disks between physical machines or
rescuing broken systems that don't boot, then booting a pre-existing
physical disk inside KVM should feel familiar.

You may also want to look at p2v migration tools:
http://libguestfs.org/virt-v2v/

Good luck!

Stefan


pgp5aF0DbrZSj.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC patch 0/6] vfio based pci pass-through for qemu/KVM on s390

2014-09-24 Thread Frank Blaschka
On Mon, Sep 22, 2014 at 02:47:31PM -0600, Alex Williamson wrote:
 On Fri, 2014-09-19 at 13:54 +0200, frank.blasc...@de.ibm.com wrote:
  This set of patches implements a vfio based solution for pci
  pass-through on the s390 platform. The kernel stuff is pretty
  much straight forward, but qemu needs more work.
  
  Most interesting patch is:
vfio: make vfio run on s390 platform
  
  I hope Alex  Alex can give me some guidance how to do the changes
  in an appropriate way. After creating a separate iommmu address space
  for each attached PCI device I can successfully run the vfio type1
  iommu. So If we could extend type1 not registering all guest memory
  (see patch) I think we do not need a special vfio iommu for s390
  for the moment.
  
  The patches implement the base pass-through support. s390 specific
  virtualization functions are currently not included. This would
  be a second step after the base support is done.
  
  kernel patches apply to linux-kvm-next
  
  KVM: s390: Enable PCI instructions
  iommu: add iommu for s390 platform
  vfio: make vfio build on s390
  
  qemu patches apply to qemu-master
  
  s390: Add PCI bus support
  s390: implement pci instruction
  vfio: make vfio run on s390 platform
  
  Thx for feedback and review comments
 
 Sending patches as attachments makes it difficult to comment inline.

Sorry, don't understand this. I sent every patch as separate email so
you can comment directly on the patch. What do you prefer?
 
 2/6
  - careful of the namespace as you're changing functions from static and
 exporting them
  - doesn't seem like functions need to be exported, just non-static to
 call from s390-iommu.c
 
Ok, will change this.

 6/6
  - We shouldn't need to globally disable mmap, each VFIO region reports
 whether it supports mmap and vfio-pci on s390 should indicate mmap is
 not supported on the platform.
Yes, this is even better to let the kernel announce a BAR can not be
mmap'ed. Checking the kernel code I realized the BARs are valid for
mmap'ing but the s390 platform does simply not allow this. So I feal we
have to introduce a platform switch in kernel. How about this ...

--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -377,9 +377,11 @@ static long vfio_pci_ioctl(void *device_

info.flags = VFIO_REGION_INFO_FLAG_READ |
 VFIO_REGION_INFO_FLAG_WRITE;
+#ifndef CONFIG_S390
if (pci_resource_flags(pdev, info.index) 
IORESOURCE_MEM  info.size = PAGE_SIZE)
info.flags |= VFIO_REGION_INFO_FLAG_MMAP;
+#endif
break;
case VFIO_PCI_ROM_REGION_INDEX:
{

  - INTx should be done the same way, the interrupt index for INTx should
 report 0 count.  The current code likely doesn't handle this, but it
 should be easy to fix.
The current code is fine. Problem is the card reports an interrupt index
(PCI_INTERRUPT_PIN) but again the platform does not support INTx at all.
So we need a platform switch as well. 

  - s390_msix_notify() vs msix_notify() should be abstracted somewhere

Platform does not have have an apic so there is nothing we could emulate
in qemu to make the existing msix_notify() work.

 else.  How would an emulated PCI device with MSI-X support work?
  - same for add_msi_route
Same here, we have to setup an adapter route due to the fact MSIX
notifications are delivered as adapter/thin IRQs on the platform.

Any suggestion or idea how a better abstraction could look like?

With all the platform constraints I was not able to find a suitable
emulated device. Remember s390:
- does not support IO BARs
- does not support INTx only MSIX
- in reality currently there is only a PCI network card available
- platform does not support fancy I/O like usb or audio :-)
  So we don't even have kernel (host and guest) support for this
  kind of devices.

  - We can probably come up with a better way to determine which address
 space to connect to the memory listener.
Any suggestion or idea for that?

 
 Looks like a reasonable first pass, good re-use of vfio code.  Thanks,
 
 Alex
 

Thx,

Frank

 

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH kvm-unit-tests] vmx_tests: do not set unsupported PAT controls in the VMCS

2014-09-24 Thread Paolo Bonzini
Otherwise, vmlaunch fails.  Also, skip PAT tests altogether if save/load
PAT is completely unsupported.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 x86/vmx_tests.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 2104fe9..184fafc 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -236,10 +236,19 @@ static int test_ctrl_pat_init()
u64 ctrl_exi;
 
msr_bmp_init();
+   if (!(ctrl_exit_rev.clr  EXI_SAVE_PAT) 
+   !(ctrl_exit_rev.clr  EXI_LOAD_PAT) 
+   !(ctrl_enter_rev.clr  ENT_LOAD_PAT)) {
+   printf(\tSave/load PAT is not supported\n);
+   return 1;
+   }
+
ctrl_ent = vmcs_read(ENT_CONTROLS);
ctrl_exi = vmcs_read(EXI_CONTROLS);
-   vmcs_write(ENT_CONTROLS, ctrl_ent | ENT_LOAD_PAT);
-   vmcs_write(EXI_CONTROLS, ctrl_exi | (EXI_SAVE_PAT | EXI_LOAD_PAT));
+   ctrl_ent |= ctrl_enter_rev.clr  ENT_LOAD_PAT;
+   ctrl_exi |= ctrl_exit_rev.clr  (EXI_SAVE_PAT | EXI_LOAD_PAT);
+   vmcs_write(ENT_CONTROLS, ctrl_ent);
+   vmcs_write(EXI_CONTROLS, ctrl_exi);
ia32_pat = rdmsr(MSR_IA32_CR_PAT);
vmcs_write(GUEST_PAT, 0x0);
vmcs_write(HOST_PAT, ia32_pat);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [next-20140923] KVM: Remove KVM_VFIO

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 10:22, Paul Bolle ha scritto:
 There are no checks for CONFIG_KVM_VFIO and nothing depends on KVM_VFIO.
 Setting KVM_VFIO has no effect. Remove that Kconfig symbol.
 
 Signed-off-by: Paul Bolle pebo...@tiscali.nl
 ---
 I choose not to mention commit 80ce1639727e (KVM: VFIO: register
 kvm_device_ops dynamically) as references to linux-next commits might
 go stale and only confuse future readers.

In the case of KVM, linux-commit hashes are substantially stable.  I'll
add back the reference.

Thanks for the patch, I'll apply it.

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm-vfio: do not use module_init

2014-09-24 Thread Paolo Bonzini
/me got confused between the kernel and QEMU.  In the kernel, you can
only have one module_init function, and it will prevent unloading the
module unless you also have the corresponding module_exit function.

So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
2014-09-02) broke unloading of the kvm module, by adding a module_init
function and no module_exit.

Repair it by making kvm_vfio_ops_init weak, and checking it in
kvm_init.

Cc: Will Deacon will.dea...@arm.com
Cc: Gleb Natapov g...@kernel.org
Cc: Alex Williamson alex.william...@redhat.com
Fixes: 80ce1639727e9d38729c34f162378508c307ca25
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 virt/kvm/kvm_main.c | 6 ++
 virt/kvm/vfio.c | 4 ++--
 virt/kvm/vfio.h | 6 ++
 3 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 virt/kvm/vfio.h

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index db57363cc287..69f90fb7899f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -57,6 +57,7 @@
 
 #include coalesced_mmio.h
 #include async_pf.h
+#include vfio.h
 
 #define CREATE_TRACE_POINTS
 #include trace/events/kvm.h
@@ -3226,6 +3227,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned 
vcpu_align,
goto out_undebugfs;
}
 
+   if (kvm_vfio_ops_init) {
+   r = kvm_vfio_ops_init();
+   WARN_ON(r);
+   }
+
return 0;
 
 out_undebugfs:
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index bb11b36ee8a2..8f7418186d7d 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -18,6 +18,7 @@
 #include linux/slab.h
 #include linux/uaccess.h
 #include linux/vfio.h
+#include vfio.h
 
 struct kvm_vfio_group {
struct list_head node;
@@ -278,8 +279,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
return 0;
 }
 
-static int __init kvm_vfio_ops_init(void)
+int __weak kvm_vfio_ops_init(void)
 {
return kvm_register_device_ops(kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
 }
-module_init(kvm_vfio_ops_init);
diff --git a/virt/kvm/vfio.h b/virt/kvm/vfio.h
new file mode 100644
index ..f70b384d0ef8
--- /dev/null
+++ b/virt/kvm/vfio.h
@@ -0,0 +1,6 @@
+#ifndef __KVM_VFIO_H
+#define __KVM_VFIO_H
+
+int __weak kvm_vfio_ops_init(void);
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 4/8] kvm, mem-hotplug: Reload L1's apic access page in vcpu_enter_guest().

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 09:57, Tang Chen ha scritto:
if (!is_guest_mode(vcpu) ||
!(vmx-nested.current_vmcs12-secondary_vm_exec_control 
  SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))

Actually, this needs to use nested_cpu_has2 (in case the secondary
controls are disabled).  I fixed that for you.

Thanks!

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm-vfio: do not use module_init

2014-09-24 Thread Will Deacon
On Wed, Sep 24, 2014 at 12:29:09PM +0100, Paolo Bonzini wrote:
 /me got confused between the kernel and QEMU.  In the kernel, you can
 only have one module_init function, and it will prevent unloading the
 module unless you also have the corresponding module_exit function.

Happy for you to take the blame, but I think this one's my fault!

 So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
 2014-09-02) broke unloading of the kvm module, by adding a module_init
 function and no module_exit.

I forget kvm builds as a module for other architectures (ie. not arm/arm64).

 Repair it by making kvm_vfio_ops_init weak, and checking it in
 kvm_init.

Hehe, if only there was a kconfig option for kvm-vfio.c...

Will
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm-vfio: do not use module_init

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 13:44, Will Deacon ha scritto:
 On Wed, Sep 24, 2014 at 12:29:09PM +0100, Paolo Bonzini wrote:
 /me got confused between the kernel and QEMU.  In the kernel, you can
 only have one module_init function, and it will prevent unloading the
 module unless you also have the corresponding module_exit function.
 
 Happy for you to take the blame, but I think this one's my fault!

That's why you were CCed! ;)

 So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
 2014-09-02) broke unloading of the kvm module, by adding a module_init
 function and no module_exit.
 
 I forget kvm builds as a module for other architectures (ie. not arm/arm64).
 
 Repair it by making kvm_vfio_ops_init weak, and checking it in
 kvm_init.
 
 Hehe, if only there was a kconfig option for kvm-vfio.c...

Yeah, I was tempted to put it back.  What do you think?

Paolo

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm-vfio: do not use module_init

2014-09-24 Thread Will Deacon
On Wed, Sep 24, 2014 at 12:45:53PM +0100, Paolo Bonzini wrote:
 Il 24/09/2014 13:44, Will Deacon ha scritto:
  On Wed, Sep 24, 2014 at 12:29:09PM +0100, Paolo Bonzini wrote:
  /me got confused between the kernel and QEMU.  In the kernel, you can
  only have one module_init function, and it will prevent unloading the
  module unless you also have the corresponding module_exit function.
  
  Happy for you to take the blame, but I think this one's my fault!
 
 That's why you were CCed! ;)
 
  So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
  2014-09-02) broke unloading of the kvm module, by adding a module_init
  function and no module_exit.
  
  I forget kvm builds as a module for other architectures (ie. not arm/arm64).
  
  Repair it by making kvm_vfio_ops_init weak, and checking it in
  kvm_init.
  
  Hehe, if only there was a kconfig option for kvm-vfio.c...
 
 Yeah, I was tempted to put it back.  What do you think?

I think it's nicer than the __weak symbol and I don't see a downside to
having the option (the reason for removing it was lack of users, which
lasted a couple of hours).

Will
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] kvm-vfio: do not use module_init

2014-09-24 Thread Paolo Bonzini
/me got confused between the kernel and QEMU.  In the kernel, you can
only have one module_init function, and it will prevent unloading the
module unless you also have the corresponding module_exit function.

So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
2014-09-02) broke unloading of the kvm module, by adding a module_init
function and no module_exit.

Repair it by making kvm_vfio_ops_init weak, and checking it in
kvm_init.

Cc: Will Deacon will.dea...@arm.com
Cc: Gleb Natapov g...@kernel.org
Cc: Alex Williamson alex.william...@redhat.com
Fixes: 80ce1639727e9d38729c34f162378508c307ca25
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 virt/kvm/kvm_main.c | 9 +
 virt/kvm/vfio.c | 4 ++--
 virt/kvm/vfio.h | 6 ++
 3 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 virt/kvm/vfio.h

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index db57363cc287..ad3439835adb 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -58,6 +58,10 @@
 #include coalesced_mmio.h
 #include async_pf.h
 
+#ifdef CONFIG_KVM_VFIO
+#include vfio.h
+#endif
+
 #define CREATE_TRACE_POINTS
 #include trace/events/kvm.h
 
@@ -3226,6 +3230,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned 
vcpu_align,
goto out_undebugfs;
}
 
+#ifdef CONFIG_KVM_VFIO
+   r = kvm_vfio_ops_init();
+   WARN_ON(r);
+#endif
+
return 0;
 
 out_undebugfs:
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index bb11b36ee8a2..281e7cf2b8e5 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -18,6 +18,7 @@
 #include linux/slab.h
 #include linux/uaccess.h
 #include linux/vfio.h
+#include vfio.h
 
 struct kvm_vfio_group {
struct list_head node;
@@ -278,8 +279,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
return 0;
 }
 
-static int __init kvm_vfio_ops_init(void)
+int kvm_vfio_ops_init(void)
 {
return kvm_register_device_ops(kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
 }
-module_init(kvm_vfio_ops_init);
diff --git a/virt/kvm/vfio.h b/virt/kvm/vfio.h
new file mode 100644
index ..f705288f5547
--- /dev/null
+++ b/virt/kvm/vfio.h
@@ -0,0 +1,6 @@
+#ifndef __KVM_VFIO_H
+#define __KVM_VFIO_H
+
+int kvm_vfio_ops_init(void);
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] kvm-vfio: do not use module_init

2014-09-24 Thread Will Deacon
On Wed, Sep 24, 2014 at 12:56:20PM +0100, Paolo Bonzini wrote:
 /me got confused between the kernel and QEMU.  In the kernel, you can
 only have one module_init function, and it will prevent unloading the
 module unless you also have the corresponding module_exit function.
 
 So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
 2014-09-02) broke unloading of the kvm module, by adding a module_init
 function and no module_exit.
 
 Repair it by making kvm_vfio_ops_init weak, and checking it in
 kvm_init.
 
 Cc: Will Deacon will.dea...@arm.com
 Cc: Gleb Natapov g...@kernel.org
 Cc: Alex Williamson alex.william...@redhat.com
 Fixes: 80ce1639727e9d38729c34f162378508c307ca25
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  virt/kvm/kvm_main.c | 9 +
  virt/kvm/vfio.c | 4 ++--
  virt/kvm/vfio.h | 6 ++
  3 files changed, 17 insertions(+), 2 deletions(-)
  create mode 100644 virt/kvm/vfio.h
 
 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
 index db57363cc287..ad3439835adb 100644
 --- a/virt/kvm/kvm_main.c
 +++ b/virt/kvm/kvm_main.c
 @@ -58,6 +58,10 @@
  #include coalesced_mmio.h
  #include async_pf.h
  
 +#ifdef CONFIG_KVM_VFIO
 +#include vfio.h
 +#endif

Can't you include this unconditionally, then have the #ifdef in the header
and a static inline kvm_vfio_ops_init that returns 0?

Will
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] kvm-vfio: do not use module_init

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 14:05, Will Deacon ha scritto:
  +#ifdef CONFIG_KVM_VFIO
  +#include vfio.h
  +#endif
 Can't you include this unconditionally, then have the #ifdef in the header
 and a static inline kvm_vfio_ops_init that returns 0?

Yup.  What was I thinking...

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] kvm-vfio: do not use module_init

2014-09-24 Thread Paolo Bonzini
/me got confused between the kernel and QEMU.  In the kernel, you can
only have one module_init function, and it will prevent unloading the
module unless you also have the corresponding module_exit function.

So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
2014-09-02) broke unloading of the kvm module, by adding a module_init
function and no module_exit.

Repair it by making kvm_vfio_ops_init weak, and checking it in
kvm_init.

Cc: Will Deacon will.dea...@arm.com
Cc: Gleb Natapov g...@kernel.org
Cc: Alex Williamson alex.william...@redhat.com
Fixes: 80ce1639727e9d38729c34f162378508c307ca25
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 virt/kvm/kvm_main.c |  4 
 virt/kvm/vfio.c |  4 ++--
 virt/kvm/vfio.h | 13 +
 3 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 virt/kvm/vfio.h

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index db57363cc287..499db0977f3c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -57,6 +57,7 @@
 
 #include coalesced_mmio.h
 #include async_pf.h
+#include vfio.h
 
 #define CREATE_TRACE_POINTS
 #include trace/events/kvm.h
@@ -3226,6 +3227,9 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned 
vcpu_align,
goto out_undebugfs;
}
 
+   r = kvm_vfio_ops_init();
+   WARN_ON(r);
+
return 0;
 
 out_undebugfs:
diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
index bb11b36ee8a2..281e7cf2b8e5 100644
--- a/virt/kvm/vfio.c
+++ b/virt/kvm/vfio.c
@@ -18,6 +18,7 @@
 #include linux/slab.h
 #include linux/uaccess.h
 #include linux/vfio.h
+#include vfio.h
 
 struct kvm_vfio_group {
struct list_head node;
@@ -278,8 +279,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 type)
return 0;
 }
 
-static int __init kvm_vfio_ops_init(void)
+int kvm_vfio_ops_init(void)
 {
return kvm_register_device_ops(kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
 }
-module_init(kvm_vfio_ops_init);
diff --git a/virt/kvm/vfio.h b/virt/kvm/vfio.h
new file mode 100644
index ..92eac75d6b62
--- /dev/null
+++ b/virt/kvm/vfio.h
@@ -0,0 +1,13 @@
+#ifndef __KVM_VFIO_H
+#define __KVM_VFIO_H
+
+#ifdef CONFIG_KVM_VFIO
+int kvm_vfio_ops_init(void);
+#else
+static inline int kvm_vfio_ops_init(void)
+{
+   return 0;
+}
+#endif
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] kvm-vfio: do not use module_init

2014-09-24 Thread Will Deacon
On Wed, Sep 24, 2014 at 01:09:28PM +0100, Paolo Bonzini wrote:
 /me got confused between the kernel and QEMU.  In the kernel, you can
 only have one module_init function, and it will prevent unloading the
 module unless you also have the corresponding module_exit function.
 
 So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
 2014-09-02) broke unloading of the kvm module, by adding a module_init
 function and no module_exit.
 
 Repair it by making kvm_vfio_ops_init weak, and checking it in
 kvm_init.
 
 Cc: Will Deacon will.dea...@arm.com
 Cc: Gleb Natapov g...@kernel.org
 Cc: Alex Williamson alex.william...@redhat.com
 Fixes: 80ce1639727e9d38729c34f162378508c307ca25
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  virt/kvm/kvm_main.c |  4 
  virt/kvm/vfio.c |  4 ++--
  virt/kvm/vfio.h | 13 +
  3 files changed, 19 insertions(+), 2 deletions(-)
  create mode 100644 virt/kvm/vfio.h

Looks good to me, thanks for fixing this:

  Acked-by: Will Deacon will.dea...@arm.com

Will

 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
 index db57363cc287..499db0977f3c 100644
 --- a/virt/kvm/kvm_main.c
 +++ b/virt/kvm/kvm_main.c
 @@ -57,6 +57,7 @@
  
  #include coalesced_mmio.h
  #include async_pf.h
 +#include vfio.h
  
  #define CREATE_TRACE_POINTS
  #include trace/events/kvm.h
 @@ -3226,6 +3227,9 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned 
 vcpu_align,
   goto out_undebugfs;
   }
  
 + r = kvm_vfio_ops_init();
 + WARN_ON(r);
 +
   return 0;
  
  out_undebugfs:
 diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
 index bb11b36ee8a2..281e7cf2b8e5 100644
 --- a/virt/kvm/vfio.c
 +++ b/virt/kvm/vfio.c
 @@ -18,6 +18,7 @@
  #include linux/slab.h
  #include linux/uaccess.h
  #include linux/vfio.h
 +#include vfio.h
  
  struct kvm_vfio_group {
   struct list_head node;
 @@ -278,8 +279,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 
 type)
   return 0;
  }
  
 -static int __init kvm_vfio_ops_init(void)
 +int kvm_vfio_ops_init(void)
  {
   return kvm_register_device_ops(kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
  }
 -module_init(kvm_vfio_ops_init);
 diff --git a/virt/kvm/vfio.h b/virt/kvm/vfio.h
 new file mode 100644
 index ..92eac75d6b62
 --- /dev/null
 +++ b/virt/kvm/vfio.h
 @@ -0,0 +1,13 @@
 +#ifndef __KVM_VFIO_H
 +#define __KVM_VFIO_H
 +
 +#ifdef CONFIG_KVM_VFIO
 +int kvm_vfio_ops_init(void);
 +#else
 +static inline int kvm_vfio_ops_init(void)
 +{
 + return 0;
 +}
 +#endif
 +
 +#endif
 -- 
 1.8.3.1
 
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] kvm-vfio: do not use module_init

2014-09-24 Thread Alex Williamson
On Wed, 2014-09-24 at 14:09 +0200, Paolo Bonzini wrote:
 /me got confused between the kernel and QEMU.  In the kernel, you can
 only have one module_init function, and it will prevent unloading the
 module unless you also have the corresponding module_exit function.
 
 So, commit 80ce1639727e (KVM: VFIO: register kvm_device_ops dynamically,
 2014-09-02) broke unloading of the kvm module, by adding a module_init
 function and no module_exit.
 
 Repair it by making kvm_vfio_ops_init weak, and checking it in
 kvm_init.
 
 Cc: Will Deacon will.dea...@arm.com
 Cc: Gleb Natapov g...@kernel.org
 Cc: Alex Williamson alex.william...@redhat.com
 Fixes: 80ce1639727e9d38729c34f162378508c307ca25
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  virt/kvm/kvm_main.c |  4 
  virt/kvm/vfio.c |  4 ++--
  virt/kvm/vfio.h | 13 +
  3 files changed, 19 insertions(+), 2 deletions(-)
  create mode 100644 virt/kvm/vfio.h

Thanks Paolo

Acked-by: Alex Williamson alex.william...@redhat.com

 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
 index db57363cc287..499db0977f3c 100644
 --- a/virt/kvm/kvm_main.c
 +++ b/virt/kvm/kvm_main.c
 @@ -57,6 +57,7 @@
  
  #include coalesced_mmio.h
  #include async_pf.h
 +#include vfio.h
  
  #define CREATE_TRACE_POINTS
  #include trace/events/kvm.h
 @@ -3226,6 +3227,9 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned 
 vcpu_align,
   goto out_undebugfs;
   }
  
 + r = kvm_vfio_ops_init();
 + WARN_ON(r);
 +
   return 0;
  
  out_undebugfs:
 diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
 index bb11b36ee8a2..281e7cf2b8e5 100644
 --- a/virt/kvm/vfio.c
 +++ b/virt/kvm/vfio.c
 @@ -18,6 +18,7 @@
  #include linux/slab.h
  #include linux/uaccess.h
  #include linux/vfio.h
 +#include vfio.h
  
  struct kvm_vfio_group {
   struct list_head node;
 @@ -278,8 +279,7 @@ static int kvm_vfio_create(struct kvm_device *dev, u32 
 type)
   return 0;
  }
  
 -static int __init kvm_vfio_ops_init(void)
 +int kvm_vfio_ops_init(void)
  {
   return kvm_register_device_ops(kvm_vfio_ops, KVM_DEV_TYPE_VFIO);
  }
 -module_init(kvm_vfio_ops_init);
 diff --git a/virt/kvm/vfio.h b/virt/kvm/vfio.h
 new file mode 100644
 index ..92eac75d6b62
 --- /dev/null
 +++ b/virt/kvm/vfio.h
 @@ -0,0 +1,13 @@
 +#ifndef __KVM_VFIO_H
 +#define __KVM_VFIO_H
 +
 +#ifdef CONFIG_KVM_VFIO
 +int kvm_vfio_ops_init(void);
 +#else
 +static inline int kvm_vfio_ops_init(void)
 +{
 + return 0;
 +}
 +#endif
 +
 +#endif



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC patch 0/6] vfio based pci pass-through for qemu/KVM on s390

2014-09-24 Thread Alex Williamson
On Wed, 2014-09-24 at 10:47 +0200, Frank Blaschka wrote:
 On Mon, Sep 22, 2014 at 02:47:31PM -0600, Alex Williamson wrote:
  On Fri, 2014-09-19 at 13:54 +0200, frank.blasc...@de.ibm.com wrote:
   This set of patches implements a vfio based solution for pci
   pass-through on the s390 platform. The kernel stuff is pretty
   much straight forward, but qemu needs more work.
   
   Most interesting patch is:
 vfio: make vfio run on s390 platform
   
   I hope Alex  Alex can give me some guidance how to do the changes
   in an appropriate way. After creating a separate iommmu address space
   for each attached PCI device I can successfully run the vfio type1
   iommu. So If we could extend type1 not registering all guest memory
   (see patch) I think we do not need a special vfio iommu for s390
   for the moment.
   
   The patches implement the base pass-through support. s390 specific
   virtualization functions are currently not included. This would
   be a second step after the base support is done.
   
   kernel patches apply to linux-kvm-next
   
   KVM: s390: Enable PCI instructions
   iommu: add iommu for s390 platform
   vfio: make vfio build on s390
   
   qemu patches apply to qemu-master
   
   s390: Add PCI bus support
   s390: implement pci instruction
   vfio: make vfio run on s390 platform
   
   Thx for feedback and review comments
  
  Sending patches as attachments makes it difficult to comment inline.
 
 Sorry, don't understand this. I sent every patch as separate email so
 you can comment directly on the patch. What do you prefer?

The patches in each email are showing up as attachments in my mail
client.  Is it just me?
 
  2/6
   - careful of the namespace as you're changing functions from static and
  exporting them
   - doesn't seem like functions need to be exported, just non-static to
  call from s390-iommu.c
  
 Ok, will change this.
 
  6/6
   - We shouldn't need to globally disable mmap, each VFIO region reports
  whether it supports mmap and vfio-pci on s390 should indicate mmap is
  not supported on the platform.
 Yes, this is even better to let the kernel announce a BAR can not be
 mmap'ed. Checking the kernel code I realized the BARs are valid for
 mmap'ing but the s390 platform does simply not allow this. So I feal we
 have to introduce a platform switch in kernel. How about this ...
 
 --- a/drivers/vfio/pci/vfio_pci.c
 +++ b/drivers/vfio/pci/vfio_pci.c
 @@ -377,9 +377,11 @@ static long vfio_pci_ioctl(void *device_
 
 info.flags = VFIO_REGION_INFO_FLAG_READ |
  VFIO_REGION_INFO_FLAG_WRITE;
 +#ifndef CONFIG_S390
 if (pci_resource_flags(pdev, info.index) 
 IORESOURCE_MEM  info.size = PAGE_SIZE)
 info.flags |= VFIO_REGION_INFO_FLAG_MMAP;
 +#endif
 break;
 case VFIO_PCI_ROM_REGION_INDEX:
 {

Maybe pull it out into a function.  Also, is there some capability or
feature we can test rather than just the architecture?  I'd prefer it to
be excluded because of a platform feature that prevents it rather than
the overall architecture itself.

   - INTx should be done the same way, the interrupt index for INTx should
  report 0 count.  The current code likely doesn't handle this, but it
  should be easy to fix.
 The current code is fine. Problem is the card reports an interrupt index
 (PCI_INTERRUPT_PIN) but again the platform does not support INTx at all.
 So we need a platform switch as well. 

Yep, let's try to do something consistent with the MMAP testing.

   - s390_msix_notify() vs msix_notify() should be abstracted somewhere
 
 Platform does not have have an apic so there is nothing we could emulate
 in qemu to make the existing msix_notify() work.
 
  else.  How would an emulated PCI device with MSI-X support work?
   - same for add_msi_route
 Same here, we have to setup an adapter route due to the fact MSIX
 notifications are delivered as adapter/thin IRQs on the platform.
 
 Any suggestion or idea how a better abstraction could look like?
 
 With all the platform constraints I was not able to find a suitable
 emulated device. Remember s390:
 - does not support IO BARs
 - does not support INTx only MSIX

What about MSI (non-X)?

 - in reality currently there is only a PCI network card available

On the physical hardware?

 - platform does not support fancy I/O like usb or audio :-)
   So we don't even have kernel (host and guest) support for this
   kind of devices.

Does that mean you couldn't?  What about virtio-net-pci with MSI-X
interrupts or emulated xhci with MSI-X interrupts, couldn't those be
supported if s390 MSI-X were properly integrated into the QEMU MSI-X
API?  vfio-pci isn't the right level to be switching between the
standard API and the s390 API.

   - We can probably come up with a better way to determine which address
  space to connect to the memory listener.
 

Re: [PATCHv7 20/26] vfio/platform: trigger an interrupt via eventfd

2014-09-24 Thread Alex Williamson
On Tue, 2014-09-23 at 16:46 +0200, Antonios Motakis wrote:
 This patch allows to set an eventfd for a patform device's interrupt,
 and also to trigger the interrupt eventfd from userspace for testing.
 
 Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
 ---
  drivers/vfio/platform/vfio_platform_irq.c | 89 
 ++-
  drivers/vfio/platform/vfio_platform_private.h |  2 +
  2 files changed, 89 insertions(+), 2 deletions(-)
 
 diff --git a/drivers/vfio/platform/vfio_platform_irq.c 
 b/drivers/vfio/platform/vfio_platform_irq.c
 index 007b386..25a7825 100644
 --- a/drivers/vfio/platform/vfio_platform_irq.c
 +++ b/drivers/vfio/platform/vfio_platform_irq.c
 @@ -45,11 +45,91 @@ static int vfio_platform_set_irq_unmask(struct 
 vfio_platform_device *vdev,
   return -EINVAL;
  }
  
 +static irqreturn_t vfio_irq_handler(int irq, void *dev_id)
 +{
 + struct vfio_platform_irq *irq_ctx = dev_id;
 +
 + eventfd_signal(irq_ctx-trigger, 1);
 +
 + return IRQ_HANDLED;
 +}
 +
 +static int vfio_set_trigger(struct vfio_platform_device *vdev,
 + int index, int fd)
 +{
 + struct vfio_platform_irq *irq = vdev-irqs[index];
 + struct eventfd_ctx *trigger;
 + int ret;
 +
 + if (irq-trigger) {
 + free_irq(irq-hwirq, irq);
 + kfree(irq-name);
 + eventfd_ctx_put(irq-trigger);
 + irq-trigger = NULL;
 + }
 +
 + if (fd  0) /* Disable only */
 + return 0;
 +
 + irq-name = kasprintf(GFP_KERNEL, vfio-irq[%d](%s),
 + irq-hwirq, vdev-name);
 + if (!irq-name)
 + return -ENOMEM;
 +
 + trigger = eventfd_ctx_fdget(fd);
 + if (IS_ERR(trigger)) {
 + kfree(irq-name);
 + return PTR_ERR(trigger);
 + }
 +
 + irq-trigger = trigger;
 +
 + ret = request_irq(irq-hwirq, vfio_irq_handler, 0, irq-name, irq);
 + if (ret) {
 + kfree(irq-name);
 + eventfd_ctx_put(trigger);
 + irq-trigger = NULL;
 + return ret;
 + }
 +
 + return 0;
 +}
 +
  static int vfio_platform_set_irq_trigger(struct vfio_platform_device *vdev,
unsigned index, unsigned start,
unsigned count, uint32_t flags, void *data)
  {
 - return -EINVAL;
 + struct vfio_platform_irq *irq = vdev-irqs[index];
 + uint8_t irq_bitmap;

Minor nit here and also present in the next patch, I believe when we
have DATA_BOOL, it's defined to be a u8 array, where each byte is a
bool, not each bit.  So it's not actually a bitmap.  The PCI code
handles any non-zero byte as true, not just bit0.  Thanks,

Alex

 + int32_t fd;
 +
 + switch (flags  VFIO_IRQ_SET_DATA_TYPE_MASK) {
 + case VFIO_IRQ_SET_DATA_NONE:
 + if (count == 0)
 + return vfio_set_trigger(vdev, index, -1);
 +
 + vfio_irq_handler(irq-hwirq, irq);
 + return 0;
 +
 + case VFIO_IRQ_SET_DATA_BOOL:
 + if (copy_from_user(irq_bitmap, data, sizeof(uint8_t)))
 + return -EFAULT;
 +
 + if (irq_bitmap == 0x1) {
 + vfio_irq_handler(irq-hwirq, irq);
 + return 0;
 + }
 +
 + return -EINVAL;
 +
 + case VFIO_IRQ_SET_DATA_EVENTFD:
 + if (copy_from_user(fd, data, sizeof(int32_t)))
 + return -EFAULT;
 +
 + return vfio_set_trigger(vdev, index, fd);
 + }
 +
 + return -EFAULT;
  }
  
  int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
 @@ -95,7 +175,7 @@ int vfio_platform_irq_init(struct vfio_platform_device 
 *vdev)
   if (hwirq  0)
   goto err;
  
 - vdev-irqs[i].flags = 0;
 + vdev-irqs[i].flags = VFIO_IRQ_INFO_EVENTFD;
   vdev-irqs[i].count = 1;
   vdev-irqs[i].hwirq = hwirq;
   }
 @@ -110,6 +190,11 @@ err:
  
  void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev)
  {
 + int i;
 +
 + for (i = 0; i  vdev-num_irqs; i++)
 + vfio_set_trigger(vdev, i, -1);
 +
   vdev-num_irqs = 0;
   kfree(vdev-irqs);
  }
 diff --git a/drivers/vfio/platform/vfio_platform_private.h 
 b/drivers/vfio/platform/vfio_platform_private.h
 index 4201b94..765b371 100644
 --- a/drivers/vfio/platform/vfio_platform_private.h
 +++ b/drivers/vfio/platform/vfio_platform_private.h
 @@ -28,6 +28,8 @@ struct vfio_platform_irq {
   u32 flags;
   u32 count;
   int hwirq;
 + char*name;
 + struct eventfd_ctx  *trigger;
  };
  
  struct vfio_platform_region {



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] kvm: Fix page ageing bugs

2014-09-24 Thread Andres Lagar-Cavilla
On Wed, Sep 24, 2014 at 1:27 AM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 24/09/2014 09:20, Wanpeng Li ha scritto:

 This trace point still dup duplicated message for the same gfn in the
 for loop.

 Yes, but the gfn argument lets you take it out again.

 Note that having the duplicated trace would make sense if you included
 the accessed bit for each spte, instead of just the young variable.

FWIW the new arrangement in kvm.git/queue LGTM

Thanks
Andres


 Paolo



-- 
Andres Lagar-Cavilla | Google Kernel Team | andre...@google.com
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


reduce networking latency

2014-09-24 Thread David Xu
Hi Michael,

I found this interesting project from KVM TODO website:

allow handling short packets from softirq or VCPU context
 Plan:
   We are going through the scheduler 3 times
   (could be up to 5 if softirqd is involved)
   Consider RX: host irq - io thread - VCPU thread -
   guest irq - guest thread.
   This adds a lot of latency.
   We can cut it by some 1.5x if we do a bit of work
   either in the VCPU or softirq context.
 Testing: netperf TCP RR - should be improved drastically
  netperf TCP STREAM guest to host - no regression

Would you mind saying more about the work either in the vCPU or
softirq context? Why it is only for short packets handling? Thanks a
lot!


Regards,

Cong
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] x86: kvm: use alternatives for VMCALL vs. VMMCALL if kernel text is read-only

2014-09-24 Thread Thomas Gleixner
On Mon, 22 Sep 2014, Paolo Bonzini wrote:

 On x86_64, kernel text mappings are mapped read-only with CONFIG_DEBUG_RODATA.
 In that case, KVM will fail to patch VMCALL instructions to VMMCALL
 as required on AMD processors.

 The failure mode is currently a divide-by-zero exception, which obviously
 is a KVM bug that has to be fixed.  However, picking the right instruction
 between VMCALL and VMMCALL will be faster and will help if you cannot upgrade
 the hypervisor.

 -/* This instruction is vmcall.  On non-VT architectures, it will generate a
 - * trap that we will then rewrite to the appropriate instruction.
 +#ifdef CONFIG_DEBUG_RODATA
 +#define KVM_HYPERCALL \
 +ALTERNATIVE(.byte 0x0f,0x01,0xc1, .byte 0x0f,0x01,0xd9, 
 X86_FEATURE_VMMCALL)

If we can do it via a feature bit and alternatives, then why do you
want to patch it manually if CONFIG_DEBUG_RODATA=n?

Just because more #ifdeffery makes the code more readable?

Thanks,

tglx
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 04/24] KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Dbsr is not visible to userspace and we do not think any need to
expose this to userspace because:
  Userspace cannot inject debug interrupt to guest (as this
  does not know guest ability to handle debug interrupt), so
  userspace will always clear DBSR.
  Now if userspace has to always clear DBSR in KVM_EXIT_DEBUG
  handling then clearing dbsr in kernel looks simple as this
  avoid doing SET_SREGS/set_one_reg() to clear DBSR

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 322da7d..b4ab86c 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -735,6 +735,8 @@ static int kvmppc_handle_debug(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
struct debug_reg *dbg_reg = (vcpu-arch.shadow_dbg_reg);
u32 dbsr = vcpu-arch.dbsr;
 
+   /* Clear guest dbsr (vcpu-arch.dbsr) */
+   vcpu-arch.dbsr = 0;
run-debug.arch.status = 0;
run-debug.arch.address = vcpu-arch.pc;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 02/24] KVM: PPC: BOOKE : Emulate rfdi instruction

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This patch adds rfdi instruction emulation which is required for
guest debug hander on BOOKE-HV

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |  1 +
 arch/powerpc/kvm/booke_emulate.c| 13 +
 2 files changed, 14 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 6040008..8a8da0a 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -139,6 +139,7 @@ enum kvm_exit_types {
EMULATED_TLBWE_EXITS,
EMULATED_RFI_EXITS,
EMULATED_RFCI_EXITS,
+   EMULATED_RFDI_EXITS,
DEC_EXITS,
EXT_INTR_EXITS,
HALT_WAKEUP,
diff --git a/arch/powerpc/kvm/booke_emulate.c b/arch/powerpc/kvm/booke_emulate.c
index 28c1588..4b9a079 100644
--- a/arch/powerpc/kvm/booke_emulate.c
+++ b/arch/powerpc/kvm/booke_emulate.c
@@ -25,6 +25,7 @@
 
 #define OP_19_XOP_RFI 50
 #define OP_19_XOP_RFCI51
+#define OP_19_XOP_RFDI39
 
 #define OP_31_XOP_MFMSR   83
 #define OP_31_XOP_WRTEE   131
@@ -37,6 +38,12 @@ static void kvmppc_emul_rfi(struct kvm_vcpu *vcpu)
kvmppc_set_msr(vcpu, vcpu-arch.shared-srr1);
 }
 
+static void kvmppc_emul_rfdi(struct kvm_vcpu *vcpu)
+{
+   vcpu-arch.pc = vcpu-arch.dsrr0;
+   kvmppc_set_msr(vcpu, vcpu-arch.dsrr1);
+}
+
 static void kvmppc_emul_rfci(struct kvm_vcpu *vcpu)
 {
vcpu-arch.pc = vcpu-arch.csrr0;
@@ -65,6 +72,12 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
*advance = 0;
break;
 
+   case OP_19_XOP_RFDI:
+   kvmppc_emul_rfdi(vcpu);
+   kvmppc_set_exit_type(vcpu, EMULATED_RFDI_EXITS);
+   *advance = 0;
+   break;
+
default:
emulated = EMULATE_FAIL;
break;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 18/24] KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads

2014-09-24 Thread Alexander Graf
From: Paul Mackerras pau...@au1.ibm.com

Occasional failures have been seen with split-core mode and migration
where the message KVM: couldn't grab cpu appears.  This increases
the length of time that we wait from 1ms to 10ms, which seems to
work around the issue.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 27cced9..4526bef 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1489,7 +1489,7 @@ static void kvmppc_remove_runnable(struct kvmppc_vcore 
*vc,
 static int kvmppc_grab_hwthread(int cpu)
 {
struct paca_struct *tpaca;
-   long timeout = 1000;
+   long timeout = 1;
 
tpaca = paca[cpu];
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 24/24] KVM: PPC: Pass enum to kvmppc_get_last_inst

2014-09-24 Thread Alexander Graf
The kvmppc_get_last_inst function recently received a facelift that allowed
us to pass an enum of the type of instruction we want to read into it rather
than an unreadable boolean.

Unfortunately, not all callers ended up passing the enum. This wasn't really
an issue as true and false happen to match the two enum values we have,
but it's still hard to read.

Update all callers of kvmppc_get_last_inst() to follow the new calling
convention.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 4 ++--
 arch/powerpc/kvm/emulate.c   | 2 +-
 arch/powerpc/kvm/emulate_loadstore.c | 2 +-
 arch/powerpc/kvm/powerpc.c   | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ed5b0dd..9b55dec 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -992,12 +992,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_DATA_STORAGE:
case BOOKE_INTERRUPT_DTLB_MISS:
case BOOKE_INTERRUPT_HV_PRIV:
-   emulated = kvmppc_get_last_inst(vcpu, false, last_inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, last_inst);
break;
case BOOKE_INTERRUPT_PROGRAM:
/* SW breakpoints arrive as illegal instructions on HV */
if (vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP)
-   emulated = kvmppc_get_last_inst(vcpu, false, 
last_inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, 
last_inst);
break;
default:
break;
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 005222b..5cc2e7a 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -219,7 +219,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
 
-   emulated = kvmppc_get_last_inst(vcpu, false, inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, inst);
if (emulated != EMULATE_DONE)
return emulated;
 
diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index 0de4ffa..6d3c0ee 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -58,7 +58,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
 
-   emulated = kvmppc_get_last_inst(vcpu, false, inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, inst);
if (emulated != EMULATE_DONE)
return emulated;
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ecf0575..c1f8f53 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -294,7 +294,7 @@ int kvmppc_emulate_mmio(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
{
u32 last_inst;
 
-   kvmppc_get_last_inst(vcpu, false, last_inst);
+   kvmppc_get_last_inst(vcpu, INST_GENERIC, last_inst);
/* XXX Deliver Program interrupt to guest. */
pr_emerg(%s: emulation failed (%08x)\n, __func__, last_inst);
r = RESUME_HOST;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 16/24] KVM: PPC: Remove the tasklet used by the hrtimer

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Powerpc timer implementation is a copycat version of s390. Now that they removed
the tasklet with commit ea74c0ea1b24a6978a6ebc80ba4dbc7b7848b32d follow this
optimization.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Bogdan Purcareata bogdan.purcare...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h | 1 -
 arch/powerpc/include/asm/kvm_ppc.h  | 2 +-
 arch/powerpc/kvm/book3s.c   | 4 +---
 arch/powerpc/kvm/booke.c| 4 +---
 arch/powerpc/kvm/powerpc.c  | 8 +---
 5 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index bad3491..d243240 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -606,7 +606,6 @@ struct kvm_vcpu_arch {
u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
 
struct hrtimer dec_timer;
-   struct tasklet_struct tasklet;
u64 dec_jiffies;
u64 dec_expires;
unsigned long pending_exceptions;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 05e58b6..73063ef 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -89,7 +89,7 @@ extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu);
 extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
-extern void kvmppc_decrementer_func(unsigned long data);
+extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu);
 extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
 extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu);
 extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 1b5adda..f23b6a5 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -718,10 +718,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu 
*vcpu,
return -EINVAL;
 }
 
-void kvmppc_decrementer_func(unsigned long data)
+void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
 {
-   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
-
kvmppc_core_queue_dec(vcpu);
kvm_vcpu_kick(vcpu);
 }
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index b4e81e6..97ec5b7 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1822,10 +1822,8 @@ void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 
tsr_bits)
update_timer_ints(vcpu);
 }
 
-void kvmppc_decrementer_func(unsigned long data)
+void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
 {
-   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
-
if (vcpu-arch.tcr  TCR_ARE) {
vcpu-arch.dec = vcpu-arch.decar;
kvmppc_emulate_dec(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0c7d191..ecf0575 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -638,7 +638,6 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
 {
/* Make sure we're not using the vcpu anymore */
hrtimer_cancel(vcpu-arch.dec_timer);
-   tasklet_kill(vcpu-arch.tasklet);
 
kvmppc_remove_vcpu_debugfs(vcpu);
 
@@ -664,16 +663,12 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
return kvmppc_core_pending_dec(vcpu);
 }
 
-/*
- * low level hrtimer wake routine. Because this runs in hardirq context
- * we schedule a tasklet to do the real work.
- */
 enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)
 {
struct kvm_vcpu *vcpu;
 
vcpu = container_of(timer, struct kvm_vcpu, arch.dec_timer);
-   tasklet_schedule(vcpu-arch.tasklet);
+   kvmppc_decrementer_func(vcpu);
 
return HRTIMER_NORESTART;
 }
@@ -683,7 +678,6 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
int ret;
 
hrtimer_init(vcpu-arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
-   tasklet_init(vcpu-arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu);
vcpu-arch.dec_timer.function = kvmppc_decrementer_wakeup;
vcpu-arch.dec_expires = ~(u64)0;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 11/24] KVM: PPC: Book3E: Increase FPU laziness

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Increase FPU laziness by loading the guest state into the unit before entering
the guest instead of doing it on each vcpu schedule. Without this improvement
an interrupt may claim floating point corrupting guest state.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c  | 43 ---
 arch/powerpc/kvm/booke.h  | 34 --
 arch/powerpc/kvm/e500mc.c |  2 --
 3 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 074b7fc..91e7217 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -124,6 +124,40 @@ static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
 }
 #endif
 
+/*
+ * Load up guest vcpu FP state if it's needed.
+ * It also set the MSR_FP in thread so that host know
+ * we're holding FPU, and then host can help to save
+ * guest vcpu FP state if other threads require to use FPU.
+ * This simulates an FP unavailable fault.
+ *
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (!(current-thread.regs-msr  MSR_FP)) {
+   enable_kernel_fp();
+   load_fp_state(vcpu-arch.fp);
+   current-thread.fp_save_area = vcpu-arch.fp;
+   current-thread.regs-msr |= MSR_FP;
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu FP state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (current-thread.regs-msr  MSR_FP)
+   giveup_fpu(current);
+   current-thread.fp_save_area = NULL;
+#endif
+}
+
 static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
 {
 #if defined(CONFIG_PPC_FPU)  !defined(CONFIG_KVM_BOOKE_HV)
@@ -658,12 +692,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
/*
 * Since we can't trap on MSR_FP in GS-mode, we consider the guest
-* as always using the FPU.  Kernel usage of FP (via
-* enable_kernel_fp()) in this thread must not occur while
-* vcpu-fpu_active is set.
+* as always using the FPU.
 */
-   vcpu-fpu_active = 1;
-
kvmppc_load_guest_fp(vcpu);
 #endif
 
@@ -687,8 +717,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
 #ifdef CONFIG_PPC_FPU
kvmppc_save_guest_fp(vcpu);
-
-   vcpu-fpu_active = 0;
 #endif
 
 out:
@@ -1194,6 +1222,7 @@ out:
else {
/* interrupts now hard-disabled */
kvmppc_fix_ee_before_entry();
+   kvmppc_load_guest_fp(vcpu);
}
}
 
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index f753543..e73d513 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -116,40 +116,6 @@ extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu 
*vcpu, int sprn,
 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
  ulong *spr_val);
 
-/*
- * Load up guest vcpu FP state if it's needed.
- * It also set the MSR_FP in thread so that host know
- * we're holding FPU, and then host can help to save
- * guest vcpu FP state if other threads require to use FPU.
- * This simulates an FP unavailable fault.
- *
- * It requires to be called with preemption disabled.
- */
-static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
-{
-#ifdef CONFIG_PPC_FPU
-   if (vcpu-fpu_active  !(current-thread.regs-msr  MSR_FP)) {
-   enable_kernel_fp();
-   load_fp_state(vcpu-arch.fp);
-   current-thread.fp_save_area = vcpu-arch.fp;
-   current-thread.regs-msr |= MSR_FP;
-   }
-#endif
-}
-
-/*
- * Save guest vcpu FP state into thread.
- * It requires to be called with preemption disabled.
- */
-static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
-{
-#ifdef CONFIG_PPC_FPU
-   if (vcpu-fpu_active  (current-thread.regs-msr  MSR_FP))
-   giveup_fpu(current);
-   current-thread.fp_save_area = NULL;
-#endif
-}
-
 static inline void kvmppc_clear_dbsr(void)
 {
mtspr(SPRN_DBSR, mfspr(SPRN_DBSR));
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 000cf82..4549349 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -145,8 +145,6 @@ static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu 
*vcpu, int cpu)
kvmppc_e500_tlbil_all(vcpu_e500);
__get_cpu_var(last_vcpu_of_lpid)[vcpu-kvm-arch.lpid] = vcpu;
}
-
-   kvmppc_load_guest_fp(vcpu);
 }
 
 static void kvmppc_core_vcpu_put_e500mc(struct kvm_vcpu *vcpu)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line 

[PULL 21/24] KVM: PPC: Book3E: Enable e6500 core

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Now that AltiVec and hardware thread support is in place enable e6500 core.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500mc.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index bf8f99f..2fdc872 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -180,6 +180,16 @@ int kvmppc_core_check_processor_compat(void)
r = 0;
else if (strcmp(cur_cpu_spec-cpu_name, e5500) == 0)
r = 0;
+#ifdef CONFIG_ALTIVEC
+   /*
+* Since guests have the priviledge to enable AltiVec, we need AltiVec
+* support in the host to save/restore their context.
+* Don't use CPU_FTR_ALTIVEC to identify cores with AltiVec unit
+* because it's cleared in the absence of CONFIG_ALTIVEC!
+*/
+   else if (strcmp(cur_cpu_spec-cpu_name, e6500) == 0)
+   r = 0;
+#endif
else
r = -ENOTSUPP;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 22/24] powerpc/kvm: support to handle sw breakpoint

2014-09-24 Thread Alexander Graf
From: Madhavan Srinivasan ma...@linux.vnet.ibm.com

This patch adds kernel side support for software breakpoint.
Design is that, by using an illegal instruction, we trap to hypervisor
via Emulation Assistance interrupt, where we check for the illegal instruction
and accordingly we return to Host or Guest. Patch also adds support for
software breakpoint in PR KVM.

Signed-off-by: Madhavan Srinivasan ma...@linux.vnet.ibm.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h |  6 ++
 arch/powerpc/kvm/book3s.c  |  3 ++-
 arch/powerpc/kvm/book3s_hv.c   | 41 ++
 arch/powerpc/kvm/book3s_pr.c   |  3 +++
 arch/powerpc/kvm/emulate.c | 15 ++
 5 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 73063ef..dbd160f 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -38,6 +38,12 @@
 #include asm/paca.h
 #endif
 
+/*
+ * KVMPPC_INST_SW_BREAKPOINT is debug Instruction
+ * for supporting software breakpoint.
+ */
+#define KVMPPC_INST_SW_BREAKPOINT  0x0000
+
 enum emulation_result {
EMULATE_DONE, /* no further processing */
EMULATE_DO_MMIO,  /* kvm_run filled with MMIO request */
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index f23b6a5..27d1b70 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -715,7 +715,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
struct kvm_guest_debug *dbg)
 {
-   return -EINVAL;
+   vcpu-guest_debug = dbg-control;
+   return 0;
 }
 
 void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 529d10a..e63587d 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -725,6 +725,30 @@ static int kvmppc_hcall_impl_hv(unsigned long cmd)
return kvmppc_hcall_impl_hv_realmode(cmd);
 }
 
+static int kvmppc_emulate_debug_inst(struct kvm_run *run,
+   struct kvm_vcpu *vcpu)
+{
+   u32 last_inst;
+
+   if (kvmppc_get_last_inst(vcpu, INST_GENERIC, last_inst) !=
+   EMULATE_DONE) {
+   /*
+* Fetch failed, so return to guest and
+* try executing it again.
+*/
+   return RESUME_GUEST;
+   }
+
+   if (last_inst == KVMPPC_INST_SW_BREAKPOINT) {
+   run-exit_reason = KVM_EXIT_DEBUG;
+   run-debug.arch.address = kvmppc_get_pc(vcpu);
+   return RESUME_HOST;
+   } else {
+   kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+   return RESUME_GUEST;
+   }
+}
+
 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 struct task_struct *tsk)
 {
@@ -807,12 +831,18 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
break;
/*
 * This occurs if the guest executes an illegal instruction.
-* We just generate a program interrupt to the guest, since
-* we don't emulate any guest instructions at this stage.
+* If the guest debug is disabled, generate a program interrupt
+* to the guest. If guest debug is enabled, we need to check
+* whether the instruction is a software breakpoint instruction.
+* Accordingly return to Guest or Host.
 */
case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
-   kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
-   r = RESUME_GUEST;
+   if (vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP) {
+   r = kvmppc_emulate_debug_inst(run, vcpu);
+   } else {
+   kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+   r = RESUME_GUEST;
+   }
break;
/*
 * This occurs if the guest (kernel or userspace), does something that
@@ -924,6 +954,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 
id,
long int i;
 
switch (id) {
+   case KVM_REG_PPC_DEBUG_INST:
+   *val = get_reg_val(id, KVMPPC_INST_SW_BREAKPOINT);
+   break;
case KVM_REG_PPC_HIOR:
*val = get_reg_val(id, 0);
break;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index faffb27..6d73708 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1319,6 +1319,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, 
u64 id,
int r = 0;
 
switch (id) {
+   case KVM_REG_PPC_DEBUG_INST:
+   *val = get_reg_val(id, 

[PULL 20/24] KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

ePAPR represents hardware threads as cpu node properties in device tree.
So with existing QEMU, hardware threads are simply exposed as vcpus with
one hardware thread.

The e6500 core shares TLBs between hardware threads. Without tlb write
conditional instruction, the Linux kernel uses per core mechanisms to
protect against duplicate TLB entries.

The guest is unable to detect real siblings threads, so it can't use the
TLB protection mechanism. An alternative solution is to use the hypervisor
to allocate different lpids to guest's vcpus that runs simultaneous on real
siblings threads. On systems with two threads per core this patch halves
the size of the lpid pool that the allocator sees and use two lpids per VM.
Use even numbers to speedup vcpu lpid computation with consecutive lpids
per VM: vm1 will use lpids 2 and 3, vm2 lpids 4 and 5, and so on.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
[agraf: fix spelling]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_booke.h |  5 +++-
 arch/powerpc/kvm/e500.h  | 20 
 arch/powerpc/kvm/e500_mmu_host.c | 18 +++---
 arch/powerpc/kvm/e500mc.c| 46 ++--
 4 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index f7aa5cc..630134d 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -23,7 +23,10 @@
 #include linux/types.h
 #include linux/kvm_host.h
 
-/* LPIDs we support with this build -- runtime limit may be lower */
+/*
+ * Number of available lpids. Only the low-order 6 bits of LPID rgister are
+ * implemented on e500mc+ cores.
+ */
 #define KVMPPC_NR_LPIDS64
 
 #define KVMPPC_INST_EHPRIV 0x7c00021c
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index a326178..72920be 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -22,6 +22,7 @@
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
 #include asm/tlb.h
+#include asm/cputhreads.h
 
 enum vcpu_ftr {
VCPU_FTR_MMU_V2
@@ -289,6 +290,25 @@ void kvmppc_e500_tlbil_all(struct kvmppc_vcpu_e500 
*vcpu_e500);
 #define kvmppc_e500_get_tlb_stid(vcpu, gtlbe)   get_tlb_tid(gtlbe)
 #define get_tlbmiss_tid(vcpu)   get_cur_pid(vcpu)
 #define get_tlb_sts(gtlbe)  (gtlbe-mas1  MAS1_TS)
+
+/*
+ * These functions should be called with preemption disabled
+ * and the returned value is valid only in that context
+ */
+static inline int get_thread_specific_lpid(int vm_lpid)
+{
+   int vcpu_lpid = vm_lpid;
+
+   if (threads_per_core == 2)
+   vcpu_lpid |= smp_processor_id()  1;
+
+   return vcpu_lpid;
+}
+
+static inline int get_lpid(struct kvm_vcpu *vcpu)
+{
+   return get_thread_specific_lpid(vcpu-kvm-arch.lpid);
+}
 #else
 unsigned int kvmppc_e500_get_tlb_stid(struct kvm_vcpu *vcpu,
  struct kvm_book3e_206_tlb_entry *gtlbe);
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index 08f14bb..c8795a6 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -69,7 +69,8 @@ static inline u32 e500_shadow_mas3_attrib(u32 mas3, int 
usermode)
  * writing shadow tlb entry to host TLB
  */
 static inline void __write_host_tlbe(struct kvm_book3e_206_tlb_entry *stlbe,
-uint32_t mas0)
+uint32_t mas0,
+uint32_t lpid)
 {
unsigned long flags;
 
@@ -80,7 +81,7 @@ static inline void __write_host_tlbe(struct 
kvm_book3e_206_tlb_entry *stlbe,
mtspr(SPRN_MAS3, (u32)stlbe-mas7_3);
mtspr(SPRN_MAS7, (u32)(stlbe-mas7_3  32));
 #ifdef CONFIG_KVM_BOOKE_HV
-   mtspr(SPRN_MAS8, stlbe-mas8);
+   mtspr(SPRN_MAS8, MAS8_TGS | get_thread_specific_lpid(lpid));
 #endif
asm volatile(isync; tlbwe : : : memory);
 
@@ -129,11 +130,12 @@ static inline void write_host_tlbe(struct 
kvmppc_vcpu_e500 *vcpu_e500,
 
if (tlbsel == 0) {
mas0 = get_host_mas0(stlbe-mas2);
-   __write_host_tlbe(stlbe, mas0);
+   __write_host_tlbe(stlbe, mas0, vcpu_e500-vcpu.kvm-arch.lpid);
} else {
__write_host_tlbe(stlbe,
  MAS0_TLBSEL(1) |
- MAS0_ESEL(to_htlb1_esel(sesel)));
+ MAS0_ESEL(to_htlb1_esel(sesel)),
+ vcpu_e500-vcpu.kvm-arch.lpid);
}
 }
 
@@ -176,7 +178,7 @@ void kvmppc_map_magic(struct kvm_vcpu *vcpu)
   MAS3_SW | MAS3_SR | MAS3_UW | MAS3_UR;
magic.mas8 = 0;
 
-   __write_host_tlbe(magic, MAS0_TLBSEL(1) | MAS0_ESEL(tlbcam_index));
+   __write_host_tlbe(magic, MAS0_TLBSEL(1) | 

[PULL 12/24] KVM: PPC: Book3e: Add AltiVec support

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Add AltiVec support in KVM for Book3e. FPU support gracefully reuse host
infrastructure so follow the same approach for AltiVec.

Book3e specification defines shared interrupt numbers for SPE and AltiVec
units. Still SPE is present in e200/e500v2 cores while AltiVec is present in
e6500 core. So we can currently decide at compile-time which of the SPE or
AltiVec units to support exclusively by using CONFIG_SPE_POSSIBLE and
CONFIG_PPC_E500MC defines. As Alexander Graf suggested, keep SPE and AltiVec
exception handlers distinct to improve code readability.

Guests have the privilege to enable AltiVec, so we always need to support
AltiVec in KVM and implicitly in host to reflect interrupts and to save/restore
the unit context. KVM will be loaded on cores with AltiVec unit only if
CONFIG_ALTIVEC is defined. Use this define to guard KVM AltiVec logic.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c  | 74 ++-
 arch/powerpc/kvm/booke.h  |  6 +++
 arch/powerpc/kvm/bookehv_interrupts.S |  9 +
 arch/powerpc/kvm/e500_emulate.c   | 20 ++
 4 files changed, 101 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 91e7217..8ace612 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -168,6 +168,40 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
 #endif
 }
 
+/*
+ * Simulate AltiVec unavailable fault to load guest state
+ * from thread to AltiVec unit.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_altivec(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_ALTIVEC
+   if (cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   if (!(current-thread.regs-msr  MSR_VEC)) {
+   enable_kernel_altivec();
+   load_vr_state(vcpu-arch.vr);
+   current-thread.vr_save_area = vcpu-arch.vr;
+   current-thread.regs-msr |= MSR_VEC;
+   }
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu AltiVec state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_altivec(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_ALTIVEC
+   if (cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   if (current-thread.regs-msr  MSR_VEC)
+   giveup_altivec(current);
+   current-thread.vr_save_area = NULL;
+   }
+#endif
+}
+
 static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
 {
/* Synchronize guest's desire to get debug interrupts into shadow MSR */
@@ -375,9 +409,15 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_ITLB_MISS:
case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_FP_UNAVAIL:
+#ifdef CONFIG_SPE_POSSIBLE
case BOOKE_IRQPRIO_SPE_UNAVAIL:
case BOOKE_IRQPRIO_SPE_FP_DATA:
case BOOKE_IRQPRIO_SPE_FP_ROUND:
+#endif
+#ifdef CONFIG_ALTIVEC
+   case BOOKE_IRQPRIO_ALTIVEC_UNAVAIL:
+   case BOOKE_IRQPRIO_ALTIVEC_ASSIST:
+#endif
case BOOKE_IRQPRIO_AP_UNAVAIL:
allowed = 1;
msr_mask = MSR_CE | MSR_ME | MSR_DE;
@@ -697,6 +737,17 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvmppc_load_guest_fp(vcpu);
 #endif
 
+#ifdef CONFIG_ALTIVEC
+   /* Save userspace AltiVec state in stack */
+   if (cpu_has_feature(CPU_FTR_ALTIVEC))
+   enable_kernel_altivec();
+   /*
+* Since we can't trap on MSR_VEC in GS-mode, we consider the guest
+* as always using the AltiVec.
+*/
+   kvmppc_load_guest_altivec(vcpu);
+#endif
+
/* Switch to guest debug context */
debug = vcpu-arch.dbg_reg;
switch_booke_debug_regs(debug);
@@ -719,6 +770,10 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvmppc_save_guest_fp(vcpu);
 #endif
 
+#ifdef CONFIG_ALTIVEC
+   kvmppc_save_guest_altivec(vcpu);
+#endif
+
 out:
vcpu-mode = OUTSIDE_GUEST_MODE;
return ret;
@@ -1025,7 +1080,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
r = RESUME_GUEST;
break;
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
case BOOKE_INTERRUPT_SPE_UNAVAIL:
/*
 * Guest wants SPE, but host kernel doesn't support it.  Send
@@ -1046,6 +1101,22 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
run-hw.hardware_exit_reason = exit_nr;
r = RESUME_HOST;
break;
+#endif /* CONFIG_SPE_POSSIBLE */
+
+/*
+ * On cores with Vector category, KVM is loaded only if CONFIG_ALTIVEC,
+ * see kvmppc_core_check_processor_compat().
+ 

[PULL 19/24] KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR

2014-09-24 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

Since the guest can read the machine's PVR (Processor Version Register)
directly and see the real value, we should disallow userspace from
setting any value for the guest's PVR other than the real host value.
Therefore this makes kvm_arch_vcpu_set_sregs_hv() check the supplied
PVR value and return an error if it is different from the host value,
which has been put into vcpu-arch.pvr at vcpu creation time.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 4526bef..529d10a 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -856,7 +856,9 @@ static int kvm_arch_vcpu_ioctl_set_sregs_hv(struct kvm_vcpu 
*vcpu,
 {
int i, j;
 
-   kvmppc_set_pvr_hv(vcpu, sregs-pvr);
+   /* Only accept the same PVR as the host's, since we can't spoof it */
+   if (sregs-pvr != vcpu-arch.pvr)
+   return -EINVAL;
 
j = 0;
for (i = 0; i  vcpu-arch.slb_nr; i++) {
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 13/24] KVM: PPC: Make ONE_REG powerpc generic

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Make ONE_REG generic for server and embedded architectures by moving
kvm_vcpu_ioctl_get_one_reg() and kvm_vcpu_ioctl_set_one_reg() functions
to powerpc layer.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s.c  | 121 +++--
 arch/powerpc/kvm/booke.c   |  91 +-
 arch/powerpc/kvm/powerpc.c |  55 +
 3 files changed, 138 insertions(+), 129 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index dd03f6b..26868e2 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -535,33 +535,28 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, 
struct kvm_fpu *fpu)
return -ENOTSUPP;
 }
 
-int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
+   union kvmppc_one_reg *val)
 {
-   int r;
-   union kvmppc_one_reg val;
-   int size;
+   int r = 0;
long int i;
 
-   size = one_reg_size(reg-id);
-   if (size  sizeof(val))
-   return -EINVAL;
-
-   r = vcpu-kvm-arch.kvm_ops-get_one_reg(vcpu, reg-id, val);
+   r = vcpu-kvm-arch.kvm_ops-get_one_reg(vcpu, id, val);
if (r == -EINVAL) {
r = 0;
-   switch (reg-id) {
+   switch (id) {
case KVM_REG_PPC_DAR:
-   val = get_reg_val(reg-id, kvmppc_get_dar(vcpu));
+   *val = get_reg_val(id, kvmppc_get_dar(vcpu));
break;
case KVM_REG_PPC_DSISR:
-   val = get_reg_val(reg-id, kvmppc_get_dsisr(vcpu));
+   *val = get_reg_val(id, kvmppc_get_dsisr(vcpu));
break;
case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
-   i = reg-id - KVM_REG_PPC_FPR0;
-   val = get_reg_val(reg-id, VCPU_FPR(vcpu, i));
+   i = id - KVM_REG_PPC_FPR0;
+   *val = get_reg_val(id, VCPU_FPR(vcpu, i));
break;
case KVM_REG_PPC_FPSCR:
-   val = get_reg_val(reg-id, vcpu-arch.fp.fpscr);
+   *val = get_reg_val(id, vcpu-arch.fp.fpscr);
break;
 #ifdef CONFIG_ALTIVEC
case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -569,110 +564,94 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
r = -ENXIO;
break;
}
-   val.vval = vcpu-arch.vr.vr[reg-id - KVM_REG_PPC_VR0];
+   val-vval = vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0];
break;
case KVM_REG_PPC_VSCR:
if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
r = -ENXIO;
break;
}
-   val = get_reg_val(reg-id, vcpu-arch.vr.vscr.u[3]);
+   *val = get_reg_val(id, vcpu-arch.vr.vscr.u[3]);
break;
case KVM_REG_PPC_VRSAVE:
-   val = get_reg_val(reg-id, vcpu-arch.vrsave);
+   *val = get_reg_val(id, vcpu-arch.vrsave);
break;
 #endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
-   long int i = reg-id - KVM_REG_PPC_VSR0;
-   val.vsxval[0] = vcpu-arch.fp.fpr[i][0];
-   val.vsxval[1] = vcpu-arch.fp.fpr[i][1];
+   i = id - KVM_REG_PPC_VSR0;
+   val-vsxval[0] = vcpu-arch.fp.fpr[i][0];
+   val-vsxval[1] = vcpu-arch.fp.fpr[i][1];
} else {
r = -ENXIO;
}
break;
 #endif /* CONFIG_VSX */
-   case KVM_REG_PPC_DEBUG_INST: {
-   u32 opcode = INS_TW;
-   r = copy_to_user((u32 __user *)(long)reg-addr,
-opcode, sizeof(u32));
+   case KVM_REG_PPC_DEBUG_INST:
+   *val = get_reg_val(id, INS_TW);
break;
-   }
 #ifdef CONFIG_KVM_XICS
case KVM_REG_PPC_ICP_STATE:
if (!vcpu-arch.icp) {
r = -ENXIO;
break;
}
-   val = get_reg_val(reg-id, kvmppc_xics_get_icp(vcpu));
+ 

[PULL 09/24] KVM: PPC: Book3S HV: Add register name when loading toc

2014-09-24 Thread Alexander Graf
From: Michael Neuling mi...@neuling.org

Add 'r' to register name r2 in kvmppc_hv_enter.

Also update comment at the top of kvmppc_hv_enter to indicate that R2/TOC is
non-volatile.

Signed-off-by: Michael Neuling mi...@neuling.org
Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index f0c4db7..edb2ccd 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -355,6 +355,7 @@ kvmppc_hv_entry:
 * MSR = ~IR|DR
 * R13 = PACA
 * R1 = host R1
+* R2 = TOC
 * all other volatile GPRS = free
 */
mflrr0
@@ -503,7 +504,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 toc_tlbie_lock:
.tc native_tlbie_lock[TC],native_tlbie_lock
.previous
-   ld  r3,toc_tlbie_lock@toc(2)
+   ld  r3,toc_tlbie_lock@toc(r2)
 #ifdef __BIG_ENDIAN__
lwz r8,PACA_LOCK_TOKEN(r13)
 #else
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 17/24] KVM: PPC: Remove shared defines for SPE and AltiVec interrupts

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

We currently decide at compile-time which of the SPE or AltiVec units to
support exclusively. Guard kernel defines with CONFIG_SPE_POSSIBLE and
CONFIG_PPC_E500MC and remove shared defines.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_asm.h | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 465dfcb..5bca220 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -53,17 +53,17 @@
 #define BOOKE_INTERRUPT_DEBUG 15
 
 /* E500 */
-#define BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL 32
-#define BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST 33
-/*
- * TODO: Unify 32-bit and 64-bit kernel exception handlers to use same defines
- */
-#define BOOKE_INTERRUPT_SPE_UNAVAIL BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL
-#define BOOKE_INTERRUPT_SPE_FP_DATA BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST
-#define BOOKE_INTERRUPT_ALTIVEC_UNAVAIL BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL
-#define BOOKE_INTERRUPT_ALTIVEC_ASSIST \
-   BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST
+#ifdef CONFIG_SPE_POSSIBLE
+#define BOOKE_INTERRUPT_SPE_UNAVAIL 32
+#define BOOKE_INTERRUPT_SPE_FP_DATA 33
 #define BOOKE_INTERRUPT_SPE_FP_ROUND 34
+#endif
+
+#ifdef CONFIG_PPC_E500MC
+#define BOOKE_INTERRUPT_ALTIVEC_UNAVAIL 32
+#define BOOKE_INTERRUPT_ALTIVEC_ASSIST 33
+#endif
+
 #define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
 #define BOOKE_INTERRUPT_DOORBELL 36
 #define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 10/24] KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This was missed in respective one_reg implementation patch.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 Documentation/virtual/kvm/api.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index f7735c7..7610eaa 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1901,6 +1901,8 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_ARCH_COMPAT   | 32
   PPC   | KVM_REG_PPC_DABRX | 32
   PPC   | KVM_REG_PPC_WORT  | 64
+  PPC  | KVM_REG_PPC_SPRG9 | 64
+  PPC  | KVM_REG_PPC_DBSR  | 32
   PPC   | KVM_REG_PPC_TM_GPR0   | 64
   ...
   PPC   | KVM_REG_PPC_TM_GPR31  | 64
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 23/24] powerpc/kvm: common sw breakpoint instr across ppc

2014-09-24 Thread Alexander Graf
From: Madhavan Srinivasan ma...@linux.vnet.ibm.com

This patch extends the use of illegal instruction as software
breakpoint instruction across the ppc platform. Patch extends
booke program interrupt code to support software breakpoint.

Signed-off-by: Madhavan Srinivasan ma...@linux.vnet.ibm.com
[agraf: Fix bookehv]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_booke.h  |  2 --
 arch/powerpc/kvm/booke.c  | 19 ++-
 arch/powerpc/kvm/bookehv_interrupts.S |  4 ++--
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index 630134d..3286f0d 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -33,8 +33,6 @@
 #define EHPRIV_OC_SHIFT11
 /* ehpriv 1 : ehpriv with OC = 1 is used for debug emulation */
 #define EHPRIV_OC_DEBUG1
-#define KVMPPC_INST_EHPRIV_DEBUG   (KVMPPC_INST_EHPRIV | \
-(EHPRIV_OC_DEBUG  EHPRIV_OC_SHIFT))
 
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 97ec5b7..ed5b0dd 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -994,6 +994,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_HV_PRIV:
emulated = kvmppc_get_last_inst(vcpu, false, last_inst);
break;
+   case BOOKE_INTERRUPT_PROGRAM:
+   /* SW breakpoints arrive as illegal instructions on HV */
+   if (vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP)
+   emulated = kvmppc_get_last_inst(vcpu, false, 
last_inst);
+   break;
default:
break;
}
@@ -1071,6 +1076,18 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case BOOKE_INTERRUPT_PROGRAM:
+   if ((vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP) 
+   (last_inst == KVMPPC_INST_SW_BREAKPOINT)) {
+   /*
+* We are here because of an SW breakpoint instr,
+* so lets return to host to handle.
+*/
+   r = kvmppc_handle_debug(run, vcpu);
+   run-exit_reason = KVM_EXIT_DEBUG;
+   kvmppc_account_exit(vcpu, DEBUG_EXITS);
+   break;
+   }
+
if (vcpu-arch.shared-msr  (MSR_PR | MSR_GS)) {
/*
 * Program traps generated by user-level software must
@@ -1647,7 +1664,7 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
*val = get_reg_val(id, vcpu-arch.tsr);
break;
case KVM_REG_PPC_DEBUG_INST:
-   *val = get_reg_val(id, KVMPPC_INST_EHPRIV_DEBUG);
+   *val = get_reg_val(id, KVMPPC_INST_SW_BREAKPOINT);
break;
case KVM_REG_PPC_VRSAVE:
*val = get_reg_val(id, vcpu-arch.vrsave);
diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index c8e4da5..81bd8a0 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -238,7 +238,7 @@ kvm_handler BOOKE_INTERRUPT_EXTERNAL, EX_PARAMS(GEN), \
 kvm_handler BOOKE_INTERRUPT_ALIGNMENT, EX_PARAMS(GEN), \
SPRN_SRR0, SPRN_SRR1,(NEED_DEAR | NEED_ESR)
 kvm_handler BOOKE_INTERRUPT_PROGRAM, EX_PARAMS(GEN), \
-   SPRN_SRR0, SPRN_SRR1,NEED_ESR
+   SPRN_SRR0, SPRN_SRR1, (NEED_ESR | NEED_EMU)
 kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, EX_PARAMS(GEN), \
SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, EX_PARAMS(GEN), \
@@ -348,7 +348,7 @@ kvm_handler BOOKE_INTERRUPT_INST_STORAGE, SPRN_SRR0, 
SPRN_SRR1, NEED_ESR
 kvm_handler BOOKE_INTERRUPT_EXTERNAL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_ALIGNMENT, \
SPRN_SRR0, SPRN_SRR1, (NEED_DEAR | NEED_ESR)
-kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, NEED_ESR
+kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, (NEED_ESR | 
NEED_EMU)
 kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 01/24] KVM: PPC: BOOKE: allow debug interrupt at debug level

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Debug interrupt can be either critical level or debug level.
There are separate set of save/restore registers used for different level.
Example: DSRR0/DSRR1 are used for debug level and CSRR0/CSRR1
are used for critical level debug interrupt.

Using CPU_FTR_DEBUG_LVL_EXC to decide which interrupt level to be used.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index b4c89fa..322da7d 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -377,7 +377,11 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
allowed = vcpu-arch.shared-msr  MSR_DE;
allowed = allowed  !crit;
msr_mask = MSR_ME;
-   int_class = INT_CLASS_CRIT;
+   if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
+   int_class = INT_CLASS_DBG;
+   else
+   int_class = INT_CLASS_CRIT;
+
break;
}
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 07/24] powerpc/booke: Restrict SPE exception handlers to e200/e500 cores

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

SPE exception handlers are now defined for 32-bit e500mc cores even though
SPE unit is not present and CONFIG_SPE is undefined.

Restrict SPE exception handlers to e200/e500 cores adding CONFIG_SPE_POSSIBLE
and consequently guard __stup_ivors and __setup_cpu functions.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Acked-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/cpu_setup_fsl_booke.S | 12 +++-
 arch/powerpc/kernel/cputable.c|  5 +
 arch/powerpc/kernel/head_fsl_booke.S  | 18 +-
 arch/powerpc/platforms/Kconfig.cputype|  6 +-
 4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/cpu_setup_fsl_booke.S 
b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
index 4f1393d..dddba3e 100644
--- a/arch/powerpc/kernel/cpu_setup_fsl_booke.S
+++ b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
@@ -91,6 +91,7 @@ _GLOBAL(setup_altivec_idle)
 
blr
 
+#ifdef CONFIG_PPC_E500MC
 _GLOBAL(__setup_cpu_e6500)
mflrr6
 #ifdef CONFIG_PPC64
@@ -107,14 +108,20 @@ _GLOBAL(__setup_cpu_e6500)
bl  __setup_cpu_e5500
mtlrr6
blr
+#endif /* CONFIG_PPC_E500MC */
 
 #ifdef CONFIG_PPC32
+#ifdef CONFIG_E200
 _GLOBAL(__setup_cpu_e200)
/* enable dedicated debug exception handling resources (Debug APU) */
mfspr   r3,SPRN_HID0
ori r3,r3,HID0_DAPUEN@l
mtspr   SPRN_HID0,r3
b   __setup_e200_ivors
+#endif /* CONFIG_E200 */
+
+#ifdef CONFIG_E500
+#ifndef CONFIG_PPC_E500MC
 _GLOBAL(__setup_cpu_e500v1)
 _GLOBAL(__setup_cpu_e500v2)
mflrr4
@@ -129,6 +136,7 @@ _GLOBAL(__setup_cpu_e500v2)
 #endif
mtlrr4
blr
+#else /* CONFIG_PPC_E500MC */
 _GLOBAL(__setup_cpu_e500mc)
 _GLOBAL(__setup_cpu_e5500)
mflrr5
@@ -159,7 +167,9 @@ _GLOBAL(__setup_cpu_e5500)
 2:
mtlrr5
blr
-#endif
+#endif /* CONFIG_PPC_E500MC */
+#endif /* CONFIG_E500 */
+#endif /* CONFIG_PPC32 */
 
 #ifdef CONFIG_PPC_BOOK3E_64
 _GLOBAL(__restore_cpu_e6500)
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 9b6dcaa..8084059 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -1961,6 +1961,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
 #endif /* CONFIG_PPC32 */
 #ifdef CONFIG_E500
 #ifdef CONFIG_PPC32
+#ifndef CONFIG_PPC_E500MC
{   /* e500 */
.pvr_mask   = 0x,
.pvr_value  = 0x8020,
@@ -2000,6 +2001,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500,
.platform   = ppc8548,
},
+#else
{   /* e500mc */
.pvr_mask   = 0x,
.pvr_value  = 0x8023,
@@ -2018,7 +2020,9 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500mc,
.platform   = ppce500mc,
},
+#endif /* CONFIG_PPC_E500MC */
 #endif /* CONFIG_PPC32 */
+#ifdef CONFIG_PPC_E500MC
{   /* e5500 */
.pvr_mask   = 0x,
.pvr_value  = 0x8024,
@@ -2062,6 +2066,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500mc,
.platform   = ppce6500,
},
+#endif /* CONFIG_PPC_E500MC */
 #ifdef CONFIG_PPC32
{   /* default match */
.pvr_mask   = 0x,
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index b497188..90f487f 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -613,6 +613,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
mfspr   r10, SPRN_SPRG_RSCRATCH0
b   InstructionStorage
 
+/* Define SPE handlers for e200 and e500v2 */
 #ifdef CONFIG_SPE
/* SPE Unavailable */
START_EXCEPTION(SPEUnavailable)
@@ -622,10 +623,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
b   fast_exception_return
 1: addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_EE_LITE(0x2010, KernelSPE)
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
EXCEPTION(0x2020, SPE_ALTIVEC_UNAVAIL, SPEUnavailable, \
  unknown_exception, EXC_XFER_EE)
-#endif /* CONFIG_SPE */
+#endif /* CONFIG_SPE_POSSIBLE */
 
/* SPE Floating Point Data */
 #ifdef CONFIG_SPE
@@ -635,12 +636,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
/* SPE Floating Point Round */
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  SPEFloatingPointRoundException, EXC_XFER_EE)
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
EXCEPTION(0x2040, SPE_FP_DATA_ALTIVEC_ASSIST, 

[PULL 03/24] KVM: PPC: BOOKE: Allow guest to change MSR_DE

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This patch changes the default behavior of MSRP_DEP, that is
guest is not allowed to change the MSR_DE, to guest can change
MSR_DE. When userspace is debugging guest then it override the
default behavior and set MSRP_DEP. This stops guest to change
MSR_DE when userspace is debugging guest.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500mc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 164bad2..000cf82 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -194,7 +194,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 #ifdef CONFIG_64BIT
vcpu-arch.shadow_epcr |= SPRN_EPCR_ICM;
 #endif
-   vcpu-arch.shadow_msrp = MSRP_UCLEP | MSRP_DEP | MSRP_PMMP;
+   vcpu-arch.shadow_msrp = MSRP_UCLEP | MSRP_PMMP;
vcpu-arch.eplc = EPC_EGS | (vcpu-kvm-arch.lpid  EPC_ELPID_SHIFT);
vcpu-arch.epsc = vcpu-arch.eplc;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 06/24] KVM: PPC: BOOKE: Add one reg interface for DBSR

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/uapi/asm/kvm.h | 1 +
 arch/powerpc/kvm/booke.c| 6 ++
 2 files changed, 7 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
b/arch/powerpc/include/uapi/asm/kvm.h
index e0e49db..3ca357a 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -557,6 +557,7 @@ struct kvm_get_htab_header {
 #define KVM_REG_PPC_DABRX  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8)
 #define KVM_REG_PPC_WORT   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb9)
 #define KVM_REG_PPC_SPRG9  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba)
+#define KVM_REG_PPC_DBSR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbb)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e47de01..074b7fc 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1494,6 +1494,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DAC2:
val = get_reg_val(reg-id, vcpu-arch.dbg_reg.dac2);
break;
+   case KVM_REG_PPC_DBSR:
+   val = get_reg_val(reg-id, vcpu-arch.dbsr);
+   break;
case KVM_REG_PPC_EPR: {
u32 epr = kvmppc_get_epr(vcpu);
val = get_reg_val(reg-id, epr);
@@ -1564,6 +1567,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DAC2:
vcpu-arch.dbg_reg.dac2 = set_reg_val(reg-id, val);
break;
+   case KVM_REG_PPC_DBSR:
+   vcpu-arch.dbsr = set_reg_val(reg-id, val);
+   break;
case KVM_REG_PPC_EPR: {
u32 new_epr = set_reg_val(reg-id, val);
kvmppc_set_epr(vcpu, new_epr);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 00/24] ppc patch queue 2014-09-24

2014-09-24 Thread Alexander Graf
Hi Paolo,

This is my current patch queue for ppc.  Please pull.

Alex


The following changes since commit f51770ed465e6eb41da7fa16fd92eb67069600cf:

  kvm: Make init_rmode_identity_map() return 0 on success. (2014-09-17 13:10:12 
+0200)

are available in the git repository at:

  git://github.com/agraf/linux-2.6.git tags/signed-kvm-ppc-next

for you to fetch changes up to 8d0eff6385640a9e6eed0b0c09113794b2bb74e9:

  KVM: PPC: Pass enum to kvmppc_get_last_inst (2014-09-22 10:11:36 +0200)


Patch queue for ppc - 2014-09-24

New awesome things in this release:

  - E500: e6500 core support
  - E500: guest and remote debug support
  - Book3S: remote sw breakpoint support
  - Book3S: HV: Minor bugfixes


Alexander Graf (1):
  KVM: PPC: Pass enum to kvmppc_get_last_inst

Bharat Bhushan (8):
  KVM: PPC: BOOKE: allow debug interrupt at debug level
  KVM: PPC: BOOKE : Emulate rfdi instruction
  KVM: PPC: BOOKE: Allow guest to change MSR_DE
  KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG
  KVM: PPC: BOOKE: Guest and hardware visible debug registers are same
  KVM: PPC: BOOKE: Add one reg interface for DBSR
  KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR
  KVM: PPC: BOOKE: Emulate debug registers and exception

Madhavan Srinivasan (2):
  powerpc/kvm: support to handle sw breakpoint
  powerpc/kvm: common sw breakpoint instr across ppc

Michael Neuling (1):
  KVM: PPC: Book3S HV: Add register name when loading toc

Mihai Caraman (10):
  powerpc/booke: Restrict SPE exception handlers to e200/e500 cores
  powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers
  KVM: PPC: Book3E: Increase FPU laziness
  KVM: PPC: Book3e: Add AltiVec support
  KVM: PPC: Make ONE_REG powerpc generic
  KVM: PPC: Move ONE_REG AltiVec support to powerpc
  KVM: PPC: Remove the tasklet used by the hrtimer
  KVM: PPC: Remove shared defines for SPE and AltiVec interrupts
  KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core
  KVM: PPC: Book3E: Enable e6500 core

Paul Mackerras (2):
  KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads
  KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR

 Documentation/virtual/kvm/api.txt |   2 +
 arch/powerpc/include/asm/kvm_asm.h|  20 +--
 arch/powerpc/include/asm/kvm_booke.h  |   7 +-
 arch/powerpc/include/asm/kvm_host.h   |   4 +-
 arch/powerpc/include/asm/kvm_ppc.h|  11 +-
 arch/powerpc/include/asm/reg_booke.h  |   2 +
 arch/powerpc/include/uapi/asm/kvm.h   |   6 +
 arch/powerpc/kernel/cpu_setup_fsl_booke.S |  12 +-
 arch/powerpc/kernel/cputable.c|   5 +
 arch/powerpc/kernel/exceptions-64e.S  |   4 +-
 arch/powerpc/kernel/head_fsl_booke.S  |  26 ++-
 arch/powerpc/kvm/book3s.c | 158 +---
 arch/powerpc/kvm/book3s_hv.c  |  47 -
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   |   3 +-
 arch/powerpc/kvm/book3s_pr.c  |   3 +
 arch/powerpc/kvm/booke.c  | 287 ++
 arch/powerpc/kvm/booke.h  |  40 +
 arch/powerpc/kvm/booke_emulate.c  | 163 +
 arch/powerpc/kvm/bookehv_interrupts.S |  13 +-
 arch/powerpc/kvm/e500.h   |  20 +++
 arch/powerpc/kvm/e500_emulate.c   |  20 +++
 arch/powerpc/kvm/e500_mmu_host.c  |  18 +-
 arch/powerpc/kvm/e500mc.c |  60 +--
 arch/powerpc/kvm/emulate.c|  17 +-
 arch/powerpc/kvm/emulate_loadstore.c  |   2 +-
 arch/powerpc/kvm/powerpc.c| 107 ++-
 arch/powerpc/platforms/Kconfig.cputype|   6 +-
 27 files changed, 763 insertions(+), 300 deletions(-)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 08/24] powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Book3E specification defines shared interrupt numbers for SPE and AltiVec
units. Still SPE is present in e200/e500v2 cores while AltiVec is present in
e6500 core. So we can currently decide at compile-time which unit to support
exclusively. As Alexander Graf suggested, this will improve code readability
especially in KVM.

Use distinct defines to identify SPE/AltiVec interrupt numbers, reverting
c58ce397 and 6b310fc5 patches that added common defines.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Acked-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/exceptions-64e.S | 4 ++--
 arch/powerpc/kernel/head_fsl_booke.S | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index bb9cac6..3e68d1c 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -635,7 +635,7 @@ interrupt_end_book3e:
 
 /* Altivec Unavailable Interrupt */
START_EXCEPTION(altivec_unavailable);
-   NORMAL_EXCEPTION_PROLOG(0x200, BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL,
+   NORMAL_EXCEPTION_PROLOG(0x200, BOOKE_INTERRUPT_ALTIVEC_UNAVAIL,
PROLOG_ADDITION_NONE)
/* we can probably do a shorter exception entry for that one... */
EXCEPTION_COMMON(0x200)
@@ -658,7 +658,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 /* AltiVec Assist */
START_EXCEPTION(altivec_assist);
NORMAL_EXCEPTION_PROLOG(0x220,
-   BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST,
+   BOOKE_INTERRUPT_ALTIVEC_ASSIST,
PROLOG_ADDITION_NONE)
EXCEPTION_COMMON(0x220)
INTS_DISABLE
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index 90f487f..fffd1f9 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -617,27 +617,27 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
 #ifdef CONFIG_SPE
/* SPE Unavailable */
START_EXCEPTION(SPEUnavailable)
-   NORMAL_EXCEPTION_PROLOG(SPE_ALTIVEC_UNAVAIL)
+   NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL)
beq 1f
bl  load_up_spe
b   fast_exception_return
 1: addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_EE_LITE(0x2010, KernelSPE)
 #elif defined(CONFIG_SPE_POSSIBLE)
-   EXCEPTION(0x2020, SPE_ALTIVEC_UNAVAIL, SPEUnavailable, \
+   EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \
  unknown_exception, EXC_XFER_EE)
 #endif /* CONFIG_SPE_POSSIBLE */
 
/* SPE Floating Point Data */
 #ifdef CONFIG_SPE
-   EXCEPTION(0x2030, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
+   EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData,
  SPEFloatingPointException, EXC_XFER_EE)
 
/* SPE Floating Point Round */
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  SPEFloatingPointRoundException, EXC_XFER_EE)
 #elif defined(CONFIG_SPE_POSSIBLE)
-   EXCEPTION(0x2040, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
+   EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData,
  unknown_exception, EXC_XFER_EE)
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  unknown_exception, EXC_XFER_EE)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 15/24] KVM: PPC: BOOKE: Emulate debug registers and exception

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This patch emulates debug registers and debug exception
to support guest using debug resource. This enables running
gdb/kgdb etc in guest.

On BOOKE architecture we cannot share debug resources between QEMU and
guest because:
When QEMU is using debug resources then debug exception must
be always enabled. To achieve this we set MSR_DE and also set
MSRP_DEP so guest cannot change MSR_DE.

When emulating debug resource for guest we want guest
to control MSR_DE (enable/disable debug interrupt on need).

So above mentioned two configuration cannot be supported
at the same time. So the result is that we cannot share
debug resources between QEMU and Guest on BOOKE architecture.

In the current design QEMU gets priority over guest, this means that if
QEMU is using debug resources then guest cannot use them and if guest is
using debug resource then QEMU can overwrite them.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h   |   3 +
 arch/powerpc/include/asm/reg_booke.h |   2 +
 arch/powerpc/kvm/booke.c |  42 +-
 arch/powerpc/kvm/booke_emulate.c | 148 +++
 4 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index fb86a22..05e58b6 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -206,6 +206,9 @@ extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, 
u32 *server,
 extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq);
 extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq);
 
+void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu);
+void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu);
+
 union kvmppc_one_reg {
u32 wval;
u64 dval;
diff --git a/arch/powerpc/include/asm/reg_booke.h 
b/arch/powerpc/include/asm/reg_booke.h
index 1d65330..16547ef 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -319,6 +319,8 @@
  * DBSR bits which have conflicting definitions on true Book E versus IBM 40x.
  */
 #ifdef CONFIG_BOOKE
+#define DBSR_IDE   0x8000  /* Imprecise Debug Event */
+#define DBSR_MRR   0x3000  /* Most Recent Reset */
 #define DBSR_IC0x0800  /* Instruction Completion */
 #define DBSR_BT0x0400  /* Branch Taken */
 #define DBSR_IRPT  0x0200  /* Exception Debug Event */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 831c1b4..b4e81e6 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -335,6 +335,16 @@ static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu 
*vcpu)
clear_bit(BOOKE_IRQPRIO_WATCHDOG, vcpu-arch.pending_exceptions);
 }
 
+void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu)
+{
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DEBUG);
+}
+
+void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu)
+{
+   clear_bit(BOOKE_IRQPRIO_DEBUG, vcpu-arch.pending_exceptions);
+}
+
 static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
 {
kvmppc_set_srr0(vcpu, srr0);
@@ -818,7 +828,32 @@ static int kvmppc_handle_debug(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
struct debug_reg *dbg_reg = (vcpu-arch.dbg_reg);
u32 dbsr = vcpu-arch.dbsr;
 
-   /* Clear guest dbsr (vcpu-arch.dbsr) */
+   if (vcpu-guest_debug == 0) {
+   /*
+* Debug resources belong to Guest.
+* Imprecise debug event is not injected
+*/
+   if (dbsr  DBSR_IDE) {
+   dbsr = ~DBSR_IDE;
+   if (!dbsr)
+   return RESUME_GUEST;
+   }
+
+   if (dbsr  (vcpu-arch.shared-msr  MSR_DE) 
+   (vcpu-arch.dbg_reg.dbcr0  DBCR0_IDM))
+   kvmppc_core_queue_debug(vcpu);
+
+   /* Inject a program interrupt if trap debug is not allowed */
+   if ((dbsr  DBSR_TIE)  !(vcpu-arch.shared-msr  MSR_DE))
+   kvmppc_core_queue_program(vcpu, ESR_PTR);
+
+   return RESUME_GUEST;
+   }
+
+   /*
+* Debug resource owned by userspace.
+* Clear guest dbsr (vcpu-arch.dbsr)
+*/
vcpu-arch.dbsr = 0;
run-debug.arch.status = 0;
run-debug.arch.address = vcpu-arch.pc;
@@ -1350,6 +1385,11 @@ int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
setup_timer(vcpu-arch.wdt_timer, kvmppc_watchdog_func,
(unsigned long)vcpu);
 
+   /*
+* Clear DBSR.MRR to avoid guest debug interrupt as
+* this is of host interest
+*/
+   mtspr(SPRN_DBSR, DBSR_MRR);
return 0;
 }
 
diff --git a/arch/powerpc/kvm/booke_emulate.c 

[PULL 05/24] KVM: PPC: BOOKE: Guest and hardware visible debug registers are same

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Guest visible debug register and hardware visible debug registers are
same, so ther is no need to have arch-shadow_dbg_reg, instead use
arch-dbg_reg.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |  2 --
 arch/powerpc/kvm/booke.c| 16 +++-
 arch/powerpc/kvm/booke_emulate.c|  2 ++
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 8a8da0a..bad3491 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -585,8 +585,6 @@ struct kvm_vcpu_arch {
u32 crit_save;
/* guest debug registers*/
struct debug_reg dbg_reg;
-   /* hardware visible debug registers when in guest state */
-   struct debug_reg shadow_dbg_reg;
 #endif
gpa_t paddr_accessed;
gva_t vaddr_accessed;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index b4ab86c..e47de01 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -668,10 +668,10 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 #endif
 
/* Switch to guest debug context */
-   debug = vcpu-arch.shadow_dbg_reg;
+   debug = vcpu-arch.dbg_reg;
switch_booke_debug_regs(debug);
debug = current-thread.debug;
-   current-thread.debug = vcpu-arch.shadow_dbg_reg;
+   current-thread.debug = vcpu-arch.dbg_reg;
 
vcpu-arch.pgdir = current-mm-pgd;
kvmppc_fix_ee_before_entry();
@@ -732,7 +732,7 @@ static int emulation_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
 
 static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
-   struct debug_reg *dbg_reg = (vcpu-arch.shadow_dbg_reg);
+   struct debug_reg *dbg_reg = (vcpu-arch.dbg_reg);
u32 dbsr = vcpu-arch.dbsr;
 
/* Clear guest dbsr (vcpu-arch.dbsr) */
@@ -1848,7 +1848,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu 
*vcpu,
int n, b = 0, w = 0;
 
if (!(dbg-control  KVM_GUESTDBG_ENABLE)) {
-   vcpu-arch.shadow_dbg_reg.dbcr0 = 0;
+   vcpu-arch.dbg_reg.dbcr0 = 0;
vcpu-guest_debug = 0;
kvm_guest_protect_msr(vcpu, MSR_DE, false);
return 0;
@@ -1856,15 +1856,13 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu 
*vcpu,
 
kvm_guest_protect_msr(vcpu, MSR_DE, true);
vcpu-guest_debug = dbg-control;
-   vcpu-arch.shadow_dbg_reg.dbcr0 = 0;
-   /* Set DBCR0_EDM in guest visible DBCR0 register. */
-   vcpu-arch.dbg_reg.dbcr0 = DBCR0_EDM;
+   vcpu-arch.dbg_reg.dbcr0 = 0;
 
if (vcpu-guest_debug  KVM_GUESTDBG_SINGLESTEP)
-   vcpu-arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
+   vcpu-arch.dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
 
/* Code below handles only HW breakpoints */
-   dbg_reg = (vcpu-arch.shadow_dbg_reg);
+   dbg_reg = (vcpu-arch.dbg_reg);
 
 #ifdef CONFIG_KVM_BOOKE_HV
/*
diff --git a/arch/powerpc/kvm/booke_emulate.c b/arch/powerpc/kvm/booke_emulate.c
index 4b9a079..92bc668 100644
--- a/arch/powerpc/kvm/booke_emulate.c
+++ b/arch/powerpc/kvm/booke_emulate.c
@@ -293,6 +293,8 @@ int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, ulong *spr_val)
break;
case SPRN_DBCR0:
*spr_val = vcpu-arch.dbg_reg.dbcr0;
+   if (vcpu-guest_debug)
+   *spr_val = *spr_val | DBCR0_EDM;
break;
case SPRN_DBCR1:
*spr_val = vcpu-arch.dbg_reg.dbcr1;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 14/24] KVM: PPC: Move ONE_REG AltiVec support to powerpc

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Move ONE_REG AltiVec support to powerpc generic layer.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/uapi/asm/kvm.h |  5 +
 arch/powerpc/kvm/book3s.c   | 42 -
 arch/powerpc/kvm/powerpc.c  | 42 +
 3 files changed, 47 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
b/arch/powerpc/include/uapi/asm/kvm.h
index 3ca357a..ab4d473 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -476,6 +476,11 @@ struct kvm_get_htab_header {
 
 /* FP and vector status/control registers */
 #define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+/*
+ * VSCR register is documented as a 32-bit register in the ISA, but it can
+ * only be accesses via a vector register. Expose VSCR as a 32-bit register
+ * even though the kernel represents it as a 128-bit vector.
+ */
 #define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
 
 /* Virtual processor areas */
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 26868e2..1b5adda 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -558,25 +558,6 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_FPSCR:
*val = get_reg_val(id, vcpu-arch.fp.fpscr);
break;
-#ifdef CONFIG_ALTIVEC
-   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   val-vval = vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0];
-   break;
-   case KVM_REG_PPC_VSCR:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   *val = get_reg_val(id, vcpu-arch.vr.vscr.u[3]);
-   break;
-   case KVM_REG_PPC_VRSAVE:
-   *val = get_reg_val(id, vcpu-arch.vrsave);
-   break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
@@ -653,29 +634,6 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_FPSCR:
vcpu-arch.fp.fpscr = set_reg_val(id, *val);
break;
-#ifdef CONFIG_ALTIVEC
-   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0] = val-vval;
-   break;
-   case KVM_REG_PPC_VSCR:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vr.vscr.u[3] = set_reg_val(id, *val);
-   break;
-   case KVM_REG_PPC_VRSAVE:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vrsave = set_reg_val(id, *val);
-   break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 8a26126..0c7d191 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -921,6 +921,29 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
if (r == -EINVAL) {
r = 0;
switch (reg-id) {
+#ifdef CONFIG_ALTIVEC
+   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
+   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   r = -ENXIO;
+   break;
+   }
+   vcpu-arch.vr.vr[reg-id - KVM_REG_PPC_VR0] = val.vval;
+   break;
+   case KVM_REG_PPC_VSCR:
+   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   r = -ENXIO;
+   break;
+   }
+   vcpu-arch.vr.vscr.u[3] = set_reg_val(reg-id, val);
+   break;
+   case KVM_REG_PPC_VRSAVE:
+   

Re: [PULL 00/24] ppc patch queue 2014-09-24

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 22:43, Alexander Graf ha scritto:
 Hi Paolo,
 
 This is my current patch queue for ppc.  Please pull.
 
 Alex
 
 
 The following changes since commit f51770ed465e6eb41da7fa16fd92eb67069600cf:
 
   kvm: Make init_rmode_identity_map() return 0 on success. (2014-09-17 
 13:10:12 +0200)
 
 are available in the git repository at:
 
   git://github.com/agraf/linux-2.6.git tags/signed-kvm-ppc-next
 
 for you to fetch changes up to 8d0eff6385640a9e6eed0b0c09113794b2bb74e9:
 
   KVM: PPC: Pass enum to kvmppc_get_last_inst (2014-09-22 10:11:36 +0200)
 
 
 Patch queue for ppc - 2014-09-24
 
 New awesome things in this release:
 
   - E500: e6500 core support
   - E500: guest and remote debug support
   - Book3S: remote sw breakpoint support
   - Book3S: HV: Minor bugfixes
 
 
 Alexander Graf (1):
   KVM: PPC: Pass enum to kvmppc_get_last_inst
 
 Bharat Bhushan (8):
   KVM: PPC: BOOKE: allow debug interrupt at debug level
   KVM: PPC: BOOKE : Emulate rfdi instruction
   KVM: PPC: BOOKE: Allow guest to change MSR_DE
   KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG
   KVM: PPC: BOOKE: Guest and hardware visible debug registers are same
   KVM: PPC: BOOKE: Add one reg interface for DBSR
   KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR
   KVM: PPC: BOOKE: Emulate debug registers and exception
 
 Madhavan Srinivasan (2):
   powerpc/kvm: support to handle sw breakpoint
   powerpc/kvm: common sw breakpoint instr across ppc
 
 Michael Neuling (1):
   KVM: PPC: Book3S HV: Add register name when loading toc
 
 Mihai Caraman (10):
   powerpc/booke: Restrict SPE exception handlers to e200/e500 cores
   powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers
   KVM: PPC: Book3E: Increase FPU laziness
   KVM: PPC: Book3e: Add AltiVec support
   KVM: PPC: Make ONE_REG powerpc generic
   KVM: PPC: Move ONE_REG AltiVec support to powerpc
   KVM: PPC: Remove the tasklet used by the hrtimer
   KVM: PPC: Remove shared defines for SPE and AltiVec interrupts
   KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core
   KVM: PPC: Book3E: Enable e6500 core
 
 Paul Mackerras (2):
   KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads
   KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR
 
  Documentation/virtual/kvm/api.txt |   2 +
  arch/powerpc/include/asm/kvm_asm.h|  20 +--
  arch/powerpc/include/asm/kvm_booke.h  |   7 +-
  arch/powerpc/include/asm/kvm_host.h   |   4 +-
  arch/powerpc/include/asm/kvm_ppc.h|  11 +-
  arch/powerpc/include/asm/reg_booke.h  |   2 +
  arch/powerpc/include/uapi/asm/kvm.h   |   6 +
  arch/powerpc/kernel/cpu_setup_fsl_booke.S |  12 +-
  arch/powerpc/kernel/cputable.c|   5 +
  arch/powerpc/kernel/exceptions-64e.S  |   4 +-
  arch/powerpc/kernel/head_fsl_booke.S  |  26 ++-
  arch/powerpc/kvm/book3s.c | 158 +---
  arch/powerpc/kvm/book3s_hv.c  |  47 -
  arch/powerpc/kvm/book3s_hv_rmhandlers.S   |   3 +-
  arch/powerpc/kvm/book3s_pr.c  |   3 +
  arch/powerpc/kvm/booke.c  | 287 
 ++
  arch/powerpc/kvm/booke.h  |  40 +
  arch/powerpc/kvm/booke_emulate.c  | 163 +
  arch/powerpc/kvm/bookehv_interrupts.S |  13 +-
  arch/powerpc/kvm/e500.h   |  20 +++
  arch/powerpc/kvm/e500_emulate.c   |  20 +++
  arch/powerpc/kvm/e500_mmu_host.c  |  18 +-
  arch/powerpc/kvm/e500mc.c |  60 +--
  arch/powerpc/kvm/emulate.c|  17 +-
  arch/powerpc/kvm/emulate_loadstore.c  |   2 +-
  arch/powerpc/kvm/powerpc.c| 107 ++-
  arch/powerpc/platforms/Kconfig.cputype|   6 +-
  27 files changed, 763 insertions(+), 300 deletions(-)
 

Pulled, thanks!

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 03/13] powerpc/spapr: vfio: Implement spapr_tce_iommu_ops

2014-09-24 Thread Alexey Kardashevskiy
On 09/24/2014 06:42 AM, Alex Williamson wrote:
 On Tue, 2014-09-23 at 13:00 +1000, Alexey Kardashevskiy wrote:
 Modern IBM POWERPC systems support multiple IOMMU tables per PE
 so we need a more reliable way (compared to container_of()) to get
 a PE pointer from the iommu_table struct pointer used in IOMMU functions.

 At the moment IOMMU group data points to an iommu_table struct. This
 introduces a spapr_tce_iommu_group struct which keeps an iommu_owner
 and a spapr_tce_iommu_ops struct. For IODA, iommu_owner is a pointer to
 the pnv_ioda_pe struct, for others it is still a pointer to
 the iommu_table struct. The ops structs correspond to the type which
 iommu_owner points to.

 This defines a get_table() callback which returns an iommu_table
 by its number.

 As the IOMMU group data pointer points to variable type instead of
 iommu_table, VFIO SPAPR TCE driver is updated to use the new type.
 This changes the tce_container struct to store iommu_group instead of
 iommu_table.

 So, it was:
 - iommu_table points to iommu_group via iommu_table::it_group;
 - iommu_group points to iommu_table via iommu_group_get_iommudata();

 now it is:
 - iommu_table points to iommu_group via iommu_table::it_group;
 - iommu_group points to spapr_tce_iommu_group via
 iommu_group_get_iommudata();
 - spapr_tce_iommu_group points to either (depending on .get_table()):
  - iommu_table;
  - pnv_ioda_pe;

 This uses pnv_ioda1_iommu_get_table for both IODA12 but IODA2 will
 have own pnv_ioda2_iommu_get_table soon and pnv_ioda1_iommu_get_table
 will only be used for IODA1.

 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 ---
  arch/powerpc/include/asm/iommu.h|   6 ++
  arch/powerpc/include/asm/tce.h  |  13 +++
  arch/powerpc/kernel/iommu.c |  35 ++-
  arch/powerpc/platforms/powernv/pci-ioda.c   |  31 +-
  arch/powerpc/platforms/powernv/pci-p5ioc2.c |   1 +
  arch/powerpc/platforms/powernv/pci.c|   2 +-
  arch/powerpc/platforms/pseries/iommu.c  |  10 +-
  drivers/vfio/vfio_iommu_spapr_tce.c | 148 
 ++--
  8 files changed, 208 insertions(+), 38 deletions(-)

 diff --git a/arch/powerpc/include/asm/iommu.h 
 b/arch/powerpc/include/asm/iommu.h
 index 42632c7..84ee339 100644
 --- a/arch/powerpc/include/asm/iommu.h
 +++ b/arch/powerpc/include/asm/iommu.h
 @@ -108,13 +108,19 @@ extern void iommu_free_table(struct iommu_table *tbl, 
 const char *node_name);
   */
  extern struct iommu_table *iommu_init_table(struct iommu_table * tbl,
  int nid);
 +
 +struct spapr_tce_iommu_ops;
  #ifdef CONFIG_IOMMU_API
  extern void iommu_register_group(struct iommu_table *tbl,
 + void *iommu_owner,
 + struct spapr_tce_iommu_ops *ops,
   int pci_domain_number, unsigned long pe_num);
  extern int iommu_add_device(struct device *dev);
  extern void iommu_del_device(struct device *dev);
  #else
  static inline void iommu_register_group(struct iommu_table *tbl,
 +void *iommu_owner,
 +struct spapr_tce_iommu_ops *ops,
  int pci_domain_number,
  unsigned long pe_num)
  {
 diff --git a/arch/powerpc/include/asm/tce.h b/arch/powerpc/include/asm/tce.h
 index 743f36b..9f159eb 100644
 --- a/arch/powerpc/include/asm/tce.h
 +++ b/arch/powerpc/include/asm/tce.h
 @@ -50,5 +50,18 @@
  #define TCE_PCI_READ0x1 /* read from PCI 
 allowed */
  #define TCE_VB_WRITE0x1 /* write from VB 
 allowed */
  
 +struct spapr_tce_iommu_group;
 +
 +struct spapr_tce_iommu_ops {
 +struct iommu_table *(*get_table)(
 +struct spapr_tce_iommu_group *data,
 +int num);
 +};
 +
 +struct spapr_tce_iommu_group {
 +void *iommu_owner;
 +struct spapr_tce_iommu_ops *ops;
 +};
 +
  #endif /* __KERNEL__ */
  #endif /* _ASM_POWERPC_TCE_H */
 diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
 index b378f78..1c5dae7 100644
 --- a/arch/powerpc/kernel/iommu.c
 +++ b/arch/powerpc/kernel/iommu.c
 @@ -878,24 +878,53 @@ void iommu_free_coherent(struct iommu_table *tbl, 
 size_t size,
   */
  static void group_release(void *iommu_data)
  {
 -struct iommu_table *tbl = iommu_data;
 -tbl-it_group = NULL;
 +kfree(iommu_data);
  }
  
 +static struct iommu_table *spapr_tce_default_get_table(
 +struct spapr_tce_iommu_group *data, int num)
 +{
 +struct iommu_table *tbl = data-iommu_owner;
 +
 +switch (num) {
 +case 0:
 +if (tbl-it_size)
 +return tbl;
 +/* fallthru */
 +default:
 +return NULL;
 +}
 +}
 +
 +static struct spapr_tce_iommu_ops spapr_tce_default_ops = {
 +.get_table = spapr_tce_default_get_table
 +};
 +
  void 

[PULL 13/24] KVM: PPC: Make ONE_REG powerpc generic

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Make ONE_REG generic for server and embedded architectures by moving
kvm_vcpu_ioctl_get_one_reg() and kvm_vcpu_ioctl_set_one_reg() functions
to powerpc layer.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s.c  | 121 +++--
 arch/powerpc/kvm/booke.c   |  91 +-
 arch/powerpc/kvm/powerpc.c |  55 +
 3 files changed, 138 insertions(+), 129 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index dd03f6b..26868e2 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -535,33 +535,28 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, 
struct kvm_fpu *fpu)
return -ENOTSUPP;
 }
 
-int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
+   union kvmppc_one_reg *val)
 {
-   int r;
-   union kvmppc_one_reg val;
-   int size;
+   int r = 0;
long int i;
 
-   size = one_reg_size(reg-id);
-   if (size  sizeof(val))
-   return -EINVAL;
-
-   r = vcpu-kvm-arch.kvm_ops-get_one_reg(vcpu, reg-id, val);
+   r = vcpu-kvm-arch.kvm_ops-get_one_reg(vcpu, id, val);
if (r == -EINVAL) {
r = 0;
-   switch (reg-id) {
+   switch (id) {
case KVM_REG_PPC_DAR:
-   val = get_reg_val(reg-id, kvmppc_get_dar(vcpu));
+   *val = get_reg_val(id, kvmppc_get_dar(vcpu));
break;
case KVM_REG_PPC_DSISR:
-   val = get_reg_val(reg-id, kvmppc_get_dsisr(vcpu));
+   *val = get_reg_val(id, kvmppc_get_dsisr(vcpu));
break;
case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
-   i = reg-id - KVM_REG_PPC_FPR0;
-   val = get_reg_val(reg-id, VCPU_FPR(vcpu, i));
+   i = id - KVM_REG_PPC_FPR0;
+   *val = get_reg_val(id, VCPU_FPR(vcpu, i));
break;
case KVM_REG_PPC_FPSCR:
-   val = get_reg_val(reg-id, vcpu-arch.fp.fpscr);
+   *val = get_reg_val(id, vcpu-arch.fp.fpscr);
break;
 #ifdef CONFIG_ALTIVEC
case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -569,110 +564,94 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
r = -ENXIO;
break;
}
-   val.vval = vcpu-arch.vr.vr[reg-id - KVM_REG_PPC_VR0];
+   val-vval = vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0];
break;
case KVM_REG_PPC_VSCR:
if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
r = -ENXIO;
break;
}
-   val = get_reg_val(reg-id, vcpu-arch.vr.vscr.u[3]);
+   *val = get_reg_val(id, vcpu-arch.vr.vscr.u[3]);
break;
case KVM_REG_PPC_VRSAVE:
-   val = get_reg_val(reg-id, vcpu-arch.vrsave);
+   *val = get_reg_val(id, vcpu-arch.vrsave);
break;
 #endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
-   long int i = reg-id - KVM_REG_PPC_VSR0;
-   val.vsxval[0] = vcpu-arch.fp.fpr[i][0];
-   val.vsxval[1] = vcpu-arch.fp.fpr[i][1];
+   i = id - KVM_REG_PPC_VSR0;
+   val-vsxval[0] = vcpu-arch.fp.fpr[i][0];
+   val-vsxval[1] = vcpu-arch.fp.fpr[i][1];
} else {
r = -ENXIO;
}
break;
 #endif /* CONFIG_VSX */
-   case KVM_REG_PPC_DEBUG_INST: {
-   u32 opcode = INS_TW;
-   r = copy_to_user((u32 __user *)(long)reg-addr,
-opcode, sizeof(u32));
+   case KVM_REG_PPC_DEBUG_INST:
+   *val = get_reg_val(id, INS_TW);
break;
-   }
 #ifdef CONFIG_KVM_XICS
case KVM_REG_PPC_ICP_STATE:
if (!vcpu-arch.icp) {
r = -ENXIO;
break;
}
-   val = get_reg_val(reg-id, kvmppc_xics_get_icp(vcpu));
+ 

[PULL 21/24] KVM: PPC: Book3E: Enable e6500 core

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Now that AltiVec and hardware thread support is in place enable e6500 core.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500mc.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index bf8f99f..2fdc872 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -180,6 +180,16 @@ int kvmppc_core_check_processor_compat(void)
r = 0;
else if (strcmp(cur_cpu_spec-cpu_name, e5500) == 0)
r = 0;
+#ifdef CONFIG_ALTIVEC
+   /*
+* Since guests have the priviledge to enable AltiVec, we need AltiVec
+* support in the host to save/restore their context.
+* Don't use CPU_FTR_ALTIVEC to identify cores with AltiVec unit
+* because it's cleared in the absence of CONFIG_ALTIVEC!
+*/
+   else if (strcmp(cur_cpu_spec-cpu_name, e6500) == 0)
+   r = 0;
+#endif
else
r = -ENOTSUPP;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 16/24] KVM: PPC: Remove the tasklet used by the hrtimer

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Powerpc timer implementation is a copycat version of s390. Now that they removed
the tasklet with commit ea74c0ea1b24a6978a6ebc80ba4dbc7b7848b32d follow this
optimization.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Bogdan Purcareata bogdan.purcare...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h | 1 -
 arch/powerpc/include/asm/kvm_ppc.h  | 2 +-
 arch/powerpc/kvm/book3s.c   | 4 +---
 arch/powerpc/kvm/booke.c| 4 +---
 arch/powerpc/kvm/powerpc.c  | 8 +---
 5 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index bad3491..d243240 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -606,7 +606,6 @@ struct kvm_vcpu_arch {
u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
 
struct hrtimer dec_timer;
-   struct tasklet_struct tasklet;
u64 dec_jiffies;
u64 dec_expires;
unsigned long pending_exceptions;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 05e58b6..73063ef 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -89,7 +89,7 @@ extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu);
 extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
 extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
-extern void kvmppc_decrementer_func(unsigned long data);
+extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu);
 extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
 extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu);
 extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 1b5adda..f23b6a5 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -718,10 +718,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu 
*vcpu,
return -EINVAL;
 }
 
-void kvmppc_decrementer_func(unsigned long data)
+void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
 {
-   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
-
kvmppc_core_queue_dec(vcpu);
kvm_vcpu_kick(vcpu);
 }
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index b4e81e6..97ec5b7 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1822,10 +1822,8 @@ void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 
tsr_bits)
update_timer_ints(vcpu);
 }
 
-void kvmppc_decrementer_func(unsigned long data)
+void kvmppc_decrementer_func(struct kvm_vcpu *vcpu)
 {
-   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
-
if (vcpu-arch.tcr  TCR_ARE) {
vcpu-arch.dec = vcpu-arch.decar;
kvmppc_emulate_dec(vcpu);
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0c7d191..ecf0575 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -638,7 +638,6 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
 {
/* Make sure we're not using the vcpu anymore */
hrtimer_cancel(vcpu-arch.dec_timer);
-   tasklet_kill(vcpu-arch.tasklet);
 
kvmppc_remove_vcpu_debugfs(vcpu);
 
@@ -664,16 +663,12 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
return kvmppc_core_pending_dec(vcpu);
 }
 
-/*
- * low level hrtimer wake routine. Because this runs in hardirq context
- * we schedule a tasklet to do the real work.
- */
 enum hrtimer_restart kvmppc_decrementer_wakeup(struct hrtimer *timer)
 {
struct kvm_vcpu *vcpu;
 
vcpu = container_of(timer, struct kvm_vcpu, arch.dec_timer);
-   tasklet_schedule(vcpu-arch.tasklet);
+   kvmppc_decrementer_func(vcpu);
 
return HRTIMER_NORESTART;
 }
@@ -683,7 +678,6 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
int ret;
 
hrtimer_init(vcpu-arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
-   tasklet_init(vcpu-arch.tasklet, kvmppc_decrementer_func, (ulong)vcpu);
vcpu-arch.dec_timer.function = kvmppc_decrementer_wakeup;
vcpu-arch.dec_expires = ~(u64)0;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 11/24] KVM: PPC: Book3E: Increase FPU laziness

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Increase FPU laziness by loading the guest state into the unit before entering
the guest instead of doing it on each vcpu schedule. Without this improvement
an interrupt may claim floating point corrupting guest state.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c  | 43 ---
 arch/powerpc/kvm/booke.h  | 34 --
 arch/powerpc/kvm/e500mc.c |  2 --
 3 files changed, 36 insertions(+), 43 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 074b7fc..91e7217 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -124,6 +124,40 @@ static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
 }
 #endif
 
+/*
+ * Load up guest vcpu FP state if it's needed.
+ * It also set the MSR_FP in thread so that host know
+ * we're holding FPU, and then host can help to save
+ * guest vcpu FP state if other threads require to use FPU.
+ * This simulates an FP unavailable fault.
+ *
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (!(current-thread.regs-msr  MSR_FP)) {
+   enable_kernel_fp();
+   load_fp_state(vcpu-arch.fp);
+   current-thread.fp_save_area = vcpu-arch.fp;
+   current-thread.regs-msr |= MSR_FP;
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu FP state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_PPC_FPU
+   if (current-thread.regs-msr  MSR_FP)
+   giveup_fpu(current);
+   current-thread.fp_save_area = NULL;
+#endif
+}
+
 static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
 {
 #if defined(CONFIG_PPC_FPU)  !defined(CONFIG_KVM_BOOKE_HV)
@@ -658,12 +692,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
/*
 * Since we can't trap on MSR_FP in GS-mode, we consider the guest
-* as always using the FPU.  Kernel usage of FP (via
-* enable_kernel_fp()) in this thread must not occur while
-* vcpu-fpu_active is set.
+* as always using the FPU.
 */
-   vcpu-fpu_active = 1;
-
kvmppc_load_guest_fp(vcpu);
 #endif
 
@@ -687,8 +717,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
 #ifdef CONFIG_PPC_FPU
kvmppc_save_guest_fp(vcpu);
-
-   vcpu-fpu_active = 0;
 #endif
 
 out:
@@ -1194,6 +1222,7 @@ out:
else {
/* interrupts now hard-disabled */
kvmppc_fix_ee_before_entry();
+   kvmppc_load_guest_fp(vcpu);
}
}
 
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index f753543..e73d513 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -116,40 +116,6 @@ extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu 
*vcpu, int sprn,
 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
  ulong *spr_val);
 
-/*
- * Load up guest vcpu FP state if it's needed.
- * It also set the MSR_FP in thread so that host know
- * we're holding FPU, and then host can help to save
- * guest vcpu FP state if other threads require to use FPU.
- * This simulates an FP unavailable fault.
- *
- * It requires to be called with preemption disabled.
- */
-static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
-{
-#ifdef CONFIG_PPC_FPU
-   if (vcpu-fpu_active  !(current-thread.regs-msr  MSR_FP)) {
-   enable_kernel_fp();
-   load_fp_state(vcpu-arch.fp);
-   current-thread.fp_save_area = vcpu-arch.fp;
-   current-thread.regs-msr |= MSR_FP;
-   }
-#endif
-}
-
-/*
- * Save guest vcpu FP state into thread.
- * It requires to be called with preemption disabled.
- */
-static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
-{
-#ifdef CONFIG_PPC_FPU
-   if (vcpu-fpu_active  (current-thread.regs-msr  MSR_FP))
-   giveup_fpu(current);
-   current-thread.fp_save_area = NULL;
-#endif
-}
-
 static inline void kvmppc_clear_dbsr(void)
 {
mtspr(SPRN_DBSR, mfspr(SPRN_DBSR));
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 000cf82..4549349 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -145,8 +145,6 @@ static void kvmppc_core_vcpu_load_e500mc(struct kvm_vcpu 
*vcpu, int cpu)
kvmppc_e500_tlbil_all(vcpu_e500);
__get_cpu_var(last_vcpu_of_lpid)[vcpu-kvm-arch.lpid] = vcpu;
}
-
-   kvmppc_load_guest_fp(vcpu);
 }
 
 static void kvmppc_core_vcpu_put_e500mc(struct kvm_vcpu *vcpu)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line 

[PULL 19/24] KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR

2014-09-24 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

Since the guest can read the machine's PVR (Processor Version Register)
directly and see the real value, we should disallow userspace from
setting any value for the guest's PVR other than the real host value.
Therefore this makes kvm_arch_vcpu_set_sregs_hv() check the supplied
PVR value and return an error if it is different from the host value,
which has been put into vcpu-arch.pvr at vcpu creation time.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 4526bef..529d10a 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -856,7 +856,9 @@ static int kvm_arch_vcpu_ioctl_set_sregs_hv(struct kvm_vcpu 
*vcpu,
 {
int i, j;
 
-   kvmppc_set_pvr_hv(vcpu, sregs-pvr);
+   /* Only accept the same PVR as the host's, since we can't spoof it */
+   if (sregs-pvr != vcpu-arch.pvr)
+   return -EINVAL;
 
j = 0;
for (i = 0; i  vcpu-arch.slb_nr; i++) {
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 09/24] KVM: PPC: Book3S HV: Add register name when loading toc

2014-09-24 Thread Alexander Graf
From: Michael Neuling mi...@neuling.org

Add 'r' to register name r2 in kvmppc_hv_enter.

Also update comment at the top of kvmppc_hv_enter to indicate that R2/TOC is
non-volatile.

Signed-off-by: Michael Neuling mi...@neuling.org
Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S 
b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index f0c4db7..edb2ccd 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -355,6 +355,7 @@ kvmppc_hv_entry:
 * MSR = ~IR|DR
 * R13 = PACA
 * R1 = host R1
+* R2 = TOC
 * all other volatile GPRS = free
 */
mflrr0
@@ -503,7 +504,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 toc_tlbie_lock:
.tc native_tlbie_lock[TC],native_tlbie_lock
.previous
-   ld  r3,toc_tlbie_lock@toc(2)
+   ld  r3,toc_tlbie_lock@toc(r2)
 #ifdef __BIG_ENDIAN__
lwz r8,PACA_LOCK_TOKEN(r13)
 #else
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 12/24] KVM: PPC: Book3e: Add AltiVec support

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Add AltiVec support in KVM for Book3e. FPU support gracefully reuse host
infrastructure so follow the same approach for AltiVec.

Book3e specification defines shared interrupt numbers for SPE and AltiVec
units. Still SPE is present in e200/e500v2 cores while AltiVec is present in
e6500 core. So we can currently decide at compile-time which of the SPE or
AltiVec units to support exclusively by using CONFIG_SPE_POSSIBLE and
CONFIG_PPC_E500MC defines. As Alexander Graf suggested, keep SPE and AltiVec
exception handlers distinct to improve code readability.

Guests have the privilege to enable AltiVec, so we always need to support
AltiVec in KVM and implicitly in host to reflect interrupts and to save/restore
the unit context. KVM will be loaded on cores with AltiVec unit only if
CONFIG_ALTIVEC is defined. Use this define to guard KVM AltiVec logic.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c  | 74 ++-
 arch/powerpc/kvm/booke.h  |  6 +++
 arch/powerpc/kvm/bookehv_interrupts.S |  9 +
 arch/powerpc/kvm/e500_emulate.c   | 20 ++
 4 files changed, 101 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 91e7217..8ace612 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -168,6 +168,40 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
 #endif
 }
 
+/*
+ * Simulate AltiVec unavailable fault to load guest state
+ * from thread to AltiVec unit.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_load_guest_altivec(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_ALTIVEC
+   if (cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   if (!(current-thread.regs-msr  MSR_VEC)) {
+   enable_kernel_altivec();
+   load_vr_state(vcpu-arch.vr);
+   current-thread.vr_save_area = vcpu-arch.vr;
+   current-thread.regs-msr |= MSR_VEC;
+   }
+   }
+#endif
+}
+
+/*
+ * Save guest vcpu AltiVec state into thread.
+ * It requires to be called with preemption disabled.
+ */
+static inline void kvmppc_save_guest_altivec(struct kvm_vcpu *vcpu)
+{
+#ifdef CONFIG_ALTIVEC
+   if (cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   if (current-thread.regs-msr  MSR_VEC)
+   giveup_altivec(current);
+   current-thread.vr_save_area = NULL;
+   }
+#endif
+}
+
 static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
 {
/* Synchronize guest's desire to get debug interrupts into shadow MSR */
@@ -375,9 +409,15 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
case BOOKE_IRQPRIO_ITLB_MISS:
case BOOKE_IRQPRIO_SYSCALL:
case BOOKE_IRQPRIO_FP_UNAVAIL:
+#ifdef CONFIG_SPE_POSSIBLE
case BOOKE_IRQPRIO_SPE_UNAVAIL:
case BOOKE_IRQPRIO_SPE_FP_DATA:
case BOOKE_IRQPRIO_SPE_FP_ROUND:
+#endif
+#ifdef CONFIG_ALTIVEC
+   case BOOKE_IRQPRIO_ALTIVEC_UNAVAIL:
+   case BOOKE_IRQPRIO_ALTIVEC_ASSIST:
+#endif
case BOOKE_IRQPRIO_AP_UNAVAIL:
allowed = 1;
msr_mask = MSR_CE | MSR_ME | MSR_DE;
@@ -697,6 +737,17 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvmppc_load_guest_fp(vcpu);
 #endif
 
+#ifdef CONFIG_ALTIVEC
+   /* Save userspace AltiVec state in stack */
+   if (cpu_has_feature(CPU_FTR_ALTIVEC))
+   enable_kernel_altivec();
+   /*
+* Since we can't trap on MSR_VEC in GS-mode, we consider the guest
+* as always using the AltiVec.
+*/
+   kvmppc_load_guest_altivec(vcpu);
+#endif
+
/* Switch to guest debug context */
debug = vcpu-arch.dbg_reg;
switch_booke_debug_regs(debug);
@@ -719,6 +770,10 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvmppc_save_guest_fp(vcpu);
 #endif
 
+#ifdef CONFIG_ALTIVEC
+   kvmppc_save_guest_altivec(vcpu);
+#endif
+
 out:
vcpu-mode = OUTSIDE_GUEST_MODE;
return ret;
@@ -1025,7 +1080,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
r = RESUME_GUEST;
break;
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
case BOOKE_INTERRUPT_SPE_UNAVAIL:
/*
 * Guest wants SPE, but host kernel doesn't support it.  Send
@@ -1046,6 +1101,22 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
run-hw.hardware_exit_reason = exit_nr;
r = RESUME_HOST;
break;
+#endif /* CONFIG_SPE_POSSIBLE */
+
+/*
+ * On cores with Vector category, KVM is loaded only if CONFIG_ALTIVEC,
+ * see kvmppc_core_check_processor_compat().
+ 

[PULL 18/24] KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads

2014-09-24 Thread Alexander Graf
From: Paul Mackerras pau...@au1.ibm.com

Occasional failures have been seen with split-core mode and migration
where the message KVM: couldn't grab cpu appears.  This increases
the length of time that we wait from 1ms to 10ms, which seems to
work around the issue.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 27cced9..4526bef 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1489,7 +1489,7 @@ static void kvmppc_remove_runnable(struct kvmppc_vcore 
*vc,
 static int kvmppc_grab_hwthread(int cpu)
 {
struct paca_struct *tpaca;
-   long timeout = 1000;
+   long timeout = 1;
 
tpaca = paca[cpu];
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 07/24] powerpc/booke: Restrict SPE exception handlers to e200/e500 cores

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

SPE exception handlers are now defined for 32-bit e500mc cores even though
SPE unit is not present and CONFIG_SPE is undefined.

Restrict SPE exception handlers to e200/e500 cores adding CONFIG_SPE_POSSIBLE
and consequently guard __stup_ivors and __setup_cpu functions.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Acked-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/cpu_setup_fsl_booke.S | 12 +++-
 arch/powerpc/kernel/cputable.c|  5 +
 arch/powerpc/kernel/head_fsl_booke.S  | 18 +-
 arch/powerpc/platforms/Kconfig.cputype|  6 +-
 4 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kernel/cpu_setup_fsl_booke.S 
b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
index 4f1393d..dddba3e 100644
--- a/arch/powerpc/kernel/cpu_setup_fsl_booke.S
+++ b/arch/powerpc/kernel/cpu_setup_fsl_booke.S
@@ -91,6 +91,7 @@ _GLOBAL(setup_altivec_idle)
 
blr
 
+#ifdef CONFIG_PPC_E500MC
 _GLOBAL(__setup_cpu_e6500)
mflrr6
 #ifdef CONFIG_PPC64
@@ -107,14 +108,20 @@ _GLOBAL(__setup_cpu_e6500)
bl  __setup_cpu_e5500
mtlrr6
blr
+#endif /* CONFIG_PPC_E500MC */
 
 #ifdef CONFIG_PPC32
+#ifdef CONFIG_E200
 _GLOBAL(__setup_cpu_e200)
/* enable dedicated debug exception handling resources (Debug APU) */
mfspr   r3,SPRN_HID0
ori r3,r3,HID0_DAPUEN@l
mtspr   SPRN_HID0,r3
b   __setup_e200_ivors
+#endif /* CONFIG_E200 */
+
+#ifdef CONFIG_E500
+#ifndef CONFIG_PPC_E500MC
 _GLOBAL(__setup_cpu_e500v1)
 _GLOBAL(__setup_cpu_e500v2)
mflrr4
@@ -129,6 +136,7 @@ _GLOBAL(__setup_cpu_e500v2)
 #endif
mtlrr4
blr
+#else /* CONFIG_PPC_E500MC */
 _GLOBAL(__setup_cpu_e500mc)
 _GLOBAL(__setup_cpu_e5500)
mflrr5
@@ -159,7 +167,9 @@ _GLOBAL(__setup_cpu_e5500)
 2:
mtlrr5
blr
-#endif
+#endif /* CONFIG_PPC_E500MC */
+#endif /* CONFIG_E500 */
+#endif /* CONFIG_PPC32 */
 
 #ifdef CONFIG_PPC_BOOK3E_64
 _GLOBAL(__restore_cpu_e6500)
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 9b6dcaa..8084059 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -1961,6 +1961,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
 #endif /* CONFIG_PPC32 */
 #ifdef CONFIG_E500
 #ifdef CONFIG_PPC32
+#ifndef CONFIG_PPC_E500MC
{   /* e500 */
.pvr_mask   = 0x,
.pvr_value  = 0x8020,
@@ -2000,6 +2001,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500,
.platform   = ppc8548,
},
+#else
{   /* e500mc */
.pvr_mask   = 0x,
.pvr_value  = 0x8023,
@@ -2018,7 +2020,9 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500mc,
.platform   = ppce500mc,
},
+#endif /* CONFIG_PPC_E500MC */
 #endif /* CONFIG_PPC32 */
+#ifdef CONFIG_PPC_E500MC
{   /* e5500 */
.pvr_mask   = 0x,
.pvr_value  = 0x8024,
@@ -2062,6 +2066,7 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_e500mc,
.platform   = ppce6500,
},
+#endif /* CONFIG_PPC_E500MC */
 #ifdef CONFIG_PPC32
{   /* default match */
.pvr_mask   = 0x,
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index b497188..90f487f 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -613,6 +613,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
mfspr   r10, SPRN_SPRG_RSCRATCH0
b   InstructionStorage
 
+/* Define SPE handlers for e200 and e500v2 */
 #ifdef CONFIG_SPE
/* SPE Unavailable */
START_EXCEPTION(SPEUnavailable)
@@ -622,10 +623,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
b   fast_exception_return
 1: addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_EE_LITE(0x2010, KernelSPE)
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
EXCEPTION(0x2020, SPE_ALTIVEC_UNAVAIL, SPEUnavailable, \
  unknown_exception, EXC_XFER_EE)
-#endif /* CONFIG_SPE */
+#endif /* CONFIG_SPE_POSSIBLE */
 
/* SPE Floating Point Data */
 #ifdef CONFIG_SPE
@@ -635,12 +636,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
/* SPE Floating Point Round */
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  SPEFloatingPointRoundException, EXC_XFER_EE)
-#else
+#elif defined(CONFIG_SPE_POSSIBLE)
EXCEPTION(0x2040, SPE_FP_DATA_ALTIVEC_ASSIST, 

[PULL 20/24] KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

ePAPR represents hardware threads as cpu node properties in device tree.
So with existing QEMU, hardware threads are simply exposed as vcpus with
one hardware thread.

The e6500 core shares TLBs between hardware threads. Without tlb write
conditional instruction, the Linux kernel uses per core mechanisms to
protect against duplicate TLB entries.

The guest is unable to detect real siblings threads, so it can't use the
TLB protection mechanism. An alternative solution is to use the hypervisor
to allocate different lpids to guest's vcpus that runs simultaneous on real
siblings threads. On systems with two threads per core this patch halves
the size of the lpid pool that the allocator sees and use two lpids per VM.
Use even numbers to speedup vcpu lpid computation with consecutive lpids
per VM: vm1 will use lpids 2 and 3, vm2 lpids 4 and 5, and so on.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
[agraf: fix spelling]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_booke.h |  5 +++-
 arch/powerpc/kvm/e500.h  | 20 
 arch/powerpc/kvm/e500_mmu_host.c | 18 +++---
 arch/powerpc/kvm/e500mc.c| 46 ++--
 4 files changed, 65 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index f7aa5cc..630134d 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -23,7 +23,10 @@
 #include linux/types.h
 #include linux/kvm_host.h
 
-/* LPIDs we support with this build -- runtime limit may be lower */
+/*
+ * Number of available lpids. Only the low-order 6 bits of LPID rgister are
+ * implemented on e500mc+ cores.
+ */
 #define KVMPPC_NR_LPIDS64
 
 #define KVMPPC_INST_EHPRIV 0x7c00021c
diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index a326178..72920be 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -22,6 +22,7 @@
 #include linux/kvm_host.h
 #include asm/mmu-book3e.h
 #include asm/tlb.h
+#include asm/cputhreads.h
 
 enum vcpu_ftr {
VCPU_FTR_MMU_V2
@@ -289,6 +290,25 @@ void kvmppc_e500_tlbil_all(struct kvmppc_vcpu_e500 
*vcpu_e500);
 #define kvmppc_e500_get_tlb_stid(vcpu, gtlbe)   get_tlb_tid(gtlbe)
 #define get_tlbmiss_tid(vcpu)   get_cur_pid(vcpu)
 #define get_tlb_sts(gtlbe)  (gtlbe-mas1  MAS1_TS)
+
+/*
+ * These functions should be called with preemption disabled
+ * and the returned value is valid only in that context
+ */
+static inline int get_thread_specific_lpid(int vm_lpid)
+{
+   int vcpu_lpid = vm_lpid;
+
+   if (threads_per_core == 2)
+   vcpu_lpid |= smp_processor_id()  1;
+
+   return vcpu_lpid;
+}
+
+static inline int get_lpid(struct kvm_vcpu *vcpu)
+{
+   return get_thread_specific_lpid(vcpu-kvm-arch.lpid);
+}
 #else
 unsigned int kvmppc_e500_get_tlb_stid(struct kvm_vcpu *vcpu,
  struct kvm_book3e_206_tlb_entry *gtlbe);
diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
index 08f14bb..c8795a6 100644
--- a/arch/powerpc/kvm/e500_mmu_host.c
+++ b/arch/powerpc/kvm/e500_mmu_host.c
@@ -69,7 +69,8 @@ static inline u32 e500_shadow_mas3_attrib(u32 mas3, int 
usermode)
  * writing shadow tlb entry to host TLB
  */
 static inline void __write_host_tlbe(struct kvm_book3e_206_tlb_entry *stlbe,
-uint32_t mas0)
+uint32_t mas0,
+uint32_t lpid)
 {
unsigned long flags;
 
@@ -80,7 +81,7 @@ static inline void __write_host_tlbe(struct 
kvm_book3e_206_tlb_entry *stlbe,
mtspr(SPRN_MAS3, (u32)stlbe-mas7_3);
mtspr(SPRN_MAS7, (u32)(stlbe-mas7_3  32));
 #ifdef CONFIG_KVM_BOOKE_HV
-   mtspr(SPRN_MAS8, stlbe-mas8);
+   mtspr(SPRN_MAS8, MAS8_TGS | get_thread_specific_lpid(lpid));
 #endif
asm volatile(isync; tlbwe : : : memory);
 
@@ -129,11 +130,12 @@ static inline void write_host_tlbe(struct 
kvmppc_vcpu_e500 *vcpu_e500,
 
if (tlbsel == 0) {
mas0 = get_host_mas0(stlbe-mas2);
-   __write_host_tlbe(stlbe, mas0);
+   __write_host_tlbe(stlbe, mas0, vcpu_e500-vcpu.kvm-arch.lpid);
} else {
__write_host_tlbe(stlbe,
  MAS0_TLBSEL(1) |
- MAS0_ESEL(to_htlb1_esel(sesel)));
+ MAS0_ESEL(to_htlb1_esel(sesel)),
+ vcpu_e500-vcpu.kvm-arch.lpid);
}
 }
 
@@ -176,7 +178,7 @@ void kvmppc_map_magic(struct kvm_vcpu *vcpu)
   MAS3_SW | MAS3_SR | MAS3_UW | MAS3_UR;
magic.mas8 = 0;
 
-   __write_host_tlbe(magic, MAS0_TLBSEL(1) | MAS0_ESEL(tlbcam_index));
+   __write_host_tlbe(magic, MAS0_TLBSEL(1) | 

[PULL 10/24] KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This was missed in respective one_reg implementation patch.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 Documentation/virtual/kvm/api.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index f7735c7..7610eaa 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1901,6 +1901,8 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_ARCH_COMPAT   | 32
   PPC   | KVM_REG_PPC_DABRX | 32
   PPC   | KVM_REG_PPC_WORT  | 64
+  PPC  | KVM_REG_PPC_SPRG9 | 64
+  PPC  | KVM_REG_PPC_DBSR  | 32
   PPC   | KVM_REG_PPC_TM_GPR0   | 64
   ...
   PPC   | KVM_REG_PPC_TM_GPR31  | 64
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 24/24] KVM: PPC: Pass enum to kvmppc_get_last_inst

2014-09-24 Thread Alexander Graf
The kvmppc_get_last_inst function recently received a facelift that allowed
us to pass an enum of the type of instruction we want to read into it rather
than an unreadable boolean.

Unfortunately, not all callers ended up passing the enum. This wasn't really
an issue as true and false happen to match the two enum values we have,
but it's still hard to read.

Update all callers of kvmppc_get_last_inst() to follow the new calling
convention.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 4 ++--
 arch/powerpc/kvm/emulate.c   | 2 +-
 arch/powerpc/kvm/emulate_loadstore.c | 2 +-
 arch/powerpc/kvm/powerpc.c   | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index ed5b0dd..9b55dec 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -992,12 +992,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_DATA_STORAGE:
case BOOKE_INTERRUPT_DTLB_MISS:
case BOOKE_INTERRUPT_HV_PRIV:
-   emulated = kvmppc_get_last_inst(vcpu, false, last_inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, last_inst);
break;
case BOOKE_INTERRUPT_PROGRAM:
/* SW breakpoints arrive as illegal instructions on HV */
if (vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP)
-   emulated = kvmppc_get_last_inst(vcpu, false, 
last_inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, 
last_inst);
break;
default:
break;
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 005222b..5cc2e7a 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -219,7 +219,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
 
-   emulated = kvmppc_get_last_inst(vcpu, false, inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, inst);
if (emulated != EMULATE_DONE)
return emulated;
 
diff --git a/arch/powerpc/kvm/emulate_loadstore.c 
b/arch/powerpc/kvm/emulate_loadstore.c
index 0de4ffa..6d3c0ee 100644
--- a/arch/powerpc/kvm/emulate_loadstore.c
+++ b/arch/powerpc/kvm/emulate_loadstore.c
@@ -58,7 +58,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu)
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
 
-   emulated = kvmppc_get_last_inst(vcpu, false, inst);
+   emulated = kvmppc_get_last_inst(vcpu, INST_GENERIC, inst);
if (emulated != EMULATE_DONE)
return emulated;
 
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index ecf0575..c1f8f53 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -294,7 +294,7 @@ int kvmppc_emulate_mmio(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
{
u32 last_inst;
 
-   kvmppc_get_last_inst(vcpu, false, last_inst);
+   kvmppc_get_last_inst(vcpu, INST_GENERIC, last_inst);
/* XXX Deliver Program interrupt to guest. */
pr_emerg(%s: emulation failed (%08x)\n, __func__, last_inst);
r = RESUME_HOST;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 14/24] KVM: PPC: Move ONE_REG AltiVec support to powerpc

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Move ONE_REG AltiVec support to powerpc generic layer.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/uapi/asm/kvm.h |  5 +
 arch/powerpc/kvm/book3s.c   | 42 -
 arch/powerpc/kvm/powerpc.c  | 42 +
 3 files changed, 47 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
b/arch/powerpc/include/uapi/asm/kvm.h
index 3ca357a..ab4d473 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -476,6 +476,11 @@ struct kvm_get_htab_header {
 
 /* FP and vector status/control registers */
 #define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+/*
+ * VSCR register is documented as a 32-bit register in the ISA, but it can
+ * only be accesses via a vector register. Expose VSCR as a 32-bit register
+ * even though the kernel represents it as a 128-bit vector.
+ */
 #define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
 
 /* Virtual processor areas */
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 26868e2..1b5adda 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -558,25 +558,6 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_FPSCR:
*val = get_reg_val(id, vcpu-arch.fp.fpscr);
break;
-#ifdef CONFIG_ALTIVEC
-   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   val-vval = vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0];
-   break;
-   case KVM_REG_PPC_VSCR:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   *val = get_reg_val(id, vcpu-arch.vr.vscr.u[3]);
-   break;
-   case KVM_REG_PPC_VRSAVE:
-   *val = get_reg_val(id, vcpu-arch.vrsave);
-   break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
@@ -653,29 +634,6 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_FPSCR:
vcpu-arch.fp.fpscr = set_reg_val(id, *val);
break;
-#ifdef CONFIG_ALTIVEC
-   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vr.vr[id - KVM_REG_PPC_VR0] = val-vval;
-   break;
-   case KVM_REG_PPC_VSCR:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vr.vscr.u[3] = set_reg_val(id, *val);
-   break;
-   case KVM_REG_PPC_VRSAVE:
-   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
-   r = -ENXIO;
-   break;
-   }
-   vcpu-arch.vrsave = set_reg_val(id, *val);
-   break;
-#endif /* CONFIG_ALTIVEC */
 #ifdef CONFIG_VSX
case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:
if (cpu_has_feature(CPU_FTR_VSX)) {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 8a26126..0c7d191 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -921,6 +921,29 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
if (r == -EINVAL) {
r = 0;
switch (reg-id) {
+#ifdef CONFIG_ALTIVEC
+   case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
+   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   r = -ENXIO;
+   break;
+   }
+   vcpu-arch.vr.vr[reg-id - KVM_REG_PPC_VR0] = val.vval;
+   break;
+   case KVM_REG_PPC_VSCR:
+   if (!cpu_has_feature(CPU_FTR_ALTIVEC)) {
+   r = -ENXIO;
+   break;
+   }
+   vcpu-arch.vr.vscr.u[3] = set_reg_val(reg-id, val);
+   break;
+   case KVM_REG_PPC_VRSAVE:
+   

[PULL 04/24] KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Dbsr is not visible to userspace and we do not think any need to
expose this to userspace because:
  Userspace cannot inject debug interrupt to guest (as this
  does not know guest ability to handle debug interrupt), so
  userspace will always clear DBSR.
  Now if userspace has to always clear DBSR in KVM_EXIT_DEBUG
  handling then clearing dbsr in kernel looks simple as this
  avoid doing SET_SREGS/set_one_reg() to clear DBSR

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 322da7d..b4ab86c 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -735,6 +735,8 @@ static int kvmppc_handle_debug(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
struct debug_reg *dbg_reg = (vcpu-arch.shadow_dbg_reg);
u32 dbsr = vcpu-arch.dbsr;
 
+   /* Clear guest dbsr (vcpu-arch.dbsr) */
+   vcpu-arch.dbsr = 0;
run-debug.arch.status = 0;
run-debug.arch.address = vcpu-arch.pc;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 06/24] KVM: PPC: BOOKE: Add one reg interface for DBSR

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/uapi/asm/kvm.h | 1 +
 arch/powerpc/kvm/booke.c| 6 ++
 2 files changed, 7 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
b/arch/powerpc/include/uapi/asm/kvm.h
index e0e49db..3ca357a 100644
--- a/arch/powerpc/include/uapi/asm/kvm.h
+++ b/arch/powerpc/include/uapi/asm/kvm.h
@@ -557,6 +557,7 @@ struct kvm_get_htab_header {
 #define KVM_REG_PPC_DABRX  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8)
 #define KVM_REG_PPC_WORT   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb9)
 #define KVM_REG_PPC_SPRG9  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba)
+#define KVM_REG_PPC_DBSR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbb)
 
 /* Transactional Memory checkpointed state:
  * This is all GPRs, all VSX regs and a subset of SPRs
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e47de01..074b7fc 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1494,6 +1494,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DAC2:
val = get_reg_val(reg-id, vcpu-arch.dbg_reg.dac2);
break;
+   case KVM_REG_PPC_DBSR:
+   val = get_reg_val(reg-id, vcpu-arch.dbsr);
+   break;
case KVM_REG_PPC_EPR: {
u32 epr = kvmppc_get_epr(vcpu);
val = get_reg_val(reg-id, epr);
@@ -1564,6 +1567,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DAC2:
vcpu-arch.dbg_reg.dac2 = set_reg_val(reg-id, val);
break;
+   case KVM_REG_PPC_DBSR:
+   vcpu-arch.dbsr = set_reg_val(reg-id, val);
+   break;
case KVM_REG_PPC_EPR: {
u32 new_epr = set_reg_val(reg-id, val);
kvmppc_set_epr(vcpu, new_epr);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 01/24] KVM: PPC: BOOKE: allow debug interrupt at debug level

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

Debug interrupt can be either critical level or debug level.
There are separate set of save/restore registers used for different level.
Example: DSRR0/DSRR1 are used for debug level and CSRR0/CSRR1
are used for critical level debug interrupt.

Using CPU_FTR_DEBUG_LVL_EXC to decide which interrupt level to be used.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index b4c89fa..322da7d 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -377,7 +377,11 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
allowed = vcpu-arch.shared-msr  MSR_DE;
allowed = allowed  !crit;
msr_mask = MSR_ME;
-   int_class = INT_CLASS_CRIT;
+   if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
+   int_class = INT_CLASS_DBG;
+   else
+   int_class = INT_CLASS_CRIT;
+
break;
}
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 08/24] powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

Book3E specification defines shared interrupt numbers for SPE and AltiVec
units. Still SPE is present in e200/e500v2 cores while AltiVec is present in
e6500 core. So we can currently decide at compile-time which unit to support
exclusively. As Alexander Graf suggested, this will improve code readability
especially in KVM.

Use distinct defines to identify SPE/AltiVec interrupt numbers, reverting
c58ce397 and 6b310fc5 patches that added common defines.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Acked-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/exceptions-64e.S | 4 ++--
 arch/powerpc/kernel/head_fsl_booke.S | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64e.S 
b/arch/powerpc/kernel/exceptions-64e.S
index bb9cac6..3e68d1c 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -635,7 +635,7 @@ interrupt_end_book3e:
 
 /* Altivec Unavailable Interrupt */
START_EXCEPTION(altivec_unavailable);
-   NORMAL_EXCEPTION_PROLOG(0x200, BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL,
+   NORMAL_EXCEPTION_PROLOG(0x200, BOOKE_INTERRUPT_ALTIVEC_UNAVAIL,
PROLOG_ADDITION_NONE)
/* we can probably do a shorter exception entry for that one... */
EXCEPTION_COMMON(0x200)
@@ -658,7 +658,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 /* AltiVec Assist */
START_EXCEPTION(altivec_assist);
NORMAL_EXCEPTION_PROLOG(0x220,
-   BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST,
+   BOOKE_INTERRUPT_ALTIVEC_ASSIST,
PROLOG_ADDITION_NONE)
EXCEPTION_COMMON(0x220)
INTS_DISABLE
diff --git a/arch/powerpc/kernel/head_fsl_booke.S 
b/arch/powerpc/kernel/head_fsl_booke.S
index 90f487f..fffd1f9 100644
--- a/arch/powerpc/kernel/head_fsl_booke.S
+++ b/arch/powerpc/kernel/head_fsl_booke.S
@@ -617,27 +617,27 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
 #ifdef CONFIG_SPE
/* SPE Unavailable */
START_EXCEPTION(SPEUnavailable)
-   NORMAL_EXCEPTION_PROLOG(SPE_ALTIVEC_UNAVAIL)
+   NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL)
beq 1f
bl  load_up_spe
b   fast_exception_return
 1: addir3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_EE_LITE(0x2010, KernelSPE)
 #elif defined(CONFIG_SPE_POSSIBLE)
-   EXCEPTION(0x2020, SPE_ALTIVEC_UNAVAIL, SPEUnavailable, \
+   EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \
  unknown_exception, EXC_XFER_EE)
 #endif /* CONFIG_SPE_POSSIBLE */
 
/* SPE Floating Point Data */
 #ifdef CONFIG_SPE
-   EXCEPTION(0x2030, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
+   EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData,
  SPEFloatingPointException, EXC_XFER_EE)
 
/* SPE Floating Point Round */
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  SPEFloatingPointRoundException, EXC_XFER_EE)
 #elif defined(CONFIG_SPE_POSSIBLE)
-   EXCEPTION(0x2040, SPE_FP_DATA_ALTIVEC_ASSIST, SPEFloatingPointData,
+   EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData,
  unknown_exception, EXC_XFER_EE)
EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \
  unknown_exception, EXC_XFER_EE)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 03/24] KVM: PPC: BOOKE: Allow guest to change MSR_DE

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This patch changes the default behavior of MSRP_DEP, that is
guest is not allowed to change the MSR_DE, to guest can change
MSR_DE. When userspace is debugging guest then it override the
default behavior and set MSRP_DEP. This stops guest to change
MSR_DE when userspace is debugging guest.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500mc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 164bad2..000cf82 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -194,7 +194,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 #ifdef CONFIG_64BIT
vcpu-arch.shadow_epcr |= SPRN_EPCR_ICM;
 #endif
-   vcpu-arch.shadow_msrp = MSRP_UCLEP | MSRP_DEP | MSRP_PMMP;
+   vcpu-arch.shadow_msrp = MSRP_UCLEP | MSRP_PMMP;
vcpu-arch.eplc = EPC_EGS | (vcpu-kvm-arch.lpid  EPC_ELPID_SHIFT);
vcpu-arch.epsc = vcpu-arch.eplc;
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 00/24] ppc patch queue 2014-09-24

2014-09-24 Thread Alexander Graf
Hi Paolo,

This is my current patch queue for ppc.  Please pull.

Alex


The following changes since commit f51770ed465e6eb41da7fa16fd92eb67069600cf:

  kvm: Make init_rmode_identity_map() return 0 on success. (2014-09-17 13:10:12 
+0200)

are available in the git repository at:

  git://github.com/agraf/linux-2.6.git tags/signed-kvm-ppc-next

for you to fetch changes up to 8d0eff6385640a9e6eed0b0c09113794b2bb74e9:

  KVM: PPC: Pass enum to kvmppc_get_last_inst (2014-09-22 10:11:36 +0200)


Patch queue for ppc - 2014-09-24

New awesome things in this release:

  - E500: e6500 core support
  - E500: guest and remote debug support
  - Book3S: remote sw breakpoint support
  - Book3S: HV: Minor bugfixes


Alexander Graf (1):
  KVM: PPC: Pass enum to kvmppc_get_last_inst

Bharat Bhushan (8):
  KVM: PPC: BOOKE: allow debug interrupt at debug level
  KVM: PPC: BOOKE : Emulate rfdi instruction
  KVM: PPC: BOOKE: Allow guest to change MSR_DE
  KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG
  KVM: PPC: BOOKE: Guest and hardware visible debug registers are same
  KVM: PPC: BOOKE: Add one reg interface for DBSR
  KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR
  KVM: PPC: BOOKE: Emulate debug registers and exception

Madhavan Srinivasan (2):
  powerpc/kvm: support to handle sw breakpoint
  powerpc/kvm: common sw breakpoint instr across ppc

Michael Neuling (1):
  KVM: PPC: Book3S HV: Add register name when loading toc

Mihai Caraman (10):
  powerpc/booke: Restrict SPE exception handlers to e200/e500 cores
  powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers
  KVM: PPC: Book3E: Increase FPU laziness
  KVM: PPC: Book3e: Add AltiVec support
  KVM: PPC: Make ONE_REG powerpc generic
  KVM: PPC: Move ONE_REG AltiVec support to powerpc
  KVM: PPC: Remove the tasklet used by the hrtimer
  KVM: PPC: Remove shared defines for SPE and AltiVec interrupts
  KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core
  KVM: PPC: Book3E: Enable e6500 core

Paul Mackerras (2):
  KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads
  KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR

 Documentation/virtual/kvm/api.txt |   2 +
 arch/powerpc/include/asm/kvm_asm.h|  20 +--
 arch/powerpc/include/asm/kvm_booke.h  |   7 +-
 arch/powerpc/include/asm/kvm_host.h   |   4 +-
 arch/powerpc/include/asm/kvm_ppc.h|  11 +-
 arch/powerpc/include/asm/reg_booke.h  |   2 +
 arch/powerpc/include/uapi/asm/kvm.h   |   6 +
 arch/powerpc/kernel/cpu_setup_fsl_booke.S |  12 +-
 arch/powerpc/kernel/cputable.c|   5 +
 arch/powerpc/kernel/exceptions-64e.S  |   4 +-
 arch/powerpc/kernel/head_fsl_booke.S  |  26 ++-
 arch/powerpc/kvm/book3s.c | 158 +---
 arch/powerpc/kvm/book3s_hv.c  |  47 -
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   |   3 +-
 arch/powerpc/kvm/book3s_pr.c  |   3 +
 arch/powerpc/kvm/booke.c  | 287 ++
 arch/powerpc/kvm/booke.h  |  40 +
 arch/powerpc/kvm/booke_emulate.c  | 163 +
 arch/powerpc/kvm/bookehv_interrupts.S |  13 +-
 arch/powerpc/kvm/e500.h   |  20 +++
 arch/powerpc/kvm/e500_emulate.c   |  20 +++
 arch/powerpc/kvm/e500_mmu_host.c  |  18 +-
 arch/powerpc/kvm/e500mc.c |  60 +--
 arch/powerpc/kvm/emulate.c|  17 +-
 arch/powerpc/kvm/emulate_loadstore.c  |   2 +-
 arch/powerpc/kvm/powerpc.c| 107 ++-
 arch/powerpc/platforms/Kconfig.cputype|   6 +-
 27 files changed, 763 insertions(+), 300 deletions(-)
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 17/24] KVM: PPC: Remove shared defines for SPE and AltiVec interrupts

2014-09-24 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

We currently decide at compile-time which of the SPE or AltiVec units to
support exclusively. Guard kernel defines with CONFIG_SPE_POSSIBLE and
CONFIG_PPC_E500MC and remove shared defines.

Signed-off-by: Mihai Caraman mihai.cara...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_asm.h | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 465dfcb..5bca220 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -53,17 +53,17 @@
 #define BOOKE_INTERRUPT_DEBUG 15
 
 /* E500 */
-#define BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL 32
-#define BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST 33
-/*
- * TODO: Unify 32-bit and 64-bit kernel exception handlers to use same defines
- */
-#define BOOKE_INTERRUPT_SPE_UNAVAIL BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL
-#define BOOKE_INTERRUPT_SPE_FP_DATA BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST
-#define BOOKE_INTERRUPT_ALTIVEC_UNAVAIL BOOKE_INTERRUPT_SPE_ALTIVEC_UNAVAIL
-#define BOOKE_INTERRUPT_ALTIVEC_ASSIST \
-   BOOKE_INTERRUPT_SPE_FP_DATA_ALTIVEC_ASSIST
+#ifdef CONFIG_SPE_POSSIBLE
+#define BOOKE_INTERRUPT_SPE_UNAVAIL 32
+#define BOOKE_INTERRUPT_SPE_FP_DATA 33
 #define BOOKE_INTERRUPT_SPE_FP_ROUND 34
+#endif
+
+#ifdef CONFIG_PPC_E500MC
+#define BOOKE_INTERRUPT_ALTIVEC_UNAVAIL 32
+#define BOOKE_INTERRUPT_ALTIVEC_ASSIST 33
+#endif
+
 #define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35
 #define BOOKE_INTERRUPT_DOORBELL 36
 #define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 23/24] powerpc/kvm: common sw breakpoint instr across ppc

2014-09-24 Thread Alexander Graf
From: Madhavan Srinivasan ma...@linux.vnet.ibm.com

This patch extends the use of illegal instruction as software
breakpoint instruction across the ppc platform. Patch extends
booke program interrupt code to support software breakpoint.

Signed-off-by: Madhavan Srinivasan ma...@linux.vnet.ibm.com
[agraf: Fix bookehv]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_booke.h  |  2 --
 arch/powerpc/kvm/booke.c  | 19 ++-
 arch/powerpc/kvm/bookehv_interrupts.S |  4 ++--
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_booke.h 
b/arch/powerpc/include/asm/kvm_booke.h
index 630134d..3286f0d 100644
--- a/arch/powerpc/include/asm/kvm_booke.h
+++ b/arch/powerpc/include/asm/kvm_booke.h
@@ -33,8 +33,6 @@
 #define EHPRIV_OC_SHIFT11
 /* ehpriv 1 : ehpriv with OC = 1 is used for debug emulation */
 #define EHPRIV_OC_DEBUG1
-#define KVMPPC_INST_EHPRIV_DEBUG   (KVMPPC_INST_EHPRIV | \
-(EHPRIV_OC_DEBUG  EHPRIV_OC_SHIFT))
 
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 97ec5b7..ed5b0dd 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -994,6 +994,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
case BOOKE_INTERRUPT_HV_PRIV:
emulated = kvmppc_get_last_inst(vcpu, false, last_inst);
break;
+   case BOOKE_INTERRUPT_PROGRAM:
+   /* SW breakpoints arrive as illegal instructions on HV */
+   if (vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP)
+   emulated = kvmppc_get_last_inst(vcpu, false, 
last_inst);
+   break;
default:
break;
}
@@ -1071,6 +1076,18 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case BOOKE_INTERRUPT_PROGRAM:
+   if ((vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP) 
+   (last_inst == KVMPPC_INST_SW_BREAKPOINT)) {
+   /*
+* We are here because of an SW breakpoint instr,
+* so lets return to host to handle.
+*/
+   r = kvmppc_handle_debug(run, vcpu);
+   run-exit_reason = KVM_EXIT_DEBUG;
+   kvmppc_account_exit(vcpu, DEBUG_EXITS);
+   break;
+   }
+
if (vcpu-arch.shared-msr  (MSR_PR | MSR_GS)) {
/*
 * Program traps generated by user-level software must
@@ -1647,7 +1664,7 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
*val = get_reg_val(id, vcpu-arch.tsr);
break;
case KVM_REG_PPC_DEBUG_INST:
-   *val = get_reg_val(id, KVMPPC_INST_EHPRIV_DEBUG);
+   *val = get_reg_val(id, KVMPPC_INST_SW_BREAKPOINT);
break;
case KVM_REG_PPC_VRSAVE:
*val = get_reg_val(id, vcpu-arch.vrsave);
diff --git a/arch/powerpc/kvm/bookehv_interrupts.S 
b/arch/powerpc/kvm/bookehv_interrupts.S
index c8e4da5..81bd8a0 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -238,7 +238,7 @@ kvm_handler BOOKE_INTERRUPT_EXTERNAL, EX_PARAMS(GEN), \
 kvm_handler BOOKE_INTERRUPT_ALIGNMENT, EX_PARAMS(GEN), \
SPRN_SRR0, SPRN_SRR1,(NEED_DEAR | NEED_ESR)
 kvm_handler BOOKE_INTERRUPT_PROGRAM, EX_PARAMS(GEN), \
-   SPRN_SRR0, SPRN_SRR1,NEED_ESR
+   SPRN_SRR0, SPRN_SRR1, (NEED_ESR | NEED_EMU)
 kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, EX_PARAMS(GEN), \
SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, EX_PARAMS(GEN), \
@@ -348,7 +348,7 @@ kvm_handler BOOKE_INTERRUPT_INST_STORAGE, SPRN_SRR0, 
SPRN_SRR1, NEED_ESR
 kvm_handler BOOKE_INTERRUPT_EXTERNAL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_ALIGNMENT, \
SPRN_SRR0, SPRN_SRR1, (NEED_DEAR | NEED_ESR)
-kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, NEED_ESR
+kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, (NEED_ESR | 
NEED_EMU)
 kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0
 kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 15/24] KVM: PPC: BOOKE: Emulate debug registers and exception

2014-09-24 Thread Alexander Graf
From: Bharat Bhushan bharat.bhus...@freescale.com

This patch emulates debug registers and debug exception
to support guest using debug resource. This enables running
gdb/kgdb etc in guest.

On BOOKE architecture we cannot share debug resources between QEMU and
guest because:
When QEMU is using debug resources then debug exception must
be always enabled. To achieve this we set MSR_DE and also set
MSRP_DEP so guest cannot change MSR_DE.

When emulating debug resource for guest we want guest
to control MSR_DE (enable/disable debug interrupt on need).

So above mentioned two configuration cannot be supported
at the same time. So the result is that we cannot share
debug resources between QEMU and Guest on BOOKE architecture.

In the current design QEMU gets priority over guest, this means that if
QEMU is using debug resources then guest cannot use them and if guest is
using debug resource then QEMU can overwrite them.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h   |   3 +
 arch/powerpc/include/asm/reg_booke.h |   2 +
 arch/powerpc/kvm/booke.c |  42 +-
 arch/powerpc/kvm/booke_emulate.c | 148 +++
 4 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index fb86a22..05e58b6 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -206,6 +206,9 @@ extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, 
u32 *server,
 extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq);
 extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq);
 
+void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu);
+void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu);
+
 union kvmppc_one_reg {
u32 wval;
u64 dval;
diff --git a/arch/powerpc/include/asm/reg_booke.h 
b/arch/powerpc/include/asm/reg_booke.h
index 1d65330..16547ef 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -319,6 +319,8 @@
  * DBSR bits which have conflicting definitions on true Book E versus IBM 40x.
  */
 #ifdef CONFIG_BOOKE
+#define DBSR_IDE   0x8000  /* Imprecise Debug Event */
+#define DBSR_MRR   0x3000  /* Most Recent Reset */
 #define DBSR_IC0x0800  /* Instruction Completion */
 #define DBSR_BT0x0400  /* Branch Taken */
 #define DBSR_IRPT  0x0200  /* Exception Debug Event */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 831c1b4..b4e81e6 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -335,6 +335,16 @@ static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu 
*vcpu)
clear_bit(BOOKE_IRQPRIO_WATCHDOG, vcpu-arch.pending_exceptions);
 }
 
+void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu)
+{
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DEBUG);
+}
+
+void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu)
+{
+   clear_bit(BOOKE_IRQPRIO_DEBUG, vcpu-arch.pending_exceptions);
+}
+
 static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
 {
kvmppc_set_srr0(vcpu, srr0);
@@ -818,7 +828,32 @@ static int kvmppc_handle_debug(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
struct debug_reg *dbg_reg = (vcpu-arch.dbg_reg);
u32 dbsr = vcpu-arch.dbsr;
 
-   /* Clear guest dbsr (vcpu-arch.dbsr) */
+   if (vcpu-guest_debug == 0) {
+   /*
+* Debug resources belong to Guest.
+* Imprecise debug event is not injected
+*/
+   if (dbsr  DBSR_IDE) {
+   dbsr = ~DBSR_IDE;
+   if (!dbsr)
+   return RESUME_GUEST;
+   }
+
+   if (dbsr  (vcpu-arch.shared-msr  MSR_DE) 
+   (vcpu-arch.dbg_reg.dbcr0  DBCR0_IDM))
+   kvmppc_core_queue_debug(vcpu);
+
+   /* Inject a program interrupt if trap debug is not allowed */
+   if ((dbsr  DBSR_TIE)  !(vcpu-arch.shared-msr  MSR_DE))
+   kvmppc_core_queue_program(vcpu, ESR_PTR);
+
+   return RESUME_GUEST;
+   }
+
+   /*
+* Debug resource owned by userspace.
+* Clear guest dbsr (vcpu-arch.dbsr)
+*/
vcpu-arch.dbsr = 0;
run-debug.arch.status = 0;
run-debug.arch.address = vcpu-arch.pc;
@@ -1350,6 +1385,11 @@ int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
setup_timer(vcpu-arch.wdt_timer, kvmppc_watchdog_func,
(unsigned long)vcpu);
 
+   /*
+* Clear DBSR.MRR to avoid guest debug interrupt as
+* this is of host interest
+*/
+   mtspr(SPRN_DBSR, DBSR_MRR);
return 0;
 }
 
diff --git a/arch/powerpc/kvm/booke_emulate.c 

Re: [PULL 00/24] ppc patch queue 2014-09-24

2014-09-24 Thread Paolo Bonzini
Il 24/09/2014 22:43, Alexander Graf ha scritto:
 Hi Paolo,
 
 This is my current patch queue for ppc.  Please pull.
 
 Alex
 
 
 The following changes since commit f51770ed465e6eb41da7fa16fd92eb67069600cf:
 
   kvm: Make init_rmode_identity_map() return 0 on success. (2014-09-17 
 13:10:12 +0200)
 
 are available in the git repository at:
 
   git://github.com/agraf/linux-2.6.git tags/signed-kvm-ppc-next
 
 for you to fetch changes up to 8d0eff6385640a9e6eed0b0c09113794b2bb74e9:
 
   KVM: PPC: Pass enum to kvmppc_get_last_inst (2014-09-22 10:11:36 +0200)
 
 
 Patch queue for ppc - 2014-09-24
 
 New awesome things in this release:
 
   - E500: e6500 core support
   - E500: guest and remote debug support
   - Book3S: remote sw breakpoint support
   - Book3S: HV: Minor bugfixes
 
 
 Alexander Graf (1):
   KVM: PPC: Pass enum to kvmppc_get_last_inst
 
 Bharat Bhushan (8):
   KVM: PPC: BOOKE: allow debug interrupt at debug level
   KVM: PPC: BOOKE : Emulate rfdi instruction
   KVM: PPC: BOOKE: Allow guest to change MSR_DE
   KVM: PPC: BOOKE: Clear guest dbsr in userspace exit KVM_EXIT_DEBUG
   KVM: PPC: BOOKE: Guest and hardware visible debug registers are same
   KVM: PPC: BOOKE: Add one reg interface for DBSR
   KVM: PPC: BOOKE: Add one_reg documentation of SPRG9 and DBSR
   KVM: PPC: BOOKE: Emulate debug registers and exception
 
 Madhavan Srinivasan (2):
   powerpc/kvm: support to handle sw breakpoint
   powerpc/kvm: common sw breakpoint instr across ppc
 
 Michael Neuling (1):
   KVM: PPC: Book3S HV: Add register name when loading toc
 
 Mihai Caraman (10):
   powerpc/booke: Restrict SPE exception handlers to e200/e500 cores
   powerpc/booke: Revert SPE/AltiVec common defines for interrupt numbers
   KVM: PPC: Book3E: Increase FPU laziness
   KVM: PPC: Book3e: Add AltiVec support
   KVM: PPC: Make ONE_REG powerpc generic
   KVM: PPC: Move ONE_REG AltiVec support to powerpc
   KVM: PPC: Remove the tasklet used by the hrtimer
   KVM: PPC: Remove shared defines for SPE and AltiVec interrupts
   KVM: PPC: e500mc: Add support for single threaded vcpus on e6500 core
   KVM: PPC: Book3E: Enable e6500 core
 
 Paul Mackerras (2):
   KVM: PPC: Book3S HV: Increase timeout for grabbing secondary threads
   KVM: PPC: Book3S HV: Only accept host PVR value for guest PVR
 
  Documentation/virtual/kvm/api.txt |   2 +
  arch/powerpc/include/asm/kvm_asm.h|  20 +--
  arch/powerpc/include/asm/kvm_booke.h  |   7 +-
  arch/powerpc/include/asm/kvm_host.h   |   4 +-
  arch/powerpc/include/asm/kvm_ppc.h|  11 +-
  arch/powerpc/include/asm/reg_booke.h  |   2 +
  arch/powerpc/include/uapi/asm/kvm.h   |   6 +
  arch/powerpc/kernel/cpu_setup_fsl_booke.S |  12 +-
  arch/powerpc/kernel/cputable.c|   5 +
  arch/powerpc/kernel/exceptions-64e.S  |   4 +-
  arch/powerpc/kernel/head_fsl_booke.S  |  26 ++-
  arch/powerpc/kvm/book3s.c | 158 +---
  arch/powerpc/kvm/book3s_hv.c  |  47 -
  arch/powerpc/kvm/book3s_hv_rmhandlers.S   |   3 +-
  arch/powerpc/kvm/book3s_pr.c  |   3 +
  arch/powerpc/kvm/booke.c  | 287 
 ++
  arch/powerpc/kvm/booke.h  |  40 +
  arch/powerpc/kvm/booke_emulate.c  | 163 +
  arch/powerpc/kvm/bookehv_interrupts.S |  13 +-
  arch/powerpc/kvm/e500.h   |  20 +++
  arch/powerpc/kvm/e500_emulate.c   |  20 +++
  arch/powerpc/kvm/e500_mmu_host.c  |  18 +-
  arch/powerpc/kvm/e500mc.c |  60 +--
  arch/powerpc/kvm/emulate.c|  17 +-
  arch/powerpc/kvm/emulate_loadstore.c  |   2 +-
  arch/powerpc/kvm/powerpc.c| 107 ++-
  arch/powerpc/platforms/Kconfig.cputype|   6 +-
  27 files changed, 763 insertions(+), 300 deletions(-)
 

Pulled, thanks!

Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html