From patchwork Wed Nov 24 18:18:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 353951 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAOIYcVg028690 for ; Wed, 24 Nov 2010 18:34:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753945Ab0KXSeE (ORCPT ); Wed, 24 Nov 2010 13:34:04 -0500 Received: from db3ehsobe002.messaging.microsoft.com ([213.199.154.140]:30675 "EHLO DB3EHSOBE002.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751339Ab0KXSeC (ORCPT ); Wed, 24 Nov 2010 13:34:02 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 24 Nov 2010 18:34:39 +0000 (UTC) X-Greylist: delayed 906 seconds by postgrey-1.27 at vger.kernel.org; Wed, 24 Nov 2010 13:34:02 EST Received: from mail62-db3-R.bigfish.com (10.3.81.243) by DB3EHSOBE002.bigfish.com (10.3.84.22) with Microsoft SMTP Server id 14.1.225.8; Wed, 24 Nov 2010 18:18:54 +0000 Received: from mail62-db3 (localhost.localdomain [127.0.0.1]) by mail62-db3-R.bigfish.com (Postfix) with ESMTP id 70E5D130824F; Wed, 24 Nov 2010 18:18:54 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzbb2cKzz1202hzz8275bhz32i691h668h67dh685h62h) X-Spam-TCS-SCL: 1:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI Received: from mail62-db3 (localhost.localdomain [127.0.0.1]) by mail62-db3 (MessageSwitch) id 1290622733963771_10030; Wed, 24 Nov 2010 18:18:53 +0000 (UTC) Received: from DB3EHSMHS006.bigfish.com (unknown [10.3.81.254]) by mail62-db3.bigfish.com (Postfix) with ESMTP id DE43710A804F; Wed, 24 Nov 2010 18:18:53 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by DB3EHSMHS006.bigfish.com (10.3.87.106) with Microsoft SMTP Server id 14.1.225.8; Wed, 24 Nov 2010 18:18:42 +0000 X-WSS-ID: 0LCEIUZ-01-37W-02 X-M-MSG: Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 26F7410288CF; Wed, 24 Nov 2010 12:18:35 -0600 (CST) Received: from sausexhtp01.amd.com (163.181.3.165) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.106.1; Wed, 24 Nov 2010 12:19:47 -0600 Received: from storexhtp02.amd.com (172.24.4.4) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 24 Nov 2010 12:18:39 -0600 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp02.amd.com (172.24.4.4) with Microsoft SMTP Server id 8.3.83.0; Wed, 24 Nov 2010 13:18:38 -0500 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 98F1A49C215; Wed, 24 Nov 2010 18:18:37 +0000 (GMT) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 95BB1FFF1E; Wed, 24 Nov 2010 19:18:39 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , , Joerg Roedel Subject: [PATCH 2/9] KVM: SVM: Add checks for CRx read and write intercepts Date: Wed, 24 Nov 2010 19:18:28 +0100 Message-ID: <1290622715-8382-3-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1290622715-8382-1-git-send-email-joerg.roedel@amd.com> References: <1290622715-8382-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index d1721c2..29f0491 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3622,7 +3622,78 @@ static void svm_fpu_deactivate(struct kvm_vcpu *vcpu) static int svm_insn_intercepted(struct kvm_vcpu *vcpu, struct x86_emulate_ctxt *ctxt) { - return X86EMUL_CONTINUE; + struct decode_cache *c = &ctxt->decode; + struct vcpu_svm *svm = to_svm(vcpu); + struct vmcb *vmcb = svm->vmcb; + int vmexit, ret; + + if (!is_nested(svm)) + return X86EMUL_CONTINUE; + + ret = X86EMUL_CONTINUE; + + if (!c->twobyte) + goto out; + + switch (c->b) { + case 0x01: + /* 0x0f 0x01 and modrm_mod == 3 encodes special instructions */ + if (c->modrm_mod == 3) + break; + + switch (c->modrm_reg) { + case 0x04: /* SMSW */ + vmcb->control.exit_code = SVM_EXIT_READ_CR0; + break; + case 0x06: { /* LMSW */ + u64 cr0, val; + + vmcb->control.exit_code = SVM_EXIT_WRITE_CR0; + + if (svm->nested.intercept_cr_write & INTERCEPT_CR0_MASK) + break; + + /* check for selective-cr0 special case */ + cr0 = vcpu->arch.cr0 & ~SVM_CR0_SELECTIVE_MASK & 0xf; + val = c->src.val & ~SVM_CR0_SELECTIVE_MASK & 0xf; + + if (cr0 ^ val) + vmcb->control.exit_code = SVM_EXIT_CR0_SEL_WRITE; + + break; + } + } + case 0x06: /* CLTS */ + vmcb->control.exit_code = SVM_EXIT_WRITE_CR0; + break; + case 0x20: /* CR read */ + vmcb->control.exit_code = SVM_EXIT_READ_CR0 + c->modrm_reg; + break; + case 0x22: /* CR write */ + vmcb->control.exit_code = SVM_EXIT_WRITE_CR0 + c->modrm_reg; + if (c->modrm_reg == 0 && + !(svm->nested.intercept_cr_write & INTERCEPT_CR0_MASK)) { + /* check for selective-cr0 special case */ + u64 cr0, val; + + cr0 = vcpu->arch.cr0 & ~SVM_CR0_SELECTIVE_MASK; + val = c->src.val & ~SVM_CR0_SELECTIVE_MASK; + + if (cr0 ^ val) + vmcb->control.exit_code = SVM_EXIT_CR0_SEL_WRITE; + } + break; + } + + vmcb->control.next_rip = ctxt->eip; + vmexit = nested_svm_exit_handled(svm); + + ret = (vmexit == NESTED_EXIT_DONE) ? X86EMUL_INTERCEPTED + : X86EMUL_CONTINUE; + +out: + + return ret; } static struct kvm_x86_ops svm_x86_ops = {