From patchwork Fri Sep 18 12:46:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11784861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5D4F618 for ; Fri, 18 Sep 2020 12:46:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5383F208B8 for ; Fri, 18 Sep 2020 12:46:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5383F208B8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arndb.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4A8DE6B0055; Fri, 18 Sep 2020 08:46:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4377A90000C; Fri, 18 Sep 2020 08:46:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AAD96B005A; Fri, 18 Sep 2020 08:46:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 0CF456B0003 for ; Fri, 18 Sep 2020 08:46:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C7D8D1DE0 for ; Fri, 18 Sep 2020 12:46:37 +0000 (UTC) X-FDA: 77276156034.28.basin55_430d8eb2712b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id A37886C04 for ; Fri, 18 Sep 2020 12:46:37 +0000 (UTC) X-Spam-Summary: 1,0,0,d03e45ee7057a247,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:2:41:69:355:379:541:800:960:966:968:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1605:1730:1747:1777:1792:1801:2196:2198:2199:2200:2393:2559:2562:2898:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4050:4120:4250:4321:4385:4605:5007:6119:6261:8660:9592:9707:10004:11026:11473:11657:11658:11914:12043:12160:12296:12297:12438:12555:12663:12683:12895:12986:13148:13161:13229:13230:13869:13894:14096:14394:21080:21324:21451:21627:21795:21939:21987:21990:30005:30012:30051:30054:30070,0,RBL:212.227.126.130:@arndb.de:.lbl8.mailshell.net-62.8.6.100 66.201.201.201;04yrc9z3t437cdu3t3prer3ncknkxyctnb91utwqxziy38y94tk34hdcbsxchyr.amxdb7ggypb1eayg3ueb69hf7hze8qy1agb594jz15fdnyejohf6i9wciew3yyg.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: basin55_430d8eb2712b X-Filterd-Recvd-Size: 9895 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.130]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Sep 2020 12:46:36 +0000 (UTC) Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1Mo77T-1kquu02zil-00peri; Fri, 18 Sep 2020 14:46:35 +0200 From: Arnd Bergmann To: Christoph Hellwig , Russell King , Alexander Viro Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v2 5/9] ARM: oabi-compat: rework epoll_wait/epoll_pwait emulation Date: Fri, 18 Sep 2020 14:46:20 +0200 Message-Id: <20200918124624.1469673-6-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200918124624.1469673-1-arnd@arndb.de> References: <20200918124624.1469673-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QZ3YqPnMGCPnIHGIg3yqftWz25JgpcwZkeORnifT5782m1gtFYy tcl5SL0wR+QDUrNc4tFOsLo/OhPMoPPFQswjmF7xmJim4CTXSoH52OHv6B30Ol4s1RNGCjd Lgp8JSlZ71u4DFJGkSybD5MRGnGtpHWMnWznsUB2CS/jmM+AlM7B7aqWka6nqCPId2lEXzm qlakF9orjL+3fEAMGrvBg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:fClDC8ZPtFI=:C5dgQ9rCVsl/R2dQGg1aUS SVR5/KZ7x0qph5iYv0ghEczvp1Hw8t9S+nKWQx0zcG0H29Wq9zxL3EppkSRKn601x/3uwImX2 TuX53x2mlnI/it759gSiLf3frJlnQzrCG9P2mPUzuwErmK6b0kSePqM+rl9RP8YV5OHcD83C6 cA1hdiYMd8I9u49X1gG6YegzgASv4zoALdYT4fG1lwFec3QdsUIq/R+ujiSB7fB92xsojYlKa 3g8wiJPggaF9s+ajOL1A2k/xRg90CU1VMl/m+TMC3gqCPBgvOgweL12fDaRKFlXQ/Oa1Op+Nc jWMtOfNMP4GE9apmQnNMowoeRNHVE9y0UFSIoeezUpyTlOoeaqpz9VbQFZHkrj5Plq6RHuvgv zwjJwGNj0xz6qF+v2rOHLK3SIq5QfVDW1Jmog/lhxVCU0K90m2w80lStF6aOgKJP2pq2VSTnM t4B2o9k3Gn8J/ghzKaRUXqkIhJWOj+M1XwnQ1+XXW0kcxuaGTmmaCIXahFpheeXwmjtqbRJAk Fq232advUlymrMdrjM1UBbYIbx4Km6vc7O4j1qryywikOUz3i34xkhb9s+gi8C633a8kvxeQG UOk/+9+NDVz+Avru2Dg99590hOysLPilE6Hs9ZLfdXo2QWiCKpO30AV5GjcwsA6lWxTOBKo2W 1z56RRMu+DgYwbmm2EuY5Y1RJoEE5tL/2C2r7xsyIYGIRc776vM+8OHg1/RmXkpHwneddo4lC rLDiRJ+x8IO5L/n4Wuk2jy1UVgmMZw3dOoTIon5ySUNe/vI30qBVrsxBEHuRu+W/EarVo3buu MluuQCVnjcpfxs7TY66tryzFNIgOulyZJOkOTNAs01oF5FPH/tGUynqaTJ+FCJT2EU6v4nv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/syscall.h | 11 +++++ arch/arm/kernel/sys_oabi-compat.c | 75 +++++++------------------------ arch/arm/tools/syscall.tbl | 4 +- fs/eventpoll.c | 5 +-- include/linux/eventpoll.h | 18 ++++++++ 5 files changed, 49 insertions(+), 64 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index 855aa7cc9b8e..156880943c16 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -28,6 +28,17 @@ static inline int syscall_get_nr(struct task_struct *task, return task_thread_info(task)->syscall & ~__NR_OABI_SYSCALL_BASE; } +static inline bool __in_oabi_syscall(struct task_struct *task) +{ + return IS_ENABLED(CONFIG_OABI_COMPAT) && + (task_thread_info(task)->syscall & __NR_OABI_SYSCALL_BASE); +} + +static inline bool in_oabi_syscall(void) +{ + return __in_oabi_syscall(current); +} + static inline void syscall_rollback(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index a2b1ae01e5bf..f9d8e5be6ba0 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -83,6 +83,8 @@ #include #include +#include + struct oldabi_stat64 { unsigned long long st_dev; unsigned int __pad1; @@ -264,70 +266,25 @@ asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd, return do_epoll_ctl(epfd, op, fd, &kernel, false); } -static long do_oabi_epoll_wait(int epfd, struct oabi_epoll_event __user *events, - int maxevents, int timeout) +struct epoll_event __user * +epoll_put_uevent(__poll_t revents, __u64 data, + struct epoll_event __user *uevent) { - struct epoll_event *kbuf; - struct oabi_epoll_event e; - mm_segment_t fs; - long ret, err, i; + if (in_oabi_syscall()) { + struct oabi_epoll_event __user *oevent = (void __user *)uevent; - if (maxevents <= 0 || - maxevents > (INT_MAX/sizeof(*kbuf)) || - maxevents > (INT_MAX/sizeof(*events))) - return -EINVAL; - if (!access_ok(events, sizeof(*events) * maxevents)) - return -EFAULT; - kbuf = kmalloc_array(maxevents, sizeof(*kbuf), GFP_KERNEL); - if (!kbuf) - return -ENOMEM; - fs = get_fs(); - set_fs(KERNEL_DS); - ret = sys_epoll_wait(epfd, kbuf, maxevents, timeout); - set_fs(fs); - err = 0; - for (i = 0; i < ret; i++) { - e.events = kbuf[i].events; - e.data = kbuf[i].data; - err = __copy_to_user(events, &e, sizeof(e)); - if (err) - break; - events++; - } - kfree(kbuf); - return err ? -EFAULT : ret; -} + if (__put_user(revents, &oevent->events) || + __put_user(data, &oevent->data)) + return NULL; -SYSCALL_DEFINE4(oabi_epoll_wait, int, epfd, - struct oabi_epoll_event __user *, events, - int, maxevents, int, timeout) -{ - return do_oabi_epoll_wait(epfd, events, maxevents, timeout); -} - -/* - * Implement the event wait interface for the eventpoll file. It is the kernel - * part of the user space epoll_pwait(2). - */ -SYSCALL_DEFINE6(oabi_epoll_pwait, int, epfd, - struct oabi_epoll_event __user *, events, int, maxevents, - int, timeout, const sigset_t __user *, sigmask, - size_t, sigsetsize) -{ - int error; - - /* - * If the caller wants a certain signal mask to be set during the wait, - * we apply it here. - */ - error = set_user_sigmask(sigmask, sigsetsize); - if (error) - return error; + return (void __user *)(oevent+1); + } - error = do_oabi_epoll_wait(epfd, events, maxevents, timeout); - restore_saved_sigmask_unless(error == -EINTR); + if (__put_user(revents, &uevent->events) || + __put_user(data, &uevent->data)) + return NULL; - return error; + return uevent+1; } struct oabi_sembuf { diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl index 39a24bee7df8..fe5cd48fed91 100644 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -266,7 +266,7 @@ 249 common lookup_dcookie sys_lookup_dcookie 250 common epoll_create sys_epoll_create 251 common epoll_ctl sys_epoll_ctl sys_oabi_epoll_ctl -252 common epoll_wait sys_epoll_wait sys_oabi_epoll_wait +252 common epoll_wait sys_epoll_wait 253 common remap_file_pages sys_remap_file_pages # 254 for set_thread_area # 255 for get_thread_area @@ -360,7 +360,7 @@ 343 common vmsplice sys_vmsplice 344 common move_pages sys_move_pages 345 common getcpu sys_getcpu -346 common epoll_pwait sys_epoll_pwait sys_oabi_epoll_pwait +346 common epoll_pwait sys_epoll_pwait 347 common kexec_load sys_kexec_load 348 common utimensat sys_utimensat_time32 349 common signalfd sys_signalfd diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 12eebcdea9c8..796d9e72dc96 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1745,8 +1745,8 @@ static __poll_t ep_send_events_proc(struct eventpoll *ep, struct list_head *head if (!revents) continue; - if (__put_user(revents, &uevent->events) || - __put_user(epi->event.data, &uevent->data)) { + uevent = epoll_put_uevent(revents, epi->event.data, uevent); + if (!uevent) { list_add(&epi->rdllink, head); ep_pm_stay_awake(epi); if (!esed->res) @@ -1754,7 +1754,6 @@ static __poll_t ep_send_events_proc(struct eventpoll *ep, struct list_head *head return 0; } esed->res++; - uevent++; if (epi->event.events & EPOLLONESHOT) epi->event.events &= EP_PRIVATE_BITS; else if (!(epi->event.events & EPOLLET)) { diff --git a/include/linux/eventpoll.h b/include/linux/eventpoll.h index 8f000fada5a4..315d28a1cf1b 100644 --- a/include/linux/eventpoll.h +++ b/include/linux/eventpoll.h @@ -77,4 +77,22 @@ static inline void eventpoll_release(struct file *file) {} #endif +#if !defined(CONFIG_ARM) || !defined(CONFIG_OABI_COMPAT) +/* ARM OABI has an incompatible struct layout and needs a special handler */ +static inline struct epoll_event __user * +epoll_put_uevent(__poll_t revents, __u64 data, + struct epoll_event __user *uevent) +{ + if (__put_user(revents, &uevent->events) || + __put_user(data, &uevent->data)) + return NULL; + + return uevent+1; +} +#else +struct epoll_event __user * +epoll_put_uevent(__poll_t revents, __u64 data, + struct epoll_event __user *uevent); +#endif + #endif /* #ifndef _LINUX_EVENTPOLL_H */