From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [intel-sgx-kernel-dev] [PATCH 08/10] kvm: vmx: add guest's IA32_SGXLEPUBKEYHASHn runtime switch support Date: Tue, 16 May 2017 16:23:43 +0200 Message-ID: <73284fac-7269-fc79-fc07-4916606776ba@redhat.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> <20170515124622.piupyk57vjdoppl5@intel.com> <478d9303-00b7-4f29-6124-0c1433851952@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: kvm list , Radim Krcmar , haim.cohen@intel.com, "intel-sgx-kernel-dev@lists.01.org" To: "Huang, Kai" , Jarkko Sakkinen , Andy Lutomirski Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60130 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752248AbdEPOYG (ORCPT ); Tue, 16 May 2017 10:24:06 -0400 In-Reply-To: <478d9303-00b7-4f29-6124-0c1433851952@linux.intel.com> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 16/05/2017 01:56, Huang, Kai wrote: >>> >>> 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. > > OK. Assuming we are going to have this percpu variable for > IA32_SGXLEPUBKEYHASHn, I suppose KVM also will update guest's value to > this percpu variable after KVM writes guest's value to hardware MSR? And > host (SGX driver) need to do the same thing (check the value and write > conditionally), correct? The percpu variable is just an optimization. If EINIT is not performance critical, you could even do the WRMSR unconditionally; what matters is having a mutex that covers both WRMSR and EINIT. Thanks, Paolo