Files
linux/include/linux
Amery Hung b5709f6d26 bpf: Support associating BPF program with struct_ops
Add a new BPF command BPF_PROG_ASSOC_STRUCT_OPS to allow associating
a BPF program with a struct_ops map. This command takes a file
descriptor of a struct_ops map and a BPF program and set
prog->aux->st_ops_assoc to the kdata of the struct_ops map.

The command does not accept a struct_ops program nor a non-struct_ops
map. Programs of a struct_ops map is automatically associated with the
map during map update. If a program is shared between two struct_ops
maps, prog->aux->st_ops_assoc will be poisoned to indicate that the
associated struct_ops is ambiguous. The pointer, once poisoned, cannot
be reset since we have lost track of associated struct_ops. For other
program types, the associated struct_ops map, once set, cannot be
changed later. This restriction may be lifted in the future if there is
a use case.

A kernel helper bpf_prog_get_assoc_struct_ops() can be used to retrieve
the associated struct_ops pointer. The returned pointer, if not NULL, is
guaranteed to be valid and point to a fully updated struct_ops struct.
For struct_ops program reused in multiple struct_ops map, the return
will be NULL.

prog->aux->st_ops_assoc is protected by bumping the refcount for
non-struct_ops programs and RCU for struct_ops programs. Since it would
be inefficient to track programs associated with a struct_ops map, every
non-struct_ops program will bump the refcount of the map to make sure
st_ops_assoc stays valid. For a struct_ops program, it is protected by
RCU as map_free will wait for an RCU grace period before disassociating
the program with the map. The helper must be called in BPF program
context or RCU read-side critical section.

struct_ops implementers should note that the struct_ops returned may not
be initialized nor attached yet. The struct_ops implementer will be
responsible for tracking and checking the state of the associated
struct_ops map if the use case expects an initialized or attached
struct_ops.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/bpf/20251203233748.668365-3-ameryhung@gmail.com
2025-12-05 16:17:57 -08:00
..
2025-11-11 10:01:30 +01:00
2025-06-15 21:19:08 +05:30
2025-09-05 15:06:03 +02:00
2025-10-14 14:50:16 -07:00
2025-07-21 18:18:51 +01:00
2025-04-21 10:27:59 +02:00
2025-04-29 15:58:38 -04:00
2025-07-31 11:28:03 -04:00
2025-09-24 02:48:05 -07:00
2025-11-21 11:21:31 +01:00
2025-10-27 09:56:27 -07:00
2025-05-21 13:39:45 +02:00
2025-08-14 10:37:33 -07:00
2025-11-04 12:36:57 +01:00
2025-04-11 18:58:10 -07:00
2025-09-23 11:13:22 +02:00
2025-04-17 10:56:11 +02:00
2025-04-10 10:39:14 +01:00
2025-11-28 12:42:23 +01:00
2025-08-21 13:58:07 +02:00
2025-07-16 14:28:21 +02:00
2025-11-24 09:46:24 -08:00
2025-05-22 11:07:05 +02:00
2025-10-29 18:28:29 -07:00
2025-09-13 17:32:44 -07:00
2025-08-29 13:39:53 -07:00
2025-11-04 12:36:02 +01:00
2025-08-02 12:06:10 -07:00
2025-09-23 11:13:22 +02:00
2025-06-11 11:57:14 -07:00
2025-07-02 17:18:01 +01:00
2025-10-24 21:39:27 +02:00
2025-07-17 06:01:16 -06:00
2025-11-23 12:30:40 +01:00
2025-09-13 16:54:50 -07:00
2025-07-09 22:41:56 -07:00
2025-09-17 15:58:29 -04:00
2025-06-17 18:18:46 -07:00
2025-11-04 19:10:33 -08:00
2025-07-14 15:20:02 -07:00
2025-09-23 13:28:20 -04:00
2025-07-08 19:11:57 -04:00
2025-11-05 23:58:20 +01:00
2025-11-03 17:41:17 +01:00
2025-11-11 10:01:30 +01:00
2025-10-01 07:55:42 -05:00
2025-05-21 16:46:37 +02:00
2025-09-13 16:55:07 -07:00
2025-06-19 14:28:24 +02:00
2025-06-19 14:28:24 +02:00
2025-11-14 17:05:53 +01:00
2025-08-24 11:41:11 -06:00
2025-07-01 12:29:29 +02:00
2025-10-30 18:35:26 +01:00
2025-10-24 21:39:27 +02:00
2025-10-31 10:16:23 +01:00
2025-05-03 12:02:04 +02:00
2025-05-11 17:54:09 -07:00
2025-05-06 11:11:45 -06:00
2025-11-25 10:07:42 +01:00
2025-08-28 13:14:50 +02:00
2025-11-27 14:22:31 +01:00
2025-11-20 17:57:40 -08:00
2025-11-03 17:41:18 +01:00
2025-07-23 11:56:02 +02:00
2025-08-17 12:46:25 +02:00
2025-03-20 08:00:50 -07:00
2025-11-25 10:07:42 +01:00
2025-09-09 10:27:01 -06:00
2025-11-03 17:41:18 +01:00
2025-10-01 07:24:55 -04:00
2025-07-17 11:26:56 +02:00
2025-11-12 09:38:34 +01:00
2025-08-02 12:01:37 -07:00