From: Cyril Hrubis <chrubis@suse.cz>
To: Pavithra <pavrampu@linux.ibm.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] hugemmap/hugemmap37: migrated task-size-overrun.c from libhugetlbfs
Date: Tue, 4 Aug 2026 18:14:49 +0200 [thread overview]
Message-ID: <anIP-a1bkmht2jKm@yuki.lan> (raw)
In-Reply-To: <20260717112629.1077734-1-pavrampu@linux.ibm.com>
Hi!
Pushed with following diff, thanks.
Changes:
- use TDEBUG for the verbose messages
- use TST_EXP_* macros, on Linux mmap() without MAP_FIXED ignores the
address hint and always succeeds
- moved the code that locates task_size into the test setup() so that
it's called exactly once on test with -i 10
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
index c15b4ad33..addd717e3 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap37.c
@@ -34,6 +34,7 @@
#define MNTPOINT "hugetlbfs/"
static long hpage_size;
+static unsigned long task_size;
static int fd = -1;
static unsigned long find_last_mapped(void)
@@ -100,10 +101,10 @@ static unsigned long find_task_size(void)
p = mmap((void *)addr, page_size, PROT_READ,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
if (p == MAP_FAILED) {
- tst_res(TINFO | TERRNO, "Map failed at 0x%lx", addr);
+ tst_res(TDEBUG | TERRNO, "Map failed at 0x%lx", addr);
high = pfn;
} else {
- tst_res(TINFO, "Map succeeded at 0x%lx", addr);
+ tst_res(TDEBUG, "Map succeeded at 0x%lx", addr);
SAFE_MUNMAP(p, page_size);
low = pfn;
}
@@ -114,45 +115,35 @@ static unsigned long find_task_size(void)
static void run_test(void)
{
- void *p;
- unsigned long task_size;
unsigned long straddle_addr;
- task_size = find_task_size();
- tst_res(TINFO, "TASK_SIZE = 0x%lx", task_size);
-
straddle_addr = task_size - hpage_size;
straddle_addr = LTP_ALIGN(straddle_addr, hpage_size);
tst_res(TINFO, "Mapping without MAP_FIXED at %lx...", straddle_addr);
- errno = 0;
- p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, 0);
- if (p == (void *)straddle_addr) {
- tst_res(TFAIL, "Apparently succeeded in mapping across TASK_SIZE boundary");
- SAFE_MUNMAP(p, 2*hpage_size);
- } else if (p != MAP_FAILED) {
- tst_res(TPASS, "mmap without MAP_FIXED correctly avoided TASK_SIZE boundary");
- SAFE_MUNMAP(p, 2*hpage_size);
- } else {
- tst_res(TPASS, "mmap without MAP_FIXED correctly failed");
- }
+
+ TST_EXP_PASS_PTR_VOID(mmap((void *)straddle_addr, 2*hpage_size,
+ PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0));
+
+ if (TST_RET_PTR != MAP_FAILED)
+ SAFE_MUNMAP(TST_RET_PTR, 2*hpage_size);
tst_res(TINFO, "Mapping with MAP_FIXED at %lx...", straddle_addr);
- errno = 0;
- p = mmap((void *)straddle_addr, 2*hpage_size, PROT_READ|PROT_WRITE,
- MAP_SHARED|MAP_FIXED, fd, 0);
- if (p != MAP_FAILED) {
- tst_res(TFAIL, "Apparently succeeded in mapping across TASK_SIZE boundary");
- SAFE_MUNMAP(p, 2*hpage_size);
- } else {
- tst_res(TPASS, "mmap with MAP_FIXED correctly failed");
- }
+
+ TST_EXP_FAIL_PTR_VOID(mmap((void *)straddle_addr, 2*hpage_size,
+ PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 0), ENOMEM);
+
+ if (TST_RET_PTR != MAP_FAILED)
+ SAFE_MUNMAP(TST_RET_PTR, 2*hpage_size);
}
static void setup(void)
{
hpage_size = tst_get_hugepage_size();
+
+ task_size = find_task_size();
+ tst_res(TINFO, "TASK_SIZE = 0x%lx", task_size);
+
fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
}
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-08-04 16:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 11:26 [LTP] [PATCH] hugemmap/hugemmap37: migrated task-size-overrun.c from libhugetlbfs Pavithra
2026-08-04 16:14 ` Cyril Hrubis [this message]
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=anIP-a1bkmht2jKm@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pavrampu@linux.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox