Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp768861imm; Wed, 20 Jun 2018 06:22:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJcZG4EggK2Ao30FyxDxUWjsNt6/3geZ4pdPOIRMWWJ7XnpbIuT9y/94eqaOfEN2iZlU09w X-Received: by 2002:a63:5401:: with SMTP id i1-v6mr18383727pgb.187.1529500933468; Wed, 20 Jun 2018 06:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529500933; cv=none; d=google.com; s=arc-20160816; b=qg0WCRMu7YXQxtL8ctPHA/9llMqA0PJBPMcmuLPyZrIxzJziLRMM7YOQezrSXbGzn+ b/QcnBqY4mDdCBQumUPzujq797rH9iDClEQIRNu7jmcP+jskmYn1hWfC/PDyKbUzt9gv nckvRO1SNqFTYxmBEM08Z1r9Ke/caHYEHHC5bBtJKhfCmmO0DCph4H/gxm4v50LZskBL VaprpMm6bO4YXLhxBh+ZS3dcXcijbIUSTpwURMnjZiJeWzQ9jalVEM3q9dS+npyzDoFj QUwNkIU+9Q7WVqP3mAnbf9NMojW2JfLFJt0HYANESohIO4OW687CXkRxrmcVx0ya9Y+E VYyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=1PN/btPnU6dmhmdq7KKn5+KQ1q0xuNIg9HsEjeWGstE=; b=FbEDBpsVjgqyOo/YSawHAaGvHajXIYRG6dntgCsMdYkQaY1R45bk4PfZCUkV7xjzkd Gc7nlMMgkoP92W6+pxMGp6FaMGn0zBSL1K4vjrJILtrStOmcOXpa8fcYxhqEeB6W5zO8 2v0K00rXtUWT4ILjrNOaJ2U0WqEV5F0vUT9953ll+jxBOGNc4voSCCJ6prFts4nmFOnO W0ElPU74NfOCz6UPWuoMl9XbdBTyCurwBjT50iR6uuTC7PJKjjaTVL60ecZ7LeTLbDkh NtPLi6dY2VD2Fw5qMSaiJgYO7iT4iavQgOS9Mt0N2dEqdAxBA4JUpAXheIW9bXKNPqLr Ojkw== 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 b5-v6si2407960plx.4.2018.06.20.06.21.59; Wed, 20 Jun 2018 06:22:13 -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 S1753896AbeFTNVO (ORCPT + 99 others); Wed, 20 Jun 2018 09:21:14 -0400 Received: from mga07.intel.com ([134.134.136.100]:47911 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752871AbeFTNVM (ORCPT ); Wed, 20 Jun 2018 09:21:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Jun 2018 06:21:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,247,1526367600"; d="scan'208";a="209671388" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.135]) by orsmga004.jf.intel.com with ESMTP; 20 Jun 2018 06:21:11 -0700 Message-ID: <1529500871.9779.58.camel@intel.com> Subject: Re: [PATCH v11 09/13] x86, sgx: basic routines for enclave page cache From: Sean Christopherson To: Jarkko Sakkinen , x86@kernel.org, platform-driver-x86@vger.kernel.org Cc: dave.hansen@intel.com, nhorman@redhat.com, npmccallum@redhat.com, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "open list:INTEL SGX" Date: Wed, 20 Jun 2018 06:21:11 -0700 In-Reply-To: <20180608171216.26521-10-jarkko.sakkinen@linux.intel.com> References: <20180608171216.26521-1-jarkko.sakkinen@linux.intel.com> <20180608171216.26521-10-jarkko.sakkinen@linux.intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-06-08 at 19:09 +0200, Jarkko Sakkinen wrote: > SGX has a set of data structures to maintain information about the enclaves > and their security properties. BIOS reserves a fixed size region of > physical memory for these structures by setting Processor Reserved Memory > Range Registers (PRMRR). This memory area is called Enclave Page Cache > (EPC). > > This commit implements the basic routines to allocate and free pages from > different EPC banks. There is also a swapper thread ksgxswapd for EPC pages > that gets woken up by sgx_alloc_page() when we run below the low watermark. > The swapper thread continues swapping pages up until it reaches the high > watermark. > > Each subsystem that uses SGX must provide a set of callbacks for EPC > pages that are used to reclaim, block and write an EPC page. Kernel > takes the responsibility of maintaining LRU cache for them. > > Signed-off-by: Jarkko Sakkinen > --- >  arch/x86/include/asm/sgx.h      |  67 +++++ >  arch/x86/include/asm/sgx_arch.h | 224 ++++++++++++++++ >  arch/x86/kernel/cpu/intel_sgx.c | 443 +++++++++++++++++++++++++++++++- >  3 files changed, 732 insertions(+), 2 deletions(-) >  create mode 100644 arch/x86/include/asm/sgx_arch.h ... > +struct sgx_pcmd { > + struct sgx_secinfo secinfo; > + uint64_t enclave_id; > + uint8_t reserved[40]; > + uint8_t mac[16]; > +}; sgx_pcmd has a 128-byte alignment requirement.  I think it's worth specifying here as sgx_pcmd is small enough that it could be put on the stack, e.g. by KVM when trapping and executing ELD* on behalf of a guest VM. In fact, it probably makes sense to add alightment attributes to all SGX structs for self-documentation purposes, even though many of them will never be allocated statically or on the stack. > + > +#define SGX_MODULUS_SIZE 384 > + > +struct sgx_sigstruct_header { > + uint64_t header1[2]; > + uint32_t vendor; > + uint32_t date; > + uint64_t header2[2]; > + uint32_t swdefined; > + uint8_t reserved1[84]; > +}; > + > +struct sgx_sigstruct_body { > + uint32_t miscselect; > + uint32_t miscmask; > + uint8_t reserved2[20]; > + uint64_t attributes; > + uint64_t xfrm; > + uint8_t attributemask[16]; > + uint8_t mrenclave[32]; > + uint8_t reserved3[32]; > + uint16_t isvprodid; > + uint16_t isvsvn; > +} __attribute__((__packed__)); > + > +struct sgx_sigstruct { > + struct sgx_sigstruct_header header; > + uint8_t modulus[SGX_MODULUS_SIZE]; > + uint32_t exponent; > + uint8_t signature[SGX_MODULUS_SIZE]; > + struct sgx_sigstruct_body body; > + uint8_t reserved4[12]; > + uint8_t q1[SGX_MODULUS_SIZE]; > + uint8_t q2[SGX_MODULUS_SIZE]; > +}; > + > +struct sgx_sigstruct_payload { > + struct sgx_sigstruct_header header; > + struct sgx_sigstruct_body body; > +}; > + > +struct sgx_einittoken_payload { > + uint32_t valid; > + uint32_t reserved1[11]; > + uint64_t attributes; > + uint64_t xfrm; > + uint8_t mrenclave[32]; > + uint8_t reserved2[32]; > + uint8_t mrsigner[32]; > + uint8_t reserved3[32]; > +}; > + > +struct sgx_einittoken { > + struct sgx_einittoken_payload payload; > + uint8_t cpusvnle[16]; > + uint16_t isvprodidle; > + uint16_t isvsvnle; > + uint8_t reserved2[24]; > + uint32_t maskedmiscselectle; > + uint64_t maskedattributesle; > + uint64_t maskedxfrmle; > + uint8_t keyid[32]; > + uint8_t mac[16]; > +}; > + > +struct sgx_report { > + uint8_t cpusvn[16]; > + uint32_t miscselect; > + uint8_t reserved1[28]; > + uint64_t attributes; > + uint64_t xfrm; > + uint8_t mrenclave[32]; > + uint8_t reserved2[32]; > + uint8_t mrsigner[32]; > + uint8_t reserved3[96]; > + uint16_t isvprodid; > + uint16_t isvsvn; > + uint8_t reserved4[60]; > + uint8_t reportdata[64]; > + uint8_t keyid[32]; > + uint8_t mac[16]; > +}; > + > +struct sgx_targetinfo { > + uint8_t mrenclave[32]; > + uint64_t attributes; > + uint64_t xfrm; > + uint8_t reserved1[4]; > + uint32_t miscselect; > + uint8_t reserved2[456]; > +}; > + > +struct sgx_keyrequest { > + uint16_t keyname; > + uint16_t keypolicy; > + uint16_t isvsvn; > + uint16_t reserved1; > + uint8_t cpusvn[16]; > + uint64_t attributemask; > + uint64_t xfrmmask; > + uint8_t keyid[32]; > + uint32_t miscmask; > + uint8_t reserved2[436]; > +};