Skip to content

Commit 94c12cc

Browse files
author
Martin Schwidefsky
committed
[S390] Inline assembly cleanup.
Major cleanup of all s390 inline assemblies. They now have a common coding style. Quite a few have been shortened, mainly by using register asm variables. Use of the EX_TABLE macro helps as well. The atomic ops, bit ops and locking inlines new use the Q-constraint if a newer gcc is used. That results in slightly better code. Thanks to Christian Borntraeger for proof reading the changes. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 25d83cb commit 94c12cc

51 files changed

Lines changed: 1759 additions & 2269 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/s390/crypto/crypt_s390.h‎

Lines changed: 65 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -104,63 +104,6 @@ struct crypt_s390_query_status {
104104
u64 low;
105105
};
106106

107-
/*
108-
* Standard fixup and ex_table sections for crypt_s390 inline functions.
109-
* label 0: the s390 crypto operation
110-
* label 1: just after 1 to catch illegal operation exception
111-
* (unsupported model)
112-
* label 6: the return point after fixup
113-
* label 7: set error value if exception _in_ crypto operation
114-
* label 8: set error value if illegal operation exception
115-
* [ret] is the variable to receive the error code
116-
* [ERR] is the error code value
117-
*/
118-
#ifndef CONFIG_64BIT
119-
#define __crypt_s390_fixup \
120-
".section .fixup,\"ax\" \n" \
121-
"7: lhi %0,%h[e1] \n" \
122-
" bras 1,9f \n" \
123-
" .long 6b \n" \
124-
"8: lhi %0,%h[e2] \n" \
125-
" bras 1,9f \n" \
126-
" .long 6b \n" \
127-
"9: l 1,0(1) \n" \
128-
" br 1 \n" \
129-
".previous \n" \
130-
".section __ex_table,\"a\" \n" \
131-
" .align 4 \n" \
132-
" .long 0b,7b \n" \
133-
" .long 1b,8b \n" \
134-
".previous"
135-
#else /* CONFIG_64BIT */
136-
#define __crypt_s390_fixup \
137-
".section .fixup,\"ax\" \n" \
138-
"7: lhi %0,%h[e1] \n" \
139-
" jg 6b \n" \
140-
"8: lhi %0,%h[e2] \n" \
141-
" jg 6b \n" \
142-
".previous\n" \
143-
".section __ex_table,\"a\" \n" \
144-
" .align 8 \n" \
145-
" .quad 0b,7b \n" \
146-
" .quad 1b,8b \n" \
147-
".previous"
148-
#endif /* CONFIG_64BIT */
149-
150-
/*
151-
* Standard code for setting the result of s390 crypto instructions.
152-
* %0: the register which will receive the result
153-
* [result]: the register containing the result (e.g. second operand length
154-
* to compute number of processed bytes].
155-
*/
156-
#ifndef CONFIG_64BIT
157-
#define __crypt_s390_set_result \
158-
" lr %0,%[result] \n"
159-
#else /* CONFIG_64BIT */
160-
#define __crypt_s390_set_result \
161-
" lgr %0,%[result] \n"
162-
#endif
163-
164107
/*
165108
* Executes the KM (CIPHER MESSAGE) operation of the CPU.
166109
* @param func: the function code passed to KM; see crypt_s390_km_func
@@ -176,28 +119,24 @@ crypt_s390_km(long func, void* param, u8* dest, const u8* src, long src_len)
176119
{
177120
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
178121
register void* __param asm("1") = param;
179-
register u8* __dest asm("4") = dest;
180122
register const u8* __src asm("2") = src;
181123
register long __src_len asm("3") = src_len;
124+
register u8* __dest asm("4") = dest;
182125
int ret;
183126

184-
ret = 0;
185-
__asm__ __volatile__ (
186-
"0: .insn rre,0xB92E0000,%1,%2 \n" /* KM opcode */
127+
asm volatile(
128+
"0: .insn rre,0xb92e0000,%3,%1 \n" /* KM opcode */
187129
"1: brc 1,0b \n" /* handle partial completion */
188-
__crypt_s390_set_result
189-
"6: \n"
190-
__crypt_s390_fixup
191-
: "+d" (ret), "+a" (__dest), "+a" (__src),
192-
[result] "+d" (__src_len)
193-
: [e1] "K" (-EFAULT), [e2] "K" (-ENOSYS), "d" (__func),
194-
"a" (__param)
195-
: "cc", "memory"
196-
);
197-
if (ret >= 0 && func & CRYPT_S390_FUNC_MASK){
198-
ret = src_len - ret;
199-
}
200-
return ret;
130+
" ahi %0,%h7\n"
131+
"2: ahi %0,%h8\n"
132+
"3:\n"
133+
EX_TABLE(0b,3b) EX_TABLE(1b,2b)
134+
: "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
135+
: "d" (__func), "a" (__param), "0" (-EFAULT),
136+
"K" (ENOSYS), "K" (-ENOSYS + EFAULT) : "cc", "memory");
137+
if (ret < 0)
138+
return ret;
139+
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
201140
}
202141

203142
/*
@@ -215,28 +154,24 @@ crypt_s390_kmc(long func, void* param, u8* dest, const u8* src, long src_len)
215154
{
216155
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
217156
register void* __param asm("1") = param;
218-
register u8* __dest asm("4") = dest;
219157
register const u8* __src asm("2") = src;
220158
register long __src_len asm("3") = src_len;
159+
register u8* __dest asm("4") = dest;
221160
int ret;
222161

223-
ret = 0;
224-
__asm__ __volatile__ (
225-
"0: .insn rre,0xB92F0000,%1,%2 \n" /* KMC opcode */
162+
asm volatile(
163+
"0: .insn rre,0xb92f0000,%3,%1 \n" /* KMC opcode */
226164
"1: brc 1,0b \n" /* handle partial completion */
227-
__crypt_s390_set_result
228-
"6: \n"
229-
__crypt_s390_fixup
230-
: "+d" (ret), "+a" (__dest), "+a" (__src),
231-
[result] "+d" (__src_len)
232-
: [e1] "K" (-EFAULT), [e2] "K" (-ENOSYS), "d" (__func),
233-
"a" (__param)
234-
: "cc", "memory"
235-
);
236-
if (ret >= 0 && func & CRYPT_S390_FUNC_MASK){
237-
ret = src_len - ret;
238-
}
239-
return ret;
165+
" ahi %0,%h7\n"
166+
"2: ahi %0,%h8\n"
167+
"3:\n"
168+
EX_TABLE(0b,3b) EX_TABLE(1b,2b)
169+
: "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
170+
: "d" (__func), "a" (__param), "0" (-EFAULT),
171+
"K" (ENOSYS), "K" (-ENOSYS + EFAULT) : "cc", "memory");
172+
if (ret < 0)
173+
return ret;
174+
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
240175
}
241176

242177
/*
@@ -258,22 +193,19 @@ crypt_s390_kimd(long func, void* param, const u8* src, long src_len)
258193
register long __src_len asm("3") = src_len;
259194
int ret;
260195

261-
ret = 0;
262-
__asm__ __volatile__ (
263-
"0: .insn rre,0xB93E0000,%1,%1 \n" /* KIMD opcode */
264-
"1: brc 1,0b \n" /* handle partical completion */
265-
__crypt_s390_set_result
266-
"6: \n"
267-
__crypt_s390_fixup
268-
: "+d" (ret), "+a" (__src), [result] "+d" (__src_len)
269-
: [e1] "K" (-EFAULT), [e2] "K" (-ENOSYS), "d" (__func),
270-
"a" (__param)
271-
: "cc", "memory"
272-
);
273-
if (ret >= 0 && (func & CRYPT_S390_FUNC_MASK)){
274-
ret = src_len - ret;
275-
}
276-
return ret;
196+
asm volatile(
197+
"0: .insn rre,0xb93e0000,%1,%1 \n" /* KIMD opcode */
198+
"1: brc 1,0b \n" /* handle partial completion */
199+
" ahi %0,%h6\n"
200+
"2: ahi %0,%h7\n"
201+
"3:\n"
202+
EX_TABLE(0b,3b) EX_TABLE(1b,2b)
203+
: "=d" (ret), "+a" (__src), "+d" (__src_len)
204+
: "d" (__func), "a" (__param), "0" (-EFAULT),
205+
"K" (ENOSYS), "K" (-ENOSYS + EFAULT) : "cc", "memory");
206+
if (ret < 0)
207+
return ret;
208+
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
277209
}
278210

279211
/*
@@ -294,22 +226,19 @@ crypt_s390_klmd(long func, void* param, const u8* src, long src_len)
294226
register long __src_len asm("3") = src_len;
295227
int ret;
296228

297-
ret = 0;
298-
__asm__ __volatile__ (
299-
"0: .insn rre,0xB93F0000,%1,%1 \n" /* KLMD opcode */
300-
"1: brc 1,0b \n" /* handle partical completion */
301-
__crypt_s390_set_result
302-
"6: \n"
303-
__crypt_s390_fixup
304-
: "+d" (ret), "+a" (__src), [result] "+d" (__src_len)
305-
: [e1] "K" (-EFAULT), [e2] "K" (-ENOSYS), "d" (__func),
306-
"a" (__param)
307-
: "cc", "memory"
308-
);
309-
if (ret >= 0 && func & CRYPT_S390_FUNC_MASK){
310-
ret = src_len - ret;
311-
}
312-
return ret;
229+
asm volatile(
230+
"0: .insn rre,0xb93f0000,%1,%1 \n" /* KLMD opcode */
231+
"1: brc 1,0b \n" /* handle partial completion */
232+
" ahi %0,%h6\n"
233+
"2: ahi %0,%h7\n"
234+
"3:\n"
235+
EX_TABLE(0b,3b) EX_TABLE(1b,2b)
236+
: "=d" (ret), "+a" (__src), "+d" (__src_len)
237+
: "d" (__func), "a" (__param), "0" (-EFAULT),
238+
"K" (ENOSYS), "K" (-ENOSYS + EFAULT) : "cc", "memory");
239+
if (ret < 0)
240+
return ret;
241+
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
313242
}
314243

315244
/*
@@ -331,22 +260,19 @@ crypt_s390_kmac(long func, void* param, const u8* src, long src_len)
331260
register long __src_len asm("3") = src_len;
332261
int ret;
333262

334-
ret = 0;
335-
__asm__ __volatile__ (
336-
"0: .insn rre,0xB91E0000,%5,%5 \n" /* KMAC opcode */
337-
"1: brc 1,0b \n" /* handle partical completion */
338-
__crypt_s390_set_result
339-
"6: \n"
340-
__crypt_s390_fixup
341-
: "+d" (ret), "+a" (__src), [result] "+d" (__src_len)
342-
: [e1] "K" (-EFAULT), [e2] "K" (-ENOSYS), "d" (__func),
343-
"a" (__param)
344-
: "cc", "memory"
345-
);
346-
if (ret >= 0 && func & CRYPT_S390_FUNC_MASK){
347-
ret = src_len - ret;
348-
}
349-
return ret;
263+
asm volatile(
264+
"0: .insn rre,0xb91e0000,%1,%1 \n" /* KLAC opcode */
265+
"1: brc 1,0b \n" /* handle partial completion */
266+
" ahi %0,%h6\n"
267+
"2: ahi %0,%h7\n"
268+
"3:\n"
269+
EX_TABLE(0b,3b) EX_TABLE(1b,2b)
270+
: "=d" (ret), "+a" (__src), "+d" (__src_len)
271+
: "d" (__func), "a" (__param), "0" (-EFAULT),
272+
"K" (ENOSYS), "K" (-ENOSYS + EFAULT) : "cc", "memory");
273+
if (ret < 0)
274+
return ret;
275+
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
350276
}
351277

352278
/**

‎arch/s390/hypfs/hypfs_diag.c‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,14 @@ static int diag204(unsigned long subcode, unsigned long size, void *addr)
333333
register unsigned long _subcode asm("0") = subcode;
334334
register unsigned long _size asm("1") = size;
335335

336-
asm volatile (" diag %2,%0,0x204\n"
337-
"0: \n" ".section __ex_table,\"a\"\n"
338-
#ifndef __s390x__
339-
" .align 4\n"
340-
" .long 0b,0b\n"
341-
#else
342-
" .align 8\n"
343-
" .quad 0b,0b\n"
344-
#endif
345-
".previous":"+d" (_subcode), "+d"(_size)
346-
:"d"(addr)
347-
:"memory");
336+
asm volatile(
337+
" diag %2,%0,0x204\n"
338+
"0:\n"
339+
EX_TABLE(0b,0b)
340+
: "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
348341
if (_subcode)
349342
return -1;
350-
else
351-
return _size;
343+
return _size;
352344
}
353345

354346
/*
@@ -491,8 +483,7 @@ static void *diag204_store(void)
491483

492484
static void diag224(void *ptr)
493485
{
494-
asm volatile(" diag %0,%1,0x224\n"
495-
: :"d" (0), "d"(ptr) : "memory");
486+
asm volatile("diag %0,%1,0x224" : :"d" (0), "d"(ptr) : "memory");
496487
}
497488

498489
static int diag224_get_name_table(void)

‎arch/s390/kernel/compat_linux.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,7 @@ sys32_execve(struct pt_regs regs)
544544
current->ptrace &= ~PT_DTRACE;
545545
task_unlock(current);
546546
current->thread.fp_regs.fpc=0;
547-
__asm__ __volatile__
548-
("sr 0,0\n\t"
549-
"sfpc 0,0\n\t"
550-
: : :"0");
547+
asm volatile("sfpc %0,0" : : "d" (0));
551548
}
552549
putname(filename);
553550
out:

0 commit comments

Comments
 (0)