diff mbox series

[v3,11/12] misc: fastrpc: Add dma handle implementation

Message ID 20220126135304.16340-12-srinivas.kandagatla@linaro.org
State New
Headers show
Series misc: fastrpc: Add missing DSP FastRPC features | expand

Commit Message

Srinivas Kandagatla Jan. 26, 2022, 1:53 p.m. UTC
From: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>

The remote arguments carry both remote buffers and dma handles. Add proper
dma handle instructions to make it compatible with DSP implementation.

Signed-off-by: Vamsi Krishna Gattupalli <quic_vgattupa@quicinc.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 52 +++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 19 deletions(-)

Comments

Dan Carpenter Jan. 28, 2022, 7:09 a.m. UTC | #1
Hi Srinivas,

url:    https://github.com/0day-ci/linux/commits/Srinivas-Kandagatla/misc-fastrpc-Add-missing-DSP-FastRPC-features/20220126-215705
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 515a2f507491e7c3818e74ef4f4e088c1fecb190
config: openrisc-randconfig-m031-20220124 (https://download.01.org/0day-ci/archive/20220127/202201272146.Ci8W6Th6-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/misc/fastrpc.c:1856 fastrpc_req_mem_map() warn: variable dereferenced before check 'map' (see line 1834)

vim +/map +1856 drivers/misc/fastrpc.c

b1c0b7969aa491 Jeya R              2022-01-26  1784  static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
b1c0b7969aa491 Jeya R              2022-01-26  1785  {
b1c0b7969aa491 Jeya R              2022-01-26  1786  	struct fastrpc_invoke_args args[4] = { [0 ... 3] = { 0 } };
b1c0b7969aa491 Jeya R              2022-01-26  1787  	struct fastrpc_mem_map_req_msg req_msg = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1788  	struct fastrpc_mmap_rsp_msg rsp_msg = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1789  	struct fastrpc_mem_unmap req_unmap = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1790  	struct fastrpc_phy_page pages = { 0 };
b1c0b7969aa491 Jeya R              2022-01-26  1791  	struct fastrpc_mem_map req;
b1c0b7969aa491 Jeya R              2022-01-26  1792  	struct device *dev = fl->sctx->dev;
b1c0b7969aa491 Jeya R              2022-01-26  1793  	struct fastrpc_map *map = NULL;
b1c0b7969aa491 Jeya R              2022-01-26  1794  	int err;
b1c0b7969aa491 Jeya R              2022-01-26  1795  	u32 sc;
b1c0b7969aa491 Jeya R              2022-01-26  1796  
b1c0b7969aa491 Jeya R              2022-01-26  1797  	if (copy_from_user(&req, argp, sizeof(req)))
b1c0b7969aa491 Jeya R              2022-01-26  1798  		return -EFAULT;
b1c0b7969aa491 Jeya R              2022-01-26  1799  
b1c0b7969aa491 Jeya R              2022-01-26  1800  	/* create SMMU mapping */
e52e7cb4a5a6f3 Srinivas Kandagatla 2022-01-26  1801  	err = fastrpc_map_create(fl, req.fd, req.length, 0, &map);
b1c0b7969aa491 Jeya R              2022-01-26  1802  	if (err) {
b1c0b7969aa491 Jeya R              2022-01-26  1803  		dev_err(dev, "failed to map buffer, fd = %d\n", req.fd);
b1c0b7969aa491 Jeya R              2022-01-26  1804  		return err;
b1c0b7969aa491 Jeya R              2022-01-26  1805  	}
b1c0b7969aa491 Jeya R              2022-01-26  1806  
b1c0b7969aa491 Jeya R              2022-01-26  1807  	req_msg.pgid = fl->tgid;
b1c0b7969aa491 Jeya R              2022-01-26  1808  	req_msg.fd = req.fd;
b1c0b7969aa491 Jeya R              2022-01-26  1809  	req_msg.offset = req.offset;
b1c0b7969aa491 Jeya R              2022-01-26  1810  	req_msg.vaddrin = req.vaddrin;
b1c0b7969aa491 Jeya R              2022-01-26  1811  	map->va = (void *) req.vaddrin;
b1c0b7969aa491 Jeya R              2022-01-26  1812  	req_msg.flags = req.flags;
b1c0b7969aa491 Jeya R              2022-01-26  1813  	req_msg.num = sizeof(pages);
b1c0b7969aa491 Jeya R              2022-01-26  1814  	req_msg.data_len = 0;
b1c0b7969aa491 Jeya R              2022-01-26  1815  
b1c0b7969aa491 Jeya R              2022-01-26  1816  	args[0].ptr = (u64) &req_msg;
b1c0b7969aa491 Jeya R              2022-01-26  1817  	args[0].length = sizeof(req_msg);
b1c0b7969aa491 Jeya R              2022-01-26  1818  
b1c0b7969aa491 Jeya R              2022-01-26  1819  	pages.addr = map->phys;
b1c0b7969aa491 Jeya R              2022-01-26  1820  	pages.size = map->size;
b1c0b7969aa491 Jeya R              2022-01-26  1821  
b1c0b7969aa491 Jeya R              2022-01-26  1822  	args[1].ptr = (u64) &pages;
b1c0b7969aa491 Jeya R              2022-01-26  1823  	args[1].length = sizeof(pages);
b1c0b7969aa491 Jeya R              2022-01-26  1824  
b1c0b7969aa491 Jeya R              2022-01-26  1825  	args[2].ptr = (u64) &pages;
b1c0b7969aa491 Jeya R              2022-01-26  1826  	args[2].length = 0;
b1c0b7969aa491 Jeya R              2022-01-26  1827  
b1c0b7969aa491 Jeya R              2022-01-26  1828  	args[3].ptr = (u64) &rsp_msg;
b1c0b7969aa491 Jeya R              2022-01-26  1829  	args[3].length = sizeof(rsp_msg);
b1c0b7969aa491 Jeya R              2022-01-26  1830  
b1c0b7969aa491 Jeya R              2022-01-26  1831  	sc = FASTRPC_SCALARS(FASTRPC_RMID_INIT_MEM_MAP, 3, 1);
b1c0b7969aa491 Jeya R              2022-01-26  1832  	err = fastrpc_internal_invoke(fl, true, FASTRPC_INIT_HANDLE, sc, &args[0]);
b1c0b7969aa491 Jeya R              2022-01-26  1833  	if (err) {
b1c0b7969aa491 Jeya R              2022-01-26 @1834  		dev_err(dev, "mem mmap error, fd %d, vaddr %llx, size %lld\n",
b1c0b7969aa491 Jeya R              2022-01-26  1835  			req.fd, req.vaddrin, map->size);
b1c0b7969aa491 Jeya R              2022-01-26  1836  		goto err_invoke;
b1c0b7969aa491 Jeya R              2022-01-26  1837  	}
b1c0b7969aa491 Jeya R              2022-01-26  1838  
b1c0b7969aa491 Jeya R              2022-01-26  1839  	/* update the buffer to be able to deallocate the memory on the DSP */
b1c0b7969aa491 Jeya R              2022-01-26  1840  	map->raddr = rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1841  
b1c0b7969aa491 Jeya R              2022-01-26  1842  	/* let the client know the address to use */
b1c0b7969aa491 Jeya R              2022-01-26  1843  	req.vaddrout = rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1844  
b1c0b7969aa491 Jeya R              2022-01-26  1845  	if (copy_to_user((void __user *)argp, &req, sizeof(req))) {
b1c0b7969aa491 Jeya R              2022-01-26  1846  		/* unmap the memory and release the buffer */
b1c0b7969aa491 Jeya R              2022-01-26  1847  		req_unmap.vaddr = (uintptr_t) rsp_msg.vaddr;
b1c0b7969aa491 Jeya R              2022-01-26  1848  		req_unmap.length = map->size;
b1c0b7969aa491 Jeya R              2022-01-26  1849  		fastrpc_req_mem_unmap_impl(fl, &req_unmap);
b1c0b7969aa491 Jeya R              2022-01-26  1850  		return -EFAULT;
b1c0b7969aa491 Jeya R              2022-01-26  1851  	}
b1c0b7969aa491 Jeya R              2022-01-26  1852  
b1c0b7969aa491 Jeya R              2022-01-26  1853  	return 0;
b1c0b7969aa491 Jeya R              2022-01-26  1854  
b1c0b7969aa491 Jeya R              2022-01-26  1855  err_invoke:
b1c0b7969aa491 Jeya R              2022-01-26 @1856  	if (map)
b1c0b7969aa491 Jeya R              2022-01-26  1857  		fastrpc_map_put(map);

"map" can't be NULL.

b1c0b7969aa491 Jeya R              2022-01-26  1858  
b1c0b7969aa491 Jeya R              2022-01-26  1859  	return err;
b1c0b7969aa491 Jeya R              2022-01-26  1860  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 6052a9cb9e2c..56ec7170b698 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -100,9 +100,20 @@  struct fastrpc_invoke_buf {
 	u32 pgidx;		/* index to start of contiguous region */
 };
 
-struct fastrpc_remote_arg {
-	u64 pv;
-	u64 len;
+struct fastrpc_remote_dmahandle {
+	s32 fd;		/* dma handle fd */
+	u32 offset;	/* dma handle offset */
+	u32 len;	/* dma handle length */
+};
+
+struct fastrpc_remote_buf {
+	u64 pv;		/* buffer pointer */
+	u64 len;	/* length of buffer */
+};
+
+union fastrpc_remote_arg {
+	struct fastrpc_remote_buf buf;
+	struct fastrpc_remote_dmahandle dma;
 };
 
 struct fastrpc_mmap_rsp_msg {
@@ -216,7 +227,7 @@  struct fastrpc_invoke_ctx {
 	struct work_struct put_work;
 	struct fastrpc_msg msg;
 	struct fastrpc_user *fl;
-	struct fastrpc_remote_arg *rpra;
+	union fastrpc_remote_arg *rpra;
 	struct fastrpc_map **maps;
 	struct fastrpc_buf *buf;
 	struct fastrpc_invoke_args *args;
@@ -766,7 +777,7 @@  static int fastrpc_map_create(struct fastrpc_user *fl, int fd,
  * >>>>>>  START of METADATA <<<<<<<<<
  * +---------------------------------+
  * |           Arguments             |
- * | type:(struct fastrpc_remote_arg)|
+ * | type:(union fastrpc_remote_arg)|
  * |             (0 - N)             |
  * +---------------------------------+
  * |         Invoke Buffer list      |
@@ -791,7 +802,7 @@  static int fastrpc_get_meta_size(struct fastrpc_invoke_ctx *ctx)
 {
 	int size = 0;
 
-	size = (sizeof(struct fastrpc_remote_arg) +
+	size = (sizeof(struct fastrpc_remote_buf) +
 		sizeof(struct fastrpc_invoke_buf) +
 		sizeof(struct fastrpc_phy_page)) * ctx->nscalars +
 		sizeof(u64) * FASTRPC_MAX_FDLIST +
@@ -856,7 +867,7 @@  static struct fastrpc_phy_page *fastrpc_phy_page_start(struct fastrpc_invoke_buf
 static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 {
 	struct device *dev = ctx->fl->sctx->dev;
-	struct fastrpc_remote_arg *rpra;
+	union fastrpc_remote_arg *rpra;
 	struct fastrpc_invoke_buf *list;
 	struct fastrpc_phy_page *pages;
 	int inbufs, i, oix, err = 0;
@@ -892,8 +903,8 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		i = ctx->olaps[oix].raix;
 		len = ctx->args[i].length;
 
-		rpra[i].pv = 0;
-		rpra[i].len = len;
+		rpra[i].buf.pv = 0;
+		rpra[i].buf.len = len;
 		list[i].num = len ? 1 : 0;
 		list[i].pgidx = i;
 
@@ -903,7 +914,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		if (ctx->maps[i]) {
 			struct vm_area_struct *vma = NULL;
 
-			rpra[i].pv = (u64) ctx->args[i].ptr;
+			rpra[i].buf.pv = (u64) ctx->args[i].ptr;
 			pages[i].addr = ctx->maps[i]->phys;
 
 			mmap_read_lock(current->mm);
@@ -930,7 +941,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 			if (rlen < mlen)
 				goto bail;
 
-			rpra[i].pv = args - ctx->olaps[oix].offset;
+			rpra[i].buf.pv = args - ctx->olaps[oix].offset;
 			pages[i].addr = ctx->buf->phys -
 					ctx->olaps[oix].offset +
 					(pkt_size - rlen);
@@ -944,7 +955,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 		}
 
 		if (i < inbufs && !ctx->maps[i]) {
-			void *dst = (void *)(uintptr_t)rpra[i].pv;
+			void *dst = (void *)(uintptr_t)rpra[i].buf.pv;
 			void *src = (void *)(uintptr_t)ctx->args[i].ptr;
 
 			if (!kernel) {
@@ -960,12 +971,15 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 	}
 
 	for (i = ctx->nbufs; i < ctx->nscalars; ++i) {
-		rpra[i].pv = (u64) ctx->args[i].ptr;
-		rpra[i].len = ctx->args[i].length;
 		list[i].num = ctx->args[i].length ? 1 : 0;
 		list[i].pgidx = i;
-		pages[i].addr = ctx->maps[i]->phys;
-		pages[i].size = ctx->maps[i]->size;
+		if (ctx->maps[i]) {
+			pages[i].addr = ctx->maps[i]->phys;
+			pages[i].size = ctx->maps[i]->size;
+		}
+		rpra[i].dma.fd = ctx->args[i].fd;
+		rpra[i].dma.len = ctx->args[i].length;
+		rpra[i].dma.offset = (u64) ctx->args[i].ptr;
 	}
 
 bail:
@@ -978,7 +992,7 @@  static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
 static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 			    u32 kernel)
 {
-	struct fastrpc_remote_arg *rpra = ctx->rpra;
+	union fastrpc_remote_arg *rpra = ctx->rpra;
 	struct fastrpc_user *fl = ctx->fl;
 	struct fastrpc_map *mmap = NULL;
 	struct fastrpc_invoke_buf *list;
@@ -995,9 +1009,9 @@  static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
 
 	for (i = inbufs; i < ctx->nbufs; ++i) {
 		if (!ctx->maps[i]) {
-			void *src = (void *)(uintptr_t)rpra[i].pv;
+			void *src = (void *)(uintptr_t)rpra[i].buf.pv;
 			void *dst = (void *)(uintptr_t)ctx->args[i].ptr;
-			u64 len = rpra[i].len;
+			u64 len = rpra[i].buf.len;
 
 			if (!kernel) {
 				if (copy_to_user((void __user *)dst, src, len))