From patchwork Wed Jun 22 01:28:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9191685 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 DFFC76075A for ; Wed, 22 Jun 2016 01:29:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFA2228111 for ; Wed, 22 Jun 2016 01:29:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C410428383; Wed, 22 Jun 2016 01:29:17 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 1A2A328358 for ; Wed, 22 Jun 2016 01:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752256AbcFVB2t (ORCPT ); Tue, 21 Jun 2016 21:28:49 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33271 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbcFVB2q (ORCPT ); Tue, 21 Jun 2016 21:28:46 -0400 Received: by mail-pf0-f193.google.com with SMTP id c74so2519672pfb.0; Tue, 21 Jun 2016 18:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ypHs0unV1uLPNVeiupO27E/9Ckoy/gg3WAzZrNg27LE=; b=t+oh7m1DLoVHg09OCc+SnnAJBnVRuKQKZKJ2Xa4tvuYFXD9Yq8zd22MTKWa0nvQDXz RMFMLrdHjM3oW0IAK2eRaroyI/FZoOoxZXvkKLQoQwpyRKn3dgaAtdf8gD4tKUtWcD+x fvuj8Y3G2by4/Ct956K+B9A6ZFC4gukkV1WQ6PoK7TKPVDkvqf+CbHJB2JuhPycfJSAI dgEdQrn5Y5Ye7CJtazADaIIGFlPBbEYM/TVaRMNtAfEojHef6DB/z4lscFSmzD111aw5 KyXv+aSO3goBmAAwFCFQVE3BUJEw5zW4JBJ9eqt3PbWlLxGcXmEMqAF52p9jBfn3yaMq ZR3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ypHs0unV1uLPNVeiupO27E/9Ckoy/gg3WAzZrNg27LE=; b=BYwdcaIcwDaqIqAm5OUCoTtt7dbKY4fs721Ff9pietdGpdk4+wEsuvyF4LiVqJoOeU t4ovGB3bcKXSYDZ7ItJU6FB8vdaOjNe6/Z9yHZBFQYsvzEjAy0BVx59CGISyN3svaFIe A9dixJNt+LdSNAtuZ+4uQg4bZo0KWdSPIiZrRmIreS15s/r1J8oFZNEJKAGlWhHnqrMe MNhXC3vocxJotnZSk3c5AfILpyVFn+IBSZcpK6VIHnPJHnHY/SAIeFqV5l1Cyy1E7k4Y pOZ2bLxVkaZGh4r6REfUuRIhC1RUAZf6FdsfcFTDH8AZAW8xaA05cgVyywxrWaFiGdpG QJXA== X-Gm-Message-State: ALyK8tKJSJ+1kB/LQiGsTRB2iJ3H3NFtmJXgvUP52sI9rAjHEVfhfFRc2HdlSdt2Ij4Zqg== X-Received: by 10.98.196.203 with SMTP id h72mr30968716pfk.54.1466558915031; Tue, 21 Jun 2016 18:28:35 -0700 (PDT) Received: from kernel.kingsoft.cn ([114.255.44.132]) by smtp.gmail.com with ESMTPSA id e14sm9861930pfb.89.2016.06.21.18.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jun 2016 18:28:34 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Linux PM list , linux-acpi@vger.kernel.org, lkp@01.org, x86@kernel.org Cc: Wanpeng Li , Len Brown , "Rafael J. Wysocki" , Zhang Rui , Chen Yu , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , jacob.jun.pan@intel.com, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Subject: [PATCH] x86: fix rdmsr MSR_PLATFORM_INFO unsafe warning in kvm guest Date: Wed, 22 Jun 2016 09:28:28 +0800 Message-Id: <1466558908-3524-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 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 From: Wanpeng Li ------------[ cut here ]------------ 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 Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.7.0-rc3+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 0000000000000000 ffffffff81c03ce0 ffffffff813b3eae ffffffff81c03d30 0000000000000000 ffffffff81c03d20 ffffffff81067181 0000003200000001 ffffffff81c03df8 ffffffff8179676c 0000000000000000 ffffffff81fcd2c0 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 After commit (fc141535ad8 : "x86 tsc_msr: Extend to include Intel Core Architecture"), rdmsr MSR_PLATFORM_INFO is used to get maximum non-turbo ratio for recent Intel Core Architecture which results in kvm guest rdmsr unsafe warning. 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. This patch fix it by using rdmsr_safe to read MSR_PLATFORM_INFO in kvm guest in order that #GP can be fixed up, then tsc will be calibrated by PIT, HPET etc. Reported-by: kernel test robot Cc: Len Brown Cc: "Rafael J. Wysocki" Cc: Zhang Rui Cc: Chen Yu Cc: Paolo Bonzini Cc: Radim Krčmář Cc: jacob.jun.pan@intel.com Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Signed-off-by: Wanpeng Li --- arch/x86/kernel/tsc_msr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 */