From patchwork Tue Aug 27 19:28:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13780086 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87DA61CFEDC for ; Tue, 27 Aug 2024 19:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786928; cv=none; b=kmf/bUxEtNdxoWiYwPDDZ4txOur23WHQDnWUzkwR/TENenCchSfFMtHAj82andwjZ4CfFGup4Kw/q9J7y+Eq2XbYlXWu9XIOBTeZyUy0QTZuLOO6jTUanQEUutMsfDkCbZ/1oEb1hrtIlU6efLg3ZGjqidM/fnsqs5FTc0yjoSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786928; c=relaxed/simple; bh=WtOPoHH3ojk9bNzE7wbXIg0IreFI7gitEnQygH1FEic=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=czl+Xh6qWRXbtha5+8H1OX0W326JBRxiixeyH7OyfbtMy9BKNAzpVGBQRgSb984efCR44J6HNnaf7s/mfAckA54FMZNCMuZOwYpzQ4gKM2xRlTKDDRFxRGpwXj2X0Fxc89lvFOSw1Rhci817hgBodhGZ3eBFPS8i9OHXTB/4acA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=cVrEs83y; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="cVrEs83y" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 47RFt2T4007760 for ; Tue, 27 Aug 2024 12:28:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= s2048-2021-q4; bh=9VsB0PPrNZTkTmlsWbAcw57wmOrI4jSQmU95eVUSBl4=; b= cVrEs83yfZ31sli+wzx7H6JPjr8YOjGSPe3UjNO8FqXVsSDwlkSZi9okAEbb7pwD yYiMUXnlEG0Z+WCx3QzUZFn/TigwXFfHh9jadw52/4G6yW0OU8DuqEpx5T9Vg7at LfwnpE1AxmqZPjHYGAKPwW6ABdAvmC9gVqiHB7B7rzKPsqsDaQD3XYBoaHalWHGP WI0+D9SRIcbrOaco695Ax2xlH0D6jgBfwQy7G2CFVFXBcpTaOZoBS4dtX9ll3bJ7 nzcL3xtC/2TJ/SgPMmYN/Egx/k/cNtxI76oWA7bELzwYS95n61Oyx1h5i7UPXks2 eWTRCAvtbTOCHsN0QjEPsw== Received: from mail.thefacebook.com ([163.114.134.16]) by m0001303.ppops.net (PPS) with ESMTPS id 419hv0spkq-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 27 Aug 2024 12:28:45 -0700 (PDT) Received: from twshared12613.02.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 27 Aug 2024 19:28:42 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 61516124FD6FB; Tue, 27 Aug 2024 12:28:27 -0700 (PDT) From: Keith Busch To: , CC: Keith Busch , Jonathan Cameron Subject: [PATCHv2 1/5] pci: make pci_stop_dev concurrent safe Date: Tue, 27 Aug 2024 12:28:22 -0700 Message-ID: <20240827192826.710031-2-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240827192826.710031-1-kbusch@meta.com> References: <20240827192826.710031-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: dqN3zLU7dCgk-m1FlhkNgsrRrykEMlUL X-Proofpoint-ORIG-GUID: dqN3zLU7dCgk-m1FlhkNgsrRrykEMlUL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_10,2024-08-27_01,2024-05-17_01 From: Keith Busch Use the atomic ADDED bit flag to safely ensure concurrent callers can't attempt to stop the device multiple times. Callers should currently be holding the pci_rescan_remove_lock, so there shouldn't be fixing any existing race. But that global lock can cause lock dependency issues, so this is preparing to reduce reliance on that lock by using the existing atomic bit ops. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch --- drivers/pci/bus.c | 2 +- drivers/pci/pci.h | 9 +++++++-- drivers/pci/remove.c | 18 ++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 55c8536860518..e41dfece0d969 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -348,7 +348,7 @@ void pci_bus_add_device(struct pci_dev *dev) if (retval < 0 && retval != -EPROBE_DEFER) pci_warn(dev, "device attach failed (%d)\n", retval); - pci_dev_assign_added(dev, true); + pci_dev_assign_added(dev); if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) { retval = of_platform_populate(dev_of_node(&dev->dev), NULL, NULL, diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 0e9b1c7b94a5a..802f7eac53115 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -444,9 +444,14 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) #define PCI_DPC_RECOVERED 1 #define PCI_DPC_RECOVERING 2 -static inline void pci_dev_assign_added(struct pci_dev *dev, bool added) +static inline void pci_dev_assign_added(struct pci_dev *dev) { - assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added); + set_bit(PCI_DEV_ADDED, &dev->priv_flags); +} + +static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev) +{ + return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags); } static inline bool pci_dev_is_added(const struct pci_dev *dev) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 910387e5bdbf9..ec3064a115bf8 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -16,17 +16,15 @@ static void pci_free_resources(struct pci_dev *dev) static void pci_stop_dev(struct pci_dev *dev) { - pci_pme_active(dev, false); - - if (pci_dev_is_added(dev)) { - of_platform_depopulate(&dev->dev); - device_release_driver(&dev->dev); - pci_proc_detach_device(dev); - pci_remove_sysfs_dev_files(dev); - of_pci_remove_node(dev); + if (!pci_dev_test_and_clear_added(dev)) + return; - pci_dev_assign_added(dev, false); - } + pci_pme_active(dev, false); + of_platform_depopulate(&dev->dev); + device_release_driver(&dev->dev); + pci_proc_detach_device(dev); + pci_remove_sysfs_dev_files(dev); + of_pci_remove_node(dev); } static void pci_destroy_dev(struct pci_dev *dev) From patchwork Tue Aug 27 19:28:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13780084 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFDF1132132 for ; Tue, 27 Aug 2024 19:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786923; cv=none; b=b7dwgW41aoOO8ZW/2SJ+kifC5zS8IOo4LRlKhlP8MWRGb+ZRDGxdFcmm+xfYmC/Vjc8gy00RaJpUl+d7JX5oxvNVWAz57xmhC2NUcU0M7WVwg63UmOPM5Qb3tG8E9Dg0ZeIFxF4QMNTsAGAoA9hzkdD9KlErUqU0Od+XZMD3W1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786923; c=relaxed/simple; bh=a6NCCDdTnSSsJB5vWnt0siNlrk3CvqWYP7g4gDbh8RU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u4npiq4N5SbOMGkbL312ikwyh+HhSFiUGI+WjlhbY18JL8HSxeQI1Iz7g6Lvj+XryJ5xufgRhVkIR46YE9L7JtIzC6Pv55hSMiP7jFHB5+r+WcZllWqffwlKlh+eeJBdAsQ1O2OMusMovPBME/etP9aDOUgZqrtAfL4JQTFYGww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=dpalijuQ; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="dpalijuQ" Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47RCZDOa032104 for ; Tue, 27 Aug 2024 12:28:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= s2048-2021-q4; bh=d858pWi/zFT9xDr3h2lbGxr8x/wj5Mm1d6pL7kZwpdE=; b= dpalijuQVqZ5FATIy4XZXFnrmAMwgcU1kKBUdTq6v4bOp8SNmoAaMBNhfG98CxoU cav3WDzQduzDMC0OZPyeR1YZD35et5YHkjflT54k2aH7YZKrai36xoyONxz2mhxI 8V3ps2IMtaeYTZlao49wfU7KJH08f26EHqVsqeocoeZwTrzN/4UKHZqGR/Joi0wC ru87sfLxObE5O7FG47rAa1UODdGFuhl+pvvfxlft9MjhCj/l9Ck7clmk8mN0qkRa H7ugY/ZhqgwSjBj2++ovb0bI7motAwb9cCSmSgjwgTTUKPVxhYVMSAuxOCf62mLU 006Kl4G/zRcp2HARn9fMwQ== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 419ex535tq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 27 Aug 2024 12:28:40 -0700 (PDT) Received: from twshared48671.38.frc1.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 27 Aug 2024 19:28:39 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 6D802124FD6FD; Tue, 27 Aug 2024 12:28:27 -0700 (PDT) From: Keith Busch To: , CC: Keith Busch , Jonathan Cameron Subject: [PATCHv2 2/5] pci: make pci_destroy_dev concurrent safe Date: Tue, 27 Aug 2024 12:28:23 -0700 Message-ID: <20240827192826.710031-3-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240827192826.710031-1-kbusch@meta.com> References: <20240827192826.710031-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: 5dPYKMpvMS12Z3fwN1h1nUL9OHCYpoLf X-Proofpoint-ORIG-GUID: 5dPYKMpvMS12Z3fwN1h1nUL9OHCYpoLf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_10,2024-08-27_01,2024-05-17_01 From: Keith Busch Use an atomic flag instead of the racey check against the device's kobj parent. We shouldn't be poking into device implementation details at this level anyway. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch --- drivers/pci/pci.h | 6 ++++++ drivers/pci/remove.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 802f7eac53115..a11a53f67a0ce 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -443,6 +443,7 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) #define PCI_DEV_ADDED 0 #define PCI_DPC_RECOVERED 1 #define PCI_DPC_RECOVERING 2 +#define PCI_DEV_REMOVED 3 static inline void pci_dev_assign_added(struct pci_dev *dev) { @@ -459,6 +460,11 @@ static inline bool pci_dev_is_added(const struct pci_dev *dev) return test_bit(PCI_DEV_ADDED, &dev->priv_flags); } +static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev) +{ + return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags); +} + #ifdef CONFIG_PCIEAER #include diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index ec3064a115bf8..8284ab20949c9 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -29,7 +29,7 @@ static void pci_stop_dev(struct pci_dev *dev) static void pci_destroy_dev(struct pci_dev *dev) { - if (!dev->dev.kobj.parent) + if (pci_dev_test_and_set_removed(dev)) return; device_del(&dev->dev); From patchwork Tue Aug 27 19:28:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13780085 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DF4377117 for ; Tue, 27 Aug 2024 19:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786927; cv=none; b=my1laPKNJp3epm0LVjJBmV1c94EJZe8Z2pQNi+PWoVpuuXOY9uCDykBxAD1SL25rEspAcxTz4GQFE9a5RooEmsCJ+XBddFdYmtFw+cuUuYoYAI3y5h+KY/SZ8u+gipSk/m+hdEBZSTuKjy4XIwsbdOXxRZWz1PvFE8kNIAzQzYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786927; c=relaxed/simple; bh=E/+qtStYpXpXCDrSVIHwjtv5rEAN0n5iq+3C1UWmc9g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DxKopLF9GJxvyweJcHXaeww3ctXmBN2B+oDITXNicDFli0kGrs6wGIlgq6qcUGuG85UP1+06snTBdlEYWgK6Tkm7ZdaRVr7IzTBM/KmSQSNmq2ELOwu6pXGHzAH+hsSBBEtUu6cr62VcKdQWrVUdmk0RAFF6jVwqu2VMJcnpSv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=UVnSOxMA; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="UVnSOxMA" Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 47RFt2T1007760 for ; Tue, 27 Aug 2024 12:28:44 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= s2048-2021-q4; bh=DDxZ4ogSCd5XQxO5J8cTxC2SVOCKfOWZBaBLDzSX5Cc=; b= UVnSOxMAtWMy0Sec3114qlqDl3beYToEjJJ7wZfkg0HK5WQnUcvbNPYoGceRCFLt BMsDMrxmbxjNQGjjh4itlLT3JjbZESw7cTTPT9pZaCP5qS55stdLuGuXxvq3kPqk kKi7lEEGHcsASjtTBdBmDmIXbQA6MhJSk6kdne0w/K9C1Q+0o2mehPWPucuXhEey xsfDZLE3jJnP2hAO8gwWkXKVkIVCNqjBAE2F2oY7CYY/rpFGEGxv6M0+9C9dyXdN tSLx/lteAogxBjvm9wLe7tTWPoAB/d44ykKHL/TQdMaRQWBTA+TeP0UfZfQ1yqDh dY/Zxw4AJhQ8eC/Mg6Uxdw== Received: from mail.thefacebook.com ([163.114.134.16]) by m0001303.ppops.net (PPS) with ESMTPS id 419hv0spkq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 27 Aug 2024 12:28:44 -0700 (PDT) Received: from twshared12613.02.ash9.facebook.com (2620:10d:c085:208::7cb7) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 27 Aug 2024 19:28:42 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 7396A124FD701; Tue, 27 Aug 2024 12:28:27 -0700 (PDT) From: Keith Busch To: , CC: Keith Busch , Jonathan Cameron Subject: [PATCHv2 3/5] pci: move the walk bus lock to where its needed Date: Tue, 27 Aug 2024 12:28:24 -0700 Message-ID: <20240827192826.710031-4-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240827192826.710031-1-kbusch@meta.com> References: <20240827192826.710031-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: QpTHNjuKcVZZ-NbstagAGRVSBhF3Ni3Z X-Proofpoint-ORIG-GUID: QpTHNjuKcVZZ-NbstagAGRVSBhF3Ni3Z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_10,2024-08-27_01,2024-05-17_01 From: Keith Busch Simplify the common function by removing an unnecessary parameter that can be more easily handled in the only caller that wants it. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch Reviewed-by: Davidlohr Bueso Reviewed-by: Ilpo Järvinen --- drivers/pci/bus.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index e41dfece0d969..7c07a141e8772 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -390,7 +390,7 @@ void pci_bus_add_devices(const struct pci_bus *bus) EXPORT_SYMBOL(pci_bus_add_devices); static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), - void *userdata, bool locked) + void *userdata) { struct pci_dev *dev; struct pci_bus *bus; @@ -398,8 +398,6 @@ static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void int retval; bus = top; - if (!locked) - down_read(&pci_bus_sem); next = top->devices.next; for (;;) { if (next == &bus->devices) { @@ -422,8 +420,6 @@ static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void if (retval) break; } - if (!locked) - up_read(&pci_bus_sem); } /** @@ -441,7 +437,9 @@ static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void */ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), void *userdata) { - __pci_walk_bus(top, cb, userdata, false); + down_read(&pci_bus_sem); + __pci_walk_bus(top, cb, userdata); + up_read(&pci_bus_sem); } EXPORT_SYMBOL_GPL(pci_walk_bus); @@ -449,7 +447,7 @@ void pci_walk_bus_locked(struct pci_bus *top, int (*cb)(struct pci_dev *, void * { lockdep_assert_held(&pci_bus_sem); - __pci_walk_bus(top, cb, userdata, true); + __pci_walk_bus(top, cb, userdata); } EXPORT_SYMBOL_GPL(pci_walk_bus_locked); From patchwork Tue Aug 27 19:28:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13780089 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D5AB1D2F57 for ; Tue, 27 Aug 2024 19:28:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786939; cv=none; b=meKHgDlE5u6KbpVjfkS3oxPKWGo5rTAhSqi5dtcUvh3RXL2uM0H49E2qr2L5n6nWV1AIVkv5IQlg503FVWEFEenc1KRiTgqwNEX8ch4ZJfkKDwCKQLf+/Drymy377sxOqN7rR9e1LYkPR1uxATm8b+/9YNpasJEk8AWX1t0YxvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786939; c=relaxed/simple; bh=JDfE9CIsszTUANv/Le/pSmFyHBszZN8y5lRLIf6i61k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aG0dPnSfh8PoZsAK7zaoWnQprpW+0hkxjuklT4fUFIFiLVUU7gIxT9U95CM4YZ0n2U4LnP0Pehkbu9CpKrvQsYGg2MGfsZVWRtb7Ehm7XK2wbXUn0hoBQaT5F6ra+kbWgTMNZb0sefuMntxX0mEfXe3xWceEVto01BBztHCd4iM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=aaGYMfky; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="aaGYMfky" Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47RDnVV2017853 for ; Tue, 27 Aug 2024 12:28:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= s2048-2021-q4; bh=pcChgNId+NSWU9SFBhOkY9Q04FHA7eNvEe/eAp23sCQ=; b= aaGYMfkyLkgo7MvoXwCyeu+5QU5XumVJCqv72Z8GjEt5mNJH9tpVvZ5rX7PrwwvI +RHOamohYhBCbcKsjqVoOwV6uznnZ8PJx6LFPJZ3ud49RHRKb3zYoDhmc+fwsTBL 2Qxeit5nz6RewmPh69O56JcdPxrnUXxxpYokWMSlr9LGg9/Dlx9BAra67PiI3fUH MOe5ZwgGko8itYMPNmagDSEvHFVLAAwya7C+KukVH04NAVkfNlqcD2guvT6QJN6o EWLQJ4Vm3HqKmff0zIv/Z2bESA4Ehi0fWLXimXJVj9Aj87/NOdtgpnABjKWWPBNe okzOy0e8lOpENsoiGQuZGg== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4193s562hh-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 27 Aug 2024 12:28:57 -0700 (PDT) Received: from twshared16760.32.frc3.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 27 Aug 2024 19:28:32 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 7DB68124FD703; Tue, 27 Aug 2024 12:28:27 -0700 (PDT) From: Keith Busch To: , CC: Keith Busch , Jonathan Cameron Subject: [PATCHv2 4/5] pci: walk bus recursively Date: Tue, 27 Aug 2024 12:28:25 -0700 Message-ID: <20240827192826.710031-5-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240827192826.710031-1-kbusch@meta.com> References: <20240827192826.710031-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: ksnOr2nSpYOCeh8P_hfqQfpIyZ8DYBDO X-Proofpoint-ORIG-GUID: ksnOr2nSpYOCeh8P_hfqQfpIyZ8DYBDO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_10,2024-08-27_01,2024-05-17_01 From: Keith Busch The original implementation purposefully chose a non-recursive walk, presumably as a precaution on stack use. We do recursive bus walking in other places though. For example: pci_bus_resettable pci_stop_bus_device pci_remove_bus_device pci_bus_allocate_dev_resources So, recursive pci bus walking is well tested and safe, and the implementation is easier to follow. The motivation for changing it now is to make it easier to introduce finer grain locking in the future. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch Reviewed-by: Ilpo Järvinen --- drivers/pci/bus.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 7c07a141e8772..8491e9c7f0586 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -389,37 +389,23 @@ void pci_bus_add_devices(const struct pci_bus *bus) } EXPORT_SYMBOL(pci_bus_add_devices); -static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), - void *userdata) +static int __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), + void *userdata) { struct pci_dev *dev; - struct pci_bus *bus; - struct list_head *next; - int retval; + int ret = 0; - bus = top; - next = top->devices.next; - for (;;) { - if (next == &bus->devices) { - /* end of this bus, go up or finish */ - if (bus == top) + list_for_each_entry(dev, &top->devices, bus_list) { + ret = cb(dev, userdata); + if (ret) + break; + if (dev->subordinate) { + ret = __pci_walk_bus(dev->subordinate, cb, userdata); + if (ret) break; - next = bus->self->bus_list.next; - bus = bus->self->bus; - continue; } - dev = list_entry(next, struct pci_dev, bus_list); - if (dev->subordinate) { - /* this is a pci-pci bridge, do its devices next */ - next = dev->subordinate->devices.next; - bus = dev->subordinate; - } else - next = dev->bus_list.next; - - retval = cb(dev, userdata); - if (retval) - break; } + return ret; } /** From patchwork Tue Aug 27 19:28:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13780087 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B77291D2F51 for ; Tue, 27 Aug 2024 19:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786939; cv=none; b=kC/nU4kbbPIwtlDObBBxj8mkCf4yHleVMalTrKqR6AJV5lK0KEturl05oTmDEf160XAD2FXX5bAo3DPmpumbLUFWRPHQZOlIhm5iWgEBSMTGubwoQJApFLmfNPHwKB2aLz8MlU5IzEptJ64BT9FZzq9hkSYPoTO2koekTviQk+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724786939; c=relaxed/simple; bh=tiCvGxXvIf6qJhtNJtaD3ZmT4CUNupTzQaXTk64jKdU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z5F/bgdki9Cn/MeqQKwUfOlSciqKn0CD9ZRh7AD/Jk+A4WVmGvpl+mb1czpghjwiwqw7H0uJZLQwrAOCqbMI9t3Vy+G4K1ygG43quH0XSUd3zOcSJiJLMhv4yT9vJN0mxb/mVxK0KPSiYrQ5D5aPdf1XUgf541KjdtI/Kxw3WJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=Tg36DlMg; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="Tg36DlMg" Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47RIpS0q023565 for ; Tue, 27 Aug 2024 12:28:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= s2048-2021-q4; bh=WtLjBrrKmUt0MuqC5UcDaN4lAOZ5FTZEdBCR44av+GY=; b= Tg36DlMgYN+c2AeEM8N/WBUNKuH/ix68+aPOhKvZpna2N9UR6rd2nV2Aev1V+xCM MaRxYM9wCshkqLum8ikdRSIuzHT/Aj1H6Ez2X1mCz8Yo+1M1mxdx3JhlEwHx9igQ +rMa0GMSIDNDvA1F5oVXc+6MJJw3pej5MZ3/GyfK23zgYlJdV/qGakqJEN9dyDqm 6ESuSZsT+D8SB7nobWDDl59b/KJAhLMrv6KIe0MoffWNdWV+Yfv2jqvno4AOWmQE apW83l9rleknvOZSzcxv0VFp8pDFu47t1wVmUok8OyoEj/C6+q2FCQCH7pEWkSsl K53JPnCDs5rdOAj7+ycyKw== Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 419meg8836-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 27 Aug 2024 12:28:57 -0700 (PDT) Received: from twshared26656.07.ash9.facebook.com (2620:10d:c0a8:1c::1b) by mail.thefacebook.com (2620:10d:c0a9:6f::237c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 27 Aug 2024 19:28:38 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 87F00124FD705; Tue, 27 Aug 2024 12:28:27 -0700 (PDT) From: Keith Busch To: , CC: Keith Busch , Jonathan Cameron Subject: [PATCHv2 5/5] pci: unexport pci_walk_bus_locked Date: Tue, 27 Aug 2024 12:28:26 -0700 Message-ID: <20240827192826.710031-6-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240827192826.710031-1-kbusch@meta.com> References: <20240827192826.710031-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: cENQFERb-aGWNtV2iUKz4qiZ0sdsl5oK X-Proofpoint-ORIG-GUID: cENQFERb-aGWNtV2iUKz4qiZ0sdsl5oK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-27_10,2024-08-27_01,2024-05-17_01 From: Keith Busch There's only one user of this, and it's internal, so no need to export it. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch Reviewed-by: Davidlohr Bueso Reviewed-by: Ilpo Järvinen --- drivers/pci/bus.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 8491e9c7f0586..30620f3bb0e2d 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -435,7 +435,6 @@ void pci_walk_bus_locked(struct pci_bus *top, int (*cb)(struct pci_dev *, void * __pci_walk_bus(top, cb, userdata); } -EXPORT_SYMBOL_GPL(pci_walk_bus_locked); struct pci_bus *pci_bus_get(struct pci_bus *bus) {