* [PATCH v2 0/2] misc: fastrpc: move ADSP duplicate session creation to the driver
@ 2026-07-08 3:58 Vinayak Katoch
2026-07-08 3:58 ` [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions Vinayak Katoch
2026-07-08 3:58 ` [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing Vinayak Katoch
0 siblings, 2 replies; 6+ messages in thread
From: Vinayak Katoch @ 2026-07-08 3:58 UTC (permalink / raw)
To: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-arm-msm, dri-devel, linux-kernel, Bharath Kumar,
Chenna Kesava Raju, Ekansh Gupta, devicetree, Vinayak Katoch
For ADSP, only a limited number of FastRPC context banks (CBs) are
available. Each CB supports a single session, which means only a few
processes can run on ADSP simultaneously. If all sessions are consumed
by fastrpc daemons, no session remains available when a user application
starts, causing the application to fail.
To work around this, some Device Tree sources set:
qcom,nsessions = <5>;
which duplicated sessions inline during fastrpc_cb_probe(). Upstream
feedback indicated that this policy does not belong in DT and should be
handled at the driver level instead.
This series removes the per-CB DT-driven duplication and replaces it with
a fixed driver-side post-probe step: after of_platform_populate() returns
in fastrpc_rpmsg_probe() — once all compute-CB child nodes have been
probed and the session array is fully populated — FASTRPC_DUP_SESSIONS (4)
copies of the last probed session are appended for the ADSP domain. This
keeps the per-CB probe path simple and ensures duplicates are always
derived from a stable, fully-initialised session state.
The qcom,nsessions binding is deprecated in the same series.
Patch [v1]: https://lore.kernel.org/r/20260609-dup-sessions-v1-1-26934abb9fa3@oss.qualcomm.com
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
---
Changes in v2:
- Added patch to deprecate the qcom,nsessions dt-binding.
- Kept the logic unchanged; only split into two patches.
---
Vinayak Katoch (2):
dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions
misc: fastrpc: create duplicate sessions after all CB probing
.../devicetree/bindings/misc/qcom,fastrpc.yaml | 2 ++
drivers/misc/fastrpc.c | 30 ++++++++++++----------
2 files changed, 19 insertions(+), 13 deletions(-)
---
base-commit: 97e797263a5e963da3d1e66e743fd518567dfe37
change-id: 20260609-dup-sessions-ea2acaac1994
Best regards,
--
Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions
2026-07-08 3:58 [PATCH v2 0/2] misc: fastrpc: move ADSP duplicate session creation to the driver Vinayak Katoch
@ 2026-07-08 3:58 ` Vinayak Katoch
2026-07-08 7:11 ` Krzysztof Kozlowski
2026-07-08 3:58 ` [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing Vinayak Katoch
1 sibling, 1 reply; 6+ messages in thread
From: Vinayak Katoch @ 2026-07-08 3:58 UTC (permalink / raw)
To: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-arm-msm, dri-devel, linux-kernel, Bharath Kumar,
Chenna Kesava Raju, Ekansh Gupta, devicetree, Vinayak Katoch
The qcom,nsessions property was used to duplicate FastRPC sessions
inline during context bank probing. Session duplication is now handled
at the driver level, making this DT property redundant. Mark it
deprecated.
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
---
Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
index ca830dd06de2..683989c468cf 100644
--- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
+++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
@@ -96,8 +96,10 @@ patternProperties:
qcom,nsessions:
$ref: /schemas/types.yaml#/definitions/uint32
default: 1
+ deprecated: true
description: >
A value indicating how many sessions can share this context bank.
+ Session duplication is now handled by the driver.
required:
- compatible
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing
2026-07-08 3:58 [PATCH v2 0/2] misc: fastrpc: move ADSP duplicate session creation to the driver Vinayak Katoch
2026-07-08 3:58 ` [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions Vinayak Katoch
@ 2026-07-08 3:58 ` Vinayak Katoch
2026-07-08 4:13 ` sashiko-bot
2026-07-08 6:11 ` Dmitry Baryshkov
1 sibling, 2 replies; 6+ messages in thread
From: Vinayak Katoch @ 2026-07-08 3:58 UTC (permalink / raw)
To: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: linux-arm-msm, dri-devel, linux-kernel, Bharath Kumar,
Chenna Kesava Raju, Ekansh Gupta, devicetree, Vinayak Katoch
For ADSP, only a limited number of FastRPC context banks (CBs) are
available. Each CB supports a single session, which means only a few
processes can run on ADSP simultaneously. If all sessions are consumed
by fastrpc daemons, no session remains available when a user application
starts, causing the application to fail.
To address this limitation, a Device Tree change was used till now:
qcom,nsessions = <5>;
However, feedback from the upstream community indicated that this change
should not be made in the Device Tree. Instead, it was recommended to
handle this as a driver-level change.
Instead of duplicating sessions inline during fastrpc_cb_probe() using
the qcom,nsessions DT property, defer duplication until after
of_platform_populate() returns in fastrpc_rpmsg_probe(), at which point
all compute-CB child nodes have been probed and the session array is
fully populated.
For the ADSP domain, append FASTRPC_DUP_SESSIONS (4) copies of the
last probed session once of_platform_populate() succeeds. This keeps
the per-CB probe path simple and ensures duplicates are always derived
from a stable, fully-initialised session state.
The qcom,nsessions DT property is no longer consumed by the driver; the
binding and DT sources are left unchanged.
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
---
drivers/misc/fastrpc.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1080f9acf70a..8a3944f6c036 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -30,6 +30,7 @@
#define CDSP_DOMAIN_ID (3)
#define GDSP_DOMAIN_ID (4)
#define FASTRPC_MAX_SESSIONS 14
+#define FASTRPC_DUP_SESSIONS 4
#define FASTRPC_MAX_VMIDS 16
#define FASTRPC_ALIGN 128
#define FASTRPC_MAX_FDLIST 16
@@ -2195,7 +2196,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
struct fastrpc_channel_ctx *cctx;
struct fastrpc_session_ctx *sess;
struct device *dev = &pdev->dev;
- int i, sessions = 0;
unsigned long flags;
int rc;
u32 dma_bits;
@@ -2204,8 +2204,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
if (!cctx)
return -EINVAL;
- of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions);
-
spin_lock_irqsave(&cctx->lock, flags);
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
dev_err(&pdev->dev, "too many sessions\n");
@@ -2225,16 +2223,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
if (of_property_read_u32(dev->of_node, "reg", &sess->sid))
dev_info(dev, "FastRPC Session ID not specified in DT\n");
- if (sessions > 0) {
- struct fastrpc_session_ctx *dup_sess;
-
- for (i = 1; i < sessions; i++) {
- if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
- break;
- dup_sess = &cctx->session[cctx->sesscount++];
- memcpy(dup_sess, sess, sizeof(*dup_sess));
- }
- }
spin_unlock_irqrestore(&cctx->lock, flags);
rc = dma_set_mask(dev, DMA_BIT_MASK(dma_bits));
if (rc) {
@@ -2445,6 +2433,22 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
if (err)
goto err_deregister_fdev;
+ if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
+ struct fastrpc_session_ctx *last_sess;
+ struct fastrpc_session_ctx *dup_sess;
+ unsigned long flags;
+
+ 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);
+ }
+
return 0;
err_deregister_fdev:
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing
2026-07-08 3:58 ` [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing Vinayak Katoch
@ 2026-07-08 4:13 ` sashiko-bot
2026-07-08 6:11 ` Dmitry Baryshkov
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-07-08 4:13 UTC (permalink / raw)
To: Vinayak Katoch; +Cc: dri-devel, conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Concurrent `open()` calls during the unprotected gap after child probing permanently leak duplicated sessions.
Pre-existing issues:
- [Critical] The misc device is exposed to userspace before crucial synchronization primitives and lists are initialized, leading to uninitialized spinlock usage and NULL pointer dereferences.
- [High] Missing `of_platform_depopulate()` on the `of_platform_populate()` error path causes dangling child devices with freed drvdata.
- [High] On the error path of `fastrpc_rpmsg_probe()`, `kfree(data)` unconditionally frees memory while a userspace file descriptor may hold a reference.
--
--- Patch [2]: [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing ---
commit 56303754fdfc0beae4b68e60fa9dc54ca7e73396
Author: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
misc: fastrpc: create duplicate sessions after all CB probing
Instead of duplicating sessions inline during fastrpc_cb_probe() using
the qcom,nsessions DT property, defer duplication until after
of_platform_populate() returns in fastrpc_rpmsg_probe(), at which point
all compute-CB child nodes have been probed and the session array is
fully populated.
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
[ ... ]
> @@ -2352,6 +2352,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
[ ... ]
> 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);
[Severity: Critical]
This isn't a bug introduced by this patch, but does registering the misc
device here expose it to userspace before crucial synchronization primitives
are initialized?
A concurrent userspace process could immediately call open(), which would
attempt to use data->refcount and data->lock before they are initialized
further down in this function.
> if (err)
> goto err_free_data;
> break;
[ ... ]
> spin_lock_init(&data->lock);
> idr_init(&data->ctx_idr);
> data->domain_id = domain_id;
> data->rpdev = rpdev;
> dev_set_drvdata(&rpdev->dev, data);
>
> err = of_platform_populate(rdev->of_node, NULL, NULL, rdev);
> if (err)
> goto err_deregister_fdev;
[Severity: High]
This is a pre-existing issue, but if of_platform_populate() fails halfway
through, does the error path miss a call to of_platform_depopulate()?
Since the channel context data is freed on the error path, this could leave
dangling child devices that might dereference freed drvdata when they are
later unbound.
> + if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
> + struct fastrpc_session_ctx *last_sess;
> + struct fastrpc_session_ctx *dup_sess;
> + unsigned long flags;
> +
> + 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));
[Severity: High]
Can this loop permanently leak session capacity if userspace calls open()
concurrently?
Since the lock is dropped in fastrpc_cb_probe() long before we get here,
could a concurrent open() claim last_sess and set its used flag to true?
If so, this memcpy() would blindly duplicate the used=true state into all
new sessions, making them permanently unavailable to subsequent users.
> + }
> + spin_unlock_irqrestore(&data->lock, flags);
> + }
> +
> return 0;
>
> err_deregister_fdev:
> if (data->fdevice)
> misc_deregister(&data->fdevice->miscdev);
> if (data->secure_fdevice)
> misc_deregister(&data->secure_fdevice->miscdev);
>
> err_free_data:
> kfree(data);
[Severity: High]
This is a pre-existing issue, but does calling kfree(data) here
unconditionally cause a use-after-free if userspace has already opened
the misc device?
Because the misc device is registered earlier in this function, a userspace
process might already hold an open file descriptor. If we free the channel
context here upon a probe failure, any subsequent ioctls or close
operations by that process will access freed memory.
> return err;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-dup-sessions-v2-0-da40f9c98a2b@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing
2026-07-08 3:58 ` [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing Vinayak Katoch
2026-07-08 4:13 ` sashiko-bot
@ 2026-07-08 6:11 ` Dmitry Baryshkov
1 sibling, 0 replies; 6+ messages in thread
From: Dmitry Baryshkov @ 2026-07-08 6:11 UTC (permalink / raw)
To: Vinayak Katoch
Cc: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-arm-msm, dri-devel, linux-kernel,
Bharath Kumar, Chenna Kesava Raju, Ekansh Gupta, devicetree
On Wed, Jul 08, 2026 at 09:28:33AM +0530, Vinayak Katoch wrote:
> For ADSP, only a limited number of FastRPC context banks (CBs) are
> available. Each CB supports a single session, which means only a few
> processes can run on ADSP simultaneously. If all sessions are consumed
> by fastrpc daemons, no session remains available when a user application
> starts, causing the application to fail.
>
> To address this limitation, a Device Tree change was used till now:
> qcom,nsessions = <5>;
>
> However, feedback from the upstream community indicated that this change
> should not be made in the Device Tree. Instead, it was recommended to
> handle this as a driver-level change.
>
> Instead of duplicating sessions inline during fastrpc_cb_probe() using
> the qcom,nsessions DT property, defer duplication until after
> of_platform_populate() returns in fastrpc_rpmsg_probe(), at which point
> all compute-CB child nodes have been probed and the session array is
> fully populated.
>
> For the ADSP domain, append FASTRPC_DUP_SESSIONS (4) copies of the
> last probed session once of_platform_populate() succeeds. This keeps
> the per-CB probe path simple and ensures duplicates are always derived
> from a stable, fully-initialised session state.
>
> The qcom,nsessions DT property is no longer consumed by the driver; the
> binding and DT sources are left unchanged.
>
> Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
> ---
> drivers/misc/fastrpc.c | 30 +++++++++++++++++-------------
> 1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index 1080f9acf70a..8a3944f6c036 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -30,6 +30,7 @@
> #define CDSP_DOMAIN_ID (3)
> #define GDSP_DOMAIN_ID (4)
> #define FASTRPC_MAX_SESSIONS 14
> +#define FASTRPC_DUP_SESSIONS 4
> #define FASTRPC_MAX_VMIDS 16
> #define FASTRPC_ALIGN 128
> #define FASTRPC_MAX_FDLIST 16
> @@ -2195,7 +2196,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
> struct fastrpc_channel_ctx *cctx;
> struct fastrpc_session_ctx *sess;
> struct device *dev = &pdev->dev;
> - int i, sessions = 0;
> unsigned long flags;
> int rc;
> u32 dma_bits;
> @@ -2204,8 +2204,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
> if (!cctx)
> return -EINVAL;
>
> - of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions);
> -
> spin_lock_irqsave(&cctx->lock, flags);
> if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
> dev_err(&pdev->dev, "too many sessions\n");
> @@ -2225,16 +2223,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
> if (of_property_read_u32(dev->of_node, "reg", &sess->sid))
> dev_info(dev, "FastRPC Session ID not specified in DT\n");
>
> - if (sessions > 0) {
> - struct fastrpc_session_ctx *dup_sess;
> -
> - for (i = 1; i < sessions; i++) {
> - if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
> - break;
> - dup_sess = &cctx->session[cctx->sesscount++];
> - memcpy(dup_sess, sess, sizeof(*dup_sess));
> - }
> - }
> spin_unlock_irqrestore(&cctx->lock, flags);
> rc = dma_set_mask(dev, DMA_BIT_MASK(dma_bits));
> if (rc) {
> @@ -2445,6 +2433,22 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
> if (err)
> goto err_deregister_fdev;
>
> + if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
There is no guarantee that child probes have finished at this point. If
you want to make it work this way, you need to replace
of_platform_populate() with the manual iteration over the child nodes,
creating CB device for each node (also getting rid of
fastrpc_cb_driver).
> + struct fastrpc_session_ctx *last_sess;
> + struct fastrpc_session_ctx *dup_sess;
> + unsigned long flags;
> +
> + 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);
> + }
> +
> return 0;
>
> err_deregister_fdev:
>
> --
> 2.34.1
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions
2026-07-08 3:58 ` [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions Vinayak Katoch
@ 2026-07-08 7:11 ` Krzysztof Kozlowski
0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2026-07-08 7:11 UTC (permalink / raw)
To: Vinayak Katoch
Cc: Srinivas Kandagatla, Amol Maheshwari, Arnd Bergmann,
Greg Kroah-Hartman, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux-arm-msm, dri-devel, linux-kernel,
Bharath Kumar, Chenna Kesava Raju, Ekansh Gupta, devicetree
On Wed, Jul 08, 2026 at 09:28:32AM +0530, Vinayak Katoch wrote:
> The qcom,nsessions property was used to duplicate FastRPC sessions
> inline during context bank probing. Session duplication is now handled
> at the driver level, making this DT property redundant. Mark it
> deprecated.
>
> Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
> ---
> Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 2 ++
> 1 file changed, 2 insertions(+)
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-08 7:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 3:58 [PATCH v2 0/2] misc: fastrpc: move ADSP duplicate session creation to the driver Vinayak Katoch
2026-07-08 3:58 ` [PATCH v2 1/2] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions Vinayak Katoch
2026-07-08 7:11 ` Krzysztof Kozlowski
2026-07-08 3:58 ` [PATCH v2 2/2] misc: fastrpc: create duplicate sessions after all CB probing Vinayak Katoch
2026-07-08 4:13 ` sashiko-bot
2026-07-08 6:11 ` Dmitry Baryshkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox