[PATCH] PPC: Sync guest visible MMU state

2009-11-30 Thread Alexander Graf
Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.

v2 - v3:

  - don't use anonymous unions/structs

v3 - v4:

  - don't change API to what it was before
---
 arch/powerpc/include/asm/kvm.h|   18 +++-
 arch/powerpc/include/asm/kvm_asm.h|1 +
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/kvm/book3s.c |   49 +
 arch/powerpc/kvm/book3s_64_emulate.c  |   38 +++--
 arch/powerpc/kvm/book3s_64_mmu.c  |2 +
 arch/powerpc/kvm/powerpc.c|3 ++
 include/linux/kvm.h   |3 ++
 8 files changed, 101 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index c9ca97f..81f3b0b 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -47,7 +47,23 @@ struct kvm_regs {
 
 struct kvm_sregs {
__u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8]; 
+   __u64 dbat[8]; 
+   } ppc32;
+   } s;
+   __u8 pad[1020];
+   } u;
 };
 
 struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
 #define BOOK3S_IRQPRIO_MAX 16
 
 #define BOOK3S_HFLAG_DCBZ320x1
+#define BOOK3S_HFLAG_SLB   0x2
 
 #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
 };
 
 struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);
 
 extern u32 kvmppc_trampoline_lowmem;
 extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..3e294bd 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 {
+   vcpu-arch.hflags = ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr = 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,62 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
+   struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
+   int i;
+
sregs-pvr = vcpu-arch.pvr;
+
+   sregs-u.s.sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-u.s.ppc64.slb[i].slbe = vcpu3s-slb[i].orige | i;
+   sregs-u.s.ppc64.slb[i].slbv = vcpu3s-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-u.s.ppc32.sr[i] = vcpu3s-sr[i].raw;
+   sregs-u.s.ppc32.sr[i] = vcpu3s-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-u.s.ppc32.ibat[i] = vcpu3s-ibat[i].raw;
+   sregs-u.s.ppc32.dbat[i] = vcpu3s-dbat[i].raw;
+   }
+   }
return 0;
 }
 
 int 

Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-30 Thread Avi Kivity

On 11/30/2009 03:02 PM, Alexander Graf wrote:

Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.
   


Looks good.  Ben, please carry this in your tree.

--
error compiling committee.c: too many arguments to function

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


[PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.
---
 arch/powerpc/include/asm/kvm.h|   20 -
 arch/powerpc/include/asm/kvm_asm.h|1 +
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/kvm/book3s.c |   47 +
 arch/powerpc/kvm/book3s_64_emulate.c  |   38 --
 arch/powerpc/kvm/book3s_64_mmu.c  |2 +
 arch/powerpc/kvm/powerpc.c|3 ++
 include/linux/kvm.h   |3 ++
 8 files changed, 100 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index c9ca97f..bc0aeba 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
 };
 
 struct kvm_sregs {
-   __u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u32 pvr;
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8]; 
+   __u64 dbat[8]; 
+   } ppc32;
+   };
+   __u8 pad[1024];
+   };
 };
 
 struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
 #define BOOK3S_IRQPRIO_MAX 16
 
 #define BOOK3S_HFLAG_DCBZ320x1
+#define BOOK3S_HFLAG_SLB   0x2
 
 #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
 };
 
 struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);
 
 extern u32 kvmppc_trampoline_lowmem;
 extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..650ebf8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 {
+   vcpu-arch.hflags = ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr = 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,60 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
+   int i;
+
sregs-pvr = vcpu-arch.pvr;
+
+   sregs-sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-ppc64.slb[i].slbe = 
to_book3s(vcpu)-slb[i].orige | i;
+   sregs-ppc64.slb[i].slbv = 
to_book3s(vcpu)-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-ppc32.ibat[i] = to_book3s(vcpu)-ibat[i].raw;
+   sregs-ppc32.dbat[i] = to_book3s(vcpu)-dbat[i].raw;
+   }
+   }
return 0;
 }
 
 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs 

Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Avi Kivity

On 11/26/2009 01:16 PM, Alexander Graf wrote:

Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.


  struct kvm_sregs {
-   __u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u32 pvr;
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8];
+   __u64 dbat[8];
+   } ppc32;
+   };
+   __u8 pad[1024];
+   };
  };
   


Please avoid unnamed unions in user-visible headers - they're a gcc 
extension.


Yes, we have them elsewhere, but let's not add to the pile.



  struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
  #define BOOK3S_IRQPRIO_MAX16

  #define BOOK3S_HFLAG_DCBZ32   0x1
+#define BOOK3S_HFLAG_SLB   0x2

  #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
  #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
  };

  struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
  extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
  extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
  extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);

  extern u32 kvmppc_trampoline_lowmem;
  extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..650ebf8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)

  void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
  {
+   vcpu-arch.hflags= ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr= 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,60 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
  int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
struct kvm_sregs *sregs)
  {
+   int i;
+
sregs-pvr = vcpu-arch.pvr;
+
+   sregs-sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-ppc64.slb[i].slbe = 
to_book3s(vcpu)-slb[i].orige | i;
+   sregs-ppc64.slb[i].slbv = 
to_book3s(vcpu)-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-ppc32.ibat[i] = to_book3s(vcpu)-ibat[i].raw;
+   sregs-ppc32.dbat[i] = to_book3s(vcpu)-dbat[i].raw;
+   }
+   }
return 0;
  }

  int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
struct kvm_sregs *sregs)
  {
+   int i;
+
kvmppc_set_pvr(vcpu, sregs-pvr);
+
+   to_book3s(vcpu)-sdr1 = sregs-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   vcpu-arch.mmu.slbmte(vcpu, sregs-ppc64.slb[i].slbv,
+   sregs-ppc64.slb[i].slbe);
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   vcpu-arch.mmu.mtsrin(vcpu, i, sregs-ppc32.sr[i]);
+   }
+   for (i = 0; i  8; i++) {
+   

Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Avi Kivity wrote:
 On 11/26/2009 02:46 PM, Alexander Graf wrote:

 Please avoid unnamed unions in user-visible headers - they're a gcc
 extension.

 Yes, we have them elsewhere, but let's not add to the pile.
  
 I'm open to scalable suggestions that don't break existing userspace
 code.
 If I name the union now, existing qemu code will break. If I align the
 pad array manually I'll definitely mess up something.


 You can keep pvr out of the (named) union.


So we'd have

sregs.padded.ppc64.slb?

I don't see how that is an improvement.


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


Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Avi Kivity

On 11/26/2009 03:16 PM, Alexander Graf wrote:



You can keep pvr out of the (named) union.
 


So we'd have

sregs.padded.ppc64.slb?

   


or sregs.u.ppc64.slb.


I don't see how that is an improvement.
   


Buildability takes precedence.

(an alternative is to drop the union, and add a BUILD_BUG_ON(sizeof...)).

--
error compiling committee.c: too many arguments to function

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


Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf


Am 26.11.2009 um 16:24 schrieb Alexander Graf ag...@suse.de:

Currently userspace has no chance to find out which virtual address  
space we're
in and resolve addresses. While that is a big problem for migration,  
it's also
unpleasent when debugging, as gdb and the monitor don't work on  
virtual

addresses.

This patch exports enough of the MMU segment state to userspace to  
make

debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.

v2 - v3:

 - don't use anonymous unions/structs
---
arch/powerpc/include/asm/kvm.h|   20 +++-
arch/powerpc/include/asm/kvm_asm.h |1 +
arch/powerpc/include/asm/kvm_book3s.h |3 ++
arch/powerpc/kvm/book3s.c |   53  
+++-

arch/powerpc/kvm/book3s_64_emulate.c  |   38 ++-
arch/powerpc/kvm/book3s_64_mmu.c |2 +
arch/powerpc/kvm/powerpc.c|3 ++
include/linux/kvm.h   |3 ++
8 files changed, 104 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/ 
asm/kvm.h

index c9ca97f..cb6ad08 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
};

struct kvm_sregs {
-__u32 pvr;
-char pad[1020];
+union {
+struct {
+__u32 pvr;


Meh this breaks old userspace. Better patch following tomorrow.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.
---
 arch/powerpc/include/asm/kvm.h|   20 -
 arch/powerpc/include/asm/kvm_asm.h|1 +
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/kvm/book3s.c |   47 +
 arch/powerpc/kvm/book3s_64_emulate.c  |   38 --
 arch/powerpc/kvm/book3s_64_mmu.c  |2 +
 arch/powerpc/kvm/powerpc.c|3 ++
 include/linux/kvm.h   |3 ++
 8 files changed, 100 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index c9ca97f..bc0aeba 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
 };
 
 struct kvm_sregs {
-   __u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u32 pvr;
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8]; 
+   __u64 dbat[8]; 
+   } ppc32;
+   };
+   __u8 pad[1024];
+   };
 };
 
 struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
 #define BOOK3S_IRQPRIO_MAX 16
 
 #define BOOK3S_HFLAG_DCBZ320x1
+#define BOOK3S_HFLAG_SLB   0x2
 
 #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
 };
 
 struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);
 
 extern u32 kvmppc_trampoline_lowmem;
 extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..650ebf8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 {
+   vcpu-arch.hflags = ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr = 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,60 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
+   int i;
+
sregs-pvr = vcpu-arch.pvr;
+
+   sregs-sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-ppc64.slb[i].slbe = 
to_book3s(vcpu)-slb[i].orige | i;
+   sregs-ppc64.slb[i].slbv = 
to_book3s(vcpu)-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-ppc32.ibat[i] = to_book3s(vcpu)-ibat[i].raw;
+   sregs-ppc32.dbat[i] = to_book3s(vcpu)-dbat[i].raw;
+   }
+   }
return 0;
 }
 
 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs 

Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Avi Kivity wrote:
 On 11/26/2009 01:16 PM, Alexander Graf wrote:
 Currently userspace has no chance to find out which virtual address
 space we're
 in and resolve addresses. While that is a big problem for migration,
 it's also
 unpleasent when debugging, as gdb and the monitor don't work on virtual
 addresses.

 This patch exports enough of the MMU segment state to userspace to make
 debugging work and thus also includes the groundwork for migration.


   struct kvm_sregs {
 -__u32 pvr;
 -char pad[1020];
 +union {
 +struct {
 +__u32 pvr;
 +__u64 sdr1;
 +struct {
 +struct {
 +__u64 slbe;
 +__u64 slbv;
 +} slb[64];
 +} ppc64;
 +struct {
 +__u32 sr[16];
 +__u64 ibat[8];
 +__u64 dbat[8];
 +} ppc32;
 +};
 +__u8 pad[1024];
 +};
   };


 Please avoid unnamed unions in user-visible headers - they're a gcc
 extension.

 Yes, we have them elsewhere, but let's not add to the pile.

I'm open to scalable suggestions that don't break existing userspace code.
If I name the union now, existing qemu code will break. If I align the
pad array manually I'll definitely mess up something.

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] PPC: Sync guest visible MMU state

2009-11-26 Thread Avi Kivity

On 11/26/2009 02:46 PM, Alexander Graf wrote:



Please avoid unnamed unions in user-visible headers - they're a gcc
extension.

Yes, we have them elsewhere, but let's not add to the pile.
 

I'm open to scalable suggestions that don't break existing userspace code.
If I name the union now, existing qemu code will break. If I align the
pad array manually I'll definitely mess up something.
   


You can keep pvr out of the (named) union.

--
error compiling committee.c: too many arguments to function

--
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] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Avi Kivity wrote:
 On 11/26/2009 02:46 PM, Alexander Graf wrote:

 Please avoid unnamed unions in user-visible headers - they're a gcc
 extension.

 Yes, we have them elsewhere, but let's not add to the pile.
  
 I'm open to scalable suggestions that don't break existing userspace
 code.
 If I name the union now, existing qemu code will break. If I align the
 pad array manually I'll definitely mess up something.


 You can keep pvr out of the (named) union.


So we'd have

sregs.padded.ppc64.slb?

I don't see how that is an improvement.


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] PPC: Sync guest visible MMU state

2009-11-26 Thread Avi Kivity

On 11/26/2009 03:16 PM, Alexander Graf wrote:



You can keep pvr out of the (named) union.
 


So we'd have

sregs.padded.ppc64.slb?

   


or sregs.u.ppc64.slb.


I don't see how that is an improvement.
   


Buildability takes precedence.

(an alternative is to drop the union, and add a BUILD_BUG_ON(sizeof...)).

--
error compiling committee.c: too many arguments to function

--
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] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf
Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.

v2 - v3:

  - don't use anonymous unions/structs
---
 arch/powerpc/include/asm/kvm.h|   20 +++-
 arch/powerpc/include/asm/kvm_asm.h|1 +
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/kvm/book3s.c |   53 +++-
 arch/powerpc/kvm/book3s_64_emulate.c  |   38 ++-
 arch/powerpc/kvm/book3s_64_mmu.c  |2 +
 arch/powerpc/kvm/powerpc.c|3 ++
 include/linux/kvm.h   |3 ++
 8 files changed, 104 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index c9ca97f..cb6ad08 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
 };
 
 struct kvm_sregs {
-   __u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u32 pvr;
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8]; 
+   __u64 dbat[8]; 
+   } ppc32;
+   } s;
+   __u8 pad[1024];
+   } u;
 };
 
 struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
 #define BOOK3S_IRQPRIO_MAX 16
 
 #define BOOK3S_HFLAG_DCBZ320x1
+#define BOOK3S_HFLAG_SLB   0x2
 
 #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
 };
 
 struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);
 
 extern u32 kvmppc_trampoline_lowmem;
 extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..583 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 {
+   vcpu-arch.hflags = ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr = 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,62 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
-   sregs-pvr = vcpu-arch.pvr;
+   struct kvmppc_vcpu_book3s *vcpu3s = to_book3s(vcpu);
+   int i;
+
+   sregs-u.s.pvr = vcpu-arch.pvr;
+
+   sregs-u.s.sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-u.s.ppc64.slb[i].slbe = vcpu3s-slb[i].orige | i;
+   sregs-u.s.ppc64.slb[i].slbv = vcpu3s-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-u.s.ppc32.sr[i] = vcpu3s-sr[i].raw;
+   sregs-u.s.ppc32.sr[i] = vcpu3s-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-u.s.ppc32.ibat[i] = vcpu3s-ibat[i].raw;
+   sregs-u.s.ppc32.dbat[i] = vcpu3s-dbat[i].raw;
+   }
+   }
return 

Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-26 Thread Alexander Graf


Am 26.11.2009 um 16:24 schrieb Alexander Graf ag...@suse.de:

Currently userspace has no chance to find out which virtual address  
space we're
in and resolve addresses. While that is a big problem for migration,  
it's also
unpleasent when debugging, as gdb and the monitor don't work on  
virtual

addresses.

This patch exports enough of the MMU segment state to userspace to  
make

debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de

---

Ben, please take this patch in your tree.

v2 - v3:

 - don't use anonymous unions/structs
---
arch/powerpc/include/asm/kvm.h|   20 +++-
arch/powerpc/include/asm/kvm_asm.h |1 +
arch/powerpc/include/asm/kvm_book3s.h |3 ++
arch/powerpc/kvm/book3s.c |   53  
+++-

arch/powerpc/kvm/book3s_64_emulate.c  |   38 ++-
arch/powerpc/kvm/book3s_64_mmu.c |2 +
arch/powerpc/kvm/powerpc.c|3 ++
include/linux/kvm.h   |3 ++
8 files changed, 104 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/ 
asm/kvm.h

index c9ca97f..cb6ad08 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
};

struct kvm_sregs {
-__u32 pvr;
-char pad[1020];
+union {
+struct {
+__u32 pvr;


Meh this breaks old userspace. Better patch following tomorrow.
--
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] PPC: Sync guest visible MMU state

2009-11-24 Thread Avi Kivity

On 11/24/2009 09:50 AM, Alexander Graf wrote:

Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.
   



index 92045a9..1240fcb 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
+#define KVM_CAP_PPC_SEGSTATE 42

   


42 is already taken (s390 psw and D. Adams), please use 43.

--
error compiling committee.c: too many arguments to function

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


Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-24 Thread Alexander Graf

On 24.11.2009, at 16:02, Avi Kivity wrote:

 On 11/24/2009 09:50 AM, Alexander Graf wrote:
 Currently userspace has no chance to find out which virtual address space 
 we're
 in and resolve addresses. While that is a big problem for migration, it's 
 also
 unpleasent when debugging, as gdb and the monitor don't work on virtual
 addresses.
   
 
 index 92045a9..1240fcb 100644
 --- a/include/linux/kvm.h
 +++ b/include/linux/kvm.h
 @@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
 +#define KVM_CAP_PPC_SEGSTATE 42
 
   
 
 42 is already taken (s390 psw and D. Adams), please use 43.

Aww. Any reason I didn't get the s390 patch in a git pull yet? (damn that 
Carsten - he got the cool number)

Alex

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


Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-24 Thread Avi Kivity

On 11/24/2009 05:04 PM, Alexander Graf wrote:



index 92045a9..1240fcb 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
+#define KVM_CAP_PPC_SEGSTATE 42


   

42 is already taken (s390 psw and D. Adams), please use 43.
 

Aww. Any reason I didn't get the s390 patch in a git pull yet? (damn that 
Carsten - he got the cool number)

   


It's in the next branch only ('git fetch blah').

--
error compiling committee.c: too many arguments to function

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


Re: [PATCH] PPC: Sync guest visible MMU state

2009-11-24 Thread Avi Kivity

On 11/24/2009 09:50 AM, Alexander Graf wrote:

Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.
   



index 92045a9..1240fcb 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
+#define KVM_CAP_PPC_SEGSTATE 42

   


42 is already taken (s390 psw and D. Adams), please use 43.

--
error compiling committee.c: too many arguments to function

--
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] PPC: Sync guest visible MMU state

2009-11-24 Thread Alexander Graf

On 24.11.2009, at 16:02, Avi Kivity wrote:

 On 11/24/2009 09:50 AM, Alexander Graf wrote:
 Currently userspace has no chance to find out which virtual address space 
 we're
 in and resolve addresses. While that is a big problem for migration, it's 
 also
 unpleasent when debugging, as gdb and the monitor don't work on virtual
 addresses.
   
 
 index 92045a9..1240fcb 100644
 --- a/include/linux/kvm.h
 +++ b/include/linux/kvm.h
 @@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
 +#define KVM_CAP_PPC_SEGSTATE 42
 
   
 
 42 is already taken (s390 psw and D. Adams), please use 43.

Aww. Any reason I didn't get the s390 patch in a git pull yet? (damn that 
Carsten - he got the cool number)

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] PPC: Sync guest visible MMU state

2009-11-24 Thread Avi Kivity

On 11/24/2009 05:04 PM, Alexander Graf wrote:



index 92045a9..1240fcb 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -492,6 +492,7 @@ struct kvm_ioeventfd {
  #ifdef __KVM_HAVE_VCPU_EVENTS
  #define KVM_CAP_VCPU_EVENTS 41
  #endif
+#define KVM_CAP_PPC_SEGSTATE 42


   

42 is already taken (s390 psw and D. Adams), please use 43.
 

Aww. Any reason I didn't get the s390 patch in a git pull yet? (damn that 
Carsten - he got the cool number)

   


It's in the next branch only ('git fetch blah').

--
error compiling committee.c: too many arguments to function

--
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] PPC: Sync guest visible MMU state

2009-11-23 Thread Alexander Graf
Currently userspace has no chance to find out which virtual address space we're
in and resolve addresses. While that is a big problem for migration, it's also
unpleasent when debugging, as gdb and the monitor don't work on virtual
addresses.

This patch exports enough of the MMU segment state to userspace to make
debugging work and thus also includes the groundwork for migration.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm.h|   20 -
 arch/powerpc/include/asm/kvm_asm.h|1 +
 arch/powerpc/include/asm/kvm_book3s.h |3 ++
 arch/powerpc/kvm/book3s.c |   47 +
 arch/powerpc/kvm/book3s_64_emulate.c  |   38 --
 arch/powerpc/kvm/book3s_64_mmu.c  |2 +
 arch/powerpc/kvm/powerpc.c|3 ++
 include/linux/kvm.h   |1 +
 8 files changed, 98 insertions(+), 17 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index c9ca97f..bc0aeba 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,8 +46,24 @@ struct kvm_regs {
 };
 
 struct kvm_sregs {
-   __u32 pvr;
-   char pad[1020];
+   union {
+   struct {
+   __u32 pvr;
+   __u64 sdr1;
+   struct {
+   struct {
+   __u64 slbe;
+   __u64 slbv;
+   } slb[64];
+   } ppc64;
+   struct {
+   __u32 sr[16];
+   __u64 ibat[8]; 
+   __u64 dbat[8]; 
+   } ppc32;
+   };
+   __u8 pad[1024];
+   };
 };
 
 struct kvm_fpu {
diff --git a/arch/powerpc/include/asm/kvm_asm.h 
b/arch/powerpc/include/asm/kvm_asm.h
index 19ddb35..af2abe7 100644
--- a/arch/powerpc/include/asm/kvm_asm.h
+++ b/arch/powerpc/include/asm/kvm_asm.h
@@ -87,6 +87,7 @@
 #define BOOK3S_IRQPRIO_MAX 16
 
 #define BOOK3S_HFLAG_DCBZ320x1
+#define BOOK3S_HFLAG_SLB   0x2
 
 #define RESUME_FLAG_NV  (10)  /* Reload guest nonvolatile state? */
 #define RESUME_FLAG_HOST(11)  /* Resume host? */
diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
index c601133..74b7369 100644
--- a/arch/powerpc/include/asm/kvm_book3s.h
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -46,6 +46,7 @@ struct kvmppc_sr {
 };
 
 struct kvmppc_bat {
+   u64 raw;
u32 bepi;
u32 bepi_mask;
bool vs;
@@ -113,6 +114,8 @@ extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct 
kvm_vcpu *vcpu, u64 ea, boo
 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, 
bool data);
 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int 
vec);
+extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
+  bool upper, u32 val);
 
 extern u32 kvmppc_trampoline_lowmem;
 extern u32 kvmppc_trampoline_enter;
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 42037d4..650ebf8 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -281,6 +281,7 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 
 void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr)
 {
+   vcpu-arch.hflags = ~BOOK3S_HFLAG_SLB;
vcpu-arch.pvr = pvr;
if ((pvr = 0x33)  (pvr  0x7033)) {
kvmppc_mmu_book3s_64_init(vcpu);
@@ -762,14 +763,60 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, 
struct kvm_regs *regs)
 int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
+   int i;
+
sregs-pvr = vcpu-arch.pvr;
+
+   sregs-sdr1 = to_book3s(vcpu)-sdr1;
+   if (vcpu-arch.hflags  BOOK3S_HFLAG_SLB) {
+   for (i = 0; i  64; i++) {
+   sregs-ppc64.slb[i].slbe = 
to_book3s(vcpu)-slb[i].orige | i;
+   sregs-ppc64.slb[i].slbv = 
to_book3s(vcpu)-slb[i].origv;
+   }
+   } else {
+   for (i = 0; i  16; i++) {
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   sregs-ppc32.sr[i] = to_book3s(vcpu)-sr[i].raw;
+   }
+   for (i = 0; i  8; i++) {
+   sregs-ppc32.ibat[i] = to_book3s(vcpu)-ibat[i].raw;
+   sregs-ppc32.dbat[i] = to_book3s(vcpu)-dbat[i].raw;
+   }
+   }
return 0;
 }
 
 int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
   struct kvm_sregs *sregs)
 {
+   int i;
+