Page MenuHomeFreeBSD

linuxkpi: Support flexible array members in ioctl
AbandonedPublic

Authored by zishun.yi.dev_gmail.com on Feb 17 2026, 1:46 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jun 4, 9:53 AM
Unknown Object (File)
May 18 2026, 6:13 AM
Unknown Object (File)
May 17 2026, 10:29 PM
Unknown Object (File)
May 17 2026, 10:29 PM
Unknown Object (File)
May 15 2026, 3:48 AM
Unknown Object (File)
May 10 2026, 2:04 AM
Unknown Object (File)
May 10 2026, 2:01 AM
Unknown Object (File)
May 9 2026, 10:06 PM

Details

Reviewers
obiwac
zlei
bz
Group Reviewers
linuxkpi
Summary

The Linux ioctl scheme passes raw user-space pointers to drivers,
natively supporting Flexible Array Members (FAM). In contrast, linuxkpi
currently relies on FreeBSD's sys_ioctl automatic copying. It provides a
"fake" pointer backed by fixed-size kernel memory, which fails for FAMs
and does not fully conform to Linux ioctl semantics.

This patch adds a fallback mechanism in linux_remap_address() that uses
the original user-space pointer when access exceeds the pre-copied
kernel buffer.

I do a simple static scan of Linux 6.19 UAPI headers indicates that more
than 30 structures across subsystems (including KVM, USB, and DRM) rely
on this pattern. It seems like a valuable compatibility improvement for
future driver ports like udmabuf.

Link: https://mail-archive.freebsd.org/cgi/getmsg.cgi?fetch=408318+0+archive/2026/freebsd-hackers/20260216.freebsd-hackers
Signed-off-by: Zishun Yi <zishun.yi.dev@gmail.com>

Diff Detail

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

Event Timeline

sys/compat/linuxkpi/common/src/linux_compat.c
932

I was wondering if there is a cleaner way to retrieve the user-space pointer?

To support the FAM cmd for udmabuf, I first decided to improve the linuxkpi ioctl through this patch, but due to some hacks in this patch and the suggestion from my GSoC mentor Aymeric, I decided to enhance the native FreeBSD ioctl call stack - to let the native FreeBSD ioctl support FAM.

After further discussion with Aymeric, we concluded that ioctl was fundamentally designed for fixed-format C structures, not variable-length payloads. Ultimately, we decided to drop the ioctl interface and use Netlink, a message-based user-kernel communication protocol. It is more modern, introspective, and most importantly, it natively supports FAM.

Therefore, this patch might be useful for future Linux compatibility, but at least for now it is useless for udmabuf.
So I think I will temporarily abandon this patch.