From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by sourceware.org (Postfix) with ESMTPS id D22AB3857C5E for ; Fri, 29 Jan 2021 13:57:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D22AB3857C5E Received: by mail.kernel.org (Postfix) with ESMTPSA id 485E464DE7; Fri, 29 Jan 2021 13:57:10 +0000 (UTC) Date: Fri, 29 Jan 2021 22:57:07 +0900 From: Masami Hiramatsu 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@sourceware.org Subject: Re: [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly Message-Id: <20210129225707.225ee83f7d204c0f119dca5f@kernel.org> In-Reply-To: References: <20210129023259.wffchzof4rlw5pvs@ast-mbp.dhcp.thefacebook.com> <20210129032638.3jpl3fmu5mlvdj3d@ast-mbp.dhcp.thefacebook.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: systemtap@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Systemtap mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2021 13:57:16 -0000 On Fri, 29 Jan 2021 11:08:07 +0100 Peter Zijlstra 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