Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2054570imu; Sat, 22 Dec 2018 11:05:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN4fd9uzX8TjUzsBxMz6hRkY2rf0vXPU4RYv7mLzFQ24sIUrK+E9AfneAwRuysLr4H/1mIsT X-Received: by 2002:a17:902:622:: with SMTP id 31mr7292259plg.171.1545505503371; Sat, 22 Dec 2018 11:05:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545505503; cv=none; d=google.com; s=arc-20160816; b=0ZdWJAZuEi6A0A14fAq0fuQWLWvE1TmHb0j+VZ/sLwOA/Ss1iBrNWz469WpaT3WDa3 G2nqspZ9r38f7ypDwVCa0DzlAsYYSALlSbJtRgmyGSjPC7q+UZFAyyQ36mNZwkrXvYWs gvS+XCuLBCl74/mfSo9CoVvAMB6Xy0AaTb7J9qoIhwfAtK+0gu0Xc+Ct/ZdxRnW9IkgP HIWvRGRPwmNQCdj0aDIutOkZTHiWPIWNmOXUDdra5SIeBIQ5lmNGNgC0gc+PvjOywoxz oXW0cCwoxwdfkpSB1AEcLXlatPq9QW7EYuXYYCRZscHxpUKiSfZNCMKdUcc04gv5q6Zo /b9A== 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=7Nkgr0pAIX4OtfsZWhJVqqn0Cb7HnruDmihxhyj0z0U=; b=leVsUsINBRFYIvFduU3kGPUqfeTWh9ktbotAC/4Mfzrlq+bZh/cZD2nVbzJ8nn0T2Q r57bWPvv+WP9wJ3Fy2ZrkAvzc7epve/JQjF8r8FrfmHr0UShLJOUefXk45n52zA8XVWZ NziWFsDVvQfrwQHxU0lfCDU3LJtJ2mqF4i9zU985Y+GPWsgQfTI+Pnzz75Sl9QVYqMdX v69wtPQ0YxupZwqgQFepF4GBwYCAy8aYwxWhLqz1FJ8EN1NmlWbykCuB1/4bs87YFZ6A b0OFzJT1Gt+L5c1uGfiUaKEBbZuxgMrWtUO3oS7dCwbwk8PIIKBVYIzQA/wtEShvXdxh Jj5Q== 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 d13si2821401plr.403.2018.12.22.11.04.34; Sat, 22 Dec 2018 11:05:03 -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 S2388370AbeLUQ20 (ORCPT + 99 others); Fri, 21 Dec 2018 11:28:26 -0500 Received: from mga06.intel.com ([134.134.136.31]:46234 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731121AbeLUQ2Z (ORCPT ); Fri, 21 Dec 2018 11:28:25 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2018 08:28:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,382,1539673200"; d="scan'208";a="112425052" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by orsmga003.jf.intel.com with ESMTP; 21 Dec 2018 08:28:25 -0800 Date: Fri, 21 Dec 2018 08:28:25 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Jethro Beekman , Jarkko Sakkinen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "x86@kernel.org" , Dave Hansen , Peter Zijlstra , "H. Peter Anvin" , "linux-kernel@vger.kernel.org" , "linux-sgx@vger.kernel.org" , Josh Triplett , Haitao Huang , "Dr . Greg Wettstein" Subject: Re: x86/sgx: uapi change proposal Message-ID: <20181221162825.GB26865@linux.intel.com> References: <20181214215729.4221-1-sean.j.christopherson@intel.com> <7706b2aa71312e1f0009958bcab24e1e9d8d1237.camel@linux.intel.com> <598cd050-f0b5-d18c-96a0-915f02525e3e@fortanix.com> <20181219091148.GA5121@linux.intel.com> <613c6814-4e71-38e5-444a-545f0e286df8@fortanix.com> <20181219144515.GA30909@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 Wed, Dec 19, 2018 at 06:58:48PM -0800, Andy Lutomirski wrote: > > On Dec 19, 2018, at 6:45 AM, Sean Christopherson wrote: > > > >> On Wed, Dec 19, 2018 at 09:36:16AM +0000, Jethro Beekman wrote: > > > I agree with Jethro, passing the enclave_fd as a param is obnoxious. > > And it means the user needs to open /dev/sgx to do anything with an > > enclave fd, e.g. the enclave fd might be passed to a builder thread, > > it shouldn't also need the device fd. > > > > E.g.: > > > > sgx_fd = open("/dev/sgx", O_RDWR); > > BUG_ON(sgx_fd < 0); > > > > enclave_fd = ioctl(sgx_fd, SGX_ENCLAVE_CREATE, &ecreate); > > BUG_ON(enclave_fd < 0); > > > > ret = ioctl(enclave_fd, SGX_ENCLAVE_ADD_PAGE, &eadd); > > BUG_ON(ret); > > > > ... > > > > ret = ioctl(enclave_fd, SGX_ENCLAVE_INIT, &einit); > > BUG_ON(ret); > > > > ... > > > > close(enclave_fd); > > close(sgx_fd); > > > > > > Take a look at virt/kvm/kvm_main.c to see how KVM manages anon inodes > > and ioctls for VMs and vCPUs. > > Can one of you explain why SGX_ENCLAVE_CREATE is better than just > opening a new instance of /dev/sgx for each encalve? Directly associating /dev/sgx with an enclave means /dev/sgx can't be used to provide ioctl()'s for other SGX-related needs, e.g. to mmap() raw EPC and expose it a VM. Proposed layout in the link below. I'll also respond to Jarkko's question about exposing EPC through /dev/sgx instead of having KVM allocate it on behalf of the VM. https://lkml.kernel.org/r/20181218185349.GC30082@linux.intel.com