From: Philippe Waroquiers Date: Sat, 1 Nov 2014 22:00:50 +0000 (+0000) Subject: fix 338995 shmat with hugepages (SHM_HUGETLB) fails with EINVAL X-Git-Tag: svn/VALGRIND_3_11_0~865 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80ae5a239562e237437ef7011440156765383dbd;p=thirdparty%2Fvalgrind.git fix 338995 shmat with hugepages (SHM_HUGETLB) fails with EINVAL Bug is not really fixed, instead the SHM_HUGETLB flag is ignored. Note that it is not straightforward to properly fix this, as this implies either to learn aspacemgr what huge pages are. Also, the trick used in the fix for 333051 cannot be used easily, because the SHM_HUGETLB flag is given in shmget, while the mmap is done in shmat. So, the easiest is to just ignore the SHM_HUGETLB flag. SHM_HUGETLB is supposed to only give a performance impact. Ignoring it should be benign. Theoretically, the caller might expect a sucessful shmget(SHM_HUGETLB)+shmat to give pages aligned on e.g. 1MB. In this case, bad luck, the program will misbehave under valgrind. To warn of this, a warning is given (once) when SHM_HUGETLB is seen. The map_unmap.c test has been restructured somewaht to allow TEST_SHM_HUGETLB to be tested independently (or not) of the TEST_MAP_HUGETLB. Note also that by default, testing MAP_HUGETLB and SHM_HUGETLB is disabled as usually, huge pages are not enabled. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14683 --- diff --git a/NEWS b/NEWS index 418e9febb3..a9497b5432 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ where XXXXXX is the bug number as listed below. 335440 arm64: ld1 (single structure) is not implemented 335713 arm64: unhanded instruction: prfm (immediate) 338731 ppc: Fix testuite build for toolchains not supporting -maltivec +338995 shmat with hugepages (SHM_HUGETLB) fails with EINVAL 339020 ppc64: memcheck/tests/ppc64/power_ISA2_05 failing in nightly build 339156 gdbsrv not called for fatal signal 339442 Fix testsuite build failure on OS X 10.9 diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c index c8c33a439b..28c010dc40 100644 --- a/coregrind/m_syswrap/syswrap-darwin.c +++ b/coregrind/m_syswrap/syswrap-darwin.c @@ -2310,6 +2310,15 @@ PRE(shmget) { PRINT("shmget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg); + if (ARG3 & VKI_SHM_HUGETLB) { + static Bool warning_given = False; + ARG3 &= ~VKI_SHM_HUGETLB; + if (!warning_given) { + warning_given = True; + VG_(umsg)( + "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n"); + } + } } PRE(shm_open) diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 99091a0199..c33afb1ddd 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -3593,6 +3593,15 @@ PRE(sys_ipc) case VKI_SHMGET: PRE_REG_READ4(int, "ipc", vki_uint, call, int, first, int, second, int, third); + if (ARG4 & VKI_SHM_HUGETLB) { + static Bool warning_given = False; + ARG4 &= ~VKI_SHM_HUGETLB; + if (!warning_given) { + warning_given = True; + VG_(umsg)( + "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n"); + } + } break; case VKI_SHMCTL: /* IPCOP_shmctl */ PRE_REG_READ5(int, "ipc", @@ -3795,6 +3804,15 @@ PRE(sys_shmget) { PRINT("sys_shmget ( %ld, %ld, %ld )",ARG1,ARG2,ARG3); PRE_REG_READ3(long, "shmget", vki_key_t, key, vki_size_t, size, int, shmflg); + if (ARG3 & VKI_SHM_HUGETLB) { + static Bool warning_given = False; + ARG3 &= ~VKI_SHM_HUGETLB; + if (!warning_given) { + warning_given = True; + VG_(umsg)( + "WARNING: valgrind ignores shmget(shmflg) SHM_HUGETLB\n"); + } + } } PRE(wrap_sys_shmat) diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index 9dadf585ab..8137e0caa3 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -1160,6 +1160,9 @@ struct vki_ipc_perm #define VKI_IPC_64 0x0100 /* New version (support 32-bit UIDs, bigger message sizes, etc. */ +// From /usr/include/bits/shm.h +# define VKI_SHM_HUGETLB 04000 + //---------------------------------------------------------------------- // From linux-2.6.8.1/include/linux/sem.h diff --git a/none/tests/map_unmap.c b/none/tests/map_unmap.c index e149c586c6..bfc2503dd9 100644 --- a/none/tests/map_unmap.c +++ b/none/tests/map_unmap.c @@ -10,7 +10,7 @@ echo 20 > /proc/sys/vm/nr_hugepages Once this is done, uncomment the below, and recompile. */ -// #define TEST_MAP_HUGETLB 1 +//#define TEST_MAP_HUGETLB 1 /* Similarly, testing SHM_HUGETLB huge pages is disabled by default. To have shmget/shmat big pages working, do (as root) @@ -18,13 +18,12 @@ where 500 is the groupid of the user that runs this test Once this is done, uncomment the below, and recompile. */ -// #define TEST_SHM_HUGETLB 1 +//#define TEST_SHM_HUGETLB 1 -#ifdef TEST_MAP_HUGETLB -#include -#include -#include +// Size to use for huge pages +#define HUGESZ (4 * 1024 * 1024) +#ifdef TEST_MAP_HUGETLB /* Ensure this compiles on pre 2.6 systems, or on glibc missing MAP_HUGETLB */ #ifndef MAP_HUGETLB /* The below works for me on an f12/x86 linux */ @@ -34,6 +33,9 @@ #endif /* TEST_MAP_HUGETLB */ #ifdef TEST_SHM_HUGETLB +#include +#include +#include #ifndef SHM_HUGETLB #define SHM_HUGETLB 04000 #endif @@ -114,7 +116,6 @@ int main() } #ifdef TEST_MAP_HUGETLB -#define HUGESZ (4 * 1024 * 1024) { void *expect3; expect3 = domap(HUGESZ, MAP_HUGETLB);