RE: [PATCH 1/6] KVM: PPC: booke: use vcpu reference from thread_struct

2012-10-04 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:58 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 1/6] KVM: PPC: booke: use vcpu reference from 
 thread_struct
 
 
 On 21.08.2012, at 15:51, Bharat Bhushan wrote:
 
  Like other places, use thread_struct to get vcpu reference.
 
 Please remove the definition of SPRN_SPRG_R/WVCPU as well.

Ok

Thanks
-Bharat

 
 
 Alex
 
 
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/kernel/asm-offsets.c   |2 +-
  arch/powerpc/kvm/booke_interrupts.S |6 ++
  2 files changed, 3 insertions(+), 5 deletions(-)
 
  diff --git a/arch/powerpc/kernel/asm-offsets.c
  b/arch/powerpc/kernel/asm-offsets.c
  index 85b05c4..fbb999c 100644
  --- a/arch/powerpc/kernel/asm-offsets.c
  +++ b/arch/powerpc/kernel/asm-offsets.c
  @@ -116,7 +116,7 @@ int main(void)
  #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
  DEFINE(THREAD_KVM_SVCPU, offsetof(struct thread_struct,
  kvm_shadow_vcpu)); #endif -#ifdef CONFIG_KVM_BOOKE_HV
  +#if defined(CONFIG_KVM)  defined(CONFIG_BOOKE)
  DEFINE(THREAD_KVM_VCPU, offsetof(struct thread_struct, kvm_vcpu));
  #endif
 
  diff --git a/arch/powerpc/kvm/booke_interrupts.S
  b/arch/powerpc/kvm/booke_interrupts.S
  index bb46b32..ca16d57 100644
  --- a/arch/powerpc/kvm/booke_interrupts.S
  +++ b/arch/powerpc/kvm/booke_interrupts.S
  @@ -56,7 +56,8 @@
  _GLOBAL(kvmppc_handler_\ivor_nr)
  /* Get pointer to vcpu and record exit number. */
  mtspr   \scratch , r4
  -   mfspr   r4, SPRN_SPRG_RVCPU
  +   mfspr   r4, SPRN_SPRG_THREAD
  +   lwz r4, THREAD_KVM_VCPU(r4)
  stw r3, VCPU_GPR(R3)(r4)
  stw r5, VCPU_GPR(R5)(r4)
  stw r6, VCPU_GPR(R6)(r4)
  @@ -402,9 +403,6 @@ lightweight_exit:
  lwz r8, kvmppc_booke_handlers@l(r8)
  mtspr   SPRN_IVPR, r8
 
  -   /* Save vcpu pointer for the exception handlers. */
  -   mtspr   SPRN_SPRG_WVCPU, r4
  -
  lwz r5, VCPU_SHARED(r4)
 
  /* Can't switch the stack pointer until after IVPR is switched,
  --
  1.7.0.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


RE: [PATCH 4/6] KVM: PPC: debug stub interface parameter defined

2012-10-04 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:09 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 4/6] KVM: PPC: debug stub interface parameter defined
 
 
 On 21.08.2012, at 15:51, Bharat Bhushan wrote:
 
  This patch defines the interface parameter for KVM_SET_GUEST_DEBUG
  ioctl support. Follow up patches will use this for setting up hardware
  breakpoints, watchpoints and software breakpoints.
 
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/include/asm/kvm.h |   33 +
  arch/powerpc/kvm/book3s.c  |6 ++
  arch/powerpc/kvm/booke.c   |6 ++
  arch/powerpc/kvm/powerpc.c |6 --
  4 files changed, 45 insertions(+), 6 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm.h
  b/arch/powerpc/include/asm/kvm.h index 3c14202..61b197e 100644
  --- a/arch/powerpc/include/asm/kvm.h
  +++ b/arch/powerpc/include/asm/kvm.h
  @@ -269,8 +269,41 @@ struct kvm_debug_exit_arch {
 
  /* for KVM_SET_GUEST_DEBUG */
  struct kvm_guest_debug_arch {
  +   struct {
  +   /* H/W breakpoint/watchpoint address */
  +   __u64 addr;
  +   /*
  +* Type denotes h/w breakpoint, read watchpoint, write
  +* watchpoint or watchpoint (both read and write).
  +*/
  +#define KVMPPC_DEBUG_NOTYPE0x0
  +#define KVMPPC_DEBUG_BREAKPOINT(1UL  1)
  +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL  2)
  +#define KVMPPC_DEBUG_WATCH_READ(1UL  3)
  +   __u32 type;
  +   __u32 pad1;
 
 Why the padding?

Not sure why, I will remove this.

 
  +   __u64 pad2;
  +   } bp[16];
 
 Why 16?

I think for now 6 (4 iac + 2 dac) is sufficient for BOOKE. We kept 16 to have 
some room for future and other platforms.

Thanks
-Bharat
 
  };
 
  +/* Debug related defines */
  +/*
  + * kvm_guest_debug-control is a 32 bit field. The lower 16 bits are
  +generic
  + * and upper 16 bits are architecture specific. Architecture specific
  +defines
  + * that ioctl is for setting hardware breakpoint or software breakpoint.
  + */
  +#define KVM_GUESTDBG_USE_SW_BP 0x0001
  +#define KVM_GUESTDBG_USE_HW_BP 0x0002
  +
  +/* When setting software breakpoint, Change the software breakpoint
  + * instruction to special trap instruction and set
  +KVM_GUESTDBG_USE_SW_BP
  + * flag in kvm_guest_debug-control. KVM does keep track of software
  + * breakpoints. So when KVM_GUESTDBG_USE_SW_BP flag is set and
  +special trap
  + * instruction is executed by guest then exit to userspace.
  + * NOTE: A Nice interface can be added to get the special trap instruction.
  + */
  +#define KVMPPC_INST_GUEST_GDB  0x7C00021C  /* ehpriv OC=0 
  */
 
 This definitely has to be passed to user space (which writes that instruction
 into guest phys memory). Other PPC subarchs will use different instructions.
 Just model it as a read-only ONE_REG.
 
 
 Alex
 


--
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 4/6] KVM: PPC: debug stub interface parameter defined

2012-10-04 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:09 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 4/6] KVM: PPC: debug stub interface parameter defined
 
 
 On 21.08.2012, at 15:51, Bharat Bhushan wrote:
 
  This patch defines the interface parameter for KVM_SET_GUEST_DEBUG
  ioctl support. Follow up patches will use this for setting up hardware
  breakpoints, watchpoints and software breakpoints.
 
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/include/asm/kvm.h |   33 +
  arch/powerpc/kvm/book3s.c  |6 ++
  arch/powerpc/kvm/booke.c   |6 ++
  arch/powerpc/kvm/powerpc.c |6 --
  4 files changed, 45 insertions(+), 6 deletions(-)
 
  diff --git a/arch/powerpc/include/asm/kvm.h
  b/arch/powerpc/include/asm/kvm.h index 3c14202..61b197e 100644
  --- a/arch/powerpc/include/asm/kvm.h
  +++ b/arch/powerpc/include/asm/kvm.h
  @@ -269,8 +269,41 @@ struct kvm_debug_exit_arch {
 
  /* for KVM_SET_GUEST_DEBUG */
  struct kvm_guest_debug_arch {
  +   struct {
  +   /* H/W breakpoint/watchpoint address */
  +   __u64 addr;
  +   /*
  +* Type denotes h/w breakpoint, read watchpoint, write
  +* watchpoint or watchpoint (both read and write).
  +*/
  +#define KVMPPC_DEBUG_NOTYPE0x0
  +#define KVMPPC_DEBUG_BREAKPOINT(1UL  1)
  +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL  2)
  +#define KVMPPC_DEBUG_WATCH_READ(1UL  3)
  +   __u32 type;
  +   __u32 pad1;
 
 Why the padding?
 
  +   __u64 pad2;
  +   } bp[16];
 
 Why 16?
 
  };
 
  +/* Debug related defines */
  +/*
  + * kvm_guest_debug-control is a 32 bit field. The lower 16 bits are
  +generic
  + * and upper 16 bits are architecture specific. Architecture specific
  +defines
  + * that ioctl is for setting hardware breakpoint or software breakpoint.
  + */
  +#define KVM_GUESTDBG_USE_SW_BP 0x0001
  +#define KVM_GUESTDBG_USE_HW_BP 0x0002
  +
  +/* When setting software breakpoint, Change the software breakpoint
  + * instruction to special trap instruction and set
  +KVM_GUESTDBG_USE_SW_BP
  + * flag in kvm_guest_debug-control. KVM does keep track of software
  + * breakpoints. So when KVM_GUESTDBG_USE_SW_BP flag is set and
  +special trap
  + * instruction is executed by guest then exit to userspace.
  + * NOTE: A Nice interface can be added to get the special trap instruction.
  + */
  +#define KVMPPC_INST_GUEST_GDB  0x7C00021C  /* ehpriv OC=0 
  */
 
 This definitely has to be passed to user space (which writes that instruction
 into guest phys memory). Other PPC subarchs will use different instructions.
 Just model it as a read-only ONE_REG.

Ok.

Thanks
-Bharat


--
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 6/6] KVM: booke/bookehv: Add debug stub support

2012-10-04 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:50 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
 On 21.08.2012, at 15:52, 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 bharat.bhus...@freescale.com
  ---
  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 linux/kvm.h */
  #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 {
  +   __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;
  };
 
  /* for KVM_SET_GUEST_DEBUG */
  @@ -276,10 +301,6 @@ struct kvm_guest_debug_arch {
   * Type denotes h/w breakpoint, read watchpoint, write
   * watchpoint or watchpoint (both read and write).
   */
  -#define KVMPPC_DEBUG_NOTYPE0x0
  -#define KVMPPC_DEBUG_BREAKPOINT(1UL  1)
  -#define KVMPPC_DEBUG_WATCH_WRITE   (1UL  2)
  -#define KVMPPC_DEBUG_WATCH_READ(1UL  3)
  __u32 type;
  __u32 pad1;
  __u64 pad2;
  diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
  index c7219c1..3ba465a 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -496,7 +496,12 @@ struct kvm_vcpu_arch {
  u32 mmucfg;
  u32 epr;
  u32 crit_save;
  +   /* guest debug registers*/
  struct kvmppc_booke_debug_reg dbg_reg;
  +   /* shadow debug registers */
  +   struct kvmppc_booke_debug_reg shadow_dbg_reg;
  +   /* host debug registers*/
  +   struct kvmppc_booke_debug_reg host_dbg_reg;
  #endif
  gpa_t paddr_accessed;
  gva_t vaddr_accessed;
  diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-
 offsets.c
  index 555448e..6987821 100644
  --- a/arch/powerpc/kernel/asm-offsets.c
  +++ b/arch/powerpc/kernel/asm-offsets.c
  @@ -564,6 +564,32 @@ int main(void)
  DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
  DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
  DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
  +   DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr));
  +   DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
  +   DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
  +   DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg,
  + dbcr0));
  +   DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg,
  + dbcr1));
  +   DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg,
  + dbcr2));
  +#ifdef CONFIG_KVM_E500MC
  +   DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg,
  + dbcr4));
  +#endif
  +   DEFINE(KVMPPC_DBG_IAC1, offsetof(struct kvmppc_booke_debug_reg,
  +iac[0]));
  +   DEFINE(KVMPPC_DBG_IAC2, offsetof(struct kvmppc_booke_debug_reg,
  +  

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

2012-10-04 Thread Alexander Graf

On 04.10.2012, at 13:06, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:50 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan Bharat-R65777
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
 On 21.08.2012, at 15:52, 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 bharat.bhus...@freescale.com
 ---
 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 linux/kvm.h */
 #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 {
 +   __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;
 };
 
 /* for KVM_SET_GUEST_DEBUG */
 @@ -276,10 +301,6 @@ struct kvm_guest_debug_arch {
  * Type denotes h/w breakpoint, read watchpoint, write
  * watchpoint or watchpoint (both read and write).
  */
 -#define KVMPPC_DEBUG_NOTYPE0x0
 -#define KVMPPC_DEBUG_BREAKPOINT(1UL  1)
 -#define KVMPPC_DEBUG_WATCH_WRITE   (1UL  2)
 -#define KVMPPC_DEBUG_WATCH_READ(1UL  3)
 __u32 type;
 __u32 pad1;
 __u64 pad2;
 diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
 index c7219c1..3ba465a 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -496,7 +496,12 @@ struct kvm_vcpu_arch {
 u32 mmucfg;
 u32 epr;
 u32 crit_save;
 +   /* guest debug registers*/
 struct kvmppc_booke_debug_reg dbg_reg;
 +   /* shadow debug registers */
 +   struct kvmppc_booke_debug_reg shadow_dbg_reg;
 +   /* host debug registers*/
 +   struct kvmppc_booke_debug_reg host_dbg_reg;
 #endif
 gpa_t paddr_accessed;
 gva_t vaddr_accessed;
 diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-
 offsets.c
 index 555448e..6987821 100644
 --- a/arch/powerpc/kernel/asm-offsets.c
 +++ b/arch/powerpc/kernel/asm-offsets.c
 @@ -564,6 +564,32 @@ int main(void)
 DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
 DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
 DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
 +   DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr));
 +   DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
 +   DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
 +   DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg,
 + dbcr0));
 +   DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg,
 + dbcr1));
 +   DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg,
 + dbcr2));
 +#ifdef CONFIG_KVM_E500MC
 +   DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg,
 + dbcr4));
 +#endif
 +   DEFINE(KVMPPC_DBG_IAC1, offsetof(struct kvmppc_booke_debug_reg,
 +iac[0]));
 +   DEFINE(KVMPPC_DBG_IAC2, offsetof(struct kvmppc_booke_debug_reg,
 +iac[1]));
 +   

[PULL 00/56] ppc patch queue 2012-10-04

2012-10-04 Thread Alexander Graf
Hi Avi / Marcelo,

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

Changes include:

  * add support for idle hcall on booke
  * icache clear on map
  * mmu notifier support for e500 and book3s_pr
  * revive the 440 support slightly (still not 100% happy)
  * unify booke and book3s_pr entry/exit code a bit
  * add watchdog emulation for booke
  * reset and migratbility fixes for book3s_64_hv
  * rework book3s_64_hv memslot locking
  * small bug fixes

Alex


The following changes since commit 1e08ec4a130e2745d96df169e67c58df98a07311:
  Gleb Natapov (1):
KVM: optimize apic interrupt delivery

are available in the git repository at:

  git://github.com/agraf/linux-2.6.git for-upstream

Alexander Graf (28):
  KVM: PPC: PR: Use generic tracepoint for guest exit
  KVM: PPC: Expose SYNC cap based on mmu notifiers
  KVM: PPC: BookE: Expose remote TLB flushes in debugfs
  KVM: PPC: E500: Fix clear_tlb_refs
  KVM: PPC: BookE: Add check_requests helper function
  KVM: PPC: BookE: Add support for vcpu-mode
  KVM: PPC: E500: Implement MMU notifiers
  KVM: PPC: BookE: Add some more trace points
  KVM: PPC: BookE: No duplicate request != 0 check
  KVM: PPC: Use same kvmppc_prepare_to_enter code for booke and book3s_pr
  KVM: PPC: Book3s: PR: Add (dumb) MMU Notifier support
  KVM: PPC: BookE: Drop redundant vcpu-mode set
  KVM: PPC: Book3S: PR: Only do resched check once per exit
  KVM: PPC: Exit guest context while handling exit
  KVM: PPC: Book3S: PR: Indicate we're out of guest mode
  KVM: PPC: Consistentify vcpu exit path
  KVM: PPC: Book3S: PR: Rework irq disabling
  KVM: PPC: Move kvm_guest_enter call into generic code
  KVM: PPC: Ignore EXITING_GUEST_MODE mode
  KVM: PPC: Add return value in prepare_to_enter
  KVM: PPC: Add return value to core_check_requests
  KVM: PPC: 44x: Initialize PVR
  KVM: PPC: BookE: Add MCSR SPR support
  KVM: PPC: Use symbols for exit trace
  KVM: PPC: E500: Remove E500_TLB_DIRTY flag
  KVM: PPC: 440: Implement mtdcrx
  KVM: PPC: 440: Implement mfdcrx
  KVM: PPC: BookE: Support FPU on non-hv systems

Bharat Bhushan (3):
  KVM: PPC: booke: Add watchdog emulation
  booke: Added ONE_REG interface for IAC/DAC debug registers
  Document IACx/DACx registers access using ONE_REG API

Julia Lawall (1):
  arch/powerpc/kvm/e500_tlb.c: fix error return code

Liu Yu-B13201 (3):
  KVM: PPC: Add support for ePAPR idle hcall in host kernel
  KVM: PPC: ev_idle hcall support for e500 guests
  PPC: Don't use hardcoded opcode for ePAPR hcall invocation

Mihai Caraman (1):
  KVM: PPC: bookehv: Allow duplicate calls of DO_KVM macro

Paul Mackerras (11):
  KVM: PPC: Quieten message about allocating linear regions
  KVM: PPC: Book3S HV: Take the SRCU read lock before looking up memslots
  KVM: PPC: Move kvm-arch.slot_phys into memslot.arch
  KVM: PPC: Book3S HV: Handle memory slot deletion and modification 
correctly
  KVM: Move some PPC ioctl definitions to the correct place
  KVM: PPC: Book3S HV: Fix updates of vcpu-cpu
  KVM: PPC: Book3S HV: Remove bogus update of physical thread IDs
  KVM: PPC: Book3S HV: Fix calculation of guest phys address for MMIO 
emulation
  KVM: PPC: Book3S: Get/set guest SPRs using the GET/SET_ONE_REG interface
  KVM: PPC: Book3S: Get/set guest FP regs using the GET/SET_ONE_REG 
interface
  KVM: PPC: Book3S HV: Provide a way for userspace to get/set per-vCPU areas

Scott Wood (5):
  powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls
  powerpc/epapr: export epapr_hypercall_start
  KVM: PPC: e500: fix allocation size error on g2h_tlb1_map
  KVM: PPC: e500: MMU API: fix leak of shared_tlb_pages
  KVM: PPC: set IN_GUEST_MODE before checking requests

Stuart Yoder (4):
  PPC: epapr: create define for return code value of success
  KVM: PPC: use definitions in epapr header for hcalls
  KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500
  PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

 Documentation/virtual/kvm/api.txt   |   49 -
 arch/powerpc/include/asm/Kbuild |1 +
 arch/powerpc/include/asm/epapr_hcalls.h |   36 ++--
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 ++--
 arch/powerpc/include/asm/kvm.h  |   59 +
 arch/powerpc/include/asm/kvm_book3s.h   |2 +-
 arch/powerpc/include/asm/kvm_booke_hv_asm.h |4 +-
 arch/powerpc/include/asm/kvm_host.h |   38 +++-
 arch/powerpc/include/asm/kvm_para.h |   21 +-
 arch/powerpc/include/asm/kvm_ppc.h  |   64 +-
 arch/powerpc/include/asm/reg_booke.h|7 +
 arch/powerpc/kernel/epapr_hcalls.S  |   28 +++
 arch/powerpc/kernel/epapr_paravirt.c|   11 +-
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kernel/ppc_ksyms.c |5 +
 arch/powerpc/kvm/44x.c 

[PATCH 01/56] PPC: epapr: create define for return code value of success

2012-10-04 Thread Alexander Graf
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/epapr_hcalls.h |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index bf2c06c..c0c7adc 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -88,7 +88,8 @@
 #define _EV_HCALL_TOKEN(id, num) (((id)  16) | (num))
 #define EV_HCALL_TOKEN(hcall_num) _EV_HCALL_TOKEN(EV_EPAPR_VENDOR_ID, 
hcall_num)
 
-/* epapr error codes */
+/* epapr return codes */
+#define EV_SUCCESS 0
 #define EV_EPERM   1   /* Operation not permitted */
 #define EV_ENOENT  2   /*  Entry Not Found */
 #define EV_EIO 3   /* I/O error occured */
-- 
1.6.0.2

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


[PATCH 03/56] KVM: PPC: add pvinfo for hcall opcodes on e500mc/e5500

2012-10-04 Thread Alexander Graf
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[stuart: factored this out from idle hcall support in host patch]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/powerpc.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0368a93..a478e66 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -751,9 +751,16 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct 
vm_fault *vmf)
 
 static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo *pvinfo)
 {
+   u32 inst_nop = 0x6000;
+#ifdef CONFIG_KVM_BOOKE_HV
+   u32 inst_sc1 = 0x4422;
+   pvinfo-hcall[0] = inst_sc1;
+   pvinfo-hcall[1] = inst_nop;
+   pvinfo-hcall[2] = inst_nop;
+   pvinfo-hcall[3] = inst_nop;
+#else
u32 inst_lis = 0x3c00;
u32 inst_ori = 0x6000;
-   u32 inst_nop = 0x6000;
u32 inst_sc = 0x4402;
u32 inst_imm_mask = 0x;
 
@@ -770,6 +777,7 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[1] = inst_ori | (KVM_SC_MAGIC_R0  inst_imm_mask);
pvinfo-hcall[2] = inst_sc;
pvinfo-hcall[3] = inst_nop;
+#endif
 
return 0;
 }
-- 
1.6.0.2

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


[PATCH 02/56] KVM: PPC: use definitions in epapr header for hcalls

2012-10-04 Thread Alexander Graf
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_para.h |   21 +++--
 arch/powerpc/kernel/kvm.c   |2 +-
 arch/powerpc/kvm/powerpc.c  |   10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_para.h 
b/arch/powerpc/include/asm/kvm_para.h
index c18916b..a168ce3 100644
--- a/arch/powerpc/include/asm/kvm_para.h
+++ b/arch/powerpc/include/asm/kvm_para.h
@@ -75,9 +75,10 @@ struct kvm_vcpu_arch_shared {
 };
 
 #define KVM_SC_MAGIC_R00x4b564d21 /* KVM! */
-#define HC_VENDOR_KVM  (42  16)
-#define HC_EV_SUCCESS  0
-#define HC_EV_UNIMPLEMENTED12
+
+#define KVM_HCALL_TOKEN(num) _EV_HCALL_TOKEN(EV_KVM_VENDOR_ID, num)
+
+#include asm/epapr_hcalls.h
 
 #define KVM_FEATURE_MAGIC_PAGE 1
 
@@ -121,7 +122,7 @@ static unsigned long kvm_hypercall(unsigned long *in,
   unsigned long *out,
   unsigned long nr)
 {
-   return HC_EV_UNIMPLEMENTED;
+   return EV_UNIMPLEMENTED;
 }
 
 #endif
@@ -132,7 +133,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, 
unsigned long *r2)
unsigned long out[8];
unsigned long r;
 
-   r = kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   r = kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
*r2 = out[0];
 
return r;
@@ -143,7 +144,7 @@ static inline long kvm_hypercall0(unsigned int nr)
unsigned long in[8];
unsigned long out[8];
 
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
@@ -152,7 +153,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned 
long p1)
unsigned long out[8];
 
in[0] = p1;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -163,7 +164,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned 
long p1,
 
in[0] = p1;
in[1] = p2;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -175,7 +176,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned 
long p1,
in[0] = p1;
in[1] = p2;
in[2] = p3;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -189,7 +190,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned 
long p1,
in[1] = p2;
in[2] = p3;
in[3] = p4;
-   return kvm_hypercall(in, out, nr | HC_VENDOR_KVM);
+   return kvm_hypercall(in, out, KVM_HCALL_TOKEN(nr));
 }
 
 
diff --git a/arch/powerpc/kernel/kvm.c b/arch/powerpc/kernel/kvm.c
index 867db1d..a61b133 100644
--- a/arch/powerpc/kernel/kvm.c
+++ b/arch/powerpc/kernel/kvm.c
@@ -419,7 +419,7 @@ static void kvm_map_magic_page(void *data)
in[0] = KVM_MAGIC_PAGE;
in[1] = KVM_MAGIC_PAGE;
 
-   kvm_hypercall(in, out, HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE);
+   kvm_hypercall(in, out, KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE));
 
*features = out[0];
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 4d213b8..0368a93 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -67,18 +67,18 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
}
 
switch (nr) {
-   case HC_VENDOR_KVM | KVM_HC_PPC_MAP_MAGIC_PAGE:
+   case KVM_HCALL_TOKEN(KVM_HC_PPC_MAP_MAGIC_PAGE):
{
vcpu-arch.magic_page_pa = param1;
vcpu-arch.magic_page_ea = param2;
 
r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
-   r = HC_EV_SUCCESS;
+   r = EV_SUCCESS;
break;
}
-   case HC_VENDOR_KVM | KVM_HC_FEATURES:
-   r = HC_EV_SUCCESS;
+   case KVM_HCALL_TOKEN(KVM_HC_FEATURES):
+   r = EV_SUCCESS;
 #if defined(CONFIG_PPC_BOOK3S) || defined(CONFIG_KVM_E500V2)
/* XXX Missing magic page on 44x */
r2 |= (1  KVM_FEATURE_MAGIC_PAGE);
@@ -87,7 +87,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
/* Second return value is in r4 */
break;
default:
-   r = HC_EV_UNIMPLEMENTED;
+   r = EV_UNIMPLEMENTED;
break;
}
 
-- 
1.6.0.2

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

[PATCH 06/56] PPC: select EPAPR_PARAVIRT for all users of epapr hcalls

2012-10-04 Thread Alexander Graf
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/platforms/Kconfig |1 +
 drivers/tty/Kconfig|1 +
 drivers/virt/Kconfig   |1 +
 3 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index e7a896a..48a920d 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -90,6 +90,7 @@ config MPIC
 config PPC_EPAPR_HV_PIC
bool
default n
+   select EPAPR_PARAVIRT
 
 config MPIC_WEIRD
bool
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 830cd62..aa99cd2 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -358,6 +358,7 @@ config TRACE_SINK
 config PPC_EPAPR_HV_BYTECHAN
tristate ePAPR hypervisor byte channel driver
depends on PPC
+   select EPAPR_PARAVIRT
help
  This driver creates /dev entries for each ePAPR hypervisor byte
  channel, thereby allowing applications to communicate with byte
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 2dcdbc9..99ebdde 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -15,6 +15,7 @@ if VIRT_DRIVERS
 config FSL_HV_MANAGER
tristate Freescale hypervisor management driver
depends on FSL_SOC
+   select EPAPR_PARAVIRT
help
   The Freescale hypervisor management driver provides several services
  to drivers and applications related to the Freescale hypervisor:
-- 
1.6.0.2

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


[PATCH 04/56] KVM: PPC: Add support for ePAPR idle hcall in host kernel

2012-10-04 Thread Alexander Graf
From: Liu Yu-B13201 yu@freescale.com

And add a new flag definition in kvm_ppc_pvinfo to indicate
whether the host supports the EV_IDLE hcall.

Signed-off-by: Liu Yu yu@freescale.com
[stuart.yo...@freescale.com: cleanup,fixes for conditions allowing idle]
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
[agraf: fix typo]
Signed-off-by: Alexander Graf ag...@suse.de
---
 Documentation/virtual/kvm/api.txt |7 +--
 arch/powerpc/include/asm/Kbuild   |1 +
 arch/powerpc/kvm/powerpc.c|   10 --
 include/linux/kvm.h   |2 ++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 36befa7..11b5d31 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1194,12 +1194,15 @@ struct kvm_ppc_pvinfo {
 This ioctl fetches PV specific information that need to be passed to the guest
 using the device tree or other means from vm context.
 
-For now the only implemented piece of information distributed here is an array
-of 4 instructions that make up a hypercall.
+The hcall array defines 4 instructions that make up a hypercall.
 
 If any additional field gets added to this structure later on, a bit for that
 additional piece of information will be set in the flags bitmap.
 
+The flags bitmap is defined as:
+
+   /* the host supports the ePAPR idle hcall
+   #define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
 
 4.48 KVM_ASSIGN_PCI_DEVICE
 
diff --git a/arch/powerpc/include/asm/Kbuild b/arch/powerpc/include/asm/Kbuild
index 7e313f1..13d6b7b 100644
--- a/arch/powerpc/include/asm/Kbuild
+++ b/arch/powerpc/include/asm/Kbuild
@@ -34,5 +34,6 @@ header-y += termios.h
 header-y += types.h
 header-y += ucontext.h
 header-y += unistd.h
+header-y += epapr_hcalls.h
 
 generic-y += rwsem.h
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index a478e66..dbf56e1 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -38,8 +38,7 @@
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-   return !(v-arch.shared-msr  MSR_WE) ||
-  !!(v-arch.pending_exceptions) ||
+   return !!(v-arch.pending_exceptions) ||
   v-requests;
 }
 
@@ -86,6 +85,11 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
 
/* Second return value is in r4 */
break;
+   case EV_HCALL_TOKEN(EV_IDLE):
+   r = EV_SUCCESS;
+   kvm_vcpu_block(vcpu);
+   clear_bit(KVM_REQ_UNHALT, vcpu-requests);
+   break;
default:
r = EV_UNIMPLEMENTED;
break;
@@ -779,6 +783,8 @@ static int kvm_vm_ioctl_get_pvinfo(struct kvm_ppc_pvinfo 
*pvinfo)
pvinfo-hcall[3] = inst_nop;
 #endif
 
+   pvinfo-flags = KVM_PPC_PVINFO_FLAGS_EV_IDLE;
+
return 0;
 }
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index d808694..6be840a 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -477,6 +477,8 @@ struct kvm_ppc_smmu_info {
struct kvm_ppc_one_seg_page_size sps[KVM_PPC_PAGE_SIZES_MAX_SZ];
 };
 
+#define KVM_PPC_PVINFO_FLAGS_EV_IDLE   (10)
+
 #define KVMIO 0xAE
 
 /* machine type bits, to be used as argument to KVM_CREATE_VM */
-- 
1.6.0.2

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


[PATCH 07/56] powerpc/fsl-soc: use CONFIG_EPAPR_PARAVIRT for hcalls

2012-10-04 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/sysdev/fsl_msi.c |9 +++--
 arch/powerpc/sysdev/fsl_soc.c |2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index 6e097de..7e2b2f2 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -236,7 +236,6 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
u32 intr_index;
u32 have_shift = 0;
struct fsl_msi_cascade_data *cascade_data;
-   unsigned int ret;
 
cascade_data = irq_get_handler_data(irq);
msi_data = cascade_data-msi_data;
@@ -268,7 +267,9 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
case FSL_PIC_IP_IPIC:
msir_value = fsl_msi_read(msi_data-msi_regs, msir_index * 0x4);
break;
-   case FSL_PIC_IP_VMPIC:
+#ifdef CONFIG_EPAPR_PARAVIRT
+   case FSL_PIC_IP_VMPIC: {
+   unsigned int ret;
ret = fh_vmpic_get_msir(virq_to_hw(irq), msir_value);
if (ret) {
pr_err(fsl-msi: fh_vmpic_get_msir() failed for 
@@ -277,6 +278,8 @@ static void fsl_msi_cascade(unsigned int irq, struct 
irq_desc *desc)
}
break;
}
+#endif
+   }
 
while (msir_value) {
intr_index = ffs(msir_value) - 1;
@@ -508,10 +511,12 @@ static const struct of_device_id fsl_of_msi_ids[] = {
.compatible = fsl,ipic-msi,
.data = (void *)ipic_msi_feature,
},
+#ifdef CONFIG_EPAPR_PARAVIRT
{
.compatible = fsl,vmpic-msi,
.data = (void *)vmpic_msi_feature,
},
+#endif
{}
 };
 
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index c449dbd..97118dc 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -253,6 +253,7 @@ struct platform_diu_data_ops diu_ops;
 EXPORT_SYMBOL(diu_ops);
 #endif
 
+#ifdef CONFIG_EPAPR_PARAVIRT
 /*
  * Restart the current partition
  *
@@ -278,3 +279,4 @@ void fsl_hv_halt(void)
pr_info(hv exit\n);
fh_partition_stop(-1);
 }
+#endif
-- 
1.6.0.2

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


[PATCH 08/56] PPC: Don't use hardcoded opcode for ePAPR hcall invocation

2012-10-04 Thread Alexander Graf
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/epapr_hcalls.h |   22 +-
 arch/powerpc/include/asm/fsl_hcalls.h   |   36 +++---
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index 833ce2c..b8d9445 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -195,7 +195,7 @@ static inline unsigned int ev_int_set_config(unsigned int 
interrupt,
r5  = priority;
r6  = destination;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4), +r (r5), +r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -224,7 +224,7 @@ static inline unsigned int ev_int_get_config(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_CONFIG);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5), =r (r6)
: : EV_HCALL_CLOBBERS4
);
@@ -254,7 +254,7 @@ static inline unsigned int ev_int_set_mask(unsigned int 
interrupt,
r3 = interrupt;
r4 = mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -279,7 +279,7 @@ static inline unsigned int ev_int_get_mask(unsigned int 
interrupt,
r11 = EV_HCALL_TOKEN(EV_INT_GET_MASK);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -307,7 +307,7 @@ static inline unsigned int ev_int_eoi(unsigned int 
interrupt)
r11 = EV_HCALL_TOKEN(EV_INT_EOI);
r3 = interrupt;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -346,7 +346,7 @@ static inline unsigned int ev_byte_channel_send(unsigned 
int handle,
r7 = be32_to_cpu(p[2]);
r8 = be32_to_cpu(p[3]);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3),
  +r (r4), +r (r5), +r (r6), +r (r7), +r (r8)
: : EV_HCALL_CLOBBERS6
@@ -385,7 +385,7 @@ static inline unsigned int ev_byte_channel_receive(unsigned 
int handle,
r3 = handle;
r4 = *count;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), +r (r4),
  =r (r5), =r (r6), =r (r7), =r (r8)
: : EV_HCALL_CLOBBERS6
@@ -423,7 +423,7 @@ static inline unsigned int ev_byte_channel_poll(unsigned 
int handle,
r11 = EV_HCALL_TOKEN(EV_BYTE_CHANNEL_POLL);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4), =r (r5)
: : EV_HCALL_CLOBBERS3
);
@@ -456,7 +456,7 @@ static inline unsigned int ev_int_iack(unsigned int handle,
r11 = EV_HCALL_TOKEN(EV_INT_IACK);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3), =r (r4)
: : EV_HCALL_CLOBBERS2
);
@@ -480,7 +480,7 @@ static inline unsigned int ev_doorbell_send(unsigned int 
handle)
r11 = EV_HCALL_TOKEN(EV_DOORBELL_SEND);
r3 = handle;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -500,7 +500,7 @@ static inline unsigned int ev_idle(void)
 
r11 = EV_HCALL_TOKEN(EV_IDLE);
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), =r (r3)
: : EV_HCALL_CLOBBERS1
);
diff --git a/arch/powerpc/include/asm/fsl_hcalls.h 
b/arch/powerpc/include/asm/fsl_hcalls.h
index 922d9b5..3abb583 100644
--- a/arch/powerpc/include/asm/fsl_hcalls.h
+++ b/arch/powerpc/include/asm/fsl_hcalls.h
@@ -96,7 +96,7 @@ static inline unsigned int fh_send_nmi(unsigned int vcpu_mask)
r11 = FH_HCALL_TOKEN(FH_SEND_NMI);
r3 = vcpu_mask;
 
-   __asm__ __volatile__ (sc 1
+   asm volatile(blepapr_hypercall_start
: +r (r11), +r (r3)
: : EV_HCALL_CLOBBERS1
);
@@ -151,7 +151,7 @@ static inline unsigned int fh_partition_get_dtprop(int 
handle,
r9 = (uint32_t)propvalue_addr;
  

[PATCH 10/56] KVM: PPC: Expose SYNC cap based on mmu notifiers

2012-10-04 Thread Alexander Graf
Semantically, the SYNC cap means that we have mmu notifiers available.
Express this in our #ifdef'ery around the feature, so that we can be sure
we don't miss out on ppc targets when they get their implementation.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/powerpc.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index dbf56e1..45fe433 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -264,10 +264,16 @@ int kvm_dev_ioctl_check_extension(long ext)
if (cpu_has_feature(CPU_FTR_ARCH_201))
r = 2;
break;
+#endif
case KVM_CAP_SYNC_MMU:
+#ifdef CONFIG_KVM_BOOK3S_64_HV
r = cpu_has_feature(CPU_FTR_ARCH_206) ? 1 : 0;
-   break;
+#elif defined(KVM_ARCH_WANT_MMU_NOTIFIER)
+   r = 1;
+#else
+   r = 0;
 #endif
+   break;
case KVM_CAP_NR_VCPUS:
/*
 * Recommending a number of CPUs is somewhat arbitrary; we
-- 
1.6.0.2

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


[PATCH 05/56] KVM: PPC: ev_idle hcall support for e500 guests

2012-10-04 Thread Alexander Graf
From: Liu Yu-B13201 yu@freescale.com

Signed-off-by: Liu Yu yu@freescale.com
[varun: 64-bit changes]
Signed-off-by: Varun Sethi varun.se...@freescale.com
Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/epapr_hcalls.h |   11 ++-
 arch/powerpc/kernel/epapr_hcalls.S  |   28 
 arch/powerpc/kernel/epapr_paravirt.c|   11 ++-
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/include/asm/epapr_hcalls.h 
b/arch/powerpc/include/asm/epapr_hcalls.h
index c0c7adc..833ce2c 100644
--- a/arch/powerpc/include/asm/epapr_hcalls.h
+++ b/arch/powerpc/include/asm/epapr_hcalls.h
@@ -50,10 +50,6 @@
 #ifndef _EPAPR_HCALLS_H
 #define _EPAPR_HCALLS_H
 
-#include linux/types.h
-#include linux/errno.h
-#include asm/byteorder.h
-
 #define EV_BYTE_CHANNEL_SEND   1
 #define EV_BYTE_CHANNEL_RECEIVE2
 #define EV_BYTE_CHANNEL_POLL   3
@@ -109,6 +105,11 @@
 #define EV_UNIMPLEMENTED   12  /* Unimplemented hypercall */
 #define EV_BUFFER_OVERFLOW 13  /* Caller-supplied buffer too small */
 
+#ifndef __ASSEMBLY__
+#include linux/types.h
+#include linux/errno.h
+#include asm/byteorder.h
+
 /*
  * Hypercall register clobber list
  *
@@ -506,5 +507,5 @@ static inline unsigned int ev_idle(void)
 
return r3;
 }
-
+#endif /* !__ASSEMBLY__ */
 #endif
diff --git a/arch/powerpc/kernel/epapr_hcalls.S 
b/arch/powerpc/kernel/epapr_hcalls.S
index 697b390..62c0dc2 100644
--- a/arch/powerpc/kernel/epapr_hcalls.S
+++ b/arch/powerpc/kernel/epapr_hcalls.S
@@ -8,13 +8,41 @@
  */
 
 #include linux/threads.h
+#include asm/epapr_hcalls.h
 #include asm/reg.h
 #include asm/page.h
 #include asm/cputable.h
 #include asm/thread_info.h
 #include asm/ppc_asm.h
+#include asm/asm-compat.h
 #include asm/asm-offsets.h
 
+/* epapr_ev_idle() was derived from e500_idle() */
+_GLOBAL(epapr_ev_idle)
+   CURRENT_THREAD_INFO(r3, r1)
+   PPC_LL  r4, TI_LOCAL_FLAGS(r3)  /* set napping bit */
+   ori r4, r4,_TLF_NAPPING /* so when we take an exception */
+   PPC_STL r4, TI_LOCAL_FLAGS(r3)  /* it will return to our caller */
+
+   wrteei  1
+
+idle_loop:
+   LOAD_REG_IMMEDIATE(r11, EV_HCALL_TOKEN(EV_IDLE))
+
+.global epapr_ev_idle_start
+epapr_ev_idle_start:
+   li  r3, -1
+   nop
+   nop
+   nop
+
+   /*
+* Guard against spurious wakeups from a hypervisor --
+* only interrupt will cause us to return to LR due to
+* _TLF_NAPPING.
+*/
+   b   idle_loop
+
 /* Hypercall entry point. Will be patched with device tree instructions. */
 .global epapr_hypercall_start
 epapr_hypercall_start:
diff --git a/arch/powerpc/kernel/epapr_paravirt.c 
b/arch/powerpc/kernel/epapr_paravirt.c
index 028aeae..f3eab85 100644
--- a/arch/powerpc/kernel/epapr_paravirt.c
+++ b/arch/powerpc/kernel/epapr_paravirt.c
@@ -21,6 +21,10 @@
 #include asm/epapr_hcalls.h
 #include asm/cacheflush.h
 #include asm/code-patching.h
+#include asm/machdep.h
+
+extern void epapr_ev_idle(void);
+extern u32 epapr_ev_idle_start[];
 
 bool epapr_paravirt_enabled;
 
@@ -41,8 +45,13 @@ static int __init epapr_paravirt_init(void)
if (len % 4 || len  (4 * 4))
return -ENODEV;
 
-   for (i = 0; i  (len / 4); i++)
+   for (i = 0; i  (len / 4); i++) {
patch_instruction(epapr_hypercall_start + i, insts[i]);
+   patch_instruction(epapr_ev_idle_start + i, insts[i]);
+   }
+
+   if (of_get_property(hyper_node, has-idle, NULL))
+   ppc_md.power_save = epapr_ev_idle;
 
epapr_paravirt_enabled = true;
 
-- 
1.6.0.2

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


[PATCH 11/56] KVM: PPC: BookE: Expose remote TLB flushes in debugfs

2012-10-04 Thread Alexander Graf
We're already counting remote TLB flushes in a variable, but don't export
it to user space yet. Do so, so we know what's going on.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 7ce2ed0..1d4ce9a 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -63,6 +63,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
{ halt_wakeup, VCPU_STAT(halt_wakeup) },
{ doorbell, VCPU_STAT(dbell_exits) },
{ guest doorbell, VCPU_STAT(gdbell_exits) },
+   { remote_tlb_flush, VM_STAT(remote_tlb_flush) },
{ NULL }
 };
 
-- 
1.6.0.2

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


[PATCH 13/56] KVM: PPC: Quieten message about allocating linear regions

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

This is printed once for every RMA or HPT region that get
preallocated.  If one preallocates hundreds of such regions
(in order to run hundreds of KVM guests), that gets rather
painful, so make it a bit quieter.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv_builtin.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c 
b/arch/powerpc/kvm/book3s_hv_builtin.c
index fb4eac2..ec0a9e5 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -157,8 +157,8 @@ static void __init kvm_linear_init_one(ulong size, int 
count, int type)
linear_info = alloc_bootmem(count * sizeof(struct kvmppc_linear_info));
for (i = 0; i  count; ++i) {
linear = alloc_bootmem_align(size, size);
-   pr_info(Allocated KVM %s at %p (%ld MB)\n, typestr, linear,
-   size  20);
+   pr_debug(Allocated KVM %s at %p (%ld MB)\n, typestr, linear,
+size  20);
linear_info[i].base_virt = linear;
linear_info[i].base_pfn = __pa(linear)  PAGE_SHIFT;
linear_info[i].npages = npages;
-- 
1.6.0.2

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


[PATCH 12/56] KVM: PPC: E500: Fix clear_tlb_refs

2012-10-04 Thread Alexander Graf
Our mapping code assumes that TLB0 entries are always mapped. However, after
calling clear_tlb_refs() this is no longer the case.

Map them dynamically if we find an entry unmapped in TLB0.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500_tlb.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index ff38b66..b56b6e1 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1039,8 +1039,12 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, 
gpa_t gpaddr,
sesel = 0; /* unused */
priv = vcpu_e500-gtlb_priv[tlbsel][esel];
 
-   kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,
-   priv-ref, eaddr, stlbe);
+   /* Only triggers after clear_tlb_refs */
+   if (unlikely(!(priv-ref.flags  E500_TLB_VALID)))
+   kvmppc_e500_tlb0_map(vcpu_e500, esel, stlbe);
+   else
+   kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,
+   priv-ref, eaddr, stlbe);
break;
 
case 1: {
-- 
1.6.0.2

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


[PATCH 14/56] powerpc/epapr: export epapr_hypercall_start

2012-10-04 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This fixes breakage introduced by the following commit:

  commit 6d2d82627f4f1e96a33664ace494fa363e0495cb
  Author: Liu Yu-B13201 yu@freescale.com
  Date:   Tue Jul 3 05:48:56 2012 +

PPC: Don't use hardcoded opcode for ePAPR hcall invocation

when a driver that uses ePAPR hypercalls is built as a module.

Reported-by: Geert Uytterhoeven ge...@linux-m68k.org
Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kernel/ppc_ksyms.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 3e40315..e597dde 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -43,6 +43,7 @@
 #include asm/dcr.h
 #include asm/ftrace.h
 #include asm/switch_to.h
+#include asm/epapr_hcalls.h
 
 #ifdef CONFIG_PPC32
 extern void transfer_to_handler(void);
@@ -192,3 +193,7 @@ EXPORT_SYMBOL(__arch_hweight64);
 #ifdef CONFIG_PPC_BOOK3S_64
 EXPORT_SYMBOL_GPL(mmu_psize_defs);
 #endif
+
+#ifdef CONFIG_EPAPR_PARAVIRT
+EXPORT_SYMBOL(epapr_hypercall_start);
+#endif
-- 
1.6.0.2

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


[PATCH 16/56] KVM: PPC: BookE: Add support for vcpu-mode

2012-10-04 Thread Alexander Graf
Generic KVM code might want to know whether we are inside guest context
or outside. It also wants to be able to push us out of guest context.

Add support to the BookE code for the generic vcpu-mode field that describes
the above states.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index bcf87fe..70a86c0 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -501,6 +501,15 @@ static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
continue;
}
 
+   if (vcpu-mode == EXITING_GUEST_MODE) {
+   r = 1;
+   break;
+   }
+
+   /* Going into guest context! Yay! */
+   vcpu-mode = IN_GUEST_MODE;
+   smp_wmb();
+
break;
}
 
@@ -572,6 +581,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
kvm_guest_exit();
 
 out:
+   vcpu-mode = OUTSIDE_GUEST_MODE;
+   smp_wmb();
local_irq_enable();
return ret;
 }
-- 
1.6.0.2

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


[PATCH 15/56] KVM: PPC: BookE: Add check_requests helper function

2012-10-04 Thread Alexander Graf
We need a central place to check for pending requests in. Add one that
only does the timer check we already do in a different place.

Later, this central function can be extended by more checks.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   24 +---
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 1d4ce9a..bcf87fe 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -419,13 +419,6 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu 
*vcpu)
unsigned long *pending = vcpu-arch.pending_exceptions;
unsigned int priority;
 
-   if (vcpu-requests) {
-   if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
-   smp_mb();
-   update_timer_ints(vcpu);
-   }
-   }
-
priority = __ffs(*pending);
while (priority  BOOKE_IRQPRIO_MAX) {
if (kvmppc_booke_irqprio_deliver(vcpu, priority))
@@ -461,6 +454,14 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
return r;
 }
 
+static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
+{
+   if (vcpu-requests) {
+   if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
+   update_timer_ints(vcpu);
+   }
+}
+
 /*
  * Common checks before entering the guest world.  Call with interrupts
  * disabled.
@@ -485,6 +486,15 @@ static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
break;
}
 
+   smp_mb();
+   if (vcpu-requests) {
+   /* Make sure we process requests preemptable */
+   local_irq_enable();
+   kvmppc_check_requests(vcpu);
+   local_irq_disable();
+   continue;
+   }
+
if (kvmppc_core_prepare_to_enter(vcpu)) {
/* interrupts got enabled in between, so we
   are back at square 1 */
-- 
1.6.0.2

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


[PATCH 19/56] KVM: PPC: BookE: No duplicate request != 0 check

2012-10-04 Thread Alexander Graf
We only call kvmppc_check_requests() when vcpu-requests != 0, so drop
the redundant check in the function itself

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

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 00bcc57..683cbd6 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -457,16 +457,14 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 
 static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
 {
-   if (vcpu-requests) {
-   trace_kvm_check_requests(vcpu);
+   trace_kvm_check_requests(vcpu);
 
-   if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
-   update_timer_ints(vcpu);
+   if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
+   update_timer_ints(vcpu);
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
-   if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
-   kvmppc_core_flush_tlb(vcpu);
+   if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
+   kvmppc_core_flush_tlb(vcpu);
 #endif
-   }
 }
 
 /*
-- 
1.6.0.2

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


[PATCH 18/56] KVM: PPC: BookE: Add some more trace points

2012-10-04 Thread Alexander Graf
Without trace points, debugging what exactly is going on inside guest
code can be very tricky. Add a few more trace points at places that
hopefully tell us more when things go wrong.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c|3 ++
 arch/powerpc/kvm/e500_tlb.c |3 ++
 arch/powerpc/kvm/trace.h|   71 +++
 3 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 52f6cbb..00bcc57 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -143,6 +143,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
 static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
unsigned int priority)
 {
+   trace_kvm_booke_queue_irqprio(vcpu, priority);
set_bit(priority, vcpu-arch.pending_exceptions);
 }
 
@@ -457,6 +458,8 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
 {
if (vcpu-requests) {
+   trace_kvm_check_requests(vcpu);
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
update_timer_ints(vcpu);
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index de8ea29..1af6fab 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -312,6 +312,7 @@ static inline void kvmppc_e500_ref_setup(struct tlbe_ref 
*ref,
 static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref)
 {
if (ref-flags  E500_TLB_VALID) {
+   trace_kvm_booke206_ref_release(ref-pfn, ref-flags);
ref-flags = 0;
}
 }
@@ -1075,6 +1076,8 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, 
gpa_t gpaddr,
 
 int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
 {
+   trace_kvm_unmap_hva(hva);
+
/*
 * Flush all shadow tlb entries everywhere. This is slow, but
 * we are 100% sure that we catch the to be unmapped page
diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
index 9fab6ed..cb2780a 100644
--- a/arch/powerpc/kvm/trace.h
+++ b/arch/powerpc/kvm/trace.h
@@ -82,6 +82,21 @@ TRACE_EVENT(kvm_exit,
)
 );
 
+TRACE_EVENT(kvm_unmap_hva,
+   TP_PROTO(unsigned long hva),
+   TP_ARGS(hva),
+
+   TP_STRUCT__entry(
+   __field(unsigned long,  hva )
+   ),
+
+   TP_fast_assign(
+   __entry-hva= hva;
+   ),
+
+   TP_printk(unmap hva 0x%lx\n, __entry-hva)
+);
+
 TRACE_EVENT(kvm_stlb_inval,
TP_PROTO(unsigned int stlb_index),
TP_ARGS(stlb_index),
@@ -149,6 +164,24 @@ TRACE_EVENT(kvm_gtlb_write,
__entry-word1, __entry-word2)
 );
 
+TRACE_EVENT(kvm_check_requests,
+   TP_PROTO(struct kvm_vcpu *vcpu),
+   TP_ARGS(vcpu),
+
+   TP_STRUCT__entry(
+   __field(__u32,  cpu_nr  )
+   __field(__u32,  requests)
+   ),
+
+   TP_fast_assign(
+   __entry-cpu_nr = vcpu-vcpu_id;
+   __entry-requests   = vcpu-requests;
+   ),
+
+   TP_printk(vcpu=%x requests=%x,
+   __entry-cpu_nr, __entry-requests)
+);
+
 
 /*
  * Book3S trace points   *
@@ -418,6 +451,44 @@ TRACE_EVENT(kvm_booke206_gtlb_write,
__entry-mas2, __entry-mas7_3)
 );
 
+TRACE_EVENT(kvm_booke206_ref_release,
+   TP_PROTO(__u64 pfn, __u32 flags),
+   TP_ARGS(pfn, flags),
+
+   TP_STRUCT__entry(
+   __field(__u64,  pfn )
+   __field(__u32,  flags   )
+   ),
+
+   TP_fast_assign(
+   __entry-pfn= pfn;
+   __entry-flags  = flags;
+   ),
+
+   TP_printk(pfn=%llx flags=%x,
+   __entry-pfn, __entry-flags)
+);
+
+TRACE_EVENT(kvm_booke_queue_irqprio,
+   TP_PROTO(struct kvm_vcpu *vcpu, unsigned int priority),
+   TP_ARGS(vcpu, priority),
+
+   TP_STRUCT__entry(
+   __field(__u32,  cpu_nr  )
+   __field(__u32,  priority)
+   __field(unsigned long,  pending )
+   ),
+
+   TP_fast_assign(
+   __entry-cpu_nr = vcpu-vcpu_id;
+   __entry-priority   = priority;
+   __entry-pending= vcpu-arch.pending_exceptions;
+   ),
+
+   TP_printk(vcpu=%x prio=%x pending=%lx,
+   __entry-cpu_nr, __entry-priority, __entry-pending)
+);
+
 #endif
 
 #endif /* _TRACE_KVM_H */
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to 

[PATCH 22/56] KVM: PPC: BookE: Drop redundant vcpu-mode set

2012-10-04 Thread Alexander Graf
We only need to set vcpu-mode to outside once.

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

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 4652e0b..492c343 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -528,8 +528,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 #endif
 
kvm_guest_exit();
-   vcpu-mode = OUTSIDE_GUEST_MODE;
-   smp_wmb();
 
 out:
vcpu-mode = OUTSIDE_GUEST_MODE;
-- 
1.6.0.2

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


[PATCH 25/56] KVM: PPC: Book3S: PR: Indicate we're out of guest mode

2012-10-04 Thread Alexander Graf
When going out of guest mode, indicate that we are in vcpu-mode. That way
requests from other CPUs don't needlessly need to kick us to process them,
because it'll just happen next time we enter the guest.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_pr.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index b4ae11e..9430a36 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1152,6 +1152,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 #endif
 
 out:
+   vcpu-mode = OUTSIDE_GUEST_MODE;
preempt_enable();
return ret;
 }
-- 
1.6.0.2

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


[PATCH 20/56] KVM: PPC: Use same kvmppc_prepare_to_enter code for booke and book3s_pr

2012-10-04 Thread Alexander Graf
We need to do the same things when preparing to enter a guest for booke and
book3s_pr cores. Fold the generic code into a generic function that both call.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h |3 ++
 arch/powerpc/kvm/book3s_pr.c   |   22 --
 arch/powerpc/kvm/booke.c   |   58 +---
 arch/powerpc/kvm/powerpc.c |   57 +++
 4 files changed, 67 insertions(+), 73 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 88de314..59b7c87 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -112,6 +112,7 @@ extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, 
int sprn,
 ulong val);
 extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
 ulong *val);
+extern void kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
 
 extern int kvmppc_booke_init(void);
 extern void kvmppc_booke_exit(void);
@@ -150,6 +151,8 @@ extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
 extern int kvmppc_bookehv_init(void);
 extern void kvmppc_bookehv_exit(void);
 
+extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
+
 /*
  * Cuts out inst bits with ordering according to spec.
  * That means the leftmost bit is zero. All given bits are included.
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 7f0fe6f..cae2def 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -88,6 +88,10 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
kvmppc_giveup_ext(vcpu, MSR_VSX);
 }
 
+void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
+{
+}
+
 static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)
 {
ulong smsr = vcpu-arch.shared-msr;
@@ -815,19 +819,9 @@ program_interrupt:
 * again due to a host external interrupt.
 */
__hard_irq_disable();
-   if (signal_pending(current)) {
-   __hard_irq_enable();
-#ifdef EXIT_DEBUG
-   printk(KERN_EMERG KVM: Going back to host\n);
-#endif
-   vcpu-stat.signal_exits++;
+   if (kvmppc_prepare_to_enter(vcpu)) {
run-exit_reason = KVM_EXIT_INTR;
r = -EINTR;
-   } else {
-   /* In case an interrupt came in that was triggered
-* from userspace (like DEC), we need to check what
-* to inject now! */
-   kvmppc_core_prepare_to_enter(vcpu);
}
}
 
@@ -1029,8 +1023,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
goto out;
}
 
-   kvmppc_core_prepare_to_enter(vcpu);
-
/*
 * Interrupts could be timers for the guest which we have to inject
 * again, so let's postpone them until we're in the guest and if we
@@ -1038,9 +1030,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 * a host external interrupt.
 */
__hard_irq_disable();
-
-   /* No need to go into the guest when all we do is going out */
-   if (signal_pending(current)) {
+   if (kvmppc_prepare_to_enter(vcpu)) {
__hard_irq_enable();
kvm_run-exit_reason = KVM_EXIT_INTR;
ret = -EINTR;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 683cbd6..4652e0b 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -455,10 +455,8 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
return r;
 }
 
-static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
+void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 {
-   trace_kvm_check_requests(vcpu);
-
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
update_timer_ints(vcpu);
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
@@ -467,60 +465,6 @@ static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
 #endif
 }
 
-/*
- * Common checks before entering the guest world.  Call with interrupts
- * disabled.
- *
- * returns !0 if a signal is pending and check_signal is true
- */
-static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
-{
-   int r = 0;
-
-   WARN_ON_ONCE(!irqs_disabled());
-   while (true) {
-   if (need_resched()) {
-   local_irq_enable();
-   cond_resched();
-   local_irq_disable();
-   continue;
-   }
-
-   if (signal_pending(current)) {
-   r = 1;
-   break;
-   }
-
-   smp_mb();
-   if (vcpu-requests) {
-   /* Make sure we 

[PATCH 23/56] KVM: PPC: Book3S: PR: Only do resched check once per exit

2012-10-04 Thread Alexander Graf
Now that we use our generic exit helper, we can safely drop our previous
kvm_resched that we used to trigger at the beginning of the exit handler
function.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_pr.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 10f8217..2c268a1 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -602,7 +602,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
 
trace_kvm_exit(exit_nr, vcpu);
preempt_enable();
-   kvm_resched(vcpu);
+
switch (exit_nr) {
case BOOK3S_INTERRUPT_INST_STORAGE:
{
-- 
1.6.0.2

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


[PATCH 21/56] KVM: PPC: Book3s: PR: Add (dumb) MMU Notifier support

2012-10-04 Thread Alexander Graf
Now that we have very simple MMU Notifier support for e500 in place,
also add the same simple support to book3s. It gets us one step closer
to actual fast support.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h   |3 +-
 arch/powerpc/kvm/Kconfig  |1 +
 arch/powerpc/kvm/book3s_32_mmu_host.c |1 +
 arch/powerpc/kvm/book3s_64_mmu_host.c |1 +
 arch/powerpc/kvm/book3s_mmu_hpte.c|5 ---
 arch/powerpc/kvm/book3s_pr.c  |   47 +
 6 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index cea9d3a..4a5ec8f 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -46,8 +46,7 @@
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
 #endif
 
-#if defined(CONFIG_KVM_BOOK3S_64_HV) || defined(CONFIG_KVM_E500V2) || \
-defined(CONFIG_KVM_E500MC)
+#if !defined(CONFIG_KVM_440)
 #include linux/mmu_notifier.h
 
 #define KVM_ARCH_WANT_MMU_NOTIFIER
diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 40cad8c..71f0cd9 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -36,6 +36,7 @@ config KVM_BOOK3S_64_HANDLER
 config KVM_BOOK3S_PR
bool
select KVM_MMIO
+   select MMU_NOTIFIER
 
 config KVM_BOOK3S_32
tristate KVM support for PowerPC book3s_32 processors
diff --git a/arch/powerpc/kvm/book3s_32_mmu_host.c 
b/arch/powerpc/kvm/book3s_32_mmu_host.c
index 837f13e..9fac010 100644
--- a/arch/powerpc/kvm/book3s_32_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_32_mmu_host.c
@@ -254,6 +254,7 @@ next_pteg:
 
kvmppc_mmu_hpte_cache_map(vcpu, pte);
 
+   kvm_release_pfn_clean(hpaddr  PAGE_SHIFT);
 out:
return r;
 }
diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c 
b/arch/powerpc/kvm/book3s_64_mmu_host.c
index 0688b6b..6b2c80e 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_host.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_host.c
@@ -168,6 +168,7 @@ map_again:
 
kvmppc_mmu_hpte_cache_map(vcpu, pte);
}
+   kvm_release_pfn_clean(hpaddr  PAGE_SHIFT);
 
 out:
return r;
diff --git a/arch/powerpc/kvm/book3s_mmu_hpte.c 
b/arch/powerpc/kvm/book3s_mmu_hpte.c
index 41cb001..2c86b0d 100644
--- a/arch/powerpc/kvm/book3s_mmu_hpte.c
+++ b/arch/powerpc/kvm/book3s_mmu_hpte.c
@@ -114,11 +114,6 @@ static void invalidate_pte(struct kvm_vcpu *vcpu, struct 
hpte_cache *pte)
hlist_del_init_rcu(pte-list_vpte);
hlist_del_init_rcu(pte-list_vpte_long);
 
-   if (pte-pte.may_write)
-   kvm_release_pfn_dirty(pte-pfn);
-   else
-   kvm_release_pfn_clean(pte-pfn);
-
spin_unlock(vcpu3s-mmu_lock);
 
vcpu3s-hpte_cache_count--;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index cae2def..10f8217 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -90,8 +90,55 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 
 void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 {
+   /* We misuse TLB_FLUSH to indicate that we want to clear
+  all shadow cache entries */
+   if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
+   kvmppc_mmu_pte_flush(vcpu, 0, 0);
 }
 
+/* MMU Notifiers */
+
+int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
+{
+   trace_kvm_unmap_hva(hva);
+
+   /*
+* Flush all shadow tlb entries everywhere. This is slow, but
+* we are 100% sure that we catch the to be unmapped page
+*/
+   kvm_flush_remote_tlbs(kvm);
+
+   return 0;
+}
+
+int kvm_unmap_hva_range(struct kvm *kvm, unsigned long start, unsigned long 
end)
+{
+   /* kvm_unmap_hva flushes everything anyways */
+   kvm_unmap_hva(kvm, start);
+
+   return 0;
+}
+
+int kvm_age_hva(struct kvm *kvm, unsigned long hva)
+{
+   /* XXX could be more clever ;) */
+   return 0;
+}
+
+int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
+{
+   /* XXX could be more clever ;) */
+   return 0;
+}
+
+void kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte)
+{
+   /* The page will get remapped properly on its next fault */
+   kvm_unmap_hva(kvm, hva);
+}
+
+/*/
+
 static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)
 {
ulong smsr = vcpu-arch.shared-msr;
-- 
1.6.0.2

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


[PATCH 24/56] KVM: PPC: Exit guest context while handling exit

2012-10-04 Thread Alexander Graf
The x86 implementation of KVM accounts for host time while processing
guest exits. Do the same for us.

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

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 2c268a1..b4ae11e 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -601,6 +601,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
__hard_irq_enable();
 
trace_kvm_exit(exit_nr, vcpu);
+   kvm_guest_exit();
preempt_enable();
 
switch (exit_nr) {
@@ -872,6 +873,7 @@ program_interrupt:
}
}
 
+   kvm_guest_enter();
trace_kvm_book3s_reenter(r, vcpu);
 
return r;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 492c343..887c7cc 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -650,6 +650,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
local_irq_enable();
 
trace_kvm_exit(exit_nr, vcpu);
+   kvm_guest_exit();
 
run-exit_reason = KVM_EXIT_UNKNOWN;
run-ready_for_interrupt_injection = 1;
@@ -952,6 +953,8 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
}
}
 
+   kvm_guest_enter();
+
return r;
 }
 
-- 
1.6.0.2

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


[PATCH 26/56] KVM: PPC: Consistentify vcpu exit path

2012-10-04 Thread Alexander Graf
When getting out of __vcpu_run, let's be consistent about the state we
return in. We want to always

  * have IRQs enabled
  * have called kvm_guest_exit before

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_pr.c |8 ++--
 arch/powerpc/kvm/booke.c |   13 -
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 9430a36..3dec346 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -868,12 +868,15 @@ program_interrupt:
 */
__hard_irq_disable();
if (kvmppc_prepare_to_enter(vcpu)) {
+   /* local_irq_enable(); */
run-exit_reason = KVM_EXIT_INTR;
r = -EINTR;
+   } else {
+   /* Going back to guest */
+   kvm_guest_enter();
}
}
 
-   kvm_guest_enter();
trace_kvm_book3s_reenter(r, vcpu);
 
return r;
@@ -1123,7 +1126,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
-   kvm_guest_exit();
+   /* No need for kvm_guest_exit. It's done in handle_exit.
+  We also get here with interrupts enabled. */
 
current-thread.regs-msr = ext_msr;
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 887c7cc..aae535f 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -481,6 +481,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
local_irq_disable();
if (kvmppc_prepare_to_enter(vcpu)) {
+   local_irq_enable();
kvm_run-exit_reason = KVM_EXIT_INTR;
ret = -EINTR;
goto out;
@@ -512,6 +513,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
+   /* No need for kvm_guest_exit. It's done in handle_exit.
+  We also get here with interrupts enabled. */
+
 #ifdef CONFIG_PPC_FPU
kvmppc_save_guest_fp(vcpu);
 
@@ -527,12 +531,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
current-thread.fpexc_mode = fpexc_mode;
 #endif
 
-   kvm_guest_exit();
-
 out:
vcpu-mode = OUTSIDE_GUEST_MODE;
smp_wmb();
-   local_irq_enable();
return ret;
 }
 
@@ -947,14 +948,16 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
if (!(r  RESUME_HOST)) {
local_irq_disable();
if (kvmppc_prepare_to_enter(vcpu)) {
+   local_irq_enable();
run-exit_reason = KVM_EXIT_INTR;
r = (-EINTR  2) | RESUME_HOST | (r  RESUME_FLAG_NV);
kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+   } else {
+   /* Going back to guest */
+   kvm_guest_enter();
}
}
 
-   kvm_guest_enter();
-
return r;
 }
 
-- 
1.6.0.2

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


[PATCH 27/56] KVM: PPC: Book3S: PR: Rework irq disabling

2012-10-04 Thread Alexander Graf
Today, we disable preemption while inside guest context, because we need
to expose to the world that we are not in a preemptible context. However,
during that time we already have interrupts disabled, which would indicate
that we are in a non-preemptible context.

The reason the checks for irqs_disabled() fail for us though is that we
manually control hard IRQs and ignore all the lazy EE framework. Let's
stop doing that. Instead, let's always use lazy EE to indicate when we
want to disable IRQs, but do a special final switch that gets us into
EE disabled, but soft enabled state. That way when we get back out of
guest state, we are immediately ready to process interrupts.

This simplifies the code drastically and reduces the time that we appear
as preempt disabled.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h   |   10 ++
 arch/powerpc/kvm/book3s_pr.c |   21 +++--
 arch/powerpc/kvm/book3s_rmhandlers.S |   15 ---
 arch/powerpc/kvm/booke.c |2 ++
 arch/powerpc/kvm/powerpc.c   |   14 ++
 5 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 59b7c87..5459364 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -234,5 +234,15 @@ static inline void kvmppc_mmu_flush_icache(pfn_t pfn)
}
 }
 
+/* Please call after prepare_to_enter. This function puts the lazy ee state
+   back to normal mode, without actually enabling interrupts. */
+static inline void kvmppc_lazy_ee_enable(void)
+{
+#ifdef CONFIG_PPC64
+   /* Only need to enable IRQs by hard enabling them after this */
+   local_paca-irq_happened = 0;
+   local_paca-soft_enabled = 1;
+#endif
+}
 
 #endif /* __POWERPC_KVM_PPC_H__ */
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 3dec346..e737db8 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -52,8 +52,6 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned 
int exit_nr,
 #define MSR_USER32 MSR_USER
 #define MSR_USER64 MSR_USER
 #define HW_PAGE_SIZE PAGE_SIZE
-#define __hard_irq_disable local_irq_disable
-#define __hard_irq_enable local_irq_enable
 #endif
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
@@ -597,12 +595,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
run-exit_reason = KVM_EXIT_UNKNOWN;
run-ready_for_interrupt_injection = 1;
 
-   /* We get here with MSR.EE=0, so enable it to be a nice citizen */
-   __hard_irq_enable();
+   /* We get here with MSR.EE=1 */
 
trace_kvm_exit(exit_nr, vcpu);
kvm_guest_exit();
-   preempt_enable();
 
switch (exit_nr) {
case BOOK3S_INTERRUPT_INST_STORAGE:
@@ -854,7 +850,6 @@ program_interrupt:
}
}
 
-   preempt_disable();
if (!(r  RESUME_HOST)) {
/* To avoid clobbering exit_reason, only check for signals if
 * we aren't already exiting to userspace for some other
@@ -866,14 +861,15 @@ program_interrupt:
 * and if we really did time things so badly, then we just exit
 * again due to a host external interrupt.
 */
-   __hard_irq_disable();
+   local_irq_disable();
if (kvmppc_prepare_to_enter(vcpu)) {
-   /* local_irq_enable(); */
+   local_irq_enable();
run-exit_reason = KVM_EXIT_INTR;
r = -EINTR;
} else {
/* Going back to guest */
kvm_guest_enter();
+   kvmppc_lazy_ee_enable();
}
}
 
@@ -1066,8 +1062,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 #endif
ulong ext_msr;
 
-   preempt_disable();
-
/* Check if we can run the vcpu at all */
if (!vcpu-arch.sane) {
kvm_run-exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -1081,9 +1075,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 * really did time things so badly, then we just exit again due to
 * a host external interrupt.
 */
-   __hard_irq_disable();
+   local_irq_disable();
if (kvmppc_prepare_to_enter(vcpu)) {
-   __hard_irq_enable();
+   local_irq_enable();
kvm_run-exit_reason = KVM_EXIT_INTR;
ret = -EINTR;
goto out;
@@ -1122,7 +1116,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
if (vcpu-arch.shared-msr  MSR_FP)
kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP);
 
-   kvm_guest_enter();
+   kvmppc_lazy_ee_enable();
 
ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
@@ -1157,7 

[PATCH 28/56] KVM: PPC: Move kvm_guest_enter call into generic code

2012-10-04 Thread Alexander Graf
We need to call kvm_guest_enter in booke and book3s, so move its
call to generic code.

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

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index e737db8..1ff0d6c 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -867,8 +867,6 @@ program_interrupt:
run-exit_reason = KVM_EXIT_INTR;
r = -EINTR;
} else {
-   /* Going back to guest */
-   kvm_guest_enter();
kvmppc_lazy_ee_enable();
}
}
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 2bd190c..5e8dc19 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -954,8 +954,6 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
r = (-EINTR  2) | RESUME_HOST | (r  RESUME_FLAG_NV);
kvmppc_account_exit(vcpu, SIGNAL_EXITS);
} else {
-   /* Going back to guest */
-   kvm_guest_enter();
kvmppc_lazy_ee_enable();
}
}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 2665499..6646574 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -101,12 +101,15 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
/* Got an interrupt in between, try again */
local_irq_enable();
local_irq_disable();
+   kvm_guest_exit();
continue;
}
 
trace_hardirqs_on();
 #endif
 
+   kvm_guest_enter();
+
/* Going into guest context! Yay! */
vcpu-mode = IN_GUEST_MODE;
smp_wmb();
-- 
1.6.0.2

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


[PATCH 29/56] KVM: PPC: Ignore EXITING_GUEST_MODE mode

2012-10-04 Thread Alexander Graf
We don't need to do anything when mode is EXITING_GUEST_MODE, because
we essentially are outside of guest mode and did everything it asked
us to do by the time we check it.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/powerpc.c |5 -
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 6646574..dc86371 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -89,11 +89,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
continue;
}
 
-   if (vcpu-mode == EXITING_GUEST_MODE) {
-   r = 1;
-   break;
-   }
-
 #ifdef CONFIG_PPC64
/* lazy EE magic */
hard_irq_disable();
-- 
1.6.0.2

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


[PATCH 31/56] KVM: PPC: Add return value to core_check_requests

2012-10-04 Thread Alexander Graf
Requests may want to tell us that we need to go back into host state,
so add a return value for the checks.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_ppc.h |2 +-
 arch/powerpc/kvm/book3s_pr.c   |6 +-
 arch/powerpc/kvm/booke.c   |6 +-
 arch/powerpc/kvm/powerpc.c |6 --
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 5459364..3dfc437 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -112,7 +112,7 @@ extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, 
int sprn,
 ulong val);
 extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
 ulong *val);
-extern void kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
+extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
 
 extern int kvmppc_booke_init(void);
 extern void kvmppc_booke_exit(void);
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 71fa0f1..b3c584f 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -86,12 +86,16 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
kvmppc_giveup_ext(vcpu, MSR_VSX);
 }
 
-void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
+int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 {
+   int r = 1; /* Indicate we want to get back into the guest */
+
/* We misuse TLB_FLUSH to indicate that we want to clear
   all shadow cache entries */
if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
kvmppc_mmu_pte_flush(vcpu, 0, 0);
+
+   return r;
 }
 
 /* MMU Notifiers */
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 1917802..c364930 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -455,14 +455,18 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
return r;
 }
 
-void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
+int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 {
+   int r = 1; /* Indicate we want to get back into the guest */
+
if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
update_timer_ints(vcpu);
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
kvmppc_core_flush_tlb(vcpu);
 #endif
+
+   return r;
 }
 
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 0e2a98a..54b12af 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -83,9 +83,11 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
/* Make sure we process requests preemptable */
local_irq_enable();
trace_kvm_check_requests(vcpu);
-   kvmppc_core_check_requests(vcpu);
+   r = kvmppc_core_check_requests(vcpu);
local_irq_disable();
-   continue;
+   if (r  0)
+   continue;
+   break;
}
 
if (kvmppc_core_prepare_to_enter(vcpu)) {
-- 
1.6.0.2

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


[PATCH 30/56] KVM: PPC: Add return value in prepare_to_enter

2012-10-04 Thread Alexander Graf
Our prepare_to_enter helper wants to be able to return in more circumstances
to the host than only when an interrupt is pending. Broaden the interface a
bit and move even more generic code to the generic helper.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_pr.c |   12 ++--
 arch/powerpc/kvm/booke.c |   16 
 arch/powerpc/kvm/powerpc.c   |   11 ---
 3 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 1ff0d6c..71fa0f1 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -589,6 +589,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
unsigned int exit_nr)
 {
int r = RESUME_HOST;
+   int s;
 
vcpu-stat.sum_exits++;
 
@@ -862,10 +863,10 @@ program_interrupt:
 * again due to a host external interrupt.
 */
local_irq_disable();
-   if (kvmppc_prepare_to_enter(vcpu)) {
+   s = kvmppc_prepare_to_enter(vcpu);
+   if (s = 0) {
local_irq_enable();
-   run-exit_reason = KVM_EXIT_INTR;
-   r = -EINTR;
+   r = s;
} else {
kvmppc_lazy_ee_enable();
}
@@ -1074,10 +1075,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
 * a host external interrupt.
 */
local_irq_disable();
-   if (kvmppc_prepare_to_enter(vcpu)) {
+   ret = kvmppc_prepare_to_enter(vcpu);
+   if (ret = 0) {
local_irq_enable();
-   kvm_run-exit_reason = KVM_EXIT_INTR;
-   ret = -EINTR;
goto out;
}
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 5e8dc19..1917802 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -467,7 +467,7 @@ void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
 
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 {
-   int ret;
+   int ret, s;
 #ifdef CONFIG_PPC_FPU
unsigned int fpscr;
int fpexc_mode;
@@ -480,10 +480,10 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct 
kvm_vcpu *vcpu)
}
 
local_irq_disable();
-   if (kvmppc_prepare_to_enter(vcpu)) {
+   s = kvmppc_prepare_to_enter(vcpu);
+   if (s = 0) {
local_irq_enable();
-   kvm_run-exit_reason = KVM_EXIT_INTR;
-   ret = -EINTR;
+   ret = s;
goto out;
}
kvmppc_lazy_ee_enable();
@@ -642,6 +642,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
unsigned int exit_nr)
 {
int r = RESUME_HOST;
+   int s;
 
/* update before a new last_exit_type is rewritten */
kvmppc_update_timing_stats(vcpu);
@@ -948,11 +949,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 */
if (!(r  RESUME_HOST)) {
local_irq_disable();
-   if (kvmppc_prepare_to_enter(vcpu)) {
+   s = kvmppc_prepare_to_enter(vcpu);
+   if (s = 0) {
local_irq_enable();
-   run-exit_reason = KVM_EXIT_INTR;
-   r = (-EINTR  2) | RESUME_HOST | (r  RESUME_FLAG_NV);
-   kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+   r = (s  2) | RESUME_HOST | (r  RESUME_FLAG_NV);
} else {
kvmppc_lazy_ee_enable();
}
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index dc86371..0e2a98a 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -53,11 +53,14 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
  * Common checks before entering the guest world.  Call with interrupts
  * disabled.
  *
- * returns !0 if a signal is pending and check_signal is true
+ * returns:
+ *
+ * == 1 if we're ready to go into guest state
+ * = 0 if we need to go back to the host with return value
  */
 int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
-   int r = 0;
+   int r = 1;
 
WARN_ON_ONCE(!irqs_disabled());
while (true) {
@@ -69,7 +72,9 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
}
 
if (signal_pending(current)) {
-   r = 1;
+   kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+   vcpu-run-exit_reason = KVM_EXIT_INTR;
+   r = -EINTR;
break;
}
 
-- 
1.6.0.2

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


[PATCH 32/56] KVM: PPC: booke: Add watchdog emulation

2012-10-04 Thread Alexander Graf
From: Bharat Bhushan r65...@freescale.com

This patch adds the watchdog emulation in KVM. The watchdog
emulation is enabled by KVM_ENABLE_CAP(KVM_CAP_PPC_BOOKE_WATCHDOG) ioctl.
The kernel timer are used for watchdog emulation and emulates
h/w watchdog state machine. On watchdog timer expiry, it exit to QEMU
if TCR.WRC is non ZERO. QEMU can reset/shutdown etc depending upon how
it is configured.

Signed-off-by: Liu Yu yu@freescale.com
Signed-off-by: Scott Wood scottw...@freescale.com
[bharat.bhus...@freescale.com: reworked patch]
Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
[agraf: adjust to new request framework]
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h  |3 +
 arch/powerpc/include/asm/kvm_ppc.h   |2 +
 arch/powerpc/include/asm/reg_booke.h |7 ++
 arch/powerpc/kvm/book3s.c|9 ++
 arch/powerpc/kvm/booke.c |  155 ++
 arch/powerpc/kvm/booke_emulate.c |8 ++
 arch/powerpc/kvm/powerpc.c   |   14 +++-
 include/linux/kvm.h  |2 +
 include/linux/kvm_host.h |1 +
 9 files changed, 199 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 4a5ec8f..51b0ccd 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -471,6 +471,8 @@ struct kvm_vcpu_arch {
ulong fault_esr;
ulong queued_dear;
ulong queued_esr;
+   spinlock_t wdt_lock;
+   struct timer_list wdt_timer;
u32 tlbcfg[4];
u32 mmucfg;
u32 epr;
@@ -486,6 +488,7 @@ struct kvm_vcpu_arch {
u8 osi_needed;
u8 osi_enabled;
u8 papr_enabled;
+   u8 watchdog_enabled;
u8 sane;
u8 cpu_type;
u8 hcall_needed;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 3dfc437..c06a64b 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -68,6 +68,8 @@ 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 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);
 
 /* Core-specific hooks */
 
diff --git a/arch/powerpc/include/asm/reg_booke.h 
b/arch/powerpc/include/asm/reg_booke.h
index 2d916c4..e07e6af 100644
--- a/arch/powerpc/include/asm/reg_booke.h
+++ b/arch/powerpc/include/asm/reg_booke.h
@@ -539,6 +539,13 @@
 #define TCR_FIE0x0080  /* FIT Interrupt Enable */
 #define TCR_ARE0x0040  /* Auto Reload Enable */
 
+#ifdef CONFIG_E500
+#define TCR_GET_WP(tcr)  tcr)  0xC000)  30) | \
+ (((tcr)  0x1E)  15))
+#else
+#define TCR_GET_WP(tcr)  (((tcr)  0xC000)  30)
+#endif
+
 /* Bit definitions for the TSR. */
 #define TSR_ENW0x8000  /* Enable Next Watchdog */
 #define TSR_WIS0x4000  /* WDT Interrupt Status */
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 3f2a836..e946665 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -411,6 +411,15 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
return 0;
 }
 
+int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu)
+{
+   return 0;
+}
+
+void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu)
+{
+}
+
 int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 {
int i;
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index c364930..09e8bf3 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -209,6 +209,16 @@ void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,
clear_bit(BOOKE_IRQPRIO_EXTERNAL_LEVEL, vcpu-arch.pending_exceptions);
 }
 
+static void kvmppc_core_queue_watchdog(struct kvm_vcpu *vcpu)
+{
+   kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_WATCHDOG);
+}
+
+static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu *vcpu)
+{
+   clear_bit(BOOKE_IRQPRIO_WATCHDOG, vcpu-arch.pending_exceptions);
+}
+
 static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
 {
 #ifdef CONFIG_KVM_BOOKE_HV
@@ -328,6 +338,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
msr_mask = MSR_CE | MSR_ME | MSR_DE;
int_class = INT_CLASS_NONCRIT;
break;
+   case BOOKE_IRQPRIO_WATCHDOG:
case BOOKE_IRQPRIO_CRITICAL:
case BOOKE_IRQPRIO_DBELL_CRIT:
allowed = vcpu-arch.shared-msr  MSR_CE;
@@ -407,12 +418,121 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu 
*vcpu,
return allowed;
 }
 
+/*
+ * Return the number of jiffies until the next timeout.  If the timeout 

[PATCH 33/56] booke: Added ONE_REG interface for IAC/DAC debug registers

2012-10-04 Thread Alexander Graf
From: Bharat Bhushan r65...@freescale.com

IAC/DAC are defined as 32 bit while they are 64 bit wide. So ONE_REG
interface is added to set/get them.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm.h  |   12 
 arch/powerpc/include/asm/kvm_host.h |   24 -
 arch/powerpc/kvm/booke.c|   48 +-
 arch/powerpc/kvm/booke_emulate.c|8 +++---
 4 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index 1bea4d8..3c14202 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -221,6 +221,12 @@ struct kvm_sregs {
 
__u32 dbsr; /* KVM_SREGS_E_UPDATE_DBSR */
__u32 dbcr[3];
+   /*
+* iac/dac registers are 64bit wide, while this API
+* interface provides only lower 32 bits on 64 bit
+* processors. ONE_REG interface is added for 64bit
+* iac/dac registers.
+*/
__u32 iac[4];
__u32 dac[2];
__u32 dvc[2];
@@ -326,5 +332,11 @@ struct kvm_book3e_206_tlb_params {
 };
 
 #define KVM_REG_PPC_HIOR   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x1)
+#define KVM_REG_PPC_IAC1   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x2)
+#define KVM_REG_PPC_IAC2   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x3)
+#define KVM_REG_PPC_IAC3   (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x4)
+#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)
 
 #endif /* __LINUX_KVM_POWERPC_H */
diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 51b0ccd..f20a5ef 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -346,6 +346,27 @@ struct kvmppc_slb {
bool class  : 1;
 };
 
+# ifdef CONFIG_PPC_FSL_BOOK3E
+#define KVMPPC_BOOKE_IAC_NUM   2
+#define KVMPPC_BOOKE_DAC_NUM   2
+# else
+#define KVMPPC_BOOKE_IAC_NUM   4
+#define KVMPPC_BOOKE_DAC_NUM   2
+# endif
+#define KVMPPC_BOOKE_MAX_IAC   4
+#define KVMPPC_BOOKE_MAX_DAC   2
+
+struct kvmppc_booke_debug_reg {
+   u32 dbcr0;
+   u32 dbcr1;
+   u32 dbcr2;
+#ifdef CONFIG_KVM_E500MC
+   u32 dbcr4;
+#endif
+   u64 iac[KVMPPC_BOOKE_MAX_IAC];
+   u64 dac[KVMPPC_BOOKE_MAX_DAC];
+};
+
 struct kvm_vcpu_arch {
ulong host_stack;
u32 host_pid;
@@ -440,8 +461,6 @@ struct kvm_vcpu_arch {
 
u32 ccr0;
u32 ccr1;
-   u32 dbcr0;
-   u32 dbcr1;
u32 dbsr;
 
u64 mmcr[3];
@@ -476,6 +495,7 @@ struct kvm_vcpu_arch {
u32 tlbcfg[4];
u32 mmucfg;
u32 epr;
+   struct kvmppc_booke_debug_reg 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 09e8bf3..959aae9 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1351,12 +1351,56 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
 
 int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
 {
-   return -EINVAL;
+   int r = -EINVAL;
+
+   switch (reg-id) {
+   case KVM_REG_PPC_IAC1:
+   case KVM_REG_PPC_IAC2:
+   case KVM_REG_PPC_IAC3:
+   case KVM_REG_PPC_IAC4: {
+   int iac = reg-id - KVM_REG_PPC_IAC1;
+   r = copy_to_user((u64 __user *)(long)reg-addr,
+vcpu-arch.dbg_reg.iac[iac], sizeof(u64));
+   break;
+   }
+   case KVM_REG_PPC_DAC1:
+   case KVM_REG_PPC_DAC2: {
+   int dac = reg-id - KVM_REG_PPC_DAC1;
+   r = copy_to_user((u64 __user *)(long)reg-addr,
+vcpu-arch.dbg_reg.dac[dac], sizeof(u64));
+   break;
+   }
+   default:
+   break;
+   }
+   return r;
 }
 
 int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
 {
-   return -EINVAL;
+   int r = -EINVAL;
+
+   switch (reg-id) {
+   case KVM_REG_PPC_IAC1:
+   case KVM_REG_PPC_IAC2:
+   case KVM_REG_PPC_IAC3:
+   case KVM_REG_PPC_IAC4: {
+   int iac = reg-id - KVM_REG_PPC_IAC1;
+   r = copy_from_user(vcpu-arch.dbg_reg.iac[iac],
+(u64 __user *)(long)reg-addr, sizeof(u64));
+   break;
+   }
+   case KVM_REG_PPC_DAC1:
+   case KVM_REG_PPC_DAC2: {
+   int dac = reg-id - KVM_REG_PPC_DAC1;
+   r = copy_from_user(vcpu-arch.dbg_reg.dac[dac],
+(u64 __user *)(long)reg-addr, 

[PATCH 35/56] KVM: PPC: BookE: Add MCSR SPR support

2012-10-04 Thread Alexander Graf
Add support for the MCSR SPR. This only implements the SPR storage
bits, not actual machine checks.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke_emulate.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke_emulate.c b/arch/powerpc/kvm/booke_emulate.c
index cc99a0b..514790f 100644
--- a/arch/powerpc/kvm/booke_emulate.c
+++ b/arch/powerpc/kvm/booke_emulate.c
@@ -237,6 +237,9 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int 
sprn, ulong spr_val)
case SPRN_IVOR15:
vcpu-arch.ivor[BOOKE_IRQPRIO_DEBUG] = spr_val;
break;
+   case SPRN_MCSR:
+   vcpu-arch.mcsr = ~spr_val;
+   break;
 
default:
emulated = EMULATE_FAIL;
@@ -329,6 +332,9 @@ int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int 
sprn, ulong *spr_val)
case SPRN_IVOR15:
*spr_val = vcpu-arch.ivor[BOOKE_IRQPRIO_DEBUG];
break;
+   case SPRN_MCSR:
+   *spr_val = vcpu-arch.mcsr;
+   break;
 
default:
emulated = EMULATE_FAIL;
-- 
1.6.0.2

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


[PATCH 36/56] KVM: PPC: Use symbols for exit trace

2012-10-04 Thread Alexander Graf
Exit traces are a lot easier to read when you don't have to remember
cryptic numbers for guest exit reasons. Symbolify them in our trace
output.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/trace.h |   58 -
 1 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
index cb2780a..519aba8 100644
--- a/arch/powerpc/kvm/trace.h
+++ b/arch/powerpc/kvm/trace.h
@@ -31,6 +31,60 @@ TRACE_EVENT(kvm_ppc_instr,
  __entry-inst, __entry-pc, __entry-emulate)
 );
 
+#ifdef CONFIG_PPC_BOOK3S
+#define kvm_trace_symbol_exit \
+   {0x100, SYSTEM_RESET}, \
+   {0x200, MACHINE_CHECK}, \
+   {0x300, DATA_STORAGE}, \
+   {0x380, DATA_SEGMENT}, \
+   {0x400, INST_STORAGE}, \
+   {0x480, INST_SEGMENT}, \
+   {0x500, EXTERNAL}, \
+   {0x501, EXTERNAL_LEVEL}, \
+   {0x502, EXTERNAL_HV}, \
+   {0x600, ALIGNMENT}, \
+   {0x700, PROGRAM}, \
+   {0x800, FP_UNAVAIL}, \
+   {0x900, DECREMENTER}, \
+   {0x980, HV_DECREMENTER}, \
+   {0xc00, SYSCALL}, \
+   {0xd00, TRACE}, \
+   {0xe00, H_DATA_STORAGE}, \
+   {0xe20, H_INST_STORAGE}, \
+   {0xe40, H_EMUL_ASSIST}, \
+   {0xf00, PERFMON}, \
+   {0xf20, ALTIVEC}, \
+   {0xf40, VSX}
+#else
+#define kvm_trace_symbol_exit \
+   {0, CRITICAL}, \
+   {1, MACHINE_CHECK}, \
+   {2, DATA_STORAGE}, \
+   {3, INST_STORAGE}, \
+   {4, EXTERNAL}, \
+   {5, ALIGNMENT}, \
+   {6, PROGRAM}, \
+   {7, FP_UNAVAIL}, \
+   {8, SYSCALL}, \
+   {9, AP_UNAVAIL}, \
+   {10, DECREMENTER}, \
+   {11, FIT}, \
+   {12, WATCHDOG}, \
+   {13, DTLB_MISS}, \
+   {14, ITLB_MISS}, \
+   {15, DEBUG}, \
+   {32, SPE_UNAVAIL}, \
+   {33, SPE_FP_DATA}, \
+   {34, SPE_FP_ROUND}, \
+   {35, PERFORMANCE_MONITOR}, \
+   {36, DOORBELL}, \
+   {37, DOORBELL_CRITICAL}, \
+   {38, GUEST_DBELL}, \
+   {39, GUEST_DBELL_CRIT}, \
+   {40, HV_SYSCALL}, \
+   {41, HV_PRIV}
+#endif
+
 TRACE_EVENT(kvm_exit,
TP_PROTO(unsigned int exit_nr, struct kvm_vcpu *vcpu),
TP_ARGS(exit_nr, vcpu),
@@ -62,7 +116,7 @@ TRACE_EVENT(kvm_exit,
__entry-last_inst  = vcpu-arch.last_inst;
),
 
-   TP_printk(exit=0x%x
+   TP_printk(exit=%s
 | pc=0x%lx
 | msr=0x%lx
 | dar=0x%lx
@@ -71,7 +125,7 @@ TRACE_EVENT(kvm_exit,
 #endif
 | last_inst=0x%lx
,
-   __entry-exit_nr,
+   __print_symbolic(__entry-exit_nr, kvm_trace_symbol_exit),
__entry-pc,
__entry-msr,
__entry-dar,
-- 
1.6.0.2

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


[PATCH 37/56] KVM: PPC: E500: Remove E500_TLB_DIRTY flag

2012-10-04 Thread Alexander Graf
Since we always mark pages as dirty immediately when mapping them read/write
now, there's no need for the dirty flag in our cache.

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

diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
index aa8b814..d162286 100644
--- a/arch/powerpc/kvm/e500.h
+++ b/arch/powerpc/kvm/e500.h
@@ -27,8 +27,7 @@
 #define E500_TLB_NUM   2
 
 #define E500_TLB_VALID 1
-#define E500_TLB_DIRTY 2
-#define E500_TLB_BITMAP 4
+#define E500_TLB_BITMAP 2
 
 struct tlbe_ref {
pfn_t pfn;
diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 1af6fab..43489a8 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -303,10 +303,8 @@ static inline void kvmppc_e500_ref_setup(struct tlbe_ref 
*ref,
ref-pfn = pfn;
ref-flags = E500_TLB_VALID;
 
-   if (tlbe_is_writable(gtlbe)) {
-   ref-flags |= E500_TLB_DIRTY;
+   if (tlbe_is_writable(gtlbe))
kvm_set_pfn_dirty(pfn);
-   }
 }
 
 static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref)
-- 
1.6.0.2

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


[PATCH 41/56] KVM: PPC: BookE: Support FPU on non-hv systems

2012-10-04 Thread Alexander Graf
When running on HV aware hosts, we can not trap when the guest sets the FP
bit, so we just let it do so when it wants to, because it has full access to
MSR.

For non-HV aware hosts with an FPU (like 440), we need to also adjust the
shadow MSR though. Otherwise the guest gets an FP unavailable trap even when
it really enabled the FP bit in MSR.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/booke.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 959aae9..5f0476a 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -122,6 +122,16 @@ static void kvmppc_vcpu_sync_spe(struct kvm_vcpu *vcpu)
 }
 #endif
 
+static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
+{
+#if defined(CONFIG_PPC_FPU)  !defined(CONFIG_KVM_BOOKE_HV)
+   /* We always treat the FP bit as enabled from the host
+  perspective, so only need to adjust the shadow MSR */
+   vcpu-arch.shadow_msr = ~MSR_FP;
+   vcpu-arch.shadow_msr |= vcpu-arch.shared-msr  MSR_FP;
+#endif
+}
+
 /*
  * Helper function for full MSR writes.  No need to call this if only
  * EE/CE/ME/DE/RI are changing.
@@ -138,6 +148,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
 
kvmppc_mmu_msr_notify(vcpu, old_msr);
kvmppc_vcpu_sync_spe(vcpu);
+   kvmppc_vcpu_sync_fpu(vcpu);
 }
 
 static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
-- 
1.6.0.2

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


[PATCH 40/56] KVM: PPC: 440: Implement mfdcrx

2012-10-04 Thread Alexander Graf
We need mfdcrx to execute properly on 460 cores.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x_emulate.c |   74 +++-
 1 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/arch/powerpc/kvm/44x_emulate.c b/arch/powerpc/kvm/44x_emulate.c
index 3843a75..1a793c4 100644
--- a/arch/powerpc/kvm/44x_emulate.c
+++ b/arch/powerpc/kvm/44x_emulate.c
@@ -27,6 +27,7 @@
 #include booke.h
 #include 44x_tlb.h
 
+#define XOP_MFDCRX  259
 #define XOP_MFDCR   323
 #define XOP_MTDCRX  387
 #define XOP_MTDCR   451
@@ -51,6 +52,43 @@ static int emulate_mtdcr(struct kvm_vcpu *vcpu, int rs, int 
dcrn)
}
 }
 
+static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn)
+{
+   /* The guest may access CPR0 registers to determine the timebase
+* frequency, and it must know the real host frequency because it
+* can directly access the timebase registers.
+*
+* It would be possible to emulate those accesses in userspace,
+* but userspace can really only figure out the end frequency.
+* We could decompose that into the factors that compute it, but
+* that's tricky math, and it's easier to just report the real
+* CPR0 values.
+*/
+   switch (dcrn) {
+   case DCRN_CPR0_CONFIG_ADDR:
+   kvmppc_set_gpr(vcpu, rt, vcpu-arch.cpr0_cfgaddr);
+   break;
+   case DCRN_CPR0_CONFIG_DATA:
+   local_irq_disable();
+   mtdcr(DCRN_CPR0_CONFIG_ADDR,
+ vcpu-arch.cpr0_cfgaddr);
+   kvmppc_set_gpr(vcpu, rt,
+  mfdcr(DCRN_CPR0_CONFIG_DATA));
+   local_irq_enable();
+   break;
+   default:
+   vcpu-run-dcr.dcrn = dcrn;
+   vcpu-run-dcr.data =  0;
+   vcpu-run-dcr.is_write = 0;
+   vcpu-arch.io_gpr = rt;
+   vcpu-arch.dcr_needed = 1;
+   kvmppc_account_exit(vcpu, DCR_EXITS);
+   return EMULATE_DO_DCR;
+   }
+
+   return EMULATE_DONE;
+}
+
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
 {
@@ -68,38 +106,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
switch (get_xop(inst)) {
 
case XOP_MFDCR:
-   /* The guest may access CPR0 registers to determine the 
timebase
-* frequency, and it must know the real host frequency 
because it
-* can directly access the timebase registers.
-*
-* It would be possible to emulate those accesses in 
userspace,
-* but userspace can really only figure out the end 
frequency.
-* We could decompose that into the factors that 
compute it, but
-* that's tricky math, and it's easier to just report 
the real
-* CPR0 values.
-*/
-   switch (dcrn) {
-   case DCRN_CPR0_CONFIG_ADDR:
-   kvmppc_set_gpr(vcpu, rt, 
vcpu-arch.cpr0_cfgaddr);
-   break;
-   case DCRN_CPR0_CONFIG_DATA:
-   local_irq_disable();
-   mtdcr(DCRN_CPR0_CONFIG_ADDR,
- vcpu-arch.cpr0_cfgaddr);
-   kvmppc_set_gpr(vcpu, rt,
-  mfdcr(DCRN_CPR0_CONFIG_DATA));
-   local_irq_enable();
-   break;
-   default:
-   run-dcr.dcrn = dcrn;
-   run-dcr.data =  0;
-   run-dcr.is_write = 0;
-   vcpu-arch.io_gpr = rt;
-   vcpu-arch.dcr_needed = 1;
-   kvmppc_account_exit(vcpu, DCR_EXITS);
-   emulated = EMULATE_DO_DCR;
-   }
+   emulated = emulate_mfdcr(vcpu, rt, dcrn);
+   break;
 
+   case XOP_MFDCRX:
+   emulated = emulate_mfdcr(vcpu, rt,
+   kvmppc_get_gpr(vcpu, ra));
break;
 
case XOP_MTDCR:
-- 
1.6.0.2

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


[PATCH 39/56] KVM: PPC: 440: Implement mtdcrx

2012-10-04 Thread Alexander Graf
We need mtdcrx to execute properly on 460 cores.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/44x_emulate.c |   36 +++-
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kvm/44x_emulate.c b/arch/powerpc/kvm/44x_emulate.c
index c8c6157..3843a75 100644
--- a/arch/powerpc/kvm/44x_emulate.c
+++ b/arch/powerpc/kvm/44x_emulate.c
@@ -28,11 +28,29 @@
 #include 44x_tlb.h
 
 #define XOP_MFDCR   323
+#define XOP_MTDCRX  387
 #define XOP_MTDCR   451
 #define XOP_TLBSX   914
 #define XOP_ICCCI   966
 #define XOP_TLBWE   978
 
+static int emulate_mtdcr(struct kvm_vcpu *vcpu, int rs, int dcrn)
+{
+   /* emulate some access in kernel */
+   switch (dcrn) {
+   case DCRN_CPR0_CONFIG_ADDR:
+   vcpu-arch.cpr0_cfgaddr = kvmppc_get_gpr(vcpu, rs);
+   return EMULATE_DONE;
+   default:
+   vcpu-run-dcr.dcrn = dcrn;
+   vcpu-run-dcr.data = kvmppc_get_gpr(vcpu, rs);
+   vcpu-run-dcr.is_write = 1;
+   vcpu-arch.dcr_needed = 1;
+   kvmppc_account_exit(vcpu, DCR_EXITS);
+   return EMULATE_DO_DCR;
+   }
+}
+
 int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
unsigned int inst, int *advance)
 {
@@ -85,20 +103,12 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
 
case XOP_MTDCR:
-   /* emulate some access in kernel */
-   switch (dcrn) {
-   case DCRN_CPR0_CONFIG_ADDR:
-   vcpu-arch.cpr0_cfgaddr = kvmppc_get_gpr(vcpu, 
rs);
-   break;
-   default:
-   run-dcr.dcrn = dcrn;
-   run-dcr.data = kvmppc_get_gpr(vcpu, rs);
-   run-dcr.is_write = 1;
-   vcpu-arch.dcr_needed = 1;
-   kvmppc_account_exit(vcpu, DCR_EXITS);
-   emulated = EMULATE_DO_DCR;
-   }
+   emulated = emulate_mtdcr(vcpu, rs, dcrn);
+   break;
 
+   case XOP_MTDCRX:
+   emulated = emulate_mtdcr(vcpu, rs,
+   kvmppc_get_gpr(vcpu, ra));
break;
 
case XOP_TLBWE:
-- 
1.6.0.2

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


[PATCH 38/56] Document IACx/DACx registers access using ONE_REG API

2012-10-04 Thread Alexander Graf
From: Bharat Bhushan r65...@freescale.com

Patch to access the debug registers (IACx/DACx) using ONE_REG api
was sent earlier. But that missed the respective documentation.

Also corrected the index number referencing in section 4.69

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

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 11b5d31..a12f4e4 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1734,7 +1734,12 @@ registers, find a list below:
   Arch  |   Register| Width (bits)
 |   |
   PPC   | KVM_REG_PPC_HIOR  | 64
-
+  PPC   | KVM_REG_PPC_IAC1  | 64
+  PPC   | KVM_REG_PPC_IAC2  | 64
+  PPC   | KVM_REG_PPC_IAC3  | 64
+  PPC   | KVM_REG_PPC_IAC4  | 64
+  PPC   | KVM_REG_PPC_DAC1  | 64
+  PPC   | KVM_REG_PPC_DAC2  | 64
 
 4.69 KVM_GET_ONE_REG
 
@@ -1750,7 +1755,7 @@ kvm_one_reg struct passed in. On success, the register 
value can be found
 at the memory location pointed to by addr.
 
 The list of registers accessible using this interface is identical to the
-list in 4.64.
+list in 4.68.
 
 
 4.70 KVM_KVMCLOCK_CTRL
-- 
1.6.0.2

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


[PATCH 42/56] KVM: PPC: bookehv: Allow duplicate calls of DO_KVM macro

2012-10-04 Thread Alexander Graf
From: Mihai Caraman mihai.cara...@freescale.com

The current form of DO_KVM macro restricts its use to one call per input
parameter set. This is caused by kvmppc_resume_\intno\()_\srr1 symbol
definition.
Duplicate calls of DO_KVM are required by distinct implementations of
exeption handlers which are delegated at runtime. Use a rare label number
to avoid conflicts with the calling contexts.

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

diff --git a/arch/powerpc/include/asm/kvm_booke_hv_asm.h 
b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
index 30a600f..a37a12a 100644
--- a/arch/powerpc/include/asm/kvm_booke_hv_asm.h
+++ b/arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -38,9 +38,9 @@
 #ifdef CONFIG_KVM_BOOKE_HV
 BEGIN_FTR_SECTION
mtocrf  0x80, r11   /* check MSR[GS] without clobbering reg */
-   bf  3, kvmppc_resume_\intno\()_\srr1
+   bf  3, 1975f
b   kvmppc_handler_\intno\()_\srr1
-kvmppc_resume_\intno\()_\srr1:
+1975:
 END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV)
 #endif
 .endm
-- 
1.6.0.2

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


[PATCH 43/56] KVM: PPC: Book3S HV: Take the SRCU read lock before looking up memslots

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

The generic KVM code uses SRCU (sleeping RCU) to protect accesses
to the memslots data structures against updates due to userspace
adding, modifying or removing memory slots.  We need to do that too,
both to avoid accessing stale copies of the memslots and to avoid
lockdep warnings.  This therefore adds srcu_read_lock/unlock pairs
around code that accesses and uses memslots.

Since the real-mode handlers for H_ENTER, H_REMOVE and H_BULK_REMOVE
need to access the memslots, and we don't want to call the SRCU code
in real mode (since we have no assurance that it would only access
the linear mapping), we hold the SRCU read lock for the VM while
in the guest.  This does mean that adding or removing memory slots
while some vcpus are executing in the guest will block for up to
two jiffies.  This tradeoff is acceptable since adding/removing
memory slots only happens rarely, while H_ENTER/H_REMOVE/H_BULK_REMOVE
are performance-critical hot paths.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c |   17 +
 arch/powerpc/kvm/book3s_hv.c|   27 +++
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index d95d113..0f031c0 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -24,6 +24,7 @@
 #include linux/slab.h
 #include linux/hugetlb.h
 #include linux/vmalloc.h
+#include linux/srcu.h
 
 #include asm/tlbflush.h
 #include asm/kvm_ppc.h
@@ -1057,20 +1058,22 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned 
long gpa,
unsigned long hva, psize, offset;
unsigned long pa;
unsigned long *physp;
+   int srcu_idx;
 
+   srcu_idx = srcu_read_lock(kvm-srcu);
memslot = gfn_to_memslot(kvm, gfn);
if (!memslot || (memslot-flags  KVM_MEMSLOT_INVALID))
-   return NULL;
+   goto err;
if (!kvm-arch.using_mmu_notifiers) {
physp = kvm-arch.slot_phys[memslot-id];
if (!physp)
-   return NULL;
+   goto err;
physp += gfn - memslot-base_gfn;
pa = *physp;
if (!pa) {
if (kvmppc_get_guest_page(kvm, gfn, memslot,
  PAGE_SIZE)  0)
-   return NULL;
+   goto err;
pa = *physp;
}
page = pfn_to_page(pa  PAGE_SHIFT);
@@ -1079,9 +1082,11 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned 
long gpa,
hva = gfn_to_hva_memslot(memslot, gfn);
npages = get_user_pages_fast(hva, 1, 1, pages);
if (npages  1)
-   return NULL;
+   goto err;
page = pages[0];
}
+   srcu_read_unlock(kvm-srcu, srcu_idx);
+
psize = PAGE_SIZE;
if (PageHuge(page)) {
page = compound_head(page);
@@ -1091,6 +1096,10 @@ void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned 
long gpa,
if (nb_ret)
*nb_ret = psize - offset;
return page_address(page) + offset;
+
+ err:
+   srcu_read_unlock(kvm-srcu, srcu_idx);
+   return NULL;
 }
 
 void kvmppc_unpin_guest_page(struct kvm *kvm, void *va)
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 83e929e..48b0d4a 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -30,6 +30,7 @@
 #include linux/cpumask.h
 #include linux/spinlock.h
 #include linux/page-flags.h
+#include linux/srcu.h
 
 #include asm/reg.h
 #include asm/cputable.h
@@ -366,13 +367,16 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)
unsigned long req = kvmppc_get_gpr(vcpu, 3);
unsigned long target, ret = H_SUCCESS;
struct kvm_vcpu *tvcpu;
+   int idx;
 
switch (req) {
case H_ENTER:
+   idx = srcu_read_lock(vcpu-kvm-srcu);
ret = kvmppc_virtmode_h_enter(vcpu, kvmppc_get_gpr(vcpu, 4),
  kvmppc_get_gpr(vcpu, 5),
  kvmppc_get_gpr(vcpu, 6),
  kvmppc_get_gpr(vcpu, 7));
+   srcu_read_unlock(vcpu-kvm-srcu, idx);
break;
case H_CEDE:
break;
@@ -411,6 +415,7 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
  struct task_struct *tsk)
 {
int r = RESUME_HOST;
+   int srcu_idx;
 
vcpu-stat.sum_exits++;
 
@@ -470,12 +475,16 @@ static int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 * have been handled already.
 */

[PATCH 46/56] KVM: Move some PPC ioctl definitions to the correct place

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

This moves the definitions of KVM_CREATE_SPAPR_TCE and
KVM_ALLOCATE_RMA in include/linux/kvm.h from the section listing the
vcpu ioctls to the section listing VM ioctls, as these are both
implemented and documented as VM ioctls.

Fortunately there is no actual collision of ioctl numbers at this
point.  Moving these to the correct section will reduce the
probability of a future collision.  This does not change the
user/kernel ABI at all.

Signed-off-by: Paul Mackerras pau...@samba.org
Acked-by: Alexander Graf ag...@suse.de
Signed-off-by: Alexander Graf ag...@suse.de
---
 include/linux/kvm.h |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 41a9fd5..99c3c50 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -842,6 +842,9 @@ struct kvm_s390_ucas_mapping {
 #define KVM_PPC_GET_SMMU_INFO_IOR(KVMIO,  0xa6, struct kvm_ppc_smmu_info)
 /* Available with KVM_CAP_PPC_ALLOC_HTAB */
 #define KVM_PPC_ALLOCATE_HTAB_IOWR(KVMIO, 0xa7, __u32)
+#define KVM_CREATE_SPAPR_TCE _IOW(KVMIO,  0xa8, struct 
kvm_create_spapr_tce)
+/* Available with KVM_CAP_RMA */
+#define KVM_ALLOCATE_RMA _IOR(KVMIO,  0xa9, struct kvm_allocate_rma)
 
 /*
  * ioctls for vcpu fds
@@ -905,9 +908,6 @@ struct kvm_s390_ucas_mapping {
 /* Available with KVM_CAP_XCRS */
 #define KVM_GET_XCRS _IOR(KVMIO,  0xa6, struct kvm_xcrs)
 #define KVM_SET_XCRS _IOW(KVMIO,  0xa7, struct kvm_xcrs)
-#define KVM_CREATE_SPAPR_TCE _IOW(KVMIO,  0xa8, struct 
kvm_create_spapr_tce)
-/* Available with KVM_CAP_RMA */
-#define KVM_ALLOCATE_RMA _IOR(KVMIO,  0xa9, struct kvm_allocate_rma)
 /* Available with KVM_CAP_SW_TLB */
 #define KVM_DIRTY_TLB_IOW(KVMIO,  0xaa, struct kvm_dirty_tlb)
 /* Available with KVM_CAP_ONE_REG */
-- 
1.6.0.2

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


[PATCH 44/56] KVM: PPC: Move kvm-arch.slot_phys into memslot.arch

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

Now that we have an architecture-specific field in the kvm_memory_slot
structure, we can use it to store the array of page physical addresses
that we need for Book3S HV KVM on PPC970 processors.  This reduces the
size of struct kvm_arch for Book3S HV, and also reduces the size of
struct kvm_arch_memory_slot for other PPC KVM variants since the fields
in it are now only compiled in for Book3S HV.

This necessitates making the kvm_arch_create_memslot and
kvm_arch_free_memslot operations specific to each PPC KVM variant.
That in turn means that we now don't allocate the rmap arrays on
Book3S PR and Book E.

Since we now unpin pages and free the slot_phys array in
kvmppc_core_free_memslot, we no longer need to do it in
kvmppc_core_destroy_vm, since the generic code takes care to free
all the memslots when destroying a VM.

We now need the new memslot to be passed in to
kvmppc_core_prepare_memory_region, since we need to initialize its
arch.slot_phys member on Book3S HV.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_host.h |9 ++-
 arch/powerpc/include/asm/kvm_ppc.h  |5 ++
 arch/powerpc/kvm/book3s_64_mmu_hv.c |6 +-
 arch/powerpc/kvm/book3s_hv.c|  104 --
 arch/powerpc/kvm/book3s_hv_rm_mmu.c |2 +-
 arch/powerpc/kvm/book3s_pr.c|   12 
 arch/powerpc/kvm/booke.c|   12 
 arch/powerpc/kvm/powerpc.c  |   13 +---
 8 files changed, 102 insertions(+), 61 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index f20a5ef..68f5a30 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -204,7 +204,7 @@ struct revmap_entry {
 };
 
 /*
- * We use the top bit of each memslot-rmap entry as a lock bit,
+ * We use the top bit of each memslot-arch.rmap entry as a lock bit,
  * and bit 32 as a present flag.  The bottom 32 bits are the
  * index in the guest HPT of a HPTE that points to the page.
  */
@@ -215,14 +215,17 @@ struct revmap_entry {
 #define KVMPPC_RMAP_PRESENT0x1ul
 #define KVMPPC_RMAP_INDEX  0xul
 
-/* Low-order bits in kvm-arch.slot_phys[][] */
+/* Low-order bits in memslot-arch.slot_phys[] */
 #define KVMPPC_PAGE_ORDER_MASK 0x1f
 #define KVMPPC_PAGE_NO_CACHE   HPTE_R_I/* 0x20 */
 #define KVMPPC_PAGE_WRITETHRU  HPTE_R_W/* 0x40 */
 #define KVMPPC_GOT_PAGE0x80
 
 struct kvm_arch_memory_slot {
+#ifdef CONFIG_KVM_BOOK3S_64_HV
unsigned long *rmap;
+   unsigned long *slot_phys;
+#endif /* CONFIG_KVM_BOOK3S_64_HV */
 };
 
 struct kvm_arch {
@@ -246,8 +249,6 @@ struct kvm_arch {
unsigned long hpt_npte;
unsigned long hpt_mask;
spinlock_t slot_phys_lock;
-   unsigned long *slot_phys[KVM_MEM_SLOTS_NUM];
-   int slot_npages[KVM_MEM_SLOTS_NUM];
unsigned short last_vcpu[NR_CPUS];
struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
struct kvmppc_linear_info *hpt_li;
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index c06a64b..41a00ea 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -143,7 +143,12 @@ extern struct kvmppc_linear_info *kvm_alloc_hpt(void);
 extern void kvm_release_hpt(struct kvmppc_linear_info *li);
 extern int kvmppc_core_init_vm(struct kvm *kvm);
 extern void kvmppc_core_destroy_vm(struct kvm *kvm);
+extern void kvmppc_core_free_memslot(struct kvm_memory_slot *free,
+struct kvm_memory_slot *dont);
+extern int kvmppc_core_create_memslot(struct kvm_memory_slot *slot,
+ unsigned long npages);
 extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
+   struct kvm_memory_slot *memslot,
struct kvm_userspace_memory_region *mem);
 extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
struct kvm_userspace_memory_region *mem);
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 0f031c0..a389cc6 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -261,7 +261,7 @@ static void kvmppc_mmu_book3s_64_hv_reset_msr(struct 
kvm_vcpu *vcpu)
 
 /*
  * This is called to get a reference to a guest page if there isn't
- * one already in the kvm-arch.slot_phys[][] arrays.
+ * one already in the memslot-arch.slot_phys[] array.
  */
 static long kvmppc_get_guest_page(struct kvm *kvm, unsigned long gfn,
  struct kvm_memory_slot *memslot,
@@ -276,7 +276,7 @@ static long kvmppc_get_guest_page(struct kvm *kvm, unsigned 
long gfn,
struct vm_area_struct *vma;
unsigned long pfn, i, npages;
 
-   physp = kvm-arch.slot_phys[memslot-id];
+   physp = 

[PATCH 45/56] KVM: PPC: Book3S HV: Handle memory slot deletion and modification correctly

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

This adds an implementation of kvm_arch_flush_shadow_memslot for
Book3S HV, and arranges for kvmppc_core_commit_memory_region to
flush the dirty log when modifying an existing slot.  With this,
we can handle deletion and modification of memory slots.

kvm_arch_flush_shadow_memslot calls kvmppc_core_flush_memslot, which
on Book3S HV now traverses the reverse map chains to remove any HPT
(hashed page table) entries referring to pages in the memslot.  This
gets called by generic code whenever deleting a memslot or changing
the guest physical address for a memslot.

We flush the dirty log in kvmppc_core_commit_memory_region for
consistency with what x86 does.  We only need to flush when an
existing memslot is being modified, because for a new memslot the
rmap array (which stores the dirty bits) is all zero, meaning that
every page is considered clean already, and when deleting a memslot
we obviously don't care about the dirty bits any more.

Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s.h |2 +-
 arch/powerpc/include/asm/kvm_ppc.h|5 -
 arch/powerpc/kvm/book3s_64_mmu_hv.c   |   33 -
 arch/powerpc/kvm/book3s_hv.c  |   18 --
 arch/powerpc/kvm/book3s_hv_rm_mmu.c   |2 +-
 arch/powerpc/kvm/book3s_pr.c  |7 ++-
 arch/powerpc/kvm/booke.c  |7 ++-
 arch/powerpc/kvm/powerpc.c|3 ++-
 8 files changed, 64 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index f0e0c6a..ab73800 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -160,7 +160,7 @@ extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, 
unsigned long flags,
 extern long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
long pte_index, unsigned long pteh, unsigned long ptel);
 extern long kvmppc_hv_get_dirty_log(struct kvm *kvm,
-   struct kvm_memory_slot *memslot);
+   struct kvm_memory_slot *memslot, unsigned long *map);
 
 extern void kvmppc_entry_trampoline(void);
 extern void kvmppc_hv_entry_trampoline(void);
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 41a00ea..3fb980d 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -151,9 +151,12 @@ extern int kvmppc_core_prepare_memory_region(struct kvm 
*kvm,
struct kvm_memory_slot *memslot,
struct kvm_userspace_memory_region *mem);
 extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
-   struct kvm_userspace_memory_region *mem);
+   struct kvm_userspace_memory_region *mem,
+   struct kvm_memory_slot old);
 extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
  struct kvm_ppc_smmu_info *info);
+extern void kvmppc_core_flush_memslot(struct kvm *kvm,
+ struct kvm_memory_slot *memslot);
 
 extern int kvmppc_bookehv_init(void);
 extern void kvmppc_bookehv_exit(void);
diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index a389cc6..f598366 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -851,7 +851,8 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long 
*rmapp,
psize = hpte_page_size(hptep[0], ptel);
if ((hptep[0]  HPTE_V_VALID) 
hpte_rpn(ptel, psize) == gfn) {
-   hptep[0] |= HPTE_V_ABSENT;
+   if (kvm-arch.using_mmu_notifiers)
+   hptep[0] |= HPTE_V_ABSENT;
kvmppc_invalidate_hpte(kvm, hptep, i);
/* Harvest R and C */
rcbits = hptep[1]  (HPTE_R_R | HPTE_R_C);
@@ -878,6 +879,28 @@ int kvm_unmap_hva_range(struct kvm *kvm, unsigned long 
start, unsigned long end)
return 0;
 }
 
+void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot 
*memslot)
+{
+   unsigned long *rmapp;
+   unsigned long gfn;
+   unsigned long n;
+
+   rmapp = memslot-arch.rmap;
+   gfn = memslot-base_gfn;
+   for (n = memslot-npages; n; --n) {
+   /*
+* Testing the present bit without locking is OK because
+* the memslot has been marked invalid already, and hence
+* no new HPTEs referencing this page can be created,
+* thus the present bit can't go from 0 to 1.
+*/
+   if (*rmapp  KVMPPC_RMAP_PRESENT)
+   kvm_unmap_rmapp(kvm, rmapp, gfn);
+  

[PATCH 49/56] KVM: PPC: Book3S HV: Fix calculation of guest phys address for MMIO emulation

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

In the case where the host kernel is using a 64kB base page size and
the guest uses a 4k HPTE (hashed page table entry) to map an emulated
MMIO device, we were calculating the guest physical address wrongly.
We were calculating a gfn as the guest physical address shifted right
16 bits (PAGE_SHIFT) but then only adding back in 12 bits from the
effective address, since the HPTE had a 4k page size.  Thus the gpa
reported to userspace was missing 4 bits.

Instead, we now compute the guest physical address from the HPTE
without reference to the host page size, and then compute the gfn
by shifting the gpa right PAGE_SHIFT bits.

Reported-by: Alexey Kardashevskiy a...@ozlabs.ru
Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_64_mmu_hv.c |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c 
b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index f598366..7a4aae9 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -571,7 +571,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
struct kvm *kvm = vcpu-kvm;
unsigned long *hptep, hpte[3], r;
unsigned long mmu_seq, psize, pte_size;
-   unsigned long gfn, hva, pfn;
+   unsigned long gpa, gfn, hva, pfn;
struct kvm_memory_slot *memslot;
unsigned long *rmap;
struct revmap_entry *rev;
@@ -609,15 +609,14 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, 
struct kvm_vcpu *vcpu,
 
/* Translate the logical address and get the page */
psize = hpte_page_size(hpte[0], r);
-   gfn = hpte_rpn(r, psize);
+   gpa = (r  HPTE_R_RPN  ~(psize - 1)) | (ea  (psize - 1));
+   gfn = gpa  PAGE_SHIFT;
memslot = gfn_to_memslot(kvm, gfn);
 
/* No memslot means it's an emulated MMIO region */
-   if (!memslot || (memslot-flags  KVM_MEMSLOT_INVALID)) {
-   unsigned long gpa = (gfn  PAGE_SHIFT) | (ea  (psize - 1));
+   if (!memslot || (memslot-flags  KVM_MEMSLOT_INVALID))
return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea,
  dsisr  DSISR_ISSTORE);
-   }
 
if (!kvm-arch.using_mmu_notifiers)
return -EFAULT; /* should never get here */
-- 
1.6.0.2

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


[PATCH 50/56] KVM: PPC: e500: fix allocation size error on g2h_tlb1_map

2012-10-04 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

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 scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
Cc: sta...@vger.kernel.org
---
 arch/powerpc/kvm/e500_tlb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

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

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


[PATCH 51/56] KVM: PPC: e500: MMU API: fix leak of shared_tlb_pages

2012-10-04 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

This was found by kmemleak.

Signed-off-by: Scott Wood scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500_tlb.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

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

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


[PATCH 52/56] KVM: PPC: set IN_GUEST_MODE before checking requests

2012-10-04 Thread Alexander Graf
From: Scott Wood scottw...@freescale.com

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 scottw...@freescale.com
Signed-off-by: Alexander Graf ag...@suse.de
---
 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 69d047c..3d1f35d 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 6002ea9..deb0d59 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.6.0.2

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


[PATCH 48/56] KVM: PPC: Book3S HV: Remove bogus update of physical thread IDs

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

When making a vcpu non-runnable we incorrectly changed the
thread IDs of all other threads on the core, just remove that
code.

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_hv.c |6 --
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 38c7f1b..c9ae314 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -706,17 +706,11 @@ extern void xics_wake_cpu(int cpu);
 static void kvmppc_remove_runnable(struct kvmppc_vcore *vc,
   struct kvm_vcpu *vcpu)
 {
-   struct kvm_vcpu *v;
-
if (vcpu-arch.state != KVMPPC_VCPU_RUNNABLE)
return;
vcpu-arch.state = KVMPPC_VCPU_BUSY_IN_HOST;
--vc-n_runnable;
++vc-n_busy;
-   /* decrement the physical thread id of each following vcpu */
-   v = vcpu;
-   list_for_each_entry_continue(v, vc-runnable_threads, arch.run_list)
-   --v-arch.ptid;
list_del(vcpu-arch.run_list);
 }
 
-- 
1.6.0.2

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


[PATCH 53/56] KVM: PPC: Book3S: Get/set guest SPRs using the GET/SET_ONE_REG interface

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

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 pau...@samba.org
[agraf: minimal style fixes]
Signed-off-by: Alexander Graf ag...@suse.de
---
 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..8e87a53 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 linux/types.h
 #include 

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

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

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 pau...@samba.org
[agraf: fix whitespace, vsx compilation]
Signed-off-by: Alexander Graf ag...@suse.de
---
 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   |   26 +++
 6 files changed, 149 insertions(+), 0 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 8e87a53..975bb4c 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]);
+  

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

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

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 pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 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 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index 975bb4c..2a4d868 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:
+   

[PATCH 56/56] arch/powerpc/kvm/e500_tlb.c: fix error return code

2012-10-04 Thread Alexander Graf
From: Julia Lawall ju...@diku.dk

Convert a 0 error return code to a negative one, as returned elsewhere in the
function.

A new label is also added to avoid freeing things that are known to not yet
be allocated.

A simplified version of the semantic match that finds the first problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
@@
identifier ret;
expression e,e1,e2,e3,e4,x;
@@

(
if (\(ret != 0\|ret  0\) || ...) { ... return ...; }
|
ret = 0
)
... when != ret = e1
*x = 
\(kmalloc\|kzalloc\|kcalloc\|devm_kzalloc\|ioremap\|ioremap_nocache\|devm_ioremap\|devm_ioremap_nocache\)(...);
... when != x = e2
when != ret = e3
*if (x == NULL || ...)
{
  ... when != ret = e4
*  return ret;
}
// /smpl

Signed-off-by: Julia Lawall ju...@diku.dk
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/e500_tlb.c |   19 +--
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kvm/e500_tlb.c b/arch/powerpc/kvm/e500_tlb.c
index 641f978..c733894 100644
--- a/arch/powerpc/kvm/e500_tlb.c
+++ b/arch/powerpc/kvm/e500_tlb.c
@@ -1233,21 +1233,27 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
}
 
virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL);
-   if (!virt)
+   if (!virt) {
+   ret = -ENOMEM;
goto err_put_page;
+   }
 
privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
   GFP_KERNEL);
privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
   GFP_KERNEL);
 
-   if (!privs[0] || !privs[1])
-   goto err_put_page;
+   if (!privs[0] || !privs[1]) {
+   ret = -ENOMEM;
+   goto err_privs;
+   }
 
g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
 GFP_KERNEL);
-   if (!g2h_bitmap)
-   goto err_put_page;
+   if (!g2h_bitmap) {
+   ret = -ENOMEM;
+   goto err_privs;
+   }
 
free_gtlb(vcpu_e500);
 
@@ -1287,10 +1293,11 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
kvmppc_recalc_tlb1map_range(vcpu_e500);
return 0;
 
-err_put_page:
+err_privs:
kfree(privs[0]);
kfree(privs[1]);
 
+err_put_page:
for (i = 0; i  num_pages; i++)
put_page(pages[i]);
 
-- 
1.6.0.2

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


[PATCH 47/56] KVM: PPC: Book3S HV: Fix updates of vcpu-cpu

2012-10-04 Thread Alexander Graf
From: Paul Mackerras pau...@samba.org

This removes the powerpc generic updates of vcpu-cpu in load and
put, and moves them to the various backends.

The reason is that HV KVM does its own sauce with that field
and the generic updates might corrupt it. The field contains the
CPU# of the -first- HW CPU of the core always for all the VCPU
threads of a core (the one that's online from a host Linux
perspective).

However, the preempt notifiers are going to be called on the
threads VCPUs when they are running (due to them sleeping on our
private waitqueue) causing unload to be called, potentially
clobbering the value.

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Signed-off-by: Paul Mackerras pau...@samba.org
Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_pr.c |3 ++-
 arch/powerpc/kvm/booke.c |2 ++
 arch/powerpc/kvm/powerpc.c   |2 --
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 4d0667a..bf3ec5d 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -64,7 +64,7 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
svcpu-slb_max = to_book3s(vcpu)-slb_shadow_max;
svcpu_put(svcpu);
 #endif
-
+   vcpu-cpu = smp_processor_id();
 #ifdef CONFIG_PPC_BOOK3S_32
current-thread.kvm_shadow_vcpu = to_book3s(vcpu)-shadow_vcpu;
 #endif
@@ -84,6 +84,7 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
kvmppc_giveup_ext(vcpu, MSR_FP);
kvmppc_giveup_ext(vcpu, MSR_VEC);
kvmppc_giveup_ext(vcpu, MSR_VSX);
+   vcpu-cpu = -1;
 }
 
 int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 3a6490f..69d047c 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1509,12 +1509,14 @@ void kvmppc_decrementer_func(unsigned long data)
 
 void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+   vcpu-cpu = smp_processor_id();
current-thread.kvm_vcpu = vcpu;
 }
 
 void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)
 {
current-thread.kvm_vcpu = NULL;
+   vcpu-cpu = -1;
 }
 
 int __init kvmppc_booke_init(void)
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 8443e23..6002ea9 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -504,7 +504,6 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
mtspr(SPRN_VRSAVE, vcpu-arch.vrsave);
 #endif
kvmppc_core_vcpu_load(vcpu, cpu);
-   vcpu-cpu = smp_processor_id();
 }
 
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
@@ -513,7 +512,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 #ifdef CONFIG_BOOKE
vcpu-arch.vrsave = mfspr(SPRN_VRSAVE);
 #endif
-   vcpu-cpu = -1;
 }
 
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
-- 
1.6.0.2

--
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 6/6] KVM: booke/bookehv: Add debug stub support

2012-10-04 Thread Bhushan Bharat-R65777


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, October 04, 2012 4:56 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
 On 04.10.2012, at 13:06, Bhushan Bharat-R65777 wrote:
 
 
 
  -Original Message-
  From: Alexander Graf [mailto:ag...@suse.de]
  Sent: Monday, September 24, 2012 9:50 PM
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan
  Bharat-R65777
  Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
  On 21.08.2012, at 15:52, 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 bharat.bhus...@freescale.com
  ---
  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 linux/kvm.h */ #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 {
  + __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;
  };
 
  /* for KVM_SET_GUEST_DEBUG */
  @@ -276,10 +301,6 @@ struct kvm_guest_debug_arch {
 * Type denotes h/w breakpoint, read watchpoint, write
 * watchpoint or watchpoint (both read and write).
 */
  -#define KVMPPC_DEBUG_NOTYPE  0x0
  -#define KVMPPC_DEBUG_BREAKPOINT  (1UL  1)
  -#define KVMPPC_DEBUG_WATCH_WRITE (1UL  2)
  -#define KVMPPC_DEBUG_WATCH_READ  (1UL  3)
__u32 type;
__u32 pad1;
__u64 pad2;
  diff --git a/arch/powerpc/include/asm/kvm_host.h
  b/arch/powerpc/include/asm/kvm_host.h
  index c7219c1..3ba465a 100644
  --- a/arch/powerpc/include/asm/kvm_host.h
  +++ b/arch/powerpc/include/asm/kvm_host.h
  @@ -496,7 +496,12 @@ struct kvm_vcpu_arch {
u32 mmucfg;
u32 epr;
u32 crit_save;
  + /* guest debug registers*/
struct kvmppc_booke_debug_reg dbg_reg;
  + /* shadow debug registers */
  + struct kvmppc_booke_debug_reg shadow_dbg_reg;
  + /* host debug registers*/
  + struct kvmppc_booke_debug_reg host_dbg_reg;
  #endif
gpa_t paddr_accessed;
gva_t vaddr_accessed;
  diff --git a/arch/powerpc/kernel/asm-offsets.c
  b/arch/powerpc/kernel/asm-
  offsets.c
  index 555448e..6987821 100644
  --- a/arch/powerpc/kernel/asm-offsets.c
  +++ b/arch/powerpc/kernel/asm-offsets.c
  @@ -564,6 +564,32 @@ int main(void)
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
  + DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr));
  + DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
  + DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
  + DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg,
  +   dbcr0));
  + DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg,
  +   dbcr1));
  + DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg,
  +   dbcr2));
  +#ifdef CONFIG_KVM_E500MC
  + DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg,
  +  

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

2012-10-04 Thread Alexander Graf

On 04.10.2012, at 16:22, Bhushan Bharat-R65777 wrote:

 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Thursday, October 04, 2012 4:56 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
 On 04.10.2012, at 13:06, Bhushan Bharat-R65777 wrote:
 
 
 
 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Monday, September 24, 2012 9:50 PM
 To: Bhushan Bharat-R65777
 Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; Bhushan
 Bharat-R65777
 Subject: Re: [PATCH 6/6] KVM: booke/bookehv: Add debug stub support
 
 
 On 21.08.2012, at 15:52, 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 bharat.bhus...@freescale.com
 ---
 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 linux/kvm.h */ #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 {
 + __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;
 };
 
 /* for KVM_SET_GUEST_DEBUG */
 @@ -276,10 +301,6 @@ struct kvm_guest_debug_arch {
* Type denotes h/w breakpoint, read watchpoint, write
* watchpoint or watchpoint (both read and write).
*/
 -#define KVMPPC_DEBUG_NOTYPE  0x0
 -#define KVMPPC_DEBUG_BREAKPOINT  (1UL  1)
 -#define KVMPPC_DEBUG_WATCH_WRITE (1UL  2)
 -#define KVMPPC_DEBUG_WATCH_READ  (1UL  3)
   __u32 type;
   __u32 pad1;
   __u64 pad2;
 diff --git a/arch/powerpc/include/asm/kvm_host.h
 b/arch/powerpc/include/asm/kvm_host.h
 index c7219c1..3ba465a 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -496,7 +496,12 @@ struct kvm_vcpu_arch {
   u32 mmucfg;
   u32 epr;
   u32 crit_save;
 + /* guest debug registers*/
   struct kvmppc_booke_debug_reg dbg_reg;
 + /* shadow debug registers */
 + struct kvmppc_booke_debug_reg shadow_dbg_reg;
 + /* host debug registers*/
 + struct kvmppc_booke_debug_reg host_dbg_reg;
 #endif
   gpa_t paddr_accessed;
   gva_t vaddr_accessed;
 diff --git a/arch/powerpc/kernel/asm-offsets.c
 b/arch/powerpc/kernel/asm-
 offsets.c
 index 555448e..6987821 100644
 --- a/arch/powerpc/kernel/asm-offsets.c
 +++ b/arch/powerpc/kernel/asm-offsets.c
 @@ -564,6 +564,32 @@ int main(void)
   DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
   DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
   DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
 + DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr));
 + DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
 + DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
 + DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg,
 +   dbcr0));
 + DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg,
 +   dbcr1));
 + DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg,
 +   dbcr2));
 +#ifdef CONFIG_KVM_E500MC
 + DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg,
 +   dbcr4));
 +#endif
 + 

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

2012-10-04 Thread Bhushan Bharat-R65777


  -static int emulation_exit(struct kvm_run *run, struct kvm_vcpu
  *vcpu)
  +static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
  + int exit_nr)
  {
  enum emulation_result er;
 
  +   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP) 
  +vcpu-arch.last_inst == KVMPPC_INST_GUEST_GDB) {
 
  This belongs into the normal emulation code path, behind the same
  switch() that everything else goes through.
 
  I am not sure I understood correctly. Below is the reason why I
  placed this
  code here.
  Instruction where software breakpoint is to be set is replaced by ehpriv
  instruction. On e500v2, this is not a valid instruction can causes
  program interrupt. On e500mc, ehpriv is a valid instruction. Both
  the exit path calls emulation_exit(), so we have placed the code in this
 function.
  Do you want this code to be moved in program interrupt exit path for
  e500v2
  and BOOKE_INTERRUPT_HV_PRIV for e500mc?
 
  Ok, in this patch you do (basically):
 
  int emulation_exit()
  {
 if (inst == DEBUG_INST) {
 debug_stuff();
 return;
 }
 
 switch (inst) {
 case INST_A:
 foo();
 
 }
  }
 
  Are not we doing something like this:
  int emulation_exit()
  {
  if (inst == DEBUG_INST) {
  debug_stuff();
  return;
  }
 
  status = kvmppc_emulate_instruction()
  switch (status) {
  case FAIL:
  foo();
  case DONE:
  foo1();
  
  }
  }
 
  Do you want something like this:
 
  int emulation_exit()
  {
 
  status = kvmppc_emulate_instruction()
  switch (status) {
  case FAIL:
  if (inst == DEBUG_INST) {
  debug_stuff();
return;
  }
  foo();
 
  case DONE:
  foo1();
  
  }
  }
 
 No, I want the DEBUG_INST be handled the same as any other instruction we
 emulate.

I would like to understand what you are thinking:
What I derived is , add the instruction in kvmppc_emulate_instruction() (or its 
child function) which, 
1) fill the relevant information in run- , kvmppc_account_exit(vcpu, 
DEBUG_EXITS); and returns EMULATION_DONE
 And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
case EMULATION_DONE:
if (inst == DEBUG)
return RESUME_HOST;
 }
 Or
2) kvmppc_account_exit(vcpu, DEBUG_EXITS); returns EMULATION_DONE;
And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
case EMULATION_DONE:
if (inst == DEBUG) {
fill run- 
return RESUME_HOST;
}
 }

Or
3) kvmppc_account_exit(vcpu, DEBUG_EXITS); returns a new status type 
(EMULATION_DEBUG_INST)
And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
case EMULATION_DEBUG_INST:
fill run- 
return RESUME_HOST;
 }

 
 
  what I want is:
 
  int emulation_exit()
  {
 switch (inst) {
 case INST_A:
 foo(); break;
 case DEBUG_INST:
 debug_stuff(); break;
 
 }
  }
 
 
 
 
  +   run-exit_reason = KVM_EXIT_DEBUG;
  +   run-debug.arch.pc = vcpu-arch.pc;
  +   run-debug.arch.exception = exit_nr;
  +   run-debug.arch.status = 0;
  +   kvmppc_account_exit(vcpu, DEBUG_EXITS);
  +   return RESUME_HOST;
  +   }
  +
  er = kvmppc_emulate_instruction(run, vcpu);
  switch (er) {
  case EMULATE_DONE:
  @@ -697,6 +711,44 @@ static int emulation_exit(struct kvm_run
  *run, struct
  kvm_vcpu *vcpu)
  default:
  BUG();
  }
  +
  +   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_ENABLE) 
  +   (vcpu-guest_debug  KVM_GUESTDBG_SINGLESTEP)) {
 
  I don't understand how this is supposed to work. When we enable
  singlestep, why would we end up in emulation_exit()?
 
  When singlestep is enabled then we set DBCR0[ICMP] and the debug
  handler
  should be able to handle this. I think you are right.
 
 
  +   run-exit_reason = KVM_EXIT_DEBUG;
  +   return RESUME_HOST;
  +   }
  +}
  +
  +static int kvmppc_handle_debug(struct kvm_run *run, struct
  +kvm_vcpu
  +*vcpu) {
  +   u32 dbsr;
  +
  +#ifndef CONFIG_KVM_BOOKE_HV
  +   if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
  +   vcpu-arch.pc = mfspr(SPRN_DSRR0);
  +   else
  +   vcpu-arch.pc = mfspr(SPRN_CSRR0); #endif
 
  Why doesn't this get handled in the asm code that recovers from the
  respective exceptions?
 
  Yes. I will remove this.
 
 
  +   dbsr = vcpu-arch.dbsr;
  +
  +   run-debug.arch.pc = vcpu-arch.pc;
  +   

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

2012-10-04 Thread Alexander Graf

On 04.10.2012, at 17:19, Bhushan Bharat-R65777 wrote:

 
 
 -static int emulation_exit(struct kvm_run *run, struct kvm_vcpu
 *vcpu)
 +static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 + int exit_nr)
 {
 enum emulation_result er;
 
 +   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_USE_SW_BP) 
 +vcpu-arch.last_inst == KVMPPC_INST_GUEST_GDB) {
 
 This belongs into the normal emulation code path, behind the same
 switch() that everything else goes through.
 
 I am not sure I understood correctly. Below is the reason why I
 placed this
 code here.
 Instruction where software breakpoint is to be set is replaced by ehpriv
 instruction. On e500v2, this is not a valid instruction can causes
 program interrupt. On e500mc, ehpriv is a valid instruction. Both
 the exit path calls emulation_exit(), so we have placed the code in this
 function.
 Do you want this code to be moved in program interrupt exit path for
 e500v2
 and BOOKE_INTERRUPT_HV_PRIV for e500mc?
 
 Ok, in this patch you do (basically):
 
 int emulation_exit()
 {
   if (inst == DEBUG_INST) {
   debug_stuff();
   return;
   }
 
   switch (inst) {
   case INST_A:
   foo();
   
   }
 }
 
 Are not we doing something like this:
 int emulation_exit()
 {
if (inst == DEBUG_INST) {
debug_stuff();
return;
}
 
status = kvmppc_emulate_instruction()
switch (status) {
case FAIL:
foo();
case DONE:
 foo1();

}
 }
 
 Do you want something like this:
 
 int emulation_exit()
 {
 
status = kvmppc_emulate_instruction()
switch (status) {
case FAIL:
 if (inst == DEBUG_INST) {
 debug_stuff();
   return;
 }
foo();
 
case DONE:
 foo1();

}
 }
 
 No, I want the DEBUG_INST be handled the same as any other instruction we
 emulate.
 
 I would like to understand what you are thinking:
 What I derived is , add the instruction in kvmppc_emulate_instruction() (or 
 its child function) which, 
 1) fill the relevant information in run- , kvmppc_account_exit(vcpu, 
 DEBUG_EXITS); and returns EMULATION_DONE
 And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
   case EMULATION_DONE:
   if (inst == DEBUG)
   return RESUME_HOST;
 }
 Or
 2) kvmppc_account_exit(vcpu, DEBUG_EXITS); returns EMULATION_DONE;
 And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
   case EMULATION_DONE:
   if (inst == DEBUG) {
   fill run- 
   return RESUME_HOST;
   }
 }
 
 Or
 3) kvmppc_account_exit(vcpu, DEBUG_EXITS); returns a new status type 
 (EMULATION_DEBUG_INST)
 And in emulation_exit()
 status = kvmppc_emulate_instruction()
 switch (status) {
   case EMULATION_DEBUG_INST:
   fill run- 
   return RESUME_HOST;
 }

This one :).

 
 
 
 what I want is:
 
 int emulation_exit()
 {
   switch (inst) {
   case INST_A:
   foo(); break;
   case DEBUG_INST:
   debug_stuff(); break;
   
   }
 }
 
 
 
 
 +   run-exit_reason = KVM_EXIT_DEBUG;
 +   run-debug.arch.pc = vcpu-arch.pc;
 +   run-debug.arch.exception = exit_nr;
 +   run-debug.arch.status = 0;
 +   kvmppc_account_exit(vcpu, DEBUG_EXITS);
 +   return RESUME_HOST;
 +   }
 +
 er = kvmppc_emulate_instruction(run, vcpu);
 switch (er) {
 case EMULATE_DONE:
 @@ -697,6 +711,44 @@ static int emulation_exit(struct kvm_run
 *run, struct
 kvm_vcpu *vcpu)
 default:
 BUG();
 }
 +
 +   if (unlikely(vcpu-guest_debug  KVM_GUESTDBG_ENABLE) 
 +   (vcpu-guest_debug  KVM_GUESTDBG_SINGLESTEP)) {
 
 I don't understand how this is supposed to work. When we enable
 singlestep, why would we end up in emulation_exit()?
 
 When singlestep is enabled then we set DBCR0[ICMP] and the debug
 handler
 should be able to handle this. I think you are right.
 
 
 +   run-exit_reason = KVM_EXIT_DEBUG;
 +   return RESUME_HOST;
 +   }
 +}
 +
 +static int kvmppc_handle_debug(struct kvm_run *run, struct
 +kvm_vcpu
 +*vcpu) {
 +   u32 dbsr;
 +
 +#ifndef CONFIG_KVM_BOOKE_HV
 +   if (cpu_has_feature(CPU_FTR_DEBUG_LVL_EXC))
 +   vcpu-arch.pc = mfspr(SPRN_DSRR0);
 +   else
 +   vcpu-arch.pc = mfspr(SPRN_CSRR0); #endif
 
 Why doesn't this get handled in the asm code that recovers from the
 respective exceptions?
 
 Yes. I will remove this.
 
 
 +   dbsr = vcpu-arch.dbsr;
 +
 +   run-debug.arch.pc = vcpu-arch.pc;
 +   run-debug.arch.status = 0;
 +   vcpu-arch.dbsr = 0;
 +
 +   if (dbsr  (DBSR_IAC1 | DBSR_IAC2 

[PATCH 1/3] kvm tools: Fix powerpc build errors caused by recent changes

2012-10-04 Thread Michael Ellerman
Several caused by commit 8074303 remove global kvm object,
ioport__setup_arch(), term_getc_iov()  term_getc() in the
spapr_hvcons.c code, and kvm_cpu__reboot() in rtas_power_off().

Commit 221b584 move active_console into struct kvm_config added
checks in h_put_term_char()  h_get_term_char() of
kvm-cfg.active_console but needs to be vcpu-kvm-cfg.active_console.

That commit also missed updates to term_putc()  term_getc() in
spapr_rtas.c, and I'm guessing that we need similar checks of
active_console in rtas_put_term_char()  rtas_get_term_char().

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
 tools/kvm/powerpc/ioport.c   |2 +-
 tools/kvm/powerpc/spapr_hvcons.c |6 +++---
 tools/kvm/powerpc/spapr_rtas.c   |   14 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/tools/kvm/powerpc/ioport.c b/tools/kvm/powerpc/ioport.c
index a8e4dc3..264fb7e 100644
--- a/tools/kvm/powerpc/ioport.c
+++ b/tools/kvm/powerpc/ioport.c
@@ -12,7 +12,7 @@
 
 #include stdlib.h
 
-void ioport__setup_arch(void)
+void ioport__setup_arch(struct kvm *kvm)
 {
/* PPC has no legacy ioports to set up */
 }
diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c
index 1fe4bdb..0bdf75b 100644
--- a/tools/kvm/powerpc/spapr_hvcons.c
+++ b/tools/kvm/powerpc/spapr_hvcons.c
@@ -50,7 +50,7 @@ static unsigned long h_put_term_char(struct kvm_cpu *vcpu, 
unsigned long opcode,
do {
int ret;
 
-   if (kvm-cfg.active_console == CONSOLE_HV)
+   if (vcpu-kvm-cfg.active_console == CONSOLE_HV)
ret = term_putc_iov(iov, 1, 0);
else
ret = 0;
@@ -74,14 +74,14 @@ static unsigned long h_get_term_char(struct kvm_cpu *vcpu, 
unsigned long opcode,
union hv_chario data;
struct iovec iov;
 
-   if (kvm-cfg.active_console != CONSOLE_HV)
+   if (vcpu-kvm-cfg.active_console != CONSOLE_HV)
return H_SUCCESS;
 
if (term_readable(0)) {
iov.iov_base = data.buf;
iov.iov_len = 16;
 
-   *len = term_getc_iov(iov, 1, 0);
+   *len = term_getc_iov(vcpu-kvm, iov, 1, 0);
*char0_7 = be64_to_cpu(data.a.char0_7);
*char8_15 = be64_to_cpu(data.a.char8_15);
} else {
diff --git a/tools/kvm/powerpc/spapr_rtas.c b/tools/kvm/powerpc/spapr_rtas.c
index 14a3462..c81d82b 100644
--- a/tools/kvm/powerpc/spapr_rtas.c
+++ b/tools/kvm/powerpc/spapr_rtas.c
@@ -41,7 +41,7 @@ static void rtas_display_character(struct kvm_cpu *vcpu,
uint32_t nret, target_ulong rets)
 {
char c = rtas_ld(vcpu-kvm, args, 0);
-   term_putc(CONSOLE_HV, c, 1, 0);
+   term_putc(c, 1, 0);
rtas_st(vcpu-kvm, rets, 0, 0);
 }
 
@@ -52,7 +52,10 @@ static void rtas_put_term_char(struct kvm_cpu *vcpu,
   uint32_t nret, target_ulong rets)
 {
char c = rtas_ld(vcpu-kvm, args, 0);
-   term_putc(CONSOLE_HV, c, 1, 0);
+
+   if (vcpu-kvm-cfg.active_console == CONSOLE_HV)
+   term_putc(c, 1, 0);
+
rtas_st(vcpu-kvm, rets, 0, 0);
 }
 
@@ -62,8 +65,9 @@ static void rtas_get_term_char(struct kvm_cpu *vcpu,
   uint32_t nret, target_ulong rets)
 {
int c;
-   if (term_readable(CONSOLE_HV, 0) 
-   (c = term_getc(CONSOLE_HV, 0)) = 0) {
+
+   if (vcpu-kvm-cfg.active_console == CONSOLE_HV  term_readable(0) 
+   (c = term_getc(vcpu-kvm, 0)) = 0) {
rtas_st(vcpu-kvm, rets, 0, 0);
rtas_st(vcpu-kvm, rets, 1, c);
} else {
@@ -115,7 +119,7 @@ static void rtas_power_off(struct kvm_cpu *vcpu,
rtas_st(vcpu-kvm, rets, 0, -3);
return;
}
-   kvm_cpu__reboot();
+   kvm_cpu__reboot(vcpu-kvm);
 }
 
 static void rtas_query_cpu_stopped_state(struct kvm_cpu *vcpu,
-- 
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


[PATCH 2/3] kvm tools: Fix segfault on powerpc in xics_register()

2012-10-04 Thread Michael Ellerman
In commit 06e6648 move kvm_cpus into struct kvm, kvm_cpu__init() became
kvm_cpu__arch_init() called from a new kvm_cpu__init(), and the call was moved
from the end of the init sequence to much earlier, and in particular prior to
irq__init().

This leads to a segfault on powerpc, because kvm_cpu__arch_init() calls into
xics_cpu_register(), which dereferences vcpu-kvm.icp which is uninitialised
until irq__init().

Later in commit a48488d use init/exit where possible, irq__init() was pulled
out of the init sequence and made a dev_base_init() routine, on x86. On powerpc
the call to irq__init() was dropped entirely.

Finally, we now have a circular dependency between kvm_cpu__init() (which needs
kvm-arch.icp), and irq__init() (which needs kvm-nrcpus). This is caused by
the combination of commit 89f40a7 move nrcpus into struct kvm_config,
which moved the global nrcpus into kvm-cfg, and commit 06e6648 move kvm_cpus
into struct kvm, which moved the setup of kvm-nrcpus from kvm-cfg into
kvm_cpu__init().

To fix it we drop irq__init() entirely, if we ever have a non xics irq option
we can bring it back. We turn xics_system_init() into xics_init(), and have it
do the allocation and setup of the icp/ics, including the per-vcpu setup,
removing the dependency from kvm_cpu__init() (via kvm_cpu__arch_init()).

xics_init() is a base_init() routine, it can't be core, which should be early
enough, fingers crossed.

Finally drop irq__exit(), it does nothing and is never called.

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
 tools/kvm/powerpc/irq.c |   19 ---
 tools/kvm/powerpc/kvm-cpu.c |3 ---
 tools/kvm/powerpc/xics.c|   38 +++---
 tools/kvm/powerpc/xics.h|5 -
 4 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index 6d134c5..e89fa3b 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -26,8 +26,6 @@
 #include xics.h
 #include spapr_pci.h
 
-#define XICS_IRQS   1024
-
 /*
  * FIXME: The code in this file assumes an SPAPR guest, using XICS.  Make
  * generic  cope with multiple PPC platform types.
@@ -51,23 +49,6 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
return 0;
 }
 
-int irq__init(struct kvm *kvm)
-{
-   /*
-* kvm-nr_cpus is now valid; for /now/, pass
-* this to xics_system_init(), which assumes servers
-* are numbered 0..nrcpus.  This may not really be true,
-* but it is OK currently.
-*/
-   kvm-arch.icp = xics_system_init(XICS_IRQS, kvm-nrcpus);
-   return 0;
-}
-
-int irq__exit(struct kvm *kvm)
-{
-   return 0;
-}
-
 int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
 {
die(__FUNCTION__);
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 6aaf424..8fce121 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -93,9 +93,6 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned 
long cpu_id)
 */
vcpu-is_running = true;
 
-   /* Register with IRQ controller (FIXME, assumes XICS) */
-   xics_cpu_register(vcpu);
-
return vcpu;
 }
 
diff --git a/tools/kvm/powerpc/xics.c b/tools/kvm/powerpc/xics.c
index 1cf9558..d4b5caa 100644
--- a/tools/kvm/powerpc/xics.c
+++ b/tools/kvm/powerpc/xics.c
@@ -18,6 +18,8 @@
 #include stdio.h
 #include malloc.h
 
+#define XICS_NUM_IRQS  1024
+
 
 /* #define DEBUG_XICS yes */
 #ifdef DEBUG_XICS
@@ -441,26 +443,19 @@ static void rtas_int_on(struct kvm_cpu *vcpu, uint32_t 
token,
rtas_st(vcpu-kvm, rets, 0, 0); /* Success */
 }
 
-void xics_cpu_register(struct kvm_cpu *vcpu)
-{
-   if (vcpu-cpu_id  vcpu-kvm-arch.icp-nr_servers)
-   vcpu-kvm-arch.icp-ss[vcpu-cpu_id].cpu = vcpu;
-   else
-   die(Setting invalid server for cpuid %ld\n, vcpu-cpu_id);
-}
-
-struct icp_state *xics_system_init(unsigned int nr_irqs, unsigned int nr_cpus)
+static int xics_init(struct kvm *kvm)
 {
int max_server_num;
unsigned int i;
struct icp_state *icp;
struct ics_state *ics;
+   int j;
 
-   max_server_num = nr_cpus;
+   max_server_num = kvm-nrcpus;
 
icp = malloc(sizeof(*icp));
icp-nr_servers = max_server_num + 1;
-   icp-ss = malloc(icp-nr_servers*sizeof(struct icp_server_state));
+   icp-ss = malloc(icp-nr_servers * sizeof(struct icp_server_state));
 
for (i = 0; i  icp-nr_servers; i++) {
icp-ss[i].xirr = 0;
@@ -475,14 +470,14 @@ struct icp_state *xics_system_init(unsigned int nr_irqs, 
unsigned int nr_cpus)
 */
 
ics = malloc(sizeof(*ics));
-   ics-nr_irqs = nr_irqs;
+   ics-nr_irqs = XICS_NUM_IRQS;
ics-offset = XICS_IRQ_OFFSET;
-   ics-irqs = malloc(nr_irqs * sizeof(struct ics_irq_state));
+   ics-irqs = malloc(ics-nr_irqs * sizeof(struct ics_irq_state));
 
icp-ics = ics;
  

[PATCH 3/3] kvm tools: Do setup_fdt() later, get powerpc to boot again

2012-10-04 Thread Michael Ellerman
In commit e3d3ced kernel load/firmware cleanup, the call to
kvm__arch_setup_firmware() was moved. Previously more or less at the end
of the init sequence, but that commit moved it into kvm__init() which
is a core_init() call and so runs quite early.

This broke booting powerpc guests, as setup_fdt() needs to be called
later in the setup sequence. In particular it looks at kvm-nrcpus,
which is uninitialised at that point.

In general setup_fdt() needs to run late in the sequence, as it encodes
the setup of the machine into the device tree.

So move setup_fdt() out of kvm__arch_setup_firmware() and make it a
firmware_init() call of its own.

With this patch I am able to boot guests again on HV KVM.

Signed-off-by: Michael Ellerman mich...@ellerman.id.au
---
 tools/kvm/powerpc/kvm.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index e4f5315..d675265 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -286,7 +286,7 @@ static void generate_segment_page_sizes(struct 
kvm_ppc_smmu_info *info, struct f
  * and whilst most PPC targets will require CPU/memory nodes, others like RTAS
  * should eventually be added separately.
  */
-static void setup_fdt(struct kvm *kvm)
+static int setup_fdt(struct kvm *kvm)
 {
uint64_tmem_reg_property[] = { 0, cpu_to_be64(kvm-ram_size) };
int smp_cpus = kvm-nrcpus;
@@ -488,7 +488,10 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_pack(fdt_dest));
 
free(segment_page_sizes.value);
+
+   return 0;
 }
+firmware_init(setup_fdt);
 
 /**
  * kvm__arch_setup_firmware
@@ -517,9 +520,6 @@ int kvm__arch_setup_firmware(struct kvm *kvm)
 
/* Load SLOF */
 
-   /* Init FDT */
-   setup_fdt(kvm);
-
return 0;
 }
 
-- 
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