linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] perf/x86/amd: fix potential integer overflow on shift of a int
@ 2022-12-02 13:51 Colin Ian King
  2022-12-02 17:36 ` Ian Rogers
  0 siblings, 1 reply; 3+ messages in thread
From: Colin Ian King @ 2022-12-02 13:51 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Kim Phillips, linux-perf-users
  Cc: kernel-janitors, linux-kernel

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: 471af006a747 ("perf/x86/amd: Constrain Large Increment per Cycle events")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 arch/x86/events/amd/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index d6f3703e4119..4386b10682ce 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -1387,7 +1387,7 @@ static int __init amd_core_pmu_init(void)
 		 * numbered counter following it.
 		 */
 		for (i = 0; i < x86_pmu.num_counters - 1; i += 2)
-			even_ctr_mask |= 1 << i;
+			even_ctr_mask |= BIT_ULL(i);
 
 		pair_constraint = (struct event_constraint)
 				    __EVENT_CONSTRAINT(0, even_ctr_mask, 0,
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] perf/x86/amd: fix potential integer overflow on shift of a int
  2022-12-02 13:51 [PATCH][next] perf/x86/amd: fix potential integer overflow on shift of a int Colin Ian King
@ 2022-12-02 17:36 ` Ian Rogers
  2022-12-02 19:10   ` Kim Phillips
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2022-12-02 17:36 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, Kim Phillips, linux-perf-users, kernel-janitors,
	linux-kernel

On Fri, Dec 2, 2022 at 5:52 AM Colin Ian King <colin.i.king@gmail.com> wrote:
>
> 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: 471af006a747 ("perf/x86/amd: Constrain Large Increment per Cycle events")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>

Acked-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  arch/x86/events/amd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index d6f3703e4119..4386b10682ce 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -1387,7 +1387,7 @@ static int __init amd_core_pmu_init(void)
>                  * numbered counter following it.
>                  */
>                 for (i = 0; i < x86_pmu.num_counters - 1; i += 2)
> -                       even_ctr_mask |= 1 << i;
> +                       even_ctr_mask |= BIT_ULL(i);
>
>                 pair_constraint = (struct event_constraint)
>                                     __EVENT_CONSTRAINT(0, even_ctr_mask, 0,
> --
> 2.38.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] perf/x86/amd: fix potential integer overflow on shift of a int
  2022-12-02 17:36 ` Ian Rogers
@ 2022-12-02 19:10   ` Kim Phillips
  0 siblings, 0 replies; 3+ messages in thread
From: Kim Phillips @ 2022-12-02 19:10 UTC (permalink / raw)
  To: Ian Rogers, Colin Ian King
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, Dave Hansen, x86,
	H . Peter Anvin, linux-perf-users, kernel-janitors, linux-kernel

On 12/2/22 11:36 AM, Ian Rogers wrote:
> On Fri, Dec 2, 2022 at 5:52 AM Colin Ian King <colin.i.king@gmail.com> wrote:
>>
>> 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: 471af006a747 ("perf/x86/amd: Constrain Large Increment per Cycle events")
>> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> 
> Acked-by: Ian Rogers <irogers@google.com>

Acked-by: Kim Phillips <kim.phillips@amd.com>

Thanks,

Kim

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-02 19:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-02 13:51 [PATCH][next] perf/x86/amd: fix potential integer overflow on shift of a int Colin Ian King
2022-12-02 17:36 ` Ian Rogers
2022-12-02 19:10   ` Kim Phillips

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).