Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
@ 2026-08-09  8:03 Mike Rapoport (Microsoft)
  2026-08-11 15:43 ` David Hildenbrand (Arm)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-09  8:03 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Mike Rapoport,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-kselftest, linux-mm

Commit 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
changed thuge-gen test to use common functions for reading hugetlb
attributes from sysfs, but it missed that the original read_free() function
special cased PAGE_SIZE tests.

For PAGE_SIZE tests, failure to read sysfs was ignored and read_free()
returned 0.

This allowed test_shmget() to essentially skip the check of how many huge
pages was consumed when it ran with PAGE_SIZE.

Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check")
fixed the common read_file() to actually return error on failure and this
exposed the issue in test_shmget() that checks the number of free hugetlb
pages even for PAGE_SIZE test, tries to access

/sys/kernel/mm/hugepages/hugepages-<PAGE_SIZE>/free_hugepages

and obviously fails there.

Gate the checks for free huge pages on size != getpagesize() and initialize
before and after variables to values matching PAGE_SIZE test.

Fixes: 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
---
 tools/testing/selftests/mm/thuge-gen.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
index 22b9c2f1c35d..50d0805b65db 100644
--- a/tools/testing/selftests/mm/thuge-gen.c
+++ b/tools/testing/selftests/mm/thuge-gen.c
@@ -71,12 +71,16 @@ void test_mmap(unsigned long size, unsigned flags)
 
 void test_shmget(unsigned long size, unsigned flags)
 {
-	int id;
-	unsigned long before, after;
+	/* values for PAGE_SIZE test */
+	unsigned long before = NUM_PAGES;
+	unsigned long after = 0;
 	struct shm_info i;
 	char *map;
+	int id;
+
+	if (size != getpagesize())
+		before = hugetlb_free_pages(size);
 
-	before = hugetlb_free_pages(size);
 	id = shmget(IPC_PRIVATE, size * NUM_PAGES, IPC_CREAT|0600|flags);
 	if (id < 0) {
 		if (errno == EPERM) {
@@ -97,10 +101,11 @@ void test_shmget(unsigned long size, unsigned flags)
 	shmctl(id, IPC_RMID, NULL);
 
 	memset(map, 0xff, size*NUM_PAGES);
-	after = hugetlb_free_pages(size);
+	if (size != getpagesize())
+		after = hugetlb_free_pages(size);
 
 	show(size);
-	ksft_test_result(size == getpagesize() || (before - after) == NUM_PAGES,
+	ksft_test_result((before - after) == NUM_PAGES,
 			 "%s: mmap %lu %x\n", __func__, size, flags);
 	if (shmdt(map))
 		ksft_exit_fail_msg("%s: shmdt: %s\n", __func__, strerror(errno));

---
base-commit: 17e5919bdca144d4e67337f53bf57d7811f62192
change-id: 20260809-selftests-thuge-gen-fix-5ac05f56307c

--
Sincerely yours,
Mike.


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

* Re: [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
  2026-08-09  8:03 [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check Mike Rapoport (Microsoft)
@ 2026-08-11 15:43 ` David Hildenbrand (Arm)
  2026-08-11 16:20 ` Andrew Morton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-08-11 15:43 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Andrew Morton
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-kselftest, linux-mm

On 8/9/26 10:03, Mike Rapoport (Microsoft) wrote:
> Commit 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> changed thuge-gen test to use common functions for reading hugetlb
> attributes from sysfs, but it missed that the original read_free() function
> special cased PAGE_SIZE tests.
> 
> For PAGE_SIZE tests, failure to read sysfs was ignored and read_free()
> returned 0.
> 
> This allowed test_shmget() to essentially skip the check of how many huge
> pages was consumed when it ran with PAGE_SIZE.
> 
> Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check")
> fixed the common read_file() to actually return error on failure and this
> exposed the issue in test_shmget() that checks the number of free hugetlb
> pages even for PAGE_SIZE test, tries to access
> 
> /sys/kernel/mm/hugepages/hugepages-<PAGE_SIZE>/free_hugepages
> 
> and obviously fails there.
> 
> Gate the checks for free huge pages on size != getpagesize() and initialize
> before and after variables to values matching PAGE_SIZE test.
> 
> Fixes: 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---

Heh :)

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

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

* Re: [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
  2026-08-09  8:03 [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check Mike Rapoport (Microsoft)
  2026-08-11 15:43 ` David Hildenbrand (Arm)
@ 2026-08-11 16:20 ` Andrew Morton
  2026-08-12  5:35 ` Sarthak Sharma
  2026-08-12  7:19 ` Lorenzo Stoakes (ARM)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-08-11 16:20 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: David Hildenbrand, Liam R. Howlett, Lorenzo Stoakes, Michal Hocko,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-kselftest, linux-mm

On Sun, 09 Aug 2026 11:03:35 +0300 "Mike Rapoport (Microsoft)" <rppt@kernel.org> wrote:

> Commit 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> changed thuge-gen test to use common functions for reading hugetlb
> attributes from sysfs, but it missed that the original read_free() function
> special cased PAGE_SIZE tests.
> 
> For PAGE_SIZE tests, failure to read sysfs was ignored and read_free()
> returned 0.
> 
> This allowed test_shmget() to essentially skip the check of how many huge
> pages was consumed when it ran with PAGE_SIZE.
> 
> Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check")
> fixed the common read_file() to actually return error on failure and this
> exposed the issue in test_shmget() that checks the number of free hugetlb
> pages even for PAGE_SIZE test, tries to access
> 
> /sys/kernel/mm/hugepages/hugepages-<PAGE_SIZE>/free_hugepages
> 
> and obviously fails there.
> 
> Gate the checks for free huge pages on size != getpagesize() and initialize
> before and after variables to values matching PAGE_SIZE test.

Thanks.

> Fixes: 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")

Which is in mm-stable.  I'll plan to slip this fixup into mm-stable
later this week.


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

* Re: [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
  2026-08-09  8:03 [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check Mike Rapoport (Microsoft)
  2026-08-11 15:43 ` David Hildenbrand (Arm)
  2026-08-11 16:20 ` Andrew Morton
@ 2026-08-12  5:35 ` Sarthak Sharma
  2026-08-12  7:19 ` Lorenzo Stoakes (ARM)
  3 siblings, 0 replies; 5+ messages in thread
From: Sarthak Sharma @ 2026-08-12  5:35 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Andrew Morton, David Hildenbrand
  Cc: Liam R. Howlett, Lorenzo Stoakes, Michal Hocko, Shuah Khan,
	Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-kselftest, linux-mm

Hi Mike!

On 8/9/26 1:33 PM, Mike Rapoport (Microsoft) wrote:
> Commit 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> changed thuge-gen test to use common functions for reading hugetlb
> attributes from sysfs, but it missed that the original read_free() function
> special cased PAGE_SIZE tests.
> 
> For PAGE_SIZE tests, failure to read sysfs was ignored and read_free()
> returned 0.>
> This allowed test_shmget() to essentially skip the check of how many huge
> pages was consumed when it ran with PAGE_SIZE.
> 
> Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check")
> fixed the common read_file() to actually return error on failure and this

This commit does not make read_file return an error, it just fixes a
"read_file() < 0" check, which can never happen since currently
read_file() never returns a negative number.

The patch from my series, "selftests/mm: make file helpers return
errors" [1], is the one that changes read_file() to return a negative
errno on failure. It also exposed the same test_shmget() issue and
caused the CI failure [2]. I also debugged the failure and traced it to
test_shmget() [3].

I was planning to fix this in my next revision, but I will drop that
change now. :)

Rest the change looks good, so:

Reviewed-by: Sarthak Sharma <sarthak.sharma@arm.com>

[1]
https://lore.kernel.org/all/20260730140825.238130-2-sarthak.sharma@arm.com/
[2]
https://github.com/linux-mm/linux-mm/actions/runs/30553882784/job/90909219578

[3]
https://lore.kernel.org/all/9eb7852a-c14f-4bbc-86dc-4775f882fe27@arm.com/

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

* Re: [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
  2026-08-09  8:03 [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check Mike Rapoport (Microsoft)
                   ` (2 preceding siblings ...)
  2026-08-12  5:35 ` Sarthak Sharma
@ 2026-08-12  7:19 ` Lorenzo Stoakes (ARM)
  3 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-08-12  7:19 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft)
  Cc: Andrew Morton, David Hildenbrand, Liam R. Howlett, Michal Hocko,
	Shuah Khan, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-kselftest, linux-mm

On Sun, Aug 09, 2026 at 11:03:35AM +0300, Mike Rapoport (Microsoft) wrote:
> Commit 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> changed thuge-gen test to use common functions for reading hugetlb
> attributes from sysfs, but it missed that the original read_free() function
> special cased PAGE_SIZE tests.
>
> For PAGE_SIZE tests, failure to read sysfs was ignored and read_free()
> returned 0.
>
> This allowed test_shmget() to essentially skip the check of how many huge
> pages was consumed when it ran with PAGE_SIZE.
>
> Commit 3199b0c09efa ("selftests/mm: fix read_file() return value check")
> fixed the common read_file() to actually return error on failure and this
> exposed the issue in test_shmget() that checks the number of free hugetlb
> pages even for PAGE_SIZE test, tries to access
>
> /sys/kernel/mm/hugepages/hugepages-<PAGE_SIZE>/free_hugepages
>
> and obviously fails there.
>
> Gate the checks for free huge pages on size != getpagesize() and initialize
> before and after variables to values matching PAGE_SIZE test.
>
> Fixes: 49a4e7186b08 ("selftests/mm: thuge-gen: add setup of HugeTLB pages")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

With the issue Sarthak brought up addressed, LGTM, so:

Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

> ---
> selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check
> ---
>  tools/testing/selftests/mm/thuge-gen.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c
> index 22b9c2f1c35d..50d0805b65db 100644
> --- a/tools/testing/selftests/mm/thuge-gen.c
> +++ b/tools/testing/selftests/mm/thuge-gen.c
> @@ -71,12 +71,16 @@ void test_mmap(unsigned long size, unsigned flags)
>
>  void test_shmget(unsigned long size, unsigned flags)
>  {
> -	int id;
> -	unsigned long before, after;
> +	/* values for PAGE_SIZE test */
> +	unsigned long before = NUM_PAGES;
> +	unsigned long after = 0;
>  	struct shm_info i;
>  	char *map;
> +	int id;
> +
> +	if (size != getpagesize())
> +		before = hugetlb_free_pages(size);
>
> -	before = hugetlb_free_pages(size);
>  	id = shmget(IPC_PRIVATE, size * NUM_PAGES, IPC_CREAT|0600|flags);
>  	if (id < 0) {
>  		if (errno == EPERM) {
> @@ -97,10 +101,11 @@ void test_shmget(unsigned long size, unsigned flags)
>  	shmctl(id, IPC_RMID, NULL);
>
>  	memset(map, 0xff, size*NUM_PAGES);
> -	after = hugetlb_free_pages(size);
> +	if (size != getpagesize())
> +		after = hugetlb_free_pages(size);
>
>  	show(size);
> -	ksft_test_result(size == getpagesize() || (before - after) == NUM_PAGES,
> +	ksft_test_result((before - after) == NUM_PAGES,
>  			 "%s: mmap %lu %x\n", __func__, size, flags);
>  	if (shmdt(map))
>  		ksft_exit_fail_msg("%s: shmdt: %s\n", __func__, strerror(errno));
>
> ---
> base-commit: 17e5919bdca144d4e67337f53bf57d7811f62192
> change-id: 20260809-selftests-thuge-gen-fix-5ac05f56307c
>
> --
> Sincerely yours,
> Mike.
>

--
Cheers, Lorenzo

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

end of thread, other threads:[~2026-08-12  7:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09  8:03 [PATCH] selftests/mm: thuge-gen: fix test_shmget() for PAGE_SIZE check Mike Rapoport (Microsoft)
2026-08-11 15:43 ` David Hildenbrand (Arm)
2026-08-11 16:20 ` Andrew Morton
2026-08-12  5:35 ` Sarthak Sharma
2026-08-12  7:19 ` Lorenzo Stoakes (ARM)

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