diff options
author | Nadav Amit <namit@cs.technion.ac.il> | 2014-11-02 04:54:55 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-07 09:44:08 -0500 |
commit | 5b7f6a1e6f6cb6537694a9bbd43bb4ee5a6d8bc2 (patch) | |
tree | b1e44f8e5eaa8c6fee7e82762c5012be6062c00a | |
parent | 38827dbd3fb85a94a002fcf67b8735d5bc1a7e1a (diff) |
KVM: x86: Combine the lgdt and lidt emulation logic
LGDT and LIDT emulation logic is almost identical. Merge the logic into a
single point to avoid redundancy. This will be used by the next patch that
will ensure the bases of the loaded GDTR and IDTR are canonical.
Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | arch/x86/kvm/emulate.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 9f960b428bb2..c86b3781fca2 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -3327,7 +3327,7 @@ static int em_sidt(struct x86_emulate_ctxt *ctxt) | |||
3327 | return emulate_store_desc_ptr(ctxt, ctxt->ops->get_idt); | 3327 | return emulate_store_desc_ptr(ctxt, ctxt->ops->get_idt); |
3328 | } | 3328 | } |
3329 | 3329 | ||
3330 | static int em_lgdt(struct x86_emulate_ctxt *ctxt) | 3330 | static int em_lgdt_lidt(struct x86_emulate_ctxt *ctxt, bool lgdt) |
3331 | { | 3331 | { |
3332 | struct desc_ptr desc_ptr; | 3332 | struct desc_ptr desc_ptr; |
3333 | int rc; | 3333 | int rc; |
@@ -3339,12 +3339,20 @@ static int em_lgdt(struct x86_emulate_ctxt *ctxt) | |||
3339 | ctxt->op_bytes); | 3339 | ctxt->op_bytes); |
3340 | if (rc != X86EMUL_CONTINUE) | 3340 | if (rc != X86EMUL_CONTINUE) |
3341 | return rc; | 3341 | return rc; |
3342 | ctxt->ops->set_gdt(ctxt, &desc_ptr); | 3342 | if (lgdt) |
3343 | ctxt->ops->set_gdt(ctxt, &desc_ptr); | ||
3344 | else | ||
3345 | ctxt->ops->set_idt(ctxt, &desc_ptr); | ||
3343 | /* Disable writeback. */ | 3346 | /* Disable writeback. */ |
3344 | ctxt->dst.type = OP_NONE; | 3347 | ctxt->dst.type = OP_NONE; |
3345 | return X86EMUL_CONTINUE; | 3348 | return X86EMUL_CONTINUE; |
3346 | } | 3349 | } |
3347 | 3350 | ||
3351 | static int em_lgdt(struct x86_emulate_ctxt *ctxt) | ||
3352 | { | ||
3353 | return em_lgdt_lidt(ctxt, true); | ||
3354 | } | ||
3355 | |||
3348 | static int em_vmmcall(struct x86_emulate_ctxt *ctxt) | 3356 | static int em_vmmcall(struct x86_emulate_ctxt *ctxt) |
3349 | { | 3357 | { |
3350 | int rc; | 3358 | int rc; |
@@ -3358,20 +3366,7 @@ static int em_vmmcall(struct x86_emulate_ctxt *ctxt) | |||
3358 | 3366 | ||
3359 | static int em_lidt(struct x86_emulate_ctxt *ctxt) | 3367 | static int em_lidt(struct x86_emulate_ctxt *ctxt) |
3360 | { | 3368 | { |
3361 | struct desc_ptr desc_ptr; | 3369 | return em_lgdt_lidt(ctxt, false); |
3362 | int rc; | ||
3363 | |||
3364 | if (ctxt->mode == X86EMUL_MODE_PROT64) | ||
3365 | ctxt->op_bytes = 8; | ||
3366 | rc = read_descriptor(ctxt, ctxt->src.addr.mem, | ||
3367 | &desc_ptr.size, &desc_ptr.address, | ||
3368 | ctxt->op_bytes); | ||
3369 | if (rc != X86EMUL_CONTINUE) | ||
3370 | return rc; | ||
3371 | ctxt->ops->set_idt(ctxt, &desc_ptr); | ||
3372 | /* Disable writeback. */ | ||
3373 | ctxt->dst.type = OP_NONE; | ||
3374 | return X86EMUL_CONTINUE; | ||
3375 | } | 3370 | } |
3376 | 3371 | ||
3377 | static int em_smsw(struct x86_emulate_ctxt *ctxt) | 3372 | static int em_smsw(struct x86_emulate_ctxt *ctxt) |