* [Qemu-devel] [PATCH] sparc: Make sure we mmap at SHMLBA alignment
@ 2017-12-08 16:57 Peter Maydell
2017-12-12 5:53 ` Richard Henderson
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2017-12-08 16:57 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, John Paul Adrian Glaubitz
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>
---
include/qemu/osdep.h | 3 +++
util/mmap-alloc.c | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index e8568a0..adb3758 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 3ec029a..2fd8cbc 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();
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] sparc: Make sure we mmap at SHMLBA alignment
2017-12-08 16:57 [Qemu-devel] [PATCH] sparc: Make sure we mmap at SHMLBA alignment Peter Maydell
@ 2017-12-12 5:53 ` Richard Henderson
2017-12-15 16:44 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2017-12-12 5:53 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: John Paul Adrian Glaubitz, patches
On 12/08/2017 08:57 AM, Peter Maydell wrote:
> 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>
r~
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] sparc: Make sure we mmap at SHMLBA alignment
2017-12-12 5:53 ` Richard Henderson
@ 2017-12-15 16:44 ` Peter Maydell
0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2017-12-15 16:44 UTC (permalink / raw)
To: Richard Henderson
Cc: QEMU Developers, John Paul Adrian Glaubitz, patches@linaro.org
On 12 December 2017 at 05:53, Richard Henderson
<richard.henderson@linaro.org> wrote:
> On 12/08/2017 08:57 AM, Peter Maydell wrote:
>> 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>
Thanks; I have applied this to master and added a sparc64
host to my set of build systems. (Thanks to John for providing
access to that host.)
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-15 16:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-08 16:57 [Qemu-devel] [PATCH] sparc: Make sure we mmap at SHMLBA alignment Peter Maydell
2017-12-12 5:53 ` Richard Henderson
2017-12-15 16:44 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).