* FAILED: patch "[PATCH] perf/x86/intel/pt: Fix buffer full but size is 0 case" failed to apply to 4.19-stable tree
@ 2024-12-02 15:03 gregkh
2024-12-04 18:11 ` [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case Adrian Hunter
0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2024-12-02 15:03 UTC (permalink / raw)
To: adrian.hunter, peterz; +Cc: stable
The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.19.y
git checkout FETCH_HEAD
git cherry-pick -x 5b590160d2cf776b304eb054afafea2bd55e3620
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2024120221-raft-bully-e091@gregkh' --subject-prefix 'PATCH 4.19.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 5b590160d2cf776b304eb054afafea2bd55e3620 Mon Sep 17 00:00:00 2001
From: Adrian Hunter <adrian.hunter@intel.com>
Date: Tue, 22 Oct 2024 18:59:07 +0300
Subject: [PATCH] perf/x86/intel/pt: Fix buffer full but size is 0 case
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@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
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index fd4670a6694e..a087bc0c5498 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -828,11 +828,13 @@ static void pt_buffer_advance(struct pt_buffer *buf)
buf->cur_idx++;
if (buf->cur_idx == buf->cur->last) {
- if (buf->cur == buf->last)
+ if (buf->cur == buf->last) {
buf->cur = buf->first;
- else
+ buf->wrapped = true;
+ } else {
buf->cur = list_entry(buf->cur->list.next, struct topa,
list);
+ }
buf->cur_idx = 0;
}
}
@@ -846,8 +848,11 @@ static void pt_buffer_advance(struct pt_buffer *buf)
static void pt_update_head(struct pt *pt)
{
struct pt_buffer *buf = perf_get_aux(&pt->handle);
+ bool wrapped = buf->wrapped;
u64 topa_idx, base, old;
+ buf->wrapped = false;
+
if (buf->single) {
local_set(&buf->data_size, buf->output_off);
return;
@@ -865,7 +870,7 @@ static void pt_update_head(struct pt *pt)
} else {
old = (local64_xchg(&buf->head, base) &
((buf->nr_pages << PAGE_SHIFT) - 1));
- if (base < old)
+ if (base < old || (base == old && wrapped))
base += buf->nr_pages << PAGE_SHIFT;
local_add(base - old, &buf->data_size);
diff --git a/arch/x86/events/intel/pt.h b/arch/x86/events/intel/pt.h
index f5e46c04c145..a1b6c04b7f68 100644
--- a/arch/x86/events/intel/pt.h
+++ b/arch/x86/events/intel/pt.h
@@ -65,6 +65,7 @@ struct pt_pmu {
* @head: logical write offset inside the buffer
* @snapshot: if this is for a snapshot/overwrite counter
* @single: use Single Range Output instead of ToPA
+ * @wrapped: buffer advance wrapped back to the first topa table
* @stop_pos: STOP topa entry index
* @intr_pos: INT topa entry index
* @stop_te: STOP topa entry pointer
@@ -82,6 +83,7 @@ struct pt_buffer {
local64_t head;
bool snapshot;
bool single;
+ bool wrapped;
long stop_pos, intr_pos;
struct topa_entry *stop_te, *intr_te;
void **data_pages;
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case
2024-12-02 15:03 FAILED: patch "[PATCH] perf/x86/intel/pt: Fix buffer full but size is 0 case" failed to apply to 4.19-stable tree gregkh
@ 2024-12-04 18:11 ` Adrian Hunter
2024-12-04 22:11 ` Sasha Levin
2024-12-06 9:29 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Adrian Hunter @ 2024-12-04 18:11 UTC (permalink / raw)
To: stable
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@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: Adrian Hunter <adrian.hunter@intel.com>
---
arch/x86/events/intel/pt.c | 11 ++++++++---
arch/x86/events/intel/pt.h | 2 ++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 87cca5622885..d37ea43df220 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -771,11 +771,13 @@ static void pt_buffer_advance(struct pt_buffer *buf)
buf->cur_idx++;
if (buf->cur_idx == buf->cur->last) {
- if (buf->cur == buf->last)
+ if (buf->cur == buf->last) {
buf->cur = buf->first;
- else
+ buf->wrapped = true;
+ } else {
buf->cur = list_entry(buf->cur->list.next, struct topa,
list);
+ }
buf->cur_idx = 0;
}
}
@@ -789,8 +791,11 @@ static void pt_buffer_advance(struct pt_buffer *buf)
static void pt_update_head(struct pt *pt)
{
struct pt_buffer *buf = perf_get_aux(&pt->handle);
+ bool wrapped = buf->wrapped;
u64 topa_idx, base, old;
+ buf->wrapped = false;
+
/* offset of the first region in this table from the beginning of buf */
base = buf->cur->offset + buf->output_off;
@@ -803,7 +808,7 @@ static void pt_update_head(struct pt *pt)
} else {
old = (local64_xchg(&buf->head, base) &
((buf->nr_pages << PAGE_SHIFT) - 1));
- if (base < old)
+ if (base < old || (base == old && wrapped))
base += buf->nr_pages << PAGE_SHIFT;
local_add(base - old, &buf->data_size);
diff --git a/arch/x86/events/intel/pt.h b/arch/x86/events/intel/pt.h
index ad4ac27f0468..7c3fc191f789 100644
--- a/arch/x86/events/intel/pt.h
+++ b/arch/x86/events/intel/pt.h
@@ -110,6 +110,7 @@ struct pt_pmu {
* @lost: if data was lost/truncated
* @head: logical write offset inside the buffer
* @snapshot: if this is for a snapshot/overwrite counter
+ * @wrapped: buffer advance wrapped back to the first topa table
* @stop_pos: STOP topa entry in the buffer
* @intr_pos: INT topa entry in the buffer
* @data_pages: array of pages from perf
@@ -125,6 +126,7 @@ struct pt_buffer {
local_t data_size;
local64_t head;
bool snapshot;
+ bool wrapped;
unsigned long stop_pos, intr_pos;
void **data_pages;
struct topa_entry *topa_index[0];
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case
2024-12-04 18:11 ` [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case Adrian Hunter
@ 2024-12-04 22:11 ` Sasha Levin
2024-12-06 9:29 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2024-12-04 22:11 UTC (permalink / raw)
To: stable; +Cc: Adrian Hunter, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: 5b590160d2cf776b304eb054afafea2bd55e3620
Status in newer kernel trees:
6.12.y | Present (different SHA1: bd0081617661)
6.11.y | Present (different SHA1: 549225e02e9b)
6.6.y | Present (different SHA1: 1488d93e3e1f)
6.1.y | Present (different SHA1: bda8868213ee)
5.15.y | Present (different SHA1: 1b843f820f7a)
5.10.y | Present (different SHA1: b243226da582)
5.4.y | Not found
4.19.y | Not found
Note: The patch differs from the upstream commit:
---
1: 5b590160d2cf7 ! 1: 787e984867a5b perf/x86/intel/pt: Fix buffer full but size is 0 case
@@ Metadata
## Commit message ##
perf/x86/intel/pt: Fix buffer full but size is 0 case
+ 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.
@@ Commit message
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: Adrian Hunter <adrian.hunter@intel.com>
## arch/x86/events/intel/pt.c ##
@@ arch/x86/events/intel/pt.c: static void pt_buffer_advance(struct pt_buffer *buf)
@@ arch/x86/events/intel/pt.c: static void pt_buffer_advance(struct pt_buffer *buf)
+ buf->wrapped = false;
+
- if (buf->single) {
- local_set(&buf->data_size, buf->output_off);
- return;
+ /* offset of the first region in this table from the beginning of buf */
+ base = buf->cur->offset + buf->output_off;
+
@@ arch/x86/events/intel/pt.c: static void pt_update_head(struct pt *pt)
} else {
old = (local64_xchg(&buf->head, base) &
@@ arch/x86/events/intel/pt.c: static void pt_update_head(struct pt *pt)
## arch/x86/events/intel/pt.h ##
@@ arch/x86/events/intel/pt.h: struct pt_pmu {
+ * @lost: if data was lost/truncated
* @head: logical write offset inside the buffer
* @snapshot: if this is for a snapshot/overwrite counter
- * @single: use Single Range Output instead of ToPA
+ * @wrapped: buffer advance wrapped back to the first topa table
- * @stop_pos: STOP topa entry index
- * @intr_pos: INT topa entry index
- * @stop_te: STOP topa entry pointer
+ * @stop_pos: STOP topa entry in the buffer
+ * @intr_pos: INT topa entry in the buffer
+ * @data_pages: array of pages from perf
@@ arch/x86/events/intel/pt.h: struct pt_buffer {
+ local_t data_size;
local64_t head;
bool snapshot;
- bool single;
+ bool wrapped;
- long stop_pos, intr_pos;
- struct topa_entry *stop_te, *intr_te;
+ unsigned long stop_pos, intr_pos;
void **data_pages;
+ struct topa_entry *topa_index[0];
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-4.19.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case
2024-12-04 18:11 ` [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case Adrian Hunter
2024-12-04 22:11 ` Sasha Levin
@ 2024-12-06 9:29 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2024-12-06 9:29 UTC (permalink / raw)
To: Adrian Hunter; +Cc: stable
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@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: Adrian Hunter <adrian.hunter@intel.com>
> ---
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-06 9:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02 15:03 FAILED: patch "[PATCH] perf/x86/intel/pt: Fix buffer full but size is 0 case" failed to apply to 4.19-stable tree gregkh
2024-12-04 18:11 ` [PATCH 4.19] perf/x86/intel/pt: Fix buffer full but size is 0 case Adrian Hunter
2024-12-04 22:11 ` Sasha Levin
2024-12-06 9:29 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox