ftrace: Store the order of pages allocated in ftrace_page

[ Upstream commit db42523b4f3e83ff86b53cdda219a9767c8b047f ]

Instead of saving the size of the records field of the ftrace_page, store
the order it uses to allocate the pages, as that is what is needed to know
in order to free the pages. This simplifies the code.

Link: https://lore.kernel.org/lkml/CAHk-=whyMxheOqXAORt9a7JK9gc9eHTgCJ55Pgs4p=X3RrQubQ@mail.gmail.com/

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[ change log written by Steven Rostedt ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Stable-dep-of: 26efd79c4624 ("ftrace: Fix possible warning on checking all pages used in ftrace_process_locs()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Linus Torvalds 2021-04-01 16:14:17 -04:00 committed by Greg Kroah-Hartman
parent e3098e52bf
commit 05ff1d355e

View File

@ -1100,7 +1100,7 @@ struct ftrace_page {
struct ftrace_page *next; struct ftrace_page *next;
struct dyn_ftrace *records; struct dyn_ftrace *records;
int index; int index;
int size; int order;
}; };
#define ENTRY_SIZE sizeof(struct dyn_ftrace) #define ENTRY_SIZE sizeof(struct dyn_ftrace)
@ -3029,7 +3029,7 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count)
ftrace_number_of_groups++; ftrace_number_of_groups++;
cnt = (PAGE_SIZE << order) / ENTRY_SIZE; cnt = (PAGE_SIZE << order) / ENTRY_SIZE;
pg->size = cnt; pg->order = order;
if (cnt > count) if (cnt > count)
cnt = count; cnt = count;
@ -3042,7 +3042,6 @@ ftrace_allocate_pages(unsigned long num_to_init)
{ {
struct ftrace_page *start_pg; struct ftrace_page *start_pg;
struct ftrace_page *pg; struct ftrace_page *pg;
int order;
int cnt; int cnt;
if (!num_to_init) if (!num_to_init)
@ -3078,13 +3077,13 @@ ftrace_allocate_pages(unsigned long num_to_init)
free_pages: free_pages:
pg = start_pg; pg = start_pg;
while (pg) { while (pg) {
order = get_count_order(pg->size / ENTRIES_PER_PAGE); if (pg->records) {
if (order >= 0) free_pages((unsigned long)pg->records, pg->order);
free_pages((unsigned long)pg->records, order); ftrace_number_of_pages -= 1 << pg->order;
}
start_pg = pg->next; start_pg = pg->next;
kfree(pg); kfree(pg);
pg = start_pg; pg = start_pg;
ftrace_number_of_pages -= 1 << order;
ftrace_number_of_groups--; ftrace_number_of_groups--;
} }
pr_info("ftrace: FAILED to allocate memory for functions\n"); pr_info("ftrace: FAILED to allocate memory for functions\n");
@ -5676,6 +5675,7 @@ static int ftrace_process_locs(struct module *mod,
p = start; p = start;
pg = start_pg; pg = start_pg;
while (p < end) { while (p < end) {
unsigned long end_offset;
addr = ftrace_call_adjust(*p++); addr = ftrace_call_adjust(*p++);
/* /*
* Some architecture linkers will pad between * Some architecture linkers will pad between
@ -5686,7 +5686,8 @@ static int ftrace_process_locs(struct module *mod,
if (!addr) if (!addr)
continue; continue;
if (pg->index == pg->size) { end_offset = (pg->index+1) * sizeof(pg->records[0]);
if (end_offset > PAGE_SIZE << pg->order) {
/* We should have allocated enough */ /* We should have allocated enough */
if (WARN_ON(!pg->next)) if (WARN_ON(!pg->next))
break; break;
@ -5826,7 +5827,6 @@ void ftrace_release_mod(struct module *mod)
struct ftrace_page **last_pg; struct ftrace_page **last_pg;
struct ftrace_page *tmp_page = NULL; struct ftrace_page *tmp_page = NULL;
struct ftrace_page *pg; struct ftrace_page *pg;
int order;
mutex_lock(&ftrace_lock); mutex_lock(&ftrace_lock);
@ -5877,12 +5877,12 @@ void ftrace_release_mod(struct module *mod)
/* Needs to be called outside of ftrace_lock */ /* Needs to be called outside of ftrace_lock */
clear_mod_from_hashes(pg); clear_mod_from_hashes(pg);
order = get_count_order(pg->size / ENTRIES_PER_PAGE); if (pg->records) {
if (order >= 0) free_pages((unsigned long)pg->records, pg->order);
free_pages((unsigned long)pg->records, order); ftrace_number_of_pages -= 1 << pg->order;
}
tmp_page = pg->next; tmp_page = pg->next;
kfree(pg); kfree(pg);
ftrace_number_of_pages -= 1 << order;
ftrace_number_of_groups--; ftrace_number_of_groups--;
} }
} }
@ -6185,7 +6185,6 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
struct ftrace_mod_map *mod_map = NULL; struct ftrace_mod_map *mod_map = NULL;
struct ftrace_init_func *func, *func_next; struct ftrace_init_func *func, *func_next;
struct list_head clear_hash; struct list_head clear_hash;
int order;
INIT_LIST_HEAD(&clear_hash); INIT_LIST_HEAD(&clear_hash);
@ -6223,10 +6222,10 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
ftrace_update_tot_cnt--; ftrace_update_tot_cnt--;
if (!pg->index) { if (!pg->index) {
*last_pg = pg->next; *last_pg = pg->next;
order = get_count_order(pg->size / ENTRIES_PER_PAGE); if (pg->records) {
if (order >= 0) free_pages((unsigned long)pg->records, pg->order);
free_pages((unsigned long)pg->records, order); ftrace_number_of_pages -= 1 << pg->order;
ftrace_number_of_pages -= 1 << order; }
ftrace_number_of_groups--; ftrace_number_of_groups--;
kfree(pg); kfree(pg);
pg = container_of(last_pg, struct ftrace_page, next); pg = container_of(last_pg, struct ftrace_page, next);