Skip to content

Commit 249dbe7

Browse files
arndbRussell King (Oracle)
authored and
Russell King (Oracle)
committed
ARM: 9108/1: oabi-compat: rework epoll_wait/epoll_pwait emulation
The epoll_wait() system call wrapper is one of the remaining users of the set_fs() infrasturcture for Arm. Changing it to not require set_fs() is rather complex unfortunately. The approach I'm taking here is to allow architectures to override the code that copies the output to user space, and let the oabi-compat implementation check whether it is getting called from an EABI or OABI system call based on the thread_info->syscall value. The in_oabi_syscall() check here mirrors the in_compat_syscall() and in_x32_syscall() helpers for 32-bit compat implementations on other architectures. Overall, the amount of code goes down, at least with the newly added sys_oabi_epoll_pwait() helper getting removed again. The downside is added complexity in the source code for the native implementation. There should be no difference in runtime performance except for Arm kernels with CONFIG_OABI_COMPAT enabled that now have to go through an external function call to check which of the two variants to use. Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
1 parent 4e57a4d commit 249dbe7

File tree

5 files changed

+49
-72
lines changed

5 files changed

+49
-72
lines changed

arch/arm/include/asm/syscall.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ static inline int syscall_get_nr(struct task_struct *task,
2828
return task_thread_info(task)->abi_syscall & __NR_SYSCALL_MASK;
2929
}
3030

31+
static inline bool __in_oabi_syscall(struct task_struct *task)
32+
{
33+
return IS_ENABLED(CONFIG_OABI_COMPAT) &&
34+
(task_thread_info(task)->abi_syscall & __NR_OABI_SYSCALL_BASE);
35+
}
36+
37+
static inline bool in_oabi_syscall(void)
38+
{
39+
return __in_oabi_syscall(current);
40+
}
41+
3142
static inline void syscall_rollback(struct task_struct *task,
3243
struct pt_regs *regs)
3344
{

arch/arm/kernel/sys_oabi-compat.c

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
#include <linux/uaccess.h>
8484
#include <linux/slab.h>
8585

86+
#include <asm/syscall.h>
87+
8688
struct oldabi_stat64 {
8789
unsigned long long st_dev;
8890
unsigned int __pad1;
@@ -264,87 +266,34 @@ asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd,
264266

265267
return do_epoll_ctl(epfd, op, fd, &kernel, false);
266268
}
267-
268-
static long do_oabi_epoll_wait(int epfd, struct oabi_epoll_event __user *events,
269-
int maxevents, int timeout)
270-
{
271-
struct epoll_event *kbuf;
272-
struct oabi_epoll_event e;
273-
mm_segment_t fs;
274-
long ret, err, i;
275-
276-
if (maxevents <= 0 ||
277-
maxevents > (INT_MAX/sizeof(*kbuf)) ||
278-
maxevents > (INT_MAX/sizeof(*events)))
279-
return -EINVAL;
280-
if (!access_ok(events, sizeof(*events) * maxevents))
281-
return -EFAULT;
282-
kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL);
283-
if (!kbuf)
284-
return -ENOMEM;
285-
fs = get_fs();
286-
set_fs(KERNEL_DS);
287-
ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout);
288-
set_fs(fs);
289-
err = 0;
290-
for (i = 0; i < ret; i++) {
291-
e.events = kbuf[i].events;
292-
e.data = kbuf[i].data;
293-
err = __copy_to_user(events, &e, sizeof(e));
294-
if (err)
295-
break;
296-
events++;
297-
}
298-
kfree(kbuf);
299-
return err ? -EFAULT : ret;
300-
}
301269
#else
302270
asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd,
303271
struct oabi_epoll_event __user *event)
304272
{
305273
return -EINVAL;
306274
}
307-
308-
asmlinkage long sys_oabi_epoll_wait(int epfd,
309-
struct oabi_epoll_event __user *events,
310-
int maxevents, int timeout)
311-
{
312-
return -EINVAL;
313-
}
314275
#endif
315276

316-
SYSCALL_DEFINE4(oabi_epoll_wait, int, epfd,
317-
struct oabi_epoll_event __user *, events,
318-
int, maxevents, int, timeout)
277+
struct epoll_event __user *
278+
epoll_put_uevent(__poll_t revents, __u64 data,
279+
struct epoll_event __user *uevent)
319280
{
320-
return do_oabi_epoll_wait(epfd, events, maxevents, timeout);
321-
}
281+
if (in_oabi_syscall()) {
282+
struct oabi_epoll_event __user *oevent = (void __user *)uevent;
322283

323-
/*
324-
* Implement the event wait interface for the eventpoll file. It is the kernel
325-
* part of the user space epoll_pwait(2).
326-
*/
327-
SYSCALL_DEFINE6(oabi_epoll_pwait, int, epfd,
328-
struct oabi_epoll_event __user *, events, int, maxevents,
329-
int, timeout, const sigset_t __user *, sigmask,
330-
size_t, sigsetsize)
331-
{
332-
int error;
284+
if (__put_user(revents, &oevent->events) ||
285+
__put_user(data, &oevent->data))
286+
return NULL;
333287

334-
/*
335-
* If the caller wants a certain signal mask to be set during the wait,
336-
* we apply it here.
337-
*/
338-
error = set_user_sigmask(sigmask, sigsetsize);
339-
if (error)
340-
return error;
288+
return (void __user *)(oevent+1);
289+
}
341290

342-
error = do_oabi_epoll_wait(epfd, events, maxevents, timeout);
343-
restore_saved_sigmask_unless(error == -EINTR);
291+
if (__put_user(revents, &uevent->events) ||
292+
__put_user(data, &uevent->data))
293+
return NULL;
344294

345-
return error;
295+
return uevent+1;
346296
}
347-
#endif
348297

349298
struct oabi_sembuf {
350299
unsigned short sem_num;

arch/arm/tools/syscall.tbl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
249 common lookup_dcookie sys_lookup_dcookie
267267
250 common epoll_create sys_epoll_create
268268
251 common epoll_ctl sys_epoll_ctl sys_oabi_epoll_ctl
269-
252 common epoll_wait sys_epoll_wait sys_oabi_epoll_wait
269+
252 common epoll_wait sys_epoll_wait
270270
253 common remap_file_pages sys_remap_file_pages
271271
# 254 for set_thread_area
272272
# 255 for get_thread_area
@@ -360,7 +360,7 @@
360360
343 common vmsplice sys_vmsplice
361361
344 common move_pages sys_move_pages
362362
345 common getcpu sys_getcpu
363-
346 common epoll_pwait sys_epoll_pwait sys_oabi_epoll_pwait
363+
346 common epoll_pwait sys_epoll_pwait
364364
347 common kexec_load sys_kexec_load
365365
348 common utimensat sys_utimensat_time32
366366
349 common signalfd sys_signalfd

fs/eventpoll.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,16 +1684,15 @@ static int ep_send_events(struct eventpoll *ep,
16841684
if (!revents)
16851685
continue;
16861686

1687-
if (__put_user(revents, &events->events) ||
1688-
__put_user(epi->event.data, &events->data)) {
1687+
events = epoll_put_uevent(revents, epi->event.data, events);
1688+
if (!events) {
16891689
list_add(&epi->rdllink, &txlist);
16901690
ep_pm_stay_awake(epi);
16911691
if (!res)
16921692
res = -EFAULT;
16931693
break;
16941694
}
16951695
res++;
1696-
events++;
16971696
if (epi->event.events & EPOLLONESHOT)
16981697
epi->event.events &= EP_PRIVATE_BITS;
16991698
else if (!(epi->event.events & EPOLLET)) {

include/linux/eventpoll.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,22 @@ static inline void eventpoll_release(struct file *file) {}
6868

6969
#endif
7070

71+
#if defined(CONFIG_ARM) && defined(CONFIG_OABI_COMPAT)
72+
/* ARM OABI has an incompatible struct layout and needs a special handler */
73+
extern struct epoll_event __user *
74+
epoll_put_uevent(__poll_t revents, __u64 data,
75+
struct epoll_event __user *uevent);
76+
#else
77+
static inline struct epoll_event __user *
78+
epoll_put_uevent(__poll_t revents, __u64 data,
79+
struct epoll_event __user *uevent)
80+
{
81+
if (__put_user(revents, &uevent->events) ||
82+
__put_user(data, &uevent->data))
83+
return NULL;
84+
85+
return uevent+1;
86+
}
87+
#endif
88+
7189
#endif /* #ifndef _LINUX_EVENTPOLL_H */

0 commit comments

Comments
 (0)