From: Aneesh Kumar K.V Date: Wed, 2 Jun 2021 03:52:29 +0000 (+1000) Subject: selftest/mremap_test: avoid crash with static build X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fbfdf8035e09d22df51db4855db4e0b816a44ee8;p=users%2Fjedix%2Flinux-maple.git 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/20210422054323.150993-3-aneesh.kumar@linux.ibm.com Signed-off-by: Aneesh Kumar K.V Reviewed-by: Kalesh Singh Cc: Christophe Leroy Cc: Joel Fernandes Cc: Michael Ellerman Cc: Nicholas Piggin Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- diff --git a/tools/testing/selftests/vm/mremap_test.c b/tools/testing/selftests/vm/mremap_test.c index c9a5461eb7868..0624d1bd71b53 100644 --- a/tools/testing/selftests/vm/mremap_test.c +++ b/tools/testing/selftests/vm/mremap_test.c @@ -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; }