From d0eb653a82060d68572fd7aef9b36097fc8f1472 Mon Sep 17 00:00:00 2001 From: myslqyr <1748189201@qq.com> Date: Tue, 19 Aug 2025 16:40:16 +0800 Subject: [PATCH] deepin: ARM:Fix segmentation fault when running fuse-bpf on ARM The Struct_op operation allocates a single memory page to store target platform binary code.On x86, where instruction lengths are shorter, one page is sufficient. However, on ARM architectures, longer instructions require more memory space, causing the single page allocation to overflow. To resolve this, the memory allocation has been increased to two pages, ensuring stable operation of the fuse_daemon. Signed-off-by: myslqyr <1748189201@qq.com> --- kernel/bpf/bpf_struct_ops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index fdc3e8705a3cb..173790e457aa9 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -13,6 +13,8 @@ #include #include +#define ST_IMAGE_SIZE (PAGE_SIZE * 2) + enum bpf_struct_ops_state { BPF_STRUCT_OPS_STATE_INIT, BPF_STRUCT_OPS_STATE_INUSE, @@ -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; @@ -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(). @@ -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 @@ -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); @@ -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);