Date: Fri, 13 Feb 2026 17:56:00 +0800 From: yi zishun <zishun.yi.dev@gmail.com> To: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Should linuxkpi linux_file_ioctl support flexible array copy? Message-ID: <CABjVtiZGjzmPi_p_Q5UEBQmf5cLEMrYY9%2Bxd8RZaeOwbwRM2gg@mail.gmail.com>
index | next in thread | raw e-mail
[-- Attachment #1 --]
Hey Hackers, I want to port udmabuf from Linux to FreeBSD, but I
encountered a problem:
udmabuf.h declares the interface which I don't want to touch or change:
...
struct udmabuf_create_list {
__u32 flags;
__u32 count;
struct udmabuf_create_item list[];
};
#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create)
#define UDMABUF_CREATE_LIST _IOW('u', 0x43, struct
udmabuf_create_list)
...
It has a flexible array and uses `_IOW`, which means the FreeBSD native
KPI (`cdevsw` ioctl) cannot get the userspace pointer to get the items
list.
So I turned to linuxkpi, but unfortunately I found that if I define
`_IOW`, Linuxkpi's `linux_file_ioctl` is only allowed to get the kernel
space pointer, just like the FreeBSD KPI. So I can't copy the flexible
array from userspace.
So I have two ways to go:
1.Change the command to use `_IO` instead of `_IOW` to prevent copying
by `sys_ioctl`. This means I will change the ABI.
2.Try to figure out a way to empower linuxkpi to skip `sys_ioctl`
helping to get the userspace pointer. This will be a big piece of work.
Any recommendations on how to handle this gracefully? Thanks~
(BTW, I'm a kernel rookie hoping to tackle the GSoC 2026 'Port or
reimplement udmabuf' project. For context, my current WIP code is here:
https://github.com/yizishun/drm-kmod/blob/dev-udmabuf/drivers/dma-buf/udmabuf.c
)
[-- Attachment #2 --]
<div>Hey Hackers, I want to port udmabuf from Linux to FreeBSD, but I<br>
encountered a problem:<br>
udmabuf.h declares the interface which I don't want to touch or change:<br>
<br>
...<br>
struct udmabuf_create_list {<br>
__u32 flags;<br>
__u32 count;<br>
struct udmabuf_create_item list[];<br>
};<br>
#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create)<br>
#define UDMABUF_CREATE_LIST _IOW('u', 0x43, struct udmabuf_create_list)<br>
...<br>
<br>
It has a flexible array and uses `_IOW`, which means the FreeBSD native<br>
KPI (`cdevsw` ioctl) cannot get the userspace pointer to get the items<br>
list.<br>
<br>
So I turned to linuxkpi, but unfortunately I found that if I define<br>
`_IOW`, Linuxkpi's `linux_file_ioctl` is only allowed to get the kernel<br>
space pointer, just like the FreeBSD KPI. So I can't copy the flexible<br>
array from userspace.<br>
<br>
So I have two ways to go:<br>
1.Change the command to use `_IO` instead of `_IOW` to prevent copying<br>
by `sys_ioctl`. This means I will change the ABI.<br>
2.Try to figure out a way to empower linuxkpi to skip `sys_ioctl`<br>
helping to get the userspace pointer. This will be a big piece of work.<br>
<br>
Any recommendations on how to handle this gracefully? Thanks~<br>
<br>
(BTW, I'm a kernel rookie hoping to tackle the GSoC 2026 'Port or<br>
reimplement udmabuf' project. For context, my current WIP code is here:<br>
<a href="https://github.com/yizishun/drm-kmod/blob/dev-udmabuf/drivers/dma-buf/udmabuf.c" rel="noreferrer" target="_blank">https://github.com/yizishun/drm-kmod/blob/dev-udmabuf/drivers/dma-buf/udmabuf.c</a>)<br>
</div>
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CABjVtiZGjzmPi_p_Q5UEBQmf5cLEMrYY9%2Bxd8RZaeOwbwRM2gg>
