From patchwork Thu Feb 25 17:15:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 82066 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 o1PHHKUN027015 for ; Thu, 25 Feb 2010 17:17:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933044Ab0BYRQw (ORCPT ); Thu, 25 Feb 2010 12:16:52 -0500 Received: from va3ehsobe005.messaging.microsoft.com ([216.32.180.15]:37024 "EHLO VA3EHSOBE006.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932996Ab0BYRQI (ORCPT ); Thu, 25 Feb 2010 12:16:08 -0500 Received: from mail78-va3-R.bigfish.com (10.7.14.241) by VA3EHSOBE006.bigfish.com (10.7.40.26) with Microsoft SMTP Server id 8.1.240.5; Thu, 25 Feb 2010 17:16:06 +0000 Received: from mail78-va3 (localhost [127.0.0.1]) by mail78-va3-R.bigfish.com (Postfix) with ESMTP id 655DC1AC00B3; Thu, 25 Feb 2010 17:16:06 +0000 (UTC) X-SpamScore: -4 X-BigFish: VPS-4(zz936eMab9bhzz1202hzzz32i6bh87h43h61h) X-Spam-TCS-SCL: 0:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail78-va3 (localhost.localdomain [127.0.0.1]) by mail78-va3 (MessageSwitch) id 1267118165775470_20456; Thu, 25 Feb 2010 17:16:05 +0000 (UTC) Received: from VA3EHSMHS018.bigfish.com (unknown [10.7.14.245]) by mail78-va3.bigfish.com (Postfix) with ESMTP id 9E339140050; Thu, 25 Feb 2010 17:16:05 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by VA3EHSMHS018.bigfish.com (10.7.99.28) with Microsoft SMTP Server (TLS) id 14.0.482.39; Thu, 25 Feb 2010 17:16:03 +0000 Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o1PHJ02P013781; Thu, 25 Feb 2010 11:19:03 -0600 X-WSS-ID: 0KYEQMG-02-N9T-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2C51FFCC210; Thu, 25 Feb 2010 11:15:52 -0600 (CST) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 25 Feb 2010 11:15:57 -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:15:57 -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 3DD12C9B0B; 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 4/5] KVM: SVM: Add correct handling of nested iopm Date: Thu, 25 Feb 2010 18:15:48 +0100 Message-ID: <1267118149-15737-5-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.0396 (UTC) FILETIME=[2EDD40C0: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:22 +0000 (UTC) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index bb75a44..3859e2c 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -78,6 +78,7 @@ struct nested_state { /* gpa pointers to the real vectors */ u64 vmcb_msrpm; + u64 vmcb_iopm; /* A VMEXIT is required but not yet emulated */ bool exit_required; @@ -1603,6 +1604,26 @@ static void nested_svm_unmap(struct page *page) kvm_release_page_dirty(page); } +static int nested_svm_intercept_ioio(struct vcpu_svm *svm) +{ + unsigned port; + u8 val, bit; + u64 gpa; + + if (!(svm->nested.intercept & (1ULL << INTERCEPT_IOIO_PROT))) + return NESTED_EXIT_HOST; + + port = svm->vmcb->control.exit_info_1 >> 16; + gpa = svm->nested.vmcb_iopm + (port / 8); + bit = port % 8; + val = 0; + + if (kvm_read_guest(svm->vcpu.kvm, gpa, &val, 1)) + val &= (1 << bit); + + return val ? NESTED_EXIT_DONE : NESTED_EXIT_HOST; +} + static bool nested_svm_exit_handled_msr(struct vcpu_svm *svm) { u32 offset, msr, value; @@ -1665,6 +1686,9 @@ static int nested_svm_intercept(struct vcpu_svm *svm) case SVM_EXIT_MSR: vmexit = nested_svm_exit_handled_msr(svm); break; + case SVM_EXIT_IOIO: + vmexit = nested_svm_intercept_ioio(svm); + break; case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR8: { u32 cr_bits = 1 << (exit_code - SVM_EXIT_READ_CR0); if (svm->nested.intercept_cr_read & cr_bits) @@ -1989,6 +2013,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm) svm->vmcb->save.cpl = nested_vmcb->save.cpl; svm->nested.vmcb_msrpm = nested_vmcb->control.msrpm_base_pa; + svm->nested.vmcb_iopm = nested_vmcb->control.iopm_base_pa & ~0x0fffULL; /* cache intercepts */ svm->nested.intercept_cr_read = nested_vmcb->control.intercept_cr_read;