From 02ad0f4aca376902ddb5069d8362e1817c808c48 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Mon, 13 Dec 2021 22:28:12 -0800 Subject: [PATCH 1/3] 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 --- drivers/soc/qcom/mem_buf/mem-buf-gh.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/soc/qcom/mem_buf/mem-buf-gh.c b/drivers/soc/qcom/mem_buf/mem-buf-gh.c index 8e145e37cd89..6bbd10ba1777 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-gh.c +++ b/drivers/soc/qcom/mem_buf/mem-buf-gh.c @@ -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__); } From 2ac7e03c0bc07cbf33887c574f1b0c4640f3ebb3 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Fri, 25 Mar 2022 20:53:11 -0700 Subject: [PATCH 2/3] dma-heaps: Fix compiler warning with function stubs Fixes: error: unused function 'qcom_carveout_heap_create'. Change-Id: I1525a3455b045c2e527847b26bfa7df5b6cf19dc Signed-off-by: Patrick Daly --- drivers/dma-buf/heaps/qcom_carveout_heap.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/dma-buf/heaps/qcom_carveout_heap.h b/drivers/dma-buf/heaps/qcom_carveout_heap.h index 6bd8c3478dae..a67e1ce0eb52 100644 --- a/drivers/dma-buf/heaps/qcom_carveout_heap.h +++ b/drivers/dma-buf/heaps/qcom_carveout_heap.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #ifndef _QCOM_CARVEOUT_HEAP_H @@ -12,13 +13,13 @@ int qcom_secure_carveout_heap_create(struct platform_heap *heap_data); int qcom_carveout_heap_create(struct platform_heap *heap_data); #else -static int qcom_secure_carveout_heap_create(struct platform_heap *heap_data) +static inline int qcom_secure_carveout_heap_create(struct platform_heap *heap_data) { - return 1; + return -EINVAL; } -static int qcom_carveout_heap_create(struct platform_heap *heap_data) +static inline int qcom_carveout_heap_create(struct platform_heap *heap_data) { - return 1; + return -EINVAL; } #endif From 8145bbae35b75aafc9356dec426c29decbe7a5d8 Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Mon, 9 May 2022 10:34:11 -0700 Subject: [PATCH 3/3] mem-buf: Add accessor for mem_buf_desc sgl list Allow clients to see what IPA address a mem_buf object is mapped to. Change-Id: Ib3d47cb78bf7b1b217950e1e59b8d542abb3a331 Signed-off-by: Patrick Daly --- drivers/soc/qcom/mem_buf/mem-buf-gh.c | 8 ++++++++ include/linux/mem-buf.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/drivers/soc/qcom/mem_buf/mem-buf-gh.c b/drivers/soc/qcom/mem_buf/mem-buf-gh.c index 6bbd10ba1777..a5b56f4b41dd 100644 --- a/drivers/soc/qcom/mem_buf/mem-buf-gh.c +++ b/drivers/soc/qcom/mem_buf/mem-buf-gh.c @@ -1145,6 +1145,14 @@ static int get_mem_buf(void *membuf_desc) return 0; } +struct gh_sgl_desc *mem_buf_get_sgl(void *__membuf) +{ + struct mem_buf_desc *membuf = __membuf; + + return membuf->sgl_desc; +} +EXPORT_SYMBOL(mem_buf_get_sgl); + static void mem_buf_retrieve_release(struct qcom_sg_buffer *buffer) { sg_free_table(&buffer->sg_table); diff --git a/include/linux/mem-buf.h b/include/linux/mem-buf.h index f9e1ecb07b3f..3f69e1d9755a 100644 --- a/include/linux/mem-buf.h +++ b/include/linux/mem-buf.h @@ -104,6 +104,7 @@ void mem_buf_put(void *membuf_desc); void *mem_buf_get(int fd); +struct gh_sgl_desc *mem_buf_get_sgl(void *membuf); #else static inline int mem_buf_get_fd(void *membuf_desc) @@ -120,5 +121,9 @@ static inline void *mem_buf_get(int fd) return ERR_PTR(-ENODEV); } +static inline struct gh_sgl_desc *mem_buf_get_sgl(void *membuf) +{ + return ERR_PTR(-EINVAL); +} #endif /* CONFIG_QCOM_MEM_BUF */ #endif /* _MEM_BUF_H */