Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2331067imm; Thu, 7 Jun 2018 08:55:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJgPXWXRVnKcwR9R5mj8Sry1b5MkGeVyVFgx9dolM2hPbAiFXZHBWVYozfTZnxuafbkdli6 X-Received: by 2002:a62:86c3:: with SMTP id x186-v6mr2308625pfd.4.1528386910941; Thu, 07 Jun 2018 08:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528386910; cv=none; d=google.com; s=arc-20160816; b=q7tto/LjbBEfzbrxrD0VM4cnTzBaAZLe23rKZenbiQ3A5K2M1UJQhYbVOgooLUFF5h sKLwGQoi/LEYh3RccKBJEZ6+D1jpuV7Rmz+5PlcFqiKgESJDz/jT0m0OPVCzSRx9h4mM Lmx7sWIN5aXlX6xCmufa+Y+9Qy+C3Kc7uzMjXVlOBR9Ub7lQHed4eL6nBXHf848O4XKQ JWDNjxCMaOQLSkB8Bfgsnhh0LS0ar7zTZsT03ANi7Z1Q9O/AXUl+4JZawZhUT/4ehS3k qE7nTKsXcPikvRNuCP4jflI249ADxvscUHVDpAemDrezO2ejOihxM7NZuq5Xxd4gCTV6 PPpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=F6fKR/ZpnEtXnWtEGaTbfqnDRvN/ID02S9hV0HtT7yA=; b=FVnMKIWQDC0cWKjm+cZ1NZ9fxCJa3Xn3SBwp3FKXpWjgkkgQVamJyDygo2P8yDxArB mMmImIVCeZX8evZbKAI+0pPJb1i11OLQj6nH1JR/HpnpuyMVaFaL2ArHeK0XHbyCmeWX jAf2JfHgclpD12g+x8FBzbVEOMhShPWIxJ4mUJFFdU4HOyjXOIv+fzNJZdWw/WoANY12 C1bzdDJzhLoLj1VE3F0qNkfsVsKTMzSaqMWauiC3B2mGt44PFzUsOkoZm0fRu6TDD93y 4YijwuVA+yky4FVIU5bdP1FWwBQZ2HxFlohd4UUid/u5MnnEsblVsD4sOm3IYP57hrNc IKew== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18-v6si6900270pfg.343.2018.06.07.08.54.56; Thu, 07 Jun 2018 08:55:10 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934315AbeFGPx7 (ORCPT + 99 others); Thu, 7 Jun 2018 11:53:59 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40356 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753549AbeFGOel (ORCPT ); Thu, 7 Jun 2018 10:34:41 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbx-0005dI-20; Thu, 07 Jun 2018 15:09:57 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvaz-0002kN-5D; Thu, 07 Jun 2018 15:08:57 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "David Woodhouse" , "Greg Kroah-Hartman" , "Paolo Bonzini" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 053/410] KVM: VMX: introduce alloc_loaded_vmcs In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini commit f21f165ef922c2146cc5bdc620f542953c41714b upstream. Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also allocate an MSR bitmap there. Signed-off-by: Paolo Bonzini Signed-off-by: David Woodhouse Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: - No loaded_vmcs::shadow_vmcs field to initialise - Adjust context] Signed-off-by: Ben Hutchings --- --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2999,11 +2999,6 @@ static struct vmcs *alloc_vmcs_cpu(int c return vmcs; } -static struct vmcs *alloc_vmcs(void) -{ - return alloc_vmcs_cpu(raw_smp_processor_id()); -} - static void free_vmcs(struct vmcs *vmcs) { free_pages((unsigned long)vmcs, vmcs_config.order); @@ -3021,6 +3016,21 @@ static void free_loaded_vmcs(struct load loaded_vmcs->vmcs = NULL; } +static struct vmcs *alloc_vmcs(void) +{ + return alloc_vmcs_cpu(raw_smp_processor_id()); +} + +static int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) +{ + loaded_vmcs->vmcs = alloc_vmcs(); + if (!loaded_vmcs->vmcs) + return -ENOMEM; + + loaded_vmcs_init(loaded_vmcs); + return 0; +} + static void free_kvm_area(void) { int cpu; @@ -5965,6 +5975,7 @@ static int handle_vmon(struct kvm_vcpu * struct vmcs *shadow_vmcs; const u64 VMXON_NEEDED_FEATURES = FEATURE_CONTROL_LOCKED | FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX; + int r; /* The Intel VMX Instruction Reference lists a bunch of bits that * are prerequisite to running VMXON, most notably cr4.VMXE must be @@ -6004,10 +6015,9 @@ static int handle_vmon(struct kvm_vcpu * return 1; } - vmx->nested.vmcs02.vmcs = alloc_vmcs(); - if (!vmx->nested.vmcs02.vmcs) + r = alloc_loaded_vmcs(&vmx->nested.vmcs02); + if (r < 0) return -ENOMEM; - loaded_vmcs_init(&vmx->nested.vmcs02); if (enable_shadow_vmcs) { shadow_vmcs = alloc_vmcs(); @@ -7612,16 +7622,15 @@ static struct kvm_vcpu *vmx_create_vcpu( goto uninit_vcpu; } - vmx->loaded_vmcs = &vmx->vmcs01; - vmx->loaded_vmcs->vmcs = alloc_vmcs(); - if (!vmx->loaded_vmcs->vmcs) - goto free_msrs; if (!vmm_exclusive) kvm_cpu_vmxon(__pa(per_cpu(vmxarea, raw_smp_processor_id()))); - loaded_vmcs_init(vmx->loaded_vmcs); + err = alloc_loaded_vmcs(&vmx->vmcs01); if (!vmm_exclusive) kvm_cpu_vmxoff(); + if (err < 0) + goto free_msrs; + vmx->loaded_vmcs = &vmx->vmcs01; cpu = get_cpu(); vmx_vcpu_load(&vmx->vcpu, cpu); vmx->vcpu.cpu = cpu;