Skip to contentSkip to conversation

selftests/vm: Fix test for virtual address range mapping for arm64

PATCH Superseded Michal Suchanek 3 participants 4 messages May 9, 2017 – May 15, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/vm: Fix test for virtual address range mapping for arm64

Arm64 has 256TB address space so fix the test to pass on Arm as well.

Also remove unneeded numaif include.

---
 tools/testing/selftests/vm/virtual_address_range.c | 36 ++++++++++++++++------
 1 file changed, 27 insertions(+), 9 deletions(-)
tools/testing/selftests/vm/virtual_address_range.c +27 -9
index 3b02aa6..ff6628f 100644
@@ -10,7 +10,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <numaif.h>
 #include <sys/mman.h>
 #include <sys/time.h>
 
@@ -32,15 +31,34 @@
  * different areas one below 128TB and one above 128TB
  * till it reaches 512TB. One with size 128TB and the
  * other being 384TB.
+ *
+ * On Arm64 the address space is 256TB and no high mappings
+ * are supported so far. Presumably support can be added in
+ * the future.
  */
+
 #define NR_CHUNKS_128TB   8192UL /* Number of 16GB chunks for 128TB */
-#define NR_CHUNKS_384TB  24576UL /* Number of 16GB chunks for 384TB */
+#define NR_CHUNKS_256TB   (NR_CHUNKS_128TB * 2UL)
+#define NR_CHUNKS_384TB   (NR_CHUNKS_128TB * 3UL)
 
 #define ADDR_MARK_128TB  (1UL << 47) /* First address beyond 128TB */
+#define ADDR_MARK_256TB  (1UL << 48) /* First address beyond 256TB */
+
+#ifdef __aarch64__
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB
+#else
+#define HIGH_ADDR_MARK  ADDR_MARK_128TB
+#define HIGH_ADDR_SHIFT 48
+#define NR_CHUNKS_LOW   NR_CHUNKS_128TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_384TB
+#endif
 
 static char *hind_addr(void)
 {
-	int bits = 48 + rand() % 15;
+	int bits = HIGH_ADDR_SHIFT + rand() % 15;
 
 	return (char *) (1UL << bits);
 }
@@ -50,14 +68,14 @@ static int validate_addr(char *ptr, int high_addr)
 	unsigned long addr = (unsigned long) ptr;
 
 	if (high_addr) {
-		if (addr < ADDR_MARK_128TB) {
+		if (addr < HIGH_ADDR_MARK) {
 			printf("Bad address %lx\n", addr);
 			return 1;
 		}
 		return 0;
 	}
 
-	if (addr > ADDR_MARK_128TB) {
+	if (addr > HIGH_ADDR_MARK) {
 		printf("Bad address %lx\n", addr);
 		return 1;
 	}
@@ -79,12 +97,12 @@ static int validate_lower_address_hint(void)
 
 int main(int argc, char *argv[])
 {
-	char *ptr[NR_CHUNKS_128TB];
-	char *hptr[NR_CHUNKS_384TB];
+	char *ptr[NR_CHUNKS_LOW];
+	char *hptr[NR_CHUNKS_HIGH];
 	char *hint;
 	unsigned long i, lchunks, hchunks;
 
-	for (i = 0; i < NR_CHUNKS_128TB; i++) {
+	for (i = 0; i < NR_CHUNKS_LOW; i++) {
 		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
 					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
@@ -99,7 +117,7 @@ int main(int argc, char *argv[])
 	}
 	lchunks = i;
 
-	for (i = 0; i < NR_CHUNKS_384TB; i++) {
+	for (i = 0; i < NR_CHUNKS_HIGH; i++) {
 		hint = hind_addr();
 		hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
 					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Signature · 1 line
2.10.2
#1 lore raw
Quoted 5 lines · Michal Suchanek

Arm64 has 256TB address space so fix the test to pass on Arm as well.

Also remove unneeded numaif include.

Thanks for finding and fixing the problem. I will get this into 4.12-rc1 if possible or it will go into 4.12-rc2

-- Shuah

Quoted 96 lines
---
 tools/testing/selftests/vm/virtual_address_range.c | 36 ++++++++++++++++------
 1 file changed, 27 insertions(+), 9 deletions(-)
tools/testing/selftests/vm/virtual_address_range.c +27 -9
index 3b02aa6..ff6628f 100644
@@ -10,7 +10,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <numaif.h>
 #include <sys/mman.h>
 #include <sys/time.h>
 
@@ -32,15 +31,34 @@
  * different areas one below 128TB and one above 128TB
  * till it reaches 512TB. One with size 128TB and the
  * other being 384TB.
+ *
+ * On Arm64 the address space is 256TB and no high mappings
+ * are supported so far. Presumably support can be added in
+ * the future.
  */
+
 #define NR_CHUNKS_128TB   8192UL /* Number of 16GB chunks for 128TB */
-#define NR_CHUNKS_384TB  24576UL /* Number of 16GB chunks for 384TB */
+#define NR_CHUNKS_256TB   (NR_CHUNKS_128TB * 2UL)
+#define NR_CHUNKS_384TB   (NR_CHUNKS_128TB * 3UL)
 
 #define ADDR_MARK_128TB  (1UL << 47) /* First address beyond 128TB */
+#define ADDR_MARK_256TB  (1UL << 48) /* First address beyond 256TB */
+
+#ifdef __aarch64__
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB
+#else
+#define HIGH_ADDR_MARK  ADDR_MARK_128TB
+#define HIGH_ADDR_SHIFT 48
+#define NR_CHUNKS_LOW   NR_CHUNKS_128TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_384TB
+#endif
 
 static char *hind_addr(void)
 {
-	int bits = 48 + rand() % 15;
+	int bits = HIGH_ADDR_SHIFT + rand() % 15;
 
 	return (char *) (1UL << bits);
 }
@@ -50,14 +68,14 @@ static int validate_addr(char *ptr, int high_addr)
 	unsigned long addr = (unsigned long) ptr;
 
 	if (high_addr) {
-		if (addr < ADDR_MARK_128TB) {
+		if (addr < HIGH_ADDR_MARK) {
 			printf("Bad address %lx\n", addr);
 			return 1;
 		}
 		return 0;
 	}
 
-	if (addr > ADDR_MARK_128TB) {
+	if (addr > HIGH_ADDR_MARK) {
 		printf("Bad address %lx\n", addr);
 		return 1;
 	}
@@ -79,12 +97,12 @@ static int validate_lower_address_hint(void)
 
 int main(int argc, char *argv[])
 {
-	char *ptr[NR_CHUNKS_128TB];
-	char *hptr[NR_CHUNKS_384TB];
+	char *ptr[NR_CHUNKS_LOW];
+	char *hptr[NR_CHUNKS_HIGH];
 	char *hint;
 	unsigned long i, lchunks, hchunks;
 
-	for (i = 0; i < NR_CHUNKS_128TB; i++) {
+	for (i = 0; i < NR_CHUNKS_LOW; i++) {
 		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
 					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
@@ -99,7 +117,7 @@ int main(int argc, char *argv[])
 	}
 	lchunks = i;
 
-	for (i = 0; i < NR_CHUNKS_384TB; i++) {
+	for (i = 0; i < NR_CHUNKS_HIGH; i++) {
 		hint = hind_addr();
 		hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
 					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#2 lore raw
In reply to Michal Suchanek
Quoted 45 lines · Michal Suchanek

Arm64 has 256TB address space so fix the test to pass on Arm as well.

Also remove unneeded numaif include.

---
 tools/testing/selftests/vm/virtual_address_range.c | 36 ++++++++++++++++------
 1 file changed, 27 insertions(+), 9 deletions(-)
tools/testing/selftests/vm/virtual_address_range.c +15 -2
index 3b02aa6..ff6628f 100644
@@ -10,7 +10,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
-#include <numaif.h>
 #include <sys/mman.h>
 #include <sys/time.h>
 
@@ -32,15 +31,34 @@
  * different areas one below 128TB and one above 128TB
  * till it reaches 512TB. One with size 128TB and the
  * other being 384TB.
+ *
+ * On Arm64 the address space is 256TB and no high mappings
+ * are supported so far. Presumably support can be added in
+ * the future.
  */
+
 #define NR_CHUNKS_128TB   8192UL /* Number of 16GB chunks for 128TB */
-#define NR_CHUNKS_384TB  24576UL /* Number of 16GB chunks for 384TB */
+#define NR_CHUNKS_256TB   (NR_CHUNKS_128TB * 2UL)
+#define NR_CHUNKS_384TB   (NR_CHUNKS_128TB * 3UL)
 
 #define ADDR_MARK_128TB  (1UL << 47) /* First address beyond 128TB */
+#define ADDR_MARK_256TB  (1UL << 48) /* First address beyond 256TB */
+
+#ifdef __aarch64__
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB
+#else

tools/testing/selftests/vm/virtual_address_range.c line 61

Quoted 10 lines
tools/testing/selftests/vm/virtual_address_range.c +6 -1
+#define HIGH_ADDR_MARK  ADDR_MARK_128TB
+#define HIGH_ADDR_SHIFT 48
+#define NR_CHUNKS_LOW   NR_CHUNKS_128TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_384TB
+#endif
 
 static char *hind_addr(void)
 {
-	int bits = 48 + rand() % 15;
+	int bits = HIGH_ADDR_SHIFT + rand() % 15;

The randomization is upto 63 bits. Hence if HIGH_ADDR_SHIFT is 49 instead of 48 then it should be rand() % 14 in that case.

Quoted 37 lines
tools/testing/selftests/vm/virtual_address_range.c +5 -5
 	return (char *) (1UL << bits);
 }
@@ -50,14 +68,14 @@ static int validate_addr(char *ptr, int high_addr)
 	unsigned long addr = (unsigned long) ptr;
 
 	if (high_addr) {
-		if (addr < ADDR_MARK_128TB) {
+		if (addr < HIGH_ADDR_MARK) {
 			printf("Bad address %lx\n", addr);
 			return 1;
 		}
 		return 0;
 	}
 
-	if (addr > ADDR_MARK_128TB) {
+	if (addr > HIGH_ADDR_MARK) {
 		printf("Bad address %lx\n", addr);
 		return 1;
 	}
@@ -79,12 +97,12 @@ static int validate_lower_address_hint(void)
 
 int main(int argc, char *argv[])
 {
-	char *ptr[NR_CHUNKS_128TB];
-	char *hptr[NR_CHUNKS_384TB];
+	char *ptr[NR_CHUNKS_LOW];
+	char *hptr[NR_CHUNKS_HIGH];
 	char *hint;
 	unsigned long i, lchunks, hchunks;
 
-	for (i = 0; i < NR_CHUNKS_128TB; i++) {
+	for (i = 0; i < NR_CHUNKS_LOW; i++) {
 		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
 					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 

tools/testing/selftests/vm/virtual_address_range.c int main(int argc, char *argv[]) · line 120

Quoted 5 lines
tools/testing/selftests/vm/virtual_address_range.c +1 -1
@@ -99,7 +117,7 @@ int main(int argc, char *argv[])
 	}
 	lchunks = i;
 
-	for (i = 0; i < NR_CHUNKS_384TB; i++) {
+	for (i = 0; i < NR_CHUNKS_HIGH; i++) {

If ARM64 does not have address space beyond 256TB, all map requests beyond 256TB (which is being attempted in this second for loop) will fail. But does the arch support the hint based mechanism like powerpc and x86 to allocate beyond certain point ? The split in the allocation (represented by two for loops) is because of the fact that below HIGH_ADDR_MARK hint is not required and its required above it till the end of the total VA space. In this case,

tools/testing/selftests/vm/virtual_address_range.c line 51

Quoted 4 lines
tools/testing/selftests/vm/virtual_address_range.c +4 -0
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB

both the for loops will be attempting below 256TB one with and one without the hint mechanism. But all the validations will fail for the second for loop (where hint will be passed beyond 256TB) as the address will not be allocated beyond 256TB where it is capped.

#3 lore raw
Quoted 54 lines · On Mon, 15 May 2017 09:31:49 +0530 Anshuman Khandual…
Quoted 53 lines · Michal Suchanek

Arm64 has 256TB address space so fix the test to pass on Arm as well.

Also remove unneeded numaif include.

---
 tools/testing/selftests/vm/virtual_address_range.c | 36

++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-)

(quoted diff) +0 -0

b/tools/testing/selftests/vm/virtual_address_range.c index 3b02aa6..ff6628f 100644 --- a/tools/testing/selftests/vm/virtual_address_range.c +++ b/tools/testing/selftests/vm/virtual_address_range.c @@ -10,7 +10,6 @@ #include <string.h>
#include <unistd.h>
#include <errno.h>

tools/testing/selftests/vm/virtual_address_range.c +5 -1
-#include <numaif.h>
 #include <sys/mman.h>
 #include <sys/time.h>
@@ -32,15 +31,34 @@
  * different areas one below 128TB and one above 128TB
  * till it reaches 512TB. One with size 128TB and the
  * other being 384TB.
+ *
+ * On Arm64 the address space is 256TB and no high mappings
+ * are supported so far. Presumably support can be added in
+ * the future.
  */
+
 #define NR_CHUNKS_128TB   8192UL /* Number of 16GB chunks for

128TB */ -#define NR_CHUNKS_384TB 24576UL /* Number of 16GB chunks
for 384TB */ +#define NR_CHUNKS_256TB (NR_CHUNKS_128TB * 2UL)
+#define NR_CHUNKS_384TB (NR_CHUNKS_128TB * 3UL)

#define ADDR_MARK_128TB (1UL << 47) /* First address beyond 128TB
*/ +#define ADDR_MARK_256TB (1UL << 48) /* First address beyond 256TB */ +

tools/testing/selftests/vm/virtual_address_range.c +11 -0
+#ifdef __aarch64__
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB
+#else
+#define HIGH_ADDR_MARK  ADDR_MARK_128TB
+#define HIGH_ADDR_SHIFT 48
+#define NR_CHUNKS_LOW   NR_CHUNKS_128TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_384TB
+#endif
Quoted 7 lines

tools/testing/selftests/vm/virtual_address_range.c line 61

Quoted 4 lines

static char *hind_addr(void)
{

tools/testing/selftests/vm/virtual_address_range.c +1 -1
-	int bits = 48 + rand() % 15;
+	int bits = HIGH_ADDR_SHIFT + rand() % 15;  

The randomization is upto 63 bits. Hence if HIGH_ADDR_SHIFT is 49 instead of 48 then it should be rand() % 14 in that case.

I was wondering if this needs fixing but did not come up with any way how this magic number is related to number of bits in the address. Thanks for pointing it out.

Quoted 41 lines
Quoted 41 lines
tools/testing/selftests/vm/virtual_address_range.c +5 -5
 	return (char *) (1UL << bits);
 }
@@ -50,14 +68,14 @@ static int validate_addr(char *ptr, int
 high_addr) unsigned long addr = (unsigned long) ptr;
 
 	if (high_addr) {
-		if (addr < ADDR_MARK_128TB) {
+		if (addr < HIGH_ADDR_MARK) {
 			printf("Bad address %lx\n", addr);
 			return 1;
 		}
 		return 0;
 	}
 
-	if (addr > ADDR_MARK_128TB) {
+	if (addr > HIGH_ADDR_MARK) {
 		printf("Bad address %lx\n", addr);
 		return 1;
 	}
@@ -79,12 +97,12 @@ static int validate_lower_address_hint(void)
 
 int main(int argc, char *argv[])
 {
-	char *ptr[NR_CHUNKS_128TB];
-	char *hptr[NR_CHUNKS_384TB];
+	char *ptr[NR_CHUNKS_LOW];
+	char *hptr[NR_CHUNKS_HIGH];
 	char *hint;
 	unsigned long i, lchunks, hchunks;
 
-	for (i = 0; i < NR_CHUNKS_128TB; i++) {
+	for (i = 0; i < NR_CHUNKS_LOW; i++) {
 		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ |
 PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
@@ -99,7 +117,7 @@ int main(int argc, char *argv[])
 	}
 	lchunks = i;
 
Quoted 6 lines

tools/testing/selftests/vm/virtual_address_range.c int main(int argc, char *argv[]) · line 120

Quoted 2 lines
tools/testing/selftests/vm/virtual_address_range.c +1 -1
-	for (i = 0; i < NR_CHUNKS_384TB; i++) {
+	for (i = 0; i < NR_CHUNKS_HIGH; i++) {  

If ARM64 does not have address space beyond 256TB, all map requests beyond 256TB (which is being attempted in this second for loop) will fail.

Same as the second loop does on x86_64 with l5 paging not (fully) implemented, yes.

Quoted 2 lines

But does the arch support the hint based mechanism like powerpc and x86 to allocate beyond certain point ?

It does not.

Quoted 5 lines

The split in the alocation
(represented by two for loops) is because of the fact that below HIGH_ADDR_MARK hint is not required and its required above it till the end of the total VA space. In this case,

Quoted 11 lines

tools/testing/selftests/vm/virtual_address_range.c line 51

Quoted 4 lines
tools/testing/selftests/vm/virtual_address_range.c +4 -0
+#define HIGH_ADDR_MARK  ADDR_MARK_256TB
+#define HIGH_ADDR_SHIFT 49
+#define NR_CHUNKS_LOW   NR_CHUNKS_256TB
+#define NR_CHUNKS_HIGH  NR_CHUNKS_256TB  

both the for loops will be attempting below 256TB one with and one without the hint mechanism. But all the validations will fail for the second for loop (where hint will be passed beyond 256TB) as the address will not be allocated beyond 256TB where it is capped.

AFAICT the allocation fails completely in the second loop on archs that don't implement the 'highmem' or what you want to call it which currently includes x86_64 making the test pass. So in this patch I move the 'highmem' to range where nothing is allowed on arm64 and extending the 'lowmem' to the actual allowed range so the test passes there as well. The second loop is superfluous but harmless and overall this gives a variable split test in case the split lands on different address on some arch in the future.

Thanks

Michal