x86/time: deal with negative deltas in get_s_time_fixed()

Callers may pass in TSC values from before the local TSC stamp was last
updated (this would in particular be the case when the TSC was latched, a
time rendezvous occurs, and the latched value is used only afterwards).
scale_delta(), otoh, deals with unsigned values, and hence would treat
negative incoming deltas as huge positive values, yielding entirely bogus
return values.

Fixes: 88e64cb785 ("x86/HVM: use fixed TSC value when saving or restoring domain")
Reported-by: Антон Марков <akmarkov45@gmail.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
master commit: 7b3e1b4e84
master date: 2026-01-20 09:03:17 +0100
This commit is contained in:
Jan Beulich committed 2026-01-29 13:37:12 +01:00
1 parent bc63b09ecc
commit b3f59203a5
1 file changed
+7 -2
+7 -2
View File
@@ -1649,8 +1649,13 @@ s_time_t get_s_time_fixed(u64 at_tsc)
tsc = at_tsc;
else
tsc = rdtsc_ordered();
delta = tsc - t->stamp.local_tsc;
return t->stamp.local_stime + scale_delta(delta, &t->tsc_scale);
if ( likely(tsc >= t->stamp.local_tsc) )
delta = scale_delta(tsc - t->stamp.local_tsc, &t->tsc_scale);
else
delta = -scale_delta(t->stamp.local_tsc - tsc, &t->tsc_scale);
return t->stamp.local_stime + delta;
}
s_time_t get_s_time(void)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.