From patchwork Fri Apr 1 14:10:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 681311 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 p31EAtRv021219 for ; Fri, 1 Apr 2011 14:10:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756908Ab1DAOKt (ORCPT ); Fri, 1 Apr 2011 10:10:49 -0400 Received: from va3ehsobe001.messaging.microsoft.com ([216.32.180.11]:52153 "EHLO VA3EHSOBE001.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756636Ab1DAOKl (ORCPT ); Fri, 1 Apr 2011 10:10:41 -0400 Received: from mail75-va3-R.bigfish.com (10.7.14.254) by VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id 14.1.225.8; Fri, 1 Apr 2011 14:10:38 +0000 Received: from mail75-va3 (localhost.localdomain [127.0.0.1]) by mail75-va3-R.bigfish.com (Postfix) with ESMTP id 366D7788617; Fri, 1 Apr 2011 14:10:38 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzbb2cKzz1202hzz8275bhz32i668h839h61h) 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 mail75-va3 (localhost.localdomain [127.0.0.1]) by mail75-va3 (MessageSwitch) id 13016670386111_328; Fri, 1 Apr 2011 14:10:38 +0000 (UTC) Received: from VA3EHSMHS026.bigfish.com (unknown [10.7.14.249]) by mail75-va3.bigfish.com (Postfix) with ESMTP id E3AB15D0052; Fri, 1 Apr 2011 14:10:37 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by VA3EHSMHS026.bigfish.com (10.7.99.36) with Microsoft SMTP Server id 14.1.225.22; Fri, 1 Apr 2011 14:10:35 +0000 X-WSS-ID: 0LIZ8PK-01-2N3-02 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 27A3D1028037; Fri, 1 Apr 2011 09:10:31 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.106.1; Fri, 1 Apr 2011 09:10:35 -0500 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; Fri, 1 Apr 2011 09:10:33 -0500 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; Fri, 1 Apr 2011 10:10:31 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 092DA49C59D; Fri, 1 Apr 2011 15:10:31 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id ED69BFF973; Fri, 1 Apr 2011 16:10:30 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , Joerg Roedel Subject: [PATCH 04/15] KVM: x86 emulator: Add check_perm callback Date: Fri, 1 Apr 2011 16:10:13 +0200 Message-ID: <1301667024-29420-5-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1301667024-29420-1-git-send-email-joerg.roedel@amd.com> References: <1301667024-29420-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.6 (demeter1.kernel.org [140.211.167.41]); Fri, 01 Apr 2011 14:10:55 +0000 (UTC) diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 366de63..a891051 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -216,6 +216,7 @@ struct decode_cache { u8 seg_override; unsigned int d; int (*execute)(struct x86_emulate_ctxt *ctxt); + int (*check_perm)(struct x86_emulate_ctxt *ctxt); unsigned long regs[NR_VCPU_REGS]; unsigned long eip; /* modrm */ diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index b05e50d..f87d7f8 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -108,6 +108,7 @@ struct opcode { struct opcode *group; struct group_dual *gdual; } u; + int (*check_perm)(struct x86_emulate_ctxt *ctxt); }; struct group_dual { @@ -2328,14 +2329,21 @@ static int em_mov(struct x86_emulate_ctxt *ctxt) #define D(_y) { .flags = (_y) } #define DI(_y, _i) { .flags = (_y), .intercept = x86_intercept_##_i } +#define DIP(_y, _i) { .flags = (_y), .intercept = x86_intercept_##_i, \ + .check_perm = em_check_perm_##_i } #define N D(0) #define G(_f, _g) { .flags = ((_f) | Group), .u.group = (_g) } #define GD(_f, _g) { .flags = ((_f) | Group | GroupDual), .u.gdual = (_g) } #define I(_f, _e) { .flags = (_f), .u.execute = (_e) } #define II(_f, _e, _i) \ { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i } +#define IIP(_f, _e, _i) \ + { .flags = (_f), .u.execute = (_e), .intercept = x86_intercept_##_i, \ + .check_perm = em_check_perm_##_i } #define D2bv(_f) D((_f) | ByteOp), D(_f) +#define D2bvI(_f, _i) DI((_f) | ByteOp, _i), DI((_f), _i) +#define D2bvIP(_f, _i) DIP((_f) | ByteOp, _i), DIP((_f), _i) #define I2bv(_f, _e) I((_f) | ByteOp, _e), I(_f, _e) #define D6ALU(_f) D2bv((_f) | DstMem | SrcReg | ModRM), \ @@ -2751,6 +2759,7 @@ done_prefixes: } c->execute = opcode.u.execute; + c->check_perm = opcode.check_perm; c->intercept = opcode.intercept; /* Unrecognised? */ @@ -2999,6 +3008,13 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) goto done; } + /* Do instruction specific permission checks */ + if (c->check_perm) { + rc = c->check_perm(ctxt); + if (rc != X86EMUL_CONTINUE) + goto done; + } + if (unlikely(ctxt->guest_mode) && c->intercept) { rc = ops->intercept(ctxt, c->intercept, X86_ICPT_POST_EXCEPT);