Skip to contentSkip to conversation

KVM: VMX: Remove unnecessary parentheses

PATCH Superseded Xin Li (Intel) 3 participants 3 messages Mar 6

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: VMX: Remove unnecessary parentheses

From: Xin Li <[email protected]>

Drop redundant parentheses; & takes precedence over &&.

---
 arch/x86/kvm/vmx/capabilities.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/capabilities.h +5 -5
index 4e371c93ae16..0dad9e7c4ff4 100644
@@ -107,7 +107,7 @@ static inline bool cpu_has_load_perf_global_ctrl(void)
 
 static inline bool cpu_has_load_cet_ctrl(void)
 {
-	return (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE);
+	return vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE;
 }
 
 static inline bool cpu_has_save_perf_global_ctrl(void)
@@ -162,7 +162,7 @@ static inline bool cpu_has_vmx_ept(void)
 static inline bool vmx_umip_emulated(void)
 {
 	return !boot_cpu_has(X86_FEATURE_UMIP) &&
-	       (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC);
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC;
 }
 
 static inline bool cpu_has_vmx_rdtscp(void)
@@ -376,9 +376,9 @@ static inline bool cpu_has_vmx_invvpid_global(void)
 
 static inline bool cpu_has_vmx_intel_pt(void)
 {
-	return (vmcs_config.misc & VMX_MISC_INTEL_PT) &&
-		(vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA) &&
-		(vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL);
+	return vmcs_config.misc & VMX_MISC_INTEL_PT &&
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA &&
+	       vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL;
 }
 
 /*

base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9

Signature · 1 line
2.53.0
#1 lore raw
Quoted 3 lines · Xin Li (Intel)

From: Xin Li <[email protected]>

Drop redundant parentheses; & takes precedence over &&.

I would not recommend relying on default operator precedence.

Quoted 29 lines
---
  arch/x86/kvm/vmx/capabilities.h | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/capabilities.h +2 -2
index 4e371c93ae16..0dad9e7c4ff4 100644
@@ -107,7 +107,7 @@ static inline bool cpu_has_load_perf_global_ctrl(void)
 
  static inline bool cpu_has_load_cet_ctrl(void)
  {
-	return (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE);
+	return vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE;
  }
 
  static inline bool cpu_has_save_perf_global_ctrl(void)
@@ -162,7 +162,7 @@ static inline bool cpu_has_vmx_ept(void)
  static inline bool vmx_umip_emulated(void)
  {
  	return !boot_cpu_has(X86_FEATURE_UMIP) &&
-	       (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC);
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC;
  }
 
  static inline bool cpu_has_vmx_rdtscp(void)

arch/x86/kvm/vmx/capabilities.h static inline bool cpu_has_vmx_invvpid_global(void) · line 382

Quoted 10 lines
arch/x86/kvm/vmx/capabilities.h +3 -3
@@ -376,9 +376,9 @@ static inline bool cpu_has_vmx_invvpid_global(void)
 
  static inline bool cpu_has_vmx_intel_pt(void)
  {
-	return (vmcs_config.misc & VMX_MISC_INTEL_PT) &&
-		(vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA) &&
-		(vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL);
+	return vmcs_config.misc & VMX_MISC_INTEL_PT &&
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA &&
+	       vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL;
  }

Removing the parentheses could significantly reduce code readability here.

Quoted 4 lines
arch/x86/kvm/vmx/capabilities.h +0 -0
  /*
 

base-commit: 5128b972fb2801ad9aca54d990a75611ab5283a9

#2 lore raw
Quoted 6 lines · BillXiang
Quoted 3 lines · Xin Li (Intel)

From: Xin Li <[email protected]>

Drop redundant parentheses; & takes precedence over &&.

I would not recommend relying on default operator precedence.

Eh, in practice, the kernel heavily relies on operator precedence all over the place, so I'm not worried about correctness. But as you note below, judicious use of parentheses can help readability.

Quoted 29 lines
Quoted 29 lines
---
  arch/x86/kvm/vmx/capabilities.h | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kvm/vmx/capabilities.h +2 -2
index 4e371c93ae16..0dad9e7c4ff4 100644
@@ -107,7 +107,7 @@ static inline bool cpu_has_load_perf_global_ctrl(void)
 
  static inline bool cpu_has_load_cet_ctrl(void)
  {
-	return (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE);
+	return vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE;
  }
 
  static inline bool cpu_has_save_perf_global_ctrl(void)
@@ -162,7 +162,7 @@ static inline bool cpu_has_vmx_ept(void)
  static inline bool vmx_umip_emulated(void)
  {
  	return !boot_cpu_has(X86_FEATURE_UMIP) &&
-	       (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC);
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_DESC;
  }
 
  static inline bool cpu_has_vmx_rdtscp(void)
@@ -376,9 +376,9 @@ static inline bool cpu_has_vmx_invvpid_global(void)
 
Quoted 11 lines

arch/x86/kvm/vmx/capabilities.h static inline bool cpu_has_vmx_invvpid_global(void) · line 382

Quoted 9 lines
arch/x86/kvm/vmx/capabilities.h +3 -3
  static inline bool cpu_has_vmx_intel_pt(void)
  {
-	return (vmcs_config.misc & VMX_MISC_INTEL_PT) &&
-		(vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA) &&
-		(vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL);
+	return vmcs_config.misc & VMX_MISC_INTEL_PT &&
+	       vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA &&
+	       vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL;
  }

Removing the parentheses could significantly reduce code readability here.

+1.

For cases like cpu_has_load_cet_ctrl() where it's a single statement, I'm 100% in favor of dropping the parentheses because they're pure noise. E.g. putting them in the return statement is kinda like doing this:

if ((vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_CET_STATE))

But for code where there are multiple checks, IMO it's totally fine to use parentheses, and probably even encourage.

Can you send a v2 to just clean up cpu_has_load_cet_ctrl()? Ah, and the changelog will need to be different, because there's no &&, which is another argument for treating "return x & y;" differently.