From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932116AbdBHQIu (ORCPT ); Wed, 8 Feb 2017 11:08:50 -0500 Received: from foss.arm.com ([217.140.101.70]:51400 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753236AbdBHQIq (ORCPT ); Wed, 8 Feb 2017 11:08:46 -0500 Date: Wed, 8 Feb 2017 15:44:34 +0000 From: Mark Rutland To: Peter Zijlstra Cc: jeyu@redhat.com, rusty@rustcorp.com.au, linux-kernel@vger.kernel.org Subject: Re: [PATCH] module: Optimize search_module_extables() Message-ID: <20170208154433.GH15459@leverpostej> References: <20170208144801.GZ6515@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170208144801.GZ6515@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 08, 2017 at 03:48:01PM +0100, Peter Zijlstra wrote: > > While looking through the __ex_table stuff I found that we do a linear > lookup of the module. Also fix up a comment. > > Signed-off-by: Peter Zijlstra (Intel) I'm not all that familiar with the module code, but from a quick scan of __module_address() this looks sane to me. FWIW: Acked-by: Mark Rutland Mark. > --- > kernel/module.c | 27 ++++++++++++++------------- > 1 file changed, 14 insertions(+), 13 deletions(-) > > diff --git a/kernel/module.c b/kernel/module.c > index 3d8f126208e3..7bcdc35dbf95 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -4165,22 +4165,23 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) > struct module *mod; > > preempt_disable(); > - list_for_each_entry_rcu(mod, &modules, list) { > - if (mod->state == MODULE_STATE_UNFORMED) > - continue; > - if (mod->num_exentries == 0) > - continue; > + mod = __module_address(addr); > + if (!mod) > + goto out; > > - e = search_extable(mod->extable, > - mod->extable + mod->num_exentries - 1, > - addr); > - if (e) > - break; > - } > + if (!mod->num_exentries) > + goto out; > + > + e = search_extable(mod->extable, > + mod->extable + mod->num_exentries - 1, > + addr); > +out: > preempt_enable(); > > - /* Now, if we found one, we are running inside it now, hence > - we cannot unload the module, hence no refcnt needed. */ > + /* > + * Now, if we found one, we are running inside it now, hence > + * we cannot unload the module, hence no refcnt needed. > + */ > return e; > } >