@@ -237,7 +237,8 @@ struct fastrpc_invoke_ctx {
int client_id;
u32 sc;
u64 *fdlist;
- u32 *crc;
+ u32 *crclist;
+ void __user *crc;
u64 ctxid;
u64 msg_sz;
struct kref refcount;
@@ -617,6 +618,7 @@ static struct fastrpc_invoke_ctx *fastrpc_context_alloc(
/* Released in fastrpc_context_put() */
fastrpc_channel_ctx_get(cctx);
+ ctx->crc = cargs->crc;
ctx->sc = sc;
ctx->retval = -1;
ctx->pid = current->pid;
@@ -972,6 +974,7 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx)
list = fastrpc_invoke_buf_start(rpra, ctx->nscalars);
pages = fastrpc_phy_page_start(list, ctx->nscalars);
ctx->fdlist = (u64 *)(pages + ctx->nscalars);
+ ctx->crclist = (u32 *)(ctx->fdlist + FASTRPC_MAX_FDLIST);
args = (uintptr_t)ctx->buf->virt + metalen;
rlen = pkt_size - metalen;
ctx->rpra = rpra;
@@ -1101,6 +1104,12 @@ static int fastrpc_put_args(struct fastrpc_invoke_ctx *ctx,
fastrpc_map_put(mmap);
}
+ if (ctx->crc && ctx->crclist && rpra) {
+ if (copy_to_user(ctx->crc, ctx->crclist,
+ FASTRPC_MAX_CRCLIST * sizeof(u32)))
+ return -EFAULT;
+ }
+
return 0;
}
@@ -1703,39 +1712,75 @@ static int fastrpc_init_attach(struct fastrpc_user *fl, int pd)
return err;
}
-static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp)
+static int fastrpc_remote_invoke(struct fastrpc_user *fl, struct fastrpc_invoke *inv,
+ struct fastrpc_ctx_args *cargs)
{
- struct fastrpc_invoke_args *args = NULL;
- struct fastrpc_ctx_args *cargs;
- struct fastrpc_invoke inv;
+ struct fastrpc_invoke_args *args;
u32 nscalars;
int err;
- if (copy_from_user(&inv, argp, sizeof(inv)))
- return -EFAULT;
-
/* nscalars is truncated here to max supported value */
- nscalars = REMOTE_SCALARS_LENGTH(inv.sc);
+ nscalars = REMOTE_SCALARS_LENGTH(inv->sc);
if (nscalars) {
args = kcalloc(nscalars, sizeof(*args), GFP_KERNEL);
if (!args)
return -ENOMEM;
- if (copy_from_user(args, (void __user *)(uintptr_t)inv.args,
+ if (copy_from_user(args, (void __user *)(uintptr_t)inv->args,
nscalars * sizeof(*args))) {
kfree(args);
return -EFAULT;
}
}
+
+ cargs->args = args;
+ err = fastrpc_internal_invoke(fl, false, inv->handle, inv->sc, cargs);
+ kfree(args);
+
+ return err;
+}
+
+static int fastrpc_invoke(struct fastrpc_user *fl, char __user *argp)
+{
+ struct fastrpc_ctx_args *cargs;
+ struct fastrpc_invoke inv;
+ int err;
+
+ if (copy_from_user(&inv, argp, sizeof(inv)))
+ return -EFAULT;
+
cargs = kzalloc(sizeof(*cargs), GFP_KERNEL);
- if (!cargs) {
- kfree(args);
+ if (!cargs)
return -ENOMEM;
+
+ err = fastrpc_remote_invoke(fl, &inv, cargs);
+ kfree(cargs);
+
+ return err;
+}
+
+static int fastrpc_invokev2(struct fastrpc_user *fl, char __user *argp)
+{
+ struct fastrpc_ctx_args *cargs;
+ struct fastrpc_invoke_v2 inv2;
+ int i, err;
+
+ if (copy_from_user(&inv2, argp, sizeof(inv2)))
+ return -EFAULT;
+
+ /* Check if all reserved fields are zero */
+ for (i = 0; i < 16; i++) {
+ if (inv2.reserved[i] != 0)
+ return -EINVAL;
}
- cargs->args = args;
- err = fastrpc_internal_invoke(fl, false, inv.handle, inv.sc, cargs);
- kfree(args);
+ cargs = kzalloc(sizeof(*cargs), GFP_KERNEL);
+ if (!cargs)
+ return -ENOMEM;
+
+ cargs->crc = (void __user *)(uintptr_t)inv2.crc;
+
+ err = fastrpc_remote_invoke(fl, &inv2.inv, cargs);
kfree(cargs);
return err;
@@ -2188,6 +2233,9 @@ static long fastrpc_device_ioctl(struct file *file, unsigned int cmd,
case FASTRPC_IOCTL_INVOKE:
err = fastrpc_invoke(fl, argp);
break;
+ case FASTRPC_IOCTL_INVOKEV2:
+ err = fastrpc_invokev2(fl, argp);
+ break;
case FASTRPC_IOCTL_INIT_ATTACH:
err = fastrpc_init_attach(fl, ROOT_PD);
break;
@@ -17,6 +17,7 @@
#define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_mem_map)
#define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_mem_unmap)
#define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability)
+#define FASTRPC_IOCTL_INVOKEV2 _IOWR('R', 14, struct fastrpc_invoke_v2)
/**
* enum fastrpc_map_flags - control flags for mapping memory on DSP user process
@@ -80,6 +81,12 @@ struct fastrpc_invoke {
__u64 args;
};
+struct fastrpc_invoke_v2 {
+ struct fastrpc_invoke inv;
+ __u64 crc;
+ __u32 reserved[16];
+};
+
struct fastrpc_init_create {
__u32 filelen; /* elf file length */
__s32 filefd; /* fd for the file */
InvokeV2 request is intended to support multiple enhanced invoke requests like CRC check, performance counter enablement and polling mode for RPC invocations. CRC check is getting enabled as part of this patch. CRC check for input and output argument helps in ensuring data consistency over a remote call. If user intends to enable CRC check, first local user CRC is calculated at user end and a CRC buffer is passed to DSP to capture remote CRC values. DSP is expected to write to the remote CRC buffer which is then compared at user level with the local CRC values. Signed-off-by: Ekansh Gupta <quic_ekangupt@quicinc.com> --- drivers/misc/fastrpc.c | 78 ++++++++++++++++++++++++++++++------- include/uapi/misc/fastrpc.h | 7 ++++ 2 files changed, 70 insertions(+), 15 deletions(-)