Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Lei Chen <lei.chen@smartx.com>,
	igor@gooddata.com, jan.cipa@gooddata.com,
	 jaroslav.pulchart@gooddata.com, kvm@vger.kernel.org,
	 linux-kernel@vger.kernel.org, pbonzini@redhat.com
Subject: Re: [PATCH v2] KVM: x86: Rate-limit global clock updates on vCPU load
Date: Fri, 26 Jun 2026 15:58:14 -0700	[thread overview]
Message-ID: <aj8EBrA_Ygg3mxZT@google.com> (raw)
In-Reply-To: <e8d802f9f1ca831f99f991567243b5d74578a514.camel@infradead.org>

On Fri, Jun 26, 2026, David Woodhouse wrote:
> On Thu, 2026-04-09 at 22:22 +0800, Lei Chen wrote:
> > 
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -5210,8 +5210,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
> >  		 * On a host with synchronized TSC, there is no need to update
> >  		 * kvmclock on vcpu->cpu migration
> >  		 */
> > -		if (!vcpu->kvm->arch.use_master_clock || vcpu->cpu == -1)
> > -			kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu);
> > +		if (!vcpu->kvm->arch.use_master_clock || vcpu->cpu == -1) {
> > +			if (__ratelimit(&vcpu->kvm->arch.kvmclock_update_rs))
> > +				kvm_make_request(KVM_REQ_GLOBAL_CLOCK_UPDATE, vcpu);
> > +			else
> > +				kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu);
> > +		}
> > +
> >  		if (vcpu->cpu != cpu)
> >  			kvm_make_request(KVM_REQ_MIGRATE_TIMER, vcpu);
> >  		vcpu->cpu = cpu;
> 
> I don't like this.

I don't think anyone likes this :-)

> We do the GLOBAL_CLOCK_UPDATE in non-masterclock mode because
> theoretically, a *failure* to do so could cause the guest to observe
> non-monotonicity across vCPUs.
> 
> With this rate-limiting, we *sometimes* protect against that non-
> monotonicity. Why even bother? Why not just rip it out completely, in
> that case? AIUI the guest should cope with anyway if its
> PVCLOCK_TSC_STABLE_BIT isn't set, and enforce monotonicity for itself
> side in __pvclock_clocksource_read() ? 

Because we needed a fix somewhat urgently, and I didn't want to risk more breakage
by going with an aggressive change.

> But also, I would *love* to kill non-masterclock mode completely.

That's not feasible until KVM drops support for hardware that, per Linux standards,
isn't _that_ old, is it?

> In this nested case, the L1 TSCs *are* actually in sync; it just don't
> have the +invtsc CPUID to *promise* that they will be.
> 
> Could we find a way for L1 KVM to use masterclock mode for its nested
> L2 VMs even in this case? Could we make it use PVCLOCK_TSC_STABLE_BIT
> to enable masterclock mode, instead?
> 
> At at the very least, could we find a way for L1 to trigger the
> GLOBAL_CLOCK_UPDATE only if an *actual* discrepancy in its TSCs is
> found? (Or, if vdso mode is not VDSO_CLOCKMODE_PVCLOCK?)

Or just advertise invtsc?  I appreciate the desire to eliminate mostly-useless
overhead like this, but at some point doesn't this boil down to "don't mess up
your setup"?

      reply	other threads:[~2026-06-26 22:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-21 14:32 [REGRESSION 6.19, BISECTED] KVM: x86: kvmclock rate-limit removal causes IPI storm and high guest steal time Jaroslav Pulchart
2026-03-23  2:27 ` Lei Chen
2026-04-01  6:43   ` Lei Chen
2026-04-01 21:16     ` Sean Christopherson
2026-04-07  7:00       ` [PATCH v1] KVM: x86: Rate-limit global clock updates on vCPU load Lei Chen
2026-04-07 18:02         ` Sean Christopherson
2026-04-09 13:03           ` Lei Chen
2026-04-09 13:36           ` Lei Chen
2026-04-09 14:22           ` [PATCH v2] " Lei Chen
2026-04-09 19:21             ` Sean Christopherson
2026-05-06  9:48               ` Thorsten Leemhuis
2026-05-06 12:55                 ` Sean Christopherson
2026-05-06 14:09                   ` Thorsten Leemhuis
2026-05-06 15:22                     ` Sean Christopherson
2026-05-06 15:58                       ` Jaroslav Pulchart
2026-05-06 20:31                         ` Sean Christopherson
2026-05-07  9:27                           ` Jaroslav Pulchart
2026-05-07 19:09                             ` Sean Christopherson
2026-05-06 20:10             ` Jaroslav Pulchart
2026-05-19  0:40             ` Sean Christopherson
2026-06-26 13:04             ` David Woodhouse
2026-06-26 22:58               ` Sean Christopherson [this message]

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=aj8EBrA_Ygg3mxZT@google.com \
    --to=seanjc@google.com \
    --cc=dwmw2@infradead.org \
    --cc=igor@gooddata.com \
    --cc=jan.cipa@gooddata.com \
    --cc=jaroslav.pulchart@gooddata.com \
    --cc=kvm@vger.kernel.org \
    --cc=lei.chen@smartx.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox