Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/mremap_test: avoid crash with static build

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>

authored by

Aneesh Kumar K.V and committed by
Linus Torvalds
a9cc9c34 f27a5c93

+3 -2
+3 -2
tools/testing/selftests/vm/mremap_test.c
··· 75 75 retry: 76 76 addr += c.src_alignment; 77 77 src_addr = mmap((void *) addr, c.region_size, PROT_READ | PROT_WRITE, 78 - MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, -1, 0); 78 + MAP_FIXED_NOREPLACE | MAP_ANONYMOUS | MAP_SHARED, 79 + -1, 0); 79 80 if (src_addr == MAP_FAILED) { 80 - if (errno == EPERM) 81 + if (errno == EPERM || errno == EEXIST) 81 82 goto retry; 82 83 goto error; 83 84 }