From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F401EC433F5 for ; Tue, 9 Nov 2021 22:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA9F661037 for ; Tue, 9 Nov 2021 22:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241716AbhKIWy3 (ORCPT ); Tue, 9 Nov 2021 17:54:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344575AbhKIWxf (ORCPT ); Tue, 9 Nov 2021 17:53:35 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A7DC110F3C for ; Tue, 9 Nov 2021 14:23:57 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id u22-20020a170902a61600b00141ab5dd25dso581255plq.5 for ; Tue, 09 Nov 2021 14:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=ycLvjef8hLdk7LZI4/gX+inYpxs+E16n7SoVAMQYbFc=; b=RH/SD9WH2rxUk9ThoB6cB4kA1NBJsDJiLeOWkZk9g7Bv9p84MfGa3RXXawQbTSAMim k26q1x/Hb/h4jpIn4uKzi0235tEai0/9kk54pQCnBsFk/KTH/MS0KZ8T1DgOTO7TMkpn s/6zUSt+EmWHfxFtHwYLE5GGRdfMyf91Kfs83Krlg3O/oMeCnwTcv3Fi2dHkcgnQXpu3 DcC9fDEQTgsnufKukuObbrWdoMJhARapdDojQb34tUuP0ulvmqIMKhu4LYmPRr/Y8+rt HzFPi8EdT1bYCPHxvKKQdro8eTBGp47rczee2Ke8vjU3I5ipEopeQMLQC97AfYEth96P KHVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=ycLvjef8hLdk7LZI4/gX+inYpxs+E16n7SoVAMQYbFc=; b=KeXQCvS4uB0N7vDv31lWktUuLa1iIEi97l8hzYfPf09ejzm2G+IgCKl/t/X01G82cV tj6kXnJxmr84aCSzblELmj1SIagLyA84JeosSoROldBc6YCb7/6+cBlsZFH9clm4EcOf ikvRS7bED9xQnezq9zuJx8USYs5hWV5MimnPjp9fxLVLytA/ULUGVKs1H1969jNsDZDz pVwa/CfKU89zAtWr1MnXzLASEJPunhIB8PKCYH4IMpMJUDVFPPsmOcBBhK58zeUnQwcv ezKm5+i96hkT9Opu5zU70WPCSoEPgBT3/N4nFeEsCRBxY1h+en4R1ekiqqIpzoxhaN/+ h8qA== X-Gm-Message-State: AOAM531wm/n+h38XMqRSeELxPpshwKR9Pu9YE0ukbOQ6HpINJUN7bRUx 1ESBVdWZwqPqLXMG21T3kCs/8RBsMnw= X-Google-Smtp-Source: ABdhPJx+mhejWFf7eZ9OTGpZ/iBTqEUfe2OZ3RjoRi5mNmTU3uuvA2OydzfWAllLfWwmUIivwje0m/ZsTb0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:c947:b0:141:e7f6:d688 with SMTP id i7-20020a170902c94700b00141e7f6d688mr10459270pla.56.1636496636511; Tue, 09 Nov 2021 14:23:56 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 9 Nov 2021 22:23:50 +0000 In-Reply-To: <20211109222350.2266045-1-seanjc@google.com> Message-Id: <20211109222350.2266045-3-seanjc@google.com> Mime-Version: 1.0 References: <20211109222350.2266045-1-seanjc@google.com> X-Mailer: git-send-email 2.34.0.rc0.344.g81b53c2807-goog Subject: [PATCH 2/2] KVM: SEV: Fall back to __vmalloc() for SEV-ES scratch area if necessary From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kvzalloc() to allocate KVM's buffer for SEV-ES's GHCB scratch area so that KVM falls back to __vmalloc() if physically contiguous memory isn't available. The buffer is purely a KVM software construct, i.e. there's no need for it to be physically contiguous, and at a max allowed size of 16kb it's just large enough that kzalloc() could feasibly fail due to memory fragmentation. Cc: Tom Lendacky Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index ea8069c9b5cb..2d5a0eea27ea 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2030,7 +2030,7 @@ void sev_free_vcpu(struct kvm_vcpu *vcpu) __free_page(virt_to_page(svm->vmsa)); if (svm->ghcb_sa_free) - kfree(svm->ghcb_sa); + kvfree(svm->ghcb_sa); } static void dump_ghcb(struct vcpu_svm *svm) @@ -2262,7 +2262,7 @@ void sev_es_unmap_ghcb(struct vcpu_svm *svm) svm->ghcb_sa_sync = false; } - kfree(svm->ghcb_sa); + kvfree(svm->ghcb_sa); svm->ghcb_sa = NULL; svm->ghcb_sa_free = false; } @@ -2350,7 +2350,7 @@ static int setup_vmgexit_scratch(struct vcpu_svm *svm, bool sync, u64 len) len, GHCB_SCRATCH_AREA_LIMIT); return -EINVAL; } - scratch_va = kzalloc(len, GFP_KERNEL_ACCOUNT); + scratch_va = kvzalloc(len, GFP_KERNEL_ACCOUNT); if (!scratch_va) return -ENOMEM; @@ -2358,7 +2358,7 @@ static int setup_vmgexit_scratch(struct vcpu_svm *svm, bool sync, u64 len) /* Unable to copy scratch area from guest */ pr_err("vmgexit: kvm_read_guest for scratch area failed\n"); - kfree(scratch_va); + kvfree(scratch_va); return -EFAULT; } -- 2.34.0.rc0.344.g81b53c2807-goog