All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Bug fix - Integer overflow when cpu frequency > u32 max value.
@ 2022-12-18 12:14 Neowutran
  2022-12-18 21:47 ` Elliott Mitchell
  0 siblings, 1 reply; 4+ messages in thread
From: Neowutran @ 2022-12-18 12:14 UTC (permalink / raw)
  To: xen-devel
  Cc: Neowutran, Jan Beulich, Andrew Cooper, Roger Pau Monné,
	Wei Liu

xen/x86: prevent overflow with high frequency TSCs

Promote tsc_khz to a 64-bit type before multiplying by 1000 to avoid a
'overflow before widen' bug.
Otherwise just above 4.294GHz the value will overflow.
Processors with clocks this high are now in production and require this to work
correctly.

Signed-off-by: Neowutran <xen@neowutran.ovh>
---
Changed since v1:
 * smaller commit message
 * using uint64_t instead of u64
 * added signed-off-by tag
---
 xen/arch/x86/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index b01acd390d..c71e79e019 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2585,7 +2585,7 @@ int tsc_set_info(struct domain *d,
     case TSC_MODE_ALWAYS_EMULATE:
         d->arch.vtsc_offset = get_s_time() - elapsed_nsec;
         d->arch.tsc_khz = gtsc_khz ?: cpu_khz;
-        set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000);
+        set_time_scale(&d->arch.vtsc_to_ns, (uint64_t)d->arch.tsc_khz * 1000);
 
         /*
          * In default mode use native TSC if the host has safe TSC and
-- 
2.38.1



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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-18 12:14 [PATCH v2] Bug fix - Integer overflow when cpu frequency > u32 max value Neowutran
2022-12-18 21:47 ` Elliott Mitchell
2022-12-19  8:00   ` Jan Beulich
2022-12-19  8:55     ` Neowutran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.