Thanks for review!
- } else {Basically, what you are saying is that once we add ftrace_pages->next to
- if (!ftrace_pages)
- goto out;
-
- if (WARN_ON(ftrace_pages->next)) {
- /* Hmm, we have free pages? */
- while (ftrace_pages->next)
- ftrace_pages = ftrace_pages->next;
- }
-
- ftrace_pages->next = start_pg;
point to the new start_pg, it becomes visible to others and that could be a
problem. And moving this code around is not really going to solve that, as
then we would need to add memory barriers.
- }Why not just test for it?
-
p = start;
pg = start_pg;
while (p < end) {
@@ -6855,6 +6841,21 @@ static int ftrace_process_locs(struct module *mod,
/* We should have used all pages */
WARN_ON(pg->next);
+ /* Add pages to ftrace_pages list */
+ if (!mod) {
+ WARN_ON(ftrace_pages || ftrace_pages_start);
+ /* First initialization */
+ ftrace_pages_start = start_pg;
+ } else {
+ if (WARN_ON(ftrace_pages->next)) {
+ /* Hmm, we have free pages? */
+ while (ftrace_pages->next)
+ ftrace_pages = ftrace_pages->next;
+ }
+
+ ftrace_pages->next = start_pg;
+ }
+
/* Assign the last page to ftrace_pages */
ftrace_pages = pg;
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 29baa97d0d53..9b2803c7a18f 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1564,7 +1564,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
key.flags = end; /* overload flags, as it is unsigned long */
for (pg = ftrace_pages_start; pg; pg = pg->next) {
- if (end < pg->records[0].ip ||
+ if (pg->index == 0 ||
+ end < pg->records[0].ip ||
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
continue;
rec = bsearch(&key, pg->records, pg->index,
-- Steve