Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp396666pxu; Tue, 6 Oct 2020 08:58:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWb2JcH9qHKUrGI42tYTaLXMmq2d+U1OkDpDDtYxkHmsrAbu0BPVg9lv/WT2tL4n1gDmlO X-Received: by 2002:a17:906:f112:: with SMTP id gv18mr191451ejb.180.1601999924649; Tue, 06 Oct 2020 08:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601999924; cv=none; d=google.com; s=arc-20160816; b=X5p2dAal5v6J44bhoYG2Njq0SCGgZPsp4VgexKXTCEW086uy6NASXF00qV5mcxhCst wiglWS2OGB96YB8VGi0rs2wXpRl57zGMYlpm8z11AYrZJ9keeyxAnQnZGCYwJi0X8I3p 0dwnI61R34HkD+4ErwAXGFTFGnpvg+q+HE5MYX3hiwCQkGHCy/MKcnwPFdWbszv9mm6a sjlU6TXGfIfJujDKuZM8/hKl0Pkikrkts8xeSthP+mDo8/0C0Wp3nDdUySKUA9I9TeAX pmd2DclUhnXk4zD2QtfPb4HhJ8aOwcui+lDTluarGN/I9cWpqNHFQ+8dn6lAm7VqcADu XfQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=XQ1EpSrMfrLrn7WxtXUbBiJs/Vq1eoSxF6wYWBh0Qc0=; b=GQXofE8cAR9C5xllgOpAv5R8w61SS5eXFHZBrxYFKbFTuNlammZ2+q5XbZuN/FtAdF fesXP9r9Bvm77xExTEdyv2QVvQCcTMQLkpcpFgpcWB8JejX6DWnIHGe3rSQBHZ/da0/L qxtCVqPGmcYPLLV4OEvPxMu1RFrMiXbzl/ONS5Bvh/A0WxBxB0ZkUAzL1rWcUP9EPjd4 A0px2/c5BzJhcJ+rf+rdZpmlENnIezbihGo7iMDst9TdELaHnEUM9O/nlDNwaqxTm/sx nYOjv1nReZ6kctDw2TTeFnxLvDgl2WXtLsS5WmFv/Yu+K8XeAWGDapVRnt//mloOm2b/ eKlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id d5si2358638ejz.709.2020.10.06.08.58.21; Tue, 06 Oct 2020 08:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726164AbgJFP4L (ORCPT + 99 others); Tue, 6 Oct 2020 11:56:11 -0400 Received: from mga18.intel.com ([134.134.136.126]:32012 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbgJFP4L (ORCPT ); Tue, 6 Oct 2020 11:56:11 -0400 IronPort-SDR: qwi6T/PSRV0myrGFzO+7k4o7cTy/lafjmEsKK8grHuk87fA/epeRERsCSZJ+nRyGOzIxkwlVOi vFWsT9yVDQfg== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="152314945" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="152314945" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 08:49:23 -0700 IronPort-SDR: uTuShdZoDAQiz9ZeZclugbz7v7M1rBWVL7iq7A7CzeddsqJ07SwpS8cn+JzabB5zIflSQo6x5s pfPMxJSLsk6g== X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="527410835" Received: from thijsmet-mobl.ger.corp.intel.com (HELO localhost) ([10.249.34.36]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 08:49:17 -0700 Date: Tue, 6 Oct 2020 18:49:10 +0300 From: Jarkko Sakkinen To: Jethro Beekman Cc: Sean Christopherson , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Cedric Xing , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, npmccallum@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com, mikko.ylinen@intel.com Subject: Re: [PATCH v39 21/24] x86/vdso: Implement a vDSO for Intel SGX enclave call Message-ID: <20201006154910.GD109815@linux.intel.com> References: <20201003045059.665934-1-jarkko.sakkinen@linux.intel.com> <20201003045059.665934-22-jarkko.sakkinen@linux.intel.com> <20201006025703.GG15803@linux.intel.com> <453c2d9b-0fd0-0d63-2bb9-096f255a6ff4@fortanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <453c2d9b-0fd0-0d63-2bb9-096f255a6ff4@fortanix.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 06, 2020 at 10:30:16AM +0200, Jethro Beekman wrote: > On 2020-10-06 04:57, Sean Christopherson wrote: > > On Sat, Oct 03, 2020 at 07:50:56AM +0300, Jarkko Sakkinen wrote: > >> From: Sean Christopherson > >> + /* Validate that the reserved area contains only zeros. */ > >> + push %rax > >> + push %rbx > >> + mov $SGX_ENCLAVE_RUN_RESERVED_START, %rbx > >> +1: > >> + mov (%rcx, %rbx), %rax > >> + cmpq $0, %rax > >> + jne .Linvalid_input > >> + > >> + add $8, %rbx > >> + cmpq $SGX_ENCLAVE_RUN_RESERVED_END, %rbx > >> + jne 1b > >> + pop %rbx > >> + pop %rax > > > > This can more succinctly be (untested): > > > > movq SGX_ENCLAVE_RUN_RESERVED_1(%rbp), %rbx > > orq SGX_ENCLAVE_RUN_RESERVED_2(%rbp), %rbx > > orq SGX_ENCLAVE_RUN_RESERVED_3(%rbp), %rbx > > jnz .Linvalid_input > > > > Note, %rbx is getting clobbered anyways, no need to save/restore it. > > > >> diff --git a/arch/x86/include/uapi/asm/sgx.h b/arch/x86/include/uapi/asm/sgx.h > >> index b6ba036a9b82..3dd2df44d569 100644 > >> --- a/arch/x86/include/uapi/asm/sgx.h > >> +++ b/arch/x86/include/uapi/asm/sgx.h > >> @@ -74,4 +74,102 @@ struct sgx_enclave_provision { > >> __u64 attribute_fd; > >> }; > >> > >> +struct sgx_enclave_run; > >> + > >> +/** > >> + * typedef sgx_enclave_user_handler_t - Exit handler function accepted by > >> + * __vdso_sgx_enter_enclave() > >> + * @run: Pointer to the caller provided struct sgx_enclave_run > >> + * > >> + * The register parameters contain the snapshot of their values at enclave > >> + * exit > >> + * > >> + * Return: > >> + * 0 or negative to exit vDSO > >> + * positive to re-enter enclave (must be EENTER or ERESUME leaf) > >> + */ > >> +typedef int (*sgx_enclave_user_handler_t)(long rdi, long rsi, long rdx, > >> + long rsp, long r8, long r9, > >> + struct sgx_enclave_run *run); > >> + > >> +/** > >> + * struct sgx_enclave_run - the execution context of __vdso_sgx_enter_enclave() > >> + * @tcs: TCS used to enter the enclave > >> + * @user_handler: User provided callback run on exception > >> + * @user_data: Data passed to the user handler > >> + * @leaf: The ENCLU leaf we were at (EENTER/ERESUME/EEXIT) > >> + * @exception_vector: The interrupt vector of the exception > >> + * @exception_error_code: The exception error code pulled out of the stack > >> + * @exception_addr: The address that triggered the exception > >> + * @reserved Reserved for possible future use > >> + */ > >> +struct sgx_enclave_run { > >> + __u64 tcs; > >> + __u64 user_handler; > >> + __u64 user_data; > >> + __u32 leaf; > > > > I am still very strongly opposed to omitting exit_reason. It is not at all > > difficult to imagine scenarios where 'leaf' alone is insufficient for the > > caller or its handler to deduce why the CPU exited the enclave. E.g. see > > Jethro's request for intercepting interrupts. > > Not entirely sure what this has to do with my request, I just expect > to see leaf=ERESUME in this case, I think? E.g. as you would see in > EAX when calling ENCLU. The documentation needs to be fixed but the answer is yes. I.e. - Leaf will contain ERESUME on interrupt. - Leaf will contain EEXIT on normal exit. Maybe I should rename it as exit_leaf and rewrite the description to improve clarity? /Jarkko