Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp785575imu; Fri, 7 Dec 2018 08:52:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/VDbaRGOGIjfBSgBwqn9shLKyBaBHZnU24OMveygUHqcnHJhFOqXrvjxls0H26XhCzwGoSK X-Received: by 2002:a62:e30d:: with SMTP id g13mr2928185pfh.151.1544201562346; Fri, 07 Dec 2018 08:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544201562; cv=none; d=google.com; s=arc-20160816; b=hk+YDxsTI0htXwcDJu5aqm5aCAUGliJ4vvlpFkjfxw0Y2PrJV7YLMAwjLbLsrlA5HQ yBbHCpeWX3oWRbsgQ/QHuj4M9owwI33u6KS2lA/CMlaTcP77PyITVqIAkFjPElhgvBCC KWaw3T6sbWopULj8dp8DQnKoblbs3/VdC4ZvrjmseYAJnEZivmfIcvnvwcEH1ZXDYIAy /k5U1xFrGmAl0a5Wizfprd30+4LNmNLoyUu6trvOBiCLoXwteNhUHjcQQE5uyFcTr3m6 fx3bAljEyk1DXDrdFyHpY7NveFSwjvuOJcIyL7AwAuDTzb7JuxevTloSpBNTQiCVhRVM u4Sw== 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=oU6gXC29UgsSyQp1H4IpQqsxVYRrIK7vObCneOLAE6M=; b=Vd32ZrrBb+f/r9pPljwdkzq9Vuvs6B1Emg5Mpin8ab5pv/bc7QSppGxyWj1l+HzIz+ V3K/hSbaW08qUV7j+ulBt3WimaJMX5OAAnefwGUtXnjbca25mVlyTtyBreGsbbA0tIla mRP8saeQU06zsp31N+UumERU7Ier+cIlDIcNzITbChhLCp6M0i2z7m8+y7cEhJ2i7pvs K4gk3uDosD1EOAGxcnJQz8EY83lThHDJ0syzfXpE4KxWiismTUFern0Wj5jpYRoTuy8n qyGGLM9zU6/U7ZA0M5unFs2T1B1SdBmhPt7jVXHvWxFPmedYChoKiTwl+DZh4NjTJGT/ OndA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k2si3252256pgh.63.2018.12.07.08.52.27; Fri, 07 Dec 2018 08:52:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbeLGQvr (ORCPT + 99 others); Fri, 7 Dec 2018 11:51:47 -0500 Received: from mga02.intel.com ([134.134.136.20]:8825 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbeLGQvq (ORCPT ); Fri, 7 Dec 2018 11:51:46 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2018 08:51:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,326,1539673200"; d="scan'208";a="96986161" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by orsmga007.jf.intel.com with ESMTP; 07 Dec 2018 08:51:45 -0800 Date: Fri, 7 Dec 2018 08:51:45 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , X86 ML , Dave Hansen , Peter Zijlstra , "H. Peter Anvin" , LKML , Jarkko Sakkinen , Josh Triplett , linux-sgx@vger.kernel.org, Haitao Huang , Jethro Beekman , "Dr. Greg" Subject: Re: [RFC PATCH v2 4/4] x86/vdso: Add __vdso_sgx_enter_enclave() to wrap SGX enclave transitions Message-ID: <20181207165145.GB10404@linux.intel.com> References: <20181206221922.31012-1-sean.j.christopherson@intel.com> <20181206221922.31012-5-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Cc: linux-sgx, Haitao, Greg and Jethro My apologies for neglecting to cc the SGX folks, original thread is here: https://lkml.kernel.org/r/20181206221922.31012-1-sean.j.christopherson@intel.com On Thu, Dec 06, 2018 at 02:50:01PM -0800, Andy Lutomirski wrote: > On Thu, Dec 6, 2018 at 2:19 PM Sean Christopherson > wrote: > > > + > > + /* > > + * Invoke the caller's exit handler if one was provided. The return > > + * value tells us whether to re-enter the enclave (EENTER or ERESUME) > > + * or to return (EEXIT). > > + */ > > + if (exit_handler) { > > + leaf = exit_handler(exit_info, tcs, priv); > > + if (leaf == SGX_EENTER || leaf == SGX_ERESUME) > > + goto enter_enclave; > > + if (leaf == SGX_EEXIT) > > + return 0; > > + return -EINVAL; > > + } else if (leaf != SGX_EEXIT) { > > + return -EFAULT; > > + } > > This still seems overcomplicated to me. How about letting the > requested leaf (EENTER or ERESUME) be a parameter to the function and > then just returning here? As it stands, you're requiring any ERESUME > that gets issued (other than the implicit ones) to be issued in the > same call stack, which is very awkward if you're doing something like > forwarding the fault to a different task over a socket and then > waiting in epoll_wait() or similar before resuming the enclave. Ah, yeah, wasn't thinking about usage models where the enclave could get passed off to a different thread. What about supporting both, i.e. keep the exit handler but make it 100% optional? And simplify the exit_handler to effectively return a boolean, i.e. "exit or continue". Something like this: notrace long __vdso_sgx_enter_enclave(u32 op, void *tcs, void *priv, struct sgx_enclave_exit_info *exit_info, sgx_enclave_exit_handler *exit_handler) { u64 rdi, rsi, rdx; u32 leaf; long ret; if (!tcs || !exit_info) return -EINVAL; enter_enclave: if (op != SGX_EENTER && op != SGX_ERESUME) return -EINVAL; /* * Invoke the caller's exit handler if one was provided. The return * value tells us whether to re-enter the enclave (EENTER or ERESUME) * or to return (EEXIT). */ if (exit_handler) { if (exit_handler(exit_info, tcs, priv)) { op = exit_info->leaf; goto enter_enclave; } } if (exit_info->leaf == SGX_EEXIT) return -EFAULT; return 0; } I like that the exit handler allows userspace to trap/panic with the full call stack in place, and in a dedicated path, i.e. outside of the basic enter/exit code. An exit handler probably doesn't fundamentally change what userspace can do with respect to debugging/reporting, but I think it would actually simplify some userspace implementations, e.g. I'd use it in my tests like so: long fault_handler(struct sgx_enclave_exit_info *exit_info, void *tcs, void *priv) { if (exit_info->leaf == SGX_EEXIT) return 0; }