From patchwork Thu Feb 25 17:15:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 82064 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1PHHKUL027015 for ; Thu, 25 Feb 2010 17:17:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933019Ab0BYRQW (ORCPT ); Thu, 25 Feb 2010 12:16:22 -0500 Received: from tx2ehsobe002.messaging.microsoft.com ([65.55.88.12]:9876 "EHLO TX2EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933008Ab0BYRQL (ORCPT ); Thu, 25 Feb 2010 12:16:11 -0500 Received: from mail176-tx2-R.bigfish.com (10.9.14.249) by TX2EHSOBE004.bigfish.com (10.9.40.24) with Microsoft SMTP Server id 8.1.340.0; Thu, 25 Feb 2010 17:16:10 +0000 Received: from mail176-tx2 (localhost [127.0.0.1]) by mail176-tx2-R.bigfish.com (Postfix) with ESMTP id 3EE991200593; Thu, 25 Feb 2010 17:16:10 +0000 (UTC) X-SpamScore: 0 X-BigFish: VPS0(zba6lz936eMab9bhzz1202hzzz32i6bh87h43h66h) X-Spam-TCS-SCL: 5:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail176-tx2 (localhost.localdomain [127.0.0.1]) by mail176-tx2 (MessageSwitch) id 1267118168850842_24597; Thu, 25 Feb 2010 17:16:08 +0000 (UTC) Received: from TX2EHSMHS039.bigfish.com (unknown [10.9.14.244]) by mail176-tx2.bigfish.com (Postfix) with ESMTP id C1A65FA004C; Thu, 25 Feb 2010 17:16:08 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by TX2EHSMHS039.bigfish.com (10.9.99.139) with Microsoft SMTP Server (TLS) id 14.0.482.39; Thu, 25 Feb 2010 17:16:06 +0000 Received: from ausb3twp01.amd.com ([163.181.250.37]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o1PHJ4D3013804; Thu, 25 Feb 2010 11:19:07 -0600 X-WSS-ID: 0KYEQMM-01-QHS-02 X-M-MSG: Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 279BD102857C; Thu, 25 Feb 2010 11:15:57 -0600 (CST) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Feb 2010 11:16:01 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Feb 2010 11:16:01 -0600 Received: from lemmy.osrc.amd.com ([165.204.15.93]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Feb 2010 18:15:52 +0100 Received: by lemmy.osrc.amd.com (Postfix, from userid 41430) id 39CEEC9B00; Thu, 25 Feb 2010 18:15:52 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: Alexander Graf , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH 3/5] KVM: SVM: Use svm_msrpm_offset in nested_svm_exit_handled_msr Date: Thu, 25 Feb 2010 18:15:47 +0100 Message-ID: <1267118149-15737-4-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.0 In-Reply-To: <1267118149-15737-1-git-send-email-joerg.roedel@amd.com> References: <1267118149-15737-1-git-send-email-joerg.roedel@amd.com> X-OriginalArrivalTime: 25 Feb 2010 17:15:52.0364 (UTC) FILETIME=[2ED85EC0:01CAB63E] MIME-Version: 1.0 X-Reverse-DNS: unknown Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 25 Feb 2010 17:17:21 +0000 (UTC) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index d15e0ea..bb75a44 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1605,40 +1605,24 @@ static void nested_svm_unmap(struct page *page) static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) { - u32 param = svm->vmcb->control.exit_info_1 & 1; - u32 msr = svm->vcpu.arch.regs[VCPU_REGS_RCX]; - bool ret = false; - u32 t0, t1; - u8 val; + u32 offset, msr, value; + int write, mask; - if (!(svm->nested.intercept & (1ULL << INTERCEPT_MSR_PROT))) - return false; + msr = svm->vcpu.arch.regs[VCPU_REGS_RCX]; + offset = svm_msrpm_offset(msr); + write = svm->vmcb->control.exit_info_1 & 1; + mask = 1 << ((2 * (msr & 0xf)) + write); - switch (msr) { - case 0 ... 0x1fff: - t0 = (msr * 2) % 8; - t1 = msr / 8; - break; - case 0xc0000000 ... 0xc0001fff: - t0 = (8192 + msr - 0xc0000000) * 2; - t1 = (t0 / 8); - t0 %= 8; - break; - case 0xc0010000 ... 0xc0011fff: - t0 = (16384 + msr - 0xc0010000) * 2; - t1 = (t0 / 8); - t0 %= 8; - break; - default: - ret = true; - goto out; - } + if (offset == MSR_INVALID) + return NESTED_EXIT_DONE; - if (!kvm_read_guest(svm->vcpu.kvm, svm->nested.vmcb_msrpm + t1, &val, 1)) - ret = val & ((1 << param) << t0); + /* Offset is in 32 bit units but need in 8 bit units */ + offset = svm->nested.vmcb_msrpm + (offset * 4); -out: - return ret; + if (kvm_read_guest(svm->vcpu.kvm, offset, &value, 4)) + return NESTED_EXIT_DONE; + + return (value & mask) ? NESTED_EXIT_DONE : NESTED_EXIT_HOST; } static int nested_svm_exit_special(struct vcpu_svm *svm)