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

core/thread: "fix" valgrind errors in thread_measure_stack_free() #20726

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

maribu
Copy link
Member

@maribu maribu commented Jun 4, 2024

Contribution description

The dark magic used used in thread_measure_stack_free() is frowned upon by valgrind. E.g. valgrind may deduce (by monitoring the stack pointer) that a specific value was at some point allocated on the stack, but has gone out of scope. When that value is now read again to estimate stack
usage, it does look a lot like someone passed a pointer to a stack allocated value, and that pointer is referenced after that value has gone out of scope.

This is "fixed" by temporarily disabling valgrind error reporting while iterating over the stack.

Testing procedure

Testing that this indeed "fixes" the warning

With this PR:

 make BOARD=native64 all-valgrind -C tests/core/thread_basic && valgrind tests/core/thread_basic/bin/native64/tests_thread_basic.elf
[...]
==2283== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

With #20723 (with current master the function is broken and doesn't iterate over the stack - hence, no errors):

[...]
==2742== ERROR SUMMARY: 34 errors from 1 contexts (suppressed: 0 from 0)

(That one context is thread_measure_stack_free().)

Confirming that suppression is reasonable

Double check my reasoning why, in this specific instance, the access of stack memory is not an error.

Issues/PRs references

Depends upon and includes:

@maribu maribu added the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 4, 2024
@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: core Area: RIOT kernel. Handle PRs marked with this with care! labels Jun 4, 2024
core/thread.c Outdated Show resolved Hide resolved
@benpicco benpicco removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 5, 2024
The dark magic used used in thread_measure_stack_free() is frowned upon
by valgrind. E.g. valgrind may deduce (by monitoring the stack pointer)
that a specific value was at some point allocated on the stack, but has
gone out of scope. When that value is now read again to estimate stack
usage, it does look a lot like someone passed a pointer to a stack
allocated value, and that pointer is referenced after that value has
gone out of scope.

This is "fixed" by temporarily disabling valgrind error reporting while
iterating over the stack.
@maribu maribu force-pushed the core/thread/valgrind-disable branch from e1d61ae to 11e273c Compare June 5, 2024 12:32
@github-actions github-actions bot removed the Area: tests Area: tests and testing framework label Jun 5, 2024
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 5, 2024
@riot-ci
Copy link

riot-ci commented Jun 5, 2024

Murdock results

✔️ PASSED

11e273c core/thread: "fix" valgrind erros in thread_measure_stack_free()

Success Failures Total Runtime
10161 0 10161 17m:20s

Artifacts

@benpicco benpicco added this pull request to the merge queue Jun 5, 2024
Merged via the queue into RIOT-OS:master with commit 54cd524 Jun 5, 2024
27 checks passed
@maribu maribu deleted the core/thread/valgrind-disable branch June 5, 2024 16:44
@maribu
Copy link
Member Author

maribu commented Jun 5, 2024

Thx :)

@mguetschow mguetschow added this to the Release 2024.07 milestone Jun 11, 2024
@maribu maribu changed the title core/thread: "fix" valgrind erros in thread_measure_stack_free() core/thread: "fix" valgrind errors in thread_measure_stack_free() Jul 26, 2024
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! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants