From patchwork Mon Jun 24 04:32:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 11012125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5363B6C5 for ; Mon, 24 Jun 2019 04:32:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4368028AC0 for ; Mon, 24 Jun 2019 04:32:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37F4D28B0B; Mon, 24 Jun 2019 04:32:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDB2428AC0 for ; Mon, 24 Jun 2019 04:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbfFXEcW (ORCPT ); Mon, 24 Jun 2019 00:32:22 -0400 Received: from gate.crashing.org ([63.228.1.57]:39070 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726812AbfFXEcW (ORCPT ); Mon, 24 Jun 2019 00:32:22 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id x5O4WJIr012950 for ; Sun, 23 Jun 2019 23:32:20 -0500 Message-ID: <02ca29627597445442bb14c069678e549429dace.camel@kernel.crashing.org> Subject: [RFC/PATCH] PCI: Protect pci_reassign_bridge_resources() against concurrent addition/removal From: Benjamin Herrenschmidt To: "linux-pci@vger.kernel.org" Date: Mon, 24 Jun 2019 14:32:19 +1000 X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_reassign_bridge_resources() can be called by pci_resize_resource() at runtime. It will walk the PCI tree up and down, and isn't currently protected against any changes or hotplug operation. Signed-off-by: Benjamin Herrenschmidt --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type) unsigned int i; int ret; + down_read(&pci_bus_sem); + /* Walk to the root hub, releasing bridge BARs when possible */ next = bridge; do { @@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type) } free_list(&saved); + up_read(&pci_bus_sem); return 0; cleanup: @@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type) pci_setup_bridge(bridge->subordinate); } free_list(&saved); + up_read(&pci_bus_sem); return ret; }