From: Changbin Du <changbin.du@gmail.com>
To: guoren@kernel.org
Cc: palmer@dabbelt.com, paul.walmsley@sifive.com,
aou@eecs.berkeley.edu, mhiramat@kernel.org,
changbin.du@intel.com, zong.li@sifive.com, rostedt@goodmis.org,
boqun.feng@gmail.com, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, Changbin Du <changbin.du@gmail.com>
Subject: Re: [PATCH V2] riscv: patch: Fixup lockdep warning in stop_machine
Date: Thu, 22 Dec 2022 20:22:07 +0800 [thread overview]
Message-ID: <20221222122207.3ycdew6azfg6cqwy@mail.google.com> (raw)
In-Reply-To: <20221120101049.2078117-1-guoren@kernel.org>
On Sun, Nov 20, 2022 at 05:10:49AM -0500, guoren@kernel.org wrote:
> From: Changbin Du <changbin.du@gmail.com>
>
> The task of ftrace_arch_code_modify(_post)_prepare() caller is
> stop_machine, whose caller and work thread are different tasks. The
> lockdep checker needs the same task context, or it's wrong. That means
> it's a bug here to use lockdep_assert_held because we don't guarantee
> the same task context.
>
> kernel/locking/lockdep.c:
> int __lock_is_held(const struct lockdep_map *lock, int read)
> {
> struct task_struct *curr = current;
> int i;
>
> for (i = 0; i < curr->lockdep_depth; i++) {
> ^^^^^^^^^^^^^^^^^^^
> struct held_lock *hlock = curr->held_locks + i;
> ^^^^^^^^^^^^^^^^
> if (match_held_lock(hlock, lock)) {
> if (read == -1 || !!hlock->read == read)
> return LOCK_STATE_HELD;
>
> The __lock_is_held depends on current held_locks records; if
> stop_machine makes the checker runing on another task, that's wrong.
>
> Here is the log:
> [ 15.761523] ------------[ cut here ]------------
> [ 15.762125] WARNING: CPU: 0 PID: 15 at arch/riscv/kernel/patch.c:63 patch_insn_write+0x72/0x364
> [ 15.763258] Modules linked in:
> [ 15.764154] CPU: 0 PID: 15 Comm: migration/0 Not tainted 6.1.0-rc1-00014-g66924be85884-dirty #377
> [ 15.765339] Hardware name: riscv-virtio,qemu (DT)
> [ 15.765985] Stopper: multi_cpu_stop+0x0/0x192 <- stop_cpus.constprop.0+0x90/0xe2
> [ 15.766711] epc : patch_insn_write+0x72/0x364
> [ 15.767011] ra : patch_insn_write+0x70/0x364
> [ 15.767276] epc : ffffffff8000721e ra : ffffffff8000721c sp : ff2000000067bca0
> [ 15.767622] gp : ffffffff81603f90 tp : ff60000002432a00 t0 : 7300000000000000
> [ 15.767919] t1 : 0000000000000000 t2 : 73695f6b636f6c5f s0 : ff2000000067bcf0
> [ 15.768238] s1 : 0000000000000008 a0 : 0000000000000000 a1 : 0000000000000000
> [ 15.768537] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000
> [ 15.768837] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000
> [ 15.769139] s2 : ffffffff80009faa s3 : ff2000000067bd10 s4 : ffffffffffffffff
> [ 15.769447] s5 : 0000000000000001 s6 : 0000000000000001 s7 : 0000000000000003
> [ 15.769740] s8 : 0000000000000002 s9 : 0000000000000004 s10: 0000000000000003
> [ 15.770027] s11: 0000000000000002 t3 : 0000000000000000 t4 : ffffffff819af097
> [ 15.770323] t5 : ffffffff819af098 t6 : ff2000000067ba28
> [ 15.770574] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000003
> [ 15.771102] [<ffffffff80007520>] patch_text_nosync+0x10/0x3a
> [ 15.771421] [<ffffffff80009c66>] ftrace_update_ftrace_func+0x74/0x10a
> [ 15.771704] [<ffffffff800fa17e>] ftrace_modify_all_code+0xb0/0x16c
> [ 15.771958] [<ffffffff800fa24c>] __ftrace_modify_code+0x12/0x1c
> [ 15.772196] [<ffffffff800e110e>] multi_cpu_stop+0x14a/0x192
> [ 15.772454] [<ffffffff800e0a34>] cpu_stopper_thread+0x96/0x14c
> [ 15.772699] [<ffffffff8003f4ea>] smpboot_thread_fn+0xf8/0x1cc
> [ 15.772945] [<ffffffff8003ac9c>] kthread+0xe2/0xf8
> [ 15.773160] [<ffffffff80003e98>] ret_from_exception+0x0/0x14
> [ 15.773471] ---[ end trace 0000000000000000 ]---
>
> Fixes: 0ff7c3b33127 ("riscv: Use text_mutex instead of patch_lock")
> Cc: Changbin Du <changbin.du@gmail.com>
> Co-developed-by: Guo Ren <guoren@kernel.org>
> Signed-off-by: Guo Ren <guoren@kernel.org>
> Cc: Zong Li <zong.li@sifive.com>
> Cc: Palmer Dabbelt <palmer@dabbelt.com>
> ---
> Changes in v2:
> - Rewrite commit log with lockdep explanation [Guo Ren]
> - Rebase on v6.1 [Guo Ren]
>
> v1:
> https://lore.kernel.org/linux-riscv/20210417023532.354714-1-changbin.du@gmail.com/
> ---
> arch/riscv/kernel/patch.c | 7 -------
> 1 file changed, 7 deletions(-)
>
> diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> index 765004b60513..8619706f8dfd 100644
> --- a/arch/riscv/kernel/patch.c
> +++ b/arch/riscv/kernel/patch.c
> @@ -55,13 +55,6 @@ static int patch_insn_write(void *addr, const void *insn, size_t len)
> bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE;
> int ret;
>
> - /*
> - * Before reaching here, it was expected to lock the text_mutex
> - * already, so we don't need to give another lock here and could
> - * ensure that it was safe between each cores.
> - */
> - lockdep_assert_held(&text_mutex);
> -
> if (across_pages)
> patch_map(addr + len, FIX_TEXT_POKE1);
>
> --
> 2.36.1
>
Signed-off-by: Changbin Du <changbin.du@gmail.com>
Thanks!
prev parent reply other threads:[~2022-12-22 12:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-20 10:10 guoren
2022-11-21 10:12 ` Conor Dooley
2022-11-21 11:09 ` Guo Ren
2022-12-22 0:19 ` Changbin Du
2022-12-22 0:29 ` Conor Dooley
2022-12-22 12:23 ` Changbin Du
2022-12-22 2:43 ` Guo Ren
2022-12-22 12:22 ` Changbin Du [this message]
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=20221222122207.3ycdew6azfg6cqwy@mail.google.com \
--to=changbin.du@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=boqun.feng@gmail.com \
--cc=changbin.du@intel.com \
--cc=guoren@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rostedt@goodmis.org \
--cc=zong.li@sifive.com \
/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
all inboxes | Powered by JetHome®