The Linux Kernel Mailing List
 help / color / mirror / Atom feed
  • * Re: [PATCH v2] KVM: x86: Rate-limit global clock updates on vCPU load
           [not found] ` <20260409142226.2581-1-lei.chen@smartx.com>
           [not found]   ` <adf8Q1VSeAMMyCa_@google.com>
    @ 2026-05-06 20:10   ` Jaroslav Pulchart
      1 sibling, 0 replies; 9+ messages in thread
    From: Jaroslav Pulchart @ 2026-05-06 20:10 UTC (permalink / raw)
      To: Lei Chen; +Cc: seanjc, igor, jan.cipa, kvm, linux-kernel, pbonzini
    
    >
    > commit 446fcce2a52b ("Revert "x86: kvm: rate-limit global clock updates"")
    > dropped the rate limiting for KVM_REQ_GLOBAL_CLOCK_UPDATE.
    >
    > As a result, kvm_arch_vcpu_load() can queue global clock update requests
    > every time a vCPU is scheduled when the master clock is disabled or when
    > the vCPU is loaded for the first time.
    >
    > Restore the throttling with a per-VM ratelimit state and gate
    > KVM_REQ_GLOBAL_CLOCK_UPDATE through __ratelimit(), so frequent vCPU
    > scheduling does not generate a steady stream of redundant clock update
    > requests.
    >
    > Fixes: 446fcce2a52b ("Revert "x86: kvm: rate-limit global clock updates"")
    > Signed-off-by: Lei Chen <lei.chen@smartx.com>
    > Reported-by: Jaroslav Pulchart <jaroslav.pulchart@gooddata.com>
    > Closes: https://lore.kernel.org/all/CAK8fFZ5gY8_Mw2A=iZVFNVKQNrXQzVsn-HTd+Me9K6ZfmdgA+Q@mail.gmail.com/
    > ---
    > CHANGELOG:
    > v2:
    > - remove comment of kvmclock_update_rs
    > - make sure kvm_arch_vcpu_load make KVM_REQ_CLOCK_UPDATE for this vcpu
    > - add RATELIMIT_MSG_ON_RELEASE to kvmclock_update_rs
    >
    > v1:
    > - initial version(https://lore.kernel.org/all/20260407070046.2336-1-lei.chen@smartx.com/)
    > ---
    >  arch/x86/include/asm/kvm_host.h |  1 +
    >  arch/x86/kvm/x86.c              | 11 +++++++++--
    >  2 files changed, 10 insertions(+), 2 deletions(-)
    >
    > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
    > index 5a3bfa293e8b..5e750c49d21e 100644
    > --- a/arch/x86/include/asm/kvm_host.h
    > +++ b/arch/x86/include/asm/kvm_host.h
    > @@ -1453,6 +1453,7 @@ struct kvm_arch {
    >         bool use_master_clock;
    >         u64 master_kernel_ns;
    >         u64 master_cycle_now;
    > +       struct ratelimit_state kvmclock_update_rs;
    >
    >  #ifdef CONFIG_KVM_HYPERV
    >         struct kvm_hv hyperv;
    > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
    > index 63afdb6bb078..a534e8391611 100644
    > --- 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;
    > @@ -13189,6 +13194,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
    >         raw_spin_lock_init(&kvm->arch.tsc_write_lock);
    >         mutex_init(&kvm->arch.apic_map_lock);
    >         seqcount_raw_spinlock_init(&kvm->arch.pvclock_sc, &kvm->arch.tsc_write_lock);
    > +       ratelimit_state_init(&kvm->arch.kvmclock_update_rs, HZ, 10);
    > +       ratelimit_set_flags(&kvm->arch.kvmclock_update_rs, RATELIMIT_MSG_ON_RELEASE);
    >         kvm->arch.kvmclock_offset = -get_kvmclock_base_ns();
    >
    >         raw_spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags);
    > --
    > 2.51.0
    >
    
    Hi Lei, I tested the v2 patch on a Firecracker host running vanilla
    kernel 7.0.3 with this patch applied, the IPI storm on vCPU load is
    gone!
    
    ^ permalink raw reply	[flat|nested] 9+ messages in thread

  • end of thread, other threads:[~2026-05-07 19:09 UTC | newest]
    
    Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <adVGrJaRlRooO4su@google.com>
         [not found] ` <20260409142226.2581-1-lei.chen@smartx.com>
         [not found]   ` <adf8Q1VSeAMMyCa_@google.com>
    2026-05-06  9:48     ` [PATCH v2] KVM: x86: Rate-limit global clock updates on vCPU load 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
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox