Skip to contentSkip to conversation

KVM: x86/xen: Use a safer data type for delta to avoid shift-count-overflow

PATCH New Like Xu 1 participant 1 message Mar 9, 2022

Subsystems (4)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: x86/xen: Use a safer data type for delta to avoid shift-count-overflow

From: Like Xu <[email protected]>

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")
---
 arch/x86/kvm/xen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/xen.c +1 -1
index 8c85a71aa8ca..097181613be5 100644
@@ -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
Signature · 1 line
2.35.1