diff mbox series

[v3,2/9] selftest/mremap_test: Avoid crash with static build

Message ID 20210330060752.592769-3-aneesh.kumar@linux.ibm.com (mailing list archive)
State Not Applicable
Headers show
Series Speedup mremap on ppc64 | expand
Related show

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (87d76f542a24ecfa797e9bd3bb56c0f19aabff57)
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
snowpatch_ozlabs/needsstable success Patch has no Fixes tags

Commit Message

Aneesh Kumar K V March 30, 2021, 6:07 a.m. UTC
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.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 tools/testing/selftests/vm/mremap_test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Kalesh Singh April 12, 2021, 6:38 p.m. UTC | #1
On Mon, Mar 29, 2021 at 11:08 PM Aneesh Kumar K.V
<aneesh.kumar@linux.ibm.com> wrote:
>
> 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.
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>

Reviewed-by: Kalesh Singh <kaleshsingh@google.com>

> ---
>  tools/testing/selftests/vm/mremap_test.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/vm/mremap_test.c b/tools/testing/selftests/vm/mremap_test.c
> index c9a5461eb786..0624d1bd71b5 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;
>         }
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/vm/mremap_test.c b/tools/testing/selftests/vm/mremap_test.c
index c9a5461eb786..0624d1bd71b5 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;
 	}