linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/xen: Use a safer data type for delta to avoid shift-count-overflow
@ 2022-03-09  6:43 Like Xu
  0 siblings, 0 replies; only message in thread
From: Like Xu @ 2022-03-09  6:43 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Joao Martins, kvm, Sean Christopherson, Jim Mattson, Wanpeng Li,
	Vitaly Kuznetsov, Joerg Roedel, linux-kernel

From: Like Xu <likexu@tencent.com>

Clang warns:

arch/x86/kvm/xen.c:1219:41: warning: right shift count >= width of type [-Wshift-count-overflow]
 1219 |         (delta > 0 && (uint32_t) (delta >> 50) != 0))) {
      |                                         ^~

The delta is long, which is 32-bit on ARCH=i386, hence the overflow
warning. Switch to uint64_t, which is 64-bit and will not overflow.

Fixes: 49c0b9159bce ("KVM: x86/xen: handle PV timers oneshot mode")
Signed-off-by: Like Xu <likexu@tencent.com>
---
 arch/x86/kvm/xen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 8c85a71aa8ca..097181613be5 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -1204,7 +1204,7 @@ static bool kvm_xen_hcall_set_timer_op(struct kvm_vcpu *vcpu, uint64_t timeout,
 
 	if (timeout) {
 		uint64_t guest_now = get_kvmclock_ns(vcpu->kvm);
-		long delta = timeout - guest_now;
+		uint64_t delta = timeout - guest_now;
 
 		/* Xen has a 'Linux workaround' in do_set_timer_op() which
 		 * checks for negative absolute timeout values (caused by
-- 
2.35.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-09  6:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09  6:43 [PATCH] KVM: x86/xen: Use a safer data type for delta to avoid shift-count-overflow Like Xu

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).