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

Avoid dropping TLS Key on sgx #103017

Merged
merged 1 commit into from
Oct 15, 2022
Merged

Conversation

raoulstrackx
Copy link
Contributor

#102655 reenabled dropping thread local Key on every platform (library/std/src/sys_common/thread_local_key.rs). That's causing problems at least for sgx.

cc: @jethrogb @ChrisDenton

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 13, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 13, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2022
@ChrisDenton
Copy link
Member

I apologise, I assumed from a comment in the code that only Windows would be affected but I really should have checked.

I wonder if a more principled approach would be to add a function to sys/{os}/thread_local_key? Something like:

// library/std/src/sys/sgx/thread_local_key.rs
#[inline(always)]
pub fn destroy_on_drop() -> bool {
    false
}

I.e. something similar to the now removed requires_synchronized_create.

@rust-log-analyzer

This comment has been minimized.

@joboet
Copy link
Member

joboet commented Oct 13, 2022

Sorry about this, I didn't check for this in the original PR. Also, how about clearing the destructor on key destruction. That would also solve the problem, if I understand correctly. Nevermind, that seems fine.

Could you share details on the problem?

@jethrogb
Copy link
Contributor

We're still investigating the issue, but the symptom is that the thread::local::dynamic_tests::hashmap test segfaults.

@jethrogb
Copy link
Contributor

Can we please merge this to get std tests passing again and then work on a permanent solution?

@joboet
Copy link
Member

joboet commented Oct 14, 2022

Does this really fix the test? Because that test does not even use thread_local_key::Key but rather (through some abstractions) thread_local_key::StaticKey, which did not change on SGX.

@raoulstrackx
Copy link
Contributor Author

Does this really fix the test? Because that test does not even use thread_local_key::Key but rather (through some abstractions) thread_local_key::StaticKey, which did not change on SGX.

Yes it does. I'm still investigating why destroying the key leads to issues.

@raoulstrackx
Copy link
Contributor Author

Found the main culprit! Data wasn't always kept in sync that caused StaticKey to return incorrect pointer values when the same key was used previously.

@ChrisDenton ChrisDenton assigned ChrisDenton and unassigned m-ou-se Oct 14, 2022
@ChrisDenton
Copy link
Member

LGTM

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 14, 2022

📌 Commit c46185b has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 14, 2022
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#102092 (refactor: use grep -E/-F instead of fgrep/egrep)
 - rust-lang#102781 (Improved documentation for `std::io::Error`)
 - rust-lang#103017 (Avoid dropping TLS Key on sgx)
 - rust-lang#103039 (checktools: fix comments)
 - rust-lang#103045 (Remove leading newlines from integer primitive doc examples)
 - rust-lang#103047 (Update browser-ui-test version to fix some flaky tests)
 - rust-lang#103054 (Clean up rust-logo rustdoc GUI test)
 - rust-lang#103059 (Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)`)
 - rust-lang#103067 (More alphabetical sorting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d47b755 into rust-lang:master Oct 15, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 15, 2022
@workingjubilee workingjubilee added the O-SGX Target: SGX label Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-SGX Target: SGX S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants