summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc_mtharu <mtharu@codeaurora.org>2017-11-24 19:24:44 +0530
committerc_mtharu <mtharu@codeaurora.org>2017-11-28 13:13:17 +0530
commit595c2eab878bbf53a1047359d81ee3f8fc7fa4e0 (patch)
tree16ba05ed85a85ae4d22ad87eb90820cb0a74c173
parentfd7545d7d2f7a2aea18482537712f0aa46f99073 (diff)
msm: ADSPRPC: validate context pointer with magic number
Validate context pointer using magic number instead of searching through context list. It removes the usage of spin lock in interrupt handler for avoiding deadlock and reducing latency. Change-Id: I2492a7984a8d6545618a9cfb7a2d239d03ddd5a2 Signed-off-by: Tharun Kumar Merugu <mtharu@codeaurora.org>
-rw-r--r--drivers/char/adsprpc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/char/adsprpc.c b/drivers/char/adsprpc.c
index 77c8f279b4f5..61a878648c59 100644
--- a/drivers/char/adsprpc.c
+++ b/drivers/char/adsprpc.c
@@ -65,6 +65,7 @@
#define BALIGN 128
#define NUM_CHANNELS 4 /* adsp,sdsp,mdsp,cdsp */
#define NUM_SESSIONS 9 /*8 compute, 1 cpz*/
+#define FASTRPC_CTX_MAGIC (0xbeeddeed)
#define IS_CACHE_ALIGNED(x) (((x) & ((L1_CACHE_BYTES)-1)) == 0)
@@ -175,6 +176,7 @@ struct smq_invoke_ctx {
struct overlap *overs;
struct overlap **overps;
struct smq_msg msg;
+ unsigned int magic;
};
struct fastrpc_ctx_lst {
@@ -955,6 +957,7 @@ static int context_alloc(struct fastrpc_file *fl, uint32_t kernel,
ctx->pid = current->pid;
ctx->tgid = current->tgid;
init_completion(&ctx->work);
+ ctx->magic = FASTRPC_CTX_MAGIC;
spin_lock(&fl->hlock);
hlist_add_head(&ctx->hn, &clst->pending);
@@ -989,6 +992,7 @@ static void context_free(struct smq_invoke_ctx *ctx)
for (i = 0; i < nbufs; ++i)
fastrpc_mmap_free(ctx->maps[i]);
fastrpc_buf_free(ctx->buf, 1);
+ ctx->magic = 0;
kfree(ctx);
}
@@ -1459,16 +1463,23 @@ static void fastrpc_smd_read_handler(int cid)
{
struct fastrpc_apps *me = &gfa;
struct smq_invoke_rsp rsp = {0};
- int ret = 0;
+ struct smq_invoke_ctx *ctx;
+ int ret = 0, err = 0;
do {
ret = smd_read_from_cb(me->channel[cid].chan, &rsp,
sizeof(rsp));
if (ret != sizeof(rsp))
break;
- rsp.ctx = rsp.ctx & ~1;
+ ctx = (struct smq_invoke_ctx *)(uint64_to_ptr(rsp.ctx));
+ VERIFY(err, (ctx && ctx->magic == FASTRPC_CTX_MAGIC));
+ if (err)
+ goto bail;
context_notify_user(uint64_to_ptr(rsp.ctx), rsp.retval);
} while (ret == sizeof(rsp));
+bail:
+ if (err)
+ pr_err("adsprpc: invalid response or context\n");
}
static void smd_event_handler(void *priv, unsigned event)