Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp882617pxy; Wed, 28 Apr 2021 16:26:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1oZEEQmvMz1Hxx/wwVus8PKcKG5cgzlR60Lh2FbA79i7lBgSNSiti8S7lhoP+Nfe/+1G7 X-Received: by 2002:a17:902:dacd:b029:e5:cf71:3901 with SMTP id q13-20020a170902dacdb02900e5cf713901mr31616337plx.23.1619652416949; Wed, 28 Apr 2021 16:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619652416; cv=none; d=google.com; s=arc-20160816; b=IP0C0qWKkr1gtGNOUOmvTQAjE5k01UWnGMvM4KemIklnbLwWB1fXu4TrbTXwZVakNE X7z3cZYAzbwg2yWQOKGyqPcocFOM5uVjxWRLUt55MkTqgOWt5m4FjWeElR1usW2p/IE7 Xw7t6143k01SstRHQJcqvyx/vzts5jfHho9MkmXP4bYpjwD1ihm1exORA7HYO8fvGH41 NKMfWp183bWEEqqWhXnZSAu+OGjMyGX31r+7Q0z/PhFlLzHW5ksqppRk+RQzPMmWaJMY 8D1ojFsimlcy8Tg5ILUzbPG5OtdhUI5Gz/Q5Dh/0SUHmHrnyn+HmwBUgUCxjqzjeZLEu U/4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=aKpqh8/4zuLl/TlAD2r85wiv0stO5WaugApE6VDhqyk=; b=OZK6JcvQfa9AYlk2ztBfE0d6WrhszUcNlQmzTio+u+M9/H7S1Azcp/eQUhEBEpZsBZ JznqjfaA7hfgxtp4NwnjkqvUMmtvckXkGa1ZQkkv8PqLCWkyOmLvFq5enZhfX2LxI8rx KeNRJaPut4ixdRYEUg+QfMtN17Vitf+hKbTUIQ81idojcrywO70QDWmTJIuLwP9QvfpO N+T+NMTSxrz+A0BWEcofWrpRS7U7564Vs9ht0HCSwJyE9lsLtKlT/NNsI7hTuKswoYzQ PDTigr8vcx5TS0ubW0cXBwFL12QwbuwslstSDm+fZ5NCULSsg7EYwmZyhQeEWGclovXh otiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si1343049pjz.86.2021.04.28.16.26.44; Wed, 28 Apr 2021 16:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbhD1XZo (ORCPT + 99 others); Wed, 28 Apr 2021 19:25:44 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:45621 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231807AbhD1XZn (ORCPT ); Wed, 28 Apr 2021 19:25:43 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R891e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=zelin.deng@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UX6F7Pt_1619652295; Received: from IT-FVFX909QHV2H.local(mailfrom:zelin.deng@linux.alibaba.com fp:SMTPD_---0UX6F7Pt_1619652295) by smtp.aliyun-inc.com(127.0.0.1); Thu, 29 Apr 2021 07:24:56 +0800 Subject: Re: [PATCH] Guest system time jumps when new vCPUs is hot-added To: Thomas Gleixner , Paolo Bonzini , Sean Christopherson , Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org References: <1619576521-81399-1-git-send-email-zelin.deng@linux.alibaba.com> <87lf92n5r1.ffs@nanos.tec.linutronix.de> From: Zelin Deng Message-ID: Date: Thu, 29 Apr 2021 07:24:55 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <87lf92n5r1.ffs@nanos.tec.linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/4/28 下午5:00, Thomas Gleixner wrote: > On Wed, Apr 28 2021 at 10:22, Zelin Deng wrote: > >> 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 > Why is TSC_ADJUST on CPU1 different from CPU0 in the first place? Per my understanding when vCPU is created by KVM, it's tsc_offset = 0 - host rdtsc() meanwhile TSC_ADJUST is 0. Assume vCPU0 boots up with tsc_offset0, after 10000 tsc cycles, hotplug via "virsh setvcpus" creates a new vCPU1 whose tsc_offset1 should be about tsc_offset0 - 10000.  Therefore there's 10000 tsc warp between rdtsc() in guest of vCPU0 and vCPU1, check_tsc_sync_target() when vCPU1 gets online will set TSC_ADJUST for vCPU1. Did I miss something? > > That's broken. > > Thanks, > > tglx