Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test
@ 2026-09-07 13:56 Zenghui Yu
  2026-09-07 14:57 ` Gregory Price
  2026-09-07 15:22 ` David Hildenbrand (Arm)
  0 siblings, 2 replies; 3+ messages in thread
From: Zenghui Yu @ 2026-09-07 13:56 UTC (permalink / raw)
  To: linux-mm, linux-kselftest, linux-kernel
  Cc: akpm, david, ljs, liam, vbabka, rppt, surenb, mhocko, shuah,
	Zenghui Yu (Huawei)

From: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>

On arm64 with 64K base pages, the huge page size is 512 MiB, and
hpage_unit_tests() builds a 5 GiB range (10 * 512 MiB) for its tests.  This
exceeds the range of the int size parameters of gethugepage(),
wp_addr_range() and pagemap_ioctl().  The implicit truncation to 1 GiB
makes gethugepage() allocate a too small buffer, while the callers keep
operating on the original 5 GiB range, resulting in spurious failures or
SIGSEGV.

Change those size parameters to size_t.

Fixes: 46fd75d4a3c9 ("selftests: mm: add pagemap ioctl tests")
Assisted-by: GLM-5.3 OpenCode
Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>
---
 tools/testing/selftests/mm/pagemap_ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
index eadc7159ca5b..48cbea3a33c9 100644
--- a/tools/testing/selftests/mm/pagemap_ioctl.c
+++ b/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -44,7 +44,7 @@ const char *progname;
 
 #define LEN(region)	((region.end - region.start)/page_size)
 
-static long pagemap_ioctl(void *start, int len, void *vec, int vec_len, int flag,
+static long pagemap_ioctl(void *start, size_t len, void *vec, int vec_len, int flag,
 			  int max_pages, long required_mask, long anyof_mask, long excluded_mask,
 			  long return_mask)
 {
@@ -152,7 +152,7 @@ int wp_free(void *addr, long size)
 	return 0;
 }
 
-int wp_addr_range(void *addr, int size)
+int wp_addr_range(void *addr, size_t size)
 {
 	if (pagemap_ioctl(addr, size, NULL, 0,
 			  PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC,
@@ -787,7 +787,7 @@ int base_tests(char *prefix, char *mem, unsigned long long mem_size, int skip)
 	return 0;
 }
 
-void *gethugepage(int map_size)
+void *gethugepage(size_t map_size)
 {
 	int ret;
 	char *map;
-- 
2.53.0



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

* Re: [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test
  2026-09-07 13:56 [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test Zenghui Yu
@ 2026-09-07 14:57 ` Gregory Price
  2026-09-07 15:22 ` David Hildenbrand (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: Gregory Price @ 2026-09-07 14:57 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: linux-mm, linux-kselftest, linux-kernel, akpm, david, ljs, liam,
	vbabka, rppt, surenb, mhocko, shuah

On Mon, Sep 07, 2026 at 09:56:13PM +0800, Zenghui Yu wrote:
> From: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>
> 
> On arm64 with 64K base pages, the huge page size is 512 MiB, and
> hpage_unit_tests() builds a 5 GiB range (10 * 512 MiB) for its tests.  This
> exceeds the range of the int size parameters of gethugepage(),
> wp_addr_range() and pagemap_ioctl().  The implicit truncation to 1 GiB
> makes gethugepage() allocate a too small buffer, while the callers keep
> operating on the original 5 GiB range, resulting in spurious failures or
> SIGSEGV.
> 
> Change those size parameters to size_t.
> 
> Fixes: 46fd75d4a3c9 ("selftests: mm: add pagemap ioctl tests")
> Assisted-by: GLM-5.3 OpenCode
> Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>

Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>

> ---
>  tools/testing/selftests/mm/pagemap_ioctl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/selftests/mm/pagemap_ioctl.c
> index eadc7159ca5b..48cbea3a33c9 100644
> --- a/tools/testing/selftests/mm/pagemap_ioctl.c
> +++ b/tools/testing/selftests/mm/pagemap_ioctl.c
> @@ -44,7 +44,7 @@ const char *progname;
>  
>  #define LEN(region)	((region.end - region.start)/page_size)
>  
> -static long pagemap_ioctl(void *start, int len, void *vec, int vec_len, int flag,
> +static long pagemap_ioctl(void *start, size_t len, void *vec, int vec_len, int flag,
>  			  int max_pages, long required_mask, long anyof_mask, long excluded_mask,
>  			  long return_mask)
>  {
> @@ -152,7 +152,7 @@ int wp_free(void *addr, long size)
>  	return 0;
>  }
>  
> -int wp_addr_range(void *addr, int size)
> +int wp_addr_range(void *addr, size_t size)
>  {
>  	if (pagemap_ioctl(addr, size, NULL, 0,
>  			  PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC,
> @@ -787,7 +787,7 @@ int base_tests(char *prefix, char *mem, unsigned long long mem_size, int skip)
>  	return 0;
>  }
>  
> -void *gethugepage(int map_size)
> +void *gethugepage(size_t map_size)
>  {
>  	int ret;
>  	char *map;
> -- 
> 2.53.0
> 


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

* Re: [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test
  2026-09-07 13:56 [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test Zenghui Yu
  2026-09-07 14:57 ` Gregory Price
@ 2026-09-07 15:22 ` David Hildenbrand (Arm)
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-07 15:22 UTC (permalink / raw)
  To: Zenghui Yu, linux-mm, linux-kselftest, linux-kernel
  Cc: akpm, ljs, liam, vbabka, rppt, surenb, mhocko, shuah

On 9/7/26 15:56, Zenghui Yu wrote:
> From: "Zenghui Yu (Huawei)" <zenghui.yu@linux.dev>
> 
> On arm64 with 64K base pages, the huge page size is 512 MiB, and
> hpage_unit_tests() builds a 5 GiB range (10 * 512 MiB) for its tests.  This
> exceeds the range of the int size parameters of gethugepage(),
> wp_addr_range() and pagemap_ioctl().  The implicit truncation to 1 GiB
> makes gethugepage() allocate a too small buffer, while the callers keep
> operating on the original 5 GiB range, resulting in spurious failures or
> SIGSEGV.
> 
> Change those size parameters to size_t.
> 
> Fixes: 46fd75d4a3c9 ("selftests: mm: add pagemap ioctl tests")
> Assisted-by: GLM-5.3 OpenCode
> Signed-off-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>
> ---

Looking at pagemap_ioctl.c ... I think most functions should actually be "static".


Using size_t is ok. But then we should also change "unsigned long long mem_size"
to size_t, no?

Also, in wp_free() we are suddenly using "long size". In pagemap_ioc() we're
also still using "int len".

Can we consistently use one type please?

-- 
Cheers,

David


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

end of thread, other threads:[~2026-09-07 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 13:56 [PATCH] selftests/mm: fix size truncation in pagemap_ioctl test Zenghui Yu
2026-09-07 14:57 ` Gregory Price
2026-09-07 15:22 ` David Hildenbrand (Arm)

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