fastrpc.c (3abe3ab3cdab71b2073ba6331edc0b2994643133) fastrpc.c (7f1f481263c3ce5387d4fd5ad63ddaa8a295aab2)
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
3// Copyright (c) 2018, Linaro Limited
4
5#include <linux/completion.h>
6#include <linux/device.h>
7#include <linux/dma-buf.h>
8#include <linux/dma-mapping.h>

--- 230 unchanged lines hidden (view full) ---

239 struct list_head users;
240 struct kref refcount;
241 /* Flag if dsp attributes are cached */
242 bool valid_attributes;
243 u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
244 struct fastrpc_device *secure_fdevice;
245 struct fastrpc_device *fdevice;
246 bool secure;
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
3// Copyright (c) 2018, Linaro Limited
4
5#include <linux/completion.h>
6#include <linux/device.h>
7#include <linux/dma-buf.h>
8#include <linux/dma-mapping.h>

--- 230 unchanged lines hidden (view full) ---

239 struct list_head users;
240 struct kref refcount;
241 /* Flag if dsp attributes are cached */
242 bool valid_attributes;
243 u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
244 struct fastrpc_device *secure_fdevice;
245 struct fastrpc_device *fdevice;
246 bool secure;
247 bool unsigned_support;
247};
248
249struct fastrpc_device {
250 struct fastrpc_channel_ctx *cctx;
251 struct miscdevice miscdev;
252 bool secure;
253};
254

--- 4 unchanged lines hidden (view full) ---

259 struct list_head mmaps;
260
261 struct fastrpc_channel_ctx *cctx;
262 struct fastrpc_session_ctx *sctx;
263 struct fastrpc_buf *init_mem;
264
265 int tgid;
266 int pd;
248};
249
250struct fastrpc_device {
251 struct fastrpc_channel_ctx *cctx;
252 struct miscdevice miscdev;
253 bool secure;
254};
255

--- 4 unchanged lines hidden (view full) ---

260 struct list_head mmaps;
261
262 struct fastrpc_channel_ctx *cctx;
263 struct fastrpc_session_ctx *sctx;
264 struct fastrpc_buf *init_mem;
265
266 int tgid;
267 int pd;
268 bool is_secure_dev;
267 /* Lock for lists */
268 spinlock_t lock;
269 /* lock for allocations */
270 struct mutex mutex;
271};
272
273static void fastrpc_free_map(struct kref *ref)
274{

--- 772 unchanged lines hidden (view full) ---

1047 fastrpc_context_put(ctx);
1048 }
1049 if (err)
1050 dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
1051
1052 return err;
1053}
1054
269 /* Lock for lists */
270 spinlock_t lock;
271 /* lock for allocations */
272 struct mutex mutex;
273};
274
275static void fastrpc_free_map(struct kref *ref)
276{

--- 772 unchanged lines hidden (view full) ---

1049 fastrpc_context_put(ctx);
1050 }
1051 if (err)
1052 dev_dbg(fl->sctx->dev, "Error: Invoke Failed %d\n", err);
1053
1054 return err;
1055}
1056
1057static bool is_session_rejected(struct fastrpc_user *fl, bool unsigned_pd_request)
1058{
1059 /* Check if the device node is non-secure and channel is secure*/
1060 if (!fl->is_secure_dev && fl->cctx->secure) {
1061 /*
1062 * Allow untrusted applications to offload only to Unsigned PD when
1063 * channel is configured as secure and block untrusted apps on channel
1064 * that does not support unsigned PD offload
1065 */
1066 if (!fl->cctx->unsigned_support || !unsigned_pd_request) {
1067 dev_err(&fl->cctx->rpdev->dev, "Error: Untrusted application trying to offload to signed PD");
1068 return true;
1069 }
1070 }
1071
1072 return false;
1073}
1074
1055static int fastrpc_init_create_process(struct fastrpc_user *fl,
1056 char __user *argp)
1057{
1058 struct fastrpc_init_create init;
1059 struct fastrpc_invoke_args *args;
1060 struct fastrpc_phy_page pages[1];
1061 struct fastrpc_map *map = NULL;
1062 struct fastrpc_buf *imem = NULL;
1063 int memlen;
1064 int err;
1065 struct {
1066 int pgid;
1067 u32 namelen;
1068 u32 filelen;
1069 u32 pageslen;
1070 u32 attrs;
1071 u32 siglen;
1072 } inbuf;
1073 u32 sc;
1075static int fastrpc_init_create_process(struct fastrpc_user *fl,
1076 char __user *argp)
1077{
1078 struct fastrpc_init_create init;
1079 struct fastrpc_invoke_args *args;
1080 struct fastrpc_phy_page pages[1];
1081 struct fastrpc_map *map = NULL;
1082 struct fastrpc_buf *imem = NULL;
1083 int memlen;
1084 int err;
1085 struct {
1086 int pgid;
1087 u32 namelen;
1088 u32 filelen;
1089 u32 pageslen;
1090 u32 attrs;
1091 u32 siglen;
1092 } inbuf;
1093 u32 sc;
1094 bool unsigned_module = false;
1074
1075 args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL);
1076 if (!args)
1077 return -ENOMEM;
1078
1079 if (copy_from_user(&init, argp, sizeof(init))) {
1080 err = -EFAULT;
1081 goto err;
1082 }
1083
1095
1096 args = kcalloc(FASTRPC_CREATE_PROCESS_NARGS, sizeof(*args), GFP_KERNEL);
1097 if (!args)
1098 return -ENOMEM;
1099
1100 if (copy_from_user(&init, argp, sizeof(init))) {
1101 err = -EFAULT;
1102 goto err;
1103 }
1104
1105 if (init.attrs & FASTRPC_MODE_UNSIGNED_MODULE)
1106 unsigned_module = true;
1107
1108 if (is_session_rejected(fl, unsigned_module)) {
1109 err = -ECONNREFUSED;
1110 goto err;
1111 }
1112
1084 if (init.filelen > INIT_FILELEN_MAX) {
1085 err = -EINVAL;
1086 goto err;
1087 }
1088
1089 inbuf.pgid = fl->tgid;
1090 inbuf.namelen = strlen(current->comm) + 1;
1091 inbuf.filelen = init.filelen;

--- 183 unchanged lines hidden (view full) ---

1275 spin_lock_init(&fl->lock);
1276 mutex_init(&fl->mutex);
1277 INIT_LIST_HEAD(&fl->pending);
1278 INIT_LIST_HEAD(&fl->maps);
1279 INIT_LIST_HEAD(&fl->mmaps);
1280 INIT_LIST_HEAD(&fl->user);
1281 fl->tgid = current->tgid;
1282 fl->cctx = cctx;
1113 if (init.filelen > INIT_FILELEN_MAX) {
1114 err = -EINVAL;
1115 goto err;
1116 }
1117
1118 inbuf.pgid = fl->tgid;
1119 inbuf.namelen = strlen(current->comm) + 1;
1120 inbuf.filelen = init.filelen;

--- 183 unchanged lines hidden (view full) ---

1304 spin_lock_init(&fl->lock);
1305 mutex_init(&fl->mutex);
1306 INIT_LIST_HEAD(&fl->pending);
1307 INIT_LIST_HEAD(&fl->maps);
1308 INIT_LIST_HEAD(&fl->mmaps);
1309 INIT_LIST_HEAD(&fl->user);
1310 fl->tgid = current->tgid;
1311 fl->cctx = cctx;
1312 fl->is_secure_dev = fdevice->secure;
1283
1284 fl->sctx = fastrpc_session_alloc(cctx);
1285 if (!fl->sctx) {
1286 dev_err(&cctx->rpdev->dev, "No session available\n");
1287 mutex_destroy(&fl->mutex);
1288 kfree(fl);
1289
1290 return -EBUSY;

--- 662 unchanged lines hidden (view full) ---

1953
1954 secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain"));
1955 data->secure = secure_dsp;
1956
1957 switch (domain_id) {
1958 case ADSP_DOMAIN_ID:
1959 case MDSP_DOMAIN_ID:
1960 case SDSP_DOMAIN_ID:
1313
1314 fl->sctx = fastrpc_session_alloc(cctx);
1315 if (!fl->sctx) {
1316 dev_err(&cctx->rpdev->dev, "No session available\n");
1317 mutex_destroy(&fl->mutex);
1318 kfree(fl);
1319
1320 return -EBUSY;

--- 662 unchanged lines hidden (view full) ---

1983
1984 secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain"));
1985 data->secure = secure_dsp;
1986
1987 switch (domain_id) {
1988 case ADSP_DOMAIN_ID:
1989 case MDSP_DOMAIN_ID:
1990 case SDSP_DOMAIN_ID:
1991 /* Unsigned PD offloading is only supported on CDSP*/
1992 data->unsigned_support = false;
1961 err = fastrpc_device_register(rdev, data, secure_dsp, domains[domain_id]);
1962 if (err)
1963 goto fdev_error;
1964 break;
1965 case CDSP_DOMAIN_ID:
1993 err = fastrpc_device_register(rdev, data, secure_dsp, domains[domain_id]);
1994 if (err)
1995 goto fdev_error;
1996 break;
1997 case CDSP_DOMAIN_ID:
1998 data->unsigned_support = true;
1966 /* Create both device nodes so that we can allow both Signed and Unsigned PD */
1967 err = fastrpc_device_register(rdev, data, true, domains[domain_id]);
1968 if (err)
1969 goto fdev_error;
1970
1971 err = fastrpc_device_register(rdev, data, false, domains[domain_id]);
1972 if (err)
1973 goto fdev_error;

--- 137 unchanged lines hidden ---
1999 /* Create both device nodes so that we can allow both Signed and Unsigned PD */
2000 err = fastrpc_device_register(rdev, data, true, domains[domain_id]);
2001 if (err)
2002 goto fdev_error;
2003
2004 err = fastrpc_device_register(rdev, data, false, domains[domain_id]);
2005 if (err)
2006 goto fdev_error;

--- 137 unchanged lines hidden ---