[PATCH 03/44] perf: Fix branch stack callchain limit

david.laight.linux@gmail.com posted 44 patches 1 week, 5 days ago
There is a newer version of this series
[PATCH 03/44] perf: Fix branch stack callchain limit
Posted by david.laight.linux@gmail.com 1 week, 5 days ago
From: David Laight <david.laight.linux@gmail.com>

The code that bounds the brs->nr to event->attr.sample_max_stack
incorrectly masks brs->nr with 65535 before the limit check.
Replace the min_t(u16, ...) with a plain min(...).

I guess there may be another limit on brs->nr (which is u64).

Fixes: c53e14f1ea4a8 ("perf: Extend per event callchain limit to branch stack")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 include/linux/perf_event.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index fd1d91017b99..f91c875ea311 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1430,7 +1430,7 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data,
 	if (branch_sample_hw_index(event))
 		size += sizeof(u64);
 
-	brs->nr = min_t(u16, event->attr.sample_max_stack, brs->nr);
+	brs->nr = min(event->attr.sample_max_stack, brs->nr);
 
 	size += brs->nr * sizeof(struct perf_branch_entry);
 
-- 
2.39.5
Re: [PATCH 03/44] perf: Fix branch stack callchain limit
Posted by Mi, Dapeng 5 days, 20 hours ago
On 11/20/2025 6:40 AM, david.laight.linux@gmail.com wrote:
> From: David Laight <david.laight.linux@gmail.com>
>
> The code that bounds the brs->nr to event->attr.sample_max_stack
> incorrectly masks brs->nr with 65535 before the limit check.
> Replace the min_t(u16, ...) with a plain min(...).
>
> I guess there may be another limit on brs->nr (which is u64).
>
> Fixes: c53e14f1ea4a8 ("perf: Extend per event callchain limit to branch stack")
> Signed-off-by: David Laight <david.laight.linux@gmail.com>
> ---
>  include/linux/perf_event.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index fd1d91017b99..f91c875ea311 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -1430,7 +1430,7 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data,
>  	if (branch_sample_hw_index(event))
>  		size += sizeof(u64);
>  
> -	brs->nr = min_t(u16, event->attr.sample_max_stack, brs->nr);
> +	brs->nr = min(event->attr.sample_max_stack, brs->nr);
>  
>  	size += brs->nr * sizeof(struct perf_branch_entry);
>  

LGTM. Thanks.

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>