Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1224707imu; Tue, 11 Dec 2018 15:13:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2Cd+1D7egFZWDXW6DILYjTEqKbyAtOH1FB3bj5qbdtabm/uP7QlFRm/aiRBY2nP9p8Lx2 X-Received: by 2002:a17:902:720c:: with SMTP id ba12mr17881484plb.79.1544570006738; Tue, 11 Dec 2018 15:13:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544570006; cv=none; d=google.com; s=arc-20160816; b=weqQsQ4CxRUDH5LGmh9ukoPi1CX00l7xEsb9tibw4t1C4JgKsPMX2x7kJi7cJLQ6sM ARp+2VYfwyy1kA6jUzJcp7d2PS5nwuVJDbiIwb1kjcoAm3jZCt6zo2k4+DH5xmQVVGS2 t2qriyQcYF1NJue0LvjtexrddShZfdboF8GfQsP9Zn3jg/bFiRPZr1BuqhbnQzxPrnc+ +7xBP6RDnbJ9y14M4TfUfEn3JqADhOKb4UIGBR+WYq2UXySeF+XQzSkrHDbTi3TXoZna vgwIhcp7W7MbOG2H5EYltEVIMfJ7ysZRxcSF8zxlPlIGvp0DBfDmpKoB+nKdQxAl5qse pc2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+i6NRK/aAXVC64rYDN2GRqSWpISvBQmVeA1LcFsPvAA=; b=WlYBl/fQSvaHkW4+6T9Tg28e6JWPSfSTFWzfZVSY6lMR7b2gg9tv5PVZDyiTzQPFJp dNixgS7lRG762qbCcGm95kGgFHSB0iC4bdwetBwnpwqk2KS87S9fYGYJWkhraTZlHwUX jNg4wm7ZSlJJCoyHoU5onBQUpJnXFgVm1WUOfWWUCNJ0SFLLcEebjW5LGuP38Ha2qdJP FAYhHdAWYDwVnK9hv5fHr2U8EeI6taLD8jAjb3aqHRjyHTnKU6OA3LZtgZHdiP+JDPBt l3DXTAVevmGqHK2jaCVlZQ3gaEEDsa2Ho1SCyTXMw/I2f/t5cjs3IQWOLv4MI4vngquT HAmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/ia8ae+"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si13237613pgl.471.2018.12.11.15.13.11; Tue, 11 Dec 2018 15:13:26 -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=@kernel.org header.s=default header.b="g/ia8ae+"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726235AbeLKXLI (ORCPT + 99 others); Tue, 11 Dec 2018 18:11:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:50084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726209AbeLKXLH (ORCPT ); Tue, 11 Dec 2018 18:11:07 -0500 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 409E52146D for ; Tue, 11 Dec 2018 23:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544569866; bh=QfNb33dE6va6caV5f1TR23O3lZh+zahl+vG3UOH7V9s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=g/ia8ae+wO15vu/vn7fvujUhArEszq5r/E91roSHC2z/Joyi/JN+p0YxCHV9R4nvt d4DRc9mkl4Xf80Xt582JC8gcN+C6OlFI2cNVPYwqSpWpx5llZiHd9s+/7ORl+iyFAK Y7+eUtiKYzdo1J6ov7vYpbsgE5auNocFcpFZ6uqE= Received: by mail-wr1-f47.google.com with SMTP id x10so15782890wrs.8 for ; Tue, 11 Dec 2018 15:11:06 -0800 (PST) X-Gm-Message-State: AA+aEWZ6qDwFnvkVqJVlZrWm600XYuu5ddI45bzYwVbtL5Wqzq1iEn/t buTpPueGP8ImkPZNKmkRnZHPVbaYhOeScfVcV7MGBg== X-Received: by 2002:adf:8323:: with SMTP id 32mr14522736wrd.176.1544569864592; Tue, 11 Dec 2018 15:11:04 -0800 (PST) MIME-Version: 1.0 References: <20181210232141.5425-1-sean.j.christopherson@intel.com> <20181210232449.GA11843@localhost> <20181211165253.GB14731@linux.intel.com> <20181211222312.GI14731@linux.intel.com> In-Reply-To: <20181211222312.GI14731@linux.intel.com> From: Andy Lutomirski Date: Tue, 11 Dec 2018 15:10:52 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v3 0/4] x86: Add exception fixup for SGX ENCLU To: "Christopherson, Sean J" Cc: Andrew Lutomirski , Josh Triplett , Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , Jarkko Sakkinen , Dave Hansen , Peter Zijlstra , "H. Peter Anvin" , LKML , linux-sgx@vger.kernel.org, Haitao Huang , Jethro Beekman , "Dr. Greg Wettstein" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 2:23 PM Sean Christopherson wrote: > > On Tue, Dec 11, 2018 at 09:58:19AM -0800, Andy Lutomirski wrote: > > > On Dec 11, 2018, at 8:52 AM, Sean Christopherson wrote: > > > > > >> On Tue, Dec 11, 2018 at 07:41:27AM -0800, Andy Lutomirski wrote: > > >> > > >> > > >>>> On Dec 10, 2018, at 3:24 PM, Josh Triplett wrote: > > >>>> > > >>>> On Mon, Dec 10, 2018 at 03:21:37PM -0800, Sean Christopherson wrote: > > >>>> At that point I realized it's a hell of a lot easier to simply provide > > >>>> an IOCTL via /dev/sgx that allows userspace to register a per-process > > >>>> ENCLU exception handler. At a high level, the basic idea is the same > > >>>> as the vDSO approach: provide a hardcoded fixup handler for ENCLU and > > >>>> attempt to fixup select unhandled exceptions that occurred in user code. > > >>> > > >>> So, on the one hand, this is *absolutely* much cleaner than the VDSO > > >>> approach. On the other hand, this is global process state and has some > > >>> of the same problems as a signal handler as a result. > > >> > > >> I liked the old version better for this reason > > > > > > This isn't fundamentally different than forcing all EENTER calls through > > > the vDSO, which is also per-process. Technically this is more flexible > > > in that regard since userspace gets to choose where their one ENCLU gets > > > to reside. Userspace can have per-enclave entry flows so long as the > > > actual ENLU[EENTER] is common, same as vDSO. > > > > Right. The problem is that user libraries have a remarkably hard time > > agreeing on where their one copy of anything lives. > > Are you concerned about userspace shooting themselves in the foot, e.g. > unknowingly overwriting their handler? Requiring unregister->register > to change the handler would mitigate that issue for the most part. Or > we could even say it's a write-once property. > > That obviously doesn't solve the issue of a userspace application > deliberately using two different libraries to run enclaves in a single > process, but I have a hard time envisioning a scenario where someone > would want to use two different *SGX* libraries in a single process. > Don't most of the signal issue arise due to loading multiple libraries > that provide *different* services needing to handle signals? I can easily imagine two SGX libraries that know nothing about each other running in the same process. One or both could be PKCS#11 modules, for example. I suspect that Linux will eventually want the ability for libraries to register exception handlers, but that's not going to get designed and implemented quickly enough for SGX's initial Linux rollout. A vDSO helper like in your earlier series should solve most of the problem without any contention issues.