Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp2087245pxb; Sat, 19 Feb 2022 01:47:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoWyNcmL0foOSzP0m0JGmmezTbWBiR0IfiW/WVmeEj2V1pPOEv8nla3/IJAwUi2D2WA4v0 X-Received: by 2002:a17:902:c612:b0:14d:d67a:82f3 with SMTP id r18-20020a170902c61200b0014dd67a82f3mr11091182plr.155.1645264077287; Sat, 19 Feb 2022 01:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645264077; cv=none; d=google.com; s=arc-20160816; b=Y/My+ZNw8QtCTm/fdjt6zKpY2JObQuJ3H4iG5oY2CvzpBdDLCIwDd3zqisIenO2aas WsqiRi0mHe9NFeNZPHC6b9VaoKMCjdNWL0lyz4vrzmUTX/iXb/ysC1pl+iVBJ7LkZXHu X7I6fk/wSI/DoTut36uiOIfnLMzl66tf4UckfrJxjSq4qvwgapzbmGr3QGmmcdOSX2wB UA80iOwVvxaJ8j1H+9Az+XROPqOnPoaHNb+mWKULqkHR3oGlnZh0lY3zVUNJi2d8z2T9 FHRbx809d9AQdjiaKJ6jIVRStM9FhJ3SQAaDCq/2OF72jS1curLgqZnfd5TOBmf15ADy h8wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3DIqXxPmp6dtbTijOx2KTFQ/AdtfYUTWecKVh7q3dDI=; b=HsRglnBEerJRK8QBHzt/p1S6BgnuWYU2AYhBJUF1rV7TucZSusVVeSUEQ5oKKexqaS jgIfHaKj244pKAT4+oHf2+Hv96P1PgX36cgYdLyNHxZ4qZpmdMv49j0yWsh8rJIjymbV WypLCfNchgvUia4l72cExkERfxQlZSxb9UpHVtSevz9PGJrKfbvA2eQ9sntLOzorpvPk eDaNk0+uK9KPy/T9loY45fL6ajDx0jXYSXy78DWEUmxcG4BiJrNojyo83xLIZ4KPu4+g 6/TgVIPEy8ELVLyVLNHyvJcyav81NVubEXzlYCzBFQ42bOUmCKj5uK3PBYKlGtpEyPUM xJ5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20210112.gappssmtp.com header.s=20210112 header.b="5c/qRto3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l10si14615576pgp.598.2022.02.19.01.47.42; Sat, 19 Feb 2022 01:47:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20210112.gappssmtp.com header.s=20210112 header.b="5c/qRto3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238962AbiBRSHj (ORCPT + 99 others); Fri, 18 Feb 2022 13:07:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238926AbiBRSHh (ORCPT ); Fri, 18 Feb 2022 13:07:37 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 546F71D6866 for ; Fri, 18 Feb 2022 10:07:20 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id m17so16759330edc.13 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=02k2Go6z1FOiOkgS/X3GJ1cf/1Dk4CLfXlghTcCfuo/QOWc94SIA6hQVgzqv6BkQ0k rIrwxl+n5ULlJlLJpYaiuYUBqaZlfFbGhqqCeEQreK0xU4SfbmVZ0RekM6hmrV8Zvt4e HzHJExyxVs5M30qMFD60evmTn54C0YBj9bO+aPCcim+h4Mffl6rQ6fWocnCMeAyw/v6A XAE3HQCYfCm6JnfGH+DtVuyeQoWLnaQ0gUetlIpjr0nvbnkfYBpravqzKryewLtVmn7k VQRnshta8G5EWawewEEsJxB65lvMRCIKuJbUsZFaWxx91OnDCCrwIHCO4ylHNYkSHvOG /+AA== X-Gm-Message-State: AOAM530IHtcAmtcB+dRqtCVF/iDSdILCzPvKCT2UIo2XBW/dKPVWH5kp 6O3REu0/FKUhhdFVDnGPirwjHFbSrLAT2BU5cEeunw== 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.