From patchwork Sun Mar 29 06:18:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 455723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9D52C14012F for ; Sun, 29 Mar 2015 17:19:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=Bk48ud51; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751012AbbC2GS6 (ORCPT ); Sun, 29 Mar 2015 02:18:58 -0400 Received: from mail-ie0-f169.google.com ([209.85.223.169]:33348 "EHLO mail-ie0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751001AbbC2GSn (ORCPT ); Sun, 29 Mar 2015 02:18:43 -0400 Received: by iecvj10 with SMTP id vj10so96675581iec.0 for ; Sat, 28 Mar 2015 23:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=5kK4o/tVX9X1tqoWSN5hEGrnCOTiu0cuMYstQcxSrlU=; b=Bk48ud51nWFZa5hnoB2lDia4QDhQVfktF4MYlbKuR43V2ayXowf5JLqUhKiPdNW4a/ 5IfLnLLKQrtgabxHuSRcNRDzT3J3ca2iQPBLagz23CgmuW3hNp/qtdMSB5VlbGJtiWfq N1NptVcfffOeVbVNfDj12CtBE7Loi52PbHZWZFjBiPlvvBG8m508faZx8zoIdQUXWIm7 Sk+62ieIt2dbZ6AaZGlkIZE8aJwR0OmRpAcHmdPqHrDM9Z9Bshy2djkG2JhXOg1niQIl qUpikFWyglHt1cR9ppRo2ogWXh3jIMvVnt0PfvTESsCqX6kMmc0zBP256/Yq6PG/F8AE pGJQ== MIME-Version: 1.0 X-Received: by 10.42.106.204 with SMTP id a12mr54775420icp.90.1427609922338; Sat, 28 Mar 2015 23:18:42 -0700 (PDT) Received: by 10.64.208.43 with HTTP; Sat, 28 Mar 2015 23:18:41 -0700 (PDT) In-Reply-To: <55167C1C.6010001@huawei.com> References: <55167C1C.6010001@huawei.com> Date: Sat, 28 Mar 2015 23:18:41 -0700 X-Google-Sender-Auth: qhbbkZ82nDaLicQKGi3o_JHQN40 Message-ID: Subject: Re: Assign mem resource fail after remove and rescan From: Yinghai Lu To: Yijing Wang Cc: Bjorn Helgaas , PCI , "Herui (Ray)" Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Sat, Mar 28, 2015 at 3:02 AM, Yijing Wang wrote: > ... > > I compared above log and found after we did remove and rescan, the bridge requested resource size extended to 0x06000000, > and when system boot up, it requested only 0x4800000. > > In hotplug(remove and rescan) path, we would call calculate_mem_align() function which would align the resource at 0x2000000. Looks like we align the size too early. Please check if attach patch could fix the problem. Thanks Yinghai Subject: [RFT PATCH] PCI: Align resource size later in bus mem sizing TEST only. We only need to align the size on bridge up one level later. --- drivers/pci/setup-bus.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) Index: linux-2.6/drivers/pci/setup-bus.c =================================================================== --- linux-2.6.orig/drivers/pci/setup-bus.c +++ linux-2.6/drivers/pci/setup-bus.c @@ -783,8 +783,7 @@ static resource_size_t calculate_iosize( static resource_size_t calculate_memsize(resource_size_t size, resource_size_t min_size, resource_size_t size1, - resource_size_t old_size, - resource_size_t align) + resource_size_t old_size) { if (size < min_size) size = min_size; @@ -792,8 +791,8 @@ static resource_size_t calculate_memsize old_size = 0; if (size < old_size) size = old_size; - size = ALIGN(size + size1, align); - return size; + + return size + size1; } resource_size_t __weak pcibios_window_alignment(struct pci_bus *bus, @@ -1008,10 +1007,10 @@ static int pbus_size_mem(struct pci_bus r->flags = 0; continue; } - size += r_size; + size += ALIGN(r_size, align); /* Exclude ranges with size > align from calculation of the alignment. */ - if (r_size == align) + if (r_size <= align) aligns[order] += align; if (order > max_order) max_order = order; @@ -1023,12 +1022,12 @@ static int pbus_size_mem(struct pci_bus min_align = calculate_mem_align(aligns, max_order); min_align = max(min_align, window_alignment(bus, b_res->flags)); - size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); + size0 = calculate_memsize(size, min_size, 0, resource_size(b_res)); if (children_add_size > add_size) add_size = children_add_size; size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 : calculate_memsize(size, min_size, add_size, - resource_size(b_res), min_align); + resource_size(b_res)); if (!size0 && !size1) { if (b_res->start || b_res->end) dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",