mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/apic: fix integer overflow on 10 bit right shift of cpu_khz
@ 2019-06-19 18:13 Colin King
  2019-06-19 18:15 ` Colin Ian King
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2019-06-19 18:13 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, x86
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The right shift of unsigned int cpu_khz will overflow for large values
of cpu_khz, so cast it to a long long before shifting it to avoid
overvlow.  For example, this can happen when cpu_khz is 4194305 (just
less than 4.2 GHz).  Also wrap line to avoid checkpatch wide line
warning.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 8c3ba8d04924 ("x86, apic: ack all pending irqs when crashed/on kexec")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 arch/x86/kernel/apic/apic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 8956072f677d..31426126e5e0 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1464,7 +1464,8 @@ static void apic_pending_intr_clear(void)
 		if (queued) {
 			if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) {
 				ntsc = rdtsc();
-				max_loops = (cpu_khz << 10) - (ntsc - tsc);
+				max_loops = ((long long)cpu_khz << 10) -
+					    (ntsc - tsc);
 			} else {
 				max_loops--;
 			}
-- 
2.20.1


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

* Re: [PATCH] x86/apic: fix integer overflow on 10 bit right shift of cpu_khz
  2019-06-19 18:13 [PATCH] x86/apic: fix integer overflow on 10 bit right shift of cpu_khz Colin King
@ 2019-06-19 18:15 ` Colin Ian King
  0 siblings, 0 replies; 2+ messages in thread
From: Colin Ian King @ 2019-06-19 18:15 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin, x86
  Cc: kernel-janitors, linux-kernel

On 19/06/2019 19:13, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The right shift of unsigned int cpu_khz will overflow for large values
> of cpu_khz, so cast it to a long long before shifting it to avoid
> overvlow.  For example, this can happen when cpu_khz is 4194305 (just
> less than 4.2 GHz).  Also wrap line to avoid checkpatch wide line
> warning.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 8c3ba8d04924 ("x86, apic: ack all pending irqs when crashed/on kexec")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  arch/x86/kernel/apic/apic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
> index 8956072f677d..31426126e5e0 100644
> --- a/arch/x86/kernel/apic/apic.c
> +++ b/arch/x86/kernel/apic/apic.c
> @@ -1464,7 +1464,8 @@ static void apic_pending_intr_clear(void)
>  		if (queued) {
>  			if (boot_cpu_has(X86_FEATURE_TSC) && cpu_khz) {
>  				ntsc = rdtsc();
> -				max_loops = (cpu_khz << 10) - (ntsc - tsc);
> +				max_loops = ((long long)cpu_khz << 10) -
> +					    (ntsc - tsc);
>  			} else {
>  				max_loops--;
>  			}
> 
Nack. V2 coming next.

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

end of thread, other threads:[~2019-06-19 18:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19 18:13 [PATCH] x86/apic: fix integer overflow on 10 bit right shift of cpu_khz Colin King
2019-06-19 18:15 ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®