[PATCH 11/38] KVM: Add get_segment_base() arch accessor
From: Avi Kivity
Date: Mon Nov 27 2006 - 07:21:58 EST
This could have been implemented in terms of the existing get_segment(), but
that make unnecessary vmx accesses.
Signed-off-by: Avi Kivity <avi@xxxxxxxxxxxx>
Index: linux-2.6/drivers/kvm/kvm.h
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm.h
+++ linux-2.6/drivers/kvm/kvm.h
@@ -248,6 +248,7 @@ struct kvm_arch_ops {
struct kvm_debug_guest *dbg);
int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
+ u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
void (*get_segment)(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg);
void (*set_segment)(struct kvm_vcpu *vcpu,
Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -1776,12 +1776,19 @@ static int emulator_cmpxchg_emulated(uns
return emulator_write_emulated(addr, new, bytes, ctxt);
}
+static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
+{
+ return kvm_arch_ops->get_segment_base(vcpu, seg);
+}
+
static void report_emulation_failure(struct x86_emulate_ctxt *ctxt)
{
static int reported;
u8 opcodes[4];
unsigned long rip = vmcs_readl(GUEST_RIP);
- unsigned long rip_linear = rip + vmcs_readl(GUEST_CS_BASE);
+ unsigned long rip_linear;
+
+ rip_linear = rip + get_segment_base(ctxt->vcpu, VCPU_SREG_CS);
if (reported)
return;
@@ -1835,14 +1842,14 @@ static int emulate_instruction(struct kv
emulate_ctxt.es_base = 0;
emulate_ctxt.ss_base = 0;
} else {
- emulate_ctxt.cs_base = vmcs_readl(GUEST_CS_BASE);
- emulate_ctxt.ds_base = vmcs_readl(GUEST_DS_BASE);
- emulate_ctxt.es_base = vmcs_readl(GUEST_ES_BASE);
- emulate_ctxt.ss_base = vmcs_readl(GUEST_SS_BASE);
+ emulate_ctxt.cs_base = get_segment_base(vcpu, VCPU_SREG_CS);
+ emulate_ctxt.ds_base = get_segment_base(vcpu, VCPU_SREG_DS);
+ emulate_ctxt.es_base = get_segment_base(vcpu, VCPU_SREG_ES);
+ emulate_ctxt.ss_base = get_segment_base(vcpu, VCPU_SREG_SS);
}
- emulate_ctxt.gs_base = vmcs_readl(GUEST_GS_BASE);
- emulate_ctxt.fs_base = vmcs_readl(GUEST_FS_BASE);
+ emulate_ctxt.gs_base = get_segment_base(vcpu, VCPU_SREG_GS);
+ emulate_ctxt.fs_base = get_segment_base(vcpu, VCPU_SREG_FS);
vcpu->mmio_is_write = 0;
r = x86_emulate_memop(&emulate_ctxt, &emulate_ops);
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -309,6 +309,13 @@ static __exit void hardware_unsetup(void
free_kvm_area();
}
+static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
+{
+ struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
+
+ return vmcs_readl(sf->base);
+}
+
static void vmx_get_segment(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg)
{
@@ -367,6 +374,7 @@ static struct kvm_arch_ops vmx_arch_ops
.set_guest_debug = set_guest_debug,
.get_msr = vmx_get_msr,
.set_msr = vmx_set_msr,
+ .get_segment_base = vmx_get_segment_base,
.get_segment = vmx_get_segment,
.set_segment = vmx_set_segment,
};
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/