Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3390908pxk; Mon, 21 Sep 2020 12:24:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxn8zcSMWuSGuO3LD0al1ovdOwU0pN1oolE1FXOiNtjevHkoWm6Nf6+xPkaXRobOBDkdyI X-Received: by 2002:aa7:c148:: with SMTP id r8mr476676edp.210.1600716252363; Mon, 21 Sep 2020 12:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600716252; cv=none; d=google.com; s=arc-20160816; b=wsO8VZsPJm3iZqu4vkpFoEfs8lU+hE+yXfZv6n01Bep85aZ1lPUVF/8fU+C25xAUT4 mCZkYlB5UcK7lVfzZEOMTAYy4Wh848jgYnZuut2g/tEAfMLxwcJhBIhkAy8/ROrvWusJ REqg737W9UIo/oM51dVP8upYnmt0yQSyIp3sR8U7DdIyS6dfvM7qa/Zv9xfKqvczOAht CSMay0vcPXLRnZGnxBVbWbjMeFNbAj/eeyRZaNU85SmCED8RYaTBqRufwgzouS2IdwZ0 aT6MMTbbCcEef0Q678wgnuVf+O1An0FxyUmxanLTlwIdZLuNQQqaWzHEYkOl5Q68u08p o+XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=jhwRiUTSfyk5+dRr2PJ9+5NHOSC4MucnlRcHhAO+xTo=; b=d7N5YVo3PTVWY7kcUiil6kjM0uSNgyWm8L0U9h6T1CunAVXox+qjEnC7WwlOsqtZmv JsGDChfJ8FzHyfljUybN0mPvoYA1up+ECO3pSpSyU33IJtwYmBAxQBfLTCyObofOlvI1 2RLu93ezovSb8GP1ctA44we9JYPxRcAuvpwr12uLM7HFa1JvkTdinSCsC9a3FbAuIyu+ Yj2tV3pczXZL+9dPGo3m5eVeVyoXv265Cs6loJ7C3e7jMuUH7kE2Qly5GLOnW0x6ELpm Vsz/82uZ7I2FQ5TlMqB/5Utenx1jDbZKVLz8DFFK3vtrFK9uhFAbv3Sk7eOdGo0pDdTi gaMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id g23si9041668edy.179.2020.09.21.12.23.47; Mon, 21 Sep 2020 12:24:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728015AbgIUTWb (ORCPT + 99 others); Mon, 21 Sep 2020 15:22:31 -0400 Received: from mga17.intel.com ([192.55.52.151]:35794 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbgIUTWb (ORCPT ); Mon, 21 Sep 2020 15:22:31 -0400 IronPort-SDR: giGhE/KQl2w2rZycbGWUp/zscbbJskczNWyzkQfcQSLSnM1mua69Ieja7cKJSfbvbZP3HbXo9v Ykof7L/HrHbg== X-IronPort-AV: E=McAfee;i="6000,8403,9751"; a="140465197" X-IronPort-AV: E=Sophos;i="5.77,287,1596524400"; d="scan'208";a="140465197" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 12:22:30 -0700 IronPort-SDR: BUKjSoNgefI449QJY3EW3BUJ/htJui4FVq98QuAEvvMfVxQ3ruEl4+7FY+AXCmtgIuLb0CSa4V GjzvMCfGkWjg== X-IronPort-AV: E=Sophos;i="5.77,287,1596524400"; d="scan'208";a="454191063" Received: from tsenx-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.44.83]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 12:22:22 -0700 Date: Mon, 21 Sep 2020 22:22:20 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: Borislav Petkov , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Jethro Beekman , Haitao Huang , Chunyang Hui , Jordan Hand , Nathaniel McCallum , Seth Moore , Darren Kenny , Suresh Siddha , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v38 14/24] x86/sgx: Add SGX_IOC_ENCLAVE_INIT Message-ID: <20200921192220.GC53597@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> <20200915112842.897265-15-jarkko.sakkinen@linux.intel.com> <20200921173514.GI5901@zn.tnic> <20200921181021.GA24481@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921181021.GA24481@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 11:10:21AM -0700, Sean Christopherson wrote: > On Mon, Sep 21, 2020 at 07:35:14PM +0200, Borislav Petkov wrote: > > On Tue, Sep 15, 2020 at 02:28:32PM +0300, Jarkko Sakkinen wrote: > > > +static int sgx_einit(struct sgx_sigstruct *sigstruct, void *token, > > > + struct sgx_epc_page *secs, u64 *lepubkeyhash) > > > +{ > > > + int ret; > > > + > > > + preempt_disable(); > > > + sgx_update_lepubkeyhash_msrs(lepubkeyhash, false); > > > > So this will update the cached copies *and* the MSRs itself if what's > > cached is stale... > > > > > + ret = __einit(sigstruct, token, sgx_get_epc_addr(secs)); > > > + if (ret == SGX_INVALID_EINITTOKEN) { > > > > ... so why would it return this error here? > > > > Definition of this error says: > > > > * %SGX_INVALID_EINITTOKEN: EINITTOKEN is invalid and enclave signer's > > * public key does not match IA32_SGXLEPUBKEYHASH. > > > > when you just updated them?! > > > > > + sgx_update_lepubkeyhash_msrs(lepubkeyhash, true); > > > > So why force a second time? > > The LE pubkey hash MSRs are special snowflakes. They get reset to Intel's > default key on any loss of EPC, e.g. if the system does a suspend/resume > cycle. The approach we took (obviously) is to assume the kernel's cache can > be stale at any given time. The alternative would be to try and track loss > of EPC conditions and emulate the reset, but that's a bit dicey on bare > metal as any missed case would hose SGX, and in a VM it's theoretically > impossible to handle as a particularly unhelpful VMM could emulate loss of > EPC at will. > > Yes, this need a big fat comment. Thanks, please provide one :-) /Jarkko