Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions kernel/bpf/bpf_struct_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <linux/btf_ids.h>
#include <linux/rcupdate_wait.h>

#define ST_IMAGE_SIZE (PAGE_SIZE * 2)

Comment on lines +16 to +17
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The struct comment for st_map->image still describes it as a single page and says PAGE_SIZE is sufficient, which is no longer true now that ST_IMAGE_SIZE is used. Please update that comment to match the new two-page allocation to avoid misleading future readers.

Copilot uses AI. Check for mistakes.
enum bpf_struct_ops_state {
BPF_STRUCT_OPS_STATE_INIT,
BPF_STRUCT_OPS_STATE_INUSE,
Expand Down Expand Up @@ -417,7 +419,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
udata = &uvalue->data;
kdata = &kvalue->data;
image = st_map->image;
image_end = st_map->image + PAGE_SIZE;
image_end = st_map->image + ST_IMAGE_SIZE;

for_each_member(i, t, member) {
const struct btf_type *mtype, *ptype;
Expand Down Expand Up @@ -515,7 +517,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
if (err)
goto reset_unlock;
}
set_memory_rox((long)st_map->image, 1);
set_memory_rox((long)st_map->image, ST_IMAGE_SIZE / PAGE_SIZE);
/* Let bpf_link handle registration & unregistration.
*
* Pair with smp_load_acquire() during lookup_elem().
Expand All @@ -524,7 +526,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
goto unlock;
}

set_memory_rox((long)st_map->image, 1);
set_memory_rox((long)st_map->image, ST_IMAGE_SIZE / PAGE_SIZE);
err = st_ops->reg(kdata);
if (likely(!err)) {
/* This refcnt increment on the map here after
Expand All @@ -547,8 +549,8 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
* there was a race in registering the struct_ops (under the same name) to
* a sub-system through different struct_ops's maps.
*/
set_memory_nx((long)st_map->image, 1);
set_memory_rw((long)st_map->image, 1);
set_memory_nx((long)st_map->image, ST_IMAGE_SIZE / PAGE_SIZE);
set_memory_rw((long)st_map->image, ST_IMAGE_SIZE / PAGE_SIZE);

reset_unlock:
bpf_struct_ops_map_put_progs(st_map);
Expand Down Expand Up @@ -685,7 +687,7 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
st_map->links =
bpf_map_area_alloc(btf_type_vlen(t) * sizeof(struct bpf_links *),
NUMA_NO_NODE);
st_map->image = bpf_jit_alloc_exec(PAGE_SIZE);
st_map->image = bpf_jit_alloc_exec(ST_IMAGE_SIZE);
if (!st_map->uvalue || !st_map->links || !st_map->image) {
Comment on lines 688 to 691
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After increasing the JIT image allocation to ST_IMAGE_SIZE, bpf_struct_ops_map_mem_usage() still accounts only PAGE_SIZE (line ~714), so map memory accounting will be under-reported by one page. Please update the mem_usage calculation to include ST_IMAGE_SIZE instead of PAGE_SIZE to keep BPF memlock/accounting accurate.

Copilot uses AI. Check for mistakes.
__bpf_struct_ops_map_free(map);
return ERR_PTR(-ENOMEM);
Expand Down