From patchwork Sat Dec 10 17:11:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 32072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1420638wrr; Sat, 10 Dec 2022 09:14:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf44vVotxxLVK7KsN8Bm3gFiu2DxYo8//TNXEZ93X0ao9wPr754dBDvGD6bPrMMsBTyh0qMt X-Received: by 2002:a17:90b:8b:b0:219:aec6:ff93 with SMTP id bb11-20020a17090b008b00b00219aec6ff93mr10000648pjb.32.1670692471472; Sat, 10 Dec 2022 09:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670692471; cv=none; d=google.com; s=arc-20160816; b=xZ6nb9MnlEyC/JdrVapj7F8xlHGLhI3l8aEMS6XFljY4XhSnb70blAmrPY3gpFzy1c rIvUuX3khA2xWHCIC56osqqD4paEpEjr2b2bqceitv6FGBl0wVwy7RGITRk8gT6i989V XNEefzg5XwM7s9sGj6QMYo/2cq5X35zX3IO970zaW91IWnihOh3r4KCGzV46SNL9MGkw BSatl94+4t0D/ZrjsOK+pImXPYRT7kBBif04Bx7Lf09H4q35HvAVEH8Av5G+XUhBkSPE JTjqS/ba2WVnFGjtF/V4Dhiy7yYgogJYs+3o7Xjq/Qr6pJULU2bXDzh3tq+O/E7tya2h gQhg== 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=jf115F4SvNM5q+I6srbzUIf8tXbMvwFh1MxUv//J9a/Q6Bdg58MsUDxUS7KmXD3MOg JbGp4sQx4yDBbOlxJdCUPN1sikuFJtaPEMbfqek/aeuMbpuR5ygtln/3E9xN/TM2+7mq PY047/cwx4SJs0OK8RBWPNw1CE1GkaCpYCyP0vwqeZs+ncJR27UVNVAo8lzeD6Z7ILmd LKvZ5MxvqEj2SxykRgooCwJ9J22nyVuC1qIKN/lS206+pRjsoeoBB4X2bQpI5V7rSzVK qNvzglOmOufkWp7efjPxhjbc6VSliFloZycwDX2JNpKxsu222cIqeF0Wh/zqredafPup rzUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fc/PhVhq"; 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 j6-20020a17090a694600b00221099307dfsi2050586pjm.92.2022.12.10.09.14.18; Sat, 10 Dec 2022 09:14:31 -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="fc/PhVhq"; 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 S229843AbiLJRMg (ORCPT + 99 others); Sat, 10 Dec 2022 12:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbiLJRMd (ORCPT ); Sat, 10 Dec 2022 12:12:33 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07B7EBC9A; Sat, 10 Dec 2022 09:12:32 -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 ams.source.kernel.org (Postfix) with ESMTPS id BB036B808C6; Sat, 10 Dec 2022 17:12:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBF9C43398; Sat, 10 Dec 2022 17:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670692349; bh=W3STfz+q/HLqif/5T6LkLEIliEWH5xJbJ52wW/3KA+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fc/PhVhqgWiTfb7inOg5nhG7idSarUYNdjr5+JsyWZaWhu2JLmRGII6Dvkg78yQr0 z9PyN+tcQxjR2MYrmzjUEGdfJyUjhJURoZo7wNpKbE+mq3FOTDpdj8CJb1ssCqqEJu +JGApwuPZBqqdF5BgGLGN6nv8PsTDFCj6h/UfeYRUc7s065I/CzXo9uyYmlvd1wHAi SVPzpcBAuVdZ5yXt5e9Gtzyy0DczmJapggV40LSB0Eg4Cj2YXVVXuPGVfZdK0LsIuT BT4yHB/QtXdFdcTvnoTNyCn8R4pctZwTcnxetP9t+Fq6fbVGIMqJy2EQWd5ySK9VP5 lRSjAIXJEAIAg== 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, paul.walmsley@sifive.com, mark.rutland@arm.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 V11 1/7] compiler_types.h: Add __noinstr_section() for noinstr Date: Sat, 10 Dec 2022 12:11:35 -0500 Message-Id: <20221210171141.1120123-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221210171141.1120123-1-guoren@kernel.org> References: <20221210171141.1120123-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?1751848029179638306?= X-GMAIL-MSGID: =?utf-8?q?1751848029179638306?= 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__ */