Received: by 10.223.176.5 with SMTP id f5csp341448wra; Sat, 27 Jan 2018 00:51:23 -0800 (PST) X-Google-Smtp-Source: AH8x226w/HJOjK/jq90zdZdtOO9vr+xUJgJERvuNwKKTMlPC435qkZskEcYQqEx/kfwUJO3sSY8a X-Received: by 10.99.47.71 with SMTP id v68mr17052897pgv.176.1517043083668; Sat, 27 Jan 2018 00:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517043083; cv=none; d=google.com; s=arc-20160816; b=Cn9aBb4CIRQvTCF77EvpPrrVfY1p82TTJ/1rjX0u7pcl23LSVzsgBeheHZoaKqNo6d OJkoExT9WGyoKB4n4LUhMtDI4EyxGC+Fvcuw8+Zol4qCq8mHnX0Zc7BYnn9+zHG5QjCr mzBIPHII7/VH36c5+Gi2RvtcQQNLBG9Kpdr5f19TPnbvZCgbOnA07sRMDWzC3D5VUHD2 ZEqbqOO4bACA8PBZh6xQRj+1c0FCucraqsTbBs1230KXUlH8TO3RbqXa7nQaJmxTEnrm TF1nowhu522kwp1CSJtPwn4xNlgc6U9ANtbb3MoEOdsuurT4Ej45Pxy1fvFt62EuVEU8 p8uw== 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=jJw5HmCybwe8H8+Es0M6nBXOzB4f8OfITvWnJaN4nI8=; b=PNDOKbl0on+cJiRh856FlJtBhOA3B1FThA4xSBBElXjqb7zhVtbSxGK49rQ8MO2X+n O4z8jjpVL1wAw8n4XY+MPzUIf893IoNu96I1VooEIw2MUjzXV/4+x9Fh8GC8usMX3YxG UWkDQTl+vtemH2qXArNOCAwuPTOb6dgjeDvVf9bwkcWZEetFFBb3c8mKAGam5BSeMjNy zBx+3vkEPRLgmN4UK1XN3x7aF0iRT6JjA2oy9q7Zd6KNY6LKeSKL9vQYZT5LNUyudTgn NldtWBLbT3XGxGtlwWtSIxSmYdDKBbzdr7hpugUHFFcdxZtDvuGDWkY5KhZOVd84o9eT 83/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pbZYaUmu; 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 t62si246152pgt.130.2018.01.27.00.51.09; Sat, 27 Jan 2018 00:51:23 -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=pbZYaUmu; 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 S1752386AbeA0Iuh (ORCPT + 99 others); Sat, 27 Jan 2018 03:50:37 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:33135 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752268AbeA0Iue (ORCPT ); Sat, 27 Jan 2018 03:50:34 -0500 Received: by mail-wr0-f194.google.com with SMTP id s5so2431663wra.0; Sat, 27 Jan 2018 00:50: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=jJw5HmCybwe8H8+Es0M6nBXOzB4f8OfITvWnJaN4nI8=; b=pbZYaUmulIBCeYaYj26nocZ9h9G3NWxuveK5p0AhzW+X68VbIPOLFkIEytSxVNbtdF 8CzhIO+oGJsmwQ9Yzy8psa3WuHbiYWGyjvk9daWoxtbufmxGYKLo3DCwnICVu+j+hipw FU/YDnUZpJFSxwS6adK/UqN9Czf1i+V+4a4l2E/PhKrRn0RAfJjNHdIaYxUdH+cZOCuE qaAGajh6c0OOMu03rnaMeCSauZ0dEYAj6zZWzAsh+1+Ke3LjgW8NqvUUteY2Dcbobw/f qXtbHFaKcX09FarTGE30bJJQXK995QOKi7d7Gu45IbHXnlNQ/W0ZjUy8gZMNiQcQH7iJ ReAQ== 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=jJw5HmCybwe8H8+Es0M6nBXOzB4f8OfITvWnJaN4nI8=; b=MxuSXYXLbsZMgDg/ZGa0jrzFFlJNZutkWCnZrSueskrsttU+PyZr7vXXsT1qvShgAV 8wJoJtlMth6Xsf+FgdZAsAdRWAd3FrCeDbtwDB+RaiViddZGgtbb18RPE1gMc4YnPQ9H XcXPJHA99Ym8dt4ESnvKiaqOyMlSYrexxajREfSBEHopqQKwFrqgYCNDMc+44akjGae1 /mHx/Hvs8YBJ2p8VrZdD9r+qXSml6CngkiE4nezZzsq5xS0R7mhqvdRRlICiw6f3pO9i xuVeP9l/9OAxNmom0pc2lkNFrAuElY4Wik2weFhOL6TIomods6O5sD4S2WTvCN7/tVqk jJXQ== X-Gm-Message-State: AKwxytcB83Sgy7Tl3IXuXx1ihOjge8Y36Mp+Jq+7GmDgTxxqji8cMZBi AxB++F2aqtjiDJtcSMV41nt/5Dh1 X-Received: by 10.223.195.201 with SMTP id d9mr13383764wrg.134.1517043032844; Sat, 27 Jan 2018 00:50:32 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-230-124.clienti.tiscali.it. [78.12.230.124]) by smtp.gmail.com with ESMTPSA id c4sm7892161wrf.25.2018.01.27.00.50.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Jan 2018 00:50: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 Subject: [PATCH v2 2/3] KVM: VMX: introduce alloc_loaded_vmcs Date: Sat, 27 Jan 2018 09:50:26 +0100 Message-Id: <1517043027-7655-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1517043027-7655-1-git-send-email-pbonzini@redhat.com> References: <1517043027-7655-1-git-send-email-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. 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; -- 1.8.3.1