Message ID | tencent_A0E82E0BEE925285F8156D540731DF805F05@qq.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 4a1e885c6d143ff1b557ec7f3fc6ddf39c51502f |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next] samples/bpf: sampleip: Replace PAGE_OFFSET with _text address | expand |
Hello: This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <ast@kernel.org>: On Wed, 12 Apr 2023 16:16:24 +0800 you wrote: > From: Rong Tao <rongtao@cestc.cn> > > Macro PAGE_OFFSET(0xffff880000000000) in sampleip_user.c is inaccurate, > for example, in aarch64 architecture, this value depends on the > CONFIG_ARM64_VA_BITS compilation configuration, this value defaults to 48, > the corresponding PAGE_OFFSET is 0xffff800000000000, if we use the value > defined in sampleip_user.c, then all KSYMs obtained by sampleip are (user) > > [...] Here is the summary with links: - [bpf-next] samples/bpf: sampleip: Replace PAGE_OFFSET with _text address https://git.kernel.org/bpf/bpf-next/c/4a1e885c6d14 You are awesome, thank you!
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c index 921c505bb567..9283f47844fb 100644 --- a/samples/bpf/sampleip_user.c +++ b/samples/bpf/sampleip_user.c @@ -21,10 +21,10 @@ #define DEFAULT_FREQ 99 #define DEFAULT_SECS 5 #define MAX_IPS 8192 -#define PAGE_OFFSET 0xffff880000000000 static int map_fd; static int nr_cpus; +static long _text_addr; static void usage(void) { @@ -108,7 +108,7 @@ static void print_ip_map(int fd) /* sort and print */ qsort(counts, max, sizeof(struct ipcount), count_cmp); for (i = 0; i < max; i++) { - if (counts[i].ip > PAGE_OFFSET) { + if (counts[i].ip > _text_addr) { sym = ksym_search(counts[i].ip); if (!sym) { printf("ksym not found. Is kallsyms loaded?\n"); @@ -169,6 +169,13 @@ int main(int argc, char **argv) return 2; } + /* used to determine whether the address is kernel space */ + _text_addr = ksym_get_addr("_text"); + if (!_text_addr) { + fprintf(stderr, "ERROR: no '_text' in /proc/kallsyms\n"); + return 3; + } + /* create perf FDs for each CPU */ nr_cpus = sysconf(_SC_NPROCESSORS_ONLN); links = calloc(nr_cpus, sizeof(struct bpf_link *));