Skip to content

Commit 543ac28

Browse files
Kan LiangIngo Molnar
authored andcommitted
perf/x86/intel/uncore: Handle invalid event coding for free-running counter
Counting with invalid event coding for free-running counter may cause OOPs, e.g. uncore_iio_free_running_0/event=1/. Current code only validate the event with free-running event format, event=0xff,umask=0xXY. Non-free-running event format never be checked for the PMU with free-running counters. Add generic hw_config() to check and reject the invalid event coding for free-running PMU. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Fixes: 0f519f0 ("perf/x86/intel/uncore: Support IIO free-running counters on SKX") Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent faaeff9 commit 543ac28

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

arch/x86/events/intel/uncore.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ static inline bool is_freerunning_event(struct perf_event *event)
419419
(((cfg >> 8) & 0xff) >= UNCORE_FREERUNNING_UMASK_START);
420420
}
421421

422+
/* Check and reject invalid config */
423+
static inline int uncore_freerunning_hw_config(struct intel_uncore_box *box,
424+
struct perf_event *event)
425+
{
426+
if (is_freerunning_event(event))
427+
return 0;
428+
429+
return -EINVAL;
430+
}
431+
422432
static inline void uncore_disable_box(struct intel_uncore_box *box)
423433
{
424434
if (box->pmu->type->ops->disable_box)

arch/x86/events/intel/uncore_snbep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,6 +3585,7 @@ static struct uncore_event_desc skx_uncore_iio_freerunning_events[] = {
35853585

35863586
static struct intel_uncore_ops skx_uncore_iio_freerunning_ops = {
35873587
.read_counter = uncore_msr_read_counter,
3588+
.hw_config = uncore_freerunning_hw_config,
35883589
};
35893590

35903591
static struct attribute *skx_uncore_iio_freerunning_formats_attr[] = {

0 commit comments

Comments
 (0)