Skip to contentSkip to conversation

KVM: x86 emulator: check io permissions only once for string pio

PATCH Applied Gleb Natapov 2 participants 2 messages Aug 2, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: x86 emulator: check io permissions only once for string pio

Do not recheck io permission on every iteration.

---
v1->v2
- Rebased.

arch/x86/include/asm/kvm_emulate.h +1 -0
index f397b79..3c7dd29 100644
@@ -219,6 +219,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 */
arch/x86/kvm/emulate.c +6 -0
index dc1ecff..c3cdd5e 100644
@@ -1622,9 +1622,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;
 }
 
arch/x86/kvm/x86.c +1 -0
index c5878d8..e7e3b50 100644
@@ -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);

--
Gleb.

Applied
#1 lore raw
Quoted 3 lines · Gleb Natapov

Do not recheck io permission on every iteration.

Applied, thanks.

arch/x86/kvm/x86.c int emulate_instruction(struct kvm_vcpu *vcpu, · line 4001

Quoted 10 lines
arch/x86/kvm/x86.c +1 -0
index c5878d8..e7e3b50 100644
@@ -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;
 

This should be in x86_decode_init(), not outside the emulator. I'll convert it in my next series.

Signature · 1 line
error compiling committee.c: too many arguments to function