Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp597610lqg; Fri, 1 Mar 2024 15:05:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWOtvdgF+DdC2jDf1jtppc5+1GcllbAvoFG2Wo9ayMCMrwUi9/p7U004FXkhuGOTB/7mqfK+XBTK+EOo0ZWIHe7yaettUmGP/uD6sjVIQ== X-Google-Smtp-Source: AGHT+IF3oK85trcyEJrYDlbP2b3dWQ/dKCeR1x/iegAfxq7XOEhaYclQl5coqaAjo8DwwHCM4QB1 X-Received: by 2002:a17:906:2651:b0:a43:9e1f:240e with SMTP id i17-20020a170906265100b00a439e1f240emr1918112ejc.60.1709334347220; Fri, 01 Mar 2024 15:05:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709334347; cv=pass; d=google.com; s=arc-20160816; b=s82cehHj9VHMp8ofGchfB+nq48P4KReK51Nxa29juNUdAqGyCD2NSIdpLnjoT++nD3 hcc2qeEQzjMCws/5rVmkd14gzihL2UY090eu3oV8atM46E3+AzIyUJEGmDef0XST/+5Q +/wNXhd3ykb8G8Yk6PEzzVHd0FebAhZ84jKcFpKRd7XC8uMnV/jwIxAsv1TLEV2XI5Wr 7ZxrxPrcmd3ybDvj5EFV87lDTtdcJK9oeAb2koK/nFrZ8HyeV/e1fqX7Q+UuYxg2mhr1 fNxelfNY3xdYSPUe3H4N/xHOJKm13hmVYvnd/VudB9uKuCyHqGhGz0RXM05yrp458TDc 7/4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=FZ9aoAeUfpNRskRCBz8BkioLby57gJekZBFuNFMLe2w=; fh=XOdxvOPFO43Gru50Zqka/kqYvyLObWj4+VQLNKZS/BU=; b=EoTC+Fw8ZOoE8qT3jT/fUVuh5q97gIfkscugIo2xM9YJzNAi3XfwQdjJDHJsj3o5Wa ROmhcBMzVUv5ipVI+/m6gjdpD8QI4bs/M2DUBzZ+0ndBRmeDpWJSSJesUKMSVZt3N7lp NU6pdUr9GI1njOscftt5Ze0HdtfLQDlDhravaaOVZrEPgAYbMP7G+InsRU0coJszsubp y04x59v5O+MJca4FOxPDx82ncLbrpAxUKIj5u6ZP0bttMMry5kLkDlR3NMJCIwV+oyZ8 uJg5xFCNFenneHvcPNhU9xPJ7Iu9CVzGRBe/jBQUEc0Yonv8PA6MnI0+7mx52KXfaqZO zq0A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dyApand6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89215-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id mc12-20020a170906eb4c00b00a443e8fea05si1858688ejb.49.2024.03.01.15.05.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:05:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dyApand6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-89215-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89215-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C86B21F220BE for ; Fri, 1 Mar 2024 23:05:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 916A95EE83; Fri, 1 Mar 2024 23:05:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dyApand6" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88DF01F16B; Fri, 1 Mar 2024 23:05:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709334339; cv=none; b=fZlzKAqswjlCQKwl0Vq1TXfx/QpT8x6GgObYYqCLeWTEVqwfbtAry30HYgdsQysiTSgegXxvhXr9PH+gZCK4RoF1bEC4ffw8XfVIooc6tIgwlZfkNF+vtdDc7D4kCqmfM0s55c0265CYMmlQ1tCh9oSDbJnRs/MqLq51ec4q1j4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709334339; c=relaxed/simple; bh=1wHBV3+ScYtLUNAXwGGPEnRrUacQTReGxON5TeeDW2Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DPQJx49LWkKQSD37aFP9AsKbz3NXDuym3XbXv7cH27fxitk7OSl0hE9zqmyjdi35E/2EFK1IsiShDgm7SbUViDYMqbOYL0z6UTjYq0wfiD33YaOSh83tOjRQ8jFbq2DseY09yc9FL9NoNWo1Coz6x94CdU7FBB5CrYfw6TkOfec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dyApand6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A50DC43394; Fri, 1 Mar 2024 23:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709334339; bh=1wHBV3+ScYtLUNAXwGGPEnRrUacQTReGxON5TeeDW2Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dyApand6fpSIYi5mrXLtftnBF8X9eE3ub8/k54U5N69kyLMgKtTr8A6ryykNrJaXP C6BAQy6wyHY/5pRkFx1EbWm35N4EIq/Lm/v51AxIWqZNhWq260tVQqh8QPqlZnjZYT RGoDPnYzSjtZoAKDl3gQZ12iEKBSwJgfVYHh8SOxkjyJvDps7Y9fA9dXO+te3TWn12 fFBuSbln1hi9Ce15/VTQYoISYluGhEE2aIQmuVJwGmPIiCaOP5z56YtUXyCskToLxU Efd5s/DG6lAkfeGVoReLEe0s37lw1z71pbNAT1hHbYJd+tAM87LZ9T9nGHCr8Ni4oO 5nTR/gA/k4qxg== Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so29346171fa.3; Fri, 01 Mar 2024 15:05:39 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVFQTQcLV74AyjX2/cnD3HooTwWeMRLoQ4Hgas5drB6jJZy+umot7tBN45IUnKZqOBknujWjcQ4YWwmJWA+tFy4THaPKHwffSaRRKYH4GArh+2X+++B8mMzpqd679P8PhOn5VYokdoiDA== X-Gm-Message-State: AOJu0Ywt2HF13et/rrZCHubIE8j0lp7ebQTzNdsMmcJ1HnsikavShQQD kEWNRURFwsRH2NGWWZbduYlOTsrIKhx+dKJ3S1DvQMRUTmU2H14AO92GebM6p9+JiTyV1VLMyd9 enllU5OYp1+G/QPf+QTDsTTj1hw== X-Received: by 2002:a2e:2c13:0:b0:2d2:2dbb:389e with SMTP id s19-20020a2e2c13000000b002d22dbb389emr2078375ljs.23.1709334337256; Fri, 01 Mar 2024 15:05:37 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240228062138.1275542-1-peng.fan@oss.nxp.com> In-Reply-To: From: Rob Herring Date: Fri, 1 Mar 2024 17:05:24 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: dynamic: notify before revert To: Peng Fan Cc: "Peng Fan (OSS)" , "saravanak@google.com" , "bhelgaas@google.com" , "pali@kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 29, 2024 at 9:04=E2=80=AFPM Peng Fan wrote: > > > Subject: Re: [PATCH] of: dynamic: notify before revert > > > > On Thu, Feb 29, 2024 at 2:01=E2=80=AFAM Peng Fan wro= te: > > > > > > > Subject: Re: [PATCH] of: dynamic: notify before revert > > > > > > > > On Wed, Feb 28, 2024 at 12:13=E2=80=AFAM Peng Fan (OSS) > > > > > > > > wrote: > > > > > > > > > > From: Peng Fan > > > > > > > > > > When PCI node was created using an overlay and the overlay is > > > > > reverted/destroyed, the "linux,pci-domain" property no longer > > > > > exists, so of_get_pci_domain_nr will return failure. Then > > > > > of_pci_bus_release_domain_nr will actually use the dynamic IDA, > > > > > even if the IDA was allocated in static IDA. > > > > > > > > That usage is broken to begin with unless there is a guarantee that > > > > static and dynamic domain numbers don't overlap. For example, a > > > > dynamic number is assigned and then you load an overlay with the sa= me > > number defined in it. > > > > > > I may not describe it clear, the code is here, because overlay > > > property removed, of_get_pci_domain_nr will return failure, so the > > > code path will goest into free a dynamic ida. But actually there is n= o > > > such dynamic ida, so dump. > > > > I understood the problem. > > > > Your usage of this is broken on applying your overlay. You just got luc= ky. > > Would you please point me out where is broken on using overlay? > > https://github.com/siemens/jailhouse/blob/master/driver/pci.c#L458 I'm not saying your exact use is broken. Obviously, it worked for you. In general, it is fragile. What happens with the following combination?: base.dts: { pci@0 { linux,pci-domain =3D <0>; }; pci@1 { /* dynamic domain allocs domain 1 */ }; }; overlay.dts: { pci@0 { linux,pci-domain =3D <1>; }; }; The only way this can work is if the overlay linux,pci-domain is ignored if there's a conflict or you reserve first N ids for static and dynamic ones start at N where N is "should be more than anyone needs". > > > So the problem is overlay was removed, but the notify callback may > > > still use the property to do some work. > > > > > > static void of_pci_bus_release_domain_nr(struct pci_bus *bus, struct > > > device *parent) { > > > if (bus->domain_nr < 0) > > > return; > > > > > > /* Release domain from IDA where it was allocated. */ > > > if (of_get_pci_domain_nr(parent->of_node) =3D=3D bus->domain_= nr) > > > ida_free(&pci_domain_nr_static_ida, bus->domain_nr); > > > else > > > ida_free(&pci_domain_nr_dynamic_ida, bus->domain_nr); > > > } > > > > > > > > > So move the notify before revert to fix the issue. > > > > > > > > You can't just change the timing. Something might require notify to > > > > be after the revert. > > > > Again ^^^ > > > > > > > > > > > Fixes: c14f7ccc9f5d ("PCI: Assign PCI domain IDs by ida_alloc()") > > > > > > > > I don't see where the notifier is even used. > > > > > > The stack is as below: > > > > > > [ 595.150529] CPU: 1 PID: 582 Comm: jailhouse Tainted: G = O > > 6.5.0-rc4-next-20230804-05021-g3d4cc14b42ef-dirty #355 > > > [ 595.161998] Hardware name: NXP i.MX93 11X11 EVK board (DT) [ > > > 595.167475] Call trace: > > > [ 595.169908] dump_backtrace+0x94/0xec [ 595.173573] > > > show_stack+0x18/0x24 [ 595.176884] dump_stack_lvl+0x48/0x60 [ > > > 595.180541] dump_stack+0x18/0x24 [ 595.183843] > > > pci_bus_release_domain_nr+0x34/0x84 > > > [ 595.188453] pci_remove_root_bus+0xa0/0xa4 [ 595.192544] > > > pci_host_common_remove+0x28/0x40 [ 595.196895] > > > platform_remove+0x54/0x6c [ 595.200641] device_remove+0x4c/0x80 [ > > > 595.204209] device_release_driver_internal+0x1d4/0x230 > > > [ 595.209430] device_release_driver+0x18/0x24 [ 595.213691] > > > bus_remove_device+0xcc/0x10c [ 595.217686] device_del+0x15c/0x41c > > > [ 595.221170] platform_device_del.part.0+0x1c/0x88 > > > [ 595.225861] platform_device_unregister+0x24/0x40 > > > [ 595.230557] of_platform_device_destroy+0xfc/0x10c > > > [ 595.235344] of_platform_notify+0x13c/0x178 [ 595.239518] > > > blocking_notifier_call_chain+0x6c/0xa0 > > > [ 595.244389] __of_changeset_entry_notify+0x148/0x16c > > > [ 595.249346] of_changeset_revert+0xa8/0xcc [ 595.253437] > > > jailhouse_pci_virtual_root_devices_remove+0x50/0x74 [jailhouse] > > > > $ git grep jailhouse_pci_virtual_root_devices_remove > > (END) > > > > Another out of tree overlay user. I have little interest in worrying ab= out them. > > No one wants to step up and solve the problems with overlays, so I'm no= t > > going to worry about them either. > > Ok, but I think this is indeed an issue, if driver accessing property aft= er > property removed with overlay revert. A pre-remove notifier might be useful, but as I said, you can't just remove the post-remove notifier without some justification why no one needs it. Notifiers aren't the best construct in the kernel, so adding to them isn't really desired either. Also, I think there are 2 other issues with the design here: Generally, the code should read the DT once upfront and not need the DT later on. So needing to access the DT on removal is kind of suspect. That's like needing to read USB device descriptors after a USB device is unplugged. It also seems like the driver should hold a reference to the DT node(s) it needs to prevent removal until it no longer needs them. Not sure if the node refcount would be enough or we need something more. Rob