Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2300573imu; Tue, 6 Nov 2018 12:14:16 -0800 (PST) X-Google-Smtp-Source: AJdET5dDUlABeW34QRrWxkiws4P46SL40P+AfesBXYecAiC5T+n27pfa2hdy2fSdW46dcLPnQtyB X-Received: by 2002:aa7:818a:: with SMTP id g10-v6mr5507446pfi.153.1541535256640; Tue, 06 Nov 2018 12:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541535256; cv=none; d=google.com; s=arc-20160816; b=rcbJkjBdL3VzEhFOSBup0X01HE89aJVxWve3fIECscTbZ0y6nwMmoOtDgPelnHkzWW 8dfWslgvWrDNu/sXKxr4iWGsaFXegaHBnYoCA8xPMmmUApMNBOBLKEYD3hRjJG7txHn2 URvqZLuFnhoUDtgcLwuADTRud3Uya6wycTvZCGRXt9ZayPMyO3N4FCgRjo5UvtNQThxC M0A8FmvCddZ/GvyrfDxw/8rqkwzCCsjWCC5UZVuOucJ0yZTs9+rFpl+NIId3F1S2SlIo qPEuetEPvC2Zlbmxi/yucDYZwr4fNbQbLRk8ryv2ZMvWLLJahZsnWxVEGfQoKHRNC32q /M4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=p/2YV/foJ7fESOKT5qFmLLlt78/aH5zyuVRwSgAdvlk=; b=yDl846G7fBnm3i9JShuvy2sr8kAMyAlHmEugrQD4Jt7nIC0BqtQ9uFS6FpCtJ0qXmx oyzV7vFYEv5D+4UJEcCFvnBMNB0EVoiVpHz9ljzut3CYEJSqZFr4/D+PY/hr+ENBYpcA Yi31Ghn3b+hU9GBdANGilT8L9DOGupt7ACTxyKa7XnAPcAyPb3UFCPUEVNSFK6Ok4dEG /CeobOpyIS4KtodMXvPPMN7XKpbxN6hsHEGTkHbnUThad5OOf8cMoGnkDF4KJgxEYaPt XO0VQjPpbWb0ktbMsm9bY0z5sUV85p9aOkoLSWcUDz0iy+H1lWwK8RhB0nGj4TGLmhH3 hKOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b="feX3s/kL"; 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 z61-v6si231777plb.46.2018.11.06.12.13.59; Tue, 06 Nov 2018 12:14:16 -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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b="feX3s/kL"; 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 S1727410AbeKGFjQ (ORCPT + 99 others); Wed, 7 Nov 2018 00:39:16 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44988 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725958AbeKGFjP (ORCPT ); Wed, 7 Nov 2018 00:39:15 -0500 Received: by mail-pg1-f193.google.com with SMTP id w3-v6so6284260pgs.11 for ; Tue, 06 Nov 2018 12:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=p/2YV/foJ7fESOKT5qFmLLlt78/aH5zyuVRwSgAdvlk=; b=feX3s/kLE5r1AviZTfPOnUJ29usFK2vHonU0AhCF7MoRz0nRET5Io2hCVd+zqhi6ch sRunlmrEObF9xWqgK7DUqUE8HM9Gb4unVhTSDYU1AQqVWglAw1UKenxmbZ2Few416rIA iFRXC+uV03UkxEnFa+7G4sYwRvxcfR6WwJvdH8Ba8rrADK8cn7HV10BL5foQQu1ZOAzF NUjt3qNnKQnt/2M/1qRJslJOB6kMgvM2akC6TZaPb7QmSVVyB9JKreIllJ0yj8L6srUJ iHbbtebby0+80VQ9aC2tBFa5/vIxBSVZZHd+izkjWFJzSlRc/cYNcUY7W64yHikbpnkX qj9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=p/2YV/foJ7fESOKT5qFmLLlt78/aH5zyuVRwSgAdvlk=; b=nr8Y4e0Ezju420ZvRQT0D5+zDP5XnXY00pgoTvDMcAVfPA+9Pp5IGvEg5tsmSd7ccl ahWlsls7oIK/3VhYk755aG2AtclCoAbsahc2HHf+kN5xuLKDMFbfeDVBESL1RG2o1GxQ BmIvBkL1L8nbKUHc2SwQgprGI7eXPSq2pHqMuRKhokoNzgU2VCWhlw1D2LWIXGFWAzp1 qUL6ePW++pEYC++qcEcufw2jTTl+CbFJfy13gEPa4c9kUk8odVChlAjFxjVpeQxFYLMB 16QM/junSnzdRgp7ybsQiyzpbIWhzSa0SMKsOuuItFCCWrpOpAQoCRMzaRwHp4PvkZY/ MgJQ== X-Gm-Message-State: AGRZ1gJwJnu1eW18F+h+bgwEQd2Cu+MAbKg+B+FqeoknX3xv/Ssh5lJX 0a8M7O92fWODf09KqZQyRi9M2w== X-Received: by 2002:a62:cac4:: with SMTP id y65-v6mr27554542pfk.27.1541535139712; Tue, 06 Nov 2018 12:12:19 -0800 (PST) Received: from ?IPv6:2601:646:c200:7429:4032:437d:ec46:1726? ([2601:646:c200:7429:4032:437d:ec46:1726]) by smtp.gmail.com with ESMTPSA id v191sm27343115pgb.77.2018.11.06.12.12.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 12:12:18 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: RFC: userspace exception fixups From: Andy Lutomirski X-Mailer: iPhone Mail (16A404) In-Reply-To: Date: Tue, 6 Nov 2018 12:12:17 -0800 Cc: Andy Lutomirski , "Christopherson, Sean J" , Jann Horn , Linus Torvalds , Rich Felker , Dave Hansen , Jethro Beekman , Jarkko Sakkinen , Florian Weimer , Linux API , X86 ML , linux-arch , LKML , Peter Zijlstra , nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, linux-sgx@vger.kernel.org, Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Carlos O'Donell , adhemerval.zanella@linaro.org Content-Transfer-Encoding: quoted-printable Message-Id: <1C426267-492F-4AE7-8BE8-C7FE278531F9@amacapital.net> References: <20181102163034.GB7393@linux.intel.com> <7050972d-a874-dc08-3214-93e81181da60@intel.com> <20181102170627.GD7393@linux.intel.com> <20181102173350.GF7393@linux.intel.com> <20181102182712.GG7393@linux.intel.com> <20181102220437.GI7393@linux.intel.com> <1541518670.7839.31.camel@intel.com> <1541524750.7839.51.camel@intel.com> <22596E35-F5D1-4935-86AB-B510DCA0FABE@amacapital.net> To: Dave Hansen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Nov 6, 2018, at 11:22 AM, Dave Hansen wrote: >=20 >> On 11/6/18 11:02 AM, Andy Lutomirski wrote: >>> On Tue, Nov 6, 2018 at 10:41 AM Dave Hansen wrot= e: >>>=20 >>>> On 11/6/18 10:20 AM, Andy Lutomirski wrote: >>>> I almost feel like the right solution is to call into SGX on its own >>>> private stack or maybe even its own private address space. >>>=20 >>> Yeah, I had the same gut feeling. Couldn't the debugger even treat the >>> enclave like its own "thread" with its own stack and its own set of >>> registers and context? That seems like a much more workable model than >>> trying to weave it together with the EENTER context. >>=20 >> So maybe the API should be, roughly >>=20 >> sgx_exit_reason_t sgx_enter_enclave(pointer_to_enclave, struct >> host_state *state); >> sgx_exit_reason_t sgx_resume_enclave(same args); >>=20 >> where host_state is something like: >>=20 >> struct host_state { >> unsigned long bp, sp, ax, bx, cx, dx, si, di; >> }; >>=20 >> and the values in host_state explicitly have nothing to do with the >> actual host registers. So, if you want to use the outcall mechanism, >> you'd allocate some memory, point sp to that memory, call >> sgx_enter_enclave(), and then read that memory to do the outcall. >=20 > Ah, so instead of the enclave rudely "hijacking" the EENTER context, we > have it nicely return and nicely _hint_ to the calling context what it > would like to do. Then, the EENTER context can make a controlled > transition over to the requested context. Exactly. And existing enclaves keep working =E2=80=94 their rudeness is just= magically translated into a hint! >=20 >> Actually implementing this would be distinctly nontrivial, and would >> almost certainly need some degree of kernel help to avoid an explosion >> when a signal gets delivered while we have host_state.sp loaded into >> the actual SP register. Maybe rseq could help with this? >=20 > As long as the memory pointed to by host_state.sp is valid and can hold > the signal frame (grows down without clobbering anything), what goes > boom? The signal handling would push a signal frame and call the > handler. It would have a shallow-looking stack, but the handler could > just do its normal business and return from the signal where the frame > would get popped and continue with %rsp=3Dhost_state.sp, blissfully > unaware of the signal ever having happened. True, but what if we have a nasty enclave that writes to memory just below S= P *before* decrementing SP? I suspect that rseq really can be used for this with only minimal-ish modifi= cations. Or we could stick this in the vDSO with some appropriate fixups in= the kernel.=