Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5244817imu; Wed, 19 Dec 2018 07:58:08 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uzjs/sM/acNSPmK0V1pcb6wEYTwLnJBg8Rp+JI/D3QWknhcLgc/z24gPWpiXytR89NpvvV X-Received: by 2002:a63:de04:: with SMTP id f4mr3338845pgg.292.1545235088122; Wed, 19 Dec 2018 07:58:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545235088; cv=none; d=google.com; s=arc-20160816; b=zPfZrF9Y/kPvI87WwKxE5NgmqaH+yz9dq7uFT4ibm9e95ufsW+4ctRnHaExBr4P+qP HH8m1SkZeR9Opd/GshSSRNini77BRmKEjRi6/cMwOGBnSVRIftXgXfjKYfEY54urVVMV oo/JS25cdYnkYZC6+drkY071WJ52yitl9SP9wemDyRUVdbZaetv6UMDm7G4okMN7bUiO HB+MuOKzyPc4L3XrZodxf035hwpKqyS69mNbwPg/h+I1XdG7ie/y+B8tgDiSRruDzhC0 8bXY32a2oaEdZUW5tz91y3/ArBeBL44S4RTEXM23Ce3OtaPl+Qi3LDXNH2ZuCAE8uNuI MxKA== 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=l1zJqRiPAr5Im/wGn9RKxIagotY7X55+9EQBi9aLLGs=; b=O8sSbw1CPXbGNAGlSlKZlr7CdUbFVHJPu2OE0IiKZscpqjyFmCCDRz+6gRpq3Mu4Nr 178g5KXCPdrwKObupUlXDFXjWDbwL0CuJcgBIUh17zo29DvF8DKm7L9Je/LTceCrZJMg B3hGHsESiI0MewC2wWns43jqx6xalPgwayKwb1F9YYIRmEWB9L3niS2kNFc9Y3kSf/80 f2dkXYyfMsK1whLuM2AtR7GlHEcVvZM8WVtyrLNNf1Ral1nhAsPpnUy87ywWZ5FHbqXi +ylPt2h31I5AeDv40woVmEaQzWx4dR6DdDZwcSxn6Gklei2qSJpu1z9nXJFLd6MQX7/s ZEMg== 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 32si16481063ple.72.2018.12.19.07.57.51; Wed, 19 Dec 2018 07:58:08 -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 S1729137AbeLSOpR (ORCPT + 99 others); Wed, 19 Dec 2018 09:45:17 -0500 Received: from mga05.intel.com ([192.55.52.43]:55084 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727473AbeLSOpQ (ORCPT ); Wed, 19 Dec 2018 09:45:16 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2018 06:45:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,373,1539673200"; d="scan'208";a="102875924" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by orsmga008.jf.intel.com with ESMTP; 19 Dec 2018 06:45:15 -0800 Date: Wed, 19 Dec 2018 06:45:15 -0800 From: Sean Christopherson To: Jethro Beekman Cc: Jarkko Sakkinen , Andy Lutomirski , 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" , Andy Lutomirski , Josh Triplett , Haitao Huang , "Dr . Greg Wettstein" Subject: Re: x86/sgx: uapi change proposal Message-ID: <20181219144515.GA30909@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <613c6814-4e71-38e5-444a-545f0e286df8@fortanix.com> 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 09:36:16AM +0000, Jethro Beekman wrote: > On 2018-12-19 14:41, Jarkko Sakkinen wrote: > >On Wed, Dec 19, 2018 at 08:41:12AM +0000, Jethro Beekman wrote: > >>One weird thing is the departure from the normal mmap behavior that the > >>memory mapping persists even if the original fd is closed. (See man mmap: > >>"closing the file descriptor does not unmap the region.") It won't (be a departure). mmap() on a file grabs a reference to the file, i.e. each VMA keeps a reference to the file. Closing the original enclave fd will only put its reference to the file/enclave, not destroy it outright. > > > >The mmapped region and enclave would be completely disjoint to start > >with. The enclave driver code would assume that an enclave VMA exists > >when it maps enclave address space to a process. > > > >I.e. VMA would no longer reference to the enclave or vice versa but > >you would still create an enclave VMA with mmap(). > > > >This is IMHO very clear and well-defined semantics. > > > >>>struct sgx_enclave_add_page { > >>> __u64 enclave_fd; > >>> __u64 src; > >>> __u64 secinfo; > >>> __u16 mrmask; > >>>} __attribute__((__packed__)); > >> > >>Wouldn't you just pass enclave_fd as the ioctl fd parameter? > > > >I'm still planning to keep the API in the device fd and use enclave_fd > >as handle to the enclave address space. I don't see any obvious reason > >to change that behavior. > > > >And if we ever add any "global" ioctls, then we would have to define > >APIs to both fd's, which would become a mess. > > > >>How to specify the address of the page that is being added? > > > >Yes, that is correct and my bad to remove it (just quickly drafted what > >I had in mind). > > So your plan is that to call EADD, userspace has to pass the device fd AND > the enclave fd AND the enclave address? That seems a little superfluous. 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.