[PATCH 02/27] Pass PVR in sregs

2009-09-29 Thread Alexander Graf
Right now sregs is unused on PPC, so we can use it for initialization
of the CPU.

KVM on BookE always virtualizes the host CPU. On Book3s we go a step further
and take the PVR from userspace that tells us what kind of CPU we are supposed
to virtualize, because we support Book3s_32 and Book3s_64 guests.

In order to get that information, we use the sregs ioctl, because we don't
want to reset the guest CPU on every normal register set.

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

diff --git a/arch/powerpc/include/asm/kvm.h b/arch/powerpc/include/asm/kvm.h
index bb2de6a..b82bd68 100644
--- a/arch/powerpc/include/asm/kvm.h
+++ b/arch/powerpc/include/asm/kvm.h
@@ -46,6 +46,8 @@ struct kvm_regs {
 };
 
 struct kvm_sregs {
+   __u64 pvr;
+   char pad[1016];
 };
 
 struct kvm_fpu {
-- 
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/27] Add Book3s fields to vcpu structs

2009-09-29 Thread Alexander Graf
We need to store more information than we currently have for vcpus
when running on Book3s.

So let's extend the internal struct definitions.

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

---

v3 - v4:

  - use context_id instead of mm_context
---
 arch/powerpc/include/asm/kvm_host.h |   75 ++-
 1 files changed, 74 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index c9c930e..8422027 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -37,6 +37,8 @@
 #define KVM_NR_PAGE_SIZES  1
 #define KVM_PAGES_PER_HPAGE(x) (1UL31)
 
+#define HPTEG_CACHE_NUM 1024
+
 struct kvm;
 struct kvm_run;
 struct kvm_vcpu;
@@ -63,6 +65,17 @@ struct kvm_vcpu_stat {
u32 dec_exits;
u32 ext_intr_exits;
u32 halt_wakeup;
+#ifdef CONFIG_PPC64
+   u32 pf_storage;
+   u32 pf_instruc;
+   u32 sp_storage;
+   u32 sp_instruc;
+   u32 queue_intr;
+   u32 ld;
+   u32 ld_slow;
+   u32 st;
+   u32 st_slow;
+#endif
 };
 
 enum kvm_exit_types {
@@ -109,9 +122,53 @@ struct kvmppc_exit_timing {
 struct kvm_arch {
 };
 
+struct kvmppc_pte {
+   u64 eaddr;
+   u64 vpage;
+   u64 raddr;
+   bool may_read;
+   bool may_write;
+   bool may_execute;
+};
+
+struct kvmppc_mmu {
+   /* book3s_64 only */
+   void (*slbmte)(struct kvm_vcpu *vcpu, u64 rb, u64 rs);
+   u64  (*slbmfee)(struct kvm_vcpu *vcpu, u64 slb_nr);
+   u64  (*slbmfev)(struct kvm_vcpu *vcpu, u64 slb_nr);
+   void (*slbie)(struct kvm_vcpu *vcpu, u64 slb_nr);
+   void (*slbia)(struct kvm_vcpu *vcpu);
+   /* book3s */
+   void (*mtsrin)(struct kvm_vcpu *vcpu, u32 srnum, ulong value);
+   u32  (*mfsrin)(struct kvm_vcpu *vcpu, u32 srnum);
+   int  (*xlate)(struct kvm_vcpu *vcpu, gva_t eaddr, struct kvmppc_pte 
*pte, bool data);
+   void (*reset_msr)(struct kvm_vcpu *vcpu);
+   void (*tlbie)(struct kvm_vcpu *vcpu, ulong addr, bool large);
+   int  (*esid_to_vsid)(struct kvm_vcpu *vcpu, u64 esid, u64 *vsid);
+   u64  (*ea_to_vp)(struct kvm_vcpu *vcpu, gva_t eaddr, bool data);
+   bool (*is_dcbz32)(struct kvm_vcpu *vcpu);
+};
+
+struct hpte_cache {
+   u64 host_va;
+   u64 pfn;
+   ulong slot;
+   struct kvmppc_pte pte;
+};
+
 struct kvm_vcpu_arch {
-   u32 host_stack;
+   ulong host_stack;
u32 host_pid;
+#ifdef CONFIG_PPC64
+   ulong host_msr;
+   ulong host_r2;
+   void *host_retip;
+   ulong trampoline_lowmem;
+   ulong trampoline_enter;
+   ulong highmem_handler;
+   ulong host_paca_phys;
+   struct kvmppc_mmu mmu;
+#endif
 
u64 fpr[32];
ulong gpr[32];
@@ -123,6 +180,10 @@ struct kvm_vcpu_arch {
ulong xer;
 
ulong msr;
+#ifdef CONFIG_PPC64
+   ulong shadow_msr;
+   ulong hflags;
+#endif
u32 mmucr;
ulong sprg0;
ulong sprg1;
@@ -149,6 +210,9 @@ struct kvm_vcpu_arch {
u32 ivor[64];
ulong ivpr;
u32 pir;
+#ifdef CONFIG_PPC64
+   u32 pvr;
+#endif
 
u32 shadow_pid;
u32 pid;
@@ -174,6 +238,9 @@ struct kvm_vcpu_arch {
 #endif
 
u32 last_inst;
+#ifdef CONFIG_PPC64
+   ulong fault_dsisr;
+#endif
ulong fault_dear;
ulong fault_esr;
gpa_t paddr_accessed;
@@ -186,7 +253,13 @@ struct kvm_vcpu_arch {
u32 cpr0_cfgaddr; /* holds the last set cpr0_cfgaddr */
 
struct timer_list dec_timer;
+   u64 dec_jiffies;
unsigned long pending_exceptions;
+
+#ifdef CONFIG_PPC64
+   struct hpte_cache hpte_cache[HPTEG_CACHE_NUM];
+   int hpte_cache_offset;
+#endif
 };
 
 #endif /* __POWERPC_KVM_HOST_H__ */
-- 
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 01/27] Move dirty logging code to sub-arch

2009-09-29 Thread Alexander Graf
PowerPC code handles dirty logging in the generic parts atm. While this
is great for return -ENOTSUPP, we need to be rather target specific
when actually implementing it.

So let's split it to implementation specific code, so we can implement
it for book3s.

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

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index e7bf4d0..06f5a9e 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -520,6 +520,11 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
return kvmppc_core_vcpu_translate(vcpu, tr);
 }
 
+int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
+{
+   return -ENOTSUPP;
+}
+
 int __init kvmppc_booke_init(void)
 {
unsigned long ivor[16];
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 5902bbc..4ae3490 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -410,11 +410,6 @@ out:
return r;
 }
 
-int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
-{
-   return -ENOTSUPP;
-}
-
 long kvm_arch_vm_ioctl(struct file *filp,
unsigned int ioctl, unsigned long arg)
 {
-- 
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 00/27] Add KVM support for Book3s_64 (PPC64) hosts v4

2009-09-29 Thread Alexander Graf
KVM for PowerPC only supports embedded cores at the moment.

While it makes sense to virtualize on small machines, it's even more fun
to do so on big boxes. So I figured we need KVM for PowerPC64 as well.

This patchset implements KVM support for Book3s_64 hosts and guest support
for Book3s_64 and G3/G4.

To really make use of this, you also need a recent version of qemu.


Don't want to apply patches? Get the git tree!

$ git clone git://csgraf.de/kvm
$ git checkout origin/ppc-v4

V1 - V2:

 - extend sregs with padding
 - new naming scheme (ppc64 - book3s_64; 74xx - book3s_32)
 - to_phys - in-kernel tophys()
 - loadimm - LOAD_REG_IMMEDIATE
 - call .ko kvm.ko
 - set magic paca bit later
 - run guest code with PACA-soft_enabled=true
 - pt_regs for host state saving (guest too?)
 - only do HV dcbz trick on 970
 - refuse to run on LPAR because of missing SLB pieces

V2 - V3:

 - fix DAR/DSISR saving
 - allow running on LPAR by modifying the SLB shadow
 - change the SLB implementation to use a mem-backed cache and do
   full world switch on enter/exit. gets rid of context magic
 - be more aggressive about DEC injection
 - remove fast ld/st because we're always in host context
 - don't use SPRGs in real-paged transition
 - implement dirty log
 - remove MMIO speedup code
 - SPRG cleanup
   - rename SPRG3 - SPRN_SPRG_PACA
   - rename SPRG1 - SPRN_SPRG_SCRATCH0
   - don't use SPRG2

V3 - V4:

 - use context_id instead of mm_alloc
 - export less

TODO:

 - use MMU Notifiers

Alexander Graf (27):
  Move dirty logging code to sub-arch
  Pass PVR in sregs
  Add Book3s definitions
  Add Book3s fields to vcpu structs
  Add asm/kvm_book3s.h
  Add Book3s_64 intercept helpers
  Add book3s_64 highmem asm code
  Add SLB switching code for entry/exit
  Add interrupt handling code
  Add book3s.c
  Add book3s_64 Host MMU handling
  Add book3s_64 guest MMU
  Add book3s_32 guest MMU
  Add book3s_64 specific opcode emulation
  Add mfdec emulation
  Add desktop PowerPC specific emulation
  Make head_64.S aware of KVM real mode code
  Add Book3s_64 offsets to asm-offsets.c
  Export symbols for KVM module
  Split init_new_context and destroy_context
  Export KVM symbols for module
  Add fields to PACA
  Export new PACA constants in asm-offsets
  Include Book3s_64 target in buildsystem
  Fix trace.h
  Enable 32bit dirty log pointers on 64bit host
  Use Little Endian for Dirty Bitmap

 arch/powerpc/include/asm/exception-64s.h |2 +
 arch/powerpc/include/asm/kvm.h   |2 +
 arch/powerpc/include/asm/kvm_asm.h   |   39 ++
 arch/powerpc/include/asm/kvm_book3s.h|  136 
 arch/powerpc/include/asm/kvm_book3s_64_asm.h |   58 ++
 arch/powerpc/include/asm/kvm_host.h  |   75 ++-
 arch/powerpc/include/asm/kvm_ppc.h   |1 +
 arch/powerpc/include/asm/mmu_context.h   |5 +
 arch/powerpc/include/asm/paca.h  |9 +
 arch/powerpc/kernel/asm-offsets.c|   18 +
 arch/powerpc/kernel/exceptions-64s.S |8 +
 arch/powerpc/kernel/head_64.S|7 +
 arch/powerpc/kernel/ppc_ksyms.c  |3 +-
 arch/powerpc/kernel/time.c   |1 +
 arch/powerpc/kvm/Kconfig |   17 +
 arch/powerpc/kvm/Makefile|   27 +-
 arch/powerpc/kvm/book3s.c|  919 ++
 arch/powerpc/kvm/book3s_32_mmu.c |  354 ++
 arch/powerpc/kvm/book3s_64_emulate.c |  338 ++
 arch/powerpc/kvm/book3s_64_exports.c |   24 +
 arch/powerpc/kvm/book3s_64_interrupts.S  |  392 +++
 arch/powerpc/kvm/book3s_64_mmu.c |  469 +
 arch/powerpc/kvm/book3s_64_mmu_host.c|  412 
 arch/powerpc/kvm/book3s_64_rmhandlers.S  |  131 
 arch/powerpc/kvm/book3s_64_slb.S |  277 
 arch/powerpc/kvm/booke.c |5 +
 arch/powerpc/kvm/emulate.c   |   43 ++-
 arch/powerpc/kvm/powerpc.c   |5 -
 arch/powerpc/kvm/trace.h |6 +-
 arch/powerpc/mm/hash_utils_64.c  |2 +
 arch/powerpc/mm/mmu_context_hash64.c |   24 +-
 virt/kvm/kvm_main.c  |   10 +-
 32 files changed, 3799 insertions(+), 20 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_book3s.h
 create mode 100644 arch/powerpc/include/asm/kvm_book3s_64_asm.h
 create mode 100644 arch/powerpc/kvm/book3s.c
 create mode 100644 arch/powerpc/kvm/book3s_32_mmu.c
 create mode 100644 arch/powerpc/kvm/book3s_64_emulate.c
 create mode 100644 arch/powerpc/kvm/book3s_64_exports.c
 create mode 100644 arch/powerpc/kvm/book3s_64_interrupts.S
 create mode 100644 arch/powerpc/kvm/book3s_64_mmu.c
 create mode 100644 arch/powerpc/kvm/book3s_64_mmu_host.c
 create mode 100644 arch/powerpc/kvm/book3s_64_rmhandlers.S
 create mode 100644 arch/powerpc/kvm/book3s_64_slb.S

--
To unsubscribe from this list: send the line unsubscribe 

[PATCH 06/27] Add Book3s_64 intercept helpers

2009-09-29 Thread Alexander Graf
We need to intercept interrupt vectors. To do that, let's add a file
we can always include which only activates the intercepts when we have
then configured.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/kvm_book3s_64_asm.h |   58 ++
 1 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_book3s_64_asm.h

diff --git a/arch/powerpc/include/asm/kvm_book3s_64_asm.h 
b/arch/powerpc/include/asm/kvm_book3s_64_asm.h
new file mode 100644
index 000..2e06ee8
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_book3s_64_asm.h
@@ -0,0 +1,58 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+#ifndef __ASM_KVM_BOOK3S_ASM_H__
+#define __ASM_KVM_BOOK3S_ASM_H__
+
+#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
+
+#include asm/kvm_asm.h
+
+.macro DO_KVM intno
+   .if (\intno == BOOK3S_INTERRUPT_SYSTEM_RESET) || \
+   (\intno == BOOK3S_INTERRUPT_MACHINE_CHECK) || \
+   (\intno == BOOK3S_INTERRUPT_DATA_STORAGE) || \
+   (\intno == BOOK3S_INTERRUPT_INST_STORAGE) || \
+   (\intno == BOOK3S_INTERRUPT_DATA_SEGMENT) || \
+   (\intno == BOOK3S_INTERRUPT_INST_SEGMENT) || \
+   (\intno == BOOK3S_INTERRUPT_EXTERNAL) || \
+   (\intno == BOOK3S_INTERRUPT_ALIGNMENT) || \
+   (\intno == BOOK3S_INTERRUPT_PROGRAM) || \
+   (\intno == BOOK3S_INTERRUPT_FP_UNAVAIL) || \
+   (\intno == BOOK3S_INTERRUPT_DECREMENTER) || \
+   (\intno == BOOK3S_INTERRUPT_SYSCALL) || \
+   (\intno == BOOK3S_INTERRUPT_TRACE) || \
+   (\intno == BOOK3S_INTERRUPT_PERFMON) || \
+   (\intno == BOOK3S_INTERRUPT_ALTIVEC) || \
+   (\intno == BOOK3S_INTERRUPT_VSX)
+
+   b   kvmppc_trampoline_\intno
+kvmppc_resume_\intno:
+
+   .endif
+.endm
+
+#else
+
+.macro DO_KVM intno
+.endm
+
+#endif /* CONFIG_KVM_BOOK3S_64_HANDLER */
+
+#endif /* __ASM_KVM_BOOK3S_ASM_H__ */
-- 
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/27] Add asm/kvm_book3s.h

2009-09-29 Thread Alexander Graf
This adds the book3s specific header file that contains structs that
are only valid on book3s specific code.

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

---

v3 - v4:

  - use context_id instead of mm_alloc
---
 arch/powerpc/include/asm/kvm_book3s.h |  136 +
 1 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_book3s.h

diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
b/arch/powerpc/include/asm/kvm_book3s.h
new file mode 100644
index 000..c601133
--- /dev/null
+++ b/arch/powerpc/include/asm/kvm_book3s.h
@@ -0,0 +1,136 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+#ifndef __ASM_KVM_BOOK3S_H__
+#define __ASM_KVM_BOOK3S_H__
+
+#include linux/types.h
+#include linux/kvm_host.h
+#include asm/kvm_ppc.h
+
+struct kvmppc_slb {
+   u64 esid;
+   u64 vsid;
+   u64 orige;
+   u64 origv;
+   bool valid;
+   bool Ks;
+   bool Kp;
+   bool nx;
+   bool large;
+   bool class;
+};
+
+struct kvmppc_sr {
+   u32 raw;
+   u32 vsid;
+   bool Ks;
+   bool Kp;
+   bool nx;
+};
+
+struct kvmppc_bat {
+   u32 bepi;
+   u32 bepi_mask;
+   bool vs;
+   bool vp;
+   u32 brpn;
+   u8 wimg;
+   u8 pp;
+};
+
+struct kvmppc_sid_map {
+   u64 guest_vsid;
+   u64 guest_esid;
+   u64 host_vsid;
+   bool valid;
+};
+
+#define SID_MAP_BITS9
+#define SID_MAP_NUM (1  SID_MAP_BITS)
+#define SID_MAP_MASK(SID_MAP_NUM - 1)
+
+struct kvmppc_vcpu_book3s {
+   struct kvm_vcpu vcpu;
+   struct kvmppc_sid_map sid_map[SID_MAP_NUM];
+   struct kvmppc_slb slb[64];
+   struct {
+   u64 esid;
+   u64 vsid;
+   } slb_shadow[64];
+   u8 slb_shadow_max;
+   struct kvmppc_sr sr[16];
+   struct kvmppc_bat ibat[8];
+   struct kvmppc_bat dbat[8];
+   u64 hid[6];
+   int slb_nr;
+   u64 sdr1;
+   u64 dsisr;
+   u64 hior;
+   u64 msr_mask;
+   u64 vsid_first;
+   u64 vsid_next;
+   u64 vsid_max;
+   int context_id;
+};
+
+#define CONTEXT_HOST   0
+#define CONTEXT_GUEST  1
+#define CONTEXT_GUEST_END  2
+
+#define VSID_REAL  0xfff0
+#define VSID_REAL_DR   0xffe0
+#define VSID_REAL_IR   0xffd0
+#define VSID_BAT   0xffc0
+#define VSID_PR0x8000
+
+extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
+extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
+extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 
pa_end);
+extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
+extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
+extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
+extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
+extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
+extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
+extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, 
bool data);
+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 u32 kvmppc_trampoline_lowmem;
+extern u32 kvmppc_trampoline_enter;
+
+static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
+{
+   return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
+}
+
+static inline ulong dsisr(void)
+{
+   ulong r;
+   asm ( mfdsisr %0  : =r (r) );
+   return r;
+}
+
+extern void kvm_return_point(void);
+
+#define INS_DCBZ   0x7c0007ec
+
+#endif /* __ASM_KVM_BOOK3S_H__ */
-- 
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/27] Add desktop PowerPC specific emulation

2009-09-29 Thread Alexander Graf
Little opcodes behave differently on desktop and embedded PowerPC cores.
In order to reflect those differences, let's add some #ifdef code to emulate.c.

We could probably also handle them in the core specific emulation files, but I
would prefer to reuse as much code as possible.

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

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 50d411d..665fa83 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -32,6 +32,7 @@
 #include trace.h
 
 #define OP_TRAP 3
+#define OP_TRAP_64 2
 
 #define OP_31_XOP_LWZX  23
 #define OP_31_XOP_LBZX  87
@@ -68,7 +69,19 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 {
unsigned long nr_jiffies;
 
+#ifdef CONFIG_PPC64
+#ifdef DEBUG_EMUL
+   printk(KERN_INFO mtDEC: %x\n, vcpu-arch.dec);
+#endif
+   /* POWER4+ triggers a dec interrupt if the value is  0 */
+   if (vcpu-arch.dec  0x8000) {
+   del_timer(vcpu-arch.dec_timer);
+   kvmppc_core_queue_dec(vcpu);
+   }
+   else if (true) {
+#else
if (vcpu-arch.tcr  TCR_DIE) {
+#endif
/* The decrementer ticks at the same rate as the timebase, so
 * that's how we convert the guest DEC value to the number of
 * host ticks. */
@@ -113,9 +126,16 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
/* this default type might be overwritten by subcategories */
kvmppc_set_exit_type(vcpu, EMULATED_INST_EXITS);
 
+#ifdef DEBUG_EMUL
+   printk(KERN_INFO Emulating opcode %d / %d\n, get_op(inst), 
get_xop(inst));
+#endif
switch (get_op(inst)) {
case OP_TRAP:
+#ifdef CONFIG_PPC64
+   case OP_TRAP_64:
+#else
vcpu-arch.esr |= ESR_PTR;
+#endif
kvmppc_core_queue_program(vcpu);
advance = 0;
break;
@@ -189,6 +209,13 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
vcpu-arch.gpr[rt] = vcpu-arch.srr0; break;
case SPRN_SRR1:
vcpu-arch.gpr[rt] = vcpu-arch.srr1; break;
+#ifdef CONFIG_PPC64
+   case SPRN_PVR:
+   vcpu-arch.gpr[rt] = vcpu-arch.pvr; break;
+   case SPRN_PIR:
+   case SPRN_MSSSR0:
+   vcpu-arch.gpr[rt] = 0; break;
+#else
case SPRN_PVR:
vcpu-arch.gpr[rt] = mfspr(SPRN_PVR); break;
case SPRN_PIR:
@@ -201,6 +228,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
vcpu-arch.gpr[rt] = mftbl(); break;
case SPRN_TBWU:
vcpu-arch.gpr[rt] = mftbu(); break;
+#endif
 
case SPRN_SPRG0:
vcpu-arch.gpr[rt] = vcpu-arch.sprg0; break;
@@ -271,6 +299,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct 
kvm_vcpu *vcpu)
case SPRN_TBWL: break;
case SPRN_TBWU: break;
 
+   case SPRN_MSSSR0: break;
+
case SPRN_DEC:
vcpu-arch.dec = vcpu-arch.gpr[rs];
kvmppc_emulate_dec(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 08/27] Add SLB switching code for entry/exit

2009-09-29 Thread Alexander Graf
This is the really low level of guest entry/exit code.

Book3s_64 has an SLB, which stores all ESID - VSID mappings we're
currently aware of.

The segments in the guest differ from the ones on the host, so we need
to switch the SLB to tell the MMU that we're in a new context.

So we store a shadow of the guest's SLB in the PACA, switch to that on
entry and only restore bolted entries on exit, leaving the rest to the
Linux SLB fault handler.

That way we get a really clean way of switching the SLB.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/book3s_64_slb.S |  277 ++
 1 files changed, 277 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_64_slb.S

diff --git a/arch/powerpc/kvm/book3s_64_slb.S b/arch/powerpc/kvm/book3s_64_slb.S
new file mode 100644
index 000..00a8367
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_slb.S
@@ -0,0 +1,277 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+/**
+ **
+ *   Entry code   *
+ **
+ */
+
+.global kvmppc_handler_trampoline_enter
+kvmppc_handler_trampoline_enter:
+
+   /* Required state:
+*
+* MSR = ~IR|DR
+* R13 = PACA
+* R9 = guest IP
+* R10 = guest MSR
+* R11 = free
+* R12 = free
+* PACA[PACA_EXMC + EX_R9] = guest R9
+* PACA[PACA_EXMC + EX_R10] = guest R10
+* PACA[PACA_EXMC + EX_R11] = guest R11
+* PACA[PACA_EXMC + EX_R12] = guest R12
+* PACA[PACA_EXMC + EX_R13] = guest R13
+* PACA[PACA_EXMC + EX_CCR] = guest CR
+* PACA[PACA_EXMC + EX_R3] = guest XER
+*/
+
+   mtsrr0  r9
+   mtsrr1  r10
+
+   mtspr   SPRN_SPRG_SCRATCH0, r0
+
+   /* Remove LPAR shadow entries */
+
+#if SLB_NUM_BOLTED == 3
+
+   ld  r12, PACA_SLBSHADOWPTR(r13)
+   ld  r10, 0x10(r12)
+   ld  r11, 0x18(r12)
+   /* Invalid? Skip. */
+   rldicl. r0, r10, 37, 63
+   beq slb_entry_skip_1
+   xoris   r9, r10, slb_esi...@h
+   std r9, 0x10(r12)
+slb_entry_skip_1:
+   ld  r9, 0x20(r12)
+   /* Invalid? Skip. */
+   rldicl. r0, r9, 37, 63
+   beq slb_entry_skip_2
+   xoris   r9, r9, slb_esi...@h
+   std r9, 0x20(r12)
+slb_entry_skip_2:
+   ld  r9, 0x30(r12)
+   /* Invalid? Skip. */
+   rldicl. r0, r9, 37, 63
+   beq slb_entry_skip_3
+   xoris   r9, r9, slb_esi...@h
+   std r9, 0x30(r12)
+slb_entry_skip_3:
+   
+#else
+#error unknown number of bolted entries
+#endif
+
+   /* Flush SLB */
+
+   slbia
+
+   /* r0 = esid  ESID_MASK */
+   rldicr  r10, r10, 0, 35
+   /* r0 |= CLASS_BIT(VSID) */
+   rldic   r12, r11, 56 - 36, 36
+   or  r10, r10, r12
+   slbie   r10
+
+   isync
+
+   /* Fill SLB with our shadow */
+
+   lbz r12, PACA_KVM_SLB_MAX(r13)
+   mulli   r12, r12, 16
+   addir12, r12, PACA_KVM_SLB
+   add r12, r12, r13
+
+   /* for (r11 = kvm_slb; r11  kvm_slb + kvm_slb_size; r11+=slb_entry) */
+   li  r11, PACA_KVM_SLB
+   add r11, r11, r13
+
+slb_loop_enter:
+
+   ld  r10, 0(r11)
+
+   rldicl. r0, r10, 37, 63
+   beq slb_loop_enter_skip
+
+   ld  r9, 8(r11)
+   slbmte  r9, r10
+
+slb_loop_enter_skip:
+   addir11, r11, 16
+   cmpdcr0, r11, r12
+   blt slb_loop_enter
+
+slb_do_enter:
+
+   /* Enter guest */
+
+   mfspr   r0, SPRN_SPRG_SCRATCH0
+
+   ld  r9, (PACA_EXMC+EX_R9)(r13)
+   ld  r10, (PACA_EXMC+EX_R10)(r13)
+   ld  r12, (PACA_EXMC+EX_R12)(r13)
+
+   lwz r11, (PACA_EXMC+EX_CCR)(r13)
+   mtcrr11
+
+   ld  r11, (PACA_EXMC+EX_R3)(r13)
+   mtxer   r11
+
+   ld  r11, (PACA_EXMC+EX_R11)(r13)
+   ld  r13, (PACA_EXMC+EX_R13)(r13)
+
+   RFI
+kvmppc_handler_trampoline_enter_end:
+

[PATCH 07/27] Add book3s_64 highmem asm code

2009-09-29 Thread Alexander Graf
This is the of entry / exit code. In order to switch between host and guest
context, we need to switch register state and call the exit code handler on
exit.

This assembly file does exactly that. To finally enter the guest it calls
into book3s_64_slb.S. On exit it gets jumped at from book3s_64_slb.S too.

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

---

v3 - v4:

  - header rename fix
---
 arch/powerpc/include/asm/kvm_ppc.h  |1 +
 arch/powerpc/kvm/book3s_64_interrupts.S |  392 +++
 2 files changed, 393 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_64_interrupts.S

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 2c6ee34..269ee46 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -39,6 +39,7 @@ enum emulation_result {
 extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
 extern char kvmppc_handlers_start[];
 extern unsigned long kvmppc_handler_len;
+extern void kvmppc_handler_highmem(void);
 
 extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
 extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
diff --git a/arch/powerpc/kvm/book3s_64_interrupts.S 
b/arch/powerpc/kvm/book3s_64_interrupts.S
new file mode 100644
index 000..7b55d80
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_interrupts.S
@@ -0,0 +1,392 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+#include asm/ppc_asm.h
+#include asm/kvm_asm.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/asm-offsets.h
+#include asm/exception-64s.h
+
+#define KVMPPC_HANDLE_EXIT .kvmppc_handle_exit
+#define ULONG_SIZE 8
+#define VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE))
+
+.macro mfpaca tmp_reg, src_reg, offset, vcpu_reg
+   ld  \tmp_reg, (PACA_EXMC+\offset)(r13)
+   std \tmp_reg, VCPU_GPR(\src_reg)(\vcpu_reg)
+.endm
+
+.macro DISABLE_INTERRUPTS
+   mfmsr   r0
+   rldicl  r0,r0,48,1
+   rotldi  r0,r0,16
+   mtmsrd  r0,1
+.endm
+
+/*
+ *   *
+ * Guest entry / exit code that is in kernel module memory (highmem) *
+ *   *
+ /
+
+/* Registers:
+ *  r3: kvm_run pointer
+ *  r4: vcpu pointer
+ */
+_GLOBAL(__kvmppc_vcpu_entry)
+
+kvm_start_entry:
+   /* Write correct stack frame */
+   mflrr0
+   std r0,16(r1)
+
+   /* Save host state to the stack */
+   stdur1, -SWITCH_FRAME_SIZE(r1)
+
+   /* Save r3 (kvm_run) and r4 (vcpu) */
+   SAVE_2GPRS(3, r1)
+
+   /* Save non-volatile registers (r14 - r31) */
+   SAVE_NVGPRS(r1)
+
+   /* Save LR */
+   mflrr14
+   std r14, _LINK(r1)
+
+/* XXX optimize non-volatile loading away */
+kvm_start_lightweight:
+
+   DISABLE_INTERRUPTS
+
+   /* Save R1/R2 in the PACA */
+   std r1, PACAR1(r13)
+   std r2, (PACA_EXMC+EX_SRR0)(r13)
+   ld  r3, VCPU_HIGHMEM_HANDLER(r4)
+   std r3, PACASAVEDMSR(r13)
+
+   /* Load non-volatile guest state from the vcpu */
+   ld  r14, VCPU_GPR(r14)(r4)
+   ld  r15, VCPU_GPR(r15)(r4)
+   ld  r16, VCPU_GPR(r16)(r4)
+   ld  r17, VCPU_GPR(r17)(r4)
+   ld  r18, VCPU_GPR(r18)(r4)
+   ld  r19, VCPU_GPR(r19)(r4)
+   ld  r20, VCPU_GPR(r20)(r4)
+   ld  r21, VCPU_GPR(r21)(r4)
+   ld  r22, VCPU_GPR(r22)(r4)
+   ld  r23, VCPU_GPR(r23)(r4)
+   ld  r24, VCPU_GPR(r24)(r4)
+   ld  r25, VCPU_GPR(r25)(r4)
+   ld  r26, VCPU_GPR(r26)(r4)
+   ld  r27, VCPU_GPR(r27)(r4)
+   ld  r28, VCPU_GPR(r28)(r4)
+   ld  r29, VCPU_GPR(r29)(r4)
+   ld  r30, VCPU_GPR(r30)(r4)
+   ld  r31, VCPU_GPR(r31)(r4)
+
+   ld  r9, VCPU_PC(r4) /* r9 = vcpu-arch.pc */
+   ld  r10, VCPU_SHADOW_MSR(r4)/* r10 = vcpu-arch.shadow_msr 
*/
+
+   ld  r3, VCPU_TRAMPOLINE_ENTER(r4)
+   mtsrr0  r3
+
+   

[PATCH 18/27] Add Book3s_64 offsets to asm-offsets.c

2009-09-29 Thread Alexander Graf
We need to access some VCPU fields from assembly code. In order to get
the proper offsets, we have to define them in asm-offsets.c.

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

diff --git a/arch/powerpc/kernel/asm-offsets.c 
b/arch/powerpc/kernel/asm-offsets.c
index 0812b0f..aba3ea6 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -398,6 +398,19 @@ int main(void)
DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
+
+   /* book3s_64 */
+#ifdef CONFIG_PPC64
+   DEFINE(VCPU_FAULT_DSISR, offsetof(struct kvm_vcpu, arch.fault_dsisr));
+   DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
+   DEFINE(VCPU_HOST_R2, offsetof(struct kvm_vcpu, arch.host_r2));
+   DEFINE(VCPU_HOST_MSR, offsetof(struct kvm_vcpu, arch.host_msr));
+   DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
+   DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, 
arch.trampoline_lowmem));
+   DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, 
arch.trampoline_enter));
+   DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, 
arch.highmem_handler));
+   DEFINE(VCPU_HFLAGS, offsetof(struct kvm_vcpu, arch.hflags));
+#endif
 #endif
 #ifdef CONFIG_44x
DEFINE(PGD_T_LOG2, PGD_T_LOG2);
-- 
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/27] Export KVM symbols for module

2009-09-29 Thread Alexander Graf
To be able to keep KVM as module, we need to export the SLB trampoline
addresses to the module, so it knows where to jump to.

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

diff --git a/arch/powerpc/kvm/book3s_64_exports.c 
b/arch/powerpc/kvm/book3s_64_exports.c
new file mode 100644
index 000..5b2db38
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_exports.c
@@ -0,0 +1,24 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+#include linux/module.h
+#include asm/kvm_book3s.h
+
+EXPORT_SYMBOL_GPL(kvmppc_trampoline_enter);
+EXPORT_SYMBOL_GPL(kvmppc_trampoline_lowmem);
-- 
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/27] Split init_new_context and destroy_context

2009-09-29 Thread Alexander Graf
For KVM we need to allocate a new context id, but don't really care about
all the mm context around it.

So let's split the alloc and destroy functions for the context id, so we can
grab one without allocating an mm context.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/mmu_context.h |5 +
 arch/powerpc/mm/mmu_context_hash64.c   |   24 +---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/mmu_context.h 
b/arch/powerpc/include/asm/mmu_context.h
index b34e94d..66b35d0 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -23,6 +23,11 @@ extern void switch_slb(struct task_struct *tsk, struct 
mm_struct *mm);
 extern void set_context(unsigned long id, pgd_t *pgd);
 
 #ifdef CONFIG_PPC_BOOK3S_64
+extern int __init_new_context(void);
+extern void __destroy_context(int context_id);
+#endif
+
+#ifdef CONFIG_PPC_BOOK3S_64
 static inline void mmu_context_init(void) { }
 #else
 extern void mmu_context_init(void);
diff --git a/arch/powerpc/mm/mmu_context_hash64.c 
b/arch/powerpc/mm/mmu_context_hash64.c
index dbeb86a..b9e4cc2 100644
--- a/arch/powerpc/mm/mmu_context_hash64.c
+++ b/arch/powerpc/mm/mmu_context_hash64.c
@@ -18,6 +18,7 @@
 #include linux/mm.h
 #include linux/spinlock.h
 #include linux/idr.h
+#include linux/module.h
 
 #include asm/mmu_context.h
 
@@ -32,7 +33,7 @@ static DEFINE_IDR(mmu_context_idr);
 #define NO_CONTEXT 0
 #define MAX_CONTEXT((1UL  19) - 1)
 
-int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+int __init_new_context(void)
 {
int index;
int err;
@@ -57,6 +58,18 @@ again:
return -ENOMEM;
}
 
+   return index;
+}
+EXPORT_SYMBOL_GPL(__init_new_context);
+
+int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
+{
+   int index;
+
+   index = __init_new_context();
+   if (index  0)
+   return index;
+
/* The old code would re-promote on fork, we don't do that
 * when using slices as it could cause problem promoting slices
 * that have been forced down to 4K
@@ -68,11 +81,16 @@ again:
return 0;
 }
 
-void destroy_context(struct mm_struct *mm)
+void __destroy_context(int context_id)
 {
spin_lock(mmu_context_lock);
-   idr_remove(mmu_context_idr, mm-context.id);
+   idr_remove(mmu_context_idr, context_id);
spin_unlock(mmu_context_lock);
+}
+EXPORT_SYMBOL_GPL(__destroy_context);
 
+void destroy_context(struct mm_struct *mm)
+{
+   __destroy_context(mm-context.id);
mm-context.id = NO_CONTEXT;
 }
-- 
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 09/27] Add interrupt handling code

2009-09-29 Thread Alexander Graf
Getting from host state to the guest is only half the story. We also need
to return to our host context and handle whatever happened to get us out of
the guest.

On PowerPC every guest exit is an interrupt. So all we need to do is trap
the host's interrupt handlers and get into our #VMEXIT code to handle it.

PowerPCs also have a register that can add an offset to the interrupt handlers'
adresses which is what the booke KVM code uses. Unfortunately that is a
hypervisor ressource and we also want to be able to run KVM when we're running
in an LPAR. So we have to hook into the Linux interrupt handlers.

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

---

v3 - v4:

  - header rename fix
---
 arch/powerpc/kvm/book3s_64_rmhandlers.S |  131 +++
 1 files changed, 131 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_64_rmhandlers.S

diff --git a/arch/powerpc/kvm/book3s_64_rmhandlers.S 
b/arch/powerpc/kvm/book3s_64_rmhandlers.S
new file mode 100644
index 000..fb7dd2e
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_rmhandlers.S
@@ -0,0 +1,131 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright SUSE Linux Products GmbH 2009
+ *
+ * Authors: Alexander Graf ag...@suse.de
+ */
+
+#include asm/ppc_asm.h
+#include asm/kvm_asm.h
+#include asm/reg.h
+#include asm/page.h
+#include asm/asm-offsets.h
+#include asm/exception-64s.h
+
+/*
+ *   *
+ *Real Mode handlers that need to be in low physical memory  *
+ *   *
+ /
+
+
+.macro INTERRUPT_TRAMPOLINE intno
+
+.global kvmppc_trampoline_\intno
+kvmppc_trampoline_\intno:
+
+   mtspr   SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
+
+   /*
+* First thing to do is to find out if we're coming
+* from a KVM guest or a Linux process.
+*
+* To distinguish, we check a magic byte in the PACA
+*/
+   mfspr   r13, SPRN_SPRG_PACA /* r13 = PACA */
+   std r12, (PACA_EXMC + EX_R12)(r13)
+   mfcrr12
+   stw r12, (PACA_EXMC + EX_CCR)(r13)
+   lbz r12, PACA_KVM_IN_GUEST(r13)
+   cmpwi   r12, 0
+   bne ..kvmppc_handler_hasmagic_\intno
+   /* No KVM guest? Then jump back to the Linux handler! */
+   lwz r12, (PACA_EXMC + EX_CCR)(r13)
+   mtcrr12
+   ld  r12, (PACA_EXMC + EX_R12)(r13)
+   mfspr   r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
+   b   kvmppc_resume_\intno/* Get back original handler */
+
+   /* Now we know we're handling a KVM guest */
+..kvmppc_handler_hasmagic_\intno:
+   /* Unset guest state */
+   li  r12, 0
+   stb r12, PACA_KVM_IN_GUEST(r13)
+
+   std r1, (PACA_EXMC+EX_R9)(r13)
+   std r10, (PACA_EXMC+EX_R10)(r13)
+   std r11, (PACA_EXMC+EX_R11)(r13)
+   std r2, (PACA_EXMC+EX_R13)(r13)
+
+   mfsrr0  r10
+   mfsrr1  r11
+
+   /* Restore R1/R2 so we can handle faults */
+   ld  r1, PACAR1(r13)
+   ld  r2, (PACA_EXMC+EX_SRR0)(r13)
+
+   /* Let's store which interrupt we're handling */
+   li  r12, \intno
+
+   /* Jump into the SLB exit code that goes to the highmem handler */
+   b   kvmppc_handler_trampoline_exit
+
+.endm
+
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_SYSTEM_RESET
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_MACHINE_CHECK
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_DATA_STORAGE
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_DATA_SEGMENT
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_INST_STORAGE
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_INST_SEGMENT
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_EXTERNAL
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_ALIGNMENT
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_PROGRAM
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_FP_UNAVAIL
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_DECREMENTER
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_SYSCALL
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_TRACE
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_PERFMON
+INTERRUPT_TRAMPOLINE   BOOK3S_INTERRUPT_ALTIVEC
+INTERRUPT_TRAMPOLINE   

[PATCH 22/27] Add fields to PACA

2009-09-29 Thread Alexander Graf
For KVM we need to store some information in the PACA, so we
need to extend it.

This patch adds KVM SLB shadow related entries to the PACA and
a field that indicates if we're inside a guest.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/include/asm/paca.h |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 7d8514c..5e9b4ef 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -129,6 +129,15 @@ struct paca_struct {
u64 system_time;/* accumulated system TB ticks */
u64 startpurr;  /* PURR/TB value snapshot */
u64 startspurr; /* SPURR value snapshot */
+
+#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
+   struct  {
+   u64 esid;
+   u64 vsid;
+   } kvm_slb[64];  /* guest SLB */
+   u8 kvm_slb_max; /* highest used guest slb entry */
+   u8 kvm_in_guest;/* are we inside the guest? */
+#endif
 };
 
 extern struct paca_struct paca[];
-- 
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/27] Add book3s_64 Host MMU handling

2009-09-29 Thread Alexander Graf
We designed the Book3S port of KVM as modular as possible. Most
of the code could be easily used on a Book3S_32 host as well.

The main difference between 32 and 64 bit cores is the MMU. To keep
things well separated, we treat the book3s_64 MMU as one possible compile
option.

This patch adds all the MMU helpers the rest of the code needs in
order to modify the host's MMU, like setting PTEs and segments.

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

diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c 
b/arch/powerpc/kvm/book3s_64_mmu_host.c
new file mode 100644
index 000..507f770
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_mmu_host.c
@@ -0,0 +1,412 @@
+/*
+ * Copyright (C) 2009 SUSE Linux Products GmbH. All rights reserved.
+ *
+ * Authors:
+ * Alexander Graf ag...@suse.de
+ * Kevin Wolf m...@kevin-wolf.de
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+#include linux/kvm_host.h
+
+#include asm/kvm_ppc.h
+#include asm/kvm_book3s.h
+#include asm/mmu-hash64.h
+#include asm/machdep.h
+#include asm/mmu_context.h
+#include asm/hw_irq.h
+
+#define PTE_SIZE 12
+#define VSID_ALL 0
+
+// #define DEBUG_MMU
+// #define DEBUG_SLB
+
+void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 guest_ea, u64 ea_mask)
+{
+   int i;
+
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing %d Shadow PTEs: 0x%llx  0x%llx\n,
+   vcpu-arch.hpte_cache_offset, guest_ea, ea_mask);
+#endif
+   BUG_ON(vcpu-arch.hpte_cache_offset  HPTEG_CACHE_NUM);
+   guest_ea = ea_mask;
+   for (i=0; ivcpu-arch.hpte_cache_offset; i++) {
+   struct hpte_cache *pte;
+
+   pte = vcpu-arch.hpte_cache[i];
+   if (!pte-host_va)
+   continue;
+
+   if ((pte-pte.eaddr  ea_mask) == guest_ea) {
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing SPT %d: 0x%llx (0x%llx) - 0x%llx\n, 
i, pte-pte.eaddr, pte-pte.vpage, pte-host_va);
+#endif
+   ppc_md.hpte_invalidate(pte-slot, pte-host_va,
+  MMU_PAGE_4K, MMU_SEGSIZE_256M,
+  false);
+   pte-host_va = 0;
+   kvm_release_pfn_dirty(pte-pfn);
+   }
+   }
+
+   /* Doing a complete flush - start from scratch */
+   if (!ea_mask)
+   vcpu-arch.hpte_cache_offset = 0;
+}
+
+void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 guest_vp, u64 vp_mask)
+{
+   int i;
+
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing %d Shadow vPTEs: 0x%llx  0x%llx\n,
+   vcpu-arch.hpte_cache_offset, guest_vp, vp_mask);
+#endif
+   BUG_ON(vcpu-arch.hpte_cache_offset  HPTEG_CACHE_NUM);
+   guest_vp = vp_mask;
+   for (i=0; ivcpu-arch.hpte_cache_offset; i++) {
+   struct hpte_cache *pte;
+
+   pte = vcpu-arch.hpte_cache[i];
+   if (!pte-host_va)
+   continue;
+
+   if ((pte-pte.vpage  vp_mask) == guest_vp) {
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing SPT %d: 0x%llx (0x%llx) - 0x%llx\n, 
i, pte-pte.eaddr, pte-pte.vpage, pte-host_va);
+#endif
+   ppc_md.hpte_invalidate(pte-slot, pte-host_va,
+  MMU_PAGE_4K, MMU_SEGSIZE_256M,
+  false);
+   pte-host_va = 0;
+   kvm_release_pfn_dirty(pte-pfn);
+   }
+   }
+}
+
+void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end)
+{
+   int i;
+
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing %d Shadow pPTEs: 0x%llx  0x%llx\n,
+   vcpu-arch.hpte_cache_offset, guest_pa, pa_mask);
+#endif
+   BUG_ON(vcpu-arch.hpte_cache_offset  HPTEG_CACHE_NUM);
+
+   for (i=0; ivcpu-arch.hpte_cache_offset; i++) {
+   struct hpte_cache *pte;
+
+   pte = vcpu-arch.hpte_cache[i];
+   if (!pte-host_va)
+   continue;
+
+   if ((pte-pte.raddr = pa_start)  (pte-pte.raddr  pa_end)) {
+#ifdef DEBUG_MMU
+   printk(KERN_INFO KVM: Flushing SPT %d: 

[PATCH 24/27] Include Book3s_64 target in buildsystem

2009-09-29 Thread Alexander Graf
Now we have everything in place to be able to build KVM, so let's add it
as config option and in the Makefile.

Signed-off-by: Alexander Graf ag...@suse.de
---
 arch/powerpc/kvm/Kconfig  |   17 +
 arch/powerpc/kvm/Makefile |   27 +++
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index c299268..07703f7 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -21,6 +21,23 @@ config KVM
select PREEMPT_NOTIFIERS
select ANON_INODES
 
+config KVM_BOOK3S_64_HANDLER
+   bool
+
+config KVM_BOOK3S_64
+   tristate KVM support for PowerPC book3s_64 processors
+   depends on EXPERIMENTAL  PPC64
+   select KVM
+   select KVM_BOOK3S_64_HANDLER
+   ---help---
+ Support running unmodified book3s_64 and book3s_32 guest kernels
+ in virtual machines on book3s_64 host processors.
+
+ This module provides access to the hardware capabilities through
+ a character device node named /dev/kvm.
+
+ If unsure, say N.
+
 config KVM_440
bool KVM support for PowerPC 440 processors
depends on EXPERIMENTAL  44x
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index 37655fe..56484d6 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -12,26 +12,45 @@ CFLAGS_44x_tlb.o  := -I.
 CFLAGS_e500_tlb.o := -I.
 CFLAGS_emulate.o  := -I.
 
-kvm-objs := $(common-objs-y) powerpc.o emulate.o
+common-objs-y += powerpc.o emulate.o
 obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o
-obj-$(CONFIG_KVM) += kvm.o
+obj-$(CONFIG_KVM_BOOK3S_64_HANDLER) += book3s_64_exports.o
 
 AFLAGS_booke_interrupts.o := -I$(obj)
 
 kvm-440-objs := \
+   $(common-objs-y) \
booke.o \
booke_emulate.o \
booke_interrupts.o \
44x.o \
44x_tlb.o \
44x_emulate.o
-obj-$(CONFIG_KVM_440) += kvm-440.o
+kvm-objs-$(CONFIG_KVM_440) := $(kvm-440-objs)
 
 kvm-e500-objs := \
+   $(common-objs-y) \
booke.o \
booke_emulate.o \
booke_interrupts.o \
e500.o \
e500_tlb.o \
e500_emulate.o
-obj-$(CONFIG_KVM_E500) += kvm-e500.o
+kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs)
+
+kvm-book3s_64-objs := \
+   $(common-objs-y) \
+   book3s.o \
+   book3s_64_emulate.o \
+   book3s_64_interrupts.o \
+   book3s_64_mmu_host.o \
+   book3s_64_mmu.o \
+   book3s_32_mmu.o
+kvm-objs-$(CONFIG_KVM_BOOK3S_64) := $(kvm-book3s_64-objs)
+
+kvm-objs := $(kvm-objs-m) $(kvm-objs-y)
+
+obj-$(CONFIG_KVM_440) += kvm.o
+obj-$(CONFIG_KVM_E500) += kvm.o
+obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o
+
-- 
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/27] Fix trace.h

2009-09-29 Thread Alexander Graf
It looks like the variable pc is defined. At least the current code always
failed on me stating that pc is already defined somewhere else.

Let's use _pc instead, because that doesn't collide.

Is this the right approach? Does it break on 440 too? If not, why not?

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

diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
index 67f219d..a8e8400 100644
--- a/arch/powerpc/kvm/trace.h
+++ b/arch/powerpc/kvm/trace.h
@@ -12,8 +12,8 @@
  * Tracepoint for guest mode entry.
  */
 TRACE_EVENT(kvm_ppc_instr,
-   TP_PROTO(unsigned int inst, unsigned long pc, unsigned int emulate),
-   TP_ARGS(inst, pc, emulate),
+   TP_PROTO(unsigned int inst, unsigned long _pc, unsigned int emulate),
+   TP_ARGS(inst, _pc, emulate),
 
TP_STRUCT__entry(
__field(unsigned int,   inst)
@@ -23,7 +23,7 @@ TRACE_EVENT(kvm_ppc_instr,
 
TP_fast_assign(
__entry-inst   = inst;
-   __entry-pc = pc;
+   __entry-pc = _pc;
__entry-emulate= emulate;
),
 
-- 
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/27] Use Little Endian for Dirty Bitmap

2009-09-29 Thread Alexander Graf
We currently use host endian long types to store information
in the dirty bitmap.

This works reasonably well on Little Endian targets, because the
u32 after the first contains the next 32 bits. On Big Endian this
breaks completely though, forcing us to be inventive here.

So Ben suggested to always use Little Endian, which looks reasonable.

We only have dirty bitmap implemented in Little Endian targets so far
and since PowerPC would be the first Big Endian platform, we can just
as well switch to Little Endian always with little effort without
breaking existing targets.

Signed-off-by: Alexander Graf ag...@suse.de
---
 virt/kvm/kvm_main.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 91c0225..5aaa67c 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -48,6 +48,7 @@
 #include asm/io.h
 #include asm/uaccess.h
 #include asm/pgtable.h
+#include asm-generic/bitops/le.h
 
 #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
 #include coalesced_mmio.h
@@ -1062,8 +1063,8 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
unsigned long rel_gfn = gfn - memslot-base_gfn;
 
/* avoid RMW */
-   if (!test_bit(rel_gfn, memslot-dirty_bitmap))
-   set_bit(rel_gfn, memslot-dirty_bitmap);
+   if (!generic_test_le_bit(rel_gfn, memslot-dirty_bitmap))
+   generic___set_le_bit(rel_gfn, memslot-dirty_bitmap);
}
 }
 
-- 
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/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Alexander Graf
With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted  32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer interpreted
correctly, I just make it bounce twice, but admittedly that is not ideal.

I'm open for suggestions here.

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

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..91c0225 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -720,6 +720,11 @@ int kvm_get_dirty_log(struct kvm *kvm,
 
r = -EFAULT;
if (copy_to_user(log-dirty_bitmap, memslot-dirty_bitmap, n))
+#ifdef __BIG_ENDIAN
+   /* Did we get a 32 bit pointer? */
+   if (copy_to_user((void*)((u64)log-dirty_bitmap  32),
+memslot-dirty_bitmap, n))
+#endif
goto out;
 
if (any)
-- 
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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Alexander Graf


On 29.09.2009, at 11:14, Avi Kivity wrote:


On 09/29/2009 10:18 AM, Alexander Graf wrote:

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted  32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer  
interpreted
correctly, I just make it bounce twice, but admittedly that is not  
ideal.


I'm open for suggestions here.




How about adding a new union member to struct kvm_dirty_log:

 __u64 dirty_bitmap_virt;


And modifying userspace to write to that one?

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: linux-next: tree build failure

2009-09-29 Thread Jan Beulich
 Hollis Blanchard  09/29/09 2:00 AM 
First, I think there is a real bug here, and the code should read like
this (to match the comment):
/* type has to be known at build time for optimization */
-BUILD_BUG_ON(__builtin_constant_p(type));
+BUILD_BUG_ON(!__builtin_constant_p(type));

However, I get the same build error *both* ways, i.e.
__builtin_constant_p(type) evaluates to both 0 and 1? Either that, or
the new BUILD_BUG_ON() macro isn't working...

No, at this point of the compilation process it's neither zero nor one,
it's simply considered non-constant by the compiler at that stage
(this builtin is used for optimization, not during parsing, and the
error gets generated when the body of the function gets parsed,
not when code gets generated from it).

Jan

--
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: linux-next: tree build failure

2009-09-29 Thread roel kluin
On Tue, Sep 29, 2009 at 11:28 AM, Jan Beulich jbeul...@novell.com wrote:
 Hollis Blanchard  09/29/09 2:00 AM 
First, I think there is a real bug here, and the code should read like
this (to match the comment):
    /* type has to be known at build time for optimization */
-    BUILD_BUG_ON(__builtin_constant_p(type));
+    BUILD_BUG_ON(!__builtin_constant_p(type));

However, I get the same build error *both* ways, i.e.
__builtin_constant_p(type) evaluates to both 0 and 1? Either that, or
the new BUILD_BUG_ON() macro isn't working...

 No, at this point of the compilation process it's neither zero nor one,
 it's simply considered non-constant by the compiler at that stage
 (this builtin is used for optimization, not during parsing, and the
 error gets generated when the body of the function gets parsed,
 not when code gets generated from it).

 Jan

then maybe

if(__builtin_constant_p(type))
BUILD_BUG_ON(1);

would work?

Roel
--
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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Avi Kivity

On 09/29/2009 11:17 AM, Alexander Graf wrote:


On 29.09.2009, at 11:14, Avi Kivity wrote:


On 09/29/2009 10:18 AM, Alexander Graf wrote:

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted 32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer interpreted
correctly, I just make it bounce twice, but admittedly that is not
ideal.

I'm open for suggestions here.




How about adding a new union member to struct kvm_dirty_log:

__u64 dirty_bitmap_virt;


And modifying userspace to write to that one?



Yes - old userspace will still build and work (we don't remove the old 
field) on little endian or BE32, new userspace will work on all 
flavours.  We need new userspace anyway to take advantage of dirty logging.


--
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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Alexander Graf


Am 29.09.2009 um 06:25 schrieb Avi Kivity a...@redhat.com:


On 09/29/2009 11:17 AM, Alexander Graf wrote:


On 29.09.2009, at 11:14, Avi Kivity wrote:


On 09/29/2009 10:18 AM, Alexander Graf wrote:

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted 32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer  
interpreted

correctly, I just make it bounce twice, but admittedly that is not
ideal.

I'm open for suggestions here.




How about adding a new union member to struct kvm_dirty_log:

__u64 dirty_bitmap_virt;


And modifying userspace to write to that one?



Yes - old userspace will still build and work (we don't remove the  
old field) on little endian or BE32, new userspace will work on all  
flavours.  We need new userspace anyway to take advantage of dirty  
logging.


Uh, the dirty logging bits are in place already IIRC :)

But yes, sounds like the cleaner way to do it.

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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Alexander Graf


On 29.09.2009, at 15:25, Avi Kivity wrote:


On 09/29/2009 11:17 AM, Alexander Graf wrote:


On 29.09.2009, at 11:14, Avi Kivity wrote:


On 09/29/2009 10:18 AM, Alexander Graf wrote:

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted 32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer  
interpreted

correctly, I just make it bounce twice, but admittedly that is not
ideal.

I'm open for suggestions here.




How about adding a new union member to struct kvm_dirty_log:

__u64 dirty_bitmap_virt;


And modifying userspace to write to that one?



Yes - old userspace will still build and work (we don't remove the  
old field) on little endian or BE32, new userspace will work on all  
flavours.  We need new userspace anyway to take advantage of dirty  
logging.


How about this one? (broken whitespace!)

From c3864a2c5e1fccff7839e47f12c09d9739ca441e Mon Sep 17 00:00:00 2001
From: Alexander Graf ag...@suse.de
Date: Thu, 23 Jul 2009 21:05:57 +0200
Subject: [PATCH] Enable 32bit dirty log pointers on 64bit host

With big endian userspace, passing a pointer from 32-bit userspace to
64-bit kernel space breaks.

This is what happens with dirty logging. To get the pointer interpreted
correctly, we can just check the guest's 32bit flag and treat the  
pointer

as 32 bits then.

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

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..00f2c59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -703,6 +703,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
int r, i;
int n;
unsigned long any = 0;
+   void *target_bm;

r = -EINVAL;
if (log-slot = KVM_MEMORY_SLOTS)
@@ -718,8 +719,15 @@ int kvm_get_dirty_log(struct kvm *kvm,
for (i = 0; !any  i  n/sizeof(long); ++i)
any = memslot-dirty_bitmap[i];

+#if defined(__BIG_ENDIAN)  defined(CONFIG_64BIT)
+   /* Need to convert user pointers */
+   if (test_thread_flag(TIF_32BIT))
+   target_bm = (void*)((u64)log-dirty_bitmap  32);
+   else
+#endif
+   target_bm = log-dirty_bitmap;
r = -EFAULT;
-   if (copy_to_user(log-dirty_bitmap, memslot-dirty_bitmap, n))
+   if (copy_to_user(target_bm, memslot-dirty_bitmap, n))
goto out;

if (any)
--
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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Avi Kivity

On 09/29/2009 06:29 PM, Alexander Graf wrote:


How about this one? (broken whitespace!)

From c3864a2c5e1fccff7839e47f12c09d9739ca441e Mon Sep 17 00:00:00 2001
From: Alexander Graf ag...@suse.de
Date: Thu, 23 Jul 2009 21:05:57 +0200
Subject: [PATCH] Enable 32bit dirty log pointers on 64bit host

With big endian userspace, passing a pointer from 32-bit userspace to
64-bit kernel space breaks.

This is what happens with dirty logging. To get the pointer interpreted
correctly, we can just check the guest's 32bit flag and treat the pointer
as 32 bits then.

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

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..00f2c59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -703,6 +703,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
int r, i;
int n;
unsigned long any = 0;
+   void *target_bm;


void __user *target_bm;



r = -EINVAL;
if (log-slot = KVM_MEMORY_SLOTS)
@@ -718,8 +719,15 @@ int kvm_get_dirty_log(struct kvm *kvm,
for (i = 0; !any  i  n/sizeof(long); ++i)
any = memslot-dirty_bitmap[i];

+#if defined(__BIG_ENDIAN)  defined(CONFIG_64BIT)
+   /* Need to convert user pointers */
+   if (test_thread_flag(TIF_32BIT))
+   target_bm = (void*)((u64)log-dirty_bitmap  32);
+   else
+#endif
+   target_bm = log-dirty_bitmap;
r = -EFAULT;
-   if (copy_to_user(log-dirty_bitmap, memslot-dirty_bitmap, n))
+   if (copy_to_user(target_bm, memslot-dirty_bitmap, n))
goto out;

if (any)


Ah, that's much better.  Plus a mental note not to put pointers in 
user-visible structures in the future.  This can serve as a reminder :)


--
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 26/27] Enable 32bit dirty log pointers on 64bit host

2009-09-29 Thread Alexander Graf


On 29.09.2009, at 18:42, Avi Kivity wrote:


On 09/29/2009 06:29 PM, Alexander Graf wrote:


How about this one? (broken whitespace!)

From c3864a2c5e1fccff7839e47f12c09d9739ca441e Mon Sep 17 00:00:00  
2001

From: Alexander Graf ag...@suse.de
Date: Thu, 23 Jul 2009 21:05:57 +0200
Subject: [PATCH] Enable 32bit dirty log pointers on 64bit host

With big endian userspace, passing a pointer from 32-bit userspace to
64-bit kernel space breaks.

This is what happens with dirty logging. To get the pointer  
interpreted
correctly, we can just check the guest's 32bit flag and treat the  
pointer

as 32 bits then.

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

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e27b7a9..00f2c59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -703,6 +703,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
   int r, i;
   int n;
   unsigned long any = 0;
+   void *target_bm;


void __user *target_bm;


k, done.





   r = -EINVAL;
   if (log-slot = KVM_MEMORY_SLOTS)
@@ -718,8 +719,15 @@ int kvm_get_dirty_log(struct kvm *kvm,
   for (i = 0; !any  i  n/sizeof(long); ++i)
   any = memslot-dirty_bitmap[i];

+#if defined(__BIG_ENDIAN)  defined(CONFIG_64BIT)
+   /* Need to convert user pointers */
+   if (test_thread_flag(TIF_32BIT))
+   target_bm = (void*)((u64)log-dirty_bitmap  32);
+   else
+#endif
+   target_bm = log-dirty_bitmap;
   r = -EFAULT;
-   if (copy_to_user(log-dirty_bitmap, memslot-dirty_bitmap,  
n))

+   if (copy_to_user(target_bm, memslot-dirty_bitmap, n))
   goto out;

   if (any)


Ah, that's much better.  Plus a mental note not to put pointers in  
user-visible structures in the future.  This can serve as a  
reminder :)


Heh, yeah :). At times like this I see the benefits of little endian...

The new code is in git://csgraf.de/kvm branch ppc-v5.
(Don't expect to pull updates from that branch until I release it - I  
will push -f in there, breaking git pull.)


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