From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarkko Sakkinen Subject: Re: [intel-sgx-kernel-dev] [PATCH 08/10] kvm: vmx: add guest's IA32_SGXLEPUBKEYHASHn runtime switch support Date: Mon, 15 May 2017 15:46:22 +0300 Message-ID: <20170515124622.piupyk57vjdoppl5@intel.com> References: <20170508052434.3627-1-kai.huang@linux.intel.com> <20170508052434.3627-9-kai.huang@linux.intel.com> <58dcdb2d-6894-b0a3-8d6f-2ab752fd6d22@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "Huang, Kai" , kvm list , Radim Krcmar , haim.cohen@intel.com, "intel-sgx-kernel-dev@lists.01.org" , Paolo Bonzini To: Andy Lutomirski Return-path: Received: from mga11.intel.com ([192.55.52.93]:54421 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750968AbdEOMq0 (ORCPT ); Mon, 15 May 2017 08:46:26 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Thu, May 11, 2017 at 08:28:37PM -0700, Andy Lutomirski wrote: > [resending due to some kind of kernel.org glitch -- sorry if anyone > gets duplicates] > > On Thu, May 11, 2017 at 5:32 PM, Huang, Kai wrote: > > My current patch is based on this assumption. For KVM guest, naturally, we > > will write the cached value to real MSRs when vcpu is scheduled in. For > > host, SGX driver should write its own value to MSRs when it performs EINIT > > for LE. > > This seems unnecessarily slow (perhaps *extremely* slow) to me. I > would propose a totally different solution: > > Have a percpu variable that stores the current SGXLEPUBKEYHASH along > with whatever lock is needed (probably just a mutex). Users of EINIT > will take the mutex, compare the percpu variable to the desired value, > and, if it's different, do WRMSR and update the percpu variable. This is exactly what I've been suggesting internally: trap EINIT and check the value and write conditionally. I think this would be the best starting point. /Jarkko