]> git.proxmox.com Git - mirror_qemu.git/commitdiff
sparc: Make sure we mmap at SHMLBA alignment
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 8 Dec 2017 16:57:28 +0000 (16:57 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Fri, 15 Dec 2017 15:26:24 +0000 (15:26 +0000)
SPARC Linux has an oddity that it insists that mmap()
of MAP_FIXED memory must be at an alignment defined by
SHMLBA, which is more aligned than the page size
(typically, SHMLBA alignment is to 16K, and pages are 8K).
This is a relic of ancient hardware that had cache
aliasing constraints, but even on modern hardware the
kernel still insists on the alignment.

To ensure that we get mmap() alignment sufficient to
make the kernel happy, change QEMU_VMALLOC_ALIGN,
qemu_fd_getpagesize() and qemu_mempath_getpagesize()
to use the maximum of getpagesize() and SHMLBA.

In particular, this allows 'make check' to pass on Sparc:
we were previously failing the ivshmem tests.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 1512752248-17857-1-git-send-email-peter.maydell@linaro.org

include/qemu/osdep.h
util/mmap-alloc.c

index e8568a0a54715ecd06dbc4bc9b2015b9c4ea866e..adb3758275cdb127ba8355587fc0d3afefdb43c8 100644 (file)
@@ -365,6 +365,9 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 #elif defined(__linux__) && defined(__s390x__)
    /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
 #  define QEMU_VMALLOC_ALIGN (256 * 4096)
+#elif defined(__linux__) && defined(__sparc__)
+#include <sys/shm.h>
+#  define QEMU_VMALLOC_ALIGN MAX(getpagesize(), SHMLBA)
 #else
 #  define QEMU_VMALLOC_ALIGN getpagesize()
 #endif
index 3ec029a9eaebccf70da0047693a179e6f9be905d..2fd8cbcc6f6e7a881686ccf0ffc8d4d73b303e37 100644 (file)
@@ -35,6 +35,10 @@ size_t qemu_fd_getpagesize(int fd)
             return fs.f_bsize;
         }
     }
+#ifdef __sparc__
+    /* SPARC Linux needs greater alignment than the pagesize */
+    return QEMU_VMALLOC_ALIGN;
+#endif
 #endif
 
     return getpagesize();
@@ -60,6 +64,10 @@ size_t qemu_mempath_getpagesize(const char *mem_path)
         /* It's hugepage, return the huge page size */
         return fs.f_bsize;
     }
+#ifdef __sparc__
+    /* SPARC Linux needs greater alignment than the pagesize */
+    return QEMU_VMALLOC_ALIGN;
+#endif
 #endif
 
     return getpagesize();