Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2034852ybh; Fri, 13 Mar 2020 11:46:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuGM1t3iMpI95Wq1xO3v88M1n9OgGeS69Cgkqy1S8D/v1DN5ImBQQjy0DIA3gKhggOqQJO+ X-Received: by 2002:a9d:b89:: with SMTP id 9mr12535558oth.297.1584125198207; Fri, 13 Mar 2020 11:46:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584125198; cv=none; d=google.com; s=arc-20160816; b=YWHl8AtiGVz9iJRb5F3xZJHZ5LjEbunYGVLoVmQ96r/Agurc/cuxIPQxCO5XPdnetK bVqSXo4AG4C5BiKrT1MeyBkDsQwe0i5535nS2LkctcvSuVlI7PANI6BOJnfOZobBd5vq rjOzY6rXMocixPHAEQodVA18r3KTVuUm+awoH/GjfLQTWNj6srZtFmtOoSqCS91zGfvn eKiGqQrqvis0US6Unfffz4yo89bha7y07GaFo1PqPFgm6b5xNaSnEzvhP93KPy2eo2ay nCTZvHLdCAPtJyVV2Iw9G8K2lZwbcFnDDLYitlBXZyt9JvJab/A+mYnkd6uHa7k4EF3a 2Ohw== 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=LJnewOGSt6LSbXS2uPLkW5rainm7ti1O1StTNu8InoA=; b=NyTBrS5xUnKkZf4AFTTX7OpljsIFPQgQPoc6K6R2vzbtA7/XJTyWFDepiPGHNcBkZF /4JftRXshkiG3E3tt6o2/ehiSJS1FrM5VTxNHv90WNlD5ogAJ2eTpA8tdMgt77U9NnFE TaS5Q9K3hga+n5Sz+mPrbBrLqW0Yh9xIEpmcvvdTezhEHL1WMAbYhkoVAiZjtBQ63WgY iC6AyfAnBmNb3N6IpagN8uCMiFhyhJ68+xIejwaBUAso5U5bSxh+D0RJ9Sx5kDmzRR8k IMvx4ikhu93SaB51iCUj5F+tQ6EdHFionK0nBg6GYct4FbBlxc4SIAtbrbMO2pX+6Gzs 6uNg== 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 y17si5049596oto.70.2020.03.13.11.46.25; Fri, 13 Mar 2020 11:46:38 -0700 (PDT) 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 S1726757AbgCMSoz (ORCPT + 99 others); Fri, 13 Mar 2020 14:44:55 -0400 Received: from mga11.intel.com ([192.55.52.93]:5934 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726666AbgCMSoz (ORCPT ); Fri, 13 Mar 2020 14:44:55 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Mar 2020 11:44:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,549,1574150400"; d="scan'208";a="442509038" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga005.fm.intel.com with ESMTP; 13 Mar 2020 11:44:53 -0700 Date: Fri, 13 Mar 2020 11:44:52 -0700 From: Sean Christopherson To: Nathaniel McCallum Cc: Jethro Beekman , Jarkko Sakkinen , linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org, akpm@linux-foundation.org, dave.hansen@intel.com, Neil Horman , "Huang, Haitao" , andriy.shevchenko@linux.intel.com, tglx@linutronix.de, "Svahn, Kai" , bp@alien8.de, Josh Triplett , luto@kernel.org, kai.huang@intel.com, David Rientjes , cedric.xing@intel.com, Patrick Uiterwijk , Andy Lutomirski , Connor Kuehl , Harald Hoyer , Lily Sturmann Subject: Re: [PATCH v28 21/22] x86/vdso: Implement a vDSO for Intel SGX enclave call Message-ID: <20200313184452.GD5181@linux.intel.com> References: <20200303233609.713348-1-jarkko.sakkinen@linux.intel.com> <20200303233609.713348-22-jarkko.sakkinen@linux.intel.com> <254f1e35-4302-e55f-c00d-0f91d9503498@fortanix.com> <20200313164622.GC5181@linux.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 On Fri, Mar 13, 2020 at 02:32:29PM -0400, Nathaniel McCallum wrote: > On Fri, Mar 13, 2020 at 12:46 PM Sean Christopherson > wrote: > > > > On Fri, Mar 13, 2020 at 11:48:54AM -0400, Nathaniel McCallum wrote: > > > Therefore, I'd like to propose that __vdso_sgx_enter_enclave(): > > > * Preserve %rbx. > > > > At first glance, that looks sane. Being able to call __vdso... from C > > would certainly be nice. > > Agreed. I think ergonomically we want __vdso...() to be called from C > and the handler to be implemented in asm (optionally); without > breaking the ability to call __vdso..() from asm in special cases. > > I think all ergonomic issues get solved by the following: > * Pass a void * into the handler from C through __vdso...(). > * Allow the handler to pop parameters off of the output stack without hacks. > > This allows the handler to pop extra arguments off the stack and write > them into the memory at the void *. Then the handler can be very small > and pass logic back to the caller of __vdso...(). > > Here's what this all means for the enclave. For maximum usability, the > enclave should preserve all callee-saved registers (except %rbx, which > is preserved by __vdso..()). For each ABI rule that the enclave > breaks, you need logic in a handler to fix it. So if you push return > params on the stack, the handler needs to undo that. Or the untrusted runtime needs to wrap the __vdso() to save state that is clobbered by the enclave. Just want to make it crystal clear that using a handler is only required for stack shenanigans. > This doesn't compromise the ability to treat __vsdo...() like ENCLU if > you need the full power. But it does make it significantly easier to > consume when you don't have special needs. So as I see it, __vdso...() > should: > > 1. preserve %rbx > 2. take leaf in %rcx > 3. gain a void* stack param which is passed to the handler Unless I'm misunderstanding the request, this already exists. %rsp at the time of EEXIT is passed to the handler. > 4. sub/add to %rsp rather than save/restore Can you elaborate on why you want to sub/add to %rsp instead of having the enclave unwind the stack? Preserving %rsp across EEXIT/ERESUME seems more in line with function call semantics, which I assume is desirable? E.g. push param3 push param2 push param1 enclu[EEXIT] add $0x18, %rsp > That would make this a very usable and fast interface without > sacrificing any of its current power.