Skip to content

Conversation

@raeburn
Copy link
Member

@raeburn raeburn commented Nov 21, 2025

We borrow code from the kernel tree for our user-mode builds to support using the same (kernel) APIs everywhere. However, the kernel builds using -fno-strict-aliasing, even in its tools/ subdirectory, and that affects how optimization may alter the code's behavior, as some kernel code may not perform correctly without it. We don't currently use that option when building programs in user mode.

We've observed that the READ_ONCE and WRITE_ONCE macros borrowed from $kernel/tools/ (the version defined for internal testing only) are not safe when applied to pointer objects in some cases due to aliasing issues. So far we've noticed no issues that would affect end users, but this isn't the only code we've borrowed from the kernel. It's better to be safe and disable such optimizations like the kernel does.

We borrow code from the kernel tree for our user-mode builds to
support using the same (kernel) APIs everywhere. However, the kernel
builds using -fno-strict-aliasing, even in its tools/ subdirectory,
and that affects how optimization may alter the code's behavior, as
some kernel code may not perform correctly without it. We don't
currently use that option when building programs in user mode.

We've observed that the READ_ONCE and WRITE_ONCE macros borrowed from
$kernel/tools/ (the version defined for internal testing only) are not
safe when applied to pointer objects in some cases due to aliasing
issues. So far we've noticed no issues that would affect end users,
but this isn't the only code we've borrowed from the kernel. It's
better to be safe and disable such optimizations like the kernel does.
@raeburn
Copy link
Member Author

raeburn commented Nov 21, 2025

This is an alternative to the approach in PR #342

Copy link
Member

@lorelei-sakai lorelei-sakai left a comment

Choose a reason for hiding this comment

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

Generally seems reasonable, but this change affects more than just the user build. Is that significant enough to call out?

@raeburn raeburn merged commit fa45c66 into dm-vdo:main Nov 22, 2025
6 checks passed
@raeburn raeburn deleted the rwonce2 branch November 22, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants