Skip to content

Commit 4f41c2b

Browse files
heicarstMartin Schwidefsky
authored andcommitted
s390/uaccess: get rid of indirect function calls
There are only two uaccess variants on s390 left: the version that is used if the mvcos instruction is available, and the page table walk variant. So there is no need for expensive indirect function calls. By default the mvcos variant will be called. If the mvcos instruction is not available it will call the page table walk variant. For minimal performance impact the "if (mvcos_is_available)" is implemented with a jump label, which will be a six byte nop on machines with mvcos. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent cfa785e commit 4f41c2b

7 files changed

Lines changed: 152 additions & 149 deletions

File tree

‎arch/s390/include/asm/futex.h‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#include <linux/uaccess.h>
66
#include <asm/errno.h>
77

8-
static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
8+
int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, u32 oldval, u32 newval);
9+
int __futex_atomic_op_inuser(int op, u32 __user *uaddr, int oparg, int *old);
10+
11+
static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
912
{
1013
int op = (encoded_op >> 28) & 7;
1114
int cmp = (encoded_op >> 24) & 15;
@@ -17,7 +20,7 @@ static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1720
oparg = 1 << oparg;
1821

1922
pagefault_disable();
20-
ret = uaccess.futex_atomic_op(op, uaddr, oparg, &oldval);
23+
ret = __futex_atomic_op_inuser(op, uaddr, oparg, &oldval);
2124
pagefault_enable();
2225

2326
if (!ret) {
@@ -34,10 +37,4 @@ static inline int futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
3437
return ret;
3538
}
3639

37-
static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
38-
u32 oldval, u32 newval)
39-
{
40-
return uaccess.futex_atomic_cmpxchg(uval, uaddr, oldval, newval);
41-
}
42-
4340
#endif /* _ASM_S390_FUTEX_H */

‎arch/s390/include/asm/uaccess.h‎

Lines changed: 61 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,58 @@ static inline unsigned long extable_fixup(const struct exception_table_entry *x)
9292
#define ARCH_HAS_SORT_EXTABLE
9393
#define ARCH_HAS_SEARCH_EXTABLE
9494

95-
struct uaccess_ops {
96-
size_t (*copy_from_user)(void *, const void __user *, size_t);
97-
size_t (*copy_to_user)(void __user *, const void *, size_t);
98-
size_t (*copy_in_user)(void __user *, const void __user *, size_t);
99-
size_t (*clear_user)(void __user *, size_t);
100-
size_t (*strnlen_user)(const char __user *, size_t);
101-
size_t (*strncpy_from_user)(char *, const char __user *, size_t);
102-
int (*futex_atomic_op)(int op, u32 __user *, int oparg, int *old);
103-
int (*futex_atomic_cmpxchg)(u32 *, u32 __user *, u32 old, u32 new);
104-
};
95+
int __handle_fault(unsigned long, unsigned long, int);
10596

106-
extern struct uaccess_ops uaccess;
107-
extern struct uaccess_ops uaccess_mvcos;
108-
extern struct uaccess_ops uaccess_pt;
97+
/**
98+
* __copy_from_user: - Copy a block of data from user space, with less checking.
99+
* @to: Destination address, in kernel space.
100+
* @from: Source address, in user space.
101+
* @n: Number of bytes to copy.
102+
*
103+
* Context: User context only. This function may sleep.
104+
*
105+
* Copy data from user space to kernel space. Caller must check
106+
* the specified block with access_ok() before calling this function.
107+
*
108+
* Returns number of bytes that could not be copied.
109+
* On success, this will be zero.
110+
*
111+
* If some data could not be copied, this function will pad the copied
112+
* data to the requested size using zero bytes.
113+
*/
114+
size_t __must_check __copy_from_user(void *to, const void __user *from,
115+
size_t n);
116+
117+
/**
118+
* __copy_to_user: - Copy a block of data into user space, with less checking.
119+
* @to: Destination address, in user space.
120+
* @from: Source address, in kernel space.
121+
* @n: Number of bytes to copy.
122+
*
123+
* Context: User context only. This function may sleep.
124+
*
125+
* Copy data from kernel space to user space. Caller must check
126+
* the specified block with access_ok() before calling this function.
127+
*
128+
* Returns number of bytes that could not be copied.
129+
* On success, this will be zero.
130+
*/
131+
unsigned long __must_check __copy_to_user(void __user *to, const void *from,
132+
unsigned long n);
109133

110-
extern int __handle_fault(unsigned long, unsigned long, int);
134+
#define __copy_to_user_inatomic __copy_to_user
135+
#define __copy_from_user_inatomic __copy_from_user
111136

112137
static inline int __put_user_fn(void *x, void __user *ptr, size_t size)
113138
{
114-
size = uaccess.copy_to_user(ptr, x, size);
115-
return size ? -EFAULT : size;
139+
size = __copy_to_user(ptr, x, size);
140+
return size ? -EFAULT : 0;
116141
}
117142

118143
static inline int __get_user_fn(void *x, const void __user *ptr, size_t size)
119144
{
120-
size = uaccess.copy_from_user(x, ptr, size);
121-
return size ? -EFAULT : size;
145+
size = __copy_from_user(x, ptr, size);
146+
return size ? -EFAULT : 0;
122147
}
123148

124149
/*
@@ -152,7 +177,7 @@ static inline int __get_user_fn(void *x, const void __user *ptr, size_t size)
152177
})
153178

154179

155-
extern int __put_user_bad(void) __attribute__((noreturn));
180+
int __put_user_bad(void) __attribute__((noreturn));
156181

157182
#define __get_user(x, ptr) \
158183
({ \
@@ -200,34 +225,11 @@ extern int __put_user_bad(void) __attribute__((noreturn));
200225
__get_user(x, ptr); \
201226
})
202227

203-
extern int __get_user_bad(void) __attribute__((noreturn));
228+
int __get_user_bad(void) __attribute__((noreturn));
204229

205230
#define __put_user_unaligned __put_user
206231
#define __get_user_unaligned __get_user
207232

208-
/**
209-
* __copy_to_user: - Copy a block of data into user space, with less checking.
210-
* @to: Destination address, in user space.
211-
* @from: Source address, in kernel space.
212-
* @n: Number of bytes to copy.
213-
*
214-
* Context: User context only. This function may sleep.
215-
*
216-
* Copy data from kernel space to user space. Caller must check
217-
* the specified block with access_ok() before calling this function.
218-
*
219-
* Returns number of bytes that could not be copied.
220-
* On success, this will be zero.
221-
*/
222-
static inline unsigned long __must_check
223-
__copy_to_user(void __user *to, const void *from, unsigned long n)
224-
{
225-
return uaccess.copy_to_user(to, from, n);
226-
}
227-
228-
#define __copy_to_user_inatomic __copy_to_user
229-
#define __copy_from_user_inatomic __copy_from_user
230-
231233
/**
232234
* copy_to_user: - Copy a block of data into user space.
233235
* @to: Destination address, in user space.
@@ -248,30 +250,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
248250
return __copy_to_user(to, from, n);
249251
}
250252

251-
/**
252-
* __copy_from_user: - Copy a block of data from user space, with less checking.
253-
* @to: Destination address, in kernel space.
254-
* @from: Source address, in user space.
255-
* @n: Number of bytes to copy.
256-
*
257-
* Context: User context only. This function may sleep.
258-
*
259-
* Copy data from user space to kernel space. Caller must check
260-
* the specified block with access_ok() before calling this function.
261-
*
262-
* Returns number of bytes that could not be copied.
263-
* On success, this will be zero.
264-
*
265-
* If some data could not be copied, this function will pad the copied
266-
* data to the requested size using zero bytes.
267-
*/
268-
static inline unsigned long __must_check
269-
__copy_from_user(void *to, const void __user *from, unsigned long n)
270-
{
271-
return uaccess.copy_from_user(to, from, n);
272-
}
273-
274-
extern void copy_from_user_overflow(void)
253+
void copy_from_user_overflow(void)
275254
#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
276255
__compiletime_warning("copy_from_user() buffer size is not provably correct")
277256
#endif
@@ -306,11 +285,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
306285
return __copy_from_user(to, from, n);
307286
}
308287

309-
static inline unsigned long __must_check
310-
__copy_in_user(void __user *to, const void __user *from, unsigned long n)
311-
{
312-
return uaccess.copy_in_user(to, from, n);
313-
}
288+
unsigned long __must_check
289+
__copy_in_user(void __user *to, const void __user *from, unsigned long n);
314290

315291
static inline unsigned long __must_check
316292
copy_in_user(void __user *to, const void __user *from, unsigned long n)
@@ -322,18 +298,22 @@ copy_in_user(void __user *to, const void __user *from, unsigned long n)
322298
/*
323299
* Copy a null terminated string from userspace.
324300
*/
301+
302+
long __strncpy_from_user(char *dst, const char __user *src, long count);
303+
325304
static inline long __must_check
326305
strncpy_from_user(char *dst, const char __user *src, long count)
327306
{
328307
might_fault();
329-
return uaccess.strncpy_from_user(dst, src, count);
308+
return __strncpy_from_user(dst, src, count);
330309
}
331310

332-
static inline unsigned long
333-
strnlen_user(const char __user * src, unsigned long n)
311+
size_t __must_check __strnlen_user(const char __user *src, size_t count);
312+
313+
static inline size_t strnlen_user(const char __user *src, size_t n)
334314
{
335315
might_fault();
336-
return uaccess.strnlen_user(src, n);
316+
return __strnlen_user(src, n);
337317
}
338318

339319
/**
@@ -355,21 +335,15 @@ strnlen_user(const char __user * src, unsigned long n)
355335
/*
356336
* Zero Userspace
357337
*/
338+
size_t __must_check __clear_user(void __user *to, size_t size);
358339

359-
static inline unsigned long __must_check
360-
__clear_user(void __user *to, unsigned long n)
361-
{
362-
return uaccess.clear_user(to, n);
363-
}
364-
365-
static inline unsigned long __must_check
366-
clear_user(void __user *to, unsigned long n)
340+
static inline size_t __must_check clear_user(void __user *to, size_t n)
367341
{
368342
might_fault();
369-
return uaccess.clear_user(to, n);
343+
return __clear_user(to, n);
370344
}
371345

372-
extern int copy_to_user_real(void __user *dest, void *src, size_t count);
373-
extern int copy_from_user_real(void *dest, void __user *src, size_t count);
346+
int copy_to_user_real(void __user *dest, void *src, size_t count);
347+
int copy_from_user_real(void *dest, void __user *src, size_t count);
374348

375349
#endif /* __S390_UACCESS_H */

‎arch/s390/kernel/setup.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <linux/compat.h>
4848

4949
#include <asm/ipl.h>
50-
#include <asm/uaccess.h>
5150
#include <asm/facility.h>
5251
#include <asm/smp.h>
5352
#include <asm/mmu_context.h>
@@ -64,12 +63,6 @@
6463
#include <asm/sclp.h>
6564
#include "entry.h"
6665

67-
/*
68-
* User copy operations.
69-
*/
70-
struct uaccess_ops uaccess;
71-
EXPORT_SYMBOL(uaccess);
72-
7366
/*
7467
* Machine setup..
7568
*/
@@ -1009,8 +1002,6 @@ void __init setup_arch(char **cmdline_p)
10091002
init_mm.end_data = (unsigned long) &_edata;
10101003
init_mm.brk = (unsigned long) &_end;
10111004

1012-
uaccess = MACHINE_HAS_MVCOS ? uaccess_mvcos : uaccess_pt;
1013-
10141005
parse_early_param();
10151006
detect_memory_layout(memory_chunk, memory_end);
10161007
os_info_init();

‎arch/s390/lib/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# Makefile for s390-specific library files..
33
#
44

5-
lib-y += delay.o string.o uaccess_pt.o find.o
5+
lib-y += delay.o string.o uaccess_pt.o uaccess_mvcos.o find.o
66
obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o mem32.o
77
obj-$(CONFIG_64BIT) += mem64.o
8-
lib-$(CONFIG_64BIT) += uaccess_mvcos.o
98
lib-$(CONFIG_SMP) += spinlock.o

‎arch/s390/lib/uaccess.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
#ifndef __ARCH_S390_LIB_UACCESS_H
77
#define __ARCH_S390_LIB_UACCESS_H
88

9-
extern int futex_atomic_op_pt(int, u32 __user *, int, int *);
10-
extern int futex_atomic_cmpxchg_pt(u32 *, u32 __user *, u32, u32);
9+
size_t copy_from_user_pt(void *to, const void __user *from, size_t n);
10+
size_t copy_to_user_pt(void __user *to, const void *from, size_t n);
11+
size_t copy_in_user_pt(void __user *to, const void __user *from, size_t n);
12+
size_t clear_user_pt(void __user *to, size_t n);
13+
size_t strnlen_user_pt(const char __user *src, size_t count);
14+
size_t strncpy_from_user_pt(char *dst, const char __user *src, size_t count);
1115

1216
#endif /* __ARCH_S390_LIB_UACCESS_H */

0 commit comments

Comments
 (0)