Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp934608imu; Wed, 9 Jan 2019 08:45:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN4RLhJ0H5UsT8MkBqUgcpJ+C3GDhS9YxyAVRwhoZeoX5vZaDHg/GuqmVOVSis44Qp95HFpz X-Received: by 2002:a63:e21:: with SMTP id d33mr6034660pgl.272.1547052338436; Wed, 09 Jan 2019 08:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547052338; cv=none; d=google.com; s=arc-20160816; b=XHl0+p7X3B9X0BU9yAAd2XdTfhnDxelnekBLmA34g2ZevrSUgYTF5n2SnmTQT+/tFj uYy4YkeUmYIt7N7k0RYF70vMB5i9tbC3VCpUUi5CpxRTNceDWAo78XkHm9ufjmpAZTBf jPEE4dKt27trcXKfOzHANn+XGEG8zMH00k6MKkV3PBiEgoA7X93RllL/YODeyzpbuVcw MuRXfrg3BAEuhjmy5p3u0HSxln+G7oURJvIE0q/EZrPxREnQZBSNM43V6/y5oYg6B4Hc P5Iz2DEEMCIMf6WvT6RtiDDfGrFMV89gjl+P49TtbAAjSEGA7TRGdP38hDS9ttiKj0v+ zCUA== 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=QyzGwaSYEHy+q3iF+TfZL+VWk/hJPUbwecv9XklIweY=; b=zDatgRqSHbMMmHIW6XCdC+hRZepRt6xbvXX5AlQZWzRKOaj46HbJMh1NyM39B3+uHP JfmVdnwlOM6o89haSQpqUbz380goUZqsFbEj/ThTiM7fzViYksBvSjl8OgYafxFVu4G7 FYFRYH55zfIj2s9Z04RzlG7AYUQsJbftkRTUSsyILP6NGcUTM7k//4DtZmNiCFFRjiXa o56vJXPB+s+31eoexA4pGPl60X9HLN5XlhxwKpA+8pnImkD5gTGtO7O8dR7Uyyj7Nk0T drTFSNM17KBvj4I1C8py9LMaWwu3LyBomq6O8ac/9KhDLJh92ck4IZeBIzwO3IX44qjR zA2A== 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 k12si12291057pgg.382.2019.01.09.08.45.23; Wed, 09 Jan 2019 08:45:38 -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 S1726439AbfAIQbj (ORCPT + 99 others); Wed, 9 Jan 2019 11:31:39 -0500 Received: from mga04.intel.com ([192.55.52.120]:21981 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbfAIQbi (ORCPT ); Wed, 9 Jan 2019 11:31:38 -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 fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 08:31:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,458,1539673200"; d="scan'208";a="108570223" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by orsmga008.jf.intel.com with ESMTP; 09 Jan 2019 08:31:37 -0800 Date: Wed, 9 Jan 2019 08:31:37 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: "Huang, Kai" , 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: <20190109163135.GA1821@linux.intel.com> References: <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> <20181221162825.GB26865@linux.intel.com> <105F7BF4D0229846AF094488D65A0989355A45B6@PGSMSX112.gar.corp.intel.com> <20190108220946.GA30462@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 Tue, Jan 08, 2019 at 02:54:11PM -0800, Andy Lutomirski wrote: > On Tue, Jan 8, 2019 at 2:09 PM Sean Christopherson > wrote: > > > > Cleaner in the sense that it's faster to get basic support up and running > > since there are fewer touchpoints, but there are long term ramifications > > to cramming EPC management in KVM. > > > > And at this point I'm not stating any absolutes, e.g. how EPC will be > > handled by KVM. What I'm pushing for is to not eliminate the possibility > > of having the SGX subsystem own all EPC management, e.g. don't tie > > /dev/sgx to a single enclave. > > I haven't gone and re-read all the relevant SDM bits, so I'll just > ask: what, if anything, are the actual semantics of mapping "raw EPC" > like this? You can't actually do anything with the mapping from user > mode unless you actually get an enclave created and initialized in it > and have it mapped at the correct linear address, right? I still > think you have the right idea, but it is a bit unusual. Correct, the EPC is inaccessible until a range is "mapped" with ECREATE. But I'd argue that it's not unusual, just different. And really it's not all that different than userspace mmap'ing /dev/sgx/enclave prior to ioctl(ENCLAVE_CREATE). In that case, userspace can still (attempt to) access the "raw" EPC, i.e. generate a #PF, the kernel/driver just happens to consider any faulting EPC address without an associated enclave as illegal, e.g. signals SIGBUS. The /dev/sgx/epc case simply has different semantics for moving pages in and out of the EPC, i.e. different fault and eviction semantics. Yes, this allows the guest kernel to directly access the "raw" EPC, but that's conceptually in line with hardware where priveleged software can directly "access" the EPC (or rather, the abort page for all intents and purposes). I.e. it's an argument for requiring certain privileges to open /dev/sgx/epc, but IMO it's not unusual. Maybe /dev/sgx/epc is a poor name and is causing confusion, e.g. /dev/sgx/virtualmachine might be more appropriate. > I do think it makes sense to have QEMU delegate the various ENCLS > operations (especially EINIT) to the regular SGX interface, which will > mean that VM guests will have exactly the same access controls applied > as regular user programs, which is probably what we want. To what end? Except for EINIT, none of the ENCLS leafs are interesting from a permissions perspective. Trapping and re-executing ENCLS leafs is painful, e.g. most leafs have multiple virtual addresses that need to be translated. And routing everything through the regular interface would make SGX even slower than it already is, e.g. every ENCLS would take an additional ~900 cycles just to handle the VM-Exit, and that's not accounting for any additional overhead in the SGX code, e.g. using the regular interface would mean superfluous locks, etc... The only benefit is that it would theoretically allow oversubscribing guest EPC without hardware support, but that would require a lot of code to do the necessary SECS tracking and refcounting. > If so, > there will need to be a way to get INITTOKEN privilege for the purpose > of running non-Linux OSes in the VM, which isn't the end of the world. Couldn't we require the same privilege/capability for VMs and and EINIT tokens? I.e. /dev/sgx/virtualmachine can only be opened by a user that can also generate tokens. > We might still want the actual ioctl to do EINIT using an actual > explicit token to be somehow restricted in a way that strongly > discourages its use by anything other than a hypervisor. Or I suppose > we could just straight-up ignore the guest-provided init token. > > P.S. Is Intel ever going to consider a way to make guests get their > own set of keys that are different from the host's keys and other > guests' keys?