Received: by 10.223.176.5 with SMTP id f5csp927356wra; Tue, 6 Feb 2018 09:36:13 -0800 (PST) X-Google-Smtp-Source: AH8x224+ePgCSznXZQokYkNFC/CRRbUHbNwrxFlh7cC+3NkFst9Gz5MgAgFGFQK/WEhPLYqmGxUT X-Received: by 10.98.58.204 with SMTP id v73mr3248461pfj.0.1517938572986; Tue, 06 Feb 2018 09:36:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517938572; cv=none; d=google.com; s=arc-20160816; b=DhvKxYyu4d6AiIvFMl1sZRzaqXhFFUsmYNIYvuOXxChYbEONqYBrgQ+uss3b/hi5Tq n5ee3O2hH/uIX3YdYb+XGXIsZWDH5UA6KmVX4fcsWJMYtmWyo1WKgBpf8y9ktU7V+/Oh V5F6y8l7dVAOA04wknP0ETmSq45br7enYSeHD+KR3Vg1DLQyCta1Wwg7uqGui7xQxPpc nPv92bywZ/L+6Vzz4khRFOEv4pVlocdXKdtEk3didN7O7JGY0zUgiAs8+TPohTG2my2e jsoXJZwaFSt9JjWXRECnBO+pk4E/KpJJw6OtxKLj0W7suvBl0xqBwjofbyX2soEV+Dyu 7Gmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=v/LgfVlkm+24JS3LGpkpIitibo9kPJy1ed/qoa/UM2M=; b=YzyrnMETCHGFFH2D7SeHxeIXAgGTaOFsun7g5Spd6uBCwcgcToK7f/0ZEog0l/FCVi DGIQA6nEiQTSZOwk6X7k2kxRj9YJCg1QkeKPoPr84eOK08MDgUVjHnqob5CUDi4f6UHH gbN+fvXVsi04h5J+wGgOWMOsLE4zi9H4GCKMl6G9qgzYLKPYdrnoeFG9KyOyDw87VpvK ahxUEjQXr6GAnpB9lv7j2MZp6jH3XM/7HkMl1LBz2YmqOt+r+xiK5BfTex3CJKL4wodS OT+gaTOtACUIr4xuboYZR1gXmUOBkMzuYpacA22WDZPgVRty4A+PXiq3DdnNeajfA4T4 vDpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=ZNWIWi5V; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5-v6si1455523pln.677.2018.02.06.09.35.58; Tue, 06 Feb 2018 09:36:12 -0800 (PST) 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; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=ZNWIWi5V; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753152AbeBFRdF (ORCPT + 99 others); Tue, 6 Feb 2018 12:33:05 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:6243 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753111AbeBFRcX (ORCPT ); Tue, 6 Feb 2018 12:32:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1517938342; x=1549474342; h=from:to:subject:date:message-id:in-reply-to:references; bh=v/LgfVlkm+24JS3LGpkpIitibo9kPJy1ed/qoa/UM2M=; b=ZNWIWi5VoeT31KYC0CYUzo/FO4kwZTkG9kNXbc8eH43ACNNDp807l0gx w1VzQgunuf3W9vFxnQiAq26Gv1uHxMMWOBedOGvoSC7JTMw+6Dz8yFQNm 8An1YiIc11s3b56E+s9XGnhHDavQMzbhSvKJOx2JvvvEeKE93uArp2v5d 8=; X-IronPort-AV: E=Sophos;i="5.46,469,1511827200"; d="scan'208";a="721415789" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Feb 2018 17:30:09 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w16HTl8R065697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 6 Feb 2018 17:29:49 GMT Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (localhost [127.0.0.1]) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w16HTlCP020674; Tue, 6 Feb 2018 17:29:47 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w16HTkIh020668; Tue, 6 Feb 2018 17:29:46 GMT From: David Woodhouse To: Paolo Bonzini , Jim Mattson , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, KarimAllah Ahmed , gregkh@linuxfoundation.org, stable@vger.kernel.org Subject: [PATCH 4/9] KVM: VMX: introduce alloc_loaded_vmcs Date: Tue, 6 Feb 2018 17:29:36 +0000 Message-Id: <1517938181-15317-5-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517938181-15317-1-git-send-email-dwmw@amazon.co.uk> References: <1517938181-15317-1-git-send-email-dwmw@amazon.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini Group together the calls to alloc_vmcs and loaded_vmcs_init. Soon we'll also allocate an MSR bitmap there. Cc: stable@vger.kernel.org # prereq for Spectre mitigation Signed-off-by: Paolo Bonzini (cherry picked from commit f21f165ef922c2146cc5bdc620f542953c41714b) Signed-off-by: David Woodhouse --- arch/x86/kvm/vmx.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 55b1474..8c562da 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3522,11 +3522,6 @@ static struct vmcs *alloc_vmcs_cpu(int cpu) 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); @@ -3545,6 +3540,22 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) WARN_ON(loaded_vmcs->shadow_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->shadow_vmcs = NULL; + loaded_vmcs_init(loaded_vmcs); + return 0; +} + static void free_kvm_area(void) { int cpu; @@ -6947,6 +6958,7 @@ static int handle_vmon(struct kvm_vcpu *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 @@ -6986,11 +6998,9 @@ static int handle_vmon(struct kvm_vcpu *vcpu) return 1; } - vmx->nested.vmcs02.vmcs = alloc_vmcs(); - vmx->nested.vmcs02.shadow_vmcs = NULL; - if (!vmx->nested.vmcs02.vmcs) + r = alloc_loaded_vmcs(&vmx->nested.vmcs02); + if (r < 0) goto out_vmcs02; - loaded_vmcs_init(&vmx->nested.vmcs02); if (cpu_has_vmx_msr_bitmap()) { vmx->nested.msr_bitmap = @@ -9111,17 +9121,15 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) if (!vmx->guest_msrs) goto free_pml; - vmx->loaded_vmcs = &vmx->vmcs01; - vmx->loaded_vmcs->vmcs = alloc_vmcs(); - vmx->loaded_vmcs->shadow_vmcs = NULL; - 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; -- 2.7.4