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; } /**