mem-buf: Add flush_delayed_fput() calls to recv kthread

When a kernel thread calls dma_buf_put() to release the last reference
to a dma-buf, fput_many() defers calling the release callback to a
workqueue. This means that if the same kernel thread later calls
dma_heap_buffer_alloc(), it has no guarantee that the memory from the
prior free is available, leading to random failures. As a short-term
workaround, call flush_delayed_fput() to ensure the free completes
synchronously.

Change-Id: Ia2ab97ca9d1adfb99cd20a316d412bf931f7b3f0
Signed-off-by: Patrick Daly <quic_pdaly@quicinc.com>
This commit is contained in:
Patrick Daly 2021-12-13 22:28:12 -08:00 committed by Chris Goldsworthy
parent 2f83e4db8c
commit 02ad0f4aca

View File

@ -222,6 +222,13 @@ static void mem_buf_rmt_free_dmaheap_mem(struct mem_buf_xfer_mem *xfer_mem)
dma_buf_unmap_attachment(attachment, mem_sgt, DMA_BIDIRECTIONAL);
dma_buf_detach(dmabuf, attachment);
dma_buf_put(dmaheap_mem_data->dmabuf);
/*
* No locks should be held at this point, as flush_delayed_fput may call the
* release callbacks of arbitrary files. It should be safe for us since we
* know this function is called only from our recv kthread, so we have control
* over what locks are currently held.
*/
flush_delayed_fput();
pr_debug("%s: DMAHEAP memory freed\n", __func__);
}