All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH 3/3] mmap24: add test for MAP_32BIT address limit
Date: Fri, 11 Sep 2026 15:59:07 +0200	[thread overview]
Message-ID: <20260911135907.GC1488703@pevik> (raw)
In-Reply-To: <20260828-mmap_32bit_coverage-v1-3-7f0b8b589773@suse.com>

Hi Andrea,

> Add a test verifying that mmap() with the MAP_32BIT flag restricts
> mappings to the first 2GB of address space and fails with ENOMEM
> when the 32-bit address space is exhausted without falling back to
> higher addresses.

Thanks!

...
> +++ b/testcases/kernel/syscalls/mmap/mmap24.c
...
> +
> +		if ((unsigned long)addr + CHUNK_SZ > ADDR_LIMIT) {
> +			tst_res(TFAIL, "mapping at %p + %zu exceeds 2GB limit",
%zu is wrong on 32 bit.

../../../../include/tst_test.h:75:55: warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 6 has type ‘long unsigned int’ [-Wformat=]
   75 |                 tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
      |                                                       ^~~~~~~~~
mmap24.c:63:25: note: in expansion of macro ‘tst_res’
   63 |                         tst_res(TFAIL, "mapping at %p + %zu exceeds 2GB limit",
      |                         ^~~~~~~

> +				addr, CHUNK_SZ);
> +			addrs[num_chunks++] = addr;
> +			cleanup();
> +			return;
> +		}
> +
> +		((char *)addr)[0] = 'a';
> +		((char *)addr)[CHUNK_SZ - 1] = 'z';
> +
> +		addrs[num_chunks++] = addr;
> +	}
> +
> +	if (!failed_with_enomem) {
> +		tst_res(TFAIL, "32-bit address space was not exhausted");
> +	} else if (!num_chunks) {
> +		tst_res(TFAIL, "failed to map any chunk with MAP_32BIT");
> +	} else {
> +		tst_res(TPASS,
> +			"Mapped %zu MB across %zu chunks within 2GB before ENOMEM",
And here as well.
> +			(num_chunks * CHUNK_SZ) / TST_MB, num_chunks);
> +	}
> +
> +	cleanup();
> +}
> +
> +static struct tst_test test = {
> +	.cleanup = cleanup,
> +	.test_all = run,
> +	.supported_archs = (const char *const []){
> +		"x86_64",
> +		NULL
> +	},
> +};


BTW I was wondering if I can get this failing when running on VM with really
small RAM, but even with 249 MB I get get mapped 928 MB (or 960 MB when I run
with -i):

mmap24.c:81: TPASS: Mapped 928 MB across 29 chunks within 2GB before ENOMEM

What am I missing?

Anyway, LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

Before merge please:

diff --git testcases/kernel/syscalls/mmap/mmap24.c testcases/kernel/syscalls/mmap/mmap24.c
index 50de620f42..94d092b809 100644
--- testcases/kernel/syscalls/mmap/mmap24.c
+++ testcases/kernel/syscalls/mmap/mmap24.c
@@ -60,7 +60,7 @@ static void run(void)
 		}
 
 		if ((unsigned long)addr + CHUNK_SZ > ADDR_LIMIT) {
-			tst_res(TFAIL, "mapping at %p + %zu exceeds 2GB limit",
+			tst_res(TFAIL, "mapping at %p + %lu exceeds 2GB limit",
 				addr, CHUNK_SZ);
 			addrs[num_chunks++] = addr;
 			cleanup();
@@ -79,7 +79,7 @@ static void run(void)
 		tst_res(TFAIL, "failed to map any chunk with MAP_32BIT");
 	} else {
 		tst_res(TPASS,
-			"Mapped %zu MB across %zu chunks within 2GB before ENOMEM",
+			"Mapped %lu MB across %zu chunks within 2GB before ENOMEM",
 			(num_chunks * CHUNK_SZ) / TST_MB, num_chunks);
 	}
 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-09-11 13:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 15:36 [LTP] [PATCH 0/3] mmap testing suite to cover MAP_32BIT Andrea Cervesato
2026-08-28 15:36 ` [LTP] [PATCH 1/3] lapi/mmap: add MAP_32BIT fallback Andrea Cervesato
2026-08-28 21:10   ` [LTP] " linuxtestproject.agent
2026-08-31  8:02     ` Andrea Cervesato via ltp
2026-09-11 13:20   ` [LTP] [PATCH 1/3] " Petr Vorel
2026-09-11 13:26     ` Petr Vorel
2026-08-28 15:36 ` [LTP] [PATCH 2/3] mmap23: add test for MAP_32BIT oversized mapping Andrea Cervesato
2026-09-11 14:08   ` Petr Vorel
2026-08-28 15:36 ` [LTP] [PATCH 3/3] mmap24: add test for MAP_32BIT address limit Andrea Cervesato
2026-09-10 14:38   ` Cyril Hrubis
2026-09-11 13:59   ` Petr Vorel [this message]
2026-09-11 15:16     ` Andrea Cervesato via ltp
2026-09-11 16:03       ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260911135907.GC1488703@pevik \
    --to=pvorel@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.