aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/powerpc/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h5
-rw-r--r--tools/testing/selftests/powerpc/mm/Makefile18
-rw-r--r--tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c72
4 files changed, 95 insertions, 2 deletions
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
index 316194f26ff4..b3dbe9ef1a40 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR
13 13
14export CC CFLAGS 14export CC CFLAGS
15 15
16TARGETS = pmu copyloops 16TARGETS = pmu copyloops mm
17 17
18endif 18endif
19 19
diff --git a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
index ccd9c84c4e3f..d1dc37425510 100644
--- a/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
+++ b/tools/testing/selftests/powerpc/copyloops/asm/ppc_asm.h
@@ -46,12 +46,15 @@
46#define R20 r20 46#define R20 r20
47#define R21 r21 47#define R21 r21
48#define R22 r22 48#define R22 r22
49#define R29 r29
50#define R30 r30
51#define R31 r31
49 52
50#define STACKFRAMESIZE 256 53#define STACKFRAMESIZE 256
51#define STK_PARAM(i) (48 + ((i)-3)*8)
52#define STK_REG(i) (112 + ((i)-14)*8) 54#define STK_REG(i) (112 + ((i)-14)*8)
53 55
54#define _GLOBAL(A) FUNC_START(test_ ## A) 56#define _GLOBAL(A) FUNC_START(test_ ## A)
57#define _GLOBAL_TOC(A) _GLOBAL(A)
55 58
56#define PPC_MTOCRF(A, B) mtocrf A, B 59#define PPC_MTOCRF(A, B) mtocrf A, B
57 60
diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
new file mode 100644
index 000000000000..357ccbd6bad9
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mm/Makefile
@@ -0,0 +1,18 @@
1noarg:
2 $(MAKE) -C ../
3
4PROGS := hugetlb_vs_thp_test
5
6all: $(PROGS)
7
8$(PROGS): ../harness.c
9
10run_tests: all
11 @-for PROG in $(PROGS); do \
12 ./$$PROG; \
13 done;
14
15clean:
16 rm -f $(PROGS)
17
18.PHONY: all run_tests clean
diff --git a/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
new file mode 100644
index 000000000000..3d8e5b033e1d
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mm/hugetlb_vs_thp_test.c
@@ -0,0 +1,72 @@
1#include <stdio.h>
2#include <sys/mman.h>
3#include <unistd.h>
4
5#include "utils.h"
6
7/* This must match the huge page & THP size */
8#define SIZE (16 * 1024 * 1024)
9
10static int test_body(void)
11{
12 void *addr;
13 char *p;
14
15 addr = (void *)0xa0000000;
16
17 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
18 MAP_HUGETLB | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
19 if (p != MAP_FAILED) {
20 /*
21 * Typically the mmap will fail because no huge pages are
22 * allocated on the system. But if there are huge pages
23 * allocated the mmap will succeed. That's fine too, we just
24 * munmap here before continuing.
25 */
26 munmap(addr, SIZE);
27 }
28
29 p = mmap(addr, SIZE, PROT_READ | PROT_WRITE,
30 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
31 if (p == MAP_FAILED) {
32 printf("Mapping failed @ %p\n", addr);
33 perror("mmap");
34 return 1;
35 }
36
37 /*
38 * Either a user or kernel access is sufficient to trigger the bug.
39 * A kernel access is easier to spot & debug, as it will trigger the
40 * softlockup or RCU stall detectors, and when the system is kicked
41 * into xmon we get a backtrace in the kernel.
42 *
43 * A good option is:
44 * getcwd(p, SIZE);
45 *
46 * For the purposes of this testcase it's preferable to spin in
47 * userspace, so the harness can kill us if we get stuck. That way we
48 * see a test failure rather than a dead system.
49 */
50 *p = 0xf;
51
52 munmap(addr, SIZE);
53
54 return 0;
55}
56
57static int test_main(void)
58{
59 int i;
60
61 /* 10,000 because it's a "bunch", and completes reasonably quickly */
62 for (i = 0; i < 10000; i++)
63 if (test_body())
64 return 1;
65
66 return 0;
67}
68
69int main(void)
70{
71 return test_harness(test_main, "hugetlb_vs_thp");
72}