Commit 9dff0aa9 authored by Mark Rutland's avatar Mark Rutland Committed by Ingo Molnar

perf/core: Don't WARN() for impossible ring-buffer sizes

The perf tool uses /proc/sys/kernel/perf_event_mlock_kb to determine how
large its ringbuffer mmap should be. This can be configured to arbitrary
values, which can be larger than the maximum possible allocation from

When this is configured to a suitably large value (e.g. thanks to the
perf fuzzer), attempting to use perf record triggers a WARN_ON_ONCE() in

   WARNING: CPU: 2 PID: 5666 at mm/page_alloc.c:4511 __alloc_pages_nodemask+0x3f8/0xbc8

Let's avoid this by checking that the requested allocation is possible
before calling kzalloc.
Reported-by: default avatarJulien Thierry <>
Signed-off-by: default avatarMark Rutland <>
Signed-off-by: default avatarPeter Zijlstra (Intel) <>
Reviewed-by: default avatarJulien Thierry <>
Cc: Alexander Shishkin <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Jiri Olsa <>
Cc: Linus Torvalds <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Cc: <>
Link: default avatarIngo Molnar <>
parent 602cae04
......@@ -734,6 +734,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
size = sizeof(struct ring_buffer);
size += nr_pages * sizeof(void *);
if (order_base_2(size) >= MAX_ORDER)
goto fail;
rb = kzalloc(size, GFP_KERNEL);
if (!rb)
goto fail;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment