Yonghong Song
ce880cb825
bpf: Fix a rcu warning for bpffs map pretty-print
Running selftest
./btf_btf -p
the kernel had the following warning:
[ 51.528185] WARNING: CPU: 3 PID: 1756 at kernel/bpf/hashtab.c:717 htab_map_get_next_key+0x2eb/0x300
[ 51.529217] Modules linked in:
[ 51.529583] CPU: 3 PID: 1756 Comm: test_btf Not tainted 5.9.0-rc1+ #878
[ 51.530346] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.9.3-1.el7.centos 04/01/2014
[ 51.531410] RIP: 0010:htab_map_get_next_key+0x2eb/0x300
...
[ 51.542826] Call Trace:
[ 51.543119] map_seq_next+0x53/0x80
[ 51.543528] seq_read+0x263/0x400
[ 51.543932] vfs_read+0xad/0x1c0
[ 51.544311] ksys_read+0x5f/0xe0
[ 51.544689] do_syscall_64+0x33/0x40
[ 51.545116] entry_SYSCALL_64_after_hwframe+0x44/0xa9
The related source code in kernel/bpf/hashtab.c:
709 static int htab_map_get_next_key(struct bpf_map *map, void *key, void *next_key)
710 {
711 struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
712 struct hlist_nulls_head *head;
713 struct htab_elem *l, *next_l;
714 u32 hash, key_size;
715 int i = 0;
716
717 WARN_ON_ONCE(!rcu_read_lock_held());
In kernel/bpf/inode.c, bpffs map pretty print calls map->ops->map_get_next_key()
without holding a rcu_read_lock(), hence causing the above warning.
To fix the issue, just surrounding map->ops->map_get_next_key() with rcu read lock.
Fixes: a26ca7c982cb ("bpf: btf: Add pretty print support to the basic arraymap")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200916004401.146277-1-yhs@fb.com
2020-09-15 18:17:39 -07:00
..
2020-07-25 20:16:33 -07:00
2020-08-18 17:36:23 -07:00
2019-05-30 11:29:53 -07:00
2020-04-06 21:54:10 +02:00
2020-06-01 15:08:04 -07:00
2020-01-09 08:46:18 -08:00
2020-06-22 22:22:58 +02:00
2020-08-03 18:27:40 -07:00
2020-08-01 20:38:28 -07:00
2020-08-07 18:57:24 +02:00
2020-07-21 09:15:28 -07:00
2020-07-04 17:48:34 -07:00
2019-06-05 17:36:38 +02:00
2019-06-05 17:36:38 +02:00
2020-03-13 12:49:52 -07:00
2020-09-03 17:36:41 -07:00
2020-06-01 14:38:22 -07:00
2020-09-15 18:17:39 -07:00
2020-07-25 20:16:36 -07:00
2020-07-01 08:07:13 -07:00
2020-07-25 20:16:32 -07:00
2020-05-15 17:29:41 +02:00
2019-05-30 11:29:53 -07:00
2020-08-06 16:39:14 -07:00
2020-08-01 20:38:28 -07:00
2020-02-17 16:53:49 +01:00
2020-02-24 16:18:20 -08:00
2019-05-30 11:29:53 -07:00
2020-07-25 20:16:32 -07:00
2020-07-01 08:07:13 -07:00
2020-07-11 00:46:00 -07:00
2020-07-11 00:46:00 -07:00
2020-08-12 18:14:49 -07:00
2020-08-24 21:03:07 -07:00
2020-03-19 12:32:38 +01:00
2020-08-18 17:36:23 -07:00
2020-03-30 14:59:53 -07:00
2020-03-30 01:34:00 +02:00
2020-08-07 18:57:24 +02:00