linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: Fix validate_addr helper
@ 2025-06-20 11:11 Dev Jain
  2025-06-20 12:08 ` Dev Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dev Jain @ 2025-06-20 11:11 UTC (permalink / raw)
  To: akpm, shuah
  Cc: linux-kselftest, linux-kernel, anshuman.khandual, ryan.roberts,
	lorenzo.stoakes, david, donettom, Dev Jain

validate_addr() function checks whether the address returned by mmap()
lies in the low or high VA space, according to whether a high addr hint
was passed or not. The fix commit mentioned below changed the code in
such a way that this function will always return failure when passed
high_addr == 1; addr will be >= HIGH_ADDR_MARK always, we will fall
down to "if (addr < HIGH_ADDR_MARK)" and return failure. Fix this.

Fixes: d1d86ce28d0f ("selftests/mm: virtual_address_range: conform to TAP format output")
Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
index b380e102b22f..169dbd692bf5 100644
--- a/tools/testing/selftests/mm/virtual_address_range.c
+++ b/tools/testing/selftests/mm/virtual_address_range.c
@@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
 {
 	unsigned long addr = (unsigned long) ptr;
 
-	if (high_addr && addr < HIGH_ADDR_MARK)
-		ksft_exit_fail_msg("Bad address %lx\n", addr);
+	if (high_addr) {
+		if (addr < HIGH_ADDR_MARK)
+			ksft_exit_fail_msg("Bad address %lx\n", addr);
+		return;
+	}
 
 	if (addr > HIGH_ADDR_MARK)
 		ksft_exit_fail_msg("Bad address %lx\n", addr);
-- 
2.30.2


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

* Re: [PATCH] selftests/mm: Fix validate_addr helper
  2025-06-20 11:11 [PATCH] selftests/mm: Fix validate_addr helper Dev Jain
@ 2025-06-20 12:08 ` Dev Jain
  2025-06-20 14:53 ` Donet Tom
  2025-06-23 10:42 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-06-20 12:08 UTC (permalink / raw)
  To: akpm, shuah
  Cc: linux-kselftest, linux-kernel, anshuman.khandual, ryan.roberts,
	lorenzo.stoakes, david, donettom


On 20/06/25 4:41 pm, Dev Jain wrote:
> validate_addr() function checks whether the address returned by mmap()
> lies in the low or high VA space, according to whether a high addr hint
> was passed or not. The fix commit mentioned below changed the code in
> such a way that this function will always return failure when passed
> high_addr == 1; addr will be >= HIGH_ADDR_MARK always, we will fall
> down to "if (addr < HIGH_ADDR_MARK)" and return failure. Fix this.

Correction: We will fall down to if (addr > HIGH_ADDR_MASK).

>
> Fixes: d1d86ce28d0f ("selftests/mm: virtual_address_range: conform to TAP format output")
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>   tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
> index b380e102b22f..169dbd692bf5 100644
> --- a/tools/testing/selftests/mm/virtual_address_range.c
> +++ b/tools/testing/selftests/mm/virtual_address_range.c
> @@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
>   {
>   	unsigned long addr = (unsigned long) ptr;
>   
> -	if (high_addr && addr < HIGH_ADDR_MARK)
> -		ksft_exit_fail_msg("Bad address %lx\n", addr);
> +	if (high_addr) {
> +		if (addr < HIGH_ADDR_MARK)
> +			ksft_exit_fail_msg("Bad address %lx\n", addr);
> +		return;
> +	}
>   
>   	if (addr > HIGH_ADDR_MARK)
>   		ksft_exit_fail_msg("Bad address %lx\n", addr);

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

* Re: [PATCH] selftests/mm: Fix validate_addr helper
  2025-06-20 11:11 [PATCH] selftests/mm: Fix validate_addr helper Dev Jain
  2025-06-20 12:08 ` Dev Jain
@ 2025-06-20 14:53 ` Donet Tom
  2025-06-23 10:42 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: Donet Tom @ 2025-06-20 14:53 UTC (permalink / raw)
  To: Dev Jain, akpm, shuah
  Cc: linux-kselftest, linux-kernel, anshuman.khandual, ryan.roberts,
	lorenzo.stoakes, david


On 6/20/25 4:41 PM, Dev Jain wrote:
> validate_addr() function checks whether the address returned by mmap()
> lies in the low or high VA space, according to whether a high addr hint
> was passed or not. The fix commit mentioned below changed the code in
> such a way that this function will always return failure when passed
> high_addr == 1; addr will be >= HIGH_ADDR_MARK always, we will fall
> down to "if (addr < HIGH_ADDR_MARK)" and return failure. Fix this.
>
> Fixes: d1d86ce28d0f ("selftests/mm: virtual_address_range: conform to TAP format output")
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>   tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
> index b380e102b22f..169dbd692bf5 100644
> --- a/tools/testing/selftests/mm/virtual_address_range.c
> +++ b/tools/testing/selftests/mm/virtual_address_range.c
> @@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
>   {
>   	unsigned long addr = (unsigned long) ptr;
>   
> -	if (high_addr && addr < HIGH_ADDR_MARK)
> -		ksft_exit_fail_msg("Bad address %lx\n", addr);
> +	if (high_addr) {
> +		if (addr < HIGH_ADDR_MARK)
> +			ksft_exit_fail_msg("Bad address %lx\n", addr);
> +		return;
> +	}
>   
>   	if (addr > HIGH_ADDR_MARK)
>   		ksft_exit_fail_msg("Bad address %lx\n", addr);


This looks good to me. Feel free to add

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


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

* Re: [PATCH] selftests/mm: Fix validate_addr helper
  2025-06-20 11:11 [PATCH] selftests/mm: Fix validate_addr helper Dev Jain
  2025-06-20 12:08 ` Dev Jain
  2025-06-20 14:53 ` Donet Tom
@ 2025-06-23 10:42 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2025-06-23 10:42 UTC (permalink / raw)
  To: Dev Jain, akpm, shuah
  Cc: linux-kselftest, linux-kernel, anshuman.khandual, ryan.roberts,
	lorenzo.stoakes, donettom

On 20.06.25 13:11, Dev Jain wrote:
> validate_addr() function checks whether the address returned by mmap()
> lies in the low or high VA space, according to whether a high addr hint
> was passed or not. The fix commit mentioned below changed the code in
> such a way that this function will always return failure when passed
> high_addr == 1; addr will be >= HIGH_ADDR_MARK always, we will fall
> down to "if (addr < HIGH_ADDR_MARK)" and return failure. Fix this.
> 
> Fixes: d1d86ce28d0f ("selftests/mm: virtual_address_range: conform to TAP format output")
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>   tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
> index b380e102b22f..169dbd692bf5 100644
> --- a/tools/testing/selftests/mm/virtual_address_range.c
> +++ b/tools/testing/selftests/mm/virtual_address_range.c
> @@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
>   {
>   	unsigned long addr = (unsigned long) ptr;
>   
> -	if (high_addr && addr < HIGH_ADDR_MARK)
> -		ksft_exit_fail_msg("Bad address %lx\n", addr);
> +	if (high_addr) {
> +		if (addr < HIGH_ADDR_MARK)
> +			ksft_exit_fail_msg("Bad address %lx\n", addr);
> +		return;
> +	}
>   
>   	if (addr > HIGH_ADDR_MARK)
>   		ksft_exit_fail_msg("Bad address %lx\n", addr);

LGTM, the logic corresponds to the way we would handle it pre d1d86ce28d0f

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb


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

end of thread, other threads:[~2025-06-23 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 11:11 [PATCH] selftests/mm: Fix validate_addr helper Dev Jain
2025-06-20 12:08 ` Dev Jain
2025-06-20 14:53 ` Donet Tom
2025-06-23 10:42 ` David Hildenbrand

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).