From: Changbin Du <changbin.du@gmail.com>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: linux-riscv@lists.infradead.org, changbin.du@gmail.com,
rostedt@goodmis.org, mingo@redhat.com,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
aou@eecs.berkeley.edu, linux-kernel@vger.kernel.org,
Palmer Dabbelt <palmerdabbelt@google.com>
Subject: Re: [PATCH] RISC-V: Don't check text_mutex during stop_machine
Date: Sun, 1 May 2022 22:09:53 +0800 [thread overview]
Message-ID: <20220501140953.3dkqa6jhkcxzammq@mail.google.com> (raw)
In-Reply-To: <20220322022331.32136-1-palmer@rivosinc.com>
On Mon, Mar 21, 2022 at 07:23:31PM -0700, Palmer Dabbelt wrote:
> From: Palmer Dabbelt <palmerdabbelt@google.com>
>
> We're currently using stop_machine() to update ftrace, which means that
> the thread that takes text_mutex during ftrace_prepare() may not be the
> same as the thread that eventually patches the code. This isn't
> actually a race because the lock is still held (preventing any other
> concurrent accesses) and there is only one thread running during
> stop_machine(), but it does trigger a lockdep failure.
>
> This patch just elides the lockdep check during stop_machine.
>
> Fixes: c15ac4fd60d5 ("riscv/ftrace: Add dynamic function tracer support")
> Suggested-by: Steven Rostedt <rostedt@goodmis.org>
> Reported-by: Changbin Du <changbin.du@gmail.com>
> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
>
> --
>
> Changes since v1 [<20210506071041.417854-1-palmer@dabbelt.com>]:
> * Use ftrace_arch_ocde_modify_{prepare,post_process}() to set the flag.
> I remember having a reason I wanted the function when I wrote the v1,
> but it's been almost a year and I forget what that was -- maybe I was
> just crazy, the patch was sent at midnight.
> * Fix DYNAMIC_FTRACE=n builds.
> ---
> arch/riscv/include/asm/ftrace.h | 7 +++++++
> arch/riscv/kernel/ftrace.c | 12 ++++++++++++
> arch/riscv/kernel/patch.c | 10 +++++++++-
> 3 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h
> index 04dad3380041..3ac7609f4ee9 100644
> --- a/arch/riscv/include/asm/ftrace.h
> +++ b/arch/riscv/include/asm/ftrace.h
> @@ -81,8 +81,15 @@ do { \
> struct dyn_ftrace;
> int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
> #define ftrace_init_nop ftrace_init_nop
> +extern int riscv_ftrace_in_stop_machine;
> #endif
>
> +#else /* CONFIG_DYNAMIC_FTRACE */
> +
> +#ifndef __ASSEMBLY__
> +#define riscv_ftrace_in_stop_machine 0
> #endif
>
> +#endif /* CONFIG_DYNAMIC_FTRACE */
> +
> #endif /* _ASM_RISCV_FTRACE_H */
> diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c
> index 4716f4cdc038..c5f77922d7ea 100644
> --- a/arch/riscv/kernel/ftrace.c
> +++ b/arch/riscv/kernel/ftrace.c
> @@ -11,15 +11,27 @@
> #include <asm/cacheflush.h>
> #include <asm/patch.h>
>
> +int riscv_ftrace_in_stop_machine;
> +
> #ifdef CONFIG_DYNAMIC_FTRACE
> int ftrace_arch_code_modify_prepare(void) __acquires(&text_mutex)
> {
> mutex_lock(&text_mutex);
> +
> + /*
> + * The code sequences we use for ftrace can't be patched while the
> + * kernel is running, so we need to use stop_machine() to modify them
> + * for now. This doesn't play nice with text_mutex, we use this flag
> + * to elide the check.
> + */
> + riscv_ftrace_in_stop_machine = true;
> +
> return 0;
> }
>
> int ftrace_arch_code_modify_post_process(void) __releases(&text_mutex)
> {
> + riscv_ftrace_in_stop_machine = false;
> mutex_unlock(&text_mutex);
> return 0;
> }
The function ftrace_init_nop() should be updated. That's not in stop-machine
context.
@@ -136,9 +124,9 @@ int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
{
int out;
- ftrace_arch_code_modify_prepare();
+ mutex_lock(&text_mutex);
out = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
- ftrace_arch_code_modify_post_process();
+ mutex_unlock(&text_mutex);
--
Cheers,
Changbin Du
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-05-01 14:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-22 2:23 [PATCH] RISC-V: Don't check text_mutex during stop_machine Palmer Dabbelt
2022-05-01 14:09 ` Changbin Du [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-05-06 7:10 Palmer Dabbelt
2021-05-06 12:31 ` kernel test robot
2021-05-06 13:20 ` Steven Rostedt
2021-05-06 13:25 ` Steven Rostedt
2021-05-22 19:32 ` Palmer Dabbelt
2021-05-28 22:21 ` Steven Rostedt
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=20220501140953.3dkqa6jhkcxzammq@mail.google.com \
--to=changbin.du@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=palmer@rivosinc.com \
--cc=palmerdabbelt@google.com \
--cc=paul.walmsley@sifive.com \
--cc=rostedt@goodmis.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