linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf: Use sample_flags for addr
@ 2022-09-21 22:00 Namhyung Kim
  2022-09-21 22:00 ` [PATCH 2/2] perf: Use sample_flags for raw_data Namhyung Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Namhyung Kim @ 2022-09-21 22:00 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

Use the new sample_flags to indicate whether the addr field is filled by
the PMU driver.  As most PMU drivers pass 0, it can set the flag only if
it has a non-zero value.  And use 0 in perf_sample_output() if it's not
filled already.

Cc: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 arch/x86/events/intel/ds.c | 8 ++++++--
 include/linux/perf_event.h | 8 ++++++--
 kernel/events/core.c       | 5 +++++
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 4ba6ab6d0d92..d2e9ff16f6ed 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -1621,8 +1621,10 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,
 
 
 	if ((sample_type & PERF_SAMPLE_ADDR_TYPE) &&
-	    x86_pmu.intel_cap.pebs_format >= 1)
+	    x86_pmu.intel_cap.pebs_format >= 1) {
 		data->addr = pebs->dla;
+		data->sample_flags |= PERF_SAMPLE_ADDR;
+	}
 
 	if (x86_pmu.intel_cap.pebs_format >= 2) {
 		/* Only set the TSX weight when no memory weight. */
@@ -1783,8 +1785,10 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,
 			data->sample_flags |= PERF_SAMPLE_DATA_SRC;
 		}
 
-		if (sample_type & PERF_SAMPLE_ADDR_TYPE)
+		if (sample_type & PERF_SAMPLE_ADDR_TYPE) {
 			data->addr = meminfo->address;
+			data->sample_flags |= PERF_SAMPLE_ADDR;
+		}
 
 		if (sample_type & PERF_SAMPLE_TRANSACTION) {
 			data->txn = intel_get_tsx_transaction(meminfo->tsx_tuning,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 368bdc4f563f..f4a13579b0e8 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1028,7 +1028,6 @@ struct perf_sample_data {
 	 * minimize the cachelines touched.
 	 */
 	u64				sample_flags;
-	u64				addr;
 	struct perf_raw_record		*raw;
 	u64				period;
 
@@ -1040,6 +1039,7 @@ struct perf_sample_data {
 	union perf_sample_weight	weight;
 	union  perf_mem_data_src	data_src;
 	u64				txn;
+	u64				addr;
 
 	u64				type;
 	u64				ip;
@@ -1079,9 +1079,13 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
 {
 	/* remaining struct members initialized in perf_prepare_sample() */
 	data->sample_flags = 0;
-	data->addr = addr;
 	data->raw  = NULL;
 	data->period = period;
+
+	if (addr) {
+		data->addr = addr;
+		data->sample_flags |= PERF_SAMPLE_ADDR;
+	}
 }
 
 /*
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c07e9a3ea94c..a91f74db9fe9 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7414,6 +7414,11 @@ void perf_prepare_sample(struct perf_event_header *header,
 	if (filtered_sample_type & PERF_SAMPLE_TRANSACTION)
 		data->txn = 0;
 
+	if (sample_type & (PERF_SAMPLE_ADDR | PERF_SAMPLE_PHYS_ADDR | PERF_SAMPLE_DATA_PAGE_SIZE)) {
+		if (filtered_sample_type & PERF_SAMPLE_ADDR)
+			data->addr = 0;
+	}
+
 	if (sample_type & PERF_SAMPLE_REGS_INTR) {
 		/* regs dump ABI info */
 		int size = sizeof(u64);
-- 
2.37.3.968.ga6b4b080e4-goog


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 2/2] perf: Use sample_flags for raw_data
  2022-09-21 22:00 [PATCH 1/2] perf: Use sample_flags for addr Namhyung Kim
@ 2022-09-21 22:00 ` Namhyung Kim
  2022-09-28  6:57   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
  2022-09-22 14:48 ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
  2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
  2 siblings, 1 reply; 25+ messages in thread
From: Namhyung Kim @ 2022-09-21 22:00 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

Use the new sample_flags to indicate whether the raw data field is
filled by the PMU driver.  Although it could check with the NULL,
follow the same rule with other fields.

Remove the raw field from the perf_sample_data_init() to minimize
the number of cache lines touched.

Cc: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 arch/s390/kernel/perf_cpum_cf.c    | 1 +
 arch/s390/kernel/perf_pai_crypto.c | 1 +
 arch/x86/events/amd/ibs.c          | 1 +
 include/linux/perf_event.h         | 5 ++---
 kernel/events/core.c               | 3 ++-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index f7dd3c849e68..f043a7ff220b 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -664,6 +664,7 @@ static int cfdiag_push_sample(struct perf_event *event,
 		raw.frag.data = cpuhw->stop;
 		raw.size = raw.frag.size;
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	overflow = perf_event_overflow(event, &data, &regs);
diff --git a/arch/s390/kernel/perf_pai_crypto.c b/arch/s390/kernel/perf_pai_crypto.c
index b38b4ae01589..6826e2a69a21 100644
--- a/arch/s390/kernel/perf_pai_crypto.c
+++ b/arch/s390/kernel/perf_pai_crypto.c
@@ -366,6 +366,7 @@ static int paicrypt_push_sample(void)
 		raw.frag.data = cpump->save;
 		raw.size = raw.frag.size;
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	overflow = perf_event_overflow(event, &data, &regs);
diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index ce5720bfb350..c29a006954c7 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -781,6 +781,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
 			},
 		};
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	/*
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f4a13579b0e8..e9b151cde491 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1028,7 +1028,6 @@ struct perf_sample_data {
 	 * minimize the cachelines touched.
 	 */
 	u64				sample_flags;
-	struct perf_raw_record		*raw;
 	u64				period;
 
 	/*
@@ -1040,6 +1039,7 @@ struct perf_sample_data {
 	union  perf_mem_data_src	data_src;
 	u64				txn;
 	u64				addr;
+	struct perf_raw_record		*raw;
 
 	u64				type;
 	u64				ip;
@@ -1078,8 +1078,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
 					 u64 addr, u64 period)
 {
 	/* remaining struct members initialized in perf_prepare_sample() */
-	data->sample_flags = 0;
-	data->raw  = NULL;
+	data->sample_flags = PERF_SAMPLE_PERIOD;
 	data->period = period;
 
 	if (addr) {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a91f74db9fe9..04e19a857d4b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7332,7 +7332,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 		struct perf_raw_record *raw = data->raw;
 		int size;
 
-		if (raw) {
+		if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) {
 			struct perf_raw_frag *frag = &raw->frag;
 			u32 sum = 0;
 
@@ -7348,6 +7348,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 			frag->pad = raw->size - sum;
 		} else {
 			size = sizeof(u64);
+			data->raw = NULL;
 		}
 
 		header->size += size;
-- 
2.37.3.968.ga6b4b080e4-goog


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/2] perf: Use sample_flags for addr
  2022-09-21 22:00 [PATCH 1/2] perf: Use sample_flags for addr Namhyung Kim
  2022-09-21 22:00 ` [PATCH 2/2] perf: Use sample_flags for raw_data Namhyung Kim
@ 2022-09-22 14:48 ` Peter Zijlstra
  2022-09-22 16:32   ` Namhyung Kim
  2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
  2 siblings, 1 reply; 25+ messages in thread
From: Peter Zijlstra @ 2022-09-22 14:48 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

On Wed, Sep 21, 2022 at 03:00:31PM -0700, Namhyung Kim wrote:
> Use the new sample_flags to indicate whether the addr field is filled by
> the PMU driver.  As most PMU drivers pass 0, it can set the flag only if
> it has a non-zero value.  And use 0 in perf_sample_output() if it's not
> filled already.

So no objection to the general idea; just a question

> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index 368bdc4f563f..f4a13579b0e8 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -1028,7 +1028,6 @@ struct perf_sample_data {
>  	 * minimize the cachelines touched.
>  	 */
>  	u64				sample_flags;
> -	u64				addr;
>  	struct perf_raw_record		*raw;
>  	u64				period;
>  
> @@ -1040,6 +1039,7 @@ struct perf_sample_data {
>  	union perf_sample_weight	weight;
>  	union  perf_mem_data_src	data_src;
>  	u64				txn;
> +	u64				addr;
>  
>  	u64				type;
>  	u64				ip;

Is there a reason you placed the variable where you did?

I'm thinking we should look at what perf-tool thinks is the common set
of SAMPLE flags and make sure those fields are grouped in as little
cachelines as possible.

Things like @ip and @type, which are basically *always* set, should
definitely be on top, no?



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/2] perf: Use sample_flags for addr
  2022-09-22 14:48 ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
@ 2022-09-22 16:32   ` Namhyung Kim
  2022-09-22 20:55     ` [PATCH] perf: Change the layout of perf_sample_data Namhyung Kim
  2022-09-23  7:45     ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
  0 siblings, 2 replies; 25+ messages in thread
From: Namhyung Kim @ 2022-09-22 16:32 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

Hi Peter,

On Thu, Sep 22, 2022 at 7:48 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Wed, Sep 21, 2022 at 03:00:31PM -0700, Namhyung Kim wrote:
> > Use the new sample_flags to indicate whether the addr field is filled by
> > the PMU driver.  As most PMU drivers pass 0, it can set the flag only if
> > it has a non-zero value.  And use 0 in perf_sample_output() if it's not
> > filled already.
>
> So no objection to the general idea; just a question
>
> > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> > index 368bdc4f563f..f4a13579b0e8 100644
> > --- a/include/linux/perf_event.h
> > +++ b/include/linux/perf_event.h
> > @@ -1028,7 +1028,6 @@ struct perf_sample_data {
> >        * minimize the cachelines touched.
> >        */
> >       u64                             sample_flags;
> > -     u64                             addr;
> >       struct perf_raw_record          *raw;
> >       u64                             period;
> >
> > @@ -1040,6 +1039,7 @@ struct perf_sample_data {
> >       union perf_sample_weight        weight;
> >       union  perf_mem_data_src        data_src;
> >       u64                             txn;
> > +     u64                             addr;
> >
> >       u64                             type;
> >       u64                             ip;
>
> Is there a reason you placed the variable where you did?

No I just followed the previous change.

>
> I'm thinking we should look at what perf-tool thinks is the common set
> of SAMPLE flags and make sure those fields are grouped in as little
> cachelines as possible.
>
> Things like @ip and @type, which are basically *always* set, should
> definitely be on top, no?

Yes, you're right.  With this change we can move the optional fields
and group the common fields on top - like ip, period, pid and so on.

Will send a patch to do the move on top of this, ok?

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH] perf: Change the layout of perf_sample_data
  2022-09-22 16:32   ` Namhyung Kim
@ 2022-09-22 20:55     ` Namhyung Kim
  2022-09-23  7:45     ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
  1 sibling, 0 replies; 25+ messages in thread
From: Namhyung Kim @ 2022-09-22 20:55 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

With recent change, it can set fields only if it's actually used.
Change the data layout so that it can have commonly used fields together
in a cache line boundary.  The main user (the perf tools) sets the
IP, TID, TIME, PERIOD always.  Also group relevant fields like addr,
phys_addr and data_page_size.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 include/linux/perf_event.h | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index e9b151cde491..8c16dae6e6bb 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1023,25 +1023,13 @@ extern u64 perf_event_read_value(struct perf_event *event,
 
 
 struct perf_sample_data {
-	/*
-	 * Fields set by perf_sample_data_init(), group so as to
-	 * minimize the cachelines touched.
-	 */
 	u64				sample_flags;
 	u64				period;
-
+	u64				type;
 	/*
-	 * The other fields, optionally {set,used} by
-	 * perf_{prepare,output}_sample().
+	 * Fields set commonly by perf tools, group so as to
+	 * minimize the cachelines touched.
 	 */
-	struct perf_branch_stack	*br_stack;
-	union perf_sample_weight	weight;
-	union  perf_mem_data_src	data_src;
-	u64				txn;
-	u64				addr;
-	struct perf_raw_record		*raw;
-
-	u64				type;
 	u64				ip;
 	struct {
 		u32	pid;
@@ -1049,22 +1037,33 @@ struct perf_sample_data {
 	}				tid_entry;
 	u64				time;
 	u64				id;
-	u64				stream_id;
 	struct {
 		u32	cpu;
 		u32	reserved;
 	}				cpu_entry;
+
+	/*
+	 * The other fields, optionally {set,used} by
+	 * perf_{prepare,output}_sample().
+	 */
 	struct perf_callchain_entry	*callchain;
-	u64				aux_size;
+	struct perf_raw_record		*raw;
+	struct perf_branch_stack	*br_stack;
+	union perf_sample_weight	weight;
+	union  perf_mem_data_src	data_src;
+	u64				txn;
 
 	struct perf_regs		regs_user;
 	struct perf_regs		regs_intr;
 	u64				stack_user_size;
 
-	u64				phys_addr;
+	u64				stream_id;
 	u64				cgroup;
+	u64				addr;
+	u64				phys_addr;
 	u64				data_page_size;
 	u64				code_page_size;
+	u64				aux_size;
 } ____cacheline_aligned;
 
 /* default value for data source */
-- 
2.37.3.998.g577e59143f-goog


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 1/2] perf: Use sample_flags for addr
  2022-09-22 16:32   ` Namhyung Kim
  2022-09-22 20:55     ` [PATCH] perf: Change the layout of perf_sample_data Namhyung Kim
@ 2022-09-23  7:45     ` Peter Zijlstra
  1 sibling, 0 replies; 25+ messages in thread
From: Peter Zijlstra @ 2022-09-23  7:45 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Arnaldo Carvalho de Melo, Jiri Olsa, LKML, Song Liu,
	Ravi Bangoria, Stephane Eranian, Kan Liang

On Thu, Sep 22, 2022 at 09:32:06AM -0700, Namhyung Kim wrote:

> Will send a patch to do the move on top of this, ok?

Yes, thanks!

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [tip: perf/core] perf: Use sample_flags for raw_data
  2022-09-21 22:00 ` [PATCH 2/2] perf: Use sample_flags for raw_data Namhyung Kim
@ 2022-09-28  6:57   ` tip-bot2 for Namhyung Kim
  2022-10-06 16:00     ` [PATCH] " Sumanth Korikkar
  2022-10-19 10:44     ` [tip: perf/core] perf: Use sample_flags for raw_data Athira Rajeev
  0 siblings, 2 replies; 25+ messages in thread
From: tip-bot2 for Namhyung Kim @ 2022-09-28  6:57 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Namhyung Kim, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     838d9bb62d132ec3baf1b5aba2e95ef9a7a9a3cd
Gitweb:        https://git.kernel.org/tip/838d9bb62d132ec3baf1b5aba2e95ef9a7a9a3cd
Author:        Namhyung Kim <namhyung@kernel.org>
AuthorDate:    Wed, 21 Sep 2022 15:00:32 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 27 Sep 2022 22:50:24 +02:00

perf: Use sample_flags for raw_data

Use the new sample_flags to indicate whether the raw data field is
filled by the PMU driver.  Although it could check with the NULL,
follow the same rule with other fields.

Remove the raw field from the perf_sample_data_init() to minimize
the number of cache lines touched.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220921220032.2858517-2-namhyung@kernel.org
---
 arch/s390/kernel/perf_cpum_cf.c    | 1 +
 arch/s390/kernel/perf_pai_crypto.c | 1 +
 arch/x86/events/amd/ibs.c          | 1 +
 include/linux/perf_event.h         | 5 ++---
 kernel/events/core.c               | 3 ++-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index f7dd3c8..f043a7f 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -664,6 +664,7 @@ static int cfdiag_push_sample(struct perf_event *event,
 		raw.frag.data = cpuhw->stop;
 		raw.size = raw.frag.size;
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	overflow = perf_event_overflow(event, &data, &regs);
diff --git a/arch/s390/kernel/perf_pai_crypto.c b/arch/s390/kernel/perf_pai_crypto.c
index b38b4ae..6826e2a 100644
--- a/arch/s390/kernel/perf_pai_crypto.c
+++ b/arch/s390/kernel/perf_pai_crypto.c
@@ -366,6 +366,7 @@ static int paicrypt_push_sample(void)
 		raw.frag.data = cpump->save;
 		raw.size = raw.frag.size;
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	overflow = perf_event_overflow(event, &data, &regs);
diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
index ce5720b..c29a006 100644
--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -781,6 +781,7 @@ fail:
 			},
 		};
 		data.raw = &raw;
+		data.sample_flags |= PERF_SAMPLE_RAW;
 	}
 
 	/*
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index f4a1357..e9b151c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1028,7 +1028,6 @@ struct perf_sample_data {
 	 * minimize the cachelines touched.
 	 */
 	u64				sample_flags;
-	struct perf_raw_record		*raw;
 	u64				period;
 
 	/*
@@ -1040,6 +1039,7 @@ struct perf_sample_data {
 	union  perf_mem_data_src	data_src;
 	u64				txn;
 	u64				addr;
+	struct perf_raw_record		*raw;
 
 	u64				type;
 	u64				ip;
@@ -1078,8 +1078,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
 					 u64 addr, u64 period)
 {
 	/* remaining struct members initialized in perf_prepare_sample() */
-	data->sample_flags = 0;
-	data->raw  = NULL;
+	data->sample_flags = PERF_SAMPLE_PERIOD;
 	data->period = period;
 
 	if (addr) {
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a91f74d..04e19a8 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7332,7 +7332,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 		struct perf_raw_record *raw = data->raw;
 		int size;
 
-		if (raw) {
+		if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) {
 			struct perf_raw_frag *frag = &raw->frag;
 			u32 sum = 0;
 
@@ -7348,6 +7348,7 @@ void perf_prepare_sample(struct perf_event_header *header,
 			frag->pad = raw->size - sum;
 		} else {
 			size = sizeof(u64);
+			data->raw = NULL;
 		}
 
 		header->size += size;

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [tip: perf/core] perf: Use sample_flags for addr
  2022-09-21 22:00 [PATCH 1/2] perf: Use sample_flags for addr Namhyung Kim
  2022-09-21 22:00 ` [PATCH 2/2] perf: Use sample_flags for raw_data Namhyung Kim
  2022-09-22 14:48 ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
@ 2022-09-28  6:57 ` tip-bot2 for Namhyung Kim
  2 siblings, 0 replies; 25+ messages in thread
From: tip-bot2 for Namhyung Kim @ 2022-09-28  6:57 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Namhyung Kim, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     7b084630153152239d84990ac4540c2dd360186f
Gitweb:        https://git.kernel.org/tip/7b084630153152239d84990ac4540c2dd360186f
Author:        Namhyung Kim <namhyung@kernel.org>
AuthorDate:    Wed, 21 Sep 2022 15:00:31 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 27 Sep 2022 22:50:24 +02:00

perf: Use sample_flags for addr

Use the new sample_flags to indicate whether the addr field is filled by
the PMU driver.  As most PMU drivers pass 0, it can set the flag only if
it has a non-zero value.  And use 0 in perf_sample_output() if it's not
filled already.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220921220032.2858517-1-namhyung@kernel.org
---
 arch/x86/events/intel/ds.c | 8 ++++++--
 include/linux/perf_event.h | 8 ++++++--
 kernel/events/core.c       | 5 +++++
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 4ba6ab6..d2e9ff1 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -1621,8 +1621,10 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event,
 
 
 	if ((sample_type & PERF_SAMPLE_ADDR_TYPE) &&
-	    x86_pmu.intel_cap.pebs_format >= 1)
+	    x86_pmu.intel_cap.pebs_format >= 1) {
 		data->addr = pebs->dla;
+		data->sample_flags |= PERF_SAMPLE_ADDR;
+	}
 
 	if (x86_pmu.intel_cap.pebs_format >= 2) {
 		/* Only set the TSX weight when no memory weight. */
@@ -1783,8 +1785,10 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event,
 			data->sample_flags |= PERF_SAMPLE_DATA_SRC;
 		}
 
-		if (sample_type & PERF_SAMPLE_ADDR_TYPE)
+		if (sample_type & PERF_SAMPLE_ADDR_TYPE) {
 			data->addr = meminfo->address;
+			data->sample_flags |= PERF_SAMPLE_ADDR;
+		}
 
 		if (sample_type & PERF_SAMPLE_TRANSACTION) {
 			data->txn = intel_get_tsx_transaction(meminfo->tsx_tuning,
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 368bdc4..f4a1357 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1028,7 +1028,6 @@ struct perf_sample_data {
 	 * minimize the cachelines touched.
 	 */
 	u64				sample_flags;
-	u64				addr;
 	struct perf_raw_record		*raw;
 	u64				period;
 
@@ -1040,6 +1039,7 @@ struct perf_sample_data {
 	union perf_sample_weight	weight;
 	union  perf_mem_data_src	data_src;
 	u64				txn;
+	u64				addr;
 
 	u64				type;
 	u64				ip;
@@ -1079,9 +1079,13 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
 {
 	/* remaining struct members initialized in perf_prepare_sample() */
 	data->sample_flags = 0;
-	data->addr = addr;
 	data->raw  = NULL;
 	data->period = period;
+
+	if (addr) {
+		data->addr = addr;
+		data->sample_flags |= PERF_SAMPLE_ADDR;
+	}
 }
 
 /*
diff --git a/kernel/events/core.c b/kernel/events/core.c
index c07e9a3..a91f74d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7414,6 +7414,11 @@ void perf_prepare_sample(struct perf_event_header *header,
 	if (filtered_sample_type & PERF_SAMPLE_TRANSACTION)
 		data->txn = 0;
 
+	if (sample_type & (PERF_SAMPLE_ADDR | PERF_SAMPLE_PHYS_ADDR | PERF_SAMPLE_DATA_PAGE_SIZE)) {
+		if (filtered_sample_type & PERF_SAMPLE_ADDR)
+			data->addr = 0;
+	}
+
 	if (sample_type & PERF_SAMPLE_REGS_INTR) {
 		/* regs dump ABI info */
 		int size = sizeof(u64);

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH] Re: [tip: perf/core] perf: Use sample_flags for raw_data
  2022-09-28  6:57   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
@ 2022-10-06 16:00     ` Sumanth Korikkar
  2022-10-06 17:12       ` Namhyung Kim
  2022-10-06 18:58       ` Jiri Olsa
  2022-10-19 10:44     ` [tip: perf/core] perf: Use sample_flags for raw_data Athira Rajeev
  1 sibling, 2 replies; 25+ messages in thread
From: Sumanth Korikkar @ 2022-10-06 16:00 UTC (permalink / raw)
  To: tip-bot2
  Cc: linux-kernel, linux-tip-commits, namhyung, peterz, x86, iii, gor,
	hca, svens, tmricht, bpf, Sumanth Korikkar

Hi,

This causes segfaults.

Steps to recreate:
*  Run ./samples/bpf/trace_output
BUG pid 9 cookie 1001000000004 sized 4
BUG pid 9 cookie 1001000000004 sized 4
BUG pid 9 cookie 1001000000004 sized 4
Segmentation fault (core dumped)

Problem:
* The following commit sets data->raw to NULL, when the raw data is not filled
by PMU driver. This leads to stale data.
   
* raw data could also be filled by bpf_perf_event_output(), bpf_event_output()
...
 686         perf_sample_data_init(sd, 0, 0);
 687         sd->raw = &raw;
 688
 689         err = __bpf_perf_event_output(regs, map, flags, sd);
...

* The below patch eliminates segfaults. However, contradicts with
the description mentioned in this commit (Filled by only PMU driver).
  
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 49fb9ec8366d..1ed08967fb97 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
 
        perf_sample_data_init(sd, 0, 0);
        sd->raw = &raw;
+       sd->sample_flags |= PERF_SAMPLE_RAW;
 
        err = __bpf_perf_event_output(regs, map, flags, sd);
 
@@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
        perf_fetch_caller_regs(regs);
        perf_sample_data_init(sd, 0, 0);
        sd->raw = &raw;
+       sd->sample_flags |= PERF_SAMPLE_RAW;
 
        ret = __bpf_perf_event_output(regs, map, flags, sd);
 out:
  
--
Thanks,
Sumanth

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH] Re: [tip: perf/core] perf: Use sample_flags for raw_data
  2022-10-06 16:00     ` [PATCH] " Sumanth Korikkar
@ 2022-10-06 17:12       ` Namhyung Kim
  2022-10-06 18:58       ` Jiri Olsa
  1 sibling, 0 replies; 25+ messages in thread
From: Namhyung Kim @ 2022-10-06 17:12 UTC (permalink / raw)
  To: Sumanth Korikkar
  Cc: tip-bot2, linux-kernel, linux-tip-commits, peterz, x86, iii, gor,
	hca, svens, tmricht, bpf

Hello,

On Thu, Oct 6, 2022 at 9:01 AM Sumanth Korikkar <sumanthk@linux.ibm.com> wrote:
>
> Hi,
>
> This causes segfaults.
>
> Steps to recreate:
> *  Run ./samples/bpf/trace_output
> BUG pid 9 cookie 1001000000004 sized 4
> BUG pid 9 cookie 1001000000004 sized 4
> BUG pid 9 cookie 1001000000004 sized 4
> Segmentation fault (core dumped)
>
> Problem:
> * The following commit sets data->raw to NULL, when the raw data is not filled
> by PMU driver. This leads to stale data.
>
> * raw data could also be filled by bpf_perf_event_output(), bpf_event_output()
> ...
>  686         perf_sample_data_init(sd, 0, 0);
>  687         sd->raw = &raw;
>  688
>  689         err = __bpf_perf_event_output(regs, map, flags, sd);
> ...
>
> * The below patch eliminates segfaults. However, contradicts with
> the description mentioned in this commit (Filled by only PMU driver).

Thank you for the fix.  Don't worry about the description - it said
it's usually filled by PMU drivers and it should be fine as long as
you set the sample flags after filling the raw data.

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 49fb9ec8366d..1ed08967fb97 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
>
>         perf_sample_data_init(sd, 0, 0);
>         sd->raw = &raw;
> +       sd->sample_flags |= PERF_SAMPLE_RAW;
>
>         err = __bpf_perf_event_output(regs, map, flags, sd);
>
> @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
>         perf_fetch_caller_regs(regs);
>         perf_sample_data_init(sd, 0, 0);
>         sd->raw = &raw;
> +       sd->sample_flags |= PERF_SAMPLE_RAW;
>
>         ret = __bpf_perf_event_output(regs, map, flags, sd);
>  out:
>
> --
> Thanks,
> Sumanth

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] Re: [tip: perf/core] perf: Use sample_flags for raw_data
  2022-10-06 16:00     ` [PATCH] " Sumanth Korikkar
  2022-10-06 17:12       ` Namhyung Kim
@ 2022-10-06 18:58       ` Jiri Olsa
  2022-10-07  8:13         ` [PATCH] bpf: fix sample_flags for bpf_perf_event_output Sumanth Korikkar
  1 sibling, 1 reply; 25+ messages in thread
From: Jiri Olsa @ 2022-10-06 18:58 UTC (permalink / raw)
  To: Sumanth Korikkar
  Cc: tip-bot2, linux-kernel, linux-tip-commits, namhyung, peterz, x86,
	iii, gor, hca, svens, tmricht, bpf

On Thu, Oct 06, 2022 at 06:00:44PM +0200, Sumanth Korikkar wrote:
> Hi,
> 
> This causes segfaults.
> 
> Steps to recreate:
> *  Run ./samples/bpf/trace_output
> BUG pid 9 cookie 1001000000004 sized 4
> BUG pid 9 cookie 1001000000004 sized 4
> BUG pid 9 cookie 1001000000004 sized 4
> Segmentation fault (core dumped)
> 
> Problem:
> * The following commit sets data->raw to NULL, when the raw data is not filled
> by PMU driver. This leads to stale data.
>    
> * raw data could also be filled by bpf_perf_event_output(), bpf_event_output()
> ...
>  686         perf_sample_data_init(sd, 0, 0);
>  687         sd->raw = &raw;
>  688
>  689         err = __bpf_perf_event_output(regs, map, flags, sd);
> ...
> 
> * The below patch eliminates segfaults. However, contradicts with
> the description mentioned in this commit (Filled by only PMU driver).

hi,
could you please resend the patch with formal changelog and Fixes tag?

thanks,
jirka

>   
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 49fb9ec8366d..1ed08967fb97 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
>  
>         perf_sample_data_init(sd, 0, 0);
>         sd->raw = &raw;
> +       sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>         err = __bpf_perf_event_output(regs, map, flags, sd);
>  
> @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
>         perf_fetch_caller_regs(regs);
>         perf_sample_data_init(sd, 0, 0);
>         sd->raw = &raw;
> +       sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>         ret = __bpf_perf_event_output(regs, map, flags, sd);
>  out:
>   
> --
> Thanks,
> Sumanth

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-06 18:58       ` Jiri Olsa
@ 2022-10-07  8:13         ` Sumanth Korikkar
  2022-10-07  9:45           ` Jiri Olsa
                             ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Sumanth Korikkar @ 2022-10-07  8:13 UTC (permalink / raw)
  To: olsajiri
  Cc: bpf, gor, hca, iii, linux-kernel, linux-tip-commits, namhyung,
	peterz, sumanthk, svens, tip-bot2, tmricht, x86

* Raw data is also filled by bpf_perf_event_output.
* Add sample_flags to indicate raw data.
* This eliminates the segfaults as shown below:
  Run ./samples/bpf/trace_output
  BUG pid 9 cookie 1001000000004 sized 4
  BUG pid 9 cookie 1001000000004 sized 4
  BUG pid 9 cookie 1001000000004 sized 4
  Segmentation fault (core dumped)

Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 49fb9ec8366d..1ed08967fb97 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
 
 	perf_sample_data_init(sd, 0, 0);
 	sd->raw = &raw;
+	sd->sample_flags |= PERF_SAMPLE_RAW;
 
 	err = __bpf_perf_event_output(regs, map, flags, sd);
 
@@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
 	perf_fetch_caller_regs(regs);
 	perf_sample_data_init(sd, 0, 0);
 	sd->raw = &raw;
+	sd->sample_flags |= PERF_SAMPLE_RAW;
 
 	ret = __bpf_perf_event_output(regs, map, flags, sd);
 out:
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-07  8:13         ` [PATCH] bpf: fix sample_flags for bpf_perf_event_output Sumanth Korikkar
@ 2022-10-07  9:45           ` Jiri Olsa
  2022-10-07 15:18             ` Peter Zijlstra
  2022-10-17 14:45           ` [tip: perf/urgent] bpf: Fix " tip-bot2 for Sumanth Korikkar
  2022-10-17 19:27           ` [PATCH] bpf: fix " SeongJae Park
  2 siblings, 1 reply; 25+ messages in thread
From: Jiri Olsa @ 2022-10-07  9:45 UTC (permalink / raw)
  To: Sumanth Korikkar, peterz
  Cc: olsajiri, bpf, gor, hca, iii, linux-kernel, linux-tip-commits,
	namhyung, svens, tip-bot2, tmricht, x86

On Fri, Oct 07, 2022 at 10:13:27AM +0200, Sumanth Korikkar wrote:
> * Raw data is also filled by bpf_perf_event_output.
> * Add sample_flags to indicate raw data.
> * This eliminates the segfaults as shown below:
>   Run ./samples/bpf/trace_output
>   BUG pid 9 cookie 1001000000004 sized 4
>   BUG pid 9 cookie 1001000000004 sized 4
>   BUG pid 9 cookie 1001000000004 sized 4
>   Segmentation fault (core dumped)
> 
> Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> Acked-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

Peter,
I think this should go through your tree again?
bpf-next/master does not have sample_flags merged yet

thanks,
jirka

> ---
>  kernel/trace/bpf_trace.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 49fb9ec8366d..1ed08967fb97 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
>  
>  	perf_sample_data_init(sd, 0, 0);
>  	sd->raw = &raw;
> +	sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>  	err = __bpf_perf_event_output(regs, map, flags, sd);
>  
> @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
>  	perf_fetch_caller_regs(regs);
>  	perf_sample_data_init(sd, 0, 0);
>  	sd->raw = &raw;
> +	sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>  	ret = __bpf_perf_event_output(regs, map, flags, sd);
>  out:
> -- 
> 2.36.1
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-07  9:45           ` Jiri Olsa
@ 2022-10-07 15:18             ` Peter Zijlstra
  2022-10-19  4:57               ` Alexei Starovoitov
  0 siblings, 1 reply; 25+ messages in thread
From: Peter Zijlstra @ 2022-10-07 15:18 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Sumanth Korikkar, bpf, gor, hca, iii, linux-kernel,
	linux-tip-commits, namhyung, svens, tip-bot2, tmricht, x86

On Fri, Oct 07, 2022 at 11:45:36AM +0200, Jiri Olsa wrote:
> On Fri, Oct 07, 2022 at 10:13:27AM +0200, Sumanth Korikkar wrote:
> > * Raw data is also filled by bpf_perf_event_output.
> > * Add sample_flags to indicate raw data.
> > * This eliminates the segfaults as shown below:
> >   Run ./samples/bpf/trace_output
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   Segmentation fault (core dumped)
> > 
> > Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> Peter,
> I think this should go through your tree again?
> bpf-next/master does not have sample_flags merged yet

Yep can do. I'll line it up in perf/urgent (Ingo just send out
perf/core).

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [tip: perf/urgent] bpf: Fix sample_flags for bpf_perf_event_output
  2022-10-07  8:13         ` [PATCH] bpf: fix sample_flags for bpf_perf_event_output Sumanth Korikkar
  2022-10-07  9:45           ` Jiri Olsa
@ 2022-10-17 14:45           ` tip-bot2 for Sumanth Korikkar
  2022-10-17 19:27           ` [PATCH] bpf: fix " SeongJae Park
  2 siblings, 0 replies; 25+ messages in thread
From: tip-bot2 for Sumanth Korikkar @ 2022-10-17 14:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sumanth Korikkar, Peter Zijlstra (Intel),
	Namhyung Kim, x86, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     21da7472a040420f2dc624ffec70291a72c5d6a6
Gitweb:        https://git.kernel.org/tip/21da7472a040420f2dc624ffec70291a72c5d6a6
Author:        Sumanth Korikkar <sumanthk@linux.ibm.com>
AuthorDate:    Fri, 07 Oct 2022 10:13:27 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 17 Oct 2022 16:32:06 +02:00

bpf: Fix sample_flags for bpf_perf_event_output

* Raw data is also filled by bpf_perf_event_output.
* Add sample_flags to indicate raw data.
* This eliminates the segfaults as shown below:
  Run ./samples/bpf/trace_output
  BUG pid 9 cookie 1001000000004 sized 4
  BUG pid 9 cookie 1001000000004 sized 4
  BUG pid 9 cookie 1001000000004 sized 4
  Segmentation fault (core dumped)

Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/r/20221007081327.1047552-1-sumanthk@linux.ibm.com
---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 49fb9ec..1ed0896 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
 
 	perf_sample_data_init(sd, 0, 0);
 	sd->raw = &raw;
+	sd->sample_flags |= PERF_SAMPLE_RAW;
 
 	err = __bpf_perf_event_output(regs, map, flags, sd);
 
@@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
 	perf_fetch_caller_regs(regs);
 	perf_sample_data_init(sd, 0, 0);
 	sd->raw = &raw;
+	sd->sample_flags |= PERF_SAMPLE_RAW;
 
 	ret = __bpf_perf_event_output(regs, map, flags, sd);
 out:

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-07  8:13         ` [PATCH] bpf: fix sample_flags for bpf_perf_event_output Sumanth Korikkar
  2022-10-07  9:45           ` Jiri Olsa
  2022-10-17 14:45           ` [tip: perf/urgent] bpf: Fix " tip-bot2 for Sumanth Korikkar
@ 2022-10-17 19:27           ` SeongJae Park
  2022-10-17 22:52             ` Namhyung Kim
  2 siblings, 1 reply; 25+ messages in thread
From: SeongJae Park @ 2022-10-17 19:27 UTC (permalink / raw)
  To: Sumanth Korikkar
  Cc: olsajiri, bpf, gor, hca, iii, linux-kernel, linux-tip-commits,
	namhyung, peterz, svens, tip-bot2, tmricht, x86

Hello,


The commit that this patch is fixing[1] also causes yet another segfault for
'perf-script' of tracepoint records.  For example:

    $ sudo timeout 3 perf record -e exceptions:page_fault_user
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.228 MB perf.data (74 samples) ]
    $ sudo perf script
    Segmentation fault

Reverting this patch and the original bug commit[1] fixes the issue.  I haven't
deep dive yet because I'm not familiar with this area.  Anybody has any idea
about this?

[1] 838d9bb62d13 ("perf: Use sample_flags for raw_data")


Thanks,
SJ

On Fri, 7 Oct 2022 10:13:27 +0200 Sumanth Korikkar <sumanthk@linux.ibm.com> wrote:

> * Raw data is also filled by bpf_perf_event_output.
> * Add sample_flags to indicate raw data.
> * This eliminates the segfaults as shown below:
>   Run ./samples/bpf/trace_output
>   BUG pid 9 cookie 1001000000004 sized 4
>   BUG pid 9 cookie 1001000000004 sized 4
>   BUG pid 9 cookie 1001000000004 sized 4
>   Segmentation fault (core dumped)
> 
> Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> Acked-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> ---
>  kernel/trace/bpf_trace.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 49fb9ec8366d..1ed08967fb97 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
>  
>  	perf_sample_data_init(sd, 0, 0);
>  	sd->raw = &raw;
> +	sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>  	err = __bpf_perf_event_output(regs, map, flags, sd);
>  
> @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
>  	perf_fetch_caller_regs(regs);
>  	perf_sample_data_init(sd, 0, 0);
>  	sd->raw = &raw;
> +	sd->sample_flags |= PERF_SAMPLE_RAW;
>  
>  	ret = __bpf_perf_event_output(regs, map, flags, sd);
>  out:
> -- 
> 2.36.1

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-17 19:27           ` [PATCH] bpf: fix " SeongJae Park
@ 2022-10-17 22:52             ` Namhyung Kim
  2022-10-17 23:35               ` SeongJae Park
  0 siblings, 1 reply; 25+ messages in thread
From: Namhyung Kim @ 2022-10-17 22:52 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Sumanth Korikkar, olsajiri, bpf, gor, hca, iii, linux-kernel,
	linux-tip-commits, peterz, svens, tip-bot2, tmricht, x86

Hi SeongJae,

On Mon, Oct 17, 2022 at 12:27 PM SeongJae Park <sj@kernel.org> wrote:
>
> Hello,
>
>
> The commit that this patch is fixing[1] also causes yet another segfault for
> 'perf-script' of tracepoint records.  For example:
>
>     $ sudo timeout 3 perf record -e exceptions:page_fault_user
>     [ perf record: Woken up 1 times to write data ]
>     [ perf record: Captured and wrote 0.228 MB perf.data (74 samples) ]
>     $ sudo perf script
>     Segmentation fault
>
> Reverting this patch and the original bug commit[1] fixes the issue.  I haven't
> deep dive yet because I'm not familiar with this area.  Anybody has any idea
> about this?
>
> [1] 838d9bb62d13 ("perf: Use sample_flags for raw_data")

Sorry for the trouble.  I think you also need to apply the below:

https://lore.kernel.org/r/20221012143857.48198-1-james.clark@arm.com

Thanks,
Namhyung

>
> On Fri, 7 Oct 2022 10:13:27 +0200 Sumanth Korikkar <sumanthk@linux.ibm.com> wrote:
>
> > * Raw data is also filled by bpf_perf_event_output.
> > * Add sample_flags to indicate raw data.
> > * This eliminates the segfaults as shown below:
> >   Run ./samples/bpf/trace_output
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   BUG pid 9 cookie 1001000000004 sized 4
> >   Segmentation fault (core dumped)
> >
> > Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> > ---
> >  kernel/trace/bpf_trace.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index 49fb9ec8366d..1ed08967fb97 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -687,6 +687,7 @@ BPF_CALL_5(bpf_perf_event_output, struct pt_regs *, regs, struct bpf_map *, map,
> >
> >       perf_sample_data_init(sd, 0, 0);
> >       sd->raw = &raw;
> > +     sd->sample_flags |= PERF_SAMPLE_RAW;
> >
> >       err = __bpf_perf_event_output(regs, map, flags, sd);
> >
> > @@ -745,6 +746,7 @@ u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
> >       perf_fetch_caller_regs(regs);
> >       perf_sample_data_init(sd, 0, 0);
> >       sd->raw = &raw;
> > +     sd->sample_flags |= PERF_SAMPLE_RAW;
> >
> >       ret = __bpf_perf_event_output(regs, map, flags, sd);
> >  out:
> > --
> > 2.36.1

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-17 22:52             ` Namhyung Kim
@ 2022-10-17 23:35               ` SeongJae Park
  0 siblings, 0 replies; 25+ messages in thread
From: SeongJae Park @ 2022-10-17 23:35 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: SeongJae Park, Sumanth Korikkar, olsajiri, bpf, gor, hca, iii,
	linux-kernel, linux-tip-commits, peterz, svens, tip-bot2,
	tmricht, x86

On Mon, 17 Oct 2022 15:52:15 -0700 Namhyung Kim <namhyung@kernel.org> wrote:

> Hi SeongJae,
> 
> On Mon, Oct 17, 2022 at 12:27 PM SeongJae Park <sj@kernel.org> wrote:
> >
> > Hello,
> >
> >
> > The commit that this patch is fixing[1] also causes yet another segfault for
> > 'perf-script' of tracepoint records.  For example:
> >
> >     $ sudo timeout 3 perf record -e exceptions:page_fault_user
> >     [ perf record: Woken up 1 times to write data ]
> >     [ perf record: Captured and wrote 0.228 MB perf.data (74 samples) ]
> >     $ sudo perf script
> >     Segmentation fault
> >
> > Reverting this patch and the original bug commit[1] fixes the issue.  I haven't
> > deep dive yet because I'm not familiar with this area.  Anybody has any idea
> > about this?
> >
> > [1] 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> 
> Sorry for the trouble.

No problem.

> I think you also need to apply the below:
> 
> https://lore.kernel.org/r/20221012143857.48198-1-james.clark@arm.com

Thank you for this nice answer.  I confirmed that this fixes my issue.


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-07 15:18             ` Peter Zijlstra
@ 2022-10-19  4:57               ` Alexei Starovoitov
  2022-10-21  1:36                 ` Alexei Starovoitov
  0 siblings, 1 reply; 25+ messages in thread
From: Alexei Starovoitov @ 2022-10-19  4:57 UTC (permalink / raw)
  To: Peter Zijlstra, Linus Torvalds
  Cc: Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik, Heiko Carstens,
	Ilya Leoshkevich, LKML, Namhyung Kim, Sven Schnelle,
	Thomas Richter, X86 ML, Daniel Borkmann

On Fri, Oct 7, 2022 at 8:31 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Oct 07, 2022 at 11:45:36AM +0200, Jiri Olsa wrote:
> > On Fri, Oct 07, 2022 at 10:13:27AM +0200, Sumanth Korikkar wrote:
> > > * Raw data is also filled by bpf_perf_event_output.
> > > * Add sample_flags to indicate raw data.
> > > * This eliminates the segfaults as shown below:
> > >   Run ./samples/bpf/trace_output
> > >   BUG pid 9 cookie 1001000000004 sized 4
> > >   BUG pid 9 cookie 1001000000004 sized 4
> > >   BUG pid 9 cookie 1001000000004 sized 4
> > >   Segmentation fault (core dumped)
> > >
> > > Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> > > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > > Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> >
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> >
> > Peter,
> > I think this should go through your tree again?
> > bpf-next/master does not have sample_flags merged yet
>
> Yep can do. I'll line it up in perf/urgent (Ingo just send out
> perf/core).

Peter,

Could you please hurry up. 11 days have passed.

This issue affects everyone the hard way now after merging
all the trees: tip -> linus -> net-next -> bpf-next.
The BPF CI is red right now with 5 tests failing because
this fix is still missing.
It's causing a headache to maintainers and developers.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [tip: perf/core] perf: Use sample_flags for raw_data
  2022-09-28  6:57   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
  2022-10-06 16:00     ` [PATCH] " Sumanth Korikkar
@ 2022-10-19 10:44     ` Athira Rajeev
  1 sibling, 0 replies; 25+ messages in thread
From: Athira Rajeev @ 2022-10-19 10:44 UTC (permalink / raw)
  To: LKML, Namhyung Kim; +Cc: linux-tip-commits, Peter Zijlstra (Intel), x86



> On 28-Sep-2022, at 12:27 PM, tip-bot2 for Namhyung Kim <tip-bot2@linutronix.de> wrote:
> 
> The following commit has been merged into the perf/core branch of tip:
> 
> Commit-ID:     838d9bb62d132ec3baf1b5aba2e95ef9a7a9a3cd
> Gitweb:        https://git.kernel.org/tip/838d9bb62d132ec3baf1b5aba2e95ef9a7a9a3cd
> Author:        Namhyung Kim <namhyung@kernel.org>
> AuthorDate:    Wed, 21 Sep 2022 15:00:32 -07:00
> Committer:     Peter Zijlstra <peterz@infradead.org>
> CommitterDate: Tue, 27 Sep 2022 22:50:24 +02:00
> 
> perf: Use sample_flags for raw_data
> 
> Use the new sample_flags to indicate whether the raw data field is
> filled by the PMU driver.  Although it could check with the NULL,
> follow the same rule with other fields.
> 
> Remove the raw field from the perf_sample_data_init() to minimize
> the number of cache lines touched.
> 
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lkml.kernel.org/r/20220921220032.2858517-2-namhyung@kernel.org

Hi Namhyung,

This commit ("perf: Use sample_flags for raw_data") added
PERF_SAMPLE_RAW check in perf_prepare_sample. To be in sync
while we output sample to memory, do we also need to add
similar check in perf_output_sample ? I am pasting change below.
Please share your thoughts.

From 46d874bc4a915dd710ddbc5198588cbb66d3ea8e Mon Sep 17 00:00:00 2001
From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Date: Wed, 19 Oct 2022 13:02:06 +0530
Subject: [PATCH] perf/core: Update sample_flags for raw_data in
 perf_output_sample

commit 838d9bb62d13 ("perf: Use sample_flags for raw_data")
added check for PERF_SAMPLE_RAW in sample_flags in
perf_prepare_sample(). But while copying the sample in memory,
the check for sample_flags is not added in perf_output_sample().
Fix adds the same in perf_output_sample as well.

Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ec3717003d5..daf387c75d33 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7099,7 +7099,7 @@ void perf_output_sample(struct perf_output_handle *handle,
 	if (sample_type & PERF_SAMPLE_RAW) {
 		struct perf_raw_record *raw = data->raw;
 
-		if (raw) {
+		if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) {
 			struct perf_raw_frag *frag = &raw->frag;
 
 			perf_output_put(handle, raw->size);
-- 
2.31.1

Thanks
Athira

> ---
> arch/s390/kernel/perf_cpum_cf.c    | 1 +
> arch/s390/kernel/perf_pai_crypto.c | 1 +
> arch/x86/events/amd/ibs.c          | 1 +
> include/linux/perf_event.h         | 5 ++---
> kernel/events/core.c               | 3 ++-
> 5 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
> index f7dd3c8..f043a7f 100644
> --- a/arch/s390/kernel/perf_cpum_cf.c
> +++ b/arch/s390/kernel/perf_cpum_cf.c
> @@ -664,6 +664,7 @@ static int cfdiag_push_sample(struct perf_event *event,
> 		raw.frag.data = cpuhw->stop;
> 		raw.size = raw.frag.size;
> 		data.raw = &raw;
> +		data.sample_flags |= PERF_SAMPLE_RAW;
> 	}
> 
> 	overflow = perf_event_overflow(event, &data, &regs);
> diff --git a/arch/s390/kernel/perf_pai_crypto.c b/arch/s390/kernel/perf_pai_crypto.c
> index b38b4ae..6826e2a 100644
> --- a/arch/s390/kernel/perf_pai_crypto.c
> +++ b/arch/s390/kernel/perf_pai_crypto.c
> @@ -366,6 +366,7 @@ static int paicrypt_push_sample(void)
> 		raw.frag.data = cpump->save;
> 		raw.size = raw.frag.size;
> 		data.raw = &raw;
> +		data.sample_flags |= PERF_SAMPLE_RAW;
> 	}
> 
> 	overflow = perf_event_overflow(event, &data, &regs);
> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
> index ce5720b..c29a006 100644
> --- a/arch/x86/events/amd/ibs.c
> +++ b/arch/x86/events/amd/ibs.c
> @@ -781,6 +781,7 @@ fail:
> 			},
> 		};
> 		data.raw = &raw;
> +		data.sample_flags |= PERF_SAMPLE_RAW;
> 	}
> 
> 	/*
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index f4a1357..e9b151c 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -1028,7 +1028,6 @@ struct perf_sample_data {
> 	 * minimize the cachelines touched.
> 	 */
> 	u64				sample_flags;
> -	struct perf_raw_record		*raw;
> 	u64				period;
> 
> 	/*
> @@ -1040,6 +1039,7 @@ struct perf_sample_data {
> 	union  perf_mem_data_src	data_src;
> 	u64				txn;
> 	u64				addr;
> +	struct perf_raw_record		*raw;
> 
> 	u64				type;
> 	u64				ip;
> @@ -1078,8 +1078,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
> 					 u64 addr, u64 period)
> {
> 	/* remaining struct members initialized in perf_prepare_sample() */
> -	data->sample_flags = 0;
> -	data->raw  = NULL;
> +	data->sample_flags = PERF_SAMPLE_PERIOD;
> 	data->period = period;
> 
> 	if (addr) {
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a91f74d..04e19a8 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -7332,7 +7332,7 @@ void perf_prepare_sample(struct perf_event_header *header,
> 		struct perf_raw_record *raw = data->raw;
> 		int size;
> 
> -		if (raw) {
> +		if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) {
> 			struct perf_raw_frag *frag = &raw->frag;
> 			u32 sum = 0;
> 
> @@ -7348,6 +7348,7 @@ void perf_prepare_sample(struct perf_event_header *header,
> 			frag->pad = raw->size - sum;
> 		} else {
> 			size = sizeof(u64);
> +			data->raw = NULL;
> 		}
> 
> 		header->size += size;


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-19  4:57               ` Alexei Starovoitov
@ 2022-10-21  1:36                 ` Alexei Starovoitov
  2022-10-23  1:16                   ` bpf+perf is still broken. Was: " Alexei Starovoitov
  0 siblings, 1 reply; 25+ messages in thread
From: Alexei Starovoitov @ 2022-10-21  1:36 UTC (permalink / raw)
  To: Peter Zijlstra, Linus Torvalds
  Cc: Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik, Heiko Carstens,
	Ilya Leoshkevich, LKML, Namhyung Kim, Sven Schnelle,
	Thomas Richter, X86 ML, Daniel Borkmann, Andrii Nakryiko,
	Jakub Kicinski, David S. Miller

Peter,

Another 2 days have passed and bpf side is still broken
due to the change that went during the merge window without
corresponding fix from the bpf side.
Looks like the patch is sitting in tip:perf/urgent.
Please send it to Linus asap.

We're not sending bpf fixes to avoid breaking bpf tree too.
We've worked around the issue in bpf CI for bpf-next tree only.
Developers still see failures when they run tests locally.

On Tue, Oct 18, 2022 at 9:57 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Fri, Oct 7, 2022 at 8:31 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Fri, Oct 07, 2022 at 11:45:36AM +0200, Jiri Olsa wrote:
> > > On Fri, Oct 07, 2022 at 10:13:27AM +0200, Sumanth Korikkar wrote:
> > > > * Raw data is also filled by bpf_perf_event_output.
> > > > * Add sample_flags to indicate raw data.
> > > > * This eliminates the segfaults as shown below:
> > > >   Run ./samples/bpf/trace_output
> > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > >   Segmentation fault (core dumped)
> > > >
> > > > Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> > > > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > > > Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> > >
> > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > >
> > > Peter,
> > > I think this should go through your tree again?
> > > bpf-next/master does not have sample_flags merged yet
> >
> > Yep can do. I'll line it up in perf/urgent (Ingo just send out
> > perf/core).
>
> Peter,
>
> Could you please hurry up. 11 days have passed.
>
> This issue affects everyone the hard way now after merging
> all the trees: tip -> linus -> net-next -> bpf-next.
> The BPF CI is red right now with 5 tests failing because
> this fix is still missing.
> It's causing a headache to maintainers and developers.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* bpf+perf is still broken. Was: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-21  1:36                 ` Alexei Starovoitov
@ 2022-10-23  1:16                   ` Alexei Starovoitov
  2022-10-23 16:55                     ` Linus Torvalds
  0 siblings, 1 reply; 25+ messages in thread
From: Alexei Starovoitov @ 2022-10-23  1:16 UTC (permalink / raw)
  To: Peter Zijlstra, Linus Torvalds
  Cc: Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik, Heiko Carstens,
	Ilya Leoshkevich, LKML, Namhyung Kim, Sven Schnelle,
	Thomas Richter, X86 ML, Daniel Borkmann, Andrii Nakryiko,
	Jakub Kicinski, David S. Miller

Another 2 days have passed and the fix is still not in the Linus's tree.

Peter,
whatever your excuse is for not sending tip:perf/urgent
this is not acceptable.

Linus,

please apply this fix directly:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=perf/urgent&id=21da7472a040420f2dc624ffec70291a72c5d6a6

or suggest the course of action.

It sucked to have such a breakage in rc1 and we don't want rc2
to stay broken.

Thanks

On Thu, Oct 20, 2022 at 6:36 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> Peter,
>
> Another 2 days have passed and bpf side is still broken
> due to the change that went during the merge window without
> corresponding fix from the bpf side.
> Looks like the patch is sitting in tip:perf/urgent.
> Please send it to Linus asap.
>
> We're not sending bpf fixes to avoid breaking bpf tree too.
> We've worked around the issue in bpf CI for bpf-next tree only.
> Developers still see failures when they run tests locally.
>
> On Tue, Oct 18, 2022 at 9:57 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Fri, Oct 7, 2022 at 8:31 AM Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Fri, Oct 07, 2022 at 11:45:36AM +0200, Jiri Olsa wrote:
> > > > On Fri, Oct 07, 2022 at 10:13:27AM +0200, Sumanth Korikkar wrote:
> > > > > * Raw data is also filled by bpf_perf_event_output.
> > > > > * Add sample_flags to indicate raw data.
> > > > > * This eliminates the segfaults as shown below:
> > > > >   Run ./samples/bpf/trace_output
> > > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > > >   BUG pid 9 cookie 1001000000004 sized 4
> > > > >   Segmentation fault (core dumped)
> > > > >
> > > > > Fixes: 838d9bb62d13 ("perf: Use sample_flags for raw_data")
> > > > > Acked-by: Namhyung Kim <namhyung@kernel.org>
> > > > > Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> > > >
> > > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > > >
> > > > Peter,
> > > > I think this should go through your tree again?
> > > > bpf-next/master does not have sample_flags merged yet
> > >
> > > Yep can do. I'll line it up in perf/urgent (Ingo just send out
> > > perf/core).
> >
> > Peter,
> >
> > Could you please hurry up. 11 days have passed.
> >
> > This issue affects everyone the hard way now after merging
> > all the trees: tip -> linus -> net-next -> bpf-next.
> > The BPF CI is red right now with 5 tests failing because
> > this fix is still missing.
> > It's causing a headache to maintainers and developers.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: bpf+perf is still broken. Was: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-23  1:16                   ` bpf+perf is still broken. Was: " Alexei Starovoitov
@ 2022-10-23 16:55                     ` Linus Torvalds
  2022-10-23 17:19                       ` Linus Torvalds
  0 siblings, 1 reply; 25+ messages in thread
From: Linus Torvalds @ 2022-10-23 16:55 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Peter Zijlstra, Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik,
	Heiko Carstens, Ilya Leoshkevich, LKML, Namhyung Kim,
	Sven Schnelle, Thomas Richter, X86 ML, Daniel Borkmann,
	Andrii Nakryiko, Jakub Kicinski, David S. Miller

On Sat, Oct 22, 2022 at 6:16 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> Linus,
>
> please apply this fix directly or suggest the course of action.

I have a pull request from Borislav with the fix that came in
overnight, so this should be all fixed in rc2.

                 Linus

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: bpf+perf is still broken. Was: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-23 16:55                     ` Linus Torvalds
@ 2022-10-23 17:19                       ` Linus Torvalds
  2022-10-23 17:28                         ` Alexei Starovoitov
  0 siblings, 1 reply; 25+ messages in thread
From: Linus Torvalds @ 2022-10-23 17:19 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Peter Zijlstra, Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik,
	Heiko Carstens, Ilya Leoshkevich, LKML, Namhyung Kim,
	Sven Schnelle, Thomas Richter, X86 ML, Daniel Borkmann,
	Andrii Nakryiko, Jakub Kicinski, David S. Miller

On Sun, Oct 23, 2022 at 9:55 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> I have a pull request from Borislav with the fix that came in
> overnight, so this should be all fixed in rc2.

.. and now it has moved from my inbox to my -git tree.

                   Linus

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: bpf+perf is still broken. Was: [PATCH] bpf: fix sample_flags for bpf_perf_event_output
  2022-10-23 17:19                       ` Linus Torvalds
@ 2022-10-23 17:28                         ` Alexei Starovoitov
  0 siblings, 0 replies; 25+ messages in thread
From: Alexei Starovoitov @ 2022-10-23 17:28 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Peter Zijlstra, Jiri Olsa, Sumanth Korikkar, bpf, Vasily Gorbik,
	Heiko Carstens, Ilya Leoshkevich, LKML, Namhyung Kim,
	Sven Schnelle, Thomas Richter, X86 ML, Daniel Borkmann,
	Andrii Nakryiko, Jakub Kicinski, David S. Miller

On Sun, Oct 23, 2022 at 10:20 AM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Sun, Oct 23, 2022 at 9:55 AM Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > I have a pull request from Borislav with the fix that came in
> > overnight, so this should be all fixed in rc2.
>
> .. and now it has moved from my inbox to my -git tree.

Great. Thank you.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2022-10-23 17:28 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 22:00 [PATCH 1/2] perf: Use sample_flags for addr Namhyung Kim
2022-09-21 22:00 ` [PATCH 2/2] perf: Use sample_flags for raw_data Namhyung Kim
2022-09-28  6:57   ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2022-10-06 16:00     ` [PATCH] " Sumanth Korikkar
2022-10-06 17:12       ` Namhyung Kim
2022-10-06 18:58       ` Jiri Olsa
2022-10-07  8:13         ` [PATCH] bpf: fix sample_flags for bpf_perf_event_output Sumanth Korikkar
2022-10-07  9:45           ` Jiri Olsa
2022-10-07 15:18             ` Peter Zijlstra
2022-10-19  4:57               ` Alexei Starovoitov
2022-10-21  1:36                 ` Alexei Starovoitov
2022-10-23  1:16                   ` bpf+perf is still broken. Was: " Alexei Starovoitov
2022-10-23 16:55                     ` Linus Torvalds
2022-10-23 17:19                       ` Linus Torvalds
2022-10-23 17:28                         ` Alexei Starovoitov
2022-10-17 14:45           ` [tip: perf/urgent] bpf: Fix " tip-bot2 for Sumanth Korikkar
2022-10-17 19:27           ` [PATCH] bpf: fix " SeongJae Park
2022-10-17 22:52             ` Namhyung Kim
2022-10-17 23:35               ` SeongJae Park
2022-10-19 10:44     ` [tip: perf/core] perf: Use sample_flags for raw_data Athira Rajeev
2022-09-22 14:48 ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
2022-09-22 16:32   ` Namhyung Kim
2022-09-22 20:55     ` [PATCH] perf: Change the layout of perf_sample_data Namhyung Kim
2022-09-23  7:45     ` [PATCH 1/2] perf: Use sample_flags for addr Peter Zijlstra
2022-09-28  6:57 ` [tip: perf/core] " tip-bot2 for Namhyung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).