Skip to content

subsys/logging: Add compiler barriers to msg stack allocation #46967

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/zephyr/logging/log_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ enum z_log_msg_mode {
Z_LOG_MSG2_ALIGNMENT), \
sizeof(uint32_t))

/*
* With Zephyr SDK 0.14.2, aarch64-zephyr-elf-gcc (10.3.0) fails to ensure $sp
* is below the active memory during message construction. As a result,
* interrupts happening in the middle of that process can end up smashing active
* data and causing a logging fault. Work around this by inserting a compiler
* barrier after the allocation and before any use to make sure GCC moves the
* stack pointer soon enough
*/

#define Z_LOG_ARM64_VLA_PROTECT() compiler_barrier()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since its only for arm64 what about:
#define Z_LOG_ARM64_VLA_PROTECT() IF_ENABLED(CONFIG_ARM64, (copiler_barrier()))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought #46986 was on arm32? Even if not, I still wonder if this is a problem in general GCC code or is specific to arm64?

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to #46967 (comment) it's not related and still reproduces after adding the barrier. If we suspect that it's affecting more platforms than im ok with keeping it for all platforms but then maybe remove ARM64 from the name and only mention in the comment that it has been seen on arm64 and other platforms may be affected as well.


#define Z_LOG_MSG2_STACK_CREATE(_cstr_cnt, _domain_id, _source, _level, _data, _dlen, ...) \
do { \
int _plen; \
Expand All @@ -211,6 +222,7 @@ do { \
} \
struct log_msg *_msg; \
Z_LOG_MSG2_ON_STACK_ALLOC(_msg, Z_LOG_MSG2_LEN(_plen, 0)); \
Z_LOG_ARM64_VLA_PROTECT(); \
if (_plen) { \
CBPRINTF_STATIC_PACKAGE(_msg->data, _plen, \
_plen, Z_LOG_MSG2_ALIGN_OFFSET, flags, \
Expand Down