]> www.infradead.org Git - linux.git/commitdiff
ftrace: Update the mcount_loc check of skipped entries
authorSteven Rostedt <rostedt@goodmis.org>
Tue, 18 Feb 2025 19:59:23 +0000 (14:59 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 18 Feb 2025 22:12:03 +0000 (17:12 -0500)
Now that weak functions turn into skipped entries, update the check to
make sure the amount that was allocated would fit both the entries that
were allocated as well as those that were skipped.

Cc: bpf <bpf@vger.kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nicolas Schier <nicolas@fjasle.eu>
Cc: Zheng Yejian <zhengyejian1@huawei.com>
Cc: Martin Kelly <martin.kelly@crowdstrike.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Link: https://lore.kernel.org/20250218200023.055162048@goodmis.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index e3f89924f603e3eafaef434d3e1660d804226c79..e657013424aa79fe47daf0ea8206fa99893f3a17 100644 (file)
@@ -7111,7 +7111,28 @@ static int ftrace_process_locs(struct module *mod,
 
        /* We should have used all pages unless we skipped some */
        if (pg_unuse) {
-               WARN_ON(!skipped);
+               unsigned long pg_remaining, remaining = 0;
+               unsigned long skip;
+
+               /* Count the number of entries unused and compare it to skipped. */
+               pg_remaining = (ENTRIES_PER_PAGE << pg->order) - pg->index;
+
+               if (!WARN(skipped < pg_remaining, "Extra allocated pages for ftrace")) {
+
+                       skip = skipped - pg_remaining;
+
+                       for (pg = pg_unuse; pg; pg = pg->next)
+                               remaining += 1 << pg->order;
+
+                       skip = DIV_ROUND_UP(skip, ENTRIES_PER_PAGE);
+
+                       /*
+                        * Check to see if the number of pages remaining would
+                        * just fit the number of entries skipped.
+                        */
+                       WARN(skip != remaining, "Extra allocated pages for ftrace: %lu with %lu skipped",
+                            remaining, skipped);
+               }
                /* Need to synchronize with ftrace_location_range() */
                synchronize_rcu();
                ftrace_free_pages(pg_unuse);