Unverified Commit 592dd126 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!1444 ring-buffer: Fix deadloop issue on reading trace_pipe

Merge Pull Request from: @LiuYongQiang0816 
 
two patches from Zheng Yejian 
 
Link:https://gitee.com/openeuler/kernel/pulls/1444

 

Reviewed-by: default avatarXu Kuohai <xukuohai@huawei.com>
Signed-off-by: default avatarZhang Changzhong <zhangchangzhong@huawei.com>
parents d7ba8395 1d801741
Loading
Loading
Loading
Loading
+29 −12
Original line number Original line Diff line number Diff line
@@ -3048,12 +3048,25 @@ static int ftrace_allocate_records(struct ftrace_page *pg, int count)
	return cnt;
	return cnt;
}
}


static void ftrace_free_pages(struct ftrace_page *pages)
{
	struct ftrace_page *pg = pages;
	int order;

	while (pg) {
		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
		free_pages((unsigned long)pg->records, order);
		pages = pg->next;
		kfree(pg);
		pg = pages;
	}
}

static struct ftrace_page *
static struct ftrace_page *
ftrace_allocate_pages(unsigned long num_to_init)
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)
@@ -3087,14 +3100,7 @@ ftrace_allocate_pages(unsigned long num_to_init)
	return start_pg;
	return start_pg;


 free_pages:
 free_pages:
	pg = start_pg;
	ftrace_free_pages(start_pg);
	while (pg) {
		order = get_count_order(pg->size / ENTRIES_PER_PAGE);
		free_pages((unsigned long)pg->records, order);
		start_pg = pg->next;
		kfree(pg);
		pg = start_pg;
	}
	pr_info("ftrace: FAILED to allocate memory for functions\n");
	pr_info("ftrace: FAILED to allocate memory for functions\n");
	return NULL;
	return NULL;
}
}
@@ -5575,9 +5581,11 @@ static int ftrace_process_locs(struct module *mod,
			       unsigned long *start,
			       unsigned long *start,
			       unsigned long *end)
			       unsigned long *end)
{
{
	struct ftrace_page *pg_unuse = NULL;
	struct ftrace_page *start_pg;
	struct ftrace_page *start_pg;
	struct ftrace_page *pg;
	struct ftrace_page *pg;
	struct dyn_ftrace *rec;
	struct dyn_ftrace *rec;
	unsigned long skipped = 0;
	unsigned long count;
	unsigned long count;
	unsigned long *p;
	unsigned long *p;
	unsigned long addr;
	unsigned long addr;
@@ -5630,8 +5638,10 @@ static int ftrace_process_locs(struct module *mod,
		 * object files to satisfy alignments.
		 * object files to satisfy alignments.
		 * Skip any NULL pointers.
		 * Skip any NULL pointers.
		 */
		 */
		if (!addr)
		if (!addr) {
			skipped++;
			continue;
			continue;
		}


		if (pg->index == pg->size) {
		if (pg->index == pg->size) {
			/* We should have allocated enough */
			/* We should have allocated enough */
@@ -5644,8 +5654,10 @@ static int ftrace_process_locs(struct module *mod,
		rec->ip = addr;
		rec->ip = addr;
	}
	}


	/* We should have used all pages */
	if (pg->next) {
	WARN_ON(pg->next);
		pg_unuse = pg->next;
		pg->next = NULL;
	}


	/* Assign the last page to ftrace_pages */
	/* Assign the last page to ftrace_pages */
	ftrace_pages = pg;
	ftrace_pages = pg;
@@ -5667,6 +5679,11 @@ static int ftrace_process_locs(struct module *mod,
 out:
 out:
	mutex_unlock(&ftrace_lock);
	mutex_unlock(&ftrace_lock);


	/* We should have used all pages unless we skipped some */
	if (pg_unuse) {
		WARN_ON(!skipped);
		ftrace_free_pages(pg_unuse);
	}
	return ret;
	return ret;
}
}


+15 −9
Original line number Original line Diff line number Diff line
@@ -4407,28 +4407,34 @@ unsigned long ring_buffer_size(struct ring_buffer *buffer, int cpu)
}
}
EXPORT_SYMBOL_GPL(ring_buffer_size);
EXPORT_SYMBOL_GPL(ring_buffer_size);


static void rb_clear_buffer_page(struct buffer_page *page)
{
	local_set(&page->write, 0);
	local_set(&page->entries, 0);
	rb_init_page(page->page);
	page->read = 0;
}

static void
static void
rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
{
{
	struct buffer_page *page;

	rb_head_page_deactivate(cpu_buffer);
	rb_head_page_deactivate(cpu_buffer);


	cpu_buffer->head_page
	cpu_buffer->head_page
		= list_entry(cpu_buffer->pages, struct buffer_page, list);
		= list_entry(cpu_buffer->pages, struct buffer_page, list);
	local_set(&cpu_buffer->head_page->write, 0);
	rb_clear_buffer_page(cpu_buffer->head_page);
	local_set(&cpu_buffer->head_page->entries, 0);
	list_for_each_entry(page, cpu_buffer->pages, list) {
	local_set(&cpu_buffer->head_page->page->commit, 0);
		rb_clear_buffer_page(page);

	}
	cpu_buffer->head_page->read = 0;


	cpu_buffer->tail_page = cpu_buffer->head_page;
	cpu_buffer->tail_page = cpu_buffer->head_page;
	cpu_buffer->commit_page = cpu_buffer->head_page;
	cpu_buffer->commit_page = cpu_buffer->head_page;


	INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
	INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
	INIT_LIST_HEAD(&cpu_buffer->new_pages);
	INIT_LIST_HEAD(&cpu_buffer->new_pages);
	local_set(&cpu_buffer->reader_page->write, 0);
	rb_clear_buffer_page(cpu_buffer->reader_page);
	local_set(&cpu_buffer->reader_page->entries, 0);
	local_set(&cpu_buffer->reader_page->page->commit, 0);
	cpu_buffer->reader_page->read = 0;


	local_set(&cpu_buffer->entries_bytes, 0);
	local_set(&cpu_buffer->entries_bytes, 0);
	local_set(&cpu_buffer->overrun, 0);
	local_set(&cpu_buffer->overrun, 0);