From patchwork Thu Jun 25 10:36:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 32353 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5PAXIg5008700 for ; Thu, 25 Jun 2009 10:33:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751654AbZFYKdK (ORCPT ); Thu, 25 Jun 2009 06:33:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1750731AbZFYKdJ (ORCPT ); Thu, 25 Jun 2009 06:33:09 -0400 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.15]:32724 "EHLO VA3EHSOBE006.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751212AbZFYKdI (ORCPT ); Thu, 25 Jun 2009 06:33:08 -0400 Received: from mail176-va3-R.bigfish.com (10.7.14.235) by VA3EHSOBE006.bigfish.com (10.7.40.26) with Microsoft SMTP Server id 8.1.340.0; Thu, 25 Jun 2009 10:33:10 +0000 Received: from mail176-va3 (localhost.localdomain [127.0.0.1]) by mail176-va3-R.bigfish.com (Postfix) with ESMTP id 452EDAD0220; Thu, 25 Jun 2009 10:33:10 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzzz32i17ch62h) X-Spam-TCS-SCL: 1:0 X-FB-SS: 5, Received: by mail176-va3 (MessageSwitch) id 1245925988720616_4097; Thu, 25 Jun 2009 10:33:08 +0000 (UCT) Received: from ausb3extmailp02.amd.com (ausb3extmailp02.amd.com [163.181.251.22]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail176-va3.bigfish.com (Postfix) with ESMTP id 96E338C0059; Thu, 25 Jun 2009 10:33:08 +0000 (UTC) Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n5PAX4Zg020200; Thu, 25 Jun 2009 05:33:07 -0500 X-WSS-ID: 0KLSIN0-01-3L0-01 Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 265EC1943D9; Thu, 25 Jun 2009 05:32:59 -0500 (CDT) Received: from sausexmb2.amd.com ([163.181.3.157]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 05:33:04 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 05:33:03 -0500 Received: from localhost.localdomain ([165.204.15.42]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Jun 2009 12:32:55 +0200 From: Andre Przywara To: avi@redhat.com CC: kvm@vger.kernel.org, aliguori@us.ibm.com, Andre Przywara Subject: [PATCH] introduce module parameter for ignoring unknown MSRs accesses Date: Thu, 25 Jun 2009 12:36:49 +0200 Message-ID: <1245926209-32280-1-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.1.3 In-Reply-To: <4A420D4E.4060005@redhat.com> References: <4A420D4E.4060005@redhat.com> X-OriginalArrivalTime: 25 Jun 2009 10:32:55.0034 (UTC) FILETIME=[4CD3D5A0:01C9F580] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KVM will inject a #GP into the guest if that tries to access unhandled MSRs. This will crash many guests. Although it would be the correct way to actually handle these MSRs, we introduce a runtime switchable module param called "ignore_msrs" (defaults to 0). If this is Y, unknown MSR reads will return 0, while MSR writes are simply dropped. In both cases we print a message to dmesg to inform the user about that. You can change the behaviour at any time by saying: # echo 1 > /sys/modules/kvm/parameters/ignore_msrs Signed-off-by: Andre Przywara --- arch/x86/kvm/x86.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5a66bb9..7d0a0bb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -83,6 +83,9 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, struct kvm_x86_ops *kvm_x86_ops; EXPORT_SYMBOL_GPL(kvm_x86_ops); +int ignore_msrs = 0; +module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR); + struct kvm_stats_debugfs_item debugfs_entries[] = { { "pf_fixed", VCPU_STAT(pf_fixed) }, { "pf_guest", VCPU_STAT(pf_guest) }, @@ -885,8 +888,15 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) "0x%x data 0x%llx\n", msr, data); break; default: - pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", msr, data); - return 1; + if (!ignore_msrs) { + pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", + msr, data); + return 1; + } else { + pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n", + msr, data); + break; + } } return 0; } @@ -1032,8 +1042,14 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) case MSR_IA32_MC0_CTL ... MSR_IA32_MC0_CTL + 4 * KVM_MAX_MCE_BANKS - 1: return get_msr_mce(vcpu, msr, pdata); default: - pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr); - return 1; + if (!ignore_msrs) { + pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr); + return 1; + } else { + pr_unimpl(vcpu, "ignored rdmsr: 0x%x\n", msr); + data = 0; + } + break; } *pdata = data; return 0;