KVM: x86 emulator: check io permissions only once for string pio
authorGleb Natapov <gleb@redhat.com>
Mon, 2 Aug 2010 09:47:51 +0000 (12:47 +0300)
committerAvi Kivity <avi@redhat.com>
Sun, 24 Oct 2010 08:50:29 +0000 (10:50 +0200)
Do not recheck io permission on every iteration.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/include/asm/kvm_emulate.h
arch/x86/kvm/emulate.c
arch/x86/kvm/x86.c

index 0f901c16cf1c03ce969529b1759fcc070c809723..8762411fe9bb4621fee65e7e1a9d906eca8a8514 100644 (file)
@@ -224,6 +224,7 @@ struct x86_emulate_ctxt {
        int interruptibility;
 
        bool restart; /* restart string instruction after writeback */
+       bool perm_ok; /* do not check permissions if true */
 
        int exception; /* exception that happens during emulation or -1 */
        u32 error_code; /* error code for exception */
index 4d49514a919e568409aa88a660fa277a5a50eb2d..760e2b030e685a22149ca0e298d784bc89b7d742 100644 (file)
@@ -1621,9 +1621,15 @@ static bool emulator_io_permited(struct x86_emulate_ctxt *ctxt,
                                 struct x86_emulate_ops *ops,
                                 u16 port, u16 len)
 {
+       if (ctxt->perm_ok)
+               return true;
+
        if (emulator_bad_iopl(ctxt, ops))
                if (!emulator_io_port_access_allowed(ctxt, ops, port, len))
                        return false;
+
+       ctxt->perm_ok = true;
+
        return true;
 }
 
index 3cbe8032394a2bd8d4dcd97f07763ca96cbe68c6..35c0f4e4a621144a16053a833398c47c773cb333 100644 (file)
@@ -3997,6 +3997,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
                memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
                vcpu->arch.emulate_ctxt.interruptibility = 0;
                vcpu->arch.emulate_ctxt.exception = -1;
+               vcpu->arch.emulate_ctxt.perm_ok = false;
 
                r = x86_decode_insn(&vcpu->arch.emulate_ctxt);
                trace_kvm_emulate_insn_start(vcpu);