Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount
@ 2026-05-18 18:17 Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 1/5] mm: selftests: Inline check_bytes() function into caller Ackerley Tng via B4 Relay
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

Hi,

I'm thinking of consolidating the tests for libhugetlbfs as kernel
selftests, and to start that off, I picked the simplest test:
tests/readback.c

I refactored hugepage-mmap.c to use the kselftest harness, and then used
FIXTURE_VARIANT from the harness to port in testing readback from an fd on
a hugetlbfs mount.

This output shows that the original test behavior was retained for the
memfd part:

  # ./hugepage-mmap
  TAP version 13
  1..1
  # Returned address is 0x7f312f200000
  # First hex is 0
  # First hex is 3020100
  ok 1 Read same data
  # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

  # ./hugepage-mmap
  TAP version 13
  1..1
  # Starting 1 tests from 1 test cases.
  #  RUN           hugepage_mmap.read_write ...
  # hugepage-mmap.c:41:read_write:Returned address is 0x7f19f3a00000
  # hugepage-mmap.c:54:read_write:First hex is 0
  # hugepage-mmap.c:59:read_write:First hex is 3020100
  #            OK  hugepage_mmap.read_write
  ok 1 hugepage_mmap.read_write
  # PASSED: 1 / 1 tests passed.
  # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

Let me know what you think before I genericize the 2M hugepage size to
other sizes!

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
Ackerley Tng (5):
      mm: selftests: Inline check_bytes() function into caller
      mm: selftests: Inline {read,write}_bytes functions
      mm: selftests: Refactor hugepage-mmap to use kselftest harness
      mm: selftests: Update hugepage-mmap to support hugetlbfs mount
      mm: selftests: Port readback test logic from libhugetlbfs

 tools/testing/selftests/mm/hugepage-mmap.c | 143 +++++++++++++++++++++--------
 1 file changed, 105 insertions(+), 38 deletions(-)
---
base-commit: 66edb901bf874d9e0787326ba12d3548b2da8700
change-id: 20260503-port-hugetlb-selftests-9bc63bde5116

Best regards,
--
Ackerley Tng <ackerleytng@google.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH RFC 1/5] mm: selftests: Inline check_bytes() function into caller
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
@ 2026-05-18 18:17 ` Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 2/5] mm: selftests: Inline {read,write}_bytes functions Ackerley Tng via B4 Relay
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

From: Ackerley Tng <ackerleytng@google.com>

Inline the check_bytes() function to prepare for using the kselftest
harness, where TH_LOG() relies on the variable _metadata being present in
the caller.

Instead of passing _metadata to a helper function like check_bytes(), call
TH_LOG() directly.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/mm/hugepage-mmap.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
index d543419de0407..8c246070572f9 100644
--- a/tools/testing/selftests/mm/hugepage-mmap.c
+++ b/tools/testing/selftests/mm/hugepage-mmap.c
@@ -20,11 +20,6 @@
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
 
-static void check_bytes(char *addr)
-{
-	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
-}
-
 static void write_bytes(char *addr)
 {
 	unsigned long i;
@@ -37,7 +32,7 @@ static int read_bytes(char *addr)
 {
 	unsigned long i;
 
-	check_bytes(addr);
+	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
 	for (i = 0; i < LENGTH; i++)
 		if (*(addr + i) != (char)i) {
 			ksft_print_msg("Error: Mismatch at %lu\n", i);
@@ -65,7 +60,7 @@ int main(void)
 	}
 
 	ksft_print_msg("Returned address is %p\n", addr);
-	check_bytes(addr);
+	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
 	write_bytes(addr);
 	ret = read_bytes(addr);
 

-- 
2.54.0.563.g4f69b47b94-goog



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 2/5] mm: selftests: Inline {read,write}_bytes functions
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 1/5] mm: selftests: Inline check_bytes() function into caller Ackerley Tng via B4 Relay
@ 2026-05-18 18:17 ` Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 3/5] mm: selftests: Refactor hugepage-mmap to use kselftest harness Ackerley Tng via B4 Relay
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

From: Ackerley Tng <ackerleytng@google.com>

When the kselftest_harness is used in a later patch, making assertions like
ASSERT_EQ() relies on _metadata's existence at the macro site, hence using
helper functions makes it more complicated.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/mm/hugepage-mmap.c | 38 +++++++++++-------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
index 8c246070572f9..64f7d28a97fdf 100644
--- a/tools/testing/selftests/mm/hugepage-mmap.c
+++ b/tools/testing/selftests/mm/hugepage-mmap.c
@@ -20,31 +20,11 @@
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
 
-static void write_bytes(char *addr)
-{
-	unsigned long i;
-
-	for (i = 0; i < LENGTH; i++)
-		*(addr + i) = (char)i;
-}
-
-static int read_bytes(char *addr)
-{
-	unsigned long i;
-
-	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
-	for (i = 0; i < LENGTH; i++)
-		if (*(addr + i) != (char)i) {
-			ksft_print_msg("Error: Mismatch at %lu\n", i);
-			return 1;
-		}
-	return 0;
-}
-
 int main(void)
 {
 	void *addr;
-	int fd, ret;
+	int fd, ret = 0;
+	unsigned long i;
 
 	ksft_print_header();
 	ksft_set_plan(1);
@@ -61,8 +41,18 @@ int main(void)
 
 	ksft_print_msg("Returned address is %p\n", addr);
 	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
-	write_bytes(addr);
-	ret = read_bytes(addr);
+
+	for (i = 0; i < LENGTH; i++)
+		*(char *)(addr + i) = (char)i;
+
+	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
+	for (i = 0; i < LENGTH; i++) {
+		if (*(char *)(addr + i) != (char)i) {
+			ksft_print_msg("Error: Mismatch at %lu\n", i);
+			ret = 1;
+			break;
+		}
+	}
 
 	munmap(addr, LENGTH);
 	close(fd);

-- 
2.54.0.563.g4f69b47b94-goog



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 3/5] mm: selftests: Refactor hugepage-mmap to use kselftest harness
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 1/5] mm: selftests: Inline check_bytes() function into caller Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 2/5] mm: selftests: Inline {read,write}_bytes functions Ackerley Tng via B4 Relay
@ 2026-05-18 18:17 ` Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 4/5] mm: selftests: Update hugepage-mmap to support hugetlbfs mount Ackerley Tng via B4 Relay
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

From: Ackerley Tng <ackerleytng@google.com>

Refactor hugepage-mmap.c to use the kselftest harness so that a later patch
can add a different setup flow.

Use a fixture for managing the hugetlbfs-backed memfd lifecycle (setup and
teardown).

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/mm/hugepage-mmap.c | 67 ++++++++++++++++--------------
 1 file changed, 36 insertions(+), 31 deletions(-)

diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
index 64f7d28a97fdf..9c8a0638d04b8 100644
--- a/tools/testing/selftests/mm/hugepage-mmap.c
+++ b/tools/testing/selftests/mm/hugepage-mmap.c
@@ -15,49 +15,54 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <fcntl.h>
-#include "kselftest.h"
+#include "kselftest_harness.h"
 
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
 
-int main(void)
+FIXTURE(hugepage_mmap)
 {
-	void *addr;
-	int fd, ret = 0;
-	unsigned long i;
-
-	ksft_print_header();
-	ksft_set_plan(1);
+	int fd;
+	char *addr;
+};
 
-	fd = memfd_create("hugepage-mmap", MFD_HUGETLB);
-	if (fd < 0)
-		ksft_exit_fail_msg("memfd_create() failed: %s\n", strerror(errno));
+FIXTURE_SETUP(hugepage_mmap)
+{
+	self->fd = memfd_create("hugepage-mmap", MFD_HUGETLB);
+	ASSERT_GE(self->fd, 0) {
+		TH_LOG("memfd_create() failed: %s", strerror(errno));
+	}
 
-	addr = mmap(NULL, LENGTH, PROTECTION, MAP_SHARED, fd, 0);
-	if (addr == MAP_FAILED) {
-		close(fd);
-		ksft_exit_fail_msg("mmap(): %s\n", strerror(errno));
+	self->addr = mmap(NULL, LENGTH, PROTECTION, MAP_SHARED, self->fd, 0);
+	ASSERT_NE(MAP_FAILED, self->addr) {
+		TH_LOG("mmap(): %s", strerror(errno));
+		close(self->fd);
 	}
+	TH_LOG("Returned address is %p", self->addr);
+}
 
-	ksft_print_msg("Returned address is %p\n", addr);
-	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
+FIXTURE_TEARDOWN(hugepage_mmap)
+{
+	munmap(self->addr, LENGTH);
+	close(self->fd);
+}
 
-	for (i = 0; i < LENGTH; i++)
-		*(char *)(addr + i) = (char)i;
+TEST_F(hugepage_mmap, read_write)
+{
+	unsigned long i;
 
-	ksft_print_msg("First hex is %x\n", *((unsigned int *)addr));
-	for (i = 0; i < LENGTH; i++) {
-		if (*(char *)(addr + i) != (char)i) {
-			ksft_print_msg("Error: Mismatch at %lu\n", i);
-			ret = 1;
-			break;
-		}
-	}
+	TH_LOG("First hex is %x", *((unsigned int *)self->addr));
 
-	munmap(addr, LENGTH);
-	close(fd);
+	for (i = 0; i < LENGTH; i++)
+		self->addr[i] = (char)i;
 
-	ksft_test_result(!ret, "Read same data\n");
+	TH_LOG("First hex is %x", *((unsigned int *)self->addr));
 
-	ksft_exit(!ret);
+	for (i = 0; i < LENGTH; i++) {
+		ASSERT_EQ(self->addr[i], (char)i) {
+			TH_LOG("Error: Mismatch at %lu\n", i);
+		};
+	}
 }
+
+TEST_HARNESS_MAIN

-- 
2.54.0.563.g4f69b47b94-goog



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 4/5] mm: selftests: Update hugepage-mmap to support hugetlbfs mount
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
                   ` (2 preceding siblings ...)
  2026-05-18 18:17 ` [PATCH RFC 3/5] mm: selftests: Refactor hugepage-mmap to use kselftest harness Ackerley Tng via B4 Relay
@ 2026-05-18 18:17 ` Ackerley Tng via B4 Relay
  2026-05-18 18:17 ` [PATCH RFC 5/5] mm: selftests: Port readback test logic from libhugetlbfs Ackerley Tng via B4 Relay
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

From: Ackerley Tng <ackerleytng@google.com>

Run the same write/read test for a file on a hugetlbfs mount, in addition
to a memfd.

Use FIXTURE_VARIANT for parametrized testing. Use an unlinked fd to make
save cleanup steps later.

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/mm/hugepage-mmap.c | 85 ++++++++++++++++++++++++++++--
 1 file changed, 80 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
index 9c8a0638d04b8..dd9fccb209b10 100644
--- a/tools/testing/selftests/mm/hugepage-mmap.c
+++ b/tools/testing/selftests/mm/hugepage-mmap.c
@@ -15,36 +15,111 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <fcntl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <limits.h>
 #include "kselftest_harness.h"
 
+static int hugetlbfs_unlinked_fd(const char *mount)
+{
+	char path[PATH_MAX];
+	int fd;
+
+	snprintf(path, sizeof(path), "%s/hugepage-mmap-XXXXXX", mount);
+	fd = mkstemp(path);
+	if (fd < 0)
+		return fd;
+
+	unlink(path);
+	return fd;
+}
+
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
 
+enum fd_kind {
+	MEMFD,
+	HUGETLBFS_FD,
+};
+
 FIXTURE(hugepage_mmap)
 {
 	int fd;
 	char *addr;
+	char mount_dir[PATH_MAX];
+};
+
+static int fd_create(struct __test_metadata *_metadata,
+		FIXTURE_DATA(hugepage_mmap) *self, enum fd_kind fd_kind)
+{
+	switch (fd_kind) {
+	case MEMFD:
+		return memfd_create("hugepage-mmap", MFD_HUGETLB);
+	case HUGETLBFS_FD: {
+		snprintf(self->mount_dir, sizeof(self->mount_dir),
+			 "/tmp/hugepage-mmap-XXXXXX");
+		ASSERT_NE(NULL, mkdtemp(self->mount_dir))
+		{
+			TH_LOG("mkdtemp() failed: %s", strerror(errno));
+		}
+		ASSERT_EQ(0, mount("none", self->mount_dir, "hugetlbfs", 0,
+				   "pagesize=2M"))
+		{
+			TH_LOG("mount() failed: %s", strerror(errno));
+		}
+		return hugetlbfs_unlinked_fd(self->mount_dir);
+	}
+	default:
+		return -1;
+	};
+}
+
+FIXTURE_VARIANT(hugepage_mmap)
+{
+	enum fd_kind fd_kind;
+};
+
+FIXTURE_VARIANT_ADD(hugepage_mmap, memfd)
+{
+	.fd_kind = MEMFD,
+};
+
+FIXTURE_VARIANT_ADD(hugepage_mmap, hugetlbfs_fd)
+{
+	.fd_kind = HUGETLBFS_FD,
 };
 
 FIXTURE_SETUP(hugepage_mmap)
 {
-	self->fd = memfd_create("hugepage-mmap", MFD_HUGETLB);
+	self->fd = -1;
+	self->addr = MAP_FAILED;
+	self->mount_dir[0] = '\0';
+	/* Enable teardown to cleanup on any assertions in FIXTURE_SETUP(). */
+	*_metadata->no_teardown = false;
+
+	self->fd = fd_create(_metadata, self, variant->fd_kind);
 	ASSERT_GE(self->fd, 0) {
-		TH_LOG("memfd_create() failed: %s", strerror(errno));
+		TH_LOG("fd creation failed: %s", strerror(errno));
 	}
 
 	self->addr = mmap(NULL, LENGTH, PROTECTION, MAP_SHARED, self->fd, 0);
 	ASSERT_NE(MAP_FAILED, self->addr) {
 		TH_LOG("mmap(): %s", strerror(errno));
-		close(self->fd);
 	}
 	TH_LOG("Returned address is %p", self->addr);
 }
 
 FIXTURE_TEARDOWN(hugepage_mmap)
 {
-	munmap(self->addr, LENGTH);
-	close(self->fd);
+	if (self->addr != MAP_FAILED)
+		munmap(self->addr, LENGTH);
+	if (self->fd >= 0)
+		close(self->fd);
+
+	if (variant->fd_kind == HUGETLBFS_FD && self->mount_dir[0]) {
+		umount(self->mount_dir);
+		rmdir(self->mount_dir);
+	}
 }
 
 TEST_F(hugepage_mmap, read_write)

-- 
2.54.0.563.g4f69b47b94-goog



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 5/5] mm: selftests: Port readback test logic from libhugetlbfs
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
                   ` (3 preceding siblings ...)
  2026-05-18 18:17 ` [PATCH RFC 4/5] mm: selftests: Update hugepage-mmap to support hugetlbfs mount Ackerley Tng via B4 Relay
@ 2026-05-18 18:17 ` Ackerley Tng via B4 Relay
  2026-05-19  5:32 ` [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Mike Rapoport
  2026-05-19 13:23 ` tarunsahu
  6 siblings, 0 replies; 8+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-05-18 18:17 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng

From: Ackerley Tng <ackerleytng@google.com>

Port verification logic from libhugetlbfs' tests/readback.c.

Iterate using an unsigned int pointer instead of a char pointer, which
enables testing against a greater range of stored values beyond [0, 255].

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
 tools/testing/selftests/mm/hugepage-mmap.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/selftests/mm/hugepage-mmap.c
index dd9fccb209b10..a7d4a3eba3dd7 100644
--- a/tools/testing/selftests/mm/hugepage-mmap.c
+++ b/tools/testing/selftests/mm/hugepage-mmap.c
@@ -45,7 +45,7 @@ enum fd_kind {
 FIXTURE(hugepage_mmap)
 {
 	int fd;
-	char *addr;
+	unsigned int *addr;
 	char mount_dir[PATH_MAX];
 };
 
@@ -122,19 +122,21 @@ FIXTURE_TEARDOWN(hugepage_mmap)
 	}
 }
 
+#define RANDOM_CONSTANT 0x1234ABCD
+
 TEST_F(hugepage_mmap, read_write)
 {
 	unsigned long i;
 
-	TH_LOG("First hex is %x", *((unsigned int *)self->addr));
+	TH_LOG("First hex is %x", *self->addr);
 
-	for (i = 0; i < LENGTH; i++)
-		self->addr[i] = (char)i;
+	for (i = 0; i < LENGTH / sizeof(*self->addr); i++)
+		self->addr[i] = RANDOM_CONSTANT ^ i;
 
-	TH_LOG("First hex is %x", *((unsigned int *)self->addr));
+	TH_LOG("First hex is %x", *self->addr);
 
-	for (i = 0; i < LENGTH; i++) {
-		ASSERT_EQ(self->addr[i], (char)i) {
+	for (i = 0; i < LENGTH / sizeof(*self->addr); i++) {
+		ASSERT_EQ(self->addr[i], RANDOM_CONSTANT ^ i) {
 			TH_LOG("Error: Mismatch at %lu\n", i);
 		};
 	}

-- 
2.54.0.563.g4f69b47b94-goog



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
                   ` (4 preceding siblings ...)
  2026-05-18 18:17 ` [PATCH RFC 5/5] mm: selftests: Port readback test logic from libhugetlbfs Ackerley Tng via B4 Relay
@ 2026-05-19  5:32 ` Mike Rapoport
  2026-05-19 13:23 ` tarunsahu
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Rapoport @ 2026-05-19  5:32 UTC (permalink / raw)
  To: ackerleytng
  Cc: Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan,
	Michal Hocko, Shuah Khan, muchun.song, osalvador, linux-mm,
	linux-kselftest, linux-kernel

Hi,

On Mon, May 18, 2026 at 11:17:32AM -0700, Ackerley Tng via B4 Relay wrote:
> Hi,
> 
> I'm thinking of consolidating the tests for libhugetlbfs as kernel
> selftests, and to start that off, I picked the simplest test:
> tests/readback.c
> 
> I refactored hugepage-mmap.c to use the kselftest harness, and then used

I made a lot of changes to mm selftests recently:
https://lore.kernel.org/all/20260511162840.375890-1-rppt@kernel.org/

This work is currently in mm.git, please take a look to avoid effort
duplication.

> FIXTURE_VARIANT from the harness to port in testing readback from an fd on
> a hugetlbfs mount.

I didn't look into the patches, but in general I'm not sure that
FIXTURE_VARIANT is such a win for simple tests.
 
> This output shows that the original test behavior was retained for the
> memfd part:
> 
>   # ./hugepage-mmap
>   TAP version 13
>   1..1
>   # Returned address is 0x7f312f200000
>   # First hex is 0
>   # First hex is 3020100
>   ok 1 Read same data
>   # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
>   # ./hugepage-mmap
>   TAP version 13
>   1..1
>   # Starting 1 tests from 1 test cases.
>   #  RUN           hugepage_mmap.read_write ...
>   # hugepage-mmap.c:41:read_write:Returned address is 0x7f19f3a00000
>   # hugepage-mmap.c:54:read_write:First hex is 0
>   # hugepage-mmap.c:59:read_write:First hex is 3020100
>   #            OK  hugepage_mmap.read_write
>   ok 1 hugepage_mmap.read_write
>   # PASSED: 1 / 1 tests passed.
>   # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> Let me know what you think before I genericize the 2M hugepage size to
> other sizes!
> 
> Signed-off-by: Ackerley Tng <ackerleytng@google.com>
> ---
> Ackerley Tng (5):
>       mm: selftests: Inline check_bytes() function into caller
>       mm: selftests: Inline {read,write}_bytes functions
>       mm: selftests: Refactor hugepage-mmap to use kselftest harness
>       mm: selftests: Update hugepage-mmap to support hugetlbfs mount
>       mm: selftests: Port readback test logic from libhugetlbfs
> 
>  tools/testing/selftests/mm/hugepage-mmap.c | 143 +++++++++++++++++++++--------
>  1 file changed, 105 insertions(+), 38 deletions(-)
> ---
> base-commit: 66edb901bf874d9e0787326ba12d3548b2da8700
> change-id: 20260503-port-hugetlb-selftests-9bc63bde5116
> 
> Best regards,
> --
> Ackerley Tng <ackerleytng@google.com>
> 
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount
  2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
                   ` (5 preceding siblings ...)
  2026-05-19  5:32 ` [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Mike Rapoport
@ 2026-05-19 13:23 ` tarunsahu
  6 siblings, 0 replies; 8+ messages in thread
From: tarunsahu @ 2026-05-19 13:23 UTC (permalink / raw)
  To: Ackerley Tng, Andrew Morton, David Hildenbrand, Lorenzo Stoakes,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Shuah Khan, muchun.song,
	osalvador
  Cc: linux-mm, linux-kselftest, linux-kernel, Ackerley Tng


If you are planning to port all the libhugetlbfs tests to kselftests
I had similar efforts done in past for LTP here:
https://github.com/linux-test-project/ltp/commits/master/?author=tar-unix

These tests were migrated to LTP from libhugetlbfs.

Just want to make sure if we completely want to itegrate in kselftests
or LTP fulfil that purpose.

OR Only tests that are not part of LTP should be ported to kselftests.

Thanks

Ackerley Tng <ackerleytng@google.com> writes:

> Hi,
>
> I'm thinking of consolidating the tests for libhugetlbfs as kernel
> selftests, and to start that off, I picked the simplest test:
> tests/readback.c
>
> I refactored hugepage-mmap.c to use the kselftest harness, and then used
> FIXTURE_VARIANT from the harness to port in testing readback from an fd on
> a hugetlbfs mount.
>
> This output shows that the original test behavior was retained for the
> memfd part:
>
>   # ./hugepage-mmap
>   TAP version 13
>   1..1
>   # Returned address is 0x7f312f200000
>   # First hex is 0
>   # First hex is 3020100
>   ok 1 Read same data
>   # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>
>   # ./hugepage-mmap
>   TAP version 13
>   1..1
>   # Starting 1 tests from 1 test cases.
>   #  RUN           hugepage_mmap.read_write ...
>   # hugepage-mmap.c:41:read_write:Returned address is 0x7f19f3a00000
>   # hugepage-mmap.c:54:read_write:First hex is 0
>   # hugepage-mmap.c:59:read_write:First hex is 3020100
>   #            OK  hugepage_mmap.read_write
>   ok 1 hugepage_mmap.read_write
>   # PASSED: 1 / 1 tests passed.
>   # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> Let me know what you think before I genericize the 2M hugepage size to
> other sizes!
>
> Signed-off-by: Ackerley Tng <ackerleytng@google.com>
> ---
> Ackerley Tng (5):
>       mm: selftests: Inline check_bytes() function into caller
>       mm: selftests: Inline {read,write}_bytes functions
>       mm: selftests: Refactor hugepage-mmap to use kselftest harness
>       mm: selftests: Update hugepage-mmap to support hugetlbfs mount
>       mm: selftests: Port readback test logic from libhugetlbfs
>
>  tools/testing/selftests/mm/hugepage-mmap.c | 143 +++++++++++++++++++++--------
>  1 file changed, 105 insertions(+), 38 deletions(-)
> ---
> base-commit: 66edb901bf874d9e0787326ba12d3548b2da8700
> change-id: 20260503-port-hugetlb-selftests-9bc63bde5116
>
> Best regards,
> --
> Ackerley Tng <ackerleytng@google.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-05-19 13:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 18:17 [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Ackerley Tng via B4 Relay
2026-05-18 18:17 ` [PATCH RFC 1/5] mm: selftests: Inline check_bytes() function into caller Ackerley Tng via B4 Relay
2026-05-18 18:17 ` [PATCH RFC 2/5] mm: selftests: Inline {read,write}_bytes functions Ackerley Tng via B4 Relay
2026-05-18 18:17 ` [PATCH RFC 3/5] mm: selftests: Refactor hugepage-mmap to use kselftest harness Ackerley Tng via B4 Relay
2026-05-18 18:17 ` [PATCH RFC 4/5] mm: selftests: Update hugepage-mmap to support hugetlbfs mount Ackerley Tng via B4 Relay
2026-05-18 18:17 ` [PATCH RFC 5/5] mm: selftests: Port readback test logic from libhugetlbfs Ackerley Tng via B4 Relay
2026-05-19  5:32 ` [PATCH RFC 0/5] Test readback from fd on hugetlbfs mount Mike Rapoport
2026-05-19 13:23 ` tarunsahu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox