Skip to contentSkip to conversation

selftests/vm: fix some tests on 32bit

PATCH Applied David Hildenbrand 1 participant 5 messages Dec 5, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover selftests/vm: fix some tests on 32bit

I finally had the time to run some of the selftests written by me (especially "cow") on x86 PAE. I found some unexpected "surprises" :)

With these changes, and with [1] on top of mm-unstable, the "cow" tests and the "ksm_functional_tests" compile and pass as expected (expected failures with hugetlb in the "cow" tests). "madv_populate" has one expected test failure -- x86 does not support softdirty tracking.

#1-#3 fix commits with stable commit ids. #4 fixes a test that is not in mm-stable yet.

A note that there are many other compile errors/warnings when compiling on 32bit and with older Linux headers ... something for another day.

[1] https://lkml.kernel.org/r/[email protected]

Cc Andrew Morton <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Yang Li <[email protected]>

David Hildenbrand (4):
mm/gup_test: fix PIN_LONGTERM_TEST_READ with highmem selftests/vm: madv_populate: fix missing MADV_POPULATE_(READ|WRITE)
definitions
selftests/vm: cow: fix compile warning on 32bit selftests/vm: ksm_functional_tests: fixes for 32bit

 mm/gup_test.c                                     | 10 +++++++---
 tools/testing/selftests/vm/cow.c                  |  4 ++--
 tools/testing/selftests/vm/ksm_functional_tests.c |  4 ++--
 tools/testing/selftests/vm/madv_populate.c        |  7 +++++++
 tools/testing/selftests/vm/vm_util.c              |  2 +-
 5 files changed, 19 insertions(+), 8 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/4 mm/gup_test: fix PIN_LONGTERM_TEST_READ with highmem

... we have to kmap()/kunmap(), otherwise this won't work as expected with highmem.

Fixes c77369b437f9 ("mm/gup_test: start/stop/read functionality for PIN LONGTERM test")
---
 mm/gup_test.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mm/gup_test.c +7 -3
index 0d76d9b4bb5a..33f431e0da60 100644
@@ -4,6 +4,7 @@
 #include <linux/uaccess.h>
 #include <linux/ktime.h>
 #include <linux/debugfs.h>
+#include <linux/highmem.h>
 #include "gup_test.h"
 
 static void put_back_pages(unsigned int cmd, struct page **pages,
@@ -297,10 +298,13 @@ static inline int pin_longterm_test_read(unsigned long arg)
 		return -EFAULT;
 
 	for (i = 0; i < pin_longterm_test_nr_pages; i++) {
-		void *addr = page_to_virt(pin_longterm_test_pages[i]);
+		void *addr = kmap_local_page(pin_longterm_test_pages[i]);
+		unsigned long ret;
 
-		if (copy_to_user((void __user *)(unsigned long)user_addr, addr,
-				 PAGE_SIZE))
+		ret = copy_to_user((void __user *)(unsigned long)user_addr, addr,
+				   PAGE_SIZE);
+		kunmap_local(addr);
+		if (ret)
 			return -EFAULT;
 		user_addr += PAGE_SIZE;
 	}
Signature · 1 line
2.38.1
#2 lore raw

PATCH 2/4 selftests/vm: madv_populate: fix missing MADV_POPULATE_(READ|WRITE) definitions

In reply to David Hildenbrand

The tests fail to compile in some environments (e.g., Debian 11.5 on x86). Let's simply conditionally define MADV_POPULATE_(READ|WRITE) if not already defined, similar to how the khugepaged.c test handles it.

Fixes 39b2e5cae43d ("selftests/vm: make MADV_POPULATE_(READ|WRITE) use in-tree headers")
---
 tools/testing/selftests/vm/madv_populate.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/vm/madv_populate.c +7 -0
index 60547245e479..262eae6b58f2 100644
@@ -20,6 +20,13 @@
 #include "../kselftest.h"
 #include "vm_util.h"
 
+#ifndef MADV_POPULATE_READ
+#define MADV_POPULATE_READ	22
+#endif /* MADV_POPULATE_READ */
+#ifndef MADV_POPULATE_WRITE
+#define MADV_POPULATE_WRITE	23
+#endif /* MADV_POPULATE_WRITE */
+
 /*
  * For now, we're using 2 MiB of private anonymous memory for all tests.
  */
Signature · 1 line
2.38.1
#3 lore raw

PATCH 3/4 selftests/vm: cow: fix compile warning on 32bit

In reply to David Hildenbrand

The compiler complains about the conversion of a pointer to an int of different width.

Fixes 6f1405efc61b ("selftests/vm: anon_cow: add R/O longterm tests via gup_test")
---
 tools/testing/selftests/vm/cow.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/vm/cow.c +2 -2
index 73e05b52c49e..26f6ea3079e2 100644
@@ -650,7 +650,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,
 	}
 
 	/* Take a R/O pin. This should trigger unsharing. */
-	args.addr = (__u64)mem;
+	args.addr = (__u64)(uintptr_t)mem;
 	args.size = size;
 	args.flags = fast ? PIN_LONGTERM_TEST_FLAG_USE_FAST : 0;
 	ret = ioctl(gup_fd, PIN_LONGTERM_TEST_START, &args);
@@ -669,7 +669,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum ro_pin_test test,
 	 * Read back the content via the pin to the temporary buffer and
 	 * test if we observed the modification.
 	 */
-	tmp_val = (__u64)tmp;
+	tmp_val = (__u64)(uintptr_t)tmp;
 	ret = ioctl(gup_fd, PIN_LONGTERM_TEST_READ, &tmp_val);
 	if (ret)
 		ksft_test_result_fail("PIN_LONGTERM_TEST_READ failed\n");
Signature · 1 line
2.38.1
#4 lore raw

PATCH 4/4 selftests/vm: ksm_functional_tests: fixes for 32bit

In reply to David Hildenbrand

The test currently fails on 32bit. Fixing the "-1ull" vs. "-1ul" seems to make the test pass and the compiler happy.

Note: This test is not in mm-stable yet. This fix should be squashed into
"selftests/vm: add KSM unmerge tests".

---
 tools/testing/selftests/vm/ksm_functional_tests.c | 4 ++--
 tools/testing/selftests/vm/vm_util.c              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/ksm_functional_tests.c +2 -2
index 96644be68962..b11b7e5115dc 100644
@@ -42,13 +42,13 @@ static bool range_maps_duplicates(char *addr, unsigned long size)
 	for (offs_a = 0; offs_a < size; offs_a += pagesize) {
 		pfn_a = pagemap_get_pfn(pagemap_fd, addr + offs_a);
 		/* Page not present or PFN not exposed by the kernel. */
-		if (pfn_a == -1ull || !pfn_a)
+		if (pfn_a == -1ul || !pfn_a)
 			continue;
 
 		for (offs_b = offs_a + pagesize; offs_b < size;
 		     offs_b += pagesize) {
 			pfn_b = pagemap_get_pfn(pagemap_fd, addr + offs_b);
-			if (pfn_b == -1ull || !pfn_b)
+			if (pfn_b == -1ul || !pfn_b)
 				continue;
 			if (pfn_a == pfn_b)
 				return true;
tools/testing/selftests/vm/vm_util.c +1 -1
index 710571902743..40e795624ff3 100644
@@ -50,7 +50,7 @@ unsigned long pagemap_get_pfn(int fd, char *start)
 	/* If present (63th bit), PFN is at bit 0 -- 54. */
 	if (entry & 0x8000000000000000ull)
 		return entry & 0x007fffffffffffffull;
-	return -1ull;
+	return -1ul;
 }
 
 void clear_softdirty(void)
Signature · 1 line
2.38.1