Skip to content

Commit bb48cf1

Browse files
Byte-LabMartin KaFai Lau
authored andcommitted
bpf: Document struct bpf_struct_ops fields
Subsystems that want to implement a struct bpf_struct_ops structure to enable struct_ops maps must currently reverse engineer how the structure works. Given that this is meant to be a way for subsystem maintainers to extend their subsystems using BPF, let's document it to make it a bit easier on them. Signed-off-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20230814185908.700553-3-void@manifault.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent 8ba651e commit bb48cf1

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

include/linux/bpf.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,53 @@ struct bpf_struct_ops_value;
15501550
struct btf_member;
15511551

15521552
#define BPF_STRUCT_OPS_MAX_NR_MEMBERS 64
1553+
/**
1554+
* struct bpf_struct_ops - A structure of callbacks allowing a subsystem to
1555+
* define a BPF_MAP_TYPE_STRUCT_OPS map type composed
1556+
* of BPF_PROG_TYPE_STRUCT_OPS progs.
1557+
* @verifier_ops: A structure of callbacks that are invoked by the verifier
1558+
* when determining whether the struct_ops progs in the
1559+
* struct_ops map are valid.
1560+
* @init: A callback that is invoked a single time, and before any other
1561+
* callback, to initialize the structure. A nonzero return value means
1562+
* the subsystem could not be initialized.
1563+
* @check_member: When defined, a callback invoked by the verifier to allow
1564+
* the subsystem to determine if an entry in the struct_ops map
1565+
* is valid. A nonzero return value means that the map is
1566+
* invalid and should be rejected by the verifier.
1567+
* @init_member: A callback that is invoked for each member of the struct_ops
1568+
* map to allow the subsystem to initialize the member. A nonzero
1569+
* value means the member could not be initialized. This callback
1570+
* is exclusive with the @type, @type_id, @value_type, and
1571+
* @value_id fields.
1572+
* @reg: A callback that is invoked when the struct_ops map has been
1573+
* initialized and is being attached to. Zero means the struct_ops map
1574+
* has been successfully registered and is live. A nonzero return value
1575+
* means the struct_ops map could not be registered.
1576+
* @unreg: A callback that is invoked when the struct_ops map should be
1577+
* unregistered.
1578+
* @update: A callback that is invoked when the live struct_ops map is being
1579+
* updated to contain new values. This callback is only invoked when
1580+
* the struct_ops map is loaded with BPF_F_LINK. If not defined, the
1581+
* it is assumed that the struct_ops map cannot be updated.
1582+
* @validate: A callback that is invoked after all of the members have been
1583+
* initialized. This callback should perform static checks on the
1584+
* map, meaning that it should either fail or succeed
1585+
* deterministically. A struct_ops map that has been validated may
1586+
* not necessarily succeed in being registered if the call to @reg
1587+
* fails. For example, a valid struct_ops map may be loaded, but
1588+
* then fail to be registered due to there being another active
1589+
* struct_ops map on the system in the subsystem already. For this
1590+
* reason, if this callback is not defined, the check is skipped as
1591+
* the struct_ops map will have final verification performed in
1592+
* @reg.
1593+
* @type: BTF type.
1594+
* @value_type: Value type.
1595+
* @name: The name of the struct bpf_struct_ops object.
1596+
* @func_models: Func models
1597+
* @type_id: BTF type id.
1598+
* @value_id: BTF value id.
1599+
*/
15531600
struct bpf_struct_ops {
15541601
const struct bpf_verifier_ops *verifier_ops;
15551602
int (*init)(struct btf *btf);

0 commit comments

Comments
 (0)