linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path
@ 2020-01-22  3:21 linmiaohe
  2020-01-22  4:42 ` Sean Christopherson
  2020-01-22  4:43 ` [PATCH 02/01] KVM: x86: Use a typedef for fastop functions Sean Christopherson
  0 siblings, 2 replies; 6+ messages in thread
From: linmiaohe @ 2020-01-22  3:21 UTC (permalink / raw)
  To: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa
  Cc: linmiaohe, kvm, linux-kernel, x86

From: Miaohe Lin <linmiaohe@huawei.com>

It also helps eliminate some duplicated code.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/emulate.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c7a0da45f60a..0accce94f660 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -5683,11 +5683,9 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
 		if (ctxt->d & Fastop) {
 			void (*fop)(struct fastop *) = (void *)ctxt->execute;
 			rc = fastop(ctxt, fop);
-			if (rc != X86EMUL_CONTINUE)
-				goto done;
-			goto writeback;
+		} else {
+			rc = ctxt->execute(ctxt);
 		}
-		rc = ctxt->execute(ctxt);
 		if (rc != X86EMUL_CONTINUE)
 			goto done;
 		goto writeback;
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path
  2020-01-22  3:21 [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path linmiaohe
@ 2020-01-22  4:42 ` Sean Christopherson
  2020-01-22 14:24   ` Paolo Bonzini
  2020-01-22  4:43 ` [PATCH 02/01] KVM: x86: Use a typedef for fastop functions Sean Christopherson
  1 sibling, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2020-01-22  4:42 UTC (permalink / raw)
  To: linmiaohe
  Cc: pbonzini, rkrcmar, vkuznets, wanpengli, jmattson, joro, tglx,
	mingo, bp, hpa, kvm, linux-kernel, x86

On Wed, Jan 22, 2020 at 11:21:44AM +0800, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> It also helps eliminate some duplicated code.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

>  arch/x86/kvm/emulate.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index c7a0da45f60a..0accce94f660 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -5683,11 +5683,9 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
>  		if (ctxt->d & Fastop) {
>  			void (*fop)(struct fastop *) = (void *)ctxt->execute;

The brackets can also be removed with a bit more cleanup, e.g. using a
typedef to handling casting ctxt->execute.  I'll send a patch that can be
applied on top and/or squashed with this one.

>  			rc = fastop(ctxt, fop);
> -			if (rc != X86EMUL_CONTINUE)
> -				goto done;
> -			goto writeback;
> +		} else {
> +			rc = ctxt->execute(ctxt);
>  		}
> -		rc = ctxt->execute(ctxt);
>  		if (rc != X86EMUL_CONTINUE)
>  			goto done;
>  		goto writeback;
> -- 
> 2.19.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 02/01] KVM: x86: Use a typedef for fastop functions
  2020-01-22  3:21 [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path linmiaohe
  2020-01-22  4:42 ` Sean Christopherson
@ 2020-01-22  4:43 ` Sean Christopherson
  2020-01-22 14:25   ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2020-01-22  4:43 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, Miaohe Lin

Add a typedef to for the fastop function prototype to make the code more
readable.

No functional change intended.

Cc: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---

Applies on top of Miaohe's patch.  Feel free to squash this.

 arch/x86/kvm/emulate.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 0accce94f660..ddbc61984227 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -311,7 +311,9 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
 #define ON64(x)
 #endif
 
-static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *));
+typedef void (*fastop_t)(struct fastop *);
+
+static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
 
 #define __FOP_FUNC(name) \
 	".align " __stringify(FASTOP_SIZE) " \n\t" \
@@ -5502,7 +5504,7 @@ static void fetch_possible_mmx_operand(struct operand *op)
 		read_mmx_reg(&op->mm_val, op->addr.mm);
 }
 
-static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
+static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop)
 {
 	ulong flags = (ctxt->eflags & EFLAGS_MASK) | X86_EFLAGS_IF;
 
@@ -5680,12 +5682,10 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
 		ctxt->eflags &= ~X86_EFLAGS_RF;
 
 	if (ctxt->execute) {
-		if (ctxt->d & Fastop) {
-			void (*fop)(struct fastop *) = (void *)ctxt->execute;
-			rc = fastop(ctxt, fop);
-		} else {
+		if (ctxt->d & Fastop)
+			rc = fastop(ctxt, (fastop_t)ctxt->execute);
+		else
 			rc = ctxt->execute(ctxt);
-		}
 		if (rc != X86EMUL_CONTINUE)
 			goto done;
 		goto writeback;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path
  2020-01-22  4:42 ` Sean Christopherson
@ 2020-01-22 14:24   ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2020-01-22 14:24 UTC (permalink / raw)
  To: Sean Christopherson, linmiaohe
  Cc: rkrcmar, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
	hpa, kvm, linux-kernel, x86

On 22/01/20 05:42, Sean Christopherson wrote:
> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

Queued, thanks to both!

Paolo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/01] KVM: x86: Use a typedef for fastop functions
  2020-01-22  4:43 ` [PATCH 02/01] KVM: x86: Use a typedef for fastop functions Sean Christopherson
@ 2020-01-22 14:25   ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2020-01-22 14:25 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel, Miaohe Lin

On 22/01/20 05:43, Sean Christopherson wrote:
> Add a typedef to for the fastop function prototype to make the code more
> readable.
> 
> No functional change intended.
> 
> Cc: Miaohe Lin <linmiaohe@huawei.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
> 
> Applies on top of Miaohe's patch.  Feel free to squash this.
> 
>  arch/x86/kvm/emulate.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 0accce94f660..ddbc61984227 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -311,7 +311,9 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
>  #define ON64(x)
>  #endif
>  
> -static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *));
> +typedef void (*fastop_t)(struct fastop *);
> +
> +static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop);
>  
>  #define __FOP_FUNC(name) \
>  	".align " __stringify(FASTOP_SIZE) " \n\t" \
> @@ -5502,7 +5504,7 @@ static void fetch_possible_mmx_operand(struct operand *op)
>  		read_mmx_reg(&op->mm_val, op->addr.mm);
>  }
>  
> -static int fastop(struct x86_emulate_ctxt *ctxt, void (*fop)(struct fastop *))
> +static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop)
>  {
>  	ulong flags = (ctxt->eflags & EFLAGS_MASK) | X86_EFLAGS_IF;
>  
> @@ -5680,12 +5682,10 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
>  		ctxt->eflags &= ~X86_EFLAGS_RF;
>  
>  	if (ctxt->execute) {
> -		if (ctxt->d & Fastop) {
> -			void (*fop)(struct fastop *) = (void *)ctxt->execute;
> -			rc = fastop(ctxt, fop);
> -		} else {
> +		if (ctxt->d & Fastop)
> +			rc = fastop(ctxt, (fastop_t)ctxt->execute);
> +		else
>  			rc = ctxt->execute(ctxt);
> -		}
>  		if (rc != X86EMUL_CONTINUE)
>  			goto done;
>  		goto writeback;
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path
@ 2020-01-22  6:41 linmiaohe
  0 siblings, 0 replies; 6+ messages in thread
From: linmiaohe @ 2020-01-22  6:41 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: pbonzini, rkrcmar, vkuznets, wanpengli, jmattson, joro, tglx,
	mingo, bp, hpa, kvm, linux-kernel, x86

Hi:
Sean Christopherson <sean.j.christopherson@intel.com> wrote:
> On Wed, Jan 22, 2020 at 11:21:44AM +0800, linmiaohe wrote:
>> From: Miaohe Lin <linmiaohe@huawei.com>
>> 
>> It also helps eliminate some duplicated code.
>
> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>

Thanks for your review.

>
>>  		if (ctxt->d & Fastop) {
>>  			void (*fop)(struct fastop *) = (void *)ctxt->execute;
>
>The brackets can also be removed with a bit more cleanup, e.g. using a typedef to handling casting ctxt->execute.  I'll send a patch that can be applied on top and/or squashed with this one.

Thanks for doing this. :)

>
>>  			rc = fastop(ctxt, fop);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-22 14:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-22  3:21 [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path linmiaohe
2020-01-22  4:42 ` Sean Christopherson
2020-01-22 14:24   ` Paolo Bonzini
2020-01-22  4:43 ` [PATCH 02/01] KVM: x86: Use a typedef for fastop functions Sean Christopherson
2020-01-22 14:25   ` Paolo Bonzini
2020-01-22  6:41 [PATCH] KVM: X86: Add 'else' to unify fastop and execute call path linmiaohe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).