Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1898434imm; Mon, 3 Sep 2018 12:21:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ5FqBMrIBektzKsdcVxs3DV1J9CicGQZBHG2eeCu5DPasuYdOR4cVXLZ2tBmD/Qa2PZuXS X-Received: by 2002:a63:c046:: with SMTP id z6-v6mr27806179pgi.114.1536002487627; Mon, 03 Sep 2018 12:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536002487; cv=none; d=google.com; s=arc-20160816; b=TP64eCIadCiA1TFTNSyOkvNCemZSgBm7EO0Gy/iEGKBDjm+oppJpLWulL74CNo6ZN9 SR+K24EPqA9r6FBirYKAWmXawLQxQ2t3MvshY4JMs0enwk1fbKH6dWmduJ2zVyI+tp5M krcy0Q16Zrld5hXXR/PcF5b+S6BuNb0r5o9kTA+mZc1wtRMjjHXvq4xyQg32y+VeLV1/ xUNIJujH6ohS0EPvu8R7ecqq2gtLVrbCtI6MqT+qrY5cN4GmZtYhLzV8RcmeraZg7wZJ MjI4qj5xeC6LHaP6CNn46iEoy5B24BupQZNnzUKGjWREyliJiscTlwW/MwXaMTyi01aS hd7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=wwk40Kaa5fmbSUTjRSDE8wYecvLMfX7lHJR9EIPutog=; b=dAe9T/pemGQHBCDflI2XTcMcELov3q2q119Vsl31Y4Ojsr4+4l6qKGk/3N6muSsIHd gLO9FRxHwRTAp1zTWmIStzct0GQN7SG1vGe6s7IyDlEVCfYyATZKJqIRs0+BU9sHtJeS 88PnHlVEKlHMIO7DhCYBojcKApJAFNe09HTGIcsVlLycUyKY6XJqLutCt42gy7lt7F0h IpwUlC1o8L5A5v1PcaPABeIPLtFG0fPgQHZr6er6ik0d4zCpC/9+VlA/xz8SwIuRqCeB wKcuTj0PAsvfmiQ3f/KTTxfK5Q5xumRiGgux4G/Y8nISIMlMoeciHk450/anPvbW6TA5 O6qg== 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 m39-v6si18380429plg.486.2018.09.03.12.21.12; Mon, 03 Sep 2018 12:21:27 -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 S1728339AbeICXlI (ORCPT + 99 others); Mon, 3 Sep 2018 19:41:08 -0400 Received: from mga17.intel.com ([192.55.52.151]:15605 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727955AbeICXlI (ORCPT ); Mon, 3 Sep 2018 19:41:08 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Sep 2018 12:19:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,326,1531810800"; d="scan'208";a="80568278" Received: from fonsecan-mobl.ger.corp.intel.com (HELO localhost) ([10.249.36.49]) by orsmga003.jf.intel.com with ESMTP; 03 Sep 2018 12:19:27 -0700 Date: Mon, 3 Sep 2018 22:19:26 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: "Huang, Kai" , "platform-driver-x86@vger.kernel.org" , "x86@kernel.org" , "nhorman@redhat.com" , "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "suresh.b.siddha@intel.com" , "Ayoun, Serge" , "hpa@zytor.com" , "npmccallum@redhat.com" , "mingo@redhat.com" , "linux-sgx@vger.kernel.org" , "Hansen, Dave" Subject: Re: [PATCH v13 10/13] x86/sgx: Add sgx_einit() for initializing enclaves Message-ID: <20180903191926.GC13497@linux.intel.com> References: <20180827185507.17087-1-jarkko.sakkinen@linux.intel.com> <20180827185507.17087-11-jarkko.sakkinen@linux.intel.com> <1535406078.3416.9.camel@intel.com> <20180828070129.GA5301@linux.intel.com> <105F7BF4D0229846AF094488D65A09893541037C@PGSMSX112.gar.corp.intel.com> <20180831121645.GA18075@linux.intel.com> <20180831181509.GB21555@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180831181509.GB21555@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 11:15:09AM -0700, Sean Christopherson wrote: > On Fri, Aug 31, 2018 at 03:17:03PM +0300, Jarkko Sakkinen wrote: > > On Wed, Aug 29, 2018 at 07:33:54AM +0000, Huang, Kai wrote: > > > [snip..] > > > > > > > > > > > > > > > @@ -38,6 +39,18 @@ static LIST_HEAD(sgx_active_page_list); static > > > > > > DEFINE_SPINLOCK(sgx_active_page_list_lock); > > > > > > static struct task_struct *ksgxswapd_tsk; static > > > > > > DECLARE_WAIT_QUEUE_HEAD(ksgxswapd_waitq); > > > > > > +static struct notifier_block sgx_pm_notifier; static u64 > > > > > > +sgx_pm_cnt; > > > > > > + > > > > > > +/* The cache for the last known values of IA32_SGXLEPUBKEYHASHx > > > > > > +MSRs > > > > > > for each > > > > > > + * CPU. The entries are initialized when they are first used by > > > > > > sgx_einit(). > > > > > > + */ > > > > > > +struct sgx_lepubkeyhash { > > > > > > + u64 msrs[4]; > > > > > > + u64 pm_cnt; > > > > > > > > > > May I ask why do we need pm_cnt here? In fact why do we need suspend > > > > > staff (namely, sgx_pm_cnt above, and related code in this patch) here > > > > > in this patch? From the patch commit message I don't see why we need > > > > > PM staff here. Please give comment why you need PM staff, or you may > > > > > consider to split the PM staff to another patch. > > > > > > > > Refining the commit message probably makes more sense because without PM > > > > code sgx_einit() would be broken. The MSRs have been reset after waking up. > > > > > > > > Some kind of counter is required to keep track of the power cycle. When going > > > > to sleep the sgx_pm_cnt is increased. sgx_einit() compares the current value of > > > > the global count to the value in the cache entry to see whether we are in a new > > > > power cycle. > > > > > > You mean reset to Intel default? I think we can also just reset the > > > cached MSR values on each power cycle, which would be simpler, IMHO? > > > > I don't really see that much difference in the complexity. > > Tracking the validity of the cache means we're hosed if we miss any > condition that causes the MSRs to be reset. I think we're better off > assuming the cache can be stale at any time, i.e. don't track power > cyles and instead handle EINIT failure due to INVALID_TOKEN by writing > the cache+MSRs with the desired hash and retrying EINIT. EINIT is > interruptible and its latency is extremely variable in any case, e.g. > tens of thousands of cycles, so this rarely-hit "slow path" probably > wouldn't affect the worst case latency of EINIT. Sounds a good refiniment. Pretty good solution to heal from host sleep on the guest VM and then there is no need for driver changes. /Jarkko