Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3125555rwb; Wed, 30 Nov 2022 15:59:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf6E+Y0png71mh0ejtpd8BboIpUI/g4V7GehYRXlRyfsEqPFvzPcnC9ZvasrDcVtMasDgBhT X-Received: by 2002:a17:906:3fd0:b0:7af:9bff:8de6 with SMTP id k16-20020a1709063fd000b007af9bff8de6mr35749441ejj.91.1669852753190; Wed, 30 Nov 2022 15:59:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669852753; cv=none; d=google.com; s=arc-20160816; b=ri/YyUJMmkj/lw7TLV6v/K9aLoeVutRkyNiC9vdJqoEw3HEPj/tk8pc6xLB5R7FD0p k5XeqgkESzwk5mwBEnCJlcGFeyOfjWuRgeCZQjTdH+Kf23nCuNhvKp35jIM41xfNsQlv 9DivPjaxjNLHB+ljsM/9we/skrYu/Fp90yrJ91BGPEf+gtOXqaH8hgSE4L1ie84IO4YL FEjEX/o8SMtOFTdlc9c56EsYLVBCIJ1uPl/382By2epcP7apBQ0OUPkEFqqyF5ZDY0cJ 4ueExAAZXKndAoaodZJ3enfkEcc6oirimvu5UdRTAkukiVLB+f4s46/tvN7o68H4ly/b XfIw== 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:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=4d3Yt8bltpBTGQfRvysGuV0Qwes6q1E1oAAkIYt6v1U=; b=m2/Q8amYe19535qZ2WWqCC8m6ANQAH6M6ZUR+ps4CLXWRTt+Qf3AOOMkMTqZjpaSUc zUTbb1dQ9zCst9scCSIW48NAxFp8LhObcVAM/oCQxKNxrA4rbkXnay22PWH9THlPA23o BGssZvxi/90Uaobwm17qqTEE/zOXhCg90dOIKJNsjm907BmzqegLW8Krz4I2ME6R6DBZ 52Cm0uKp6R8bSDQMi0EItYiQK6HYKTGrvTyCUNBLCaCP+IVbZSQ91z/5RT32b0gPsRhk fOCvZIKbHDLb5iQrMSL8hvAw+F2oVQO0yWZ2Lza0TghE3z1Gcsljl42lH5Sp/iNuyA4E YyNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="R2EUvQh/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf30-20020a1709077f1e00b007ae72eabbe0si2237416ejc.928.2022.11.30.15.58.53; Wed, 30 Nov 2022 15:59:13 -0800 (PST) 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=@google.com header.s=20210112 header.b="R2EUvQh/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbiK3XKM (ORCPT + 83 others); Wed, 30 Nov 2022 18:10:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiK3XKB (ORCPT ); Wed, 30 Nov 2022 18:10:01 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67169701E for ; Wed, 30 Nov 2022 15:09:46 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id f19-20020a056a001ad300b0056dd07cebfcso203706pfv.3 for ; Wed, 30 Nov 2022 15:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=4d3Yt8bltpBTGQfRvysGuV0Qwes6q1E1oAAkIYt6v1U=; b=R2EUvQh/d5tOiXan3raQzQlRv7gR1ONI/pTsvNFLPNlIvb1HQkPh0aZeDhUMSwPjU6 WmKXxIVdA8mWbdpdJ9mQWSFS0GaxhUMED8VA7z9aivgbFGgRyi5KO45SYxDJSk//Lrmi TvHQq/KXHoU6IG02YXxnz+VoMPrjzvItFwl89sStfSe8vLDomvkTbOfZZylixHCAfv3w Jgwxv2s/jYVL/cbZz1XyHU/++UQYcJaWUXGIWbWEnIOtbM+sQTznmLBg+6U7bpNOdsk9 JFaEVxGzY3mhCDrcWoTbsIO4wRxo80HsCG5wPORw/u3RxuNka0IHsD1GSswNFX6QovYX 0b5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4d3Yt8bltpBTGQfRvysGuV0Qwes6q1E1oAAkIYt6v1U=; b=7pYXyIrwUf24EuAlpwhhOi0KS1uXj10Jea0DaoO1l9XlVR6vgMwUVIXeAG2EGh7FyT xFMuobibO01o01Sk7khoYRsGL04yaiJjpQ2sVLEFH23dFf3Vtg4oFrX0Ca0RDh9f6mG9 cMmyRi4k2fpiWW7yNpJ7MBX3fp0WyIbQv3MmDd8U6T8aVE0dIRDgEXbbmpAymKs/H+EV gIsShDiRiiy111KASF4INX3Kz5uJm0ksePxOIYwDvpx7PolKevqiJ6dfOeP3w0lN3GBe 81mb4fNLKSexGlhaXUAFShDCs/AGgxT2XXafrmohm/w+k4Hj0XLIFK1bMY8lzqG3AAwS wWAQ== X-Gm-Message-State: ANoB5pmA6arX7Nq27joYnaogXoxx0CO1SvzmsFoly8VE7+P7egtFf3X+ N81xQzhlJYb593dQEwh5b5H1oszVLgU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d58d:b0:188:ff21:e76b with SMTP id k13-20020a170902d58d00b00188ff21e76bmr9022156plh.60.1669849786225; Wed, 30 Nov 2022 15:09:46 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 30 Nov 2022 23:08:49 +0000 In-Reply-To: <20221130230934.1014142-1-seanjc@google.com> Mime-Version: 1.0 References: <20221130230934.1014142-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221130230934.1014142-6-seanjc@google.com> Subject: [PATCH v2 05/50] KVM: s390: Unwind kvm_arch_init() piece-by-piece() if a step fails From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Matthew Rosato , Eric Farman , Sean Christopherson , Vitaly Kuznetsov , David Woodhouse , Paul Durrant Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Yao , Cornelia Huck , Isaku Yamahata , "=?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?=" , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 In preparation for folding kvm_arch_hardware_setup() into kvm_arch_init(), unwind initialization one step at a time instead of simply calling kvm_arch_exit(). Using kvm_arch_exit() regardless of which initialization step failed relies on all affected state playing nice with being undone even if said state wasn't first setup. That holds true for state that is currently configured by kvm_arch_init(), but not for state that's handled by kvm_arch_hardware_setup(), e.g. calling gmap_unregister_pte_notifier() without first registering a notifier would result in list corruption due to attempting to delete an entry that was never added to the list. Signed-off-by: Sean Christopherson Reviewed-by: Eric Farman --- arch/s390/kvm/kvm-s390.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index e4890e04b210..221481a09742 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -498,11 +498,11 @@ int kvm_arch_init(void *opaque) kvm_s390_dbf_uv = debug_register("kvm-uv", 32, 1, 7 * sizeof(long)); if (!kvm_s390_dbf_uv) - goto out; + goto err_kvm_uv; if (debug_register_view(kvm_s390_dbf, &debug_sprintf_view) || debug_register_view(kvm_s390_dbf_uv, &debug_sprintf_view)) - goto out; + goto err_debug_view; kvm_s390_cpu_feat_init(); @@ -510,25 +510,32 @@ int kvm_arch_init(void *opaque) rc = kvm_register_device_ops(&kvm_flic_ops, KVM_DEV_TYPE_FLIC); if (rc) { pr_err("A FLIC registration call failed with rc=%d\n", rc); - goto out; + goto err_flic; } if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) { rc = kvm_s390_pci_init(); if (rc) { pr_err("Unable to allocate AIFT for PCI\n"); - goto out; + goto err_pci; } } rc = kvm_s390_gib_init(GAL_ISC); if (rc) - goto out; + goto err_gib; return 0; -out: - kvm_arch_exit(); +err_gib: + if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) + kvm_s390_pci_exit(); +err_pci: +err_flic: +err_debug_view: + debug_unregister(kvm_s390_dbf_uv); +err_kvm_uv: + debug_unregister(kvm_s390_dbf); return rc; } -- 2.38.1.584.g0f3c55d4c2-goog