From patchwork Thu Oct 1 14:12:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811515 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 5422392C for ; Thu, 1 Oct 2020 14:13:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A6BE221EF for ; Thu, 1 Oct 2020 14:13:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A6BE221EF 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 0E7446B0072; Thu, 1 Oct 2020 10:12:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BB3DA900004; Thu, 1 Oct 2020 10:12:57 -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 8F87D8E0003; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id 2C3F66B0074 for ; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A04153631 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.15.robin08_060cd9e2719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 647F418030C8C for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-Spam-Summary: 1,0,0,b5fa4b3d1d2a435d,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1534:1542:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2901:3138:3139:3140:3141:3142:3353:3865:3867:3868:3871:3874:4321:5007:6119:6261:7903:8603:10004:11026:11473:11658:11914:12043:12114:12160:12291:12297:12438:12555:12895:13894:14096:14181:14394:14721:21080:21451:21627:21740:21990:30054:30070:30079,0,RBL:217.72.192.73:@arndb.de:.lbl8.mailshell.net-62.8.6.100 64.201.201.201;04y8scd5wdydn76huo4s5okhhoxfqochm4hkpyigu7f7ybpy85bw9cxpjdeh4ek.dcj4a3ueugthgb94iouind8i5yprszbzf44mia8gycfyj69em5owt19kg8yujjy.c-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:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: robin08_060cd9e2719c X-Filterd-Recvd-Size: 4728 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N7zNt-1kSR3A338F-0153Zr; Thu, 01 Oct 2020 16:12:51 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 01/10] mm/maccess: fix unaligned copy_{from,to}_kernel_nofault Date: Thu, 1 Oct 2020 16:12:24 +0200 Message-Id: <20201001141233.119343-2-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:JIkXMdpDR0ur20R0TfErz+SS7ek7hvlvdV08ZHXeS+8QM4q5qK6 oT9S3UUAu8+kuKQ310bTrvgZsTPi8oFqjkMnDCgDogD5CTA1129uIhJSRz66AIMQ6yGzpwV VZ7gSDOe+HZl0q0ILFE1GDKaBjPyI0M+DNF+78LaWKBU+07VvQz5UeP0edPN78w8PRlI3rm B1KVNZjXcwcfTqz40kzbw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:qrUogoUvLLw=:+pbjXbqQxUCpKCme1RZhl2 zc7bJzX+2DAGkGh5VmN+7gSpTBJPbC7RolI8bMF2Z+DDea3ZJF0kR6Ld4B3RfHVd7vPkaUMdp 0WNymXhXx9vd7jZDICIyZnrsBgtxCbzP6LcRMb4SqZhoxOh8wfn+W4eOuPpBuDI5WGBRc9MDO ixnj2wBXKRn+HqufENoX5QQHVVntKLkjakka7wvZvZLtdl4EqZDo6/CjGsmQGxtqA9kRHlXV0 sr74KwumQ3Xz6zPbZgANxK06SwKVY/My6ROTRnnrIBDI/cBpMXATnpv5phPBGDFSacF9dD5JJ MzPNeuOItveG9UFf35QfuUyer+jFhh5+c9ObUBKal9r8zByMU+MCHHc5TgqIut6/rfmRHgLm2 Sir1y2RGYkDtmy0tqy69PraNN5UdK30CrCGbzFtwem0Xqg6+Am2xwZe6zvdErMVmmoMLe4mE8 iNv7MGsq3+S9z+0FP3drVF0zuapLhZlZ6Rh4JYT+ehx/Q6CUkDmXC75hnG+ai94YFqkJPb6TL rfoz2Exakbgw+hN6w7QJceYdHmDsTkluvtyvFleqZqH9w42ZOGiE54PSm4btuAcKS+gXEbEPa uGmo8WsfKwITSzMLnlPhmghA1NiwJs3P7E2IcvmyL67yRlcSLrV4VPfPkYmjOKRjK1AdmoMTe cj4x989Ytn+yfkYcdMT2v3CA0U/KIilQZb9AYID1UvZOBm53SCy50RwDtw8DYd/vFC91+4WH6 K2/pebXwCupnWz1vbQk4cDs4H47oFOSHca74ZXpDQH8HDxeRQrvhaBgeudfixDl6iiSZOVCke 0wTJXd3yoRzjMH5PXfMOcM4a1cFCkerlUapMYjUCpadICOCeAEuHGAiIvHtnRwtHtC7NLJL 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: On machines such as ARMv5 that trap unaligned accesses, these two functions can be slow when each access needs to be emulated, or they might not work at all. Change them so that each loop is only used when both the src and dst pointers are naturally aligned. Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- mm/maccess.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/mm/maccess.c b/mm/maccess.c index 3bd70405f2d8..d3f1a1f0b1c1 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -24,13 +24,21 @@ bool __weak copy_from_kernel_nofault_allowed(const void *unsafe_src, long copy_from_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + if (!copy_from_kernel_nofault_allowed(src, size)) return -ERANGE; pagefault_disable(); - copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_from_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); copy_from_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; @@ -50,10 +58,18 @@ EXPORT_SYMBOL_GPL(copy_from_kernel_nofault); long copy_to_kernel_nofault(void *dst, const void *src, size_t size) { + unsigned long align = 0; + + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + align = (unsigned long)dst | (unsigned long)src; + pagefault_disable(); - copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); - copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); + if (!(align & 7)) + copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); + if (!(align & 3)) + copy_to_kernel_nofault_loop(dst, src, size, u32, Efault); + if (!(align & 1)) + copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); copy_to_kernel_nofault_loop(dst, src, size, u8, Efault); pagefault_enable(); return 0; From patchwork Thu Oct 1 14:12:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811501 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 BDBA392C for ; Thu, 1 Oct 2020 14:12:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 387DD20B1F for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 387DD20B1F 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 04C776B0068; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F0BB76B006E; Thu, 1 Oct 2020 10:12:55 -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 DD2A98E0001; Thu, 1 Oct 2020 10:12:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id A9B3D6B0068 for ; Thu, 1 Oct 2020 10:12:55 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3FCAF2DFA for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-FDA: 77323547910.16.map14_2401ed02719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 19B10100E4AFB for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 40,2.5,0,c57e79b0e8220518,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:69:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2693:2901:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6119:6261:7904:9389:9592:10011:11026:11473:11658:11914:12043:12160:12296:12297:12555:12683:12895:13894:14181:14394:14721:21080:21433:21451:21627:21795:30012:30051:30054,0,RBL:217.72.192.74:@arndb.de:.lbl8.mailshell.net-66.201.201.201 62.14.6.100;04yr8gehstmzfqn1fg71tk9syjsdbych5sy7ggadbf5sad4b8sqkguwijmaksma.879kkoju7t5bxjimk3ztqfb37q9buf9e3yqafoskobdc9d411hu45635gjf8gnk.c-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:neutral,Custom_rules:0:1:0,LFtime:19,LUA_SUMMARY:none X-HE-Tag: map14_2401ed02719c X-Filterd-Recvd-Size: 5889 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:54 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1Mi2Fj-1ksOCT0Dcf-00e4nJ; Thu, 01 Oct 2020 16:12:52 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 02/10] ARM: traps: use get_kernel_nofault instead of set_fs() Date: Thu, 1 Oct 2020 16:12:25 +0200 Message-Id: <20201001141233.119343-3-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:bdOfhwwBBRSt/4DOOJUnmGtWrsvKQpezNqOznMTEofVRfuUQlXA X87CCp0XIB1Oa5guDvzEWLOmiOSrvDxOopnL87e93NYoWsre4aIkXzGrxlbH2ym5kNTLI18 ca4Ho0AXD0m7+Cy6A5vM4/eBgni/drXtxn7O69DSEVOkarAPXcTfVI0bU1cTLu0pQssoo8f Iu8KTgt6Y7CliDwvjbTMA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Szc4dFsfUBQ=:nxTDskwhGfcu7ntfGfAaY+ Dd87fn4NarNP2ZDAd34jAMNnWjle8Z8Y40KlZCId3CLHJNmcd0VgIUH435tCedDcA2iVG8Mjp NI0saGFNQSvCKjYXru9oVIK/Hu092AIEmlXuoNUCk3V2i7yUjpBMMDCc0ob9H5Ic3SIU9p+JN QGxDJr6PArOdidNfXE3U+xPQoQbpA8dwL3i/0ogruuC806fXckMTOzE4GAXxo76Ojr03s13Ex im9qJpp7afwvZpqFNovt7YSI9So/vMueQFtQHr26MTMMMjigvHADShV/GmuGrYN6g741Hg7OM PSlm271Fxk65rjbFKDYIWPqLXiHoYQOlurJUtnCBHu1kKY1PS+JDFLJLR+kp73clhD7i/RyMB qz1APo7A05M8MxbFenXvRuD1WgYD7wGeU3yb39ZjOkydYpGOv20hPRLUJa0jqFx44mxFijmpj Y85WbeYL3D7nTEW9OQt6Su7gHvJpNvJ+VG0WccfE475shveN+wOJaHHa7CD6oguiWrstxvqHc NFqSeZJk8BBgRYi1dvnuT42ndGFJ2akvvG1Mamzu8vORSer1FlTexDM6jbujYolrzjkJolI7T igB/ESc3cepL10X/CjspXmECItQEIK8HesSTXpGBP0OScOVJoCPAEfrEtlSzjbJS6KIqiUkNI zv/BqMkN6ZZqr3evUfbyGktFanBMPpjUDHsJHc32+h3AlEas9uzZrrCXrocTpNFfGbXWGKZPL ur9R/fXrEFYrhIejn6Vx1oONXWDU/euG/FLAfAZLXkNqaz5kd7L8zPdE6M59pfmfgTwt5detd N0IZHwqihu/kbX6kNo+kiU+H6mrT/4miiTzZ7ku9FblfrbvepgUylk5KkgXSD4sruVXmZzI 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: ARM uses set_fs() and __get_user() to allow the stack dumping code to access possibly invalid pointers carefully. These can be changed to the simpler get_kernel_nofault(), and allow the eventual removal of set_fs(). dump_instr() will print either kernel or user space pointers, depending on how it was called. For dump_mem(), I assume we are only interested in kernel pointers, and the only time that this is called with user_mode(regs)==true is when the regs themselves are unreliable as a result of the condition that caused the trap. Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- arch/arm/kernel/traps.c | 47 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 17d5a785df28..c3964a283b63 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -122,17 +122,8 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, unsigned long top) { unsigned long first; - mm_segment_t fs; int i; - /* - * We need to switch to kernel mode so that we can use __get_user - * to safely read from kernel space. Note that we now dump the - * code first, just in case the backtrace kills us. - */ - fs = get_fs(); - set_fs(KERNEL_DS); - printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top); for (first = bottom & ~31; first < top; first += 32) { @@ -145,7 +136,7 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, for (p = first, i = 0; i < 8 && p < top; i++, p += 4) { if (p >= bottom && p < top) { unsigned long val; - if (__get_user(val, (unsigned long *)p) == 0) + if (get_kernel_nofault(val, (unsigned long *)p)) sprintf(str + i * 9, " %08lx", val); else sprintf(str + i * 9, " ????????"); @@ -153,11 +144,9 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom, } printk("%s%04lx:%s\n", lvl, first & 0xffff, str); } - - set_fs(fs); } -static void __dump_instr(const char *lvl, struct pt_regs *regs) +static void dump_instr(const char *lvl, struct pt_regs *regs) { unsigned long addr = instruction_pointer(regs); const int thumb = thumb_mode(regs); @@ -173,10 +162,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) for (i = -4; i < 1 + !!thumb; i++) { unsigned int val, bad; - if (thumb) - bad = get_user(val, &((u16 *)addr)[i]); - else - bad = get_user(val, &((u32 *)addr)[i]); + if (!user_mode(regs)) { + if (thumb) { + u16 val16; + bad = get_kernel_nofault(val16, &((u16 *)addr)[i]); + val = val16; + } else { + bad = get_kernel_nofault(val, &((u32 *)addr)[i]); + } + } else { + if (thumb) + bad = get_user(val, &((u16 *)addr)[i]); + else + bad = get_user(val, &((u32 *)addr)[i]); + } if (!bad) p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ", @@ -189,20 +188,6 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) printk("%sCode: %s\n", lvl, str); } -static void dump_instr(const char *lvl, struct pt_regs *regs) -{ - mm_segment_t fs; - - if (!user_mode(regs)) { - fs = get_fs(); - set_fs(KERNEL_DS); - __dump_instr(lvl, regs); - set_fs(fs); - } else { - __dump_instr(lvl, regs); - } -} - #ifdef CONFIG_ARM_UNWIND static inline void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, const char *loglvl) From patchwork Thu Oct 1 14:12:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811509 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 A34CA6CA for ; Thu, 1 Oct 2020 14:13:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 731A420872 for ; Thu, 1 Oct 2020 14:13:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 731A420872 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 8F8D28E0005; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 80A368E0001; Thu, 1 Oct 2020 10:12:57 -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 34E3C6B0072; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id DD7136B0071 for ; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7BB01181AE886 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.23.thing78_0308fd52719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 560AC3760C for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-Spam-Summary: 1,0,0,a052df58c05fb307,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3354:3865:3866:3867:3870:3871:3872:4250:4321:4605:5007:6119:6261:10004:11026:11473:11658:11914:12043:12160:12291:12296:12297:12438:12555:12663:12679:12683:12895:12986:13161:13229:13870:13894:14096:14181:14394:14721:21080:21324:21433:21451:21627:21795:21990:30051:30054,0,RBL:217.72.192.73:@arndb.de:.lbl8.mailshell.net-64.201.201.201 62.8.6.100;04yf4pawtjruanej1rhujzqpr7eu3op4789e36xbe34843yqer8jor8i96danib.s6ka4gyiz75zmci5imij9c5pmaqao8ssyqgrmmjw68betusf3c9c8wpkha1f7if.g-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:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: thing78_0308fd52719c X-Filterd-Recvd-Size: 5298 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MvbJw-1kepec1eTe-00shEs; Thu, 01 Oct 2020 16:12:52 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann , stable@vger.kernel.org Subject: [PATCH v3 03/10] ARM: oabi-compat: add epoll_pwait handler Date: Thu, 1 Oct 2020 16:12:26 +0200 Message-Id: <20201001141233.119343-4-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:cWWCYuRJriYKt0llInUlGsi6sGZrKAuOlwaggzj3/coCoUzqfLK tdhpTdf+H1PnSpU5qTRkfZCY1eCG1Cjc26hA5rHMOatSmHap4G/tHtXis84Mc+nDdeUaSjS PlQBkFWU32fdiDbaBtMFwdhbryJMvp4bYkfA1tB83+ywMKEBtsP41yb1F5scXxc27obsYYl e2PBjElmQm1a2yMG97plw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:1EcS5jnnr5c=:1nhTSp9Le4lI6Ga8UCr5JX ipyTMFNr/ZP7v+X4Nv+sXpevyJjaGWoU3bmRuRFg41lsTEICDGn80l+k1ld6seKph2+6q2K5+ bO9Kc4cwSs6KYjZ2k+XxJ8v7ThMQVqKLjWaNHd082KwpwKaqm2WD9OXB8PR6eB3VTG+U/fmci wYYlfW46pyc0F1RJGW2RW/0iud2hoOZQzFOnO3aEiv50e0+HSV+6mDhAT4d10Sc2elBtgfUnt i2JW60cF6AVPW4UpsI8PQ07ly1/EOe0NJ82Br6fqWl1Ts5OLWf6GJgpu0YngvC0VGa1anEcud IbX43EodVT/85TdzRFpvawl586wog/J/ico+QQrz9/hJppRGHWcxGqDqpeM4/eQQZL+2ehdSL WzQdmIeYblZCXeIWmpdvOzcoDPyx+eVnsv8Gjct0G5ibU6JD8129XNJe0FiqeEPNGwaBEolQ4 8FoffRKSXJ6obHkMZMlyPhjCVM+39A/2ljYk2fGfFlED5YbHhB4ktz0ctaDgehZ+BdIS71d/y crzTKNN7I5YHtfReJWyjg4LgFpgoMI3LppDnAwXFmLQAn6d3V1m9z+7jVrPEi9jY9BETXXmP1 u+17FAEZ+ICVJXW97PTALiByF5UQsDzfn68gPV+d2ihUq6WAqDN5k4h1ZNoz0BJfRoOKRWBO2 8vQObH3r/eEbkG47hp/76MVrYdp6B2VCvkXOTJVnp092ZbDmiHVv1VhuOPC2uOZBZLJdVWjOH +I7iC88PjghCZ/dX7e5ii0Lb5R7ZGFkt/WIAIwHGg+6lLckIAehVXLBmB3Q1Sc99unfuBq6PJ VHM/WoRyYYZ6w/XYDjLofdAonNAqxxzrfRwkIbNE/A9okryX3sbushKiYtKaRXzdQV77VmV 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() syscall has a special version for OABI compat mode to convert the arguments to the EABI structure layout of the kernel. However, the later epoll_pwait() syscall was added in arch/arm in linux-2.6.32 without this conversion. Use the same kind of handler for both. Fixes: 369842658a36 ("ARM: 5677/1: ARM support for TIF_RESTORE_SIGMASK/pselect6/ppoll/epoll_pwait") Cc: stable@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Arnd Bergmann --- arch/arm/kernel/sys_oabi-compat.c | 37 ++++++++++++++++++++++++++++--- arch/arm/tools/syscall.tbl | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index 0203e545bbc8..a2b1ae01e5bf 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -264,9 +264,8 @@ asmlinkage long sys_oabi_epoll_ctl(int epfd, int op, int fd, return do_epoll_ctl(epfd, op, fd, &kernel, false); } -asmlinkage long sys_oabi_epoll_wait(int epfd, - struct oabi_epoll_event __user *events, - int maxevents, int timeout) +static long do_oabi_epoll_wait(int epfd, struct oabi_epoll_event __user *events, + int maxevents, int timeout) { struct epoll_event *kbuf; struct oabi_epoll_event e; @@ -299,6 +298,38 @@ asmlinkage long sys_oabi_epoll_wait(int epfd, return err ? -EFAULT : ret; } +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; + + error = do_oabi_epoll_wait(epfd, events, maxevents, timeout); + restore_saved_sigmask_unless(error == -EINTR); + + return error; +} + struct oabi_sembuf { unsigned short sem_num; short sem_op; diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl index 171077cbf419..39a24bee7df8 100644 --- a/arch/arm/tools/syscall.tbl +++ b/arch/arm/tools/syscall.tbl @@ -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 +346 common epoll_pwait sys_epoll_pwait sys_oabi_epoll_pwait 347 common kexec_load sys_kexec_load 348 common utimensat sys_utimensat_time32 349 common signalfd sys_signalfd From patchwork Thu Oct 1 14:12:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811505 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 3793992C for ; Thu, 1 Oct 2020 14:13:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DDE6B2087D for ; Thu, 1 Oct 2020 14:13:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDE6B2087D 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 BDF006B0070; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC7596B0072; Thu, 1 Oct 2020 10:12:56 -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 965A26B0071; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 5BBAA6B0070 for ; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 03BB92484 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.01.door03_4606b9d2719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id DC0E010046484 for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,544014446cc922a4,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1544:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3308:3355:3865:3866:3867:3868:3870:3871:3872:3874:4117:4250:4321:4605:5007:6119:6261:8660:10004:11026:11473:11657:11658:11914:12043:12114:12160:12296:12297:12438:12555:12895:12986:13148:13161:13229:13230:13618:13894:13972:14096:14181:14394:14721:21080:21212:21324:21433:21451:21627:21740:21939:21990:30003:30034:30054:30070:30090,0,RBL:212.227.17.24:@arndb.de:.lbl8.mailshell.net-62.8.6.100 66.201.201.201;04yfftcq31ickxahyrzyyya6777udycnu3kwzao3d8fi9u4f5c34k159ks8qqa8.xih6jktn9z7f31ndaf9gxdwc5gjwcdp8yjsfpkdsij5c85j4ewicp8dnwwxmdmh.y-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:neutral,Custom_rules:0:0:0,LFtime:19,LUA_SUMMARY:none X-HE-Tag: door03_4606b9d2719c X-Filterd-Recvd-Size: 6856 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1M2fHt-1kPNAh308t-0049t9; Thu, 01 Oct 2020 16:12:52 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 04/10] ARM: syscall: always store thread_info->syscall Date: Thu, 1 Oct 2020 16:12:27 +0200 Message-Id: <20201001141233.119343-5-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:JdmTWg1P4Ite9iAXVekvbKrwOeo3zfmqvIUPmBGn+poLbujFLTV 2SgE+hM5gZQIFpNPMD3oP2bmSfMYjV3uPhcNDB3Zsd703BBEuGl9FCny5XBsupWcCJC6dZq 0pBNxlWVJpncndUy6cI4qi4jYZO1+EeN48k0Ux7HAAuoFhjskkN5Hc0E3oxzbbRrELPLzpE CSX9YYxA0ixVWmUc+/nZg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:b+AJ6TOvCp0=:YXq7XKKBW6rBTVGiaDz4uP V9bs8W1xoR+KsgMIVJEN70mXfM+j7JFe9Pmob5gCOjug3IRXJTr0tslI/oVkbJwO/LUXZlx5w d3vF/k2pFPG3epdAXvPmmPREw2LDPGQUoxZr6vc0xfcAzjJ9IyvpnxnVE5Sj96NjS8PZTOdJO gm4FGzpt/nRta/OfmNk0UBaWatCKhzGKwkSUdLHlamzQu0N6/lcTnd4GNZGLF2YCGAqip83SZ ym/XuqiPHUsoQR3IgDEH/1BKVUOB++oGq2d0tqtYUfKyPE+ICnR0gSO6pVynbkslF7zxzu6Hr oY071Py+VrHRwa6vy+XoLKzCPxBx3pC9ZocG3Y91EV2sMKzCww9Tnqio7eRSUgeVl9kJ2aipw OBHPofD535M+mzZHR2cButM3UgBJtCLZJgevTTBFD+BO0Upuie5CA+dP8UC2RwUUjK2SLRllL e7djj9rLqMx+XimMNh+F7uW8E6F4TqIa1w8bs/Nej2TxKzlJB13dg23RqDqNwo4q3BNq/2l9o IAcVNCjZRBxe8NCHfYKp2rUL1arUXUemCJ+KrwNy2WHWC9sMbCCQZdgn17GXUukFavvkCX5Ty pUrIg/791zN2UHXgjnVOXKYQr34GFPMk4Prosqy7ZzjYdhC/EZbMOKEU1jNZ2dGF7JIyW7jGD ME/TUXPQiZkqWBhkNeBBNmGiYuWhAAP8c+hdqEWoxdQ+1p9h/kTP6+kxgAfF2KjQIlzBNF0zI HqioUMGEJnlIxZ6ekVGvWXoeklbonfyLuiSA6lS/hoF9ziE77pch7z24+cXR/SHp3a5lTP6HA fX6BgyW6RufWHpXdA/N6arAOJhWmmx0Si6MIN/u6mw8HbY9jb2vsPSrm4KAWAjOgFmC1qlH 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 system call number is used in a a couple of places, in particular ptrace, seccomp and /proc//syscall. The last one apparently never worked reliably on ARM for tasks that are not currently getting traced. Storing the syscall number in the normal entry path makes it work, as well as allowing us to see if the current system call is for OABI compat mode, which is the next thing I want to hook into. Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/syscall.h | 5 ++++- arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kernel/entry-common.S | 8 ++++++-- arch/arm/kernel/ptrace.c | 9 +++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h index fd02761ba06c..89898497edd6 100644 --- a/arch/arm/include/asm/syscall.h +++ b/arch/arm/include/asm/syscall.h @@ -22,7 +22,10 @@ extern const unsigned long sys_call_table[]; static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { - return task_thread_info(task)->syscall; + if (IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT)) + return task_thread_info(task)->syscall; + + return task_thread_info(task)->syscall & ~__NR_OABI_SYSCALL_BASE; } static inline void syscall_rollback(struct task_struct *task, diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index a1570c8bab25..97af6735172b 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -46,6 +46,7 @@ int main(void) DEFINE(TI_CPU, offsetof(struct thread_info, cpu)); DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain)); DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context)); + DEFINE(TI_SYSCALL, offsetof(struct thread_info, syscall)); DEFINE(TI_USED_CP, offsetof(struct thread_info, used_cp)); DEFINE(TI_TP_VALUE, offsetof(struct thread_info, tp_value)); DEFINE(TI_FPSTATE, offsetof(struct thread_info, fpstate)); diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 271cb8a1eba1..9a76467bbb47 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -223,6 +223,7 @@ ENTRY(vector_swi) /* saved_psr and saved_pc are now dead */ uaccess_disable tbl + get_thread_info tsk adr tbl, sys_call_table @ load syscall table pointer @@ -234,13 +235,17 @@ ENTRY(vector_swi) * get the old ABI syscall table address. */ bics r10, r10, #0xff000000 + strne r10, [tsk, #TI_SYSCALL] + streq scno, [tsk, #TI_SYSCALL] eorne scno, r10, #__NR_OABI_SYSCALL_BASE ldrne tbl, =sys_oabi_call_table #elif !defined(CONFIG_AEABI) bic scno, scno, #0xff000000 @ mask off SWI op-code + str scno, [tsk, #TI_SYSCALL] eor scno, scno, #__NR_SYSCALL_BASE @ check OS number +#else + str scno, [tsk, #TI_SYSCALL] #endif - get_thread_info tsk /* * Reload the registers that may have been corrupted on entry to * the syscall assembly (by tracing or context tracking.) @@ -285,7 +290,6 @@ ENDPROC(vector_swi) * context switches, and waiting for our parent to respond. */ __sys_trace: - mov r1, scno add r0, sp, #S_OFF bl syscall_trace_enter mov scno, r0 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c index 2771e682220b..683edb8b627d 100644 --- a/arch/arm/kernel/ptrace.c +++ b/arch/arm/kernel/ptrace.c @@ -25,6 +25,7 @@ #include #include +#include #include #define CREATE_TRACE_POINTS @@ -885,9 +886,9 @@ static void tracehook_report_syscall(struct pt_regs *regs, regs->ARM_ip = ip; } -asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno) +asmlinkage int syscall_trace_enter(struct pt_regs *regs) { - current_thread_info()->syscall = scno; + int scno; if (test_thread_flag(TIF_SYSCALL_TRACE)) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); @@ -898,11 +899,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno) return -1; #else /* XXX: remove this once OABI gets fixed */ - secure_computing_strict(current_thread_info()->syscall); + secure_computing_strict(syscall_get_nr(current, regs)); #endif /* Tracer or seccomp may have changed syscall. */ - scno = current_thread_info()->syscall; + scno = syscall_get_nr(current, regs); if (test_thread_flag(TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, scno); From patchwork Thu Oct 1 14:12:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811503 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 BE4226CA for ; Thu, 1 Oct 2020 14:12:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F46320872 for ; Thu, 1 Oct 2020 14:12:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F46320872 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 4D5666B006C; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 437376B006E; Thu, 1 Oct 2020 10:12:56 -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 2408C6B0071; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id CE4606B006C for ; Thu, 1 Oct 2020 10:12:55 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5226A18037C6F for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-FDA: 77323547910.29.oil01_160852b2719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 0DBD41807E1DF for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,fa509882a5de70be,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.17.10:@arndb.de:.lbl8.mailshell.net-62.14.6.100 66.201.201.201;04ygxsqg495tcowrnmkdrgwerc68ooctnb91utwqxziy38y94tk34hdcbsxchyr.amxdb7ggypb1eaygd4hmc9ja8cze8qy1agb594jz15fdnyejohf6i9wciew3yyg.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:21,LUA_SUMMARY:none X-HE-Tag: oil01_160852b2719c X-Filterd-Recvd-Size: 9889 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:54 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MZTua-1jsYXD0BPy-00WXhu; Thu, 01 Oct 2020 16:12:53 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 05/10] ARM: oabi-compat: rework epoll_wait/epoll_pwait emulation Date: Thu, 1 Oct 2020 16:12:28 +0200 Message-Id: <20201001141233.119343-6-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:XIaaingPpec+a6Y9LnJdFRwLVmXn4q8tvLz+Ns67E/nR1D/CxZu 2f3ZnnElaftMX2cx8jyMBlmpalu7G5S/I031cpRt14OJk2MLBpS6dKgk+Bdl3ce64tXMDWm Hwnv2472nk9CekGEslTcGf322mcSuHLrXX8gQI8H1dtCigaz/f5YFFNOB8S3+XW2dhKOK6N Rl0wHOU7kQNzOOiMgPY2g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:ZDmt+JVyqPo=:wUWBan/XhTM7os4S00g0T1 sAA5nlHwb2VVfsFK9dU/a72r9wdjyeUBgIFSad74IASqgKIVGCoU+8vZ7BfHvdlMiqjHAQp9Z tgCOQ+zioezPU4zafO96vEDsV5BF9fVIZkeVKR9d/W/Bfj1aG0pVpwdcSc11+/eoFhv69GK8w w8QHdRPUVOPNHiYwh65IIuC8Ow9o80p5akdwFNDzx/v44Hv4qGjrgA7RVfxSNtBPQ/3moCKyW wSFfkeEc5qed66reLd4wMONAaR8dya2lOTQddbcrXhUfOkoU7Hgnytl431wF8Kw/7Fnty0p6v csZbFnhptYVWvuEB0e0pCeH9V2vAW9wUct0VI0gh/tZi1FNqlCPpJeUElc/pAnc0ZOfXRFeqk hx6oEqu32UlvEGgtKT79aP346fSXQEPKGg/NBf3PU9h5ZAf0LWxPUgiE2eGqKyaij+zjd1M3w Rua29DbwZhTMWZ/OlqwLboQ3VGaZiDA75hKH1iUV7H+J3vvCKGVTyyUHQ/W0hx9M/g75B+2cP ImMGY8kLdF0n5crMk+bRxpEFdmqh90hlyOHzvdBkTNSGyI0ARmeAmDuIEaj/4mC+DEBR2+pel av/0ToexShtb0AthHNwYs1xfxh55pIlVpyHtdcptQD6g2CtaRcUtJWUS8CrERRaFSumcX9q2t BC/Dnec1dYFdqDUDukAvVwYCUqaKaeIyRkWPernuN+z7P7K89nAW2flez9NT72UaMBubcb26Q gIkmca9Si1jS80rxKq1DDxkLiYZ5g8/VNHKrm0opo1X7zy9hV0nCqymt1Rkjyvrvw59QYUVm/ UUpavLZQBScTTuFf50HVhGD+9UL/yjmdAh2WCFRLV+NFjWwPrDfOXE4XUDlJFNNvevClVaL 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 89898497edd6..9efb7b3384e5 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..d1f13147ed69 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 */ +extern struct epoll_event __user * +epoll_put_uevent(__poll_t revents, __u64 data, + struct epoll_event __user *uevent); +#else +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; +} +#endif + #endif /* #ifndef _LINUX_EVENTPOLL_H */ From patchwork Thu Oct 1 14:12:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811521 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 0D7446CA for ; Thu, 1 Oct 2020 14:13:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B274F20B1F for ; Thu, 1 Oct 2020 14:13:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B274F20B1F 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 AAB7C8E0001; Thu, 1 Oct 2020 10:12:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 80B06900003; Thu, 1 Oct 2020 10:12:58 -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 59F858E0001; Thu, 1 Oct 2020 10:12:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id EDD026B0073 for ; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7CB0E1802A36C for ; Thu, 1 Oct 2020 14:12:57 +0000 (UTC) X-FDA: 77323547994.06.pull42_3e007d02719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 3E262100B42EC for ; Thu, 1 Oct 2020 14:12:57 +0000 (UTC) X-Spam-Summary: 1,0,0,8ec658bc104084ae,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:1:2:41:69:355:379:541:800:960:966:968:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1605:1730:1747:1777:1792:1801:2194:2196:2198:2199:2200:2201:2393:2553:2559:2562:2897:2904:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4052:4250:4321:4385:4419:4605:5007:6119:6261:7875:7903:8660:9010:9592:9707:10004:11026:11473:11658:11914:12043:12160:12296:12297:12438:12555:12683:12895:12986:13148:13161:13229:13230:13894:14394:21080:21324:21451:21627:21740:21939:21990:30012:30029:30051:30054:30060:30064:30079:30090,0,RBL:212.227.17.13:@arndb.de:.lbl8.mailshell.net-66.201.201.201 62.8.6.100;04yfqpeg1bytbbz4hawbpzk3rf81hyp9zwjdissamqrh7w7qai6jbwcskpz7ax3.z658rzeem3jpdimhwr1m68oxky6wxq1d3u7mhhg9o3fjgfsoa6fe5kunonz6zte.4-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:neutral,Custom_rules:0:0:0,LFtime:19,LUA_SU MMARY:no X-HE-Tag: pull42_3e007d02719c X-Filterd-Recvd-Size: 11596 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N0X0U-1kZtyb1XM4-00wZ7M; Thu, 01 Oct 2020 16:12:53 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 06/10] ARM: oabi-compat: rework sys_semtimedop emulation Date: Thu, 1 Oct 2020 16:12:29 +0200 Message-Id: <20201001141233.119343-7-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:mc0z0RPOQhPoHEJNRXCeunuQO9IZJam8MHkko5ZbZ+UBJoRcaer m4VzOW7EeSmD9ItCHgsgsZXsf5mXJIdR7fcLnad4HN7WAoPJvNAxGvPBZ3a8djyS2kFia6e 5VzJs8t+5t000PXJmGkH/OC7WEuqP5Y23aJzhH8jf07Sx9jozpblOnqm2gNt83zoHsaUNzo jli/UnPFkQd8te6xyL+sg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:YRwDRxI1T2A=:ZRCV2UeaIBnv+rDsxRDhjP hdUBbK9Z/uL5PZYwUqntXTpQ+UK5wtPRaXA+LiexVeeSbx+XHAuOyUosEmvCzGxQlDHzgZCJD zmmihFGV2utDG105fphBQ7Tqa7pppgNJzdcj5KqqUzfT/OVV3x2FUJHHRMBvaeQjiX0+b/dEH dmJQIRkGNjlEVdXVyRYmEX7SaxEGa0LcXrMQUZ9E3HcRpWglZczhoVyQmtKlTOKa6DH9eVRcD qL5jD/zIQy+mlAIPyh7tQT8WtM/aoSNRuHCxKEtOP7T6YC50GOU6wPeHlYsoZ3NszxgDiheWW jihkw75VpeSkrKNJEn2/wEgUCsDVUtQlTksrO98IlSrE39JVHVFbqrwVpJPEOzgucKGvxhE4/ 0bT35qFBjEoQXCWu7goH3xs+S4qEH57PK2dHIZVTenMRkiVQp9b3ebIN9iltkLzoDC7+6pRAd te24TFW8oCZkp4XJAGUV9FdqpMpL5gxtN+ergNFxZEekBYK0uhWOyBUEumN6hwltd4xtrX0ai BiaUM/Hu9Z2lA55Qgmj8NYvNpOFgZRIchmgWvImd1UWaIYvWzpI/LHRSl76NqamC5CEE8RT+n 4nuHOHHqBMz7jQn7Kc/hBixz4GEEpNW6l5Mzx0KFjSKMiwBuXYpEv+i2FEV7kBq8rmQY4uEnt pm9PlpMZGkFGfqELEI47ZmkwoiXYHIWUJtWpYG+twisTURGUaiIczUTWO+8Y+Jdd4auH4QziU aHE6w/RXkMRQFeDfCasSJhvqql15apxu9grDWHA5N8OhmKVEjT06iBpQouA6wKDHFvNX5PB23 H01fuY0kkZJ13KpSh+wV92P1OkVgXzFRQ1NdAU4QGbAHVPT2nKGrM+H3UeOd1l+r5vCnbBT 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: sys_oabi_semtimedop() is one of the last users of set_fs() on Arm. To remove this one, expose the internal code of the actual implementation that operates on a kernel pointer and call it directly after copying. There should be no measurable impact on the normal execution of this function, and it makes the overly long function a little shorter, which may help readability. While reworking the oabi version, make it behave a little more like the native one, using kvmalloc_array() and restructure the code flow in a similar way. The naming of __do_semtimedop() is not very good, I hope someone can come up with a better name. One regression was spotted by kernel test robot and fixed before the first mailing list submission. Signed-off-by: Arnd Bergmann --- arch/arm/kernel/sys_oabi-compat.c | 38 ++++++++------ include/linux/syscalls.h | 3 ++ ipc/sem.c | 84 +++++++++++++++++++------------ 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index f9d8e5be6ba0..c3e63b73b6ae 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -80,6 +80,7 @@ #include #include #include +#include #include #include @@ -294,46 +295,51 @@ struct oabi_sembuf { unsigned short __pad; }; +#define sc_semopm sem_ctls[2] + asmlinkage long sys_oabi_semtimedop(int semid, struct oabi_sembuf __user *tsops, unsigned nsops, const struct old_timespec32 __user *timeout) { + struct ipc_namespace *ns; struct sembuf *sops; - struct old_timespec32 local_timeout; long err; int i; + ns = current->nsproxy->ipc_ns; + if (nsops > ns->sc_semopm) + return -E2BIG; if (nsops < 1 || nsops > SEMOPM) return -EINVAL; - if (!access_ok(tsops, sizeof(*tsops) * nsops)) - return -EFAULT; - sops = kmalloc_array(nsops, sizeof(*sops), GFP_KERNEL); + sops = kvmalloc_array(nsops, sizeof(*sops), GFP_KERNEL); if (!sops) return -ENOMEM; err = 0; for (i = 0; i < nsops; i++) { struct oabi_sembuf osb; - err |= __copy_from_user(&osb, tsops, sizeof(osb)); + err |= copy_from_user(&osb, tsops, sizeof(osb)); sops[i].sem_num = osb.sem_num; sops[i].sem_op = osb.sem_op; sops[i].sem_flg = osb.sem_flg; tsops++; } - if (timeout) { - /* copy this as well before changing domain protection */ - err |= copy_from_user(&local_timeout, timeout, sizeof(*timeout)); - timeout = &local_timeout; - } if (err) { err = -EFAULT; - } else { - mm_segment_t fs = get_fs(); - set_fs(KERNEL_DS); - err = sys_semtimedop_time32(semid, sops, nsops, timeout); - set_fs(fs); + goto out; + } + + if (timeout) { + struct timespec64 ts; + err = get_old_timespec32(&ts, timeout); + if (err) + goto out; + err = __do_semtimedop(semid, sops, nsops, &ts, ns); + goto out; } - kfree(sops); + err = __do_semtimedop(semid, sops, nsops, NULL, ns); +out: + kvfree(sops); return err; } diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 75ac7f8ae93c..bb5ed3a712a5 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1340,6 +1340,9 @@ long ksys_old_shmctl(int shmid, int cmd, struct shmid_ds __user *buf); long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems, unsigned int nsops, const struct old_timespec32 __user *timeout); +long __do_semtimedop(int semid, struct sembuf *tsems, unsigned int nsops, + const struct timespec64 *timeout, + struct ipc_namespace *ns); int __sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen); diff --git a/ipc/sem.c b/ipc/sem.c index 8c0244e0365e..515a39a67534 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -1978,46 +1978,34 @@ static struct sem_undo *find_alloc_undo(struct ipc_namespace *ns, int semid) return un; } -static long do_semtimedop(int semid, struct sembuf __user *tsops, - unsigned nsops, const struct timespec64 *timeout) +long __do_semtimedop(int semid, struct sembuf *sops, + unsigned nsops, const struct timespec64 *timeout, + struct ipc_namespace *ns) { int error = -EINVAL; struct sem_array *sma; - struct sembuf fast_sops[SEMOPM_FAST]; - struct sembuf *sops = fast_sops, *sop; + struct sembuf *sop; struct sem_undo *un; int max, locknum; bool undos = false, alter = false, dupsop = false; struct sem_queue queue; unsigned long dup = 0, jiffies_left = 0; - struct ipc_namespace *ns; - - ns = current->nsproxy->ipc_ns; if (nsops < 1 || semid < 0) return -EINVAL; if (nsops > ns->sc_semopm) return -E2BIG; - if (nsops > SEMOPM_FAST) { - sops = kvmalloc_array(nsops, sizeof(*sops), GFP_KERNEL); - if (sops == NULL) - return -ENOMEM; - } - - if (copy_from_user(sops, tsops, nsops * sizeof(*tsops))) { - error = -EFAULT; - goto out_free; - } if (timeout) { if (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L) { error = -EINVAL; - goto out_free; + goto out; } jiffies_left = timespec64_to_jiffies(timeout); } + max = 0; for (sop = sops; sop < sops + nsops; sop++) { unsigned long mask = 1ULL << ((sop->sem_num) % BITS_PER_LONG); @@ -2046,7 +2034,7 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, un = find_alloc_undo(ns, semid); if (IS_ERR(un)) { error = PTR_ERR(un); - goto out_free; + goto out; } } else { un = NULL; @@ -2057,25 +2045,25 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, if (IS_ERR(sma)) { rcu_read_unlock(); error = PTR_ERR(sma); - goto out_free; + goto out; } error = -EFBIG; if (max >= sma->sem_nsems) { rcu_read_unlock(); - goto out_free; + goto out; } error = -EACCES; if (ipcperms(ns, &sma->sem_perm, alter ? S_IWUGO : S_IRUGO)) { rcu_read_unlock(); - goto out_free; + goto out; } error = security_sem_semop(&sma->sem_perm, sops, nsops, alter); if (error) { rcu_read_unlock(); - goto out_free; + goto out; } error = -EIDRM; @@ -2089,7 +2077,7 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, * entangled here and why it's RMID race safe on comments at sem_lock() */ if (!ipc_valid_object(&sma->sem_perm)) - goto out_unlock_free; + goto out_unlock; /* * semid identifiers are not unique - find_alloc_undo may have * allocated an undo structure, it was invalidated by an RMID @@ -2098,7 +2086,7 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, * "un" itself is guaranteed by rcu. */ if (un && un->semid == -1) - goto out_unlock_free; + goto out_unlock; queue.sops = sops; queue.nsops = nsops; @@ -2124,10 +2112,10 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, rcu_read_unlock(); wake_up_q(&wake_q); - goto out_free; + goto out; } if (error < 0) /* non-blocking error path */ - goto out_unlock_free; + goto out_unlock; /* * We need to sleep on this operation, so we put the current @@ -2192,14 +2180,14 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, if (error != -EINTR) { /* see SEM_BARRIER_2 for purpose/pairing */ smp_acquire__after_ctrl_dep(); - goto out_free; + goto out; } rcu_read_lock(); locknum = sem_lock(sma, sops, nsops); if (!ipc_valid_object(&sma->sem_perm)) - goto out_unlock_free; + goto out_unlock; /* * No necessity for any barrier: We are protect by sem_lock() @@ -2211,7 +2199,7 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, * Leave without unlink_queue(), but with sem_unlock(). */ if (error != -EINTR) - goto out_unlock_free; + goto out_unlock; /* * If an interrupt occurred we have to clean up the queue. @@ -2222,13 +2210,45 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops, unlink_queue(sma, &queue); -out_unlock_free: +out_unlock: sem_unlock(sma, locknum); rcu_read_unlock(); +out: + return error; +} + +static long do_semtimedop(int semid, struct sembuf __user *tsops, + unsigned nsops, const struct timespec64 *timeout) +{ + struct sembuf fast_sops[SEMOPM_FAST]; + struct sembuf *sops = fast_sops; + struct ipc_namespace *ns; + int ret; + + ns = current->nsproxy->ipc_ns; + if (nsops > ns->sc_semopm) + return -E2BIG; + if (nsops < 1) + return -EINVAL; + + if (nsops > SEMOPM_FAST) { + sops = kvmalloc_array(nsops, sizeof(*sops), GFP_KERNEL); + if (sops == NULL) + return -ENOMEM; + } + + if (copy_from_user(sops, tsops, nsops * sizeof(*tsops))) { + ret = -EFAULT; + goto out_free; + } + + ret = __do_semtimedop(semid, sops, nsops, timeout, ns); + out_free: if (sops != fast_sops) kvfree(sops); - return error; + + return ret; } long ksys_semtimedop(int semid, struct sembuf __user *tsops, From patchwork Thu Oct 1 14:12:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811523 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 5EAF592C for ; Thu, 1 Oct 2020 14:13:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1D1F920872 for ; Thu, 1 Oct 2020 14:13:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D1F920872 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 8F3CD900004; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 89DF6900003; Thu, 1 Oct 2020 10:13:06 -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 6B262900004; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id 3606A900003 for ; Thu, 1 Oct 2020 10:13:06 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B293B3631 for ; Thu, 1 Oct 2020 14:13:05 +0000 (UTC) X-FDA: 77323548330.17.end34_4b181d22719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id B87AA1807EE81 for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,2207c55afb94f48f,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3871:3872:4321:4605:5007:6119:6261:7903:7904:9592:9707:10004:11026:11658:11914:12043:12160:12291:12297:12555:12683:12895:13161:13229:13894:14096:14110:14181:14394:14721:21080:21627:21795:21990:30051:30054:30070:30079,0,RBL:217.72.192.75:@arndb.de:.lbl8.mailshell.net-64.201.201.201 62.8.6.100;04ygeg6xxba35m4qn6q1i46p5r5e8yp5ih3zofx6yr4c5kmke7opidd17ptegrf.paftoi8b8chy3pspnief371zxj8a9ozs4ph4g9k3ichh5akrys6sm1d8s9i9kec.o-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:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: end34_4b181d22719c X-Filterd-Recvd-Size: 5789 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:54 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MLR9p-1k6ala2thD-00IXTP; Thu, 01 Oct 2020 16:12:53 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 07/10] ARM: oabi-compat: rework fcntl64() emulation Date: Thu, 1 Oct 2020 16:12:30 +0200 Message-Id: <20201001141233.119343-8-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:3TKgNrSTMpXNYGaFmu+SKHQrcSCbfmgZhLqpwbUtnDHIn9vPu29 oSkmHqaY7tsVWPZ2Ptkj1ib/NP/Dj6JPyQuSGpHXVR1Gqq30UVLFmv4Ia29rizLkAFHMdnl ozciaEsv5U1wTT6P8yVO75ZH+AeAXUIPO3efL7tlJ3g/x+yGiqwRxzgti7AONfBzTsd4hu2 JhI+LZ53Zez1akbZmzfzw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:w4rV1cQPcYg=:EYlyzTuBZ/LUfCWS+MzcGD kMfyyUknM+NGlxu5WBpVCEYA1LRustzlIEARJoYZofCaPKT8/dorMGR5Hr3nvdkP1cIs6McH1 qwT8N4mE9Q/ii5jF84vfiLgM3AddNFZbeXDLGOOGU5X/pyq4uSUY21T3O3icI+WZTF5pfyYpy 9DuJbOAYpzMgK8MtlknyOgV93A/KijM5rxcuUglbkmTdgq1EEnDENMO0Glt/qE6weMaG+fsy6 Krc1lkjbXQkIhPxHQg/6xnbepbCQN+0dshF18C3D/Zn4koW0EkRAb3XwvMRIsFfCB8ykkdHdB XSCv+v9HaIk7Guf6hFtuAXwLvZu7X4KUoAqs/cB+e/ZcMzs/Q9gkL0QhLfFVtgxZv9ftyBsyQ TD+rXPLIB/1q1M0/sbhCYec3Kpjd1QriCjO5mNR1iOnefl6VsAo7M/MTGvLJGsrKaqfsSCMYb L7KG8rfu8kd/OjXc0oL7N1EIcjHf9fzJS1xNyKOgTds2kzWlHP8mubFzySKwTc19CHJQ51qgo py0nbEm9jac3RR09S9gstqr8OGEkxH4O7d1g8uxinKK5xLLUGW129ZcRjQWwrxkfkIjJ6as3G 2IIhS1mqvsh8dP7or52uNvPR6tiyxwePa7QT8/A7ghsJ/IyWHLpZjUW98AwBOdbP/Fhcz/dU8 bJcj3ooA9MwkzpcyRqg85wPztd7M7JIdj08prwnymILsBvnMO+8aGRj45XaQb/3K+Wx0EDx8k Soqy/pKwglc2a6OAD8CqfxmS8hf7i9wXQMEBupL/22XLoqp9dU/TKBsVm+l2n0oOYyCe1o0bj fZfZIXsgGpQDcFiaZt66nmNuAc1OjREDo9MO8Y3cA6082coiaCG8i5fUQYhYo/D5qXXMpoT 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: This is one of the last users of get_fs(), and this is fairly easy to change, since the infrastructure for it is already there. The replacement here is essentially a copy of the existing fcntl64() syscall entry function. Signed-off-by: Arnd Bergmann --- arch/arm/kernel/sys_oabi-compat.c | 93 ++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/arch/arm/kernel/sys_oabi-compat.c b/arch/arm/kernel/sys_oabi-compat.c index c3e63b73b6ae..3449e163ea88 100644 --- a/arch/arm/kernel/sys_oabi-compat.c +++ b/arch/arm/kernel/sys_oabi-compat.c @@ -194,56 +194,83 @@ struct oabi_flock64 { pid_t l_pid; } __attribute__ ((packed,aligned(4))); -static long do_locks(unsigned int fd, unsigned int cmd, - unsigned long arg) +static int get_oabi_flock(struct flock64 *kernel, struct oabi_flock64 __user *arg) { - struct flock64 kernel; struct oabi_flock64 user; - mm_segment_t fs; - long ret; if (copy_from_user(&user, (struct oabi_flock64 __user *)arg, sizeof(user))) return -EFAULT; - kernel.l_type = user.l_type; - kernel.l_whence = user.l_whence; - kernel.l_start = user.l_start; - kernel.l_len = user.l_len; - kernel.l_pid = user.l_pid; - - fs = get_fs(); - set_fs(KERNEL_DS); - ret = sys_fcntl64(fd, cmd, (unsigned long)&kernel); - set_fs(fs); - - if (!ret && (cmd == F_GETLK64 || cmd == F_OFD_GETLK)) { - user.l_type = kernel.l_type; - user.l_whence = kernel.l_whence; - user.l_start = kernel.l_start; - user.l_len = kernel.l_len; - user.l_pid = kernel.l_pid; - if (copy_to_user((struct oabi_flock64 __user *)arg, - &user, sizeof(user))) - ret = -EFAULT; - } - return ret; + + kernel->l_type = user.l_type; + kernel->l_whence = user.l_whence; + kernel->l_start = user.l_start; + kernel->l_len = user.l_len; + kernel->l_pid = user.l_pid; + + return 0; +} + +static int put_oabi_flock(struct flock64 *kernel, struct oabi_flock64 __user *arg) +{ + struct oabi_flock64 user; + + user.l_type = kernel->l_type; + user.l_whence = kernel->l_whence; + user.l_start = kernel->l_start; + user.l_len = kernel->l_len; + user.l_pid = kernel->l_pid; + + if (copy_to_user((struct oabi_flock64 __user *)arg, + &user, sizeof(user))) + return -EFAULT; + + return 0; } asmlinkage long sys_oabi_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg) { + void __user *argp = (void __user *)arg; + struct fd f = fdget_raw(fd); + struct flock64 flock; + long err = -EBADF; + + if (!f.file) + goto out; + switch (cmd) { - case F_OFD_GETLK: - case F_OFD_SETLK: - case F_OFD_SETLKW: case F_GETLK64: + case F_OFD_GETLK: + err = security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err = get_oabi_flock(&flock, argp); + if (err) + break; + err = fcntl_getlk64(f.file, cmd, &flock); + if (!err) + err = put_oabi_flock(&flock, argp); + break; case F_SETLK64: case F_SETLKW64: - return do_locks(fd, cmd, arg); - + case F_OFD_SETLK: + case F_OFD_SETLKW: + err = security_file_fcntl(f.file, cmd, arg); + if (err) + break; + err = get_oabi_flock(&flock, argp); + if (err) + break; + err = fcntl_setlk64(fd, f.file, cmd, &flock); + break; default: - return sys_fcntl64(fd, cmd, arg); + err = sys_fcntl64(fd, cmd, arg); + break; } + fdput(f); +out: + return err; } struct oabi_epoll_event { From patchwork Thu Oct 1 14:12:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811507 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 3E1B492C for ; Thu, 1 Oct 2020 14:13:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C965A20B1F for ; Thu, 1 Oct 2020 14:13:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C965A20B1F 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 3647F6B0071; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2B28C6B0075; Thu, 1 Oct 2020 10:12:57 -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 091F56B0074; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id A33D96B006E for ; Thu, 1 Oct 2020 10:12:56 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 394EE181AE873 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.29.hour63_1d16eda2719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id D57E5180385F1 for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) X-Spam-Summary: 1,0,0,62ffd13c495bf4c4,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:1:2:41:69:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1605:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3743:3865:3866:3867:3868:3871:3872:4052:4321:4605:5007:6261:7875:8603:9036:9592:10004:11026:11232:11473:11657:11658:11914:12043:12114:12160:12291:12296:12297:12438:12555:12683:12895:12986:13161:13229:13894:14394:21080:21433:21451:21627:21740:21939:30003:30012:30054:30070,0,RBL:217.72.192.75:@arndb.de:.lbl8.mailshell.net-62.8.6.100 64.201.201.201;04y8zkj54ox74u3sfpajkfmijqqt4opmworqoyxxnesqjd8z9c6cwa79srxkbd4.amjda5jz7nemtptwdbtdr1uj5a8amgyksznre3s99dsm8afgjogzi8iofmrzma7.c-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:neutral,Custom_rules:0:0:0,LFtime:19,LUA_SUMMARY:none X-HE-Tag: hour63_1d16eda2719c X-Filterd-Recvd-Size: 11358 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.75]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MFshF-1kC9kn03HL-00HLAt; Thu, 01 Oct 2020 16:12:54 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 08/10] ARM: uaccess: add __{get,put}_kernel_nofault Date: Thu, 1 Oct 2020 16:12:31 +0200 Message-Id: <20201001141233.119343-9-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:6Pw+IdMtuuuRfExdV9J/hy/KpU2/RIytHtCrfwskoeMr5jufDuD 2sdNXOnzzFn3Cxx/yJ8Ek3CVmJh5Fd/A/gsGZb+DJGJIy0IXBCuv6Sth9pIq5SxKFBfeQQj qJVoteQfe//af/XjvJ9HEQ8XLs5T40KE/HRC3NFaoQmFLy9zRJbgFJeWRbZSLiYfnXJHUhC oNCw5jW5Ji3QahkkDBc6A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:EDxnNVS/DeY=:96E/HkW8eKf1LYRqSsWSyx A+k77fy+NVkx7qEBjMLIfJY2EK45wKGDtz1cl5rulbSlz3UacqmNpC/vwEDj97S06lg62dypZ zrDv8a/V3mVt1SCMZ5vZKRUXA7zBajOWH9A05Jx8x48AhhctDmEMzU7HvbG8jfyucursOlb8O ZHSpwqDuwj9hpdNcstGxY8lBikNR71gqrHFItFlT34nxWjKwb19tNILriRd3Eam79CU4m5tnh 8NWSmdMELjTurCOKdOauBO/4lySfhbDOYxl7jUKYNSsOce7KQVvkGWTU0CSt4KCmSdIpb6Hz2 I3+poKaTKGTbFHowzO5vc7thxgBZ9fIrGNVnvANlFKZoCUv1BWmWfM2P0wzSBGeMOIonOm/EW Twfy55oR0ehtb7eX2PSyOEYsVMaNgve2Ahslnd3vqkn+Ay919EeOYuSAAfOgoXRBQhqaUBp9e cTVoVwrYDiA3cnm8FewJfb/upkgkfO/NkUejJMSmw+dmlaokxN+VHjY6rHekVRcC98lhXqYxk vy0634nWv4ArA4ZAjyp+/Gs+bzuyR615PV72xdBW9ggPjGgcZAVFZIyBZWCedn1BoMAnnAKUe 4iH4ux/oYvw2U9Ex9UyZ7SOgC/kI20FyqATRnp5WDZEWKOR+UzhMuQ39iKhoZjU5VuExSgO+g 3FXnVto7XTH9ePJMvl1GGgBN3avo0FDu8hXiXMZpTDftJj8rUVGX6+dPSl+vCJ/uQ8Qp904q1 yOh5Xh2BoETIv4Ov0v6kastKWts5lswMHuju6MaGmdvT0T6SpuOrqKcD8vbsj13tsUXyEpvIW i1jpEj5u+DtXtXojbgTeGSw7bM+iDae5UdgNzfIJ+8WSDIqbwDyFkifVCNuTLZjt0kQtNXM 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: These mimic the behavior of get_user and put_user, except for domain switching, address limit checking and handling of mismatched sizes, none of which are relevant here. To work with pre-Armv6 kernels, this has to avoid TUSER() inside of the new macros, the new approach passes the "t" string along with the opcode, which is a bit uglier but avoids duplicating more code. As there is no __get_user_asm_dword(), I work around it by copying 32 bit at a time, which is possible because the output size is known. Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/uaccess.h | 123 ++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 40 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index a13d90206472..4f60638755c4 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -308,11 +308,11 @@ static inline void set_fs(mm_segment_t fs) #define __get_user(x, ptr) \ ({ \ long __gu_err = 0; \ - __get_user_err((x), (ptr), __gu_err); \ + __get_user_err((x), (ptr), __gu_err, TUSER()); \ __gu_err; \ }) -#define __get_user_err(x, ptr, err) \ +#define __get_user_err(x, ptr, err, __t) \ do { \ unsigned long __gu_addr = (unsigned long)(ptr); \ unsigned long __gu_val; \ @@ -321,18 +321,19 @@ do { \ might_fault(); \ __ua_flags = uaccess_save_and_enable(); \ switch (sizeof(*(ptr))) { \ - case 1: __get_user_asm_byte(__gu_val, __gu_addr, err); break; \ - case 2: __get_user_asm_half(__gu_val, __gu_addr, err); break; \ - case 4: __get_user_asm_word(__gu_val, __gu_addr, err); break; \ + case 1: __get_user_asm_byte(__gu_val, __gu_addr, err, __t); break; \ + case 2: __get_user_asm_half(__gu_val, __gu_addr, err, __t); break; \ + case 4: __get_user_asm_word(__gu_val, __gu_addr, err, __t); break; \ default: (__gu_val) = __get_user_bad(); \ } \ uaccess_restore(__ua_flags); \ (x) = (__typeof__(*(ptr)))__gu_val; \ } while (0) +#endif #define __get_user_asm(x, addr, err, instr) \ __asm__ __volatile__( \ - "1: " TUSER(instr) " %1, [%2], #0\n" \ + "1: " instr " %1, [%2], #0\n" \ "2:\n" \ " .pushsection .text.fixup,\"ax\"\n" \ " .align 2\n" \ @@ -348,40 +349,38 @@ do { \ : "r" (addr), "i" (-EFAULT) \ : "cc") -#define __get_user_asm_byte(x, addr, err) \ - __get_user_asm(x, addr, err, ldrb) +#define __get_user_asm_byte(x, addr, err, __t) \ + __get_user_asm(x, addr, err, "ldrb" __t) #if __LINUX_ARM_ARCH__ >= 6 -#define __get_user_asm_half(x, addr, err) \ - __get_user_asm(x, addr, err, ldrh) +#define __get_user_asm_half(x, addr, err, __t) \ + __get_user_asm(x, addr, err, "ldrh" __t) #else #ifndef __ARMEB__ -#define __get_user_asm_half(x, __gu_addr, err) \ +#define __get_user_asm_half(x, __gu_addr, err, __t) \ ({ \ unsigned long __b1, __b2; \ - __get_user_asm_byte(__b1, __gu_addr, err); \ - __get_user_asm_byte(__b2, __gu_addr + 1, err); \ + __get_user_asm_byte(__b1, __gu_addr, err, __t); \ + __get_user_asm_byte(__b2, __gu_addr + 1, err, __t); \ (x) = __b1 | (__b2 << 8); \ }) #else -#define __get_user_asm_half(x, __gu_addr, err) \ +#define __get_user_asm_half(x, __gu_addr, err, __t) \ ({ \ unsigned long __b1, __b2; \ - __get_user_asm_byte(__b1, __gu_addr, err); \ - __get_user_asm_byte(__b2, __gu_addr + 1, err); \ + __get_user_asm_byte(__b1, __gu_addr, err, __t); \ + __get_user_asm_byte(__b2, __gu_addr + 1, err, __t); \ (x) = (__b1 << 8) | __b2; \ }) #endif #endif /* __LINUX_ARM_ARCH__ >= 6 */ -#define __get_user_asm_word(x, addr, err) \ - __get_user_asm(x, addr, err, ldr) -#endif - +#define __get_user_asm_word(x, addr, err, __t) \ + __get_user_asm(x, addr, err, "ldr" __t) #define __put_user_switch(x, ptr, __err, __fn) \ do { \ @@ -425,7 +424,7 @@ do { \ #define __put_user_nocheck(x, __pu_ptr, __err, __size) \ do { \ unsigned long __pu_addr = (unsigned long)__pu_ptr; \ - __put_user_nocheck_##__size(x, __pu_addr, __err); \ + __put_user_nocheck_##__size(x, __pu_addr, __err, TUSER());\ } while (0) #define __put_user_nocheck_1 __put_user_asm_byte @@ -433,9 +432,11 @@ do { \ #define __put_user_nocheck_4 __put_user_asm_word #define __put_user_nocheck_8 __put_user_asm_dword +#endif /* !CONFIG_CPU_SPECTRE */ + #define __put_user_asm(x, __pu_addr, err, instr) \ __asm__ __volatile__( \ - "1: " TUSER(instr) " %1, [%2], #0\n" \ + "1: " instr " %1, [%2], #0\n" \ "2:\n" \ " .pushsection .text.fixup,\"ax\"\n" \ " .align 2\n" \ @@ -450,36 +451,36 @@ do { \ : "r" (x), "r" (__pu_addr), "i" (-EFAULT) \ : "cc") -#define __put_user_asm_byte(x, __pu_addr, err) \ - __put_user_asm(x, __pu_addr, err, strb) +#define __put_user_asm_byte(x, __pu_addr, err, __t) \ + __put_user_asm(x, __pu_addr, err, "strb" __t) #if __LINUX_ARM_ARCH__ >= 6 -#define __put_user_asm_half(x, __pu_addr, err) \ - __put_user_asm(x, __pu_addr, err, strh) +#define __put_user_asm_half(x, __pu_addr, err, __t) \ + __put_user_asm(x, __pu_addr, err, "strh" __t) #else #ifndef __ARMEB__ -#define __put_user_asm_half(x, __pu_addr, err) \ +#define __put_user_asm_half(x, __pu_addr, err, __t) \ ({ \ unsigned long __temp = (__force unsigned long)(x); \ - __put_user_asm_byte(__temp, __pu_addr, err); \ - __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \ + __put_user_asm_byte(__temp, __pu_addr, err, __t); \ + __put_user_asm_byte(__temp >> 8, __pu_addr + 1, err, __t);\ }) #else -#define __put_user_asm_half(x, __pu_addr, err) \ +#define __put_user_asm_half(x, __pu_addr, err, __t) \ ({ \ unsigned long __temp = (__force unsigned long)(x); \ - __put_user_asm_byte(__temp >> 8, __pu_addr, err); \ - __put_user_asm_byte(__temp, __pu_addr + 1, err); \ + __put_user_asm_byte(__temp >> 8, __pu_addr, err, __t); \ + __put_user_asm_byte(__temp, __pu_addr + 1, err, __t); \ }) #endif #endif /* __LINUX_ARM_ARCH__ >= 6 */ -#define __put_user_asm_word(x, __pu_addr, err) \ - __put_user_asm(x, __pu_addr, err, str) +#define __put_user_asm_word(x, __pu_addr, err, __t) \ + __put_user_asm(x, __pu_addr, err, "str" __t) #ifndef __ARMEB__ #define __reg_oper0 "%R2" @@ -489,12 +490,12 @@ do { \ #define __reg_oper1 "%R2" #endif -#define __put_user_asm_dword(x, __pu_addr, err) \ +#define __put_user_asm_dword(x, __pu_addr, err, __t) \ __asm__ __volatile__( \ - ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \ - ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \ - THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \ - THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \ + ARM( "1: str" __t " " __reg_oper1 ", [%1], #4\n" ) \ + ARM( "2: str" __t " " __reg_oper0 ", [%1]\n" ) \ + THUMB( "1: str" __t " " __reg_oper1 ", [%1]\n" ) \ + THUMB( "2: str" __t " " __reg_oper0 ", [%1, #4]\n" ) \ "3:\n" \ " .pushsection .text.fixup,\"ax\"\n" \ " .align 2\n" \ @@ -510,7 +511,49 @@ do { \ : "r" (x), "i" (-EFAULT) \ : "cc") -#endif /* !CONFIG_CPU_SPECTRE */ +#define HAVE_GET_KERNEL_NOFAULT + +#define __get_kernel_nofault(dst, src, type, err_label) \ +do { \ + const type *__pk_ptr = (src); \ + unsigned long __src = (unsigned long)(__pk_ptr); \ + type __val; \ + int __err = 0; \ + switch (sizeof(type)) { \ + case 1: __get_user_asm_byte(__val, __src, __err, ""); break; \ + case 2: __get_user_asm_half(__val, __src, __err, ""); break; \ + case 4: __get_user_asm_word(__val, __src, __err, ""); break; \ + case 8: { \ + u32 *__v32 = (u32*)&__val; \ + __get_user_asm_word(__v32[0], __src, __err, ""); \ + if (__err) \ + break; \ + __get_user_asm_word(__v32[1], __src+4, __err, ""); \ + break; \ + } \ + default: __err = __get_user_bad(); break; \ + } \ + *(type *)(dst) = __val; \ + if (__err) \ + goto err_label; \ +} while (0) + +#define __put_kernel_nofault(dst, src, type, err_label) \ +do { \ + const type *__pk_ptr = (dst); \ + unsigned long __dst = (unsigned long)__pk_ptr; \ + int __err = 0; \ + type __val = *(type *)src; \ + switch (sizeof(type)) { \ + case 1: __put_user_asm_byte(__val, __dst, __err, ""); break; \ + case 2: __put_user_asm_half(__val, __dst, __err, ""); break; \ + case 4: __put_user_asm_word(__val, __dst, __err, ""); break; \ + case 8: __put_user_asm_dword(__val, __dst, __err, ""); break; \ + default: __err = __put_user_bad(); break; \ + } \ + if (__err) \ + goto err_label; \ +} while (0) #ifdef CONFIG_MMU extern unsigned long __must_check From patchwork Thu Oct 1 14:12:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811517 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 975946CA for ; Thu, 1 Oct 2020 14:13:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C03B20872 for ; Thu, 1 Oct 2020 14:13:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C03B20872 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 3752B6B007B; Thu, 1 Oct 2020 10:12:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F3A5D6B0074; Thu, 1 Oct 2020 10:12:57 -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 A0DBA900002; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0119.hostedemail.com [216.40.44.119]) by kanga.kvack.org (Postfix) with ESMTP id 1BC6D6B006E for ; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id AE853181AE88A for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.13.vase08_5414e552719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 8DBE018144D51 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-Spam-Summary: 1,0,0,c6c978119f4271f4,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:41:355:379:541:800:960:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1534:1540:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3351:3740:3865:3866:3867:3870:3871:4250:4321:5007:6261:8784:10004:11026:11473:11657:11658:11914:12043:12160:12296:12297:12555:12895:12986:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21451:21627:30054,0,RBL:217.72.192.74:@arndb.de:.lbl8.mailshell.net-66.201.201.201 62.8.6.100;04y8iisjipkgmjmd43mi1jek539qxycepeu3bbeqirnwrqxzigisxn1upfzxjwa.c3pr9snuid3cafkwwmeaxmh8fymrqswjsdi1xa9jxjgkdfq3n85wmuj4q9tud9x.r-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:neutral,Custom_rules:0:0:0,LFtime:19,LUA_SUMMARY:none X-HE-Tag: vase08_5414e552719c X-Filterd-Recvd-Size: 3233 Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.74]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MfYDO-1kusF41PTs-00fzfk; Thu, 01 Oct 2020 16:12:54 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 09/10] ARM: provide a TASK_SIZE_MAX definition Date: Thu, 1 Oct 2020 16:12:32 +0200 Message-Id: <20201001141233.119343-10-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:DOv13eMPHGqZxsnqif/m3T728BfBiW7qrK545tQGFsrb67TUR3n 7fs2n1e5laks2MZCVMQQVC1K0fF+GjnDwY6oQsmjBjoLd2f9YmAbdG9jXPHlBQj/RZX8CcU E2uCvfGVtswAxxKV5jbZPMeAaY8cHzsVphcg4rjL+AXg+2Nag/2ozWU/GlMgZnlb7uLfLiH DoQlYgSLJ6ZLPRZPNRyVw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:12YauErV9iU=:TZwvRNoGMGw5djDk2HmyRa UWQe8fCOetDIAV+KKYlye+zJA/In/18cThHGpcQh0D9HPmf3SskcnOhNE9t0793eJ24DZap3K uhTbM8OhF5aayQi8dR2sDdYVMIp4LAgzAvO6SycJkvaXxOQ383GZBEA3XwB3fBljAr6igjFYH SyOrZ3jgO8lLdmo0uxYx9rAopH+hs4Lx92KE/oBPjxnphzvOk5cMs4og4Yyy3fbCZrKrBccUn 65ap1JVwcBL5/8fy+ZFWK0blWlz8GoWU5PEcjTUV8nqWV9NX8Hfu+tlfmStRUzECdc1cq+zca I8RDzqQYlkVnrQMc0hgbpIQuwnFH1EF9DnGCK5uuH70RIF5NFHZPXuALCFn/seJO6a/EZAODt Vsp632APiOepMYYMj0UAkmsSvhYrUNghiFzBs4FpUM48+xpdf6WRNZi3jfM9gCxz9WvAZcdmu OCPnPFNb3JIlnCzI2dh2iTKfYSXY/mWB7l5XVsJdA4IQqAmncpUbu4IXoITrQFl7xAdmSV9yq UIkuZ8tLyOtQUCQU8JlprBRbYzJGHwlFfdW7ajO67G8q34cO11caDG09Ey6o4Fo99HTtn+Nbs 0ObcBGDz4iXU5OUYT6vRC3hgo8iVwmogy62ve0ulTUue2dE2mvKuTNwCuDhP4isM6XVrAADw1 yIG4W6u0UeHMR55UzugDQPzmqolne9ytc0VCVA01om0AgIul0UsrKy83HrWUND620LHfeSZx0 8XjfvP2grTlNSWF2RUbI3k5fb2omHv/8CeA5vbMAmQfaaoc7UHf68NjaYBWo1bWgumbXxGZzo QVLryn5PDC3SDp3LNw9GFhGvvTIGIqKyYbNB75t8DNWQpJqf4zCSdrTh9El1xuKdd/fAydx 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: Define TASK_SIZE_MAX to allow building without CONFIG_SET_FS Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/memory.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h index 99035b5891ef..285b32fd1a12 100644 --- a/arch/arm/include/asm/memory.h +++ b/arch/arm/include/asm/memory.h @@ -29,6 +29,7 @@ * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area */ #define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M)) +#define TASK_SIZE_MAX TASK_SIZE #define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) /* @@ -91,6 +92,7 @@ extern unsigned long vectors_base; * Fortunately, there is no reference for this in noMMU mode, for now. */ #define TASK_SIZE UL(0xffffffff) +#define TASK_SIZE_MAX TASK_SIZE #ifndef TASK_UNMAPPED_BASE #define TASK_UNMAPPED_BASE UL(0x00000000) From patchwork Thu Oct 1 14:12:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11811519 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 ACE4A92C for ; Thu, 1 Oct 2020 14:13:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53AA42087D for ; Thu, 1 Oct 2020 14:13:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53AA42087D 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 686B5900002; Thu, 1 Oct 2020 10:12:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2DC4D6B0078; Thu, 1 Oct 2020 10:12:58 -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 C277B900005; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id 43C336B007B for ; Thu, 1 Oct 2020 10:12:57 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D1355824999B for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-FDA: 77323547952.18.vest53_550fa082719c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id A0C23100ED3D4 for ; Thu, 1 Oct 2020 14:12:56 +0000 (UTC) X-Spam-Summary: 1,0,0,d7c4f8b8bf7f3d46,d41d8cd98f00b204,arnd@arndb.de,,RULES_HIT:1:41:69:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1605:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:2637:2693:2899:2901:3138:3139:3140:3141:3142:3865:3866:3867:3870:3871:3872:3874:4250:4321:4605:5007:6119:6261:7903:8603:8660:9592:10004:11026:11232:11473:11657:11658:11914:12043:12160:12296:12297:12438:12555:12683:12895:12986:13148:13161:13229:13230:13894:13972:14394:21080:21433:21451:21611:21627:21740:21795:21939:21990:30003:30012:30045:30051:30054:30069:30070,0,RBL:212.227.17.10:@arndb.de:.lbl8.mailshell.net-62.8.6.100 66.201.201.201;04yroh157oyojqedk8tiqzbxiesyeypqemmh9y5gqdpf3g633ms8mgy6nn5kdkb.ey4kx5w8q6168f4yrej4cn7xso3b49nm4gzn6qp91akgqmy14r3uc8k7dnratjr.6-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:neutral,Custom_rules:0:0:0,LFtime:19,LUA_SUMMARY:none X-HE-Tag: vest53_550fa082719c X-Filterd-Recvd-Size: 14076 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 1 Oct 2020 14:12:55 +0000 (UTC) Received: from threadripper.lan ([46.223.126.90]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1N6svJ-1kTY2z35jT-018LMt; Thu, 01 Oct 2020 16:12:54 +0200 From: Arnd Bergmann To: Russell King , Christoph Hellwig Cc: Alexander Viro , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Arnd Bergmann Subject: [PATCH v3 10/10] ARM: uaccess: remove set_fs() implementation Date: Thu, 1 Oct 2020 16:12:33 +0200 Message-Id: <20201001141233.119343-11-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201001141233.119343-1-arnd@arndb.de> References: <20201001141233.119343-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:c7n0899ba8d89RLFZcbAnXcastoMvP/Hnya1NwGppWzA7LX+6tV K/Rpy0z8l8UnvUaL9Jq7NFahgP+9gQAg+aGw3QxEOxk6lxFUJczIuKqvzbgZWX3qLFi6rqv RQoRLkb0/PeJSdpiXfjdx/WMheBYzcwiQTkvPD1TsQ1bjwyB/D/H11Myzet6r+tSTathaYd vYp/jVf4G/7wk+E8HzVOg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:sU6SUszacMQ=:A4WOI1kzbArwynTSMwPbdk cxeOyZYokJRfXyLfRpwokvTkMf1GAMJcUbYRvQ2E4N1lnBwOS6QgLVI/faFAo5ZJ24N8Jwile UCNiVccw7nYYTCPn0G48IG0Az/pAPaYq/9PBWnYjKbEWYF0puWBGRfdY68x7yZReIohpwwj6f hid6GiLJDlS0nvd+WYsUqAK0TNvSc7Z/Laa2LmoZVfOlXC28exFuWMMYXORjv3sTUIt4vBaFu jMLjiwbCwZrV9z0fEIkIk0Lopys9DhRa2ZQ+oBxPkSh7MrV81Zr5yLXcUuUR0EnZtkzQoyB39 SD/UW8fy507LibkfnSIkOc9V+nRGBsXyswUszUZVkbc1mlzjudOJwupYJNFHChoDXnBJVWUey c0tKfqZhFDfa9/gkjcevYa+xHl5LjMDppDZl104CHIenx/a2dPGqCXDxvd19fojix8ZpbXhXq 1NQ4/hcs80EpCChHa33gds2+HIL70pQdV5nxdcSzAXj7AZ6I6Y/TYd2pPIpGGIN0np1fpDj56 YE/1kgP63VVyoisv8H3JfKIHKSPOWLKxvmC9mChk3R3F3qmT19jmdfljqmflRxZJeOcTpRS2m RB51Jomy8qEIMD6BIBVYb1Vnt8vsLyUETNy8IrP0lGqzzVaiEt6h5SQt0TZV3D7CW2TXtrOLM 26+10ef5VY4InfP1DBlIz4AUPV02w71zb6ngGtyCmPaukbW/TWAY9sFMhPLLx/RCAPXBXbrme 4v3ops1EXzbJRko2Zd1dm0UwULNzt4pQs0auhuvgjkvv0H5iOOS14YA48UzwB2QNwbhAiXg9B Z1uc4IRgj1ihZX+USgUdrBhPd9Q1IkIrYW1zE/ejGhKgoUv6dbKrZLtszcsl/ISAQJ8ce2E 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: There are no remaining callers of set_fs(), so just remove it along with all associated code that operates on thread_info->addr_limit. There are still further optimizations that can be done: - In get_user(), the address check could be moved entirely into the out of line code, rather than passing a constant as an argument, - I assume the DACR handling can be simplified as we now only change it during user access when CONFIG_CPU_SW_DOMAIN_PAN is set, but not during set_fs(). Signed-off-by: Arnd Bergmann --- arch/arm/Kconfig | 1 - arch/arm/include/asm/ptrace.h | 1 - arch/arm/include/asm/thread_info.h | 4 --- arch/arm/include/asm/uaccess-asm.h | 6 ---- arch/arm/include/asm/uaccess.h | 46 +++--------------------------- arch/arm/kernel/asm-offsets.c | 2 -- arch/arm/kernel/entry-common.S | 9 ------ arch/arm/kernel/process.c | 7 +---- arch/arm/kernel/signal.c | 8 ------ arch/arm/lib/copy_from_user.S | 3 +- arch/arm/lib/copy_to_user.S | 3 +- 11 files changed, 7 insertions(+), 83 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 87e1478a42dc..e00d94b16658 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -118,7 +118,6 @@ config ARM select PCI_SYSCALL if PCI select PERF_USE_VMALLOC select RTC_LIB - select SET_FS select SYS_SUPPORTS_APM_EMULATION # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 91d6b7856be4..93051e2f402c 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -19,7 +19,6 @@ struct pt_regs { struct svc_pt_regs { struct pt_regs regs; u32 dacr; - u32 addr_limit; }; #define to_svc_pt_regs(r) container_of(r, struct svc_pt_regs, regs) diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h index 536b6b979f63..8b705f611216 100644 --- a/arch/arm/include/asm/thread_info.h +++ b/arch/arm/include/asm/thread_info.h @@ -23,8 +23,6 @@ struct task_struct; #include -typedef unsigned long mm_segment_t; - struct cpu_context_save { __u32 r4; __u32 r5; @@ -46,7 +44,6 @@ struct cpu_context_save { struct thread_info { unsigned long flags; /* low level flags */ int preempt_count; /* 0 => preemptable, <0 => bug */ - mm_segment_t addr_limit; /* address limit */ struct task_struct *task; /* main task structure */ __u32 cpu; /* cpu */ __u32 cpu_domain; /* cpu domain */ @@ -72,7 +69,6 @@ struct thread_info { .task = &tsk, \ .flags = 0, \ .preempt_count = INIT_PREEMPT_COUNT, \ - .addr_limit = KERNEL_DS, \ } /* diff --git a/arch/arm/include/asm/uaccess-asm.h b/arch/arm/include/asm/uaccess-asm.h index 907571fd05c6..6451a433912c 100644 --- a/arch/arm/include/asm/uaccess-asm.h +++ b/arch/arm/include/asm/uaccess-asm.h @@ -84,12 +84,8 @@ * if \disable is set. */ .macro uaccess_entry, tsk, tmp0, tmp1, tmp2, disable - ldr \tmp1, [\tsk, #TI_ADDR_LIMIT] - mov \tmp2, #TASK_SIZE - str \tmp2, [\tsk, #TI_ADDR_LIMIT] DACR( mrc p15, 0, \tmp0, c3, c0, 0) DACR( str \tmp0, [sp, #SVC_DACR]) - str \tmp1, [sp, #SVC_ADDR_LIMIT] .if \disable && IS_ENABLED(CONFIG_CPU_SW_DOMAIN_PAN) /* kernel=client, user=no access */ mov \tmp2, #DACR_UACCESS_DISABLE @@ -106,9 +102,7 @@ /* Restore the user access state previously saved by uaccess_entry */ .macro uaccess_exit, tsk, tmp0, tmp1 - ldr \tmp1, [sp, #SVC_ADDR_LIMIT] DACR( ldr \tmp0, [sp, #SVC_DACR]) - str \tmp1, [\tsk, #TI_ADDR_LIMIT] DACR( mcr p15, 0, \tmp0, c3, c0, 0) .endm diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index 4f60638755c4..084d1c07c2d0 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -52,32 +52,8 @@ static __always_inline void uaccess_restore(unsigned int flags) extern int __get_user_bad(void); extern int __put_user_bad(void); -/* - * Note that this is actually 0x1,0000,0000 - */ -#define KERNEL_DS 0x00000000 - #ifdef CONFIG_MMU -#define USER_DS TASK_SIZE -#define get_fs() (current_thread_info()->addr_limit) - -static inline void set_fs(mm_segment_t fs) -{ - current_thread_info()->addr_limit = fs; - - /* - * Prevent a mispredicted conditional call to set_fs from forwarding - * the wrong address limit to access_ok under speculation. - */ - dsb(nsh); - isb(); - - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER); -} - -#define uaccess_kernel() (get_fs() == KERNEL_DS) - /* * We use 33-bit arithmetic here. Success returns zero, failure returns * addr_limit. We take advantage that addr_limit will be zero for KERNEL_DS, @@ -89,7 +65,7 @@ static inline void set_fs(mm_segment_t fs) __asm__(".syntax unified\n" \ "adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \ : "=&r" (flag), "=&r" (roksum) \ - : "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \ + : "r" (addr), "Ir" (size), "0" (TASK_SIZE) \ : "cc"); \ flag; }) @@ -120,7 +96,7 @@ static inline void __user *__uaccess_mask_range_ptr(const void __user *ptr, " subshs %1, %1, %2\n" " movlo %0, #0\n" : "+r" (safe_ptr), "=&r" (tmp) - : "r" (size), "r" (current_thread_info()->addr_limit) + : "r" (size), "r" (TASK_SIZE) : "cc"); csdb(); @@ -194,7 +170,7 @@ extern int __get_user_64t_4(void *); #define __get_user_check(x, p) \ ({ \ - unsigned long __limit = current_thread_info()->addr_limit - 1; \ + unsigned long __limit = TASK_SIZE - 1; \ register typeof(*(p)) __user *__p asm("r0") = (p); \ register __inttype(x) __r2 asm("r2"); \ register unsigned long __l asm("r1") = __limit; \ @@ -245,7 +221,7 @@ extern int __put_user_8(void *, unsigned long long); #define __put_user_check(__pu_val, __ptr, __err, __s) \ ({ \ - unsigned long __limit = current_thread_info()->addr_limit - 1; \ + unsigned long __limit = TASK_SIZE - 1; \ register typeof(__pu_val) __r2 asm("r2") = __pu_val; \ register const void __user *__p asm("r0") = __ptr; \ register unsigned long __l asm("r1") = __limit; \ @@ -262,19 +238,8 @@ extern int __put_user_8(void *, unsigned long long); #else /* CONFIG_MMU */ -/* - * uClinux has only one addr space, so has simplified address limits. - */ -#define USER_DS KERNEL_DS - -#define uaccess_kernel() (true) #define __addr_ok(addr) ((void)(addr), 1) #define __range_ok(addr, size) ((void)(addr), 0) -#define get_fs() (KERNEL_DS) - -static inline void set_fs(mm_segment_t fs) -{ -} #define get_user(x, p) __get_user(x, p) #define __put_user_check __put_user_nocheck @@ -283,9 +248,6 @@ static inline void set_fs(mm_segment_t fs) #define access_ok(addr, size) (__range_ok(addr, size) == 0) -#define user_addr_max() \ - (uaccess_kernel() ? ~0UL : get_fs()) - #ifdef CONFIG_CPU_SPECTRE /* * When mitigating Spectre variant 1, it is not worth fixing the non- diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c index 97af6735172b..78f0a25baf2d 100644 --- a/arch/arm/kernel/asm-offsets.c +++ b/arch/arm/kernel/asm-offsets.c @@ -41,7 +41,6 @@ int main(void) BLANK(); DEFINE(TI_FLAGS, offsetof(struct thread_info, flags)); DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count)); - DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit)); DEFINE(TI_TASK, offsetof(struct thread_info, task)); DEFINE(TI_CPU, offsetof(struct thread_info, cpu)); DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain)); @@ -90,7 +89,6 @@ int main(void) DEFINE(S_OLD_R0, offsetof(struct pt_regs, ARM_ORIG_r0)); DEFINE(PT_REGS_SIZE, sizeof(struct pt_regs)); DEFINE(SVC_DACR, offsetof(struct svc_pt_regs, dacr)); - DEFINE(SVC_ADDR_LIMIT, offsetof(struct svc_pt_regs, addr_limit)); DEFINE(SVC_REGS_SIZE, sizeof(struct svc_pt_regs)); BLANK(); DEFINE(SIGFRAME_RC3_OFFSET, offsetof(struct sigframe, retcode[3])); diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index 9a76467bbb47..2c0bde14fba6 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -49,9 +49,6 @@ __ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) disable_irq_notrace @ disable interrupts - ldr r2, [tsk, #TI_ADDR_LIMIT] - cmp r2, #TASK_SIZE - blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK bne fast_work_pending @@ -86,9 +83,6 @@ __ret_fast_syscall: bl do_rseq_syscall #endif disable_irq_notrace @ disable interrupts - ldr r2, [tsk, #TI_ADDR_LIMIT] - cmp r2, #TASK_SIZE - blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK beq no_work_pending @@ -127,9 +121,6 @@ ret_slow_syscall: #endif disable_irq_notrace @ disable interrupts ENTRY(ret_to_user_from_irq) - ldr r2, [tsk, #TI_ADDR_LIMIT] - cmp r2, #TASK_SIZE - blne addr_limit_check_failed ldr r1, [tsk, #TI_FLAGS] tst r1, #_TIF_WORK_MASK bne slow_work_pending diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index 8e6ace03e960..28a1a4a9dd77 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -97,7 +97,7 @@ void __show_regs(struct pt_regs *regs) unsigned long flags; char buf[64]; #ifndef CONFIG_CPU_V7M - unsigned int domain, fs; + unsigned int domain; #ifdef CONFIG_CPU_SW_DOMAIN_PAN /* * Get the domain register for the parent context. In user @@ -106,14 +106,11 @@ void __show_regs(struct pt_regs *regs) */ if (user_mode(regs)) { domain = DACR_UACCESS_ENABLE; - fs = get_fs(); } else { domain = to_svc_pt_regs(regs)->dacr; - fs = to_svc_pt_regs(regs)->addr_limit; } #else domain = get_domain(); - fs = get_fs(); #endif #endif @@ -149,8 +146,6 @@ void __show_regs(struct pt_regs *regs) if ((domain & domain_mask(DOMAIN_USER)) == domain_val(DOMAIN_USER, DOMAIN_NOACCESS)) segment = "none"; - else if (fs == KERNEL_DS) - segment = "kernel"; else segment = "user"; diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c index c9dc912b83f0..618b5d938317 100644 --- a/arch/arm/kernel/signal.c +++ b/arch/arm/kernel/signal.c @@ -710,14 +710,6 @@ struct page *get_signal_page(void) return page; } -/* Defer to generic check */ -asmlinkage void addr_limit_check_failed(void) -{ -#ifdef CONFIG_MMU - addr_limit_user_check(); -#endif -} - #ifdef CONFIG_DEBUG_RSEQ asmlinkage void do_rseq_syscall(struct pt_regs *regs) { diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S index f8016e3db65d..f481ef789a93 100644 --- a/arch/arm/lib/copy_from_user.S +++ b/arch/arm/lib/copy_from_user.S @@ -109,8 +109,7 @@ ENTRY(arm_copy_from_user) #ifdef CONFIG_CPU_SPECTRE - get_thread_info r3 - ldr r3, [r3, #TI_ADDR_LIMIT] + mov r3, #TASK_SIZE uaccess_mask_range_ptr r1, r2, r3, ip #endif diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S index ebfe4cb3d912..215da16c7d6e 100644 --- a/arch/arm/lib/copy_to_user.S +++ b/arch/arm/lib/copy_to_user.S @@ -109,8 +109,7 @@ ENTRY(__copy_to_user_std) WEAK(arm_copy_to_user) #ifdef CONFIG_CPU_SPECTRE - get_thread_info r3 - ldr r3, [r3, #TI_ADDR_LIMIT] + mov r3, #TASK_SIZE uaccess_mask_range_ptr r0, r2, r3, ip #endif