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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1057DC3A5A4 for ; Fri, 30 Aug 2019 09:41:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BCAC021670 for ; Fri, 30 Aug 2019 09:41:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="WD3CvYLK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCAC021670 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TcltfdtuBqKtzidsNkIBYxd9THL7wXuoGAzFdcnVTsk=; b=WD3CvYLKip8eZZ dteiPtkYnEJlOkCTbaeHA3l1hgPhHwUKVm6HWC87kowZHe8p11ToEUYg1CFXN/hl/9AS64T9+e5Dk GLQUD7aTatAc8FMHIRxSH8WA5f1ImBqxb75s05ucJQGC8F/BYNwmSY6Pj/dM+519iF5MwhP8DBsXA 8CFKRYso8YpZHAhvEWVmfYTCbJUbUGrWHVLrXyUd+4a7b/Hv1yToGR4Ms3MdIfVoz+m0dIlg7eEYE 01D3qxKfrkVYnmV9JjSZmIzKLrth7Kbouo/8UxDu6I3GldBMat5rmLyR+kxgHRkF8HudHyU7s73Tg xVaBxKwxmrd+JHDf+9Nw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i3dPn-0003hK-3v; Fri, 30 Aug 2019 09:41:55 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i3dP0-0002xO-Hq for linux-arm-kernel@lists.infradead.org; Fri, 30 Aug 2019 09:41:08 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 39120344; Fri, 30 Aug 2019 02:41:06 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D989D3F718; Fri, 30 Aug 2019 02:41:04 -0700 (PDT) Date: Fri, 30 Aug 2019 10:41:02 +0100 From: Mark Rutland To: Viresh Kumar Subject: Re: [PATCH ARM64 v4.4 V3 08/44] arm64: uaccess: Don't bother eliding access_ok checks in __{get, put}_user Message-ID: <20190830094102.GH46475@lakrids.cambridge.arm.com> References: <40fe1d91c9cd8d78ae952b821185681621f92b10.1567077734.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <40fe1d91c9cd8d78ae952b821185681621f92b10.1567077734.git.viresh.kumar@linaro.org> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190830_024106_777743_662E88D8 X-CRM114-Status: GOOD ( 16.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Thierry , Marc Zyngier , Catalin Marinas , Will Deacon , stable@vger.kernel.org, mark.brown@arm.com, Russell King , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Aug 29, 2019 at 05:03:53PM +0530, Viresh Kumar wrote: > From: Will Deacon > > commit 84624087dd7e3b482b7b11c170ebc1f329b3a218 upstream. > > access_ok isn't an expensive operation once the addr_limit for the current > thread has been loaded into the cache. Given that the initial access_ok > check preceding a sequence of __{get,put}_user operations will take > the brunt of the miss, we can make the __* variants identical to the > full-fat versions, which brings with it the benefits of address masking. > > The likely cost in these sequences will be from toggling PAN/UAO, which > we can address later by implementing the *_unsafe versions. > > Reviewed-by: Robin Murphy > Signed-off-by: Will Deacon > Signed-off-by: Catalin Marinas > [ v4.4: Fixed conflicts around {__get_user|__put_user}_unaligned macros ] > Signed-off-by: Viresh Kumar > --- Reviewed-by: Mark Rutland [v4.4 backport] Mark. > arch/arm64/include/asm/uaccess.h | 62 ++++++++++++++++++-------------- > 1 file changed, 36 insertions(+), 26 deletions(-) > > diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h > index fc11c50af558..a34324436ce1 100644 > --- a/arch/arm64/include/asm/uaccess.h > +++ b/arch/arm64/include/asm/uaccess.h > @@ -200,30 +200,35 @@ do { \ > CONFIG_ARM64_PAN)); \ > } while (0) > > -#define __get_user(x, ptr) \ > +#define __get_user_check(x, ptr, err) \ > ({ \ > - int __gu_err = 0; \ > - __get_user_err((x), (ptr), __gu_err); \ > - __gu_err; \ > + __typeof__(*(ptr)) __user *__p = (ptr); \ > + might_fault(); \ > + if (access_ok(VERIFY_READ, __p, sizeof(*__p))) { \ > + __p = uaccess_mask_ptr(__p); \ > + __get_user_err((x), __p, (err)); \ > + } else { \ > + (x) = 0; (err) = -EFAULT; \ > + } \ > }) > > #define __get_user_error(x, ptr, err) \ > ({ \ > - __get_user_err((x), (ptr), (err)); \ > + __get_user_check((x), (ptr), (err)); \ > (void)0; \ > }) > > -#define __get_user_unaligned __get_user > - > -#define get_user(x, ptr) \ > +#define __get_user(x, ptr) \ > ({ \ > - __typeof__(*(ptr)) __user *__p = (ptr); \ > - might_fault(); \ > - access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \ > - __p = uaccess_mask_ptr(__p), __get_user((x), __p) : \ > - ((x) = 0, -EFAULT); \ > + int __gu_err = 0; \ > + __get_user_check((x), (ptr), __gu_err); \ > + __gu_err; \ > }) > > +#define __get_user_unaligned __get_user > + > +#define get_user __get_user > + > #define __put_user_asm(instr, reg, x, addr, err) \ > asm volatile( \ > "1: " instr " " reg "1, [%2]\n" \ > @@ -266,30 +271,35 @@ do { \ > CONFIG_ARM64_PAN)); \ > } while (0) > > -#define __put_user(x, ptr) \ > +#define __put_user_check(x, ptr, err) \ > ({ \ > - int __pu_err = 0; \ > - __put_user_err((x), (ptr), __pu_err); \ > - __pu_err; \ > + __typeof__(*(ptr)) __user *__p = (ptr); \ > + might_fault(); \ > + if (access_ok(VERIFY_WRITE, __p, sizeof(*__p))) { \ > + __p = uaccess_mask_ptr(__p); \ > + __put_user_err((x), __p, (err)); \ > + } else { \ > + (err) = -EFAULT; \ > + } \ > }) > > #define __put_user_error(x, ptr, err) \ > ({ \ > - __put_user_err((x), (ptr), (err)); \ > + __put_user_check((x), (ptr), (err)); \ > (void)0; \ > }) > > -#define __put_user_unaligned __put_user > - > -#define put_user(x, ptr) \ > +#define __put_user(x, ptr) \ > ({ \ > - __typeof__(*(ptr)) __user *__p = (ptr); \ > - might_fault(); \ > - access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \ > - __p = uaccess_mask_ptr(__p), __put_user((x), __p) : \ > - -EFAULT; \ > + int __pu_err = 0; \ > + __put_user_check((x), (ptr), __pu_err); \ > + __pu_err; \ > }) > > +#define __put_user_unaligned __put_user > + > +#define put_user __put_user > + > extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n); > extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n); > extern unsigned long __must_check __copy_in_user(void __user *to, const void __user *from, unsigned long n); > -- > 2.21.0.rc0.269.g1a574e7a288b > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel