Skip to content

Commit c2e42dd

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf, cpumask: Clean up bpf_cpu_map_entry directly in cpu_map_free
After synchronous_rcu(), both the dettached XDP program and xdp_do_flush() are completed, and the only user of bpf_cpu_map_entry will be cpu_map_kthread_run(), so instead of calling __cpu_map_entry_replace() to stop kthread and cleanup entry after a RCU grace period, do these things directly. Signed-off-by: Hou Tao <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 8f8500a commit c2e42dd

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

kernel/bpf/cpumap.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,15 @@ static void cpu_map_free(struct bpf_map *map)
566566
/* At this point bpf_prog->aux->refcnt == 0 and this map->refcnt == 0,
567567
* so the bpf programs (can be more than one that used this map) were
568568
* disconnected from events. Wait for outstanding critical sections in
569-
* these programs to complete. The rcu critical section only guarantees
570-
* no further "XDP/bpf-side" reads against bpf_cpu_map->cpu_map.
571-
* It does __not__ ensure pending flush operations (if any) are
572-
* complete.
569+
* these programs to complete. synchronize_rcu() below not only
570+
* guarantees no further "XDP/bpf-side" reads against
571+
* bpf_cpu_map->cpu_map, but also ensure pending flush operations
572+
* (if any) are completed.
573573
*/
574-
575574
synchronize_rcu();
576575

577-
/* For cpu_map the remote CPUs can still be using the entries
578-
* (struct bpf_cpu_map_entry).
576+
/* The only possible user of bpf_cpu_map_entry is
577+
* cpu_map_kthread_run().
579578
*/
580579
for (i = 0; i < cmap->map.max_entries; i++) {
581580
struct bpf_cpu_map_entry *rcpu;
@@ -584,8 +583,8 @@ static void cpu_map_free(struct bpf_map *map)
584583
if (!rcpu)
585584
continue;
586585

587-
/* bq flush and cleanup happens after RCU grace-period */
588-
__cpu_map_entry_replace(cmap, i, NULL); /* call_rcu */
586+
/* Stop kthread and cleanup entry directly */
587+
__cpu_map_entry_free(&rcpu->free_work.work);
589588
}
590589
bpf_map_area_free(cmap->cpu_map);
591590
bpf_map_area_free(cmap);

0 commit comments

Comments
 (0)