Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp648109rwi; Wed, 2 Nov 2022 16:42:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM50IrwpjMUTj2TWfUBKWE1RhIfNZebX1TMOBAdCzG/kD0hHteGso19P2B2HQqPsJj2D9M88 X-Received: by 2002:a05:6402:847:b0:453:944a:ba8e with SMTP id b7-20020a056402084700b00453944aba8emr26883875edz.326.1667432529261; Wed, 02 Nov 2022 16:42:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667432529; cv=none; d=google.com; s=arc-20160816; b=pS/LvJQr7jsFEon0wq3WGTculL7ibazB45fFVf+Zkc0D+BR1rfJWZ0DV+u9Qe6nZOz 2c0lbn1sr5XAl6f0NNTqptGlnNejGOg50iCV9sjeubaEeYI757hc7D43rHyP4dc0O8fD LUgK4m/qwoIgfi5bXPZFU24C13mESvG2eBUTjXhYr8kwUJv2QduJ7Om8QPKXMvj79AsD O1nulfoIAC6kjC3QaRboSup4nLwg0cYgwvVCzdtmbuWet5V6BMWzlzrOGJBvLntk8XbV C2cJFn1jU02YGPL3maodnQY9ojbzpKqXigK9WpyYzoAVJHV1cehG8tYaXtcKLUxYqhGi Bkgg== 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=61+uc/Y9XgqKqIqJKklgZKwyXFi4EpAveqLf+gzND20=; b=dJX0MEJWmm36xvQ3AjZvIfsCQZno3MnJSmY9CSmRLGWz48Vet4zkFOQVUqI8L0fp9R NvnMia0RAtZz241PLPwqi+YCmf76Pco8/i1ptl8v48f2nn9p80otDeNubMeXCKh/oqLg Qds/rG2aW6WfrPL3PAhEc0JRlRF58I2CEyDv7pzyg9kJZePRVnw0OgX+TWGgpmLZA9it bJAJN65IoUFFDAVDq3fCsv3gr6ecWECsIlpHCEsIhY0xspOIMjpKmlVMVITWSaEy6eGN 451sazsdvLTJaMRbFHHq7dhk3KkC8mmq4T1dm1Yaj4WYQESZ5Y8+Nedf2y8vp6LowoMg HPsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Utw2bIoF; 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 be7-20020a1709070a4700b007a46fa50b26si19196174ejc.517.2022.11.02.16.41.46; Wed, 02 Nov 2022 16:42:09 -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=@google.com header.s=20210112 header.b=Utw2bIoF; 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 S230336AbiKBXUN (ORCPT + 98 others); Wed, 2 Nov 2022 19:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbiKBXT2 (ORCPT ); Wed, 2 Nov 2022 19:19:28 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEF5825F8 for ; Wed, 2 Nov 2022 16:19:23 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id om10-20020a17090b3a8a00b002108b078ab1so2472083pjb.9 for ; Wed, 02 Nov 2022 16:19:23 -0700 (PDT) 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=61+uc/Y9XgqKqIqJKklgZKwyXFi4EpAveqLf+gzND20=; b=Utw2bIoFpd0OsW8gcFI5XrC8r/opoeV6PzEujs3E4Mr9+St+h1iGz7I0t2dfS8UClh tAtUjqK55zt6/KkvBXOzqfYjfHXVvlGdNUDx6aXeRWpNBB/SzUU3M7O4hGxRvmfcP7Dv H7xUVWjzIm9fOWFawnQ+tUiBa9aTdqs3xjhRiHy7QmZH5iQmDFc0LC68bjVk8Tk76MUY okNb1d05tSvdlxWMqm8WJt1KJ94gRKBpU/aaJyEkAN3CmyDtunrNwjuXsVAB9MDK12T5 qP1tSiadBS2lzWdtmS7wbdVgSkTUTO1m/e38yDr5/ydciJMTwj/jwYNum8ez3aI14Ekv m1vw== 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=61+uc/Y9XgqKqIqJKklgZKwyXFi4EpAveqLf+gzND20=; b=tHImZWtoX3J9SPyXeGPegcRSBWytqBlYEzBGeZEJ+LlKXfqM06x8KHysvBonIKwgev tPYpt/Wa3Jc+LjihhKrxqbeRnDLYUKozYQHucKF3SvUhD7hNzzFxz+syHdFyIGf4t1as apVY47y5WmnS5y2p6qvLm8lZX+8H/zVjzX1AGGTHrG6RRh8gQMdeucxwUenaQ+1YS5Ri VU3rbh+qQy8/ThB2amL89wuMuhOJFZmm46R0EeL05nj/KDMz1xKRHKInQvwsC1nfRSBP fpVCRl3pykKqDkyzonWCYkmIvM67vHY+vOMIQ3QhufeL2Wj/j/6Bj98aANHkN4tSId8N 1xAg== X-Gm-Message-State: ACrzQf1Zd0THGbCbDatOv6rie1yliD9aAFVs7MA5r/1YX+yUV5G3ko3R xdasjJjqnyz2ODtYrrvV1M/6gK8Lf24= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:38cd:b0:214:184f:4007 with SMTP id nn13-20020a17090b38cd00b00214184f4007mr9764899pjb.82.1667431162802; Wed, 02 Nov 2022 16:19:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 2 Nov 2022 23:18:32 +0000 In-Reply-To: <20221102231911.3107438-1-seanjc@google.com> Mime-Version: 1.0 References: <20221102231911.3107438-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221102231911.3107438-6-seanjc@google.com> Subject: [PATCH 05/44] 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 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, Isaku Yamahata , Fabiano Rosas , Michael Ellerman , Chao Gao , Thomas Gleixner , Yuan Yao 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=ham 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 --- 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 45d4b8182b07..8395433a79b2 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -490,11 +490,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(); @@ -502,25 +502,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.431.g37b22c650d-goog