linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: linux-sgx@vger.kernel.org,
	Nathaniel McCallum <npmccallum@redhat.com>,
	Haitao Huang <haitao.huang@linux.intel.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Cedric Xing <cedric.xing@intel.com>
Subject: Re: [PATCH] x86/vdso: Flatten and clean up struct sgx_enclave_run
Date: Fri, 2 Oct 2020 06:20:24 +0300	[thread overview]
Message-ID: <20201002025218.GA30634@linux.intel.com> (raw)
In-Reply-To: <20201001225029.GJ7474@linux.intel.com>

On Thu, Oct 01, 2020 at 03:50:29PM -0700, Sean Christopherson wrote:
> On Fri, Oct 02, 2020 at 12:46:11AM +0300, Jarkko Sakkinen wrote:
> > On Thu, Oct 01, 2020 at 09:51:51AM -0700, Sean Christopherson wrote:
> > > > Remove 'exit_reason' as it is really a redundant field to save some space.
> > > > Instead, have just a field called 'leaf' that tells the last seen ENCLU.
> > > 
> > > This justification contradicts the removal of flags.  If you want to shave
> > > bytes, keep flags and enforce that flags is zero so that you don't need to
> > > have reserved bytes at the end of the struct.
> > > 
> > > IMO, having a separate exit reason provides saner code for userspace, e.g. 
> > > 
> > >   if (run->exit_reason == SGX_EXCEPTION_EXIT)
> > > 	<do exception stuff>
> > > 
> > > versus
> > > 
> > >   if (run->leaf == EENTER || run->leaf == ERESUME)
> > >         <do exception stuff>
> > > 
> > > I would prefer to be explicit about why the vDSO is transferring control to
> > > the caller or its handler.  It also gives us line of sight to supporting
> > > exit types other than EEXIT and exceptions.  Maybe we never end up with
> > > another type, but IMO shaving 4 bytes and a MOV isn't worth the risk of
> > > ending up with a mess of an API if another exit reason comes along.
> > 
> > 'exit_reason' is just waste of expensive memory space that we have
> > limited fixed amount of.
> 
> Huh?  4 bytes on the user stack can't possibly be a real concern, the default
> stack size on x86-64 is 8MB.  Golang shaves that down to 2kb but dynamically
> adjusts the stack as needed.  The "allocation" is completely free, the caller
> will already be adjusting RSP to create space for the struct, and it doesn't
> need to be initialized.

It's unnecessary in the space that is chosen for the run structure. 64
bytes takes only one cacheline and the padding is also fast to validate
to contain only zeros (check three qwords).

Maybe I'm just weird but I'd just store all the leafs numbers in the
field that is designated to store leaf numbers.

> > Using the same field in a *guaranteed*
> > non-conflicting manner saves space. There is absolutely no question
> > that what I did should not be done.
> 
> But you can't guarantee that it doesn't conflict with future changes to the
> SGX architecture.  Hell, you can't even guarantee that it doesn't conflict
> with the current SGX architecture, e.g. see Jethro's request to invoke the
> handler on AEX's due to interrupts.

Reserved space can be used for any sort of new fields as long as the
whole structure is validated, including the padding. With or without
'flags' this should be always done.

Then there is no issue to add a new field after the merge. And thus,
there is no issue resolving [*], even if the 'flags' is not added
right now. You don't simply add stuff that is useless before it gets
used. You ensure that your data is in stable state. That's all one
hould do.

[*] https://lore.kernel.org/linux-sgx/0f88f6d7-fa2d-59b0-c90f-4aa9e04d0af5@fortanix.com/

/Jarkko

  reply	other threads:[~2020-10-02  3:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 16:16 [PATCH] x86/vdso: Flatten and clean up struct sgx_enclave_run Jarkko Sakkinen
2020-10-01 16:51 ` Sean Christopherson
2020-10-01 21:46   ` Jarkko Sakkinen
2020-10-01 22:50     ` Sean Christopherson
2020-10-02  3:20       ` Jarkko Sakkinen [this message]
2020-10-02  4:25     ` Jarkko Sakkinen
2020-10-02 14:27       ` Jarkko Sakkinen
2020-10-02 15:49         ` Jarkko Sakkinen

Reply instructions:

You may reply publicly 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=20201002025218.GA30634@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=cedric.xing@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=haitao.huang@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=npmccallum@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).