Skip to content

Commit 34209fe

Browse files
petrpavlurostedt
authored andcommitted
tracing: Fix a warning when allocating buffered events fails
Function trace_buffered_event_disable() produces an unexpected warning when the previous call to trace_buffered_event_enable() fails to allocate pages for buffered events. The situation can occur as follows: * The counter trace_buffered_event_ref is at 0. * The soft mode gets enabled for some event and trace_buffered_event_enable() is called. The function increments trace_buffered_event_ref to 1 and starts allocating event pages. * The allocation fails for some page and trace_buffered_event_disable() is called for cleanup. * Function trace_buffered_event_disable() decrements trace_buffered_event_ref back to 0, recognizes that it was the last use of buffered events and frees all allocated pages. * The control goes back to trace_buffered_event_enable() which returns. The caller of trace_buffered_event_enable() has no information that the function actually failed. * Some time later, the soft mode is disabled for the same event. Function trace_buffered_event_disable() is called. It warns on "WARN_ON_ONCE(!trace_buffered_event_ref)" and returns. Buffered events are just an optimization and can handle failures. Make trace_buffered_event_enable() exit on the first failure and left any cleanup later to when trace_buffered_event_disable() is called. Link: https://lore.kernel.org/all/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 0fc1b09 ("tracing: Use temp buffer when filtering events") Signed-off-by: Petr Pavlu <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 7fed14f commit 34209fe

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

kernel/trace/trace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,8 +2728,11 @@ void trace_buffered_event_enable(void)
27282728
for_each_tracing_cpu(cpu) {
27292729
page = alloc_pages_node(cpu_to_node(cpu),
27302730
GFP_KERNEL | __GFP_NORETRY, 0);
2731-
if (!page)
2732-
goto failed;
2731+
/* This is just an optimization and can handle failures */
2732+
if (!page) {
2733+
pr_err("Failed to allocate event buffer\n");
2734+
break;
2735+
}
27332736

27342737
event = page_address(page);
27352738
memset(event, 0, sizeof(*event));
@@ -2743,10 +2746,6 @@ void trace_buffered_event_enable(void)
27432746
WARN_ON_ONCE(1);
27442747
preempt_enable();
27452748
}
2746-
2747-
return;
2748-
failed:
2749-
trace_buffered_event_disable();
27502749
}
27512750

27522751
static void enable_trace_buffered_event(void *data)

0 commit comments

Comments
 (0)