[PATCH v2 3/8] Fix x86_emulate_insn() to handle faults propagated from kvm_load_segment_descriptor()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We change the x86_emulate_insn() to handle faults propagated
from kvm_load_segment_descriptor().

Original code checks if the return value is negative or not.
But this means nothing because kvm_load_segment_descriptor()
never returns negative value. Instead of this, we use the
rc variable to hold the return value and if it is not
X86EMUL_CONTINUE goto done, not cannot_emulate.

Be sure that those codes following done label checks rc is
X86EMUL_UNHANDLEABLE or not, and if it is so do the same
thing as cannot_emulate: only the FAULT case will change.


Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@xxxxxxxxxxxxx>
---
 arch/x86/kvm/emulate.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 645b245..4527940 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1980,7 +1980,6 @@ special_insn:
 	case 0x8e: { /* mov seg, r/m16 */
 		uint16_t sel;
 		int type_bits;
-		int err;
 
 		sel = c->src.val;
 		if (c->modrm_reg == VCPU_SREG_SS)
@@ -1988,16 +1987,16 @@ special_insn:
 
 		if (c->modrm_reg <= 5) {
 			type_bits = (c->modrm_reg == 1) ? 9 : 1;
-			err = kvm_load_segment_descriptor(ctxt->vcpu, sel,
-							  type_bits, c->modrm_reg);
+			rc = kvm_load_segment_descriptor(ctxt->vcpu, sel,
+							 type_bits, c->modrm_reg);
 		} else {
 			printk(KERN_INFO "Invalid segreg in modrm byte 0x%02x\n",
 					c->modrm);
 			goto cannot_emulate;
 		}
 
-		if (err < 0)
-			goto cannot_emulate;
+		if (rc != X86EMUL_CONTINUE)
+			goto done;
 
 		c->dst.type = OP_NONE;  /* Disable writeback. */
 		break;
@@ -2168,11 +2167,10 @@ special_insn:
 	case 0xe9: /* jmp rel */
 		goto jmp;
 	case 0xea: /* jmp far */
-		if (kvm_load_segment_descriptor(ctxt->vcpu, c->src2.val, 9,
-					VCPU_SREG_CS) < 0) {
-			DPRINTF("jmp far: Failed to load CS descriptor\n");
-			goto cannot_emulate;
-		}
+		rc = kvm_load_segment_descriptor(ctxt->vcpu, c->src2.val, 9,
+						 VCPU_SREG_CS);
+		if (rc != X86EMUL_CONTINUE)
+			goto done;
 
 		c->eip = c->src.val;
 		break;
-- 
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux