aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/kvm/pmu.h
diff options
context:
space:
mode:
authorGravatar Sean Christopherson <seanjc@google.com> 2023-11-09 18:28:52 -0800
committerGravatar Sean Christopherson <seanjc@google.com> 2024-02-01 09:35:48 -0800
commite5a65d4f723ab9997deab798c539e6bfd71f8440 (patch)
treec8ad383b1b4c18509af87f9aea4e66133a372067 /arch/x86/kvm/pmu.h
parentKVM: x86/pmu: Snapshot and clear reprogramming bitmap before reprogramming (diff)
downloadlinux-e5a65d4f723ab9997deab798c539e6bfd71f8440.tar.gz
linux-e5a65d4f723ab9997deab798c539e6bfd71f8440.tar.bz2
linux-e5a65d4f723ab9997deab798c539e6bfd71f8440.zip
KVM: x86/pmu: Add macros to iterate over all PMCs given a bitmap
Add and use kvm_for_each_pmc() to dedup a variety of open coded for-loops that iterate over valid PMCs given a bitmap (and because seeing checkpatch whine about bad macro style is always amusing). No functional change intended. Link: https://lore.kernel.org/r/20231110022857.1273836-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'arch/x86/kvm/pmu.h')
-rw-r--r--arch/x86/kvm/pmu.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
index 56e8e665e1af..fd18bc0b281c 100644
--- a/arch/x86/kvm/pmu.h
+++ b/arch/x86/kvm/pmu.h
@@ -83,6 +83,12 @@ static inline struct kvm_pmc *kvm_pmc_idx_to_pmc(struct kvm_pmu *pmu, int idx)
return NULL;
}
+#define kvm_for_each_pmc(pmu, pmc, i, bitmap) \
+ for_each_set_bit(i, bitmap, X86_PMC_IDX_MAX) \
+ if (!(pmc = kvm_pmc_idx_to_pmc(pmu, i))) \
+ continue; \
+ else \
+
static inline u64 pmc_bitmask(struct kvm_pmc *pmc)
{
struct kvm_pmu *pmu = pmc_to_pmu(pmc);