From patchwork Thu Dec 8 02:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 31123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp529414wrr; Wed, 7 Dec 2022 19:00:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7tXJD+2deLY7Ou9su5BxP26l78V/51MwEa/DQ1PEWyO4AnhvksKjUCZMQs0WpuFYhzRHa/ X-Received: by 2002:a17:907:770b:b0:7c1:277:caf3 with SMTP id kw11-20020a170907770b00b007c10277caf3mr9720905ejc.247.1670468415964; Wed, 07 Dec 2022 19:00:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670468415; cv=none; d=google.com; s=arc-20160816; b=nlLA7xu+WQU4/jj81rgBvVO4gwtRmA0rnbcjyWywWTN74NwIlDHAOMax3+tHY0FtRR fjLqgvhKyujYoaB+6vUutuJ3MS/DMjt9211308p6+wShAI8DZ8r9++p2L8vSdqUfAOu+ A36wumZZdYYuh2HnHAKOMmk2ku73YcRjp1yYXRx2XrUT1Ip0QJNeqiK1yke+Sd4lP4Sx 661TcMuLijrqJRwOoXsRUpZKoM9wAHZ1c11OV6X5Nkowb8qxRzENVo4D/CInniAU/YwV j84U8ikZBi6/CmLjIqCvLzf6hEuJVVqTHQt/es2k/OqqmNKzQXV4dtBhX+Tr+jIiYxWD BMsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4ihkhrFZYyA+CmyEDNWJ9/fzSUG1hGDYLCFrcTZICUQ=; b=Q14me1NQiuLSdXohbhoE6PUHzT2/dZ4S5B6A0kVFYl0ykq0bp3+klGf9ycHio8YEtg 0ed9OQPaPzKH4NGJfukH5UzxslISrxxTdIEvahm0VIBmw6BTH5GPNutuTww/gBHF8PMJ NFcubKTjpNk4/NdF0kegQ6WAq8eSp4DA24acnB3rbjocLAOOtXGKqwy5WfNe6lEUyPd8 dpdTy4wglRXW3gSh5INZ/y9/rapAHj8rRDWwX34ABhEkIAo4sAUn4c1TgPYiq62vdXa3 LYJ0vLCvMzG9zkZBPwlJOJfrPuus6b16zeyuZouWyPLyMYOWxMJ0+5UP20TZoPTRY+6o M0fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FpO6gBmH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a17090631d100b0078e29796733si14177498ejf.653.2022.12.07.18.59.53; Wed, 07 Dec 2022 19:00:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FpO6gBmH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbiLHC6r (ORCPT + 99 others); Wed, 7 Dec 2022 21:58:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiLHC6o (ORCPT ); Wed, 7 Dec 2022 21:58:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 698CB9074C; Wed, 7 Dec 2022 18:58:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EDEB061D4E; Thu, 8 Dec 2022 02:58:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C531C4347C; Thu, 8 Dec 2022 02:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670468322; bh=W3STfz+q/HLqif/5T6LkLEIliEWH5xJbJ52wW/3KA+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FpO6gBmHALJhTC1fn2hPPUyNbCq2Da3mgaGbaxZt4coQKztR57vVEqrWWJncgc0Mt uu3QREO80RIPW8sSvQvb7oDMJV5GvYD9dFZ0h1lO66t8xeX4jrPipOzfH1IQXnc+4F WjQDP9FPKW7GOCLIVCBv+wJga4OJwWLSo0JapUJh2m492mlcl47X0PewkHTFG0fUKD Fi08NZ5VBX6VVXwkW8HZ8Da9oRJSOlQPCocp6+hK9bjTob7fkfxV8lq/Yssem20I9L 2E2L8Q5bHhRCX2GEOr1i5VkpA2PDTQKlmpAaw0DDNz0WVWAkc1Mnu92sgw/fH6qYcW sbzYsaUfoanng== From: guoren@kernel.org To: arnd@arndb.de, guoren@kernel.org, palmer@rivosinc.com, tglx@linutronix.de, peterz@infradead.org, luto@kernel.org, conor.dooley@microchip.com, heiko@sntech.de, jszhang@kernel.org, lazyparser@gmail.com, falcon@tinylab.org, chenhuacai@kernel.org, apatel@ventanamicro.com, atishp@atishpatra.org, palmer@dabbelt.com, paul.walmsley@sifive.com, mark.rutland@arm.com, zouyipeng@huawei.com, bigeasy@linutronix.de, David.Laight@aculab.com, chenzhongjin@huawei.com, greentime.hu@sifive.com, andy.chiu@sifive.com, ben@decadent.org.uk, bjorn@kernel.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Lai Jiangshan , Borislav Petkov , Miguel Ojeda , Kees Cook , Nick Desaulniers Subject: [PATCH -next V10 01/10] compiler_types.h: Add __noinstr_section() for noinstr Date: Wed, 7 Dec 2022 21:58:07 -0500 Message-Id: <20221208025816.138712-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221208025816.138712-1-guoren@kernel.org> References: <20221208025816.138712-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751613089245753296?= X-GMAIL-MSGID: =?utf-8?q?1751613089245753296?= From: Lai Jiangshan Using __noinstr_section() doesn't automatically disable all instrumentations on the section. Inhibition for some instrumentations requires extra code. I.E. KPROBES explicitly avoids instrumenting on .noinstr.text. Cc: Borislav Petkov Reviewed-by: Miguel Ojeda Reviewed-by: Kees Cook Suggested-by: Nick Desaulniers Suggested-by: Peter Zijlstra Tested-by: Jisheng Zhang Tested-by: Guo Ren Signed-off-by: Guo Ren Signed-off-by: Lai Jiangshan --- include/linux/compiler_types.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index eb0466236661..41e4faa4cd95 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -230,12 +230,19 @@ struct ftrace_likely_data { #define __no_sanitize_or_inline __always_inline #endif -/* Section for code which can't be instrumented at all */ -#define noinstr \ - noinline notrace __attribute((__section__(".noinstr.text"))) \ - __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \ +/* + * Using __noinstr_section() doesn't automatically disable all instrumentations + * on the section. Inhibition for some instrumentations requires extra code. + * I.E. KPROBES explicitly avoids instrumenting on .noinstr.text. + */ +#define __noinstr_section(section) \ + noinline notrace __section(section) __no_profile \ + __no_kcsan __no_sanitize_address __no_sanitize_coverage \ __no_sanitize_memory +/* Section for code which can't be instrumented at all */ +#define noinstr __noinstr_section(".noinstr.text") + #endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */