Commit 994fd192 authored by Kan Liang's avatar Kan Liang Committed by Wentao Guan
Browse files

perf/core: Fix low freq setting via IOC_PERIOD

stable inclusion
from stable-v6.6.81
commit 01d5165304741880e2a4fa192be381e9468ad1c5
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBYZED

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=01d5165304741880e2a4fa192be381e9468ad1c5



--------------------------------

commit 0d39844150546fa1415127c5fbae26db64070dd3 upstream.

A low attr::freq value cannot be set via IOC_PERIOD on some platforms.

The perf_event_check_period() introduced in:

  81ec3f3c ("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: 81ec3f3c ("perf/x86: Add check_period PMU callback")
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarRavi 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/


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 01d5165304741880e2a4fa192be381e9468ad1c5)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 4fa4f2ae
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -5861,14 +5861,15 @@ static int _perf_event_period(struct perf_event *event, u64 value)
	if (!value)
		return -EINVAL;

	if (event->attr.freq && value > sysctl_perf_event_sample_rate)
	if (event->attr.freq) {
		if (value > sysctl_perf_event_sample_rate)
			return -EINVAL;

	} else {
		if (perf_event_check_period(event, value))
			return -EINVAL;

	if (!event->attr.freq && (value & (1ULL << 63)))
		if (value & (1ULL << 63))
			return -EINVAL;
	}

	event_function_call(event, __perf_event_period, &value);