[PATCH/RFC] kvm/powerpc: Add new ioctl to retreive support page sizes and encodings

2012-03-16 Thread Benjamin Herrenschmidt
This is necessary for qemu to be able to pass the right information
to the guest, as the supported sizes and encodings can vary depending
on the machine, the type of KVM used (PR vs HV) and the version of KVM

Signed-off-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---

Please comment ASAP. I'm tired of the qemu side never working properly
because of that and our out-of-tree nasty patches we've been carrying
internally, so I'd like to get something like that in real quick :-)

I have the qemu side patches that use this to generate the appropriate
device-tree when available, and use heuristics for the fallback. I'll
post them later, let's agree on the kernel interfaces first.

The heuristics work as long as we have a reasonable guarantee that this
kernel patch will get in -before- any patch that enables the PVINFO
ioctl on HV KVM, that way I can rely on the later not working as
a way to differenciate PR and HV KVM if this new ioctl is not supported. 

Note: We probably want an other ioctl for getting other type of
MMU info, such as whether we support 1T segments etc... but I didn't
want to try to kill to many birds at once and end up in bike shed
painting on the mailing list for the next 6 month...

Cheers,
Ben.

 arch/powerpc/include/asm/kvm_ppc.h |3 ++-
 arch/powerpc/kvm/book3s_hv.c   |   35 +++
 arch/powerpc/kvm/book3s_pr.c   |   22 ++
 arch/powerpc/kvm/powerpc.c |   18 +-
 include/linux/kvm.h|   29 +
 5 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index c1069f6..bf530fd 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -140,7 +140,8 @@ extern int kvmppc_core_prepare_memory_region(struct kvm 
*kvm,
struct kvm_userspace_memory_region *mem);
 extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
struct kvm_userspace_memory_region *mem);
-
+extern int kvm_vm_ioctl_get_page_sizes(struct kvm *kvm,
+  struct kvm_ppc_page_sizes *ps);
 extern int kvmppc_bookehv_init(void);
 extern void kvmppc_bookehv_exit(void);
 
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 8ee46b9..c7f7f20 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1174,6 +1174,37 @@ long kvm_vm_ioctl_allocate_rma(struct kvm *kvm, struct 
kvm_allocate_rma *ret)
return fd;
 }
 
+static void kvmppc_add_seg_page_size(struct kvm_ppc_one_seg_page_size **sps,
+int linux_psize)
+{
+   struct mmu_psize_def *def = mmu_psize_defs[linux_psize];
+
+   if (!def-shift)
+   return;
+   *sps-page_shift = def-shift;
+   *sps-slb_enc = def-sllp;
+   *sps-enc[0].page_shift = def-shift;
+   *sps-enc[0].pte_enc = def-penc;
+   *sps++;
+}
+
+int kvm_vm_ioctl_get_page_sizes(struct kvm *kvm, struct kvm_ppc_page_sizes *ps)
+{
+   struct kvm_ppc_one_seg_page_size *sps;
+   int i;
+
+   /* Page sizes limited by backing store */
+   ps-flags = KVM_PPC_PAGE_SIZES_REAL;
+
+   /* We only support these sizes for now, and no muti-size segments */
+   sps = ps-sps[0];
+   kvmppc_add_seg_page_size(sps, MMU_PAGE_4K);
+   kvmppc_add_seg_page_size(sps, MMU_PAGE_64K);
+   kvmppc_add_seg_page_size(sps, MMU_PAGE_16M);
+
+   return 0;
+}
+
 /*
  * Get (and clear) the dirty memory log for a memory slot.
  */
@@ -1211,6 +1242,10 @@ out:
return r;
 }
 
+int kvm_vm_ioctl_get_page_sizes(struct kvm *kvm, struct kvm_ppc_page_sizes *ps)
+{
+}
+
 static unsigned long slb_pgsize_encoding(unsigned long psize)
 {
unsigned long senc = 0;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 5f0ee48..3c823ed 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1154,6 +1154,28 @@ out:
return r;
 }
 
+#ifdef CONFIG_PPC64
+int kvm_vm_ioctl_get_page_sizes(struct kvm *kvm, struct kvm_ppc_page_sizes *ps)
+{
+   /* No flags */
+   ps-flags = 0;
+
+   /* Standard 4k base page size segment */
+   ps-sps[0].page_shift = 12;
+   ps-sps[0].slb_enc = 0;
+   ps-sps[0].enc[0].page_shift = 12;
+   ps-sps[0].enc[0].pte_enc = 0;
+
+   /* Standard 16M large page size segment */
+   ps-sps[1].page_shift = 24;
+   ps-sps[1].slb_enc = SLB_VSID_L;
+   ps-sps[1].enc[0].page_shift = 24;
+   ps-sps[1].enc[0].pte_enc = 0;
+
+   return 0;
+}
+#endif /* CONFIG_PPC64 */
+
 int kvmppc_core_prepare_memory_region(struct kvm *kvm,
  struct kvm_userspace_memory_region *mem)
 {
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 6ac3115..6f0c066 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ 

[PATCH v2] kvm/book3s: Make kernel emulated H_PUT_TCE available for PR KVM

2012-03-16 Thread Benjamin Herrenschmidt
There is nothing in the code for emulating TCE tables in the kernel
that prevents it from working on PR KVM... other than ifdef's and
location of the code.

This renames book3s_64_vio_hv.c to book3s_64_vio.c and moves the
bulk of the code there.

This speeds things up a bit on my G5.
---

v2. Changed the ifdef as per discussion with Alex. I still didn't
manage to get git to figure out the rename but that's no big deal,
the old file had only one small function in it. There's no code
change, you can trust me on that one, It's really just moving
things around :-)

 arch/powerpc/include/asm/kvm_host.h |4 +-
 arch/powerpc/include/asm/kvm_ppc.h  |2 +
 arch/powerpc/kvm/Makefile   |3 +-
 arch/powerpc/kvm/book3s_64_vio.c|  187 +++
 arch/powerpc/kvm/book3s_64_vio_hv.c |   73 --
 arch/powerpc/kvm/book3s_hv.c|  109 
 arch/powerpc/kvm/book3s_pr.c|3 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   18 
 arch/powerpc/kvm/powerpc.c  |8 +-
 9 files changed, 221 insertions(+), 186 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_64_vio.c
 delete mode 100644 arch/powerpc/kvm/book3s_64_vio_hv.c

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 42a527e..d848cdc 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -237,7 +237,6 @@ struct kvm_arch {
unsigned long vrma_slb_v;
int rma_setup_done;
int using_mmu_notifiers;
-   struct list_head spapr_tce_tables;
spinlock_t slot_phys_lock;
unsigned long *slot_phys[KVM_MEM_SLOTS_NUM];
int slot_npages[KVM_MEM_SLOTS_NUM];
@@ -245,6 +244,9 @@ struct kvm_arch {
struct kvmppc_vcore *vcores[KVM_MAX_VCORES];
struct kvmppc_linear_info *hpt_li;
 #endif /* CONFIG_KVM_BOOK3S_64_HV */
+#ifdef CONFIG_PPC_BOOK3S_64
+   struct list_head spapr_tce_tables;
+#endif
 };
 
 /*
diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index 7f0a3da..c1069f6 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -126,6 +126,8 @@ extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,
 extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
 extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
struct kvm_create_spapr_tce *args);
+extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
+unsigned long ioba, unsigned long tce);
 extern long kvm_vm_ioctl_allocate_rma(struct kvm *kvm,
struct kvm_allocate_rma *rma);
 extern struct kvmppc_linear_info *kvm_alloc_rma(void);
diff --git a/arch/powerpc/kvm/Makefile b/arch/powerpc/kvm/Makefile
index 25225ae..8c95def 100644
--- a/arch/powerpc/kvm/Makefile
+++ b/arch/powerpc/kvm/Makefile
@@ -54,6 +54,7 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \
book3s_paired_singles.o \
book3s_pr.o \
book3s_pr_papr.o \
+   book3s_64_vio.o \
book3s_emulate.o \
book3s_interrupts.o \
book3s_mmu_hpte.o \
@@ -70,7 +71,7 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \
 kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \
book3s_hv_rmhandlers.o \
book3s_hv_rm_mmu.o \
-   book3s_64_vio_hv.o \
+   book3s_64_vio.o \
book3s_hv_builtin.o
 
 kvm-book3s_64-module-objs := \
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
new file mode 100644
index 000..193ba68
--- /dev/null
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -0,0 +1,187 @@
+/*
+ * 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 2010 Paul Mackerras, IBM Corp. pau...@au1.ibm.com
+ * Copyright 2011 David Gibson, IBM Corporation d...@au1.ibm.com
+ */
+
+#include linux/types.h
+#include linux/string.h
+#include linux/kvm.h
+#include linux/kvm_host.h
+#include linux/highmem.h
+#include linux/gfp.h
+#include linux/slab.h
+#include linux/hugetlb.h
+#include linux/list.h
+#include linux/anon_inodes.h
+
+#include asm/tlbflush.h
+#include asm/kvm_ppc.h
+#include asm/kvm_book3s.h
+#include asm/mmu-hash64.h
+#include asm/hvcall.h
+#include asm/synch.h
+#include asm/ppc-opcode.h
+#include asm/kvm_host.h
+#include asm/udbg.h
+
+#define TCES_PER_PAGE  

[no subject]

2012-03-16 Thread Luis
--
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