From: Sean Christopherson <seanjc@google.com>
To: BillXiang <xiangwencheng@lanxincomputing.com>
Cc: "Xin Li (Intel)" <xin@zytor.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com
Subject: Re: [PATCH v1] KVM: VMX: Remove unnecessary parentheses
Date: Fri, 6 Mar 2026 08:24:54 -0800 [thread overview]
Message-ID: <aar_1pOk4t3_MX4p@google.com> (raw)
In-Reply-To: <1795684a-b453-440e-88bb-035993d9deab@lanxincomputing.com>
On Fri, Mar 06, 2026, BillXiang wrote:
> On 3/6/2026 7:54 AM, Xin Li (Intel) wrote:
> > From: Xin Li <xin@zytor.com>
> >
> > 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.
> > Signed-off-by: Xin Li <xin@zytor.com>
> > ---
> > arch/x86/kvm/vmx/capabilities.h | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h
> > index 4e371c93ae16..0dad9e7c4ff4 100644
> > --- a/arch/x86/kvm/vmx/capabilities.h
> > +++ b/arch/x86/kvm/vmx/capabilities.h
> > @@ -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;
> > }
>
> 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.
prev parent reply other threads:[~2026-03-06 16:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 23:54 [PATCH v1] KVM: VMX: Remove unnecessary parentheses Xin Li (Intel)
2026-03-06 6:17 ` BillXiang
2026-03-06 16:24 ` Sean Christopherson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aar_1pOk4t3_MX4p@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xiangwencheng@lanxincomputing.com \
--cc=xin@zytor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox