Skip to contentSkip to conversation

Kill decode_cache

PATCH In review Avi Kivity 2 participants 5 messages Jun 1, 2011

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Kill decode_cache

This mostly mindless patchset folds decode_cache into its enclosing struct, x86_emulate_context. The point is to remove tons of pointless

       struct decode_cache *c = &ctxt->decode;

lines from the code, which contribute absolutely nothing.

Avi Kivity (2):
KVM: x86 emulator: rename decode_cache::eip to _eip
KVM: x86 emulator: fold decode_cache into x86_emulate_ctxt

 arch/x86/include/asm/kvm_emulate.h |   46 +-
 arch/x86/kvm/emulate.c             | 1275 +++++++++++++++++-------------------
 arch/x86/kvm/trace.h               |    8 +-
 arch/x86/kvm/x86.c                 |   47 +-
 4 files changed, 631 insertions(+), 745 deletions(-)
Signature · 1 line
1.7.5.3
author
#1 lore raw

PATCH 1/2 KVM: x86 emulator: rename decode_cache::eip to _eip

The name eip conflicts with a field of the same name in x86_emulate_ctxt, which we plan to fold decode_cache into.

The name _eip is unfortunate, but what's really needed is a refactoring here, not a better name.

---
 arch/x86/include/asm/kvm_emulate.h |    2 +-
 arch/x86/kvm/emulate.c             |  120 ++++++++++++++++++------------------
 arch/x86/kvm/trace.h               |    2 +-
 arch/x86/kvm/x86.c                 |    6 +-
 4 files changed, 65 insertions(+), 65 deletions(-)
arch/x86/include/asm/kvm_emulate.h +1 -1
index c0f77e0..d0e100f55 100644
@@ -253,7 +253,7 @@ struct decode_cache {
 	u8 modrm_rm;
 	u8 modrm_seg;
 	bool rip_relative;
-	unsigned long eip;
+	unsigned long _eip;
 	/* Fields above regs are cleared together. */
 	unsigned long regs[NR_VCPU_REGS];
 	struct fetch_cache fetch;
arch/x86/kvm/emulate.c +60 -60

391 lines not on this page · raw message

arch/x86/kvm/trace.h +1 -1
index db93276..d69e758 100644
@@ -677,7 +677,7 @@ TRACE_EVENT(kvm_emulate_insn,
 	TP_fast_assign(
 		__entry->rip = vcpu->arch.emulate_ctxt.decode.fetch.start;
 		__entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
-		__entry->len = vcpu->arch.emulate_ctxt.decode.eip
+		__entry->len = vcpu->arch.emulate_ctxt.decode._eip
 			       - vcpu->arch.emulate_ctxt.decode.fetch.start;
 		memcpy(__entry->insn,
 		       vcpu->arch.emulate_ctxt.decode.fetch.data,
arch/x86/kvm/x86.c +3 -3
index 39d8b04..7e452fe 100644
@@ -4560,13 +4560,13 @@ int kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip)
 
 	c->op_bytes = 2;
 	c->ad_bytes = 2;
-	c->eip = ctxt->eip + inc_eip;
+	c->_eip = ctxt->eip + inc_eip;
 	ret = emulate_int_real(ctxt, irq);
 
 	if (ret != X86EMUL_CONTINUE)
 		return EMULATE_FAIL;
 
-	ctxt->eip = c->eip;
+	ctxt->eip = c->_eip;
 	memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
 	kvm_rip_write(vcpu, ctxt->eip);
 	kvm_set_rflags(vcpu, ctxt->eflags);
@@ -4661,7 +4661,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
 	}
 
 	if (emulation_type & EMULTYPE_SKIP) {
-		kvm_rip_write(vcpu, c->eip);
+		kvm_rip_write(vcpu, c->_eip);
 		return EMULATE_DONE;
 	}
 
Signature · 1 line
1.7.5.3
author
#2 lore raw

PATCH 2/2 KVM: x86 emulator: fold decode_cache into x86_emulate_ctxt

In reply to Avi Kivity

This saves a lot of pointless casts x86_emulate_ctxt and decode_cache.

---
 arch/x86/include/asm/kvm_emulate.h |   44 +-
 arch/x86/kvm/emulate.c             | 1275 +++++++++++++++++-------------------
 arch/x86/kvm/trace.h               |    8 +-
 arch/x86/kvm/x86.c                 |   47 +-
 4 files changed, 630 insertions(+), 744 deletions(-)
arch/x86/include/asm/kvm_emulate.h +20 -24
index d0e100f55..6040d11 100644
@@ -229,7 +229,26 @@ struct read_cache {
 	unsigned long end;
 };
 
-struct decode_cache {
+struct x86_emulate_ctxt {
+	struct x86_emulate_ops *ops;
+
+	/* Register state before/after emulation. */
+	unsigned long eflags;
+	unsigned long eip; /* eip before instruction emulation */
+	/* Emulated execution mode, represented by an X86EMUL_MODE value. */
+	int mode;
+
+	/* interruptibility state, as a result of execution of STI or MOV SS */
+	int interruptibility;
+
+	bool guest_mode; /* guest running a nested guest */
+	bool perm_ok; /* do not check permissions if true */
+	bool only_vendor_specific_insn;
+
+	bool have_exception;
+	struct x86_exception exception;
+
+	/* decode cache */
 	u8 twobyte;
 	u8 b;
 	u8 intercept;
@@ -261,29 +280,6 @@ struct decode_cache {
 	struct read_cache mem_read;
 };
 
-struct x86_emulate_ctxt {
-	struct x86_emulate_ops *ops;
-
-	/* Register state before/after emulation. */
-	unsigned long eflags;
-	unsigned long eip; /* eip before instruction emulation */
-	/* Emulated execution mode, represented by an X86EMUL_MODE value. */
-	int mode;
-
-	/* interruptibility state, as a result of execution of STI or MOV SS */
-	int interruptibility;
-
-	bool guest_mode; /* guest running a nested guest */
-	bool perm_ok; /* do not check permissions if true */
-	bool only_vendor_specific_insn;
-
-	bool have_exception;
-	struct x86_exception exception;
-
-	/* decode cache */
-	struct decode_cache decode;
-};
-
 /* Repeat String Operation Prefix */
 #define REPE_PREFIX	0xf3
 #define REPNE_PREFIX	0xf2
arch/x86/kvm/emulate.c +584 -691

2,663 lines not on this page · raw message

arch/x86/kvm/trace.h +4 -4
index d69e758..624f8cb 100644
@@ -675,12 +675,12 @@ TRACE_EVENT(kvm_emulate_insn,
 		),
 
 	TP_fast_assign(
-		__entry->rip = vcpu->arch.emulate_ctxt.decode.fetch.start;
+		__entry->rip = vcpu->arch.emulate_ctxt.fetch.start;
 		__entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
-		__entry->len = vcpu->arch.emulate_ctxt.decode._eip
-			       - vcpu->arch.emulate_ctxt.decode.fetch.start;
+		__entry->len = vcpu->arch.emulate_ctxt._eip
+			       - vcpu->arch.emulate_ctxt.fetch.start;
 		memcpy(__entry->insn,
-		       vcpu->arch.emulate_ctxt.decode.fetch.data,
+		       vcpu->arch.emulate_ctxt.fetch.data,
 		       15);
 		__entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
 		__entry->failed = failed;
arch/x86/kvm/x86.c +22 -25

124 lines not on this page · raw message

Signature · 1 line
1.7.5.3
#3 lore raw
In reply to Avi Kivity
Quoted 7 lines · Avi Kivity

This mostly mindless patchset folds decode_cache into its enclosing struct, x86_emulate_context. The point is to remove tons of pointless

       struct decode_cache *c = &ctxt->decode;

lines from the code, which contribute absolutely nothing.

Didn't we plan some day to have a cache of decoded instructions to skip decoding stage? Not all the fields currently in decode_cache belong there of course (regs, io_read, mem_read).

Quoted 4 lines

Avi Kivity (2):
KVM: x86 emulator: rename decode_cache::eip to _eip
KVM: x86 emulator: fold decode_cache into x86_emulate_ctxt

Quoted 13 lines
 arch/x86/include/asm/kvm_emulate.h |   46 +-
 arch/x86/kvm/emulate.c             | 1275 +++++++++++++++++-------------------
 arch/x86/kvm/trace.h               |    8 +-
 arch/x86/kvm/x86.c                 |   47 +-
 4 files changed, 631 insertions(+), 745 deletions(-)
Signature · 6 lines
1.7.5.3

--
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

--
Gleb.

author
#4 lore raw
Quoted 4 lines · Gleb Natapov
Quoted 3 lines · Avi Kivity

This mostly mindless patchset folds decode_cache into its enclosing struct, x86_emulate_context. The point is to remove tons of pointless

Quoted 8 lines
Quoted 4 lines
        struct decode_cache *c =&ctxt->decode;

lines from the code, which contribute absolutely nothing.

Didn't we plan some day to have a cache of decoded instructions to skip decoding stage? Not all the fields currently in decode_cache belong there of course (regs, io_read, mem_read).

I remember something vaguely. But it will be a much smaller subset of decode_cache than what we have here.

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