bpf: udp: Implement batching for sockets iterator
authorAditi Ghag <aditi.ghag@isovalent.com>
Fri, 19 May 2023 22:51:53 +0000 (22:51 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Sat, 20 May 2023 00:45:47 +0000 (17:45 -0700)
commitc96dac8d369ffd713a45f4e5c30f23c47a1671f0
treea99014cf54b2996a83335271d7ba4fb1190537f2
parente4fe1bf13e09019578b9b93b942fff3d76ed5793
bpf: udp: Implement batching for sockets iterator

Batch UDP sockets from BPF iterator that allows for overlapping locking
semantics in BPF/kernel helpers executed in BPF programs.  This facilitates
BPF socket destroy kfunc (introduced by follow-up patches) to execute from
BPF iterator programs.

Previously, BPF iterators acquired the sock lock and sockets hash table
bucket lock while executing BPF programs. This prevented BPF helpers that
again acquire these locks to be executed from BPF iterators.  With the
batching approach, we acquire a bucket lock, batch all the bucket sockets,
and then release the bucket lock. This enables BPF or kernel helpers to
skip sock locking when invoked in the supported BPF contexts.

The batching logic is similar to the logic implemented in TCP iterator:
https://lore.kernel.org/bpf/20210701200613.1036157-1-kafai@fb.com/.

Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com>
Link: https://lore.kernel.org/r/20230519225157.760788-6-aditi.ghag@isovalent.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
net/ipv4/udp.c