Skip to contentSkip to conversation

selftests/mm: Fix validate_addr helper

PATCH Applied Dev Jain 3 participants 4 messages Jun 20, 2025 – Jun 23, 2025

Subsystems (2)
lore
Share & tools
lore

Dev Jain

author
#0 lore raw

PATCH 1/1 selftests/mm: Fix validate_addr helper

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")
---
 tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/virtual_address_range.c +5 -2
index b380e102b22f..169dbd692bf5 100644
@@ -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);
Signature · 1 line
2.30.2
author
#1 lore raw
Quoted 6 lines · 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.

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

Quoted 25 lines
Fixes d1d86ce28d0f ("selftests/mm: virtual_address_range: conform to TAP format output")
---
  tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/virtual_address_range.c +5 -2
index b380e102b22f..169dbd692bf5 100644
@@ -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);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Dev Jain
Quoted 21 lines · 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")
---
  tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/virtual_address_range.c +0 -0
index b380e102b22f..169dbd692bf5 100644
@@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
  {
  	unsigned long addr = (unsigned long) ptr;
 

tools/testing/selftests/mm/virtual_address_range.c static void validate_addr(char *ptr, int high_addr) · line 87

Quoted 10 lines
tools/testing/selftests/mm/virtual_address_range.c +5 -2
-	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

Acked-by on v1 1/1
#3 lore raw
In reply to Dev Jain
Quoted 21 lines · 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")
---
  tools/testing/selftests/mm/virtual_address_range.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/virtual_address_range.c +0 -0
index b380e102b22f..169dbd692bf5 100644
@@ -77,8 +77,11 @@ static void validate_addr(char *ptr, int high_addr)
  {
  	unsigned long addr = (unsigned long) ptr;
 

tools/testing/selftests/mm/virtual_address_range.c static void validate_addr(char *ptr, int high_addr) · line 87

Quoted 10 lines
tools/testing/selftests/mm/virtual_address_range.c +5 -2
-	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

Signature · 3 lines
Cheers,

David / dhildenb