Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp436967imb; Fri, 1 Mar 2019 04:53:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxQ0n5fQHXEVd57SJH4t4UOm/EOygLjfDWPYsfTjPGzMN/vGP6DlgvZoxdcQHgguZM7wDwY X-Received: by 2002:a62:b61a:: with SMTP id j26mr5362885pff.151.1551444780022; Fri, 01 Mar 2019 04:53:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551444780; cv=none; d=google.com; s=arc-20160816; b=SW4OOxlRL7skXoj85uYzAiAGpesM3GXkpsEZIZUCeE5giEKh2B2TtUaOxpeFf/Yr0s yZ46tohG7LZOE9lrlGInCQmlmbK/1AMI0HAGxyDLM+RZ9x9Jm5cWNtn04v4gtyb3N+Zb nUL0CKNEhKAjWTFEglbczq8x7xyzLmAxOcsTquWpcHhN272VE6R0c+Vz8IgWVOKJcT3M sCBJ2q86DEmekbbhcwOtxvh9/nhQxvjQgSb7EW3v66cKeEqP4XglgTEuddIYQ8n6Z8Zy 1b0gRAXLgzCnFagVl/lhWrCcA5kinysOjevgO0ewmzLHVTOE6rhxxmlLJvGVpAgiYYgt +1CA== 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=5nST5mD8fD941OtCbMGRJbm3+ycdOPkj4s+kpXfPFPo=; b=nOpen9LHRURQbmTJ3dJQAAvuQS8n9gCx2n+Bb39l9azO2f/RxNF5c6L4MhcdbBwIpH vhSPh5NxbCMKgETA36ah1vc/XEUSJ6JAefO8BldmjuL4YULllVnFg/mCoWU/Bd3eO4km i+ii8dBa/XnI32N43rVdPQA4PMXOvjbHiJseKpk8VfRcAUizZVHE0yq9fBSXLP1/7nIk 1o/mUg6jLV512ZPfBL3rdzi7pSSHEi9GWnjWWQjX2qwk236YqBez344+2y4K/njl6Zej 7Vak8vij/fZoSGlrD9aDST06ht0tq36UPwptpdLZvdCsf51z7BTz+MATn8nGJtAUvnqv qPHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=mgCTnxXY; 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 c11si15500731pfc.39.2019.03.01.04.52.44; Fri, 01 Mar 2019 04:53:00 -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=mgCTnxXY; 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 S1728157AbfCAM2A (ORCPT + 99 others); Fri, 1 Mar 2019 07:28:00 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:34828 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfCAM2A (ORCPT ); Fri, 1 Mar 2019 07:28:00 -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=5nST5mD8fD941OtCbMGRJbm3+ycdOPkj4s+kpXfPFPo=; b=mgCTnxXYhucOsqOGadNl6VYWl f9hiCB/2wvbQreuDGnU3qoA2B2PgrCVuKxV0DHlcBt41uVeEXa+qDz/la9DK9LVCUZAx7vkB+Np5X KJINIHGYtOmcDAThC1XdsxIFIEiXxVjH+zbQ+iHtLCPY6OgzGBohIviJmRZHtJbYXjcLaY7249tWE sFLWPxB1giQr8cE4PG7UuoGYWvysPEDtBEIGweMp/1OIkxUm3XD1ivtHFzWm577KmyAdB2Xhand0O E4DVyRdK/5qmVZWwCifCpLCQFmgYdJltFPt8+NQKkj0RRkuQFHzhdXZ3gJzDDL3sR+rKsbDfBYFiQ pA1wGyzlg==; 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 1gzhGX-00079d-Cn; Fri, 01 Mar 2019 12:27:50 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CD6992030867F; Fri, 1 Mar 2019 13:27:45 +0100 (CET) Date: Fri, 1 Mar 2019 13:27:45 +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: <20190301122745.GR32534@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190301103452.GQ32534@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 11:34:52AM +0100, Peter Zijlstra wrote: > Let me do an allmodconfig build to see how much pain is caused by that > redundant CLAC warning. arch/x86/lib/usercopy_64.o: warning: objtool: .altinstr_replacement+0x30: redundant UACCESS disable drivers/gpu/drm/i915/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x22: redundant UACCESS disable drivers/gpu/drm/i915/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x64: redundant UACCESS disable drivers/xen/privcmd.o: warning: objtool: privcmd_ioctl()+0x1c0: call to {dynamic}() with UACCESS enabled 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? --- diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c index ee42bb0cbeb3..e1ab9a50937c 100644 --- a/arch/x86/lib/usercopy_64.c +++ b/arch/x86/lib/usercopy_64.c @@ -59,7 +59,7 @@ EXPORT_SYMBOL(clear_user); * Since protection fault in copy_from/to_user is not a normal situation, * it is not necessary to optimize tail handling. */ -__visible unsigned long +__visible notrace unsigned long copy_user_handle_tail(char *to, char *from, unsigned len) { for (; len; --len, to++) { diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 485b259127c3..695212c5bd07 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -1606,6 +1606,7 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb) len)) { end_user: user_access_end(); +end: kvfree(relocs); err = -EFAULT; goto err; @@ -1625,7 +1626,7 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb) * relocations were valid. */ if (!user_access_begin(urelocs, size)) - goto end_user; + goto end; for (copied = 0; copied < nreloc; copied++) unsafe_put_user(-1, @@ -2616,7 +2617,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, * when we did the "copy_from_user()" above. */ if (!user_access_begin(user_exec_list, count * sizeof(*user_exec_list))) - goto end_user; + goto end; for (i = 0; i < args->buffer_count; i++) { if (!(exec2_list[i].offset & UPDATE)) @@ -2630,6 +2631,7 @@ i915_gem_execbuffer2_ioctl(struct drm_device *dev, void *data, } end_user: user_access_end(); +end:; } args->flags &= ~__I915_EXEC_UNKNOWN_FLAGS;