Do not recheck io permission on every iteration.

Signed-off-by: Gleb Natapov <[email protected]>
---
 arch/x86/include/asm/kvm_emulate.h |    1 +
 arch/x86/kvm/emulate.c             |    6 ++++++
 arch/x86/kvm/x86.c                 |    1 +
 3 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/kvm_emulate.h 
b/arch/x86/include/asm/kvm_emulate.h
index 51cfd73..ded05cf 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -216,6 +216,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 */
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index b38bd8b..3996fb0 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2161,9 +2161,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;
 }
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7e5f075..de54582 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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, &emulate_ops);
                trace_kvm_emulate_insn_start(vcpu);
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to