Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3659045imm; Mon, 25 Jun 2018 02:22:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIQ9353gJ/n4ihMQi+2F+w8LBA6U7pGD1g6/ywUmZv5JpC61ZiOy430M58VxBuTjqcd9unu X-Received: by 2002:a63:9402:: with SMTP id m2-v6mr9872094pge.8.1529918558421; Mon, 25 Jun 2018 02:22:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529918558; cv=none; d=google.com; s=arc-20160816; b=0K8y2CVu/2bge/YezgqCgpe/+irs6muU4NF9RSmfQnSZ5IY7sVNyIxHDB4o3Le9Whc TkaVkrv3Gn3N6Qa4lhxJ/LoNvf5peRwgwWC8hqELwOWQxkV8onrTRUrAB6g+875W1Jvt MYtJzjvGdv22oVaxZH0NiSEmlqFNnmbpnZDSuRvYo9MFNPzThrXtOVetkCsgiKRC2d09 1RDF9RicA1jCO/FRqO23KDeU1TuVWDJ/ui1QRwzPeaRQPQkOkWLuz0VBZmkC3hTsKXWf vIZ4hdeHt8Hr4Pb5NIzvmxQqS+ZNrUz40Y/WDpxq6FJdjgk9XCHLtcDtlCU0Qiiog9E9 988Q== 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 :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=htfAGeVERikZAn6bdZmyGBk0IFZSWkjVkeDXa9jYedI=; b=YWD1ImBKk73UkvWPF99kyTBQ/nZjvPqSAwCi4W4VfciMFIqIPDPAfRB9EyCKBoJLCd fzr0uM/6Vb0gp0HlwUMD+ffJEME8n02rnhq49ShHgakVRURY0yqu7b3nulMSWE0vofGe ZhdA0lY1taLz/LGE1JB0D6snVgstTMPQQ34qhx6GjOAVLdF1ZVO3zPym/WhRX+rans/q dKgX1ziVp9B3yCW65SlFhzf5pEKTngcka6rH3a9NoIrNXdjC4C9Tw5eOrni4wbpAKUBA 6kA1zVYr0c4ZjHbv+KlFbf3017oR6ouaC2Scg8OlnJ5vbcY5wBkEpRLw3PxEIsfVk3xl 6zLw== 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 j8-v6si13078483plk.261.2018.06.25.02.22.23; Mon, 25 Jun 2018 02:22:38 -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 S1754881AbeFYJV3 (ORCPT + 99 others); Mon, 25 Jun 2018 05:21:29 -0400 Received: from mga11.intel.com ([192.55.52.93]:58839 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754449AbeFYJV1 (ORCPT ); Mon, 25 Jun 2018 05:21:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jun 2018 02:21:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,269,1526367600"; d="scan'208";a="240363011" Received: from jsakkine-mobl1.tm.intel.com (HELO sfriis-mobl.ger.corp.intel.com) ([10.237.50.42]) by fmsmga006.fm.intel.com with ESMTP; 25 Jun 2018 02:21:23 -0700 Message-ID: Subject: Re: [PATCH v11 09/13] x86, sgx: basic routines for enclave page cache From: Jarkko Sakkinen To: Sean Christopherson , 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: Mon, 25 Jun 2018 12:21:22 +0300 In-Reply-To: <1529500871.9779.58.camel@intel.com> References: <20180608171216.26521-1-jarkko.sakkinen@linux.intel.com> <20180608171216.26521-10-jarkko.sakkinen@linux.intel.com> <1529500871.9779.58.camel@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-06-20 at 06:21 -0700, Sean Christopherson wrote: > 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. I agree with this. It also documents stuff so that you don't have to look it up from the SDM. Neil: this should also clear your concerns. /Jarkko