From patchwork Wed May 24 07:37:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 9745239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF49E601C2 for ; Wed, 24 May 2017 07:39:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B168B288F9 for ; Wed, 24 May 2017 07:39:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A621E28901; Wed, 24 May 2017 07:39:48 +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=-1.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0CE4D288F9 for ; Wed, 24 May 2017 07:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Evv4VzDAE4UGoI5xJNxwwMs/yeH5LT82Lkrkc11eUlc=; b=Sfz +xWR7o9xS0m3diWlIyoVdvePUpXewDx9fQkMeJAcLwXSbPss9SeO+tbURt1o+4z5TTvI9t11ZIEj5 5SEXfe8n/hFVsTfRurX/6VGaxk9Kukh55Cl68ah8dLA6u+9PvV5swD9dLqH14kPN5iSDfZK+7Tvon XTlvXg11dgsY1R+nAdTQQNVtP2fgIj/LV3wsCrXVHy7K04PZwg33u9g89Wfnr11XNquJf7n5Btyqr GIKU1d0VsBDSUgGbNQLzQjWKympV8teD46C3LZ99sUbXr8YssMFWBosvaUi9HfTfwKfGWSsljxGlH 6Vo1gN05sFWrHydQUKyYOU40j5vzKIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dDQtX-00021G-7T; Wed, 24 May 2017 07:39:47 +0000 Received: from lucky1.263xmail.com ([211.157.147.135]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDQtT-0001zo-G7 for linux-rockchip@lists.infradead.org; Wed, 24 May 2017 07:39:45 +0000 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.242]) by lucky1.263xmail.com (Postfix) with ESMTP id 8C7A972C; Wed, 24 May 2017 15:39:16 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTP id 59FAA39E; Wed, 24 May 2017 15:39:09 +0800 (CST) X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: bhelgaas@google.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 267145D9YE5; Wed, 24 May 2017 15:39:11 +0800 (CST) From: Shawn Lin To: Bjorn Helgaas Subject: [PATCH v4] PCI: use IDA to manage domain number if not getting it from DT Date: Wed, 24 May 2017 15:37:35 +0800 Message-Id: <1495611455-41952-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170524_003943_933600_2F88127C X-CRM114-Status: GOOD ( 19.54 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, Jeffy Chen , Brian Norris , Shawn Lin , linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If not getting domain number from DT, the domain number will keep increasing once doing unbind/bind RC drivers. This could introduce pointless tree view of lspci as shows below: -+-[0001:00]---00.0-[01]----00.0 \-[0000:00]- The more test we do, the lengthier it would be. The more serious issue is that if attaching two hierarchies for two different domains belonging to two root bridges, so when doing unbind/bind test for one of them and keep the other, then the domain number would finally overflow and make the two hierarchies of devices share the some domain number but actually they shouldn't. So it looks like we need to invent a new indexing ID mechanism to manage domain number. This patch introduces idr to achieve our purpose. Cc: Brian Norris Cc: Jeffy Chen Signed-off-by: Shawn Lin --- Changes in v4: - make domain_nr depends on CONFIG_PCI_DOMAINS instead of CONFIG_PCI_DOMAINS_GENERIC.(reported by Kbuild Robot) Changes in v3: - make ida_domain a system-wide property and check it in the code to combine with use_dt_domains. Also update the comment there. Changes in v2: - add a remove wrapper - rename use_dt_domains to ida_domain and set this bit in pci_get_new_domain_nr and test it in the remove wrapper. drivers/pci/pci.c | 42 ++++++++++++++++++++++++++++-------------- drivers/pci/remove.c | 2 ++ include/linux/pci.h | 10 +++++++--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b01bd5b..e5f5db0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -5340,15 +5341,25 @@ static void pci_no_domains(void) } #ifdef CONFIG_PCI_DOMAINS -static atomic_t __domain_nr = ATOMIC_INIT(-1); +DEFINE_IDA(__domain_nr); -int pci_get_new_domain_nr(void) +/* get domain number from IDA */ +static bool ida_domain = true; + +int pci_get_new_domain_nr(struct pci_bus *bus) +{ + return ida_simple_get(&__domain_nr, 0, sizeof(u64), GFP_KERNEL); +} + +void pci_put_old_domain_nr(struct pci_bus *bus) { - return atomic_inc_return(&__domain_nr); + if (ida_domain) + ida_simple_remove(&__domain_nr, bus->domain_nr); } #ifdef CONFIG_PCI_DOMAINS_GENERIC -static int of_pci_bus_find_domain_nr(struct device *parent) +static int of_pci_bus_find_domain_nr(struct pci_bus *bus, + struct device *parent) { static int use_dt_domains = -1; int domain = -1; @@ -5361,19 +5372,21 @@ static int of_pci_bus_find_domain_nr(struct device *parent) * If DT domain property is valid (domain >= 0) and * use_dt_domains != 0, the DT assignment is valid since this means * we have not previously allocated a domain number by using - * pci_get_new_domain_nr(); we should also update use_dt_domains to - * 1, to indicate that we have just assigned a domain number from - * DT. + * pci_get_new_domain_nr(), so we should set ida_domain to false to + * indicate that we don't allocate domain from idr; we should also + * update use_dt_domains to 1, to indicate that we have just assigned + * a domain number from DT. * * If DT domain property value is not valid (ie domain < 0), and we * have not previously assigned a domain number from DT - * (use_dt_domains != 1) we should assign a domain number by - * using the: + * (use_dt_domains != 1 && ida_domain != false) we should assign a + * domain number by using the: * * pci_get_new_domain_nr() * - * API and update the use_dt_domains value to keep track of method we - * are using to assign domain numbers (use_dt_domains = 0). + * API and update the use_dt_domains and ida_domain value to keep track + * of method we are using to assign domain numbers (use_dt_domains = 0 + * and ida_domain = true). * * All other combinations imply we have a platform that is trying * to mix domain numbers obtained from DT and pci_get_new_domain_nr(), @@ -5383,9 +5396,10 @@ static int of_pci_bus_find_domain_nr(struct device *parent) */ if (domain >= 0 && use_dt_domains) { use_dt_domains = 1; - } else if (domain < 0 && use_dt_domains != 1) { + ida_domain = false; + } else if (domain < 0 && use_dt_domains != 1 && ida_domain != false) { use_dt_domains = 0; - domain = pci_get_new_domain_nr(); + domain = pci_get_new_domain_nr(bus); } else { dev_err(parent, "Node %s has inconsistent \"linux,pci-domain\" property in DT\n", parent->of_node->full_name); @@ -5397,7 +5411,7 @@ static int of_pci_bus_find_domain_nr(struct device *parent) int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent) { - return acpi_disabled ? of_pci_bus_find_domain_nr(parent) : + return acpi_disabled ? of_pci_bus_find_domain_nr(bus, parent) : acpi_pci_bus_find_domain_nr(bus); } #endif diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 73a03d3..1bbbb37 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -157,6 +157,8 @@ void pci_remove_root_bus(struct pci_bus *bus) list_for_each_entry_safe(child, tmp, &bus->devices, bus_list) pci_remove_bus_device(child); + + pci_put_old_domain_nr(bus); pci_remove_bus(bus); host_bridge->bus = NULL; diff --git a/include/linux/pci.h b/include/linux/pci.h index 33c2b0b..af81e76 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -511,7 +511,7 @@ struct pci_bus { unsigned char primary; /* number of primary bridge */ unsigned char max_bus_speed; /* enum pci_bus_speed */ unsigned char cur_bus_speed; /* enum pci_bus_speed */ -#ifdef CONFIG_PCI_DOMAINS_GENERIC +#ifdef CONFIG_PCI_DOMAINS int domain_nr; #endif @@ -1445,13 +1445,17 @@ static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity) * configuration space. */ #ifdef CONFIG_PCI_DOMAINS +extern struct ida __domain_nr; extern int pci_domains_supported; -int pci_get_new_domain_nr(void); +int pci_get_new_domain_nr(struct pci_bus *bus); +void pci_put_old_domain_nr(struct pci_bus *bus); #else enum { pci_domains_supported = 0 }; static inline int pci_domain_nr(struct pci_bus *bus) { return 0; } static inline int pci_proc_domain(struct pci_bus *bus) { return 0; } -static inline int pci_get_new_domain_nr(void) { return -ENOSYS; } +static inline int pci_get_new_domain_nr(struct pci_bus *bus) +{ return -ENOSYS; } +static inline void pci_put_old_domain_nr(struct pci_bus *bus) { } #endif /* CONFIG_PCI_DOMAINS */ /*