Skip to content

Commit 43deb76

Browse files
ahunter6Peter Zijlstra
authored andcommitted
perf: Fix default aux_watermark calculation
The default aux_watermark is half the AUX area buffer size. In general, on a 64-bit architecture, the AUX area buffer size could be a bigger than fits in a 32-bit type, but the calculation does not allow for that possibility. However the aux_watermark value is recorded in a u32, so should not be more than U32_MAX either. Fix by doing the calculation in a correctly sized type, and limiting the result to U32_MAX. Fixes: d68e679 ("perf: Cap allocation order at aux_watermark") Signed-off-by: Adrian Hunter <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dbc48c8 commit 43deb76

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/events/ring_buffer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,9 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
688688
* max_order, to aid PMU drivers in double buffering.
689689
*/
690690
if (!watermark)
691-
watermark = nr_pages << (PAGE_SHIFT - 1);
691+
watermark = min_t(unsigned long,
692+
U32_MAX,
693+
(unsigned long)nr_pages << (PAGE_SHIFT - 1));
692694

693695
/*
694696
* Use aux_watermark as the basis for chunking to

0 commit comments

Comments
 (0)