Re: [PATCH v5 14/21] kprobes: Remove NMI context check
From: Steven Rostedt
Date: Mon Nov 02 2020 - 09:27:33 EST
[ Peter Z, please take a look a this ]
On Mon, 2 Nov 2020 16:02:34 +0900
Masami Hiramatsu <mhiramat@xxxxxxxxxx> wrote:
> >From 509b27efef8c7dbf56cab2e812916d6cd778c745 Mon Sep 17 00:00:00 2001
> From: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> Date: Mon, 2 Nov 2020 15:37:28 +0900
> Subject: [PATCH] kprobes: Disable lockdep for kprobe busy area
>
> Since the code area in between kprobe_busy_begin()/end() prohibits
> other kprobs to call probe handlers, we can avoid inconsitent
> locks there. But lockdep doesn't know that, so it warns rp->lock
> or kretprobe_table_lock.
>
> To supress those false-positive errors, disable lockdep while
> kprobe_busy is set.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
> ---
> kernel/kprobes.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 8a12a25fa40d..c7196e583600 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1295,10 +1295,12 @@ void kprobe_busy_begin(void)
> __this_cpu_write(current_kprobe, &kprobe_busy);
> kcb = get_kprobe_ctlblk();
> kcb->kprobe_status = KPROBE_HIT_ACTIVE;
> + lockdep_off();
> }
>
> void kprobe_busy_end(void)
> {
> + lockdep_on();
> __this_cpu_write(current_kprobe, NULL);
> preempt_enable();
> }
> --
No, this is not the correct workaround (too big of a hammer). You could do
the following: