* Re: [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly
[not found] ` <YBPeh9VYq+YdkMNg@hirez.programming.kicks-ass.net>
@ 2021-01-29 13:57 ` Masami Hiramatsu
0 siblings, 0 replies; only message in thread
From: Masami Hiramatsu @ 2021-01-29 13:57 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Alexei Starovoitov, Andy Lutomirski, Andy Lutomirski,
Yonghong Song, Jann Horn, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, bpf, Alexei Starovoitov, kernel-team, X86 ML,
KP Singh, Masami Hiramatsu, systemtap
On Fri, 29 Jan 2021 11:08:07 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> On Fri, Jan 29, 2021 at 10:44:48AM +0100, Peter Zijlstra wrote:
> > There is one case where it hijacks the fault entirely, and I'm tempted
> > to rip that out, that's just gross. Also, it seems entirely unused in-kernel.
>
> Masami, please explain why the below isn't appropriate.
>
> ---
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index df776cdca327..86cd8f15a978 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -949,9 +949,13 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
> * if handler tries to access user space by
> * copy_from_user(), get_user() etc. Let the
> * user-specified handler try to fix it first.
> - */
> + *
> + * Which is a bloody stupid thing to do from non-preemptible code
> + * so why should we support idiocy like that.
> + *
> if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
> return 1;
> + */
> }
Hmm, good point. This is a fail-safe code which, as far as I know, systemtap
uses this hook to count faults and notify user an error (e.g. guru-mode).
I just maintained it to preserve the use case. Actually, in the kernel there
is no fault handler user. e.g. kprobe tracer uses non-fault (safe) kernel
memory access functions.
>
> return 0;
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index 106b22d1d189..817a93da794e 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1186,7 +1186,7 @@ do_kern_addr_fault(struct pt_regs *regs, unsigned long hw_error_code,
> return;
>
> /* kprobes don't want to hook the spurious faults: */
> - if (kprobe_page_fault(regs, X86_TRAP_PF))
> + if (WARN_ON_ONCE(kprobe_page_fault(regs, X86_TRAP_PF)))
> return;
>
> /*
> @@ -1217,7 +1217,7 @@ void do_user_addr_fault(struct pt_regs *regs,
> mm = tsk->mm;
>
> /* kprobes don't want to hook the spurious faults: */
> - if (unlikely(kprobe_page_fault(regs, X86_TRAP_PF)))
> + if (WARN_ON_ONCE(kprobe_page_fault(regs, X86_TRAP_PF)))
> return;
>
> /*
--
Masami Hiramatsu <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-29 13:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20210129023259.wffchzof4rlw5pvs@ast-mbp.dhcp.thefacebook.com>
[not found] ` <D8D2B06A-295E-4E13-A176-0D5D7F226E84@amacapital.net>
[not found] ` <20210129032638.3jpl3fmu5mlvdj3d@ast-mbp.dhcp.thefacebook.com>
[not found] ` <YBPZEF0cTKnoKKVN@hirez.programming.kicks-ass.net>
[not found] ` <YBPeh9VYq+YdkMNg@hirez.programming.kicks-ass.net>
2021-01-29 13:57 ` [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly Masami Hiramatsu
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 read-only IMAP folder(s) and NNTP newsgroup(s).