[PATCH v5 1/3] KVM: PPC: Book3S: Get/set guest SPRs using the GET/SET_ONE_REG interface

2012-09-25 Thread Paul Mackerras
This enables userspace to get and set various SPRs (special-purpose
registers) using the KVM_[GS]ET_ONE_REG ioctls.  With this, userspace
can get and set all the SPRs that are part of the guest state, either
through the KVM_[GS]ET_REGS ioctls, the KVM_[GS]ET_SREGS ioctls, or
the KVM_[GS]ET_ONE_REG ioctls.

The SPRs that are added here are:

- DABR:  Data address breakpoint register
- DSCR:  Data stream control register
- PURR:  Processor utilization of resources register
- SPURR: Scaled PURR
- DAR:   Data address register
- DSISR: Data storage interrupt status register
- AMR:   Authority mask register
- UAMOR: User authority mask override register
- MMCR0, MMCR1, MMCRA: Performance monitor unit control registers
- PMC1..PMC8: Performance monitor unit counter registers

In order to reduce code duplication between PR and HV KVM code, this
moves the kvm_vcpu_ioctl_[gs]et_one_reg functions into book3s.c and
centralizes the copying between user and kernel space there.  The
registers that are handled differently between PR and HV, and those
that exist only in one flavor, are handled in kvmppc_[gs]et_one_reg()
functions that are specific to each flavor.

Signed-off-by: Paul Mackerras 
---
v5: Use get/set_reg_val rather than get/set_one_reg

 Documentation/virtual/kvm/api.txt  |   19 +
 arch/powerpc/include/asm/kvm.h |   21 ++
 arch/powerpc/include/asm/kvm_ppc.h |   32 +++
 arch/powerpc/kvm/book3s.c  |   68 
 arch/powerpc/kvm/book3s_hv.c   |   76 ++--
 arch/powerpc/kvm/book3s_pr.c   |   23 ++-
 6 files changed, 215 insertions(+), 24 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index a12f4e4..407556f 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1740,6 +1740,25 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_IAC4  | 64
   PPC   | KVM_REG_PPC_DAC1  | 64
   PPC   | KVM_REG_PPC_DAC2  | 64
+  PPC   | KVM_REG_PPC_DABR  | 64
+  PPC   | KVM_REG_PPC_DSCR  | 64
+  PPC   | KVM_REG_PPC_PURR  | 64
+  PPC   | KVM_REG_PPC_SPURR | 64
+  PPC   | KVM_REG_PPC_DAR   | 64
+  PPC   | KVM_REG_PPC_DSISR| 32
+  PPC   | KVM_REG_PPC_AMR   | 64
+  PPC   | KVM_REG_PPC_UAMOR | 64
+  PPC   | KVM_REG_PPC_MMCR0 | 64
+  PPC   | KVM_REG_PPC_MMCR1 | 64
+  PPC   | KVM_REG_PPC_MMCRA | 64
+  PPC   | KVM_REG_PPC_PMC1  | 32
+  PPC   | KVM_REG_PPC_PMC2  | 32
+  PPC   | KVM_REG_PPC_PMC3  | 32
+  PPC   | KVM_REG_PPC_PMC4  | 32
+  PPC   | KVM_REG_PPC_PMC5  | 32
+  PPC   | KVM_REG_PPC_PMC6  | 32
+  PPC   | KVM_REG_PPC_PMC7  | 32
+  PPC   | KVM_REG_PPC_PMC8  | 32
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 3c14202..9557576 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -338,5 +338,26 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_IAC4   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
 #define KVM_REG_PPC_DAC1   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
 #define KVM_REG_PPC_DAC2   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
+#define KVM_REG_PPC_DABR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
+#define KVM_REG_PPC_DSCR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
+#define KVM_REG_PPC_PURR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
+#define KVM_REG_PPC_SPURR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
+#define KVM_REG_PPC_DAR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
+#define KVM_REG_PPC_DSISR  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
+#define KVM_REG_PPC_AMR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
+#define KVM_REG_PPC_UAMOR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
+
+#define KVM_REG_PPC_MMCR0  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
+#define KVM_REG_PPC_MMCR1  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
+#define KVM_REG_PPC_MMCRA  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+
+#define KVM_REG_PPC_PMC1   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
+#define KVM_REG_PPC_PMC2   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
+#define KVM_REG_PPC_PMC3   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
+#define KVM_REG_PPC_PMC4   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
+#define KVM_REG_PPC_PMC5   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
+#define KVM_REG_PPC_PMC6   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
+#define KVM_REG_PPC_PMC7   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
+#define KVM_REG_PPC_PMC8   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 3fb980d..709f0dd 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef CONFIG_PPC_BOOK3S
 #include 
 #else
@@ -196,6 +197,35 @@ static inline

[PATCH v5 3/3] KVM: PPC: Book3S HV: Provide a way for userspace to get/set per-vCPU areas

2012-09-25 Thread Paul Mackerras
The PAPR paravirtualization interface lets guests register three
different types of per-vCPU buffer areas in its memory for communication
with the hypervisor.  These are called virtual processor areas (VPAs).
Currently the hypercalls to register and unregister VPAs are handled
by KVM in the kernel, and userspace has no way to know about or save
and restore these registrations across a migration.

This adds "register" codes for these three areas that userspace can
use with the KVM_GET/SET_ONE_REG ioctls to see what addresses have
been registered, and to register or unregister them.  This will be
needed for guest hibernation and migration, and is also needed so
that userspace can unregister them on reset (otherwise we corrupt
guest memory after reboot by writing to the VPAs registered by the
previous kernel).

The "register" for the VPA is a 64-bit value containing the address,
since the length of the VPA is fixed.  The "registers" for the SLB
shadow buffer and dispatch trace log (DTL) are 128 bits long,
consisting of the guest physical address in the high (first) 64 bits
and the length in the low 64 bits.

This also fixes a bug where we were calling init_vpa unconditionally,
leading to an oops when unregistering the VPA.

Signed-off-by: Paul Mackerras 
---
 Documentation/virtual/kvm/api.txt  |3 ++
 arch/powerpc/include/asm/kvm.h |6 
 arch/powerpc/include/asm/kvm_ppc.h |4 +++
 arch/powerpc/kvm/book3s_hv.c   |   64 +++-
 4 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index a02f0de..57cb6cc 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1770,6 +1770,9 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_VSR31 | 128
   PPC   | KVM_REG_PPC_FPSCR | 64
   PPC   | KVM_REG_PPC_VSCR  | 32
+  PPC   | KVM_REG_PPC_VPA_ADDR  | 64
+  PPC   | KVM_REG_PPC_VPA_SLB   | 128
+  PPC   | KVM_REG_PPC_VPA_DTL   | 128
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 1466975..b89ae4d 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -380,4 +380,10 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
 #define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
 
+/* Virtual processor areas */
+/* For SLB & DTL, address in high (first) half, length in low half */
+#define KVM_REG_PPC_VPA_ADDR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x82)
+#define KVM_REG_PPC_VPA_SLB(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x83)
+#define KVM_REG_PPC_VPA_DTL(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x84)
+
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 51604a1..609cca3 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -202,6 +202,10 @@ union kvmppc_one_reg {
u64 dval;
vector128 vval;
u64 vsxval[2];
+   struct {
+   u64 addr;
+   u64 length;
+   }   vpaval;
 };
 
 #define one_reg_size(id)   \
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 94ec0e3..9a15da7 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -143,6 +143,22 @@ static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca 
*vpa)
vpa->yield_count = 1;
 }
 
+static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v,
+  unsigned long addr, unsigned long len)
+{
+   /* check address is cacheline aligned */
+   if (addr & (L1_CACHE_BYTES - 1))
+   return -EINVAL;
+   spin_lock(&vcpu->arch.vpa_update_lock);
+   if (v->next_gpa != addr || v->len != len) {
+   v->next_gpa = addr;
+   v->len = addr ? len : 0;
+   v->update_pending = 1;
+   }
+   spin_unlock(&vcpu->arch.vpa_update_lock);
+   return 0;
+}
+
 /* Length for a per-processor buffer is passed in at offset 4 in the buffer */
 struct reg_vpa {
u32 dummy;
@@ -321,7 +337,8 @@ static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)
spin_lock(&vcpu->arch.vpa_update_lock);
if (vcpu->arch.vpa.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.vpa);
-   init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
+   if (vcpu->arch.vpa.pinned_addr)
+   init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
}
if (vcpu->arch.dtl.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.dtl);
@@ -600,6 +617,23 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, 
union kvmppc_one_reg *val)
}
break;
 #endif /* CONFIG_VSX */
+   case KVM_REG_PPC_VPA_ADDR:
+   spin_lock(&vcpu->arch.vpa_update_lock);
+   *

[PATCH v5 2/3] KVM: PPC: Book3S: Get/set guest FP regs using the GET/SET_ONE_REG interface

2012-09-25 Thread Paul Mackerras
This enables userspace to get and set all the guest floating-point
state using the KVM_[GS]ET_ONE_REG ioctls.  The floating-point state
includes all of the traditional floating-point registers and the
FPSCR (floating point status/control register), all the VMX/Altivec
vector registers and the VSCR (vector status/control register), and
on POWER7, the vector-scalar registers (note that each FP register
is the high-order half of the corresponding VSR).

Most of these are implemented in common Book 3S code, except for VSX
on POWER7.  Because HV and PR differ in how they store the FP and VSX
registers on POWER7, the code for these cases is not common.  On POWER7,
the FP registers are the upper halves of the VSX registers vsr0 - vsr31.
PR KVM stores vsr0 - vsr31 in two halves, with the upper halves in the
arch.fpr[] array and the lower halves in the arch.vsr[] array, whereas
HV KVM on POWER7 stores the whole VSX register in arch.vsr[].

Signed-off-by: Paul Mackerras 
---
 Documentation/virtual/kvm/api.txt  |   11 +
 arch/powerpc/include/asm/kvm.h |   20 +++
 arch/powerpc/include/asm/kvm_ppc.h |2 ++
 arch/powerpc/kvm/book3s.c  |   48 
 arch/powerpc/kvm/book3s_hv.c   |   42 +++
 arch/powerpc/kvm/book3s_pr.c   |   24 ++
 6 files changed, 147 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 407556f..a02f0de 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1759,6 +1759,17 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_PMC6  | 32
   PPC   | KVM_REG_PPC_PMC7  | 32
   PPC   | KVM_REG_PPC_PMC8  | 32
+  PPC   | KVM_REG_PPC_FPR0 | 64
+  ...
+  PPC   | KVM_REG_PPC_FPR31 | 64
+  PPC   | KVM_REG_PPC_VR0  | 128
+  ...
+  PPC   | KVM_REG_PPC_VR31  | 128
+  PPC   | KVM_REG_PPC_VSR0 | 128
+  ...
+  PPC   | KVM_REG_PPC_VSR31 | 128
+  PPC   | KVM_REG_PPC_FPSCR | 64
+  PPC   | KVM_REG_PPC_VSCR  | 32
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 9557576..1466975 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -360,4 +360,24 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_PMC7   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
 #define KVM_REG_PPC_PMC8   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
+/* 32 floating-point registers */
+#define KVM_REG_PPC_FPR0   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x20)
+#define KVM_REG_PPC_FPR(n) (KVM_REG_PPC_FPR0 + (n))
+#define KVM_REG_PPC_FPR31  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3f)
+
+/* 32 VMX/Altivec vector registers */
+#define KVM_REG_PPC_VR0(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x40)
+#define KVM_REG_PPC_VR(n)  (KVM_REG_PPC_VR0 + (n))
+#define KVM_REG_PPC_VR31   (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x5f)
+
+/* 32 double-width FP registers for VSX */
+/* High-order halves overlap with FP regs */
+#define KVM_REG_PPC_VSR0   (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x60)
+#define KVM_REG_PPC_VSR(n) (KVM_REG_PPC_VSR0 + (n))
+#define KVM_REG_PPC_VSR31  (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x7f)
+
+/* FP and vector status/control registers */
+#define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+#define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
+
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 709f0dd..51604a1 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -200,6 +200,8 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int 
lsb, int value)
 union kvmppc_one_reg {
u32 wval;
u64 dval;
+   vector128 vval;
+   u64 vsxval[2];
 };
 
 #define one_reg_size(id)   \
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index a5af28f..a4b6452 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -490,6 +490,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
int r;
union kvmppc_one_reg val;
int size;
+   long int i;
 
size = one_reg_size(reg->id);
if (size > sizeof(val))
@@ -506,6 +507,29 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DSISR:
val = get_reg_val(reg->id, vcpu->arch.shared->dsisr);
break;
+   case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
+   i = reg->id - KVM_REG_PPC_FPR0;
+   val = get_reg_val(reg->id, vcpu->arch.fpr[i]);
+   break;
+   case KVM_REG_PPC_FPSCR:
+   val = get_reg_val(reg->id, vcpu->arch.fpscr);
+   

Re: [PATCH] KVM: PPC: set IN_GUEST_MODE before checking requests

2012-09-25 Thread Scott Wood

On 09/25/2012 02:44:52 AM, Alexander Graf wrote:


On 23.08.2012, at 03:03, Scott Wood wrote:

> Avoid a race as described in the code comment.
>
> Also remove a related smp_wmb() from booke's  
kvmppc_prepare_to_enter().
> I can't see any reason for it, and the book3s_pr version doesn't  
have it.

>
> Signed-off-by: Scott Wood 

Does this patch address your comments on the previous pull request?


It addresses the comments on the vcpu->mode race... I don't remember if  
I had any other comments. :-)


-Scott
--
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


Re: [PATCH v4 1/3] KVM: PPC: Book3S: Get/set guest SPRs using the GET/SET_ONE_REG interface

2012-09-25 Thread Alexander Graf

On 25.09.2012, at 11:44, Paul Mackerras wrote:

> This enables userspace to get and set various SPRs (special-purpose
> registers) using the KVM_[GS]ET_ONE_REG ioctls.  With this, userspace
> can get and set all the SPRs that are part of the guest state, either
> through the KVM_[GS]ET_REGS ioctls, the KVM_[GS]ET_SREGS ioctls, or
> the KVM_[GS]ET_ONE_REG ioctls.
> 
> The SPRs that are added here are:
> 
> - DABR:  Data address breakpoint register
> - DSCR:  Data stream control register
> - PURR:  Processor utilization of resources register
> - SPURR: Scaled PURR
> - DAR:   Data address register
> - DSISR: Data storage interrupt status register
> - AMR:   Authority mask register
> - UAMOR: User authority mask override register
> - MMCR0, MMCR1, MMCRA: Performance monitor unit control registers
> - PMC1..PMC8: Performance monitor unit counter registers
> 
> In order to reduce code duplication between PR and HV KVM code, this
> moves the kvm_vcpu_ioctl_[gs]et_one_reg functions into book3s.c and
> centralizes the copying between user and kernel space there.  The
> registers that are handled differently between PR and HV, and those
> that exist only in one flavor, are handled in kvmppc_[gs]et_one_reg()
> functions that are specific to each flavor.
> 
> Signed-off-by: Paul Mackerras 
> ---
> v4: define and use set_one_reg/get_one_reg macros
> 
> Documentation/virtual/kvm/api.txt  |   19 +
> arch/powerpc/include/asm/kvm.h |   21 ++
> arch/powerpc/include/asm/kvm_ppc.h |   30 ++
> arch/powerpc/kvm/book3s.c  |   68 
> arch/powerpc/kvm/book3s_hv.c   |   76 ++--
> arch/powerpc/kvm/book3s_pr.c   |   23 ++-
> 6 files changed, 213 insertions(+), 24 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index a12f4e4..407556f 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -1740,6 +1740,25 @@ registers, find a list below:
>   PPC   | KVM_REG_PPC_IAC4  | 64
>   PPC   | KVM_REG_PPC_DAC1  | 64
>   PPC   | KVM_REG_PPC_DAC2  | 64
> +  PPC   | KVM_REG_PPC_DABR  | 64
> +  PPC   | KVM_REG_PPC_DSCR  | 64
> +  PPC   | KVM_REG_PPC_PURR  | 64
> +  PPC   | KVM_REG_PPC_SPURR | 64
> +  PPC   | KVM_REG_PPC_DAR   | 64
> +  PPC   | KVM_REG_PPC_DSISR  | 32
> +  PPC   | KVM_REG_PPC_AMR   | 64
> +  PPC   | KVM_REG_PPC_UAMOR | 64
> +  PPC   | KVM_REG_PPC_MMCR0 | 64
> +  PPC   | KVM_REG_PPC_MMCR1 | 64
> +  PPC   | KVM_REG_PPC_MMCRA | 64
> +  PPC   | KVM_REG_PPC_PMC1  | 32
> +  PPC   | KVM_REG_PPC_PMC2  | 32
> +  PPC   | KVM_REG_PPC_PMC3  | 32
> +  PPC   | KVM_REG_PPC_PMC4  | 32
> +  PPC   | KVM_REG_PPC_PMC5  | 32
> +  PPC   | KVM_REG_PPC_PMC6  | 32
> +  PPC   | KVM_REG_PPC_PMC7  | 32
> +  PPC   | KVM_REG_PPC_PMC8  | 32
> 
> 4.69 KVM_GET_ONE_REG
> 
> diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
> index 3c14202..9557576 100644
> --- a/arch/powerpc/include/asm/kvm.h
> +++ b/arch/powerpc/include/asm/kvm.h
> @@ -338,5 +338,26 @@ struct kvm_book3e_206_tlb_params {
> #define KVM_REG_PPC_IAC4  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
> #define KVM_REG_PPC_DAC1  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
> #define KVM_REG_PPC_DAC2  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
> +#define KVM_REG_PPC_DABR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
> +#define KVM_REG_PPC_DSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
> +#define KVM_REG_PPC_PURR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
> +#define KVM_REG_PPC_SPURR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
> +#define KVM_REG_PPC_DAR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
> +#define KVM_REG_PPC_DSISR(KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
> +#define KVM_REG_PPC_AMR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
> +#define KVM_REG_PPC_UAMOR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
> +
> +#define KVM_REG_PPC_MMCR0(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
> +#define KVM_REG_PPC_MMCR1(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
> +#define KVM_REG_PPC_MMCRA(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
> +
> +#define KVM_REG_PPC_PMC1 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
> +#define KVM_REG_PPC_PMC2 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
> +#define KVM_REG_PPC_PMC3 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
> +#define KVM_REG_PPC_PMC4 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
> +#define KVM_REG_PPC_PMC5 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
> +#define KVM_REG_PPC_PMC6 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
> +#define KVM_REG_PPC_PMC7 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
> +#define KVM_REG_PPC_PMC8 (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
> 
> #endif /* __LINUX_KVM_POWERPC_H */
> diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> b/arch/powerpc/include/asm/kvm_ppc.h
> index 3fb980d..a460f024 100644
> --- a/arch/powerpc/include/a

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Alexander Graf

On 25.09.2012, at 13:06, Jan Kiszka wrote:

> On 2012-09-25 12:58, Alexander Graf wrote:
>> 
>> On 25.09.2012, at 12:56, Jan Kiszka wrote:
>> 
>>> On 2012-09-25 12:47, Alexander Graf wrote:
 
 On 25.09.2012, at 12:38, Jan Kiszka wrote:
 
> On 2012-09-24 16:46, Alexander Graf wrote:
>> 
>> On 07.09.2012, at 00:56, Scott Wood wrote:
>> 
>>> On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
 
 
> -Original Message-
> From: Wood Scott-B07421
> Sent: Thursday, September 06, 2012 4:57 AM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; 
> Bhushan Bharat-
> R65777
> Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
> 
> On 09/05/2012 06:23 PM, Scott Wood wrote:
>> On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
>>> This patch adds the debug stub support on booke/bookehv.
>>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
>>> breakpoint to debug guest.
>>> 
>>> Signed-off-by: Bharat Bhushan 
>>> ---
>>> arch/powerpc/include/asm/kvm.h|   29 ++-
>>> arch/powerpc/include/asm/kvm_host.h   |5 +
>>> arch/powerpc/kernel/asm-offsets.c |   26 ++
>>> arch/powerpc/kvm/booke.c  |  144 
>>> +--
> --
>>> arch/powerpc/kvm/booke_interrupts.S   |  110 
>>> +
>>> arch/powerpc/kvm/bookehv_interrupts.S |  141
> +++-
>>> arch/powerpc/kvm/e500mc.c |3 +-
>>> 7 files changed, 435 insertions(+), 23 deletions(-)
>>> 
>>> diff --git a/arch/powerpc/include/asm/kvm.h
>>> b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
>>> --- a/arch/powerpc/include/asm/kvm.h
>>> +++ b/arch/powerpc/include/asm/kvm.h
>>> @@ -25,6 +25,7 @@
>>> /* Select powerpc specific features in  */  #define
>>> __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
>>> +#define __KVM_HAVE_GUEST_DEBUG
>>> 
>>> struct kvm_regs {
>>> __u64 pc;
>>> @@ -264,7 +265,31 @@ struct kvm_fpu {
>>> __u64 fpr[32];
>>> };
>>> 
>>> +
>>> +/*
>>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
>>> + * software breakpoint.
>>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and 
>>> "status"
>>> + * for KVM_DEBUG_EXIT.
>>> + */
>>> +#define KVMPPC_DEBUG_NONE  0x0
>>> +#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
>>> +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
>>> +#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
>>> struct kvm_debug_exit_arch {
>> 
>> That says "arch", but it's not in an arch-specific file.
> 
> Sigh, I can't read today apparently.
> 
>>> +   __u64 pc;
>>> +   /*
>>> +* exception -> returns the exception number. If the 
>>> KVM_DEBUG_EXIT
>>> +* exit is not handled (say not h/w breakpoint or software 
>>> breakpoint
>>> +* set for this address) by qemu then it is supposed to inject 
>>> this
>>> +* exception to guest.
>>> +*/
>>> +   __u32 exception;
>>> +   /*
>>> +* exiting to userspace because of h/w breakpoint, watchpoint
>>> +* (read, write or both) and software breakpoint.
>>> +*/
>>> +   __u32 status;
>>> };
>> 
>> What does "exception number" mean in a generic API?
> 
> Still, "exception number" is not a well-defined concept powerpc-wide.
 
 Just for background why we added is that, on x86 this exception number 
 is used to inject the exception to guest if QEMU is not able to handle 
 the debug exception.
 
 Should we just through a print with clearing the exception condition? 
 Or something else you would like to suggest?
>>> 
>>> We can pass up the exception type; it just needs more documentation
>>> about what exactly you're referring to, and probably some enumeration
>>> that says which exception numberspace it is.
>>> 
>>> For booke the exception number should probably be related to the fixed
>>> offsets rather than the IVOR number, as IVORs are phased out.
>> 
>> Jan, I would like to get your comment on this one.
>> 
>> Since we don't have standardized exception vectors like x86 does, we 
>> need to convert things between different semantics in user space if we 
>> want to make use of the exception type. Do we actually need 

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Jan Kiszka
On 2012-09-25 12:58, Alexander Graf wrote:
> 
> On 25.09.2012, at 12:56, Jan Kiszka wrote:
> 
>> On 2012-09-25 12:47, Alexander Graf wrote:
>>>
>>> On 25.09.2012, at 12:38, Jan Kiszka wrote:
>>>
 On 2012-09-24 16:46, Alexander Graf wrote:
>
> On 07.09.2012, at 00:56, Scott Wood wrote:
>
>> On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
>>>
>>>
 -Original Message-
 From: Wood Scott-B07421
 Sent: Thursday, September 06, 2012 4:57 AM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; 
 Bhushan Bharat-
 R65777
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

 On 09/05/2012 06:23 PM, Scott Wood wrote:
> On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
>> This patch adds the debug stub support on booke/bookehv.
>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
>> breakpoint to debug guest.
>>
>> Signed-off-by: Bharat Bhushan 
>> ---
>> arch/powerpc/include/asm/kvm.h|   29 ++-
>> arch/powerpc/include/asm/kvm_host.h   |5 +
>> arch/powerpc/kernel/asm-offsets.c |   26 ++
>> arch/powerpc/kvm/booke.c  |  144 
>> +--
 --
>> arch/powerpc/kvm/booke_interrupts.S   |  110 
>> +
>> arch/powerpc/kvm/bookehv_interrupts.S |  141
 +++-
>> arch/powerpc/kvm/e500mc.c |3 +-
>> 7 files changed, 435 insertions(+), 23 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/kvm.h
>> b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
>> --- a/arch/powerpc/include/asm/kvm.h
>> +++ b/arch/powerpc/include/asm/kvm.h
>> @@ -25,6 +25,7 @@
>> /* Select powerpc specific features in  */  #define
>> __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
>> +#define __KVM_HAVE_GUEST_DEBUG
>>
>> struct kvm_regs {
>>  __u64 pc;
>> @@ -264,7 +265,31 @@ struct kvm_fpu {
>>  __u64 fpr[32];
>> };
>>
>> +
>> +/*
>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
>> + * software breakpoint.
>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and 
>> "status"
>> + * for KVM_DEBUG_EXIT.
>> + */
>> +#define KVMPPC_DEBUG_NONE   0x0
>> +#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1)
>> +#define KVMPPC_DEBUG_WATCH_WRITE(1UL << 2)
>> +#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)
>> struct kvm_debug_exit_arch {
>
> That says "arch", but it's not in an arch-specific file.

 Sigh, I can't read today apparently.

>> +__u64 pc;
>> +/*
>> + * exception -> returns the exception number. If the 
>> KVM_DEBUG_EXIT
>> + * exit is not handled (say not h/w breakpoint or software 
>> breakpoint
>> + * set for this address) by qemu then it is supposed to inject 
>> this
>> + * exception to guest.
>> + */
>> +__u32 exception;
>> +/*
>> + * exiting to userspace because of h/w breakpoint, watchpoint
>> + * (read, write or both) and software breakpoint.
>> + */
>> +__u32 status;
>> };
>
> What does "exception number" mean in a generic API?

 Still, "exception number" is not a well-defined concept powerpc-wide.
>>>
>>> Just for background why we added is that, on x86 this exception number 
>>> is used to inject the exception to guest if QEMU is not able to handle 
>>> the debug exception.
>>>
>>> Should we just through a print with clearing the exception condition? 
>>> Or something else you would like to suggest?
>>
>> We can pass up the exception type; it just needs more documentation
>> about what exactly you're referring to, and probably some enumeration
>> that says which exception numberspace it is.
>>
>> For booke the exception number should probably be related to the fixed
>> offsets rather than the IVOR number, as IVORs are phased out.
>
> Jan, I would like to get your comment on this one.
>
> Since we don't have standardized exception vectors like x86 does, we need 
> to convert things between different semantics in user space if we want to 
> make use of the exception type. Do we actually need to know about it in 
> user space or do we only need to store it in case we get a migration at 
> that point?
>
> If it's the latter, can we maybe keep 

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Alexander Graf

On 25.09.2012, at 12:56, Jan Kiszka wrote:

> On 2012-09-25 12:47, Alexander Graf wrote:
>> 
>> On 25.09.2012, at 12:38, Jan Kiszka wrote:
>> 
>>> On 2012-09-24 16:46, Alexander Graf wrote:
 
 On 07.09.2012, at 00:56, Scott Wood wrote:
 
> On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
>> 
>> 
>>> -Original Message-
>>> From: Wood Scott-B07421
>>> Sent: Thursday, September 06, 2012 4:57 AM
>>> To: Bhushan Bharat-R65777
>>> Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; 
>>> Bhushan Bharat-
>>> R65777
>>> Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
>>> 
>>> On 09/05/2012 06:23 PM, Scott Wood wrote:
 On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
> This patch adds the debug stub support on booke/bookehv.
> Now QEMU debug stub can use hw breakpoint, watchpoint and software
> breakpoint to debug guest.
> 
> Signed-off-by: Bharat Bhushan 
> ---
> arch/powerpc/include/asm/kvm.h|   29 ++-
> arch/powerpc/include/asm/kvm_host.h   |5 +
> arch/powerpc/kernel/asm-offsets.c |   26 ++
> arch/powerpc/kvm/booke.c  |  144 
> +--
>>> --
> arch/powerpc/kvm/booke_interrupts.S   |  110 +
> arch/powerpc/kvm/bookehv_interrupts.S |  141
>>> +++-
> arch/powerpc/kvm/e500mc.c |3 +-
> 7 files changed, 435 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm.h
> b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
> --- a/arch/powerpc/include/asm/kvm.h
> +++ b/arch/powerpc/include/asm/kvm.h
> @@ -25,6 +25,7 @@
> /* Select powerpc specific features in  */  #define
> __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
> +#define __KVM_HAVE_GUEST_DEBUG
> 
> struct kvm_regs {
>   __u64 pc;
> @@ -264,7 +265,31 @@ struct kvm_fpu {
>   __u64 fpr[32];
> };
> 
> +
> +/*
> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
> + * software breakpoint.
> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
> + * for KVM_DEBUG_EXIT.
> + */
> +#define KVMPPC_DEBUG_NONE0x0
> +#define KVMPPC_DEBUG_BREAKPOINT  (1UL << 1)
> +#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
> +#define KVMPPC_DEBUG_WATCH_READ  (1UL << 3)
> struct kvm_debug_exit_arch {
 
 That says "arch", but it's not in an arch-specific file.
>>> 
>>> Sigh, I can't read today apparently.
>>> 
> + __u64 pc;
> + /*
> +  * exception -> returns the exception number. If the 
> KVM_DEBUG_EXIT
> +  * exit is not handled (say not h/w breakpoint or software 
> breakpoint
> +  * set for this address) by qemu then it is supposed to inject 
> this
> +  * exception to guest.
> +  */
> + __u32 exception;
> + /*
> +  * exiting to userspace because of h/w breakpoint, watchpoint
> +  * (read, write or both) and software breakpoint.
> +  */
> + __u32 status;
> };
 
 What does "exception number" mean in a generic API?
>>> 
>>> Still, "exception number" is not a well-defined concept powerpc-wide.
>> 
>> Just for background why we added is that, on x86 this exception number 
>> is used to inject the exception to guest if QEMU is not able to handle 
>> the debug exception.
>> 
>> Should we just through a print with clearing the exception condition? Or 
>> something else you would like to suggest?
> 
> We can pass up the exception type; it just needs more documentation
> about what exactly you're referring to, and probably some enumeration
> that says which exception numberspace it is.
> 
> For booke the exception number should probably be related to the fixed
> offsets rather than the IVOR number, as IVORs are phased out.
 
 Jan, I would like to get your comment on this one.
 
 Since we don't have standardized exception vectors like x86 does, we need 
 to convert things between different semantics in user space if we want to 
 make use of the exception type. Do we actually need to know about it in 
 user space or do we only need to store it in case we get a migration at 
 that point?
 
 If it's the latter, can we maybe keep the reinjection logic internal to 
 KVM and make DEBUG exits non-migratable similar to how we already handle 
 MMIO/PIO exits today?
>>> 
>>

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Jan Kiszka
On 2012-09-25 12:47, Alexander Graf wrote:
> 
> On 25.09.2012, at 12:38, Jan Kiszka wrote:
> 
>> On 2012-09-24 16:46, Alexander Graf wrote:
>>>
>>> On 07.09.2012, at 00:56, Scott Wood wrote:
>>>
 On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
>
>
>> -Original Message-
>> From: Wood Scott-B07421
>> Sent: Thursday, September 06, 2012 4:57 AM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; 
>> Bhushan Bharat-
>> R65777
>> Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
>>
>> On 09/05/2012 06:23 PM, Scott Wood wrote:
>>> On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
 This patch adds the debug stub support on booke/bookehv.
 Now QEMU debug stub can use hw breakpoint, watchpoint and software
 breakpoint to debug guest.

 Signed-off-by: Bharat Bhushan 
 ---
 arch/powerpc/include/asm/kvm.h|   29 ++-
 arch/powerpc/include/asm/kvm_host.h   |5 +
 arch/powerpc/kernel/asm-offsets.c |   26 ++
 arch/powerpc/kvm/booke.c  |  144 
 +--
>> --
 arch/powerpc/kvm/booke_interrupts.S   |  110 +
 arch/powerpc/kvm/bookehv_interrupts.S |  141
>> +++-
 arch/powerpc/kvm/e500mc.c |3 +-
 7 files changed, 435 insertions(+), 23 deletions(-)

 diff --git a/arch/powerpc/include/asm/kvm.h
 b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
 --- a/arch/powerpc/include/asm/kvm.h
 +++ b/arch/powerpc/include/asm/kvm.h
 @@ -25,6 +25,7 @@
 /* Select powerpc specific features in  */  #define
 __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
 +#define __KVM_HAVE_GUEST_DEBUG

 struct kvm_regs {
__u64 pc;
 @@ -264,7 +265,31 @@ struct kvm_fpu {
__u64 fpr[32];
 };

 +
 +/*
 + * Defines for h/w breakpoint, watchpoint (read, write or both) and
 + * software breakpoint.
 + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
 + * for KVM_DEBUG_EXIT.
 + */
 +#define KVMPPC_DEBUG_NONE 0x0
 +#define KVMPPC_DEBUG_BREAKPOINT   (1UL << 1)
 +#define KVMPPC_DEBUG_WATCH_WRITE  (1UL << 2)
 +#define KVMPPC_DEBUG_WATCH_READ   (1UL << 3)
 struct kvm_debug_exit_arch {
>>>
>>> That says "arch", but it's not in an arch-specific file.
>>
>> Sigh, I can't read today apparently.
>>
 +  __u64 pc;
 +  /*
 +   * exception -> returns the exception number. If the 
 KVM_DEBUG_EXIT
 +   * exit is not handled (say not h/w breakpoint or software 
 breakpoint
 +   * set for this address) by qemu then it is supposed to inject 
 this
 +   * exception to guest.
 +   */
 +  __u32 exception;
 +  /*
 +   * exiting to userspace because of h/w breakpoint, watchpoint
 +   * (read, write or both) and software breakpoint.
 +   */
 +  __u32 status;
 };
>>>
>>> What does "exception number" mean in a generic API?
>>
>> Still, "exception number" is not a well-defined concept powerpc-wide.
>
> Just for background why we added is that, on x86 this exception number is 
> used to inject the exception to guest if QEMU is not able to handle the 
> debug exception.
>
> Should we just through a print with clearing the exception condition? Or 
> something else you would like to suggest?

 We can pass up the exception type; it just needs more documentation
 about what exactly you're referring to, and probably some enumeration
 that says which exception numberspace it is.

 For booke the exception number should probably be related to the fixed
 offsets rather than the IVOR number, as IVORs are phased out.
>>>
>>> Jan, I would like to get your comment on this one.
>>>
>>> Since we don't have standardized exception vectors like x86 does, we need 
>>> to convert things between different semantics in user space if we want to 
>>> make use of the exception type. Do we actually need to know about it in 
>>> user space or do we only need to store it in case we get a migration at 
>>> that point?
>>>
>>> If it's the latter, can we maybe keep the reinjection logic internal to KVM 
>>> and make DEBUG exits non-migratable similar to how we already handle 
>>> MMIO/PIO exits today?
>>
>> Reinjection depends on userspace. It has to check if the debug event was
>> related to the host debugging the guest or if it was due to a
>> guest-internal debugging ev

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Jan Kiszka
On 2012-09-24 16:46, Alexander Graf wrote:
> 
> On 07.09.2012, at 00:56, Scott Wood wrote:
> 
>> On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
>>>
>>>
 -Original Message-
 From: Wood Scott-B07421
 Sent: Thursday, September 06, 2012 4:57 AM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; Bhushan 
 Bharat-
 R65777
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

 On 09/05/2012 06:23 PM, Scott Wood wrote:
> On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
>> This patch adds the debug stub support on booke/bookehv.
>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
>> breakpoint to debug guest.
>>
>> Signed-off-by: Bharat Bhushan 
>> ---
>> arch/powerpc/include/asm/kvm.h|   29 ++-
>> arch/powerpc/include/asm/kvm_host.h   |5 +
>> arch/powerpc/kernel/asm-offsets.c |   26 ++
>> arch/powerpc/kvm/booke.c  |  144 
>> +--
 --
>> arch/powerpc/kvm/booke_interrupts.S   |  110 +
>> arch/powerpc/kvm/bookehv_interrupts.S |  141
 +++-
>> arch/powerpc/kvm/e500mc.c |3 +-
>> 7 files changed, 435 insertions(+), 23 deletions(-)
>>
>> diff --git a/arch/powerpc/include/asm/kvm.h
>> b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
>> --- a/arch/powerpc/include/asm/kvm.h
>> +++ b/arch/powerpc/include/asm/kvm.h
>> @@ -25,6 +25,7 @@
>> /* Select powerpc specific features in  */  #define
>> __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
>> +#define __KVM_HAVE_GUEST_DEBUG
>>
>> struct kvm_regs {
>>  __u64 pc;
>> @@ -264,7 +265,31 @@ struct kvm_fpu {
>>  __u64 fpr[32];
>> };
>>
>> +
>> +/*
>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
>> + * software breakpoint.
>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
>> + * for KVM_DEBUG_EXIT.
>> + */
>> +#define KVMPPC_DEBUG_NONE   0x0
>> +#define KVMPPC_DEBUG_BREAKPOINT (1UL << 1)
>> +#define KVMPPC_DEBUG_WATCH_WRITE(1UL << 2)
>> +#define KVMPPC_DEBUG_WATCH_READ (1UL << 3)
>> struct kvm_debug_exit_arch {
>
> That says "arch", but it's not in an arch-specific file.

 Sigh, I can't read today apparently.

>> +__u64 pc;
>> +/*
>> + * exception -> returns the exception number. If the 
>> KVM_DEBUG_EXIT
>> + * exit is not handled (say not h/w breakpoint or software 
>> breakpoint
>> + * set for this address) by qemu then it is supposed to inject 
>> this
>> + * exception to guest.
>> + */
>> +__u32 exception;
>> +/*
>> + * exiting to userspace because of h/w breakpoint, watchpoint
>> + * (read, write or both) and software breakpoint.
>> + */
>> +__u32 status;
>> };
>
> What does "exception number" mean in a generic API?

 Still, "exception number" is not a well-defined concept powerpc-wide.
>>>
>>> Just for background why we added is that, on x86 this exception number is 
>>> used to inject the exception to guest if QEMU is not able to handle the 
>>> debug exception.
>>>
>>> Should we just through a print with clearing the exception condition? Or 
>>> something else you would like to suggest?
>>
>> We can pass up the exception type; it just needs more documentation
>> about what exactly you're referring to, and probably some enumeration
>> that says which exception numberspace it is.
>>
>> For booke the exception number should probably be related to the fixed
>> offsets rather than the IVOR number, as IVORs are phased out.
> 
> Jan, I would like to get your comment on this one.
> 
> Since we don't have standardized exception vectors like x86 does, we need to 
> convert things between different semantics in user space if we want to make 
> use of the exception type. Do we actually need to know about it in user space 
> or do we only need to store it in case we get a migration at that point?
> 
> If it's the latter, can we maybe keep the reinjection logic internal to KVM 
> and make DEBUG exits non-migratable similar to how we already handle MMIO/PIO 
> exits today?

Reinjection depends on userspace. It has to check if the debug event was
related to the host debugging the guest or if it was due to a
guest-internal debugging event. That's because the kernel does not track
individual breakpoints, just controls the trapping. So we need a way to
manage the reinjection, and we do this (on x86) by passing the exception
up and then using it for SET_VCPU_EVENTS to reinject it if necessary.

The general logic (reinjection filter in userspace) should be gene

Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support

2012-09-25 Thread Alexander Graf

On 25.09.2012, at 12:38, Jan Kiszka wrote:

> On 2012-09-24 16:46, Alexander Graf wrote:
>> 
>> On 07.09.2012, at 00:56, Scott Wood wrote:
>> 
>>> On 09/06/2012 09:56 AM, Bhushan Bharat-R65777 wrote:
 
 
> -Original Message-
> From: Wood Scott-B07421
> Sent: Thursday, September 06, 2012 4:57 AM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; Bhushan 
> Bharat-
> R65777
> Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
> 
> On 09/05/2012 06:23 PM, Scott Wood wrote:
>> On 08/21/2012 08:52 AM, Bharat Bhushan wrote:
>>> This patch adds the debug stub support on booke/bookehv.
>>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
>>> breakpoint to debug guest.
>>> 
>>> Signed-off-by: Bharat Bhushan 
>>> ---
>>> arch/powerpc/include/asm/kvm.h|   29 ++-
>>> arch/powerpc/include/asm/kvm_host.h   |5 +
>>> arch/powerpc/kernel/asm-offsets.c |   26 ++
>>> arch/powerpc/kvm/booke.c  |  144 
>>> +--
> --
>>> arch/powerpc/kvm/booke_interrupts.S   |  110 +
>>> arch/powerpc/kvm/bookehv_interrupts.S |  141
> +++-
>>> arch/powerpc/kvm/e500mc.c |3 +-
>>> 7 files changed, 435 insertions(+), 23 deletions(-)
>>> 
>>> diff --git a/arch/powerpc/include/asm/kvm.h
>>> b/arch/powerpc/include/asm/kvm.h index 61b197e..53479ea 100644
>>> --- a/arch/powerpc/include/asm/kvm.h
>>> +++ b/arch/powerpc/include/asm/kvm.h
>>> @@ -25,6 +25,7 @@
>>> /* Select powerpc specific features in  */  #define
>>> __KVM_HAVE_SPAPR_TCE  #define __KVM_HAVE_PPC_SMT
>>> +#define __KVM_HAVE_GUEST_DEBUG
>>> 
>>> struct kvm_regs {
>>> __u64 pc;
>>> @@ -264,7 +265,31 @@ struct kvm_fpu {
>>> __u64 fpr[32];
>>> };
>>> 
>>> +
>>> +/*
>>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
>>> + * software breakpoint.
>>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
>>> + * for KVM_DEBUG_EXIT.
>>> + */
>>> +#define KVMPPC_DEBUG_NONE  0x0
>>> +#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
>>> +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
>>> +#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
>>> struct kvm_debug_exit_arch {
>> 
>> That says "arch", but it's not in an arch-specific file.
> 
> Sigh, I can't read today apparently.
> 
>>> +   __u64 pc;
>>> +   /*
>>> +* exception -> returns the exception number. If the 
>>> KVM_DEBUG_EXIT
>>> +* exit is not handled (say not h/w breakpoint or software 
>>> breakpoint
>>> +* set for this address) by qemu then it is supposed to inject 
>>> this
>>> +* exception to guest.
>>> +*/
>>> +   __u32 exception;
>>> +   /*
>>> +* exiting to userspace because of h/w breakpoint, watchpoint
>>> +* (read, write or both) and software breakpoint.
>>> +*/
>>> +   __u32 status;
>>> };
>> 
>> What does "exception number" mean in a generic API?
> 
> Still, "exception number" is not a well-defined concept powerpc-wide.
 
 Just for background why we added is that, on x86 this exception number is 
 used to inject the exception to guest if QEMU is not able to handle the 
 debug exception.
 
 Should we just through a print with clearing the exception condition? Or 
 something else you would like to suggest?
>>> 
>>> We can pass up the exception type; it just needs more documentation
>>> about what exactly you're referring to, and probably some enumeration
>>> that says which exception numberspace it is.
>>> 
>>> For booke the exception number should probably be related to the fixed
>>> offsets rather than the IVOR number, as IVORs are phased out.
>> 
>> Jan, I would like to get your comment on this one.
>> 
>> Since we don't have standardized exception vectors like x86 does, we need to 
>> convert things between different semantics in user space if we want to make 
>> use of the exception type. Do we actually need to know about it in user 
>> space or do we only need to store it in case we get a migration at that 
>> point?
>> 
>> If it's the latter, can we maybe keep the reinjection logic internal to KVM 
>> and make DEBUG exits non-migratable similar to how we already handle 
>> MMIO/PIO exits today?
> 
> Reinjection depends on userspace. It has to check if the debug event was
> related to the host debugging the guest or if it was due to a
> guest-internal debugging event. That's because the kernel does not track
> individual breakpoints, just controls the trapping. So we need a way to
> manag

[PATCH v4 1/3] KVM: PPC: Book3S: Get/set guest SPRs using the GET/SET_ONE_REG interface

2012-09-25 Thread Paul Mackerras
This enables userspace to get and set various SPRs (special-purpose
registers) using the KVM_[GS]ET_ONE_REG ioctls.  With this, userspace
can get and set all the SPRs that are part of the guest state, either
through the KVM_[GS]ET_REGS ioctls, the KVM_[GS]ET_SREGS ioctls, or
the KVM_[GS]ET_ONE_REG ioctls.

The SPRs that are added here are:

- DABR:  Data address breakpoint register
- DSCR:  Data stream control register
- PURR:  Processor utilization of resources register
- SPURR: Scaled PURR
- DAR:   Data address register
- DSISR: Data storage interrupt status register
- AMR:   Authority mask register
- UAMOR: User authority mask override register
- MMCR0, MMCR1, MMCRA: Performance monitor unit control registers
- PMC1..PMC8: Performance monitor unit counter registers

In order to reduce code duplication between PR and HV KVM code, this
moves the kvm_vcpu_ioctl_[gs]et_one_reg functions into book3s.c and
centralizes the copying between user and kernel space there.  The
registers that are handled differently between PR and HV, and those
that exist only in one flavor, are handled in kvmppc_[gs]et_one_reg()
functions that are specific to each flavor.

Signed-off-by: Paul Mackerras 
---
v4: define and use set_one_reg/get_one_reg macros

 Documentation/virtual/kvm/api.txt  |   19 +
 arch/powerpc/include/asm/kvm.h |   21 ++
 arch/powerpc/include/asm/kvm_ppc.h |   30 ++
 arch/powerpc/kvm/book3s.c  |   68 
 arch/powerpc/kvm/book3s_hv.c   |   76 ++--
 arch/powerpc/kvm/book3s_pr.c   |   23 ++-
 6 files changed, 213 insertions(+), 24 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index a12f4e4..407556f 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1740,6 +1740,25 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_IAC4  | 64
   PPC   | KVM_REG_PPC_DAC1  | 64
   PPC   | KVM_REG_PPC_DAC2  | 64
+  PPC   | KVM_REG_PPC_DABR  | 64
+  PPC   | KVM_REG_PPC_DSCR  | 64
+  PPC   | KVM_REG_PPC_PURR  | 64
+  PPC   | KVM_REG_PPC_SPURR | 64
+  PPC   | KVM_REG_PPC_DAR   | 64
+  PPC   | KVM_REG_PPC_DSISR| 32
+  PPC   | KVM_REG_PPC_AMR   | 64
+  PPC   | KVM_REG_PPC_UAMOR | 64
+  PPC   | KVM_REG_PPC_MMCR0 | 64
+  PPC   | KVM_REG_PPC_MMCR1 | 64
+  PPC   | KVM_REG_PPC_MMCRA | 64
+  PPC   | KVM_REG_PPC_PMC1  | 32
+  PPC   | KVM_REG_PPC_PMC2  | 32
+  PPC   | KVM_REG_PPC_PMC3  | 32
+  PPC   | KVM_REG_PPC_PMC4  | 32
+  PPC   | KVM_REG_PPC_PMC5  | 32
+  PPC   | KVM_REG_PPC_PMC6  | 32
+  PPC   | KVM_REG_PPC_PMC7  | 32
+  PPC   | KVM_REG_PPC_PMC8  | 32
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 3c14202..9557576 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -338,5 +338,26 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_IAC4   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x5)
 #define KVM_REG_PPC_DAC1   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x6)
 #define KVM_REG_PPC_DAC2   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x7)
+#define KVM_REG_PPC_DABR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8)
+#define KVM_REG_PPC_DSCR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x9)
+#define KVM_REG_PPC_PURR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xa)
+#define KVM_REG_PPC_SPURR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb)
+#define KVM_REG_PPC_DAR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc)
+#define KVM_REG_PPC_DSISR  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xd)
+#define KVM_REG_PPC_AMR(KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xe)
+#define KVM_REG_PPC_UAMOR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xf)
+
+#define KVM_REG_PPC_MMCR0  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x10)
+#define KVM_REG_PPC_MMCR1  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x11)
+#define KVM_REG_PPC_MMCRA  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x12)
+
+#define KVM_REG_PPC_PMC1   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x18)
+#define KVM_REG_PPC_PMC2   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x19)
+#define KVM_REG_PPC_PMC3   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1a)
+#define KVM_REG_PPC_PMC4   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1b)
+#define KVM_REG_PPC_PMC5   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1c)
+#define KVM_REG_PPC_PMC6   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1d)
+#define KVM_REG_PPC_PMC7   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
+#define KVM_REG_PPC_PMC8   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 3fb980d..a460f024 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef CONFIG_PPC_BOOK3S
 #include 
 #else
@@ -196,6 +197,33 @@ static inline u

[PATCH 3/3] KVM: PPC: Book3S HV: Provide a way for userspace to get/set per-vCPU areas

2012-09-25 Thread Paul Mackerras
The PAPR paravirtualization interface lets guests register three
different types of per-vCPU buffer areas in its memory for communication
with the hypervisor.  These are called virtual processor areas (VPAs).
Currently the hypercalls to register and unregister VPAs are handled
by KVM in the kernel, and userspace has no way to know about or save
and restore these registrations across a migration.

This adds "register" codes for these three areas that userspace can
use with the KVM_GET/SET_ONE_REG ioctls to see what addresses have
been registered, and to register or unregister them.  This will be
needed for guest hibernation and migration, and is also needed so
that userspace can unregister them on reset (otherwise we corrupt
guest memory after reboot by writing to the VPAs registered by the
previous kernel).

The "register" for the VPA is a 64-bit value containing the address,
since the length of the VPA is fixed.  The "registers" for the SLB
shadow buffer and dispatch trace log (DTL) are 128 bits long,
consisting of the guest physical address in the high (first) 64 bits
and the length in the low 64 bits.

This also fixes a bug where we were calling init_vpa unconditionally,
leading to an oops when unregistering the VPA.

Signed-off-by: Paul Mackerras 
---
 Documentation/virtual/kvm/api.txt  |3 ++
 arch/powerpc/include/asm/kvm.h |6 
 arch/powerpc/include/asm/kvm_ppc.h |4 +++
 arch/powerpc/kvm/book3s_hv.c   |   64 +++-
 4 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index a02f0de..57cb6cc 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1770,6 +1770,9 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_VSR31 | 128
   PPC   | KVM_REG_PPC_FPSCR | 64
   PPC   | KVM_REG_PPC_VSCR  | 32
+  PPC   | KVM_REG_PPC_VPA_ADDR  | 64
+  PPC   | KVM_REG_PPC_VPA_SLB   | 128
+  PPC   | KVM_REG_PPC_VPA_DTL   | 128
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 1466975..b89ae4d 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -380,4 +380,10 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
 #define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
 
+/* Virtual processor areas */
+/* For SLB & DTL, address in high (first) half, length in low half */
+#define KVM_REG_PPC_VPA_ADDR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x82)
+#define KVM_REG_PPC_VPA_SLB(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x83)
+#define KVM_REG_PPC_VPA_DTL(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x84)
+
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 5c182c6..467f087 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -202,6 +202,10 @@ union kvmppc_one_reg {
u64 dval;
vector128 vval;
u64 vsxval[2];
+   struct {
+   u64 addr;
+   u64 length;
+   }   vpaval;
 };
 
 #define one_reg_size(id)   \
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 5eaf2f3..d7e9029 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -143,6 +143,22 @@ static void init_vpa(struct kvm_vcpu *vcpu, struct lppaca 
*vpa)
vpa->yield_count = 1;
 }
 
+static int set_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *v,
+  unsigned long addr, unsigned long len)
+{
+   /* check address is cacheline aligned */
+   if (addr & (L1_CACHE_BYTES - 1))
+   return -EINVAL;
+   spin_lock(&vcpu->arch.vpa_update_lock);
+   if (v->next_gpa != addr || v->len != len) {
+   v->next_gpa = addr;
+   v->len = addr ? len : 0;
+   v->update_pending = 1;
+   }
+   spin_unlock(&vcpu->arch.vpa_update_lock);
+   return 0;
+}
+
 /* Length for a per-processor buffer is passed in at offset 4 in the buffer */
 struct reg_vpa {
u32 dummy;
@@ -321,7 +337,8 @@ static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)
spin_lock(&vcpu->arch.vpa_update_lock);
if (vcpu->arch.vpa.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.vpa);
-   init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
+   if (vcpu->arch.vpa.pinned_addr)
+   init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
}
if (vcpu->arch.dtl.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.dtl);
@@ -600,6 +617,23 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, 
union kvmppc_one_reg *val)
}
break;
 #endif /* CONFIG_VSX */
+   case KVM_REG_PPC_VPA_ADDR:
+   spin_lock(&vcpu->arch.vpa_update_lock);
+   g

[PATCH 2/3] KVM: PPC: Book3S: Get/set guest FP regs using the GET/SET_ONE_REG interface

2012-09-25 Thread Paul Mackerras
This enables userspace to get and set all the guest floating-point
state using the KVM_[GS]ET_ONE_REG ioctls.  The floating-point state
includes all of the traditional floating-point registers and the
FPSCR (floating point status/control register), all the VMX/Altivec
vector registers and the VSCR (vector status/control register), and
on POWER7, the vector-scalar registers (note that each FP register
is the high-order half of the corresponding VSR).

Most of these are implemented in common Book 3S code, except for VSX
on POWER7.  Because HV and PR differ in how they store the FP and VSX
registers on POWER7, the code for these cases is not common.  On POWER7,
the FP registers are the upper halves of the VSX registers vsr0 - vsr31.
PR KVM stores vsr0 - vsr31 in two halves, with the upper halves in the
arch.fpr[] array and the lower halves in the arch.vsr[] array, whereas
HV KVM on POWER7 stores the whole VSX register in arch.vsr[].

Signed-off-by: Paul Mackerras 
---
 Documentation/virtual/kvm/api.txt  |   11 +
 arch/powerpc/include/asm/kvm.h |   20 
 arch/powerpc/include/asm/kvm_ppc.h |2 ++
 arch/powerpc/kvm/book3s.c  |   44 
 arch/powerpc/kvm/book3s_hv.c   |   42 ++
 arch/powerpc/kvm/book3s_pr.c   |   24 
 6 files changed, 143 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 407556f..a02f0de 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1759,6 +1759,17 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_PMC6  | 32
   PPC   | KVM_REG_PPC_PMC7  | 32
   PPC   | KVM_REG_PPC_PMC8  | 32
+  PPC   | KVM_REG_PPC_FPR0 | 64
+  ...
+  PPC   | KVM_REG_PPC_FPR31 | 64
+  PPC   | KVM_REG_PPC_VR0  | 128
+  ...
+  PPC   | KVM_REG_PPC_VR31  | 128
+  PPC   | KVM_REG_PPC_VSR0 | 128
+  ...
+  PPC   | KVM_REG_PPC_VSR31 | 128
+  PPC   | KVM_REG_PPC_FPSCR | 64
+  PPC   | KVM_REG_PPC_VSCR  | 32
 
 4.69 KVM_GET_ONE_REG
 
diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 9557576..1466975 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -360,4 +360,24 @@ struct kvm_book3e_206_tlb_params {
 #define KVM_REG_PPC_PMC7   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1e)
 #define KVM_REG_PPC_PMC8   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x1f)
 
+/* 32 floating-point registers */
+#define KVM_REG_PPC_FPR0   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x20)
+#define KVM_REG_PPC_FPR(n) (KVM_REG_PPC_FPR0 + (n))
+#define KVM_REG_PPC_FPR31  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3f)
+
+/* 32 VMX/Altivec vector registers */
+#define KVM_REG_PPC_VR0(KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x40)
+#define KVM_REG_PPC_VR(n)  (KVM_REG_PPC_VR0 + (n))
+#define KVM_REG_PPC_VR31   (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x5f)
+
+/* 32 double-width FP registers for VSX */
+/* High-order halves overlap with FP regs */
+#define KVM_REG_PPC_VSR0   (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x60)
+#define KVM_REG_PPC_VSR(n) (KVM_REG_PPC_VSR0 + (n))
+#define KVM_REG_PPC_VSR31  (KVM_REG_PPC | KVM_REG_SIZE_U128 | 0x7f)
+
+/* FP and vector status/control registers */
+#define KVM_REG_PPC_FPSCR  (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x80)
+#define KVM_REG_PPC_VSCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x81)
+
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index a460f024..5c182c6 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -200,6 +200,8 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int 
lsb, int value)
 union kvmppc_one_reg {
u32 wval;
u64 dval;
+   vector128 vval;
+   u64 vsxval[2];
 };
 
 #define one_reg_size(id)   \
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 0ebf03b..cbcc8e0 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -506,6 +506,28 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
case KVM_REG_PPC_DSISR:
get_one_reg(reg->id, val, vcpu->arch.shared->dsisr);
break;
+   case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31:
+   val.dval = vcpu->arch.fpr[reg->id - KVM_REG_PPC_FPR0];
+   break;
+   case KVM_REG_PPC_FPSCR:
+   val.dval = vcpu->arch.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[reg->i

Re: [PATCH 2/2] KVM: PPC: e500: MMU API: fix leak of shared_tlb_pages

2012-09-25 Thread Alexander Graf

On 23.08.2012, at 03:04, Scott Wood wrote:

> This was found by kmemleak.
> 
> Signed-off-by: Scott Wood 

Thanks, applied to kvm-ppc-next.


Alex

> ---
> arch/powerpc/kvm/e500_tlb.c |2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
> index a27d134..641f978 100644
> --- a/arch/powerpc/kvm/e500_tlb.c
> +++ b/arch/powerpc/kvm/e500_tlb.c
> @@ -1134,6 +1134,8 @@ static void free_gtlb(struct kvmppc_vcpu_e500 
> *vcpu_e500)
>   }
> 
>   vcpu_e500->num_shared_tlb_pages = 0;
> +
> + kfree(vcpu_e500->shared_tlb_pages);
>   vcpu_e500->shared_tlb_pages = NULL;
>   } else {
>   kfree(vcpu_e500->gtlb_arch);
> -- 
> 1.7.9.5
> 
> 

--
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


Re: [PATCH 1/2] KVM: PPC: e500: fix allocation size error on g2h_tlb1_map

2012-09-25 Thread Alexander Graf

On 23.08.2012, at 03:04, Scott Wood wrote:

> We were only allocating half the bytes we need, which was made more
> obvious by a recent fix to the memset in  clear_tlb1_bitmap().
> 
> Signed-off-by: Scott Wood 

Thanks, applied to kvm-ppc-next.

Avi, Marcelo, this one should get applied to anything currently -stable as it 
essentially means we could overrun an array that has been allocated too small. 
How do we do this?


Alex

> ---
> arch/powerpc/kvm/e500_tlb.c |2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
> index 43489a8..a27d134 100644
> --- a/arch/powerpc/kvm/e500_tlb.c
> +++ b/arch/powerpc/kvm/e500_tlb.c
> @@ -1385,7 +1385,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 
> *vcpu_e500)
>   if (!vcpu_e500->gtlb_priv[1])
>   goto err;
> 
> - vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(unsigned int) *
> + vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(u64) *
> vcpu_e500->gtlb_params[1].entries,
> GFP_KERNEL);
>   if (!vcpu_e500->g2h_tlb1_map)
> -- 
> 1.7.9.5
> 
> 
> --
> 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

--
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


Re: [PATCH] KVM: PPC: set IN_GUEST_MODE before checking requests

2012-09-25 Thread Alexander Graf

On 23.08.2012, at 03:03, Scott Wood wrote:

> Avoid a race as described in the code comment.
> 
> Also remove a related smp_wmb() from booke's kvmppc_prepare_to_enter().
> I can't see any reason for it, and the book3s_pr version doesn't have it.
> 
> Signed-off-by: Scott Wood 

Does this patch address your comments on the previous pull request?

Applied to kvm-ppc-next.


Alex

> ---
> arch/powerpc/kvm/booke.c   |1 -
> arch/powerpc/kvm/powerpc.c |   14 +-
> 2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index 5f0476a..88711f8 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -674,7 +674,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
> kvm_vcpu *vcpu)
> 
> out:
>   vcpu->mode = OUTSIDE_GUEST_MODE;
> - smp_wmb();
>   return ret;
> }
> 
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 32d217c..3d460a0 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -78,7 +78,16 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
>   break;
>   }
> 
> + vcpu->mode = IN_GUEST_MODE;
> +
> + /*
> +  * Reading vcpu->requests must happen after setting vcpu->mode,
> +  * so we don't miss a request because the requester sees
> +  * OUTSIDE_GUEST_MODE and assumes we'll be checking requests
> +  * before next entering the guest (and thus doesn't IPI).
> +  */
>   smp_mb();
> +
>   if (vcpu->requests) {
>   /* Make sure we process requests preemptable */
>   local_irq_enable();
> @@ -111,11 +120,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
> #endif
> 
>   kvm_guest_enter();
> -
> - /* Going into guest context! Yay! */
> - vcpu->mode = IN_GUEST_MODE;
> - smp_wmb();
> -
>   break;
>   }
> 
> -- 
> 1.7.9.5
> 
> 

--
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