Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp716326pxb; Fri, 8 Jan 2021 16:53:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb3gJnMI8OR3grrzaQF8UzbtVhhx3tntVLT3LEcq9+i/itXehVsPbUcX84xUJ4gouapupf X-Received: by 2002:a17:906:85cf:: with SMTP id i15mr4515325ejy.373.1610153629560; Fri, 08 Jan 2021 16:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610153629; cv=none; d=google.com; s=arc-20160816; b=D+ZYDLgTPePIHMs/63ZnL2+auioUZL+jN9M86GIWm96mHk9Ve22K7kiP4qjgpo84tC ituaMmQcv9/tCfiArX41U9rPFIq7VL1Al3X8gyQbUylOjc4ydOwZ7syiuH4xmM3fFX2j zgsCGwIyopvg4FnIohYi8U7cVDDYdfpvqSFzpQ3TETpGE1438Xi45GRxBT70edvDrztR +0RUxLYfFtklZmU41fJo+1nqp3nLxu0qBFau8fS6kay43olzNpxuIOEINhQH6gvHyKy6 a9XZ3HzaJeJ3+zCAoioq/BTJ50Q2o+1lokuVypbPdA48wiwPU2UHNVeVy0Jik2M0opno c8cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:sender:dkim-signature; bh=GZIGOjVPda+c+O82UamW1h7IewucBItkY9B2sexVha8=; b=Mrv88wWlW59xPnzjLHfX4JP9jPbmMze92F9+VHPgoUYXU/YvSpr9QoC81r9Mn9bnP2 8TaqjVMXdnNYR1IzbLSrZrTIO/7AQRUOIXwjZ1ZrscU6NDzub6Iw+yZtB6bOhul2j5dQ Eew5ZHmccAhxSvDBQsIcRs88KHHiq/QAdC1zfqwmXZcuhe4r4Xtf046mgQfFZiLhmiO0 AsUiqvFq8VSSPWFzVurjIqCvE0rDoGFtO0kHN2YzU9ElU2wDBtbgTIZ2MIK3iOC1AeCH oZjko/KmNo41tZaUJxCnLuB8F4secJ7QIBhhron+AwQENdTehOTMR8v3x02V1mq+Wb0I ezUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nDFk3WbL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o25si4018273ejg.728.2021.01.08.16.53.26; Fri, 08 Jan 2021 16:53:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nDFk3WbL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbhAIAtk (ORCPT + 99 others); Fri, 8 Jan 2021 19:49:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbhAIAtg (ORCPT ); Fri, 8 Jan 2021 19:49:36 -0500 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD6F2C0617A3 for ; Fri, 8 Jan 2021 16:48:00 -0800 (PST) Received: by mail-qv1-xf4a.google.com with SMTP id eb4so9431004qvb.21 for ; Fri, 08 Jan 2021 16:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=GZIGOjVPda+c+O82UamW1h7IewucBItkY9B2sexVha8=; b=nDFk3WbLzXD2CBf61X7QA3DO3OSq5V59DWDGCi6i+KTqpxvu+JJDnXm3xHU+hr6Bz7 xmHonSFW0NOY6zZ0SktkyIxYosOmBgSbl/Dr6AYd4lPimUvBH0Td6tMW8DMG31TkLHom VpfhFYL7V+SgXAC7JTaCjbbSkEdKeUP1dB/tf5vCInrJcPRkNI96DOrFb8/8Jla1CzGm UqSF530amN0qmVtPLEIW8GP8DnKTrfea+KCeyDlbtCykDakVgdLpVki40DgzRfjcw+r6 yBSwX8nA8lx1SIq+Z2Sv4b5t8qHskOQUVQLzhqi7JydBbrPOKPCubmhhK/fizNOJsCo1 ioIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=GZIGOjVPda+c+O82UamW1h7IewucBItkY9B2sexVha8=; b=knjqkG0I1ddw48iJEqj9Kx7l8kOOiIMkoj7XoskvsXDLhII0rEljYsyoc19JS3NPvd jWjcL17QDlmAJ6UMk62/+cpU6XwOkt2OpOyFYgrC+czA/cpshPTK1higmOu4NXlZq/Td OeQUUSI3QlhCROccrTThMRD3hmyvEUO01YPV51GwVoMvXQ++OvvNLwweSKDshw2RAmll dML1RrW2BD4lMOq9My6bjTHVTGCQeHTHpfLFQVK3+SlFTUH4YCoaV/QaHe2VfTCi2Owu vdtfmMt5oN85YcQ5DjoXvvoIrnIEH/dY92OhkgL7JYVN72sZRfeiV3zWmlVTydDYsFuI mlSA== X-Gm-Message-State: AOAM532xYQBQ8vWKyLVOFTA6U4NVWL7w74x8tmuadSzvZNSdlOkAu2RC 13kBs7JWrC8GxDC+p2I8mvMvdxPt9qA= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:1ea0:b8ff:fe73:50f5]) (user=seanjc job=sendgmr) by 2002:a05:6214:370:: with SMTP id t16mr6428915qvu.22.1610153280070; Fri, 08 Jan 2021 16:48:00 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 8 Jan 2021 16:47:11 -0800 In-Reply-To: <20210109004714.1341275-1-seanjc@google.com> Message-Id: <20210109004714.1341275-11-seanjc@google.com> Mime-Version: 1.0 References: <20210109004714.1341275-1-seanjc@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 10/13] KVM: SVM: Move SEV VMCB tracking allocation to sev.c From: Sean Christopherson To: Paolo Bonzini , Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky , Borislav Petkov , Brijesh Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the allocation of the SEV VMCB array to sev.c to help pave the way toward encapsulating SEV enabling wholly within sev.c. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 13 +++++++++++++ arch/x86/kvm/svm/svm.c | 17 ++++++++--------- arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 3d25d24bcb48..8c34c467a09d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1323,6 +1323,19 @@ void sev_hardware_teardown(void) sev_flush_asids(); } +int sev_cpu_init(struct svm_cpu_data *sd) +{ + if (!svm_sev_enabled()) + return 0; + + sd->sev_vmcbs = kmalloc_array(max_sev_asid + 1, sizeof(void *), + GFP_KERNEL | __GFP_ZERO); + if (!sd->sev_vmcbs) + return -ENOMEM; + + return 0; +} + /* * Pages used by hardware to hold guest encrypted state must be flushed before * returning them to the system. diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index bb7b99743bea..89b95fb87a0c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -552,23 +552,22 @@ static void svm_cpu_uninit(int cpu) static int svm_cpu_init(int cpu) { struct svm_cpu_data *sd; + int ret; sd = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL); if (!sd) return -ENOMEM; sd->cpu = cpu; sd->save_area = alloc_page(GFP_KERNEL); - if (!sd->save_area) + if (!sd->save_area) { + ret = -ENOMEM; goto free_cpu_data; + } clear_page(page_address(sd->save_area)); - if (svm_sev_enabled()) { - sd->sev_vmcbs = kmalloc_array(max_sev_asid + 1, - sizeof(void *), - GFP_KERNEL | __GFP_ZERO); - if (!sd->sev_vmcbs) - goto free_save_area; - } + ret = sev_cpu_init(sd); + if (ret) + goto free_save_area; per_cpu(svm_data, cpu) = sd; @@ -578,7 +577,7 @@ static int svm_cpu_init(int cpu) __free_page(sd->save_area); free_cpu_data: kfree(sd); - return -ENOMEM; + return ret; } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 8e169835f52a..4eb4bab0ca3e 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -583,6 +583,7 @@ int svm_unregister_enc_region(struct kvm *kvm, void pre_sev_run(struct vcpu_svm *svm, int cpu); void __init sev_hardware_setup(void); void sev_hardware_teardown(void); +int sev_cpu_init(struct svm_cpu_data *sd); void sev_free_vcpu(struct kvm_vcpu *vcpu); int sev_handle_vmgexit(struct vcpu_svm *svm); int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in); -- 2.30.0.284.gd98b1dd5eaa7-goog