public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: stable@vger.kernel.org
Cc: Martynas Pumputis <m@lambda.lt>, Song Liu <song@kernel.org>,
	bpf@vger.kernel.org
Subject: [PATCH stable 6.0 2/8] ftrace: Add support to resolve module symbols in ftrace_lookup_symbols
Date: Fri, 16 Dec 2022 13:56:22 +0100	[thread overview]
Message-ID: <20221216125628.1622505-3-jolsa@kernel.org> (raw)
In-Reply-To: <20221216125628.1622505-1-jolsa@kernel.org>

commit 3640bf8584f4ab0f5eed6285f09213954acd8b62 upstream.

Currently ftrace_lookup_symbols iterates only over core symbols,
adding module_kallsyms_on_each_symbol call to check on modules
symbols as well.

Also removing 'args.found == args.cnt' condition, because it's
already checked in kallsyms_callback function.

Also removing 'err < 0' check, because both *kallsyms_on_each_symbol
functions do not return error.

Reported-by: Martynas Pumputis <m@lambda.lt>
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20221025134148.3300700-3-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/trace/ftrace.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 9e6231f4a04f..768306ec3c94 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -8261,6 +8261,10 @@ struct kallsyms_data {
 	size_t found;
 };
 
+/* This function gets called for all kernel and module symbols
+ * and returns 1 in case we resolved all the requested symbols,
+ * 0 otherwise.
+ */
 static int kallsyms_callback(void *data, const char *name,
 			     struct module *mod, unsigned long addr)
 {
@@ -8304,17 +8308,19 @@ static int kallsyms_callback(void *data, const char *name,
 int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs)
 {
 	struct kallsyms_data args;
-	int err;
+	int found_all;
 
 	memset(addrs, 0, sizeof(*addrs) * cnt);
 	args.addrs = addrs;
 	args.syms = sorted_syms;
 	args.cnt = cnt;
 	args.found = 0;
-	err = kallsyms_on_each_symbol(kallsyms_callback, &args);
-	if (err < 0)
-		return err;
-	return args.found == args.cnt ? 0 : -ESRCH;
+
+	found_all = kallsyms_on_each_symbol(kallsyms_callback, &args);
+	if (found_all)
+		return 0;
+	found_all = module_kallsyms_on_each_symbol(kallsyms_callback, &args);
+	return found_all ? 0 : -ESRCH;
 }
 
 #ifdef CONFIG_SYSCTL
-- 
2.38.1


  parent reply	other threads:[~2022-12-16 12:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 12:56 [PATCH stable 6.0 0/8] bpf: Fix kprobe_multi link attachment to kernel modules Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 1/8] kallsyms: Make module_kallsyms_on_each_symbol generally available Jiri Olsa
2022-12-16 12:56 ` Jiri Olsa [this message]
2022-12-16 12:56 ` [PATCH stable 6.0 3/8] bpf: Rename __bpf_kprobe_multi_cookie_cmp to bpf_kprobe_multi_addrs_cmp Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 4/8] bpf: Take module reference on kprobe_multi link Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 5/8] selftests/bpf: Add load_kallsyms_refresh function Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 6/8] selftests/bpf: Add bpf_testmod_fentry_* functions Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 7/8] selftests/bpf: Add kprobe_multi check to module attach test Jiri Olsa
2022-12-16 12:56 ` [PATCH stable 6.0 8/8] selftests/bpf: Add kprobe_multi kmod attach api tests Jiri Olsa
2022-12-19 12:24 ` [PATCH stable 6.0 0/8] bpf: Fix kprobe_multi link attachment to kernel modules Greg KH

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=20221216125628.1622505-3-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=m@lambda.lt \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    /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