From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932235AbdKOK36 (ORCPT ); Wed, 15 Nov 2017 05:29:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42930 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932107AbdKOK3s (ORCPT ); Wed, 15 Nov 2017 05:29:48 -0500 Subject: Re: [PATCH v3] KVM: X86: Fix softlockup when get the current kvmclock To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1510195932-6232-1-git-send-email-wanpeng.li@hotmail.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <5d6e5f30-3191-6d8d-dbff-9f44bb5a5954@redhat.com> Date: Wed, 15 Nov 2017 11:29:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1510195932-6232-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 15 Nov 2017 10:29:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09.11.2017 03:52, Wanpeng Li wrote: > From: Wanpeng Li > > watchdog: BUG: soft lockup - CPU#6 stuck for 22s! [qemu-system-x86:10185] > CPU: 6 PID: 10185 Comm: qemu-system-x86 Tainted: G OE 4.14.0-rc4+ #4 > RIP: 0010:kvm_get_time_scale+0x4e/0xa0 [kvm] > Call Trace: > ? get_kvmclock_ns+0xa3/0x140 [kvm] > get_time_ref_counter+0x5a/0x80 [kvm] > kvm_hv_process_stimers+0x120/0x5f0 [kvm] > ? kvm_hv_process_stimers+0x120/0x5f0 [kvm] > ? preempt_schedule+0x27/0x30 > ? ___preempt_schedule+0x16/0x18 > kvm_arch_vcpu_ioctl_run+0x4b4/0x1690 [kvm] > ? kvm_arch_vcpu_load+0x47/0x230 [kvm] > kvm_vcpu_ioctl+0x33a/0x620 [kvm] > ? kvm_vcpu_ioctl+0x33a/0x620 [kvm] > ? kvm_vm_ioctl_check_extension_generic+0x3b/0x40 [kvm] > ? kvm_dev_ioctl+0x279/0x6c0 [kvm] > do_vfs_ioctl+0xa1/0x5d0 > ? __fget+0x73/0xa0 > SyS_ioctl+0x79/0x90 > entry_SYSCALL_64_fastpath+0x1e/0xa9 > > This can be reproduced when running kvm-unit-tests/hyperv_stimer.flat and > cpu-hotplug stress simultaneously. __this_cpu_read(cpu_tsc_khz) returns 0 > (set in kvmclock_cpu_down_prep()) when the pCPU is unhotplug which results > in kvm_get_time_scale() gets into an infinite loop. > > This patch fixes it by treating the unhotplug pCPU as not using master clock. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/x86.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 03869eb..d61dcce3 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1795,10 +1795,13 @@ u64 get_kvmclock_ns(struct kvm *kvm) > /* both __this_cpu_read() and rdtsc() should be on the same cpu */ > get_cpu(); > > - kvm_get_time_scale(NSEC_PER_SEC, __this_cpu_read(cpu_tsc_khz) * 1000LL, > - &hv_clock.tsc_shift, > - &hv_clock.tsc_to_system_mul); > - ret = __pvclock_read_cycles(&hv_clock, rdtsc()); > + if (__this_cpu_read(cpu_tsc_khz)) { > + kvm_get_time_scale(NSEC_PER_SEC, __this_cpu_read(cpu_tsc_khz) * 1000LL, > + &hv_clock.tsc_shift, > + &hv_clock.tsc_to_system_mul); > + ret = __pvclock_read_cycles(&hv_clock, rdtsc()); > + } else Can we add a comment like /* unplugging a physical CPU -> avoid using the master clock */ > + ret = ktime_get_boot_ns() + ka->kvmclock_offset; > > put_cpu(); > > Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb