Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1450517rdb; Fri, 19 Jan 2024 22:42:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSqaH/bvwRlCtkbwyQoHcYPB70PM2+63I1FDP3WYSZUBCV8om8VjdAaW9hZSMnqVVjUpIb X-Received: by 2002:a17:906:1413:b0:a28:e326:a96d with SMTP id p19-20020a170906141300b00a28e326a96dmr494620ejc.117.1705732934791; Fri, 19 Jan 2024 22:42:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705732934; cv=pass; d=google.com; s=arc-20160816; b=hFpgeLpjk9nh3xLQ8vQeQOixcSGJPb4OT6UXQwkR81XKBWDJ/c/RfjQjEsvsRPrrPG 0NyfKstvV46FwTMGgz+fdxQRmfZA2AxRZF2slc0SJJAj0Nl9JSYT4f4M/DwF4d21NLp5 DJoSzKOYEvEKNftj22C6/BzTVmQINMAc7lddeDhh8puNCR4tYywDpe4p33VnhG85c0h2 R1uTGOfCuTPrmz+DVRrxlNyMTVEFuKju7J/4flliKgZ/huCqeloVkI3sL7OlMyjvg2Yd tzJKdj0ZT4jXTORUHEpRfv0y+JucqTtTdVjA0wK2ttKXkke5RlWchFDadXEBoGO0tgfj N3wQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=dDZa048057b+mL/IdAmyoRcwV68H5JKdVpgmpVrpWx8=; fh=1vlKUeURsAt/zMOh4tjASWRnN4VX07xaBzRVhd1Vp80=; b=lAXKsvzVtyeLLhjQD1GqqZhuIVlhwnZz+/gCV4psyP4Z4VAM5UclSMgXyZYac8uoFB 9MA7rUvw4gxl3ulDDlh3mmicsgOxS1zN8r74IcmYoelg18B7BTHDlEX6jJqiZv7+saTj OrLRTli3cR1wxiidne8f0pJldhUtBMnmjTbl5HGCs6KOf/eoj9bthOSOtpQOA4AymUk/ 19s7ZQwisU1fdgoxBIBlnRkqfjLK2zU2YgpEDiUqU/Se/Ut3CThM+q0eOmwcelXITPTR E0UJ1obfA4+nyjlQSFv+2K+hEoaDFSJJNx9TI7v7nqBE7TVHP412LRur31Ir53cAKGTi 6ZdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Ptvn843N; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-31720-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j2-20020a170906254200b00a2b12e231b1si8269155ejb.334.2024.01.19.22.42.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 22:42:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31720-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=@linux.microsoft.com header.s=default header.b=Ptvn843N; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-31720-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31720-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com 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 81C2A1F223FB for ; Sat, 20 Jan 2024 06:42:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E214520F8; Sat, 20 Jan 2024 06:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Ptvn843N" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D10D6EC8; Sat, 20 Jan 2024 06:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705732924; cv=none; b=V6BN8AHLYM1GaZQ1y50jaBVOyXiGwjd8lSO+xA49gdB0fNwKDiaLVR/EqdPdaQv7LmRgqsNOCFs0qNCEXnWT49oi0EfQCTE9bK/Xk3yuwLvAN0Q5/vcaZ6bwrQOv5jUO7C4LuBUEOQLS5WUOLtUSFjEp1GDPYshmIuf/jKClBM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705732924; c=relaxed/simple; bh=eIO89xILSdrUTep7U5mjbNLB6mGQy666g44edAJ3Sv4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BK9/uLNMbTeW1AUIUNkQMihyuYONqgReJ/Wscpa1C0ALKgYqXbsp9+637YaFmC2lSVrEAmIhU+KryCs7mw/kkUoIbO2CEPYM2wknmbNy5j5PbMs4/Bw0jj8zb4XhRdmigFdS5E47GlduU8Rm6451g6MWFeDGyCDWg8R6BgL67aU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Ptvn843N; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1127) id 64F8320DFE87; Fri, 19 Jan 2024 22:41:56 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 64F8320DFE87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705732916; bh=dDZa048057b+mL/IdAmyoRcwV68H5JKdVpgmpVrpWx8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ptvn843NtrBtQ0ZeT/e0IudCy+mQIrIUiWDqfRF22Gd/xSrLYUhxLvH1vWyR/BsU1 ilvk5Qlri5i1pS+0OuAdsbuWuhgOhvGtKhHmEvgUpgsb64I+rPO1EQMa0g93kZkFZd UUlfWQ83+LYfPDuxCEKYdblQXkORSzDs5EIYqL/g= Date: Fri, 19 Jan 2024 22:41:56 -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: <20240120064156.GA3130@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1702093576-30405-1-git-send-email-ssengar@linux.microsoft.com> <5736414.DvuYhMxLoT@steina-w> <20231212082805.GA3521@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20240104053803.GA16954@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240104053803.GA16954@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> User-Agent: Mutt/1.5.21 (2010-09-15) On Wed, Jan 03, 2024 at 09:38:03PM -0800, Saurabh Singh Sengar wrote: > On Tue, Dec 12, 2023 at 12:28:05AM -0800, Saurabh Singh Sengar wrote: > > 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. > > > Hi Alexander, > Have you got time to check this ? Please let me know if you think there is any > concern left with this patch. Hi PCI Maintainers, If there is no objection, can we take this patch in ? Regards, Saurabh