sgx-lkl
sgx-lkl copied to clipboard
SGX-LKL sometimes doesn't terminate with multiple app threads
When running a multi-threaded application using OpenMP, SGX-LKL doesn't terminate cleanly and blocks. To reproduce, run the OpenMP sample application. When running it with make run-sw
, it freezes as follows:
[ 0.054180] EXT4-fs (vda): mounted filesystem with ordered data mode. Opts:
[ SGX-LKL ] Set working directory: /
[ SGX-LKL ] Calling app main: app/openmp-test
Running with following number of threads: 8
Hello from thread: 5
Hello from thread: 3
Hello from thread: 2
Hello from thread: 6
Hello from thread: 4
Hello from thread: 7
Hello from thread: 0
Hello from thread: 1
42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42
42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42
42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42
42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42
[ 0.066855] EXT4-fs (vda): re-mounted. Opts: (null)
[ 0.066937] reboot: Restarting system
[ SGX-LKL ] vio_enclave_process_host_event: [ dev_id = 0 ] exit
[ SGX-LKL ] vio_enclave_process_host_event: [ dev_id = 1 ] exit
[ SGX-LKL ] vio_enclave_process_host_event: [ dev_id = 2 ] exit
[ SGX-LKL ] sgxlkl_ethread_init done. ethread_id=3 result=0 (OE_OK)
After the main thread has terminated, we set the lthread scheduler exit flag, so all other threads should also stop. The fact that this is not happening suggests that control is not passed to the scheduler anymore. (Since SGX-LKL doesn't have pre-emptive scheduling, it cannot force an lthread/ethread to exit the enclave if it is inside of a busy loop.)