Skip to contentSkip to conversation

Segment cleanups and optimizations

PATCH New Avi Kivity 1 participant 3 messages Apr 28, 2011

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Segment cleanups and optimizations

The first patch in this segment-themed patchset cleans up segment handling in the emulator; while the second patch undoes some of the performance hit taken by the emulator segment limit checks.

Avi Kivity (2):
KVM: x86 emulator: consolidate segment accessors
KVM: VMX: Cache vmcs segment fields

 arch/x86/include/asm/kvm_emulate.h |   13 +---
 arch/x86/include/asm/kvm_host.h    |    1 +
 arch/x86/kvm/emulate.c             |  122 ++++++++++++++++++++----------------
 arch/x86/kvm/vmx.c                 |  102 +++++++++++++++++++++++++++---
 arch/x86/kvm/x86.c                 |   41 +++---------
 5 files changed, 176 insertions(+), 103 deletions(-)
Signature · 1 line
1.7.4.3
author
#1 lore raw

PATCH 1/2 KVM: x86 emulator: consolidate segment accessors

Instead of separate accessors for the segment selector and cached descriptor, use one accessor for both. This simplifies the code somewhat.

---
 arch/x86/include/asm/kvm_emulate.h |   13 +---
 arch/x86/kvm/emulate.c             |  122 ++++++++++++++++++++----------------
 arch/x86/kvm/x86.c                 |   41 +++---------
 3 files changed, 83 insertions(+), 93 deletions(-)
arch/x86/include/asm/kvm_emulate.h +4 -9
index 28114f5..0049211 100644
@@ -164,15 +164,10 @@ struct x86_emulate_ops {
 				int size, unsigned short port, const void *val,
 				unsigned int count);
 
-	bool (*get_cached_descriptor)(struct x86_emulate_ctxt *ctxt,
-				      struct desc_struct *desc, u32 *base3,
-				      int seg);
-	void (*set_cached_descriptor)(struct x86_emulate_ctxt *ctxt,
-				      struct desc_struct *desc, u32 base3,
-				      int seg);
-	u16 (*get_segment_selector)(struct x86_emulate_ctxt *ctxt, int seg);
-	void (*set_segment_selector)(struct x86_emulate_ctxt *ctxt,
-				     u16 sel, int seg);
+	bool (*get_segment)(struct x86_emulate_ctxt *ctxt, u16 *selector,
+			    struct desc_struct *desc, u32 *base3, int seg);
+	void (*set_segment)(struct x86_emulate_ctxt *ctxt, u16 selector,
+			    struct desc_struct *desc, u32 base3, int seg);
 	unsigned long (*get_cached_segment_base)(struct x86_emulate_ctxt *ctxt,
 						 int seg);
 	void (*get_gdt)(struct x86_emulate_ctxt *ctxt, struct desc_ptr *dt);
arch/x86/kvm/emulate.c +69 -53

253 lines not on this page · raw message

arch/x86/kvm/x86.c +10 -31

73 lines not on this page · raw message

Signature · 1 line
1.7.4.3
author
#2 lore raw

PATCH 2/2 KVM: VMX: Cache vmcs segment fields

In reply to Avi Kivity

Since the emulator now checks segment limits and access rights, it generates a lot more accesses to the vmcs segment fields. Undo some of the performance hit by cacheing those fields in a read-only cache (the entire cache is invalidated on any write, or on guest exit).

---
 arch/x86/include/asm/kvm_host.h |    1 +
 arch/x86/kvm/vmx.c              |  102 +++++++++++++++++++++++++++++++++++----
 2 files changed, 93 insertions(+), 10 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
index afb0e69..d2ac8e2 100644
@@ -136,6 +136,7 @@ enum kvm_reg_ex {
 	VCPU_EXREG_CR3,
 	VCPU_EXREG_RFLAGS,
 	VCPU_EXREG_CPL,
+	VCPU_EXREG_SEGMENTS,
 };
 
 enum {
arch/x86/kvm/vmx.c +92 -10

209 lines not on this page · raw message

Signature · 1 line
1.7.4.3