From patchwork Tue Oct 22 22:48:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13846245 X-Patchwork-Delegate: bhelgaas@google.com 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 B15EC1CDFAE for ; Tue, 22 Oct 2024 22:49:17 +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=1729637359; cv=none; b=NWkdm8qgmZBYDqggwJ1saOQO/yTHOjPPans92n+skawx202FtiCPY+pxVarBdRNyKm2I/CUxTH1M8azTRU1rRgmGxuel0ZjsCqLUuhcDzy6cVIyYH2iC77oQhOQelCOrF8AN//4RFaOYszgImoW0sWc81tAwKHSZT2YjwVnmYqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729637359; c=relaxed/simple; bh=viiuCp8o8xe/WgY+254iES/RD5a7szdU4pB3fCcKt5Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lTGWJJDSx/60eUn0/56N9cKqbJ+TGWIrFAv2VLnBQouTUJrxWZrlFu0hfGwBL8zHb/d4i/s2t4kEkfWWk1iOeUHnWDnR6xjWt/3N0UFUimd0DzraeECKRUuFgsIQM6Qi2D3ugTzHCo2RNIGo0ZfOqRj5LL5hyvbuCPGTpY2lfY8= 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=b6AIl4fV; 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="b6AIl4fV" Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49MLZgaY000394 for ; Tue, 22 Oct 2024 15:49:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=s5DkJC0dpxojjbkkf8DNyHozhv8fkFdulB2c6JVTBlw=; b=b6AIl4fV3oPL ZRVFJYRkG0bl9sYUREjryVlmeWNie2LlTaAE+yAN+JgsT2icbcLEPARrghP+0rbT rgvZTaxmALeaAmBYECxWi6mav+lvDhenERbZuJQ/fd10Et8CJIoV4RqWfvZBIQMC WdezCAJJGytijzAwa2dT+2MB7Y3e8Chn53dx4wMBXzvHTXuJmZ+heH/TaB8V9CL9 p9ppgJdZGaklb10grm02DN/LyDG0G4U52wYuTi6aaosOXpihTSGuriglFHWN0Y+0 7BphSwp2NqherMfmo7c4f9Xfq4ypSKOTSvRr7Eb8jAwMaLEHKn/1Kk0LKELel4sd KbyJ+pLcZw== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42em3h0dsm-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 15:49:16 -0700 (PDT) Received: from twshared4872.05.ash9.facebook.com (2620:10d:c0a8:1b::2d) 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, 22 Oct 2024 22:49:08 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 8600414610C96; Tue, 22 Oct 2024 15:48:53 -0700 (PDT) From: Keith Busch To: , CC: , Keith Busch , Jonathan Cameron Subject: [PATCHv3 1/5] pci: make pci_stop_dev concurrent safe Date: Tue, 22 Oct 2024 15:48:47 -0700 Message-ID: <20241022224851.340648-2-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241022224851.340648-1-kbusch@meta.com> References: <20241022224851.340648-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: _5JMbL-jI-cdjh5Ra0ektapL2jD1-yhL X-Proofpoint-ORIG-GUID: _5JMbL-jI-cdjh5Ra0ektapL2jD1-yhL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_02,2024-10-04_01,2024-09-30_01 From: Keith Busch Use the atomic ADDED flag to safely ensure concurrent callers can't attempt to stop the device multiple times. Callers should currently all be holding the pci_rescan_remove_lock, so there shouldn't be an 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 existing atomic bit ops. Reviewed-by: Jonathan Cameron Signed-off-by: Keith Busch --- drivers/pci/bus.c | 2 +- drivers/pci/pci.h | 11 +++++++++-- drivers/pci/remove.c | 20 +++++++++----------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index e0a2441be6d32..aec08e81abff7 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -358,7 +358,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 d89fdbf04f363..c4cceec006d0d 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -470,9 +470,16 @@ 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); + smp_mb__before_atomic(); + set_bit(PCI_DEV_ADDED, &dev->priv_flags); + smp_mb__after_atomic(); +} + +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 e4ce1145aa3ee..e0d4402ec3391 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -31,18 +31,16 @@ static int pci_pwrctl_unregister(struct device *dev, void *data) static void pci_stop_dev(struct pci_dev *dev) { - pci_pme_active(dev, false); - - if (pci_dev_is_added(dev)) { - device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev), - pci_pwrctl_unregister); - 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); + device_for_each_child(dev->dev.parent, dev_of_node(&dev->dev), + pci_pwrctl_unregister); + 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 Oct 22 22:48:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13846240 X-Patchwork-Delegate: bhelgaas@google.com 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 5FFE61C8FCF for ; Tue, 22 Oct 2024 22:49:08 +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=1729637350; cv=none; b=u1FandBt4hLcvIGZXxDhD/vFYWIqzAXO+rqLeeL3vyU235P6aqKVZdqEZIMiyvQeKgCPgL6RD1/zk6xWejfmMImUSYEVHysilcVxZu+JxydeX1QOSfgciG1j4z4Kbwpfaz6cm3WMpDaWBNOPiYmcxg4Kahug4CYqciVsWUUCQPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729637350; c=relaxed/simple; bh=a15521MOGeqZ1cJ69vj9iYsK5ut2rHJLwjyWRShlC5k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q3+L+Lq2i4U7E9mCsrwhOTp4qEekIH2KjHC+AabKjuFJD+PPOBnaatYW8wQRJpZZSHOASjyOL4gyhgbuWtOaQZXzJg9OzMVGFf1nT3ImivbiZS8hhLZxcqtFoFzziyddlFOqYY/7e/VTOVxNtMA7hVnxpLnvLIkKCTW91jM5fd4= 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=GrCrj5pA; 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="GrCrj5pA" 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 49MLYUaf013198 for ; Tue, 22 Oct 2024 15:49:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=JliJt//HLigc9llM64OOEVUe6/OfzydkWpVzE1gpEC0=; b=GrCrj5pA6zlQ sO6uEr21khIIyMqAJ6wdV0KRV2UHtkJaHf4WfHrE89jXj9HZytg0Fe8pDbJMWb34 emqtQ8/C4T1o6JohY4o/5oS2m4WS004tv2uv1cVYRsDDM8ZE5U93v419m3EaxXGG ADl1OGyohJrLIDb7hg8F7XmjZ1gCIDhfbdGBkAWPZAdYyTsqZccm80VJJMK4fRyL 7xddR6cVav3SJ8jPQaYBxVdJ3tJds0Bd01zInzKVh2RMY7nOD+KjMFX39squkSQT bliwoI8b2mMC711V9Ct9dRvbtM0ZNdgBHu1VDSM3oIoI93h1J3GvgXVbrj70+XSr kbOl4HiRnQ== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42em38ge1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 15:49:07 -0700 (PDT) Received: from twshared11284.02.ash9.facebook.com (2620:10d:c0a8:fe::f072) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 22 Oct 2024 22:49:06 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 8E25F14610C98; Tue, 22 Oct 2024 15:48:53 -0700 (PDT) From: Keith Busch To: , CC: , Keith Busch , Jonathan Cameron Subject: [PATCHv3 2/5] pci: make pci_destroy_dev concurrent safe Date: Tue, 22 Oct 2024 15:48:48 -0700 Message-ID: <20241022224851.340648-3-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241022224851.340648-1-kbusch@meta.com> References: <20241022224851.340648-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: VUl-_-60KvDO1KcBOpkebdueZ54on7K0 X-Proofpoint-ORIG-GUID: VUl-_-60KvDO1KcBOpkebdueZ54on7K0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_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 c4cceec006d0d..cae4f55d5a4be 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -469,6 +469,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) { @@ -487,6 +488,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 e0d4402ec3391..2e940101ce1bf 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -45,7 +45,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; pci_npem_remove(dev); From patchwork Tue Oct 22 22:48:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13846241 X-Patchwork-Delegate: bhelgaas@google.com 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 3BA731CDA24 for ; Tue, 22 Oct 2024 22:49:09 +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=1729637351; cv=none; b=J9oGUu+/jQQ/pLzc+w+DOqUcNZnBuJvsJ8vQdPLGtc+haPwRIc8PxTjvMHoyN4B5BrHDaGlu7pSU4sq6MwPW6HckXMnHtzIoZEb5ye+AZJWSNsUN79wKeU9GQwuFTg2kUpakf/chcR5yeU+n/1QyEWOBn4jGwJFXykAUSqQgf5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729637351; c=relaxed/simple; bh=rgeVw793e2iRFZ8msLe+UDwAExH7L41enKwaLiEzpFA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o5F2K84kXveOeK2C7b+yM2Y1JPkQBg218wRSYY+wQpWS8C7G9tvGk+IhroeqJSwueLR3XfN81XnmeAiudZg8Zi5VlQhJ6Ry2tMuj1Hrb1SnB6+EJhDCalaI4C5olDitEHE1oWn50Fv7iEmw0M4mG+DpFs+QBOIk87mx8pJfeTMc= 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=eTFP0kd4; 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="eTFP0kd4" 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 49MLYUai013198 for ; Tue, 22 Oct 2024 15:49:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=cRndAYK402/XjUPXTH7hpV73wtq9J/dnq5zNXuazwO0=; b=eTFP0kd4FydN xKKWUh1bfj6bP9p5buMOYa6vKvJ/WBkAJYhsqGR8mKumjCoGXevQv9KaKvxKpjwo Ak1CIU7SFBG2UqrVztzem8nPvQ/YaFXEqSkgNnvqXUteXCTIoo3BJkWeFcjq2ci+ gVbTRQRx+3JtJ4Wh2qISPlJyBLrdpjbbM2TndoQsDZJNbiNv3dImtUejzQqbF9yf A3TymsgOmVvROJ9l1BAJvZOPRXndeJUMFe7FilirFGXfQviz0OCAhR63Gbpj8WzO SUZhy/oop1APfkDgcc1QN8VeU095j+tfJXtwzuTSuVhWeVQ3FEaST8+1RUY7QY2P pjTFtEVD1A== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42em38ge1u-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 15:49:09 -0700 (PDT) Received: from twshared4872.05.ash9.facebook.com (2620:10d:c0a8:1c::11) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 22 Oct 2024 22:49:08 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id 943B814610C9A; Tue, 22 Oct 2024 15:48:53 -0700 (PDT) From: Keith Busch To: , CC: , Keith Busch , Jonathan Cameron , Davidlohr Bueso , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCHv3 3/5] pci: move the walk bus lock to where its needed Date: Tue, 22 Oct 2024 15:48:49 -0700 Message-ID: <20241022224851.340648-4-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241022224851.340648-1-kbusch@meta.com> References: <20241022224851.340648-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: STtuJrBsLNhIDri_v78kSMdzxYGM5oP6 X-Proofpoint-ORIG-GUID: STtuJrBsLNhIDri_v78kSMdzxYGM5oP6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_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 Reviewed-by: Davidlohr Bueso Reviewed-by: Ilpo Järvinen Signed-off-by: Keith Busch --- 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 aec08e81abff7..b863b8bdd6ee6 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -400,7 +400,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; @@ -408,8 +408,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) { @@ -432,8 +430,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); } /** @@ -451,7 +447,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); @@ -459,7 +457,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 Oct 22 22:48:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13846243 X-Patchwork-Delegate: bhelgaas@google.com 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 A28461CDFD9 for ; Tue, 22 Oct 2024 22:49:13 +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=1729637355; cv=none; b=WD29xii+PmzmPmVBi2AkB3O8w6axjY7cA/MZPVLQBmecDgLQP5jBEiyaplsOF6n313416h0C3YTByCDRfyF/mdxwGcxVsoF5EiP18GzFk6jA736RSh8zXZYCg5+hMXWSNVRFgLC3pfMHuWeH5X8TtItsTUi6KcLsEzKcEg4gGVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729637355; c=relaxed/simple; bh=aLZQPUQb09q56DLxFDOZeH+/4+VV7u/2RuEYaZhTCjg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gcavJBe5nSG5nYgFzm3RH6C8zqUndX7v6SHCDZZu+Cw9TrDZnC221aBiJ8EeulWEG5fJBu15IkbbTZY+mMZB9D4fR+WBXgQImXvZIb1CKLySORW7kHyPTxRn+xnBxpRKYBKHxT07m1a8lmtnvXp0zr4jaFzfw7KaSb9nDgCW1Pw= 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=fxNzG7oZ; 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="fxNzG7oZ" Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49MLZgaS000394 for ; Tue, 22 Oct 2024 15:49:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=4aFkJROKKdtf7LdW6qIzOXM5lLno41es/F0fnRTRHE4=; b=fxNzG7oZRPTz gQAAKXYFPcMsSh7SxkOLXmpDGKxNC2+BIWq5ggE99hI0YktiefcLwcpHzCh4hZ+l V1nD7JaF9XtZOjsuVXzW+jZnxAaYQMgxhNEo4eN4rzmjFFDfLuu4UKsA4q1R9jjg gw8qe9wi0yD8Z4d5t7fDnc0Uwb09FjdvK/oqgAls7n4btYo8bk06vNZ7lUFX+72H N026OqoJbZNEo8Z5o2sSCYICoqm+Y1UnITnJyBkaqRRHtiRylcKCsxQ6JztBajgy WYnc8XukdoTewX+kuZcbFlpanTlvf30cag72lE38vYTX9btfhzmsSA7TZKiq42oP MLX9LLpUMA== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42em3h0dsm-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 15:49:12 -0700 (PDT) Received: from twshared4872.05.ash9.facebook.com (2620:10d:c0a8:1c::11) 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, 22 Oct 2024 22:49:08 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id A473414610C9C; Tue, 22 Oct 2024 15:48:53 -0700 (PDT) From: Keith Busch To: , CC: , Keith Busch , Jonathan Cameron , =?utf-8?q?Ilpo_J=C3=A4rvine?= =?utf-8?q?n?= Subject: [PATCHv3 4/5] pci: walk bus recursively Date: Tue, 22 Oct 2024 15:48:50 -0700 Message-ID: <20241022224851.340648-5-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241022224851.340648-1-kbusch@meta.com> References: <20241022224851.340648-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: mftasU6mblYLGDYhSmGYxKVfbdDB7_lt X-Proofpoint-ORIG-GUID: mftasU6mblYLGDYhSmGYxKVfbdDB7_lt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_02,2024-10-04_01,2024-09-30_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 Reviewed-by: Ilpo Järvinen Signed-off-by: Keith Busch --- 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 b863b8bdd6ee6..9c552396241e0 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -399,37 +399,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 Oct 22 22:48:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13846244 X-Patchwork-Delegate: bhelgaas@google.com 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 9D6A01CEE8A for ; Tue, 22 Oct 2024 22:49:16 +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=1729637358; cv=none; b=jm9r+ZGjoEMQqEXtGaovpLNKnsWE1akTUZqosK5Y3IfhEMkpb6AE1ppubCFP72Gwb0EUdxuVsL/lsMlzV00iOZb3zzzXna55TTaY7BrV8GOrxamtmeiozzbEBvVlEDIcbL5EwSkZ17wQ9Nn4DV9UZGMHZtHZP1ZPto6aWzNUHh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729637358; c=relaxed/simple; bh=IypPAGyFtGRj0Hz4ryPlIxZLtVZFLChHM+CpWAnC10k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cbqhk8zDS311a44K2gfqyr40mj4o5bMmII9ehpU8HsRT5yVwjb6mTF/xIqmWY0XJTYUOBBrDSd8XMw097c2iUmier3vIwbAL1p1KKUcvP+pUzf1v2wAJwjYW3GrSIAZ9sJgCsnzeDD9a9zFQtMbmNBlCObijTp7rq4EEkk19qCg= 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=Hp56XrPP; 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="Hp56XrPP" 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 49MLYUat013198 for ; Tue, 22 Oct 2024 15:49:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=feAYGlWcbNhzQOhHTlCxYj6AKWRGMHrwIGF1wygblmY=; b=Hp56XrPPQl7R SnSXXrPgLG5+mEwUrOXK6nC16mBGQFeMZFq7oWb/E/eXtQKyzw0IexfflR/UeyoN UNlK/J7IGUj9u3kin1ZVBEEqzmYeM23NHoxxzfViV6LV/ilbcCu+kuIBTeDAVLLn STGF44jlroYDLVLgA19fGT9gmOdsqlBNcro7SLfmz7+JPQAYWVx4X5QfbesAUxM0 0j23dx2gP1Xct1vGsi9FIjvmYNSeZlvWsfrR0KPkUbxJJzRiFLPMSaCB5EnrWAGu eO5x0/AKb58q6/yWzpUbZScrsJGaygSTmi7pfte3r4thMrYMbbQsiyBZqi6nqLrw 3OZJTJ/11g== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 42em38ge1u-14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 22 Oct 2024 15:49:15 -0700 (PDT) Received: from twshared4872.05.ash9.facebook.com (2620:10d:c0a8:1c::11) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.11; Tue, 22 Oct 2024 22:49:08 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id AAA1E14610C9E; Tue, 22 Oct 2024 15:48:53 -0700 (PDT) From: Keith Busch To: , CC: , Keith Busch , Jonathan Cameron , Davidlohr Bueso , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCHv3 5/5] pci: unexport pci_walk_bus_locked Date: Tue, 22 Oct 2024 15:48:51 -0700 Message-ID: <20241022224851.340648-6-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241022224851.340648-1-kbusch@meta.com> References: <20241022224851.340648-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: 6YwAkLNpKk0cbCKoSLjyE8XLRJy2raMj X-Proofpoint-ORIG-GUID: 6YwAkLNpKk0cbCKoSLjyE8XLRJy2raMj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-05_03,2024-10-04_01,2024-09-30_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 Reviewed-by: Davidlohr Bueso Reviewed-by: Ilpo Järvinen Signed-off-by: Keith Busch --- drivers/pci/bus.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 9c552396241e0..d015d5821cefc 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -445,7 +445,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) {