Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1071883rwl; Wed, 12 Apr 2023 07:58:14 -0700 (PDT) X-Google-Smtp-Source: AKy350a5UgVtnt76ClSgde9aAvXCJPOILsQ05SweYV5qKBXCupfNnc+Io23WHINW9eA9h1o7yBb7 X-Received: by 2002:a05:6402:50ce:b0:504:7b24:7dff with SMTP id h14-20020a05640250ce00b005047b247dffmr3145613edb.9.1681311494495; Wed, 12 Apr 2023 07:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681311494; cv=none; d=google.com; s=arc-20160816; b=H6/UIStSmqa6ChiLDElZkX8kxvtnesSymMyd9ZDPYxL3aPsGBo23FevM+uZOXGMXEA hxXNKFDO4tddeWRMLVEkK9ROrB13rjt3zpGgBQIVN2c/EohcUJQSUrsEMjjkf3dtFunM CAVUgyIE1UdQBmlPefDOhMO/IJln+K3I60AzWLaqKJ5jIHCkV17aF67b8g7g+YjEenyt zQfAzDRZ9L+mAGakcF65+ZaKA+jzwx5NliAet7qjhFqN0MvDH59o9mBFxMDfliSRj/N+ P+iVMFNxt8Xn4Dpot9hPK13eMZAsTK3mXhMK5L1g7D+j6E/pPVRDdMDuYoiJU9H0PBqK UVuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=hvqL5OvNUsZFZ+sHFmNlvVzy0tXAUd/iqPbCE7rbU6Q=; b=yp91Gscg+955jJI9jHCDvrX4QzWKBx2WAOIpG0QuE/2VkxKQEQCJEiQGO92lzkyXpN p9cB438EjX7MlqfNdT2lQ89rjQgsqfFcWjLAZjeIclQwS4dbdl/hApVQfaGj8hWvgeK7 mEScCP3om6gzeLX2Ogr+iTH9Jxfso08jJjuHF+MikWEyt1H9dhEs6Yk1UsRFN7HRqw7x qHtPB5kT7ApkcYMVIvSfpNfCEjZJJM1Lak7CUhxy1bCfx8lDo9pKZ99rx893YlKjvIsL nytittgPPzFoIuN/VPM/uIBUaPKpnn+YQTg1IjJScQVOFo9z0hWguzcXxPbQpIY+Qi0N 1Nww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="A/TfUhI3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020aa7c60c000000b004ab9fed6acesi3156931edq.384.2023.04.12.07.57.50; Wed, 12 Apr 2023 07:58:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="A/TfUhI3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229778AbjDLOwp (ORCPT + 99 others); Wed, 12 Apr 2023 10:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjDLOwo (ORCPT ); Wed, 12 Apr 2023 10:52:44 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00AC85B99 for ; Wed, 12 Apr 2023 07:52:38 -0700 (PDT) Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 17E263F429 for ; Wed, 12 Apr 2023 14:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1681311156; bh=hvqL5OvNUsZFZ+sHFmNlvVzy0tXAUd/iqPbCE7rbU6Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=A/TfUhI3f/UPL84W3whA4eG0Wdx/lBn4TNfGEN0LKZDcUK/oGINKgfOLh1eAMNuba uuYLntYchwDKW7L7XNSdHHfVwG2CoKnRiH2PbZklQqTbzu3o2qRkoofzgaWfNrwGLa 3GcRW+KmnPXrznnwrJuZw50iAiHA6GK7iWPpmuH+MpgdkaLK/Pz5Ii9GyQCcstwEAy CNO4u8yG2plPke5k6k3KUxiFUF5WIyZPvpkWSbYp2gXX65Nt6TBFX4Rz6yZHusS6+R 8zmD+tUN46vcFshXz2DzkByO42nEbyWU4jT4OBLXIDsZ6VltT916GfHPuQsYKsf487 V3IAVkTBbxtbQ== Received: by mail-yb1-f200.google.com with SMTP id j203-20020a2523d4000000b00b8f21897f2fso6102414ybj.22 for ; Wed, 12 Apr 2023 07:52:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681311155; x=1683903155; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hvqL5OvNUsZFZ+sHFmNlvVzy0tXAUd/iqPbCE7rbU6Q=; b=T7xYIq9R9/PAf4h5yyHQIhh8u3EHvM21rdn8v9EMU+goudbZPK0KuZvYzrTz8fdJg7 GoM6ELzakbcVC7WtgJ2Y1SUZCoDY2EUqBb4Q7KuKkH1+QhbjOegGZ5uALYMheUBsRO1S POcEvsGnxYnlamYLVievSNAQ2s4Jqg2jfBG2M0e3PaEeoocWf2VC2WKkwqkn82ho/iV+ s7Dlshwk0ZGaOjxUQVc7AKzqUgzMUgYnxuokyoVfWe+VhBLIq8KjSgw6pY4VUFoJr7zK MGCyh0+eaWP7jyE8Cab5+L8tTtOkLZhjPw2Y979O+tsCbDH5ZBp4rCRclKgZOObqnai6 NYzw== X-Gm-Message-State: AAQBX9dAXHGmgkjYsPd1/Ax9JPoUlLuq5FwH8eibfDSrp4MujhWsNagL 8qkJyo8xp+l9vUxSqQWCysl+HdA79jmGYym/pz8X23p3iBiN2nOdTWXMYBlzta9zcTdhEVitkyU sJ/uF+82VZx3jQOGP7tmp0i1CGt3Is6b5/v+HUNoCXJpabbpHd7k0BDkZ5w== X-Received: by 2002:a25:d884:0:b0:b8e:f1ef:a144 with SMTP id p126-20020a25d884000000b00b8ef1efa144mr2178691ybg.0.1681311155118; Wed, 12 Apr 2023 07:52:35 -0700 (PDT) X-Received: by 2002:a25:d884:0:b0:b8e:f1ef:a144 with SMTP id p126-20020a25d884000000b00b8ef1efa144mr2178685ybg.0.1681311154914; Wed, 12 Apr 2023 07:52:34 -0700 (PDT) MIME-Version: 1.0 References: <20230404122652.275005-1-aleksandr.mikhalitsyn@canonical.com> <20230404122652.275005-2-aleksandr.mikhalitsyn@canonical.com> <20230411224737.00001d67.zhi.wang.linux@gmail.com> In-Reply-To: <20230411224737.00001d67.zhi.wang.linux@gmail.com> From: Aleksandr Mikhalitsyn Date: Wed, 12 Apr 2023 16:52:23 +0200 Message-ID: Subject: Re: [PATCH 1/2] KVM: SVM: free sev_*asid_bitmap init if SEV init fails To: Zhi Wang Cc: pbonzini@redhat.com, Sean Christopherson , =?UTF-8?Q?St=C3=A9phane_Graber?= , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 11, 2023 at 9:47=E2=80=AFPM Zhi Wang = wrote: > > On Tue, 4 Apr 2023 14:26:51 +0200 > Alexander Mikhalitsyn wrote: > > > If misc_cg_set_capacity() fails for some reason then we have > > a memleak for sev_reclaim_asid_bitmap/sev_asid_bitmap. It's > > not a case right now, because misc_cg_set_capacity() just can't > > fail and check inside it is always successful. > > > > But let's fix that for code consistency. > > > > Cc: Sean Christopherson > > Cc: Paolo Bonzini > > Cc: St=C3=A9phane Graber > > Cc: kvm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Alexander Mikhalitsyn > > --- > > arch/x86/kvm/svm/sev.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c > > index c25aeb550cd9..a42536a0681a 100644 > > --- a/arch/x86/kvm/svm/sev.c > > +++ b/arch/x86/kvm/svm/sev.c > > @@ -2213,8 +2213,13 @@ void __init sev_hardware_setup(void) > > } > > > > sev_asid_count =3D max_sev_asid - min_sev_asid + 1; > > - if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)) > > + if (misc_cg_set_capacity(MISC_CG_RES_SEV, sev_asid_count)) { > > + bitmap_free(sev_reclaim_asid_bitmap); > > + sev_reclaim_asid_bitmap =3D NULL; > > + bitmap_free(sev_asid_bitmap); > > + sev_asid_bitmap =3D NULL; > > goto out; > > + } > > > > pr_info("SEV supported: %u ASIDs\n", sev_asid_count); > > sev_supported =3D true; > > It would be nice that another case can also be fixed: > > sev_es_asid_count =3D min_sev_asid - 1; > if (misc_cg_set_capacity(MISC_CG_RES_SEV_ES, sev_es_asid_count)) > goto out; /* <----HERE */ Nope. There is no leak. Because when we are at this point then sev_supported =3D true and everything is fine. > > Maybe it would be a good idea to factor out an common error handling path= .