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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E89EDC433F5 for ; Tue, 23 Nov 2021 11:30:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 448A96B0071; Tue, 23 Nov 2021 06:29:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7846B0072; Tue, 23 Nov 2021 06:29:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BEA06B0073; Tue, 23 Nov 2021 06:29:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 1A4AE6B0071 for ; Tue, 23 Nov 2021 06:29:58 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D3A52183B2F97 for ; Tue, 23 Nov 2021 11:29:47 +0000 (UTC) X-FDA: 78839975256.09.2D56FAE Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf18.hostedemail.com (Postfix) with ESMTP id 34AA44002093 for ; Tue, 23 Nov 2021 11:29:45 +0000 (UTC) Received: by mail-wm1-f48.google.com with SMTP id p3-20020a05600c1d8300b003334fab53afso1913865wms.3 for ; Tue, 23 Nov 2021 03:29:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RCz+vh2bGRc6vOt1cmcyty/tcvje22f5Ps81nyvaJl8=; b=iORsK4eh4R+VVO0sDDWs6uTCsHBtofK80yTNi9dqOfNYeed7XHyX/ZfeH+Dt/A2Mmr ibZcB9b26lSFWliz15RiW1sj9gi+8SymVg50wZHsg4kCilz1jTj457cJpB+lC0i2Jw0t 7zk4vqDtR4SIpE4Ak5/Ihi93S1MuMyeQh3TV/q8qcP77MzIAGUzsEhpHJvK4n3rgn5Vx B1wfxE32t81OHx+/2be9ibS6Pif8hlJKRWcKJftKQ+ehU3nb+NOxk46JYSgNYRj5qr1r my70BvYQfLjB6Fbt7G3JOfy+QD0RhUzJi1S7h4rogn5D8SGsHp4Ikmb4/hSnuYfHnP9x ZVjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RCz+vh2bGRc6vOt1cmcyty/tcvje22f5Ps81nyvaJl8=; b=naulY+aeHoEc+QMAdEBEn+P3CJqySuHor0BAuTBV5MW9vTihZGFrPqziBF8BmawQtB tjtY/lm+iBMu5h08XEQhBmZshoVX5t5INDpRorThu/leuUB6ZruuOkYSRBuezj4RAgZo NJA5Rm1/9a4/GQHx8NWi9qSTSzhYwTZV1jUsYgUfJFlqis4ax8j3Aq99LRbpAaNuP5Sc i7pHJ3el2WmteC07x0M5aRmxPwB3wWaCigLN47BIMpeZehFvAWeSMSkRZTAUYkuBpb+G KnUFQ8BJ7748yBAM2yG64ZTIQ6Hxi9GCc/cC793pyRIcGAKtZCLnIpNaEzDADq3vdNpa bTvQ== X-Gm-Message-State: AOAM530ejt/Bo1mDVhhAOzyJlXq7ivX+w6PiR0/O33gIPkOODG6c4QuQ 6i+1RiRWFUXeYNGhrrCt+s5Cgw== X-Google-Smtp-Source: ABdhPJxgNU3F5ZbiL2IqSNSUEI6y0Mv5STMnCz4bk2DhNavYM0VNX4mAmCashJwrmSsH5krcZ0V+eg== X-Received: by 2002:a05:600c:1c20:: with SMTP id j32mr2110302wms.1.1637666985890; Tue, 23 Nov 2021 03:29:45 -0800 (PST) Received: from elver.google.com ([2a00:79e0:15:13:1444:3668:5c57:85cc]) by smtp.gmail.com with ESMTPSA id k27sm1041180wms.41.2021.11.23.03.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 03:29:44 -0800 (PST) Date: Tue, 23 Nov 2021 12:29:39 +0100 From: Marco Elver To: Josh Poimboeuf Cc: "Paul E. McKenney" , Alexander Potapenko , Boqun Feng , Borislav Petkov , Dmitry Vyukov , Ingo Molnar , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: Re: [PATCH v2 23/23] objtool, kcsan: Remove memory barrier instrumentation from noinstr Message-ID: References: <20211118081027.3175699-1-elver@google.com> <20211118081027.3175699-24-elver@google.com> <20211119203135.clplwzh3hyo5xddg@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211119203135.clplwzh3hyo5xddg@treble> User-Agent: Mutt/2.0.5 (2021-01-21) X-Stat-Signature: 6otd9pnwyahbyu4i7y8w3uzx6jh5e75g Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=iORsK4eh; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of elver@google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=elver@google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 34AA44002093 X-HE-Tag: 1637666985-330723 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 19, 2021 at 12:31PM -0800, Josh Poimboeuf wrote: > On Thu, Nov 18, 2021 at 09:10:27AM +0100, Marco Elver wrote: [...] > > + if (insn->sec->noinstr && sym->removable_instr) { [...] > I'd love to have a clearer name than 'removable_instr', though I'm > having trouble coming up with something. [...] I now have the below as v3 of this patch. The naming isn't entirely obvious, but coming up with a short name for this is tricky, but hopefully the comments make it clear. We can of course still pick another name. Does that look reasonable? Note, I'd like this series to sit in -next for a while (probably from some time next week after sending v3 if there are no further complaints). By default everything will be picked up by the -rcu tree, and we're targeting Linux 5.18. If you feel there might be objtool conflicts coming, this patch could be taken through another tree as there are no hard dependencies, as long as this patch reaches mainline before or with the rest. Thanks, -- Marco ------ >8 ------ From: Marco Elver Date: Mon, 9 Aug 2021 12:11:14 +0200 Subject: [PATCH] objtool, kcsan: Remove memory barrier instrumentation from noinstr Teach objtool to turn instrumentation required for memory barrier modeling into nops in noinstr text. The __tsan_func_entry/exit calls are still emitted by compilers even with the __no_sanitize_thread attribute. The memory barrier instrumentation will be inserted explicitly (without compiler help), and thus needs to also explicitly be removed. Signed-off-by: Marco Elver --- v3: * s/removable_instr/profiling_func/ (suggested by Josh Poimboeuf) * Fix and add more comments. v2: * Rewrite after rebase to v5.16-rc1. --- tools/objtool/check.c | 41 ++++++++++++++++++++++++----- tools/objtool/include/objtool/elf.h | 2 +- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 61dfb66b30b6..a78186c583f4 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1072,11 +1072,11 @@ static void annotate_call_site(struct objtool_file *file, } /* - * Many compilers cannot disable KCOV with a function attribute - * so they need a little help, NOP out any KCOV calls from noinstr - * text. + * Many compilers cannot disable KCOV or sanitizer calls with a function + * attribute so they need a little help, NOP out any such calls from + * noinstr text. */ - if (insn->sec->noinstr && sym->kcov) { + if (insn->sec->noinstr && sym->profiling_func) { if (reloc) { reloc->type = R_NONE; elf_write_reloc(file->elf, reloc); @@ -1991,6 +1991,35 @@ static int read_intra_function_calls(struct objtool_file *file) return 0; } +/* + * Return true if name matches an instrumentation function, where calls to that + * function from noinstr code can safely be removed, but compilers won't do so. + */ +static bool is_profiling_func(const char *name) +{ + /* + * Many compilers cannot disable KCOV with a function attribute. + */ + if (!strncmp(name, "__sanitizer_cov_", 16)) + return true; + + /* + * Compilers currently do not remove __tsan_func_entry/exit with the + * __no_sanitize_thread attribute, remove them. + * + * Memory barrier instrumentation is not emitted by the compiler, but + * inserted explicitly, so we need to also remove them. + */ + if (!strncmp(name, "__tsan_func_", 12) || + !strcmp(name, "__kcsan_mb") || + !strcmp(name, "__kcsan_wmb") || + !strcmp(name, "__kcsan_rmb") || + !strcmp(name, "__kcsan_release")) + return true; + + return false; +} + static int classify_symbols(struct objtool_file *file) { struct section *sec; @@ -2011,8 +2040,8 @@ static int classify_symbols(struct objtool_file *file) if (!strcmp(func->name, "__fentry__")) func->fentry = true; - if (!strncmp(func->name, "__sanitizer_cov_", 16)) - func->kcov = true; + if (is_profiling_func(func->name)) + func->profiling_func = true; } } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index cdc739fa9a6f..d22336781401 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -58,7 +58,7 @@ struct symbol { u8 static_call_tramp : 1; u8 retpoline_thunk : 1; u8 fentry : 1; - u8 kcov : 1; + u8 profiling_func : 1; struct list_head pv_target; }; -- 2.34.0.rc2.393.gf8c9666880-goog