Page MenuHomeFreeBSD

netlink: Add sync path in user-kernel interface
Needs ReviewPublic

Authored by zishun.yi.dev_gmail.com on Wed, Jun 10, 8:36 AM.

Details

Reviewers
melifaro
obiwac
Group Reviewers
network
Summary

My GSoC 2026 project is to implement udmabuf, which needs to pass
variable-length structures (flexible arrays) to the kernel. Neither FreeBSD's
native ioctl nor linuxkpi ioctl supports this well. Therefore, we plan to use
generic netlink, which natively supports flexible arrays.

The problem is that FreeBSD's netlink is asynchronous. It uses a taskqueue,
meaning the callback is not executed in the user's thread context. Because of
this, operations that depend on the user's process, such as translating an fd
to a file structure, cannot be implemented.

A similar issue was solved in Linux, see commit cd40b7d3983c
("[NET]: make netlink user -> kernel interface synchronious").

To solve this problem, this diff adds a sync path in nl_sosend and introduces
a new socket option NETLINK_SND_SYNC to turn it on.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 73837
Build 70720: arc lint + arc unit

Event Timeline

fix potential deadlock

Deadlock:

  • When the recv buffer is full, the async path stops processing and waits for a signal to resume, but it does not trigger a wakeup.
  • The sync path sleeps indefinitely waiting for the async path to wake it up, so it cannot signal the async path.

Solution:

  • Add a timeout to the sync path sleep and return an ENOBUFS error.
  • Signal the async path before sleeping, so it can resume processing upon the user's next retry.