From: Namhyung Kim <namhyung@kernel.org>
To: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
eranian@google.com, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, tglx@linutronix.de, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
santosh.shukla@amd.com, ananth.narayan@amd.com,
sandipan.das@amd.com
Subject: Re: [PATCH 5/8] perf/amd/ibs: Don't allow freq mode event creation through ->config interface
Date: Mon, 7 Oct 2024 12:24:33 -0700 [thread overview]
Message-ID: <ZwQ1cRhRuE3kunjK@google.com> (raw)
In-Reply-To: <20241007034810.754-6-ravi.bangoria@amd.com>
On Mon, Oct 07, 2024 at 03:48:07AM +0000, Ravi Bangoria wrote:
> Most perf_event_attr->config bits directly maps to IBS_{FETCH|OP}_CTL
> MSR. Since the sample period is programmed in these control registers,
> IBS PMU driver allows opening an IBS event by setting sample period
> value directly in perf_event_attr->config instead of using explicit
> perf_event_attr->sample_period interface.
>
> However, this logic is not applicable for freq mode events since the
> semantics of control register fields are applicable only to fixed
> sample period whereas the freq mode event adjusts sample period after
> each and every sample. Currently, IBS driver (unintentionally) allows
> creating freq mode event via ->config interface, which is semantically
> wrong as well as detrimental because it can be misused to bypass
> perf_event_max_sample_rate checks.
>
> Don't allow freq mode event creation through perf_event_attr->config
> interface.
Sounds reasonable. I agree the freq mode should use the standard
interface using attr->sample_freq. But I'm not sure if the behaivor is
defined when attr->freq is set and attr->sample_freq is 0. Maybe this
should be handled in the generic code.
Thanks,
Namhyung
>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com>
> ---
> arch/x86/events/amd/ibs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
> index 152f9116af1e..368ed839b612 100644
> --- a/arch/x86/events/amd/ibs.c
> +++ b/arch/x86/events/amd/ibs.c
> @@ -302,6 +302,9 @@ static int perf_ibs_init(struct perf_event *event)
> } else {
> u64 period = 0;
>
> + if (event->attr.freq)
> + return -EINVAL;
> +
> if (perf_ibs == &perf_ibs_op) {
> period = (config & IBS_OP_MAX_CNT) << 4;
> if (ibs_caps & IBS_CAPS_OPCNTEXT)
> --
> 2.46.2
>
next prev parent reply other threads:[~2024-10-07 19:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 3:48 [PATCH 0/8] perf/amd/ibs: Fix sample period computations Ravi Bangoria
2024-10-07 3:48 ` [PATCH 1/8] perf/amd/ibs: Remove IBS_{FETCH|OP}_CONFIG_MASK macros Ravi Bangoria
2024-10-07 3:48 ` [PATCH 2/8] perf/amd/ibs: Remove pointless sample period check Ravi Bangoria
2024-10-07 19:16 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 3/8] perf/amd/ibs: Fix ->config to sample period calculation for OP pmu Ravi Bangoria
2024-10-07 3:48 ` [PATCH 4/8] perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt Ravi Bangoria
2024-10-07 3:48 ` [PATCH 5/8] perf/amd/ibs: Don't allow freq mode event creation through ->config interface Ravi Bangoria
2024-10-07 19:24 ` Namhyung Kim [this message]
2024-10-08 5:30 ` Ravi Bangoria
2024-10-09 6:27 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 6/8] perf/amd/ibs: Add pmu specific minimum period Ravi Bangoria
2024-10-07 19:30 ` Namhyung Kim
2024-10-08 5:46 ` Ravi Bangoria
2024-10-09 6:32 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 7/8] perf/amd/ibs: Add ->check_period() callback Ravi Bangoria
2024-10-07 19:33 ` Namhyung Kim
2024-10-07 3:48 ` [PATCH 8/8] perf/core: Introduce pmu->adjust_period() callback Ravi Bangoria
2024-10-09 6:33 ` [PATCH 0/8] perf/amd/ibs: Fix sample period computations Namhyung Kim
2024-11-19 13:35 ` Ravi Bangoria
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=ZwQ1cRhRuE3kunjK@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ananth.narayan@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=sandipan.das@amd.com \
--cc=santosh.shukla@amd.com \
--cc=tglx@linutronix.de \
--cc=x86@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