Skip to content

Commit 0d39844

Browse files
Kan LiangIngo Molnar
authored andcommitted
perf/core: Fix low freq setting via IOC_PERIOD
A low attr::freq value cannot be set via IOC_PERIOD on some platforms. The perf_event_check_period() introduced in: 81ec3f3 ("perf/x86: Add check_period PMU callback") was intended to check the period, rather than the frequency. A low frequency may be mistakenly rejected by limit_period(). Fix it. Fixes: 81ec3f3 ("perf/x86: Add check_period PMU callback") Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250117151913.3043942-2-kan.liang@linux.intel.com Closes: https://lore.kernel.org/lkml/20250115154949.3147-1-ravi.bangoria@amd.com/
1 parent 88ec7ee commit 0d39844

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/events/core.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5969,14 +5969,15 @@ static int _perf_event_period(struct perf_event *event, u64 value)
59695969
if (!value)
59705970
return -EINVAL;
59715971

5972-
if (event->attr.freq && value > sysctl_perf_event_sample_rate)
5973-
return -EINVAL;
5974-
5975-
if (perf_event_check_period(event, value))
5976-
return -EINVAL;
5977-
5978-
if (!event->attr.freq && (value & (1ULL << 63)))
5979-
return -EINVAL;
5972+
if (event->attr.freq) {
5973+
if (value > sysctl_perf_event_sample_rate)
5974+
return -EINVAL;
5975+
} else {
5976+
if (perf_event_check_period(event, value))
5977+
return -EINVAL;
5978+
if (value & (1ULL << 63))
5979+
return -EINVAL;
5980+
}
59805981

59815982
event_function_call(event, __perf_event_period, &value);
59825983

0 commit comments

Comments
 (0)