Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp899058rwr; Thu, 27 Apr 2023 09:28:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7v6usfj+u+xO413Y8NZOrBGbqHIrhpVtpnc9XzraHFHDzvs9crWqKGWuH0rf5CFDzwrZGK X-Received: by 2002:a05:6a20:72a3:b0:c0:2875:9e8c with SMTP id o35-20020a056a2072a300b000c028759e8cmr3120264pzk.1.1682612933916; Thu, 27 Apr 2023 09:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682612933; cv=none; d=google.com; s=arc-20160816; b=ibhCLP85dlO+iE4CUldUb+fTlOMT9nATAjAtjCIco+notHd0gE/EGId1BHF1iLcNt2 9yxxDZYjdOs2QVdrvmOLAb7mU9I34S+LjRkdFER+gu6owJmhUhj+Ueu+tNRvrLYRr0li nvSqs2sSG29ekCUWcSP54Z3UL5v/5912EkRf8Ory9p9UYPJEqP75/maBovasEfA1czNo aHtT+DB5ZYQEhl2tcG7TmmF4nlsISOP6br+6PwXM7ymIQAud/DS9hw9DMHpLCs52ZOz1 0n7aprGvEEwWHBXj58W2QJIpiZ71oVdq0CS5mZ2cPhennGMSKOnToQ0cE90zjmHyeuA6 hwFw== 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-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=+mKQKMczfN+TlgwZiyO4BXk8fsV3/jMhqPdNiyNO9ek=; b=ZYqkOzKTDyc1j7fKg/HcUw1Z5AxzAab2VFpjcR+i9uqOukuiWGr2xmCDT4bNJ5oVa8 oBS4gI2rBnvdwCe3hZ8hENbJuSXvMRcjTfY6GJaJqvvpWd+WNo32yBEyQfoo5DUDdCIg Z0CQB8I9i+j4kIHDIvCVTqqv0nQktRPxlEMc3wJ5nQwsViOCwSMDvuzZpcjrdyrVghaj 6Kn+Wu5iVBs2vuV8gR1qJbyhJ5pQAc4Ridjuzt55xtdm1PrPLvrAP2zk1WCiBEjxa/ZG hO8CQqnf8kEjrWQ7Zyeq8hhPG6kWNjVw3Du2rUx1LFpydTnDvoVtCJCpNZL+H/aCnk34 kRDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NEXNs1L9; 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 v68-20020a626147000000b00639e52424a6si18392294pfb.146.2023.04.27.09.28.34; Thu, 27 Apr 2023 09:28:53 -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=NEXNs1L9; 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 S244000AbjD0QPF (ORCPT + 99 others); Thu, 27 Apr 2023 12:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232698AbjD0QPC (ORCPT ); Thu, 27 Apr 2023 12:15:02 -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 51B881FD4; Thu, 27 Apr 2023 09:15:01 -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 EADB361050; Thu, 27 Apr 2023 16:15:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 299DCC433EF; Thu, 27 Apr 2023 16:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682612100; bh=fxTrS+s2c8YlhXQmpP9j+DvPz8LMLKyuHrslsFK1DrE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=NEXNs1L91RH1f0081I2HTyPt6Mj5UFOrhXbEp1sHjFm+HbXtFP5DpJhC3lSAPxuTf +gfHIac8Dmez/eFaWLsGq0GD9+kt+INEqf9Ad+mUGbCafGEQ01eQ88hrAICxrUjH1V GRyH18e/c5aDylm9HEYGzA29Cbr8C0Lk4RdoiWi5jYbxSnLtRW0VlNvEI8Zte13jRG 9osgTQusKy+V+Jcm/YOZOdrz+gsijj3br7i+2mr+7j/hK/RkyXb9nC0Tr1mTAUrB3d bwJI4h68Qhd+uG7liwRndW6ufbJYPp8eLrJxqaUSk3ugt4sbOswq7G4Na5pMGRVxnj GEU8r/xV8PGQA== Date: Thu, 27 Apr 2023 11:14:58 -0500 From: Bjorn Helgaas To: Alexander Stein Cc: Bjorn Helgaas , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Korneliusz Osmenda , Oliver Neukum Subject: Re: [PATCH 0/3] PCI: Fix race condition upon sysfs init Message-ID: <20230427161458.GA249886@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> X-Spam-Status: No, score=-4.6 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,T_SCC_BODY_TEXT_LINE 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 On Thu, Apr 27, 2023 at 04:28:58PM +0200, Alexander Stein wrote: > Hi everyone, > > this series is a totally different approach for fixing the sysfs init race > condition. The initial problem is stated at [1]. Previous proposals were > rejected ([2] and [3]). Here is what's happening > > > CPU 0 CPU 1 > > imx6_pcie_probe() > dw_pcie_host_init() > pci_host_probe() > pci_scan_root_bus_bridge() > pci_scan_child_bus_extend() > pci_scan_slot() > pci_scan_single_device() > pci_device_add() > pci_sysfs_init() device_add() > sysfs_initialized = 1; bus_add_device() > for_each_pci_dev() ... > pci_create_sysfs_dev_files() > pci_bus_add_devices() > pci_bus_add_device() > pci_create_sysfs_dev_files() > > Eventually calling pci_create_sysfs_dev_files() twice on the same pci_dev. > It's a very tight window, deeper PCIe trees increase that window during > host probe. Asynchronous PCIe host probe is a necessity > (PROBE_PREFER_ASYNCHRONOUS). > > The first two patches are preparations for the last one actually fixing > the race. As functions like pci_create_sysfs_dev_files() are called from > externtal and internal to pci-sysfs, an internal version without checking > for sysfs_initialized is required. > For the fix a wait queue is introduced where all callers from external > callsites (regarding pci-sysfs.c) are waiting until pci_sysfs_init > initcall has finished and woken up all waiters. > > A subtlety is that within __pci_create_sysfs_dev_files the resource files > (created by pci_sysfs_init) need to be removed, so they can be created > again from pci_host_probe call. I'll look at this in more detail, but if there's any way at all that we could get rid of pci_sysfs_init() completely and do this with static attributes or some other existing sysfs infrastructure, I would STRONGLY prefer it because that infrastructure has already solved this problem. Maybe that's impossible and we really need to make a one-off solution just for PCI, but ... I haven't been convinced yet. > Links: > [1] https://bugzilla.kernel.org/show_bug.cgi?id=215515 > [2] https://lore.kernel.org/linux-pci/20230316091540.494366-1-alexander.stein@ew.tq-group.com/ > [3] https://lore.kernel.org/linux-pci/20230316103036.1837869-1-alexander.stein@ew.tq-group.com/ > > Alexander Stein (3): > PCI/sysfs: sort headers alphabetically > PCI/sysfs: create private functions for > pci_create_legacy_files/pci_create_sysfs_dev_files > PCI/sysfs: Fix sysfs init race condition > > drivers/pci/pci-sysfs.c | 87 +++++++++++++++++++++++++---------------- > 1 file changed, 53 insertions(+), 34 deletions(-) > > -- > 2.34.1 >