From patchwork Thu Jan 26 17:25:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 48816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp396470wrn; Thu, 26 Jan 2023 09:33:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsVruZbSwBNJCJfk8kEn2S4P7V0rSufPC2b5ZYXZz4dnlIwuKk+y9L1t2XN7Dt+cEcey4SP X-Received: by 2002:a05:6402:49:b0:49e:33ce:144d with SMTP id f9-20020a056402004900b0049e33ce144dmr85514981edu.37.1674754384329; Thu, 26 Jan 2023 09:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674754384; cv=none; d=google.com; s=arc-20160816; b=nDCCiPaIOLJ9DtiPTfbdAWmAJbP/2nE4/S+oO/B7Zh69ry+nZUfgy0P2OYi+S7y42X kmmH6EJ5ViM1RyBzeR28OMCt09u1bGzgq+pM/2Umd6Rcv+slvEQZtdnSIH9sFNYN1Llw 2zAcWLiOc/QoO1ZWpgEFcgm2w9iDy6hv0mksFHpD+Y8/jlb9LhHACImRAkq1C6gq918x 0GEedncURnw/Z/9Kz4azZsMF3kHcs72TpSUsNNW3PwbiGgsjKAp9BpNQ7KUwNwBgST38 cH60GrYoCbhOUL9R6Yqban3sM8bOS3s0wqQBkmOK1JMJzRrH/O5gono+5wH3LARMjaIs AaNA== 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=882N5kPyz5Iu3B048L5CJXSWFwyMUDkDVuR5YzqG7H4=; b=jGt7zfvZ2KUhwZCIbe+tgWGUgX1uHU8rCf1r7oIm9V6mXCAZYgFrZKbohP8zvOe8s9 WlY2f8S/qV5AHZmNNqaPrnArf+2q/gXaLI9cOVTdG94+aTaprdGnUaAclYYzE6mr/uaj kJuq50mraszOXWy0aB1I7LH4/EFHus0/TJTZFoTh3Sp4FceJwP/NtrXrDKQCKN2UMJzi JVWkWXOeY/VUtFNyjqcGmLF2MsTjkr1V1ysB2OFHcFh707s1fElwEK9zTFGxInM4GEsG Hus6DzqaZdTPcWwI2GL0v/uvmsb+zQgyKuksBe5WQdO7F0M9tA9e4snqFia5HgHVrrWf n9+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VVYfNAnI; 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 ef14-20020a05640228ce00b0049f512ad602si2387852edb.336.2023.01.26.09.32.40; Thu, 26 Jan 2023 09:33:04 -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=VVYfNAnI; 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 S231549AbjAZRZr (ORCPT + 99 others); Thu, 26 Jan 2023 12:25:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231548AbjAZRZo (ORCPT ); Thu, 26 Jan 2023 12:25: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 D84915D11C; Thu, 26 Jan 2023 09:25:41 -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 771D661904; Thu, 26 Jan 2023 17:25:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3822DC433B4; Thu, 26 Jan 2023 17:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674753940; bh=lEoTBcehc8n4upJA5LC+k+yiIJ7hxcNhFuHkvMT2WVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVYfNAnITdk+h/XCgrVAnqxWrI4TwMqCqEfV+BmOS7L2eCkMIcszxEzU+XFjbSocL 9KhXDfL/GdSOT4+PEPe9m46anHArz5ptw6Iz6RJP7BeoJDRLY+vvbmiqlpS6Ykob2i WSgISfj4Kvvom3EIwAS+ZQ29TACfOW1one51oQZgLM9cxFeZ5GY2laePVJB09byeKq NENZXefsIoFZlcryjUAbAoHHKjSxdLcJV0M0YMkokkb5msKTvVYUua8+uA3BUXY8CJ ouU3jNI5Y0IINCZZeX66thibWENgEKBPbAAiud1Mdf/K2Y5MMQ2GCkmuhmm6O9subv zPr50c4ZU7eqQ== 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 V15 1/7] compiler_types.h: Add __noinstr_section() for noinstr Date: Thu, 26 Jan 2023 12:25:10 -0500 Message-Id: <20230126172516.1580058-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230126172516.1580058-1-guoren@kernel.org> References: <20230126172516.1580058-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?1756107253143656197?= X-GMAIL-MSGID: =?utf-8?q?1756107253143656197?= 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__ */