mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, irogers@google.com,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Cc: ak@linux.intel.com, ravi.bangoria@amd.com, jolsa@redhat.com,
	Kan Liang <kan.liang@linux.intel.com>,
	stable@vger.kernel.org
Subject: [PATCH 2/3] perf: Fix low freq setting via IOC_PERIOD
Date: Fri, 17 Jan 2025 07:19:12 -0800	[thread overview]
Message-ID: <20250117151913.3043942-2-kan.liang@linux.intel.com> (raw)
In-Reply-To: <20250117151913.3043942-1-kan.liang@linux.intel.com>

From: Kan Liang <kan.liang@linux.intel.com>

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

The perf_event_check_period() introduced in commit 81ec3f3c4c4d
("perf/x86: Add check_period PMU callback") intended to check the
period, rather than the freq. A low freq may be mistakenly rejected by
the limit_period().

Fixes: 81ec3f3c4c4d ("perf/x86: Add check_period PMU callback")
Closes: https://lore.kernel.org/lkml/20250115154949.3147-1-ravi.bangoria@amd.com/
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: stable@vger.kernel.org
---
 kernel/events/core.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index f91ba29048ce..a9a04d4f3619 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5960,14 +5960,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)
-		return -EINVAL;
-
-	if (perf_event_check_period(event, value))
-		return -EINVAL;
-
-	if (!event->attr.freq && (value & (1ULL << 63)))
-		return -EINVAL;
+	if (event->attr.freq) {
+		if (value > sysctl_perf_event_sample_rate)
+			return -EINVAL;
+	} else {
+		if (perf_event_check_period(event, value))
+			return -EINVAL;
+		if (value & (1ULL << 63))
+			return -EINVAL;
+	}
 
 	event_function_call(event, __perf_event_period, &value);
 
-- 
2.38.1


  reply	other threads:[~2025-01-17 15:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-17 15:19 [PATCH 1/3] perf/x86: Fix low freq setting issue kan.liang
2025-01-17 15:19 ` kan.liang [this message]
2025-01-20  4:59   ` [PATCH 2/3] perf: Fix low freq setting via IOC_PERIOD Ravi Bangoria
2025-02-25 14:14   ` [tip: perf/urgent] perf/core: " tip-bot2 for Kan Liang
2025-01-17 15:19 ` [RESEND PATCH 3/3] perf/x86/intel: New start period for the freq mode kan.liang
2025-02-25 14:14   ` [tip: perf/urgent] " tip-bot2 for Kan Liang
2025-02-25 19:48   ` [tip: perf/urgent] perf/x86/intel: Use better start period for frequency mode tip-bot2 for Kan Liang
2025-01-20  5:00 ` [PATCH 1/3] perf/x86: Fix low freq setting issue Ravi Bangoria
2025-02-25 14:14 ` [tip: perf/urgent] perf/x86: Fix low freqency " tip-bot2 for Kan Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250117151913.3043942-2-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome