Re: [PATCH RFC bpf-next v2 03/18] bpf: Implement lookup, delete, update for resizable hashtab

Mykyta Yatsenko
2026-04-14T10:28:40Z

On 4/14/26 11:25 AM, Leon Hwang wrote:
> On Wed, Apr 08, 2026 at 08:10:08AM -0700, Mykyta Yatsenko wrote:
> [...]
>>
>> static int rhtab_map_lookup_and_delete_elem(struct bpf_map *map, void *key, void *value, u64 flags)
>> {
>> - return -EOPNOTSUPP;
>> + struct bpf_rhtab *rhtab = container_of(map, struct bpf_rhtab, map);
>> + struct rhtab_elem *l;
>> + int err;
>> +
>> + if ((flags & ~BPF_F_LOCK) ||
>> + ((flags & BPF_F_LOCK) && !btf_record_has_field(map->record, BPF_SPIN_LOCK)))
>> + return -EINVAL;
>
> At the moment, we can check the flags using bpf_map_check_op_flags() helper.
>
> This helper can be applied to flags check in this series.
>

Thanks, I'll use it.

>> +
>> + /* Make sure element is not deleted between lookup and copy */
>> + guard(rcu)();
>> +
>> + l = rhtab_lookup_elem(map, key);
>> + if (!l)
>> + return -ENOENT;
>> +
>> + rhtab_read_elem_value(map, value, l, flags);
>> + err = rhtab_delete_elem(rhtab, l);
>> + if (err)
>> + return err;
>> +
>> + check_and_init_map_value(map, value);
>> + return 0;
>> }
> [...]
>>
>> -static void rhtab_map_free_internal_structs(struct bpf_map *map)
>> +static long rhtab_map_update_elem(struct bpf_map *map, void *key, void *value, u64 map_flags)
>> {
>> + struct bpf_rhtab *rhtab = container_of(map, struct bpf_rhtab, map);
>> + struct rhtab_elem *elem, *tmp;
>> +
>> + if (unlikely((map_flags & ~BPF_F_LOCK) > BPF_EXIST))
>> + return -EINVAL;
>> +
>> + if ((map_flags & BPF_F_LOCK) && !btf_record_has_field(map->record, BPF_SPIN_LOCK))
>> + return -EINVAL;
>
> ditto
>
> Thanks,
> Leon
>
>> + …