From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Антон Марков" <akmarkov45@gmail.com>
Subject: Re: [PATCH 1/5] x86/time: deal with negative deltas in get_s_time_fixed()
Date: Thu, 15 Jan 2026 09:24:16 +0100 [thread overview]
Message-ID: <aWikMGJKa3VPQQzi@Mac.lan> (raw)
In-Reply-To: <e9205e59-fb1d-429e-877d-28aa8cb950ca@suse.com>
On Thu, Jan 15, 2026 at 09:00:07AM +0100, Jan Beulich wrote:
> On 14.01.2026 18:49, Roger Pau Monné wrote:
> > On Tue, Jan 06, 2026 at 02:58:11PM +0100, Jan Beulich wrote:
> >> A similar issue looks to exist in read_xen_timer() and its read_cycle()
> >> helper, if we're scheduled out (and beck in) between reading of the TSC
> >> and calculation of the delta (involving ->tsc_timestamp). Am I
> >> overlooking anything there?
> >
> > If we are scheduled out in the middle, and the ->tsc_timestamp is
> > updated, ->version would also be bumped, and hence the loop will be
> > restarted. I don't think there's an issue there.
>
> Oh, indeed - I was too focused on the read_cycle() alone. That may go
> wrong, but as you say the result then simply won't be used.
>
> >> stime2tsc() guards against negative deltas by using 0 instead; I'm not
> >> quite sure that's correct either.
> >
> > Hm, we should likely do the same for stime2tsc() that you do for
> > get_s_time_fixed(). Given the current callers I think we might be
> > safe, but it's a risk.
>
> Will do then.
>
> >> amd_check_erratum_1474() (next to its call to tsc_ticks2ns()) has a
> >> comment towards the TSC being "sane", but is that correct? Due to
> >> TSC_ADJUST, rdtsc() may well return a huge value (and the TSC would then
> >> wrap through 0 at some point). Shouldn't we subtract boot_tsc_stamp before
> >> calling tsc_ticks2ns()?
> >
> > amd_check_erratum_1474() runs after early_time_init(), which would
> > have cleared any TSC_ADJUST offset AFAICT. There's a note in the
> > initcall to that regard:
> >
> > /*
> > * Must be executed after early_time_init() for tsc_ticks2ns() to have been
> > * calibrated. That prevents us doing the check in init_amd().
> > */
> > presmp_initcall(amd_check_erratum_1474);
>
> Hmm, I should have written "Due to e.g. TSC_ADJUST". Firmware may also
> have played other games with MSR_TSC.
For amd_check_erratum_1474() we don't want to subtract boot_tsc_stamp,
otherwise when kexec'ed we won't be accounting properly for the time
since host startup, as subtracting boot_tsc_stamp would remove any
time consumed by a previously run OS.
> >> A similar issue looks to exist in tsc_get_info(), again when rdtsc()
> >> possibly returns a huge value due to TSC_ADJUST. Once again I wonder
> >> whether we shouldn't subtract boot_tsc_stamp.
> >
> > I would expect tsc_get_info() to also get called exclusively after
> > early_time_init()?
>
> Same here then (obviously).
For tsc_get_info() I think you are worried that the TSC might
overflow, and hence the calculation in scale_delta() would then be
skewed. We must have other instances of this pattern however, what
about get_s_time_fixed(), I think it would also be affected?
Or maybe I'm not understanding the concern. Given the proposed
scale_delta() logic, it won't be possible to distinguish rdtsc
overflowing from a value in the past.
Thanks, Roger.
next prev parent reply other threads:[~2026-01-15 8:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 13:57 [PATCH 0/5] x86: assorted time handling adjustments Jan Beulich
2026-01-06 13:58 ` [PATCH 1/5] x86/time: deal with negative deltas in get_s_time_fixed() Jan Beulich
2026-01-06 20:10 ` Антон Марков
2026-01-07 8:02 ` Jan Beulich
2026-01-09 16:11 ` Anton Markov
2026-01-12 10:31 ` Anton Markov
2026-01-12 11:45 ` Jan Beulich
2026-01-12 12:49 ` Anton Markov
2026-01-12 14:13 ` Jan Beulich
2026-01-12 14:51 ` Anton Markov
2026-01-12 16:08 ` Jan Beulich
2026-01-12 16:41 ` Anton Markov
2026-01-13 11:21 ` Jan Beulich
2026-01-13 12:35 ` Anton Markov
2026-01-14 17:49 ` Roger Pau Monné
2026-01-15 8:00 ` Jan Beulich
2026-01-15 8:24 ` Roger Pau Monné [this message]
2026-01-15 8:49 ` Anton Markov
2026-01-15 10:38 ` Jan Beulich
2026-01-15 11:48 ` Roger Pau Monné
2026-01-15 12:04 ` Jan Beulich
2026-01-20 8:50 ` Jan Beulich
2026-01-20 9:28 ` Jan Beulich
2026-01-06 13:58 ` [PATCH 2/5] x86/time: scale_delta() can be static Jan Beulich
2026-01-13 18:40 ` Roger Pau Monné
2026-01-06 13:58 ` [PATCH 3/5] x86/HVM: drop at_tsc parameter from ->set_tsc_offset() hook Jan Beulich
2026-01-14 9:40 ` Roger Pau Monné
2026-01-06 13:59 ` [PATCH 4/5] x86/time: gtsc_to_gtime() is HVM-only Jan Beulich
2026-01-14 9:43 ` Roger Pau Monné
2026-01-14 9:52 ` Roger Pau Monné
2026-01-06 14:00 ` [PATCH 5/5] x86/time: pv_soft_rdtsc() is PV-only Jan Beulich
2026-01-14 9:46 ` Roger Pau Monné
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aWikMGJKa3VPQQzi@Mac.lan \
--to=roger.pau@citrix.com \
--cc=akmarkov45@gmail.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.