-
Notifications
You must be signed in to change notification settings - Fork 103
[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] perf: Fix dangling cgroup pointer in cpuctx #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: linux-6.6.y
Are you sure you want to change the base?
[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] perf: Fix dangling cgroup pointer in cpuctx #1292
Conversation
mainline inclusion from mainline-v6.16-rc3 commit 12b6c62 category: bugfix Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=12b6c62c038e85354154aee4eb2cf7a2168b3ecc -------------------------------- Commit a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit") moves the event->state update to before list_del_event(). This makes the event->state test in list_del_event() always false; never calling perf_cgroup_event_disable(). As a result, cpuctx->cgrp won't be cleared properly; causing havoc. Fixes: a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit") Signed-off-by: Yeoreum Yun <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: David Wang <[email protected]> Link: https://lore.kernel.org/all/aD2TspKH%[email protected]/ (cherry picked from commit 3b7a34a) Signed-off-by: Wentao Guan <[email protected]> Conflicts: kernel/events/core.c
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFix dangling cgroup pointer in perf cpuctx by relocating perf_cgroup_event_disable from list_del_event to __perf_remove_from_context, ensuring proper cgroup cleanup for exit/dead events. Sequence diagram for perf event removal and cgroup cleanupsequenceDiagram
participant "perf_event"
participant "perf_event_context"
participant "pmu_ctx"
participant "cgroup"
"perf_event"->>"perf_event_context": __perf_remove_from_context(event, ctx, flags)
alt flags include DETACH_EXIT or DETACH_DEAD
"perf_event"->>"perf_event_context": event_sched_out(event, ctx)
alt event.state > PERF_EVENT_STATE_OFF
"perf_event"->>"cgroup": perf_cgroup_event_disable(event, ctx)
end
"perf_event"->>"perf_event_context": perf_event_set_state(event, min(event.state, state))
end
Class diagram for updated perf event removal logicclassDiagram
class perf_event {
state
group_leader
pending_disable
}
class perf_event_context {
generation
}
class pmu_ctx {
nr_events
}
perf_event --> perf_event_context : ctx
perf_event --> pmu_ctx
perf_event_context --> pmu_ctx
perf_event : perf_cgroup_event_disable(event, ctx)
perf_event : perf_event_set_state(event, state)
perf_event : event_sched_out(event, ctx)
perf_event_context : generation++
pmu_ctx : nr_events--
perf_event : pending_disable
perf_event : group_leader
perf_event : state
perf_event : group_leader == event
perf_event : del_event_from_groups(event, ctx)
perf_event : perf_group_detach(event)
perf_event : state > PERF_EVENT_STATE_OFF
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这个Git diff进行审查:
改进建议:
总体来说,这是一个良好的代码重构,提高了代码的组织性和可维护性,没有引入明显的性能或安全隐患。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Note: Although this appears unrelated to the patches in this PR, deepin’s linux-perf (and other tools) seem not to have been updated for a very long time. As a rule, they must be updated alongside kernel changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR backports an upstream bug fix that addresses a dangling cgroup pointer issue in the perf events subsystem. The fix resolves a problem where cpuctx->cgrp wasn't being cleared properly due to a timing issue with state checks.
Key Changes:
- Moved
perf_cgroup_event_disable()call fromlist_del_event()to__perf_remove_from_context() - Ensured cgroup disable happens before state transition to fix the bug
- Removed obsolete
pending_disableassignment that was part of the broken flow
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
NOTE: Deepin’s perf and other Linux tools haven’t been updated in a very, very, very long time. Normally, they should be updated together with each kernel release. |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Avenger-285714 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
mainline inclusion
from mainline-v6.16-rc3
commit 12b6c62
category: bugfix
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=12b6c62c038e85354154aee4eb2cf7a2168b3ecc
Commit a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit") moves the event->state update to before list_del_event(). This makes the event->state test in list_del_event() always false; never calling perf_cgroup_event_disable().
As a result, cpuctx->cgrp won't be cleared properly; causing havoc.
Fixes: a3c3c66("perf/core: Fix child_total_time_enabled accounting bug at task exit")
Signed-off-by: Yeoreum Yun [email protected]
Signed-off-by: Peter Zijlstra (Intel) [email protected]
Tested-by: David Wang [email protected]
Link: https://lore.kernel.org/all/aD2TspKH%[email protected]/ (cherry picked from commit 3b7a34a)
Signed-off-by: Wentao Guan [email protected]
Conflicts:
kernel/events/core.c
Summary by Sourcery
Restore correct cgroup cleanup for perf events by moving perf_cgroup_event_disable to __perf_remove_from_context and removing outdated disable logic from list_del_event, fixing dangling cgroup pointers in CPU contexts
Bug Fixes: