From patchwork Thu Apr 27 14:28:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 88282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp311620vqo; Thu, 27 Apr 2023 07:33:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65ty77p1mQKSxxkugb79BXqxbqcQeIA08I3Ztkj73t3GrWK2FxlQozf4AHSUHLi97qnYL/ X-Received: by 2002:a05:6a20:7f97:b0:f3:67da:9db5 with SMTP id d23-20020a056a207f9700b000f367da9db5mr2327496pzj.38.1682606025600; Thu, 27 Apr 2023 07:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682606025; cv=none; d=google.com; s=arc-20160816; b=gLH7uWkLk8ciZwA2rh0N10skJI0RKv7U0eBZmNjl3LPYMHbAB0Jiz/o6bNy/3uUw2C 6RrJZNDdUKko98ao9Q6oahd2FWLyk2y1G/wgnqnwH8RNOuCGLVFAZyEocEUykAZd1pxb DJHduHu3Tb3eA9vaSwHtfGOAIskP56J1mtnVv4MVuqdCEZPv4EsvlKR3p+bv7OaYzt2e GYJe5CJsRhUsye3Gnou1kZlASKrKJAgDQJiDyl3RM7tSLWM+sAIiZqigy9uEPc4gnJ9H 6E0dp+Q6UCUi8wpNny2Z6PAA0SbT4a9kJ2oPTCURgTqURtpmMENwizVLWtPEEth3INrA IDLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Ds9/wjMM0PLi1AVS093HPsnv7S1iVHOpqdUFFwjwWNA=; b=LiZus/0Byf7zWXjw8zdgGM0gRD6dtOCTgI+KvvC/tjtJkHn/5L8cr5ojL6I+T3HnAO 5bdLjy1ctk2dsVwmYYsqudcf7+aBkstppWtowULztUbub1QVd7pktm8++uj7iS8PLpnh 5FkMdaVKk4ifaCaBA3TH5f7BNSLLpNpqxRGWyiA3UTSRJ5BzQ9mdeH5aKBtWCa3AaFKv UNZ2n72bEfuKyhjca+RGuXLA1dneCHeoWCp13ZCJU3tUAVxfR/iSbTIjx/xDecjs7ZSu Fq8l/cVN523scQ/kZmBwNqjsUkMqyB7A482UmG12zBj66aWicWpNSxHNRRPdJkb+xSBy JY/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=aRDJnYIs; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Lf3pZ+ea; 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=tq-group.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v6-20020a63f846000000b0051b58fc93b3si19456902pgj.223.2023.04.27.07.33.30; Thu, 27 Apr 2023 07:33:45 -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=@tq-group.com header.s=key1 header.b=aRDJnYIs; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Lf3pZ+ea; 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=tq-group.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244062AbjD0O3O (ORCPT + 99 others); Thu, 27 Apr 2023 10:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243466AbjD0O3M (ORCPT ); Thu, 27 Apr 2023 10:29:12 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 616CC1FE6; Thu, 27 Apr 2023 07:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605750; x=1714141750; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ds9/wjMM0PLi1AVS093HPsnv7S1iVHOpqdUFFwjwWNA=; b=aRDJnYIs6BSGz+H8xZcyZZW+5SgtWCavWxX0TtbX050+hrU1hUvGZXSN n1S6pkdxYbt/Bg8Z2ViIgTt0D7ls2ACf1PFdwCZ9EZJltoEUnRCVnKYRB gzq+8fAEh+X+lOj1V1HTtUWWyXBO5a9R/h+i2DbZN1y4GMKJA2Uudpiia Y2Uwpy4PY/+JINuLeYlt4e9X9ZQOJDPLAPXbDdPsoCegYviMOceilfRlq Sl/XjPRO2aIHAnf/d/qDBOHuKIAm4k+dB4n876lYojU0R5kNlYvgKatRk NeQnEW8i8go7IUX+ZPD2BEAYyb0rc12ggWridICIQufyXwhE7eGDE3H1y g==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607876" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Thu, 27 Apr 2023 16:29:08 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Thu, 27 Apr 2023 16:29:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605748; x=1714141748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ds9/wjMM0PLi1AVS093HPsnv7S1iVHOpqdUFFwjwWNA=; b=Lf3pZ+ea6b614EGfAExzt9LtkoOJHhiswD3PWBQSZsIWGv6tfZ3/6qGL 0TYgZNuEHS3HTdLWRf2culOpckhf/koWsgPgI+61NM2W0TGaMuq4WwCQT BkWkhyXcSg2oBwabsaTSgM9DOhNFQ10C/rdYX97w1jL2wpw9Jt/dBeAhG r/u5e0o7WGfq+QqL7vNXkpNRvMdwC17/GbzYes8o4NNjBxjIMoRmRxiRV Ue0p9GTLypeKWc2LUKfzdDIsAzcLJKrW19YTmPgQ5wuvPJEAToMkWw6JG OUw+cAapmw8Jk795tka/sLi8oeCh0RplRg9b2LXtX8pQbwBZETqO9e6E0 Q==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607874" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from steina-w.tq-net.de (unknown [10.123.53.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id 44DD7280072; Thu, 27 Apr 2023 16:29:08 +0200 (CEST) From: Alexander Stein To: Bjorn Helgaas Cc: Alexander Stein , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Korneliusz Osmenda , Oliver Neukum Subject: [PATCH 1/3] PCI/sysfs: sort headers alphabetically Date: Thu, 27 Apr 2023 16:28:59 +0200 Message-Id: <20230427142901.3570536-2-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> References: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764340295519441871?= X-GMAIL-MSGID: =?utf-8?q?1764340295519441871?= The includes were not sorted alphabetically. Sorts them properly. Signed-off-by: Alexander Stein --- drivers/pci/pci-sysfs.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index ab32a91f287b..289c1c17b41f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -13,22 +13,22 @@ */ -#include -#include -#include -#include +#include +#include #include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include #include -#include -#include -#include -#include #include "pci.h" static int sysfs_initialized; /* = 0 */ From patchwork Thu Apr 27 14:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 88291 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp320685vqo; Thu, 27 Apr 2023 07:48:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5I3VMGbRcrZ1nPOB1YdMPWILm3aY7kB7/23ko+0FBwIU9n8y16jqIy7jdtfyLpQkMkhrZJ X-Received: by 2002:a17:90a:ce8a:b0:24b:fd98:f760 with SMTP id g10-20020a17090ace8a00b0024bfd98f760mr2339457pju.0.1682606924837; Thu, 27 Apr 2023 07:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682606924; cv=none; d=google.com; s=arc-20160816; b=gYbgQbBOPBS/FFvnCvu80227BeKBK11BUIE0iYApPhVOm7IGs5idMC/eqfpJl5e04Z UOTI1mHUAE6Zh/tEFNuMM/JUfwIg753QE/+S5Nk8lKqmDWtY4PPSEJHk2pecGmsdVjn1 14lQm/c34geHhUHFPbpw8psyCatng2WowTi00/m/jwavZGdMuGX+3TmllwQfjO54ag55 5AXLX2aK+F1tgj5W+n7Ro8ZUQIcJI3uoS+oPCaYMHz6N8cfVNS+ZI5lxGjHTxvz31ckl SIxdiE2Xy12sANzM4DqP9eDgeedC6xb11ylyd83Wkh30hQ8vab0j7xJQ7UzvGLMCXE4b cvLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=vJflgAPzg8RDVjQuBtT2lckjqglKouKkXFWqrky4874=; b=VNBDFeDoVXALmrkfuBcgyw1woEtfld0oRSr78Md8sYYborvwkk8nQPhh9vdBpL71ku 1/rWwyh4oJdXVwEN+KjYGVm99is/DGyNgkP6fcuVVuxFCoCdqEs/Rn8qNSJMYH0y5eqD HPLTot1GDUQwu6+MqNMaBvDwaWVmczLJ5GYBhtBOOTS6MzaQEKzVOBsc5vFYVt8pzcef 5IdC5n6jzNI/B+kBEHuHC0v3+E7swzAYaRovTosB1XNuPIXl7eQIMgsgrRIKiZs5iush 3rulLYp+gYegMATxnSI2Z0zqe2LUJkcQXjIx9d+/aLI+fxLHA8k9pUio3tcw9MKrdfvz M8vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b="lNSX9/k5"; dkim=pass header.i=@tq-group.com header.s=key1 header.b=az0+pLIQ; 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=tq-group.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a170902e80300b001a979141a24si11443819plg.214.2023.04.27.07.48.30; Thu, 27 Apr 2023 07:48:44 -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=@tq-group.com header.s=key1 header.b="lNSX9/k5"; dkim=pass header.i=@tq-group.com header.s=key1 header.b=az0+pLIQ; 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=tq-group.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244082AbjD0O3T (ORCPT + 99 others); Thu, 27 Apr 2023 10:29:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243792AbjD0O3P (ORCPT ); Thu, 27 Apr 2023 10:29:15 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E521FE6; Thu, 27 Apr 2023 07:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605754; x=1714141754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vJflgAPzg8RDVjQuBtT2lckjqglKouKkXFWqrky4874=; b=lNSX9/k5JwXMkTeJ69tJQheMy9gG3OAvcpf6TySB/PAWGke1awr9fIBG MSmS6JcNiyCxaL6eHBxyZIAkkoLU1Ifws2yhX2X/ji7LVWLluDgD9SQGV 5DLldgAc6jeM7mOM2I8BsC1uJcjnwj3CN+/oxbe/ZyAWXedtrFUY+irjM 4BN4Ui4EcmTWdpXMJZ/wCwpX7NklNt944XyEagOCIJxBcXPI9gahPZWgM 74rDtdyxTJ0oMObAJh2XaYBmM375EIxvSAMI8faUuWJvf2bh+EfGByhyu M0xNl7kJe2fRUrX7KUEe/ULNkqnt0qAl0WPNmmPe2kSk4dlDTBqet//70 A==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607878" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Thu, 27 Apr 2023 16:29:08 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Thu, 27 Apr 2023 16:29:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605748; x=1714141748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vJflgAPzg8RDVjQuBtT2lckjqglKouKkXFWqrky4874=; b=az0+pLIQtDltHklgOlpPW/vYzuzilM5OvJaA8lhubHdk2XIDm7hSfLFR YEYFOifqAoVpR44WpCzIuduLURIqSqMqVsaZq8WmngcguuhkSqW1shGUK bVrUNq91XnGGtFZY800VnNbee+JYG7nVwKsgNd7XnBMnKlEfHgZrH9njk yGp7q56irFhF3R3TxGiKBv2RnqqNXAnRbKAMa3XbL2n8Q0dC7a8uNTaC8 XWE1AJkISc2mZZZsrCWJhSx/7/zAFzFUtfeN74RCfkfJoUErwm0s81RmU wd9xIvhD0yiIvWo1T14QsWCMz5gKZpk1ImAtPUi6Y/esyqKi8LIIgF/0z A==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607877" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from steina-w.tq-net.de (unknown [10.123.53.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id 67CE1280073; Thu, 27 Apr 2023 16:29:08 +0200 (CEST) From: Alexander Stein To: Bjorn Helgaas Cc: Alexander Stein , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Korneliusz Osmenda , Oliver Neukum Subject: [PATCH 2/3] PCI/sysfs: create private functions for pci_create_legacy_files/pci_create_sysfs_dev_files Date: Thu, 27 Apr 2023 16:29:00 +0200 Message-Id: <20230427142901.3570536-3-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> References: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764341239300319482?= X-GMAIL-MSGID: =?utf-8?q?1764341239300319482?= The only difference is they don't have the check against sysfs_initialized. This is a preparation for the sysfs init race condition fix. No functional change intended. Signed-off-by: Alexander Stein --- drivers/pci/pci-sysfs.c | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 289c1c17b41f..7d4733773633 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -938,24 +938,10 @@ void __weak pci_adjust_legacy_attr(struct pci_bus *b, { } -/** - * pci_create_legacy_files - create legacy I/O port and memory files - * @b: bus to create files under - * - * Some platforms allow access to legacy I/O port and ISA memory space on - * a per-bus basis. This routine creates the files and ties them into - * their associated read, write and mmap files from pci-sysfs.c - * - * On error unwind, but don't propagate the error to the caller - * as it is ok to set up the PCI bus without these files. - */ -void pci_create_legacy_files(struct pci_bus *b) +static void __pci_create_legacy_files(struct pci_bus *b) { int error; - if (!sysfs_initialized) - return; - b->legacy_io = kcalloc(2, sizeof(struct bin_attribute), GFP_ATOMIC); if (!b->legacy_io) @@ -998,6 +984,25 @@ void pci_create_legacy_files(struct pci_bus *b) dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n"); } +/** + * pci_create_legacy_files - create legacy I/O port and memory files + * @b: bus to create files under + * + * Some platforms allow access to legacy I/O port and ISA memory space on + * a per-bus basis. This routine creates the files and ties them into + * their associated read, write and mmap files from pci-sysfs.c + * + * On error unwind, but don't propagate the error to the caller + * as it is ok to set up the PCI bus without these files. + */ +void pci_create_legacy_files(struct pci_bus *b) +{ + if (!sysfs_initialized) + return; + + __pci_create_legacy_files(b); +} + void pci_remove_legacy_files(struct pci_bus *b) { if (b->legacy_io) { @@ -1006,6 +1011,8 @@ void pci_remove_legacy_files(struct pci_bus *b) kfree(b->legacy_io); /* both are allocated here */ } } +#else +static void __pci_create_legacy_files(struct pci_bus *b) {} #endif /* HAVE_PCI_LEGACY */ #if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE) @@ -1492,12 +1499,17 @@ static const struct attribute_group pci_dev_resource_resize_group = { .is_visible = resource_resize_is_visible, }; +int __must_check __pci_create_sysfs_dev_files(struct pci_dev *pdev) +{ + return pci_create_resource_files(pdev); +} + int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) { if (!sysfs_initialized) return -EACCES; - return pci_create_resource_files(pdev); + return __pci_create_sysfs_dev_files(pdev); } /** From patchwork Thu Apr 27 14:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 88283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp311857vqo; Thu, 27 Apr 2023 07:34:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73MkfkloTp7zBwUmK1fjr1zkV/vdARsQrmuerlAV3UgriaPaZv4CtvNLz5gCcjFBUXcJ29 X-Received: by 2002:a05:6a20:160a:b0:f5:6cb8:105 with SMTP id l10-20020a056a20160a00b000f56cb80105mr2472694pzj.45.1682606049110; Thu, 27 Apr 2023 07:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682606049; cv=none; d=google.com; s=arc-20160816; b=k0MRmVGNJrT7jlL+oZBpQ+WJPlh/LFSQw0KEsFrhlFnV7zFfDt7l+FxRLTXHecimHL ebDo8uaoyoOQ5yp6IY0F/ScsVtBoJ+iTs+0vKzaxC+F19r8SynY2K0oqiuSH7THeccmO kjbUNQJU88I+J9ErVHGv1CF4eUES8nzSrC+1lajP8ILag/j7aCW2POiQ/eJ2F8KvaPJ4 HDMZmrayZACeycvLGfXOd0npKeWqzdQh2UFAOwCWSdozhmCwZzbX3mlmsRgBVRwnHEz/ I+aMEIsLOMTBB3zTZMKJl/UPtC2iMiO7wy02JTtianqKDea7Cyj/YEWvsQUhvnrqk/12 uuOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=tCtpg2kzjPTTO6+C2f0a+KHi0QEOneW24SbJ2emNudM=; b=ftRRkGDY/UeYA0H/2tZWDxHtXS+FVRnewrZHKaXQJhS09xyU+epy1/TdCuMmh/908Z Dvxr0eExTp3Dv5pJLP0vXM74Vyd4x77e6XEMrnWTof1V6LwmeqY6+XNLqHBxbBO2hPN6 AfdDXv+fI9qaDpwJNX6Iu36zGQgIAEbC/LmkHFYIO00XF9HlAnYvEXiVkQFvv1x2pjRm Ln3drX2cI+/Dz89N+ELBii/BjrEQdA6SgiCTXCyOQoTf4oxhVSWfCQ77BVf1ZaRAB4xb 8Ckh4f/cNnq83aiOufRd5rUQqKy+/0GdZ4s6AD2vlZqUxmaR8rAAr28HNcGk0ECyd37T BWQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=KuRJGzx8; dkim=pass header.i=@tq-group.com header.s=key1 header.b="L/YQ/vIT"; 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=tq-group.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l25-20020a656819000000b005285e30a362si8583238pgt.593.2023.04.27.07.33.54; Thu, 27 Apr 2023 07:34:09 -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=@tq-group.com header.s=key1 header.b=KuRJGzx8; dkim=pass header.i=@tq-group.com header.s=key1 header.b="L/YQ/vIT"; 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=tq-group.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244065AbjD0O3W (ORCPT + 99 others); Thu, 27 Apr 2023 10:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244069AbjD0O3Q (ORCPT ); Thu, 27 Apr 2023 10:29:16 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D30030D6; Thu, 27 Apr 2023 07:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605754; x=1714141754; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tCtpg2kzjPTTO6+C2f0a+KHi0QEOneW24SbJ2emNudM=; b=KuRJGzx8lV/sjwNP8LiRfyjcPYIr/uzas9q7X5CR1JLofBbzBeht2++J dWTwnz05ekqzDhTnbBuSZjciM9HdogMDwhebauSSGYwr7CoYj/+xs+EwU vAmunHg151Xw19B8ekWqdWISH8fRus9yC0BBHNAZ6gWgWlawHOMh9+wou Zvx4kohor+ahPXXrshk4uhHqizqsvq/3LctRlS//CKqW3Yys22SQ54v0g X4hYcXrjtO8V/0cfEIkILvUQCe7DjWoS0zY/qDqRhGPJxLbNaAf86Q2Yq x8DRawIcIO4bIe0LdjRWCD5beb8JK2kUktzWXM3fqccy6/nXfCmJZTntN w==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607880" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Thu, 27 Apr 2023 16:29:08 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Thu, 27 Apr 2023 16:29:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1682605748; x=1714141748; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tCtpg2kzjPTTO6+C2f0a+KHi0QEOneW24SbJ2emNudM=; b=L/YQ/vITar0NtqrbWXl/dzAKUrkYB78hr85SoNiuvkk2LgBeuBaxjq3O pHNBG/UPBA9e8J04M99Bs7W5MlpYEsSRbG8ULCnbGJzbrIGikXukmOuxn PP9mwMOAK42eLIvERYXunEQSUmUkyC+2zfc/WvR/34Yj1Ij6HfYNZ4WcV xTrRtb7ry/xPoOb1FeNX/eSKgI0yqMSUqUgphI9qUkhHzzSIhwDIXokM+ HdH+JEHvMZ8LxjAlN/OanFNsvnEEpVUpfXEAucSY+32nZXF3BOX9kB6zW XyfrVpykrcgsgVXO45fycQS405a5/4PsOxne+Hem5lgcBnZjQ/h9+fGfO Q==; X-IronPort-AV: E=Sophos;i="5.99,230,1677538800"; d="scan'208";a="30607879" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 27 Apr 2023 16:29:08 +0200 Received: from steina-w.tq-net.de (unknown [10.123.53.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by vtuxmail01.tq-net.de (Postfix) with ESMTPSA id 8F0A1280056; Thu, 27 Apr 2023 16:29:08 +0200 (CEST) From: Alexander Stein To: Bjorn Helgaas Cc: Alexander Stein , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Korneliusz Osmenda , Oliver Neukum Subject: [PATCH 3/3] PCI/sysfs: Fix sysfs init race condition Date: Thu, 27 Apr 2023 16:29:01 +0200 Message-Id: <20230427142901.3570536-4-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> References: <20230427142901.3570536-1-alexander.stein@ew.tq-group.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764340320276968701?= X-GMAIL-MSGID: =?utf-8?q?1764340320276968701?= sysfs attribute files for PCIe devices (pci_create_sysfs_dev_files) can be created by two paths: 1. pci_sysfs_init() 2. pci_bus_add_device() (drivers/pci/bus.c) There is a race during startup where an asynchronous PCIe host probe races against the pci_sysfs_init() late_initcall. In this case the PCIe devices are already added to the bus, for_each_pci_dev() will see them, but pci_bus_add_device() has not yet finished, so both code paths try to add the sysfs attributes. Fix this by waiting on a workqueue until sysfs has been initialized. pci_sysfs_init() needs the internal function without the check that sysfs_initialized has been set to 1. __pci_create_sysfs_dev_files still needs to remove resource files, which might have been created during pci_sysfs_init initcall. Signed-off-by: Alexander Stein --- drivers/pci/pci-sysfs.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 7d4733773633..3067d55f981c 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -29,9 +29,11 @@ #include #include #include +#include #include "pci.h" static int sysfs_initialized; /* = 0 */ +static DECLARE_WAIT_QUEUE_HEAD(sysfs_wq); /* show configuration fields */ #define pci_config_attr(field, format_string) \ @@ -997,8 +999,7 @@ static void __pci_create_legacy_files(struct pci_bus *b) */ void pci_create_legacy_files(struct pci_bus *b) { - if (!sysfs_initialized) - return; + wait_event(sysfs_wq, sysfs_initialized); __pci_create_legacy_files(b); } @@ -1501,13 +1502,18 @@ static const struct attribute_group pci_dev_resource_resize_group = { int __must_check __pci_create_sysfs_dev_files(struct pci_dev *pdev) { + /* + * sysfs attributes might already be created by pci_sysfs_init(), + * delete them here just in case + */ + pci_remove_resource_files(pdev); return pci_create_resource_files(pdev); } int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) { - if (!sysfs_initialized) - return -EACCES; + /* Wait until sysfs has been initialized */ + wait_event(sysfs_wq, sysfs_initialized); return __pci_create_sysfs_dev_files(pdev); } @@ -1520,8 +1526,8 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) */ void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { - if (!sysfs_initialized) - return; + /* Wait until sysfs has been initialized */ + wait_event(sysfs_wq, sysfs_initialized); pci_remove_resource_files(pdev); } @@ -1532,9 +1538,8 @@ static int __init pci_sysfs_init(void) struct pci_bus *pbus = NULL; int retval; - sysfs_initialized = 1; for_each_pci_dev(pdev) { - retval = pci_create_sysfs_dev_files(pdev); + retval = __pci_create_sysfs_dev_files(pdev); if (retval) { pci_dev_put(pdev); return retval; @@ -1542,7 +1547,9 @@ static int __init pci_sysfs_init(void) } while ((pbus = pci_find_next_bus(pbus))) - pci_create_legacy_files(pbus); + __pci_create_legacy_files(pbus); + sysfs_initialized = 1; + wake_up_all(&sysfs_wq); return 0; }