All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V7 1/2] perf: Track per-PMU sched_task() callback users
@ 2021-05-13 14:23 kan.liang
  2021-05-13 14:23 ` [PATCH V7 2/2] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task kan.liang
  2021-05-13 14:42 ` [PATCH V7 1/2] perf: Track per-PMU sched_task() callback users Peter Zijlstra
  0 siblings, 2 replies; 9+ messages in thread
From: kan.liang @ 2021-05-13 14:23 UTC (permalink / raw)
  To: peterz, mingo, linux-kernel
  Cc: robh, ak, acme, mark.rutland, luto, eranian, namhyung, Kan Liang

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

Current perf only tracks the per-CPU sched_task() callback users, which
doesn't work if a callback user is a task. For example, the dirty
counters have to be cleared to prevent data leakage when a new RDPMC
task is scheduled in. The task may be created on one CPU but running on
another CPU. It cannot be tracked by the per-CPU variable. A global
variable is not going to work either because of the hybrid PMUs.
Add a per-PMU variable to track the callback users.

In theory, the per-PMU variable should be checked everywhere the
sched_task() can be called. But the X86 RDPMC is the only user for the
per-PMU sched_cb_usage. A callback for the X86 RDPMC is required only
when a different context is scheduled in. To avoid unnecessary
sched_task() invoke, the per-PMU sched_cb_usage is only checked there.
Should there be any other ARCHs which require it in the other places,
it can be added later separately.

Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---

- New patch. Split the V6 to core and x86 parts.

 include/linux/perf_event.h | 3 +++
 kernel/events/core.c       | 9 ++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index c8a3388..c6ee202 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -301,6 +301,9 @@ struct pmu {
 	/* number of address filters this PMU can do */
 	unsigned int			nr_addr_filters;
 
+	/* Track the per PMU sched_task() callback users */
+	atomic_t			sched_cb_usage;
+
 	/*
 	 * Fully disable/enable this PMU, can be used to protect from the PMI
 	 * as well as for lazy/batch writing of the MSRs.
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1574b70..286b718 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3851,7 +3851,14 @@ static void perf_event_context_sched_in(struct perf_event_context *ctx,
 		cpu_ctx_sched_out(cpuctx, EVENT_FLEXIBLE);
 	perf_event_sched_in(cpuctx, ctx, task);
 
-	if (cpuctx->sched_cb_usage && pmu->sched_task)
+	/*
+	 * X86 RDPMC is the only user for the per-PMU sched_cb_usage.
+	 * A callback for the X86 RDPMC is required only when a
+	 * different context is scheduled in.
+	 * To avoid unnecessary sched_task() invoke, the per-PMU
+	 * sched_cb_usage is only checked here.
+	 */
+	if (pmu->sched_task && (cpuctx->sched_cb_usage || atomic_read(&pmu->sched_cb_usage)))
 		pmu->sched_task(cpuctx->task_ctx, true);
 
 	perf_pmu_enable(pmu);
-- 
2.7.4


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

end of thread, other threads:[~2021-05-14 15:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13 14:23 [PATCH V7 1/2] perf: Track per-PMU sched_task() callback users kan.liang
2021-05-13 14:23 ` [PATCH V7 2/2] perf/x86: Reset the dirty counter to prevent the leak for an RDPMC task kan.liang
2021-05-13 15:02   ` Peter Zijlstra
2021-05-13 22:14     ` Liang, Kan
2021-05-14  3:50       ` Rob Herring
2021-05-14 13:48         ` Liang, Kan
2021-05-14 14:44       ` Peter Zijlstra
2021-05-14 15:30         ` Liang, Kan
2021-05-13 14:42 ` [PATCH V7 1/2] perf: Track per-PMU sched_task() callback users Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.