Skip to content

Commit 37d56e0

Browse files
Ekansh Guptagregkh
authored andcommitted
misc: fastrpc: Add support for multiple PD from one process
Memory intensive applications(which requires more tha 4GB) that wants to offload tasks to DSP might have to split the tasks to multiple user PD to make the resources available. For every call to DSP, fastrpc driver passes the process tgid which works as an identifier for the DSP to enqueue the tasks to specific PD. With current design, if any process opens device node more than once and makes PD init request, same tgid will be passed to DSP which will be considered a bad request and this will result in failure as the same identifier cannot be used for multiple DSP PD. Assign and pass a client ID to DSP which would be assigned during device open and will be dependent on the index of session allocated for the PD. This will allow the same process to open the device more than once and spawn multiple dynamic PD for ease of processing. Signed-off-by: Ekansh Gupta <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6847b00 commit 37d56e0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

drivers/misc/fastrpc.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ struct fastrpc_user {
299299
struct fastrpc_session_ctx *sctx;
300300
struct fastrpc_buf *init_mem;
301301

302-
int tgid;
302+
int client_id;
303303
int pd;
304304
bool is_secure_dev;
305305
/* Lock for lists */
@@ -614,7 +614,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc(
614614
ctx->sc = sc;
615615
ctx->retval = -1;
616616
ctx->pid = current->pid;
617-
ctx->tgid = user->tgid;
617+
ctx->tgid = user->client_id;
618618
ctx->cctx = cctx;
619619
init_completion(&ctx->work);
620620
INIT_WORK(&ctx->put_work, fastrpc_context_put_wq);
@@ -1115,7 +1115,7 @@ static int fastrpc_invoke_send(struct fastrpc_session_ctx *sctx,
11151115
int ret;
11161116

11171117
cctx = fl->cctx;
1118-
msg->pid = fl->tgid;
1118+
msg->pid = fl->client_id;
11191119
msg->tid = current->pid;
11201120

11211121
if (kernel)
@@ -1293,7 +1293,7 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,
12931293
}
12941294
}
12951295

1296-
inbuf.pgid = fl->tgid;
1296+
inbuf.pgid = fl->client_id;
12971297
inbuf.namelen = init.namelen;
12981298
inbuf.pageslen = 0;
12991299
fl->pd = USER_PD;
@@ -1395,7 +1395,7 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
13951395
goto err;
13961396
}
13971397

1398-
inbuf.pgid = fl->tgid;
1398+
inbuf.pgid = fl->client_id;
13991399
inbuf.namelen = strlen(current->comm) + 1;
14001400
inbuf.filelen = init.filelen;
14011401
inbuf.pageslen = 1;
@@ -1469,8 +1469,9 @@ static int fastrpc_init_create_process(struct fastrpc_user *fl,
14691469
}
14701470

14711471
static struct fastrpc_session_ctx *fastrpc_session_alloc(
1472-
struct fastrpc_channel_ctx *cctx)
1472+
struct fastrpc_user *fl)
14731473
{
1474+
struct fastrpc_channel_ctx *cctx = fl->cctx;
14741475
struct fastrpc_session_ctx *session = NULL;
14751476
unsigned long flags;
14761477
int i;
@@ -1480,6 +1481,8 @@ static struct fastrpc_session_ctx *fastrpc_session_alloc(
14801481
if (!cctx->session[i].used && cctx->session[i].valid) {
14811482
cctx->session[i].used = true;
14821483
session = &cctx->session[i];
1484+
/* any non-zero ID will work, session_idx + 1 is the simplest one */
1485+
fl->client_id = i + 1;
14831486
break;
14841487
}
14851488
}
@@ -1504,7 +1507,7 @@ static int fastrpc_release_current_dsp_process(struct fastrpc_user *fl)
15041507
int tgid = 0;
15051508
u32 sc;
15061509

1507-
tgid = fl->tgid;
1510+
tgid = fl->client_id;
15081511
args[0].ptr = (u64)(uintptr_t) &tgid;
15091512
args[0].length = sizeof(tgid);
15101513
args[0].fd = -1;
@@ -1579,11 +1582,10 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)
15791582
INIT_LIST_HEAD(&fl->maps);
15801583
INIT_LIST_HEAD(&fl->mmaps);
15811584
INIT_LIST_HEAD(&fl->user);
1582-
fl->tgid = current->tgid;
15831585
fl->cctx = cctx;
15841586
fl->is_secure_dev = fdevice->secure;
15851587

1586-
fl->sctx = fastrpc_session_alloc(cctx);
1588+
fl->sctx = fastrpc_session_alloc(fl);
15871589
if (!fl->sctx) {
15881590
dev_err(&cctx->rpdev->dev, "No session available\n");
15891591
mutex_destroy(&fl->mutex);
@@ -1647,7 +1649,7 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp)
16471649
static int fastrpc_init_attach(struct fastrpc_user *fl, int pd)
16481650
{
16491651
struct fastrpc_invoke_args args[1];
1650-
int tgid = fl->tgid;
1652+
int tgid = fl->client_id;
16511653
u32 sc;
16521654

16531655
args[0].ptr = (u64)(uintptr_t) &tgid;
@@ -1803,7 +1805,7 @@ static int fastrpc_req_munmap_impl(struct fastrpc_user *fl, struct fastrpc_buf *
18031805
int err;
18041806
u32 sc;
18051807

1806-
req_msg.pgid = fl->tgid;
1808+
req_msg.pgid = fl->client_id;
18071809
req_msg.size = buf->size;
18081810
req_msg.vaddr = buf->raddr;
18091811

@@ -1889,7 +1891,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)
18891891
return err;
18901892
}
18911893

1892-
req_msg.pgid = fl->tgid;
1894+
req_msg.pgid = fl->client_id;
18931895
req_msg.flags = req.flags;
18941896
req_msg.vaddr = req.vaddrin;
18951897
req_msg.num = sizeof(pages);
@@ -1978,7 +1980,7 @@ static int fastrpc_req_mem_unmap_impl(struct fastrpc_user *fl, struct fastrpc_me
19781980
return -EINVAL;
19791981
}
19801982

1981-
req_msg.pgid = fl->tgid;
1983+
req_msg.pgid = fl->client_id;
19821984
req_msg.len = map->len;
19831985
req_msg.vaddrin = map->raddr;
19841986
req_msg.fd = map->fd;
@@ -2031,7 +2033,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
20312033
return err;
20322034
}
20332035

2034-
req_msg.pgid = fl->tgid;
2036+
req_msg.pgid = fl->client_id;
20352037
req_msg.fd = req.fd;
20362038
req_msg.offset = req.offset;
20372039
req_msg.vaddrin = req.vaddrin;

0 commit comments

Comments
 (0)