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)

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) {
__bpf_struct_ops_map_free(map);
return ERR_PTR(-ENOMEM);
Expand Down