Received: by 10.223.164.202 with SMTP id h10csp2170952wrb; Thu, 16 Nov 2017 10:28:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ6cuZtQW1WYrMK8TAjpllNXtUlwoed4rCMZyI+FYsdo3aCeS1/AAFk6JzBnpwA7+Zu/0fs X-Received: by 10.84.241.5 with SMTP id a5mr2461237pll.81.1510856882643; Thu, 16 Nov 2017 10:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510856882; cv=none; d=google.com; s=arc-20160816; b=Jacs5pmTx15mWPTgIusw/s3WejrkxSIZhdjic04eBNEUM8yFhP3gxGOWd+HsvzRN2v s+8Wc1e0MKs2RAFlXc1J+CmHKlCLsbVjPuIqTRm1JIQfBDzGUSboboola/lR9lyVIYk8 cf7OCJQkFYbOknhAbumUv/h7vr/l95KR7ZU+hbuNmJi+/O5Yp0O0mer15MlFH0J3WI0l U5I5BII5OlJYFgT4zGmQTf859TmD/LEoW0j5EfX8uNVYFKT3qKOUGIMHGE5bQluCofc5 /shyeg4LK7j7uVw1HvArE+dAx4yjVKhG+Dql/KKhjNo6rqKmH4EhnsPfe1Nb4INStXHL EM6A== 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=irZCZ4NmvgRx2iohVcONfGncOP29GmzG5qSj2DpdzFE=; b=Qm5CbTwoFdCXT2pFV7W6DlBLs1BEjPF155tJVsYuehRFEShcz2WCGyXvfJmN44GNGb B1sj+e/6sCM+gaZWfXcj39tIKoJWk/mNl/+FyhvbxCCkkfEXgfmeYuQITwXm+bA+ns/W z7grl2CyCmgsCukj4E5qDrOFLN7ovwIbw5pZZ5mlETw+fgggc/OH05RuvybWNm74+2/2 4MKCUTF50asdrCipkrHB39CGT9ffmBX9mPKcmz2cdVd0l7Qzpsx7ZYXpOPFWUbKSiTbF keUcXX0jT3WkbePVazmGq6vKgRdad8xsXBnMYlpkTYWOkz0+8Uv77op9gwTVUDGJllyZ i43w== 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 r2si1385154pfj.361.2017.11.16.10.27.47; Thu, 16 Nov 2017 10:28:02 -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 S1760696AbdKPSZ5 (ORCPT + 92 others); Thu, 16 Nov 2017 13:25:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57014 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760569AbdKPSZu (ORCPT ); Thu, 16 Nov 2017 13:25:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31DA51665; Thu, 16 Nov 2017 18:25:50 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 09420614C3; Thu, 16 Nov 2017 18:25:47 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 16 Nov 2017 19:25:47 +0100 Date: Thu, 16 Nov 2017 19:25:47 +0100 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: "linux-kernel@vger.kernel.org" , kvm , Paolo Bonzini , Wanpeng Li Subject: Re: [PATCH v3] KVM: X86: Fix softlockup when get the current kvmclock Message-ID: <20171116182546.GD20438@flask> References: <1510195932-6232-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: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 16 Nov 2017 18:25:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-15 09:17+0800, Wanpeng Li: > Ping, :) Ah, sorry, I got distracted while learning about the hotplug mechanism. Indeed we cannot move move the callback earlier because the cpufreq driver kvm uses on crappy hardware gets set in CPUHP_AP_ONLINE_DYN, which is way too late. > 2017-11-09 10:52 GMT+08:00 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 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, Would be safer to read __this_cpu_read(cpu_tsc_khz) only once, but I think it works for now as unplug thread must be scheduled and get_cpu() prevents changes. > > + &hv_clock.tsc_shift, > > + &hv_clock.tsc_to_system_mul); > > + ret = __pvclock_read_cycles(&hv_clock, rdtsc()); > > + } else > > + ret = ktime_get_boot_ns() + ka->kvmclock_offset; Not pretty, but gets the job done ... Reviewed-by: Radim Krčmář From 1584127693013966257@xxx Wed Nov 15 10:31:34 +0000 2017 X-GM-THRID: 1583555269032973391 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread