linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: bigeasy@linutronix.de
Cc: bp@alien8.de, da.gomez@samsung.com, dave.hansen@linux.intel.com,
	hpa@zytor.com, jpoimboe@kernel.org, linux-kernel@vger.kernel.org,
	linux-modules@vger.kernel.org, mcgrof@kernel.org,
	mingo@redhat.com, paulmck@kernel.org, peterz@infradead.org,
	petr.pavlu@suse.com, samitolvanen@google.com, tglx@linutronix.de,
	x86@kernel.org
Subject: Re: [PATCH v3 22/28] x86: Use RCU in all users of __module_address().
Date: Mon, 3 Nov 2025 11:08:35 +0100	[thread overview]
Message-ID: <20251103110835.1dca378c.michal.pecio@gmail.com> (raw)
In-Reply-To: <20250108090457.512198-23-bigeasy@linutronix.de>

> x86: Use RCU in all users of __module_address().
>
> __module_address() can be invoked within a RCU section, there is no
> requirement to have preemption disabled.
> 
> Replace the preempt_disable() section around __module_address() with
> RCU.
> 
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: x86@kernel.org
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>  arch/x86/kernel/callthunks.c | 3 +--
>  arch/x86/kernel/unwind_orc.c | 4 +---
>  2 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c
> index f17d166078823..276b5368ff6b0 100644
> --- a/arch/x86/kernel/callthunks.c
> +++ b/arch/x86/kernel/callthunks.c
> @@ -98,11 +98,10 @@ static inline bool within_module_coretext(void *addr)
>  #ifdef CONFIG_MODULES
>  	struct module *mod;
>  
> -	preempt_disable();
> +	guard(rcu)();
>  	mod = __module_address((unsigned long)addr);
>  	if (mod && within_module_core((unsigned long)addr, mod))
>  		ret = true;
> -	preempt_enable();
>  #endif
>  	return ret;
>  }
> diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
> index d4705a348a804..977ee75e047c8 100644
> --- a/arch/x86/kernel/unwind_orc.c
> +++ b/arch/x86/kernel/unwind_orc.c
> @@ -476,7 +476,7 @@ bool unwind_next_frame(struct unwind_state *state)
>  		return false;
>  
>  	/* Don't let modules unload while we're reading their ORC data. */
> -	preempt_disable();
> +	guard(rcu)();
>  
>  	/* End-of-stack check for user tasks: */
>  	if (state->regs && user_mode(state->regs))
> @@ -669,14 +669,12 @@ bool unwind_next_frame(struct unwind_state *state)
>  		goto err;
>  	}
>  
> -	preempt_enable();
>  	return true;

Hi,

There is a regression report on a distribution forum which involves
an out of tree module on a patched kernel (yes, I know) calling
stack_trace_save() in task context, which arrives here and apparently
calls the various deref_stack_xxx() functions with preemption enabled,
which in turn call stack_access_ok() leading to a BUG:

Nov 02 21:44:30 ArchBasement kernel: BUG: using smp_processor_id() in preemptible [00000000] code: Xorg/1183
Nov 02 21:44:30 ArchBasement kernel: caller is in_entry_stack+0x11/0x60
Nov 02 21:44:30 ArchBasement kernel: CPU: 0 UID: 1000 PID: 1183 Comm: Xorg Tainted: P           OE       6.16.12-hardened1-1-hardened #1 PREEMPT(full)  6edb90a7a07fab33bbee72d6d5ef53ba6eec3b9c
Nov 02 21:44:30 ArchBasement kernel: Tainted: [P]=PROPRIETARY_MODULE, [O]=OOT_MODULE, [E]=UNSIGNED_MODULE
Nov 02 21:44:30 ArchBasement kernel: Hardware name: ASUS All Series/Z97-E, BIOS 0803 02/23/2016
Nov 02 21:44:30 ArchBasement kernel: Call Trace:
Nov 02 21:44:30 ArchBasement kernel:  <TASK>
Nov 02 21:44:30 ArchBasement kernel:  dump_stack_lvl+0x5d/0x80
Nov 02 21:44:30 ArchBasement kernel:  check_preemption_disabled+0xe5/0xf0
Nov 02 21:44:30 ArchBasement kernel:  in_entry_stack+0x11/0x60
Nov 02 21:44:30 ArchBasement kernel:  get_stack_info+0x2c/0x80
Nov 02 21:44:30 ArchBasement kernel:  stack_access_ok+0x51/0xa0
Nov 02 21:44:30 ArchBasement kernel:  unwind_next_frame+0x1cb/0x7b0
Nov 02 21:44:30 ArchBasement kernel:  ? _nv003168kms+0x42/0x50 [nvidia_modeset 90775ea8a26c5e58b97ef4b3f46eb45efa040eb2]
Nov 02 21:44:30 ArchBasement kernel:  ? __pfx_stack_trace_consume_entry+0x10/0x10
Nov 02 21:44:30 ArchBasement kernel:  arch_stack_walk+0xa6/0x110
Nov 02 21:44:30 ArchBasement kernel:  ? _nv003168kms+0x42/0x50 [nvidia_modeset 90775ea8a26c5e58b97ef4b3f46eb45efa040eb2]
Nov 02 21:44:30 ArchBasement kernel:  stack_trace_save+0x4d/0x70

Is this nvidia doing something wrong, or a problem with this commit?

The removed code suggests that preemption is allowed here, and as far
as I see, this call trace is still possible on vanilla 6.18. Perhaps
preempt_disable() needs to be restored around this code?

Regards,
Michal

  reply	other threads:[~2025-11-03 10:08 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  9:04 [PATCH v3 00/28] module: Use RCU instead of RCU-sched Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 01/28] module: Extend the preempt disabled section in dereference_symbol_descriptor() Sebastian Andrzej Siewior
2025-01-08  9:55   ` Helge Deller
2025-01-08 10:52     ` Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 02/28] module: Begin to move from RCU-sched to RCU Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 03/28] module: Use proper RCU assignment in add_kallsyms() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 04/28] module: Use RCU in find_kallsyms_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 05/28] module: Use RCU in module_get_kallsym() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 06/28] module: Use RCU in find_module_all() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 07/28] module: Use RCU in __find_kallsyms_symbol_value() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 08/28] module: Use RCU in module_kallsyms_on_each_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 09/28] module: Remove module_assert_mutex_or_preempt() from try_add_tainted_module() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 10/28] module: Use RCU in find_symbol() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 11/28] module: Use RCU in __is_module_percpu_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 12/28] module: Allow __module_address() to be called from RCU section Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 13/28] module: Use RCU in search_module_extables() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 14/28] module: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 15/28] module: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2025-04-23 15:17   ` Benjamin Berg
2025-04-23 18:16     ` Paul E. McKenney
2025-04-24  9:05       ` Sebastian Andrzej Siewior
2025-04-24  9:30         ` Benjamin Berg
2025-04-24 14:47           ` Paul E. McKenney
2025-04-24 15:17           ` Peter Zijlstra
2025-01-08  9:04 ` [PATCH v3 16/28] ARM: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 17/28] arm64: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 18/28] LoongArch/orc: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 19/28] LoongArch: ftrace: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 20/28] powerpc/ftrace: " Sebastian Andrzej Siewior
2025-01-20 10:09   ` Shrikanth Hegde
2025-01-08  9:04 ` [PATCH v3 21/28] cfi: Use RCU while invoking __module_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 22/28] x86: Use RCU in all users of __module_address() Sebastian Andrzej Siewior
2025-11-03 10:08   ` Michal Pecio [this message]
2025-11-03 10:34     ` Sebastian Andrzej Siewior
2025-11-03 10:39       ` Michal Pecio
2025-11-03 11:37         ` Sebastian Andrzej Siewior
2025-11-03 17:37           ` Michal Pecio
2025-01-08  9:04 ` [PATCH v3 23/28] jump_label: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 24/28] jump_label: Use RCU in all users of __module_text_address() Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 25/28] bpf: " Sebastian Andrzej Siewior
2025-01-09 18:38   ` Alexei Starovoitov
2025-01-09 20:54     ` Sebastian Andrzej Siewior
2025-01-09 21:00       ` Alexei Starovoitov
2025-01-29  8:47         ` [PATCH v3.5 " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 26/28] kprobes: " Sebastian Andrzej Siewior
2025-01-28  5:44   ` Masami Hiramatsu
2025-01-28  7:10     ` Sebastian Andrzej Siewior
2025-01-29  8:49     ` [PATCH v3.5 25/28] " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 27/28] static_call: " Sebastian Andrzej Siewior
2025-01-08  9:04 ` [PATCH v3 28/28] bug: Use RCU instead RCU-sched to protect module_bug_list Sebastian Andrzej Siewior
2025-01-13 11:09 ` [PATCH v3 00/28] module: Use RCU instead of RCU-sched Petr Pavlu
2025-01-13 13:23   ` Sebastian Andrzej Siewior
2025-01-24 17:49   ` Sebastian Andrzej Siewior
2025-01-27 12:22     ` Petr Pavlu
2025-01-29  8:52       ` Sebastian Andrzej Siewior
2025-01-30 13:42         ` Petr Pavlu

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=20251103110835.1dca378c.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=bp@alien8.de \
    --cc=da.gomez@samsung.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=tglx@linutronix.de \
    --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).