summaryrefslogtreecommitdiff
path: root/tools/lib/python
diff options
context:
space:
mode:
authorShengwen Cheng <shengwen1997.tw@gmail.com>2026-06-26 13:40:51 +0800
committerAnup Patel <anup@brainfault.org>2026-07-13 18:16:56 +0530
commit0cc15f2c7a55820bc0a1c7713222d1d7ee46cab4 (patch)
tree46b724f440ffe621b27d1742890ec54004f813bf /tools/lib/python
parentb8aa7571e943591c26512667da824988917d3b67 (diff)
KVM: riscv: PMU: Bound counter mask scan to BITS_PER_LONG
The PMU SBI handler passes the guest argument registers directly to the PMU start/stop helpers: kvm_riscv_vcpu_pmu_ctr_start(vcpu, cp->a0, cp->a1, cp->a2, ...) kvm_riscv_vcpu_pmu_ctr_stop(vcpu, cp->a0, cp->a1, cp->a2, ...) which map to: unsigned long ctr_base unsigned long ctr_mask unsigned long flags Thus cp->a1 is a single unsigned long ctr_mask, not a bitmap array sized for RISCV_MAX_COUNTERS. On RV32, RISCV_MAX_COUNTERS is 64 while BITS_PER_LONG is 32. Using for_each_set_bit() with RISCV_MAX_COUNTERS can therefore make find_next_bit() access bits beyond the storage of ctr_mask on RV32. Limit the scan to BITS_PER_LONG. The requested counter range is already validated by kvm_pmu_validate_counter_mask(), so this preserves RV64 behavior and avoids an out-of-bounds bitmap read on RV32. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Signed-off-by: Shengwen Cheng <shengwen1997.tw@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260626054051.3360865-1-shengwen1997.tw@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions