x86 noinstr fixes
Subsystems (4)
Peter Zijlstra
maintainercover x86 noinstr fixes
With exception of patch #6 (which I'm really not sure about), this series cures all noinstr warnings I found today after looking at a report from Randy.
Please consider...
Peter Zijlstra
maintainerPATCH 1/6 x86/entry: Fix noinstr fail
vmlinux.o: warning: objtool: __do_fast_syscall_32()+0x47: call to syscall_enter_from_user_mode_work() leaves .noinstr.text section
--- arch/x86/entry/common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/entry/common.c +7 -3
@@ -73,10 +73,8 @@ static __always_inline void do_syscall_3 unsigned int nr) {if (likely (nr < IA32_NR_syscalls)) { -instrumentation_begin (); nr =array_index_nospec (nr, IA32_NR_syscalls); regs->ax = ia32_sys_call_table[nr](regs); -instrumentation_end (); } }
@@ -91,8 +89,11 @@ __visible noinstr void do_int80_syscall_* or may not be necessary, but it matches the old asm behavior. */ nr = (unsigned int )syscall_enter_from_user_mode (regs, nr); +instrumentation_begin ();do_syscall_32_irqs_on (regs, nr); + +instrumentation_end ();syscall_exit_to_user_mode (regs); }
@@ -121,11 +122,12 @@ static noinstr bool __do_fast_syscall_32 res =get_user (*(u32 *)®s->bp, (u32 __user __force *)(unsigned long )(u32 )regs->sp); } -instrumentation_end ();if (res) {/* User code screwed up. */ regs->ax = -EFAULT ; + +instrumentation_end ();syscall_exit_to_user_mode (regs);return false; }
@@ -135,6 +137,8 @@ static noinstr bool __do_fast_syscall_32/* Now this is just like a normal syscall. */ do_syscall_32_irqs_on (regs, nr); + +instrumentation_end ();syscall_exit_to_user_mode (regs);return true; }
[tip: x86/urgent] x86/entry: Fix noinstr fail
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 9caa7ff509add50959a793b811cc7c9339e281cd Gitweb: https://git.kernel.org/tip/9caa7ff509add50959a793b811cc7c9339e281cd Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 06 Jan 2021 15:36:20 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Jan 2021 21:10:58 +01:00
x86/entry: Fix noinstr fail
vmlinux.o: warning: objtool: __do_fast_syscall_32()+0x47: call to syscall_enter_from_user_mode_work() leaves .noinstr.text section
--- arch/x86/entry/common.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
arch/x86/entry/common.c +7 -3
@@ -73,10 +73,8 @@ static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs, unsigned int nr) {if (likely (nr < IA32_NR_syscalls)) { -instrumentation_begin (); nr =array_index_nospec (nr, IA32_NR_syscalls); regs->ax = ia32_sys_call_table[nr](regs); -instrumentation_end (); } }
@@ -91,8 +89,11 @@ __visible noinstr void do_int80_syscall_32(struct pt_regs *regs)* or may not be necessary, but it matches the old asm behavior. */ nr = (unsigned int )syscall_enter_from_user_mode (regs, nr); +instrumentation_begin ();do_syscall_32_irqs_on (regs, nr); + +instrumentation_end ();syscall_exit_to_user_mode (regs); }
@@ -121,11 +122,12 @@ static noinstr bool __do_fast_syscall_32(struct pt_regs *regs) res =get_user (*(u32 *)®s->bp, (u32 __user __force *)(unsigned long )(u32 )regs->sp); } -instrumentation_end ();if (res) {/* User code screwed up. */ regs->ax = -EFAULT ; + +instrumentation_end ();syscall_exit_to_user_mode (regs);return false; }
@@ -135,6 +137,8 @@ static noinstr bool __do_fast_syscall_32(struct pt_regs *regs)/* Now this is just like a normal syscall. */ do_syscall_32_irqs_on (regs, nr); + +instrumentation_end ();syscall_exit_to_user_mode (regs);return true; }
Peter Zijlstra
maintainerPATCH 2/6 x86/sev: Fix nonistr violation
In reply to Peter ZijlstraWhen the compiler fails to inline; we violate nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to sev_es_wr_ghcb_msr() leaves .noinstr.text section
--- arch/x86/kernel/sev-es.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/sev-es.c +1 -1
@@ -225,7 +225,7 @@ static inline u64 sev_es_rd_ghcb_msr(voireturn __rdmsr (MSR_AMD64_SEV_ES_GHCB ); } -static inline void sev_es_wr_ghcb_msr (u64 val) +static __always_inline void sev_es_wr_ghcb_msr(u64 val) {u32 low, high;
Re: [PATCH 2/6] x86/sev: Fix nonistr violation
Quoted 3 lines · Peter Zijlstra
When the compiler fails to inline; we violate nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to
sev_es_wr_ghcb_msr()leaves .noinstr.text section
I am still seeing (a variant of) this one:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
Quoted 1 line
gcc --version
gcc (SUSE Linux) 7.5.0
The other 2 that I reported are gone with all 6 patches applied.
Quoted 20 lines
Fixes 4ca68e023b11 ("x86/sev-es: Handle NMI State")Reported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- arch/x86/kernel/sev-es.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/sev-es.c +1
-1@@ -225,7 +225,7 @@ static inline u64 sev_es_rd_ghcb_msr(voireturn __rdmsr (MSR_AMD64_SEV_ES_GHCB ); } -static inline void sev_es_wr_ghcb_msr (u64 val) +static __always_inline void sev_es_wr_ghcb_msr(u64 val) {u32 low, high;
Signature · 1 line
~Randy
Peter Zijlstra
maintainerRe: [PATCH 2/6] x86/sev: Fix nonistr violation
Quoted 8 lines · Randy Dunlap
Quoted 3 lines · Peter Zijlstra
When the compiler fails to inline; we violate nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to
sev_es_wr_ghcb_msr()leaves .noinstr.text sectionI am still seeing (a variant of) this one:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
Gah, sorry, I managed to mess up my .config :/ /me goes try again.
Peter Zijlstra
maintainer[PATCH 7/6] x86: __always_inline __{rd,wr}msr()
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Randy Dunlap
Quoted 3 lines · Peter Zijlstra
When the compiler fails to inline; we violate nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to
sev_es_wr_ghcb_msr()leaves .noinstr.text sectionI am still seeing (a variant of) this one:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
Gah, sorry, I managed to mess up my .config :/ /me goes try again.
OK, restored your original .config and that did indeed reproduce, the below cures it.
---
Subject: x86: __always_inline __{rd,wr}msr()
From: Peter Zijlstra <[email protected]>
Date: Thu Jan 7 11:14:25 CET 2021
When the compiler choses to not inline the trivial MSR helpers:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
--- arch/x86/include/asm/msr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/msr.h +2 -2
@@ -86,7 +86,7 @@ static inline void do_trace_rdpmc(unsign* think of extending them - you will be slapped with a stinking trout or a frozen * shark will reach you, wherever you are! You've been warned. */ -static inline unsigned long long notrace __rdmsr (unsigned int msr) +static __always_inline unsigned long long __rdmsr (unsigned int msr) {DECLARE_ARGS (val, low, high);
@@ -98,7 +98,7 @@ static inline unsigned long long notracereturn EAX_EDX_VAL (val, low, high); } -static inline void notrace __wrmsr(unsigned int msr, u32 low, u32 high) +static __always_inline void __wrmsr(unsigned int msr, u32 low, u32 high) { asmvolatile ("1: wrmsr\n" "2:\n"
RE: [PATCH 7/6] x86: __always_inline __{rd,wr}msr()
From: Peter Zijlstra
Quoted 1 line
Sent: 07 January 2021 10:18
...
arch/x86/include/asm/msr.h static inline void do_trace_rdpmc(unsign · line 89
Quoted 2 lines
arch/x86/include/asm/msr.h +1
-1-static inline unsigned long long notrace __rdmsr (unsigned int msr) +static __always_inline unsigned long long __rdmsr (unsigned int msr)
Since we (should) only request 'inline' for things that need to be inlined, maybe inline should expand to __attribute__((always_inline)).
That might throw up a few warnings where inline has been misused. But they are less problematic than things not being inlined.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Randy Dunlap
Acked-byRe: [PATCH 7/6] x86: __always_inline __{rd,wr}msr()
In reply to Peter ZijlstraQuoted 22 lines · Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Randy Dunlap
Quoted 3 lines · Peter Zijlstra
When the compiler fails to inline; we violate nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to
sev_es_wr_ghcb_msr()leaves .noinstr.text sectionI am still seeing (a variant of) this one:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
Gah, sorry, I managed to mess up my .config :/ /me goes try again.
OK, restored your original .config and that did indeed reproduce, the below cures it.
---
Subject: x86:
__always_inline__{rd,wr}msr()
From: Peter Zijlstra <[email protected]>
Date: Thu Jan 7 11:14:25 CET 2021
Quoted 6 lines
When the compiler choses to not inline the trivial MSR helpers:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xce: call to __wrmsr.constprop.14() leaves .noinstr.text section
Reported-by Randy Dunlap <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>
Thanks.
Quoted 25 lines
--- arch/x86/include/asm/msr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/include/asm/msr.h +2
-2@@ -86,7 +86,7 @@ static inline void do_trace_rdpmc(unsign* think of extending them - you will be slapped with a stinking trout or a frozen * shark will reach you, wherever you are! You've been warned. */ -static inline unsigned long long notrace __rdmsr (unsigned int msr) +static __always_inline unsigned long long __rdmsr (unsigned int msr) {DECLARE_ARGS (val, low, high);@@ -98,7 +98,7 @@ static inline unsigned long long notracereturn EAX_EDX_VAL (val, low, high); } -static inline void notrace __wrmsr(unsigned int msr, u32 low, u32 high) +static __always_inline void __wrmsr(unsigned int msr, u32 low, u32 high) { asmvolatile ("1: wrmsr\n" "2:\n"
Signature · 1 line
~Randy
[tip: x86/urgent] x86/sev: Fix nonistr violation
In reply to Peter ZijlstraThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: a1d5c98aac33a5a0004ecf88905dcc261c52f988 Gitweb: https://git.kernel.org/tip/a1d5c98aac33a5a0004ecf88905dcc261c52f988 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 06 Jan 2021 15:36:21 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Jan 2021 21:10:58 +01:00
x86/sev: Fix nonistr violation
When the compiler fails to inline, it violates nonisntr:
vmlinux.o: warning: objtool: __sev_es_nmi_complete()+0xc7: call to sev_es_wr_ghcb_msr() leaves .noinstr.text section
--- arch/x86/kernel/sev-es.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/sev-es.c +1 -1
@@ -225,7 +225,7 @@ static inline u64 sev_es_rd_ghcb_msr(void)return __rdmsr (MSR_AMD64_SEV_ES_GHCB ); } -static inline void sev_es_wr_ghcb_msr (u64 val) +static __always_inline void sev_es_wr_ghcb_msr(u64 val) {u32 low, high;
Peter Zijlstra
maintainerPATCH 3/6 locking/lockdep: Cure noinstr fail
In reply to Peter ZijlstraWhen the compiler doesn't feel like inlining, it causes a noinstr fail:
vmlinux.o: warning: objtool: lock_is_held_type()+0xb: call to lockdep_enabled() leaves .noinstr.text section
--- kernel/locking/lockdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -1
@@ -79,7 +79,7 @@ module_param(lock_stat, int, 0644); DEFINE_PER_CPU(unsigned int, lockdep_recursion);EXPORT_PER_CPU_SYMBOL_GPL (lockdep_recursion); -static inline bool lockdep_enabled (void ) +static __always_inline bool lockdep_enabled(void) {if (!debug_locks)return false;
[tip: x86/urgent] locking/lockdep: Cure noinstr fail
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 0afda3a888dccf12557b41ef42eee942327d122b Gitweb: https://git.kernel.org/tip/0afda3a888dccf12557b41ef42eee942327d122b Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 06 Jan 2021 15:36:22 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Jan 2021 21:10:59 +01:00
locking/lockdep: Cure noinstr fail
When the compiler doesn't feel like inlining, it causes a noinstr fail:
vmlinux.o: warning: objtool: lock_is_held_type()+0xb: call to lockdep_enabled() leaves .noinstr.text section
--- kernel/locking/lockdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/lockdep.c +1 -1
@@ -79,7 +79,7 @@ module_param(lock_stat, int, 0644); DEFINE_PER_CPU(unsigned int, lockdep_recursion);EXPORT_PER_CPU_SYMBOL_GPL (lockdep_recursion); -static inline bool lockdep_enabled (void ) +static __always_inline bool lockdep_enabled(void) {if (!debug_locks)return false;
Peter Zijlstra
maintainerPATCH 4/6 locking/lockdep: Avoid noinstr warning for DEBUG_LOCKDEP
In reply to Peter Zijlstravmlinux.o: warning: objtool: lock_is_held_type()+0x60: call to check_flags.part.0() leaves .noinstr.text section
--- kernel/locking/lockdep.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/locking/lockdep.c +6 -1
@@ -5271,12 +5271,15 @@ static void __lock_unpin_lock(struct loc/* * Check whether we follow the irq-flags state precisely: */ -static void check_flags (unsigned long flags) +static noinstr void check_flags(unsigned long flags) {#if defined(CONFIG_PROVE_LOCKING ) && defined(CONFIG_DEBUG_LOCKDEP )if (!debug_locks)return ; +/* Get the warning out.. */ +instrumentation_begin (); +if (irqs_disabled_flags (flags)) {if (DEBUG_LOCKS_WARN_ON (lockdep_hardirqs_enabled ())) {printk ("possible reason: unannotated irqs-off.\n" );
@@ -5304,6 +5307,8 @@ static void check_flags(unsigned long flif (!debug_locks)print_irqtrace_events (current); + +instrumentation_end ();#endif }
[tip: x86/urgent] locking/lockdep: Avoid noinstr warning for DEBUG_LOCKDEP
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 77ca93a6b1223e210e58e1000c09d8d420403c94 Gitweb: https://git.kernel.org/tip/77ca93a6b1223e210e58e1000c09d8d420403c94 Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 06 Jan 2021 15:36:23 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Jan 2021 21:10:59 +01:00
locking/lockdep: Avoid noinstr warning for DEBUG_LOCKDEP
vmlinux.o: warning: objtool: lock_is_held_type()+0x60: call to check_flags.part.0() leaves .noinstr.text section
--- kernel/locking/lockdep.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/locking/lockdep.c +6 -1
@@ -5271,12 +5271,15 @@ static void __lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie cookie/* * Check whether we follow the irq-flags state precisely: */ -static void check_flags (unsigned long flags) +static noinstr void check_flags(unsigned long flags) {#if defined(CONFIG_PROVE_LOCKING ) && defined(CONFIG_DEBUG_LOCKDEP )if (!debug_locks)return ; +/* Get the warning out.. */ +instrumentation_begin (); +if (irqs_disabled_flags (flags)) {if (DEBUG_LOCKS_WARN_ON (lockdep_hardirqs_enabled ())) {printk ("possible reason: unannotated irqs-off.\n" );
@@ -5304,6 +5307,8 @@ static void check_flags(unsigned long flags)if (!debug_locks)print_irqtrace_events (current); + +instrumentation_end ();#endif }
Peter Zijlstra
maintainerPATCH 5/6 x86/mce: Remove explicit/superfluous tracing
In reply to Peter ZijlstraThere's some explicit tracing left in exc_machine_check_kernel(), remove it, as it's already implied by irqentry_nmi_enter().
--- arch/x86/kernel/cpu/mce/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mce/core.c +4 -3
@@ -1992,10 +1992,9 @@ static __always_inline void exc_machine_* that out because it's an indirect call. Annotate it. */ instrumentation_begin (); -trace_hardirqs_off_finish (); +machine_check_vector (regs); -if (regs->flags &X86_EFLAGS_IF ) -trace_hardirqs_on_prepare (); +instrumentation_end ();irqentry_nmi_exit (regs, irq_state); }
@@ -2004,7 +2003,9 @@ static __always_inline void exc_machine_ {irqentry_enter_from_user_mode (regs);instrumentation_begin (); +machine_check_vector (regs); +instrumentation_end ();irqentry_exit_to_user_mode (regs); }
[tip: x86/urgent] x86/mce: Remove explicit/superfluous tracing
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 737495361d4469477ffe45d51e6fc56f44f3cc6a Gitweb: https://git.kernel.org/tip/737495361d4469477ffe45d51e6fc56f44f3cc6a Author: Peter Zijlstra <[email protected]> AuthorDate: Wed, 06 Jan 2021 15:36:24 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 12 Jan 2021 21:10:59 +01:00
x86/mce: Remove explicit/superfluous tracing
There's some explicit tracing left in exc_machine_check_kernel(), remove it, as it's already implied by irqentry_nmi_enter().
--- arch/x86/kernel/cpu/mce/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mce/core.c +4 -3
@@ -1992,10 +1992,9 @@ static __always_inline void exc_machine_check_kernel(struct pt_regs *regs)* that out because it's an indirect call. Annotate it. */ instrumentation_begin (); -trace_hardirqs_off_finish (); +machine_check_vector (regs); -if (regs->flags &X86_EFLAGS_IF ) -trace_hardirqs_on_prepare (); +instrumentation_end ();irqentry_nmi_exit (regs, irq_state); }
@@ -2004,7 +2003,9 @@ static __always_inline void exc_machine_check_user(struct pt_regs *regs) {irqentry_enter_from_user_mode (regs);instrumentation_begin (); +machine_check_vector (regs); +instrumentation_end ();irqentry_exit_to_user_mode (regs); }
Peter Zijlstra
maintainerRFC PATCH 6/6 x86/mce: Dont use noinstr for now
In reply to Peter ZijlstraWe call do_machine_check() from a 'safe' context, instrumentation should be possible. However, due to the nature of the beast, MCE is fragile and we really rather would not want to hit additional code.
Currently this is done by marking do_machine_check() as noinstr, however there's at least one objtool warning because of that:
vmlinux.o: warning: objtool: do_machine_check()+0x650: call to queue_task_work() leaves .noinstr.text section
trying to fix that leads down a rabbit-hole. A _lot_ of code would end up having to be marked noinstr outside of the MCE code. While possible, doing so is undesired because it would hide it from instrumentation for all other users.
Instead of using noinstr, kill instrumentation for all of mce/. This switches MCE over to a best-effort but non-validated mode. Doing better will require a significant investment of time and effort.
The obvious problem with tracing the MCE is that the tracer will trigger a further MCE and we DIE an instant death.
--- arch/x86/kernel/cpu/mce/Makefile | 7 +++++++ arch/x86/kernel/cpu/mce/core.c | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/mce/Makefile +7 -0
@@ -1,4 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 + +# No instrumentation for MCE code +KASAN_SANITIZE := n +UBSAN_SANITIZE := n +KCOV_INSTRUMENT := n +ccflags-remove-$(CONFIG_FUNCTION_TRACER) += $(CC_FLAGS_FTRACE) + obj-y = core.o severity.o genpool.o obj-$(CONFIG_X86_ANCIENT_MCE) += winchip.o p5.o
arch/x86/kernel/cpu/mce/core.c +1 -5
@@ -1299,7 +1299,7 @@ static void queue_task_work(struct mce ** backing the user stack, tracing that reads the user stack will cause * potentially infinite recursion. */ -noinstr void do_machine_check(struct pt_regs *regs) +void do_machine_check (struct pt_regs *regs) {DECLARE_BITMAP (valid_banks,MAX_NR_BANKS );DECLARE_BITMAP (toclear,MAX_NR_BANKS );
@@ -1987,10 +1987,6 @@ static __always_inline void exc_machine_return ; irq_state =irqentry_nmi_enter (regs); -/* -* The call targets are marked noinstr, but objtool can't figure -* that out because it's an indirect call. Annotate it. -*/ instrumentation_begin ();machine_check_vector (regs);
Boris Petkov
maintainerRe: [RFC][PATCH 6/6] x86/mce: Dont use noinstr for now
Quoted 3 lines · Peter Zijlstra
Instead of using noinstr, kill instrumentation for all of mce/. This switches MCE over to a best-effort but non-validated mode. Doing better will require a significant investment of time and effort.
Another thing that we could do is carve out only the stuff which needs to be noinstr into a separate compilation unit and disable tracing only for that while keeping the rest traceable. Need to try it to see how ugly it'll get...
Signature · 1 line
Sent from a small device: formatting sux and brevity is inevitable.
Borislav Petkov
maintainerRe: [RFC][PATCH 6/6] x86/mce: Dont use noinstr for now
Quoted 4 lines · Boris Petkov
Another thing that we could do is carve out only the stuff which needs to be noinstr into a separate compilation unit and disable tracing only for that while keeping the rest traceable. Need to try it to see how ugly it'll get...
Something like the below, it barely builds.
I haven't found out whether I can even do
ccflags-remove
on a per-file basis, I guess I cannot so that's not there yet.
core_noinstr.c ended up containing all the code needed by the #MC handler so that should be ok-ish, carve-out-wise.
Also, I've exported a bunch of functions which are in mce/core.c through the internal.h header so that core_noinstr.c can call them. There are no more objtool warnings but if it turns out that we have to move those functions:
+/* core_noinstr.c */
+bool mce_check_crashing_cpu(void);
+void print_mce(struct mce *m);
+void mce_reset(void);
+bool whole_page(struct mce *m);
+u64 mce_rdmsrl(u32 msr);
+void mce_wrmsrl(u32 msr, u64 v);
+void mce_read_aux(struct mce *m, int i);
+void mce_gather_info(struct mce *m, struct pt_regs *regs);
to core_noinstr.c after all, then we can do your solution directly.
Ok, gnight. :-)
---
arch/x86/kernel/cpu/mce/Makefile +6 -1
@@ -1,5 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y = core.o severity.o genpool.o +# No instrumentation for #MC handler code +KASAN_SANITIZE_core_instr.o := n +UBSAN_SANITIZE_core_instr.o := n +KCOV_INSTRUMENT_core_instr.o := n + +obj-y = core.o core_noinstr.o severity.o genpool.o obj-$(CONFIG_X86_ANCIENT_MCE) += winchip.o p5.o obj-$(CONFIG_X86_MCE_INTEL) += intel.o
arch/x86/kernel/cpu/mce/core.c +9 -710
811 lines not on this page · raw message
arch/x86/kernel/cpu/mce/core_noinstr.c new file +712 -0
712 lines not on this page · raw message
arch/x86/kernel/cpu/mce/internal.h +19 -0
@@ -11,6 +11,15 @@/* Pointer to the installed machine check handler for this CPU setup. */ extern void (*machine_check_vector)(struct pt_regs *); +struct mce_bank { +u64 ctl;/* subevents to enable */ +bool init;/* initialise bank? */ +}; + +DECLARE_PER_CPU_READ_MOSTLY(struct mce_bank[MAX_NR_BANKS], mce_banks_array); +extern int fake_panic; +extern void (*quirk_no_way_out)(int bank,struct mce *m,struct pt_regs *regs); +enum severity_level {MCE_NO_SEVERITY ,MCE_DEFERRED_SEVERITY ,
@@ -196,4 +205,14 @@ __visible bool ex_handler_wrmsr_fault(const struct exception_table_entry *fixup,unsigned long error_code, unsigned long fault_addr); +/* core_noinstr.c */ +bool mce_check_crashing_cpu (void ); +void print_mce (struct mce *m); +void mce_reset (void ); +bool whole_page (struct mce *m); +u64 mce_rdmsrl (u32 msr); +void mce_wrmsrl (u32 msr,u64 v); +void mce_read_aux (struct mce *m,int i); +void mce_gather_info (struct mce *m,struct pt_regs *regs); +#endif /* __X86_MCE_INTERNAL_H__ */
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePeter Zijlstra
maintainerRe: [RFC][PATCH 6/6] x86/mce: Dont use noinstr for now
Quoted 42 lines · Borislav Petkov
Quoted 4 lines · Boris Petkov
Another thing that we could do is carve out only the stuff which needs to be noinstr into a separate compilation unit and disable tracing only for that while keeping the rest traceable. Need to try it to see how ugly it'll get...
Something like the below, it barely builds.
I haven't found out whether I can even do
ccflags-remove
on a per-file basis, I guess I cannot so that's not there yet.
core_noinstr.cended up containing all the code needed by the #MC handler so that should be ok-ish, carve-out-wise.Also, I've exported a bunch of functions which are in
mce/core.cthrough theinternal.hheader so thatcore_noinstr.ccan call them. There are no more objtool warnings but if it turns out that we have to move those functions:arch/x86/kernel/cpu/mce/internal.h +9
-0+/* core_noinstr.c */ +bool mce_check_crashing_cpu (void ); +void print_mce (struct mce *m); +void mce_reset (void ); +bool whole_page (struct mce *m); +u64 mce_rdmsrl (u32 msr); +void mce_wrmsrl (u32 msr,u64 v); +void mce_read_aux (struct mce *m,int i); +void mce_gather_info (struct mce *m,struct pt_regs *regs);to
core_noinstr.cafter all, then we can do your solution directly.Ok, gnight. :-)
---
arch/x86/kernel/cpu/mce/Makefile +0
-0
arch/x86/kernel/cpu/mce/Makefile line 5
Quoted 6 lines
arch/x86/kernel/cpu/mce/Makefile +4
-1@@ -1,5 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y = core.o severity.o genpool.o +# No instrumentation for #MC handler code +KASAN_SANITIZE_core_instr.o := n +UBSAN_SANITIZE_core_instr.o := n +KCOV_INSTRUMENT_core_instr.o := n
ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_core_instr.o = $(CC_FLAGS_FTRACE)
endif
arch/x86/kernel/cpu/mce/Makefile line 7
Quoted 2 lines
arch/x86/kernel/cpu/mce/Makefile +2
-0+ +obj-y = core.o core_noinstr.o severity.o genpool.o
I'm thinking
Borislav Petkov
maintainerRe: [RFC][PATCH 6/6] x86/mce: Dont use noinstr for now
Quoted 3 lines · Peter Zijlstra
ifdef
CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_core_instr.o = $(CC_FLAGS_FTRACE)
endif
Ah, looks familiar, thanks!
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette