Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4069613pxk; Tue, 22 Sep 2020 09:31:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsxwkr2USbfdfjHCz7oPf1PhivXO1spy2uHBqLfXkXh4Hyoeaf15mnkDLFR/RxpDmaxjrI X-Received: by 2002:a17:906:8508:: with SMTP id i8mr6127970ejx.390.1600792297452; Tue, 22 Sep 2020 09:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600792297; cv=none; d=google.com; s=arc-20160816; b=CFIsnIaYiE/bqO1FC4fcnL9mhCXELZGO9MBbBLHHWPyQM2Td8MZ8pvVFofAMECsIhl z5pi+/yRFnKfC+OAArLpKNFRVrdJuEhUX44dQx3+oXM8pF5m60Hdi9EiOus7NQxXM3GE YjLniz+SO/53jVG0aQNOnUc4ebKjnvedQHwJV3GynR3YgN9mcI6zOD/aIN5rdEu9wAsg zKRs0cZb9Kudq38XzGID3ZXbUVZr1NlSGr5Q9fPRtQCAYKqTGXxM6YXDJStw/GfYD0Kb 91hadA3a0aAkSVkVBm+iI1vfQbyyqy8Zq0mqQI/6COacki2YfqWn+rbZ3o7Y1MW4J7F7 uW6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=Zec1ct60VNgPosbkAyAn+jif3+JHVU5FHVdD6yPYIAs=; b=qWsLSjo1vPzzDjWvpCvQPSIG9h8joNQ4OdIo6F2idLP4huL3a2SO9Il345Kkjw9YzO YaE5zpxZRexjjb1OpaNegOv+FmCgIy76/q00zH0VqdCe4Hmouj8uwDYofq0OYxpFnyZw WI0wzJKv46sBgu3RxopUv+WVwfCrB2MXItiQ6wplsO/jXfzru27fe28D+rpUT9pc/5HT rCwt8Bkh7DXRnqqo/I1M77GEmEqBuBLHPLusb6mv3k4FVinhFODRNPri2jIp6Usda6La 8XAuR52sgEIGeLUp3bWBmTj8JziNMnXu+pM4KQ7v6cxkvVZgFLp6bmE5qJLjB2pnN3zK GOXA== 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 y11si11267738edm.191.2020.09.22.09.31.13; Tue, 22 Sep 2020 09:31:37 -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 S1726623AbgIVQ3r (ORCPT + 99 others); Tue, 22 Sep 2020 12:29:47 -0400 Received: from mga07.intel.com ([134.134.136.100]:3474 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbgIVQ3r (ORCPT ); Tue, 22 Sep 2020 12:29:47 -0400 IronPort-SDR: QtGKYdt4mk0Zzm4CKdhbk0RJxFuyWcUqZg90pFQqwtFrD3aJsc0TkF3Bhr2HHW/Wj7BSJWWE4N deQCV+kMu54A== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="224796412" X-IronPort-AV: E=Sophos;i="5.77,291,1596524400"; d="scan'208";a="224796412" 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/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 09:29:45 -0700 IronPort-SDR: +aeJPR2XrCKLGqGj8JJVXa4YiaebSvPnxQMdwGKoIAIIm/kaeKLAXe7lM19L1OQTd9WisYrRdl vXhvgTMRbPUQ== X-IronPort-AV: E=Sophos;i="5.77,291,1596524400"; d="scan'208";a="454549490" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 09:29:45 -0700 Date: Tue, 22 Sep 2020 09:29:44 -0700 From: Sean Christopherson To: Jethro Beekman Cc: Borislav Petkov , Jarkko Sakkinen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, 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: <20200922162944.GA30874@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> <20200921182753.GK5901@zn.tnic> <20200921191658.GA24823@linux.intel.com> <20200922082918.GC22660@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 02:56:19PM +0200, Jethro Beekman wrote: > On 2020-09-22 10:29, Borislav Petkov wrote: > > On Mon, Sep 21, 2020 at 12:17:00PM -0700, Sean Christopherson wrote: > >> That was effectively my original suggestion as well, check for a stale cache > >> and retry indefinitely. I capitulated because it did feel like I was being > >> overly paranoid. I'm obviously ok going the retry indefinitely route :-). > >> > >> https://lkml.kernel.org/r/20180904163546.GA5421@linux.intel.com > > > > Right, so if EINIT is so expensive, why does it matter how many cyccles > > WRMSR has? I.e., you don't really need to cache - you simply write the 4 > > MSRs and you're done. Simple. Hmm, true. The 1200+ cycles to write the hash MSRs (they're 3x slower than other MSRs) seems scary, but compared to the 60k cycles it really doesn't matter. > > As to "indefinitely" - caller can increment a counter which counts > > how many times it returned SGX_INVALID_EINITTOKEN. I guess when it > > reaches some too high number which should not be reached during normal > > usage patterns, you can give up and issue a message to say that counter > > reached max retries or so but other than that, you should be ok. That > > thing is running interruptible in a loop anyway... > > I don't see why you'd need to retry indefinitely. Yes the MSRs may not match > the cached value for “reasons”, but if after you've written them once it > still doesn't work, clearly either 1) an “unhelpful” VMM is actively messing > with the MSRs which I'd say is at best a VMM bug or 2) there was an EPC reset > and your enclave is now invalid anyway, so no need to EINIT. Ah, also true, I overlooked that an MSR reset would also kill the enclave. So yeah, this can be simplified to: if (SGX_LC) { for (i = 0; i < 4; i++) wrmsrl(...); } return __einit(...);