Skip to contentSkip to conversation

KVM: x86 emulator: emulate RETF imm

PATCH Superseded Bruce Rogers 2 participants 6 messages Sep 3, 2013 – Sep 9, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86 emulator: emulate RETF imm

Opcode CA

This gets used by a DOS based NetWare guest.

---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +22 -1
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+
 static int em_cmpxchg(struct x86_emulate_ctxt *ctxt)
 {
 	/* Save real source value, then compare EAX against destination. */
@@ -3763,7 +3783,8 @@ static const struct opcode opcode_table[256] = {
 	G(ByteOp, group11), G(0, group11),
 	/* 0xC8 - 0xCF */
 	I(Stack | SrcImmU16 | Src2ImmByte, em_enter), I(Stack, em_leave),
-	N, I(ImplicitOps | Stack, em_ret_far),
+	I(ImplicitOps | Stack | SrcImmU16, em_ret_far_imm),
+	I(ImplicitOps | Stack, em_ret_far),
 	D(ImplicitOps), DI(SrcImmByte, intn),
 	D(ImplicitOps | No64), II(ImplicitOps, em_iret, iret),
 	/* 0xD0 - 0xD7 */
Signature · 1 line
1.7.7
#1 lore raw
Quoted 4 lines · Bruce Rogers

Opcode CA

This gets used by a DOS based NetWare guest.

Thanks. All emulator fixes should be accompanied by unit test[1]. Can you write one?

[1] https://git.kernel.org/cgit/virt/kvm/kvm-unit-tests.git/tree/x86/realmode.c

Quoted 48 lines
---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +22 -1
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+
 static int em_cmpxchg(struct x86_emulate_ctxt *ctxt)
 {
 	/* Save real source value, then compare EAX against destination. */
@@ -3763,7 +3783,8 @@ static const struct opcode opcode_table[256] = {
 	G(ByteOp, group11), G(0, group11),
 	/* 0xC8 - 0xCF */
 	I(Stack | SrcImmU16 | Src2ImmByte, em_enter), I(Stack, em_leave),
-	N, I(ImplicitOps | Stack, em_ret_far),
+	I(ImplicitOps | Stack | SrcImmU16, em_ret_far_imm),
+	I(ImplicitOps | Stack, em_ret_far),
 	D(ImplicitOps), DI(SrcImmByte, intn),
 	D(ImplicitOps | No64), II(ImplicitOps, em_iret, iret),
 	/* 0xD0 - 0xD7 */
Signature · 1 line
1.7.7

--
Gleb.

#2 lore raw
In reply to Bruce Rogers
Quoted 27 lines · Bruce Rogers

Opcode CA

This gets used by a DOS based NetWare guest.

---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +10 -0
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;

arch/x86/kvm/emulate.c static int em_ret_far(struct x86_emulate_ctxt *ctxt) · line 2047

Quoted 10 lines
arch/x86/kvm/emulate.c +10 -0
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+

Why not:

static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)

{
	int rc;
	rc = em_ret_far(struct x86_emulate_ctxt *ctxt);
	if (rc != X86EMUL_CONTINUE)
		return rc;
	rsp_increment(ctxt, ctxt->src.val);
	return X86EMUL_CONTINUE;
}

--
Gleb.

#4 lore raw
In reply to Bruce Rogers
Quoted 51 lines · Bruce Rogers
Quoted 51 lines
Quoted 1 line
Quoted 1 line · Gleb Natapov
Quoted 27 lines · Bruce Rogers

Opcode CA

This gets used by a DOS based NetWare guest.

---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +10 -0
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;

arch/x86/kvm/emulate.c static int em_ret_far(struct x86_emulate_ctxt *ctxt) · line 2047

Quoted 10 lines
arch/x86/kvm/emulate.c +10 -0
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+

Why not:

static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)

{
	int rc;
	rc = em_ret_far(struct x86_emulate_ctxt *ctxt);
	if (rc != X86EMUL_CONTINUE)
		return rc;
	rsp_increment(ctxt, ctxt->src.val);
	return X86EMUL_CONTINUE;
}
Quoted 5 lines
Quoted 2 lines

--
Gleb.

Yes, that does seem better. Ack.

Somebody still needs to write a proper patch :) Can you do it please?

--
Gleb.

#3 lore raw
In reply to Gleb Natapov
Quoted 51 lines
Quoted 1 line
Quoted 1 line · Gleb Natapov
Quoted 27 lines · Bruce Rogers

Opcode CA

This gets used by a DOS based NetWare guest.

---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +10 -0
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;

arch/x86/kvm/emulate.c static int em_ret_far(struct x86_emulate_ctxt *ctxt) · line 2047

Quoted 10 lines
arch/x86/kvm/emulate.c +10 -0
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+

Why not:

static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)

{
	int rc;
	rc = em_ret_far(struct x86_emulate_ctxt *ctxt);
	if (rc != X86EMUL_CONTINUE)
		return rc;
	rsp_increment(ctxt, ctxt->src.val);
	return X86EMUL_CONTINUE;
}
Quoted 2 lines

--
Gleb.

Yes, that does seem better. Ack.

Bruce

#5 lore raw
In reply to Gleb Natapov
Quoted 53 lines
Quoted 1 line
Quoted 1 line · Gleb Natapov
Quoted 51 lines · Bruce Rogers
Quoted 51 lines
Quoted 1 line
Quoted 1 line · Gleb Natapov
Quoted 27 lines · Bruce Rogers

Opcode CA

This gets used by a DOS based NetWare guest.

---
 arch/x86/kvm/emulate.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +10 -0
index 2bc1e81..aee238a 100644
@@ -2025,6 +2025,26 @@ static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 	return rc;
 }
 
+static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)
+{
+        int rc;
+        unsigned long cs;
+
+        rc = emulate_pop(ctxt, &ctxt->_eip, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        if (ctxt->op_bytes == 4)
+                ctxt->_eip = (u32)ctxt->_eip;

arch/x86/kvm/emulate.c static int em_ret_far(struct x86_emulate_ctxt *ctxt) · line 2047

Quoted 10 lines
arch/x86/kvm/emulate.c +10 -0
+        rc = emulate_pop(ctxt, &cs, ctxt->op_bytes);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rc = load_segment_descriptor(ctxt, (u16)cs, VCPU_SREG_CS);
+        if (rc != X86EMUL_CONTINUE)
+                return rc;
+        rsp_increment(ctxt, ctxt->src.val);
+        return X86EMUL_CONTINUE;
+}
+

Why not:

static int em_ret_far_imm(struct x86_emulate_ctxt *ctxt)

{
	int rc;
	rc = em_ret_far(struct x86_emulate_ctxt *ctxt);
	if (rc != X86EMUL_CONTINUE)
		return rc;
	rsp_increment(ctxt, ctxt->src.val);
	return X86EMUL_CONTINUE;
}
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

--
Gleb.

Yes, that does seem better. Ack.

Somebody still needs to write a proper patch :) Can you do it please?

Sure, will do.

Bruce