Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4215159imu; Tue, 18 Dec 2018 10:55:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/WemdqkmJVxmhwbSo0dIenVDIQMdthOFQYBox0/YwXJrvtvMbFBegyzstUTEeFj9RmNHite X-Received: by 2002:a63:104d:: with SMTP id 13mr16761351pgq.303.1545159307445; Tue, 18 Dec 2018 10:55:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545159307; cv=none; d=google.com; s=arc-20160816; b=LqDHqhnJgKjlhCl7OyPsfy2dHFrKUESncyckgJ3lNkvgMpxYwNConVhqKDjotdUC5C 3FlAPQHtiL4SadH+08QV95TSQh7qidjTK1MfCptHDArAwRYMKyYSiDQpwWwHHhIDMbpc Ev0qyNyD8NQ2ED3YbC1U8JCXA7XSEPEn21+0k8reisgQr9jn33rJwssKNdkFZ852WlPi utigtxYAAzncBXERzkSfJYeBjipzuYslnygn910DuAhnzSoYFQFAYWnrEOcdDEyAdy0W x+wqhRH8EDQ000goi0MYhOriL1mvZ3z0ZenXa4uP/HNgrFTxHDVaPzTUTPDW/efjhgNj Ak3A== 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=WSmhWu1eS7ZFhdWtvDfh5vAe4lSy6PfEl8tPJBdos10=; b=Q/8XzVwTR7Z7/NUby1ekHWjdk+YXSzqcu+fZBFl4V9h0OMv62XdVA2jwA9H80NbhMO IulfjVUkZ/c12I0cUYPmzpKq0Yg0TnrFUJ7ck3auiQhT0wpsvpLX6ZRcVwYd0ns6bQn7 VUUkM5c4ExHLR0Qbw82V5ADvGA8Soa5kT6FFcvIfDL0fEfjWwZ1+piHiSa+mwu60eYGf VKrSFWmEJFx7QF2N2uE8bpJqlT2uiWa8+TOsPOGK9/+6Ay6zuGC3lh81fctn9TJagH9f h8gl37p2Ps6yb7993UIAErPvZSutMX05D7R37/2Wvo4VDEXhr842scupQaBr8PKsrWsh DzGg== 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 r6si14040415pli.248.2018.12.18.10.54.51; Tue, 18 Dec 2018 10:55:07 -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 S1726759AbeLRSxv (ORCPT + 99 others); Tue, 18 Dec 2018 13:53:51 -0500 Received: from mga07.intel.com ([134.134.136.100]:20846 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726446AbeLRSxv (ORCPT ); Tue, 18 Dec 2018 13:53:51 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2018 10:53:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,368,1539673200"; d="scan'208";a="108376886" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by fmsmga007.fm.intel.com with ESMTP; 18 Dec 2018 10:53:49 -0800 Date: Tue, 18 Dec 2018 10:53:49 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Dave Hansen , Jarkko Sakkinen , X86 ML , Platform Driver , linux-sgx@vger.kernel.org, nhorman@redhat.com, npmccallum@redhat.com, "Ayoun, Serge" , shay.katz-zamir@intel.com, Haitao Huang , Andy Shevchenko , Thomas Gleixner , "Svahn, Kai" , mark.shanahan@intel.com, Suresh Siddha , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Darren Hart , Andy Shevchenko , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v17 18/23] platform/x86: Intel SGX driver Message-ID: <20181218185349.GC30082@linux.intel.com> References: <20181116010412.23967-19-jarkko.sakkinen@linux.intel.com> <7d5cde02-4649-546b-0f03-2d6414bb80b5@intel.com> <20181217180102.GA12560@linux.intel.com> <20181217183613.GD12491@linux.intel.com> <20181217184333.GA26920@linux.intel.com> <20181217222047.GG12491@linux.intel.com> <20181218154417.GC28326@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181218154417.GC28326@linux.intel.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 Tue, Dec 18, 2018 at 07:44:18AM -0800, Sean Christopherson wrote: > On Mon, Dec 17, 2018 at 08:59:54PM -0800, Andy Lutomirski wrote: > > On Mon, Dec 17, 2018 at 2:20 PM Sean Christopherson > > wrote: > > > > > > > > My brain is still sorting out the details, but I generally like the idea > > > of allocating an anon inode when creating an enclave, and exposing the > > > other ioctls() via the returned fd. This is essentially the approach > > > used by KVM to manage multiple "layers" of ioctls across KVM itself, VMs > > > and vCPUS. There are even similarities to accessing physical memory via > > > multiple disparate domains, e.g. host kernel, host userspace and guest. > > > > > > > In my mind, opening /dev/sgx would give you the requisite inode. I'm > > not 100% sure that the chardev infrastructure allows this, but I think > > it does. > > My fd/inode knowledge is lacking, to say the least. Whatever works, so > long as we have a way to uniquely identify enclaves. Actually, while we're dissecting the interface... What if we re-organize the ioctls in such a way that we leave open the possibility of allocating raw EPC for KVM via /dev/sgx? I'm not 100% positive this approach will work[1], but conceptually it fits well with KVM's memory model, e.g. KVM is aware of the GPA<->HVA association but generally speaking doesn't know what's physically backing each memory region. Tangentially related, I think we should support allocating multiple enclaves from a single /dev/sgx fd, i.e. a process shouldn't have to open /dev/sgx every time it wants to create a new enclave. Something like this: /dev/sgx | -> mmap() { return -EINVAL; } | -> unlocked_ioctl() | -> SGX_CREATE_ENCLAVE: { return alloc_enclave_fd(); } | | | -> mmap() { ... } | | | -> get_unmapped_area() { | | if (enclave->size) { | | if (!addr) | | addr = enclave->base; | | if (addr + len + pgoff > enclave->base + enclave->size) | | return -EINVAL; | | } else { | | if (!validate_size(len)) | | return -EINVAL; | | addr = naturally_align(len); | | } | | } | | | -> unlocked_ioctl() { | SGX_ENCLAVE_ADD_PAGE: { ... } | SGX_ENCLAVE_INIT: { ... } | SGX_ENCLAVE_REMOVE_PAGES: { ... } | SGX_ENCLAVE_MODIFY_PAGES: { ... } | } | -> SGX_CREATE_VIRTUAL_EPC: {return alloc_epc_fd(); } | -> mmap() { ... } | -> get_unmapped_area() { } | -> unlocked_ioctl() { SGX_VIRTUAL_EPC_???: SGX_VIRTUAL_EPC_???: } [1] Delegating EPC management to /dev/sgx is viable for virtualizing SGX without oversubscribing EPC to guests, but oversubscribing EPC in a VMM requires handling EPC-related VM-Exits and using instructions that will #UD if the CPU is not post-VMXON. I *think* having KVM forward VM-Exits to x86/sgx would work, but it's entirely possible it'd be a complete cluster.