Skip to content

Fix threading edge cases on Apple and Zephyr, document async poll locking - #12157

Merged
philljj merged 3 commits into
wolfSSL:masterfrom
julek-wolfssl:fenrir-concurrency-fixes
Nov 24, 2026
Merged

philljj merged 3 commits into
wolfSSL:masterfrom
julek-wolfssl:fenrir-concurrency-fixes

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member
  • Apple: wolfSSL_CondSignal no longer drops and re-takes cond->mutex around dispatch_semaphore_signal. Failure of either step could return with the mutex not held, which broke the CondStart/CondEnd contract. The signal never blocks, so releasing the mutex is unnecessary (F-11183).
  • Zephyr: wolfSSL_NewThread and wolfSSL_JoinThread each read the global wolfsslThreadHeapHint separately, so a change between the two could free the thread struct and stack to the wrong heap. The hint is now read once and stored in THREAD_TYPE. The stack size check in mem_track.h gets the same treatment (F-15097).
  • Async: documents that the event queue poll holds queue->lock across the device poll (QAT, Nitrox and the software backend), and that the crypto callback poll follows the same model. The lock is intentional because it serializes the poll callbacks of one queue, so the locking is unchanged and the docs now state the rule a handler must follow (F-12216).

wolfSSL_CondSignal dropped and re-took cond->mutex around
dispatch_semaphore_signal. A failure of either step returned with the
mutex not held, breaking the CondStart/CondEnd contract. The signal
never blocks so there is no need to release the mutex.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 14:20
@julek-wolfssl julek-wolfssl self-assigned this Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the threading fixes and async callback locking documentation.

No open issues 🎉

What changed in this PR

This PR fixes Apple and Zephyr threading edge cases in wolfSSL’s portability layer and documents existing async callback locking requirements.

Changes:

  • Keep the Apple condition-variable mutex held while signaling.
  • Capture the Zephyr heap hint once so thread allocations and cleanup use the same heap.
  • Document async poll callback restrictions in headers and English/Japanese API documentation, without changing locking behavior.
File Description
wolfssl/​wolfcrypt/​types.h Store the allocation heap in Zephyr’s thread structure.
wolfssl/​wolfcrypt/​mem_track.h Reuse one heap hint throughout Zephyr stack-size checks.
wolfssl/​wolfcrypt/​cryptocb.h Document that async poll callbacks run with the queue lock held.
wolfcrypt/​src/​wc_port.c Preserve Zephyr heap pairing and Apple mutex ownership during signaling.
doc/​dox_comments/​header_files/​cryptocb.h Explain async callback locking restrictions in English.
doc/​dox_comments/​header_files-ja/​cryptocb.h Add equivalent locking guidance in Japanese.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,800 B (+4.9%, 296,380 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@yosuke-wolfssl yosuke-wolfssl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JA doc is clear and easy to understand for me.

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #12157

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files-ja/cryptocb.h, doc/dox_comments/header_files/cryptocb.h
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@philljj philljj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feedback given offline

@philljj philljj assigned julek-wolfssl and unassigned wolfSSL-Bot Nov 24, 2026
The event queue poll has always held queue->lock across the device
poll, for QAT, Nitrox and the software backend. The crypto callback
poll follows the same model. Holding the lock is intended: it serializes
the poll callbacks of one queue. State the rule a handler has to follow
instead of changing the locking.
wolfSSL_NewThread and wolfSSL_JoinThread both read the global
wolfsslThreadHeapHint. Changing it between the two frees memory to the
wrong heap. The hint is meant to be set once at startup, so state that
instead of supporting a change.
@julek-wolfssl
julek-wolfssl force-pushed the fenrir-concurrency-fixes branch from 25a231b to 8a96986 Compare November 24, 2026 09:47
@julek-wolfssl

Copy link
Copy Markdown
Member Author

@philljj addressed

@philljj

philljj commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

(single PRB subtest hiccup)

@philljj
philljj merged commit d31d625 into wolfSSL:master Nov 24, 2026
459 of 461 checks passed
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.

6 participants