Skip to content

Commit 862b416

Browse files
pcercueigregkh
authored andcommitted
usb: gadget: functionfs: Wait for fences before enqueueing DMABUF
Instead of bailing when fences have already been installed on the DMABUF, wait for them (with a timeout) when doing a blocking operation. This fixes the issue where userspace would submit a DMABUF with fences already installed, with the (correct) expectation that it would just work. Fixes: 7b07a2a ("usb: gadget: functionfs: Add DMABUF import interface") Signed-off-by: Paul Cercueil <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1500a7b commit 862b416

File tree

1 file changed

+12
-11
lines changed
  • drivers/usb/gadget/function

1 file changed

+12
-11
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
4848

49+
#define DMABUF_ENQUEUE_TIMEOUT_MS 5000
50+
4951
MODULE_IMPORT_NS(DMA_BUF);
5052

5153
/* Reference counter handling */
@@ -1580,9 +1582,11 @@ static int ffs_dmabuf_transfer(struct file *file,
15801582
struct usb_request *usb_req;
15811583
enum dma_resv_usage resv_dir;
15821584
struct dma_buf *dmabuf;
1585+
unsigned long timeout;
15831586
struct ffs_ep *ep;
15841587
bool cookie;
15851588
u32 seqno;
1589+
long retl;
15861590
int ret;
15871591

15881592
if (req->flags & ~USB_FFS_DMABUF_TRANSFER_MASK)
@@ -1616,17 +1620,14 @@ static int ffs_dmabuf_transfer(struct file *file,
16161620
goto err_attachment_put;
16171621

16181622
/* Make sure we don't have writers */
1619-
if (!dma_resv_test_signaled(dmabuf->resv, DMA_RESV_USAGE_WRITE)) {
1620-
pr_vdebug("FFS WRITE fence is not signaled\n");
1621-
ret = -EBUSY;
1622-
goto err_resv_unlock;
1623-
}
1624-
1625-
/* If we're writing to the DMABUF, make sure we don't have readers */
1626-
if (epfile->in &&
1627-
!dma_resv_test_signaled(dmabuf->resv, DMA_RESV_USAGE_READ)) {
1628-
pr_vdebug("FFS READ fence is not signaled\n");
1629-
ret = -EBUSY;
1623+
timeout = nonblock ? 0 : msecs_to_jiffies(DMABUF_ENQUEUE_TIMEOUT_MS);
1624+
retl = dma_resv_wait_timeout(dmabuf->resv,
1625+
dma_resv_usage_rw(epfile->in),
1626+
true, timeout);
1627+
if (retl == 0)
1628+
retl = -EBUSY;
1629+
if (retl < 0) {
1630+
ret = (int)retl;
16301631
goto err_resv_unlock;
16311632
}
16321633

0 commit comments

Comments
 (0)