From patchwork Thu Jan 12 09:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 13097736 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3BBD2C54EBD for ; Thu, 12 Jan 2023 09:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ptJZytdUErNBn+BwlgUNNnZp9RvF8dAzo8Oe4mULc0I=; b=Q8FPQxJpEl5Bn6 6UH1iwVd5DBs+gFZyAwmxnFpqJctA+g1TvW40lcYmNJLrRRmXAxrmdwjZ0jKDaIROHwW7MdyaEJS8 Wf5FlYXtqBCQFH0Te6YhSZXoAw0nl9VnPrGobQzqkSsZfUSTQdcVq5pOqFt+7kVSuyRJlMff2okTr DxLCtJr7grTBLxqekQlVQEr8Ny6bvaG3s/Xni9MdMVor9pDOUCRcr8cODGLpuH0Wu/EGSfQdo9Y78 K6Jfm+Z2uyCkv9CkjJn/seIZJpOuwjx4lcqvlhGQibuM4FzYKZQkC4HQ+lMtdv1kfNsyg6Djp5Hz5 jtwSGNFJfqgpXC0NXkNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFuMe-00EU74-EU; Thu, 12 Jan 2023 09:59:16 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFuMb-00EU4y-C7 for linux-riscv@lists.infradead.org; Thu, 12 Jan 2023 09:59:14 +0000 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 F37F461FCC; Thu, 12 Jan 2023 09:59:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4F8EC433F1; Thu, 12 Jan 2023 09:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673517552; bh=lEoTBcehc8n4upJA5LC+k+yiIJ7hxcNhFuHkvMT2WVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3LUoS2yPQhhieChvQkuzMhUaKk2EO8QVQJltwWKfuWZ+SkkbXA5RK5CtTE7nc0A0 XAzoI6vnjxVWDwoce1t5aSAEbem8n6gB5HeQ+VO816eSfconfnXfEY1hVTUlV5Asgx VHC/dX3bPnFeD1WbtW5SgPoV+r70IrO8Xrs4pebhxhjtza71Nn9rX7pzqk/sGX0zBD 79RK7mOHm1yj17Vc5rYmwuRdmpxLsNjMI+hKQF56Pwrp/+NdaXyhhyMwV7jIkWpayj TF+UTsn4KxSqTRumiZ6F6ildmH/UVGa76/tA4cpcRotzezxXnQHv30hYFOQagyMlBq 3KR5+v3ZjdmGA== 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, mark.rutland@arm.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 , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Nick Desaulniers Subject: [PATCH -next V14 1/7] compiler_types.h: Add __noinstr_section() for noinstr Date: Thu, 12 Jan 2023 04:58:42 -0500 Message-Id: <20230112095848.1464404-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230112095848.1464404-1-guoren@kernel.org> References: <20230112095848.1464404-1-guoren@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230112_015913_582428_ECCADDFD X-CRM114-Status: GOOD ( 12.33 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Björn Töpel 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 7c1afe0f4129..0a2ca5755be7 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -231,12 +231,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__ */