linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Ram Pai <linuxram@us.ibm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH 01/21] PCI : Calculate right add_size
Date: Sat, 21 Jan 2012 02:08:17 -0800	[thread overview]
Message-ID: <1327140517-14811-2-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1327140517-14811-1-git-send-email-yinghai@kernel.org>

During debug one SRIOV enabled hotplug, found add_size is not passed properly.

the device have devices under two level bridges..

 +-[0000:80]-+-00.0-[81-8f]--
 |           +-01.0-[90-9f]--
 |           +-02.0-[a0-af]----00.0-[a1-a3]--+-02.0-[a2]--+-00.0  Oracle Corporation Device
 |           |                               \-03.0-[a3]--+-00.0  Oracle Corporation Device

so later parent bridge will not try to add big range.
[  557.455077] pci 0000:a0:00.0: BAR 14: assigned [mem 0xf9000000-0xf93fffff]
[  557.461974] pci 0000:a0:00.0: BAR 15: assigned [mem 0xf6000000-0xf61fffff pref]
[  557.469340] pci 0000:a1:02.0: BAR 14: assigned [mem 0xf9000000-0xf91fffff]
[  557.476231] pci 0000:a1:02.0: BAR 15: assigned [mem 0xf6000000-0xf60fffff pref]
[  557.483582] pci 0000:a1:03.0: BAR 14: assigned [mem 0xf9200000-0xf93fffff]
[  557.490468] pci 0000:a1:03.0: BAR 15: assigned [mem 0xf6100000-0xf61fffff pref]
[  557.497833] pci 0000:a1:03.0: BAR 14: can't assign mem (size 0x200000)
[  557.504378] pci 0000:a1:03.0: failed to add optional resources res=[mem 0xf9200000-0xf93fffff]
[  557.513026] pci 0000:a1:02.0: BAR 14: can't assign mem (size 0x200000)
[  557.519578] pci 0000:a1:02.0: failed to add optional resources res=[mem 0xf9000000-0xf91fffff]

it turns out We did not calculate size1 properly.

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)
{
        if (size < min_size)
                size = min_size;
        if (old_size == 1 )
                old_size = 0;
        if (size < old_size)
                size = old_size;
        size = ALIGN(size + size1, align);
        return size;
}

We should not pass add_size with min_size in calculate_memsize.
that will make add_size not contribute final add_size.

Just pass add_size with size1 to calculate_memsize()

With this change, We should have chance to remove extra addon in pci_reassign_resource...

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |    4 ++--
 drivers/pci/setup-res.c |    5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 86b69f85..9d932f4 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -612,7 +612,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
 	if (children_add_size > add_size)
 		add_size = children_add_size;
 	size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
-		calculate_iosize(size, min_size+add_size, size1,
+		calculate_iosize(size, min_size, add_size + size1,
 			resource_size(b_res), 4096);
 	if (!size0 && !size1) {
 		if (b_res->start || b_res->end)
@@ -726,7 +726,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
 	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, 0,
+		calculate_memsize(size, min_size, add_size,
 				resource_size(b_res), min_align);
 	if (!size0 && !size1) {
 		if (b_res->start || b_res->end)
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 5717509b..8b25f9c 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -233,11 +233,12 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz
 		return -EINVAL;
 	}
 
-	new_size = resource_size(res) + addsize + min_align;
+	/* already aligned with min_align */
+	new_size = resource_size(res) + addsize;
 	ret = _pci_assign_resource(dev, resno, new_size, min_align);
 	if (!ret) {
 		res->flags &= ~IORESOURCE_STARTALIGN;
-		dev_info(&dev->dev, "BAR %d: assigned %pR\n", resno, res);
+		dev_info(&dev->dev, "BAR %d: reassigned %pR\n", resno, res);
 		if (resno < PCI_BRIDGE_RESOURCES)
 			pci_update_resource(dev, resno);
 	}
-- 
1.7.7


  reply	other threads:[~2012-01-21 10:08 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
2012-01-21 10:08 ` Yinghai Lu [this message]
2012-01-27 17:55   ` [PATCH 01/21] PCI : Calculate right add_size Jesse Barnes
2012-01-21 10:08 ` [PATCH 02/21] PCI: Make add_to_list() return status Yinghai Lu
2012-01-21 10:08 ` [PATCH 03/21] PCI: Move get_res_add_size() early Yinghai Lu
2012-01-21 10:08 ` [PATCH 04/21] PCI: Try to assign required+option size at first Yinghai Lu
2012-01-21 10:08 ` [PATCH 05/21] PCI: Using add_list in pcie hotplug path Yinghai Lu
2012-01-21 10:08 ` [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed Yinghai Lu
2012-01-27 18:00   ` Jesse Barnes
2012-01-21 10:08 ` [PATCH 07/21] PCI: Make pci_rescan_bus handle add_list Yinghai Lu
2012-01-21 10:08 ` [PATCH 08/21] PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges Yinghai Lu
2012-01-21 10:08 ` [PATCH 09/21] PCI: Move pdev_sort_resources() to setup-bus.c Yinghai Lu
2012-01-21 10:08 ` [PATCH 10/21] PCI: Move struct resource_list " Yinghai Lu
2012-01-21 10:08 ` [PATCH 11/21] PCI: Replace resource_list with generic list Yinghai Lu
2012-01-21 10:08 ` [PATCH 12/21] PCI: Merge pci_dev_resource_x and pci_dev_resource Yinghai Lu
2012-01-21 10:08 ` [PATCH 13/21] PCI: Rename dev_res_x to add_res or fail_res Yinghai Lu
2012-01-21 10:08 ` [PATCH 14/21] PCI: Change free_list() to function Yinghai Lu
2012-01-21 10:08 ` [PATCH 15/21] PCI: add debug print out for add_size Yinghai Lu
2012-01-21 10:08 ` [PATCH 16/21] PCI: remove add_to_failed_list() Yinghai Lu
2012-01-27 18:21   ` Jesse Barnes
2012-01-21 10:08 ` [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL Yinghai Lu
2012-01-27 18:22   ` Jesse Barnes
2012-01-27 18:39     ` Yinghai Lu
2012-01-21 10:08 ` [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling Yinghai Lu
2012-01-27 18:23   ` Jesse Barnes
2012-01-27 21:37     ` Yinghai Lu
2012-02-05 21:58       ` Dominik Brodowski
2012-02-05 23:30         ` Yinghai Lu
2012-02-10 15:35           ` Dominik Brodowski
2012-02-10 17:07             ` Yinghai Lu
2012-01-21 10:08 ` [PATCH 19/21] PCI: Retry on type IORESOURCE_IO allocation Yinghai Lu
2012-01-21 10:08 ` [PATCH 20/21] PCI: Make pci bridge reallocating enabled/disabled Yinghai Lu
2012-01-21 10:08 ` [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned Yinghai Lu
2012-01-27 18:25   ` Jesse Barnes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327140517-14811-2-git-send-email-yinghai@kernel.org \
    --to=yinghai@kernel.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxram@us.ibm.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).