Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp457490imb; Fri, 1 Mar 2019 05:24:50 -0800 (PST) X-Google-Smtp-Source: AHgI3IYX1/p5G6MxBiwqZR+LBiR1nbAzYf7oGhQtwmFcls2Hux1jXHbKoFbB7sb4RKWChFV+I87x X-Received: by 2002:a62:3990:: with SMTP id u16mr5561554pfj.80.1551446690694; Fri, 01 Mar 2019 05:24:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551446690; cv=none; d=google.com; s=arc-20160816; b=uwYeo0rwW1WVd7amBh/sMsLI6BnTjGsGYYeTfhGR9cnDDiLn/KFxdZqFpbq32NzxjD JxMeQW5nxGJaDErZS4VUUqr45L72nnBYNV1WI0TJYzbyjYU048S2f2Rwwmqu7ZT0t5ED e3v/x5UHMYncAHPOuOeVGcyWFTOUsXzfhXNzHOYakpNVbkAq60GkjklEmGIXPCBXaTcu fPY0VlWmuYu41e+z8cCvg+xT3h+KNVMTKNakREbdYY43huNuEguhMsVQWLo189e1+ubS NH5Ipkye84bm8fEpLW6onMctv3foGmsKchWqh5SGxTHIjsDUYWy+IB9gtXsZP8mGRBIp XJ2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mz4oRaDKZXq7U5gDKqGBgje3puwQYNVzedxYb1qsnAk=; b=BAgFPbHh/XXyhd5oXwLoQ0KeBDHi+u5zqPju6aNg/I43Nhhns04W694rjTcUD0Jrs1 F96QXvtf6M3r4IdJb0ufcGbuZhJy79Iq++DAeB1Y4DFMHpqaUnv7Y7ghC6zepKXym3J8 4otbSa/PlS+qWAeHcBbL29StIncwRyaRr/yZVEs5NsH02YCsClK4likhBXTCOuCRCPvI aPkARNKGxMCyzCoPSd7J7y+N+gzJddGKfmoic+RXyEZSA6PujBcYSEysoEL7i6MBAZtR LiFMJtwi2J7qCXCyk6k+v0xcoAFMM/YFMk+WHlBk0Ybyy9WDW1qePSNgotpuuoQ4bo3C mD7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Srxb/Bb7"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y192si8122764pfb.127.2019.03.01.05.24.35; Fri, 01 Mar 2019 05:24:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="Srxb/Bb7"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728171AbfCAM51 (ORCPT + 99 others); Fri, 1 Mar 2019 07:57:27 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:41384 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfCAM50 (ORCPT ); Fri, 1 Mar 2019 07:57:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mz4oRaDKZXq7U5gDKqGBgje3puwQYNVzedxYb1qsnAk=; b=Srxb/Bb79KEp6Pqg3cbb9Ka/P AnjA/aPwg/yd4EjFacKJmCdQ+cL3WODX35ZyxV3O/I0RaAdKxc9bzUw3lX3+QqznDkDsp/6hwE5bA 70ehIqlt2xgkktPX58xI0vgLqf/7aeidBo7Lg2JQRrCd7Ocx+vvU83maiKvIfMDfCpPWpfejfMvPf HVXOwzrNMbUVszDuUeIU1G8BoUYmjFeytppfJWvpJLWODKRAn41BS5u+8ro+Zv/AZvTHA0RFA/Hcd 8rZ5Cw+ezOEX4ZbQV8n/wUB3Rf7f7GUAo8xitBoRFP6Exz2Kxc2qBFsm4o2S1ylpEgQwirBqGRIcO WkiqYmVLQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzhj6-0002yJ-0I; Fri, 01 Mar 2019 12:57:20 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6D5EC239359C0; Fri, 1 Mar 2019 13:57:18 +0100 (CET) Date: Fri, 1 Mar 2019 13:57:18 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: Thomas Gleixner , Peter Anvin , Julien Thierry , Will Deacon , Andy Lutomirski , Ingo Molnar , Catalin Marinas , James Morse , valentin.schneider@arm.com, Brian Gerst , Josh Poimboeuf , Andrew Lutomirski , Borislav Petkov , Denys Vlasenko , Linux List Kernel Mailing , Chris Wilson Subject: Re: [PATCH 6/8] i915,uaccess: Fix redundant CLAC Message-ID: <20190301125718.GS32534@hirez.programming.kicks-ass.net> References: <20190228145450.289603901@infradead.org> <20190228150152.540038736@infradead.org> <20190228175114.GG32494@hirez.programming.kicks-ass.net> <20190228180154.GO32534@hirez.programming.kicks-ass.net> <20190228190111.GI32494@hirez.programming.kicks-ass.net> <20190301103452.GQ32534@hirez.programming.kicks-ass.net> <20190301122745.GR32534@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190301122745.GR32534@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 01, 2019 at 01:27:45PM +0100, Peter Zijlstra wrote: > arch/x86/lib/usercopy_64.o: warning: objtool: .altinstr_replacement+0x30: redundant UACCESS disable > The usercopy one is difficult, that's copy_user_handle_tail(), it is > buggered though, because that lacks notrace and thus has a __fentry__ > call in. > > Also, afaict all exception jumps into copy_user_handle_tail() will have > AC=1, but the __{get,put}_user_nocheck() things do STAC/CLAC all over > again. > > So what do we do? Annotate that we start with AC=1 and then immediately > do the clac, and then let __{get,put}_user_nocheck() do their own thing? > or make it use the unsafe stuff? Or.. we move the thing to assembly. Of course, I suck at (writing) asm, so the below is probably broken in various ways. --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -208,9 +208,6 @@ __copy_from_user_flushcache(void *dst, c } unsigned long -copy_user_handle_tail(char *to, char *from, unsigned len); - -unsigned long mcsafe_handle_tail(char *to, char *from, unsigned len); #endif /* _ASM_X86_UACCESS_64_H */ --- a/arch/x86/lib/copy_user_64.S +++ b/arch/x86/lib/copy_user_64.S @@ -194,6 +194,29 @@ ENDPROC(copy_user_enhanced_fast_string) EXPORT_SYMBOL(copy_user_enhanced_fast_string) /* + * Try to copy last bytes and clear the rest if needed. + * Since protection fault in copy_from/to_user is not a normal situation, + * it is not necessary to optimize tail handling. + * + * Input: + * rdi destination + * rsi source + * rdx count + * + * Output: + * eax uncopied bytes or 0 if successful. + */ +ENTRY(copy_user_handle_tail) + movl %edx,%ecx +1: rep movsb +2: mov %ecx,%eax + ASM_CLAC + ret + + _ASM_EXTABLE_UA(1b, 2b) +END(copy_user_handle_tail) + +/* * copy_user_nocache - Uncached memory copy with exception handling * This will force destination out of cache for more performance. * --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -55,26 +55,6 @@ unsigned long clear_user(void __user *to EXPORT_SYMBOL(clear_user); /* - * Try to copy last bytes and clear the rest if needed. - * Since protection fault in copy_from/to_user is not a normal situation, - * it is not necessary to optimize tail handling. - */ -__visible unsigned long -copy_user_handle_tail(char *to, char *from, unsigned len) -{ - for (; len; --len, to++) { - char c; - - if (__get_user_nocheck(c, from++, sizeof(char))) - break; - if (__put_user_nocheck(c, to, sizeof(char))) - break; - } - clac(); - return len; -} - -/* * Similar to copy_user_handle_tail, probe for the write fault point, * but reuse __memcpy_mcsafe in case a new read error is encountered. * clac() is handled in _copy_to_iter_mcsafe().