aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2010-04-28 12:15:29 -0400
committerAvi Kivity <avi@redhat.com>2010-08-01 03:35:31 -0400
commit5951c4423724759906b10a26aa6a8817c4afa615 (patch)
tree552b885e950cf61e841534cbefd0231f9ad0992d
parent3fb1b5dbd397d16a855c97c3fb80fe6e9196ce7c (diff)
KVM: x86 emulator: add get_cached_segment_base() callback to x86_emulate_ops
On VMX it is expensive to call get_cached_descriptor() just to get segment base since multiple vmcs_reads are done instead of only one. Introduce new call back get_cached_segment_base() for efficiency. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r--arch/x86/include/asm/kvm_emulate.h1
-rw-r--r--arch/x86/kvm/emulate.c13
-rw-r--r--arch/x86/kvm/x86.c7
3 files changed, 9 insertions, 12 deletions
diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h
index f751657be732..df53ba2294b6 100644
--- a/arch/x86/include/asm/kvm_emulate.h
+++ b/arch/x86/include/asm/kvm_emulate.h
@@ -132,6 +132,7 @@ struct x86_emulate_ops {
132 int seg, struct kvm_vcpu *vcpu); 132 int seg, struct kvm_vcpu *vcpu);
133 u16 (*get_segment_selector)(int seg, struct kvm_vcpu *vcpu); 133 u16 (*get_segment_selector)(int seg, struct kvm_vcpu *vcpu);
134 void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu); 134 void (*set_segment_selector)(u16 sel, int seg, struct kvm_vcpu *vcpu);
135 unsigned long (*get_cached_segment_base)(int seg, struct kvm_vcpu *vcpu);
135 void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu); 136 void (*get_gdt)(struct desc_ptr *dt, struct kvm_vcpu *vcpu);
136 ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu); 137 ulong (*get_cr)(int cr, struct kvm_vcpu *vcpu);
137 void (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu); 138 void (*set_cr)(int cr, ulong val, struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 7c8ed560fd41..8228778ace38 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2097,17 +2097,6 @@ static bool emulator_io_permited(struct x86_emulate_ctxt *ctxt,
2097 return true; 2097 return true;
2098} 2098}
2099 2099
2100static u32 get_cached_descriptor_base(struct x86_emulate_ctxt *ctxt,
2101 struct x86_emulate_ops *ops,
2102 int seg)
2103{
2104 struct desc_struct desc;
2105 if (ops->get_cached_descriptor(&desc, seg, ctxt->vcpu))
2106 return get_desc_base(&desc);
2107 else
2108 return ~0;
2109}
2110
2111static void save_state_to_tss16(struct x86_emulate_ctxt *ctxt, 2100static void save_state_to_tss16(struct x86_emulate_ctxt *ctxt,
2112 struct x86_emulate_ops *ops, 2101 struct x86_emulate_ops *ops,
2113 struct tss_segment_16 *tss) 2102 struct tss_segment_16 *tss)
@@ -2383,7 +2372,7 @@ static int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt,
2383 int ret; 2372 int ret;
2384 u16 old_tss_sel = ops->get_segment_selector(VCPU_SREG_TR, ctxt->vcpu); 2373 u16 old_tss_sel = ops->get_segment_selector(VCPU_SREG_TR, ctxt->vcpu);
2385 ulong old_tss_base = 2374 ulong old_tss_base =
2386 get_cached_descriptor_base(ctxt, ops, VCPU_SREG_TR); 2375 ops->get_cached_segment_base(VCPU_SREG_TR, ctxt->vcpu);
2387 u32 desc_limit; 2376 u32 desc_limit;
2388 2377
2389 /* FIXME: old_tss_base == ~0 ? */ 2378 /* FIXME: old_tss_base == ~0 ? */
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e3a5455049b0..9a469df6011c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3714,6 +3714,12 @@ static void emulator_get_gdt(struct desc_ptr *dt, struct kvm_vcpu *vcpu)
3714 kvm_x86_ops->get_gdt(vcpu, dt); 3714 kvm_x86_ops->get_gdt(vcpu, dt);
3715} 3715}
3716 3716
3717static unsigned long emulator_get_cached_segment_base(int seg,
3718 struct kvm_vcpu *vcpu)
3719{
3720 return get_segment_base(vcpu, seg);
3721}
3722
3717static bool emulator_get_cached_descriptor(struct desc_struct *desc, int seg, 3723static bool emulator_get_cached_descriptor(struct desc_struct *desc, int seg,
3718 struct kvm_vcpu *vcpu) 3724 struct kvm_vcpu *vcpu)
3719{ 3725{
@@ -3804,6 +3810,7 @@ static struct x86_emulate_ops emulate_ops = {
3804 .set_cached_descriptor = emulator_set_cached_descriptor, 3810 .set_cached_descriptor = emulator_set_cached_descriptor,
3805 .get_segment_selector = emulator_get_segment_selector, 3811 .get_segment_selector = emulator_get_segment_selector,
3806 .set_segment_selector = emulator_set_segment_selector, 3812 .set_segment_selector = emulator_set_segment_selector,
3813 .get_cached_segment_base = emulator_get_cached_segment_base,
3807 .get_gdt = emulator_get_gdt, 3814 .get_gdt = emulator_get_gdt,
3808 .get_cr = emulator_get_cr, 3815 .get_cr = emulator_get_cr,
3809 .set_cr = emulator_set_cr, 3816 .set_cr = emulator_set_cr,