[PATCH v5 06/13] KVM: x86/pmu: Do a single atomic OR when reprogramming counters

Yosry Ahmed
2026-04-30T20:28:03Z

Do a single atomic OR using the atomic overlay of reprogram_pmi bitmask,
instead of one atomic set_bit() call per counter.

Signed-off-by: Yosry Ahmed <yosry@kernel.org>
---
arch/x86/kvm/pmu.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index f8286067722b0..0e99022168a85 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -213,13 +213,10 @@ static inline void kvm_pmu_request_counter_reprogram(struct kvm_pmc *pmc)
static inline void kvm_pmu_request_counters_reprogram(struct kvm_pmu *pmu,
u64 counters)
{
- int bit;
-
if (!counters)
return;

- for_each_set_bit(bit, (unsigned long *)&counters, X86_PMC_IDX_MAX)
- set_bit(bit, pmu->reprogram_pmi);
+ atomic64_or(counters, &pmu->__reprogram_pmi);
kvm_make_request(KVM_REQ_PMU, pmu_to_vcpu(pmu));
}

--
2.54.0.545.g6539524ca2-goog