Skip to contentSkip to conversation

perf/x86: Annotate struct bts_buffer with __counted_by()

PATCH Applied Thorsten Blum 2 participants 2 messages Mar 5, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf/x86: Annotate struct bts_buffer with __counted_by()

Add the __counted_by() compiler attribute to the flexible array member buf to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

No functional changes intended.

---
Changes in v2:
- struct_size() changes should be a separate patch as suggested by Ingo
- Link to v1: https://lore.kernel.org/r/[email protected]/

---
 arch/x86/events/intel/bts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/bts.c +1 -1
index 8f78b0c900ef..c7be60c0b94f 100644
@@ -58,7 +58,7 @@ struct bts_buffer {
 	local_t		head;
 	unsigned long	end;
 	void		**data_pages;
-	struct bts_phys	buf[];
+	struct bts_phys	buf[] __counted_by(nr_bufs);
 };
 
 static struct pmu bts_pmu;
Signature · 1 line
2.48.1
merge bot Applied
#1 lore raw

[tip: perf/core] perf/x86: Annotate struct bts_buffer::buf with __counted_by()

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

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

Commit-ID:     5e7adc81ae1b27ff565714d2933b291cf1e1271f
Gitweb:        https://git.kernel.org/tip/5e7adc81ae1b27ff565714d2933b291cf1e1271f
Author:        Thorsten Blum <[email protected]>
AuthorDate:    Wed, 05 Mar 2025 13:31:34 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 05 Mar 2025 18:28:22 +01:00

perf/x86: Annotate struct bts_buffer::buf with __counted_by()

Add the __counted_by() compiler attribute to the flexible array member buf to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE.

No functional changes intended.

---
 arch/x86/events/intel/bts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/events/intel/bts.c +1 -1
index 8e09319..953868d 100644
@@ -58,7 +58,7 @@ struct bts_buffer {
 	local_t		head;
 	unsigned long	end;
 	void		**data_pages;
-	struct bts_phys	buf[];
+	struct bts_phys	buf[] __counted_by(nr_bufs);
 };
 
 static struct pmu bts_pmu;