Skip to content

Commit 6f6ecce

Browse files
Merge patch series "SBI PMU event related fixes"
Atish Patra <atishp@rivosinc.com> says: Here are two minor improvement/fixes in the PMU event path. The first patch was part of the series[1]. The 2nd patch was suggested during the series review. While the series can only be merged once SBI v3.0 is frozen, these two patches can be independent of SBI v3.0 and can be merged sooner. Hence, these two patches are sent as a separate series. * b4-shazam-merge: drivers/perf: riscv: Do not allow invalid raw event config drivers/perf: riscv: Return error for default case drivers/perf: riscv: Fix Platform firmware event data Link: https://lore.kernel.org/r/20241212-pmu_event_fixes_v2-v2-0-813e8a4f5962@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents 89726fb + 3aff4cd commit 6f6ecce

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

arch/riscv/include/asm/sbi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct riscv_pmu_snapshot_data {
159159
};
160160

161161
#define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(47, 0)
162+
#define RISCV_PMU_PLAT_FW_EVENT_MASK GENMASK_ULL(61, 0)
162163
#define RISCV_PMU_RAW_EVENT_IDX 0x20000
163164
#define RISCV_PLAT_FW_EVENT 0xFFFF
164165

drivers/perf/riscv_pmu_sbi.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
507507
{
508508
u32 type = event->attr.type;
509509
u64 config = event->attr.config;
510-
u64 raw_config_val;
511-
int ret;
510+
int ret = -ENOENT;
512511

513512
/*
514513
* Ensure we are finished checking standard hardware events for
@@ -528,21 +527,23 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
528527
case PERF_TYPE_RAW:
529528
/*
530529
* As per SBI specification, the upper 16 bits must be unused
531-
* for a raw event.
530+
* for a hardware raw event.
532531
* Bits 63:62 are used to distinguish between raw events
533532
* 00 - Hardware raw event
534533
* 10 - SBI firmware events
535534
* 11 - Risc-V platform specific firmware event
536535
*/
537-
raw_config_val = config & RISCV_PMU_RAW_EVENT_MASK;
536+
538537
switch (config >> 62) {
539538
case 0:
540-
ret = RISCV_PMU_RAW_EVENT_IDX;
541-
*econfig = raw_config_val;
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+
}
542544
break;
543545
case 2:
544-
ret = (raw_config_val & 0xFFFF) |
545-
(SBI_PMU_EVENT_TYPE_FW << 16);
546+
ret = (config & 0xFFFF) | (SBI_PMU_EVENT_TYPE_FW << 16);
546547
break;
547548
case 3:
548549
/*
@@ -551,12 +552,13 @@ static int pmu_sbi_event_map(struct perf_event *event, u64 *econfig)
551552
* Event data - raw event encoding
552553
*/
553554
ret = SBI_PMU_EVENT_TYPE_FW << 16 | RISCV_PLAT_FW_EVENT;
554-
*econfig = raw_config_val;
555+
*econfig = config & RISCV_PMU_PLAT_FW_EVENT_MASK;
556+
break;
557+
default:
555558
break;
556559
}
557560
break;
558561
default:
559-
ret = -ENOENT;
560562
break;
561563
}
562564

0 commit comments

Comments
 (0)