Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp733016imi; Fri, 22 Jul 2022 08:16:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spGcPZndKnvx+5A1vhHMzpq7UNjMIpEF2fzXlnyK4b8kJ6RT0nW5xvqjdoeBM1AgMnTvQ4 X-Received: by 2002:a17:907:2888:b0:72b:4a91:b21a with SMTP id em8-20020a170907288800b0072b4a91b21amr310199ejc.35.1658502961197; Fri, 22 Jul 2022 08:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658502961; cv=none; d=google.com; s=arc-20160816; b=ptBVU8ijeKVHMuro1OU4NzIX5RxsKicOAJD5BvS7Ia/5OyxBe/qW2VPB84wmtS4+oS Mhl2dd+8t4NPDbM+qs+Z+m251Oo+MCv8vi3ibT7vwPuhK2oXavkb6gbDB1u6vuaaYVpk aDttnZvmDvZEUu5dk3UAELPPd5ff7UqwYNBzD8RCrAMCXROhKSUGxOOQ6rGzhuq2qo7g 1vcmVT5miN7T/6+biMN6BBFqhAkquf1/NctUFdBWcCokc5QKUETal5b5YF04MiUMPGEb KfP5FlEXwY2HeOGrPA7V85PDl/EPeMag7NIkMMnHqjczk81qZEDbvVdjqLTiQZVtgjtb jplQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=3hPXPL65qpnRZ7XSJmdZ58BkdqtiQp8mRXrD6jtpXKw=; b=AM3ipQ7TGBWlpA7QzXTw6QlIELNOdMSyTew+EttiQouOZOAl2SQpApk3s2zwRy7J0k EbQEbnvT8gIFuCzBw6s1O1p7DHY/DBB/84Xr+KPYEMeT18D+8OYqN3ty4p2naiB7CZqo besm7kLAaYkYgEIXuDSvvGyahhnCgfRjKTI1cIP4NUvjCLMvp0udWhOxPSBT/wycj3Qt pH+y64YB5tpYceD4zjHA1VHkAh945U56v0hlIMU4LT+eZ9aILWgMIOhCwVkdVR/FN0hp DbZBAugny50uhXB83NI33eB4vKjA3zCgXtM1yapGYs9rouCVzZxyL7svctpQOmvr2E6U 5kbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cWpThtsl; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz20-20020a1709077d9400b00718cd33f793si6472194ejc.158.2022.07.22.08.15.34; Fri, 22 Jul 2022 08:16:01 -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=@kernel.org header.s=k20201202 header.b=cWpThtsl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234488AbiGVOjO (ORCPT + 99 others); Fri, 22 Jul 2022 10:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiGVOjJ (ORCPT ); Fri, 22 Jul 2022 10:39:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB5C697D77; Fri, 22 Jul 2022 07:39:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 68525620CB; Fri, 22 Jul 2022 14:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89A2CC341C6; Fri, 22 Jul 2022 14:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658500746; bh=i9MolRRFysQmipFNqDdyS2FEgC82Is2tN0xSHqCNBa4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=cWpThtslXHPv+iAzaZkVc/vQMqUHIH1oWtRCpX1ZyL5OPuyR4Q2Vq/9h7QcL8XCsl R73d+sV96NxVlQnlu53MwutYa/t4X24pgPBz/eFkVpUYYB5FVlg3BTyop+2LfeO0QY FTcFyqXCwXIymj/WH82yTChjq0sF8R4SakcmFjAGfcs5Zxd+NvgeZrS6B6vg/nrRhh DabYztinEYTQJ2iVayhVFMx84b1Nv0g2Cvu4Xhu+/i1DKm3nJ0jhHzMKcpKlQNu/6J ogjefvLfOTpj/C4amueWsVWtf1hncC5jXksRGl4RjAt4Ppi1n7tht05uSQTZm2li2n liU/X8LnoUw8w== Date: Fri, 22 Jul 2022 09:39:05 -0500 From: Bjorn Helgaas To: Pali =?iso-8859-1?Q?Roh=E1r?= , Johan Hovold Cc: Kishon Vijay Abraham I , Xiaowei Song , Binghui Wang , Thierry Reding , Ryder Lee , Jianjun Wang , linux-pci@vger.kernel.org, Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Ley Foon Tan , linux-kernel@vger.kernel.org, Marc Zyngier Subject: Re: Why set .suppress_bind_attrs even though .remove() implemented? Message-ID: <20220722143905.GA1818909@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220721222122.GA1754784@bhelgaas> X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 [+cc Marc, can you clarify when we need irq_dispose_mapping()?] On Thu, Jul 21, 2022 at 05:21:22PM -0500, Bjorn Helgaas wrote: > On Thu, Jul 21, 2022 at 10:46:07PM +0200, Pali Roh?r wrote: > > On Thursday 21 July 2022 14:54:33 Bjorn Helgaas wrote: > > > The j721e, kirin, tegra, and mediatek drivers all implement .remove(). > > > > > > They also set ".suppress_bind_attrs = true". I think this means > > > bus_add_driver() will not create the "bind" and "unbind" sysfs > > > attributes for the driver that would allow users to users to manually > > > attach and detach devices from it. > > > > > > Is there a reason for this, or should these drivers stop setting > > > .suppress_bind_attrs? > > > > I have already asked this question during review of kirin driver: > > https://lore.kernel.org/linux-pci/20211031205527.ochhi72dfu4uidii@pali/ > > > > Microchip driver wanted to change its type from bool to tristate > > https://lore.kernel.org/linux-pci/20220420093449.38054-1-u.kleine-koenig@pengutronix.de/t/#u > > and after discussion it seems that it is needed to do more work for this > > driver. > > > > > For example, Pali and Ley Foon *did* stop setting .suppress_bind_attrs > > > when adding .remove() methods in these commits: > > > > > > 0746ae1be121 ("PCI: mvebu: Add support for compiling driver as module") > > > 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module") > > > ec15c4d0d5d2 ("PCI: altera: Allow building as module") > > > > I added it for both pci-mvebu.c and pci-aardvark.c. And just few days > > ago I realized why suppress_bind_attrs was set to true and remove method > > was not implemented. > > With suppress_bind_attrs, the user can't manually unbind a device, so > we can't get to mvebu_pcie_remove() that way, but since mvebu is a > modular driver, I assume we can unload the module and *that* would > call mvebu_pcie_remove(). Right? > > > Implementing remove method is not really simple, specially when pci > > controller driver implements also interrupt controller (e.g. for > > handling legacy interrupts). > > Hmmm. Based on your patches below, it looks like we need to call > irq_dispose_mapping() in some cases, but I'm very confused about > *which* cases. > > I first thought it was for mappings created with irq_create_mapping(), > but pci-aardvark.c never calls that, so there must be more to it. > > Currently only altera, iproc, mediatek-gen3, and mediatek call > irq_dispose_mapping() from their .remove() methods. (They all call > irq_domain_remove() *before* irq_dispose_mapping(). Is that legal? > Your patches do irq_dispose_mapping() *first*.) > > altera, mediatek-gen3, and mediatek call irq_dispose_mapping() on IRQs > that came from platform_get_irq(). > > qcom is a DWC driver, so all the IRQ stuff happens in > dw_pcie_host_init(). qcom_pcie_remove() does call > dw_pcie_host_deinit(), which calls irq_domain_remove(), but nobody > calls irq_dispose_mapping(). > > I'm thoroughly confused by all this. But I suspect that maybe I > should drop the "make qcom modular" patch because it seems susceptible > to this problem: > > https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?h=pci/ctrl/qcom&id=41b68c2d097e > > > Here are waiting fixup patches for pci-mvebu.c and pci-aardvark.c which > > fixes .remove callback. Without these patches calling 'rmmod driver' let > > dangling pointer in kernel which may cause random kernel crashes. See: > > > > https://lore.kernel.org/linux-pci/20220709161858.15031-1-pali@kernel.org/ > > https://lore.kernel.org/linux-pci/20220711120626.11492-1-pali@kernel.org/ > > https://lore.kernel.org/linux-pci/20220711120626.11492-2-pali@kernel.org/ > > > > So I would suggest to do more detailed review when adding .remove > > callback for pci controller driver (or when remove suppress_bind_attrs) > > and do more testings and checking if all IRQ mappings are disposed. > > I'm not smart enough to do "more detailed review" because I don't know > what things to look for :) Thanks for all your work in sorting out > these arcane details! > > Bjorn