aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2016-07-11 01:25:18 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-07-14 06:26:25 -0400
commit24af8c5a52a70bbfd275f59836feadd9b9ebc83b (patch)
tree1a53bee7a96f8e15f542bc6f69ab6c0ebdb298ae
parente0ddf7a24558b356d5cf5ecc12cb4e305c800953 (diff)
selftests/powerpc: Add a test for PROT_SAO
PROT_SAO is a powerpc-specific flag to mmap(), and we rely on arch specific logic to allow it to be passed to mmap(). Add a small test to ensure mmap() accepts PROT_SAO. We don't have a good way to test that it actually causes the mapping to be created with the right flags, so for now we just touch the mapping so it's faulted in. In future we might be able to do something better. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--tools/testing/selftests/powerpc/mm/.gitignore1
-rw-r--r--tools/testing/selftests/powerpc/mm/Makefile4
-rw-r--r--tools/testing/selftests/powerpc/mm/prot_sao.c42
-rw-r--r--tools/testing/selftests/powerpc/utils.h5
4 files changed, 51 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/mm/.gitignore b/tools/testing/selftests/powerpc/mm/.gitignore
index b43ade0ec861..e715a3f2fbf4 100644
--- a/tools/testing/selftests/powerpc/mm/.gitignore
+++ b/tools/testing/selftests/powerpc/mm/.gitignore
@@ -1,3 +1,4 @@
1hugetlb_vs_thp_test 1hugetlb_vs_thp_test
2subpage_prot 2subpage_prot
3tempfile 3tempfile
4prot_sao \ No newline at end of file
diff --git a/tools/testing/selftests/powerpc/mm/Makefile b/tools/testing/selftests/powerpc/mm/Makefile
index ee179e22308c..3bdb96eae558 100644
--- a/tools/testing/selftests/powerpc/mm/Makefile
+++ b/tools/testing/selftests/powerpc/mm/Makefile
@@ -1,13 +1,15 @@
1noarg: 1noarg:
2 $(MAKE) -C ../ 2 $(MAKE) -C ../
3 3
4TEST_PROGS := hugetlb_vs_thp_test subpage_prot 4TEST_PROGS := hugetlb_vs_thp_test subpage_prot prot_sao
5TEST_FILES := tempfile 5TEST_FILES := tempfile
6 6
7all: $(TEST_PROGS) $(TEST_FILES) 7all: $(TEST_PROGS) $(TEST_FILES)
8 8
9$(TEST_PROGS): ../harness.c 9$(TEST_PROGS): ../harness.c
10 10
11prot_sao: ../utils.c
12
11include ../../lib.mk 13include ../../lib.mk
12 14
13tempfile: 15tempfile:
diff --git a/tools/testing/selftests/powerpc/mm/prot_sao.c b/tools/testing/selftests/powerpc/mm/prot_sao.c
new file mode 100644
index 000000000000..611530d43fa9
--- /dev/null
+++ b/tools/testing/selftests/powerpc/mm/prot_sao.c
@@ -0,0 +1,42 @@
1/*
2 * Copyright 2016, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <sys/mman.h>
10
11#include <asm/cputable.h>
12
13#include "utils.h"
14
15#define SIZE (64 * 1024)
16
17int test_prot_sao(void)
18{
19 char *p;
20
21 /* 2.06 or later should support SAO */
22 SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06));
23
24 /*
25 * Ensure we can ask for PROT_SAO.
26 * We can't really verify that it does the right thing, but at least we
27 * confirm the kernel will accept it.
28 */
29 p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE | PROT_SAO,
30 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
31 FAIL_IF(p == MAP_FAILED);
32
33 /* Write to the mapping, to at least cause a fault */
34 memset(p, 0xaa, SIZE);
35
36 return 0;
37}
38
39int main(void)
40{
41 return test_harness(test_prot_sao, "prot-sao");
42}
diff --git a/tools/testing/selftests/powerpc/utils.h b/tools/testing/selftests/powerpc/utils.h
index a985cfaa535e..fbd33e52ef8f 100644
--- a/tools/testing/selftests/powerpc/utils.h
+++ b/tools/testing/selftests/powerpc/utils.h
@@ -27,6 +27,11 @@ int test_harness(int (test_function)(void), char *name);
27extern void *get_auxv_entry(int type); 27extern void *get_auxv_entry(int type);
28int pick_online_cpu(void); 28int pick_online_cpu(void);
29 29
30static inline bool have_hwcap(unsigned long ftr)
31{
32 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
33}
34
30static inline bool have_hwcap2(unsigned long ftr2) 35static inline bool have_hwcap2(unsigned long ftr2)
31{ 36{
32 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2; 37 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;