Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp430750imm; Fri, 31 Aug 2018 04:25:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYOwGBYO+Ic/OM3OxzCSHq+6wKZFdJeIIWo/mfbfP3nvkDZ3nVhaZ3xdGMStoaDgxoN9X9M X-Received: by 2002:a63:e318:: with SMTP id f24-v6mr12321614pgh.175.1535714717894; Fri, 31 Aug 2018 04:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535714717; cv=none; d=google.com; s=arc-20160816; b=VPIBzxNjvX46X2tJMZRTznv8KovOpZWjvOcKjVDCoOWj9h/4c+Q6D5YAwsBvlDNrEn 3tqEvMUDwxyJKi6KKpH619GE++9vT7/700itcQXhfREX6QThcbagv2pS/T74nQslv3Hj IWU6nnl6IxKVPS1YYBFhgLHEvMx9dtNL0kPwN0NHvgPgpZYskBqNQMaqPJDfAGoMSAyC L18yXovG9CXuWYReBCJEaaKrxxjRc7l+EQaDz7ltsBmGoGlMuZfliYzFhMX0w3cE2BE3 OFhnukQH9CeAgmREovsLhPRozQoou8mvr85ie2dcGQhf6MZFAND3HU1CmI94aN/Cqa9F FV1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=5s49Tt48+5BF3BZJVE3YXK9rf/sahDmE6NsUIa0uky0=; b=BsKcP9Q/Siesw03Iym9sreZQ4fkWq80WKDndylxRYzpEEu2KBd51OW5F4pk729gQwP s6hLuI6x++PPQVXCoyl1SLQS5dXRb+McH9OLyBpqoJ+tXWA0bnOxRJrcIU0DIbwE286g 78E4stEycGoXW76R9Ckq0SKJzUEWHHyoe/9SvEQDcaGeUV2slJOxpxe1aW+AvUl2uz3h zmxTuATzqKHyuFwO12zT8ym3GuwqfMRZl/kMiotfutvp6gjVWWc/cPwMFoB1hXZWpjbI ayB7K7j6kDuspVU47ffDiPJrp6kTDMkHAxm9NBCSoewXGEi6/0bzbdgQfS5OqIfPZqJG nnsQ== 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 bd6-v6si8924273plb.265.2018.08.31.04.25.02; Fri, 31 Aug 2018 04:25:17 -0700 (PDT) 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 S1728058AbeHaPaE (ORCPT + 99 others); Fri, 31 Aug 2018 11:30:04 -0400 Received: from mga09.intel.com ([134.134.136.24]:17906 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbeHaPaE (ORCPT ); Fri, 31 Aug 2018 11:30:04 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2018 04:23:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,311,1531810800"; d="scan'208";a="84966070" Received: from ssirohi-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.48.112]) by fmsmga004.fm.intel.com with ESMTP; 31 Aug 2018 04:22:47 -0700 Date: Fri, 31 Aug 2018 14:22:45 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Dave Hansen , x86@kernel.org, platform-driver-x86@vger.kernel.org, nhorman@redhat.com, npmccallum@redhat.com, linux-sgx@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Suresh Siddha , Serge Ayoun , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" Subject: Re: [PATCH v13 09/13] x86/sgx: Enclave Page Cache (EPC) memory manager Message-ID: <20180831112245.GC16827@linux.intel.com> References: <20180827185507.17087-1-jarkko.sakkinen@linux.intel.com> <20180827185507.17087-10-jarkko.sakkinen@linux.intel.com> <7c5df14e-3028-46b3-fe93-aa6ba8352317@intel.com> <20180828083540.GH15508@linux.intel.com> <132d309d-77e2-52ed-7251-abb2c80cdf49@intel.com> <20180828212244.GA29488@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180828212244.GA29488@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 28, 2018 at 02:22:44PM -0700, Sean Christopherson wrote: > On Tue, Aug 28, 2018 at 07:07:33AM -0700, Dave Hansen wrote: > > On 08/28/2018 01:35 AM, Jarkko Sakkinen wrote: > > > On Mon, Aug 27, 2018 at 02:15:34PM -0700, Dave Hansen wrote: > > >> On 08/27/2018 11:53 AM, Jarkko Sakkinen wrote: > > >>> +struct sgx_epc_page_ops { > > >>> + bool (*get)(struct sgx_epc_page *epc_page); > > >>> + void (*put)(struct sgx_epc_page *epc_page); > > >>> + bool (*reclaim)(struct sgx_epc_page *epc_page); > > >>> + void (*block)(struct sgx_epc_page *epc_page); > > >>> + void (*write)(struct sgx_epc_page *epc_page); > > >>> +}; > > >> Why do we need a fancy, slow (retpoline'd) set of function pointers when > > >> we only have one user of these (the SGX driver)? > > > KVM has its own implementation for these operations. > > > > That belongs in the changelog. > > > > Also, where is the implementation? How can we assess this code that was > > built to create an abstraction without both of the users? > > I can provide an early preview of the KVM reclaim code, but honestly > I think that would do more harm than good. The VMX architecture for > EPC reclaim is complex, even for SGX standards. Opening that can of > worms would likely derail this discussion. That being said, this > abstraction isn't exactly what KVM will need, but it's pretty close > and gives us something to build on. > > Regardless, this layer of indirection is justifiable even with a > single implementation. Reclaiming an EPC page is not a simple matter > of copying the data somewhere else and marking the page not present. > Actual eviction requires a reference to the Secure Enclave Control > Structure (SECS) of the enclave that owns the page. Software needs > to ensure it doesn't violate the hardware-enforced access rules, e.g. > most reclaim activites need to be done under a per-enclave lock. > Not all pages have the same reclaim rules, e.g. an SECS can only > be reclaimed after all its child pages have reclaimed, a VA page > doesn't need to be blocked, etc... And the list goes on... To simplify a bit what Sean said about the key difference to a standard page is that in SGX a page is part of a hierarchical structure. EPC pages have hardware enforced dependencies to each other. Examples: 1. You cannot delete or swap SECS before its children have been deleted or swapped. You get SGX_CHILD_PRESENT erro from EREMOVE. 2. In order to swap or fault a page you need to have an EPC page that holds a version number for the page you want to swap. These are called Version Array (VA) pages. /Jarkko