From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933182AbdDZUJV (ORCPT ); Wed, 26 Apr 2017 16:09:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50826 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754251AbdDZUJL (ORCPT ); Wed, 26 Apr 2017 16:09:11 -0400 From: "Naveen N. Rao" To: Michael Ellerman Cc: David Laight , Masami Hiramatsu , Paul Clarke , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kallsyms: optimize kallsyms_lookup_name() for a few cases Date: Thu, 27 Apr 2017 01:38:10 +0530 X-Mailer: git-send-email 2.12.2 In-Reply-To: <87lgqn1m8k.fsf@concordia.ellerman.id.au> References: <87lgqn1m8k.fsf@concordia.ellerman.id.au> X-TM-AS-MML: disable x-cbid: 17042620-1617-0000-0000-000001C6DDC2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042620-1618-0000-0000-000048075453 Message-Id: <20170426200810.2126-1-naveen.n.rao@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-26_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704260337 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michael Ellerman wrote: > "Naveen N. Rao" writes: >> diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c >> index 6a3b249a2ae1..d134b060564f 100644 >> --- a/kernel/kallsyms.c >> +++ b/kernel/kallsyms.c >> @@ -205,6 +205,12 @@ unsigned long kallsyms_lookup_name(const char *name) >> unsigned long i; >> unsigned int off; >> >> + if (!name || *name == '\0') >> + return false; >> + >> + if (strnchr(name, MODULE_NAME_LEN, ':')) >> + return module_kallsyms_lookup_name(name); >> + >> for (i = 0, off = 0; i < kallsyms_num_syms; i++) { >> off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); > ... > } > return module_kallsyms_lookup_name(name); > > Is the rest of the context. > > Which looks a bit odd, we already did module lookup previously? > > But it's correct, because you can lookup a symbol in a module without a > module prefix, it just looks in every module. Yes. > > You could invert the logic, ie. check that there isn't a ":" in the name > and only in that case do the for loop, always falling back to module > lookup. > > Or just add a comment explaining why we call module lookup in two places. Good point. Here's a v2 - I'm using a goto so as to not indent the code too much. Thanks for the review! - Naveen -- [PATCH v2] kallsyms: optimize kallsyms_lookup_name() for a few cases 1. Fail early for invalid/zero length symbols. 2. Detect names of the form and skip checking for kernel symbols in that case. Signed-off-by: Naveen N. Rao --- kernel/kallsyms.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 6a3b249a2ae1..f7558dc5c6ac 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -205,12 +205,20 @@ unsigned long kallsyms_lookup_name(const char *name) unsigned long i; unsigned int off; + if (!name || *name == '\0') + return 0; + + /* For symbols of the form :, only check the modules */ + if (strnchr(name, MODULE_NAME_LEN, ':')) + goto mod; + for (i = 0, off = 0; i < kallsyms_num_syms; i++) { off = kallsyms_expand_symbol(off, namebuf, ARRAY_SIZE(namebuf)); if (strcmp(namebuf, name) == 0) return kallsyms_sym_address(i); } +mod: return module_kallsyms_lookup_name(name); } EXPORT_SYMBOL_GPL(kallsyms_lookup_name); -- 2.12.2