Skip to content

Commit 82d6229

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/uaccess: Merge cmpxchg_user_key() inline assemblies
The inline assemblies for __cmpxchg_user_key1() and __cmpxchg_user_key2() are identical. Get rid of the duplication and provide a common helper function. Suggested-by: Mete Durlu <[email protected]> Acked-by: Alexander Gordeev <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent d2b73ce commit 82d6229

File tree

1 file changed

+25
-55
lines changed

1 file changed

+25
-55
lines changed

arch/s390/lib/uaccess.c

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,16 @@ EXPORT_SYMBOL(_copy_to_user_key);
150150

151151
#define CMPXCHG_USER_KEY_MAX_LOOPS 128
152152

153-
int __kprobes __cmpxchg_user_key1(unsigned long address, unsigned char *uval,
154-
unsigned char old, unsigned char new, unsigned long key)
153+
static nokprobe_inline int __cmpxchg_user_key_small(unsigned long address, unsigned int *uval,
154+
unsigned int old, unsigned int new,
155+
unsigned int mask, unsigned long key)
155156
{
156-
unsigned int prev, shift, mask, _old, _new;
157157
unsigned long count;
158+
unsigned int prev;
158159
bool sacf_flag;
159160
int rc = 0;
160161

161162
skey_regions_initialize();
162-
shift = (3 ^ (address & 3)) << 3;
163-
address ^= address & 3;
164-
_old = (unsigned int)old << shift;
165-
_new = (unsigned int)new << shift;
166-
mask = ~(0xff << shift);
167163
sacf_flag = enable_sacf_uaccess();
168164
asm_inline volatile(
169165
"20: spka 0(%[key])\n"
@@ -193,77 +189,51 @@ int __kprobes __cmpxchg_user_key1(unsigned long address, unsigned char *uval,
193189
: [rc] "+&d" (rc),
194190
[prev] "=&d" (prev),
195191
[address] "+Q" (*(int *)address),
196-
[tmp] "+&d" (_old),
197-
[new] "+&d" (_new),
192+
[tmp] "+&d" (old),
193+
[new] "+&d" (new),
198194
[mask] "+&d" (mask),
199195
[count] "=a" (count)
200196
: [key] "%[count]" (key << 4),
201197
[default_key] "J" (PAGE_DEFAULT_KEY),
202198
[max_loops] "J" (CMPXCHG_USER_KEY_MAX_LOOPS)
203199
: "memory", "cc");
204200
disable_sacf_uaccess(sacf_flag);
205-
*uval = prev >> shift;
201+
*uval = prev;
206202
if (!count)
207203
rc = -EAGAIN;
208204
return rc;
209205
}
206+
207+
int __kprobes __cmpxchg_user_key1(unsigned long address, unsigned char *uval,
208+
unsigned char old, unsigned char new, unsigned long key)
209+
{
210+
unsigned int prev, shift, mask, _old, _new;
211+
int rc;
212+
213+
shift = (3 ^ (address & 3)) << 3;
214+
address ^= address & 3;
215+
_old = (unsigned int)old << shift;
216+
_new = (unsigned int)new << shift;
217+
mask = ~(0xff << shift);
218+
rc = __cmpxchg_user_key_small(address, &prev, _old, _new, mask, key);
219+
*uval = prev >> shift;
220+
return rc;
221+
}
210222
EXPORT_SYMBOL(__cmpxchg_user_key1);
211223

212224
int __kprobes __cmpxchg_user_key2(unsigned long address, unsigned short *uval,
213225
unsigned short old, unsigned short new, unsigned long key)
214226
{
215227
unsigned int prev, shift, mask, _old, _new;
216-
unsigned long count;
217-
bool sacf_flag;
218-
int rc = 0;
228+
int rc;
219229

220-
skey_regions_initialize();
221230
shift = (2 ^ (address & 2)) << 3;
222231
address ^= address & 2;
223232
_old = (unsigned int)old << shift;
224233
_new = (unsigned int)new << shift;
225234
mask = ~(0xffff << shift);
226-
sacf_flag = enable_sacf_uaccess();
227-
asm_inline volatile(
228-
"20: spka 0(%[key])\n"
229-
" sacf 256\n"
230-
" llill %[count],%[max_loops]\n"
231-
"0: l %[prev],%[address]\n"
232-
"1: nr %[prev],%[mask]\n"
233-
" xilf %[mask],0xffffffff\n"
234-
" or %[new],%[prev]\n"
235-
" or %[prev],%[tmp]\n"
236-
"2: lr %[tmp],%[prev]\n"
237-
"3: cs %[prev],%[new],%[address]\n"
238-
"4: jnl 5f\n"
239-
" xr %[tmp],%[prev]\n"
240-
" xr %[new],%[tmp]\n"
241-
" nr %[tmp],%[mask]\n"
242-
" jnz 5f\n"
243-
" brct %[count],2b\n"
244-
"5: sacf 768\n"
245-
" spka %[default_key]\n"
246-
"21:\n"
247-
EX_TABLE_UA_LOAD_REG(0b, 5b, %[rc], %[prev])
248-
EX_TABLE_UA_LOAD_REG(1b, 5b, %[rc], %[prev])
249-
EX_TABLE_UA_LOAD_REG(3b, 5b, %[rc], %[prev])
250-
EX_TABLE_UA_LOAD_REG(4b, 5b, %[rc], %[prev])
251-
SKEY_REGION(20b, 21b)
252-
: [rc] "+&d" (rc),
253-
[prev] "=&d" (prev),
254-
[address] "+Q" (*(int *)address),
255-
[tmp] "+&d" (_old),
256-
[new] "+&d" (_new),
257-
[mask] "+&d" (mask),
258-
[count] "=a" (count)
259-
: [key] "%[count]" (key << 4),
260-
[default_key] "J" (PAGE_DEFAULT_KEY),
261-
[max_loops] "J" (CMPXCHG_USER_KEY_MAX_LOOPS)
262-
: "memory", "cc");
263-
disable_sacf_uaccess(sacf_flag);
235+
rc = __cmpxchg_user_key_small(address, &prev, _old, _new, mask, key);
264236
*uval = prev >> shift;
265-
if (!count)
266-
rc = -EAGAIN;
267237
return rc;
268238
}
269239
EXPORT_SYMBOL(__cmpxchg_user_key2);

0 commit comments

Comments
 (0)