Received: by 10.223.176.5 with SMTP id f5csp1889819wra; Wed, 31 Jan 2018 13:10:24 -0800 (PST) X-Google-Smtp-Source: AH8x226Y0xKTI/i7Gt3Uotzt52Nq5aQjymfBjFqbeyOfwb22B9g6Th8uUiJV+24K7N6gmElcOfkL X-Received: by 10.99.126.75 with SMTP id o11mr27289585pgn.97.1517433024370; Wed, 31 Jan 2018 13:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517433024; cv=none; d=google.com; s=arc-20160816; b=nAxe0L+xGSdZO/Ooy2tA0c/p/2OzjpvI6JQyBRPTeCmzq8YmbvEdKrvbg3WAILFdDg dKO2rS1eJbfd4Au/xTkz7iQiADRDSKrekNIMVGYwV1iXNUDiyGwLYztr4/RWiVvJ6kwA bFZh/PQZTj0RCYl/VUFzluHRF8Z8+cNVW1o0JMNclfIuAmWZ2aPw7r1PLBhtwHJf2crJ 7mWP9uvhXO2vjso08oYw7iTPv5nbBoXP1j8z/57zvTeQ7fY49zRy41YegTmsmqBGASm0 bsN4ttK9dQE+Vnikx9ykayNVWhTmOR1xBX5MxHYJTcYs3KO19vU1K4oWv0Jy4qWJaQv9 R6Kg== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=DE1VMXzsAkaf7tD+OhTPzmZC0jLAppwcX1Y9jgiomxw=; b=CBYdbE+/3WBJq7WWnYfj1otb9GGoUDqBew3pu0OGdyHNLusNIRc151BCA6EMNyLxa1 V1YN/divbXkH9WsnZ0siSYOR4raderTzTOQzBElsQXquavVAXA+g5ohKZ55uGKjT80CM 2ytL7r8V/yMdcIFHTT95ESJloDsYtD5Q2nGMaeMThvT19WPCzZ6fgUOi55yh9U4RPiY0 2oo6Lvf1BUKzgJ6Ea4FZy4YKb4EC5305AWFY/urEfiLxBxB9loanx0qVOCtIgXtiNPFS oXvcbeRqjRny6APQvuC6RYhSKU3Fg7gs0IY0bxkm3nn6GAS3rcdunQuUXUCHmljLdcJY cTNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ehzlej27; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si2277853pgc.831.2018.01.31.13.10.07; Wed, 31 Jan 2018 13:10:24 -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=fail header.i=@gmail.com header.s=20161025 header.b=Ehzlej27; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753142AbeAaVJk (ORCPT + 99 others); Wed, 31 Jan 2018 16:09:40 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39699 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752844AbeAaVJe (ORCPT ); Wed, 31 Jan 2018 16:09:34 -0500 Received: by mail-wr0-f194.google.com with SMTP id f6so14925074wra.6; Wed, 31 Jan 2018 13:09:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DE1VMXzsAkaf7tD+OhTPzmZC0jLAppwcX1Y9jgiomxw=; b=Ehzlej27vfTP1BvM2azeFySN5zJ9fV8KULOIYYJm5rUU0dhlJGo0DIL6ymSeuAy8Lw aadt7Er5zgaf4S+br+MFh4XjS81o740Ndnpz58LuBG2oeSnuYk5hL9NfC8pOvN3AW1xU 0hZXFkd/FqoxAZi4T+EipJ949F2htstMUEATVdmaLHPfzyJHzQOnyLcPm2PfIwOtPS88 70XhrG7sPVdWm/aId6wZijyh6lbbh93phE0NXI9d+GRrsp7y8AUk8z8lJssO4gIgO5QG pX4ewTRw9KVt8KBlgNzc+oDL311TGqtinAzcGKneqsPhRA7JY6QHAi3DP2t1YsC/qIYY y71w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DE1VMXzsAkaf7tD+OhTPzmZC0jLAppwcX1Y9jgiomxw=; b=Ony8pHDuOZC9QQlN9iAFGBFh5YtgsLvAcpy9pH1E1unfNN/rM7wIzG/hTgzzhmbtwu NXPjSllo2fFiYP8DkA3S+M2kYhxq+ZwMc7ZnKBTodJjJ7F0EC7IL9taylJUSmWgRoGuZ 7+iYMVDuOVXYzMWSTzKSaOcyOLRgWFG6/Rp/yRgfOhHktl/1gMt3bB5TXc6q9O8yf/hS qkRc1tZW3CthQrW4zUMbjv1kYlF/jsJU8MKXBiNALj3aGoFmL0xnL+hL4PBZ8Kcf38aM k7cDs1DqrDZ8s3KosdTO3fwkR7rcMKgXOieFsVixYVWke6D/0dGZO3wjafO/noZxERbS FUMw== X-Gm-Message-State: AKwxytdtTBA2ZRD1etyeR9lyfn5ZMDialwCUGq3R+aCnEMqDg4VY7FT6 LcHLkaiEH8sMKmWa0wWK9D6kMRHc X-Received: by 10.223.184.120 with SMTP id u53mr25254028wrf.99.1517432972792; Wed, 31 Jan 2018 13:09:32 -0800 (PST) Received: from donizetti.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id d5sm1064316wra.72.2018.01.31.13.09.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jan 2018 13:09:32 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , David Woodhouse , KarimAllah Ahmed , stable@vger.kernel.org Subject: [PATCH 2/3] KVM: VMX: introduce alloc_loaded_vmcs Date: Wed, 31 Jan 2018 16:09:23 -0500 Message-Id: <20180131210924.22812-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180131210924.22812-1-pbonzini@redhat.com> References: <20180131210924.22812-1-pbonzini@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/kvm/vmx.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ad6a883b7a32..ab4b9bc99a52 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3829,11 +3829,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); @@ -3852,6 +3847,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; @@ -7145,12 +7156,11 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu) { 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(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) + 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; -- 2.14.3