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

CPU feature detection may be racy #931

Open
briansmith opened this issue Jan 2, 2020 · 0 comments
Open

CPU feature detection may be racy #931

briansmith opened this issue Jan 2, 2020 · 0 comments
Assignees

Comments

@briansmith
Copy link
Owner

When cpu.rs was originally written, it used std::sync::Once. std::sync::Once explicitly guarantees "that any memory writes performed by the executed closure can be reliably observed by other threads at this point (there is a happens-before relation between the closure and code executing after the return)" and we relied on this to ensure that the writes to GFp_ia32cap_P and GFp_iarmcap_P are seen by all threads.

Later, cpu.rs was modified to use spin-rs directly instead of std::sync::Once However, spin-rs's Once does NOT provide the same guarantee in its documentation. (Neither does lazy_static!.) See https://mvdnes.github.io/rust-docs/spin-rs/spin/struct.Once.html#method.call_once.

I think that because x86 and x86-64 have a strong memory model, only the feature detection for other CPUs (currently ARM) may be racy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant