Skip to content

Commit 3abe3ab

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
misc: fastrpc: add secure domain support
ADSP/MDSP/SDSP are by default secured, which means it can only be loaded with a Signed process. Where as CDSP can be either be secured/unsecured. non-secured Compute DSP would allow users to load unsigned process and run hexagon instructions, but blocking access to secured hardware within the DSP. Where as signed process with secure CDSP would be allowed to access all the dsp resources. This patch adds basic code to create device nodes as per device tree property. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20220214161002.6831-6-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fb42387 commit 3abe3ab

1 file changed

Lines changed: 46 additions & 9 deletions

File tree

drivers/misc/fastrpc.c

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,15 @@ struct fastrpc_channel_ctx {
241241
/* Flag if dsp attributes are cached */
242242
bool valid_attributes;
243243
u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
244+
struct fastrpc_device *secure_fdevice;
244245
struct fastrpc_device *fdevice;
246+
bool secure;
245247
};
246248

247249
struct fastrpc_device {
248250
struct fastrpc_channel_ctx *cctx;
249251
struct miscdevice miscdev;
252+
bool secure;
250253
};
251254

252255
struct fastrpc_user {
@@ -1697,7 +1700,7 @@ static int fastrpc_req_mem_map(struct fastrpc_user *fl, char __user *argp)
16971700
return -EFAULT;
16981701

16991702
/* create SMMU mapping */
1700-
err = fastrpc_map_create(fl, req.fd, req.length, &map);
1703+
err = fastrpc_map_create(fl, req.fd, req.length, 0, &map);
17011704
if (err) {
17021705
dev_err(dev, "failed to map buffer, fd = %d\n", req.fd);
17031706
return err;
@@ -1891,7 +1894,7 @@ static struct platform_driver fastrpc_cb_driver = {
18911894
};
18921895

18931896
static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx,
1894-
const char *domain)
1897+
bool is_secured, const char *domain)
18951898
{
18961899
struct fastrpc_device *fdev;
18971900
int err;
@@ -1900,13 +1903,19 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct
19001903
if (!fdev)
19011904
return -ENOMEM;
19021905

1906+
fdev->secure = is_secured;
19031907
fdev->cctx = cctx;
19041908
fdev->miscdev.minor = MISC_DYNAMIC_MINOR;
19051909
fdev->miscdev.fops = &fastrpc_fops;
1906-
fdev->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "fastrpc-%s", domain);
1910+
fdev->miscdev.name = devm_kasprintf(dev, GFP_KERNEL, "fastrpc-%s%s",
1911+
domain, is_secured ? "-secure" : "");
19071912
err = misc_register(&fdev->miscdev);
1908-
if (!err)
1909-
cctx->fdevice = fdev;
1913+
if (!err) {
1914+
if (is_secured)
1915+
cctx->secure_fdevice = fdev;
1916+
else
1917+
cctx->fdevice = fdev;
1918+
}
19101919

19111920
return err;
19121921
}
@@ -1917,6 +1926,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
19171926
struct fastrpc_channel_ctx *data;
19181927
int i, err, domain_id = -1;
19191928
const char *domain;
1929+
bool secure_dsp;
19201930

19211931
err = of_property_read_string(rdev->of_node, "label", &domain);
19221932
if (err) {
@@ -1940,10 +1950,31 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
19401950
if (!data)
19411951
return -ENOMEM;
19421952

1943-
err = fastrpc_device_register(rdev, data, domains[domain_id]);
1944-
if (err) {
1945-
kfree(data);
1946-
return err;
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:
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:
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;
1974+
break;
1975+
default:
1976+
err = -EINVAL;
1977+
goto fdev_error;
19471978
}
19481979

19491980
kref_init(&data->refcount);
@@ -1957,6 +1988,9 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
19571988
data->rpdev = rpdev;
19581989

19591990
return of_platform_populate(rdev->of_node, NULL, NULL, rdev);
1991+
fdev_error:
1992+
kfree(data);
1993+
return err;
19601994
}
19611995

19621996
static void fastrpc_notify_users(struct fastrpc_user *user)
@@ -1983,6 +2017,9 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
19832017
if (cctx->fdevice)
19842018
misc_deregister(&cctx->fdevice->miscdev);
19852019

2020+
if (cctx->secure_fdevice)
2021+
misc_deregister(&cctx->secure_fdevice->miscdev);
2022+
19862023
of_platform_depopulate(&rpdev->dev);
19872024

19882025
cctx->rpdev = NULL;

0 commit comments

Comments
 (0)