diff mbox series

[v2,03/11] KVM: x86: emulator: remove assign_eip_near/far

Message ID 20220621150902.46126-4-mlevitsk@redhat.com (mailing list archive)
State New, archived
Headers show
Series SMM emulation and interrupt shadow fixes | expand

Commit Message

Maxim Levitsky June 21, 2022, 3:08 p.m. UTC
Now the assign_eip_far just updates the emulation mode in addition to
updating the rip, it doesn't make sense to keep that function.

Move mode update to the callers and remove these functions.

No functional change is intended.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 arch/x86/kvm/emulate.c | 47 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

Comments

Sean Christopherson July 20, 2022, 11:51 p.m. UTC | #1
On Tue, Jun 21, 2022, Maxim Levitsky wrote:
> Now the assign_eip_far just updates the emulation mode in addition to
> updating the rip, it doesn't make sense to keep that function.
> 
> Move mode update to the callers and remove these functions.

I disagree, IMO there's a lot of value in differentiating between near and far.
Yeah, the assign_eip_near() wrapper is kinda silly, but have that instead of
a bare assign_eip() documents that e.g. jmp_rel() is a near jump and that it's
not missing an update.
Maxim Levitsky July 21, 2022, 11:52 a.m. UTC | #2
On Wed, 2022-07-20 at 23:51 +0000, Sean Christopherson wrote:
> On Tue, Jun 21, 2022, Maxim Levitsky wrote:
> > Now the assign_eip_far just updates the emulation mode in addition to
> > updating the rip, it doesn't make sense to keep that function.
> > 
> > Move mode update to the callers and remove these functions.
> 
> I disagree, IMO there's a lot of value in differentiating between near and far.
> Yeah, the assign_eip_near() wrapper is kinda silly, but have that instead of
> a bare assign_eip() documents that e.g. jmp_rel() is a near jump and that it's
> not missing an update.
> 


OK, I'll drop this patch then.

Best regards,
	Maxim Levitsky
diff mbox series

Patch

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 2c0087df2d7e6a..334a06e6c9b093 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -866,24 +866,9 @@  static inline int update_emulation_mode(struct x86_emulate_ctxt *ctxt)
 	return X86EMUL_CONTINUE;
 }
 
-static inline int assign_eip_near(struct x86_emulate_ctxt *ctxt, ulong dst)
-{
-	return assign_eip(ctxt, dst);
-}
-
-static int assign_eip_far(struct x86_emulate_ctxt *ctxt, ulong dst)
-{
-	int rc = update_emulation_mode(ctxt);
-
-	if (rc != X86EMUL_CONTINUE)
-		return rc;
-
-	return assign_eip(ctxt, dst);
-}
-
 static inline int jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)
 {
-	return assign_eip_near(ctxt, ctxt->_eip + rel);
+	return assign_eip(ctxt, ctxt->_eip + rel);
 }
 
 static int linear_read_system(struct x86_emulate_ctxt *ctxt, ulong linear,
@@ -2213,7 +2198,12 @@  static int em_jmp_far(struct x86_emulate_ctxt *ctxt)
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 
-	rc = assign_eip_far(ctxt, ctxt->src.val);
+	rc = update_emulation_mode(ctxt);
+	if (rc != X86EMUL_CONTINUE)
+		return rc;
+
+	rc = assign_eip(ctxt, ctxt->src.val);
+
 	/* Error handling is not implemented. */
 	if (rc != X86EMUL_CONTINUE)
 		return X86EMUL_UNHANDLEABLE;
@@ -2223,7 +2213,7 @@  static int em_jmp_far(struct x86_emulate_ctxt *ctxt)
 
 static int em_jmp_abs(struct x86_emulate_ctxt *ctxt)
 {
-	return assign_eip_near(ctxt, ctxt->src.val);
+	return assign_eip(ctxt, ctxt->src.val);
 }
 
 static int em_call_near_abs(struct x86_emulate_ctxt *ctxt)
@@ -2232,7 +2222,7 @@  static int em_call_near_abs(struct x86_emulate_ctxt *ctxt)
 	long int old_eip;
 
 	old_eip = ctxt->_eip;
-	rc = assign_eip_near(ctxt, ctxt->src.val);
+	rc = assign_eip(ctxt, ctxt->src.val);
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 	ctxt->src.val = old_eip;
@@ -2270,7 +2260,7 @@  static int em_ret(struct x86_emulate_ctxt *ctxt)
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 
-	return assign_eip_near(ctxt, eip);
+	return assign_eip(ctxt, eip);
 }
 
 static int em_ret_far(struct x86_emulate_ctxt *ctxt)
@@ -2291,7 +2281,13 @@  static int em_ret_far(struct x86_emulate_ctxt *ctxt)
 				       &new_desc);
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
-	rc = assign_eip_far(ctxt, eip);
+
+	rc = update_emulation_mode(ctxt);
+	if (rc != X86EMUL_CONTINUE)
+		return rc;
+
+	rc = assign_eip(ctxt, eip);
+
 	/* Error handling is not implemented. */
 	if (rc != X86EMUL_CONTINUE)
 		return X86EMUL_UNHANDLEABLE;
@@ -3511,7 +3507,12 @@  static int em_call_far(struct x86_emulate_ctxt *ctxt)
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 
-	rc = assign_eip_far(ctxt, ctxt->src.val);
+	rc = update_emulation_mode(ctxt);
+	if (rc != X86EMUL_CONTINUE)
+		return rc;
+
+	rc = assign_eip(ctxt, ctxt->src.val);
+
 	if (rc != X86EMUL_CONTINUE)
 		goto fail;
 
@@ -3544,7 +3545,7 @@  static int em_ret_near_imm(struct x86_emulate_ctxt *ctxt)
 	rc = emulate_pop(ctxt, &eip, ctxt->op_bytes);
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
-	rc = assign_eip_near(ctxt, eip);
+	rc = assign_eip(ctxt, eip);
 	if (rc != X86EMUL_CONTINUE)
 		return rc;
 	rsp_increment(ctxt, ctxt->src.val);