All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-17  5:00 ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Hi all,

This is a series for kvmtool that uses a newish kernel API to get
MMU info, which is then fed to the guest.

Currently we just make a good guess based on the PVR, but that is
potentially flakey in a few ways. The most notable is that if you don't
specify hugepages we don't boot - because the guest is told we support
16M pages, but we don't really (on HV).

I've tested this with 4K/64K host page size, and with hugepages, on
both 3.4 and 3.5 based host kernels. I've also given it a quick smoke
test with PR KVM, and it seems to work.

I'm seeing a guest crash with a 4K host kernel, but I think that is
unrelated, and happens with or without this patch series.

cheers


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-17  5:00 ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Hi all,

This is a series for kvmtool that uses a newish kernel API to get
MMU info, which is then fed to the guest.

Currently we just make a good guess based on the PVR, but that is
potentially flakey in a few ways. The most notable is that if you don't
specify hugepages we don't boot - because the guest is told we support
16M pages, but we don't really (on HV).

I've tested this with 4K/64K host page size, and with hugepages, on
both 3.4 and 3.5 based host kernels. I've also given it a quick smoke
test with PR KVM, and it seems to work.

I'm seeing a guest crash with a 4K host kernel, but I think that is
unrelated, and happens with or without this patch series.

cheers


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 01/10] kvm tools: Move mmap_anon_or_hugetblfs() into util
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

So we can use it on powerpc.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/include/kvm/util.h |    2 +-
 tools/kvm/util/util.c        |   13 +++++++++++++
 tools/kvm/x86/kvm.c          |   13 -------------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index dabf544..3d1d987 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -90,6 +90,6 @@ static inline void msleep(unsigned int msecs)
 	usleep(MSECS_TO_USECS(msecs));
 }
 
-void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
+void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size);
 
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index e7feebc..a80cf86 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -113,3 +113,16 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 
 	return addr;
 }
+
+/* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
+void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
+{
+	if (hugetlbfs_path)
+		/*
+		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
+		 * if the user specifies a hugetlbfs path.
+		 */
+		return mmap_hugetlbfs(hugetlbfs_path, size);
+	else
+		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
+}
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 10a1212..8931639 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -128,19 +128,6 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 		strcat(cmdline, " console=ttyS0 earlyprintk=serial i8042.noaux=1");
 }
 
-/* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
-static void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
-{
-	if (hugetlbfs_path)
-		/*
-		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
-		 * if the user specifies a hugetlbfs path.
-		 */
-		return mmap_hugetlbfs(hugetlbfs_path, size);
-	else
-		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
-}
-
 /* Architecture-specific KVM init */
 void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 {
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 01/10] kvm tools: Move mmap_anon_or_hugetblfs() into util
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

So we can use it on powerpc.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/include/kvm/util.h |    2 +-
 tools/kvm/util/util.c        |   13 +++++++++++++
 tools/kvm/x86/kvm.c          |   13 -------------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index dabf544..3d1d987 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -90,6 +90,6 @@ static inline void msleep(unsigned int msecs)
 	usleep(MSECS_TO_USECS(msecs));
 }
 
-void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
+void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size);
 
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index e7feebc..a80cf86 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -113,3 +113,16 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 
 	return addr;
 }
+
+/* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
+void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
+{
+	if (hugetlbfs_path)
+		/*
+		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
+		 * if the user specifies a hugetlbfs path.
+		 */
+		return mmap_hugetlbfs(hugetlbfs_path, size);
+	else
+		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
+}
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 10a1212..8931639 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -128,19 +128,6 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 		strcat(cmdline, " console=ttyS0 earlyprintk=serial i8042.noaux=1");
 }
 
-/* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
-static void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
-{
-	if (hugetlbfs_path)
-		/*
-		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
-		 * if the user specifies a hugetlbfs path.
-		 */
-		return mmap_hugetlbfs(hugetlbfs_path, size);
-	else
-		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
-}
-
 /* Architecture-specific KVM init */
 void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 {
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 02/10] kvm tools, powerpc: Use mmap_anon_or_hugetblfs() in kvm__arch_init()
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

It implements essentially the same logic. The one difference is it sets
MAP_NORESERVE when using anonymous mmap, but I think that is OK.

Reword the comment about hugetblfs, we are no longer required to use
hugepages to back the guest.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/kvm.c |   20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index cbc0d8f..0d8a9da 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -97,20 +97,12 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 
 	kvm->ram_size		= ram_size;
 
-	/*
-	 * Currently, HV-mode PPC64 SPAPR requires that we map from hugetlfs.
-	 * Allow a 'default' option to assist.
-	 * PR-mode does not require this.
-	 */
-	if (hugetlbfs_path) {
-		if (!strcmp(hugetlbfs_path, "default"))
-			hugetlbfs_path = HUGETLBFS_PATH;
-		kvm->ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm->ram_size);
-	} else {
-		kvm->ram_start = mmap(0, kvm->ram_size, PROT_READ | PROT_WRITE,
-				      MAP_ANON | MAP_PRIVATE,
-				      -1, 0);
-	}
+	/* Map "default" hugetblfs path to the standard 16M mount point */
+	if (hugetlbfs_path && !strcmp(hugetlbfs_path, "default"))
+		hugetlbfs_path = HUGETLBFS_PATH;
+
+	kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, kvm->ram_size);
+
 	if (kvm->ram_start == MAP_FAILED)
 		die("Couldn't map %lld bytes for RAM (%d)\n",
 		    kvm->ram_size, errno);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 02/10] kvm tools, powerpc: Use mmap_anon_or_hugetblfs() in kvm__arch_init()
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

It implements essentially the same logic. The one difference is it sets
MAP_NORESERVE when using anonymous mmap, but I think that is OK.

Reword the comment about hugetblfs, we are no longer required to use
hugepages to back the guest.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/kvm.c |   20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index cbc0d8f..0d8a9da 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -97,20 +97,12 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 
 	kvm->ram_size		= ram_size;
 
-	/*
-	 * Currently, HV-mode PPC64 SPAPR requires that we map from hugetlfs.
-	 * Allow a 'default' option to assist.
-	 * PR-mode does not require this.
-	 */
-	if (hugetlbfs_path) {
-		if (!strcmp(hugetlbfs_path, "default"))
-			hugetlbfs_path = HUGETLBFS_PATH;
-		kvm->ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm->ram_size);
-	} else {
-		kvm->ram_start = mmap(0, kvm->ram_size, PROT_READ | PROT_WRITE,
-				      MAP_ANON | MAP_PRIVATE,
-				      -1, 0);
-	}
+	/* Map "default" hugetblfs path to the standard 16M mount point */
+	if (hugetlbfs_path && !strcmp(hugetlbfs_path, "default"))
+		hugetlbfs_path = HUGETLBFS_PATH;
+
+	kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, kvm->ram_size);
+
 	if (kvm->ram_start = MAP_FAILED)
 		die("Couldn't map %lld bytes for RAM (%d)\n",
 		    kvm->ram_size, errno);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 03/10] kvm tools: Remember page size as kvm->ram_pagesize
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

On some powerpc platforms we need to make sure we only advertise page
sizes to the guest which are <= the size of the pages backing guest RAM.

So have mmap_hugetblfs() save the hugetblfs page size for us, and also
teach mmap_anon_or_hugetblfs() to set the page size for anonymous mmap.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/include/kvm/util.h             |    4 +++-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |    1 +
 tools/kvm/powerpc/kvm.c                  |    2 +-
 tools/kvm/util/util.c                    |   13 +++++++++----
 tools/kvm/x86/include/kvm/kvm-arch.h     |    1 +
 tools/kvm/x86/kvm.c                      |    4 ++--
 6 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index 3d1d987..0df9f0d 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -90,6 +90,8 @@ static inline void msleep(unsigned int msecs)
 	usleep(MSECS_TO_USECS(msecs));
 }
 
-void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size);
+struct kvm;
+void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size);
+void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size);
 
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 404e33e..316fe79 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -54,6 +54,7 @@ struct kvm {
 
 	u64			ram_size;
 	void			*ram_start;
+	u64			ram_pagesize;
 
 	u64			sdr1;
 	u32			pvr;
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 0d8a9da..e3a7e52 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -101,7 +101,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 	if (hugetlbfs_path && !strcmp(hugetlbfs_path, "default"))
 		hugetlbfs_path = HUGETLBFS_PATH;
 
-	kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, kvm->ram_size);
+	kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, kvm->ram_size);
 
 	if (kvm->ram_start == MAP_FAILED)
 		die("Couldn't map %lld bytes for RAM (%d)\n",
diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index a80cf86..c11a15a 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -4,6 +4,7 @@
 
 #include "kvm/util.h"
 
+#include <kvm/kvm.h>
 #include <linux/magic.h>	/* For HUGETLBFS_MAGIC */
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -80,7 +81,7 @@ void die_perror(const char *s)
 	exit(1);
 }
 
-void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
+void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size)
 {
 	char mpath[PATH_MAX];
 	int fd;
@@ -100,6 +101,8 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 		    blk_size, size);
 	}
 
+	kvm->ram_pagesize = blk_size;
+
 	snprintf(mpath, PATH_MAX, "%s/kvmtoolXXXXXX", htlbfs_path);
 	fd = mkstemp(mpath);
 	if (fd < 0)
@@ -115,14 +118,16 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 }
 
 /* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
-void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
+void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size)
 {
 	if (hugetlbfs_path)
 		/*
 		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
 		 * if the user specifies a hugetlbfs path.
 		 */
-		return mmap_hugetlbfs(hugetlbfs_path, size);
-	else
+		return mmap_hugetlbfs(kvm, hugetlbfs_path, size);
+	else {
+		kvm->ram_pagesize = getpagesize();
 		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
+	}
 }
diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h b/tools/kvm/x86/include/kvm/kvm-arch.h
index 551c8b4..dd385d4 100644
--- a/tools/kvm/x86/include/kvm/kvm-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-arch.h
@@ -34,6 +34,7 @@ struct kvm {
 
 	u64			ram_size;
 	void			*ram_start;
+	u64			ram_pagesize;
 
 	bool			nmi_disabled;
 
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 8931639..0a40fd5 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -144,9 +144,9 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 
 	if (ram_size < KVM_32BIT_GAP_START) {
 		kvm->ram_size = ram_size;
-		kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size);
+		kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size);
 	} else {
-		kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE);
+		kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE);
 		kvm->ram_size = ram_size + KVM_32BIT_GAP_SIZE;
 		if (kvm->ram_start != MAP_FAILED)
 			/*
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 03/10] kvm tools: Remember page size as kvm->ram_pagesize
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

On some powerpc platforms we need to make sure we only advertise page
sizes to the guest which are <= the size of the pages backing guest RAM.

So have mmap_hugetblfs() save the hugetblfs page size for us, and also
teach mmap_anon_or_hugetblfs() to set the page size for anonymous mmap.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/include/kvm/util.h             |    4 +++-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |    1 +
 tools/kvm/powerpc/kvm.c                  |    2 +-
 tools/kvm/util/util.c                    |   13 +++++++++----
 tools/kvm/x86/include/kvm/kvm-arch.h     |    1 +
 tools/kvm/x86/kvm.c                      |    4 ++--
 6 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index 3d1d987..0df9f0d 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -90,6 +90,8 @@ static inline void msleep(unsigned int msecs)
 	usleep(MSECS_TO_USECS(msecs));
 }
 
-void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size);
+struct kvm;
+void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size);
+void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size);
 
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 404e33e..316fe79 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -54,6 +54,7 @@ struct kvm {
 
 	u64			ram_size;
 	void			*ram_start;
+	u64			ram_pagesize;
 
 	u64			sdr1;
 	u32			pvr;
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 0d8a9da..e3a7e52 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -101,7 +101,7 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 	if (hugetlbfs_path && !strcmp(hugetlbfs_path, "default"))
 		hugetlbfs_path = HUGETLBFS_PATH;
 
-	kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, kvm->ram_size);
+	kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, kvm->ram_size);
 
 	if (kvm->ram_start = MAP_FAILED)
 		die("Couldn't map %lld bytes for RAM (%d)\n",
diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index a80cf86..c11a15a 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -4,6 +4,7 @@
 
 #include "kvm/util.h"
 
+#include <kvm/kvm.h>
 #include <linux/magic.h>	/* For HUGETLBFS_MAGIC */
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -80,7 +81,7 @@ void die_perror(const char *s)
 	exit(1);
 }
 
-void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
+void *mmap_hugetlbfs(struct kvm *kvm, const char *htlbfs_path, u64 size)
 {
 	char mpath[PATH_MAX];
 	int fd;
@@ -100,6 +101,8 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 		    blk_size, size);
 	}
 
+	kvm->ram_pagesize = blk_size;
+
 	snprintf(mpath, PATH_MAX, "%s/kvmtoolXXXXXX", htlbfs_path);
 	fd = mkstemp(mpath);
 	if (fd < 0)
@@ -115,14 +118,16 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 }
 
 /* This function wraps the decision between hugetlbfs map (if requested) or normal mmap */
-void *mmap_anon_or_hugetlbfs(const char *hugetlbfs_path, u64 size)
+void *mmap_anon_or_hugetlbfs(struct kvm *kvm, const char *hugetlbfs_path, u64 size)
 {
 	if (hugetlbfs_path)
 		/*
 		 * We don't /need/ to map guest RAM from hugetlbfs, but we do so
 		 * if the user specifies a hugetlbfs path.
 		 */
-		return mmap_hugetlbfs(hugetlbfs_path, size);
-	else
+		return mmap_hugetlbfs(kvm, hugetlbfs_path, size);
+	else {
+		kvm->ram_pagesize = getpagesize();
 		return mmap(NULL, size, PROT_RW, MAP_ANON_NORESERVE, -1, 0);
+	}
 }
diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h b/tools/kvm/x86/include/kvm/kvm-arch.h
index 551c8b4..dd385d4 100644
--- a/tools/kvm/x86/include/kvm/kvm-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-arch.h
@@ -34,6 +34,7 @@ struct kvm {
 
 	u64			ram_size;
 	void			*ram_start;
+	u64			ram_pagesize;
 
 	bool			nmi_disabled;
 
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 8931639..0a40fd5 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -144,9 +144,9 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 
 	if (ram_size < KVM_32BIT_GAP_START) {
 		kvm->ram_size = ram_size;
-		kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size);
+		kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size);
 	} else {
-		kvm->ram_start = mmap_anon_or_hugetlbfs(hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE);
+		kvm->ram_start = mmap_anon_or_hugetlbfs(kvm, hugetlbfs_path, ram_size + KVM_32BIT_GAP_SIZE);
 		kvm->ram_size = ram_size + KVM_32BIT_GAP_SIZE;
 		if (kvm->ram_start != MAP_FAILED)
 			/*
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 04/10] kvm tools, powerpc: Use designated initializers for struct cpu_info
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Using designated initializers for structs is preferable because it
is self documenting, and more robust against changes to the structure
layout.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |   38 +++++++++++++++++++++-----------------
 tools/kvm/powerpc/cpu_info.h |    6 +++---
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index c364b74..ad27451 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -30,14 +30,16 @@ static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1
 static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 static struct cpu_info cpu_power7_info = {
-	"POWER7",
-	power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
-	power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
-	32, 		/* SLB size */
-	512000000, 	/* TB frequency */
-	128,		/* d-cache block size */
-	128,		/* i-cache block size */
-	CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
+	.name = "POWER7",
+	.page_sizes_prop = power7_page_sizes_prop,
+	.page_sizes_prop_len = sizeof(power7_segment_sizes_prop),
+	.segment_sizes_prop = power7_segment_sizes_prop,
+	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
+	.slb_size = 32,
+	.tb_freq = 512000000,
+	.d_bsize = 128,
+	.i_bsize = 128,
+	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
 };
 
 /* PPC970/G5 */
@@ -45,18 +47,20 @@ static struct cpu_info cpu_power7_info = {
 static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
 
 static struct cpu_info cpu_970_info = {
-	"G5",
-	g5_page_sizes_prop, sizeof(g5_page_sizes_prop),
-	0 /* Null = no segment sizes prop, use defaults */, 0,
-	0, 		/* SLB size default */
-	33333333, 	/* TB frequency */
-	128,		/* d-cache block size */
-	128,		/* i-cache block size */
-	CPUINFO_FLAG_VMX
+	.name = "G5",
+	.page_sizes_prop = g5_page_sizes_prop,
+	.page_sizes_prop_len = sizeof(g5_page_sizes_prop),
+	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
+	.segment_sizes_prop_len = 0,
+	.slb_size = 0,
+	.tb_freq = 33333333,
+	.d_bsize = 128,
+	.i_bsize = 128,
+	.flags = CPUINFO_FLAG_VMX,
 };
 
 /* This is a default catchall for 'no match' on PVR: */
-static struct cpu_info cpu_dummy_info = { "unknown", 0, 0, 0, 0, 0, 0, 0, 0 };
+static struct cpu_info cpu_dummy_info = { .name = "unknown" };
 
 static struct pvr_info host_pvr_info[] = {
 	{ 0xffffffff, 0x0f000003, &cpu_power7_info },
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 4a43ed5..2115c7f 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -21,9 +21,9 @@ struct cpu_info {
 	u32 		*segment_sizes_prop;
 	u32		segment_sizes_prop_len;
 	u32		slb_size;
-	u32		tb_freq;
-	u32		d_bsize;
-	u32		i_bsize;
+	u32		tb_freq; /* timebase frequency */
+	u32		d_bsize; /* d-cache block size */
+	u32		i_bsize; /* i-cache block size */
 	u32		flags;
 };
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 04/10] kvm tools, powerpc: Use designated initializers for struct cpu_info
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Using designated initializers for structs is preferable because it
is self documenting, and more robust against changes to the structure
layout.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |   38 +++++++++++++++++++++-----------------
 tools/kvm/powerpc/cpu_info.h |    6 +++---
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index c364b74..ad27451 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -30,14 +30,16 @@ static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1
 static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 static struct cpu_info cpu_power7_info = {
-	"POWER7",
-	power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
-	power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
-	32, 		/* SLB size */
-	512000000, 	/* TB frequency */
-	128,		/* d-cache block size */
-	128,		/* i-cache block size */
-	CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
+	.name = "POWER7",
+	.page_sizes_prop = power7_page_sizes_prop,
+	.page_sizes_prop_len = sizeof(power7_segment_sizes_prop),
+	.segment_sizes_prop = power7_segment_sizes_prop,
+	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
+	.slb_size = 32,
+	.tb_freq = 512000000,
+	.d_bsize = 128,
+	.i_bsize = 128,
+	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
 };
 
 /* PPC970/G5 */
@@ -45,18 +47,20 @@ static struct cpu_info cpu_power7_info = {
 static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
 
 static struct cpu_info cpu_970_info = {
-	"G5",
-	g5_page_sizes_prop, sizeof(g5_page_sizes_prop),
-	0 /* Null = no segment sizes prop, use defaults */, 0,
-	0, 		/* SLB size default */
-	33333333, 	/* TB frequency */
-	128,		/* d-cache block size */
-	128,		/* i-cache block size */
-	CPUINFO_FLAG_VMX
+	.name = "G5",
+	.page_sizes_prop = g5_page_sizes_prop,
+	.page_sizes_prop_len = sizeof(g5_page_sizes_prop),
+	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
+	.segment_sizes_prop_len = 0,
+	.slb_size = 0,
+	.tb_freq = 33333333,
+	.d_bsize = 128,
+	.i_bsize = 128,
+	.flags = CPUINFO_FLAG_VMX,
 };
 
 /* This is a default catchall for 'no match' on PVR: */
-static struct cpu_info cpu_dummy_info = { "unknown", 0, 0, 0, 0, 0, 0, 0, 0 };
+static struct cpu_info cpu_dummy_info = { .name = "unknown" };
 
 static struct pvr_info host_pvr_info[] = {
 	{ 0xffffffff, 0x0f000003, &cpu_power7_info },
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 4a43ed5..2115c7f 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -21,9 +21,9 @@ struct cpu_info {
 	u32 		*segment_sizes_prop;
 	u32		segment_sizes_prop_len;
 	u32		slb_size;
-	u32		tb_freq;
-	u32		d_bsize;
-	u32		i_bsize;
+	u32		tb_freq; /* timebase frequency */
+	u32		d_bsize; /* d-cache block size */
+	u32		i_bsize; /* i-cache block size */
 	u32		flags;
 };
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 05/10] kvm tools, powerpc: Use ARRAY_SIZE() in find_cpu_info()
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index ad27451..7326f5b 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -75,7 +75,7 @@ static struct pvr_info host_pvr_info[] = {
 struct cpu_info *find_cpu_info(u32 pvr)
 {
 	unsigned int i;
-	for (i = 0; i < sizeof(host_pvr_info)/sizeof(struct pvr_info); i++) {
+	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
 		if ((pvr & host_pvr_info[i].pvr_mask) ==
 		    host_pvr_info[i].pvr) {
 			return host_pvr_info[i].cpu_info;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 05/10] kvm tools, powerpc: Use ARRAY_SIZE() in find_cpu_info()
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index ad27451..7326f5b 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -75,7 +75,7 @@ static struct pvr_info host_pvr_info[] = {
 struct cpu_info *find_cpu_info(u32 pvr)
 {
 	unsigned int i;
-	for (i = 0; i < sizeof(host_pvr_info)/sizeof(struct pvr_info); i++) {
+	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
 		if ((pvr & host_pvr_info[i].pvr_mask) =
 		    host_pvr_info[i].pvr) {
 			return host_pvr_info[i].cpu_info;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 06/10] kvm tools, powerpc: Reformatting in find_cpu_info()
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Matt's enter key was broken when he wrote this ;)

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 7326f5b..586b232 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -75,13 +75,15 @@ static struct pvr_info host_pvr_info[] = {
 struct cpu_info *find_cpu_info(u32 pvr)
 {
 	unsigned int i;
+
 	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
-		if ((pvr & host_pvr_info[i].pvr_mask) ==
-		    host_pvr_info[i].pvr) {
+		if ((pvr & host_pvr_info[i].pvr_mask) == host_pvr_info[i].pvr) {
 			return host_pvr_info[i].cpu_info;
 		}
 	}
+
 	/* Didn't find anything? Rut-ro. */
 	pr_warning("Host CPU unsupported by kvmtool\n");
+
 	return &cpu_dummy_info;
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 06/10] kvm tools, powerpc: Reformatting in find_cpu_info()
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Matt's enter key was broken when he wrote this ;)

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 7326f5b..586b232 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -75,13 +75,15 @@ static struct pvr_info host_pvr_info[] = {
 struct cpu_info *find_cpu_info(u32 pvr)
 {
 	unsigned int i;
+
 	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
-		if ((pvr & host_pvr_info[i].pvr_mask) =
-		    host_pvr_info[i].pvr) {
+		if ((pvr & host_pvr_info[i].pvr_mask) = host_pvr_info[i].pvr) {
 			return host_pvr_info[i].cpu_info;
 		}
 	}
+
 	/* Didn't find anything? Rut-ro. */
 	pr_warning("Host CPU unsupported by kvmtool\n");
+
 	return &cpu_dummy_info;
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 07/10] kvm tools, powerpc: Restructure find_cpu_info()
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

We are about to add more logic to find_cpu_info(). To support this we
need to pass kvm through to it, and also restructure the return flow
so we can operate on info before it is returned.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |   16 +++++++++++-----
 tools/kvm/powerpc/cpu_info.h |    4 +++-
 tools/kvm/powerpc/kvm.c      |    2 +-
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 586b232..5015a4b 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -72,18 +72,24 @@ static struct pvr_info host_pvr_info[] = {
         { 0xffff0000, 0x00450000, &cpu_970_info },
 };
 
-struct cpu_info *find_cpu_info(u32 pvr)
+struct cpu_info *find_cpu_info(struct kvm *kvm)
 {
+	struct cpu_info *info;
 	unsigned int i;
+	u32 pvr = kvm->pvr;
 
-	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
+	for (info = NULL, i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
 		if ((pvr & host_pvr_info[i].pvr_mask) == host_pvr_info[i].pvr) {
-			return host_pvr_info[i].cpu_info;
+			info = host_pvr_info[i].cpu_info;
+			break;
 		}
 	}
 
 	/* Didn't find anything? Rut-ro. */
-	pr_warning("Host CPU unsupported by kvmtool\n");
+	if (!info) {
+		pr_warning("Host CPU unsupported by kvmtool\n");
+		info = &cpu_dummy_info;
+	}
 
-	return &cpu_dummy_info;
+	return info;
 }
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 2115c7f..439f3940 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -11,6 +11,8 @@
 #ifndef CPU_INFO_H
 #define CPU_INFO_H
 
+#include <kvm/kvm.h>
+
 #include <linux/types.h>
 #include <linux/kernel.h>
 
@@ -38,6 +40,6 @@ struct pvr_info {
 #define CPUINFO_FLAG_VMX	0x00000002
 #define CPUINFO_FLAG_VSX	0x00000004
 
-struct cpu_info *find_cpu_info(u32 pvr);
+struct cpu_info *find_cpu_info(struct kvm *kvm);
 
 #endif
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index e3a7e52..dbfea3e 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -229,7 +229,7 @@ static void setup_fdt(struct kvm *kvm)
 	int 		i, j;
 	char 		cpu_name[30];
 	u8		staging_fdt[FDT_MAX_SIZE];
-	struct cpu_info *cpu_info = find_cpu_info(kvm->pvr);
+	struct cpu_info *cpu_info = find_cpu_info(kvm);
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 07/10] kvm tools, powerpc: Restructure find_cpu_info()
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

We are about to add more logic to find_cpu_info(). To support this we
need to pass kvm through to it, and also restructure the return flow
so we can operate on info before it is returned.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |   16 +++++++++++-----
 tools/kvm/powerpc/cpu_info.h |    4 +++-
 tools/kvm/powerpc/kvm.c      |    2 +-
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 586b232..5015a4b 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -72,18 +72,24 @@ static struct pvr_info host_pvr_info[] = {
         { 0xffff0000, 0x00450000, &cpu_970_info },
 };
 
-struct cpu_info *find_cpu_info(u32 pvr)
+struct cpu_info *find_cpu_info(struct kvm *kvm)
 {
+	struct cpu_info *info;
 	unsigned int i;
+	u32 pvr = kvm->pvr;
 
-	for (i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
+	for (info = NULL, i = 0; i < ARRAY_SIZE(host_pvr_info); i++) {
 		if ((pvr & host_pvr_info[i].pvr_mask) = host_pvr_info[i].pvr) {
-			return host_pvr_info[i].cpu_info;
+			info = host_pvr_info[i].cpu_info;
+			break;
 		}
 	}
 
 	/* Didn't find anything? Rut-ro. */
-	pr_warning("Host CPU unsupported by kvmtool\n");
+	if (!info) {
+		pr_warning("Host CPU unsupported by kvmtool\n");
+		info = &cpu_dummy_info;
+	}
 
-	return &cpu_dummy_info;
+	return info;
 }
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 2115c7f..439f3940 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -11,6 +11,8 @@
 #ifndef CPU_INFO_H
 #define CPU_INFO_H
 
+#include <kvm/kvm.h>
+
 #include <linux/types.h>
 #include <linux/kernel.h>
 
@@ -38,6 +40,6 @@ struct pvr_info {
 #define CPUINFO_FLAG_VMX	0x00000002
 #define CPUINFO_FLAG_VSX	0x00000004
 
-struct cpu_info *find_cpu_info(u32 pvr);
+struct cpu_info *find_cpu_info(struct kvm *kvm);
 
 #endif
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index e3a7e52..dbfea3e 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -229,7 +229,7 @@ static void setup_fdt(struct kvm *kvm)
 	int 		i, j;
 	char 		cpu_name[30];
 	u8		staging_fdt[FDT_MAX_SIZE];
-	struct cpu_info *cpu_info = find_cpu_info(kvm->pvr);
+	struct cpu_info *cpu_info = find_cpu_info(kvm);
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 08/10] kvm tools, powerpc: Use MMU info from the kernel for ibm,segment-page-sizes
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Recent kernels (>= v3.5-rc1) have an ioctl which allows us to retrieve the
list of page sizes supported for the guest.

So rework the cpu info code to use that ioctl when available, falling
back to the same values we used previously if the ioctl is not present.

We may also need to filter the list of page sizes against the page size
of the memory backing guest RAM - this accounts for the unfortunate amount
of code in setup_mmu_info().

Finally we need to turn the structure as returned by the kernel into the
format expected in the device tree.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |  132 ++++++++++++++++++++++++++++++++++++++----
 tools/kvm/powerpc/cpu_info.h |    4 +-
 tools/kvm/powerpc/kvm.c      |   81 +++++++++++++++++++++++++-
 3 files changed, 200 insertions(+), 17 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 5015a4b..1cfb50d 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -15,24 +15,19 @@
  * by the Free Software Foundation.
  */
 
+#include <kvm/kvm.h>
+#include <sys/ioctl.h>
+
 #include "cpu_info.h"
 #include "kvm/util.h"
 
 /* POWER7 */
 
-/*
- * Basic set of pages for POWER7.  It actually supports more but there were some
- * limitations as to which may be advertised to the guest.  FIXME when this
- * settles down -- for now use basic set:
- */
-static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
 /* POWER7 has 1T segments, so advertise these */
 static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.page_sizes_prop = power7_page_sizes_prop,
-	.page_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.segment_sizes_prop = power7_segment_sizes_prop,
 	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.slb_size = 32,
@@ -40,16 +35,15 @@ static struct cpu_info cpu_power7_info = {
 	.d_bsize = 128,
 	.i_bsize = 128,
 	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
+	.mmu_info = {
+		.flags = KVM_PPC_PAGE_SIZES_REAL | KVM_PPC_1T_SEGMENTS,
+	},
 };
 
 /* PPC970/G5 */
 
-static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
-
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.page_sizes_prop = g5_page_sizes_prop,
-	.page_sizes_prop_len = sizeof(g5_page_sizes_prop),
 	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
 	.segment_sizes_prop_len = 0,
 	.slb_size = 0,
@@ -72,6 +66,118 @@ static struct pvr_info host_pvr_info[] = {
         { 0xffff0000, 0x00450000, &cpu_970_info },
 };
 
+/* If we can't query the kernel for supported page sizes assume 4K and 16M */
+static struct kvm_ppc_one_seg_page_size fallback_sps[] = {
+	[0] = {
+		.page_shift = 12,
+		.slb_enc    = 0,
+		.enc =  {
+			[0] = {
+				.page_shift = 12,
+				.pte_enc    = 0,
+			},
+		},
+	},
+	[1] = {
+		.page_shift = 24,
+		.slb_enc    = 0x100,
+		.enc =  {
+			[0] = {
+				.page_shift = 24,
+				.pte_enc    = 0,
+			},
+		},
+	},
+};
+
+
+static void setup_mmu_info(struct kvm *kvm, struct cpu_info *cpu_info)
+{
+	static struct kvm_ppc_smmu_info *mmu_info;
+	struct kvm_ppc_one_seg_page_size *sps;
+	int i, j, k, valid;
+
+	if (!kvm__supports_extension(kvm, KVM_CAP_PPC_GET_SMMU_INFO)) {
+		memcpy(&cpu_info->mmu_info.sps, fallback_sps, sizeof(fallback_sps));
+	} else if (ioctl(kvm->vm_fd, KVM_PPC_GET_SMMU_INFO, &cpu_info->mmu_info) < 0) {
+			die_perror("KVM_PPC_GET_SMMU_INFO failed");
+	}
+
+	mmu_info = &cpu_info->mmu_info;
+
+	if (!(mmu_info->flags & KVM_PPC_PAGE_SIZES_REAL))
+		/* Guest pages are not restricted by the backing page size */
+		return;
+
+	/* Filter based on backing page size */
+
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &mmu_info->sps[i];
+
+		if (!sps->page_shift)
+			break;
+
+		if (kvm->ram_pagesize < (1ul << sps->page_shift)) {
+			/* Mark the whole segment size invalid */
+			sps->page_shift = 0;
+			continue;
+		}
+
+		/* Check each page size for the segment */
+		for (j = 0, valid = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (!sps->enc[j].page_shift)
+				break;
+
+			if (kvm->ram_pagesize < (1ul << sps->enc[j].page_shift))
+				sps->enc[j].page_shift = 0;
+			else
+				valid++;
+		}
+
+		if (!valid) {
+			/* Mark the whole segment size invalid */
+			sps->page_shift = 0;
+			continue;
+		}
+
+		/* Mark any trailing entries invalid if we broke out early */
+		for (k = j; k < KVM_PPC_PAGE_SIZES_MAX_SZ; k++)
+			sps->enc[k].page_shift = 0;
+
+		/* Collapse holes */
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (sps->enc[j].page_shift)
+				continue;
+
+			for (k = j + 1; k < KVM_PPC_PAGE_SIZES_MAX_SZ; k++) {
+				if (sps->enc[k].page_shift) {
+					sps->enc[j] = sps->enc[k];
+					sps->enc[k].page_shift = 0;
+					break;
+				}
+			}
+		}
+	}
+
+	/* Mark any trailing entries invalid if we broke out early */
+	for (j = i; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
+		mmu_info->sps[j].page_shift = 0;
+
+	/* Collapse holes */
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		if (mmu_info->sps[i].page_shift)
+			continue;
+
+		for (j = i + 1; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (mmu_info->sps[j].page_shift) {
+				mmu_info->sps[i] = mmu_info->sps[j];
+				mmu_info->sps[j].page_shift = 0;
+				break;
+			}
+		}
+	}
+}
+
 struct cpu_info *find_cpu_info(struct kvm *kvm)
 {
 	struct cpu_info *info;
@@ -91,5 +197,7 @@ struct cpu_info *find_cpu_info(struct kvm *kvm)
 		info = &cpu_dummy_info;
 	}
 
+	setup_mmu_info(kvm, info);
+
 	return info;
 }
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 439f3940..9da6afe 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -15,11 +15,10 @@
 
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/kvm.h>
 
 struct cpu_info {
 	const char	*name;
-	u32 		*page_sizes_prop;
-	u32		page_sizes_prop_len;
 	u32 		*segment_sizes_prop;
 	u32		segment_sizes_prop_len;
 	u32		slb_size;
@@ -27,6 +26,7 @@ struct cpu_info {
 	u32		d_bsize; /* d-cache block size */
 	u32		i_bsize; /* i-cache block size */
 	u32		flags;
+	struct kvm_ppc_smmu_info mmu_info;
 };
 
 struct pvr_info {
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index dbfea3e..293812a 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -211,6 +211,74 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
 	return false;
 }
 
+struct fdt_prop {
+	void *value;
+	int size;
+};
+
+static void generate_segment_page_sizes(struct kvm_ppc_smmu_info *info, struct fdt_prop *prop)
+{
+	struct kvm_ppc_one_seg_page_size *sps;
+	int i, j, size;
+	u32 *p;
+
+	for (size = 0, i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &info->sps[i];
+
+		if (sps->page_shift == 0)
+			break;
+
+		/* page shift, slb enc & count */
+		size += 3;
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (info->sps[i].enc[j].page_shift == 0)
+				break;
+
+			/* page shift & pte enc */
+			size += 2;
+		}
+	}
+
+	if (!size) {
+		prop->value = NULL;
+		prop->size = 0;
+		return;
+	}
+
+	/* Convert size to bytes */
+	prop->size = size * sizeof(u32);
+
+	prop->value = malloc(prop->size);
+	if (!prop->value)
+		die_perror("malloc failed");
+
+	p = (u32 *)prop->value;
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &info->sps[i];
+
+		if (sps->page_shift == 0)
+			break;
+
+		*p++ = sps->page_shift;
+		*p++ = sps->slb_enc;
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
+			if (!info->sps[i].enc[j].page_shift)
+				break;
+
+		*p++ = j;	/* count of enc */
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (!info->sps[i].enc[j].page_shift)
+				break;
+
+			*p++ = info->sps[i].enc[j].page_shift;
+			*p++ = info->sps[i].enc[j].pte_enc;
+		}
+	}
+}
+
 #define SMT_THREADS 4
 
 /*
@@ -230,6 +298,7 @@ static void setup_fdt(struct kvm *kvm)
 	char 		cpu_name[30];
 	u8		staging_fdt[FDT_MAX_SIZE];
 	struct cpu_info *cpu_info = find_cpu_info(kvm);
+	struct fdt_prop segment_page_sizes;
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
@@ -293,6 +362,8 @@ static void setup_fdt(struct kvm *kvm)
 			  sizeof(mem_reg_property)));
 	_FDT(fdt_end_node(fdt));
 
+	generate_segment_page_sizes(&cpu_info->mmu_info, &segment_page_sizes);
+
 	/* CPUs */
 	_FDT(fdt_begin_node(fdt, "cpus"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
@@ -347,10 +418,12 @@ static void setup_fdt(struct kvm *kvm)
 		_FDT(fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
 				  gservers_prop,
 				  threads * 2 * sizeof(uint32_t)));
-		if (cpu_info->page_sizes_prop)
+
+		if (segment_page_sizes.value)
 			_FDT(fdt_property(fdt, "ibm,segment-page-sizes",
-					  cpu_info->page_sizes_prop,
-					  cpu_info->page_sizes_prop_len));
+					  segment_page_sizes.value,
+					  segment_page_sizes.size));
+
 		if (cpu_info->segment_sizes_prop)
 			_FDT(fdt_property(fdt, "ibm,processor-segment-sizes",
 					  cpu_info->segment_sizes_prop,
@@ -411,6 +484,8 @@ static void setup_fdt(struct kvm *kvm)
 
 	_FDT(fdt_add_mem_rsv(fdt_dest, kvm->rtas_gra, kvm->rtas_size));
 	_FDT(fdt_pack(fdt_dest));
+
+	free(segment_page_sizes.value);
 }
 
 /**
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 08/10] kvm tools, powerpc: Use MMU info from the kernel for ibm,segment-page-sizes
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Recent kernels (>= v3.5-rc1) have an ioctl which allows us to retrieve the
list of page sizes supported for the guest.

So rework the cpu info code to use that ioctl when available, falling
back to the same values we used previously if the ioctl is not present.

We may also need to filter the list of page sizes against the page size
of the memory backing guest RAM - this accounts for the unfortunate amount
of code in setup_mmu_info().

Finally we need to turn the structure as returned by the kernel into the
format expected in the device tree.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |  132 ++++++++++++++++++++++++++++++++++++++----
 tools/kvm/powerpc/cpu_info.h |    4 +-
 tools/kvm/powerpc/kvm.c      |   81 +++++++++++++++++++++++++-
 3 files changed, 200 insertions(+), 17 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 5015a4b..1cfb50d 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -15,24 +15,19 @@
  * by the Free Software Foundation.
  */
 
+#include <kvm/kvm.h>
+#include <sys/ioctl.h>
+
 #include "cpu_info.h"
 #include "kvm/util.h"
 
 /* POWER7 */
 
-/*
- * Basic set of pages for POWER7.  It actually supports more but there were some
- * limitations as to which may be advertised to the guest.  FIXME when this
- * settles down -- for now use basic set:
- */
-static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
 /* POWER7 has 1T segments, so advertise these */
 static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.page_sizes_prop = power7_page_sizes_prop,
-	.page_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.segment_sizes_prop = power7_segment_sizes_prop,
 	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.slb_size = 32,
@@ -40,16 +35,15 @@ static struct cpu_info cpu_power7_info = {
 	.d_bsize = 128,
 	.i_bsize = 128,
 	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
+	.mmu_info = {
+		.flags = KVM_PPC_PAGE_SIZES_REAL | KVM_PPC_1T_SEGMENTS,
+	},
 };
 
 /* PPC970/G5 */
 
-static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 0x18, 0x0};
-
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.page_sizes_prop = g5_page_sizes_prop,
-	.page_sizes_prop_len = sizeof(g5_page_sizes_prop),
 	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
 	.segment_sizes_prop_len = 0,
 	.slb_size = 0,
@@ -72,6 +66,118 @@ static struct pvr_info host_pvr_info[] = {
         { 0xffff0000, 0x00450000, &cpu_970_info },
 };
 
+/* If we can't query the kernel for supported page sizes assume 4K and 16M */
+static struct kvm_ppc_one_seg_page_size fallback_sps[] = {
+	[0] = {
+		.page_shift = 12,
+		.slb_enc    = 0,
+		.enc =  {
+			[0] = {
+				.page_shift = 12,
+				.pte_enc    = 0,
+			},
+		},
+	},
+	[1] = {
+		.page_shift = 24,
+		.slb_enc    = 0x100,
+		.enc =  {
+			[0] = {
+				.page_shift = 24,
+				.pte_enc    = 0,
+			},
+		},
+	},
+};
+
+
+static void setup_mmu_info(struct kvm *kvm, struct cpu_info *cpu_info)
+{
+	static struct kvm_ppc_smmu_info *mmu_info;
+	struct kvm_ppc_one_seg_page_size *sps;
+	int i, j, k, valid;
+
+	if (!kvm__supports_extension(kvm, KVM_CAP_PPC_GET_SMMU_INFO)) {
+		memcpy(&cpu_info->mmu_info.sps, fallback_sps, sizeof(fallback_sps));
+	} else if (ioctl(kvm->vm_fd, KVM_PPC_GET_SMMU_INFO, &cpu_info->mmu_info) < 0) {
+			die_perror("KVM_PPC_GET_SMMU_INFO failed");
+	}
+
+	mmu_info = &cpu_info->mmu_info;
+
+	if (!(mmu_info->flags & KVM_PPC_PAGE_SIZES_REAL))
+		/* Guest pages are not restricted by the backing page size */
+		return;
+
+	/* Filter based on backing page size */
+
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &mmu_info->sps[i];
+
+		if (!sps->page_shift)
+			break;
+
+		if (kvm->ram_pagesize < (1ul << sps->page_shift)) {
+			/* Mark the whole segment size invalid */
+			sps->page_shift = 0;
+			continue;
+		}
+
+		/* Check each page size for the segment */
+		for (j = 0, valid = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (!sps->enc[j].page_shift)
+				break;
+
+			if (kvm->ram_pagesize < (1ul << sps->enc[j].page_shift))
+				sps->enc[j].page_shift = 0;
+			else
+				valid++;
+		}
+
+		if (!valid) {
+			/* Mark the whole segment size invalid */
+			sps->page_shift = 0;
+			continue;
+		}
+
+		/* Mark any trailing entries invalid if we broke out early */
+		for (k = j; k < KVM_PPC_PAGE_SIZES_MAX_SZ; k++)
+			sps->enc[k].page_shift = 0;
+
+		/* Collapse holes */
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (sps->enc[j].page_shift)
+				continue;
+
+			for (k = j + 1; k < KVM_PPC_PAGE_SIZES_MAX_SZ; k++) {
+				if (sps->enc[k].page_shift) {
+					sps->enc[j] = sps->enc[k];
+					sps->enc[k].page_shift = 0;
+					break;
+				}
+			}
+		}
+	}
+
+	/* Mark any trailing entries invalid if we broke out early */
+	for (j = i; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
+		mmu_info->sps[j].page_shift = 0;
+
+	/* Collapse holes */
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		if (mmu_info->sps[i].page_shift)
+			continue;
+
+		for (j = i + 1; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (mmu_info->sps[j].page_shift) {
+				mmu_info->sps[i] = mmu_info->sps[j];
+				mmu_info->sps[j].page_shift = 0;
+				break;
+			}
+		}
+	}
+}
+
 struct cpu_info *find_cpu_info(struct kvm *kvm)
 {
 	struct cpu_info *info;
@@ -91,5 +197,7 @@ struct cpu_info *find_cpu_info(struct kvm *kvm)
 		info = &cpu_dummy_info;
 	}
 
+	setup_mmu_info(kvm, info);
+
 	return info;
 }
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 439f3940..9da6afe 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -15,11 +15,10 @@
 
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/kvm.h>
 
 struct cpu_info {
 	const char	*name;
-	u32 		*page_sizes_prop;
-	u32		page_sizes_prop_len;
 	u32 		*segment_sizes_prop;
 	u32		segment_sizes_prop_len;
 	u32		slb_size;
@@ -27,6 +26,7 @@ struct cpu_info {
 	u32		d_bsize; /* d-cache block size */
 	u32		i_bsize; /* i-cache block size */
 	u32		flags;
+	struct kvm_ppc_smmu_info mmu_info;
 };
 
 struct pvr_info {
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index dbfea3e..293812a 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -211,6 +211,74 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
 	return false;
 }
 
+struct fdt_prop {
+	void *value;
+	int size;
+};
+
+static void generate_segment_page_sizes(struct kvm_ppc_smmu_info *info, struct fdt_prop *prop)
+{
+	struct kvm_ppc_one_seg_page_size *sps;
+	int i, j, size;
+	u32 *p;
+
+	for (size = 0, i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &info->sps[i];
+
+		if (sps->page_shift = 0)
+			break;
+
+		/* page shift, slb enc & count */
+		size += 3;
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (info->sps[i].enc[j].page_shift = 0)
+				break;
+
+			/* page shift & pte enc */
+			size += 2;
+		}
+	}
+
+	if (!size) {
+		prop->value = NULL;
+		prop->size = 0;
+		return;
+	}
+
+	/* Convert size to bytes */
+	prop->size = size * sizeof(u32);
+
+	prop->value = malloc(prop->size);
+	if (!prop->value)
+		die_perror("malloc failed");
+
+	p = (u32 *)prop->value;
+	for (i = 0; i < KVM_PPC_PAGE_SIZES_MAX_SZ; i++) {
+		sps = &info->sps[i];
+
+		if (sps->page_shift = 0)
+			break;
+
+		*p++ = sps->page_shift;
+		*p++ = sps->slb_enc;
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++)
+			if (!info->sps[i].enc[j].page_shift)
+				break;
+
+		*p++ = j;	/* count of enc */
+
+		for (j = 0; j < KVM_PPC_PAGE_SIZES_MAX_SZ; j++) {
+			if (!info->sps[i].enc[j].page_shift)
+				break;
+
+			*p++ = info->sps[i].enc[j].page_shift;
+			*p++ = info->sps[i].enc[j].pte_enc;
+		}
+	}
+}
+
 #define SMT_THREADS 4
 
 /*
@@ -230,6 +298,7 @@ static void setup_fdt(struct kvm *kvm)
 	char 		cpu_name[30];
 	u8		staging_fdt[FDT_MAX_SIZE];
 	struct cpu_info *cpu_info = find_cpu_info(kvm);
+	struct fdt_prop segment_page_sizes;
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
@@ -293,6 +362,8 @@ static void setup_fdt(struct kvm *kvm)
 			  sizeof(mem_reg_property)));
 	_FDT(fdt_end_node(fdt));
 
+	generate_segment_page_sizes(&cpu_info->mmu_info, &segment_page_sizes);
+
 	/* CPUs */
 	_FDT(fdt_begin_node(fdt, "cpus"));
 	_FDT(fdt_property_cell(fdt, "#address-cells", 0x1));
@@ -347,10 +418,12 @@ static void setup_fdt(struct kvm *kvm)
 		_FDT(fdt_property(fdt, "ibm,ppc-interrupt-gserver#s",
 				  gservers_prop,
 				  threads * 2 * sizeof(uint32_t)));
-		if (cpu_info->page_sizes_prop)
+
+		if (segment_page_sizes.value)
 			_FDT(fdt_property(fdt, "ibm,segment-page-sizes",
-					  cpu_info->page_sizes_prop,
-					  cpu_info->page_sizes_prop_len));
+					  segment_page_sizes.value,
+					  segment_page_sizes.size));
+
 		if (cpu_info->segment_sizes_prop)
 			_FDT(fdt_property(fdt, "ibm,processor-segment-sizes",
 					  cpu_info->segment_sizes_prop,
@@ -411,6 +484,8 @@ static void setup_fdt(struct kvm *kvm)
 
 	_FDT(fdt_add_mem_rsv(fdt_dest, kvm->rtas_gra, kvm->rtas_size));
 	_FDT(fdt_pack(fdt_dest));
+
+	free(segment_page_sizes.value);
 }
 
 /**
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 09/10] kvm tools, powerpc: Use MMU info for ibm,processor-segment-sizes
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    7 -------
 tools/kvm/powerpc/cpu_info.h |    2 --
 tools/kvm/powerpc/kvm.c      |    7 ++++---
 3 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 1cfb50d..82a9d4f 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -23,13 +23,8 @@
 
 /* POWER7 */
 
-/* POWER7 has 1T segments, so advertise these */
-static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
-
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.segment_sizes_prop = power7_segment_sizes_prop,
-	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.slb_size = 32,
 	.tb_freq = 512000000,
 	.d_bsize = 128,
@@ -44,8 +39,6 @@ static struct cpu_info cpu_power7_info = {
 
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
-	.segment_sizes_prop_len = 0,
 	.slb_size = 0,
 	.tb_freq = 33333333,
 	.d_bsize = 128,
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 9da6afe..00b9436b 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -19,8 +19,6 @@
 
 struct cpu_info {
 	const char	*name;
-	u32 		*segment_sizes_prop;
-	u32		segment_sizes_prop_len;
 	u32		slb_size;
 	u32		tb_freq; /* timebase frequency */
 	u32		d_bsize; /* d-cache block size */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 293812a..8353355 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -299,6 +299,7 @@ static void setup_fdt(struct kvm *kvm)
 	u8		staging_fdt[FDT_MAX_SIZE];
 	struct cpu_info *cpu_info = find_cpu_info(kvm);
 	struct fdt_prop segment_page_sizes;
+	u32 segment_sizes_1T[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
@@ -424,10 +425,10 @@ static void setup_fdt(struct kvm *kvm)
 					  segment_page_sizes.value,
 					  segment_page_sizes.size));
 
-		if (cpu_info->segment_sizes_prop)
+		if (cpu_info->mmu_info.flags & KVM_PPC_1T_SEGMENTS)
 			_FDT(fdt_property(fdt, "ibm,processor-segment-sizes",
-					  cpu_info->segment_sizes_prop,
-					  cpu_info->segment_sizes_prop_len));
+					  segment_sizes_1T, sizeof(segment_sizes_1T)));
+
 		/* VSX / DFP options: */
 		if (cpu_info->flags & CPUINFO_FLAG_VMX)
 			_FDT(fdt_property_cell(fdt, "ibm,vmx",
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 09/10] kvm tools, powerpc: Use MMU info for ibm,processor-segment-sizes
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    7 -------
 tools/kvm/powerpc/cpu_info.h |    2 --
 tools/kvm/powerpc/kvm.c      |    7 ++++---
 3 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 1cfb50d..82a9d4f 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -23,13 +23,8 @@
 
 /* POWER7 */
 
-/* POWER7 has 1T segments, so advertise these */
-static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
-
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.segment_sizes_prop = power7_segment_sizes_prop,
-	.segment_sizes_prop_len = sizeof(power7_segment_sizes_prop),
 	.slb_size = 32,
 	.tb_freq = 512000000,
 	.d_bsize = 128,
@@ -44,8 +39,6 @@ static struct cpu_info cpu_power7_info = {
 
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.segment_sizes_prop = NULL /* no segment sizes prop, use defaults */,
-	.segment_sizes_prop_len = 0,
 	.slb_size = 0,
 	.tb_freq = 33333333,
 	.d_bsize = 128,
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 9da6afe..00b9436b 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -19,8 +19,6 @@
 
 struct cpu_info {
 	const char	*name;
-	u32 		*segment_sizes_prop;
-	u32		segment_sizes_prop_len;
 	u32		slb_size;
 	u32		tb_freq; /* timebase frequency */
 	u32		d_bsize; /* d-cache block size */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 293812a..8353355 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -299,6 +299,7 @@ static void setup_fdt(struct kvm *kvm)
 	u8		staging_fdt[FDT_MAX_SIZE];
 	struct cpu_info *cpu_info = find_cpu_info(kvm);
 	struct fdt_prop segment_page_sizes;
+	u32 segment_sizes_1T[] = {0x1c, 0x28, 0xffffffff, 0xffffffff};
 
 	/* Generate an appropriate DT at kvm->fdt_gra */
 	void *fdt_dest = guest_flat_to_host(kvm, kvm->fdt_gra);
@@ -424,10 +425,10 @@ static void setup_fdt(struct kvm *kvm)
 					  segment_page_sizes.value,
 					  segment_page_sizes.size));
 
-		if (cpu_info->segment_sizes_prop)
+		if (cpu_info->mmu_info.flags & KVM_PPC_1T_SEGMENTS)
 			_FDT(fdt_property(fdt, "ibm,processor-segment-sizes",
-					  cpu_info->segment_sizes_prop,
-					  cpu_info->segment_sizes_prop_len));
+					  segment_sizes_1T, sizeof(segment_sizes_1T)));
+
 		/* VSX / DFP options: */
 		if (cpu_info->flags & CPUINFO_FLAG_VMX)
 			_FDT(fdt_property_cell(fdt, "ibm,vmx",
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 10/10] kvm tools, powerpc: Use MMU info for ibm,slb-size
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  5:00   ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    3 +--
 tools/kvm/powerpc/cpu_info.h |    1 -
 tools/kvm/powerpc/kvm.c      |    5 +++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 82a9d4f..1f440a5 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -25,13 +25,13 @@
 
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.slb_size = 32,
 	.tb_freq = 512000000,
 	.d_bsize = 128,
 	.i_bsize = 128,
 	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
 	.mmu_info = {
 		.flags = KVM_PPC_PAGE_SIZES_REAL | KVM_PPC_1T_SEGMENTS,
+		.slb_size = 32,
 	},
 };
 
@@ -39,7 +39,6 @@ static struct cpu_info cpu_power7_info = {
 
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.slb_size = 0,
 	.tb_freq = 33333333,
 	.d_bsize = 128,
 	.i_bsize = 128,
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 00b9436b..f61707a 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -19,7 +19,6 @@
 
 struct cpu_info {
 	const char	*name;
-	u32		slb_size;
 	u32		tb_freq; /* timebase frequency */
 	u32		d_bsize; /* d-cache block size */
 	u32		i_bsize; /* i-cache block size */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 8353355..83b8edd 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -393,8 +393,9 @@ static void setup_fdt(struct kvm *kvm)
 		/* Lies, but safeish lies! */
 		_FDT(fdt_property_cell(fdt, "clock-frequency", 0xddbab200));
 
-		if (cpu_info->slb_size)
-			_FDT(fdt_property_cell(fdt, "ibm,slb-size", cpu_info->slb_size));
+		if (cpu_info->mmu_info.slb_size)
+			_FDT(fdt_property_cell(fdt, "ibm,slb-size", cpu_info->mmu_info.slb_size));
+
 		/*
 		 * HPT size is hardwired; KVM currently fixes it at 16MB but the
 		 * moment that changes we'll need to read it out of the kernel.
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 10/10] kvm tools, powerpc: Use MMU info for ibm,slb-size
@ 2012-07-17  5:00   ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-17  5:00 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, matt, penberg, kvm-ppc, prerna, David Gibson

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 tools/kvm/powerpc/cpu_info.c |    3 +--
 tools/kvm/powerpc/cpu_info.h |    1 -
 tools/kvm/powerpc/kvm.c      |    5 +++--
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 82a9d4f..1f440a5 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -25,13 +25,13 @@
 
 static struct cpu_info cpu_power7_info = {
 	.name = "POWER7",
-	.slb_size = 32,
 	.tb_freq = 512000000,
 	.d_bsize = 128,
 	.i_bsize = 128,
 	.flags = CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX,
 	.mmu_info = {
 		.flags = KVM_PPC_PAGE_SIZES_REAL | KVM_PPC_1T_SEGMENTS,
+		.slb_size = 32,
 	},
 };
 
@@ -39,7 +39,6 @@ static struct cpu_info cpu_power7_info = {
 
 static struct cpu_info cpu_970_info = {
 	.name = "G5",
-	.slb_size = 0,
 	.tb_freq = 33333333,
 	.d_bsize = 128,
 	.i_bsize = 128,
diff --git a/tools/kvm/powerpc/cpu_info.h b/tools/kvm/powerpc/cpu_info.h
index 00b9436b..f61707a 100644
--- a/tools/kvm/powerpc/cpu_info.h
+++ b/tools/kvm/powerpc/cpu_info.h
@@ -19,7 +19,6 @@
 
 struct cpu_info {
 	const char	*name;
-	u32		slb_size;
 	u32		tb_freq; /* timebase frequency */
 	u32		d_bsize; /* d-cache block size */
 	u32		i_bsize; /* i-cache block size */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 8353355..83b8edd 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -393,8 +393,9 @@ static void setup_fdt(struct kvm *kvm)
 		/* Lies, but safeish lies! */
 		_FDT(fdt_property_cell(fdt, "clock-frequency", 0xddbab200));
 
-		if (cpu_info->slb_size)
-			_FDT(fdt_property_cell(fdt, "ibm,slb-size", cpu_info->slb_size));
+		if (cpu_info->mmu_info.slb_size)
+			_FDT(fdt_property_cell(fdt, "ibm,slb-size", cpu_info->mmu_info.slb_size));
+
 		/*
 		 * HPT size is hardwired; KVM currently fixes it at 16MB but the
 		 * moment that changes we'll need to read it out of the kernel.
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
  2012-07-17  5:00 ` Michael Ellerman
@ 2012-07-17  9:33   ` Matt Evans
  -1 siblings, 0 replies; 32+ messages in thread
From: Matt Evans @ 2012-07-17  9:33 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: kvm, linux-kernel, penberg, kvm-ppc, prerna, David Gibson

Hi Michael,

On 2012-07-17 06:00, Michael Ellerman wrote:

> This is a series for kvmtool that uses a newish kernel API to get
> MMU info, which is then fed to the guest.
>
> Currently we just make a good guess based on the PVR, but that is
> potentially flakey in a few ways. The most notable is that if you 
> don't
> specify hugepages we don't boot - because the guest is told we 
> support
> 16M pages, but we don't really (on HV).

Just had a look, all good.  Thanks for tidying some old FIXMEs, 
especially the page/segment DT props encoding grot -- and the designated 
inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
;-)


Acked-by: Matt Evans <matt@ozlabs.org>


Matt


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-17  9:33   ` Matt Evans
  0 siblings, 0 replies; 32+ messages in thread
From: Matt Evans @ 2012-07-17  9:33 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: kvm, linux-kernel, penberg, kvm-ppc, prerna, David Gibson

Hi Michael,

On 2012-07-17 06:00, Michael Ellerman wrote:

> This is a series for kvmtool that uses a newish kernel API to get
> MMU info, which is then fed to the guest.
>
> Currently we just make a good guess based on the PVR, but that is
> potentially flakey in a few ways. The most notable is that if you 
> don't
> specify hugepages we don't boot - because the guest is told we 
> support
> 16M pages, but we don't really (on HV).

Just had a look, all good.  Thanks for tidying some old FIXMEs, 
especially the page/segment DT props encoding grot -- and the designated 
inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
;-)


Acked-by: Matt Evans <matt@ozlabs.org>


Matt


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
  2012-07-17  9:33   ` Matt Evans
@ 2012-07-17 14:09     ` Pekka Enberg
  -1 siblings, 0 replies; 32+ messages in thread
From: Pekka Enberg @ 2012-07-17 14:09 UTC (permalink / raw)
  To: Matt Evans
  Cc: Michael Ellerman, kvm, linux-kernel, kvm-ppc, prerna,
	David Gibson, Sasha Levin, Asias He, Cyrill Gorcunov,
	Ingo Molnar

On Tue, Jul 17, 2012 at 12:33 PM, Matt Evans <matt@ozlabs.org> wrote:
> Just had a look, all good.  Thanks for tidying some old FIXMEs, especially
> the page/segment DT props encoding grot -- and the designated inits in the
> cpuinfo struct, whew, I heard the scream on IRC.  Sorry. ;-)
>
> Acked-by: Matt Evans <matt@ozlabs.org>

Applied, thanks guys!

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-17 14:09     ` Pekka Enberg
  0 siblings, 0 replies; 32+ messages in thread
From: Pekka Enberg @ 2012-07-17 14:09 UTC (permalink / raw)
  To: Matt Evans
  Cc: Michael Ellerman, kvm, linux-kernel, kvm-ppc, prerna,
	David Gibson, Sasha Levin, Asias He, Cyrill Gorcunov,
	Ingo Molnar

On Tue, Jul 17, 2012 at 12:33 PM, Matt Evans <matt@ozlabs.org> wrote:
> Just had a look, all good.  Thanks for tidying some old FIXMEs, especially
> the page/segment DT props encoding grot -- and the designated inits in the
> cpuinfo struct, whew, I heard the scream on IRC.  Sorry. ;-)
>
> Acked-by: Matt Evans <matt@ozlabs.org>

Applied, thanks guys!

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
  2012-07-17  9:33   ` Matt Evans
@ 2012-07-18  2:03     ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-18  2:03 UTC (permalink / raw)
  To: Matt Evans; +Cc: kvm, linux-kernel, penberg, kvm-ppc, prerna, David Gibson

On Tue, 2012-07-17 at 10:33 +0100, Matt Evans wrote:
> Hi Michael,
> 
> On 2012-07-17 06:00, Michael Ellerman wrote:
> 
> > This is a series for kvmtool that uses a newish kernel API to get
> > MMU info, which is then fed to the guest.
> >
> > Currently we just make a good guess based on the PVR, but that is
> > potentially flakey in a few ways. The most notable is that if you 
> > don't
> > specify hugepages we don't boot - because the guest is told we 
> > support
> > 16M pages, but we don't really (on HV).
> 
> Just had a look, all good.  Thanks for tidying some old FIXMEs, 
> especially the page/segment DT props encoding grot -- and the designated 
> inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
> ;-)

Thanks Matt, no worries about the grot, there was no better way when you
wrote the original code.

The lack of designated inits did bite me quite well, while bisecting I
accidentally dropped the hunk that updated the struct definition but
kept the hunk that changed the initialisation - leading to a VM with a
slb size of 512000000 (tb_freq) etc. :)

cheers


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-18  2:03     ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-18  2:03 UTC (permalink / raw)
  To: Matt Evans; +Cc: kvm, linux-kernel, penberg, kvm-ppc, prerna, David Gibson

On Tue, 2012-07-17 at 10:33 +0100, Matt Evans wrote:
> Hi Michael,
> 
> On 2012-07-17 06:00, Michael Ellerman wrote:
> 
> > This is a series for kvmtool that uses a newish kernel API to get
> > MMU info, which is then fed to the guest.
> >
> > Currently we just make a good guess based on the PVR, but that is
> > potentially flakey in a few ways. The most notable is that if you 
> > don't
> > specify hugepages we don't boot - because the guest is told we 
> > support
> > 16M pages, but we don't really (on HV).
> 
> Just had a look, all good.  Thanks for tidying some old FIXMEs, 
> especially the page/segment DT props encoding grot -- and the designated 
> inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
> ;-)

Thanks Matt, no worries about the grot, there was no better way when you
wrote the original code.

The lack of designated inits did bite me quite well, while bisecting I
accidentally dropped the hunk that updated the struct definition but
kept the hunk that changed the initialisation - leading to a VM with a
slb size of 512000000 (tb_freq) etc. :)

cheers


^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
  2012-07-17 14:09     ` Pekka Enberg
@ 2012-07-18  2:08       ` Michael Ellerman
  -1 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-18  2:08 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Matt Evans, kvm, linux-kernel, kvm-ppc, prerna, David Gibson,
	Sasha Levin, Asias He, Cyrill Gorcunov, Ingo Molnar

On Tue, 2012-07-17 at 17:09 +0300, Pekka Enberg wrote:
> On Tue, Jul 17, 2012 at 12:33 PM, Matt Evans <matt@ozlabs.org> wrote:
> > Just had a look, all good.  Thanks for tidying some old FIXMEs, especially
> > the page/segment DT props encoding grot -- and the designated inits in the
> > cpuinfo struct, whew, I heard the scream on IRC.  Sorry. ;-)
> >
> > Acked-by: Matt Evans <matt@ozlabs.org>
> 
> Applied, thanks guys!

Thanks Pekka.

It occurred to me overnight that I forgot to mention that in order to
build the new code you need the headers from a 3.5-rc1 era kernel (for
the ioctl & KVM_CAP definitions).

The easiest way to do that is to merge linus' tree into kvmtool.

Are you planning on doing that in the master kvmtool tree anytime soon?
It's still based on 3.4-rc1 it seems.

cheers



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-18  2:08       ` Michael Ellerman
  0 siblings, 0 replies; 32+ messages in thread
From: Michael Ellerman @ 2012-07-18  2:08 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Matt Evans, kvm, linux-kernel, kvm-ppc, prerna, David Gibson,
	Sasha Levin, Asias He, Cyrill Gorcunov, Ingo Molnar

On Tue, 2012-07-17 at 17:09 +0300, Pekka Enberg wrote:
> On Tue, Jul 17, 2012 at 12:33 PM, Matt Evans <matt@ozlabs.org> wrote:
> > Just had a look, all good.  Thanks for tidying some old FIXMEs, especially
> > the page/segment DT props encoding grot -- and the designated inits in the
> > cpuinfo struct, whew, I heard the scream on IRC.  Sorry. ;-)
> >
> > Acked-by: Matt Evans <matt@ozlabs.org>
> 
> Applied, thanks guys!

Thanks Pekka.

It occurred to me overnight that I forgot to mention that in order to
build the new code you need the headers from a 3.5-rc1 era kernel (for
the ioctl & KVM_CAP definitions).

The easiest way to do that is to merge linus' tree into kvmtool.

Are you planning on doing that in the master kvmtool tree anytime soon?
It's still based on 3.4-rc1 it seems.

cheers



^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
  2012-07-18  2:08       ` Michael Ellerman
@ 2012-07-31  6:22         ` Pekka Enberg
  -1 siblings, 0 replies; 32+ messages in thread
From: Pekka Enberg @ 2012-07-31  6:22 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Matt Evans, kvm, linux-kernel, kvm-ppc, prerna, David Gibson,
	Sasha Levin, Asias He, Cyrill Gorcunov, Ingo Molnar

On Wed, 18 Jul 2012, Michael Ellerman wrote:
> It occurred to me overnight that I forgot to mention that in order to
> build the new code you need the headers from a 3.5-rc1 era kernel (for
> the ioctl & KVM_CAP definitions).
> 
> The easiest way to do that is to merge linus' tree into kvmtool.
> 
> Are you planning on doing that in the master kvmtool tree anytime soon?
> It's still based on 3.4-rc1 it seems.

Done. Sorry for the delay!

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool
@ 2012-07-31  6:22         ` Pekka Enberg
  0 siblings, 0 replies; 32+ messages in thread
From: Pekka Enberg @ 2012-07-31  6:22 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: Matt Evans, kvm, linux-kernel, kvm-ppc, prerna, David Gibson,
	Sasha Levin, Asias He, Cyrill Gorcunov, Ingo Molnar

On Wed, 18 Jul 2012, Michael Ellerman wrote:
> It occurred to me overnight that I forgot to mention that in order to
> build the new code you need the headers from a 3.5-rc1 era kernel (for
> the ioctl & KVM_CAP definitions).
> 
> The easiest way to do that is to merge linus' tree into kvmtool.
> 
> Are you planning on doing that in the master kvmtool tree anytime soon?
> It's still based on 3.4-rc1 it seems.

Done. Sorry for the delay!

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2012-07-31  6:23 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17  5:00 [RFC/PATCH] Use kernel supplied MMU info for kvm tool Michael Ellerman
2012-07-17  5:00 ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 01/10] kvm tools: Move mmap_anon_or_hugetblfs() into util Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 02/10] kvm tools, powerpc: Use mmap_anon_or_hugetblfs() in kvm__arch_init() Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 03/10] kvm tools: Remember page size as kvm->ram_pagesize Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 04/10] kvm tools, powerpc: Use designated initializers for struct cpu_info Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 05/10] kvm tools, powerpc: Use ARRAY_SIZE() in find_cpu_info() Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 06/10] kvm tools, powerpc: Reformatting " Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 07/10] kvm tools, powerpc: Restructure find_cpu_info() Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 08/10] kvm tools, powerpc: Use MMU info from the kernel for ibm,segment-page-sizes Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 09/10] kvm tools, powerpc: Use MMU info for ibm,processor-segment-sizes Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  5:00 ` [PATCH 10/10] kvm tools, powerpc: Use MMU info for ibm,slb-size Michael Ellerman
2012-07-17  5:00   ` Michael Ellerman
2012-07-17  9:33 ` [RFC/PATCH] Use kernel supplied MMU info for kvm tool Matt Evans
2012-07-17  9:33   ` Matt Evans
2012-07-17 14:09   ` Pekka Enberg
2012-07-17 14:09     ` Pekka Enberg
2012-07-18  2:08     ` Michael Ellerman
2012-07-18  2:08       ` Michael Ellerman
2012-07-31  6:22       ` Pekka Enberg
2012-07-31  6:22         ` Pekka Enberg
2012-07-18  2:03   ` Michael Ellerman
2012-07-18  2:03     ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.