KDBUS in FreeBSD
Things in the Linux world (e.g. GNOME, systemd) are increasingly moving towards requiring kdbus support from the kernel. This page contains notes on what a FreeBSD implementation will look like.
Goals
The FreeBSD implementation has the following basic requirements:
- Source compatibility with Linux kdbus
- Integration with Capsicum and other FreeBSD features (audit, MAC)
- Kernel changes only where required for performance
- Use existing UNIX APIs where possible (e.g. aio_read() for one-copy I/O).
Kdbus on Linux has two major components: IPC and namespace management. The IPC component allows:
- Support point-to-point and multicast messaging
- Fast one-copy messaging
- Message-oriented protocol
- Userspace and kernel endpoints
- Messages contain bytes and / or file descriptors
The namespace management is responsible for creating hierarchies (under /dev in Linux) containing the busses.
High-level design
Endpoints should be represented by a new kind of file descriptor, which should support all of the capsicum restrictions. These should be either anonymous or present in the filesystem. Placing them in the filesystem allows a userspace component to manage the namespace. Anonymous endpoints allow integration with Capsicum by providing endpoints to sandboxed processes without ever placing them in a global namespace.
Implementation
According to https://lwn.net/Articles/580194/ kdbus is implemented as a character device in the kernel. Process then join the bus by opening the device path (its unique name space) and then use mmap() memory for the message buffer using the file descriptor.
One question is how much of the IPC should be implemented in the kernel. The following email thread seems to indicate there is some pretty good overhead compared to a simpler IPC (i.e. pipe): http://lists.freedesktop.org/archives/systemd-devel/2014-March/017563.html Note the overhead is hidden, however, for very large messages. Of course, the two don't really compare feature wise.