From patchwork Wed Nov 24 18:18:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 353831 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 oAOIKJOl017532 for ; Wed, 24 Nov 2010 18:20:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756013Ab0KXSTw (ORCPT ); Wed, 24 Nov 2010 13:19:52 -0500 Received: from db3ehsobe003.messaging.microsoft.com ([213.199.154.141]:4546 "EHLO DB3EHSOBE003.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755997Ab0KXSTt (ORCPT ); Wed, 24 Nov 2010 13:19:49 -0500 Received: from mail2-db3-R.bigfish.com (10.3.81.250) by DB3EHSOBE003.bigfish.com (10.3.84.23) with Microsoft SMTP Server id 14.1.225.8; Wed, 24 Nov 2010 18:19:46 +0000 Received: from mail2-db3 (localhost.localdomain [127.0.0.1]) by mail2-db3-R.bigfish.com (Postfix) with ESMTP id 91C21450435; Wed, 24 Nov 2010 18:19:46 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzbb2cKzz1202hzz8275bhz32i691h668h67dh685h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI Received: from mail2-db3 (localhost.localdomain [127.0.0.1]) by mail2-db3 (MessageSwitch) id 1290622736919438_27330; Wed, 24 Nov 2010 18:18:56 +0000 (UTC) Received: from DB3EHSMHS005.bigfish.com (unknown [10.3.81.243]) by mail2-db3.bigfish.com (Postfix) with ESMTP id D2B77B0055; Wed, 24 Nov 2010 18:18:54 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by DB3EHSMHS005.bigfish.com (10.3.87.105) with Microsoft SMTP Server id 14.1.225.8; Wed, 24 Nov 2010 18:18:42 +0000 X-WSS-ID: 0LCEIV0-01-382-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 285B710288D0; Wed, 24 Nov 2010 12:18:35 -0600 (CST) Received: from sausexhtp02.amd.com (163.181.3.152) 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 storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) 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 storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Wed, 24 Nov 2010 13:18:39 -0500 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id ECA3A49C2BF; Wed, 24 Nov 2010 18:18:37 +0000 (GMT) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id F351EFFF1E; Wed, 24 Nov 2010 19:18:39 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , , Joerg Roedel Subject: [PATCH 8/9] KVM: SVM: Add checks for IO instructions Date: Wed, 24 Nov 2010 19:18:34 +0100 Message-ID: <1290622715-8382-9-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 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:20:32 +0000 (UTC) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 2a30b5b..a2c513d 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3668,6 +3668,47 @@ static void svm_check_group7(struct vmcb *vmcb, struct x86_emulate_ctxt *ctxt) } } +static void svm_check_ioio(struct vmcb *vmcb, struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c; + u32 bytes, seg; + u32 exit_info; + + c = &ctxt->decode; + /* Encode Port */ + exit_info = (c->regs[VCPU_REGS_RDX] & 0xffff) << 16; + seg = 0; + + /* Encode Address Size */ + exit_info |= (u32)c->ad_bytes << (SVM_IOIO_ASIZE_SHIFT - 1); + + if (c->rep_prefix) + exit_info |= SVM_IOIO_REP_MASK; + + if ((c->b & 0x06) == 0x06) { + /* OUT* Instruction */ + bytes = c->dst.bytes; + } else { + /* IN* Instruction */ + bytes = c->src.bytes; + exit_info |= SVM_IOIO_TYPE_MASK; + } + + /* Encode Data Size */ + bytes = min(bytes, 4u); + exit_info |= bytes << SVM_IOIO_SIZE_SHIFT; + + /* Check for the string variants */ + if ((c->b & 0xf0) == 0x60) { + exit_info |= SVM_IOIO_STR_MASK; + exit_info |= (seg & 0x07) << 10; + } + + vmcb->control.exit_info_1 = exit_info; + vmcb->control.exit_info_2 = ctxt->eip; + vmcb->control.exit_code = SVM_EXIT_IOIO; +} + static void svm_check_onebyte(struct vmcb *vmcb, struct x86_emulate_ctxt *ctxt) { struct decode_cache *c = &ctxt->decode; @@ -3685,6 +3726,20 @@ static void svm_check_onebyte(struct vmcb *vmcb, struct x86_emulate_ctxt *ctxt) case 0xcd: /* INTn */ vmcb->control.exit_code = SVM_EXIT_SWINT; break; + case 0x6c: /* INS */ + case 0x6d: + case 0xe4: /* IN */ + case 0xe5: + case 0xec: + case 0xed: + case 0x6e: /* OUTS */ + case 0x6f: + case 0xe6: /* OUT */ + case 0xe7: + case 0xee: + case 0xef: + svm_check_ioio(vmcb, ctxt); + break; case 0xcf: /* IRET */ vmcb->control.exit_code = SVM_EXIT_IRET; break;