linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ftrace: Fix possible warning on checking all pages used in ftrace_process_locs()
@ 2023-07-10 21:29 Zheng Yejian
  2023-07-10 14:46 ` Steven Rostedt
  0 siblings, 1 reply; 9+ messages in thread
From: Zheng Yejian @ 2023-07-10 21:29 UTC (permalink / raw)
  To: rostedt, mhiramat; +Cc: linux-kernel, linux-trace-kernel, zhengyejian1

As comments in ftrace_process_locs(), there may be NULL pointers in
mcount_loc section:
 > Some architecture linkers will pad between
 > the different mcount_loc sections of different
 > object files to satisfy alignments.
 > Skip any NULL pointers.

After 20e5227e9f55 ("ftrace: allow NULL pointers in mcount_loc"),
NULL pointers will be accounted when allocating ftrace pages but
skipped before adding into ftrace pages, this may result in some
pages not being used. Then after 706c81f87f84 ("ftrace: Remove extra
helper functions"), warning may occur at:
  WARN_ON(pg->next);

So we may need to skip NULL pointers before allocating ftrace pages.

Fixes: 706c81f87f84 ("ftrace: Remove extra helper functions")
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
---
 kernel/trace/ftrace.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 3740aca79fe7..5b474165df31 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -6485,6 +6485,16 @@ static int ftrace_process_locs(struct module *mod,
 	if (!count)
 		return 0;
 
+	p = start;
+	while (p < end) {
+		/*
+		 * Refer to conments below, there may be NULL pointers,
+		 * skip them before allocating pages
+		 */
+		addr = ftrace_call_adjust(*p++);
+		if (!addr)
+			count--;
+	}
 	/*
 	 * Sorting mcount in vmlinux at build time depend on
 	 * CONFIG_BUILDTIME_MCOUNT_SORT, while mcount loc in
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-07-12 12:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-10 21:29 [PATCH] ftrace: Fix possible warning on checking all pages used in ftrace_process_locs() Zheng Yejian
2023-07-10 14:46 ` Steven Rostedt
2023-07-11  6:21   ` Zheng Yejian
2023-07-11 11:27   ` [PATCH v3] " Zheng Yejian
2023-07-11 20:16   ` [PATCH v2] " Zheng Yejian
2023-07-11 13:58     ` Steven Rostedt
2023-07-12  1:31       ` [PATCH v4] " Zheng Yejian
2023-07-12  6:04       ` [PATCH v5] " Zheng Yejian
2023-07-12 12:37         ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).