Netdev List
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: <netdev@vger.kernel.org>
Cc: <kernel-team@fb.com>, Song Liu <songliubraving@fb.com>,
	<ast@kernel.org>, <daniel@iogearbox.net>,
	<sandipan@linux.vnet.ibm.com>
Subject: [PATCH  v2 bpf 1/3] bpf: show real jited prog address in /proc/kallsyms
Date: Fri, 2 Nov 2018 10:16:15 -0700	[thread overview]
Message-ID: <20181102171617.310178-2-songliubraving@fb.com> (raw)
In-Reply-To: <20181102171617.310178-1-songliubraving@fb.com>

Currently, /proc/kallsyms shows page address of jited bpf program. The
main reason here is to not expose randomized start address. However,
This is not ideal for detailed profiling (find hot instructions from
stack traces). This patch replaces the page address with real prog start
address.

This change is OK because these addresses are still protected by sysctl
kptr_restrict (see kallsyms_show_value()), and only programs loaded by
root are added to kallsyms (see bpf_prog_kallsyms_add()).

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 kernel/bpf/core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 6377225b2082..1a796e0799ec 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -553,7 +553,6 @@ bool is_bpf_text_address(unsigned long addr)
 int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 		    char *sym)
 {
-	unsigned long symbol_start, symbol_end;
 	struct bpf_prog_aux *aux;
 	unsigned int it = 0;
 	int ret = -ERANGE;
@@ -566,10 +565,9 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 		if (it++ != symnum)
 			continue;
 
-		bpf_get_prog_addr_region(aux->prog, &symbol_start, &symbol_end);
 		bpf_get_prog_name(aux->prog, sym);
 
-		*value = symbol_start;
+		*value = (unsigned long)aux->prog->bpf_func;
 		*type  = BPF_SYM_ELF_TYPE;
 
 		ret = 0;
-- 
2.17.1

  reply	other threads:[~2018-11-03  2:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-02 17:16 [PATCH v2 bpf 0/3] show more accurrate bpf program address Song Liu
2018-11-02 17:16 ` Song Liu [this message]
2018-11-02 17:16 ` [PATCH v2 bpf 2/3] bpf: show real jited address in bpf_prog_info->jited_ksyms Song Liu
2018-11-02 17:16 ` [PATCH v2 bpf 3/3] bpf: show main program address and length in bpf_prog_info Song Liu
2018-11-02 20:45 ` [PATCH v2 bpf 0/3] show more accurrate bpf program address Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181102171617.310178-2-songliubraving@fb.com \
    --to=songliubraving@fb.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=sandipan@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox