-
Notifications
You must be signed in to change notification settings - Fork 149
zeroize: replace atomic_fence with optimization_barrier
#1252
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
Open
newpavlov
wants to merge
8
commits into
master
Choose a base branch
from
zeroize/observe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+106
−90
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35b5fab
zeroize: add `observe` function
newpavlov 3ac353e
add `proxy_alloc_observe_test`
newpavlov 75f4aa1
fix
newpavlov bf1eaf7
Replace `atomic_fence` with `observe`
newpavlov 4d90d4d
fix aaarch64
newpavlov 9e01370
Fix impl for `DefaultIsZeroes`
newpavlov f14749f
use the `MAX` associated constant for non-zero types
newpavlov 865e479
Rename `observe` to `optimization_barrier`
newpavlov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer the removal of volatile writes be done in a separate PR, so this PR does what it says on the label: replaces
atomic_fencewithoptimization_barrier.The removal of volatile writes removes the longstanding defense this crate has been built on in the past, and I think that much deserves to be in the commit message (and I would also prefer it be spelled out nicely, and not jammed in like "replace atomic_fence with optimization_barrier and removes volatile writes".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think we should probably leave the volatile writes in place unless we're using
asm!. Otherwise we're relying onblack_boxas the only line of defense.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Will do it tomorrow.
Well. AFAIK it works without issues on the mainline compiler. Yes, we don't have any hard guarantees for it, but, as we discussed above, it applies to the
asm!approach as well. IIRCblack_boxgets ignored on an alternative compiler (I forgot the name), but I don't think it supports the target arches in question in the first place and I am not sure how it handles volatile OPs.We could discuss potential hardening approaches for
black_box, but I would strongly prefer to concentrate onoptimization_barrierdoing what we want instead of piling different hacks on top of each other. In other words, I want for the snippet in this comment to be practice worthy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unacceptable for
black_boxto be the only line of defenseUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this is a gross overstatement of the situation. This PR does not notably make the codebase smaller. What it does do is delete a lot of the
SAFETYcomments that describe the strategy the library uses.Had you just changed
volatile_writeandvolatile_setto callptr::write_bytes, the PR itself could've included considerably fewer changes. They exist so there's a single consistent strategy used throughout the library, and as a place to document how that strategy works.Adding a little bit of compile-time gating to implement those functions in terms of either volatile or non-volatile depending on if an
asm!barrier is in-place is neither particularly complicated nor "piling different hacks on top of each other".It's a question of "we get the guarantee from a volatile write" vs "we get the guarantee from an
asm!optimization barrier" (which is, itself, perhaps overstating the situation).black_boxhas no guarantees. You would need to delete all the documentation that says this library has guarantees, and that's a change I don't want to make.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, we could look into ways to harden
black_box. For example, see here. We also could write:But, as expected, it results in a pretty atrocious codegen. We could improve it a bit by casting the reference to
[usize; N]if size allows, but the#[inline(never)]solution looks better to me. Finally, some of the leftover targets supportasm!on Nigthly, so we could add an unstable feature for them.