From patchwork Thu Feb 25 02:12:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 8416241 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 126D3C0553 for ; Thu, 25 Feb 2016 02:16:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2CCBB2022A for ; Thu, 25 Feb 2016 02:16:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D60BB2034A for ; Thu, 25 Feb 2016 02:16:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758943AbcBYCQS (ORCPT ); Wed, 24 Feb 2016 21:16:18 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:38379 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932711AbcBYCNx (ORCPT ); Wed, 24 Feb 2016 21:13:53 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1P2DVLo019186 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Feb 2016 02:13:32 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1P2DVPJ016094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 25 Feb 2016 02:13:31 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u1P2DUEU016704; Thu, 25 Feb 2016 02:13:30 GMT Received: from userv0022.oracle.com (/10.132.126.176) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Feb 2016 18:13:30 -0800 From: Yinghai Lu To: Bjorn Helgaas , David Miller , Benjamin Herrenschmidt , Wei Yang , TJ , Yijing Wang , Khalid Aziz Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v10 45/59] PCI: Fix size calculation with old_size on rescan path Date: Wed, 24 Feb 2016 18:12:36 -0800 Message-Id: <1456366370-28995-46-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1456366370-28995-1-git-send-email-yinghai@kernel.org> References: <1456366370-28995-1-git-send-email-yinghai@kernel.org> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On booting path, we don't pass realloc at first, and treat all optional just as required, in some case we can have smaller size/align with optional than required only. 04:00.0 has children bridges: 05:03.0, 05:04.0 pref layout after booting path like followings: pci 0000:04:00.0: BAR 9: assigned [mem 0x84000000-0x9fffffff 64bit pref] pci 0000:05:04.0: BAR 9: assigned [mem 0x88000000-0x9fffffff 64bit pref] pci 0000:05:03.0: BAR 9: assigned [mem 0x84000000-0x841fffff 64bit pref] pci 0000:05:03.0: PCI bridge to [bus 08-0f] pci 0000:05:03.0: bridge window [mem 0x84000000-0x841fffff 64bit pref] pci 0000:05:04.0: PCI bridge to [bus 10] pci 0000:05:04.0: bridge window [mem 0x88000000-0x9fffffff 64bit pref] pci 0000:04:00.0: PCI bridge to [bus 05-10] pci 0000:04:00.0: bridge window [mem 0x84000000-0x9fffffff 64bit pref] so the old size in rescan for 04:00.0 would be 0x1c000000, and align is 0x4000000 during remove and rescan: pci 0000:05:03.0: bridge window [mem 0x00000000-0xffffffffffffffff 64bit pref] to [bus 08-0f] add_size 200000 add_align 100000 alt_size 0 alt_align 0 must_size 0 must_align 0 pci 0000:05:03.0: bridge window [mem 0x00000000-0xffffffffffffffff] to [bus 08-0f] add_size 200000 add_align 100000 alt_size 0 alt_align 0 must_size 0 must_align 0 pci 0000:05:04.0: bridge window [mem 0x08000000-0x1fffffff 64bit pref] to [bus 10] add_size 0 add_align 0 alt_size 10100000 alt_align 10000000 must_size 18000000 must_align 8000000 pci 0000:05:03.0: BAR 9: [mem 0x00000000-0xffffffffffffffff 64bit pref] get_res_add_size add_size 200000 pci 0000:05:03.0: BAR 9: [mem 0x00000000-0xffffffffffffffff 64bit pref] get_res_add_align min_align 100000 pci 0000:04:00.0: bridge window [mem 0x08000000-0x27ffffff 64bit pref] to [bus 05-10] add_size 0 add_align 0 alt_size 10100000 alt_align 10000000 must_size 20000000 must_align 8000000 align old size 0x1c000000 to 0x2000000 as size0, 0x1c000000 as size1. so for 04:00.0 will have big must and no optional size anymore. So don't align old size, then we will have same size0 and size1, and use smaller add_align as must align. After the patch, rescan works properly. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 1fcb9b2..5eee16b 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1134,9 +1134,9 @@ static resource_size_t calculate_memsize(resource_size_t size, size = min_size; if (old_size == 1) old_size = 0; + size = ALIGN(size, align); if (size < old_size) size = old_size; - size = ALIGN(size, align); return size; } @@ -1596,6 +1596,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, b_res->flags = 0; return 0; } + + /* + * It happens when boot path is not passing realloc + * and later rescan is passing realloc. + * The old value from boot path is bigger, and calculate_size will + * use old value as size0 and size1, and also have + * chance optional align is smaller than must only align. + */ + if(size0 == size1 && min_align > min_add_align) + min_align = min_add_align; + b_res->start = min_align; b_res->end = size0 + min_align - 1; b_res->flags |= IORESOURCE_STARTALIGN;