linux-stable/arch/x86/events/intel
Kan Liang b06f306af9 perf/x86/intel/ds: Don't clear ->pebs_data_cfg for the last PEBS event
commit 312be9fc22 upstream.

The MSR_PEBS_DATA_CFG MSR register is used to configure which data groups
should be generated into a PEBS record, and it's shared among all counters.

If there are different configurations among counters, perf combines all the
configurations.

The first perf command as below requires a complete PEBS record
(including memory info, GPRs, XMMs, and LBRs). The second perf command
only requires a basic group. However, after the second perf command is
running, the MSR_PEBS_DATA_CFG register is cleared. Only a basic group is
generated in a PEBS record, which is wrong. The required information
for the first perf command is missed.

 $ perf record --intr-regs=AX,SP,XMM0 -a -C 8 -b -W -d -c 100000003 -o /dev/null -e cpu/event=0xd0,umask=0x81/upp &
 $ sleep 5
 $ perf record  --per-thread  -c 1  -e cycles:pp --no-timestamp --no-tid taskset -c 8 ./noploop 1000

The first PEBS event is a system-wide PEBS event. The second PEBS event
is a per-thread event. When the thread is scheduled out, the
intel_pmu_pebs_del() function is invoked to update the PEBS state.
Since the system-wide event is still available, the cpuc->n_pebs is 1.
The cpuc->pebs_data_cfg is cleared. The data configuration for the
system-wide PEBS event is lost.

The (cpuc->n_pebs == 1) check was introduced in commit:

  b6a32f023f ("perf/x86: Fix PEBS threshold initialization")

At that time, it indeed didn't hurt whether the state was updated
during the removal, because only the threshold is updated.

The calculation of the threshold takes the last PEBS event into
account.

However, since commit:

  b752ea0c28 ("perf/x86/intel/ds: Flush PEBS DS when changing PEBS_DATA_CFG")

we delay the threshold update, and clear the PEBS data config, which triggers
the bug.

The PEBS data config update scope should not be shrunk during removal.

[ mingo: Improved the changelog & comments. ]

Fixes: b752ea0c28 ("perf/x86/intel/ds: Flush PEBS DS when changing PEBS_DATA_CFG")
Reported-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20240401133320.703971-1-kan.liang@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-10 16:38:19 +02:00
..
Makefile perf/x86/intel/uncore: Parse uncore discovery tables 2021-04-02 10:04:54 +02:00
bts.c perf/x86: Add compiler barrier after updating BTS 2021-09-17 15:08:38 +02:00
core.c Performance events changes for v6.8 are: 2024-01-08 19:37:20 -08:00
cstate.c perf/x86/intel/cstate: Add Grand Ridge support 2023-11-17 10:54:53 +01:00
ds.c perf/x86/intel/ds: Don't clear ->pebs_data_cfg for the last PEBS event 2024-04-10 16:38:19 +02:00
knc.c
lbr.c perf/x86/intel: Support branch counters logging 2023-10-27 15:05:11 +02:00
p4.c perf/x86: Make struct p4_event_bind::cntr signed array 2022-11-19 00:56:15 +01:00
p6.c x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping 2018-02-15 01:15:52 +01:00
pt.c perf/x86/intel/pt: Fix kernel-doc comments 2023-10-09 12:26:22 +02:00
pt.h perf/x86/intel/pt: Prevent redundant WRMSRs 2019-11-13 11:06:18 +01:00
uncore.c perf/x86/intel/uncore: Support Sierra Forest and Grand Ridge 2023-11-24 20:25:03 +01:00
uncore.h perf/x86/intel/uncore: Support Granite Rapids 2023-11-24 20:25:01 +01:00
uncore_discovery.c perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array 2023-11-24 20:25:01 +01:00
uncore_discovery.h perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array 2023-11-24 20:25:01 +01:00
uncore_nhmex.c perf/x86/uncore: Use u64 to replace unsigned for the uncore offsets array 2023-11-24 20:25:01 +01:00
uncore_snb.c perf/x86/intel/uncore: Add Meteor Lake support 2023-02-11 12:39:03 +01:00
uncore_snbep.c perf/x86/intel/uncore: Factor out topology_gidnid_map() 2023-11-30 14:29:53 +01:00