aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-12-08 16:33:04 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-12-08 16:33:04 +0000
commitf632a3ff491adaefeff0a86637fd0323bd08cdb5 (patch)
tree21fbd7728bd3db0710e1f1bb685a61eaccde2f62
parent2babfe0c9241c239272a03fec785165a50e8288c (diff)
downloadqemu-arm-sparc-pagealign.tar.gz
sparc: Make sure we mmap at SHMLBA alignmentsparc-pagealign
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. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--include/qemu/osdep.h3
-rw-r--r--util/mmap-alloc.c8
2 files changed, 11 insertions, 0 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index e8568a0a54..adb3758275 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -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
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 3ec029a9ea..2fd8cbcc6f 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -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();