Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix thread return with local message queue #17502

Merged
merged 2 commits into from
Jan 15, 2022

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Jan 11, 2022

Contribution description

When a message queue is configured from the stack, that main function
must never return -- otherwise, during sched_task_exit (which the
thread's function "returns" to), message senders might still send
messages into already freed stack space (which would be reused by
sched_task_exit).

[new] A follow-up commit adds a line on this to the msg_init_queue documentation.

Most occurrences of queue initialization throughout RIOT are either static or followed by an endless loop without breaks / returns; the few examples not matching either pattern are fixed here.

Testing procedure

I don't see any way to make the fixed behavior actually happen; this is more about best practice. (Especially given that sched_task_exit currently starts with a debug statement followed by irq_disable, so the message would need to hit right into the execution of debug printing).

The two altered tesets that don't depend on hardware can be and were successfully run (in tests/thread_msg_block_w_queue and tests/posix_semaphore) on native.

Issues/PRs references

This came up when nailing down the safety criteria of msg_init_queue in Rust.

[edit: see [new]]

@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Jan 11, 2022
@chrysn chrysn added Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed Area: tests Area: tests and testing framework labels Jan 11, 2022
@github-actions github-actions bot added Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: tests Area: tests and testing framework labels Jan 11, 2022
@chrysn chrysn added Process: needs >1 ACK Integration Process: This PR requires more than one ACK Area: doc Area: Documentation labels Jan 11, 2022
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Looks good to me. I think the arrays could be static, couldn't they?

(I'm aware it is style and subjective, but a blank line before a function makes it IMO easier to spot where the function starts. Feel free to ignore, if you disagree.)

tests/driver_nrf24l01p_lowlevel/main.c Outdated Show resolved Hide resolved
tests/posix_semaphore/main.c Outdated Show resolved Hide resolved
tests/posix_semaphore/main.c Outdated Show resolved Hide resolved
tests/posix_semaphore/main.c Outdated Show resolved Hide resolved
tests/thread_msg_block_w_queue/main.c Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the Area: doc Area: Documentation label Jan 11, 2022
@chrysn
Copy link
Member Author

chrysn commented Jan 11, 2022

Yes they can be static, and probably should (not that it'd matter a lot in the test applications); going with your newlines as well.

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

ACK. The change is unscary enough to go in without testing. Please squash :)

chrysn and others added 2 commits January 11, 2022 21:51
When a message queue is configured from the stack, that main function
must never return -- otherwise, during sched_task_exit (which the
thread's function "returns" to), message senders might still send
messages into already freed stack space (which would be reused by
sched_task_exit).

Co-authored-by: Marian Buschsieweke <maribu@users.noreply.github.com>
@chrysn chrysn added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 12, 2022
@maribu maribu removed the Process: needs >1 ACK Integration Process: This PR requires more than one ACK label Jan 13, 2022
@maribu
Copy link
Member

maribu commented Jan 13, 2022

No need for a second ACK IMO. If you insist on a 2nd ACK, speak up now.

@chrysn chrysn merged commit 95b5052 into RIOT-OS:master Jan 15, 2022
@chrysn chrysn deleted the queue-on-stack-never-quit branch January 15, 2022 22:26
@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants