From patchwork Mon Jul 11 07:40:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot for Kobe Wu X-Patchwork-Id: 9222965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B590860760 for ; Mon, 11 Jul 2016 07:41:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6AAE27BEE for ; Mon, 11 Jul 2016 07:41:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9766427C05; Mon, 11 Jul 2016 07:41:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A986527BEE for ; Mon, 11 Jul 2016 07:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753327AbcGKHlK (ORCPT ); Mon, 11 Jul 2016 03:41:10 -0400 Received: from terminus.zytor.com ([198.137.202.10]:38996 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751421AbcGKHlJ (ORCPT ); Mon, 11 Jul 2016 03:41:09 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id u6B7eJ3r003950; Mon, 11 Jul 2016 00:40:19 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id u6B7eJfj003945; Mon, 11 Jul 2016 00:40:19 -0700 Date: Mon, 11 Jul 2016 00:40:19 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Wanpeng Li Message-ID: Cc: len.brown@intel.com, linux-pm@vger.kernel.org, y.c.chen@intel.com, tglx@linutronix.de, rui.zhang@intel.com, hpa@zytor.com, mingo@kernel.org, xiaolong.ye@intel.com, rkrcmar@redhat.com, pbonzini@redhat.com, rjw@rjwysocki.net, peterz@infradead.org, wanpeng.li@hotmail.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org Reply-To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, wanpeng.li@hotmail.com, rjw@rjwysocki.net, peterz@infradead.org, pbonzini@redhat.com, rkrcmar@redhat.com, xiaolong.ye@intel.com, mingo@kernel.org, hpa@zytor.com, rui.zhang@intel.com, tglx@linutronix.de, y.c.chen@intel.com, linux-pm@vger.kernel.org, len.brown@intel.com In-Reply-To: <1466558908-3524-1-git-send-email-wanpeng.li@hotmail.com> References: <1466558908-3524-1-git-send-email-wanpeng.li@hotmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] x86/tsc_msr: Fix rdmsr(MSR_PLATFORM_INFO) unsafe warning in KVM guest Git-Commit-ID: 37c528ee1af7f24eb31f4195b8b7d4f23e6c716d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit-ID: 37c528ee1af7f24eb31f4195b8b7d4f23e6c716d Gitweb: http://git.kernel.org/tip/37c528ee1af7f24eb31f4195b8b7d4f23e6c716d Author: Wanpeng Li AuthorDate: Wed, 22 Jun 2016 09:28:28 +0800 Committer: Ingo Molnar CommitDate: Mon, 11 Jul 2016 09:20:36 +0200 x86/tsc_msr: Fix rdmsr(MSR_PLATFORM_INFO) unsafe warning in KVM guest After this commit: fc273eeef314 ("x86/tsc_msr: Extend to include Intel Core Architecture") The following unsafe MSR reading warning triggers: WARNING: CPU: 0 PID: 0 at arch/x86/mm/extable.c:50 ex_handler_rdmsr_unsafe+0x6a/0x70 unchecked MSR access error: RDMSR from 0xce Call Trace: dump_stack+0x67/0x99 __warn+0xd1/0xf0 warn_slowpath_fmt+0x4f/0x60 ex_handler_rdmsr_unsafe+0x6a/0x70 fixup_exception+0x39/0x50 do_general_protection+0x93/0x1b0 general_protection+0x22/0x30 ? cpu_khz_from_msr+0xd8/0x1c0 native_calibrate_cpu+0x30/0x5b0 tsc_init+0x2b/0x297 x86_late_time_init+0xf/0x11 start_kernel+0x398/0x451 ? set_init_arg+0x55/0x55 x86_64_start_reservations+0x2f/0x31 x86_64_start_kernel+0xea/0xed As Radim pointed out before: | MSR_PLATFORM_INFO: Intel changes it from family to family and there is | no obvious overlap or default. If we picked 0 (any other fixed value), | then the guest would have to know that 0 doesn't mean that | MSR_PLATFORM_INFO returned 0, but that KVM doesn't emulate this MSR and | the value cannot be used. This is very similar to handling a #GP in the | guest, but also has a disadvantage, because KVM cannot say that | MSR_PLATFORM_INFO is 0. Simple emulation is not possible. Fix it by using rdmsr_safe(MSR_PLATFORM_INFO) in KVM guest to not trigger a #GP, then tsc will be calibrated by a fallback method: PIT, HPET etc. Reported-by: kernel test robot Signed-off-by: Wanpeng Li Acked-by: Paolo Bonzini Cc: Chen Yu Cc: H. Peter Anvin Cc: Len Brown Cc: Linus Torvalds Cc: Linux PM list Cc: Peter Zijlstra Cc: Radim Krčmář Cc: Rafael J. Wysocki Cc: Thomas Gleixner Cc: Zhang Rui Cc: jacob.jun.pan@intel.com Cc: kvm@vger.kernel.org Cc: linux-acpi@vger.kernel.org Cc: lkp@01.org Link: http://lkml.kernel.org/r/1466558908-3524-1-git-send-email-wanpeng.li@hotmail.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/tsc_msr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/kernel/tsc_msr.c b/arch/x86/kernel/tsc_msr.c index e0c2b30..e6e465e 100644 --- a/arch/x86/kernel/tsc_msr.c +++ b/arch/x86/kernel/tsc_msr.c @@ -70,7 +70,7 @@ static int match_cpu(u8 family, u8 model) */ unsigned long cpu_khz_from_msr(void) { - u32 lo, hi, ratio, freq_id, freq; + u32 lo, hi, freq_id, freq, ratio = 0; unsigned long res; int cpu_index; @@ -123,8 +123,8 @@ unsigned long cpu_khz_from_msr(void) } get_ratio: - rdmsr(MSR_PLATFORM_INFO, lo, hi); - ratio = (lo >> 8) & 0xff; + if (!rdmsr_safe(MSR_PLATFORM_INFO, &lo, &hi)) + ratio = (lo >> 8) & 0xff; done: /* TSC frequency = maximum resolved freq * maximum resolved bus ratio */