Skip to content

Commit 638e4b8

Browse files
Alexei Starovoitovborkmann
authored andcommitted
bpf: Allows per-cpu maps and map-in-map in sleepable programs
Since sleepable programs are now executing under migrate_disable the per-cpu maps are safe to use. The map-in-map were ok to use in sleepable from the time sleepable progs were introduced. Note that non-preallocated maps are still not safe, since there is no rcu_read_lock yet in sleepable programs and dynamically allocated map elements are relying on rcu protection. The sleepable programs have rcu_read_lock_trace instead. That limitation will be addresses in the future. Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Acked-by: KP Singh <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent dcf33b6 commit 638e4b8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

kernel/bpf/hashtab.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,
11481148
/* unknown flags */
11491149
return -EINVAL;
11501150

1151-
WARN_ON_ONCE(!rcu_read_lock_held());
1151+
WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
11521152

11531153
key_size = map->key_size;
11541154

@@ -1202,7 +1202,7 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,
12021202
/* unknown flags */
12031203
return -EINVAL;
12041204

1205-
WARN_ON_ONCE(!rcu_read_lock_held());
1205+
WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held());
12061206

12071207
key_size = map->key_size;
12081208

kernel/bpf/verifier.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10384,9 +10384,14 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env,
1038410384
case BPF_MAP_TYPE_HASH:
1038510385
case BPF_MAP_TYPE_LRU_HASH:
1038610386
case BPF_MAP_TYPE_ARRAY:
10387+
case BPF_MAP_TYPE_PERCPU_HASH:
10388+
case BPF_MAP_TYPE_PERCPU_ARRAY:
10389+
case BPF_MAP_TYPE_LRU_PERCPU_HASH:
10390+
case BPF_MAP_TYPE_ARRAY_OF_MAPS:
10391+
case BPF_MAP_TYPE_HASH_OF_MAPS:
1038710392
if (!is_preallocated_map(map)) {
1038810393
verbose(env,
10389-
"Sleepable programs can only use preallocated hash maps\n");
10394+
"Sleepable programs can only use preallocated maps\n");
1039010395
return -EINVAL;
1039110396
}
1039210397
break;

0 commit comments

Comments
 (0)