Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4493326rdb; Tue, 12 Dec 2023 00:30:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGd81OVyNA6pkDI5l8eLnYZe9EEiEx6zo+vHXklI+OdL1M1CAB5uM0nnmILdJqrc4VRfAZ X-Received: by 2002:a05:6a00:1951:b0:6b7:18c1:c09a with SMTP id s17-20020a056a00195100b006b718c1c09amr3614274pfk.5.1702369808798; Tue, 12 Dec 2023 00:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702369808; cv=none; d=google.com; s=arc-20160816; b=FmtcmVTD8KkHf6GGCEu6YCtBKZUs7QesI+VcstPmplwMjLsq0C28j3ytqbLEOEixKG tqxotPcqbEcSPhJnEtvsuRFhk0N4IqC29xTXQV6p93U3o4122MSIz7BA//z6jAo1xzsl UoECQNmBPHrYyT/wCgeKX+eOilY/cdTuI/+drqK7Ikn1QGlWz5opXlD+cogQDXIajUz8 5sQVEl2X1RocjwwbjGhvAYLDTlzGeKeZ6oLs+FHGuGsmVtRcxR9PidTwnRp1TIo4wagl QZvQyr12MrZNniYW3kNojv5d9tXZkqqWP0Y9EB8DQ1TrpGhyQGYhjuFdK+yxZKQ0tF+d sJSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=E9qH6anoPIu1fFHlQdJcDaDMF2TZeaJBTSNCTizOVQg=; fh=1vlKUeURsAt/zMOh4tjASWRnN4VX07xaBzRVhd1Vp80=; b=BXW9ENJ3bekQvWo162aXI8A9gx6eCppdfGkv+RVQYGcpve/kMac72juGzXCl6NlpR/ qOYpUlpXkman+O8FvtKtNPAClZSlJta3hfYqGUc1BrInsnDo8n7QWKnIXHHjZKvkGSxp D8QQn7TUFQQD9nfpirBAf00Gnuysu769QBY2+4ZoNGQtHoXYvPx/dvb0OTsLDDMnCzOx sS4TT48n2YF/oRrR8J+UEYrSu6N0/T4FWLIQfG4G6UTOjENKqusiDbSLUod/W2fxRlJP 6XHTC9nbn/HD9pah0rBRVJsg0G14r7hNDEendG0+TUr21pNam3zF+jBuXhsIuLB5E++h KXNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="gFYAT/+L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h7-20020a056a00230700b006ce03e2549csi7373954pfh.4.2023.12.12.00.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:30:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="gFYAT/+L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 865D0805F9C8; Tue, 12 Dec 2023 00:30:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345818AbjLLI3z (ORCPT + 99 others); Tue, 12 Dec 2023 03:29:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbjLLI3n (ORCPT ); Tue, 12 Dec 2023 03:29:43 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C792A325F; Tue, 12 Dec 2023 00:28:05 -0800 (PST) Received: by linux.microsoft.com (Postfix, from userid 1127) id 546A320B74C0; Tue, 12 Dec 2023 00:28:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 546A320B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1702369685; bh=E9qH6anoPIu1fFHlQdJcDaDMF2TZeaJBTSNCTizOVQg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gFYAT/+Lmsxa9SwAlA9n+5OHbwSCyty97O0d521bMKxld/+Ka3eJmK80OJBUpoXZz TetpPHNvq1W7jz22x0W382/PEScSES7rKFSNi4sTAJdZlP5jYuvhXn5Hnvv4i9q/Ux q1bnTzetUat6Rx442nYBO7eS8uAeWipb4Je6sq3M= Date: Tue, 12 Dec 2023 00:28:05 -0800 From: Saurabh Singh Sengar To: Alexander Stein Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, decui@microsoft.com Subject: Re: [PATCH] PCI/sysfs: Fix race in pci sysfs creation Message-ID: <20231212082805.GA3521@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1702093576-30405-1-git-send-email-ssengar@linux.microsoft.com> <5736414.DvuYhMxLoT@steina-w> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5736414.DvuYhMxLoT@steina-w> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 00:30:07 -0800 (PST) On Tue, Dec 12, 2023 at 08:19:11AM +0100, Alexander Stein wrote: > Hi Saurabh, > > thanks for the patch. > > Am Samstag, 9. Dezember 2023, 04:46:16 CET schrieb Saurabh Sengar: > > Currently there is a race in calling pci_create_resource_files function > > from two different therads, first therad is triggered by pci_sysfs_init > > from the late initcall where as the second thread is initiated by > > pci_bus_add_devices from the respective PCI drivers probe. > > > > The synchronization between these threads relies on the sysfs_initialized > > flag. However, in pci_sysfs_init, sysfs_initialized is set right before > > calling pci_create_resource_files which is wrong as it can create race > > condition with pci_bus_add_devices threads. Fix this by setting > > sysfs_initialized flag at the end of pci_sysfs_init and direecly call the > > Small typo here: direecly -> directly > > > pci_create_resource_files function from it. > > > > There can be an additional case where driver probe is so delayed that > > pci_bus_add_devices is called after the sysfs is created by pci_sysfs_init. > > In such cases, attempting to access already existing sysfs resources is > > unnecessary. Fix this by adding a check for sysfs attributes and return > > if they are already allocated. > > > > In both cases, the consequence will be the removal of sysfs resources that > > were appropriately allocated by pci_sysfs_init following the warning below. > > I'm not sure if this is the way to go. Unfortunately I can't trigger this > error on my imx6 platform at the moment (apparently timing is off). > But reading [1] again, the most expressive way is that pci_bus_add_devices() > needs to wait until pci_sysfs_init() has passed. (I correct my self a bit in my earlier reply) The problem with waiting is that sysfs entries will be created by pci_sysfs_init already and when pci_bus_add_devices try to create it will observe that the entries are already existing and in such case PCI code will remove the sysfs entries created by pci_sysfs_init. Resulting system will be having no sysfs entries. - Saurabh