All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures
@ 2015-08-07 13:44 ` Thierry Reding
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2015-08-07 13:44 UTC (permalink / raw)
  To: Shuah Khan, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli, linux-api, linux-kernel

From: Thierry Reding <treding@nvidia.com>

According to Documentation/vm/pagemap.txt, the /proc/pid/pagemap file
contains one 64-bit value for each virtual page. The test code relies
on the size of unsigned long being 64-bit, which breaks the test when
run on 32-bit architectures. Use a uint64_t to store values read from
the file instead, so that it works irrespective of the architecture's
word size.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tools/testing/selftests/vm/mlock2-tests.c | 33 +++++++++++++------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/vm/mlock2-tests.c b/tools/testing/selftests/vm/mlock2-tests.c
index c49122bebf3c..11c38e96f336 100644
--- a/tools/testing/selftests/vm/mlock2-tests.c
+++ b/tools/testing/selftests/vm/mlock2-tests.c
@@ -1,4 +1,5 @@
 #include <sys/mman.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -82,10 +83,10 @@ out:
 	return ret;
 }
 
-static unsigned long get_pageflags(unsigned long addr)
+static uint64_t get_pageflags(unsigned long addr)
 {
 	FILE *file;
-	unsigned long pfn;
+	uint64_t pfn;
 	unsigned long offset;
 
 	file = fopen("/proc/self/pagemap", "r");
@@ -94,13 +95,14 @@ static unsigned long get_pageflags(unsigned long addr)
 		_exit(1);
 	}
 
-	offset = addr / getpagesize() * sizeof(unsigned long);
+	offset = addr / getpagesize() * sizeof(pfn);
+
 	if (fseek(file, offset, SEEK_SET)) {
 		perror("fseek pagemap");
 		_exit(1);
 	}
 
-	if (fread(&pfn, sizeof(unsigned long), 1, file) != 1) {
+	if (fread(&pfn, sizeof(pfn), 1, file) != 1) {
 		perror("fread pagemap");
 		_exit(1);
 	}
@@ -111,7 +113,7 @@ static unsigned long get_pageflags(unsigned long addr)
 
 static unsigned long get_kpageflags(unsigned long pfn)
 {
-	unsigned long flags;
+	uint64_t flags;
 	FILE *file;
 
 	file = fopen("/proc/kpageflags", "r");
@@ -120,12 +122,12 @@ static unsigned long get_kpageflags(unsigned long pfn)
 		_exit(1);
 	}
 
-	if (fseek(file, pfn * sizeof(unsigned long), SEEK_SET)) {
+	if (fseek(file, pfn * sizeof(flags), SEEK_SET)) {
 		perror("fseek kpageflags");
 		_exit(1);
 	}
 
-	if (fread(&flags, sizeof(unsigned long), 1, file) != 1) {
+	if (fread(&flags, sizeof(flags), 1, file) != 1) {
 		perror("fread kpageflags");
 		_exit(1);
 	}
@@ -211,9 +213,8 @@ out:
 
 static int lock_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -246,9 +247,8 @@ static int lock_check(char *map)
 
 static int unlock_lock_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -310,9 +310,8 @@ out:
 
 static int onfault_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -355,9 +354,8 @@ static int onfault_check(char *map)
 
 static int unlock_onfault_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page1_flags = get_kpageflags(page1_flags & PFN_MASK);
@@ -422,9 +420,8 @@ static int test_lock_onfault_of_present()
 {
 	char *map;
 	int ret = 1;
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
 		   MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
@@ -471,8 +468,6 @@ static int test_munlockall()
 {
 	char *map;
 	int ret = 1;
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
 
 	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
-- 
2.4.5


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

* [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures
@ 2015-08-07 13:44 ` Thierry Reding
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2015-08-07 13:44 UTC (permalink / raw)
  To: Shuah Khan, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli,
	linux-api-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

According to Documentation/vm/pagemap.txt, the /proc/pid/pagemap file
contains one 64-bit value for each virtual page. The test code relies
on the size of unsigned long being 64-bit, which breaks the test when
run on 32-bit architectures. Use a uint64_t to store values read from
the file instead, so that it works irrespective of the architecture's
word size.

Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 tools/testing/selftests/vm/mlock2-tests.c | 33 +++++++++++++------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/vm/mlock2-tests.c b/tools/testing/selftests/vm/mlock2-tests.c
index c49122bebf3c..11c38e96f336 100644
--- a/tools/testing/selftests/vm/mlock2-tests.c
+++ b/tools/testing/selftests/vm/mlock2-tests.c
@@ -1,4 +1,5 @@
 #include <sys/mman.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -82,10 +83,10 @@ out:
 	return ret;
 }
 
-static unsigned long get_pageflags(unsigned long addr)
+static uint64_t get_pageflags(unsigned long addr)
 {
 	FILE *file;
-	unsigned long pfn;
+	uint64_t pfn;
 	unsigned long offset;
 
 	file = fopen("/proc/self/pagemap", "r");
@@ -94,13 +95,14 @@ static unsigned long get_pageflags(unsigned long addr)
 		_exit(1);
 	}
 
-	offset = addr / getpagesize() * sizeof(unsigned long);
+	offset = addr / getpagesize() * sizeof(pfn);
+
 	if (fseek(file, offset, SEEK_SET)) {
 		perror("fseek pagemap");
 		_exit(1);
 	}
 
-	if (fread(&pfn, sizeof(unsigned long), 1, file) != 1) {
+	if (fread(&pfn, sizeof(pfn), 1, file) != 1) {
 		perror("fread pagemap");
 		_exit(1);
 	}
@@ -111,7 +113,7 @@ static unsigned long get_pageflags(unsigned long addr)
 
 static unsigned long get_kpageflags(unsigned long pfn)
 {
-	unsigned long flags;
+	uint64_t flags;
 	FILE *file;
 
 	file = fopen("/proc/kpageflags", "r");
@@ -120,12 +122,12 @@ static unsigned long get_kpageflags(unsigned long pfn)
 		_exit(1);
 	}
 
-	if (fseek(file, pfn * sizeof(unsigned long), SEEK_SET)) {
+	if (fseek(file, pfn * sizeof(flags), SEEK_SET)) {
 		perror("fseek kpageflags");
 		_exit(1);
 	}
 
-	if (fread(&flags, sizeof(unsigned long), 1, file) != 1) {
+	if (fread(&flags, sizeof(flags), 1, file) != 1) {
 		perror("fread kpageflags");
 		_exit(1);
 	}
@@ -211,9 +213,8 @@ out:
 
 static int lock_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -246,9 +247,8 @@ static int lock_check(char *map)
 
 static int unlock_lock_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -310,9 +310,8 @@ out:
 
 static int onfault_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page2_flags = get_pageflags((unsigned long)map + page_size);
@@ -355,9 +354,8 @@ static int onfault_check(char *map)
 
 static int unlock_onfault_check(char *map)
 {
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags;
 
 	page1_flags = get_pageflags((unsigned long)map);
 	page1_flags = get_kpageflags(page1_flags & PFN_MASK);
@@ -422,9 +420,8 @@ static int test_lock_onfault_of_present()
 {
 	char *map;
 	int ret = 1;
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
+	uint64_t page1_flags, page2_flags;
 
 	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
 		   MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
@@ -471,8 +468,6 @@ static int test_munlockall()
 {
 	char *map;
 	int ret = 1;
-	unsigned long page1_flags;
-	unsigned long page2_flags;
 	unsigned long page_size = getpagesize();
 
 	map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE,
-- 
2.4.5

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

* [PATCH 2/4] selftests: vm: Ensure the mlock2 syscall number can be found
  2015-08-07 13:44 ` Thierry Reding
  (?)
@ 2015-08-07 13:44 ` Thierry Reding
  -1 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2015-08-07 13:44 UTC (permalink / raw)
  To: Shuah Khan, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli, linux-api, linux-kernel

From: Thierry Reding <treding@nvidia.com>

Include the syscall.h header to ensure that the mlock2 syscall number is
available. Otherwise the test program will always return ENOSYS from the
mlock2() implementation.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tools/testing/selftests/vm/mlock2-tests.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/vm/mlock2-tests.c b/tools/testing/selftests/vm/mlock2-tests.c
index 11c38e96f336..2949fd949973 100644
--- a/tools/testing/selftests/vm/mlock2-tests.c
+++ b/tools/testing/selftests/vm/mlock2-tests.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <syscall.h>
 #include <errno.h>
 #include <stdbool.h>
 
-- 
2.4.5


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

* [PATCH 3/4] selftests: vm: Use the right arguments for main()
  2015-08-07 13:44 ` Thierry Reding
  (?)
  (?)
@ 2015-08-07 13:44 ` Thierry Reding
  -1 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2015-08-07 13:44 UTC (permalink / raw)
  To: Shuah Khan, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli, linux-api, linux-kernel

From: Thierry Reding <treding@nvidia.com>

The prototype for the main() function is:

	int main(int argc, char **argv);

but the mlock2-tests test program lists the arguments in the wrong
order. It gets away with this because the arguments are never used. Fix
it nevertheless to keep recent versions of GCC from complaining.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tools/testing/selftests/vm/mlock2-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vm/mlock2-tests.c b/tools/testing/selftests/vm/mlock2-tests.c
index 2949fd949973..af4bc752797d 100644
--- a/tools/testing/selftests/vm/mlock2-tests.c
+++ b/tools/testing/selftests/vm/mlock2-tests.c
@@ -643,7 +643,7 @@ static int test_mlockall(int (test_function)(bool call_mlock))
 	return ret;
 }
 
-int main(char **argv, int argc)
+int main(int argc, char **argv)
 {
 	int ret = 0;
 	ret += test_mlock_lock();
-- 
2.4.5


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

* [PATCH 4/4] selftests: vm: Pick up sanitized kernel headers
  2015-08-07 13:44 ` Thierry Reding
                   ` (2 preceding siblings ...)
  (?)
@ 2015-08-07 13:44 ` Thierry Reding
  -1 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2015-08-07 13:44 UTC (permalink / raw)
  To: Shuah Khan, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli, linux-api, linux-kernel

From: Thierry Reding <treding@nvidia.com>

Add the usr/include subdirectory of the top-level tree to the include
path, and make sure to include headers without relative paths to make
sure the sanitized headers get picked up. Otherwise the compiler will
not be able to find the linux/compiler.h header included by the non-
sanitized include/uapi/linux/userfaultfd.h.

While at it, make sure to only hardcode the syscall numbers on x86 and
PowerPC if they haven't been properly picked up from the headers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tools/testing/selftests/vm/Makefile      | 2 +-
 tools/testing/selftests/vm/userfaultfd.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
index bb888c651bf2..1dacac81bb68 100644
--- a/tools/testing/selftests/vm/Makefile
+++ b/tools/testing/selftests/vm/Makefile
@@ -1,6 +1,6 @@
 # Makefile for vm selftests
 
-CFLAGS = -Wall
+CFLAGS = -Wall -I ../../../../usr/include $(EXTRA_CFLAGS)
 BINARIES = compaction_test
 BINARIES += hugepage-mmap
 BINARIES += hugepage-shm
diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c
index 76071b14cb93..2bf1fc3f562b 100644
--- a/tools/testing/selftests/vm/userfaultfd.c
+++ b/tools/testing/selftests/vm/userfaultfd.c
@@ -64,8 +64,9 @@
 #include <sys/syscall.h>
 #include <sys/ioctl.h>
 #include <pthread.h>
-#include "../../../../include/uapi/linux/userfaultfd.h"
+#include <linux/userfaultfd.h>
 
+#ifndef __NR_userfaultfd
 #ifdef __x86_64__
 #define __NR_userfaultfd 323
 #elif defined(__i386__)
@@ -75,6 +76,7 @@
 #else
 #error "missing __NR_userfaultfd definition"
 #endif
+#endif
 
 static unsigned long nr_cpus, nr_pages, nr_pages_per_cpu, page_size;
 
-- 
2.4.5


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

* Re: [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures
@ 2015-08-10 19:27   ` Shuah Khan
  0 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2015-08-10 19:27 UTC (permalink / raw)
  To: Thierry Reding, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli, linux-api, linux-kernel, Shuah Khan

On 08/07/2015 07:44 AM, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> According to Documentation/vm/pagemap.txt, the /proc/pid/pagemap file
> contains one 64-bit value for each virtual page. The test code relies
> on the size of unsigned long being 64-bit, which breaks the test when
> run on 32-bit architectures. Use a uint64_t to store values read from
> the file instead, so that it works irrespective of the architecture's
> word size.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---

Looks good to me. Andrew! Would you like me to take this patch
and the other two in this series through kselftest git?

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

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

* Re: [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures
@ 2015-08-10 19:27   ` Shuah Khan
  0 siblings, 0 replies; 7+ messages in thread
From: Shuah Khan @ 2015-08-10 19:27 UTC (permalink / raw)
  To: Thierry Reding, Andrew Morton
  Cc: Eric B Munson, Andrea Arcangeli,
	linux-api-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Shuah Khan

On 08/07/2015 07:44 AM, Thierry Reding wrote:
> From: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> 
> According to Documentation/vm/pagemap.txt, the /proc/pid/pagemap file
> contains one 64-bit value for each virtual page. The test code relies
> on the size of unsigned long being 64-bit, which breaks the test when
> run on 32-bit architectures. Use a uint64_t to store values read from
> the file instead, so that it works irrespective of the architecture's
> word size.
> 
> Signed-off-by: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---

Looks good to me. Andrew! Would you like me to take this patch
and the other two in this series through kselftest git?

thanks,
-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org | (970) 217-8978

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

end of thread, other threads:[~2015-08-10 19:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-07 13:44 [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures Thierry Reding
2015-08-07 13:44 ` Thierry Reding
2015-08-07 13:44 ` [PATCH 2/4] selftests: vm: Ensure the mlock2 syscall number can be found Thierry Reding
2015-08-07 13:44 ` [PATCH 3/4] selftests: vm: Use the right arguments for main() Thierry Reding
2015-08-07 13:44 ` [PATCH 4/4] selftests: vm: Pick up sanitized kernel headers Thierry Reding
2015-08-10 19:27 ` [PATCH 1/4] selftests: vm: Fix mlock2-tests for 32-bit architectures Shuah Khan
2015-08-10 19:27   ` Shuah Khan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.