diff options
author | Avi Kivity <avi@redhat.com> | 2011-04-27 13:20:30 +0300 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-05-22 08:47:39 -0400 |
commit | 1aa366163b8b69f660cf94fd5062fa44859e4318 (patch) | |
tree | 29d6843cbe1c66a04c11dad24169ec5e1318e53d /arch/x86/kvm/x86.c | |
parent | 0a434bb2bf094f463ca3ca71ac42cea9e423048f (diff) | |
download | op-kernel-dev-1aa366163b8b69f660cf94fd5062fa44859e4318.zip op-kernel-dev-1aa366163b8b69f660cf94fd5062fa44859e4318.tar.gz |
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.
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 22bc69c..77c9d86 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4304,13 +4304,14 @@ static unsigned long emulator_get_cached_segment_base( return get_segment_base(emul_to_vcpu(ctxt), seg); } -static bool emulator_get_cached_descriptor(struct x86_emulate_ctxt *ctxt, - struct desc_struct *desc, u32 *base3, - int seg) +static bool emulator_get_segment(struct x86_emulate_ctxt *ctxt, u16 *selector, + struct desc_struct *desc, u32 *base3, + int seg) { struct kvm_segment var; kvm_get_segment(emul_to_vcpu(ctxt), &var, seg); + *selector = var.selector; if (var.unusable) return false; @@ -4335,16 +4336,14 @@ static bool emulator_get_cached_descriptor(struct x86_emulate_ctxt *ctxt, return true; } -static void emulator_set_cached_descriptor(struct x86_emulate_ctxt *ctxt, - struct desc_struct *desc, u32 base3, - int seg) +static void emulator_set_segment(struct x86_emulate_ctxt *ctxt, u16 selector, + struct desc_struct *desc, u32 base3, + int seg) { struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); struct kvm_segment var; - /* needed to preserve selector */ - kvm_get_segment(vcpu, &var, seg); - + var.selector = selector; var.base = get_desc_base(desc); #ifdef CONFIG_X86_64 var.base |= ((u64)base3) << 32; @@ -4368,24 +4367,6 @@ static void emulator_set_cached_descriptor(struct x86_emulate_ctxt *ctxt, return; } -static u16 emulator_get_segment_selector(struct x86_emulate_ctxt *ctxt, int seg) -{ - struct kvm_segment kvm_seg; - - kvm_get_segment(emul_to_vcpu(ctxt), &kvm_seg, seg); - return kvm_seg.selector; -} - -static void emulator_set_segment_selector(struct x86_emulate_ctxt *ctxt, - u16 sel, int seg) -{ - struct kvm_segment kvm_seg; - - kvm_get_segment(emul_to_vcpu(ctxt), &kvm_seg, seg); - kvm_seg.selector = sel; - kvm_set_segment(emul_to_vcpu(ctxt), &kvm_seg, seg); -} - static int emulator_get_msr(struct x86_emulate_ctxt *ctxt, u32 msr_index, u64 *pdata) { @@ -4436,10 +4417,8 @@ static struct x86_emulate_ops emulate_ops = { .invlpg = emulator_invlpg, .pio_in_emulated = emulator_pio_in_emulated, .pio_out_emulated = emulator_pio_out_emulated, - .get_cached_descriptor = emulator_get_cached_descriptor, - .set_cached_descriptor = emulator_set_cached_descriptor, - .get_segment_selector = emulator_get_segment_selector, - .set_segment_selector = emulator_set_segment_selector, + .get_segment = emulator_get_segment, + .set_segment = emulator_set_segment, .get_cached_segment_base = emulator_get_cached_segment_base, .get_gdt = emulator_get_gdt, .get_idt = emulator_get_idt, |