Re: [PATCH 1/2] kprobes: Remove kprobe::fault_handler

From: Masami Hiramatsu
Date: Wed May 26 2021 - 09:51:18 EST


On Wed, 26 May 2021 16:20:25 +0530
"Naveen N. Rao" <naveen.n.rao@xxxxxxxxxxxxxxxxxx> wrote:

> Peter Zijlstra wrote:
> > The reason for kprobe::fault_handler(), as given by their comment:
> >
> > * We come here because instructions in the pre/post
> > * handler caused the page_fault, this could happen
> > * if handler tries to access user space by
> > * copy_from_user(), get_user() etc. Let the
> > * user-specified handler try to fix it first.
> >
> > Is just plain bad. Those other handlers are ran from non-preemptible
> > context and had better use _nofault() functions. Also, there is no
> > upstream usage of this.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > Reviewed-by: Christoph Hellwig <hch@xxxxxx>
> > ---
> > Documentation/trace/kprobes.rst | 24 +++++-------------------
> > arch/arc/kernel/kprobes.c | 10 ----------
> > arch/arm/probes/kprobes/core.c | 9 ---------
> > arch/arm64/kernel/probes/kprobes.c | 10 ----------
> > arch/csky/kernel/probes/kprobes.c | 10 ----------
> > arch/ia64/kernel/kprobes.c | 9 ---------
> > arch/mips/kernel/kprobes.c | 3 ---
> > arch/powerpc/kernel/kprobes.c | 10 ----------
> > arch/riscv/kernel/probes/kprobes.c | 10 ----------
> > arch/s390/kernel/kprobes.c | 10 ----------
> > arch/sh/kernel/kprobes.c | 10 ----------
> > arch/sparc/kernel/kprobes.c | 10 ----------
> > arch/x86/kernel/kprobes/core.c | 10 ----------
> > include/linux/kprobes.h | 8 --------
> > kernel/kprobes.c | 19 -------------------
> > samples/kprobes/kprobe_example.c | 15 ---------------
> > 16 files changed, 5 insertions(+), 172 deletions(-)
> >
>
> <snip>
>
> > --- a/arch/x86/kernel/kprobes/core.c
> > +++ b/arch/x86/kernel/kprobes/core.c
> > @@ -947,16 +947,6 @@ int kprobe_fault_handler(struct pt_regs
> > * these specific fault cases.
> > */
> > kprobes_inc_nmissed_count(cur);
>
> Not necessarily related, but I'm wondering why we're incrementing the
> probe miss count here. Unlike what the comment above indicates, this is
> not a 'fault' counter, but just a count of the number of times the probe
> handler wasn't called.

Good catch! Indeed, we have no ned to count these fault because
it anyway gets back to the user handler. (so no user_handler is skipped)
Hmm, we need to clean up these countings too.

Thank you,

>
> > -
> > - /*
> > - * We come here because instructions in the pre/post
> > - * handler caused the page_fault, this could happen
> > - * if handler tries to access user space by
> > - * copy_from_user(), get_user() etc. Let the
> > - * user-specified handler try to fix it first.
> > - */
> > - if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
> > - return 1;
> > }
>
>
> - Naveen
>


--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>