* [PATCH v3] selftests/mm: pass filename as input param to VM_PFNMAP tests
@ 2025-08-05 1:36 Sudarsan Mahendran
2025-08-05 8:47 ` David Hildenbrand
0 siblings, 1 reply; 3+ messages in thread
From: Sudarsan Mahendran @ 2025-08-05 1:36 UTC (permalink / raw)
To: linux-kselftest, David Hildenbrand
Cc: Shuah Khan, Axel Rasmussen, linux-mm, Andrew Morton, linux-kernel,
trivial, Sudarsan Mahendran
Enable these tests to be run on other pfnmap'ed memory like
NVIDIA's EGM.
Add '--' as a separator to pass in file path. This allows
passing of cmd line arguments to kselftest_harness.
Use '/dev/mem' as default filename.
Existing test passes:
pfnmap
TAP version 13
1..6
# Starting 6 tests from 1 test cases.
# PASSED: 6 / 6 tests passed.
# Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
Pass params to kselftest_harness:
pfnmap -r pfnmap:mremap_fixed
TAP version 13
1..1
# Starting 1 tests from 1 test cases.
# RUN pfnmap.mremap_fixed ...
# OK pfnmap.mremap_fixed
ok 1 pfnmap.mremap_fixed
# PASSED: 1 / 1 tests passed.
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Pass non-existent file name as input:
pfnmap -- /dev/blah
TAP version 13
1..6
# Starting 6 tests from 1 test cases.
# RUN pfnmap.madvise_disallowed ...
# SKIP Cannot open '/dev/blah'
Pass non pfnmap'ed file as input:
pfnmap -r pfnmap.madvise_disallowed -- randfile.txt
TAP version 13
1..1
# Starting 1 tests from 1 test cases.
# RUN pfnmap.madvise_disallowed ...
# SKIP Invalid file: 'randfile.txt'. Not pfnmap'ed
Signed-off-by: Sudarsan Mahendran <sudarsanm@google.com>
---
v2 -> v3:
* Add check_vmflag_pfnmap func
* Re-use existing check_vmflag_io func
* Verify pfnmap using mmap addr
* Rename phys_addr to offset
v1 -> v2:
* Add verify_pfnmap func to sanity check the input param
* mmap with zero offset if filename != '/dev/mem'
---
tools/testing/selftests/mm/pfnmap.c | 48 ++++++++++++++++++++--------
tools/testing/selftests/mm/vm_util.c | 14 ++++++--
tools/testing/selftests/mm/vm_util.h | 1 +
3 files changed, 47 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/mm/pfnmap.c b/tools/testing/selftests/mm/pfnmap.c
index 866ac023baf5..88659f0a90ea 100644
--- a/tools/testing/selftests/mm/pfnmap.c
+++ b/tools/testing/selftests/mm/pfnmap.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * Basic VM_PFNMAP tests relying on mmap() of '/dev/mem'
+ * Basic VM_PFNMAP tests relying on mmap() of input file provided.
+ * Use '/dev/mem' as default.
*
* Copyright 2025, Red Hat, Inc.
*
@@ -25,6 +26,7 @@
#include "vm_util.h"
static sigjmp_buf sigjmp_buf_env;
+static char *file = "/dev/mem";
static void signal_handler(int sig)
{
@@ -51,7 +53,7 @@ static int test_read_access(char *addr, size_t size, size_t pagesize)
return ret;
}
-static int find_ram_target(off_t *phys_addr,
+static int find_ram_target(off_t *offset,
unsigned long long pagesize)
{
unsigned long long start, end;
@@ -91,7 +93,7 @@ static int find_ram_target(off_t *phys_addr,
/* We need two pages. */
if (end > start + 2 * pagesize) {
fclose(file);
- *phys_addr = start;
+ *offset = start;
return 0;
}
}
@@ -100,7 +102,7 @@ static int find_ram_target(off_t *phys_addr,
FIXTURE(pfnmap)
{
- off_t phys_addr;
+ off_t offset;
size_t pagesize;
int dev_mem_fd;
char *addr1;
@@ -113,23 +115,31 @@ FIXTURE_SETUP(pfnmap)
{
self->pagesize = getpagesize();
- /* We'll require two physical pages throughout our tests ... */
- if (find_ram_target(&self->phys_addr, self->pagesize))
- SKIP(return, "Cannot find ram target in '/proc/iomem'\n");
+ if (strncmp(file, "/dev/mem", strlen("/dev/mem")) == 0) {
+ /* We'll require two physical pages throughout our tests ... */
+ if (find_ram_target(&self->offset, self->pagesize))
+ SKIP(return,
+ "Cannot find ram target in '/proc/iomem'\n");
+ } else {
+ self->offset = 0;
+ }
- self->dev_mem_fd = open("/dev/mem", O_RDONLY);
+ self->dev_mem_fd = open(file, O_RDONLY);
if (self->dev_mem_fd < 0)
- SKIP(return, "Cannot open '/dev/mem'\n");
+ SKIP(return, "Cannot open '%s'\n", file);
self->size1 = self->pagesize * 2;
self->addr1 = mmap(NULL, self->size1, PROT_READ, MAP_SHARED,
- self->dev_mem_fd, self->phys_addr);
+ self->dev_mem_fd, self->offset);
if (self->addr1 == MAP_FAILED)
- SKIP(return, "Cannot mmap '/dev/mem'\n");
+ SKIP(return, "Cannot mmap '%s'\n", file);
+
+ if (!check_vmflag_pfnmap(self->addr1))
+ SKIP(return, "Invalid file: '%s'. Not pfnmap'ed\n", file);
/* ... and want to be able to read from them. */
if (test_read_access(self->addr1, self->size1, self->pagesize))
- SKIP(return, "Cannot read-access mmap'ed '/dev/mem'\n");
+ SKIP(return, "Cannot read-access mmap'ed '%s'\n", file);
self->size2 = 0;
self->addr2 = MAP_FAILED;
@@ -182,7 +192,7 @@ TEST_F(pfnmap, munmap_split)
*/
self->size2 = self->pagesize;
self->addr2 = mmap(NULL, self->pagesize, PROT_READ, MAP_SHARED,
- self->dev_mem_fd, self->phys_addr);
+ self->dev_mem_fd, self->offset);
ASSERT_NE(self->addr2, MAP_FAILED);
}
@@ -246,4 +256,14 @@ TEST_F(pfnmap, fork)
ASSERT_EQ(ret, 0);
}
-TEST_HARNESS_MAIN
+int main(int argc, char **argv)
+{
+ for (int i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "--") == 0) {
+ if (i + 1 < argc && strlen(argv[i + 1]) > 0)
+ file = argv[i + 1];
+ return test_harness_run(i, argv);
+ }
+ }
+ return test_harness_run(argc, argv);
+}
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 5492e3f784df..2cebe4212db8 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -402,7 +402,7 @@ unsigned long get_free_hugepages(void)
return fhp;
}
-bool check_vmflag_io(void *addr)
+static bool check_vmflag(void *addr, const char *flag)
{
char buffer[MAX_LINE_LENGTH];
const char *flags;
@@ -419,13 +419,23 @@ bool check_vmflag_io(void *addr)
if (!flaglen)
return false;
- if (flaglen == strlen("io") && !memcmp(flags, "io", flaglen))
+ if (flaglen == strlen(flag) && !memcmp(flags, flag, flaglen))
return true;
flags += flaglen;
}
}
+bool check_vmflag_io(void *addr)
+{
+ return check_vmflag(addr, "io");
+}
+
+bool check_vmflag_pfnmap(void *addr)
+{
+ return check_vmflag(addr, "pf");
+}
+
/*
* Open an fd at /proc/$pid/maps and configure procmap_out ready for
* PROCMAP_QUERY query. Returns 0 on success, or an error code otherwise.
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index b8136d12a0f8..ec1f61f30fe7 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -84,6 +84,7 @@ int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
bool miss, bool wp, bool minor, uint64_t *ioctls);
unsigned long get_free_hugepages(void);
bool check_vmflag_io(void *addr);
+bool check_vmflag_pfnmap(void *addr);
int open_procmap(pid_t pid, struct procmap_fd *procmap_out);
int query_procmap(struct procmap_fd *procmap);
bool find_vma_procmap(struct procmap_fd *procmap, void *address);
--
2.50.1.565.gc32cd1483b-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] selftests/mm: pass filename as input param to VM_PFNMAP tests
2025-08-05 1:36 [PATCH v3] selftests/mm: pass filename as input param to VM_PFNMAP tests Sudarsan Mahendran
@ 2025-08-05 8:47 ` David Hildenbrand
2025-08-05 16:51 ` Sudarsan Mahendran
0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2025-08-05 8:47 UTC (permalink / raw)
To: Sudarsan Mahendran, linux-kselftest
Cc: Shuah Khan, Axel Rasmussen, linux-mm, Andrew Morton, linux-kernel,
trivial
On 05.08.25 03:36, Sudarsan Mahendran wrote:
> Enable these tests to be run on other pfnmap'ed memory like
> NVIDIA's EGM.
>
> Add '--' as a separator to pass in file path. This allows
> passing of cmd line arguments to kselftest_harness.
> Use '/dev/mem' as default filename.
>
> Existing test passes:
> pfnmap
> TAP version 13
> 1..6
> # Starting 6 tests from 1 test cases.
> # PASSED: 6 / 6 tests passed.
> # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> Pass params to kselftest_harness:
> pfnmap -r pfnmap:mremap_fixed
> TAP version 13
> 1..1
> # Starting 1 tests from 1 test cases.
> # RUN pfnmap.mremap_fixed ...
> # OK pfnmap.mremap_fixed
> ok 1 pfnmap.mremap_fixed
> # PASSED: 1 / 1 tests passed.
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> Pass non-existent file name as input:
> pfnmap -- /dev/blah
> TAP version 13
> 1..6
> # Starting 6 tests from 1 test cases.
> # RUN pfnmap.madvise_disallowed ...
> # SKIP Cannot open '/dev/blah'
>
> Pass non pfnmap'ed file as input:
> pfnmap -r pfnmap.madvise_disallowed -- randfile.txt
> TAP version 13
> 1..1
> # Starting 1 tests from 1 test cases.
> # RUN pfnmap.madvise_disallowed ...
> # SKIP Invalid file: 'randfile.txt'. Not pfnmap'ed
>
> Signed-off-by: Sudarsan Mahendran <sudarsanm@google.com>
> ---
Thanks!
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] selftests/mm: pass filename as input param to VM_PFNMAP tests
2025-08-05 8:47 ` David Hildenbrand
@ 2025-08-05 16:51 ` Sudarsan Mahendran
0 siblings, 0 replies; 3+ messages in thread
From: Sudarsan Mahendran @ 2025-08-05 16:51 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kselftest, Shuah Khan, Axel Rasmussen, linux-mm,
Andrew Morton, linux-kernel, trivial
Thanks David for your insightful review comments.
On Tue, Aug 5, 2025 at 1:47 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 05.08.25 03:36, Sudarsan Mahendran wrote:
> > Enable these tests to be run on other pfnmap'ed memory like
> > NVIDIA's EGM.
> >
> > Add '--' as a separator to pass in file path. This allows
> > passing of cmd line arguments to kselftest_harness.
> > Use '/dev/mem' as default filename.
> >
> > Existing test passes:
> > pfnmap
> > TAP version 13
> > 1..6
> > # Starting 6 tests from 1 test cases.
> > # PASSED: 6 / 6 tests passed.
> > # Totals: pass:6 fail:0 xfail:0 xpass:0 skip:0 error:0
> >
> > Pass params to kselftest_harness:
> > pfnmap -r pfnmap:mremap_fixed
> > TAP version 13
> > 1..1
> > # Starting 1 tests from 1 test cases.
> > # RUN pfnmap.mremap_fixed ...
> > # OK pfnmap.mremap_fixed
> > ok 1 pfnmap.mremap_fixed
> > # PASSED: 1 / 1 tests passed.
> > # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> >
> > Pass non-existent file name as input:
> > pfnmap -- /dev/blah
> > TAP version 13
> > 1..6
> > # Starting 6 tests from 1 test cases.
> > # RUN pfnmap.madvise_disallowed ...
> > # SKIP Cannot open '/dev/blah'
> >
> > Pass non pfnmap'ed file as input:
> > pfnmap -r pfnmap.madvise_disallowed -- randfile.txt
> > TAP version 13
> > 1..1
> > # Starting 1 tests from 1 test cases.
> > # RUN pfnmap.madvise_disallowed ...
> > # SKIP Invalid file: 'randfile.txt'. Not pfnmap'ed
> >
> > Signed-off-by: Sudarsan Mahendran <sudarsanm@google.com>
> > ---
>
> Thanks!
>
> Acked-by: David Hildenbrand <david@redhat.com>
>
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-05 16:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-05 1:36 [PATCH v3] selftests/mm: pass filename as input param to VM_PFNMAP tests Sudarsan Mahendran
2025-08-05 8:47 ` David Hildenbrand
2025-08-05 16:51 ` Sudarsan Mahendran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).