public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Andy Lutomirski <luto@kernel.org>, Yonghong Song <yhs@fb.com>,
	Jann Horn <jannh@google.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andriin@fb.com>, Martin KaFai Lau <kafai@fb.com>,
	bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	kernel-team <kernel-team@fb.com>, X86 ML <x86@kernel.org>,
	KP Singh <kpsingh@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	systemtap@sourceware.org
Subject: Re: [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly
Date: Fri, 29 Jan 2021 22:57:07 +0900	[thread overview]
Message-ID: <20210129225707.225ee83f7d204c0f119dca5f@kernel.org> (raw)
In-Reply-To: <YBPeh9VYq+YdkMNg@hirez.programming.kicks-ass.net>

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>

           reply	other threads:[~2021-01-29 13:57 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <YBPeh9VYq+YdkMNg@hirez.programming.kicks-ass.net>]

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=20210129225707.225ee83f7d204c0f119dca5f@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jannh@google.com \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=systemtap@sourceware.org \
    --cc=x86@kernel.org \
    --cc=yhs@fb.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).