From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DBFCC433B4 for ; Wed, 28 Apr 2021 02:22:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7389961407 for ; Wed, 28 Apr 2021 02:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239577AbhD1CWs (ORCPT ); Tue, 27 Apr 2021 22:22:48 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:40121 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbhD1CWr (ORCPT ); Tue, 27 Apr 2021 22:22:47 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=zelin.deng@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UX10nnq_1619576521; Received: from localhost(mailfrom:zelin.deng@linux.alibaba.com fp:SMTPD_---0UX10nnq_1619576521) by smtp.aliyun-inc.com(127.0.0.1); Wed, 28 Apr 2021 10:22:01 +0800 From: Zelin Deng To: Paolo Bonzini , Sean Christopherson , Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org Subject: [PATCH] Guest system time jumps when new vCPUs is hot-added Date: Wed, 28 Apr 2021 10:22:00 +0800 Message-Id: <1619576521-81399-1-git-send-email-zelin.deng@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, I have below VM configuration: ... 2 ... 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(+) -- 1.8.3.1