On Tue, Mar 3, 2020 at 6:39 PM Jarkko Sakkinen jarkko.sakkinen@linux.intel.com wrote:
diff --git a/tools/testing/selftests/x86/sgx/sgx_call.S b/tools/testing/selftests/x86/sgx/sgx_call.S new file mode 100644 index 000000000000..ca4c7893f9d9 --- /dev/null +++ b/tools/testing/selftests/x86/sgx/sgx_call.S @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ +/** +* Copyright(c) 2016-18 Intel Corporation. +*/
.text
.macro ENCLU
.byte 0x0f, 0x01, 0xd7
.endm
.text
.global sgx_call_eenter
+sgx_call_eenter:
push %rbx
mov $0x02, %rax
mov %rdx, %rbx
lea sgx_async_exit(%rip), %rcx
+sgx_async_exit:
ENCLU
pop %rbx
ret
You need to push and pop all the callee-saved registers here since the enclave zeros them. This code works today by accident. A future compiler may emit different register allocation which will cause this to break.
We might consider making it part of the Linux enclave ABI that the enclave has to save and restore these registers. This would have a slight performance advantage in a critical code-path compared to zeroing and then restoring them. But the VDSO code will need to know what the expectation is.