From patchwork Mon Oct 28 05:23:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 3100531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 01018BF924 for ; Mon, 28 Oct 2013 05:25:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0C12420259 for ; Mon, 28 Oct 2013 05:25:04 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07D9120250 for ; Mon, 28 Oct 2013 05:25:03 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VafJy-0005Fo-Hf; Mon, 28 Oct 2013 05:24:58 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VafJv-0003J6-Uf; Mon, 28 Oct 2013 05:24:55 +0000 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VafJs-0003HO-0m for linux-arm-kernel@lists.infradead.org; Mon, 28 Oct 2013 05:24:53 +0000 Received: by mail-pd0-f174.google.com with SMTP id z10so1851787pdj.5 for ; Sun, 27 Oct 2013 22:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-type:content-transfer-encoding; bh=KXz6OblN/s5LUUj+vS6gHOY08Q7Dxro6Fo7oYRQjPNw=; b=r0F+32bwQ/eo7WftYIcaby9TuUxkHe7qYl9tjnWqnNdPADMW1lQ5LJQFDpNH9wp3Jq HYv3vxtICem9hfyRzFMuxczGKStyMYNxQ1zMipCmoSFU6tgl5wwgdeu8wQ8OmNrSYKJO uRQcts4POexeshw6e5VGzNumU1wWs5I1zUR25sDYNMpO/tdA5+LrW9G6bmTZxEsNVqbA UEEYalcW0LhZkJxN15ZLUYk26eJStqSa6lwMPS7ClUYylKmc2QLUkVOS58ZPFox7OF5+ EztVjLNWqFfcOEvKVOCRE/ihk4Wp5ATTQFLIaBQ41JEXBo7udSgvI/eNcsSrN1xxnBtP uNBw== X-Received: by 10.68.245.227 with SMTP id xr3mr61855pbc.182.1382937869170; Sun, 27 Oct 2013 22:24:29 -0700 (PDT) Received: from tom-ThinkPad-T410 ([183.49.45.239]) by mx.google.com with ESMTPSA id bt1sm25756020pbb.2.2013.10.27.22.24.24 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 27 Oct 2013 22:24:28 -0700 (PDT) Date: Mon, 28 Oct 2013 13:23:48 +0800 From: Ming Lei To: Rusty Russell Subject: Re: [RFC PATCH] kernel/kallsyms.c: only show legal kernel symbol Message-ID: <20131028132348.62f7e368@tom-ThinkPad-T410> In-Reply-To: <874n82gk89.fsf@rustcorp.com.au> References: <1382498320-26594-1-git-send-email-tom.leiming@gmail.com> <87eh7bfoq9.fsf@rustcorp.com.au> <20131024084559.GD16735@n2100.arm.linux.org.uk> <87mwlyclng.fsf@rustcorp.com.au> <87y55h7vcd.fsf@rustcorp.com.au> <87sivp7eai.fsf@rustcorp.com.au> <874n82gk89.fsf@rustcorp.com.au> Organization: Ming X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131028_012452_217813_8871B3A5 X-CRM114-Status: GOOD ( 24.83 ) X-Spam-Score: -2.0 (--) Cc: Michal Marek , Russell King - ARM Linux , Ming Lei , Chen Gang , Linux Kernel Mailing List , Andrew Morton , linux-arm-kernel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 28 Oct 2013 13:44:30 +1030 Rusty Russell wrote: > Ming Lei writes: > > I don't know... It would be your job, as the person making the change, > to find all the users of kallsyms and prove that. > > This is why it is easier not to include incorrect values in the kernel's > kallsyms in the first place. OK, thanks for your comment, and I figured out one way to do it in scripts/kallsyms.c, could you comment on below patch? Acked-by: Rusty Russell --- From 4327534dedfa60d208ac3e23db7556c243e1c7dc Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Mon, 28 Oct 2013 13:04:49 +0800 Subject: [PATCH] scripts/kallsyms: filter symbols not in kernel address space This patch uses CONFIG_PAGE_OFFSET to filter symbols which are not in kernel address space because these symbols are generally for generating code purpose and can't be run at kernel mode, so we needn't keep them in /proc/kallsyms. For example, on ARM there are some symbols which may be linked in relocatable code section, then perf can't parse symbols any more from /proc/kallsyms, this patch fixes the problem. Cc: Russell King Cc: linux-arm-kernel@lists.infradead.org Cc: Rusty Russell Cc: Michal Marek Signed-off-by: Ming Lei --- scripts/kallsyms.c | 12 +++++++++++- scripts/link-vmlinux.sh | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 487ac6f..9a11f9f 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -55,6 +55,7 @@ static struct sym_entry *table; static unsigned int table_size, table_cnt; static int all_symbols = 0; static char symbol_prefix_char = '\0'; +static unsigned long long kernel_start_addr = 0; int token_profit[0x10000]; @@ -65,7 +66,10 @@ unsigned char best_table_len[256]; static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--symbol-prefix=] < in.map > out.S\n"); + fprintf(stderr, "Usage: kallsyms [--all-symbols] " + "[--symbol-prefix=] " + "[--page-offset=] " + "< in.map > out.S\n"); exit(1); } @@ -194,6 +198,9 @@ static int symbol_valid(struct sym_entry *s) int i; int offset = 1; + if (s->addr < kernel_start_addr) + return 0; + /* skip prefix char */ if (symbol_prefix_char && *(s->sym + 1) == symbol_prefix_char) offset++; @@ -646,6 +653,9 @@ int main(int argc, char **argv) if ((*p == '"' && *(p+2) == '"') || (*p == '\'' && *(p+2) == '\'')) p++; symbol_prefix_char = *p; + } else if (strncmp(argv[i], "--page-offset=", 14) == 0) { + const char *p = &argv[i][14]; + kernel_start_addr = strtoull(p, NULL, 16); } else usage(); } diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 0149949..32b10f5 100644 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -82,6 +82,8 @@ kallsyms() kallsymopt="${kallsymopt} --all-symbols" fi + kallsymopt="${kallsymopt} --page-offset=$CONFIG_PAGE_OFFSET" + local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}"