LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Add changes for cached buffer and persistent header buffers
@ 2023-06-09 10:39 Ekansh Gupta
  2023-06-09 10:39 ` [PATCH v1 1/2] misc: fastrpc: Add cached buffer support Ekansh Gupta
  2023-06-09 10:39 ` [PATCH v1 2/2] misc: fastrpc: Add persistent header " Ekansh Gupta
  0 siblings, 2 replies; 5+ messages in thread
From: Ekansh Gupta @ 2023-06-09 10:39 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-arm-msm
  Cc: Ekansh Gupta, ekangupt, gregkh, linux-kernel, fastrpc.upstream,
	quic_anane

This patch series carries changes to reduce RPC call overhead by
skippikng DMA API allocation calls for all type of buffer allocation
requests.

Cached buffer support enables caching of allocated buffers
instead of freeing which can be reused for any new request.

Persistent header buffer changes allocated a number for header
buffers during CDSP process initialization which is then used
for remote calls by the process.

When any process make a remote call, the metadata buffer is first
tried to be used from allocated persistent header buffers. If due
to any reason, persistent header buffers are not available, the
allocation request falls back to cached buffers and allocations
using DMA API.

Ekansh Gupta (2):
  misc: fastrpc: Add cached buffer support
  misc: fastrpc: Add persistent header buffer support

 drivers/misc/fastrpc.c      | 348 ++++++++++++++++++++++++++++++++++++--------
 include/uapi/misc/fastrpc.h |   8 +
 2 files changed, 295 insertions(+), 61 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/2] misc: fastrpc: Add cached buffer support
  2023-06-09 10:39 [PATCH v1 0/2] Add changes for cached buffer and persistent header buffers Ekansh Gupta
@ 2023-06-09 10:39 ` Ekansh Gupta
  2023-06-12 12:55   ` Srinivas Kandagatla
  2023-06-09 10:39 ` [PATCH v1 2/2] misc: fastrpc: Add persistent header " Ekansh Gupta
  1 sibling, 1 reply; 5+ messages in thread
From: Ekansh Gupta @ 2023-06-09 10:39 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-arm-msm
  Cc: Ekansh Gupta, ekangupt, gregkh, linux-kernel, fastrpc.upstream,
	quic_anane

FastRPC driver uses DMA API for region allocation for any buf_alloc
request and the DMA region is unmap and freed once the usage is
complete.

Cached buffer support enables caching of certain types of buffers
instead of freeing which help in reducing the overhead of DMA API
call for every buffer allocation request.

A list of cached buffer is maintained which will get reused when
needed and this buffer list will get freed during device release.

Co-developed-by: Anandu Krishnan E <quic_anane@quicinc.com>
Signed-off-by: Anandu Krishnan E <quic_anane@quicinc.com>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
---
 drivers/misc/fastrpc.c      | 133 +++++++++++++++++++++++++++++++++++++-------
 include/uapi/misc/fastrpc.h |   8 +++
 2 files changed, 122 insertions(+), 19 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 30d4d04..a961a66 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -41,6 +41,10 @@
 #define INIT_FILE_NAMELEN_MAX (128)
 #define FASTRPC_DEVICE_NAME	"fastrpc"
 
+/* Maximum buffers cached in cached buffer list */
+#define FASTRPC_MAX_CACHED_BUFS (32)
+#define FASTRPC_MAX_CACHE_BUF_SIZE (8*1024*1024)
+
 /* Add memory to static PD pool, protection thru XPU */
 #define ADSP_MMAP_HEAP_ADDR  4
 /* MAP static DMA buffer on DSP User PD */
@@ -195,6 +199,7 @@ struct fastrpc_buf {
 	struct dma_buf *dmabuf;
 	struct device *dev;
 	void *virt;
+	u32 type;
 	u64 phys;
 	u64 size;
 	/* Lock for dma buf attachments */
@@ -293,6 +298,7 @@ struct fastrpc_user {
 	struct list_head maps;
 	struct list_head pending;
 	struct list_head mmaps;
+	struct list_head cached_bufs;
 
 	struct fastrpc_channel_ctx *cctx;
 	struct fastrpc_session_ctx *sctx;
@@ -300,6 +306,8 @@ struct fastrpc_user {
 
 	int tgid;
 	int pd;
+	/* total cached buffers */
+	u32 num_cached_buf;
 	bool is_secure_dev;
 	/* Lock for lists */
 	spinlock_t lock;
@@ -391,17 +399,95 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,
 	return ret;
 }
 
-static void fastrpc_buf_free(struct fastrpc_buf *buf)
+static void __fastrpc_buf_free(struct fastrpc_buf *buf)
 {
 	dma_free_coherent(buf->dev, buf->size, buf->virt,
 			  FASTRPC_PHYS(buf->phys));
 	kfree(buf);
 }
 
+static void fastrpc_cached_buf_list_add(struct fastrpc_buf *buf)
+{
+	struct fastrpc_user *fl = buf->fl;
+
+	if (buf->size < FASTRPC_MAX_CACHE_BUF_SIZE) {
+		spin_lock(&fl->lock);
+		if (fl->num_cached_buf > FASTRPC_MAX_CACHED_BUFS) {
+			spin_unlock(&fl->lock);
+			goto skip_buf_cache;
+		}
+
+		list_add_tail(&buf->node, &fl->cached_bufs);
+		fl->num_cached_buf++;
+		buf->type = -1;
+		spin_unlock(&fl->lock);
+	}
+	return;
+
+skip_buf_cache:
+	__fastrpc_buf_free(buf);
+}
+
+static void fastrpc_buf_free(struct fastrpc_buf *buf, bool cache)
+{
+	if (cache)
+		fastrpc_cached_buf_list_add(buf);
+	else
+		__fastrpc_buf_free(buf);
+}
+
+static inline bool fastrpc_get_cached_buf(struct fastrpc_user *fl,
+		size_t size, int buf_type, struct fastrpc_buf **obuf)
+{
+	bool found = false;
+	struct fastrpc_buf *buf, *n, *cbuf = NULL;
+
+	if (buf_type == USER_BUF)
+		return found;
+
+	/* find the smallest buffer that fits in the cache */
+	spin_lock(&fl->lock);
+	list_for_each_entry_safe(buf, n, &fl->cached_bufs, node) {
+		if (buf->size >= size && (!cbuf || cbuf->size > buf->size))
+			cbuf = buf;
+	}
+	if (cbuf) {
+		list_del_init(&cbuf->node);
+		fl->num_cached_buf--;
+	}
+	spin_unlock(&fl->lock);
+	if (cbuf) {
+		cbuf->type = buf_type;
+		*obuf = cbuf;
+		found = true;
+	}
+
+	return found;
+}
+
+static void fastrpc_cached_buf_list_free(struct fastrpc_user *fl)
+{
+	struct fastrpc_buf *buf, *n, *free;
+
+	do {
+		free = NULL;
+		spin_lock(&fl->lock);
+		list_for_each_entry_safe(buf, n, &fl->cached_bufs, node) {
+			list_del(&buf->node);
+			fl->num_cached_buf--;
+			free = buf;
+			break;
+		}
+		spin_unlock(&fl->lock);
+		if (free)
+			fastrpc_buf_free(free, false);
+	} while (free);
+}
+
 static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 			     u64 size, struct fastrpc_buf **obuf)
 {
-	struct fastrpc_buf *buf;
+	struct fastrpc_buf *buf = NULL;
 
 	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 	if (!buf)
@@ -432,16 +518,23 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 }
 
 static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
-			     u64 size, struct fastrpc_buf **obuf)
+			     u64 size, u32 buf_type, struct fastrpc_buf **obuf)
 {
 	int ret;
 	struct fastrpc_buf *buf;
 
+	if (fastrpc_get_cached_buf(fl, size, buf_type, obuf))
+		return 0;
 	ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
-	if (ret)
-		return ret;
+	if (ret == -ENOMEM) {
+		fastrpc_cached_buf_list_free(fl);
+		ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
+		if (ret)
+			return ret;
+	}
 
 	buf = *obuf;
+	buf->type = buf_type;
 
 	if (fl->sctx && fl->sctx->sid)
 		buf->phys += ((u64)fl->sctx->sid << 32);
@@ -490,7 +583,7 @@ static void fastrpc_context_free(struct kref *ref)
 		fastrpc_map_put(ctx->maps[i]);
 
 	if (ctx->buf)
-		fastrpc_buf_free(ctx->buf);
+		fastrpc_buf_free(ctx->buf, true);
 
 	spin_lock_irqsave(&cctx->lock, flags);
 	idr_remove(&cctx->ctx_idr, ctx->ctxid >> 4);
@@ -674,7 +767,7 @@ static void fastrpc_release(struct dma_buf *dmabuf)
 {
 	struct fastrpc_buf *buffer = dmabuf->priv;
 
-	fastrpc_buf_free(buffer);
+	fastrpc_buf_free(buffer, false);
 }
 
 static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,
@@ -951,7 +1044,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 
 	ctx->msg_sz = pkt_size;
 
-	err = fastrpc_buf_alloc(ctx->fl, dev, pkt_size, &ctx->buf);
+	err = fastrpc_buf_alloc(ctx->fl, dev, pkt_size, METADATA_BUF, &ctx->buf);
 	if (err)
 		return err;
 
@@ -1334,7 +1427,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
 				fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);
 	}
 err_map:
-	fastrpc_buf_free(fl->cctx->remote_heap);
+	fastrpc_buf_free(fl->cctx->remote_heap, false);
 err_name:
 	kfree(name);
 err:
@@ -1403,7 +1496,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
 	memlen = ALIGN(max(INIT_FILELEN_MAX, (int)init.filelen * 4),
 		       1024 * 1024);
 	err = fastrpc_buf_alloc(fl, fl->sctx->dev, memlen,
-				&imem);
+				INITMEM_BUF, &imem);
 	if (err)
 		goto err_alloc;
 
@@ -1450,7 +1543,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
 
 err_invoke:
 	fl->init_mem = NULL;
-	fastrpc_buf_free(imem);
+	fastrpc_buf_free(imem, false);
 err_alloc:
 	fastrpc_map_put(map);
 err:
@@ -1521,7 +1614,7 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
 	spin_unlock_irqrestore(&cctx->lock, flags);
 
 	if (fl->init_mem)
-		fastrpc_buf_free(fl->init_mem);
+		fastrpc_buf_free(fl->init_mem, false);
 
 	list_for_each_entry_safe(ctx, n, &fl->pending, node) {
 		list_del(&ctx->node);
@@ -1533,9 +1626,10 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
 
 	list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
 		list_del(&buf->node);
-		fastrpc_buf_free(buf);
+		fastrpc_buf_free(buf, false);
 	}
 
+	fastrpc_cached_buf_list_free(fl);
 	fastrpc_session_free(cctx, fl->sctx);
 	fastrpc_channel_ctx_put(cctx);
 
@@ -1570,6 +1664,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
 	INIT_LIST_HEAD(&fl->maps);
 	INIT_LIST_HEAD(&fl->mmaps);
 	INIT_LIST_HEAD(&fl->user);
+	INIT_LIST_HEAD(&fl->cached_bufs);
 	fl->tgid = current->tgid;
 	fl->cctx = cctx;
 	fl->is_secure_dev = fdevice->secure;
@@ -1600,7 +1695,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
 	if (copy_from_user(&bp, argp, sizeof(bp)))
 		return -EFAULT;
 
-	err = fastrpc_buf_alloc(fl, fl->sctx->dev, bp.size, &buf);
+	err = fastrpc_buf_alloc(fl, fl->sctx->dev, bp.size, USER_BUF, &buf);
 	if (err)
 		return err;
 	exp_info.ops = &fastrpc_dma_buf_ops;
@@ -1610,7 +1705,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
 	buf->dmabuf = dma_buf_export(&exp_info);
 	if (IS_ERR(buf->dmabuf)) {
 		err = PTR_ERR(buf->dmabuf);
-		fastrpc_buf_free(buf);
+		fastrpc_buf_free(buf, false);
 		return err;
 	}
 
@@ -1805,7 +1900,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
 		spin_lock(&fl->lock);
 		list_del(&buf->node);
 		spin_unlock(&fl->lock);
-		fastrpc_buf_free(buf);
+		fastrpc_buf_free(buf, false);
 	} else {
 		dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr);
 	}
@@ -1866,7 +1961,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 		return -EINVAL;
 	}
 
-	err = fastrpc_buf_alloc(fl, fl->sctx->dev, req.size, &buf);
+	err = fastrpc_buf_alloc(fl, fl->sctx->dev, req.size, USER_BUF, &buf);
 	if (err) {
 		dev_err(dev, "failed to allocate buffer\n");
 		return err;
@@ -1935,7 +2030,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
 err_assign:
 	fastrpc_req_munmap_impl(fl, buf);
 err_invoke:
-	fastrpc_buf_free(buf);
+	fastrpc_buf_free(buf, false);
 
 	return err;
 }
@@ -2380,7 +2475,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
 		list_del(&buf->node);
 
 	if (cctx->remote_heap)
-		fastrpc_buf_free(cctx->remote_heap);
+		fastrpc_buf_free(cctx->remote_heap, false);
 
 	of_platform_depopulate(&rpdev->dev);
 
diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h
index f33d914..91c7c4f 100644
--- a/include/uapi/misc/fastrpc.h
+++ b/include/uapi/misc/fastrpc.h
@@ -64,6 +64,14 @@ enum fastrpc_proc_attr {
 	FASTRPC_MODE_PRIVILEGED		= (1 << 6),
 };
 
+ /* Types of fastrpc DMA bufs sent to DSP */
+ enum fastrpc_buf_type {
+	METADATA_BUF,
+	COPYDATA_BUF,
+	INITMEM_BUF,
+	USER_BUF,
+};
+
 /* Fastrpc attribute for memory protection of buffers */
 #define FASTRPC_ATTR_SECUREMAP	(1)
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/2] misc: fastrpc: Add persistent header buffer support
  2023-06-09 10:39 [PATCH v1 0/2] Add changes for cached buffer and persistent header buffers Ekansh Gupta
  2023-06-09 10:39 ` [PATCH v1 1/2] misc: fastrpc: Add cached buffer support Ekansh Gupta
@ 2023-06-09 10:39 ` Ekansh Gupta
  2023-06-09 18:13   ` kernel test robot
  1 sibling, 1 reply; 5+ messages in thread
From: Ekansh Gupta @ 2023-06-09 10:39 UTC (permalink / raw)
  To: srinivas.kandagatla, linux-arm-msm
  Cc: Ekansh Gupta, ekangupt, gregkh, linux-kernel, fastrpc.upstream,
	quic_anane

This change enables the usage of persistent header buffers which
are allocated during process initialization and is mapped to CDSP.
This mechanism helps in reducing the RPC overhead for remote calls.

For any user process remote RPC call to CDSP, it is tried to use
persistent header buffers. In case all persistent buffers are
already in use, there is a fallback to cached buffer usage and
allocation using DMA API.

Co-developed-by: Anandu Krishnan E <quic_anane@quicinc.com>
Signed-off-by: Anandu Krishnan E <quic_anane@quicinc.com>
Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
---
 drivers/misc/fastrpc.c | 215 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 173 insertions(+), 42 deletions(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index a961a66..0132b63 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -44,6 +44,8 @@
 /* Maximum buffers cached in cached buffer list */
 #define FASTRPC_MAX_CACHED_BUFS (32)
 #define FASTRPC_MAX_CACHE_BUF_SIZE (8*1024*1024)
+/* Max no. of persistent headers pre-allocated per user process */
+#define FASTRPC_MAX_PERSISTENT_HEADERS    (25)
 
 /* Add memory to static PD pool, protection thru XPU */
 #define ADSP_MMAP_HEAP_ADDR  4
@@ -54,7 +56,9 @@
 /* Add memory to userPD pool, for user heap */
 #define ADSP_MMAP_ADD_PAGES 0x1000
 /* Add memory to userPD pool, for LLC heap */
-#define ADSP_MMAP_ADD_PAGES_LLC 0x3000,
+#define ADSP_MMAP_ADD_PAGES_LLC 0x3000
+/* Map persistent header buffer on DSP */
+#define ADSP_MMAP_PERSIST_HDR  0x4000
 
 #define DSP_UNSUPPORTED_API (0x80000414)
 /* MAX NUMBER of DSP ATTRIBUTES SUPPORTED */
@@ -208,6 +212,7 @@ struct fastrpc_buf {
 	/* mmap support */
 	struct list_head node; /* list of user requested mmaps */
 	uintptr_t raddr;
+	bool in_use;
 };
 
 struct fastrpc_dma_buf_attachment {
@@ -303,11 +308,17 @@ struct fastrpc_user {
 	struct fastrpc_channel_ctx *cctx;
 	struct fastrpc_session_ctx *sctx;
 	struct fastrpc_buf *init_mem;
+	/* Pre-allocated header buffer */
+	struct fastrpc_buf *pers_hdr_buf;
+	/* Pre-allocated buffer divided into N chunks */
+	struct fastrpc_buf *hdr_bufs;
 
 	int tgid;
 	int pd;
 	/* total cached buffers */
 	u32 num_cached_buf;
+	/* total persistent headers */
+	u32 num_pers_hdrs;
 	bool is_secure_dev;
 	/* Lock for lists */
 	spinlock_t lock;
@@ -399,6 +410,37 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,
 	return ret;
 }
 
+static bool fastrpc_get_persistent_buf(struct fastrpc_user *fl,
+		size_t size, int buf_type, struct fastrpc_buf **obuf)
+{
+	u32 i = 0;
+	bool found = false;
+	struct fastrpc_buf *buf = NULL;
+
+	spin_lock(&fl->lock);
+	/*
+	 * Persistent header buffer can be used only if
+	 * metadata length is less than 1 page size.
+	 */
+	if (!fl->num_pers_hdrs || buf_type != METADATA_BUF || size > PAGE_SIZE) {
+		spin_unlock(&fl->lock);
+		return found;
+	}
+
+	for (i = 0; i < fl->num_pers_hdrs; i++) {
+		buf = &fl->hdr_bufs[i];
+		/* If buffer not in use, then assign it for requested alloc */
+		if (!buf->in_use) {
+			buf->in_use = true;
+			*obuf = buf;
+			found = true;
+			break;
+		}
+	}
+	spin_unlock(&fl->lock);
+	return found;
+}
+
 static void __fastrpc_buf_free(struct fastrpc_buf *buf)
 {
 	dma_free_coherent(buf->dev, buf->size, buf->virt,
@@ -430,6 +472,15 @@ static void fastrpc_cached_buf_list_add(struct fastrpc_buf *buf)
 
 static void fastrpc_buf_free(struct fastrpc_buf *buf, bool cache)
 {
+	struct fastrpc_user *fl = buf->fl;
+
+	if (buf->in_use) {
+		/* Don't free persistent header buf. Just mark as available */
+		spin_lock(&fl->lock);
+		buf->in_use = false;
+		spin_unlock(&fl->lock);
+		return;
+	}
 	if (cache)
 		fastrpc_cached_buf_list_add(buf);
 	else
@@ -523,6 +574,8 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 	int ret;
 	struct fastrpc_buf *buf;
 
+	if (fastrpc_get_persistent_buf(fl, size, buf_type, obuf))
+		return 0;
 	if (fastrpc_get_cached_buf(fl, size, buf_type, obuf))
 		return 0;
 	ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
@@ -1305,6 +1358,107 @@ static int fastrpc_internal_invoke(struct fastrpc_user *fl,  u32 kernel,
 	return err;
 }
 
+static int fastrpc_mem_map_to_dsp(struct fastrpc_user *fl, int fd, int offset,
+				u32 flags, u32 va, u64 phys,
+				size_t size, uintptr_t *raddr)
+{
+	struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } };
+	struct fastrpc_mem_map_req_msg req_msg = { 0 };
+	struct fastrpc_mmap_rsp_msg rsp_msg = { 0 };
+	struct fastrpc_phy_page pages = { 0 };
+	struct device *dev = fl->sctx->dev;
+	int err = 0;
+	u32 sc;
+
+	req_msg.pgid = fl->tgid;
+	req_msg.fd = fd;
+	req_msg.offset = offset;
+	req_msg.vaddrin = va;
+	req_msg.flags = flags;
+	req_msg.num = sizeof(pages);
+	req_msg.data_len = 0;
+
+	args[0].ptr = (u64) (uintptr_t) &req_msg;
+	args[0].length = sizeof(req_msg);
+
+	pages.addr = phys;
+	pages.size = size;
+
+	args[1].ptr = (u64) (uintptr_t) &pages;
+	args[1].length = sizeof(pages);
+
+	args[2].ptr = (u64) (uintptr_t) &pages;
+	args[2].length = 0;
+
+	args[3].ptr = (u64) (uintptr_t) &rsp_msg;
+	args[3].length = sizeof(rsp_msg);
+
+	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1);
+	err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]);
+	if (err) {
+		dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n",
+			fd, va, size);
+		return err;
+	}
+	*raddr = rsp_msg.vaddr;
+
+	return 0;
+}
+
+static int fastrpc_create_persistent_headers(struct fastrpc_user *fl)
+{
+	int err = 0;
+	int i = 0;
+	u64 virtb = 0;
+	struct device *dev = fl->sctx->dev;
+	struct fastrpc_buf *hdr_bufs, *buf, *pers_hdr_buf = NULL;
+	u32 num_pers_hdrs = 0;
+	size_t hdr_buf_alloc_len = 0;
+
+	/*
+	 * Pre-allocate memory for persistent header buffers based
+	 * on concurrency info passed by user. Upper limit enforced.
+	 */
+	num_pers_hdrs = FASTRPC_MAX_PERSISTENT_HEADERS;
+	hdr_buf_alloc_len = num_pers_hdrs * PAGE_SIZE;
+	err = fastrpc_buf_alloc(fl, dev, hdr_buf_alloc_len,
+			METADATA_BUF, &pers_hdr_buf);
+	if (err)
+		return err;
+
+	virtb = (u64) (uintptr_t)(pers_hdr_buf->virt);
+	err = fastrpc_mem_map_to_dsp(fl, -1, 0,
+				ADSP_MMAP_PERSIST_HDR, 0, (u64) (uintptr_t)(pers_hdr_buf->phys),
+				pers_hdr_buf->size, &pers_hdr_buf->raddr);
+	if (err)
+		goto err_dsp_map;
+
+	hdr_bufs = kcalloc(num_pers_hdrs, sizeof(struct fastrpc_buf),
+				GFP_KERNEL);
+	if (!hdr_bufs)
+		return -ENOMEM;
+
+	spin_lock(&fl->lock);
+	fl->pers_hdr_buf = pers_hdr_buf;
+	fl->num_pers_hdrs = num_pers_hdrs;
+	fl->hdr_bufs = hdr_bufs;
+	for (i = 0; i < num_pers_hdrs; i++) {
+		buf = &fl->hdr_bufs[i];
+		buf->fl = fl;
+		buf->virt = (void *)(virtb + (i * PAGE_SIZE));
+		buf->phys = pers_hdr_buf->phys + (i * PAGE_SIZE);
+		buf->size = PAGE_SIZE;
+		buf->type = pers_hdr_buf->type;
+		buf->in_use = false;
+	}
+	spin_unlock(&fl->lock);
+
+	return 0;
+err_dsp_map:
+	fastrpc_buf_free(pers_hdr_buf, 0);
+	return err;
+}
+
 static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_request)
 {
 	/* Check if the device node is non-secure and channel is secure*/
@@ -1537,6 +1691,12 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
 	if (err)
 		goto err_invoke;
 
+	if (fl->cctx->domain_id == CDSP_DOMAIN_ID) {
+		err = fastrpc_create_persistent_headers(fl);
+		if (err)
+			goto err_invoke;
+	}
+
 	kfree(args);
 
 	return 0;
@@ -1629,6 +1789,10 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
 		fastrpc_buf_free(buf, false);
 	}
 
+	if (fl->pers_hdr_buf)
+		fastrpc_buf_free(fl->pers_hdr_buf, false);
+	kfree(fl->hdr_bufs);
+
 	fastrpc_cached_buf_list_free(fl);
 	fastrpc_session_free(cctx, fl->sctx);
 	fastrpc_channel_ctx_put(cctx);
@@ -2089,16 +2253,11 @@ static int fastrpc_req_mem_unmap(struct fastrpc_user *fl, char __user *argp)
 
 static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
 {
-	struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } };
-	struct fastrpc_mem_map_req_msg req_msg = { 0 };
-	struct fastrpc_mmap_rsp_msg rsp_msg = { 0 };
 	struct fastrpc_mem_unmap req_unmap = { 0 };
-	struct fastrpc_phy_page pages = { 0 };
-	struct fastrpc_mem_map req;
+	struct fastrpc_mem_map req = {0};
 	struct device *dev = fl->sctx->dev;
 	struct fastrpc_map *map = NULL;
 	int err;
-	u32 sc;
 
 	if (copy_from_user(&req, argp, sizeof(req)))
 		return -EFAULT;
@@ -2110,57 +2269,29 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
 		return err;
 	}
 
-	req_msg.pgid = fl->tgid;
-	req_msg.fd = req.fd;
-	req_msg.offset = req.offset;
-	req_msg.vaddrin = req.vaddrin;
 	map->va = (void *) (uintptr_t) req.vaddrin;
-	req_msg.flags = req.flags;
-	req_msg.num = sizeof(pages);
-	req_msg.data_len = 0;
-
-	args[0].ptr = (u64) (uintptr_t) &req_msg;
-	args[0].length = sizeof(req_msg);
-
-	pages.addr = map->phys;
-	pages.size = map->size;
-
-	args[1].ptr = (u64) (uintptr_t) &pages;
-	args[1].length = sizeof(pages);
-
-	args[2].ptr = (u64) (uintptr_t) &pages;
-	args[2].length = 0;
-
-	args[3].ptr = (u64) (uintptr_t) &rsp_msg;
-	args[3].length = sizeof(rsp_msg);
-
-	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1);
-	err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]);
+	/* map to dsp, get virtual adrress for the user*/
+	err = fastrpc_mem_map_to_dsp(fl, map->fd, req.offset,
+					req.flags, req.vaddrin, map->phys,
+					map->size, (uintptr_t *)&req.vaddrout);
 	if (err) {
-		dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n",
-			req.fd, req.vaddrin, map->size);
+		dev_err(dev, "failed to map buffer on dsp, fd = %d\n", map->fd);
 		goto err_invoke;
 	}
 
 	/* update the buffer to be able to deallocate the memory on the DSP */
-	map->raddr = rsp_msg.vaddr;
-
-	/* let the client know the address to use */
-	req.vaddrout = rsp_msg.vaddr;
+	map->raddr = req.vaddrout;
 
 	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
 		/* unmap the memory and release the buffer */
-		req_unmap.vaddr = (uintptr_t) rsp_msg.vaddr;
+		req_unmap.vaddr = (uintptr_t)req.vaddrout;
 		req_unmap.length = map->size;
 		fastrpc_req_mem_unmap_impl(fl, &req_unmap);
 		return -EFAULT;
 	}
-
 	return 0;
-
 err_invoke:
 	fastrpc_map_put(map);
-
 	return err;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 2/2] misc: fastrpc: Add persistent header buffer support
  2023-06-09 10:39 ` [PATCH v1 2/2] misc: fastrpc: Add persistent header " Ekansh Gupta
@ 2023-06-09 18:13   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-06-09 18:13 UTC (permalink / raw)
  To: Ekansh Gupta, srinivas.kandagatla, linux-arm-msm
  Cc: llvm, oe-kbuild-all, Ekansh Gupta, ekangupt, gregkh, linux-kernel,
	fastrpc.upstream, quic_anane

Hi Ekansh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus linus/master v6.4-rc5 next-20230609]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ekansh-Gupta/misc-fastrpc-Add-cached-buffer-support/20230609-184517
base:   char-misc/char-misc-testing
patch link:    https://lore.kernel.org/r/1686307187-15199-3-git-send-email-quic_ekangupt%40quicinc.com
patch subject: [PATCH v1 2/2] misc: fastrpc: Add persistent header buffer support
config: arm64-randconfig-r024-20230608 (https://download.01.org/0day-ci/archive/20230610/202306100111.JeCyQ9wW-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        mkdir -p ~/bin
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        git remote add char-misc https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
        git fetch char-misc char-misc-testing
        git checkout char-misc/char-misc-testing
        b4 shazam https://lore.kernel.org/r/1686307187-15199-3-git-send-email-quic_ekangupt@quicinc.com
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/misc/

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306100111.JeCyQ9wW-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/misc/fastrpc.c:1400:8: warning: format specifies type 'unsigned long long' but the argument has type 'u32' (aka 'unsigned int') [-Wformat]
                           fd, va, size);
                               ^~
   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
           dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
                                                                  ~~~     ^~~~~~~~~~~
   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
                   _p_func(dev, fmt, ##__VA_ARGS__);                       \
                                ~~~    ^~~~~~~~~~~
>> drivers/misc/fastrpc.c:1400:12: warning: format specifies type 'long long' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
                           fd, va, size);
                                   ^~~~
   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
           dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
                                                                  ~~~     ^~~~~~~~~~~
   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
                   _p_func(dev, fmt, ##__VA_ARGS__);                       \
                                ~~~    ^~~~~~~~~~~
   2 warnings generated.


vim +1400 drivers/misc/fastrpc.c

  1360	
  1361	static int fastrpc_mem_map_to_dsp(struct fastrpc_user *fl, int fd, int offset,
  1362					u32 flags, u32 va, u64 phys,
  1363					size_t size, uintptr_t *raddr)
  1364	{
  1365		struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } };
  1366		struct fastrpc_mem_map_req_msg req_msg = { 0 };
  1367		struct fastrpc_mmap_rsp_msg rsp_msg = { 0 };
  1368		struct fastrpc_phy_page pages = { 0 };
  1369		struct device *dev = fl->sctx->dev;
  1370		int err = 0;
  1371		u32 sc;
  1372	
  1373		req_msg.pgid = fl->tgid;
  1374		req_msg.fd = fd;
  1375		req_msg.offset = offset;
  1376		req_msg.vaddrin = va;
  1377		req_msg.flags = flags;
  1378		req_msg.num = sizeof(pages);
  1379		req_msg.data_len = 0;
  1380	
  1381		args[0].ptr = (u64) (uintptr_t) &req_msg;
  1382		args[0].length = sizeof(req_msg);
  1383	
  1384		pages.addr = phys;
  1385		pages.size = size;
  1386	
  1387		args[1].ptr = (u64) (uintptr_t) &pages;
  1388		args[1].length = sizeof(pages);
  1389	
  1390		args[2].ptr = (u64) (uintptr_t) &pages;
  1391		args[2].length = 0;
  1392	
  1393		args[3].ptr = (u64) (uintptr_t) &rsp_msg;
  1394		args[3].length = sizeof(rsp_msg);
  1395	
  1396		sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1);
  1397		err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]);
  1398		if (err) {
  1399			dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n",
> 1400				fd, va, size);
  1401			return err;
  1402		}
  1403		*raddr = rsp_msg.vaddr;
  1404	
  1405		return 0;
  1406	}
  1407	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] misc: fastrpc: Add cached buffer support
  2023-06-09 10:39 ` [PATCH v1 1/2] misc: fastrpc: Add cached buffer support Ekansh Gupta
@ 2023-06-12 12:55   ` Srinivas Kandagatla
  0 siblings, 0 replies; 5+ messages in thread
From: Srinivas Kandagatla @ 2023-06-12 12:55 UTC (permalink / raw)
  To: Ekansh Gupta, linux-arm-msm
  Cc: ekangupt, gregkh, linux-kernel, fastrpc.upstream, quic_anane



On 09/06/2023 11:39, Ekansh Gupta wrote:
> FastRPC driver uses DMA API for region allocation for any buf_alloc
> request and the DMA region is unmap and freed once the usage is
> complete.
> 
> Cached buffer support enables caching of certain types of buffers
> instead of freeing which help in reducing the overhead of DMA API
> call for every buffer allocation request.

Can you quanitfy this argument with some measurments?

what kind of savings/overhead are we seeing with this patch vs without?

--srini
> 
> A list of cached buffer is maintained which will get reused when
> needed and this buffer list will get freed during device release.
> 
> Co-developed-by: Anandu Krishnan E <quic_anane@quicinc.com>
> Signed-off-by: Anandu Krishnan E <quic_anane@quicinc.com>
> Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com>
> ---
>   drivers/misc/fastrpc.c      | 133 +++++++++++++++++++++++++++++++++++++-------
>   include/uapi/misc/fastrpc.h |   8 +++
>   2 files changed, 122 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 30d4d04..a961a66 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -41,6 +41,10 @@
>   #define INIT_FILE_NAMELEN_MAX (128)
>   #define FASTRPC_DEVICE_NAME	"fastrpc"
>   
> +/* Maximum buffers cached in cached buffer list */
> +#define FASTRPC_MAX_CACHED_BUFS (32)
> +#define FASTRPC_MAX_CACHE_BUF_SIZE (8*1024*1024)
> +
>   /* Add memory to static PD pool, protection thru XPU */
>   #define ADSP_MMAP_HEAP_ADDR  4
>   /* MAP static DMA buffer on DSP User PD */
> @@ -195,6 +199,7 @@ struct fastrpc_buf {
>   	struct dma_buf *dmabuf;
>   	struct device *dev;
>   	void *virt;
> +	u32 type;
>   	u64 phys;
>   	u64 size;
>   	/* Lock for dma buf attachments */
> @@ -293,6 +298,7 @@ struct fastrpc_user {
>   	struct list_head maps;
>   	struct list_head pending;
>   	struct list_head mmaps;
> +	struct list_head cached_bufs;
>   
>   	struct fastrpc_channel_ctx *cctx;
>   	struct fastrpc_session_ctx *sctx;
> @@ -300,6 +306,8 @@ struct fastrpc_user {
>   
>   	int tgid;
>   	int pd;
> +	/* total cached buffers */
> +	u32 num_cached_buf;
>   	bool is_secure_dev;
>   	/* Lock for lists */
>   	spinlock_t lock;
> @@ -391,17 +399,95 @@ static int fastrpc_map_lookup(struct fastrpc_user *fl, int fd,
>   	return ret;
>   }
>   
> -static void fastrpc_buf_free(struct fastrpc_buf *buf)
> +static void __fastrpc_buf_free(struct fastrpc_buf *buf)
>   {
>   	dma_free_coherent(buf->dev, buf->size, buf->virt,
>   			  FASTRPC_PHYS(buf->phys));
>   	kfree(buf);
>   }
>   
> +static void fastrpc_cached_buf_list_add(struct fastrpc_buf *buf)
> +{
> +	struct fastrpc_user *fl = buf->fl;
> +
> +	if (buf->size < FASTRPC_MAX_CACHE_BUF_SIZE) {
> +		spin_lock(&fl->lock);
> +		if (fl->num_cached_buf > FASTRPC_MAX_CACHED_BUFS) {
> +			spin_unlock(&fl->lock);
> +			goto skip_buf_cache;
> +		}
> +
> +		list_add_tail(&buf->node, &fl->cached_bufs);
> +		fl->num_cached_buf++;
> +		buf->type = -1;
> +		spin_unlock(&fl->lock);
> +	}
> +	return;
> +
> +skip_buf_cache:
> +	__fastrpc_buf_free(buf);
> +}
> +
> +static void fastrpc_buf_free(struct fastrpc_buf *buf, bool cache)
> +{
> +	if (cache)
> +		fastrpc_cached_buf_list_add(buf);
> +	else
> +		__fastrpc_buf_free(buf);
> +}
> +
> +static inline bool fastrpc_get_cached_buf(struct fastrpc_user *fl,
> +		size_t size, int buf_type, struct fastrpc_buf **obuf)
> +{
> +	bool found = false;
> +	struct fastrpc_buf *buf, *n, *cbuf = NULL;
> +
> +	if (buf_type == USER_BUF)
> +		return found;
> +
> +	/* find the smallest buffer that fits in the cache */
> +	spin_lock(&fl->lock);
> +	list_for_each_entry_safe(buf, n, &fl->cached_bufs, node) {
> +		if (buf->size >= size && (!cbuf || cbuf->size > buf->size))
> +			cbuf = buf;
> +	}
> +	if (cbuf) {
> +		list_del_init(&cbuf->node);
> +		fl->num_cached_buf--;
> +	}
> +	spin_unlock(&fl->lock);
> +	if (cbuf) {
> +		cbuf->type = buf_type;
> +		*obuf = cbuf;
> +		found = true;
> +	}
> +
> +	return found;
> +}
> +
> +static void fastrpc_cached_buf_list_free(struct fastrpc_user *fl)
> +{
> +	struct fastrpc_buf *buf, *n, *free;
> +
> +	do {
> +		free = NULL;
> +		spin_lock(&fl->lock);
> +		list_for_each_entry_safe(buf, n, &fl->cached_bufs, node) {
> +			list_del(&buf->node);
> +			fl->num_cached_buf--;
> +			free = buf;
> +			break;
> +		}
> +		spin_unlock(&fl->lock);
> +		if (free)
> +			fastrpc_buf_free(free, false);
> +	} while (free);
> +}
> +
>   static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
>   			     u64 size, struct fastrpc_buf **obuf)
>   {
> -	struct fastrpc_buf *buf;
> +	struct fastrpc_buf *buf = NULL;
>   
>   	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
>   	if (!buf)
> @@ -432,16 +518,23 @@ static int __fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
>   }
>   
>   static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
> -			     u64 size, struct fastrpc_buf **obuf)
> +			     u64 size, u32 buf_type, struct fastrpc_buf **obuf)
>   {
>   	int ret;
>   	struct fastrpc_buf *buf;
>   
> +	if (fastrpc_get_cached_buf(fl, size, buf_type, obuf))
> +		return 0;
>   	ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
> -	if (ret)
> -		return ret;
> +	if (ret == -ENOMEM) {
> +		fastrpc_cached_buf_list_free(fl);
> +		ret = __fastrpc_buf_alloc(fl, dev, size, obuf);
> +		if (ret)
> +			return ret;
> +	}
>   
>   	buf = *obuf;
> +	buf->type = buf_type;
>   
>   	if (fl->sctx && fl->sctx->sid)
>   		buf->phys += ((u64)fl->sctx->sid << 32);
> @@ -490,7 +583,7 @@ static void fastrpc_context_free(struct kref *ref)
>   		fastrpc_map_put(ctx->maps[i]);
>   
>   	if (ctx->buf)
> -		fastrpc_buf_free(ctx->buf);
> +		fastrpc_buf_free(ctx->buf, true);
>   
>   	spin_lock_irqsave(&cctx->lock, flags);
>   	idr_remove(&cctx->ctx_idr, ctx->ctxid >> 4);
> @@ -674,7 +767,7 @@ static void fastrpc_release(struct dma_buf *dmabuf)
>   {
>   	struct fastrpc_buf *buffer = dmabuf->priv;
>   
> -	fastrpc_buf_free(buffer);
> +	fastrpc_buf_free(buffer, false);
>   }
>   
>   static int fastrpc_dma_buf_attach(struct dma_buf *dmabuf,
> @@ -951,7 +1044,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
>   
>   	ctx->msg_sz = pkt_size;
>   
> -	err = fastrpc_buf_alloc(ctx->fl, dev, pkt_size, &ctx->buf);
> +	err = fastrpc_buf_alloc(ctx->fl, dev, pkt_size, METADATA_BUF, &ctx->buf);
>   	if (err)
>   		return err;
>   
> @@ -1334,7 +1427,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
>   				fl->cctx->remote_heap->phys, fl->cctx->remote_heap->size, err);
>   	}
>   err_map:
> -	fastrpc_buf_free(fl->cctx->remote_heap);
> +	fastrpc_buf_free(fl->cctx->remote_heap, false);
>   err_name:
>   	kfree(name);
>   err:
> @@ -1403,7 +1496,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
>   	memlen = ALIGN(max(INIT_FILELEN_MAX, (int)init.filelen * 4),
>   		       1024 * 1024);
>   	err = fastrpc_buf_alloc(fl, fl->sctx->dev, memlen,
> -				&imem);
> +				INITMEM_BUF, &imem);
>   	if (err)
>   		goto err_alloc;
>   
> @@ -1450,7 +1543,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
>   
>   err_invoke:
>   	fl->init_mem = NULL;
> -	fastrpc_buf_free(imem);
> +	fastrpc_buf_free(imem, false);
>   err_alloc:
>   	fastrpc_map_put(map);
>   err:
> @@ -1521,7 +1614,7 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
>   	spin_unlock_irqrestore(&cctx->lock, flags);
>   
>   	if (fl->init_mem)
> -		fastrpc_buf_free(fl->init_mem);
> +		fastrpc_buf_free(fl->init_mem, false);
>   
>   	list_for_each_entry_safe(ctx, n, &fl->pending, node) {
>   		list_del(&ctx->node);
> @@ -1533,9 +1626,10 @@ static int fastrpc_device_release(struct inode *inode, struct file *file)
>   
>   	list_for_each_entry_safe(buf, b, &fl->mmaps, node) {
>   		list_del(&buf->node);
> -		fastrpc_buf_free(buf);
> +		fastrpc_buf_free(buf, false);
>   	}
>   
> +	fastrpc_cached_buf_list_free(fl);
>   	fastrpc_session_free(cctx, fl->sctx);
>   	fastrpc_channel_ctx_put(cctx);
>   
> @@ -1570,6 +1664,7 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
>   	INIT_LIST_HEAD(&fl->maps);
>   	INIT_LIST_HEAD(&fl->mmaps);
>   	INIT_LIST_HEAD(&fl->user);
> +	INIT_LIST_HEAD(&fl->cached_bufs);
>   	fl->tgid = current->tgid;
>   	fl->cctx = cctx;
>   	fl->is_secure_dev = fdevice->secure;
> @@ -1600,7 +1695,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
>   	if (copy_from_user(&bp, argp, sizeof(bp)))
>   		return -EFAULT;
>   
> -	err = fastrpc_buf_alloc(fl, fl->sctx->dev, bp.size, &buf);
> +	err = fastrpc_buf_alloc(fl, fl->sctx->dev, bp.size, USER_BUF, &buf);
>   	if (err)
>   		return err;
>   	exp_info.ops = &fastrpc_dma_buf_ops;
> @@ -1610,7 +1705,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
>   	buf->dmabuf = dma_buf_export(&exp_info);
>   	if (IS_ERR(buf->dmabuf)) {
>   		err = PTR_ERR(buf->dmabuf);
> -		fastrpc_buf_free(buf);
> +		fastrpc_buf_free(buf, false);
>   		return err;
>   	}
>   
> @@ -1805,7 +1900,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
>   		spin_lock(&fl->lock);
>   		list_del(&buf->node);
>   		spin_unlock(&fl->lock);
> -		fastrpc_buf_free(buf);
> +		fastrpc_buf_free(buf, false);
>   	} else {
>   		dev_err(dev, "unmmap\tpt 0x%09lx ERROR\n", buf->raddr);
>   	}
> @@ -1866,7 +1961,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>   		return -EINVAL;
>   	}
>   
> -	err = fastrpc_buf_alloc(fl, fl->sctx->dev, req.size, &buf);
> +	err = fastrpc_buf_alloc(fl, fl->sctx->dev, req.size, USER_BUF, &buf);
>   	if (err) {
>   		dev_err(dev, "failed to allocate buffer\n");
>   		return err;
> @@ -1935,7 +2030,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
>   err_assign:
>   	fastrpc_req_munmap_impl(fl, buf);
>   err_invoke:
> -	fastrpc_buf_free(buf);
> +	fastrpc_buf_free(buf, false);
>   
>   	return err;
>   }
> @@ -2380,7 +2475,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
>   		list_del(&buf->node);
>   
>   	if (cctx->remote_heap)
> -		fastrpc_buf_free(cctx->remote_heap);
> +		fastrpc_buf_free(cctx->remote_heap, false);
>   
>   	of_platform_depopulate(&rpdev->dev);
>   
> diff --git a/include/uapi/misc/fastrpc.h b/include/uapi/misc/fastrpc.h
> index f33d914..91c7c4f 100644
> --- a/include/uapi/misc/fastrpc.h
> +++ b/include/uapi/misc/fastrpc.h
> @@ -64,6 +64,14 @@ enum fastrpc_proc_attr {
>   	FASTRPC_MODE_PRIVILEGED		= (1 << 6),
>   };
>   
> + /* Types of fastrpc DMA bufs sent to DSP */
> + enum fastrpc_buf_type {
> +	METADATA_BUF,
> +	COPYDATA_BUF,
> +	INITMEM_BUF,
> +	USER_BUF,
> +};
> +
>   /* Fastrpc attribute for memory protection of buffers */
>   #define FASTRPC_ATTR_SECUREMAP	(1)
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-12 12:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 10:39 [PATCH v1 0/2] Add changes for cached buffer and persistent header buffers Ekansh Gupta
2023-06-09 10:39 ` [PATCH v1 1/2] misc: fastrpc: Add cached buffer support Ekansh Gupta
2023-06-12 12:55   ` Srinivas Kandagatla
2023-06-09 10:39 ` [PATCH v1 2/2] misc: fastrpc: Add persistent header " Ekansh Gupta
2023-06-09 18:13   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).