Skip to content

Commit ab21d60

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
bpf: Introduce 8-byte BTF set
Introduce support for defining flags for kfuncs using a new set of macros, BTF_SET8_START/BTF_SET8_END, which define a set which contains 8 byte elements (each of which consists of a pair of BTF ID and flags), using a new BTF_ID_FLAGS macro. This will be used to tag kfuncs registered for a certain program type as acquire, release, sleepable, ret_null, etc. without having to create more and more sets which was proving to be an unscalable solution. Now, when looking up whether a kfunc is allowed for a certain program, we can also obtain its kfunc flags in the same call and avoid further lookups. The resolve_btfids change is split into a separate patch. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 5cb62b7 commit ab21d60

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

include/linux/btf_ids.h

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ struct btf_id_set {
88
u32 ids[];
99
};
1010

11+
struct btf_id_set8 {
12+
u32 cnt;
13+
u32 flags;
14+
struct {
15+
u32 id;
16+
u32 flags;
17+
} pairs[];
18+
};
19+
1120
#ifdef CONFIG_DEBUG_INFO_BTF
1221

1322
#include <linux/compiler.h> /* for __PASTE */
@@ -25,18 +34,19 @@ struct btf_id_set {
2534

2635
#define BTF_IDS_SECTION ".BTF_ids"
2736

28-
#define ____BTF_ID(symbol) \
37+
#define ____BTF_ID(symbol, word) \
2938
asm( \
3039
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
3140
".local " #symbol " ; \n" \
3241
".type " #symbol ", STT_OBJECT; \n" \
3342
".size " #symbol ", 4; \n" \
3443
#symbol ": \n" \
3544
".zero 4 \n" \
45+
word \
3646
".popsection; \n");
3747

38-
#define __BTF_ID(symbol) \
39-
____BTF_ID(symbol)
48+
#define __BTF_ID(symbol, word) \
49+
____BTF_ID(symbol, word)
4050

4151
#define __ID(prefix) \
4252
__PASTE(prefix, __COUNTER__)
@@ -46,7 +56,14 @@ asm( \
4656
* to 4 zero bytes.
4757
*/
4858
#define BTF_ID(prefix, name) \
49-
__BTF_ID(__ID(__BTF_ID__##prefix##__##name##__))
59+
__BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), "")
60+
61+
#define ____BTF_ID_FLAGS(prefix, name, flags) \
62+
__BTF_ID(__ID(__BTF_ID__##prefix##__##name##__), ".long " #flags "\n")
63+
#define __BTF_ID_FLAGS(prefix, name, flags, ...) \
64+
____BTF_ID_FLAGS(prefix, name, flags)
65+
#define BTF_ID_FLAGS(prefix, name, ...) \
66+
__BTF_ID_FLAGS(prefix, name, ##__VA_ARGS__, 0)
5067

5168
/*
5269
* The BTF_ID_LIST macro defines pure (unsorted) list
@@ -145,17 +162,60 @@ asm( \
145162
".popsection; \n"); \
146163
extern struct btf_id_set name;
147164

165+
/*
166+
* The BTF_SET8_START/END macros pair defines sorted list of
167+
* BTF IDs and their flags plus its members count, with the
168+
* following layout:
169+
*
170+
* BTF_SET8_START(list)
171+
* BTF_ID_FLAGS(type1, name1, flags)
172+
* BTF_ID_FLAGS(type2, name2, flags)
173+
* BTF_SET8_END(list)
174+
*
175+
* __BTF_ID__set8__list:
176+
* .zero 8
177+
* list:
178+
* __BTF_ID__type1__name1__3:
179+
* .zero 4
180+
* .word (1 << 0) | (1 << 2)
181+
* __BTF_ID__type2__name2__5:
182+
* .zero 4
183+
* .word (1 << 3) | (1 << 1) | (1 << 2)
184+
*
185+
*/
186+
#define __BTF_SET8_START(name, scope) \
187+
asm( \
188+
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
189+
"." #scope " __BTF_ID__set8__" #name "; \n" \
190+
"__BTF_ID__set8__" #name ":; \n" \
191+
".zero 8 \n" \
192+
".popsection; \n");
193+
194+
#define BTF_SET8_START(name) \
195+
__BTF_ID_LIST(name, local) \
196+
__BTF_SET8_START(name, local)
197+
198+
#define BTF_SET8_END(name) \
199+
asm( \
200+
".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \
201+
".size __BTF_ID__set8__" #name ", .-" #name " \n" \
202+
".popsection; \n"); \
203+
extern struct btf_id_set8 name;
204+
148205
#else
149206

150207
#define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
151208
#define BTF_ID(prefix, name)
209+
#define BTF_ID_FLAGS(prefix, name, flags)
152210
#define BTF_ID_UNUSED
153211
#define BTF_ID_LIST_GLOBAL(name, n) u32 __maybe_unused name[n];
154212
#define BTF_ID_LIST_SINGLE(name, prefix, typename) static u32 __maybe_unused name[1];
155213
#define BTF_ID_LIST_GLOBAL_SINGLE(name, prefix, typename) u32 __maybe_unused name[1];
156214
#define BTF_SET_START(name) static struct btf_id_set __maybe_unused name = { 0 };
157215
#define BTF_SET_START_GLOBAL(name) static struct btf_id_set __maybe_unused name = { 0 };
158216
#define BTF_SET_END(name)
217+
#define BTF_SET8_START(name) static struct btf_id_set8 __maybe_unused name = { 0 };
218+
#define BTF_SET8_END(name) static struct btf_id_set8 __maybe_unused name = { 0 };
159219

160220
#endif /* CONFIG_DEBUG_INFO_BTF */
161221

0 commit comments

Comments
 (0)