From: Rob Herring <[email protected]>

commit 82ff0c022d19c2ad69a472692bb7ee01ac07a40b upstream

On arm64, user space counter access will be controlled differently
compared to x86. On x86, access in the strictest mode is enabled for all
tasks in an MM when any event is mmap'ed. For arm64, access is
explicitly requested for an event and only enabled when the event's
context is active. This avoids hooks into the arch context switch code
and gives better control of when access is enabled.

In order to configure user space access when the PMU is enabled, it is
necessary to know if any event (currently active or not) in the current
context has user space accessed enabled. Add a counter similar to other
counters in the context to avoid walking the event list every time.

Reviewed-by: Mark Rutland <[email protected]>
Reviewed-by: Thomas Gleixner <[email protected]>
Signed-off-by: Rob Herring <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Will Deacon <[email protected]>
Signed-off-by: Adrian Zaharia <[email protected]>
---
 include/linux/perf_event.h | 1 +
 kernel/events/core.c       | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 9d2dffddeb2b..23b805d08c58 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -814,6 +814,7 @@ struct perf_event_context {
 
        int                             nr_events;
        int                             nr_active;
+       int                             nr_user;
        int                             is_active;
        int                             nr_stat;
        int                             nr_freq;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 8ba155a7b59e..fcb84e22f09e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1889,6 +1889,8 @@ list_add_event(struct perf_event *event, struct 
perf_event_context *ctx)
 
        list_add_rcu(&event->event_entry, &ctx->event_list);
        ctx->nr_events++;
+       if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT)
+               ctx->nr_user++;
        if (event->attr.inherit_stat)
                ctx->nr_stat++;
 
@@ -2074,6 +2076,8 @@ list_del_event(struct perf_event *event, struct 
perf_event_context *ctx)
        event->attach_state &= ~PERF_ATTACH_CONTEXT;
 
        ctx->nr_events--;
+       if (event->hw.flags & PERF_EVENT_FLAG_USER_READ_CNT)
+               ctx->nr_user--;
        if (event->attr.inherit_stat)
                ctx->nr_stat--;
 
-- 
2.36.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#12036): 
https://lists.yoctoproject.org/g/linux-yocto/message/12036
Mute This Topic: https://lists.yoctoproject.org/mt/95765177/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to