Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp489572imm; Fri, 31 Aug 2018 05:57:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYkPgMaoCwCS+Ylm0zs/xpWoYlKXa5MjlcNTDEPQva8c6xaYcFYMPb8XuA9s6eEb/hukCNc X-Received: by 2002:a17:902:6946:: with SMTP id k6-v6mr15339721plt.268.1535720249699; Fri, 31 Aug 2018 05:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535720249; cv=none; d=google.com; s=arc-20160816; b=BKEAKN3//nnnoMKAeGOOstPUg93FD0YlwuLFmFtnC32TNOuG7XSPrEgF+WJv7kH503 4U/1koXUR/lrLuurttLMKJJZTzD8tOUYp4ZadpfZOTfds3FL/8Q1pDZhTdnBxxKpjP1X G7Hj0aUNyZ8o9PNljHqt3X5Je3sGVjuBlM2GEyspmOAKiM0tqccrAovKuq+YWl+ejBqq yMXgx3J5h8G8XzfCRYaELmnX7cTnBf/fQTFjv3Bx+O/JDrDSm7kwKXJO/xzuCzUL35cX aw3EXLt9W0zwy9WwSn7ETeCHFkaxCbR51n5C0V3vZPgTqJ4YhT4/OlLY2zEYfPkxqArk YhDA== 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=4iD5ZMiv302JQ2dk9bozt6Zu8Oea+3wx+CYQKUZytxI=; b=gAU6+fJCxJN47gxyK4QzSxb7OIr2uk+JTimrQ7hYEy7TA+OUFdtLGEwJ79ivPfP9xA U9xnB+fZOWzWqxzSLmj8AvCZr9BOkLuzi4xyUhLMXupydkuPMTntDhVhcGit7+Mdqp0m KEnrD+dH9t6b8vMAZ/tJDwLaa1aniBEx6I9sdt8KmAra3zCYaeLrPC26eQaMqfzD5OId oFbAqJQJh0F8qI5XzDgCGdEezEh/FSiSaZXXZcU2B+SnMfqePm4BYi4kuq/OuwDMgTcG yqadgyDaDh++sCKqqozEqfhPRJzcPy9qMhRvSzyrVEb9hTC7IgKhnffBz4lRn/ZYoyaD Fpyw== 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 l2-v6si9978356pfb.69.2018.08.31.05.57.15; Fri, 31 Aug 2018 05:57:29 -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 S1728290AbeHaQYV (ORCPT + 99 others); Fri, 31 Aug 2018 12:24:21 -0400 Received: from mga12.intel.com ([192.55.52.136]:21175 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727942AbeHaQYV (ORCPT ); Fri, 31 Aug 2018 12:24:21 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Aug 2018 05:17:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,311,1531810800"; d="scan'208";a="84976574" Received: from dbarealo-mobl.ger.corp.intel.com (HELO localhost) ([10.252.36.33]) by fmsmga004.fm.intel.com with ESMTP; 31 Aug 2018 05:17:04 -0700 Date: Fri, 31 Aug 2018 15:17:03 +0300 From: Jarkko Sakkinen To: "Huang, Kai" Cc: "platform-driver-x86@vger.kernel.org" , "x86@kernel.org" , "nhorman@redhat.com" , "linux-kernel@vger.kernel.org" , "Christopherson, Sean J" , "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: <20180831121645.GA18075@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <105F7BF4D0229846AF094488D65A09893541037C@PGSMSX112.gar.corp.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 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. > I think we definitely need some code to handle S3-S5, but should be in > separate patches, since I think the major impact of S3-S5 is entire > EPC being destroyed. I think keeping pm_cnt is not sufficient enough > to handle such case? The driver has SGX_POWER_LOST_ENCLAVE for ioctls and it deletes the TCS entries. > > This brings up one question though: how do we deal with VM host going to sleep? > > VM guest would not be aware of this. > > IMO VM just gets "sudden loss of EPC" after suspend & resume in host. > SGX driver and SDK should be able to handle "sudden loss of EPC", ie, > co-working together to re-establish the missing enclaves. This is not about EPC. It is already dealt by the driver. I'm concerned about the MSR cache as it would mess up. But I guess this logic is part of the KVM code anyway now that I think more of it. /Jarkko