linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
@ 2025-09-03 13:52 Arnaud Lecomte
  2025-09-03 13:53 ` Arnaud Lecomte
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Arnaud Lecomte @ 2025-09-03 13:52 UTC (permalink / raw)
  To: alexei.starovoitov, yonghong.song, song
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, martin.lau, sdf,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs, Arnaud Lecomte

A new helper function stack_map_calculate_max_depth() that
computes the max depth for a stackmap.

Changes in v2:
 - Removed the checking 'map_size % map_elem_size' from
   stack_map_calculate_max_depth
 - Changed stack_map_calculate_max_depth params name to be more generic

Changes in v3:
 - Changed map size param to size in max depth helper

Changes in v4:
 - Fixed indentation in max depth helper for args

Changes in v5:
 - Bound back trace_nr to num_elem in __bpf_get_stack
 - Make a copy of sysctl_perf_event_max_stack
   in stack_map_calculate_max_depth

Changes in v6:
 - Restrained max_depth computation only when required
 - Additional cleanup from Song in __bpf_get_stack

Link to v5: https://lore.kernel.org/all/20250826212229.143230-1-contact@arnaud-lcm.com/

Signed-off-by: Arnaud Lecomte <contact@arnaud-lcm.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Cc: Song Lui <song@kernel.org>
---
 kernel/bpf/stackmap.c | 58 ++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 17 deletions(-)

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 3615c06b7dfa..1ebc525b7c2f 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -42,6 +42,28 @@ static inline int stack_map_data_size(struct bpf_map *map)
 		sizeof(struct bpf_stack_build_id) : sizeof(u64);
 }
 
+/**
+ * stack_map_calculate_max_depth - Calculate maximum allowed stack trace depth
+ * @size:  Size of the buffer/map value in bytes
+ * @elem_size:  Size of each stack trace element
+ * @flags:  BPF stack trace flags (BPF_F_USER_STACK, BPF_F_USER_BUILD_ID, ...)
+ *
+ * Return: Maximum number of stack trace entries that can be safely stored
+ */
+static u32 stack_map_calculate_max_depth(u32 size, u32 elem_size, u64 flags)
+{
+	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
+	u32 max_depth;
+	u32 curr_sysctl_max_stack = READ_ONCE(sysctl_perf_event_max_stack);
+
+	max_depth = size / elem_size;
+	max_depth += skip;
+	if (max_depth > curr_sysctl_max_stack)
+		return curr_sysctl_max_stack;
+
+	return max_depth;
+}
+
 static int prealloc_elems_and_freelist(struct bpf_stack_map *smap)
 {
 	u64 elem_size = sizeof(struct stack_map_bucket) +
@@ -300,20 +322,17 @@ static long __bpf_get_stackid(struct bpf_map *map,
 BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map,
 	   u64, flags)
 {
-	u32 max_depth = map->value_size / stack_map_data_size(map);
-	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
+	u32 elem_size = stack_map_data_size(map);
 	bool user = flags & BPF_F_USER_STACK;
 	struct perf_callchain_entry *trace;
 	bool kernel = !user;
+	u32 max_depth;
 
 	if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
 			       BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID)))
 		return -EINVAL;
 
-	max_depth += skip;
-	if (max_depth > sysctl_perf_event_max_stack)
-		max_depth = sysctl_perf_event_max_stack;
-
+	max_depth = stack_map_calculate_max_depth(map->value_size, elem_size, flags);
 	trace = get_perf_callchain(regs, 0, kernel, user, max_depth,
 				   false, false);
 
@@ -350,6 +369,7 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 {
 	struct perf_event *event = ctx->event;
 	struct perf_callchain_entry *trace;
+	u32 elem_size, max_depth;
 	bool kernel, user;
 	__u64 nr_kernel;
 	int ret;
@@ -371,11 +391,14 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 		return -EFAULT;
 
 	nr_kernel = count_kernel_ip(trace);
+	elem_size = stack_map_data_size(map);
 
 	if (kernel) {
 		__u64 nr = trace->nr;
 
-		trace->nr = nr_kernel;
+		max_depth =
+			stack_map_calculate_max_depth(map->value_size, elem_size, flags);
+		trace->nr = min_t(u32, nr_kernel, max_depth);
 		ret = __bpf_get_stackid(map, trace, flags);
 
 		/* restore nr */
@@ -388,6 +411,9 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 			return -EFAULT;
 
 		flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
+		max_depth =
+			stack_map_calculate_max_depth(map->value_size, elem_size, flags);
+		trace->nr = min_t(u32, trace->nr, max_depth);
 		ret = __bpf_get_stackid(map, trace, flags);
 	}
 	return ret;
@@ -406,8 +432,8 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 			    struct perf_callchain_entry *trace_in,
 			    void *buf, u32 size, u64 flags, bool may_fault)
 {
-	u32 trace_nr, copy_len, elem_size, num_elem, max_depth;
 	bool user_build_id = flags & BPF_F_USER_BUILD_ID;
+	u32 trace_nr, copy_len, elem_size, max_depth;
 	bool crosstask = task && task != current;
 	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
 	bool user = flags & BPF_F_USER_STACK;
@@ -438,21 +464,20 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 		goto clear;
 	}
 
-	num_elem = size / elem_size;
-	max_depth = num_elem + skip;
-	if (sysctl_perf_event_max_stack < max_depth)
-		max_depth = sysctl_perf_event_max_stack;
+	max_depth = stack_map_calculate_max_depth(size, elem_size, flags);
 
 	if (may_fault)
 		rcu_read_lock(); /* need RCU for perf's callchain below */
 
-	if (trace_in)
+	if (trace_in) {
 		trace = trace_in;
-	else if (kernel && task)
+		trace->nr = min_t(u32, trace->nr, max_depth);
+	} else if (kernel && task) {
 		trace = get_callchain_entry_for_task(task, max_depth);
-	else
+	} else {
 		trace = get_perf_callchain(regs, 0, kernel, user, max_depth,
-					   crosstask, false);
+			crosstask, false);
+	}
 
 	if (unlikely(!trace) || trace->nr < skip) {
 		if (may_fault)
@@ -461,7 +486,6 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 	}
 
 	trace_nr = trace->nr - skip;
-	trace_nr = (trace_nr <= num_elem) ? trace_nr : num_elem;
 	copy_len = trace_nr * elem_size;
 
 	ips = trace->ip + skip;
-- 
2.47.3

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

* [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
  2025-09-03 13:52 [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Arnaud Lecomte
@ 2025-09-03 13:53 ` Arnaud Lecomte
  2025-09-03 13:53 ` [PATCH bpf-next v6 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid() Arnaud Lecomte
  2025-09-03 16:12 ` [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Alexei Starovoitov
  2 siblings, 0 replies; 7+ messages in thread
From: Arnaud Lecomte @ 2025-09-03 13:53 UTC (permalink / raw)
  To: alexei.starovoitov, yonghong.song, song
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, martin.lau, sdf,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs, Arnaud Lecomte

A new helper function stack_map_calculate_max_depth() that
computes the max depth for a stackmap.

Changes in v2:
 - Removed the checking 'map_size % map_elem_size' from
   stack_map_calculate_max_depth
 - Changed stack_map_calculate_max_depth params name to be more generic

Changes in v3:
 - Changed map size param to size in max depth helper

Changes in v4:
 - Fixed indentation in max depth helper for args

Changes in v5:
 - Bound back trace_nr to num_elem in __bpf_get_stack
 - Make a copy of sysctl_perf_event_max_stack
   in stack_map_calculate_max_depth

Changes in v6:
 - Restrained max_depth computation only when required
 - Additional cleanup from Song in __bpf_get_stack

Link to v5: https://lore.kernel.org/all/20250826212229.143230-1-contact@arnaud-lcm.com/

Signed-off-by: Arnaud Lecomte <contact@arnaud-lcm.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Cc: Song Lui <song@kernel.org>
---
 kernel/bpf/stackmap.c | 58 ++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 17 deletions(-)

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 3615c06b7dfa..1ebc525b7c2f 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -42,6 +42,28 @@ static inline int stack_map_data_size(struct bpf_map *map)
 		sizeof(struct bpf_stack_build_id) : sizeof(u64);
 }
 
+/**
+ * stack_map_calculate_max_depth - Calculate maximum allowed stack trace depth
+ * @size:  Size of the buffer/map value in bytes
+ * @elem_size:  Size of each stack trace element
+ * @flags:  BPF stack trace flags (BPF_F_USER_STACK, BPF_F_USER_BUILD_ID, ...)
+ *
+ * Return: Maximum number of stack trace entries that can be safely stored
+ */
+static u32 stack_map_calculate_max_depth(u32 size, u32 elem_size, u64 flags)
+{
+	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
+	u32 max_depth;
+	u32 curr_sysctl_max_stack = READ_ONCE(sysctl_perf_event_max_stack);
+
+	max_depth = size / elem_size;
+	max_depth += skip;
+	if (max_depth > curr_sysctl_max_stack)
+		return curr_sysctl_max_stack;
+
+	return max_depth;
+}
+
 static int prealloc_elems_and_freelist(struct bpf_stack_map *smap)
 {
 	u64 elem_size = sizeof(struct stack_map_bucket) +
@@ -300,20 +322,17 @@ static long __bpf_get_stackid(struct bpf_map *map,
 BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map,
 	   u64, flags)
 {
-	u32 max_depth = map->value_size / stack_map_data_size(map);
-	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
+	u32 elem_size = stack_map_data_size(map);
 	bool user = flags & BPF_F_USER_STACK;
 	struct perf_callchain_entry *trace;
 	bool kernel = !user;
+	u32 max_depth;
 
 	if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK |
 			       BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID)))
 		return -EINVAL;
 
-	max_depth += skip;
-	if (max_depth > sysctl_perf_event_max_stack)
-		max_depth = sysctl_perf_event_max_stack;
-
+	max_depth = stack_map_calculate_max_depth(map->value_size, elem_size, flags);
 	trace = get_perf_callchain(regs, 0, kernel, user, max_depth,
 				   false, false);
 
@@ -350,6 +369,7 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 {
 	struct perf_event *event = ctx->event;
 	struct perf_callchain_entry *trace;
+	u32 elem_size, max_depth;
 	bool kernel, user;
 	__u64 nr_kernel;
 	int ret;
@@ -371,11 +391,14 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 		return -EFAULT;
 
 	nr_kernel = count_kernel_ip(trace);
+	elem_size = stack_map_data_size(map);
 
 	if (kernel) {
 		__u64 nr = trace->nr;
 
-		trace->nr = nr_kernel;
+		max_depth =
+			stack_map_calculate_max_depth(map->value_size, elem_size, flags);
+		trace->nr = min_t(u32, nr_kernel, max_depth);
 		ret = __bpf_get_stackid(map, trace, flags);
 
 		/* restore nr */
@@ -388,6 +411,9 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bpf_perf_event_data_kern *, ctx,
 			return -EFAULT;
 
 		flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip;
+		max_depth =
+			stack_map_calculate_max_depth(map->value_size, elem_size, flags);
+		trace->nr = min_t(u32, trace->nr, max_depth);
 		ret = __bpf_get_stackid(map, trace, flags);
 	}
 	return ret;
@@ -406,8 +432,8 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 			    struct perf_callchain_entry *trace_in,
 			    void *buf, u32 size, u64 flags, bool may_fault)
 {
-	u32 trace_nr, copy_len, elem_size, num_elem, max_depth;
 	bool user_build_id = flags & BPF_F_USER_BUILD_ID;
+	u32 trace_nr, copy_len, elem_size, max_depth;
 	bool crosstask = task && task != current;
 	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
 	bool user = flags & BPF_F_USER_STACK;
@@ -438,21 +464,20 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 		goto clear;
 	}
 
-	num_elem = size / elem_size;
-	max_depth = num_elem + skip;
-	if (sysctl_perf_event_max_stack < max_depth)
-		max_depth = sysctl_perf_event_max_stack;
+	max_depth = stack_map_calculate_max_depth(size, elem_size, flags);
 
 	if (may_fault)
 		rcu_read_lock(); /* need RCU for perf's callchain below */
 
-	if (trace_in)
+	if (trace_in) {
 		trace = trace_in;
-	else if (kernel && task)
+		trace->nr = min_t(u32, trace->nr, max_depth);
+	} else if (kernel && task) {
 		trace = get_callchain_entry_for_task(task, max_depth);
-	else
+	} else {
 		trace = get_perf_callchain(regs, 0, kernel, user, max_depth,
-					   crosstask, false);
+			crosstask, false);
+	}
 
 	if (unlikely(!trace) || trace->nr < skip) {
 		if (may_fault)
@@ -461,7 +486,6 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
 	}
 
 	trace_nr = trace->nr - skip;
-	trace_nr = (trace_nr <= num_elem) ? trace_nr : num_elem;
 	copy_len = trace_nr * elem_size;
 
 	ips = trace->ip + skip;
-- 
2.47.3

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

* [PATCH bpf-next v6 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid()
  2025-09-03 13:52 [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Arnaud Lecomte
  2025-09-03 13:53 ` Arnaud Lecomte
@ 2025-09-03 13:53 ` Arnaud Lecomte
  2025-09-03 16:12 ` [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Alexei Starovoitov
  2 siblings, 0 replies; 7+ messages in thread
From: Arnaud Lecomte @ 2025-09-03 13:53 UTC (permalink / raw)
  To: alexei.starovoitov, yonghong.song, song
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, martin.lau, sdf,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs, Arnaud Lecomte

Syzkaller reported a KASAN slab-out-of-bounds write in __bpf_get_stackid()
when copying stack trace data. The issue occurs when the perf trace
 contains more stack entries than the stack map bucket can hold,
 leading to an out-of-bounds write in the bucket's data array.

Changes in v2:
 - Fixed max_depth names across get stack id

Changes in v4:
 - Removed unnecessary empty line in __bpf_get_stackid

Changs in v6:
 - Added back trace_len computation in __bpf_get_stackid

Link to v5: https://lore.kernel.org/all/20250826212229.143230-1-contact@arnaud-lcm.com/

Reported-by: syzbot+c9b724fbb41cf2538b7b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c9b724fbb41cf2538b7b
Fixes: ee2a098851bf ("bpf: Adjust BPF stack helper functions to accommodate skip > 0")
Signed-off-by: Arnaud Lecomte <contact@arnaud-lcm.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
 kernel/bpf/stackmap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c
index 1ebc525b7c2f..8b2dcb8a6dc3 100644
--- a/kernel/bpf/stackmap.c
+++ b/kernel/bpf/stackmap.c
@@ -251,8 +251,9 @@ static long __bpf_get_stackid(struct bpf_map *map,
 {
 	struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);
 	struct stack_map_bucket *bucket, *new_bucket, *old_bucket;
+	u32 hash, id, trace_nr, trace_len, i, max_depth;
 	u32 skip = flags & BPF_F_SKIP_FIELD_MASK;
-	u32 hash, id, trace_nr, trace_len, i;
+	u32 elem_size = stack_map_data_size(map);
 	bool user = flags & BPF_F_USER_STACK;
 	u64 *ips;
 	bool hash_matches;
@@ -261,8 +262,12 @@ static long __bpf_get_stackid(struct bpf_map *map,
 		/* skipping more than usable stack trace */
 		return -EFAULT;
 
+	max_depth =
+		stack_map_calculate_max_depth(map->value_size, elem_size, flags);
 	trace_nr = trace->nr - skip;
+	trace_nr = min_t(u32, trace_nr, max_depth - skip);
 	trace_len = trace_nr * sizeof(u64);
+
 	ips = trace->ip + skip;
 	hash = jhash2((u32 *)ips, trace_len / sizeof(u32), 0);
 	id = hash & (smap->n_buckets - 1);
-- 
2.47.3

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

* Re: [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
  2025-09-03 13:52 [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Arnaud Lecomte
  2025-09-03 13:53 ` Arnaud Lecomte
  2025-09-03 13:53 ` [PATCH bpf-next v6 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid() Arnaud Lecomte
@ 2025-09-03 16:12 ` Alexei Starovoitov
  2025-09-03 16:20   ` Lecomte, Arnaud
  2 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2025-09-03 16:12 UTC (permalink / raw)
  To: Arnaud Lecomte
  Cc: Yonghong Song, Song Liu, Andrii Nakryiko, Alexei Starovoitov, bpf,
	Daniel Borkmann, Eduard, Hao Luo, John Fastabend, Jiri Olsa,
	KP Singh, LKML, Martin KaFai Lau, Stanislav Fomichev,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs

On Wed, Sep 3, 2025 at 6:52 AM Arnaud Lecomte <contact@arnaud-lcm.com> wrote:
>
> A new helper function stack_map_calculate_max_depth() that
> computes the max depth for a stackmap.
>
> Changes in v2:
>  - Removed the checking 'map_size % map_elem_size' from
>    stack_map_calculate_max_depth
>  - Changed stack_map_calculate_max_depth params name to be more generic
>
> Changes in v3:
>  - Changed map size param to size in max depth helper
>
> Changes in v4:
>  - Fixed indentation in max depth helper for args
>
> Changes in v5:
>  - Bound back trace_nr to num_elem in __bpf_get_stack
>  - Make a copy of sysctl_perf_event_max_stack
>    in stack_map_calculate_max_depth
>
> Changes in v6:
>  - Restrained max_depth computation only when required
>  - Additional cleanup from Song in __bpf_get_stack

This is not a refactor anymore.
Pls don't squash different things into one patch.
Keep refactor as patch 1, and another cleanup as patch 2.

pw-bot: cr

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

* Re: [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
  2025-09-03 16:12 ` [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Alexei Starovoitov
@ 2025-09-03 16:20   ` Lecomte, Arnaud
  2025-09-03 16:22     ` Alexei Starovoitov
  0 siblings, 1 reply; 7+ messages in thread
From: Lecomte, Arnaud @ 2025-09-03 16:20 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Yonghong Song, Song Liu, Andrii Nakryiko, Alexei Starovoitov, bpf,
	Daniel Borkmann, Eduard, Hao Luo, John Fastabend, Jiri Olsa,
	KP Singh, LKML, Martin KaFai Lau, Stanislav Fomichev,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs


On 03/09/2025 18:12, Alexei Starovoitov wrote:
> On Wed, Sep 3, 2025 at 6:52 AM Arnaud Lecomte <contact@arnaud-lcm.com> wrote:
>> A new helper function stack_map_calculate_max_depth() that
>> computes the max depth for a stackmap.
>>
>> Changes in v2:
>>   - Removed the checking 'map_size % map_elem_size' from
>>     stack_map_calculate_max_depth
>>   - Changed stack_map_calculate_max_depth params name to be more generic
>>
>> Changes in v3:
>>   - Changed map size param to size in max depth helper
>>
>> Changes in v4:
>>   - Fixed indentation in max depth helper for args
>>
>> Changes in v5:
>>   - Bound back trace_nr to num_elem in __bpf_get_stack
>>   - Make a copy of sysctl_perf_event_max_stack
>>     in stack_map_calculate_max_depth
>>
>> Changes in v6:
>>   - Restrained max_depth computation only when required
>>   - Additional cleanup from Song in __bpf_get_stack
> This is not a refactor anymore.
> Pls don't squash different things into one patch.
> Keep refactor as patch 1, and another cleanup as patch 2.

The main problem is that patch 2 is not a cleanup too. It is a bug fix 
so it doesn't really
fit either.
We could maybe split this patch into 2 new patches but I don't really 
like this idea.
If we decide to stick to 2 patches format, I don't have any preference 
which patch's scope
should be extended.

>
> pw-bot: cr
>

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

* Re: [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
  2025-09-03 16:20   ` Lecomte, Arnaud
@ 2025-09-03 16:22     ` Alexei Starovoitov
  2025-09-03 23:46       ` Lecomte, Arnaud
  0 siblings, 1 reply; 7+ messages in thread
From: Alexei Starovoitov @ 2025-09-03 16:22 UTC (permalink / raw)
  To: Lecomte, Arnaud
  Cc: Yonghong Song, Song Liu, Andrii Nakryiko, Alexei Starovoitov, bpf,
	Daniel Borkmann, Eduard, Hao Luo, John Fastabend, Jiri Olsa,
	KP Singh, LKML, Martin KaFai Lau, Stanislav Fomichev,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs

On Wed, Sep 3, 2025 at 9:20 AM Lecomte, Arnaud <contact@arnaud-lcm.com> wrote:
>
>
> On 03/09/2025 18:12, Alexei Starovoitov wrote:
> > On Wed, Sep 3, 2025 at 6:52 AM Arnaud Lecomte <contact@arnaud-lcm.com> wrote:
> >> A new helper function stack_map_calculate_max_depth() that
> >> computes the max depth for a stackmap.
> >>
> >> Changes in v2:
> >>   - Removed the checking 'map_size % map_elem_size' from
> >>     stack_map_calculate_max_depth
> >>   - Changed stack_map_calculate_max_depth params name to be more generic
> >>
> >> Changes in v3:
> >>   - Changed map size param to size in max depth helper
> >>
> >> Changes in v4:
> >>   - Fixed indentation in max depth helper for args
> >>
> >> Changes in v5:
> >>   - Bound back trace_nr to num_elem in __bpf_get_stack
> >>   - Make a copy of sysctl_perf_event_max_stack
> >>     in stack_map_calculate_max_depth
> >>
> >> Changes in v6:
> >>   - Restrained max_depth computation only when required
> >>   - Additional cleanup from Song in __bpf_get_stack
> > This is not a refactor anymore.
> > Pls don't squash different things into one patch.
> > Keep refactor as patch 1, and another cleanup as patch 2.
>
> The main problem is that patch 2 is not a cleanup too. It is a bug fix
> so it doesn't really
> fit either.
> We could maybe split this patch into 2 new patches but I don't really
> like this idea.
> If we decide to stick to 2 patches format, I don't have any preference
> which patch's scope
> should be extended.

I wasn't proposing to squash cleanup into patch 2.
Make 3 patches where each one is doing one thing.

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

* Re: [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack()
  2025-09-03 16:22     ` Alexei Starovoitov
@ 2025-09-03 23:46       ` Lecomte, Arnaud
  0 siblings, 0 replies; 7+ messages in thread
From: Lecomte, Arnaud @ 2025-09-03 23:46 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Yonghong Song, Song Liu, Andrii Nakryiko, Alexei Starovoitov, bpf,
	Daniel Borkmann, Eduard, Hao Luo, John Fastabend, Jiri Olsa,
	KP Singh, LKML, Martin KaFai Lau, Stanislav Fomichev,
	syzbot+c9b724fbb41cf2538b7b, syzkaller-bugs


On 03/09/2025 18:22, Alexei Starovoitov wrote:
> On Wed, Sep 3, 2025 at 9:20 AM Lecomte, Arnaud <contact@arnaud-lcm.com> wrote:
>>
>> On 03/09/2025 18:12, Alexei Starovoitov wrote:
>>> On Wed, Sep 3, 2025 at 6:52 AM Arnaud Lecomte <contact@arnaud-lcm.com> wrote:
>>>> A new helper function stack_map_calculate_max_depth() that
>>>> computes the max depth for a stackmap.
>>>>
>>>> Changes in v2:
>>>>    - Removed the checking 'map_size % map_elem_size' from
>>>>      stack_map_calculate_max_depth
>>>>    - Changed stack_map_calculate_max_depth params name to be more generic
>>>>
>>>> Changes in v3:
>>>>    - Changed map size param to size in max depth helper
>>>>
>>>> Changes in v4:
>>>>    - Fixed indentation in max depth helper for args
>>>>
>>>> Changes in v5:
>>>>    - Bound back trace_nr to num_elem in __bpf_get_stack
>>>>    - Make a copy of sysctl_perf_event_max_stack
>>>>      in stack_map_calculate_max_depth
>>>>
>>>> Changes in v6:
>>>>    - Restrained max_depth computation only when required
>>>>    - Additional cleanup from Song in __bpf_get_stack
>>> This is not a refactor anymore.
>>> Pls don't squash different things into one patch.
>>> Keep refactor as patch 1, and another cleanup as patch 2.
>> The main problem is that patch 2 is not a cleanup too. It is a bug fix
>> so it doesn't really
>> fit either.
>> We could maybe split this patch into 2 new patches but I don't really
>> like this idea.
>> If we decide to stick to 2 patches format, I don't have any preference
>> which patch's scope
>> should be extended.
> I wasn't proposing to squash cleanup into patch 2.
> Make 3 patches where each one is doing one thing.
I've sent it: 
https://lore.kernel.org/all/20250903233910.29431-1-contact@arnaud-lcm.com/
Thanks !
Arnaud
>

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

end of thread, other threads:[~2025-09-03 23:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 13:52 [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Arnaud Lecomte
2025-09-03 13:53 ` Arnaud Lecomte
2025-09-03 13:53 ` [PATCH bpf-next v6 2/2] bpf: fix stackmap overflow check in __bpf_get_stackid() Arnaud Lecomte
2025-09-03 16:12 ` [PATCH bpf-next v6 1/2] bpf: refactor max_depth computation in bpf_get_stack() Alexei Starovoitov
2025-09-03 16:20   ` Lecomte, Arnaud
2025-09-03 16:22     ` Alexei Starovoitov
2025-09-03 23:46       ` Lecomte, Arnaud

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).