Skip to contentSkip to conversation

KVM: VMX: replace "fall through" with "return true" to indicate different case

PATCH Superseded linmiaohe 5 participants 5 messages Feb 18, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

linmiaohe

author
#0 lore raw

PATCH 1/1 KVM: VMX: replace "fall through" with "return true" to indicate different case

From: Miaohe Lin <[email protected]>

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.

---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index a13368b2719c..c5bcbbada2db 100644
@@ -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:
Signature · 1 line
2.19.1
#1 lore raw
Quoted 3 lines · linmiaohe

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.

[]

arch/x86/kvm/vmx/vmx.c

Quoted 1 line
arch/x86/kvm/vmx/vmx.c +0 -0

[]

arch/x86/kvm/vmx/vmx.c static bool rmode_exception(struct kvm_vcpu *vcpu, int vec) · line 4498

Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -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));
maintainer
#2 lore raw
Quoted 15 lines · Joe Perches
Quoted 3 lines · linmiaohe

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.

[]

arch/x86/kvm/vmx/vmx.c

Quoted 1 line
arch/x86/kvm/vmx/vmx.c +0 -0

[]

arch/x86/kvm/vmx/vmx.c static bool rmode_exception(struct kvm_vcpu *vcpu, int vec) · line 4498

Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -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

Quoted 1 line
		return !(vcpu->guest_debug & (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP));

Nice, thanks Joe.

Paolo

Reviewed-by on v1 1/1
#3 lore raw
In reply to linmiaohe
Quoted 17 lines · linmiaohe

From: Miaohe Lin <[email protected]>

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.

---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +0 -0
index a13368b2719c..c5bcbbada2db 100644

arch/x86/kvm/vmx/vmx.c static bool rmode_exception(struct kvm_vcpu *vcpu, int vec) · line 4501

Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -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:

Thanks!

Signature · 1 line
Vitaly
#4 lore raw
In reply to linmiaohe
Quoted 17 lines · linmiaohe

From: Miaohe Lin <[email protected]>

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.

---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +0 -0
index a13368b2719c..c5bcbbada2db 100644

arch/x86/kvm/vmx/vmx.c static bool rmode_exception(struct kvm_vcpu *vcpu, int vec) · line 4498

Quoted 5 lines
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -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.

Quoted 6 lines
arch/x86/kvm/vmx/vmx.c +0 -0
 	case DE_VECTOR:
 	case OF_VECTOR:
 	case BR_VECTOR:
Signature · 1 line
2.19.1