Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1064876pxb; Thu, 4 Mar 2021 02:15:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8dXENnB9qUdThpgD/4FgepIUvehxVN/sHt/L9tOENBDWfEBk4DVBtSF0cIrcw+OaHXGhE X-Received: by 2002:a17:906:8a6e:: with SMTP id hy14mr3488296ejc.356.1614852903713; Thu, 04 Mar 2021 02:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614852903; cv=none; d=google.com; s=arc-20160816; b=Fz1cUGjUDSBn5ppdWc+8EcbdjBsrP2rBw5l9FKh02DLUDVQkzIS4yvP5ai3FV/AsNY VZqxt33LzRKskeYKy4bnq6WB67PHqP4BOI0e34CXFSadEocI2atQ10vezRIjpWLGF061 ETEH0qUzlrYGQhfGJneC+Zw0Txcg7sscuZ7j7ke3YG6h4x+3nf2jyfHlLG3AeIRKk8KA yHuIhZwGnbZEVDjtItk2VzfaMsxx/LJ/4f8+XdFXPfHOrFO/PdSCSIUv3zNZjW3MNPtF nc6lJKrk4AdIElC1KeVvywoPhd0mWsOSDBwvIEwx3bLYTS4xy1Al2UERGZB5t6Q4scrh 6Uaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=g/gTB4lQTNPNY/Z8U5KBZldMFRqfKkHfbSSlMpobRHM=; b=ScB2n7tMWgxGbZgNTiIP6kXv91JIZa+Ffk8Kq5KQLmaSwRH0JYYa+S5znVQDnCJyuH jmze9H1Bugw9u20IL6hwg2+Vhr45PUzaUj5XIe1DqBwKgbhqd7hY+Z7Gt5bWUdhc1B2J 1pP2zJhj6/vKV+1aGjm8ojmsb09H3ZoH9k9/UZTVd3bkJpVZ3gvKC/h+vW/P33hX2p7L 18AkNng15SBbQWBWFXL/F59leA9rBUsYa+hXKnRdtRQsKWketZPEFYf+PY/QBtdFBWVw 37W3UkBBpEVcF7hBos1RLR2aCvXXdLGoxSklkygvsj43qDzjJflPXXvnH7k6oQHkVxlk 3hxQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o16si14817803ejd.213.2021.03.04.02.14.41; Thu, 04 Mar 2021 02:15:03 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231998AbhCCQig (ORCPT + 99 others); Wed, 3 Mar 2021 11:38:36 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:13849 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352972AbhCCLzn (ORCPT ); Wed, 3 Mar 2021 06:55:43 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DrC6K3q7Yz7rxF; Wed, 3 Mar 2021 19:52:25 +0800 (CST) Received: from localhost (10.174.150.118) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Wed, 3 Mar 2021 19:54:00 +0800 From: To: CC: , , , Zhuang Yanying Subject: [PATCH] KVM: x86: fix cpu hang due to tsc adjustment when kvmclock in use Date: Wed, 3 Mar 2021 19:53:57 +0800 Message-ID: <20210303115357.7464-1-ann.zhuangyanying@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.150.118] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhuang Yanying If the TSC frequency of the VM is not equal to the host, hot-plugging vCPU will cause the VM to be hang. The time of hang depends on the current TSC value of the VM. System time calculation of kvmclock is based on (tsc_timestamp, system_time), and adjusted by delta ( = rdtsc_ordered() - src->tsc_timestamp).The tsc of the hotplugged cpu is initialized to 0, which will trigger check_tsc_sync_target() to adjust the tsc of the hotplugged cpu according to another online cpu, that is, rdtsc_ordered() will change abruptly to a large value. Then system time based on kvmclock is modified at the same time. So after modifying the tsc offset, update vcpu->hv_clock immediately. --- Host: Intel(R) Xeon(R) Gold 6161 CPU @ 2.20GHz linux-5.11 qemu-5.1 Guest: Centos8.1 (4.18.0-147.el8.x86_64) After Hotplug cpu, vm hang for 290s: [ 283.224026] CPU3 has been hot-added [ 283.226118] smpboot: Booting Node 0 Processor 3 APIC 0x3 [ 283.226964] kvm-clock: cpu 3, msr 9e5e010c1, secondary cpu clock [ 283.247200] TSC ADJUST compensate: CPU3 observed 867529151959 warp. Adjust: 867529151959 [ 572.445543] KVM setup async PF for cpu 3 [ 572.446412] kvm-stealtime: cpu 3, msr a16ce5040 [ 572.448108] Will online and init hotplugged CPU: 3 Feb 27 18:47:28 localhost kernel: CPU3 has been hot-added Feb 27 18:47:28 localhost kernel: smpboot: Booting Node 0 Processor 3 APIC 0x3 Feb 27 18:47:28 localhost kernel: kvm-clock: cpu 3, msr 9e5e010c1, secondary cpu clock Feb 27 18:47:28 localhost kernel: TSC ADJUST compensate: CPU3 observed 867529151959 warp. Adjust: 867529151959 Feb 27 18:47:28 localhost kernel: KVM setup async PF for cpu 3 Feb 27 18:47:28 localhost kernel: kvm-stealtime: cpu 3, msr a16ce5040 Feb 27 18:47:28 localhost kernel: Will online and init hotplugged CPU: 3 Feb 27 18:47:28 localhost systemd[1]: Started /usr/lib/udev/kdump-udev-throttler. [ 572.495181] clocksource: timekeeping watchdog on CPU2: Marking clocksource 'tsc' as unstable because the skew is too large: [ 572.495181] clocksource: 'kvm-clock' wd_now: 86ab1286a2 wd_last: 4344b44d09 mask: ffffffffffffffff [ 572.495181] clocksource: 'tsc' cs_now: ca313c563b cs_last: c9d88b54d2 mask: ffffffffffffffff [ 572.495181] tsc: Marking TSC unstable due to clocksource watchdog [ 572.495181] clocksource: Switched to clocksource kvm-clock Feb 27 18:47:28 localhost kernel: clocksource: timekeeping watchdog on CPU2: Marking clocksource 'tsc' as unstable because the skew Feb 27 18:47:28 localhost kernel: clocksource: 'kvm-clock' wd_now: 86ab1286a2 wd_last: 4344b44d09 mask: ffffff Feb 27 18:47:28 localhost kernel: clocksource: 'tsc' cs_now: ca313c563b cs_last: c9d88b54d2 mask: ffffffffffff Feb 27 18:47:28 localhost kernel: tsc: Marking TSC unstable due to clocksource watchdog Feb 27 18:47:28 localhost kernel: clocksource: Switched to clocksource kvm-clock Feb 27 18:47:28 localhost systemd[1]: Started Getty on tty2. Feb 27 18:47:29 localhost kdump-udev-throttler[3530]: kexec: unloaded kdump kernel Feb 27 18:47:29 localhost kdump-udev-throttler[3530]: Stopping kdump: [OK] Feb 27 18:47:29 localhost kdump-udev-throttler[3530]: kexec: loaded kdump kernel Feb 27 18:47:29 localhost kdump-udev-throttler[3530]: Starting kdump: [OK] --- arch/x86/kvm/x86.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3712bb5245eb..429206d65989 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3078,6 +3078,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (!msr_info->host_initiated) { s64 adj = data - vcpu->arch.ia32_tsc_adjust_msr; adjust_tsc_offset_guest(vcpu, adj); + kvm_make_request(KVM_REQ_CLOCK_UPDATE, vcpu); } vcpu->arch.ia32_tsc_adjust_msr = data; } -- 2.23.0