From: Brijesh Singh Subject: Re: [Part1 PATCH v6 16/17] X86/KVM: Decrypt shared per-cpu variables when SEV is active Date: Tue, 17 Oct 2017 10:42:45 -0500 Message-ID: <35973f2a-664e-97e8-3dba-00db5f8d9719@amd.com> References: <20171016153423.2980-1-brijesh.singh@amd.com> <20171016153423.2980-17-brijesh.singh@amd.com> <20171016222416.x26tp222x2ox3tkz@pd.tnic> <20171017082020.ctgjuo4xcvsaitdf@pd.tnic> <57ef6c36-1708-56f2-b0ac-ea2267f6aa9d@amd.com> <20171017133555.de4omyuoveaijkk6@pd.tnic> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: brijesh.singh@amd.com, x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Tom Lendacky , linux-kernel@vger.kernel.org, kvm@vger.kernel.org To: Borislav Petkov Return-path: In-Reply-To: <20171017133555.de4omyuoveaijkk6@pd.tnic> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 10/17/17 8:35 AM, Borislav Petkov wrote: ... >> The second call is for UP cases. The kvm_smp_prepapre_boot_cpu() is >> called only when CONFIG_SMP is enabled. Am I missing something ? > Yes, you are. > > kvm_guest_init() gets called unconditionally from setup_arch(). But then > you said kvm_guest_init() is called before setup_per_cpu_areas() so why > do you need that call there at all? percpu areas are not ready yet, what > makes them ready in the UP case? I believe in the case of UP,  the setup_per_cpu_areas() does not do anything special for the static per-cpu variables hence its fine to access them. If we look at kvm_guest_init() then it directly jumps to kvm_guest_cpu_init() in UP case. But in the case of CONFIG_SMP the kvm_guest_cpu_init() is called from the kvm_smp_prepare_boot_cpu(). > IOW, this sev_map_percpu_data() needs to happen only once, during boot. > So call it only once by finding the right spot and not by adding a > second call for the UP case. > > AFAICT, it looks the easiest if you put it in kvm_guest_cpu_init() and > do something like: > > if (smp_processor_id() == boot_cpu_data.cpu_index) > sev_map_percpu_data(); > > ... > OK, this goes back to your initial feedback during RFC v3 where I tried to do similar thing. But since sev_map_percpu_data() uses __init functions hence we need to mark the kvm_guest_cpu_init() as __ref but you didn't like the idea and asked me to call the sev_map_percpu_data from kvm_smp_prepare_boot_cpu() which is already __init.