Skip to content

misc: fastrpc: fix init ordering race in rpmsg probe - #1256

Open
Vinayak Katoch (quic-vkatoch) wants to merge 5 commits into
qualcomm-linux:qcom-6.18.yfrom
quic-vkatoch:fix-probe-init-race
Open

Vinayak Katoch (quic-vkatoch) wants to merge 5 commits into
qualcomm-linux:qcom-6.18.yfrom
quic-vkatoch:fix-probe-init-race

Conversation

@quic-vkatoch

Copy link
Copy Markdown

fastrpc_device_register() calls misc_register(), making the device node visible to userspace. However kref_init(), spin_lock_init(), INIT_LIST_HEAD(), dev_set_drvdata(), and fastrpc_cb_devices_create() were all called after the switch block, leaving a window where userspace can open the device on a partially initialised channel context.

A concurrent open() in this window calls kref_get() on a kzalloc-zeroed, never kref_init()'d refcount of 0:

refcount_t: addition on 0; use-after-free.
Call trace:
 refcount_warn_saturate+0x120/0x148 (P)
 fastrpc_device_open+0x204/0x258 [fastrpc]
 misc_open+0xd8/0x1a0

Since fastrpc_cb_devices_create() hasn't run yet, sesscount is 0, so fastrpc_session_alloc() returns NULL and the error path calls fastrpc_channel_ctx_put() on the bogus refcount, freeing the channel context. A subsequent IRQ-path fastrpc_rpmsg_callback() then dereferences the freed spinlock:

Unable to handle kernel paging request at virtual address ffffcd5841510ca0
Internal error: Oops: 0000000096000047 [#1] SMP
Call trace:
 queued_spin_lock_slowpath+0x414/0x5e0 (P)
 _raw_spin_lock_irqsave+0x74/0x90
 fastrpc_rpmsg_callback+0x4c/0xf0 [fastrpc]
 qcom_glink_native_rx+0x6c4/0xf10
 qcom_glink_smem_intr+0x1c/0x38 [qcom_glink_smem]
 Kernel panic - not syncing: Oops: Fatal exception in interrupt

Move all channel context initialisation before fastrpc_device_register() so the struct is fully ready before the device node is visible to userspace. Add an err_depopulate label to properly tear down CB children when fastrpc_device_register() fails.

Link: https://lore.kernel.org/all/20261001-fastrpc-probe-fixes-v1-2-1376d93b8b3e@oss.qualcomm.com/
CRs-Fixed: 4670685

…form_populate

of_platform_populate() only guarantees that child devices are registered,
not that their probes have completed before it returns. This creates a
window where fastrpc_cb_init() may not have run for all context bank
nodes, leaving the channel context partially initialised.

Introduce fastrpc_cb_devices_create() to iterate over child DT nodes
directly and call fastrpc_cb_init() synchronously for each
qcom,fastrpc-compute-cb node. This ensures all context banks are fully
initialised before fastrpc_rpmsg_probe() returns.

Introduce fastrpc_cb_devices_destroy() as the symmetric counterpart.
Before destroying the CB platform devices, invalidate all sessions under
the channel lock so that any fastrpc_user still holding a reference to
the channel context cannot acquire a new session backed by a destroyed
device.

Since fastrpc_cb_driver is no longer needed as an independent platform
driver, remove it along with its match table and remove callback. Use
module_rpmsg_driver() now that only a single driver registration remains.

Link: https://lore.kernel.org/all/20260923-dup-sessions-v5-1-e953133a1827@oss.qualcomm.com/
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
…driver

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, qcom,nsessions = <5> was set in DT to duplicate
sessions inline during fastrpc_cb_init(). This policy does not belong
in DT and should be handled at the driver level instead.

Remove the qcom,nsessions DT property read and the per-CB duplication
logic from fastrpc_cb_init(). After all context banks have been
initialised in fastrpc_rpmsg_probe(), append FASTRPC_DUP_SESSIONS (4)
copies of the last session for the ADSP domain.

Link: https://lore.kernel.org/all/20260923-dup-sessions-v5-2-e953133a1827@oss.qualcomm.com/
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
The qcom,nsessions property was used to duplicate FastRPC sessions
inline during context bank initialisation. Session duplication is now
handled at the driver level, making this DT property redundant. Mark
it deprecated.

Link: https://lore.kernel.org/all/20260923-dup-sessions-v5-3-e953133a1827@oss.qualcomm.com/
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
…c fails

When a fastrpc client process dies abnormally without closing its file
descriptor, fastrpc_device_release() is never called and the compute-cb
session slot is never freed. The abnormal client death on the DSP side
triggers a glink channel teardown which propagates up through the rpmsg
bus and calls fastrpc_rpmsg_remove().

fastrpc_rpmsg_remove() nulls cctx->rpdev before calling
misc_deregister(). If a concurrent open() enters fastrpc_device_open()
in this window and fastrpc_session_alloc() returns NULL (sessions
exhausted by the leaked slot), the error path dereferences
cctx->rpdev->dev causing a NULL pointer dereference:

  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
  pc : fastrpc_device_open+0x1b8/0x258 [fastrpc]
  Call trace:
   fastrpc_device_open+0x1b8/0x258 [fastrpc] (P)
   misc_open+0xd8/0x1a0

Fix by moving misc_deregister() before rpdev = NULL. misc_open() and
misc_deregister() both take misc_mtx, so misc_deregister() will either
block until fastrpc_device_open() completes or prevent new opens from
entering it entirely.

Link: https://lore.kernel.org/all/20261001-fastrpc-probe-fixes-v1-1-1376d93b8b3e@oss.qualcomm.com/
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
fastrpc_device_register() calls misc_register() which makes the device
node visible to userspace. However, kref_init(), spin_lock_init(),
INIT_LIST_HEAD(), dev_set_drvdata() and fastrpc_cb_devices_create()
were all called after the switch/misc_register block, leaving a window
where userspace can open the device and call fastrpc_device_open() on
a partially initialised channel context.

On a concurrent open(), fastrpc_channel_ctx_get() calls kref_get() on
a kzalloc-zeroed, never kref_init()'d refcount of 0, triggering:

  refcount_t: addition on 0; use-after-free.
  Call trace:
   refcount_warn_saturate+0x120/0x148 (P)
   fastrpc_device_open+0x204/0x258 [fastrpc]
   misc_open+0xd8/0x1a0

Additionally, fastrpc_cb_devices_create() not having run means
sesscount is still 0, so fastrpc_session_alloc() returns NULL and
fastrpc_device_open() hits the error path which calls
fastrpc_channel_ctx_put() on the already-bogus refcount. This
triggers the free callback, kfree()-ing the channel context. A
subsequent IRQ-path fastrpc_rpmsg_callback() then dereferences the
freed spinlock:

  Unable to handle kernel paging request at virtual address ffffcd5841510ca0
  Internal error: Oops: 0000000096000047 [qualcomm-linux#1] SMP
  Call trace:
   queued_spin_lock_slowpath+0x414/0x5e0 (P)
   _raw_spin_lock_irqsave+0x74/0x90
   fastrpc_rpmsg_callback+0x4c/0xf0 [fastrpc]
   qcom_glink_native_rx+0x6c4/0xf10
   qcom_glink_smem_intr+0x1c/0x38 [qcom_glink_smem]
  Kernel panic - not syncing: Oops: Fatal exception in interrupt

Fix by moving all channel context initialisation (kref_init,
spin_lock_init, INIT_LIST_HEAD, idr_init, dev_set_drvdata) and
fastrpc_cb_devices_create() before fastrpc_device_register(), ensuring
the struct is fully ready before the device node is visible to
userspace.

Add err_depopulate label in the error path since
fastrpc_cb_devices_create() now runs before misc_register(); a
fastrpc_device_register() failure must call fastrpc_cb_devices_destroy()
to clean up the compute-cb children before freeing data.

Link: https://lore.kernel.org/all/20261001-fastrpc-probe-fixes-v1-2-1376d93b8b3e@oss.qualcomm.com/
Fixes: 3abe3ab ("misc: fastrpc: add secure domain support")
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
@qswat-orbit-external

Copy link
Copy Markdown

Merge Check Failed: No Change Task Found

No associated change tasks found for CR 4670685 on any of the following entities:

Entities:

  • kernel.qli.2.0

CR: 4670685

Please ensure the CR has a change task associated with at least one of the entities for this branch.

@qlijarvis

Copy link
Copy Markdown

PR #1256 — validate-patch

PR: #1256

Verdict Issues Detailed Report
✅ 0 Full report

Final Summary

  1. Lore link present: Yes — all 5 commits have valid lore.kernel.org links in Link: trailers.
  2. Lore link matches PR commits: Yes — diff content, commit messages, and authorship are faithful to lore sources; only line number context differs due to tree state.
  3. Upstream patch status: ⏳ Decision Pending — Commits 1-3 have Reviewed-by tags (Krzysztof Kozlowski, Ekansh Gupta); commits 4-5 posted Oct 1, 2026, no review tags yet. None merged into mainline.
  4. PR present in qcom-next/topics: Partial - 1/5 commit(s) only have partial integration evidence
Verdict: ✅ — click to expand

🔍 Patch Validation

PR: #1256 - misc: fastrpc: fix ADSP duplicate session creation (5 commits)
Upstream commits: lore.kernel.org series (v5 3-patch + v1 2-patch)
Verdict: ✅ PASS


Summary by Commit

Commit 1/5: FROMLIST: misc: fastrpc: iterate CB nodes manually instead of of_platform_populate

Lore link: https://lore.kernel.org/all/20260923-dup-sessions-v5-1-e953133a1827@oss.qualcomm.com/

Check Status Note
Subject matches upstream ✅ Identical (FROMLIST prefix added)
Body preserves rationale ✅ Identical
Fixes tag present/correct N/A No Fixes tag in upstream or PR
Authorship preserved ✅ From: Vinayak Katoch matches lore; Signed-off-by present
Backport note N/A FROMLIST, not a backport

Diff comparison: ✅ PASS — Code changes identical; only line number context differs (PR: @@ -2395, lore: @@ -2333) due to tree state.

Upstream status: ⏳ Decision Pending — Reviewed-by: Krzysztof Kozlowski, Reviewed-by: Ekansh Gupta; no merge confirmation yet.

Integration presence: ✅ Present in qcom-next/topics (partial in qcom-next, full in topics).


Commit 2/5: FROMLIST: misc: fastrpc: move ADSP duplicate session creation to the driver

Lore link: https://lore.kernel.org/all/20260923-dup-sessions-v5-2-e953133a1827@oss.qualcomm.com/

Check Status Note
Subject matches upstream ✅ Identical (FROMLIST prefix added)
Body preserves rationale ✅ Identical
Fixes tag present/correct N/A No Fixes tag in upstream or PR
Authorship preserved ✅ From: Vinayak Katoch matches lore; Signed-off-by present
Backport note N/A FROMLIST, not a backport

Diff comparison: ✅ PASS — Code changes identical (verified FASTRPC_DUP_SESSIONS logic matches).

Upstream status: ⏳ Decision Pending — Reviewed-by: Krzysztof Kozlowski, Reviewed-by: Ekansh Gupta; no merge confirmation yet.

Integration presence: ✅ Present in qcom-next/topics (partial in qcom-next, full in topics).


Commit 3/5: FROMLIST: dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions

Lore link: https://lore.kernel.org/all/20260923-dup-sessions-v5-3-e953133a1827@oss.qualcomm.com/

Check Status Note
Subject matches upstream ✅ Identical (FROMLIST prefix added)
Body preserves rationale ✅ Identical
Fixes tag present/correct N/A No Fixes tag in upstream or PR
Authorship preserved ✅ From: Vinayak Katoch matches lore; Signed-off-by present
Backport note N/A FROMLIST, not a backport

Diff comparison: ✅ PASS — dt-binding deprecation change matches lore.

Upstream status: ⏳ Decision Pending — Reviewed-by: Krzysztof Kozlowski, Reviewed-by: Ekansh Gupta; no merge confirmation yet.

Integration presence: ✅ Present in topics (exact patch-id match at d0f45111b3cd17c7f7f35e71894e25e341d92f14).


Commit 4/5: FROMLIST: misc: fastrpc: fix NULL rpdev dereference when session alloc fails

Lore link: https://lore.kernel.org/all/20261001-fastrpc-probe-fixes-v1-1-1376d93b8b3e@oss.qualcomm.com/

Check Status Note
Subject matches upstream ✅ Identical (FROMLIST prefix added)
Body preserves rationale ✅ Identical
Fixes tag present/correct N/A No Fixes tag in upstream or PR
Authorship preserved ✅ From: Vinayak Katoch matches lore; Signed-off-by present
Backport note N/A FROMLIST, not a backport

Diff comparison: ✅ PASS — Code changes match lore patch.

Upstream status: ⏳ Decision Pending — No Reviewed-by/Acked-by tags yet; posted Oct 1, 2026.

Integration presence: ✅ Present in qcom-next (all checked added lines present).


Commit 5/5: FROMLIST: misc: fastrpc: fix init ordering race in rpmsg probe

Lore link: https://lore.kernel.org/all/20261001-fastrpc-probe-fixes-v1-2-1376d93b8b3e@oss.qualcomm.com/

Check Status Note
Subject matches upstream ✅ Identical (FROMLIST prefix added)
Body preserves rationale ✅ Identical
Fixes tag present/correct N/A No Fixes tag in upstream or PR
Authorship preserved ✅ From: Vinayak Katoch matches lore; Signed-off-by present
Backport note N/A FROMLIST, not a backport

Diff comparison: ✅ PASS — Code changes match lore patch.

Upstream status: ⏳ Decision Pending — No Reviewed-by/Acked-by tags yet; posted Oct 1, 2026.

Integration presence: ⚠️ Partial — Only partial integration evidence in both qcom-next and topics.


Issues

None. All commits faithfully represent their upstream lore sources.


Verdict

✅ PASS — Merge as-is.

All five commits are faithful FROMLIST representations of their upstream lore patches. Commit messages, authorship, and diff content match the lore sources. The FROMLIST prefix is correctly applied (patches posted to mailing list but not yet merged into mainline). Commits 1-3 have Reviewed-by tags from subsystem reviewers; commits 4-5 are newer (Oct 1) and under review. Four of five commits are already present in qcom-next or topics; commit 5/5 has partial integration evidence.


Final Summary

  1. Lore link present: Yes — all 5 commits have valid lore.kernel.org links in Link: trailers.
  2. Lore link matches PR commits: Yes — diff content, commit messages, and authorship are faithful to lore sources; only line number context differs due to tree state.
  3. Upstream patch status: ⏳ Decision Pending — Commits 1-3 have Reviewed-by tags (Krzysztof Kozlowski, Ekansh Gupta); commits 4-5 posted Oct 1, 2026, no review tags yet. None merged into mainline.
  4. PR present in qcom-next/topics: Partial — 4/5 commits present (commits 1-4 fully present in qcom-next or topics); commit 5/5 has partial integration evidence only.

Deterministic Integration Presence

Integration Presence Report

This report is generated by Jarvis before validate-patch runs.
It is the authoritative source for whether PR changes are already present
in qcom-next or in the kernel topic branches.

Kernel repo: /local/mnt/workspace/sgaud/Qgenie/image_pipeline/kernel
qcom-next ref: ba86f67908354f41f269ca1d64b22e4624766dcf
topics remote: topics -> https://github.com/qualcomm-linux/kernel-topics
topics fetch: fetched

Commit Subject qcom-next topics Final
1/5 [PATCH 1/5] FROMLIST: misc: fastrpc: iterate CB nodes manually partial - subject or partial tree evidence found, but full change was not verified present - all checked added lines are present present
2/5 [PATCH 2/5] FROMLIST: misc: fastrpc: move ADSP duplicate session partial - subject or partial tree evidence found, but full change was not verified present - all checked added lines are present present
3/5 [PATCH 3/5] FROMLIST: dt-bindings: misc: qcom,fastrpc: deprecate missing - no subject, patch-id, or full tree-content match found present - exact patch-id match at d0f45111b3cd17c7f7f35e71894e25e341d92f14 present
4/5 [PATCH 4/5] FROMLIST: misc: fastrpc: fix NULL rpdev dereference when present - all checked added lines are present skipped - not checked because qcom-next already contains the change present
5/5 [PATCH 5/5] FROMLIST: misc: fastrpc: fix init ordering race in rpmsg partial - subject or partial tree evidence found, but full change was not verified partial - subject or partial tree evidence found, but full change was not verified partial

Final Status

overall_status: PARTIAL
present_commits: 4/5
partial_commits: 1/5
missing_commits: 0/5
topics_checked_for_commits: 4/5
final_summary: PR present in qcom-next/topics: Partial - 1/5 commit(s) only have partial integration evidence

@qlijarvis

Copy link
Copy Markdown

PR #1256 — checker-log-analyzer

PR: #1256
Checker run: https://github.com/qualcomm-linux/kernel-config/actions/runs/37761337681

Checker Result Summary
Checker Result Summary
checkpatch ❌ 2 commits with COMMIT_LOG_LONG_LINE warnings
dt-binding-check ✅ Passed
dtb-check ⏭️ Skipped (no DTS changes)
sparse-check ✅ Passed
check-uapi-headers ✅ Passed
check-patch-compliance ❌ 3 commits with content mismatch
tag-check ✅ All commits have valid FROMLIST: prefix

Detailed report: Full report

Checker analysis — click to expand

🤖 CI Checker Analysis (checker-log-analyzer)

PR: #1256 - misc: fastrpc: iterate CB nodes manually + probe fixes
Source: https://github.com/qualcomm-linux/kernel-config/actions/runs/37761337681
Target branch: qcom-6.18.y

Checker Result Summary
checkpatch ❌ 2 commits with COMMIT_LOG_LONG_LINE warnings
dt-binding-check ✅ Passed
dtb-check ⏭️ Skipped (no DTS changes)
sparse-check ✅ Passed
check-uapi-headers ✅ Passed
check-patch-compliance ❌ 3 commits with content mismatch
tag-check ✅ All commits have valid FROMLIST: prefix

❌ checkpatch

Root cause: Commit messages contain crash log lines exceeding 75 characters.

Failure details:

Commit d6bfd8c ("FROMLIST: misc: fastrpc: fix NULL rpdev dereference when session alloc fails"):

WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
#19: 
  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000

Commit 1d07300 ("FROMLIST: misc: fastrpc: fix init ordering race in rpmsg probe"):

WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit description?)
#31: 
  Unable to handle kernel paging request at virtual address ffffcd5841510ca0

Analysis: Both warnings are triggered by kernel crash log lines embedded in the commit message body. These are false positives — kernel crash logs (oops messages, stack traces) are conventionally included verbatim in commit messages to document the exact failure being fixed. Wrapping them would reduce readability and deviate from kernel documentation conventions.

Fix: No action required. These are acceptable exceptions to the 75-char guideline.

Reproduce locally:

./scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES --git 37734126ee574665bdb74dc5bbcba78517ebf193..060b95a6b4205236cf005eb1e9eb6d80a9bc339d

❌ check-patch-compliance

Root cause: Three commits have content differences from their upstream lore.kernel.org links.

Failure details:

Checking commit: FROMLIST: misc: fastrpc: iterate CB nodes manually instead of of_platform_populate
Change is different from the one mentioned in Link

Checking commit: FROMLIST: misc: fastrpc: move ADSP duplicate session creation to the driver
Change is different from the one mentioned in Link

Checking commit: FROMLIST: misc: fastrpc: fix init ordering race in rpmsg probe
Change is different from the one mentioned in Link

Analysis: The checker detected differences between the PR commits and the upstream patches at the provided lore.kernel.org links. This can occur due to:

  1. Context-only differences — surrounding code differs between upstream and the target branch (qcom-6.18.y), causing line number shifts but no actual code change.
  2. Legitimate adaptations — the patch was modified to apply cleanly to qcom-6.18.y (e.g., resolving conflicts, adjusting for missing dependencies).
  3. Backport modifications — changes required for stable branch compatibility.

Recommended action:

  1. Verify the nature of the differences:

    # Fetch upstream patch for commit 1 (example)
    b4 am --single-message -C -l -3 https://lore.kernel.org/all/20260923-dup-sessions-v5-1-e953133a1827@oss.qualcomm.com/ -o /tmp/upstream1.mbx
    
    # Compare actual code changes (+ and - lines only)
    git format-patch -1 05d361ee3cba --stdout | awk '/^diff/,/^--$/' | grep -E '^[+-][^+-]' > /tmp/pr1.diff
    awk '/^diff/,/^--$/' /tmp/upstream1.mbx/*.mbx | grep -E '^[+-][^+-]' > /tmp/upstream1.diff
    diff /tmp/pr1.diff /tmp/upstream1.diff
  2. If differences are context-only (line numbers shifted but code identical) → no action needed; this is a checker limitation.

  3. If differences are legitimate adaptations → document them in the commit message:

    [ Upstream commit <sha> ]
    
    Adapted for qcom-6.18.y:
    - Adjusted context in fastrpc_rpmsg_probe() due to missing commit XYZ
    - Resolved conflict with vendor-specific session handling
    
  4. If differences are unintended → rebase on the correct upstream patch.

Reproduce locally:

# For each failing commit:
b4 am --single-message -C -l -3 <Link-URL> -o /tmp/out
git format-patch -1 <commit-sha> --stdout > /tmp/pr-commit.patch
# Manual diff comparison

Verdict

2 blockers to address before merge:

  1. check-patch-compliance content mismatches — Verify whether the differences from upstream are intentional adaptations for qcom-6.18.y. If so, document them in the commit messages. If not, rebase on the correct upstream patches.

  2. checkpatch warnings — These are false positives (kernel crash logs in commit messages) and do not require fixes. However, if the maintainer prefers, you can wrap the crash log lines at 75 chars, though this reduces readability.

All other checkers passed:

  • ✅ dt-binding-check: YAML schema validation passed
  • ✅ sparse-check: No static analysis warnings
  • ✅ check-uapi-headers: No ABI changes
  • ✅ tag-check: All commits correctly prefixed with FROMLIST:

Recommendation: Investigate the content mismatches in check-patch-compliance. If they are legitimate adaptations for the stable branch, document them clearly in the commit messages. The checkpatch warnings can be ignored as they are standard practice for including crash logs in commit messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants