* [PATCH 0/2] misc: fastrpc: probe-time DSP capability query and unsigned ADSP node
@ 2026-11-27 9:56 Anandu Krishnan E
2026-11-27 9:56 ` [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time Anandu Krishnan E
2026-11-27 9:56 ` [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP Anandu Krishnan E
0 siblings, 2 replies; 7+ messages in thread
From: Anandu Krishnan E @ 2026-11-27 9:56 UTC (permalink / raw)
To: Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann,
Greg Kroah-Hartman
Cc: linux-arm-msm, dri-devel, quic_bkumar, quic_chennak,
dmitry.baryshkov, Anandu Krishnan E
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.
Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
---
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,
--
Anandu Krishnan E <anandu.e@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time 2026-11-27 9:56 [PATCH 0/2] misc: fastrpc: probe-time DSP capability query and unsigned ADSP node Anandu Krishnan E @ 2026-11-27 9:56 ` Anandu Krishnan E 2026-11-27 10:23 ` sashiko-bot 2026-12-01 10:48 ` Murali Krishna 2026-11-27 9:56 ` [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP Anandu Krishnan E 1 sibling, 2 replies; 7+ messages in thread From: Anandu Krishnan E @ 2026-11-27 9:56 UTC (permalink / raw) To: Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman Cc: linux-arm-msm, dri-devel, quic_bkumar, quic_chennak, dmitry.baryshkov, Anandu Krishnan E 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. Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com> --- drivers/misc/fastrpc.c | 317 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 264 insertions(+), 53 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 5375847d8c9a..48ded6080ddd 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -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_ct return 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); -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time 2026-11-27 9:56 ` [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time Anandu Krishnan E @ 2026-11-27 10:23 ` sashiko-bot 2026-12-01 10:48 ` Murali Krishna 1 sibling, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-11-27 10:23 UTC (permalink / raw) To: Anandu Krishnan E; +Cc: dri-devel 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 <anandu.e@oss.qualcomm.com> 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. > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index 5375847d8c9a2..48ded6080ddd6 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c [ ... ] > @@ -2585,6 +2617,195 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ct > return err; > } > > +static int fastrpc_register_devices(struct fastrpc_channel_ctx *cctx, > + struct rpmsg_device *rpdev) > +{ > + struct device *rdev = &rpdev->dev; > + int err, i; [ ... ] > + 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; > +} [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. > + > +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; [ ... ] > + /* > + * 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); [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 CPU0 fastrpc_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 dereference If 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. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127-master-v1-0-f998ec22497b@oss.qualcomm.com?part=1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time 2026-11-27 9:56 ` [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time Anandu Krishnan E 2026-11-27 10:23 ` sashiko-bot @ 2026-12-01 10:48 ` Murali Krishna 1 sibling, 0 replies; 7+ messages in thread From: Murali Krishna @ 2026-12-01 10:48 UTC (permalink / raw) To: Anandu Krishnan E Cc: Murali Krishna, Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman, Vinayak Katoch, linux-arm-msm, dri-devel, quic_bkumar, quic_chennak, dmitry.baryshkov On Fri, Nov 27, 2026 at 03:26:38PM +0530, Anandu Krishnan E wrote: > /* > * Linked into cctx->users so fastrpc_rpmsg_remove() can abort us > * via fastrpc_notify_users() instead of waiting out the timeout. > */ I think this abort path currently deadlocks, and that the series makes an existing bug much easier to reach rather than introducing one. The work links fl onto cctx->users and then calls fastrpc_get_info_from_dsp(), which goes through fastrpc_internal_invoke() -> fastrpc_context_alloc(), and that puts a ctx on fl->pending. So for as long as the query is outstanding, the throwaway fl is on cctx->users with a non-empty fl->pending. That is exactly the state fastrpc_notify_users() walks, and on this base it does: fastrpc_notify_users(): spin_lock(&user->lock); fastrpc_context_schedule_put_work(): spin_lock(&ctx->fl->lock); with ctx->fl == user, since fastrpc_context_alloc() sets ctx->fl to the same fl it links the ctx onto. Same spinlock twice on one CPU, and fastrpc_rpmsg_remove() is holding cctx->lock with interrupts masked while it does this, so it is a hard lockup rather than a stall. Vinayak's "misc: fastrpc: make put_work scheduling lock-free" fixes that lock, and I think this series needs it underneath rather than alongside: both are based on a9c48428cbd8 and neither mentions the other. That patch now carries Ekansh's Reviewed-by and a Tested-by from Shawn Guo, who hit the same deadlock on Nord and reports it firing on every remoteproc stop of a DSP with an active fastrpc user, so none of this is theoretical. Worth noting how much this series changes the exposure. Today you need a userspace process with an invocation in flight at unbind time. With this series the driver itself has an invocation in flight on every probe, for up to the full timeout, and the mechanism it deliberately relies on to be aborted is the one that hangs. An unbind shortly after bind would hit it. There is a third change in this area now, too: Shawn Guo's "misc: fastrpc: Keep compute-cb devices across channel removal", posted today, reworks fastrpc_cb_devices_create() and fastrpc_cb_devices_destroy() and adjusts both fastrpc_rpmsg_probe() and fastrpc_rpmsg_remove() -- the same two functions this series restructures, with overlapping hunks. Together with the put_work fix that makes three changes in flight against the same teardown path. It seemed better to say so than to let it turn up as a conflict. Second, a behaviour change I did not see mentioned. Before this patch fastrpc_rpmsg_probe() called fastrpc_device_register() itself, from the domain switch, so the device nodes existed by the time probe() returned. Now probe() queues the work and returns, and the nodes appear only after the query finishes. fastrpc_get_info_from_dsp() is a kernel invoke, so fastrpc_wait_for_response() uses wait_for_completion_timeout(&ctx->work, 10 * HZ): on a DSP that never answers, /dev/fastrpc-* shows up ten seconds after the device is bound. Anything that binds and then opens the node, a udev rule or an init script, now races where it did not before. If that is an acceptable trade it would be good to have it in the commit message, since it is the kind of thing that gets bisected to later. It also looks avoidable for most domains. fastrpc_register_devices() only consults the queried attributes for ADSP_DOMAIN_ID; for MDSP, SDSP, CDSP and GDSP the result does not affect which nodes are created, yet all of them now wait for it. Queueing the query only for ADSP, and leaving the other domains registering inline as they do today, would keep the new asynchrony confined to the domain that actually needs it. Which leads to a question rather than a comment. The capability is already queried lazily and cached in cctx->dsp_attributes behind cctx->valid_attributes on the FASTRPC_IOCTL_GET_DSP_INFO path, so the only reason to ask at probe time is to decide the ADSP node. Does compute-capability vary by firmware image at runtime, or only by SoC? If it only varies by SoC, soc_data already carries that sort of per-platform difference and would settle it without the workqueue, the throwaway user and session, the cancel_work_sync() dance, or the new cctx->rpdev re-checks in fastrpc_device_open() -- 264 added lines to learn one bit. If it really is per-image then that does not work and the query is needed, but it seemed worth asking, and it is close to the question already raised on 2/2 about dropping the domain_id handling. Two small things: checkpatch --strict has one complaint on 1/2: CHECK: Alignment should match open parenthesis + data->cap_wq = alloc_ordered_workqueue("fastrpc_cap_wq_%s", + WQ_HIGHPRI, domain); And, pre-existing rather than yours, but in a function you are restructuring anyway: fastrpc_device_open() publishes fl on cctx->users and drops cctx->lock before kref_init(&fl->refcount) runs, so fl is briefly reachable from the list with a refcount of zero. Nothing takes a reference off that list today, so it is latent, but moving the kref_init() above the list_add_tail() would cost nothing. On the mechanical side, on linux-next next-20261127: git apply --check clean, 1/2 then 2/2 in order make W=1 fastrpc.o 0 warnings sparse 0.6.4 C=1 only the two pre-existing of_device_id warnings, unchanged checkpatch --strict 1/2: 0 errors, 0 warnings, 1 check (above) 2/2: clean I have no Qualcomm hardware, so none of this was run; it is all reading the code and building it. I may well have the firmware-versus-SoC question backwards, in which case most of the above falls away. Thanks, Murali Krishna ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP 2026-11-27 9:56 [PATCH 0/2] misc: fastrpc: probe-time DSP capability query and unsigned ADSP node Anandu Krishnan E 2026-11-27 9:56 ` [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time Anandu Krishnan E @ 2026-11-27 9:56 ` Anandu Krishnan E 2026-11-27 10:06 ` Konrad Dybcio 2026-11-27 10:20 ` sashiko-bot 1 sibling, 2 replies; 7+ messages in thread From: Anandu Krishnan E @ 2026-11-27 9:56 UTC (permalink / raw) To: Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman Cc: linux-arm-msm, dri-devel, quic_bkumar, quic_chennak, dmitry.baryshkov, 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 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. Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com> --- drivers/misc/fastrpc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 48ded6080ddd..28d29c768aad 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -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); -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP 2026-11-27 9:56 ` [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP Anandu Krishnan E @ 2026-11-27 10:06 ` Konrad Dybcio 2026-11-27 10:20 ` sashiko-bot 1 sibling, 0 replies; 7+ messages in thread From: Konrad Dybcio @ 2026-11-27 10:06 UTC (permalink / raw) To: Anandu Krishnan E, Srinivas Kandagatla, Ekansh Gupta, Arnd Bergmann, Greg Kroah-Hartman Cc: linux-arm-msm, dri-devel, quic_bkumar, quic_chennak, dmitry.baryshkov On 11/27/26 10:56 AM, Anandu Krishnan E wrote: > 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 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. > > Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com> > --- [...] > @@ -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: With capability discovery in place, can we drop the domain_id handling from the driver altogether? Konrad ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP 2026-11-27 9:56 ` [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP Anandu Krishnan E 2026-11-27 10:06 ` Konrad Dybcio @ 2026-11-27 10:20 ` sashiko-bot 1 sibling, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-11-27 10:20 UTC (permalink / raw) To: Anandu Krishnan E; +Cc: dri-devel 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 <anandu.e@oss.qualcomm.com> 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. > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index 48ded6080ddd6..28d29c768aad7 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c [ ... ] > @@ -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. > 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); [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. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261127-master-v1-0-f998ec22497b@oss.qualcomm.com?part=2 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-01 10:49 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-27 9:56 [PATCH 0/2] misc: fastrpc: probe-time DSP capability query and unsigned ADSP node Anandu Krishnan E 2026-11-27 9:56 ` [PATCH 1/2] misc: fastrpc: query the dsp capabilities during probe time Anandu Krishnan E 2026-11-27 10:23 ` sashiko-bot 2026-12-01 10:48 ` Murali Krishna 2026-11-27 9:56 ` [PATCH 2/2] misc: fastrpc: expose unsigned PD node for compute-capable ADSP Anandu Krishnan E 2026-11-27 10:06 ` Konrad Dybcio 2026-11-27 10:20 ` sashiko-bot
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.