linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: "Wanpeng Li" <kernellwp@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Wanpeng Li" <wanpeng.li@hotmail.com>,
	"Sasha Levin" <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 4.9 20/55] KVM: X86: Fix softlockup when get the current kvmclock
Date: Wed, 24 Jan 2018 04:15:39 +0000	[thread overview]
Message-ID: <20180124041521.32223-20-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180124041521.32223-1-alexander.levin@microsoft.com>

From: Wanpeng Li <kernellwp@gmail.com>

[ Upstream commit e70b57a6ce4e8b92a56a615ae79bdb2bd66035e7 ]

 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_time_ref_counter+0x5a/0x80 [kvm]
  kvm_hv_process_stimers+0x120/0x5f0 [kvm]
  kvm_arch_vcpu_ioctl_run+0x4b4/0x1690 [kvm]
  kvm_vcpu_ioctl+0x33a/0x620 [kvm]
  do_vfs_ioctl+0xa1/0x5d0
  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.

Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
 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 6c11a98860d1..e023ef981feb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1751,10 +1751,13 @@ static 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
+		ret = ktime_get_boot_ns() + ka->kvmclock_offset;
 
 	put_cpu();
 
-- 
2.11.0

  parent reply	other threads:[~2018-01-24  4:17 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24  4:15 [PATCH AUTOSEL for 4.9 01/55] drm/vc4: Account for interrupts in flight Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 02/55] cpupowerutils: bench - Fix cpu online check Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 04/55] KVM: x86: emulator: Return to user-mode on L1 CPL=0 emulation failure Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 03/55] cpupower : Fix cpupower working when cpu0 is offline Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 05/55] KVM: x86: Don't re-execute instruction when not passing CR2 value Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 06/55] KVM: X86: Fix operand/address-size during instruction decoding Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 07/55] KVM: x86: ioapic: Fix level-triggered EOI and IOAPIC reconfigure race Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 09/55] KVM: x86: ioapic: Preserve read-only values in the redirection table Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 08/55] KVM: x86: ioapic: Clear Remote IRR when entry is switched to edge-triggered Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 10/55] ACPI / bus: Leave modalias empty for devices which are not present Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 11/55] cpufreq: Add Loongson machine dependencies Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 12/55] bcache: check return value of register_shrinker Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 13/55] drm/amdgpu: Fix SDMA load/unload sequence on HWS disabled mode Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 14/55] drm/amdkfd: Fix SDMA ring buffer size calculation Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 16/55] openvswitch: fix the incorrect flow action alloc size Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 15/55] drm/amdkfd: Fix SDMA oversubsription handling Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 18/55] btrfs: fix deadlock when writing out space cache Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 17/55] mac80211: fix the update of path metric for RANN frame Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 19/55] reiserfs: remove unneeded i_version bump Sasha Levin
2018-01-24  4:15 ` Sasha Levin [this message]
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 21/55] KVM: VMX: Fix rflags cache during vCPU reset Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 22/55] xfs: always free inline data before resetting inode fork during ifree Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 23/55] xen-netfront: remove warning when unloading module Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 24/55] auxdisplay: img-ascii-lcd: Only build on archs that have IOMEM Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 25/55] nfsd: CLOSE SHOULD return the invalid special stateid for NFSv4.x (x>0) Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 26/55] nfsd: Ensure we don't recognise lock stateids after freeing them Sasha Levin
2018-01-24 15:47   ` J. Bruce Fields
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 27/55] nfsd: Ensure we check stateid validity in the seqid operation checks Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 28/55] grace: replace BUG_ON by WARN_ONCE in exit_net hook Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 29/55] nfsd: check for use of the closed special stateid Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 30/55] lockd: fix "list_add double add" caused by legacy signal interface Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 31/55] hwmon: (pmbus) Use 64bit math for DIRECT format values Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 32/55] bnxt_en: Fix an error handling path in 'bnxt_get_module_eeprom()' Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 33/55] xfs: fortify xfs_alloc_buftarg error handling Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 34/55] drm/amdgpu: don't try to move pinned BOs Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 35/55] net: ethernet: xilinx: Mark XILINX_LL_TEMAC broken on 64-bit Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 36/55] quota: Check for register_shrinker() failure Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 37/55] SUNRPC: Allow connect to return EHOSTUNREACH Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 39/55] kmemleak: add scheduling point to kmemleak_scan() Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 38/55] fs/mbcache.c: make count_objects() more robust Sasha Levin
2018-01-24  4:29   ` Eric Biggers
2018-01-24 17:27     ` Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 40/55] drm/bridge: tc358767: do no fail on hi-res displays Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 41/55] drm/bridge: tc358767: filter out too high modes Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 42/55] drm/bridge: tc358767: fix DP0_MISC register set Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 43/55] drm/bridge: tc358767: fix timing calculations Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 44/55] drm/bridge: tc358767: fix AUXDATAn registers access Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 46/55] drm/omap: Fix error handling path in 'omap_dmm_probe()' Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 45/55] drm/bridge: tc358767: fix 1-lane behavior Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 48/55] xfs: Properly retry failed dquot items in case of error during buffer writeback Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 47/55] xfs: ubsan fixes Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 50/55] scsi: ufs: ufshcd: fix potential NULL pointer dereference in ufshcd_config_vreg Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 49/55] scsi: aacraid: Prevent crash in case of free interrupt during scsi EH path Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 51/55] iwlwifi: mvm: fix the TX queue hang timeout for MONITOR vif type Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 52/55] ARM: dts: NSP: Fix PPI interrupt types Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 53/55] media: usbtv: add a new usbid Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 54/55] usb: gadget: don't dereference g until after it has been null checked Sasha Levin
2018-01-24  4:15 ` [PATCH AUTOSEL for 4.9 55/55] staging: rtl8188eu: Fix incorrect response to SIOCGIWESSID Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180124041521.32223-20-alexander.levin@microsoft.com \
    --to=alexander.levin@microsoft.com \
    --cc=kernellwp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).