All of lore.kernel.org
 help / color / mirror / Atom feed
diff for duplicates of <87y3myzx7z.fsf@linux.vnet.ibm.com>

diff --git a/a/1.txt b/N1/1.txt
index 17914bc..e9a231f 100644
--- a/a/1.txt
+++ b/N1/1.txt
@@ -20,3 +20,227 @@ is converted in my selftest. I also want to do the boundary check twice.
 The hash trasnslation mode in POWER require us to track addr limit and
 we had bugs around address space slection before and after updating the
 addr limit.
+
+>From 7739eb02bb6b6602572a9c259e915ef23950aae1 Mon Sep 17 00:00:00 2001
+From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
+Date: Mon, 13 Nov 2017 10:41:10 +0530
+Subject: [PATCH] selftest/mm: Add test for checking mmap across 128TB boundary
+
+Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
+---
+ tools/testing/selftests/vm/Makefile         |   1 +
+ tools/testing/selftests/vm/run_vmtests      |  11 ++
+ tools/testing/selftests/vm/va_128TBswitch.c | 170 ++++++++++++++++++++++++++++
+ 3 files changed, 182 insertions(+)
+ create mode 100644 tools/testing/selftests/vm/va_128TBswitch.c
+
+diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile
+index cbb29e41ef2b..b1fb3cd7cf52 100644
+--- a/tools/testing/selftests/vm/Makefile
++++ b/tools/testing/selftests/vm/Makefile
+@@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress
+ TEST_GEN_FILES += userfaultfd
+ TEST_GEN_FILES += mlock-random-test
+ TEST_GEN_FILES += virtual_address_range
++TEST_GEN_FILES += va_128TBswitch
+ 
+ TEST_PROGS := run_vmtests
+ 
+diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests
+index 07548a1fa901..b367f7801b67 100755
+--- a/tools/testing/selftests/vm/run_vmtests
++++ b/tools/testing/selftests/vm/run_vmtests
+@@ -176,4 +176,15 @@ else
+ 	echo "[PASS]"
+ fi
+ 
++echo "-----------------------------"
++echo "running virtual address 128TB switch test" 
++echo "-----------------------------"
++./va_128TBswitch
++if [ $? -ne 0 ]; then
++	echo "[FAIL]"
++	exitcode=1
++else
++	echo "[PASS]"
++fi
++
+ exit $exitcode
+diff --git a/tools/testing/selftests/vm/va_128TBswitch.c b/tools/testing/selftests/vm/va_128TBswitch.c
+new file mode 100644
+index 000000000000..dfa501b825a8
+--- /dev/null
++++ b/tools/testing/selftests/vm/va_128TBswitch.c
+@@ -0,0 +1,170 @@
++/*
++ * Copyright IBM Corporation, 2017
++ * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
++ *
++ * This program is free software; you can redistribute it and/or modify it
++ * under the terms of version 2.1 of the GNU Lesser General Public License
++ * as published by the Free Software Foundation.
++ *
++ * This program is distributed in the hope that it would be useful, but
++ * WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
++ *
++ */
++
++#include <stdio.h>
++#include <stdlib.h>
++#include <sys/mman.h>
++
++#ifdef DEBUG
++#define pr_debug(fmt, ...)  printf(fmt, ##__VA_ARGS__)
++#else
++#define pr_debug(fmt, ...)
++#endif
++
++/*
++ * >= 128TB is the hint addr value we used to select
++ * large address space.
++ */
++#define ADDR_SWITCH_HINT (1UL << 47)
++
++#ifdef __powerpc64__
++#define MAP_SIZE  64*1024
++#else
++#define MAP_SIZE  4*1024
++#endif
++
++
++void report_failure(long in_addr, unsigned long flags)
++{
++	printf("Failed to map 0x%lx with flags 0x%lx\n", in_addr, flags);
++	exit(1);
++}
++
++int *__map_addr(long in_addr, int size, unsigned long flags, int unmap)
++{
++	int *addr;
++
++	addr = (int *)mmap((void *)in_addr, size, PROT_READ | PROT_WRITE,
++			   MAP_ANONYMOUS | MAP_PRIVATE | flags, -1, 0);
++	if (addr == MAP_FAILED)
++		report_failure(in_addr, flags);
++	pr_debug("Mapped addr 0x%lx-0x%lx for request 0x%lx with flag 0x%lx\n",
++		 (unsigned long)addr, ((unsigned long)addr + size), in_addr, flags);
++	/*
++	 * Try to access to catch errors in fault handling/slb miss handling
++	 */
++	*addr = 10;
++	if (unmap)
++		munmap(addr, size);
++	return addr;
++}
++
++int *map_addr(long in_addr, unsigned long flags, int unmap)
++{
++	return __map_addr(in_addr, MAP_SIZE, flags, unmap);
++}
++
++void boundary_check(void)
++{
++	int *a;
++
++	/*
++	 * If stack is moved, we could possibly allocate
++	 * this at the requested address.
++	 */
++	a = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 0, 1);
++	if ((unsigned long)a > ADDR_SWITCH_HINT - MAP_SIZE)
++		report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);
++
++	/*
++	 * We should never allocate at the requested address or above it
++	 * The len cross the 128TB boundary. Without MAP_FIXED
++	 * we will always search in the lower address space.
++	 */
++	a = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, 0, 1);
++	if ((unsigned long)a >= ADDR_SWITCH_HINT - MAP_SIZE)
++		report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);
++	/*
++	 * Exact mapping at 128TB, the area is free we should get that
++	 * even without MAP_FIXED. Don't unmap. We check fixed in the
++	 * same range later.
++	 */
++	a = map_addr(ADDR_SWITCH_HINT, 0, 0);
++	if ((unsigned long)a != ADDR_SWITCH_HINT)
++		report_failure(ADDR_SWITCH_HINT, 0);
++
++	a = map_addr(ADDR_SWITCH_HINT + MAP_SIZE, 0, 1);
++	if ((unsigned long)a < ADDR_SWITCH_HINT)
++		report_failure(ADDR_SWITCH_HINT, 0);
++
++#if 0
++	/*
++	 * Enable this with stack mapped MAP_SIZE below 128TB
++	 */
++	a = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), MAP_FIXED, 1);
++	if ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE)
++		report_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);
++	a = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, MAP_FIXED, 1);
++	if ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE)
++		report_failure(ADDR_SWITCH_HINT - MAP_SIZE, MAP_FIXED);
++
++#endif
++	a = map_addr(ADDR_SWITCH_HINT, MAP_FIXED, 1);
++	if ((unsigned long)a != ADDR_SWITCH_HINT)
++		report_failure(ADDR_SWITCH_HINT, MAP_FIXED);
++}
++
++static int supported_arch(void)
++{
++#if defined(__powerpc64__)
++	return 1;
++#elif defined(__x86_64__)
++	return 1;
++#else
++	return 0;
++#endif
++
++}
++
++int main(int argc, char *argv[])
++{
++	int *a;
++
++	if (!supported_arch())
++		return 0;
++	/*
++	 * check the 128TB boundary before we update addr_limit
++	 */
++	boundary_check();
++
++	a = map_addr(0, 0, 1);
++	if ((unsigned long)a > ADDR_SWITCH_HINT)
++		report_failure(0, 0);
++
++	a = map_addr(-1, 0, 1);
++	if ((unsigned long)a < ADDR_SWITCH_HINT)
++		report_failure(-1, 0);
++
++	/* don't unmap this one */
++	a = map_addr((1UL << 48), 0, 0);
++	if ((unsigned long)a != 1UL << 48)
++		report_failure((1UL << 48), 0);
++
++	a = map_addr((1UL << 48), 0, 1);
++	if ((unsigned long)a < ADDR_SWITCH_HINT)
++		report_failure((1UL << 48), 0);
++
++	a = map_addr(0, 0, 1);
++	if ((unsigned long)a > ADDR_SWITCH_HINT)
++		report_failure(0, 0);
++
++	a = map_addr(-1, 0, 1);
++	if ((unsigned long)a < ADDR_SWITCH_HINT)
++		report_failure(-1, 0);
++	/*
++	 * Try boundary conditions again after we allocated something above 128TB
++	 * and updated addr_limit.
++	 */
++	boundary_check();
++}
+-- 
+2.14.3
diff --git a/a/content_digest b/N1/content_digest
index 3253805..ecebafe 100644
--- a/a/content_digest
+++ b/N1/content_digest
@@ -12,7 +12,8 @@
   Andy Lutomirski <luto@amacapital.net>
   Nicholas Piggin <npiggin@gmail.com>
   linux-mm@kvack.org
- " linux-kernel@vger.kernel.org\0"
+  linux-kernel@vger.kernel.org
+ " Kirill A. Shutemov <kirill.shutemov@linux.intel.com>\0"
  "\00:1\0"
  "b\0"
  "\"Kirill A. Shutemov\" <kirill.shutemov@linux.intel.com> writes:\n"
@@ -36,6 +37,230 @@
  "is converted in my selftest. I also want to do the boundary check twice.\n"
  "The hash trasnslation mode in POWER require us to track addr limit and\n"
  "we had bugs around address space slection before and after updating the\n"
- addr limit.
+ "addr limit.\n"
+ "\n"
+ ">From 7739eb02bb6b6602572a9c259e915ef23950aae1 Mon Sep 17 00:00:00 2001\n"
+ "From: \"Aneesh Kumar K.V\" <aneesh.kumar@linux.vnet.ibm.com>\n"
+ "Date: Mon, 13 Nov 2017 10:41:10 +0530\n"
+ "Subject: [PATCH] selftest/mm: Add test for checking mmap across 128TB boundary\n"
+ "\n"
+ "Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>\n"
+ "---\n"
+ " tools/testing/selftests/vm/Makefile         |   1 +\n"
+ " tools/testing/selftests/vm/run_vmtests      |  11 ++\n"
+ " tools/testing/selftests/vm/va_128TBswitch.c | 170 ++++++++++++++++++++++++++++\n"
+ " 3 files changed, 182 insertions(+)\n"
+ " create mode 100644 tools/testing/selftests/vm/va_128TBswitch.c\n"
+ "\n"
+ "diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile\n"
+ "index cbb29e41ef2b..b1fb3cd7cf52 100644\n"
+ "--- a/tools/testing/selftests/vm/Makefile\n"
+ "+++ b/tools/testing/selftests/vm/Makefile\n"
+ "@@ -17,6 +17,7 @@ TEST_GEN_FILES += transhuge-stress\n"
+ " TEST_GEN_FILES += userfaultfd\n"
+ " TEST_GEN_FILES += mlock-random-test\n"
+ " TEST_GEN_FILES += virtual_address_range\n"
+ "+TEST_GEN_FILES += va_128TBswitch\n"
+ " \n"
+ " TEST_PROGS := run_vmtests\n"
+ " \n"
+ "diff --git a/tools/testing/selftests/vm/run_vmtests b/tools/testing/selftests/vm/run_vmtests\n"
+ "index 07548a1fa901..b367f7801b67 100755\n"
+ "--- a/tools/testing/selftests/vm/run_vmtests\n"
+ "+++ b/tools/testing/selftests/vm/run_vmtests\n"
+ "@@ -176,4 +176,15 @@ else\n"
+ " \techo \"[PASS]\"\n"
+ " fi\n"
+ " \n"
+ "+echo \"-----------------------------\"\n"
+ "+echo \"running virtual address 128TB switch test\" \n"
+ "+echo \"-----------------------------\"\n"
+ "+./va_128TBswitch\n"
+ "+if [ $? -ne 0 ]; then\n"
+ "+\techo \"[FAIL]\"\n"
+ "+\texitcode=1\n"
+ "+else\n"
+ "+\techo \"[PASS]\"\n"
+ "+fi\n"
+ "+\n"
+ " exit $exitcode\n"
+ "diff --git a/tools/testing/selftests/vm/va_128TBswitch.c b/tools/testing/selftests/vm/va_128TBswitch.c\n"
+ "new file mode 100644\n"
+ "index 000000000000..dfa501b825a8\n"
+ "--- /dev/null\n"
+ "+++ b/tools/testing/selftests/vm/va_128TBswitch.c\n"
+ "@@ -0,0 +1,170 @@\n"
+ "+/*\n"
+ "+ * Copyright IBM Corporation, 2017\n"
+ "+ * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>\n"
+ "+ *\n"
+ "+ * This program is free software; you can redistribute it and/or modify it\n"
+ "+ * under the terms of version 2.1 of the GNU Lesser General Public License\n"
+ "+ * as published by the Free Software Foundation.\n"
+ "+ *\n"
+ "+ * This program is distributed in the hope that it would be useful, but\n"
+ "+ * WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
+ "+ *\n"
+ "+ */\n"
+ "+\n"
+ "+#include <stdio.h>\n"
+ "+#include <stdlib.h>\n"
+ "+#include <sys/mman.h>\n"
+ "+\n"
+ "+#ifdef DEBUG\n"
+ "+#define pr_debug(fmt, ...)  printf(fmt, ##__VA_ARGS__)\n"
+ "+#else\n"
+ "+#define pr_debug(fmt, ...)\n"
+ "+#endif\n"
+ "+\n"
+ "+/*\n"
+ "+ * >= 128TB is the hint addr value we used to select\n"
+ "+ * large address space.\n"
+ "+ */\n"
+ "+#define ADDR_SWITCH_HINT (1UL << 47)\n"
+ "+\n"
+ "+#ifdef __powerpc64__\n"
+ "+#define MAP_SIZE  64*1024\n"
+ "+#else\n"
+ "+#define MAP_SIZE  4*1024\n"
+ "+#endif\n"
+ "+\n"
+ "+\n"
+ "+void report_failure(long in_addr, unsigned long flags)\n"
+ "+{\n"
+ "+\tprintf(\"Failed to map 0x%lx with flags 0x%lx\\n\", in_addr, flags);\n"
+ "+\texit(1);\n"
+ "+}\n"
+ "+\n"
+ "+int *__map_addr(long in_addr, int size, unsigned long flags, int unmap)\n"
+ "+{\n"
+ "+\tint *addr;\n"
+ "+\n"
+ "+\taddr = (int *)mmap((void *)in_addr, size, PROT_READ | PROT_WRITE,\n"
+ "+\t\t\t   MAP_ANONYMOUS | MAP_PRIVATE | flags, -1, 0);\n"
+ "+\tif (addr == MAP_FAILED)\n"
+ "+\t\treport_failure(in_addr, flags);\n"
+ "+\tpr_debug(\"Mapped addr 0x%lx-0x%lx for request 0x%lx with flag 0x%lx\\n\",\n"
+ "+\t\t (unsigned long)addr, ((unsigned long)addr + size), in_addr, flags);\n"
+ "+\t/*\n"
+ "+\t * Try to access to catch errors in fault handling/slb miss handling\n"
+ "+\t */\n"
+ "+\t*addr = 10;\n"
+ "+\tif (unmap)\n"
+ "+\t\tmunmap(addr, size);\n"
+ "+\treturn addr;\n"
+ "+}\n"
+ "+\n"
+ "+int *map_addr(long in_addr, unsigned long flags, int unmap)\n"
+ "+{\n"
+ "+\treturn __map_addr(in_addr, MAP_SIZE, flags, unmap);\n"
+ "+}\n"
+ "+\n"
+ "+void boundary_check(void)\n"
+ "+{\n"
+ "+\tint *a;\n"
+ "+\n"
+ "+\t/*\n"
+ "+\t * If stack is moved, we could possibly allocate\n"
+ "+\t * this at the requested address.\n"
+ "+\t */\n"
+ "+\ta = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 0, 1);\n"
+ "+\tif ((unsigned long)a > ADDR_SWITCH_HINT - MAP_SIZE)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);\n"
+ "+\n"
+ "+\t/*\n"
+ "+\t * We should never allocate at the requested address or above it\n"
+ "+\t * The len cross the 128TB boundary. Without MAP_FIXED\n"
+ "+\t * we will always search in the lower address space.\n"
+ "+\t */\n"
+ "+\ta = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, 0, 1);\n"
+ "+\tif ((unsigned long)a >= ADDR_SWITCH_HINT - MAP_SIZE)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);\n"
+ "+\t/*\n"
+ "+\t * Exact mapping at 128TB, the area is free we should get that\n"
+ "+\t * even without MAP_FIXED. Don't unmap. We check fixed in the\n"
+ "+\t * same range later.\n"
+ "+\t */\n"
+ "+\ta = map_addr(ADDR_SWITCH_HINT, 0, 0);\n"
+ "+\tif ((unsigned long)a != ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT, 0);\n"
+ "+\n"
+ "+\ta = map_addr(ADDR_SWITCH_HINT + MAP_SIZE, 0, 1);\n"
+ "+\tif ((unsigned long)a < ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT, 0);\n"
+ "+\n"
+ "+#if 0\n"
+ "+\t/*\n"
+ "+\t * Enable this with stack mapped MAP_SIZE below 128TB\n"
+ "+\t */\n"
+ "+\ta = map_addr((ADDR_SWITCH_HINT - MAP_SIZE), MAP_FIXED, 1);\n"
+ "+\tif ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT - MAP_SIZE, 0);\n"
+ "+\ta = __map_addr((ADDR_SWITCH_HINT - MAP_SIZE), 2*MAP_SIZE, MAP_FIXED, 1);\n"
+ "+\tif ((unsigned long)a != ADDR_SWITCH_HINT - MAP_SIZE)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT - MAP_SIZE, MAP_FIXED);\n"
+ "+\n"
+ "+#endif\n"
+ "+\ta = map_addr(ADDR_SWITCH_HINT, MAP_FIXED, 1);\n"
+ "+\tif ((unsigned long)a != ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(ADDR_SWITCH_HINT, MAP_FIXED);\n"
+ "+}\n"
+ "+\n"
+ "+static int supported_arch(void)\n"
+ "+{\n"
+ "+#if defined(__powerpc64__)\n"
+ "+\treturn 1;\n"
+ "+#elif defined(__x86_64__)\n"
+ "+\treturn 1;\n"
+ "+#else\n"
+ "+\treturn 0;\n"
+ "+#endif\n"
+ "+\n"
+ "+}\n"
+ "+\n"
+ "+int main(int argc, char *argv[])\n"
+ "+{\n"
+ "+\tint *a;\n"
+ "+\n"
+ "+\tif (!supported_arch())\n"
+ "+\t\treturn 0;\n"
+ "+\t/*\n"
+ "+\t * check the 128TB boundary before we update addr_limit\n"
+ "+\t */\n"
+ "+\tboundary_check();\n"
+ "+\n"
+ "+\ta = map_addr(0, 0, 1);\n"
+ "+\tif ((unsigned long)a > ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(0, 0);\n"
+ "+\n"
+ "+\ta = map_addr(-1, 0, 1);\n"
+ "+\tif ((unsigned long)a < ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(-1, 0);\n"
+ "+\n"
+ "+\t/* don't unmap this one */\n"
+ "+\ta = map_addr((1UL << 48), 0, 0);\n"
+ "+\tif ((unsigned long)a != 1UL << 48)\n"
+ "+\t\treport_failure((1UL << 48), 0);\n"
+ "+\n"
+ "+\ta = map_addr((1UL << 48), 0, 1);\n"
+ "+\tif ((unsigned long)a < ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure((1UL << 48), 0);\n"
+ "+\n"
+ "+\ta = map_addr(0, 0, 1);\n"
+ "+\tif ((unsigned long)a > ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(0, 0);\n"
+ "+\n"
+ "+\ta = map_addr(-1, 0, 1);\n"
+ "+\tif ((unsigned long)a < ADDR_SWITCH_HINT)\n"
+ "+\t\treport_failure(-1, 0);\n"
+ "+\t/*\n"
+ "+\t * Try boundary conditions again after we allocated something above 128TB\n"
+ "+\t * and updated addr_limit.\n"
+ "+\t */\n"
+ "+\tboundary_check();\n"
+ "+}\n"
+ "-- \n"
+ 2.14.3
 
-d8d3fbfc14a244fba29010d56db5023dafe9ef6ba07dcc311ff7140e72e77c92
+cce6fc18b84b841efee63375134f6e6be68be5c08b48fc675b0a9815ed56b434

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.