[PATCH 15/16] x86/cpu: Clean up use of LCAP_* constants

Andrew Cooper posted 16 patches 1 week, 4 days ago
[PATCH 15/16] x86/cpu: Clean up use of LCAP_* constants
Posted by Andrew Cooper 1 week, 4 days ago
Now that the LCAP_* constants are single bits, we can simplify the expressions
using them.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Julian Vetter <julian.vetter@vates.tech>
CC: Teddy Astie <teddy.astie@vates.tech>
---
 xen/arch/x86/cpu/amd.c | 12 ++++++------
 xen/arch/x86/domain.c  | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 06646fc1af93..f259a2112a16 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -171,7 +171,7 @@ void cf_check amd_ctxt_switch_masking(const struct vcpu *next)
 		(nextd && is_pv_domain(nextd) && nextd->arch.pv.cpuidmasks)
 		? nextd->arch.pv.cpuidmasks : &cpuidmask_defaults;
 
-	if ((levelling_caps & LCAP_1cd) == LCAP_1cd) {
+	if (levelling_caps & LCAP_1cd) {
 		uint64_t val = masks->_1cd;
 
 		/*
@@ -192,7 +192,7 @@ void cf_check amd_ctxt_switch_masking(const struct vcpu *next)
 #define LAZY(cap, msr, field)						\
 	({								\
 		if (unlikely(these_masks->field != masks->field) &&	\
-		    ((levelling_caps & cap) == cap))			\
+		    (levelling_caps & cap))				\
 		{							\
 			wrmsr_amd(msr, masks->field);			\
 			these_masks->field = masks->field;		\
@@ -251,7 +251,7 @@ static void __init amd_init_levelling(void)
 	 */
 	probe_masking_msrs();
 
-	if ((levelling_caps & LCAP_1cd) == LCAP_1cd) {
+	if (levelling_caps & LCAP_1cd) {
 		uint32_t ecx, edx, tmp;
 
 		cpuid(0x00000001, &tmp, &tmp, &ecx, &edx);
@@ -264,7 +264,7 @@ static void __init amd_init_levelling(void)
 		cpuidmask_defaults._1cd = ((uint64_t)ecx << 32) | edx;
 	}
 
-	if ((levelling_caps & LCAP_e1cd) == LCAP_e1cd) {
+	if (levelling_caps & LCAP_e1cd) {
 		uint32_t ecx, edx, tmp;
 
 		cpuid(0x80000001, &tmp, &tmp, &ecx, &edx);
@@ -275,7 +275,7 @@ static void __init amd_init_levelling(void)
 		cpuidmask_defaults.e1cd = ((uint64_t)ecx << 32) | edx;
 	}
 
-	if ((levelling_caps & LCAP_7ab0) == LCAP_7ab0) {
+	if (levelling_caps & LCAP_7ab0) {
 		uint32_t eax, ebx, tmp;
 
 		cpuid(0x00000007, &eax, &ebx, &tmp, &tmp);
@@ -283,7 +283,7 @@ static void __init amd_init_levelling(void)
 		cpuidmask_defaults._7ab0 &= ((uint64_t)eax << 32) | ebx;
 	}
 
-	if ((levelling_caps & LCAP_6c) == LCAP_6c) {
+	if (levelling_caps & LCAP_6c) {
 		uint32_t ecx = cpuid_ecx(6);
 
 		cpuidmask_defaults._6c &= (~0ULL << 32) | ecx;
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index c29a6b0decee..441f99e92088 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -303,7 +303,7 @@ void domain_cpu_policy_changed(struct domain *d)
 
     if ( is_pv_domain(d) )
     {
-        if ( ((levelling_caps & LCAP_1cd) == LCAP_1cd) )
+        if ( levelling_caps & LCAP_1cd )
         {
             uint64_t mask = cpuidmask_defaults._1cd;
             uint32_t ecx = p->basic._1c;
@@ -368,7 +368,7 @@ void domain_cpu_policy_changed(struct domain *d)
             d->arch.pv.cpuidmasks->_1cd = mask;
         }
 
-        if ( ((levelling_caps & LCAP_6c) == LCAP_6c) )
+        if ( levelling_caps & LCAP_6c )
         {
             uint64_t mask = cpuidmask_defaults._6c;
 
@@ -378,7 +378,7 @@ void domain_cpu_policy_changed(struct domain *d)
             d->arch.pv.cpuidmasks->_6c = mask;
         }
 
-        if ( ((levelling_caps & LCAP_7ab0) == LCAP_7ab0) )
+        if ( levelling_caps & LCAP_7ab0 )
         {
             uint64_t mask = cpuidmask_defaults._7ab0;
 
@@ -395,7 +395,7 @@ void domain_cpu_policy_changed(struct domain *d)
             d->arch.pv.cpuidmasks->_7ab0 = mask;
         }
 
-        if ( ((levelling_caps & LCAP_Da1) == LCAP_Da1) )
+        if ( levelling_caps & LCAP_Da1 )
         {
             uint64_t mask = cpuidmask_defaults.Da1;
             uint32_t eax = p->xstate.Da1;
@@ -406,7 +406,7 @@ void domain_cpu_policy_changed(struct domain *d)
             d->arch.pv.cpuidmasks->Da1 = mask;
         }
 
-        if ( ((levelling_caps & LCAP_e1cd) == LCAP_e1cd) )
+        if ( levelling_caps & LCAP_e1cd )
         {
             uint64_t mask = cpuidmask_defaults.e1cd;
             uint32_t ecx = p->extd.e1c;
-- 
2.39.5


Re: [PATCH 15/16] x86/cpu: Clean up use of LCAP_* constants
Posted by Jan Beulich 1 week, 3 days ago
On 26.01.2026 18:53, Andrew Cooper wrote:
> Now that the LCAP_* constants are single bits, we can simplify the expressions
> using them.
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

I was meaning to ask in reply to patch 08, but luckily this time I remembered
to peek ahead in the series.

Jan