Re: [PATCH bpf-next v3 2/5] bpf: Add ksock kfuncs
Song Liu <[email protected]> Tue, 4 Aug 2026 21:55:44 -0700
| Newsgroups | org.kernel.vger.bpf,org.kernel.vger.netdev |
|---|---|
| Message-ID | <CAPhsuW7=6Wy31ZKqUiwOOPJA7-39y_DtJXBO8BFj+OUfgnzRWg@mail.gmail.com> |
On Tue, Aug 4, 2026 at 9:47 AM Mahe Tardy <[email protected]> wrote: [...] > +__bpf_kfunc int bpf_ksock_send(struct bpf_ksock *ks, const void *data, > + u32 data__sz) > +{ > + struct msghdr msg = { > + .msg_flags = MSG_DONTWAIT, > + }; > + struct kvec iov = { > + .iov_base = (void *)data, > + .iov_len = data__sz, > + }; > + int ret; > + > + if (!bpf_ksock_has_user_task_context()) > + return -EOPNOTSUPP; > + > + /* Early check for UDP. Exact limits enforced by kernel_sendmsg(). */ > + if (data__sz > IP_MAX_MTU) > + return -EMSGSIZE; > + > + if (current->in_bpf_ksock_send) > + return -EBUSY; Returning EBUSY is not ideal. Can we avoid recursion by disallowing calling bpf_ksock_send from certain hooks? You can find examples check_kfunc_call() or check_special_kfunc(). This probably means we need to grow special_kfunc_list, which is not ideal. @Kumar, do you have strong objection that we grow special_kfunc_list for this use case? Thanks, Song > + > + current->in_bpf_ksock_send = true; > + ret = kernel_sendmsg(ks->sock, &msg, &iov, 1, data__sz); > + current->in_bpf_ksock_send = false; > + > + return ret; > +} > + > +__bpf_kfunc_end_defs();