Received: by 10.223.176.5 with SMTP id f5csp2831452wra; Mon, 5 Feb 2018 10:34:49 -0800 (PST) X-Google-Smtp-Source: AH8x226xOMzczjeuQFKswo5tSdgmX8j9BEXBF6KCXma7M9GocBv/xaSXWGi8kOi4z3z3m7uhNuTj X-Received: by 10.98.35.14 with SMTP id j14mr49762606pfj.62.1517855689796; Mon, 05 Feb 2018 10:34:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517855689; cv=none; d=google.com; s=arc-20160816; b=uxVwJU9O+pLdW6dSfMtQDhoTP39gUzBqhqAS+GQ8wvJhVxZpoQKWTWDaI5xa61JmX7 I8noEx8CktfsWktPiUnY5ECWJ97DpmuLJX3rnhW1UQq3v3yLMqT0E8XwjfMd+bknSG13 1A5+jA46lgxBD8DDqk6i6Otz97qStKzTN2pjUQzZTkfhhGV/DzStoj5XtlWeh499s1LD Nxo3S6LZtu17fmc3ObSxV+2OpPfKdlZu/hjFGtbIEZc9BAR1AXSwPCrYhnvflYU5wOU0 IJ4DSTLOnI53OKMBiQ8tTbM+8Txn9LL9yz2U3yZsOrbqklBuTA6TEmSCdE0uy3XynBl5 YszQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8/c79yjkb+e4BWYTydubxG1iRcLOOUgQAv56Cx/mW2M=; b=H2NxrnHM/NMKGvB38M2f1QdeTMouOluOAzoCGSp2w8sxp3BwG5H92Uxr7FwF6dkXCv XAqTtEaimU2SKAmO5Hyou28oiFvEJiUxnwCzN22bGsuXMH4TcU9L+ZjijEqJVk9Y2+ah vTM6v4nsEVpCRsdPtFpC7tiQYTdjeHwyiSWAoVzYOmyz4cb/wSQHvYD9M0J4p9ZbbIyX VMFj8yVujTx+3fCK+8JgCb9xJOdUx5oxZ3WCUtX0mGfhvWOdUBu7uWdkUIddQgA0l63y HWfn72d5kMdX0LA0YweEVqyCvBgQ6uL05mhKRAuWw1MpH39XndWdZBk/mmG02FOINz5b TfoQ== 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 l6si5744541pgq.164.2018.02.05.10.34.35; Mon, 05 Feb 2018 10:34:49 -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; 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 S1753967AbeBEScM (ORCPT + 99 others); Mon, 5 Feb 2018 13:32:12 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:53090 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753833AbeBES0A (ORCPT ); Mon, 5 Feb 2018 13:26:00 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7107E1152; Mon, 5 Feb 2018 18:25:43 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Bonzini Subject: [PATCH 4.15 23/60] KVM: VMX: introduce alloc_loaded_vmcs Date: Mon, 5 Feb 2018 10:22:56 -0800 Message-Id: <20180205182214.882760776@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182213.902626065@linuxfoundation.org> References: <20180205182213.902626065@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini pbonzini@redhat.com commit f21f165ef922c2146cc5bdc620f542953c41714b 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 Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3829,11 +3829,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); @@ -3852,6 +3847,22 @@ static void free_loaded_vmcs(struct load 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; @@ -7145,12 +7156,11 @@ static int enter_vmx_operation(struct kv { struct vcpu_vmx *vmx = to_vmx(vcpu); struct vmcs *shadow_vmcs; + int r; - 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 = @@ -9545,13 +9555,11 @@ static struct kvm_vcpu *vmx_create_vcpu( 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) + err = alloc_loaded_vmcs(&vmx->vmcs01); + if (err < 0) goto free_msrs; - loaded_vmcs_init(vmx->loaded_vmcs); + vmx->loaded_vmcs = &vmx->vmcs01; cpu = get_cpu(); vmx_vcpu_load(&vmx->vcpu, cpu); vmx->vcpu.cpu = cpu;