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

Process termination test for SGX #70416

Merged
merged 4 commits into from May 13, 2020
Merged

Process termination test for SGX #70416

merged 4 commits into from May 13, 2020

Conversation

mzohreva
Copy link
Contributor

The issue is described in fortanix/rust-sgx#109

cc @jethrogb

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 26, 2020
@nikomatsakis
Copy link
Contributor

I have no particular problem adding this test to the rust repo, but I'm curious if the Rust repo is the best place for it, since it seems more like a bug in https://github.com/fortanix/rust-sgx/.

(I'm not sure how things are setup or exactly what the role of the rust-sgx project is, to be clear.)

all:
$(RUSTC) accept.rs --target x86_64-fortanix-unknown-sgx
$(FTXSGX_ELF2SGXS) $(TMPDIR)/accept --heap-size 0x1001000 --stack-size 0x20000 --threads 10
timeout 10s $(FTXSGX_RUNNER) $(TMPDIR)/accept.sgxs
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you not using timeout 10s cargo run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at the other tests in run-make and they almost all use rustc directly with some machinery in run-make-fulldeps/tools.mk. The 2 exceptions using cargo that I found looked hacky:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think those hacks (i.e. setting RUSTC_BOOTSTRAP=1) may be removed, as I don't see any nightly features set in Cargo.toml

thread::spawn(move || {
let listen = TcpListener::bind("0:0").unwrap();
tx.send(()).unwrap();
while let Ok(_) = listen.accept() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

So there's technically a race here where the channel receiver might wake up before accept is called...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but I think there is no reasonable way to avoid that race: we need one thread to be blocked on some I/O and another thread to cause process exit. While the first thread is blocked on I/O it cannot notify the other thread (by definition), and the second thread does not have a way of knowing the first thread is truly blocked on I/O on its own unless we are willing to check /proc/self/task/*/stat or something similar.

I think we can reasonably expect that the main thread does not exit before the spawned thread blocks on accept() in most cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can do thread::yield_now a bunch after recv

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the println! is sufficient, but thread::yield_now maybe more readable.

@@ -0,0 +1,8 @@
-include ../../run-make-fulldeps/tools.mk

# only-sgx
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, I think this should run on all platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some platforms may need a platform-specific way of running the code (see wasm-* or thumb-* tests in run-make for example), do you want to have platform-specific code here to run the test for those?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just add ignore statements for platforms that have special requirements. Everything that can just run with cargo run should get tested.

@mzohreva
Copy link
Contributor Author

It is true that there is a bug in rust-sgx at the moment, but it is possible to inadvertently create a bug in rust itself w.r.t this test. We think it is better to include this test here, so we can catch both kinds.

@nikomatsakis
Copy link
Contributor

OK, let me know when y'all feel this is ready for review.

@jethrogb
Copy link
Contributor

jethrogb commented Apr 1, 2020

LGTM

@mzohreva
Copy link
Contributor Author

mzohreva commented Apr 1, 2020

I squashed the commits, it's ready for review

cp -a $(HERE)/$(CRATE) $(WORK_DIR)/$(CRATE)
cd $(WORK_DIR)/$(CRATE) && \
$(CARGO) build --target $(TARGET) --verbose && \
timeout 10s $(CARGO) run --target $(TARGET)
Copy link
Contributor

Choose a reason for hiding this comment

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

So why exactly does this need to be a run-make test -- is it this timeout 10s call? i.e., why can't we just make this a normal run-pass test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. The failure case would be the program not exiting and hanging indefinitely due to listener.accept().

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure but the timeout is not needed in the success case, right? So then it's not needed ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

run-pass tests will eventually timeout too, though I don't know how long it takes. Or maybe they don't, but instead just print some warnings and things.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think an ordinary run-pass test would be better, personally, run-make tests are kind of a pain.

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2020
@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2020
@joelpalmer
Copy link

Ping from Triage: Hi @mzohreva, any updates?

@mzohreva
Copy link
Contributor Author

sorry for the delay, I rebased and restructured the test according to our previous discussion. It is now in src/test/ui/process-termination. I also added another test which is in the same category (and has already found a bug in our rust-sgx implementation)

@nikomatsakis
Copy link
Contributor

@bors r+ rollup

Thanks!

@bors
Copy link
Contributor

bors commented Apr 28, 2020

📌 Commit db1fbd4 has been approved by nikomatsakis

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 28, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 28, 2020
Process termination test for SGX

The issue is described in fortanix/rust-sgx#109

cc @jethrogb
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 28, 2020
Process termination test for SGX

The issue is described in fortanix/rust-sgx#109

cc @jethrogb
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 2, 2020
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 4, 2020

📌 Commit 2e749a5 has been approved by nikomatsakis

@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 May 4, 2020
@bors
Copy link
Contributor

bors commented May 5, 2020

⌛ Testing commit 2e749a5 with merge 26604521fcbc365ab54a3966a4cd0254d6de7a0f...

@bors
Copy link
Contributor

bors commented May 5, 2020

💔 Test failed - checks-azure

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 5, 2020
@mzohreva
Copy link
Contributor Author

mzohreva commented May 5, 2020

The failure seems unrelated to the PR. It failed during an LLVM build

@nikomatsakis
Copy link
Contributor

@bors retry

@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 May 6, 2020
@bors
Copy link
Contributor

bors commented May 7, 2020

⌛ Testing commit 2e749a5 with merge 4249dae4d0c22b8ef962ef97829c6c315a31d3a3...

@bors
Copy link
Contributor

bors commented May 7, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 7, 2020
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let listen = TcpListener::bind("0:0").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably specify 0.0.0.0:0 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 11, 2020

📌 Commit 2b3adc9 has been approved by nikomatsakis

@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 May 11, 2020
@bors
Copy link
Contributor

bors commented May 13, 2020

⌛ Testing commit 2b3adc9 with merge a2e0b48...

@bors
Copy link
Contributor

bors commented May 13, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: nikomatsakis
Pushing a2e0b48 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 13, 2020
@bors bors merged commit a2e0b48 into rust-lang:master May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants