bpf: allow struct bpf_wq to be embedded in arraymaps and hashmaps
Currently bpf_wq_cancel_and_free() is just a placeholder as there is no memory allocation for bpf_wq just yet. Again, duplication of the bpf_timer approach Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> Link: https://lore.kernel.org/r/20240420-bpf_wq-v2-9-6c986a5a741f@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Alexei Starovoitov
parent
d940c9b94d
commit
246331e3f1
+11
-7
@@ -428,17 +428,21 @@ static void *array_map_vmalloc_addr(struct bpf_array *array)
|
||||
return (void *)round_down((unsigned long)array, PAGE_SIZE);
|
||||
}
|
||||
|
||||
static void array_map_free_timers(struct bpf_map *map)
|
||||
static void array_map_free_timers_wq(struct bpf_map *map)
|
||||
{
|
||||
struct bpf_array *array = container_of(map, struct bpf_array, map);
|
||||
int i;
|
||||
|
||||
/* We don't reset or free fields other than timer on uref dropping to zero. */
|
||||
if (!btf_record_has_field(map->record, BPF_TIMER))
|
||||
return;
|
||||
/* We don't reset or free fields other than timer and workqueue
|
||||
* on uref dropping to zero.
|
||||
*/
|
||||
if (btf_record_has_field(map->record, BPF_TIMER))
|
||||
for (i = 0; i < array->map.max_entries; i++)
|
||||
bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i));
|
||||
|
||||
for (i = 0; i < array->map.max_entries; i++)
|
||||
bpf_obj_free_timer(map->record, array_map_elem_ptr(array, i));
|
||||
if (btf_record_has_field(map->record, BPF_WORKQUEUE))
|
||||
for (i = 0; i < array->map.max_entries; i++)
|
||||
bpf_obj_free_workqueue(map->record, array_map_elem_ptr(array, i));
|
||||
}
|
||||
|
||||
/* Called when map->refcnt goes to zero, either from workqueue or from syscall */
|
||||
@@ -782,7 +786,7 @@ const struct bpf_map_ops array_map_ops = {
|
||||
.map_alloc = array_map_alloc,
|
||||
.map_free = array_map_free,
|
||||
.map_get_next_key = array_map_get_next_key,
|
||||
.map_release_uref = array_map_free_timers,
|
||||
.map_release_uref = array_map_free_timers_wq,
|
||||
.map_lookup_elem = array_map_lookup_elem,
|
||||
.map_update_elem = array_map_update_elem,
|
||||
.map_delete_elem = array_map_delete_elem,
|
||||
|
||||
Reference in New Issue
Block a user