Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp80324pxy; Wed, 21 Apr 2021 19:12:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3pUw+gxc0jSK4drfammFOwF1xQ0rTHutrAXY7uBH28JepMYn2IUPam249p3r2jJCNqDfj X-Received: by 2002:aa7:8483:0:b029:261:a7ad:6468 with SMTP id u3-20020aa784830000b0290261a7ad6468mr899455pfn.43.1619057551094; Wed, 21 Apr 2021 19:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619057551; cv=none; d=google.com; s=arc-20160816; b=LsbPcTUCiQUVRbcmZvJRje/gC2fTLHTZC8WEPz+hBlmHv34YbJ8r8Ht85+ZqUrd6FZ 26459KNIzGWzWgR2xwh+wcAW7KbxnDYH7lij2RtzS8rDkcs3NddELb+JZq4ldyWWkHxf 7GxDoBteO8ic4tAbqQn0cUBgFyTNwVM97H9fTxiHUNPQ5FpgdImuhmrflFpXz5suWz9q LQ4oT1gnD0l1KJOrP6TkL4bhn6S9anoBroNYTYq9jpwL1DhZHfiqXdufC7ejxAi+mXA+ w0DYBTARt4W+rQZFanDp3FzduyEpr+q7f8pIQTAzk4jorS6kJQnFDwAos4mlZfNT3/ik qOZg== 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:dkim-signature; bh=8s0SzW+l4+6E9FQkwta1CXoWCr5k2rhkG3YB86R5vGE=; b=KXjXEHiQoApnb3chlhoHhHO7ykXpUKIQ7nFiP5gX0iJhmK2Rloao0uYLgqVgIc8hK0 8U98Fkp2KdSSDg28EN+/d9JkMaCBY62L4ObxqynX2TdcHtN8e+7VrwYX4waWu+z8iapr OO+1JOafLuh6Il5bHlRjIKhN+JTo57aNAA8yVlvYARrenMU2PLLiJofiCLNJMIkqD9Qi 177qwocPofHWsEQiF53Ad+LdfnwM1L5xhPURhckAkhj3ziHsUnylcEO17Sn0v5a8QfKG 7sgU9VNdNULiCM6y74C3alUCv5Cyoh+POHobM3S6iSl43F1PYKrJK+i/aokzL3zCoo6q 1scA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IUFr8Ehv; 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 m1si1493179pgg.380.2021.04.21.19.12.19; Wed, 21 Apr 2021 19:12:31 -0700 (PDT) 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=IUFr8Ehv; 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 S234140AbhDVCMK (ORCPT + 99 others); Wed, 21 Apr 2021 22:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbhDVCMJ (ORCPT ); Wed, 21 Apr 2021 22:12:09 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0DBBC06138B for ; Wed, 21 Apr 2021 19:11:33 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id c1-20020a5b0bc10000b02904e7c6399b20so18226595ybr.12 for ; Wed, 21 Apr 2021 19:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=8s0SzW+l4+6E9FQkwta1CXoWCr5k2rhkG3YB86R5vGE=; b=IUFr8Ehv63gVs8gd2PTxTfVtoYJynmAwaRBpO0kkEzY6jD1vvWafZxEu2vY0QGWooS F+WJevqvw5evQnOgKlzmHMXL/W6wcKb0iB7CXpIEjDwqdr3AKjmoT/mw9MEX0hFLHzoO gdXAL6HAnU94i0nUW0Zc8hn+psMX5XJTsmCfiLNM7ZcpziQJckPI++f3VX2an/IoLNhN QtFymOYkFRVuguzd2eJy2MCb1PvcYSf9hC7iuekDiBX1Ib9uops0Vu63mIb7m9udrNNr Yzsu5hXegUFAva10ZkmRbTYQ5l60RciHsmYXs8zuGqCgHHwCva3uHFGvVGZv53OTE3to eYDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=8s0SzW+l4+6E9FQkwta1CXoWCr5k2rhkG3YB86R5vGE=; b=aO2a3P/NEKqJEqBBLrC8Ef5QhsFa1aF+9g5tipWOvLA46JUo5jOetT57HRPk2DhBAF ZOFP+1+lKVZ+FUce6t5ZO01WT3wx037uhISTRLUuuh/P19Av4MYSyYm7GptMEzun2TKV kb1viPcFM9qJsd6n77z+VykB+rx4pXfttb0134vDaeQ1ds6iGgu61P33+0O3aFQmxAVf PocV3iabthMD2ag1LU7tqftRgCCcLwQmrXU07sC+PCAmWhSjnx8O6uUmAI5+FFZyGokn Zmdkd/pfGipz0m7sQkQrUDkqTAWc8xtNo2X90Vz+24aGbuM4sb0YvDycd0buPEdGMhFp wuhA== X-Gm-Message-State: AOAM533DQniKlNgnDI8U/H15WpStdHgpKu8qmuHXRXrFf0YSIPe+bmcU lxSuuAwHCDimdhjnB5pvoQd61TUv7a0= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:e012:374c:592:6194]) (user=seanjc job=sendgmr) by 2002:a25:14d4:: with SMTP id 203mr1322961ybu.261.1619057492934; Wed, 21 Apr 2021 19:11:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 21 Apr 2021 19:11:12 -0700 In-Reply-To: <20210422021125.3417167-1-seanjc@google.com> Message-Id: <20210422021125.3417167-3-seanjc@google.com> Mime-Version: 1.0 References: <20210422021125.3417167-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH v5 02/15] KVM: SVM: Free sev_asid_bitmap during init if SEV setup fails 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, Borislav Petkov , Tom Lendacky , Brijesh Singh Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Free sev_asid_bitmap if the reclaim bitmap allocation fails, othwerise KVM will unnecessarily keep the bitmap when SEV is not fully enabled. Freeing the page is also necessary to avoid introducing a bug when a future patch eliminates svm_sev_enabled() in favor of using the global 'sev' flag directly. While sev_hardware_enabled() checks max_sev_asid, which is true even if KVM setup fails, 'sev' will be true if and only if KVM setup fully succeeds. Fixes: 33af3a7ef9e6 ("KVM: SVM: Reduce WBINVD/DF_FLUSH invocations") Cc: Tom Lendacky Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/sev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index b4e471b0a231..5ff8a202cc01 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1788,8 +1788,11 @@ void __init sev_hardware_setup(void) goto out; sev_reclaim_asid_bitmap = bitmap_zalloc(max_sev_asid, GFP_KERNEL); - if (!sev_reclaim_asid_bitmap) + if (!sev_reclaim_asid_bitmap) { + bitmap_free(sev_asid_bitmap); + sev_asid_bitmap = NULL; goto out; + } pr_info("SEV supported: %u ASIDs\n", max_sev_asid - min_sev_asid + 1); sev_supported = true; -- 2.31.1.498.g6c1eba8ee3d-goog