From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934682AbdACKzw (ORCPT ); Tue, 3 Jan 2017 05:55:52 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:59728 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756818AbdACKyQ (ORCPT ); Tue, 3 Jan 2017 05:54:16 -0500 Date: Tue, 3 Jan 2017 11:54:02 +0100 From: Peter Zijlstra To: Masami Hiramatsu Cc: Ingo Molnar , Josh Poimboeuf , linux-kernel@vger.kernel.org, Ananth N Mavinakayanahalli , Thomas Gleixner , "H . Peter Anvin" , Andrey Konovalov , Steven Rostedt Subject: Re: [PATCH tip/master v3] kprobes: extable: Identify kprobes' insn-slots as kernel text area Message-ID: <20170103105402.GB25813@worktop.programming.kicks-ass.net> References: <20161226133012.347f7e45dbf8a8d671ea07fb@kernel.org> <148281924021.12148.14275351848773920571.stgit@devbox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <148281924021.12148.14275351848773920571.stgit@devbox> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 27, 2016 at 03:14:10PM +0900, Masami Hiramatsu wrote: > diff --git a/kernel/extable.c b/kernel/extable.c > index e820cce..81c9633 100644 > --- a/kernel/extable.c > +++ b/kernel/extable.c > @@ -123,7 +126,11 @@ int kernel_text_address(unsigned long addr) > return 1; > if (is_module_text_address(addr)) > return 1; > - return is_ftrace_trampoline(addr); > + if (is_ftrace_trampoline(addr)) > + return 1; > + if (is_kprobe_optinsn_slot(addr) || is_kprobe_insn_slot(addr)) > + return 1; > + return 0; > } > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index d630954..be41f6d 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > +/* > + * Check given address is on the page of kprobe instruction slots. > + * This will be used for checking whether the address on a stack > + * is on a text area or not. > + */ > +bool __is_insn_slot_addr(struct kprobe_insn_cache *c, unsigned long addr) > +{ > + struct kprobe_insn_page *kip; > + bool ret = false; > + > + rcu_read_lock(); > + list_for_each_entry_rcu(kip, &c->pages, list) { > + if (addr >= (unsigned long)kip->insns && > + addr < (unsigned long)kip->insns + PAGE_SIZE) { > + ret = true; > + break; > + } > + } > + rcu_read_unlock(); > + > + return ret; > +} How many entries should one expect on that list? I spend quite a bit of time reducing the cost of is_module_text_address() a while back and see that both ftrace (which actually needs this to be fast) and now kprobes have linear list walks in here. I'm assuming the ftrace thing to be mostly empty, since I never saw it on my benchmarks back then, but it is something Steve should look at I suppose. Similarly, the changelog here should include some talk about worst case costs. FWIW, see commit: 93c2e105f6bc ("module: Optimize __module_address() using a latched RB-tree")