Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2674738imm; Sat, 9 Jun 2018 22:33:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIByl4inq548Dc+gkHMQXCFxPbTzuGYlt30XsVfkEIS+RaU+hk3b2XWcP7AV+vAfX7oZFfy X-Received: by 2002:a62:3f4f:: with SMTP id m76-v6mr12576874pfa.109.1528608836871; Sat, 09 Jun 2018 22:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528608836; cv=none; d=google.com; s=arc-20160816; b=dYJnJF/9yvfmkH7xAv29R+Keq27+a5ND+IYL3lS/H/KRvE5aX/mIVPM2Kd5zLvEOYQ nwV9boC8VMe1H9z2bPPhcXdWRyhfaiqYVu6wRZILlYXpOUMlyNExzni/qUsIS1c7sEUT eGD3W35IB8o2vwDYLgT0jlrhNB0/nfeU7rC0gzq9SZ6iy5uuOmg5cwQXrr7RHhVjjJRq Qq8N03tzV7fmyTo1LGmgIYw+XLsMyYM1zs5QM7RpIVNB3KLUTHP35KuKTGDK8IEK+QJO gYyHCHLHP18j9OQV0/Yx5RxebnJnEPzxPCPQKxhXQfpeCq3seZcoDrtWavgWiRv2yFkH IhxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=FFunNjd9xBklcsD4rNZjqynC9axIeNg2X0N3OBUFS6Q=; b=bZr+djwX6Z/G6+Ps5/cE98VDoUyB0m81eKvNHNlBomfdfniXA42XDIYJ3ahmXnfS+r p9pGCdqehAgiStzlsidn02RIR4tsLDQcFAdwkRZQvz3pAdNmmKZASdgwh+jzTPMCCJuC rpZTcHKtyZkrHhWcFBg09GRUJcdGrPnBvkVMRN2EkGyt6IGZhm2n/5Fj7O6xS2XeI7P+ zNe9Qq18N1IsDysiptkCLgoaBOgWapMmqwQn5z/Q7VqW9qSNnvZ0KyisomEfxZ7J6Pq3 wDzbyggUD+NlrC+c0K+eG2eTG/lZULg1BmAWMu7PtiySP6N/vDeoDvXpaoUiNtYWjGlT C8aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2OuMiWyr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92-v6si59412440pli.280.2018.06.09.22.33.42; Sat, 09 Jun 2018 22:33:56 -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; dkim=pass header.i=@kernel.org header.s=default header.b=2OuMiWyr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932124AbeFJFch (ORCPT + 99 others); Sun, 10 Jun 2018 01:32:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:43672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932086AbeFJFcf (ORCPT ); Sun, 10 Jun 2018 01:32:35 -0400 Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A696A208AD for ; Sun, 10 Jun 2018 05:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528608755; bh=+J5x0eICSCLh2R1EzuQmwIt2G+wxvbQvWCYGLBeq5yg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=2OuMiWyr3RarJeBBxJlivlu/bKKa/bNUdkfQTLLpB4RcVFpu3x8aFEejZTNhX93mP niOeTRSM/pKPBGqdbjC7Grl+Evli/pDnOl23MnsMDd8Y+5eNarycjjzvtnJB4SzfuD eW4/6O5ViOD/YbNeHRWiSHeQmh8pjpRMrXXptEdU= Received: by mail-wm0-f47.google.com with SMTP id r15-v6so9289421wmc.1 for ; Sat, 09 Jun 2018 22:32:34 -0700 (PDT) X-Gm-Message-State: APt69E26qHAh1MQWf/zXh0/0PsqZ0mgykkmUj6O0w9XCwzfYoufvfCIn EM7QyffoJACGB/pgfbXDtpj1YCRjfH/RIMwZWhtmlw== X-Received: by 2002:a1c:34c9:: with SMTP id b192-v6mr5467743wma.21.1528608753151; Sat, 09 Jun 2018 22:32:33 -0700 (PDT) MIME-Version: 1.0 References: <20180608171216.26521-1-jarkko.sakkinen@linux.intel.com> <20180608171216.26521-10-jarkko.sakkinen@linux.intel.com> In-Reply-To: <20180608171216.26521-10-jarkko.sakkinen@linux.intel.com> From: Andy Lutomirski Date: Sat, 9 Jun 2018 22:32:21 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [intel-sgx-kernel-dev] [PATCH v11 09/13] x86, sgx: basic routines for enclave page cache To: 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? > + 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); > +