From: Martin KaFai Lau Date: Wed, 6 Aug 2025 20:39:59 +0000 (-0700) Subject: Merge branch 'allow-struct_ops-to-create-map-id-to' X-Git-Tag: v6.18-rc1~175^2~117 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=911c0359d8f6da3ffdeee52886f820fbf1c7fa5c;p=thirdparty%2Fkernel%2Fstable.git Merge branch 'allow-struct_ops-to-create-map-id-to' Amery Hung says: ==================== This patchset allows struct_ops implementors to get map id from kdata in reg(), unreg() and update() so that they create an id to struct_ops instance mapping. This in turn allows struct_ops kfuncs to refer to the calling instance without passing a pointer to the struct_ops. The selftest provides an end-to-end example. Some struct_ops users extend themselves with other bpf programs, which also need to call struct_ops kfuncs. For example, scx_layered uses syscall bpf programs as a scx_layered specific control plane and uses tracing programs to get additional information for scheduling [0]. The kfuncs may need to refer to the struct_ops instance and perform jobs accordingly. To allow calling struct_ops kfuncs referring to specific instances from different program types and context (e.g., struct_ops, tracing, async callbacks), the traditional way is to pass the struct_ops pointer to kfuncs. This patchset provides an alternative way, through a combination of bpf map id and global variable. First, a struct_ops implementor will use the map id of the struct_ops map as the id of an instance. Then, it needs to maintain an id to instance mapping: inserting a new mapping during reg() and removing it during unreg(). The map id can be acquired by calling bpf_struct_ops_id(). v1 -> v2 Add bpf_struct_ops_id() instead of using bpf_struct_ops_get() [0] https://github.com/sched-ext/scx/blob/main/scheds/rust/scx_layered/src/bpf/main.bpf.c ==================== Link: https://patch.msgid.link/20250806162540.681679-1-ameryhung@gmail.com Signed-off-by: Martin KaFai Lau --- 911c0359d8f6da3ffdeee52886f820fbf1c7fa5c