mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu
@ 2023-10-24  9:29 Yicong Yang
  2023-10-24  9:29 ` [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init() Yicong Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yicong Yang @ 2023-10-24  9:29 UTC (permalink / raw)
  To: jonathan.cameron, will, mark.rutland, linux-arm-kernel, linux-kernel
  Cc: hejunhao3, prime.zeng, yangyicong, linuxarm

From: Yicong Yang <yangyicong@hisilicon.com>

This patchset includes 2 minor updates for the hisi_pcie_pmu:
- fix issue that we may touch others events in some case
- modify the event->cpu only on the success pmu::event_init()

Yicong Yang (2):
  drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
  drivers/perf: hisi_pcie: Initialize event->cpu only on success

 drivers/perf/hisilicon/hisi_pcie_pmu.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
  2023-10-24  9:29 [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Yicong Yang
@ 2023-10-24  9:29 ` Yicong Yang
  2023-10-24  9:29 ` [PATCH 2/2] drivers/perf: hisi_pcie: Initialize event->cpu only on success Yicong Yang
  2023-10-24 12:51 ` [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Yicong Yang @ 2023-10-24  9:29 UTC (permalink / raw)
  To: jonathan.cameron, will, mark.rutland, linux-arm-kernel, linux-kernel
  Cc: hejunhao3, prime.zeng, yangyicong, linuxarm

From: Yicong Yang <yangyicong@hisilicon.com>

Check whether the event type matches the PMU type firstly in
pmu::event_init() before touching the event. Otherwise we'll
change the events of others and lead to incorrect results.
Since in perf_init_event() we may call every pmu's event_init()
in a certain case, we should not modify the event if it's not
ours.

Fixes: 8404b0fbc7fb ("drivers/perf: hisi: Add driver for HiSilicon PCIe PMU")
Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/perf/hisilicon/hisi_pcie_pmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c
index 5a00adb2de8c..051efffc44c8 100644
--- a/drivers/perf/hisilicon/hisi_pcie_pmu.c
+++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c
@@ -353,6 +353,10 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
 	struct hisi_pcie_pmu *pcie_pmu = to_pcie_pmu(event->pmu);
 	struct hw_perf_event *hwc = &event->hw;
 
+	/* Check the type first before going on, otherwise it's not our event */
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
 	event->cpu = pcie_pmu->on_cpu;
 
 	if (EXT_COUNTER_IS_USED(hisi_pcie_get_event(event)))
@@ -360,9 +364,6 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
 	else
 		hwc->event_base = HISI_PCIE_CNT;
 
-	if (event->attr.type != event->pmu->type)
-		return -ENOENT;
-
 	/* Sampling is not supported. */
 	if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
 		return -EOPNOTSUPP;
-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] drivers/perf: hisi_pcie: Initialize event->cpu only on success
  2023-10-24  9:29 [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Yicong Yang
  2023-10-24  9:29 ` [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init() Yicong Yang
@ 2023-10-24  9:29 ` Yicong Yang
  2023-10-24 12:51 ` [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Yicong Yang @ 2023-10-24  9:29 UTC (permalink / raw)
  To: jonathan.cameron, will, mark.rutland, linux-arm-kernel, linux-kernel
  Cc: hejunhao3, prime.zeng, yangyicong, linuxarm

From: Yicong Yang <yangyicong@hisilicon.com>

Initialize the event->cpu only on success. To be more reasonable
and keep consistent with other PMUs.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/perf/hisilicon/hisi_pcie_pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c
index 051efffc44c8..b90ba8aca3fa 100644
--- a/drivers/perf/hisilicon/hisi_pcie_pmu.c
+++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c
@@ -357,8 +357,6 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
 	if (event->attr.type != event->pmu->type)
 		return -ENOENT;
 
-	event->cpu = pcie_pmu->on_cpu;
-
 	if (EXT_COUNTER_IS_USED(hisi_pcie_get_event(event)))
 		hwc->event_base = HISI_PCIE_EXT_CNT;
 	else
@@ -374,6 +372,8 @@ static int hisi_pcie_pmu_event_init(struct perf_event *event)
 	if (!hisi_pcie_pmu_validate_event_group(event))
 		return -EINVAL;
 
+	event->cpu = pcie_pmu->on_cpu;
+
 	return 0;
 }
 
-- 
2.24.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu
  2023-10-24  9:29 [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Yicong Yang
  2023-10-24  9:29 ` [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init() Yicong Yang
  2023-10-24  9:29 ` [PATCH 2/2] drivers/perf: hisi_pcie: Initialize event->cpu only on success Yicong Yang
@ 2023-10-24 12:51 ` Will Deacon
  2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2023-10-24 12:51 UTC (permalink / raw)
  To: mark.rutland, Yicong Yang, linux-kernel, linux-arm-kernel,
	jonathan.cameron
  Cc: catalin.marinas, kernel-team, Will Deacon, yangyicong,
	prime.zeng, linuxarm, hejunhao3

On Tue, 24 Oct 2023 17:29:52 +0800, Yicong Yang wrote:
> From: Yicong Yang <yangyicong@hisilicon.com>
> 
> This patchset includes 2 minor updates for the hisi_pcie_pmu:
> - fix issue that we may touch others events in some case
> - modify the event->cpu only on the success pmu::event_init()
> 
> Yicong Yang (2):
>   drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
>   drivers/perf: hisi_pcie: Initialize event->cpu only on success
> 
> [...]

Applied to will (for-next/perf), thanks!

[1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init()
      https://git.kernel.org/will/c/6d7d51e88e21
[2/2] drivers/perf: hisi_pcie: Initialize event->cpu only on success
      https://git.kernel.org/will/c/868f8a709874

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-24 12:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24  9:29 [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Yicong Yang
2023-10-24  9:29 ` [PATCH 1/2] drivers/perf: hisi_pcie: Check the type first in pmu::event_init() Yicong Yang
2023-10-24  9:29 ` [PATCH 2/2] drivers/perf: hisi_pcie: Initialize event->cpu only on success Yicong Yang
2023-10-24 12:51 ` [PATCH 0/2] Minor fix and cleanup for hisi_pcie_pmu Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®