On Wed, Dec 04, 2024 at 08:11:26PM +0200, Adrian Hunter wrote: > commit 5b590160d2cf776b304eb054afafea2bd55e3620 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: 52ca9ced3f70 ("perf/x86/intel/pt: Add Intel PT PMU driver") > Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx> > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> > Cc: stable@xxxxxxxxxxxxxxx > Link: https://lkml.kernel.org/r/20241022155920.17511-2-adrian.hunter@xxxxxxxxx > Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx> > --- > arch/x86/events/intel/pt.c | 11 ++++++++--- > arch/x86/events/intel/pt.h | 2 ++ > 2 files changed, 10 insertions(+), 3 deletions(-) Sorry, but 4.19.y is now end-of-life.