misc: fastrpc: probe-time DSP capability query and unsigned ADSP node
cover misc: fastrpc: probe-time DSP capability query and unsigned ADSP node
This series moves FastRPC device node registration out of fastrpc_rpmsg_probe() and into an asynchronous per-channel workqueue that first queries the DSP for its capabilities, then registers the device nodes based on what it finds. Probe no longer blocks on the DSP responding.
With the DSP capabilities known before nodes are registered, the series also starts creating an additional unsigned PD device node for an ADSP domain whose firmware image reports itself as compute-capable, matching the existing CDSP/GDSP behaviour, instead of only ever exposing the signed node for ADSP.
Patch 1 does the probe-time refactor (capability query, async device registration, and the locking changes in fastrpc_device_open()/ fastrpc_rpmsg_remove() needed to keep that safe against SSR/remove() races). Patch 2 adds the unsigned node for compute-capable ADSP on top of it.
---
Anandu Krishnan E (2):
misc: fastrpc: query the dsp capabilities during probe time
misc: fastrpc: expose unsigned PD node for compute-capable ADSP
drivers/misc/fastrpc.c | 338 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 285 insertions(+), 53 deletions(-)
---
base-commit: a9c48428cbd8d96b26f92631d0db6f8519c5fcc5
change-id: 20261127-master-3f445438861f
Best regards,
Signature · 1 line
Anandu Krishnan E <[email protected]>
PATCH 1/2 misc: fastrpc: query the dsp capabilities during probe time
fastrpc_rpmsg_probe() currently registers the FastRPC device nodes synchronously before returning, with no way to know the DSP's compute capability at that point. A later change needs that capability available at probe time, to decide per domain whether an additional unsigned PD device node should be created.
Move device node registration into fastrpc_register_devices(), and run it from a new per-channel ordered workqueue instead of inline in probe(): queue a work item that first queries the DSP for its attributes using a throwaway fastrpc_user/session, caches the result in cctx->dsp_attributes, and then calls fastrpc_register_devices(). Probe returns immediately without waiting on the DSP.
The duplicate-ADSP-session block is also moved into fastrpc_register_devices(), ahead of any fastrpc_device_register()
call: since device node registration now happens after fastrpc_cb_devices_create() instead of before it, sessions may already be allocated by the time the node appears, and duplicating session state before exposing the node avoids copying a session that a racing open() has already marked used.
fastrpc_rpmsg_remove() cancels and drains the capability-query work (after notifying any in-flight invocation so it can't stay blocked on a DSP that is going away) before destroying the workqueue, so the work can never run against a channel that has already been torn down. Device node deregistration is kept after this drain, since the capability-query work may still be the one registering the nodes.
Device registration moving out from under probe()'s synchronous control also means fastrpc_device_open() can no longer assume that a live device node implies a non-NULL cctx->rpdev: it now re-checks cctx->rpdev, under the same lock fastrpc_rpmsg_remove() uses to clear it and notify cctx->users, both before doing any work and again right before linking the new fastrpc_user onto cctx->users.
Note: if fastrpc_register_devices() fails from within this work, it's just logged for now; retrying is left as a follow-up.
--- drivers/misc/fastrpc.c | 317 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 264 insertions(+), 53 deletions(-)
drivers/misc/fastrpc.c +264 -53
@@ -29,6 +29,7 @@#include <linux/bitops.h> #include <linux/compiler.h> #include <linux/iopoll.h> +#include <linux/workqueue.h> #define ADSP_DOMAIN_ID (0)#define MDSP_DOMAIN_ID (1)
@@ -339,6 +340,10 @@ struct fastrpc_channel_ctx {atomic_t ctx_seq;u64 dma_mask;const struct fastrpc_soc_data *soc_data; +/* Per-channel workqueue for the probe-time DSP capability query */ +struct workqueue_struct *cap_wq; +struct work_struct cap_query_work; +char domain[8 ]; };struct fastrpc_device {
@@ -1854,11 +1859,24 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp)struct fastrpc_channel_ctx *cctx;struct fastrpc_device *fdevice;struct fastrpc_user *fl =NULL ; +struct rpmsg_device *rpdev;unsigned long flags; fdevice =miscdev_to_fdevice (filp->private_data); cctx = fdevice->cctx; +/* +* The device node can still be open()able for a short time after +* fastrpc_rpmsg_remove() has cleared cctx->rpdev (misc_deregister() +* only runs once the capability-query work is fully drained). Bail +* out now instead of racing a NULL cctx->rpdev below. +*/ +spin_lock_irqsave (&cctx->lock, flags); + rpdev = cctx->rpdev; +spin_unlock_irqrestore (&cctx->lock, flags); +if (!rpdev) +return -ENODEV ; + fl =kzalloc_obj (*fl);if (!fl)return -ENOMEM ;
@@ -1879,14 +1897,28 @@ static int fastrpc_device_open(struct inode *inode, struct file *filp) fl->sctx =fastrpc_session_alloc (fl);if (!fl->sctx) { -dev_err_ratelimited (&cctx->rpdev->dev,"No session available\n" ); +dev_err_ratelimited (&rpdev->dev,"No session available\n" );mutex_destroy (&fl->mutex);kfree (fl);fastrpc_channel_ctx_put (cctx);return -EBUSY ; } +/* +* Re-check under the same lock fastrpc_rpmsg_remove() uses to clear +* cctx->rpdev and notify cctx->users: either this fl is linked before +* that notify loop runs (so it's included), or cctx->rpdev is already +* NULL here (so it's rejected) -- never linked in and missed by it. +*/ spin_lock_irqsave (&cctx->lock, flags); +if (!cctx->rpdev) { +spin_unlock_irqrestore (&cctx->lock, flags); +fastrpc_session_free (cctx, fl->sctx); +mutex_destroy (&fl->mutex); +kfree (fl); +fastrpc_channel_ctx_put (cctx); +return -ENODEV ; + }list_add_tail (&fl->user, &cctx->users);spin_unlock_irqrestore (&cctx->lock, flags);kref_init (&fl->refcount);
@@ -2585,6 +2617,195 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctreturn err; } +static int fastrpc_register_devices (struct fastrpc_channel_ctx *cctx, +struct rpmsg_device *rpdev) +{ +struct device *rdev = &rpdev->dev; +int err, i; + +/* +* Duplicate the ADSP sessions before any device node is registered +* below: misc_register() lets userspace open() and allocate a +* session immediately, and that allocation can mark session[sesscount - 1] +* used before it's copied into the new slots. +*/ +if (cctx->domain_id ==ADSP_DOMAIN_ID && cctx->sesscount >0 ) { +struct fastrpc_session_ctx *last_sess; +struct fastrpc_session_ctx *dup_sess; +unsigned long flags; + +spin_lock_irqsave (&cctx->lock, flags); + last_sess = &cctx->session[cctx->sesscount -1 ]; +for (i =0 ; i <FASTRPC_DUP_SESSIONS ; i++) { +if (cctx->sesscount >=FASTRPC_MAX_SESSIONS ) +break ; + dup_sess = &cctx->session[cctx->sesscount++]; +memcpy (dup_sess, last_sess,sizeof (*dup_sess)); + } +spin_unlock_irqrestore (&cctx->lock, flags); + } + +switch (cctx->domain_id) { +case ADSP_DOMAIN_ID : +case MDSP_DOMAIN_ID : +case SDSP_DOMAIN_ID : +/* Unsigned PD offloading is only supported on CDSP and GDSP */ + cctx->unsigned_support = false; + err =fastrpc_device_register (rdev, cctx, cctx->secure, cctx->domain); +if (err) + goto err_deregister_fdev; +break ; +case CDSP_DOMAIN_ID : +case GDSP_DOMAIN_ID : + cctx->unsigned_support = true; +/* Create both device nodes so that we can allow both Signed and Unsigned PD */ + err =fastrpc_device_register (rdev, cctx, true, cctx->domain); +if (err) + goto err_deregister_fdev; + + err =fastrpc_device_register (rdev, cctx, false, cctx->domain); +if (err) + goto err_deregister_fdev; +break ; +default : + err = -EINVAL ; + goto err_deregister_fdev; + } + +return 0 ; + +err_deregister_fdev: +if (cctx->fdevice) +misc_deregister (&cctx->fdevice->miscdev); +if (cctx->secure_fdevice) +misc_deregister (&cctx->secure_fdevice->miscdev); + +return err; +} + +static void fastrpc_cap_query_work (struct work_struct *work) +{ +struct fastrpc_channel_ctx *cctx = + container_of(work, struct fastrpc_channel_ctx, cap_query_work); +struct rpmsg_device *rpdev; +struct device *rdev; +u32 *dsp_attributes; +struct fastrpc_user *fl; +unsigned long flags; +int err; + +/* +* fastrpc_rpmsg_remove() can race this work and clear cctx->rpdev +* right before cancel_work_sync() waits on it. Take a stable, +* locked snapshot instead of reading cctx->rpdev unlocked: if the +* channel is already gone there's nothing left to query or +* register, and remove() owns the teardown. +*/ +spin_lock_irqsave (&cctx->lock, flags); + rpdev = cctx->rpdev; +spin_unlock_irqrestore (&cctx->lock, flags); +if (!rpdev) +return ; + rdev = &rpdev->dev; + + fl =kzalloc_obj (*fl); +if (!fl) + goto register_devices; + +spin_lock_init (&fl->lock); +mutex_init (&fl->mutex); +INIT_LIST_HEAD (&fl->pending); +INIT_LIST_HEAD (&fl->interrupted); +INIT_LIST_HEAD (&fl->maps); +INIT_LIST_HEAD (&fl->mmaps); +INIT_LIST_HEAD (&fl->user); + fl->cctx = cctx; + fl->pd =ROOT_PD ; +kref_init (&fl->refcount); +fastrpc_channel_ctx_get (cctx); + + fl->sctx =fastrpc_session_alloc (fl); +if (!fl->sctx) { +dev_warn (rdev,"no session for capability query, skipping\n" ); +fastrpc_user_put (fl); + goto register_devices; + } + + dsp_attributes =kzalloc_objs (*dsp_attributes,FASTRPC_MAX_DSP_ATTRIBUTES ); +if (!dsp_attributes) + goto err_cleanup_register; + +/* +* Linked into cctx->users so fastrpc_rpmsg_remove() can abort us +* via fastrpc_notify_users() instead of waiting out the timeout. +*/ +spin_lock_irqsave (&cctx->lock, flags); +if (!cctx->rpdev) { +spin_unlock_irqrestore (&cctx->lock, flags); +kfree (dsp_attributes); +fastrpc_session_free (cctx, fl->sctx); + fl->sctx =NULL ; +fastrpc_user_put (fl); +return ; + } +list_add_tail (&fl->user, &cctx->users); +spin_unlock_irqrestore (&cctx->lock, flags); + + err =fastrpc_get_info_from_dsp (fl, dsp_attributes,FASTRPC_MAX_DSP_ATTRIBUTES ); + +/* +* On -ETIMEDOUT, fastrpc_internal_invoke() leaves the ctx parked on +* fl->pending for a possible late DSP answer or a future SSR to +* resolve, and fastrpc_notify_users() can only find it through +* cctx->users: unlinking fl here would orphan that ctx forever if +* the DSP never answers (e.g. it crashed). Every other outcome means +* the ctx is already fully unlinked, so fl can leave cctx->users now. +*/ +if (err != -ETIMEDOUT ) { +spin_lock_irqsave (&cctx->lock, flags); +/* list_del_init(), not list_del(): fastrpc_user_free() removes fl +* from this same list again on the final put, so leave it pointing +* to itself instead of to LIST_POISON. +*/ +list_del_init (&fl->user); +spin_unlock_irqrestore (&cctx->lock, flags); + } + +if (err == -EPIPE ) { +/* Channel is going away; remove() will tear it down. */ +kfree (dsp_attributes); +fastrpc_session_free (cctx, fl->sctx); + fl->sctx =NULL ; +fastrpc_user_put (fl); +return ; + } + +if (!err) { +spin_lock_irqsave (&cctx->lock, flags); +memcpy (cctx->dsp_attributes, dsp_attributes, +FASTRPC_MAX_DSP_ATTRIBUTES_LEN ); + cctx->valid_attributes = true; +spin_unlock_irqrestore (&cctx->lock, flags); +dev_dbg (rdev,"DSP capabilities cached at probe time\n" ); + }else if (err ==DSP_UNSUPPORTED_API ) { +dev_info (rdev,"DSP does not support capability query\n" ); + }else { +dev_warn (rdev, +"probe-time capability query failed (%d), will retry on demand\n" , + err); + } + +err_cleanup_register: +kfree (dsp_attributes); +fastrpc_session_free (cctx, fl->sctx); + fl->sctx =NULL ; +fastrpc_user_put (fl); + +register_devices: +if (fastrpc_register_devices (cctx, rpdev)) +dev_err (rdev,"failed to register device nodes\n" ); +} +static int fastrpc_get_domain_id (const char *domain) {if (!strncmp (domain,"adsp" ,4 ))
@@ -2893,59 +3114,31 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) data->rpdev = rpdev;dev_set_drvdata (&rpdev->dev, data); -switch (domain_id) { -case ADSP_DOMAIN_ID : -case MDSP_DOMAIN_ID : -case SDSP_DOMAIN_ID : -/* Unsigned PD offloading is only supported on CDSP and GDSP */ - data->unsigned_support = false; - err =fastrpc_device_register (rdev, data, secure_dsp, domain); -if (err) - goto err_notify; -break ; -case CDSP_DOMAIN_ID : -case GDSP_DOMAIN_ID : - data->unsigned_support = true; -/* Create both device nodes so that we can allow both Signed and Unsigned PD */ - err =fastrpc_device_register (rdev, data, true, domain); -if (err) - goto err_notify; - - err =fastrpc_device_register (rdev, data, false, domain); -if (err) - goto err_deregister_fdev; -break ; -default : - err = -EINVAL ; - goto err_notify; - } - err =fastrpc_cb_devices_create (rpdev);if (err) - goto err_deregister_fdev; + goto err_notify; -if (data->domain_id ==ADSP_DOMAIN_ID && data->sesscount >0 ) { -struct fastrpc_session_ctx *last_sess; -struct fastrpc_session_ctx *dup_sess; +strscpy (data->domain, domain,sizeof (data->domain)); -spin_lock_irqsave (&data->lock, flags); - last_sess = &data->session[data->sesscount -1 ]; -for (i =0 ; i <FASTRPC_DUP_SESSIONS ; i++) { -if (data->sesscount >=FASTRPC_MAX_SESSIONS ) -break ; - dup_sess = &data->session[data->sesscount++]; -memcpy (dup_sess, last_sess,sizeof (*dup_sess)); - } -spin_unlock_irqrestore (&data->lock, flags); + data->cap_wq =alloc_ordered_workqueue ("fastrpc_cap_wq_%s" , +WQ_HIGHPRI , domain); +if (!data->cap_wq) { + err = -ENOMEM ; + goto err_destroy_cb; } +INIT_WORK (&data->cap_query_work, fastrpc_cap_query_work); + +/* +* Device node registration (and, for ADSP, the capability query that +* decides whether an unsigned PD node is also needed) happens +* asynchronously so a slow or unresponsive DSP cannot stall probe(). +*/ +queue_work (data->cap_wq, &data->cap_query_work);return 0 ; -err_deregister_fdev: -if (data->fdevice) -misc_deregister (&data->fdevice->miscdev); -if (data->secure_fdevice) -misc_deregister (&data->secure_fdevice->miscdev); +err_destroy_cb: +fastrpc_cb_devices_destroy (rpdev); err_notify:/*
@@ -2974,19 +3167,37 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)struct fastrpc_user *user;unsigned long flags; -if (cctx->fdevice) -misc_deregister (&cctx->fdevice->miscdev); - -if (cctx->secure_fdevice) -misc_deregister (&cctx->secure_fdevice->miscdev); - -/* No invocations past this point */ +/* +* No invocations past this point. Do this before cancel_work_sync() +* below: the probe-time capability query may be blocked waiting on a +* response from the very DSP that's going away, and fastrpc_notify_users() +* is what wakes it back up with -EPIPE. fastrpc_device_open() checks +* cctx->rpdev under the same lock before linking a new fl onto +* cctx->users, so no fl added after this point is missed here. +*/ spin_lock_irqsave (&cctx->lock, flags); cctx->rpdev =NULL ;list_for_each_entry (user, &cctx->users, user)fastrpc_notify_users (user);spin_unlock_irqrestore (&cctx->lock, flags); +/* +* Wait for the capability query (and the device node registration it +* may still be running) to fully finish before deregistering: it +* captured rpdev before this function ran and does not re-check +* cctx->rpdev, so it can still be registering a node concurrently. +*/ +if (cctx->cap_wq) { +cancel_work_sync (&cctx->cap_query_work); +destroy_workqueue (cctx->cap_wq); + } + +if (cctx->fdevice) +misc_deregister (&cctx->fdevice->miscdev); + +if (cctx->secure_fdevice) +misc_deregister (&cctx->secure_fdevice->miscdev); +fastrpc_remote_heap_release (cctx, rpdev);fastrpc_cb_devices_destroy (rpdev);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] misc: fastrpc: race between fastrpc_cap_query_work() and fastrpc_rpmsg_remove() - [Medium] misc…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] misc: fastrpc: race between fastrpc_cap_query_work() and fastrpc_rpmsg_remove()
- [Medium] misc: fastrpc: double misc_deregister() after fastrpc_register_devices() error
--
commit 502b28e3abb8ed99c00c841e2045fedc442784d7
Author: Anandu Krishnan E <[email protected]>
misc: fastrpc: query the dsp capabilities during probe time
This commit moves FastRPC device node registration out of fastrpc_rpmsg_probe() into a per-channel workqueue that first queries and caches the DSP capabilities before registering the device nodes.
Quoted 4 lines
drivers/misc/fastrpc.c +0
-0
[ ... ]
Quoted 9 lines
drivers/misc/fastrpc.c +5
-0@@ -2585,6 +2617,195 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctreturn err; } +static int fastrpc_register_devices (struct fastrpc_channel_ctx *cctx, +struct rpmsg_device *rpdev) +{ +struct device *rdev = &rpdev->dev; +int err, i;
[ ... ]
Quoted 17 lines
drivers/misc/fastrpc.c +17
-0+case CDSP_DOMAIN_ID : +case GDSP_DOMAIN_ID : + cctx->unsigned_support = true; +/* Create both device nodes so that we can allow both Signed and Unsigned PD */ + err =fastrpc_device_register (rdev, cctx, true, cctx->domain); +if (err) + goto err_deregister_fdev; + + err =fastrpc_device_register (rdev, cctx, false, cctx->domain); +if (err) + goto err_deregister_fdev; +break ; +default : + err = -EINVAL ; + goto err_deregister_fdev; + } +
drivers/misc/fastrpc.c static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct · line 2684
Quoted 10 lines
drivers/misc/fastrpc.c +10
-0+return 0 ; + +err_deregister_fdev: +if (cctx->fdevice) +misc_deregister (&cctx->fdevice->miscdev); +if (cctx->secure_fdevice) +misc_deregister (&cctx->secure_fdevice->miscdev); + +return err; +}
[Severity: Medium]
Can this cause a double misc_deregister() in fastrpc_rpmsg_remove() if the second fastrpc_device_register() call fails?
Previously, a registration failure aborted fastrpc_rpmsg_probe(), so fastrpc_rpmsg_remove() never ran. Now probe returns 0 before fastrpc_register_devices() runs, and fastrpc_cap_query_work() only logs the error. Because err_deregister_fdev does not clear cctx->secure_fdevice or cctx->fdevice after deregistering them, fastrpc_rpmsg_remove() will call misc_deregister() on cctx->secure_fdevice->miscdev a second time after its dynamic minor was already freed and reset to MISC_DYNAMIC_MINOR.
Also, at the register_devices label in fastrpc_cap_query_work(), fastrpc_register_devices() runs using the initial rpdev snapshot without re-checking whether fastrpc_rpmsg_remove() has already cleared cctx->rpdev.
Quoted 11 lines
drivers/misc/fastrpc.c +11
-0+ +static void fastrpc_cap_query_work (struct work_struct *work) +{ +struct fastrpc_channel_ctx *cctx = + container_of(work, struct fastrpc_channel_ctx, cap_query_work); +struct rpmsg_device *rpdev; +struct device *rdev; +u32 *dsp_attributes; +struct fastrpc_user *fl; +unsigned long flags; +int err;
[ ... ]
Quoted 7 lines
drivers/misc/fastrpc.c +7
-0+/* +* Linked into cctx->users so fastrpc_rpmsg_remove() can abort us +* via fastrpc_notify_users() instead of waiting out the timeout. +*/ +spin_lock_irqsave (&cctx->lock, flags); +if (!cctx->rpdev) { +spin_unlock_irqrestore (&cctx->lock, flags);
drivers/misc/fastrpc.c static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct · line 2754
Quoted 10 lines
drivers/misc/fastrpc.c +10
-0+kfree (dsp_attributes); +fastrpc_session_free (cctx, fl->sctx); + fl->sctx =NULL ; +fastrpc_user_put (fl); +return ; + } +list_add_tail (&fl->user, &cctx->users); +spin_unlock_irqrestore (&cctx->lock, flags); + + err =fastrpc_get_info_from_dsp (fl, dsp_attributes,FASTRPC_MAX_DSP_ATTRIBUTES );
[Severity: High]
Can fastrpc_rpmsg_remove() clear cctx->rpdev and finish its fastrpc_notify_users() pass after cctx->lock is dropped here, but before fastrpc_get_info_from_dsp() sends the message?
kworker CPU0fastrpc_cap_query_work()
spin_lock_irqsave(&cctx->lock)
list_add_tail(&fl->user, ...)
spin_unlock_irqrestore(&cctx->lock)
fastrpc_get_info_from_dsp()
fastrpc_internal_invoke()
if (!fl->cctx->rpdev)
fastrpc_rpmsg_remove()
spin_lock_irqsave(&cctx->lock)
cctx->rpdev = NULL
fastrpc_notify_users(fl)
/* fl->pending is still empty */
spin_unlock_irqrestore(&cctx->lock)
cancel_work_sync(&cctx->cap_query_work)
fastrpc_context_alloc()
...
fastrpc_invoke_send()
rpmsg_send(cctx->rpdev->ept, ...)
<-- NULL pointer dereferenceIf fastrpc_rpmsg_remove() runs after fastrpc_context_alloc() adds ctx to fl->pending (while fastrpc_get_args() sleeps in dma_alloc_coherent()) and before fastrpc_invoke_send() takes the worker reference with fastrpc_context_get(ctx), fastrpc_notify_users() also schedules ctx->put_work on a context with a refcount of 1, freeing ctx while fastrpc_internal_invoke() is still using it.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 misc: fastrpc: expose unsigned PD node for compute-capable ADSP
In reply to Anandu Krishnan EADSP running a compute-capable firmware image needs an additional unsigned PD device node, same as CDSP/GDSP, instead of only the signed node it gets today. The probe-time capability query now caches the DSP's attributes before device nodes are registered, so fastrpc_register_devices() can check DSP_IMAGE_CONFIG_ATTR_IDX and fall through to the CDSP/GDSP unsigned+signed registration path when the queried ADSP reports FASTRPC_DSP_COMPUTE_LITE.
--- drivers/misc/fastrpc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/misc/fastrpc.c +21 -0
@@ -88,6 +88,14 @@#define FASTRPC_MAX_DSP_ATTRIBUTES (256)#define FASTRPC_MAX_DSP_ATTRIBUTES_LEN (sizeof(u32) * FASTRPC_MAX_DSP_ATTRIBUTES) +/* remote_dsp_attributes[] index reporting the DSP's image configuration */ +#define DSP_IMAGE_CONFIG_ATTR_IDX (14) + +/* enum dsp_image_config: values reported at DSP_IMAGE_CONFIG_ATTR_IDX */ +#define FASTRPC_DSP_COMPUTE (1) +#define FASTRPC_DSP_COMPUTE_LITE (2) +#define FASTRPC_DSP_AUDIO (3) +/* Retrives number of input buffers from the scalars parameter */ #define REMOTE_SCALARS_INBUFS (sc) (((sc) >> 16) & 0x0ff)
@@ -2621,8 +2629,17 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, struct rpmsg_device *rpdev) {struct device *rdev = &rpdev->dev; +bool compute_capable = false;int err, i; +/* +* ADSP running a compute-capable firmware image also needs an +* unsigned PD node, same as CDSP/GDSP. +*/ +if (cctx->domain_id ==ADSP_DOMAIN_ID && cctx->valid_attributes && + cctx->dsp_attributes[DSP_IMAGE_CONFIG_ATTR_IDX ] ==FASTRPC_DSP_COMPUTE_LITE ) + compute_capable = true; +/* * Duplicate the ADSP sessions before any device node is registered * below: misc_register() lets userspace open() and allocate a
@@ -2647,6 +2664,9 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx,switch (cctx->domain_id) {case ADSP_DOMAIN_ID : +if (compute_capable) + goto unsigned_capable; + fallthrough;case MDSP_DOMAIN_ID :case SDSP_DOMAIN_ID :/* Unsigned PD offloading is only supported on CDSP and GDSP */
@@ -2657,6 +2677,7 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx,break ;case CDSP_DOMAIN_ID :case GDSP_DOMAIN_ID : +unsigned_capable: cctx->unsigned_support = true;/* Create both device nodes so that we can allow both Signed and Unsigned PD */ err =fastrpc_device_register (rdev, cctx, true, cctx->domain);
Signature · 1 line
2.34.1
Re: [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP
Quoted 10 lines · Anandu Krishnan E
ADSP running a compute-capable firmware image needs an additional unsigned PD device node, same as CDSP/GDSP, instead of only the signed node it gets today. The probe-time capability query now caches the DSP's attributes before device nodes are registered, so
fastrpc_register_devices()can checkDSP_IMAGE_CONFIG_ATTR_IDXand fall through to the CDSP/GDSP unsigned+signed registration path when the queried ADSP reportsFASTRPC_DSP_COMPUTE_LITE.Signed-off-by Anandu Krishnan E <[email protected]>---
[...]
Quoted 19 lines
drivers/misc/fastrpc.c +9
-0@@ -2621,8 +2629,17 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, struct rpmsg_device *rpdev) {struct device *rdev = &rpdev->dev; +bool compute_capable = false;int err, i; +/* +* ADSP running a compute-capable firmware image also needs an +* unsigned PD node, same as CDSP/GDSP. +*/ +if (cctx->domain_id ==ADSP_DOMAIN_ID && cctx->valid_attributes && + cctx->dsp_attributes[DSP_IMAGE_CONFIG_ATTR_IDX ] ==FASTRPC_DSP_COMPUTE_LITE ) + compute_capable = true; +/* * Duplicate the ADSP sessions before any device node is registered * below: misc_register() lets userspace open() and allocate a
drivers/misc/fastrpc.c static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, · line 2666
Quoted 3 lines
drivers/misc/fastrpc.c +0
-0@@ -2647,6 +2664,9 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx,switch (cctx->domain_id) {case ADSP_DOMAIN_ID :
With capability discovery in place, can we drop the domain_id handling from the driver altogether?
Konrad
[email protected]
AI reviewRe: [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP
In reply to Anandu Krishnan EThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] misc: fastrpc: unsigned ADSP node bypasses is_session_rejected() on attach - [Medium] misc: fastrpc…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] misc: fastrpc: unsigned ADSP node bypasses is_session_rejected() on attach
- [Medium] misc: fastrpc: double misc_deregister() on fastrpc_register_devices() failure
--
commit d18eec61ddce41081d48907710281fa58756b138
Author: Anandu Krishnan E <[email protected]>
misc: fastrpc: expose unsigned PD node for compute-capable ADSP
This commit registers both the secure and non-secure fastrpc device nodes when an ADSP domain reports FASTRPC_DSP_COMPUTE_LITE in its cached DSP attributes.
Quoted 4 lines
drivers/misc/fastrpc.c +0
-0
[ ... ]
drivers/misc/fastrpc.c static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, · line 2669
Quoted 7 lines
drivers/misc/fastrpc.c +3
-0@@ -2647,6 +2664,9 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx,switch (cctx->domain_id) {case ADSP_DOMAIN_ID : +if (compute_capable) + goto unsigned_capable; + fallthrough;
[Severity: High]
Can an untrusted application opening the non-secure /dev/fastrpc-adsp node on a secure ADSP channel bypass is_session_rejected() and attach to signed protection domains?
Jumping to unsigned_capable registers a non-secure node (fl->is_secure_dev is false) on a secure ADSP channel (fl->cctx->secure is true). While fastrpc_init_create_process() calls is_session_rejected() to restrict non-secure nodes to unsigned PD requests, neither fastrpc_init_create_static_process() nor fastrpc_init_attach() checks is_session_rejected(fl, false). Unlike CDSP and GDSP, ADSP populates cctx->remote_heap_addr, so an unprivileged caller holding an fd to /dev/fastrpc-adsp can invoke FASTRPC_IOCTL_INIT_CREATE_STATIC, FASTRPC_IOCTL_INIT_ATTACH, or FASTRPC_IOCTL_INIT_ATTACH_SNS to attach to the static Audio PD, ROOT_PD, or SENSORS_PD and invoke remote methods in those privileged PDs.
drivers/misc/fastrpc.c static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, · line 2683
Quoted 11 lines
drivers/misc/fastrpc.c +1
-0case MDSP_DOMAIN_ID :case SDSP_DOMAIN_ID :/* Unsigned PD offloading is only supported on CDSP and GDSP */ @@ -2657,6 +2677,7 @@ static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx,break ;case CDSP_DOMAIN_ID :case GDSP_DOMAIN_ID : +unsigned_capable: cctx->unsigned_support = true;/* Create both device nodes so that we can allow both Signed and Unsigned PD */ err =fastrpc_device_register (rdev, cctx, true, cctx->domain);
[Severity: Medium]
Can a failure when registering the second device node under unsigned_capable cause a double misc_deregister() on cctx->secure_fdevice->miscdev?
If the first fastrpc_device_register() succeeds and sets cctx->secure_fdevice, and the second fastrpc_device_register() for the non-secure node fails, err_deregister_fdev deregisters cctx->secure_fdevice->miscdev without clearing cctx->secure_fdevice to NULL:
drivers/misc/fastrpc.c:fastrpc_register_devices() {
...
err_deregister_fdev:
if (cctx->fdevice)
misc_deregister(&cctx->fdevice->miscdev);
if (cctx->secure_fdevice)
misc_deregister(&cctx->secure_fdevice->miscdev);
return err;
}Because fastrpc_register_devices() runs asynchronously in fastrpc_cap_query_work() after fastrpc_rpmsg_probe() has already returned 0, the rpmsg device remains bound. When fastrpc_rpmsg_remove() later runs on channel teardown, it sees cctx->secure_fdevice still non-NULL and calls misc_deregister(&cctx->secure_fdevice->miscdev) a second time, freeing an already-freed minor number.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2