Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2401635imu; Fri, 14 Dec 2018 10:22:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/XnhZFyetNrDIFn1mQPeIvpO++XKFDN+EYzOrP+nm5uSD4DcAY96wLia+bKah5B1HPzceAA X-Received: by 2002:a63:fc49:: with SMTP id r9mr3517267pgk.209.1544811753520; Fri, 14 Dec 2018 10:22:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544811753; cv=none; d=google.com; s=arc-20160816; b=uXiJ7cqzz8MEfJeS/Leq2sJp804qFjLp240ptoZ6vZ1TjVNF4qwIPPZ/AfJgQGo0KW 1PDTZ+9K1JRS5X8wUXilNDE5ngbLeekkNHYE4C4wLjdvGLnDAaNbUEoD5rKFIGgvgh+x d8WN64h17k22OSRfEvacZfiq+35pI1J4/8S4OE15o09s3C1KIcvyeInKKQeyyxHH+07j UsAMs/CxdLlKz8RN2PRpx1J6ukJwfTmSW7YJobeJpbWDCLuWyT01z9JJcwjGUXzOBw5b vNWIXK/8OMgCmPqCUFO3KWaPNLYii2Pf6v91IL0NJb4M9FJ+jFW+VhUHhmkRae/GDq4/ cNwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Uh96gYAwV3hfCe0WgXdp3VF6zWSaryg5wm/RUWPi3VU=; b=iJZL9F74Nn7gjDohMdDOALjjkZduc/lnRas1AMoC4mtXEVUrKT4I+621iDBCFrSQcn Kp1zd0brHjzMYuR275/BzhBCOuS781XlHOhto55ntsw2pTOEyo98tRfyssJR9XaXgpCO kZG7bEegfcmsHUmbDQP1DUAiSbj6PjJ9Q5hl0wV6PxZeAlvFaIrFzJMMVFTTur/NpJDB Leb4r8RPxPl6+s3bXWN/mcHu3qoEP25XIeRLkMQagokY/EEk9v6AIqW5ceVtXwtC1jhK fBz/dBna/xLOAW1Nxyr6Jk93ZZQzXMuSOlFFUckJ4RQhQOjod1eQsodWI3ikQD13VMc/ ai5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13si4445686pgi.46.2018.12.14.10.22.09; Fri, 14 Dec 2018 10:22:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730447AbeLNSU5 (ORCPT + 99 others); Fri, 14 Dec 2018 13:20:57 -0500 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:60589 "EHLO relay9-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730264AbeLNSU5 (ORCPT ); Fri, 14 Dec 2018 13:20:57 -0500 X-Originating-IP: 134.134.139.75 Received: from localhost (jfdmzpr06-ext.jf.intel.com [134.134.139.75]) (Authenticated sender: josh@joshtriplett.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 16D4EFF80A; Fri, 14 Dec 2018 18:20:43 +0000 (UTC) Date: Fri, 14 Dec 2018 10:20:39 -0800 From: Josh Triplett To: Sean Christopherson Cc: Jethro Beekman , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "x86@kernel.org" , Dave Hansen , Peter Zijlstra , Jarkko Sakkinen , "H. Peter Anvin" , "linux-kernel@vger.kernel.org" , "linux-sgx@vger.kernel.org" , Andy Lutomirski , Haitao Huang , "Dr . Greg Wettstein" Subject: Re: [RFC PATCH v4 5/5] x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions Message-ID: <20181214182039.GA3883@localhost> References: <20181213213135.12913-1-sean.j.christopherson@intel.com> <20181213213135.12913-6-sean.j.christopherson@intel.com> <20181214151204.GA22063@linux.intel.com> <20181214153830.GB22063@linux.intel.com> <20181214170310.GC22063@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181214170310.GC22063@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 14, 2018 at 09:03:11AM -0800, Sean Christopherson wrote: > On Fri, Dec 14, 2018 at 07:38:30AM -0800, Sean Christopherson wrote: > > On Fri, Dec 14, 2018 at 07:12:04AM -0800, Sean Christopherson wrote: > > > On Fri, Dec 14, 2018 at 09:55:49AM +0000, Jethro Beekman wrote: > > > > On 2018-12-14 03:01, Sean Christopherson wrote: > > > > >+2: pop %rbx > > > > >+ pop %r12 > > > > >+ pop %r13 > > > > >+ pop %r14 > > > > >+ pop %r15 > > > > >+ pop %rbp > > > > >+ ret > > > > > > > > x86-64 ABI requires that you call CLD here (enclave may set it). > > > > > > Ugh. Technically MXCSR and the x87 CW also need to be preserved. > > > > > > What if rather than treating the enclave as hostile we require it to be > > > compliant with the x86-64 ABI like any other function? That would solve > > > the EFLAGS.DF, MXCSR and x87 issues without adding unnecessary overhead. > > > And we wouldn't have to save/restore R12-R15. It'd mean we couldn't use > > > the stack's red zone to hold @regs and @e, but that's poor form anyways. > > > > Grr, except the processor crushes R12-R15, FCW and MXCSR on asynchronous > > exits. But not EFLAGS.DF, that's real helpful. > > I can think of three options that are at least somewhat reasonable: > > 1) Save/restore MXCSR and FCW > > + 100% compliant with the x86-64 ABI > + Callable from any code > + Minimal documentation required > - Restoring MXCSR/FCW is likely unnecessary 99% of the time > - Slow > > 2) Clear EFLAGS.DF but not save/restore MXCSR and FCW > > + Mostly compliant with the x86-64 ABI > + Callable from any code that doesn't use SIMD registers > - Need to document deviations from x86-64 ABI > > 3) Require the caller to save/restore everything. > > + Fast > + Userspace can pass all GPRs to the enclave (minus EAX, RBX and RCX) > - Completely custom ABI > - For all intents and purposes must be called from an assembly wrapper > > > Option (3) actually isn't all that awful. RCX can be used to pass an > optional pointer to a 'struct sgx_enclave_exception' and we can still > return standard error codes, e.g. -EFAULT. Entering and exiting a syscall requires an assembly wrapper, and that doesn't seem completely unreasonable. It's an easy bit of inline assembly.