From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07EA9C433F5 for ; Fri, 18 Feb 2022 18:07:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D36A6B0074; Fri, 18 Feb 2022 13:07:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 47F7E6B0075; Fri, 18 Feb 2022 13:07:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D2826B0078; Fri, 18 Feb 2022 13:07:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 1A35F6B0074 for ; Fri, 18 Feb 2022 13:07:21 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C7E9D8248D52 for ; Fri, 18 Feb 2022 18:07:20 +0000 (UTC) X-FDA: 79156682640.17.7029F58 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf16.hostedemail.com (Postfix) with ESMTP id 45779180010 for ; Fri, 18 Feb 2022 18:07:20 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id cm8so7199335edb.3 for ; Fri, 18 Feb 2022 10:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3DIqXxPmp6dtbTijOx2KTFQ/AdtfYUTWecKVh7q3dDI=; b=5c/qRto3YK3Y6/Rhnnpp4RzKmf8QhiKseObhkqXIpnLfhpnv2ua8Z7YCExbmjSYUCG SbBSycxSpm4FRe5zOaxst92xyRDLRie0B4d4p8x0W6snNr+dG6MghxLfcakTWMQA17Pf gOp7JS9gIpdJumtDaMv9IluyX8dB5LI5eLR/YC2U+D7T5N3aQr9NOYHAOP982E02xanw SC1uTLhbyKEp3+LiMa1bFSquyveVGLxTCPf/eSvmTiEZzxEI+wIe4AMdv5VgRD2GYf6G kO3gnVVxKK1wWuKxjcQ5nhLyDgmj/c1nxTJoqfRQTmuVCBNlEZ4IpVOo74LURbiOVsEg CBWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3DIqXxPmp6dtbTijOx2KTFQ/AdtfYUTWecKVh7q3dDI=; b=qZZhSssR9q6JRIDn4tttvY6FA7XmKQgaQ/9bEUp85CtYxZD36OzExekXZYlwB56uqW uo0ZDs7+mpdj3bwVOONupnRUbJ9jDTogMBMOKOIk8diSQEkRgpNiseGuh4pXIC5KBLNw ofGt2+iRjJX1laocoRn3rmKBV9zZMOgj0F+VGPjGDhv/kpf/UMHOsq3Ini3j/JcAlPKH CGvGxwQbiRslvXQ/V+SOWMp+6JkloJQ3hMRcQeBUQ7qhOKVzaoEBBk46LlwC1eBT4KeY BRqVl5QdfEVocG6livpX+Kxdpz54hEtbtNmS5mloxN4E+wjZjFSlsa9ZwaCz7NZOGSfb FRrw== X-Gm-Message-State: AOAM533rCIYaBhf9uKSwN3KJ8Xe3wW5MvZWBtANUDY8QyR3ncrJ7fDWV pTAobtg80/qNrSRkgr5VHa0NE7vdxzrlBmJWlv2yEw== X-Google-Smtp-Source: ABdhPJzKi9/dAquBFvy+ZlpESpcVBT1I3X4XtLJClo2SaEqFpqb8kdqwnL9Fphl8e/qcsjqeDfp/tX4JIrAspWajnck= X-Received: by 2002:a05:6402:430f:b0:410:a082:c6da with SMTP id m15-20020a056402430f00b00410a082c6damr9386454edc.438.1645207638871; Fri, 18 Feb 2022 10:07:18 -0800 (PST) MIME-Version: 1.0 References: <20220216131332.1489939-1-arnd@kernel.org> <20220216131332.1489939-14-arnd@kernel.org> <93a1ee797e9d4f789dff85a3c0f0c232@AcuMS.aculab.com> In-Reply-To: <93a1ee797e9d4f789dff85a3c0f0c232@AcuMS.aculab.com> From: Andy Lutomirski Date: Fri, 18 Feb 2022 10:07:07 -0800 Message-ID: Subject: Re: [PATCH v2 13/18] uaccess: generalize access_ok() To: David Laight Cc: Arnd Bergmann , Linus Torvalds , Christoph Hellwig , "linux-arch@vger.kernel.org" , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , "arnd@arndb.de" , "linux-kernel@vger.kernel.org" , "viro@zeniv.linux.org.uk" , "linux@armlinux.org.uk" , "will@kernel.org" , "guoren@kernel.org" , "bcain@codeaurora.org" , "geert@linux-m68k.org" , "monstr@monstr.eu" , "tsbogend@alpha.franken.de" , "nickhu@andestech.com" , "green.hu@gmail.com" , "dinguyen@kernel.org" , "shorne@gmail.com" , "deller@gmx.de" , "mpe@ellerman.id.au" , "peterz@infradead.org" , "mingo@redhat.com" , "mark.rutland@arm.com" , "hca@linux.ibm.com" , "dalias@libc.org" , "davem@davemloft.net" , "richard@nod.at" , "x86@kernel.org" , "jcmvbkbc@gmail.com" , "ebiederm@xmission.com" , "akpm@linux-foundation.org" , "ardb@kernel.org" , "linux-alpha@vger.kernel.org" , "linux-snps-arc@lists.infradead.org" , "linux-csky@vger.kernel.org" , "linux-hexagon@vger.kernel.org" , "linux-ia64@vger.kernel.org" , "linux-m68k@lists.linux-m68k.org" , "linux-mips@vger.kernel.org" , "openrisc@lists.librecores.org" , "linux-parisc@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "linux-sh@vger.kernel.org" , "sparclinux@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-xtensa@linux-xtensa.org" Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 45779180010 X-Stat-Signature: 3cdrasqxd768kyu3u67hxd9wn5hdiej3 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amacapital-net.20210112.gappssmtp.com header.s=20210112 header.b="5c/qRto3"; spf=pass (imf16.hostedemail.com: domain of luto@amacapital.net designates 209.85.208.46 as permitted sender) smtp.mailfrom=luto@amacapital.net; dmarc=none X-Rspam-User: X-HE-Tag: 1645207640-698701 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 Fri, Feb 18, 2022 at 1:30 AM David Laight wrote: > > From: Andy Lutomirski > > Sent: 17 February 2022 19:15 > ... > > This isn't actually optimal. On x86, TASK_SIZE_MAX is a bizarre > > constant that has a very specific value to work around a bug^Wdesign > > error^Wfeature of Intel CPUs. TASK_SIZE_MAX is the maximum address at > > which userspace is permitted to allocate memory, but there is a huge > > gap between user and kernel addresses, and any value in the gap would > > be adequate for the comparison. If we wanted to optimize this, simply > > checking the high bit (which x86 can do without any immediate > > constants at all) would be sufficient and, for an access known to fit > > in 32 bits, one could get even fancier and completely ignore the size > > of the access. (For accesses not known to fit in 32 bits, I suspect > > some creativity could still come up with a construction that's > > substantially faster than the one in your patch.) > > > > So there's plenty of room for optimization here. > > > > (This is not in any respect a NAK -- it's just an observation that > > this could be even better.) > > For 64bit arch that use the top bit to separate user/kernel > you can test '(addr | size) >> 62)'. > The compiler optimises out constant sizes. > > This has all been mentioned a lot of times. > You do get different fault types. > > OTOH an explicit check for constant size (less than something big) > can use the cheaper test of the sign bit. > Big constant sizes could be compile time errors. The different fault type issue may well be a real problem. Right now the core x86 fault code reserves the right to grouch if we get #GP instead of #PF. We could change that.