Skip to content

Fix RP2040 task lock acquire ordering#1440

Open
Old-Ding wants to merge 1 commit into
FreeRTOS:mainfrom
Old-Ding:fix-rp2040-task-lock-acquire-barrier
Open

Fix RP2040 task lock acquire ordering#1440
Old-Ding wants to merge 1 commit into
FreeRTOS:mainfrom
Old-Ding:fix-rp2040-task-lock-acquire-barrier

Conversation

@Old-Ding

Copy link
Copy Markdown

Description

Fixes #1430.

vPortRecursiveLock() used spin_try_lock_unsafe() for the uncontended RP2040 task/ISR lock path, then immediately read lock-protected bookkeeping. The blocking path already gets acquire ordering from spin_lock_unsafe_blocking(), but the successful try-lock path did not.

This adds an acquire fence only on the try-lock success path. The contended path is left unchanged so it does not receive a duplicate fence.

Test Steps

  • Inspected the RP2040 lock flow in portable/ThirdParty/GCC/RP2040/include/portmacro.h.
  • Compared against pico-sdk spin_lock_unsafe_blocking() / spin_try_lock_unsafe() definitions to confirm only the try-lock fast path lacks acquire ordering.
  • Ran git diff HEAD~1 HEAD --check.
  • Verified the modified file uses CRLF line endings.

Not run: RP2040 hardware build/runtime test; the local Windows environment does not have cmake or arm-none-eabi-gcc installed.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1430

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Old-Ding Old-Ding marked this pull request as ready for review June 29, 2026 16:56
@Old-Ding Old-Ding force-pushed the fix-rp2040-task-lock-acquire-barrier branch from 84e705e to dbbe30e Compare July 2, 2026 03:43
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@Old-Ding

Old-Ding commented Jul 4, 2026

Copy link
Copy Markdown
Author

Follow-up verification:

  • The acquire fence is intentionally on the successful spin_try_lock_unsafe() fast path only. The blocking path already gets acquire ordering from spin_lock_unsafe_blocking(), so this avoids adding a duplicate barrier there.
  • This matches the root cause described in [BUG] RP2040: task-lock fast path missing acquire barrier #1430: the fast path became the lock owner before reading lock-protected bookkeeping, but had no acquire edge.
  • git diff --check origin/main...HEAD passes on the branch.

I still do not have an RP2040 hardware/build environment available locally, so this remains source-level and memory-ordering validation rather than a board runtime test.

@Old-Ding

Old-Ding commented Jul 7, 2026

Copy link
Copy Markdown
Author

Maintainer ping: SonarCloud is green, the branch is mergeable, and this is scoped to the RP2040 task lock acquire ordering. Could this be routed for kernel/port review when possible?

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.

[BUG] RP2040: task-lock fast path missing acquire barrier

2 participants