Skip to content

Commit 0824567

Browse files
ColinIanKingPeter Zijlstra
authored andcommitted
perf/x86/amd: fix potential integer overflow on shift of a int
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then passed as a 64 bit function argument. In the case where i is 32 or more this can lead to an overflow. Avoid this by shifting using the BIT_ULL macro instead. Fixes: 471af00 ("perf/x86/amd: Constrain Large Increment per Cycle events") Signed-off-by: Colin Ian King <colin.i.king@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Ian Rogers <irogers@google.com> Acked-by: Kim Phillips <kim.phillips@amd.com> Link: https://lore.kernel.org/r/20221202135149.1797974-1-colin.i.king@gmail.com
1 parent f841b68 commit 0824567

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/events/amd/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ static int __init amd_core_pmu_init(void)
13871387
* numbered counter following it.
13881388
*/
13891389
for (i = 0; i < x86_pmu.num_counters - 1; i += 2)
1390-
even_ctr_mask |= 1 << i;
1390+
even_ctr_mask |= BIT_ULL(i);
13911391

13921392
pair_constraint = (struct event_constraint)
13931393
__EVENT_CONSTRAINT(0, even_ctr_mask, 0,

0 commit comments

Comments
 (0)