From: Peter Zijlstra <peterz@infradead.org>
To: frederic@kernel.org, paulmck@kernel.org, rjw@rjwysocki.net,
x86@kernel.org
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, jpoimboe@kernel.org
Subject: [RFC][PATCH 8/9] objtool/idle: Validate __cpuidle code as noinstr
Date: Thu, 19 May 2022 23:27:58 +0200 [thread overview]
Message-ID: <20220519213422.059293174@infradead.org> (raw)
In-Reply-To: 20220519212750.656413111@infradead.org
Idle code is very like entry code in that RCU isn't available. As
such, add a little validation.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/include/asm/irqflags.h | 11 ++++-------
arch/x86/include/asm/mwait.h | 2 +-
include/linux/compiler_types.h | 8 ++++++--
include/linux/cpu.h | 3 ---
tools/objtool/check.c | 15 ++++++++++++++-
5 files changed, 25 insertions(+), 14 deletions(-)
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -8,9 +8,6 @@
#include <asm/nospec-branch.h>
-/* Provide __cpuidle; we can't safely include <linux/cpu.h> */
-#define __cpuidle __section(".cpuidle.text")
-
/*
* Interrupt control:
*/
@@ -45,13 +42,13 @@ static __always_inline void native_irq_e
asm volatile("sti": : :"memory");
}
-static inline __cpuidle void native_safe_halt(void)
+static __always_inline void native_safe_halt(void)
{
mds_idle_clear_cpu_buffers();
asm volatile("sti; hlt": : :"memory");
}
-static inline __cpuidle void native_halt(void)
+static __always_inline void native_halt(void)
{
mds_idle_clear_cpu_buffers();
asm volatile("hlt": : :"memory");
@@ -84,7 +81,7 @@ static __always_inline void arch_local_i
* Used in the idle loop; sti takes one instruction cycle
* to complete:
*/
-static inline __cpuidle void arch_safe_halt(void)
+static __always_inline void arch_safe_halt(void)
{
native_safe_halt();
}
@@ -93,7 +90,7 @@ static inline __cpuidle void arch_safe_h
* Used when interrupts are already enabled or to
* shutdown the processor:
*/
-static inline __cpuidle void halt(void)
+static __always_inline void halt(void)
{
native_halt();
}
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -104,7 +104,7 @@ static inline void __sti_mwait(unsigned
* New with Core Duo processors, MWAIT can take some hints based on CPU
* capability.
*/
-static inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
+static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
{
if (static_cpu_has_bug(X86_BUG_MONITOR) || !current_set_polling_and_test()) {
if (static_cpu_has_bug(X86_BUG_CLFLUSH_MONITOR)) {
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -225,10 +225,14 @@ struct ftrace_likely_data {
#endif
/* Section for code which can't be instrumented at all */
-#define noinstr \
- noinline notrace __attribute((__section__(".noinstr.text"))) \
+#define __noinstr_section(section) \
+ noinline notrace __attribute((__section__(section))) \
__no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage
+#define noinstr __noinstr_section(".noinstr.text")
+
+#define __cpuidle __noinstr_section(".cpuidle.text")
+
#endif /* __KERNEL__ */
#endif /* __ASSEMBLY__ */
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -171,9 +171,6 @@ void __noreturn cpu_startup_entry(enum c
void cpu_idle_poll_ctrl(bool enable);
-/* Attach to any functions which should be considered cpuidle. */
-#define __cpuidle __section(".cpuidle.text")
-
bool cpu_in_idle(unsigned long pc);
void arch_cpu_idle(void);
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -373,7 +373,8 @@ static int decode_instructions(struct ob
sec->text = true;
if (!strcmp(sec->name, ".noinstr.text") ||
- !strcmp(sec->name, ".entry.text"))
+ !strcmp(sec->name, ".entry.text") ||
+ !strcmp(sec->name, ".cpuidle.text"))
sec->noinstr = true;
for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
@@ -3077,6 +3078,12 @@ static inline bool noinstr_call_dest(str
return true;
/*
+ * If the symbol is a static_call trampoline, we can't tell.
+ */
+ if (func->static_call_tramp)
+ return true;
+
+ /*
* The __ubsan_handle_*() calls are like WARN(), they only happen when
* something 'BAD' happened. At the risk of taking the machine down,
* let them proceed to get the message out.
@@ -3645,6 +3652,12 @@ static int validate_noinstr_sections(str
if (sec) {
warnings += validate_section(file, sec);
warnings += validate_unwind_hints(file, sec);
+ }
+
+ sec = find_section_by_name(file->elf, ".cpuidle.text");
+ if (sec) {
+ warnings += validate_section(file, sec);
+ warnings += validate_unwind_hints(file, sec);
}
return warnings;
next prev parent reply other threads:[~2022-05-19 21:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-19 21:27 [RFC][PATCH 0/9] Rework cpuidle vs instrumentation Peter Zijlstra
2022-05-19 21:27 ` [RFC][PATCH 1/9] x86/perf/amd: Remove tracing from perf_lopwr_cb() Peter Zijlstra
2022-05-19 21:27 ` [RFC][PATCH 2/9] x86/idle: Replace x86_idle with a static_call Peter Zijlstra
2022-05-30 11:07 ` Frederic Weisbecker
2022-05-19 21:27 ` [RFC][PATCH 3/9] cpuidle: Move IRQ state validation Peter Zijlstra
2022-05-30 11:36 ` Frederic Weisbecker
2022-05-30 12:00 ` Peter Zijlstra
2022-05-19 21:27 ` [RFC][PATCH 4/9] idle: Fix rcu_idle_*() usage Peter Zijlstra
2022-05-23 9:46 ` Gautham R. Shenoy
2022-05-31 9:33 ` Peter Zijlstra
2022-05-19 21:27 ` [RFC][PATCH 5/9] rcu: Fix rcu_idle_exit() Peter Zijlstra
2022-05-20 21:00 ` Paul E. McKenney
2022-05-19 21:27 ` [RFC][PATCH 6/9] acpi_idle: Remove tracing Peter Zijlstra
2022-05-19 21:27 ` [RFC][PATCH 7/9] cpuidle: Annotate poll_idle() Peter Zijlstra
2022-05-19 21:27 ` Peter Zijlstra [this message]
2022-05-19 21:27 ` [RFC][PATCH 9/9] arch/idle: Change arch_cpu_idle() IRQ behaviour Peter Zijlstra
2022-05-19 22:03 ` Peter Zijlstra
2022-05-20 2:20 ` Kirill A. Shutemov
2022-05-20 7:06 ` Peter Zijlstra
2022-05-20 10:13 ` Kirill A. Shutemov
2022-05-20 12:58 ` Peter Zijlstra
2022-05-24 14:55 ` Isaku Yamahata
2022-05-23 10:02 ` Gautham R. Shenoy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220519213422.059293174@infradead.org \
--to=peterz@infradead.org \
--cc=frederic@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).