Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp548931ybt; Wed, 17 Jun 2020 07:52:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzczTlZaxBjS0Ca+thqShZOCRsXu/RC25kgIkROYzAvzjVr/NYm/VKQUmP8b/2L1Lu2zXje X-Received: by 2002:a50:f9cc:: with SMTP id a12mr7766278edq.227.1592405563305; Wed, 17 Jun 2020 07:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592405563; cv=none; d=google.com; s=arc-20160816; b=fLIOJp+qryk2mK4qwjJKleH/Dq+fu3vr7viDoC03R+DUyJlqb0H67SnSEdQ+V57YEf ZKl4hy/3Vbu7wxehVzewC5xhAPgWAt86s72jMilDYjBAKb5OubfuMv8NGlOY8CdJxPKz 6ByqkeecuLi9xOEbuq805J/Y62RPo437fdg5o/CMXILGgifwQConegxzuAdsan/Is0RA cry25bY50YD5PtCmLrm1OtcHb6B409KSYhxfZtHzagrs92t/uQ3WFDql4Pa9BIMrDiGg mzyBthX0H5xQjv9XCUvS85SCCUQGhmFweJ4viCO0Pxo2jhxDF1cLURNAD3jFQmQiiFdf ccpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=8tV90J3ommZlSIBCa9GxO7kk+JI83XJ4xYdDZnD4Ijc=; b=RkmzHeHlGjo10Cym94kuGxxe9DeFeCCk9TpqVSoYoBz+zmknDO2y8iQnfRFQiFSpV0 cfvt9HMM4tO1C779P0nuTLTf2SGY17a5B4tmH8JAECGq7u6ARQK81HkdX5ttNCtu94Og scGe27qPINwVHQWMxBVejeiLIYtZrDvpkq0aJU/nfUbXr+gnACn1yXfeNSdgrjoVN90G cHPPVIvyBKQzkeigbJmE0YXzzaJQUdNlnb0w1w4X85hTwF3oLU4/KElXFw81bbd6x1T+ AH31MeeG1VB74OXPm9SnjYNHhLkLBxyt14nTKta4LcJ6OZqYXBz2DNAxxIMOOezFlWpi V/QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=l5S4jMfS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si131082edp.105.2020.06.17.07.52.20; Wed, 17 Jun 2020 07:52:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=l5S4jMfS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbgFQOuD (ORCPT + 99 others); Wed, 17 Jun 2020 10:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725894AbgFQOuD (ORCPT ); Wed, 17 Jun 2020 10:50:03 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9399CC06174E for ; Wed, 17 Jun 2020 07:50:03 -0700 (PDT) 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; bh=8tV90J3ommZlSIBCa9GxO7kk+JI83XJ4xYdDZnD4Ijc=; b=l5S4jMfSGIQUg/N8n1oegTOpBr asq6get5vZnR0xcL5ok+/GxmscseDXThs3pWAf8MS4xt0KRUZHySA+8l776NFslmhaoeJuwoTHHQP QdLvZhOIH5t4fEtuo5cOMH8GIEl3blBERoOyji8T9SEP8t+4Yj/mUGnoqPpZcitkgYDCckft19ZMl jc/8T3XRi7Pp+UGFWyPKBo5/ubnvbkHQ0SwBz43y6/zQYIMw0wWfgcnzmkk5T8+B3MWtip12iR29m ce3AuRL0CF/esGImMZ6A2H+dj7bEsnWJ+gF6uBCecUPBvqyq7PVVkYKTOLT4myp3+1S7iZkzxgN3w PK1zCIrQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlZNv-0005BJ-Ds; Wed, 17 Jun 2020 14:49:51 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 91214301DFC; Wed, 17 Jun 2020 16:49:49 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7D29A203CE7F6; Wed, 17 Jun 2020 16:49:49 +0200 (CEST) Date: Wed, 17 Jun 2020 16:49:49 +0200 From: Peter Zijlstra To: Marco Elver Cc: Dmitry Vyukov , Andrey Konovalov , Mark Rutland , Borislav Petkov , Thomas Gleixner , Ingo Molnar , clang-built-linux , "Paul E. McKenney" , Alexander Potapenko , kasan-dev , LKML , the arch/x86 maintainers , Andrew Morton , Josh Poimboeuf , ndesaulniers@google.com Subject: Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible Message-ID: <20200617144949.GA576905@hirez.programming.kicks-ass.net> References: <20200611215538.GE4496@worktop.programming.kicks-ass.net> <20200612114900.GA187027@google.com> <20200615142949.GT2531@hirez.programming.kicks-ass.net> <20200615145336.GA220132@google.com> <20200615150327.GW2531@hirez.programming.kicks-ass.net> <20200615152056.GF2554@hirez.programming.kicks-ass.net> <20200617143208.GA56208@elver.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200617143208.GA56208@elver.google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 17, 2020 at 04:32:08PM +0200, Marco Elver wrote: > On Mon, Jun 15, 2020 at 05:20PM +0200, Peter Zijlstra wrote: > > On Mon, Jun 15, 2020 at 05:03:27PM +0200, Peter Zijlstra wrote: > > > > > Yes, I think so. x86_64 needs lib/memcpy_64.S in .noinstr.text then. For > > > i386 it's an __always_inline inline-asm thing. > > > > Bah, I tried writing it without memcpy, but clang inserts memcpy anyway > > :/ > > Hmm, __builtin_memcpy() won't help either. > > Turns out, Clang 11 got __builtin_memcpy_inline(): https://reviews.llvm.org/D73543 > > The below works, no more crash on either KASAN or KCSAN with Clang. We > can test if we have it with __has_feature(__builtin_memcpy_inline) > (although that's currently not working as expected, trying to fix :-/). > > Would a memcpy_inline() be generally useful? It's not just Clang but > also GCC that isn't entirely upfront about which memcpy is inlined and > which isn't. If the compiler has __builtin_memcpy_inline(), we can use > it, otherwise the arch likely has to provide the implementation. > > Thoughts? I had the below, except of course that yields another objtool complaint, and I was still looking at that. Does GCC (8, as per the new KASAN thing) have that __builtin_memcpy_inline() ? --- diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index af75109485c26..a7d1570905727 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -690,13 +690,13 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s) (struct bad_iret_stack *)__this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1; /* Copy the IRET target to the temporary storage. */ - memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); + __memcpy(&tmp.regs.ip, (void *)s->regs.sp, 5*8); /* Copy the remainder of the stack from the current stack. */ - memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); + __memcpy(&tmp, s, offsetof(struct bad_iret_stack, regs.ip)); /* Update the entry stack */ - memcpy(new_stack, &tmp, sizeof(tmp)); + __memcpy(new_stack, &tmp, sizeof(tmp)); BUG_ON(!user_mode(&new_stack->regs)); return new_stack; diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S index 56b243b14c3a2..bbcc05bcefadb 100644 --- a/arch/x86/lib/memcpy_64.S +++ b/arch/x86/lib/memcpy_64.S @@ -8,6 +8,8 @@ #include #include +.pushsection .noinstr.text, "ax" + /* * We build a jump to memcpy_orig by default which gets NOPped out on * the majority of x86 CPUs which set REP_GOOD. In addition, CPUs which @@ -184,6 +186,8 @@ SYM_FUNC_START_LOCAL(memcpy_orig) retq SYM_FUNC_END(memcpy_orig) +.popsection + #ifndef CONFIG_UML MCSAFE_TEST_CTL