]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
8f4c199c675feaaa6f7e4bcbd31a49678c597a71
[thirdparty/kernel/stable-queue.git] /
1 From foo@baz Sun Jun 17 12:07:34 CEST 2018
2 From: Ingo Molnar <mingo@kernel.org>
3 Date: Mon, 14 May 2018 10:56:23 +0200
4 Subject: x86/pkeys/selftests: Adjust the self-test to fresh distros that export the pkeys ABI
5
6 From: Ingo Molnar <mingo@kernel.org>
7
8 [ Upstream commit 0fb96620dce351608aa82eed5942e2f58b07beda ]
9
10 Ubuntu 18.04 started exporting pkeys details in header files, resulting
11 in build failures and warnings in the pkeys self-tests:
12
13 protection_keys.c:232:0: warning: "SEGV_BNDERR" redefined
14 protection_keys.c:387:5: error: conflicting types for ‘pkey_get’
15 protection_keys.c:409:5: error: conflicting types for ‘pkey_set’
16 ...
17
18 Fix these namespace conflicts and double definitions, plus also
19 clean up the ABI definitions to make it all a bit more readable ...
20
21 Cc: Dave Hansen <dave.hansen@linux.intel.com>
22 Cc: Linus Torvalds <torvalds@linux-foundation.org>
23 Cc: Peter Zijlstra <peterz@infradead.org>
24 Cc: Thomas Gleixner <tglx@linutronix.de>
25 Cc: akpm@linux-foundation.org
26 Cc: dave.hansen@intel.com
27 Cc: linux-mm@kvack.org
28 Cc: linuxram@us.ibm.com
29 Cc: mpe@ellerman.id.au
30 Cc: shakeelb@google.com
31 Cc: shuah@kernel.org
32 Link: http://lkml.kernel.org/r/20180514085623.GB7094@gmail.com
33 Signed-off-by: Ingo Molnar <mingo@kernel.org>
34 Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
35 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
36 ---
37 tools/testing/selftests/x86/protection_keys.c | 67 +++++++++++++++-----------
38 1 file changed, 41 insertions(+), 26 deletions(-)
39
40 --- a/tools/testing/selftests/x86/protection_keys.c
41 +++ b/tools/testing/selftests/x86/protection_keys.c
42 @@ -191,26 +191,30 @@ void lots_o_noops_around_write(int *writ
43 #ifdef __i386__
44
45 #ifndef SYS_mprotect_key
46 -# define SYS_mprotect_key 380
47 +# define SYS_mprotect_key 380
48 #endif
49 +
50 #ifndef SYS_pkey_alloc
51 -# define SYS_pkey_alloc 381
52 -# define SYS_pkey_free 382
53 +# define SYS_pkey_alloc 381
54 +# define SYS_pkey_free 382
55 #endif
56 -#define REG_IP_IDX REG_EIP
57 -#define si_pkey_offset 0x14
58 +
59 +#define REG_IP_IDX REG_EIP
60 +#define si_pkey_offset 0x14
61
62 #else
63
64 #ifndef SYS_mprotect_key
65 -# define SYS_mprotect_key 329
66 +# define SYS_mprotect_key 329
67 #endif
68 +
69 #ifndef SYS_pkey_alloc
70 -# define SYS_pkey_alloc 330
71 -# define SYS_pkey_free 331
72 +# define SYS_pkey_alloc 330
73 +# define SYS_pkey_free 331
74 #endif
75 -#define REG_IP_IDX REG_RIP
76 -#define si_pkey_offset 0x20
77 +
78 +#define REG_IP_IDX REG_RIP
79 +#define si_pkey_offset 0x20
80
81 #endif
82
83 @@ -225,8 +229,14 @@ void dump_mem(void *dumpme, int len_byte
84 }
85 }
86
87 -#define SEGV_BNDERR 3 /* failed address bound checks */
88 -#define SEGV_PKUERR 4
89 +/* Failed address bound checks: */
90 +#ifndef SEGV_BNDERR
91 +# define SEGV_BNDERR 3
92 +#endif
93 +
94 +#ifndef SEGV_PKUERR
95 +# define SEGV_PKUERR 4
96 +#endif
97
98 static char *si_code_str(int si_code)
99 {
100 @@ -393,10 +403,15 @@ pid_t fork_lazy_child(void)
101 return forkret;
102 }
103
104 -#define PKEY_DISABLE_ACCESS 0x1
105 -#define PKEY_DISABLE_WRITE 0x2
106 +#ifndef PKEY_DISABLE_ACCESS
107 +# define PKEY_DISABLE_ACCESS 0x1
108 +#endif
109 +
110 +#ifndef PKEY_DISABLE_WRITE
111 +# define PKEY_DISABLE_WRITE 0x2
112 +#endif
113
114 -u32 pkey_get(int pkey, unsigned long flags)
115 +static u32 hw_pkey_get(int pkey, unsigned long flags)
116 {
117 u32 mask = (PKEY_DISABLE_ACCESS|PKEY_DISABLE_WRITE);
118 u32 pkru = __rdpkru();
119 @@ -418,7 +433,7 @@ u32 pkey_get(int pkey, unsigned long fla
120 return masked_pkru;
121 }
122
123 -int pkey_set(int pkey, unsigned long rights, unsigned long flags)
124 +static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags)
125 {
126 u32 mask = (PKEY_DISABLE_ACCESS|PKEY_DISABLE_WRITE);
127 u32 old_pkru = __rdpkru();
128 @@ -452,15 +467,15 @@ void pkey_disable_set(int pkey, int flag
129 pkey, flags);
130 pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
131
132 - pkey_rights = pkey_get(pkey, syscall_flags);
133 + pkey_rights = hw_pkey_get(pkey, syscall_flags);
134
135 - dprintf1("%s(%d) pkey_get(%d): %x\n", __func__,
136 + dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
137 pkey, pkey, pkey_rights);
138 pkey_assert(pkey_rights >= 0);
139
140 pkey_rights |= flags;
141
142 - ret = pkey_set(pkey, pkey_rights, syscall_flags);
143 + ret = hw_pkey_set(pkey, pkey_rights, syscall_flags);
144 assert(!ret);
145 /*pkru and flags have the same format */
146 shadow_pkru |= flags << (pkey * 2);
147 @@ -468,8 +483,8 @@ void pkey_disable_set(int pkey, int flag
148
149 pkey_assert(ret >= 0);
150
151 - pkey_rights = pkey_get(pkey, syscall_flags);
152 - dprintf1("%s(%d) pkey_get(%d): %x\n", __func__,
153 + pkey_rights = hw_pkey_get(pkey, syscall_flags);
154 + dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
155 pkey, pkey, pkey_rights);
156
157 dprintf1("%s(%d) pkru: 0x%x\n", __func__, pkey, rdpkru());
158 @@ -483,24 +498,24 @@ void pkey_disable_clear(int pkey, int fl
159 {
160 unsigned long syscall_flags = 0;
161 int ret;
162 - int pkey_rights = pkey_get(pkey, syscall_flags);
163 + int pkey_rights = hw_pkey_get(pkey, syscall_flags);
164 u32 orig_pkru = rdpkru();
165
166 pkey_assert(flags & (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
167
168 - dprintf1("%s(%d) pkey_get(%d): %x\n", __func__,
169 + dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
170 pkey, pkey, pkey_rights);
171 pkey_assert(pkey_rights >= 0);
172
173 pkey_rights |= flags;
174
175 - ret = pkey_set(pkey, pkey_rights, 0);
176 + ret = hw_pkey_set(pkey, pkey_rights, 0);
177 /* pkru and flags have the same format */
178 shadow_pkru &= ~(flags << (pkey * 2));
179 pkey_assert(ret >= 0);
180
181 - pkey_rights = pkey_get(pkey, syscall_flags);
182 - dprintf1("%s(%d) pkey_get(%d): %x\n", __func__,
183 + pkey_rights = hw_pkey_get(pkey, syscall_flags);
184 + dprintf1("%s(%d) hw_pkey_get(%d): %x\n", __func__,
185 pkey, pkey, pkey_rights);
186
187 dprintf1("%s(%d) pkru: 0x%x\n", __func__, pkey, rdpkru());