perf/x86: Fix multiple LBR sampling issues
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v7 Latest24 patches 4 repliesIn review
- v620 patches 5 repliesSuperseded
- v518 patches 20 repliesSuperseded
Earlier versions · 2
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v4 | 5 patches | 4 replies | Superseded | |
| v3 | 4 patches | 4 replies | Superseded |
Changes in v7 from the cover letter
- Patch 06/08: Set/clear the cpuc->enabled flag to track the PMU enabling state in the *_snapshot_branch_stack() helpers. (Sashiko)
- Patch 10: Rename __lbr_stack[] to __bhrb_stack[] and the related helpers accordingly, to stay consistent with the original powerpc code.
- Patch 14-16: New patches. Fix lbr_users/lbr_pebs_users not being accounted correctly in several corner cases. (Sashiko)
- Patch 17-19: New patches. Fix the non-PEBS LBR stack being overwritten by the PEBS LBR stack in two corner cases. (Sashiko)
- Patch 24: New patch. Fix the PERF_METRICS overflow bit not being cleared correctly.
Patches in v7 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/24 | perf/x86: Disable LBR if x86_pmu.lbr_nr exceeds MAX_LBR_ENTRIESarch/ | +6 | 0 replies | |
| 2/24 | perf/x86/intel: Validate LBR XSAVE state before updating LBR stackarch/ | +8 | 0 replies | |
| 3/24 | perf/x86/amd/lbr: Limit branch snapshots to valid entriesarch/ arch/ | +4 | 0 replies | |
| 4/24 | perf/x86/intel: Limit branch snapshots to valid entriesarch/ arch/ | +8 | 1 reply | |
| 5/24 | perf/x86: Add lbr_enabled to track LBR statearch/ arch/ arch/ +1 more | +18 | 0 replies | |
| 6/24 | perf/x86/amd: Avoid re-enabling PMU and LBR for BPF when disabledarch/ | +12 | 0 replies | |
| 7/24 | perf/x86/intel: Add helper to enable PMU without LBRarch/ | +9 | 0 replies | |
| 8/24 | perf/x86/intel: Avoid re-enabling PMU and LBR for BPF when disabledarch/ | +35 | 0 replies | |
| 9/24 | perf/x86/intel: Keep LBR frozen throughout PMI handlingarch/ | +11 | 0 replies | |
| 10/24 | perf: Add counted-bounds tracking for perf_branch_stackarch/ arch/ arch/ +8 more | +149 | 0 replies | |
| 11/24 | perf/x86/intel: Allow LBR read helpers to operate on explicit stacksarch/ arch/ arch/ +2 more | +64 | 0 replies | |
| 12/24 | perf/x86/intel: Use a dedicated LBR stack for BPF snapshottingarch/ | +12 | 0 replies | |
| 13/24 | perf/x86/intel: Always snapshot live hardware LBR state for BPFarch/ arch/ | +6 | 0 replies | |
| 14/24 | perf/x86/intel: Account lbr_pebs_users for arch-PEBS eventsarch/ arch/ | +9 | 1 reply | |
| 15/24 | perf/x86/intel: Set PERF_EV_CAP_SIBLING for pure branch counter eventsarch/ | +11 | 1 reply | |
| 16/24 | perf/x86/intel: Account LBR user counts for pure branch counter eventsarch/ | +39 | 0 replies | |
| 17/24 | perf/x86/intel: Refresh LBR stack for non-PEBS LBR events when neededarch/ arch/ arch/ | +16 | 0 replies | |
| 18/24 | perf/x86/intel: Fix draining of un-overflowed PEBS buffer in PMI handlerarch/ arch/ | +9 | 0 replies | |
| 19/24 | perf/x86/intel: Drain PEBS buffer for branch events with PEBS LBR usersarch/ | +39 | 0 replies | |
| 20/24 | perf/x86/intel: Clear raw LBR counters in the LBR stackarch/ arch/ arch/ | +16 | 1 reply | |
| 21/24 | perf/x86/intel: Refresh LBR stack for LBR counter events in PMI handlerarch/ | +10 | 0 replies | |
| 22/24 | perf/x86/intel: Pass LBR stack size into intel_pmu_store_lbr()arch/ arch/ arch/ | +17 | 0 replies | |
| 23/24 | perf/core: Don't mutate shared branch stack depthinclude/ kernel/ kernel/ | +18 | 0 replies | |
| 24/24 | perf/x86/intel: Fix incorrect PERF_METRICS overflow bit clearingarch/ arch/ | +3 | 0 replies |
Reviews trailers per patch
1 of 24 patches has a Reviewed-by or Acked-by.
| Patch | Dapeng Mi |
|---|---|
| 1/24 | |
| 2/24 | |
| 3/24 | R-b |
| 4/24 | |
| 5/24 | |
| 6/24 | |
| 7/24 | |
| 8/24 | |
| 9/24 | |
| 10/24 | |
| 11/24 | |
| 12/24 | |
| 13/24 | |
| 14/24 | |
| 15/24 | |
| 16/24 | |
| 17/24 | |
| 18/24 | |
| 19/24 | |
| 20/24 | |
| 21/24 | |
| 22/24 | |
| 23/24 | |
| 24/24 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [Patch v7 00/24] perf/x86: Fix multiple LBR sampling issues
This patch series fixes several x86 LBR sampling issues discovered during review and debugging. Most of them are related to BPF LBR snapshotting support.
The series originally targeted the BPF stack out-of-bounds access issue, but additional problems were found during debugging and code review, including:
- PMU and LBR being re-enabled unconditionally at BPF snapshotting exit, even when they had already been disabled before BPF snapshotting on both AMD and Intel.
- LBR not being fully frozen in the PMI handler on Intel, which allows branches in the PMI path to pollute the BPF LBR snapshot.
- BPF snapshotting overwriting the cached LBR stack of PEBS LBR events on Intel.
- PEBS LBR events overwriting the LBR stack of non-PEBS LBR events on Intel when both overflow in the same PMI.
- LBR counter events reporting zero counters on Intel when multiple LBR counter events overflow in the same PMI.
Patch layout:
- Patch 01: Add a sanity check to ensure the LBR stack depth never exceeds MAX_LBR_ENTRIES.
- Patch 02: Validate that hardware has actually written LBR data into the XSAVE area before parsing it.
- Patch 03-04: Fix a potential LBR stack out-of-bounds access on AMD and Intel, respectively.
- Patch 05-08: Fix incorrect PMU and LBR re-enabling in perf_snapshot_branch_stack() on AMD and Intel, respectively.
- Patch 09: Keep the LBR frozen throughout PMI processing so that all LBR events observe a consistent LBR stack in the PMI handler.
- Patch 10: Add bounds tracking for the number of entries counted in struct perf_branch_stack.
- Patch 11-12: Add a dedicated LBR stack for BPF LBR snapshots to avoid clobbering the default LBR stack used by other LBR events.
- Patch 13: Make perf_snapshot_branch_stack() snapshot the live hardware LBR data instead of the cached PEBS LBR stack.
- Patch 14-16: Account lbr_users/lbr_pebs_users for arch-PEBS and pure branch counter events.
- Patch 17-19: Prevent the PEBS LBR stack from overwriting the non-PEBS LBR stack in several corner cases.
- Patch 20-21: Ensure LBR counters are not lost when multiple LBR counter events overflow in the same PMI.
- Patch 22: Clamp the parsed PEBS LBR stack depth to x86_pmu.lbr_nr to avoid an LBR stack out-of-bounds access.
- Patch 23: Fix the shared LBR stack depth truncation issue.
- Patch 24: Fix incorrect clearing of the PERF_METRICS overflow bit.
Changes in v7:
- Patch 06/08: Set/clear the cpuc->enabled flag to track the PMU enabling state in the *_snapshot_branch_stack() helpers. (Sashiko)
- Patch 10: Rename __lbr_stack[] to __bhrb_stack[] and the related helpers accordingly, to stay consistent with the original powerpc code.
- Patch 14-16: New patches. Fix lbr_users/lbr_pebs_users not being accounted correctly in several corner cases. (Sashiko)
- Patch 17-19: New patches. Fix the non-PEBS LBR stack being overwritten by the PEBS LBR stack in two corner cases. (Sashiko)
- Patch 24: New patch. Fix the PERF_METRICS overflow bit not being cleared correctly.
Changes in v6:
- Patch 01: Move LBR stack depth validation into common init_hw_perf_events(). (Peter)
- Patch 10: New patch, add __counted_by() tracking for flexible array entries[] of perf_branch_stack{}. (Peter)
- Patch 14: Refresh LBR stack only when LBR users are active for AMD. (Peter)
- Patch 15: Refactor code to ensure no duplicated LBR stack reading. (Peter)
- Patch 16: New patch, remove dead lbr_pebs_users.
Changes in v5:
- Patch 02: Clear xsave->header.xfeatures before calling the xsaves instructuion to read LBR states.
- Patch 05-18: New patches to fix newly discovered issues described above.
Changes in v4:
- Patch 01: Disable LBR if parsed x86_pmu.lbr_nr exceeds MAX_LBR_ENTRIES (Sashiko).
- Patch 05: New patch, which always snapshots live hardware LBR stack for BPF path (Sashiko).
Changes in v3:
- Patch 01: A new patch to ensure x86_pmu.lbr_nr not to exclude MAX_LBR_ENTRIES (Internal Sashiko).
- Patch 03: Clean cached LBR stack when reseting hardware LBR registers, which prevents stale LBR stack leakage.
- Patch 04: Don't reset cached LBR stack if all LBR events are PEBS events. This ensures PEBS captured LBR stack isn't cleared (Sashiko).
Changes in v2:
- Include a fix for Intel LBR.
- Add Tested-by from Dapeng to the Intel fix.
https://lore.kernel.org/all/[email protected]/
History:
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Dapeng Mi (23):
perf/x86: Disable LBR if x86_pmu.lbr_nr exceeds MAX_LBR_ENTRIES perf/x86/intel: Validate LBR XSAVE state before updating LBR stack perf/x86/intel: Limit branch snapshots to valid entries perf/x86: Add lbr_enabled to track LBR state
perf/x86/amd: Avoid re-enabling PMU and LBR for BPF when disabled perf/x86/intel: Add helper to enable PMU without LBR perf/x86/intel: Avoid re-enabling PMU and LBR for BPF when disabled perf/x86/intel: Keep LBR frozen throughout PMI handling
perf: Add counted-bounds tracking for perf_branch_stack perf/x86/intel: Allow LBR read helpers to operate on explicit stacks perf/x86/intel: Use a dedicated LBR stack for BPF snapshotting perf/x86/intel: Always snapshot live hardware LBR state for BPF perf/x86/intel: Account lbr_pebs_users for arch-PEBS events perf/x86/intel: Set PERF_EV_CAP_SIBLING for pure branch counter events perf/x86/intel: Account LBR user counts for pure branch counter events perf/x86/intel: Refresh LBR stack for non-PEBS LBR events when needed perf/x86/intel: Fix draining of un-overflowed PEBS buffer in PMI
handler
perf/x86/intel: Drain PEBS buffer for branch events with PEBS LBR
users
perf/x86/intel: Clear raw LBR counters in the LBR stack perf/x86/intel: Refresh LBR stack for LBR counter events in PMI
handler
perf/x86/intel: Pass LBR stack size into intel_pmu_store_lbr() perf/core: Don't mutate shared branch stack depth perf/x86/intel: Fix incorrect PERF_METRICS overflow bit clearing
Sandipan Das (1):
perf/x86/amd/lbr: Limit branch snapshots to valid entries
arch/powerpc/perf/core-book3s.c | 47 ++++-- arch/x86/events/amd/brs.c | 7 +- arch/x86/events/amd/core.c | 25 +++- arch/x86/events/amd/lbr.c | 48 ++++--- arch/x86/events/core.c | 8 +- arch/x86/events/intel/core.c | 231 +++++++++++++++++++++++++----- arch/x86/events/intel/ds.c | 31 ++-- arch/x86/events/intel/lbr.c | 169 +++++++++++++--------- arch/x86/events/perf_event.h | 52 ++++++- arch/x86/include/asm/perf_event.h | 1 + drivers/perf/arm_brbe.c | 5 + include/linux/perf_event.h | 15 +- kernel/events/core.c | 8 +- kernel/trace/bpf_trace.c | 6 +- 14 files changed, 477 insertions(+), 176 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.34.1