Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DMA_BUF_IOCTL_SYNC doesn't work #156

Open
jbeich opened this issue Jul 2, 2019 · 3 comments
Open

DMA_BUF_IOCTL_SYNC doesn't work #156

jbeich opened this issue Jul 2, 2019 · 3 comments

Comments

@jbeich
Copy link

jbeich commented Jul 2, 2019

EDIT: Description has been rewritten as the initial test case was incorrect.

Waypipe (package, workaround) relies on DMA_BUF_IOCTL_SYNC to check if a given file descripter is backed by DMABUF. On FreeBSD the ioctl always fails with EBADF which is unexpected according to the implementation:

static int
dma_buf_ioctl(struct file *fp, u_long com, void *data,
struct ucred *active_cred, struct thread *td)
{
struct dma_buf *db;
struct dma_buf_sync *sync;
enum dma_data_direction dir;
int rc;
if (!fp_is_db(fp))
return (EINVAL);
db = fp->f_data;
sync = data;
rc = 0;
switch (com) {
case DMA_BUF_IOCTL_SYNC:
if (sync->flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK)
return (EINVAL);
switch (sync->flags & DMA_BUF_SYNC_RW) {
case DMA_BUF_SYNC_READ:
dir = DMA_FROM_DEVICE;
break;
case DMA_BUF_SYNC_WRITE:
dir = DMA_TO_DEVICE;
break;
case DMA_BUF_SYNC_RW:
dir = DMA_BIDIRECTIONAL;
break;
default:
return (EINVAL);
}
if (sync->flags & DMA_BUF_SYNC_END)
rc = dma_buf_end_cpu_access(db, dir);
else
rc = dma_buf_begin_cpu_access(db, dir);
return (-rc);
default:
return (ENOTTY);
}
/* UNREACHED */
return (0);
}

Test case: https://gitlab.freedesktop.org/snippets/621

@mstoeckl
Copy link

mstoeckl commented Jul 2, 2019

The invalid flags used by waypipe are something of a hack, for lack of an easier way to generically detect DMABUFs on Linux without trying to import with GBM or using driver-specific code.

Also, FYI, the Linux version is https://github.com/torvalds/linux/blob/master/drivers/dma-buf/dma-buf.c#L279.

Edit: The sample code tries the ioctl on an fd for a render node, not for a DMABUF.

@jbeich jbeich closed this as completed Jul 2, 2019
@jbeich jbeich changed the title DMA_BUF_IOCTL_SYNC is broken: accepts invalid flags DMA_BUF_IOCTL_SYNC doesn't work Aug 31, 2019
@jbeich jbeich reopened this Aug 31, 2019
@jbeich
Copy link
Author

jbeich commented Jun 16, 2022

Can someone try reproducing using DMA-BUF reimplementation ? drm-subtree doesn't seem to have i915 or amdgpu, so testing on amd64 is not currently possible.

@mstoeckl
Copy link

For future reference: Waypipe no longer relies on this behavior on FreeBSD, since v0.8.0, which was released more than a year ago. As of recent git commits, it has also stopped using the EBADF hack on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants