Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4181458imm; Mon, 11 Jun 2018 08:13:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIPUQMY7Fi5wcNrHOfQBantpXOELEAxiKZl9NiKLKE0tiL+9216ad1433j4hCHlzltPAa1x X-Received: by 2002:a63:79c5:: with SMTP id u188-v6mr15109862pgc.111.1528730022868; Mon, 11 Jun 2018 08:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528730022; cv=none; d=google.com; s=arc-20160816; b=lndqYVa2QT/9Ny1VjoVrHJNQJ3G+r3dl8T3yqPO6rfyxgs//nUmpqbghpStHDJNMnE uQPvVsTaMgKztfa6YvYMT3EU2w08w+3XlLGaBpYslE7fIiZCUWXwU7y/tcqGr3JSkuXj EJ/dTRVD+Vl++FR2pjZK1/02GKGNmxQrqs2pfaUknwpbCPrTLNse6xWLg9I6Wt7b8Pas qkwK8xJTHR5XP4StGAnQIG85CRL5RY7bm/lNrItPoVFfXmJSYlKMd6cSQrmWp5qj9g71 wEJhaTxbBpZqifWBA/GUkyK2Hc9IkGa2V5wmjR+lHj5keBKTbbooypd/QaBkLjRWYLaH JT/Q== 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=x7M7II9f1x0HerVHfhR0EPHdDorLPBqJXmW93J53t20=; b=aGJPVvoUorrgZ2aad0n8Kc/z6pTrv6cusdfnrFGo0EEk1Ggh989qxAUrqmN4Thqdbg p1hu9BM3ipFzf4HqlHxxixXja9V6qOiJEpw9Oa/4JWIaPNN9qZr+w1KPNUjF7+2vZ093 DUFH14z+JemM1UKKMwh32sQqopXHCKxMMOXdPUphG7/ReEpGe+SYpQsii4oVT16+szzQ w9K4vAdO/ekYQy2dR+lPfOub+R16DT7DC97I7MdmgZ2CurAYA97xFrtmtKQENB/byJ3m mM7GeIxq2DQtCagUUiXk6w1XuEcD7hsWh4E3+rESOfbfex6TjqYkH8XPCPWsCymfF3dy 3sgQ== 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 v5-v6si64216764plo.166.2018.06.11.08.13.28; Mon, 11 Jun 2018 08:13:42 -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 S932647AbeFKPMu (ORCPT + 99 others); Mon, 11 Jun 2018 11:12:50 -0400 Received: from mga14.intel.com ([192.55.52.115]:2109 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932298AbeFKPMs (ORCPT ); Mon, 11 Jun 2018 11:12:48 -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 fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2018 08:12:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,502,1520924400"; d="scan'208";a="207115734" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.135]) by orsmga004.jf.intel.com with ESMTP; 11 Jun 2018 08:12:48 -0700 Message-ID: <1528729968.9779.33.camel@intel.com> Subject: Re: [intel-sgx-kernel-dev] [PATCH v11 09/13] x86, sgx: basic routines for enclave page cache From: Sean Christopherson To: Andy Lutomirski , Jarkko Sakkinen Cc: X86 ML , Platform Driver , nhorman@redhat.com, npmccallum@redhat.com, LKML , Ingo Molnar , intel-sgx-kernel-dev@lists.01.org, "H. Peter Anvin" , Thomas Gleixner Date: Mon, 11 Jun 2018 08:12:48 -0700 In-Reply-To: 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 Sat, 2018-06-09 at 22:32 -0700, Andy Lutomirski wrote: > On Fri, Jun 8, 2018 at 10:22 AM 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). > > > > > > +/** > > + * sgx_einit - EINIT an enclave with the appropriate LE pubkey hash > > + * @sigstruct:         a pointer to the enclave's sigstruct > > + * @token:             a pointer to the enclave's EINIT token > > + * @secs_page:         a pointer to the enclave's SECS EPC page > > + * @le_pubkey_hash:    the desired LE pubkey hash for EINIT > > + */ > > +int sgx_einit(struct sgx_sigstruct *sigstruct, struct sgx_einittoken *token, > > +             struct sgx_epc_page *secs_page, u64 le_pubkey_hash[4]) > > +{ > > +       u64 __percpu *cache; > > +       void *secs; > > +       int i, ret; > > + > > +       secs = sgx_get_page(secs_page); > > + > > +       if (!sgx_lc_enabled) { > I'm confused.  What does this code path do?  It kind of looks like the > driver will load and just malfunction if we don't have write access to > the MSRs.  What is the intended behavior? The driver will also allow itself to load if the MSRs are read-only, but only if the MSRs' pubkey hash matches that of its launch enclave, i.e. the system has been pre-configured for the kernel's LE.  Whether or not that is a valid scenario is probably a different discussion. > > +               ret = __einit(sigstruct, token, secs); > > +               goto out; > > +       } > > + > > +       cache = per_cpu(sgx_le_pubkey_hash_cache, smp_processor_id()); > > + > > +       preempt_disable(); > > +       for (i = 0; i < 4; i++) { > > +               if (le_pubkey_hash[i] == cache[i]) > > +                       continue; > > + > > +               wrmsrl(MSR_IA32_SGXLEPUBKEYHASH0 + i, le_pubkey_hash[i]); > > +               cache[i] = le_pubkey_hash[i]; > > +       } > > +       ret = __einit(sigstruct, token, secs); > > +       preempt_enable(); > > + > > +out: > > +       sgx_put_page(secs); > > +       return ret; > > +} > > +EXPORT_SYMBOL(sgx_einit); > > +