mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Zelin Deng <zelin.deng@linux.alibaba.com>,
	Sean Christopherson <seanjc@google.com>,
	Wanpeng Li <wanpengli@tencent.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH] Guest system time jumps when new vCPUs is hot-added
Date: Mon, 6 Sep 2021 13:22:49 +0200	[thread overview]
Message-ID: <9f0d0543-db41-fbb0-019c-7df5b9319c33@redhat.com> (raw)
In-Reply-To: <1619576521-81399-1-git-send-email-zelin.deng@linux.alibaba.com>

On 28/04/21 04:22, Zelin Deng wrote:
> Hello,
> I have below VM configuration:
> ...
>      <vcpu placement='static' current='1'>2</vcpu>
>      <cpu mode='host-passthrough'>
>      </cpu>
>      <clock offset='utc'>
>          <timer name='tsc' frequency='3000000000'/>
>      </clock>
> ...
> After VM has been up for a few minutes, I use "virsh setvcpus" to hot-add
> second vCPU into VM, below dmesg is observed:
> [   53.273484] CPU1 has been hot-added
> [   85.067135] SMP alternatives: switching to SMP code
> [   85.078409] x86: Booting SMP configuration:
> [   85.079027] smpboot: Booting Node 0 Processor 1 APIC 0x1
> [   85.080240] kvm-clock: cpu 1, msr 77601041, secondary cpu clock
> [   85.080450] smpboot: CPU 1 Converting physical 0 to logical die 1
> [   85.101228] TSC ADJUST compensate: CPU1 observed 169175101528 warp. Adjust: 169175101528
> [  141.513496] TSC ADJUST compensate: CPU1 observed 166 warp. Adjust: 169175101694
> [  141.513496] TSC synchronization [CPU#0 -> CPU#1]:
> [  141.513496] Measured 235 cycles TSC warp between CPUs, turning off TSC clock.
> [  141.513496] tsc: Marking TSC unstable due to check_tsc_sync_source failed
> [  141.543996] KVM setup async PF for cpu 1
> [  141.544281] kvm-stealtime: cpu 1, msr 13bd2c080
> [  141.549381] Will online and init hotplugged CPU: 1
> 
> System time jumps from 85.101228 to 141.51.3496.
> 
> Guest:                                   KVM
> -----                                    ------
> check_tsc_sync_target()
> wrmsrl(MSR_IA32_TSC_ADJUST,...)
>                                           kvm_set_msr_common(vcpu,...)
>                                           adjust_tsc_offset_guest(vcpu,...) //tsc_offset jumped
>                                           vcpu_enter_guest(vcpu) //tsc_timestamp was not changed
> ...
> rdtsc() jumped, system time jumped
> 
> tsc_timestamp must be updated before go back to guest.
> 
> ---
> Zelin Deng (1):
>    KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset
>      is adjusted
> 
>   arch/x86/kvm/x86.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 

While Thomas is right in general, what you found is indeed a bug with 
the KVM->userspace API to set up the vCPU TSC adjust.  So I'm queueing 
the patch for 5.15.

Thanks,

Paolo


      parent reply	other threads:[~2021-09-06 11:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  2:22 Zelin Deng
2021-04-28  2:22 ` [PATCH] KVM: x86: Update vCPU's hv_clock before back to guest when tsc_offset is adjusted Zelin Deng
2021-04-28  9:00 ` [PATCH] Guest system time jumps when new vCPUs is hot-added Thomas Gleixner
2021-04-28  9:09   ` Thomas Gleixner
2021-04-28 23:24   ` Zelin Deng
2021-04-29  8:46     ` Thomas Gleixner
2021-04-29  9:38       ` Zelin Deng
2021-04-29 16:02         ` Thomas Gleixner
2021-04-29 22:40           ` Zelin Deng
2021-09-06 11:22 ` Paolo Bonzini [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=9f0d0543-db41-fbb0-019c-7df5b9319c33@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    --cc=zelin.deng@linux.alibaba.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

all inboxes | Powered by JetHome®