Skip to content

Commit 3aff4cd

Browse files
atishp04palmer-dabbelt
authored andcommitted
drivers/perf: riscv: Do not allow invalid raw event config
The SBI specification allows only lower 48bits of hpmeventX to be configured via SBI PMU. Currently, the driver masks of the higher bits but doesn't return an error. This will lead to an additional SBI call for config matching which should return for an invalid event error in most of the cases. However, if a platform(i.e Rocket and sifive cores) implements a bitmap of all bits in the event encoding this will lead to an incorrect event being programmed leading to user confusion. Report the error to the user if higher bits are set during the event mapping itself to avoid the confusion and save an additional SBI call. Suggested-by: Samuel Holland <[email protected]> Signed-off-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 2c206cd commit 3aff4cd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/perf/riscv_pmu_sbi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,11 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
536536

537537
switch (config >> 62) {
538538
case 0:
539-
ret = RISCV_PMU_RAW_EVENT_IDX;
540-
*econfig = config & RISCV_PMU_RAW_EVENT_MASK;
539+
/* Return error any bits [48-63] is set as it is not allowed by the spec */
540+
if (!(config & ~RISCV_PMU_RAW_EVENT_MASK)) {
541+
*econfig = config & RISCV_PMU_RAW_EVENT_MASK;
542+
ret = RISCV_PMU_RAW_EVENT_IDX;
543+
}
541544
break;
542545
case 2:
543546
ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16);

0 commit comments

Comments
 (0)