]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Remember page size as kvm->ram_pagesize
authorMichael Ellerman <michael@ellerman.id.au>
Tue, 17 Jul 2012 05:00:13 +0000 (15:00 +1000)
committerPekka Enberg <penberg@kernel.org>
Tue, 17 Jul 2012 14:07:21 +0000 (17:07 +0300)
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.

Acked-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/util.h
tools/kvm/powerpc/include/kvm/kvm-arch.h
tools/kvm/powerpc/kvm.c
tools/kvm/util/util.c
tools/kvm/x86/include/kvm/kvm-arch.h
tools/kvm/x86/kvm.c

index 3d1d9871244fee30df22902143fab15f9a20e899..0df9f0dfdb43e70dda0ef3a83bf56eed08f8c55d 100644 (file)
@@ -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 */
index 404e33eda07e25c45024f05cfe4908d32250e264..316fe79b5db634632a6bbca8978eb23009da0116 100644 (file)
@@ -54,6 +54,7 @@ struct kvm {
 
        u64                     ram_size;
        void                    *ram_start;
+       u64                     ram_pagesize;
 
        u64                     sdr1;
        u32                     pvr;
index 0d8a9da7283aea08823f8e4df87bc362a3a77564..e3a7e526997a71c93e3aacdd8c091f948d089d4e 100644 (file)
@@ -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",
index a80cf86a2b50e4c8c016f11c4c95066fea1ed5c8..c11a15a304a549b326171390513c2051fd0be276 100644 (file)
@@ -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);
+       }
 }
index 551c8b49cff5bbe3bb769d44e35295e1c4ae6f6c..dd385d4a7c0dadd0d98fe279b2cb2a27f101fcfc 100644 (file)
@@ -34,6 +34,7 @@ struct kvm {
 
        u64                     ram_size;
        void                    *ram_start;
+       u64                     ram_pagesize;
 
        bool                    nmi_disabled;
 
index 8931639aaccce367a5174c81c12ba6e5ae5d6b9e..0a40fd54bcaa163ab1b810ed1d096fa2423d9cc0 100644 (file)
@@ -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)
                        /*