mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-27 12:57:53 +00:00
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/20231208102355.2628918-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
commit
8477fe1de9
1 changed files with 14 additions and 5 deletions
|
@ -203,7 +203,6 @@ static int bpf_map_update_value(struct bpf_map *map, struct file *map_file,
|
|||
rcu_read_unlock();
|
||||
}
|
||||
bpf_enable_instrumentation();
|
||||
maybe_wait_bpf_programs(map);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -264,7 +263,6 @@ static int bpf_map_copy_value(struct bpf_map *map, void *key, void *value,
|
|||
}
|
||||
|
||||
bpf_enable_instrumentation();
|
||||
maybe_wait_bpf_programs(map);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -1578,6 +1576,8 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr)
|
|||
}
|
||||
|
||||
err = bpf_map_update_value(map, f.file, key, value, attr->flags);
|
||||
if (!err)
|
||||
maybe_wait_bpf_programs(map);
|
||||
|
||||
kvfree(value);
|
||||
free_key:
|
||||
|
@ -1633,7 +1633,8 @@ static int map_delete_elem(union bpf_attr *attr, bpfptr_t uattr)
|
|||
err = map->ops->map_delete_elem(map, key);
|
||||
rcu_read_unlock();
|
||||
bpf_enable_instrumentation();
|
||||
maybe_wait_bpf_programs(map);
|
||||
if (!err)
|
||||
maybe_wait_bpf_programs(map);
|
||||
out:
|
||||
kvfree(key);
|
||||
err_put:
|
||||
|
@ -1730,6 +1731,9 @@ int generic_map_delete_batch(struct bpf_map *map,
|
|||
if (!max_count)
|
||||
return 0;
|
||||
|
||||
if (put_user(0, &uattr->batch.count))
|
||||
return -EFAULT;
|
||||
|
||||
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
|
||||
if (!key)
|
||||
return -ENOMEM;
|
||||
|
@ -1759,7 +1763,6 @@ int generic_map_delete_batch(struct bpf_map *map,
|
|||
|
||||
kvfree(key);
|
||||
|
||||
maybe_wait_bpf_programs(map);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -1787,6 +1790,9 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
|
|||
if (!max_count)
|
||||
return 0;
|
||||
|
||||
if (put_user(0, &uattr->batch.count))
|
||||
return -EFAULT;
|
||||
|
||||
key = kvmalloc(map->key_size, GFP_USER | __GFP_NOWARN);
|
||||
if (!key)
|
||||
return -ENOMEM;
|
||||
|
@ -1817,6 +1823,7 @@ int generic_map_update_batch(struct bpf_map *map, struct file *map_file,
|
|||
|
||||
kvfree(value);
|
||||
kvfree(key);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -5030,8 +5037,10 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
|
|||
else
|
||||
BPF_DO_BATCH(map->ops->map_delete_batch, map, attr, uattr);
|
||||
err_put:
|
||||
if (has_write)
|
||||
if (has_write) {
|
||||
maybe_wait_bpf_programs(map);
|
||||
bpf_map_write_active_dec(map);
|
||||
}
|
||||
fdput(f);
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue