Received: by 10.223.164.202 with SMTP id h10csp1710669wrb; Wed, 8 Nov 2017 08:27:39 -0800 (PST) X-Google-Smtp-Source: ABhQp+RxQ8CR+UMtSqmi9NsDo/PkOsD6GoTLe52n1YXef6ORZYF0sRdsEHnycPsb4loYbx2nhXR6 X-Received: by 10.98.34.130 with SMTP id p2mr1077751pfj.108.1510158459351; Wed, 08 Nov 2017 08:27:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510158459; cv=none; d=google.com; s=arc-20160816; b=wvn3RTk7pmRqn5T8i5/V9BNr44EUgauH1d1LckJ8JMNrBxt2aZzT/ioCsuGPUNu9+/ eMkVA9rQxfN847XMUJLV3iz+sTdDDCMhSYBveBwAUVBLodE5iP1U9pGy/1DZnXU18nse Gjyw0b0HJqlvcC6TVJwg/toZlYioNaMJsS0Dk1ZAXFfs+D09NDh4PTo8H3NL3KSW8Y5D PYhnP2gQOSysAuxx4LAuCnjalPQ3Idiw17giV4u0nWILB/Io4HzzKmlnBPcR3z6oZjRn 75/ZXXmNZWz+U32DipNBvAQjjq4U0XAWq9B7/5Ten3nUYzahHdjKbnMJ0fS4x1ebOwdr eHQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=VxfV0KRqE5UcMIerOXdcoOMiNglwg7ft4fGw7Mu9srA=; b=DR9qWWVcRBb5D8M+uFC96ZOKgiG0f4zsyb+MJYdln+PsZKFHpAQWZTU6hiW/AQedbS 3bkJ6Ecdcm2YxVz5XPeDTeMp5h0+JS574Sp8D5z3wwR1S7bWwrqiqIbFaJjtWhbHxTVq ASbTmFGwQ9vXZWKoYN7Tt1tlvuuwg9A/H7IxqrdlQg8j9YP+2h19oGI3yQi49FjLc6lt hgtQS37kKM18ShTj/Ihng++JEm+hRKrc3lsbv76fALA+03blGwB/ttoORUhJ5yo9awli nomy6L1Bt/A2KUzIvQXy1yYJm5cYhxswlZhx8gA6bYiLaFTj6X5OCghTY9xCl4AMsFys 6mRQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si4345827plf.106.2017.11.08.08.27.27; Wed, 08 Nov 2017 08:27:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752675AbdKHQ0h (ORCPT + 83 others); Wed, 8 Nov 2017 11:26:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58175 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752326AbdKHQ0f (ORCPT ); Wed, 8 Nov 2017 11:26:35 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FE155F795; Wed, 8 Nov 2017 16:26:35 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 00A7E5D6A9; Wed, 8 Nov 2017 16:26:31 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Wed, 08 Nov 2017 17:26:31 +0100 Date: Wed, 8 Nov 2017 17:26:31 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li Subject: Re: [PATCH v2] KVM: X86: Fix softlockup when get the current kvmclock timestamp Message-ID: <20171108162630.GA3099@flask> References: <1509970640-18679-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1509970640-18679-1-git-send-email-wanpeng.li@hotmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 08 Nov 2017 16:26:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-06 04:17-0800, Wanpeng Li: > 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 skipping to fill the hv_clock when the pCPU is offline. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > v1 -> v2: > * avoid infinite loop > > arch/x86/kvm/x86.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 03869eb..d2507c6 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1259,6 +1259,9 @@ static void kvm_get_time_scale(uint64_t scaled_hz, uint64_t base_hz, > uint64_t tps64; > uint32_t tps32; > > + if (unlikely(base_hz == 0)) > + return; This is a sensible thing to do and will prevent the loop, but KVM will still have a minor bug: get_kvmclock_ns() passes uninitialized stack values with the expectation that kvm_get_time_scale() will set them, but returning here would result in __pvclock_read_cycles() with random data and inject timer interrupts early (if not worse). I think it would be best if kvm_get_time_scale() wasn't executing when cpu_tsc_khz is 0, by clearing cpu_tsc_khz later and setting earlier; do you see any problems with moving the CPUHP_AP_X86_KVM_CLK_ONLINE before CPUHP_AP_ONLINE? Thanks. From 1583319037672285676@xxx Mon Nov 06 12:18:20 +0000 2017 X-GM-THRID: 1583276151146767154 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread