linux-stable/arch
Adrian Hunter c0978ecb28 perf/x86/intel/pt: Fix buffer full but size is 0 case
commit 5b590160d2 upstream.

If the trace data buffer becomes full, a truncated flag [T] is reported
in PERF_RECORD_AUX.  In some cases, the size reported is 0, even though
data must have been added to make the buffer full.

That happens when the buffer fills up from empty to full before the
Intel PT driver has updated the buffer position.  Then the driver
calculates the new buffer position before calculating the data size.
If the old and new positions are the same, the data size is reported
as 0, even though it is really the whole buffer size.

Fix by detecting when the buffer position is wrapped, and adjust the
data size calculation accordingly.

Example

  Use a very small buffer size (8K) and observe the size of truncated [T]
  data. Before the fix, it is possible to see records of 0 size.

  Before:

    $ perf record -m,8K -e intel_pt// uname
    Linux
    [ perf record: Woken up 2 times to write data ]
    [ perf record: Captured and wrote 0.105 MB perf.data ]
    $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
    Warning:
    AUX data lost 2 times out of 3!

    5 19462712368111 0x19710 [0x40]: PERF_RECORD_AUX offset: 0 size: 0 flags: 0x1 [T]
    5 19462712700046 0x19ba8 [0x40]: PERF_RECORD_AUX offset: 0x170 size: 0xe90 flags: 0x1 [T]

 After:

    $ perf record -m,8K -e intel_pt// uname
    Linux
    [ perf record: Woken up 3 times to write data ]
    [ perf record: Captured and wrote 0.040 MB perf.data ]
    $ perf script -D --no-itrace | grep AUX | grep -F '[T]'
    Warning:
    AUX data lost 2 times out of 3!

    1 113720802995 0x4948 [0x40]: PERF_RECORD_AUX offset: 0 size: 0x2000 flags: 0x1 [T]
    1 113720979812 0x6b10 [0x40]: PERF_RECORD_AUX offset: 0x2000 size: 0x2000 flags: 0x1 [T]

Fixes: 52ca9ced3f ("perf/x86/intel/pt: Add Intel PT PMU driver")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20241022155920.17511-2-adrian.hunter@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-12-14 19:44:55 +01:00
..
alpha y2038: rusage: use __kernel_old_timeval 2024-03-15 10:48:18 -04:00
arc ARC: [plat-hsdk]: Remove misplaced interrupt-cells property 2024-05-02 16:18:33 +02:00
arm ARM: dts: cubieboard4: Fix DCDC5 regulator constraints 2024-12-14 19:44:24 +01:00
arm64 arm64: tls: Fix context-switching of tpidrro_el0 when kpti is enabled 2024-12-14 19:44:38 +01:00
c6x dma-mapping: drop the dev argument to arch_sync_dma_for_* 2023-04-05 11:16:43 +02:00
csky csky, hexagon: fix broken sys_sync_file_range 2024-07-05 09:08:31 +02:00
h8300 h8300: Fix build errors from do_exit() to make_task_dead() transition 2023-02-06 07:52:49 +01:00
hexagon hexagon: fix fadvise64_64 calling conventions 2024-07-05 09:08:31 +02:00
ia64 arch, mm: remove stale mentions of DISCONIGMEM 2024-02-23 08:25:13 +01:00
m68k m68k: coldfire/device.c: only build FEC when HW macros are defined 2024-12-14 19:44:31 +01:00
microblaze microblaze: don't treat zero reserved memory regions as error 2024-11-08 16:20:25 +01:00
mips mips: asm: fix warning when disabling MIPS_FP_SUPPORT 2024-12-14 19:44:21 +01:00
nds32 arch, mm: remove stale mentions of DISCONIGMEM 2024-02-23 08:25:13 +01:00
nios2 nios2: dts: Fix tse_mac "max-frame-size" property 2023-06-21 15:44:10 +02:00
openrisc openrisc: Call setup_memory() earlier in the init sequence 2024-09-04 13:14:57 +02:00
parisc parisc: Fix 64-bit userspace syscall path 2024-11-08 16:20:40 +01:00
powerpc powerpc/prom_init: Fixup missing powermac #size-cells 2024-12-14 19:44:54 +01:00
riscv riscv: Remove unused GENERATING_ASM_OFFSETS 2024-11-08 16:20:54 +01:00
s390 s390/cpum_sf: Handle CPU hotplug remove during sampling 2024-12-14 19:44:49 +01:00
sh sh: cpuinfo: Fix a warning for CONFIG_CPUMASK_OFFSTACK 2024-12-14 19:44:37 +01:00
sparc sparc64: Fix incorrect function signature and add prototype for prom_cif_init 2024-08-19 05:33:32 +02:00
um um: Always dump trace for specified task in show_stack 2024-12-14 19:44:40 +01:00
unicore32 mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
x86 perf/x86/intel/pt: Fix buffer full but size is 0 case 2024-12-14 19:44:55 +01:00
xtensa arch, mm: remove stale mentions of DISCONIGMEM 2024-02-23 08:25:13 +01:00
.gitignore
Kconfig init: Provide arch_cpu_finalize_init() 2023-08-08 19:56:33 +02:00