-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Process termination test for SGX #70416
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
Conversation
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. |
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 |
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.
Why are you not using timeout 10s cargo run
?
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 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:
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 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() {} |
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.
So there's technically a race here where the channel receiver might wake up before accept is called...
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.
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.
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.
Maybe you can do thread::yield_now
a bunch after recv
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 the println!
is sufficient, but thread::yield_now
maybe more readable.
@@ -0,0 +1,8 @@ | |||
-include ../../run-make-fulldeps/tools.mk | |||
|
|||
# only-sgx |
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 discussed, I think this should run on all platforms?
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.
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?
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 we should just add ignore
statements for platforms that have special requirements. Everything that can just run with cargo run
should get tested.
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. |
OK, let me know when y'all feel this is ready for review. |
LGTM |
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) |
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.
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?
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.
Yes, exactly. The failure case would be the program not exiting and hanging indefinitely due to listener.accept()
.
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.
Sure but the timeout
is not needed in the success case, right? So then it's not needed ;)
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.
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.
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 an ordinary run-pass test would be better, personally, run-make tests are kind of a pain.
Ping from Triage: Hi @mzohreva, any updates? |
Related issues: - fortanix/rust-sgx#109
sorry for the delay, I rebased and restructured the test according to our previous discussion. It is now in |
@bors r+ rollup Thanks! |
📌 Commit db1fbd4 has been approved by |
Process termination test for SGX The issue is described in fortanix/rust-sgx#109 cc @jethrogb
Process termination test for SGX The issue is described in fortanix/rust-sgx#109 cc @jethrogb
@bors r+ |
📌 Commit 2e749a5 has been approved by |
⌛ Testing commit 2e749a5 with merge 26604521fcbc365ab54a3966a4cd0254d6de7a0f... |
💔 Test failed - checks-azure |
The failure seems unrelated to the PR. It failed during an LLVM build |
@bors retry |
⌛ Testing commit 2e749a5 with merge 4249dae4d0c22b8ef962ef97829c6c315a31d3a3... |
💔 Test failed - checks-actions |
fn main() { | ||
let (tx, rx) = mpsc::channel(); | ||
thread::spawn(move || { | ||
let listen = TcpListener::bind("0:0").unwrap(); |
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.
Should probably specify 0.0.0.0:0
here
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.
Thanks, fixed
@bors r+ |
📌 Commit 2b3adc9 has been approved by |
☀️ Test successful - checks-actions, checks-azure |
The issue is described in fortanix/rust-sgx#109
cc @jethrogb