Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
@ 2026-05-12 10:13 Hongfu Li
  2026-05-12 10:33 ` David Hildenbrand (Arm)
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Hongfu Li @ 2026-05-12 10:13 UTC (permalink / raw)
  To: jgg, leon, akpm, david, ljs, vbabka, rppt, surenb, mhocko, shuah
  Cc: linux-mm, linux-kselftest, linux-kernel, Hongfu Li

mmap() returns MAP_FAILED on error, not NULL.  The current check uses
!buffer->ptr, which evaluates to false when mmap() fails (since
MAP_FAILED is (void *)-1, not 0), so the error path is never taken.

Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
 tools/testing/selftests/mm/hmm-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
index 788689497e92..d72adba5c74e 100644
--- a/tools/testing/selftests/mm/hmm-tests.c
+++ b/tools/testing/selftests/mm/hmm-tests.c
@@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
 	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
 			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
-	if (!buffer->ptr)
+	if (buffer->ptr == MAP_FAILED)
 		return -1;
 
 	/* Apply THP hint if requested */
-- 
2.25.1



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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
@ 2026-05-12 10:33 ` David Hildenbrand (Arm)
  2026-05-12 11:13 ` Dev Jain
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand (Arm) @ 2026-05-12 10:33 UTC (permalink / raw)
  To: Hongfu Li, jgg, leon, akpm, ljs, vbabka, rppt, surenb, mhocko,
	shuah
  Cc: linux-mm, linux-kselftest, linux-kernel

On 5/12/26 12:13, Hongfu Li wrote:
> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.
> 
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
> ---
>  tools/testing/selftests/mm/hmm-tests.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..d72adba5c74e 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>  	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
>  			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
> -	if (!buffer->ptr)
> +	if (buffer->ptr == MAP_FAILED)
>  		return -1;
>  
>  	/* Apply THP hint if requested */


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

-- 
Cheers,

David


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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
  2026-05-12 10:33 ` David Hildenbrand (Arm)
@ 2026-05-12 11:13 ` Dev Jain
  2026-05-12 12:21 ` Mike Rapoport
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dev Jain @ 2026-05-12 11:13 UTC (permalink / raw)
  To: Hongfu Li, jgg, leon, akpm, david, ljs, vbabka, rppt, surenb,
	mhocko, shuah
  Cc: linux-mm, linux-kselftest, linux-kernel



On 12/05/26 3:43 pm, Hongfu Li wrote:
> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.
> 
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
> ---

Reviewed-by: Dev Jain <dev.jain@arm.com>

>  tools/testing/selftests/mm/hmm-tests.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..d72adba5c74e 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>  	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
>  			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
> -	if (!buffer->ptr)
> +	if (buffer->ptr == MAP_FAILED)
>  		return -1;
>  
>  	/* Apply THP hint if requested */



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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
  2026-05-12 10:33 ` David Hildenbrand (Arm)
  2026-05-12 11:13 ` Dev Jain
@ 2026-05-12 12:21 ` Mike Rapoport
  2026-05-12 12:57 ` Donet Tom
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Mike Rapoport @ 2026-05-12 12:21 UTC (permalink / raw)
  To: Hongfu Li
  Cc: jgg, leon, akpm, david, ljs, vbabka, surenb, mhocko, shuah,
	linux-mm, linux-kselftest, linux-kernel

On Tue, May 12, 2026 at 06:13:05PM +0800, Hongfu Li wrote:
> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.
> 
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>

Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  tools/testing/selftests/mm/hmm-tests.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..d72adba5c74e 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>  	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
>  			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
> -	if (!buffer->ptr)
> +	if (buffer->ptr == MAP_FAILED)
>  		return -1;
>  
>  	/* Apply THP hint if requested */
> -- 
> 2.25.1
> 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
                   ` (2 preceding siblings ...)
  2026-05-12 12:21 ` Mike Rapoport
@ 2026-05-12 12:57 ` Donet Tom
  2026-05-12 14:06 ` Lorenzo Stoakes
  2026-05-13  0:42 ` SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: Donet Tom @ 2026-05-12 12:57 UTC (permalink / raw)
  To: Hongfu Li, jgg, leon, akpm, david, ljs, vbabka, rppt, surenb,
	mhocko, shuah
  Cc: linux-mm, linux-kselftest, linux-kernel


On 5/12/26 3:43 PM, Hongfu Li wrote:
> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.
>
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>


LGTM

Reviewed-by: Donet Tom <donettom@linux.ibm.com>

> ---
>   tools/testing/selftests/mm/hmm-tests.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..d72adba5c74e 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>   	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
>   			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>   
> -	if (!buffer->ptr)
> +	if (buffer->ptr == MAP_FAILED)
>   		return -1;
>   
>   	/* Apply THP hint if requested */


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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
                   ` (3 preceding siblings ...)
  2026-05-12 12:57 ` Donet Tom
@ 2026-05-12 14:06 ` Lorenzo Stoakes
  2026-05-13  0:42 ` SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: Lorenzo Stoakes @ 2026-05-12 14:06 UTC (permalink / raw)
  To: Hongfu Li
  Cc: jgg, leon, akpm, david, vbabka, rppt, surenb, mhocko, shuah,
	linux-mm, linux-kselftest, linux-kernel

On Tue, May 12, 2026 at 06:13:05PM +0800, Hongfu Li wrote:
> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.
>
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>

LGTM, so:

Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>

> ---
>  tools/testing/selftests/mm/hmm-tests.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftests/mm/hmm-tests.c
> index 788689497e92..d72adba5c74e 100644
> --- a/tools/testing/selftests/mm/hmm-tests.c
> +++ b/tools/testing/selftests/mm/hmm-tests.c
> @@ -2688,7 +2688,7 @@ static inline int run_migration_benchmark(int fd, int use_thp, size_t buffer_siz
>  	buffer->ptr = mmap(NULL, buffer_size, PROT_READ | PROT_WRITE,
>  			  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>
> -	if (!buffer->ptr)
> +	if (buffer->ptr == MAP_FAILED)
>  		return -1;
>
>  	/* Apply THP hint if requested */
> --
> 2.25.1
>


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

* Re: [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark
  2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
                   ` (4 preceding siblings ...)
  2026-05-12 14:06 ` Lorenzo Stoakes
@ 2026-05-13  0:42 ` SeongJae Park
  5 siblings, 0 replies; 7+ messages in thread
From: SeongJae Park @ 2026-05-13  0:42 UTC (permalink / raw)
  To: Hongfu Li
  Cc: SeongJae Park, jgg, leon, akpm, david, ljs, vbabka, rppt, surenb,
	mhocko, shuah, linux-mm, linux-kselftest, linux-kernel

On Tue, 12 May 2026 18:13:05 +0800 Hongfu Li <lihongfu@kylinos.cn> wrote:

> mmap() returns MAP_FAILED on error, not NULL.  The current check uses
> !buffer->ptr, which evaluates to false when mmap() fails (since
> MAP_FAILED is (void *)-1, not 0), so the error path is never taken.

Good catch, thank you!

> 
> Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>

Reviewed-by: SeongJae Park <sj@kernel.org>


Thanks,
SJ

[...]


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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 10:13 [PATCH] selftests/mm: Fix mmap() return value check in run_migration_benchmark Hongfu Li
2026-05-12 10:33 ` David Hildenbrand (Arm)
2026-05-12 11:13 ` Dev Jain
2026-05-12 12:21 ` Mike Rapoport
2026-05-12 12:57 ` Donet Tom
2026-05-12 14:06 ` Lorenzo Stoakes
2026-05-13  0:42 ` SeongJae Park

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