Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,19 @@ union bpf_iter_link_info {
* returning the lock. This must be specified if the
* elements contain a spinlock.
*
* On success, *count* elements from the map are copied into the
* user buffer, with the keys copied into *keys* and the values
* copied into the corresponding indices in *values*.
*
* If an error is returned and *errno* is not **EFAULT**, *count*
* is set to the number of successfully processed elements.
* On success, up to *count* elements from the map are copied into
* the user buffer, with the keys copied into *keys* and the
* values copied into the corresponding indices in *values*.
*
* Return
* Returns zero on success. On error, -1 is returned and *errno*
* is set appropriately.
*
* If an error is returned and *errno* is not **EFAULT**, then
* *count* is set to the number of successfully processed
* elements. In particular, the *errno* may be set to **ENOENT**
* in case of success to indicate that the end of map is reached.
*
* May set *errno* to **ENOSPC** to indicate that *keys* or
* *values* is too small to dump an entire bucket during
* iteration of a hash-based map type.
Expand All @@ -655,15 +657,15 @@ union bpf_iter_link_info {
* **BPF_MAP_LOOKUP_BATCH** with two exceptions:
*
* * Every element that is successfully returned is also deleted
* from the map. This is at least *count* elements. Note that
* *count* is both an input and an output parameter.
* from the map. The *count* parameter is set to the number of
* returned elements. This value can be less than the actual
* number of deleted elements, see the next item.
* * Upon returning with *errno* set to **EFAULT**, up to
* *count* elements may be deleted without returning the keys
* and values of the deleted elements.
*
* Return
* Returns zero on success. On error, -1 is returned and *errno*
* is set appropriately.
* Same as the BPF_MAP_LOOKUP_BATCH return values.
*
* BPF_MAP_UPDATE_BATCH
* Description
Expand Down
14 changes: 7 additions & 7 deletions kernel/bpf/hashtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,13 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,
struct bucket *b;
int ret = 0;

max_count = attr->batch.count;
if (!max_count)
return 0;

if (put_user(0, &uattr->batch.count))
return -EFAULT;

elem_map_flags = attr->batch.elem_flags;
if ((elem_map_flags & ~BPF_F_LOCK) ||
((elem_map_flags & BPF_F_LOCK) && !btf_record_has_field(map->record, BPF_SPIN_LOCK)))
Expand All @@ -1701,13 +1708,6 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,
if (map_flags)
return -EINVAL;

max_count = attr->batch.count;
if (!max_count)
return 0;

if (put_user(0, &uattr->batch.count))
return -EFAULT;

batch = 0;
if (ubatch && copy_from_user(&batch, ubatch, sizeof(batch)))
return -EFAULT;
Expand Down