Skip to content

Commit 8477fe1

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-fixes-for-maybe_wait_bpf_programs'
Hou Tao says: ==================== The patch set aims to fix the problems found when inspecting the code related with maybe_wait_bpf_programs(). Patch #1 removes unnecessary invocation of maybe_wait_bpf_programs(). Patch #2 calls maybe_wait_bpf_programs() only once for batched update. Patch #3 adds the missed waiting when doing batched lookup_deletion on htab of maps. Patch #4 does wait only if the update or deletion operation succeeds. Patch #5 fixes the value of batch.count when memory allocation fails. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 32fa058 + 06e5c99 commit 8477fe1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

kernel/bpf/syscall.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ static int bpf_map_update_value(struct bpf_map *map, struct file *map_file,
203203
rcu_read_unlock();
204204
}
205205
bpf_enable_instrumentation();
206-
maybe_wait_bpf_programs(map);
207206

208207
return err;
209208
}
@@ -264,7 +263,6 @@ static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,
264263
}
265264

266265
bpf_enable_instrumentation();
267-
maybe_wait_bpf_programs(map);
268266

269267
return err;
270268
}
@@ -1578,6 +1576,8 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
15781576
}
15791577

15801578
err = bpf_map_update_value(map, f.file, key, value, attr->flags);
1579+
if (!err)
1580+
maybe_wait_bpf_programs(map);
15811581

15821582
kvfree(value);
15831583
free_key:
@@ -1633,7 +1633,8 @@ static int map_delete_elem(union bpf_attr *attr, bpfptr_t uattr)
16331633
err = map->ops->map_delete_elem(map, key);
16341634
rcu_read_unlock();
16351635
bpf_enable_instrumentation();
1636-
maybe_wait_bpf_programs(map);
1636+
if (!err)
1637+
maybe_wait_bpf_programs(map);
16371638
out:
16381639
kvfree(key);
16391640
err_put:
@@ -1730,6 +1731,9 @@ int generic_map_delete_batch(struct bpf_map *map,
17301731
if (!max_count)
17311732
return 0;
17321733

1734+
if (put_user(0, &uattr->batch.count))
1735+
return -EFAULT;
1736+
17331737
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
17341738
if (!key)
17351739
return -ENOMEM;
@@ -1759,7 +1763,6 @@ int generic_map_delete_batch(struct bpf_map *map,
17591763

17601764
kvfree(key);
17611765

1762-
maybe_wait_bpf_programs(map);
17631766
return err;
17641767
}
17651768

@@ -1787,6 +1790,9 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
17871790
if (!max_count)
17881791
return 0;
17891792

1793+
if (put_user(0, &uattr->batch.count))
1794+
return -EFAULT;
1795+
17901796
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
17911797
if (!key)
17921798
return -ENOMEM;
@@ -1817,6 +1823,7 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
18171823

18181824
kvfree(value);
18191825
kvfree(key);
1826+
18201827
return err;
18211828
}
18221829

@@ -5030,8 +5037,10 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
50305037
else
50315038
BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
50325039
err_put:
5033-
if (has_write)
5040+
if (has_write) {
5041+
maybe_wait_bpf_programs(map);
50345042
bpf_map_write_active_dec(map);
5043+
}
50355044
fdput(f);
50365045
return err;
50375046
}

0 commit comments

Comments
 (0)