mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Ellerman <michael@ellerman.id.au>
To: <kvm@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <matt@ozlabs.org>,
	<penberg@kernel.org>, <kvm-ppc@vger.kernel.org>,
	<prerna@linux.vnet.ibm.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 03/10] kvm tools: Remember page size as kvm->ram_pagesize
Date: Tue, 17 Jul 2012 15:00:13 +1000	[thread overview]
Message-ID: <1342501220-10209-4-git-send-email-michael@ellerman.id.au> (raw)
In-Reply-To: <1342501220-10209-1-git-send-email-michael@ellerman.id.au>

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


  parent reply	other threads:[~2012-07-17  5:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-17  5:00 [RFC/PATCH] Use kernel supplied MMU info for kvm tool 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 ` [PATCH 02/10] kvm tools, powerpc: Use mmap_anon_or_hugetblfs() in kvm__arch_init() Michael Ellerman
2012-07-17  5:00 ` Michael Ellerman [this message]
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 ` [PATCH 05/10] kvm tools, powerpc: Use ARRAY_SIZE() in find_cpu_info() Michael Ellerman
2012-07-17  5:00 ` [PATCH 06/10] kvm tools, powerpc: Reformatting " Michael Ellerman
2012-07-17  5:00 ` [PATCH 07/10] kvm tools, powerpc: Restructure find_cpu_info() 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 ` [PATCH 09/10] kvm tools, powerpc: Use MMU info for ibm,processor-segment-sizes 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  9:33 ` [RFC/PATCH] Use kernel supplied MMU info for kvm tool Matt Evans
2012-07-17 14:09   ` Pekka Enberg
2012-07-18  2:08     ` Michael Ellerman
2012-07-31  6:22       ` Pekka Enberg
2012-07-18  2:03   ` Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1342501220-10209-4-git-send-email-michael@ellerman.id.au \
    --to=michael@ellerman.id.au \
    --cc=david@gibson.dropbear.id.au \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@ozlabs.org \
    --cc=penberg@kernel.org \
    --cc=prerna@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®