Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

arm: perf/kvm: Use GENMASK for ARMV8_PMU_PMCR_N

This is so that FIELD_GET and FIELD_PREP can be used and that the fields
are in a consistent format to arm64/tools/sysreg

Signed-off-by: James Clark <james.clark@arm.com>
Link: https://lore.kernel.org/r/20231211161331.1277825-3-james.clark@arm.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

James Clark and committed by
Will Deacon
62e1f212 9343c790

+8 -11
+3 -5
arch/arm64/kvm/pmu-emul.c
··· 267 267 268 268 u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu) 269 269 { 270 - u64 val = kvm_vcpu_read_pmcr(vcpu) >> ARMV8_PMU_PMCR_N_SHIFT; 270 + u64 val = FIELD_GET(ARMV8_PMU_PMCR_N, kvm_vcpu_read_pmcr(vcpu)); 271 271 272 - val &= ARMV8_PMU_PMCR_N_MASK; 273 272 if (val == 0) 274 273 return BIT(ARMV8_PMU_CYCLE_IDX); 275 274 else ··· 1135 1136 */ 1136 1137 u64 kvm_vcpu_read_pmcr(struct kvm_vcpu *vcpu) 1137 1138 { 1138 - u64 pmcr = __vcpu_sys_reg(vcpu, PMCR_EL0) & 1139 - ~(ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); 1139 + u64 pmcr = __vcpu_sys_reg(vcpu, PMCR_EL0); 1140 1140 1141 - return pmcr | ((u64)vcpu->kvm->arch.pmcr_n << ARMV8_PMU_PMCR_N_SHIFT); 1141 + return u64_replace_bits(pmcr, vcpu->kvm->arch.pmcr_n, ARMV8_PMU_PMCR_N); 1142 1142 }
+2 -2
arch/arm64/kvm/sys_regs.c
··· 877 877 u64 pmcr, val; 878 878 879 879 pmcr = kvm_vcpu_read_pmcr(vcpu); 880 - val = (pmcr >> ARMV8_PMU_PMCR_N_SHIFT) & ARMV8_PMU_PMCR_N_MASK; 880 + val = FIELD_GET(ARMV8_PMU_PMCR_N, pmcr); 881 881 if (idx >= val && idx != ARMV8_PMU_CYCLE_IDX) { 882 882 kvm_inject_undefined(vcpu); 883 883 return false; ··· 1143 1143 static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, 1144 1144 u64 val) 1145 1145 { 1146 - u8 new_n = (val >> ARMV8_PMU_PMCR_N_SHIFT) & ARMV8_PMU_PMCR_N_MASK; 1146 + u8 new_n = FIELD_GET(ARMV8_PMU_PMCR_N, val); 1147 1147 struct kvm *kvm = vcpu->kvm; 1148 1148 1149 1149 mutex_lock(&kvm->arch.config_lock);
+2 -2
drivers/perf/arm_pmuv3.c
··· 15 15 #include <clocksource/arm_arch_timer.h> 16 16 17 17 #include <linux/acpi.h> 18 + #include <linux/bitfield.h> 18 19 #include <linux/clocksource.h> 19 20 #include <linux/of.h> 20 21 #include <linux/perf/arm_pmu.h> ··· 1112 1111 probe->present = true; 1113 1112 1114 1113 /* Read the nb of CNTx counters supported from PMNC */ 1115 - cpu_pmu->num_events = (armv8pmu_pmcr_read() >> ARMV8_PMU_PMCR_N_SHIFT) 1116 - & ARMV8_PMU_PMCR_N_MASK; 1114 + cpu_pmu->num_events = FIELD_GET(ARMV8_PMU_PMCR_N, armv8pmu_pmcr_read()); 1117 1115 1118 1116 /* Add the CPU cycles counter */ 1119 1117 cpu_pmu->num_events += 1;
+1 -2
include/linux/perf/arm_pmuv3.h
··· 215 215 #define ARMV8_PMU_PMCR_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ 216 216 #define ARMV8_PMU_PMCR_LC (1 << 6) /* Overflow on 64 bit cycle counter */ 217 217 #define ARMV8_PMU_PMCR_LP (1 << 7) /* Long event counter enable */ 218 - #define ARMV8_PMU_PMCR_N_SHIFT 11 /* Number of counters supported */ 219 - #define ARMV8_PMU_PMCR_N_MASK 0x1f 218 + #define ARMV8_PMU_PMCR_N GENMASK(15, 11) /* Number of counters supported */ 220 219 #define ARMV8_PMU_PMCR_MASK 0xff /* Mask for writable bits */ 221 220 222 221 /*