Re: RFC: userspace exception fixups

From: Sean Christopherson
Date: Fri Nov 02 2018 - 13:06:31 EST


On Fri, Nov 02, 2018 at 09:56:44AM -0700, Dave Hansen wrote:
> On 11/2/18 9:30 AM, Sean Christopherson wrote:
> > What if rather than having userspace register an address for fixup, the
> > kernel instead unconditionally does fixup on the ENCLU opcode?
>
> The problem is knowing what to do for the fixup. If we have a simple
> action to take that's universal, like backing up %RIP, or setting some
> other register state, it's not bad.

Isn't the EENTER/RESUME behavior universal? Or am I missing something?

> Think of our prefetch fixups in the page fault code. We do some
> instruction decoding to look for them, and then largely return from the
> fault and let the CPU retry. We know *exactly* what to do for these.
>
> But, if we need to call arbitrary code, or switch stacks, we need an
> explicit ABI around it *anyway*, because the action to take isn't clear.
>
> For an enclave exit that's because of a hardware interrupt or page
> fault, life is good. We really *could* just set %RIP to let ERESUME run
> again, kinda like we do for (some) syscall situations. But the
> situations for which we can't just call ERESUME, like the out-calls make
> this more challenging. I think we'd need some explicit new interfaces
> for those.

I don't see how out-calls are a problem. Once EEXIT completes we're
no longer in the enclave and EPCM faults are no longer a concern, i.e.
we don't need to do fixup. Every other enclave exit is either an
exception or an interrupt. And the only way to get back into the
enclave is via ENCLU (EENTER or ERESUME).