]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
fix 338995 shmat with hugepages (SHM_HUGETLB) fails with EINVAL
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 1 Nov 2014 22:00:50 +0000 (22:00 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 1 Nov 2014 22:00:50 +0000 (22:00 +0000)
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

NEWS
coregrind/m_syswrap/syswrap-darwin.c
coregrind/m_syswrap/syswrap-linux.c
include/vki/vki-linux.h
none/tests/map_unmap.c

diff --git a/NEWS b/NEWS
index 418e9febb3e2c29fa746754ca721a6398ee97e9e..a9497b5432d49966d626a8523a2dea8c24e4edd4 100644 (file)
--- 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
index c8c33a439b5dc74a24d0d1354e5e9d9d02e74cfc..28c010dc403d468ae8d76c4e32192daa740151b5 100644 (file)
@@ -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)
index 99091a019920ad06087ca16f42455b5ecfd1d791..c33afb1ddd00e35a13bd9a514b6fdd467064dfb3 100644 (file)
@@ -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)
index 9dadf585ab21ca4723b86625aa090527ded32082..8137e0caa3133075078e4f4ec428428cd698c26e 100644 (file)
@@ -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
index e149c586c6f0d41bb636222e8015f9058f1d52ad..bfc2503dd98f5c82420610590c57f6c203e8cf87 100644 (file)
@@ -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)
    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 <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/stat.h>
+// 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 <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/stat.h>
 #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);