From patchwork Thu Mar 16 09:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Stein X-Patchwork-Id: 70687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp380312wrt; Thu, 16 Mar 2023 02:39:10 -0700 (PDT) X-Google-Smtp-Source: AK7set9vIk9fOl9WG8R2kmEZlHOhG4Uw74gdS/kpIl5d31QCdpCGwcsR+qEkKAfK8YLd9uwI0R0R X-Received: by 2002:a17:902:db08:b0:19e:866c:3547 with SMTP id m8-20020a170902db0800b0019e866c3547mr3129380plx.65.1678959550355; Thu, 16 Mar 2023 02:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678959550; cv=none; d=google.com; s=arc-20160816; b=Eqf75fwbGDLmegDofJ/YV7mv5w4Ja9Cv0rSBbA8iDq9WAaTkspVJS131gQXIl58utV 4gjlOwbwlDT/SF4MfwpijpZi61Jff5p2eQ6RE2Zg/35JUia63DrUAwxSeaWv0HfAlq0I muffdbVqiF2dIJRuSQmGkvLiwYYa3MBzS8zthNTttausnYAhVXQJcXw9WbqqfOTabHPc 7m98iJxbvDC19ULg+DgveqtqYgqE6Rue6qEK8036zstdFoD8fLd9hZFlLHpRO5F+u2/H Y0hBW3NP5a6f3514xVxeCEnLXHLrf6BbKmTknPt5HRDSSxCTVcbZAcyc5+wel4eehsGA slTw== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=vNBKUCn+oSOubieZrKRWxbCHp3w8zx3bOHe3umDYycw=; b=I9QTy1oCSvEdE4IgUXqiDE+tvm7R8HsCM8RdjBAy5CAel88qMkWf+/ezuL3qs7MDzN Zw8tg9e5FZ79dmELO/ldk0hOsSWNuwzDAITMK96B+7Mh5vpg7vl5R7C/qEsbvRz7SX3C TWGEMALFhu3IgiZaTq6BKkiawsjNxwA0fH2fQpOc4yqnKkdwhFlby8hD4t4UhQvHr7Hq PJhecsY1EZpS6k+A+/nUYo/A8WK2IT4thkOmRX9ijBmw6Pu526syE7Fp38Niw6t4+YWi 9qMgLJd0aJEL2a2/wTjdh3K52zqxmjNOJxFXgA4z0ReUoCwIO2INF0zfLBSA2ofuPKdO 8lxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=aDstGSYa; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Q4h+tnXT; 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 j9-20020a170902da8900b001a0a44fa57csi5074989plx.389.2023.03.16.02.38.57; Thu, 16 Mar 2023 02:39:10 -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=aDstGSYa; dkim=pass header.i=@tq-group.com header.s=key1 header.b=Q4h+tnXT; 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 S230283AbjCPJP5 (ORCPT + 99 others); Thu, 16 Mar 2023 05:15:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230177AbjCPJPy (ORCPT ); Thu, 16 Mar 2023 05:15:54 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0805AB4D; Thu, 16 Mar 2023 02:15:52 -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=1678958152; x=1710494152; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=vNBKUCn+oSOubieZrKRWxbCHp3w8zx3bOHe3umDYycw=; b=aDstGSYayo0Uez0xz1sw0mJ3Zqsb7qmgeec3GwAjf4CrwsAexESBYOmY g3bHZzzp7UF5oaEt2shEP1QWlVYmJ7Lbf3NVg3FwhBMAsKCC0rxSnqAeA rr2xllU+6Wl5NsEKyGPfeLQnF3zoaHHnPqpzKyjdgYpa2qsEfaVNkNuCN zyDp/4GfrGpAnAdwvUl02v9So1ymvO7CuT0NAm2sQo8kYiIxiGDFRncl2 BgcwgHn3KgLjoxvazMUPTtwT2tBztIvjR/ELUB1I0TEcS2Qb8LEvNk1CU YP3uC9Cicaq8zpKkHr4OnbTJe5NjjQcs4G8Q66Cdletojg6hUq0X59Nlj A==; X-IronPort-AV: E=Sophos;i="5.98,265,1673910000"; d="scan'208";a="29730469" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 16 Mar 2023 10:15:49 +0100 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Thu, 16 Mar 2023 10:15:49 +0100 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Thu, 16 Mar 2023 10:15:49 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1678958149; x=1710494149; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=vNBKUCn+oSOubieZrKRWxbCHp3w8zx3bOHe3umDYycw=; b=Q4h+tnXTJvDIjbGBHT/Ri4SboGxaSMFFTAKh3SM6/NJITqg1XKuptYgu uylJwGqVYU72CEntyARNxePw7usmJe/tVkeZxi2LRwME08vlUR2pd9plL dWSOO6uXdpTNzE5zZdlFULRiW6ZSPbhflJHlYpxIc2gBfz7N2sYtiFrXM DOxKI455z4K+HsfXemK1CAjflfZq9TJEPF/giHWpIakZ9Eg+AboZsaynQ NlZZykyNugPQ1zyhMFaSxKKvux59jnSYcy8GhvBPheLFTLQtbRKPd41iG 0EiV7t581d3yLbTXSF5cb0ATY2RCv78yI86/JjvRegx6WouKHezC2RZkB w==; X-IronPort-AV: E=Sophos;i="5.98,265,1673910000"; d="scan'208";a="29730468" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 16 Mar 2023 10:15:49 +0100 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 3ABF8280056; Thu, 16 Mar 2023 10:15:49 +0100 (CET) From: Alexander Stein To: Bjorn Helgaas Cc: Korneliusz Osmenda , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Stein Subject: [PATCH v2 1/1] Guard pci_create_sysfs_dev_files with atomic value Date: Thu, 16 Mar 2023 10:15:40 +0100 Message-Id: <20230316091540.494366-1-alexander.stein@ew.tq-group.com> X-Mailer: git-send-email 2.34.1 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 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?1760515837549639695?= X-GMAIL-MSGID: =?utf-8?q?1760516689472021501?= From: Korneliusz Osmenda On Gateworks Ventana there is a number of PCI devices and: - imx6_pcie_probe takes longer than start of late init - pci_sysfs_init sets up flag sysfs_initialized - pci_sysfs_init initializes already found devices - imx6_pcie_probe tries to reinitialize device Link: https://bugzilla.kernel.org/show_bug.cgi?id=215515 Signed-off-by: Korneliusz Osmenda Signed-off-by: Alexander Stein --- drivers/pci/pci-sysfs.c | 6 ++++++ include/linux/pci.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index dd0d9d9bc509..998e44716b6f 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1497,6 +1497,9 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev) if (!sysfs_initialized) return -EACCES; + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 0, 1) == 1) + return 0; /* already added */ + return pci_create_resource_files(pdev); } @@ -1511,6 +1514,9 @@ void pci_remove_sysfs_dev_files(struct pci_dev *pdev) if (!sysfs_initialized) return; + if (atomic_cmpxchg(&pdev->sysfs_init_cnt, 1, 0) == 0) + return; /* already removed */ + pci_remove_resource_files(pdev); } diff --git a/include/linux/pci.h b/include/linux/pci.h index b50e5c79f7e3..024313a7a90a 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -467,6 +467,8 @@ struct pci_dev { pci_dev_flags_t dev_flags; atomic_t enable_cnt; /* pci_enable_device has been called */ + atomic_t sysfs_init_cnt; /* pci_create_sysfs_dev_files has been called */ + u32 saved_config_space[16]; /* Config space saved at suspend time */ struct hlist_head saved_cap_space; int rom_attr_enabled; /* Display of ROM attribute enabled? */