]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftest/mremap_test: avoid crash with static build
authorAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Thu, 8 Jul 2021 01:10:03 +0000 (18:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 8 Jul 2021 18:48:22 +0000 (11:48 -0700)
With a large mmap map size, we can overlap with the text area and using
MAP_FIXED results in unmapping that area.  Switch to MAP_FIXED_NOREPLACE
and handle the EEXIST error.

Link: https://lkml.kernel.org/r/20210616045239.370802-3-aneesh.kumar@linux.ibm.com
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Reviewed-by: Kalesh Singh <kaleshsingh@google.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Hugh Dickins <hughd@google.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
tools/testing/selftests/vm/mremap_test.c

index c9a5461eb78686becd33541c199a0ddd8a12606e..0624d1bd71b5352a2584c8f4f1a4860cdd498e52 100644 (file)
@@ -75,9 +75,10 @@ static void *get_source_mapping(struct config c)
 retry:
        addr += c.src_alignment;
        src_addr = mmap((void *) addr, c.region_size, PROT_READ | PROT_WRITE,
-                       MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+                       MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED,
+                       -1, 0);
        if (src_addr == MAP_FAILED) {
-               if (errno == EPERM)
+               if (errno == EPERM || errno == EEXIST)
                        goto retry;
                goto error;
        }