linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
@ 2020-02-18  3:39 linmiaohe
  2020-02-18  3:42 ` Joe Perches
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: linmiaohe @ 2020-02-18  3:39 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>

The second "/* fall through */" in rmode_exception() makes code harder to
read. Replace it with "return true" to indicate they are different cases
and also this improves the readability.

Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index a13368b2719c..c5bcbbada2db 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
 		if (vcpu->guest_debug &
 			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
 			return false;
-		/* fall through */
+		return true;
 	case DE_VECTOR:
 	case OF_VECTOR:
 	case BR_VECTOR:
-- 
2.19.1


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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
  2020-02-18  3:39 [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case linmiaohe
@ 2020-02-18  3:42 ` Joe Perches
  2020-02-18 16:25   ` Paolo Bonzini
  2020-02-18 12:25 ` Vitaly Kuznetsov
  2020-02-18 15:42 ` Sean Christopherson
  2 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2020-02-18  3:42 UTC (permalink / raw)
  To: linmiaohe, pbonzini, rkrcmar, sean.j.christopherson, vkuznets,
	wanpengli, jmattson, joro, tglx, mingo, bp, hpa
  Cc: kvm, linux-kernel, x86

On Tue, 2020-02-18 at 11:39 +0800, linmiaohe wrote:
> The second "/* fall through */" in rmode_exception() makes code harder to
> read. Replace it with "return true" to indicate they are different cases
> and also this improves the readability.
[]
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
[]
> @@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
>  		if (vcpu->guest_debug &
>  			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
>  			return false;
> -		/* fall through */
> +		return true;

perhaps
		return !(vcpu->guest_debug & (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));



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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
  2020-02-18  3:39 [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case linmiaohe
  2020-02-18  3:42 ` Joe Perches
@ 2020-02-18 12:25 ` Vitaly Kuznetsov
  2020-02-18 15:42 ` Sean Christopherson
  2 siblings, 0 replies; 7+ messages in thread
From: Vitaly Kuznetsov @ 2020-02-18 12:25 UTC (permalink / raw)
  To: linmiaohe
  Cc: kvm, linux-kernel, x86, pbonzini, rkrcmar, sean.j.christopherson,
	wanpengli, jmattson, joro, tglx, mingo, bp, hpa

linmiaohe <linmiaohe@huawei.com> writes:

> From: Miaohe Lin <linmiaohe@huawei.com>
>
> The second "/* fall through */" in rmode_exception() makes code harder to
> read. Replace it with "return true" to indicate they are different cases
> and also this improves the readability.
>
> Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  arch/x86/kvm/vmx/vmx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index a13368b2719c..c5bcbbada2db 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
>  		if (vcpu->guest_debug &
>  			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
>  			return false;
> -		/* fall through */
> +		return true;
>  	case DE_VECTOR:
>  	case OF_VECTOR:
>  	case BR_VECTOR:

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Thanks!

-- 
Vitaly


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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
  2020-02-18  3:39 [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case linmiaohe
  2020-02-18  3:42 ` Joe Perches
  2020-02-18 12:25 ` Vitaly Kuznetsov
@ 2020-02-18 15:42 ` Sean Christopherson
  2 siblings, 0 replies; 7+ messages in thread
From: Sean Christopherson @ 2020-02-18 15:42 UTC (permalink / raw)
  To: linmiaohe
  Cc: pbonzini, rkrcmar, vkuznets, wanpengli, jmattson, joro, tglx,
	mingo, bp, hpa, kvm, linux-kernel, x86

On Tue, Feb 18, 2020 at 11:39:28AM +0800, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> The second "/* fall through */" in rmode_exception() makes code harder to
> read. Replace it with "return true" to indicate they are different cases
> and also this improves the readability.
> 
> Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  arch/x86/kvm/vmx/vmx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index a13368b2719c..c5bcbbada2db 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
>  		if (vcpu->guest_debug &
>  			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
>  			return false;
> -		/* fall through */
> +		return true;

I prefer the current code, i.e. the fall through.  This code is already
burdened with a fall through, from #BP->#DB, and IMO the fall through makes
it more obvious that the vcpu->guest_debug checks are corner cases, while
everything else is handled by common logic.

>  	case DE_VECTOR:
>  	case OF_VECTOR:
>  	case BR_VECTOR:
> -- 
> 2.19.1
> 

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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
  2020-02-18  3:42 ` Joe Perches
@ 2020-02-18 16:25   ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2020-02-18 16:25 UTC (permalink / raw)
  To: Joe Perches, linmiaohe, rkrcmar, sean.j.christopherson, vkuznets,
	wanpengli, jmattson, joro, tglx, mingo, bp, hpa
  Cc: kvm, linux-kernel, x86

On 18/02/20 04:42, Joe Perches wrote:
> On Tue, 2020-02-18 at 11:39 +0800, linmiaohe wrote:
>> The second "/* fall through */" in rmode_exception() makes code harder to
>> read. Replace it with "return true" to indicate they are different cases
>> and also this improves the readability.
> []
>> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> []
>> @@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
>>  		if (vcpu->guest_debug &
>>  			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
>>  			return false;
>> -		/* fall through */
>> +		return true;
> 
> perhaps
> 		return !(vcpu->guest_debug & (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));

Nice, thanks Joe.

Paolo


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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
@ 2020-02-19  1:59 linmiaohe
  0 siblings, 0 replies; 7+ messages in thread
From: linmiaohe @ 2020-02-19  1:59 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: pbonzini, rkrcmar, vkuznets, wanpengli, jmattson, joro, tglx,
	mingo, bp, hpa, kvm, linux-kernel, x86

Sean Christopherson <sean.j.christopherson@intel.com> wrote:
>On Tue, Feb 18, 2020 at 11:39:28AM +0800, linmiaohe wrote:
>> From: Miaohe Lin <linmiaohe@huawei.com>
>> 
>> @@ -4495,7 +4495,7 @@ static bool rmode_exception(struct kvm_vcpu *vcpu, int vec)
>>  		if (vcpu->guest_debug &
>>  			(KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
>>  			return false;
>> -		/* fall through */
>> +		return true;
>
>I prefer the current code, i.e. the fall through.  This code is already burdened with a fall through, from #BP->#DB, and IMO the fall through makes it more obvious that the vcpu->guest_debug checks are corner cases, while everything else is handled by common logic.

Yeh, it looks better this way. But from a different perspective, "return turn" here indicates #BP and #DB need do vcpu->guest_debug checks, while others not.
Thanks. :)

>
>>  	case DE_VECTOR:
>>  	case OF_VECTOR:
>>  	case BR_VECTOR: 

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

* Re: [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case
@ 2020-02-19  1:40 linmiaohe
  0 siblings, 0 replies; 7+ messages in thread
From: linmiaohe @ 2020-02-19  1:40 UTC (permalink / raw)
  To: Joe Perches
  Cc: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa, kvm, linux-kernel, x86

Joe Perches <joe@perches.com> wrote:
>On Tue, 2020-02-18 at 11:39 +0800, linmiaohe wrote:
>> The second "/* fall through */" in rmode_exception() makes code harder 
>> to read. Replace it with "return true" to indicate they are different 
>> cases and also this improves the readability.
>
>perhaps
>		return !(vcpu->guest_debug & (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));
>

Will do. Thanks for your advice.


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

end of thread, other threads:[~2020-02-19  1:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18  3:39 [PATCH] KVM: VMX: replace "fall through" with "return true" to indicate different case linmiaohe
2020-02-18  3:42 ` Joe Perches
2020-02-18 16:25   ` Paolo Bonzini
2020-02-18 12:25 ` Vitaly Kuznetsov
2020-02-18 15:42 ` Sean Christopherson
2020-02-19  1:40 linmiaohe
2020-02-19  1:59 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).