Skip to content

Commit ffce84b

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-avoid-rcu-context-warning-when-unpinning-htab-with-internal-structs'
KaFai Wan says: ==================== bpf: Avoid RCU context warning when unpinning htab with internal structs This small patchset is about avoid RCU context warning when unpinning htab with internal structs (timer, workqueue, or task_work). v3: - fix nit (Yonghong Song) - add Acked-by: Yonghong Song <yonghong.song@linux.dev> v2: - rename bpf_free_inode() to bpf_destroy_inode() (Andrii) https://lore.kernel.org/all/20251007012235.755853-1-kafai.wan@linux.dev/ v1: https://lore.kernel.org/all/20251003084528.502518-1-kafai.wan@linux.dev/ --- ==================== Link: https://patch.msgid.link/20251008102628.808045-1-kafai.wan@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 07ca98f + accb9a7 commit ffce84b

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

kernel/bpf/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static int bpf_show_options(struct seq_file *m, struct dentry *root)
775775
return 0;
776776
}
777777

778-
static void bpf_free_inode(struct inode *inode)
778+
static void bpf_destroy_inode(struct inode *inode)
779779
{
780780
enum bpf_type type;
781781

@@ -790,7 +790,7 @@ const struct super_operations bpf_super_ops = {
790790
.statfs = simple_statfs,
791791
.drop_inode = inode_just_drop,
792792
.show_options = bpf_show_options,
793-
.free_inode = bpf_free_inode,
793+
.destroy_inode = bpf_destroy_inode,
794794
};
795795

796796
enum {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <test_progs.h>
4+
#include "test_pinning_htab.skel.h"
5+
6+
static void unpin_map(const char *map_name, const char *pin_path)
7+
{
8+
struct test_pinning_htab *skel;
9+
struct bpf_map *map;
10+
int err;
11+
12+
skel = test_pinning_htab__open_and_load();
13+
if (!ASSERT_OK_PTR(skel, "skel open_and_load"))
14+
return;
15+
16+
map = bpf_object__find_map_by_name(skel->obj, map_name);
17+
if (!ASSERT_OK_PTR(map, "bpf_object__find_map_by_name"))
18+
goto out;
19+
20+
err = bpf_map__pin(map, pin_path);
21+
if (!ASSERT_OK(err, "bpf_map__pin"))
22+
goto out;
23+
24+
err = bpf_map__unpin(map, pin_path);
25+
ASSERT_OK(err, "bpf_map__unpin");
26+
out:
27+
test_pinning_htab__destroy(skel);
28+
}
29+
30+
void test_pinning_htab(void)
31+
{
32+
if (test__start_subtest("timer_prealloc"))
33+
unpin_map("timer_prealloc", "/sys/fs/bpf/timer_prealloc");
34+
if (test__start_subtest("timer_no_prealloc"))
35+
unpin_map("timer_no_prealloc", "/sys/fs/bpf/timer_no_prealloc");
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
struct timer_val {
9+
struct bpf_timer timer;
10+
};
11+
12+
struct {
13+
__uint(type, BPF_MAP_TYPE_HASH);
14+
__type(key, __u32);
15+
__type(value, struct timer_val);
16+
__uint(max_entries, 1);
17+
} timer_prealloc SEC(".maps");
18+
19+
struct {
20+
__uint(type, BPF_MAP_TYPE_HASH);
21+
__type(key, __u32);
22+
__type(value, struct timer_val);
23+
__uint(max_entries, 1);
24+
__uint(map_flags, BPF_F_NO_PREALLOC);
25+
} timer_no_prealloc SEC(".maps");

0 commit comments

Comments
 (0)