Linux-Sgx Archive on lore.kernel.org
 help / color / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: [PATCH for_v23 4/5] x86/vdso: sgx: Reorder params to callback to improve readability
Date: Thu, 10 Oct 2019 17:40:58 -0700
Message-ID: <20191011004059.28581-5-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191011004059.28581-1-sean.j.christopherson@intel.com>

Swap @ret and @ursp in the callback prototype so that the output from
the vDSO itself, @ret and @e, are grouped together.  Having the first
N parameters all share a type also makes the prototype easier to parse
by (some) humans.  And, passing @ursp via register saves one whole
MOV instruction!

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/entry/vdso/vsgx_enter_enclave.S | 16 +++++++---------
 arch/x86/include/uapi/asm/sgx.h          | 10 +++++-----
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/arch/x86/entry/vdso/vsgx_enter_enclave.S b/arch/x86/entry/vdso/vsgx_enter_enclave.S
index 3dd22780b7ef..94f613b53b13 100644
--- a/arch/x86/entry/vdso/vsgx_enter_enclave.S
+++ b/arch/x86/entry/vdso/vsgx_enter_enclave.S
@@ -134,23 +134,21 @@ ENTRY(__vdso_sgx_enter_enclave)
 	jmp	.Lhandle_exit
 
 .Linvoke_userspace_handler:
+	/* Pass the untrusted RSP (at exit) to the callback via %rcx. */
+	mov	%rsp, %rcx
+
 	/*
-	 * Align stack per x86_64 ABI. Save the original %rsp in %rbx to be
-	 * restored after the callback returns.  Note, %rsp needs to be 16-byte
-	 * aligned _after_ pushing the three parameters on the stack.
+	 * Align stack per x86_64 ABI. Note, %rsp needs to be 16-byte aligned
+	 * _after_ pushing the three parameters on the stack.
 	 */
-	mov	%rsp, %rbx
 	and	$-0x10, %rsp
 	sub	$0x8, %rsp
 
-	/* Push @e, u_rsp and @tcs as parameters to the callback. */
+	/* Push @e, the "return" value and @tcs as params to the callback. */
 	push	0x18(%rbp)
-	push	%rbx
+	push	%rax
 	push	0x10(%rbp)
 
-	/* Pass the "return" value to the callback via %rcx. */
-	mov	%eax, %ecx
-
 	/* Clear RFLAGS.DF per x86_64 ABI */
 	cld
 
diff --git a/arch/x86/include/uapi/asm/sgx.h b/arch/x86/include/uapi/asm/sgx.h
index 255392f5054f..95f69f938b58 100644
--- a/arch/x86/include/uapi/asm/sgx.h
+++ b/arch/x86/include/uapi/asm/sgx.h
@@ -88,16 +88,16 @@ struct sgx_enclave_exception {
  * @rdi:	RDI at the time of enclave exit
  * @rsi:	RSI at the time of enclave exit
  * @rdx:	RDX at the time of enclave exit
- * @ret:	0 on success (EEXIT), -EFAULT on an exception
+ * @ursp:	RSP at the time of enclave exit (untrusted stack)
  * @r8:		R8 at the time of enclave exit
  * @r9:		R9 at the time of enclave exit
  * @tcs:	Thread Control Structure used to enter enclave
- * @ursp:	RSP at the time of enclave exit
+ * @ret:	0 on success (EEXIT), -EFAULT on an exception
  * @e:		Pointer to struct sgx_enclave_exception (as provided by caller)
  */
-typedef int (*sgx_enclave_exit_handler_t)(long rdi, long rsi, long rdx, int ret,
-					  long r8, long r9, void *tcs,
-					  long ursp,
+typedef int (*sgx_enclave_exit_handler_t)(long rdi, long rsi, long rdx,
+					  long ursp, long r8, long r9,
+					  void *tcs, int ret,
 					  struct sgx_enclave_exception *e);
 
 #endif /* _UAPI_ASM_X86_SGX_H */
-- 
2.22.0


  parent reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11  0:40 [PATCH for_v23 0/5] x86/vdso: sgx: Bug fixes Sean Christopherson
2019-10-11  0:40 ` [PATCH for_v23 1/5] x86/vdso: sgx: Fix misaligned stack bug when invoking exit handler Sean Christopherson
2019-10-11  0:40 ` [PATCH for_v23 2/5] selftests/x86/sgx: Add check to verify exit handler stack alignment Sean Christopherson
2019-10-14 21:09   ` Jarkko Sakkinen
2019-10-14 21:14     ` Jarkko Sakkinen
2019-10-11  0:40 ` [PATCH for_v23 3/5] x86/vdso: sgx: Fix unwinder support Sean Christopherson
2019-10-16 22:25   ` Xing, Cedric
2019-10-11  0:40 ` Sean Christopherson [this message]
2019-10-16 22:24   ` [PATCH for_v23 4/5] x86/vdso: sgx: Reorder params to callback to improve readability Xing, Cedric
2019-10-16 23:06     ` Sean Christopherson
2019-10-11  0:40 ` [PATCH for_v23 5/5] selftests/x86/sgx: Update the callbacks function parameters Sean Christopherson
2019-10-14 21:27 ` [PATCH for_v23 0/5] x86/vdso: sgx: Bug fixes Jarkko Sakkinen

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191011004059.28581-5-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Sgx Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sgx/0 linux-sgx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sgx linux-sgx/ https://lore.kernel.org/linux-sgx \
		linux-sgx@vger.kernel.org
	public-inbox-index linux-sgx

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sgx


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git