All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Yang <weiyang@linux.vnet.ibm.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	David Miller <davem@davemloft.net>,
	David Ahern <david.ahern@oracle.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Wei Yang <weiyang@linux.vnet.ibm.com>, TJ <linux@iam.tj>,
	Yijing Wang <wangyijing@huawei.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 36/36] PCI: Don't set flags to 0 when assign resource fail
Date: Thu, 9 Jul 2015 11:30:30 +0800	[thread overview]
Message-ID: <20150709033030.GA7079@richard> (raw)
In-Reply-To: <1436225966-27247-37-git-send-email-yinghai@kernel.org>

Hi, Yinghai

This patch may introduce some problem.

On my P8 machine, after applying this patch, I see following error:

[    0.589948] pnv_ioda_setup_pe_seg: trigger IO SEG 0
[    0.589992] pnv_ioda_setup_pe_seg: res[io  0x1000-0x3fff] 100

The last 0x100 is the res->flags, which indicates the UNSET and DISABLED bit
is not set.

On P8, we don't have IO window, which means the IO BAR will not be assigned.
And those io_segmap is not allocated. The following trace is printed since the
io_segmap is accessed, while it is NULL.

[    0.590050] Unable to handle kernel paging request for data at address 0x00000000
[    0.590115] Faulting instruction address: 0xc0000000000759b8
[    0.590172] Oops: Kernel access of bad area, sig: 11 [#1]
[    0.590216] SMP NR_CPUS=1024 NUMA PowerNV
[    0.590262] Modules linked in:
[    0.590309] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.2.0-rc1eeh_refactor+ #244
[    0.590375] task: c000002ff4380000 ti: c000002ff6084000 task.ti: c000002ff6084000
[    0.590440] NIP: c0000000000759b8 LR: c000000000075960 CTR: 000000003004a1bc
[    0.590506] REGS: c000002ff6087620 TRAP: 0300   Not tainted  (4.2.0-rc1eeh_refactor+)
[    0.590572] MSR: 9000000000009032 <SF,HV,EE,ME,IR,DR,RI>  CR: 22000028  XER: 20000000
[    0.590727] CFAR: c000000000008468 DAR: 0000000000000000 DSISR: 42000000 SOFTE: 1 
GPR00: c000000000075960 c000002ff60878a0 c000000001534f00 0000000000000031 
GPR04: 0000000000000001 0000000000000003 0000000000000000 0000000000000000 
GPR08: 0000000000000006 0000000000000000 0000000000000000 00000000000003f2 
GPR12: 0000000022000022 c00000000fda0000 c000000000b82c88 0000000000000000 
GPR16: 0000000000003fff 0000000000000000 0000000000001000 c000000000b82cc8 
GPR20: c000000000b82c50 c000000000b82c70 c000000001452148 c000002fffb2d900 
GPR24: c000000000923c40 c000002fffb4c810 c000002fffb4c300 0000000000102000 
GPR28: c000002fffb40720 c000001ff42aa500 c000002fffb4c580 0000000000000000 
[    0.591603] NIP [c0000000000759b8] .pnv_pci_ioda_fixup+0xaa8/0xb20
[    0.591658] LR [c000000000075960] .pnv_pci_ioda_fixup+0xa50/0xb20
[    0.591713] Call Trace:
[    0.591736] [c000002ff60878a0] [c000000000075960] .pnv_pci_ioda_fixup+0xa50/0xb20 (unreliable)
[    0.591824] [c000002ff6087a40] [c000000000caf0a8] .pcibios_resource_survey+0x3a8/0x404
[    0.591901] [c000002ff6087b60] [c000000000cae7f0] .pcibios_init+0xa0/0xd4
[    0.591968] [c000002ff6087bf0] [c00000000000ad30] .do_one_initcall+0x110/0x280
[    0.592045] [c000002ff6087ce0] [c000000000ca45c4] .kernel_init_freeable+0x274/0x35c
[    0.592122] [c000002ff6087db0] [c00000000000b5e4] .kernel_init+0x24/0x140
[    0.592188] [c000002ff6087e30] [c0000000000094e8] .ret_from_kernel_thread+0x58/0x70
[    0.592265] Instruction dump:
[    0.592298] 7d3107b4 7f084840 7e525214 7fb09040 4099f7b8 419cf7b4 e93e0180 811c0024 
[    0.592408] 7a2a1764 38a00003 7a270420 38c00000 <7d09512e> a09c0026 e87e0018 4bff1c59 
[    0.592524] ---[ end trace 856c9d223a60380c ]---
[    0.593584] 
[    2.593742] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
[    2.593742] 
[    2.605223] Rebooting in 10 seconds..


On Mon, Jul 06, 2015 at 04:39:26PM -0700, Yinghai Lu wrote:
>make flags take IORESOURCE_UNSET | IORESOURCE_DISABLED instead.
>
>Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>---
> drivers/pci/setup-bus.c | 52 +++++++++++++++++++++++++------------------------
> drivers/pci/setup-res.c | 11 +++++++++++
> 2 files changed, 38 insertions(+), 25 deletions(-)
>
>diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
>index 9b27e15..e82655b 100644
>--- a/drivers/pci/setup-bus.c
>+++ b/drivers/pci/setup-bus.c
>@@ -255,7 +255,8 @@ static void pdev_check_resources(struct pci_dev *dev,
> 		if (r->flags & IORESOURCE_PCI_FIXED)
> 			continue;
>
>-		if (!(r->flags) || r->parent)
>+		if (!r->flags || r->parent ||
>+		    (r->flags & IORESOURCE_DISABLED))
> 			continue;
>
> 		r_align = __pci_resource_alignment(dev, r, realloc_head);
>@@ -296,13 +297,6 @@ static void __dev_check_resources(struct pci_dev *dev,
> 	pdev_check_resources(dev, realloc_head, head);
> }
>
>-static inline void reset_resource(struct resource *res)
>-{
>-	res->start = 0;
>-	res->end = 0;
>-	res->flags = 0;
>-}
>-
> static void __sort_resources(struct list_head *head)
> {
> 	struct pci_dev_resource *res1, *tmp_res, *res2;
>@@ -387,7 +381,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
> 	list_for_each_entry_safe(add_res, tmp, realloc_head, list) {
> 		res = add_res->res;
> 		/* skip resource that has been reset */
>-		if (!res->flags)
>+		if (res->flags & IORESOURCE_DISABLED)
> 			goto out;
>
> 		/* skip this resource if not found in head list */
>@@ -405,7 +399,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
> 			res->start = align;
> 			res->end = res->start + add_size - 1;
> 			if (pci_assign_resource(add_res->dev, idx))
>-				reset_resource(res);
>+				res->flags |= IORESOURCE_DISABLED;
> 		} else {
> 			/* could just assigned with alt, add difference ? */
> 			if (r_size < add_res->must_size)
>@@ -454,7 +448,7 @@ static void assign_requested_resources_sorted(struct list_head *head,
> 		    pci_assign_resource(dev_res->dev, idx)) {
> 			if (fail_head)
> 				add_to_list(fail_head, dev_res->dev, res);
>-			reset_resource(res);
>+			res->flags |= IORESOURCE_DISABLED;
> 		}
> 	}
> }
>@@ -672,7 +666,7 @@ static void __assign_resources_alt_sorted(struct list_head *head,
> 			release_resource(dev_res->res);
> 			/* put into fail list */
> 			add_to_list(local_fail_head, dev_res->dev, res);
>-			reset_resource(res);
>+			res->flags |= IORESOURCE_DISABLED;
> 		}
>
> 		alt_res = res_to_dev_res(realloc_head, res);
>@@ -716,7 +710,7 @@ static void __assign_resources_alt_sorted(struct list_head *head,
> 		res->end = res->start + dev_res->must_size - 1;
>
> 		add_to_list(local_fail_head, fail_res->dev, res);
>-		reset_resource(res);
>+		res->flags |= IORESOURCE_DISABLED;
> 	}
> 	free_list(&local_alt_fail_head);
> }
>@@ -872,7 +866,7 @@ static void pci_setup_bridge_io(struct pci_dev *bridge)
> 	/* Set up the top and bottom of the PCI I/O segment for this bus. */
> 	res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0];
> 	pcibios_resource_to_bus(bridge->bus, &region, res);
>-	if (res->flags & IORESOURCE_IO) {
>+	if ((res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_UNSET)) {
> 		pci_read_config_word(bridge, PCI_IO_BASE, &l);
> 		io_base_lo = (region.start >> 8) & io_mask;
> 		io_limit_lo = (region.end >> 8) & io_mask;
>@@ -902,7 +896,8 @@ static void pci_setup_bridge_mmio(struct pci_dev *bridge)
> 	/* Set up the top and bottom of the PCI Memory segment for this bus. */
> 	res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1];
> 	pcibios_resource_to_bus(bridge->bus, &region, res);
>-	if (res->flags & IORESOURCE_MEM) {
>+	if ((res->flags & IORESOURCE_MEM) &&
>+	    !(res->flags & IORESOURCE_UNSET)) {
> 		l = (region.start >> 16) & 0xfff0;
> 		l |= region.end & 0xfff00000;
> 		dev_info(&bridge->dev, "  bridge window %pR\n", res);
>@@ -927,7 +922,8 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
> 	bu = lu = 0;
> 	res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2];
> 	pcibios_resource_to_bus(bridge->bus, &region, res);
>-	if (res->flags & IORESOURCE_PREFETCH) {
>+	if ((res->flags & IORESOURCE_PREFETCH) &&
>+	    !(res->flags & IORESOURCE_UNSET)) {
> 		l = (region.start >> 16) & 0xfff0;
> 		l |= region.end & 0xfff00000;
> 		if (res->flags & IORESOURCE_MEM_64) {
>@@ -1046,6 +1042,7 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
>
> 	b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
> 	b_res[1].flags |= IORESOURCE_MEM;
>+	b_res[1].flags &= ~IORESOURCE_DISABLED;
>
> 	pci_read_config_word(bridge, PCI_IO_BASE, &io);
> 	if (!io) {
>@@ -1053,8 +1050,10 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
> 		pci_read_config_word(bridge, PCI_IO_BASE, &io);
> 		pci_write_config_word(bridge, PCI_IO_BASE, 0x0);
> 	}
>-	if (io)
>+	if (io) {
> 		b_res[0].flags |= IORESOURCE_IO;
>+		b_res[0].flags &= ~IORESOURCE_DISABLED;
>+	}
>
> 	/*  DECchip 21050 pass 2 errata: the bridge may miss an address
> 	    disconnect boundary by one PCI data phase.
>@@ -1071,6 +1070,7 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
> 	}
> 	if (pmem) {
> 		b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
>+		b_res[2].flags &= ~IORESOURCE_DISABLED;
> 		if ((pmem & PCI_PREF_RANGE_TYPE_MASK) ==
> 		    PCI_PREF_RANGE_TYPE_64) {
> 			b_res[2].flags |= IORESOURCE_MEM_64;
>@@ -1214,8 +1214,10 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
> 			struct resource *r = &dev->resource[i];
> 			unsigned long r_size;
>
>-			if (r->parent || !(r->flags & IORESOURCE_IO))
>+			if (r->parent || !(r->flags & IORESOURCE_IO) ||
>+			    (r->flags & IORESOURCE_DISABLED))
> 				continue;
>+
> 			r_size = resource_size(r);
>
> 			if (r_size < 0x400)
>@@ -1244,7 +1246,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
> 		if (b_res->start || b_res->end)
> 			dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",
> 				 b_res, &bus->busn_res);
>-		b_res->flags = 0;
>+		b_res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
> 		return;
> 	}
>
>@@ -1513,7 +1515,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
>
> 			if (r->parent || ((flags & mask) != type &&
> 					  (flags & mask) != type2 &&
>-					  (flags & mask) != type3))
>+					  (flags & mask) != type3) ||
>+			    (r->flags & IORESOURCE_DISABLED))
> 				continue;
>
> 			r_size = resource_size(r);
>@@ -1534,7 +1537,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
> 			if (align > (1ULL<<37)) { /*128 Gb*/
> 				dev_warn(&dev->dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
> 					i, r, (unsigned long long) align);
>-				r->flags = 0;
>+				r->flags |= IORESOURCE_UNSET |
>+					    IORESOURCE_DISABLED;
> 				continue;
> 			}
>
>@@ -1622,7 +1626,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
> 		if (b_res->start || b_res->end)
> 			dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",
> 				 b_res, &bus->busn_res);
>-		b_res->flags = 0;
>+		b_res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
> 		return 0;
> 	}
> 	b_res->start = min_align;
>@@ -2024,7 +2028,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus,
> 		/* keep the old size */
> 		r->end = resource_size(r) - 1;
> 		r->start = 0;
>-		r->flags = 0;
>+		r->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
>
> 		/* avoiding touch the one without PREF */
> 		if (type & IORESOURCE_PREFETCH)
>@@ -2284,7 +2288,6 @@ again:
> 		res->end = fail_res->end;
> 		res->flags = fail_res->flags;
> 		if (fail_res->dev->subordinate) {
>-			res->flags = 0;
> 			/* last or third times and later */
> 			if (tried_times + 1 == pci_try_num ||
> 			    tried_times + 1 > 2) {
>@@ -2372,7 +2375,6 @@ again:
> 		res->end = fail_res->end;
> 		res->flags = fail_res->flags;
> 		if (fail_res->dev->subordinate) {
>-			res->flags = 0;
> 			/* last time */
> 			res->start = 0;
> 			res->end = res->start - 1;
>diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
>index 26aedde..2a5cddc 100644
>--- a/drivers/pci/setup-res.c
>+++ b/drivers/pci/setup-res.c
>@@ -371,6 +371,17 @@ int pci_enable_resources(struct pci_dev *dev, int mask)
> 			continue;
>
> 		if (r->flags & IORESOURCE_UNSET) {
>+			/* bridge BAR could be disabled one by one */
>+			if (dev->subordinate && i >= PCI_BRIDGE_RESOURCES &&
>+						i <= PCI_BRIDGE_RESOURCE_END)
>+				continue;
>+
>+#ifdef CONFIG_PCI_IOV
>+			/* SRIOV ? */
>+			if (i >= PCI_IOV_RESOURCES && i <= PCI_IOV_RESOURCE_END)
>+				continue;
>+#endif
>+
> 			dev_err(&dev->dev, "can't enable device: BAR %d %pR not assigned\n",
> 				i, r);
> 			return -EINVAL;
>-- 
>1.8.4.5

-- 
Richard Yang
Help you, Help me


  reply	other threads:[~2015-07-09  3:30 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 23:38 [PATCH 00/36] PCI: Resource allocation cleanup for v4.3 Yinghai Lu
2015-07-06 23:38 ` [PATCH 01/36] PCI: Cleanup res_to_dev_res() printout for addon resources Yinghai Lu
2015-07-06 23:38 ` [PATCH 02/36] PCI: Reuse res_to_dev_res in reassign_resources_sorted Yinghai Lu
2015-07-06 23:38 ` [PATCH 03/36] PCI: Use correct align for optional only resources during sorting for resource allocation Yinghai Lu
2015-07-06 23:38 ` [PATCH 04/36] PCI: Optimize bus align/size calculation during sizing Yinghai Lu
2015-07-06 23:38 ` [PATCH 05/36] PCI: Optimize bus align/size calculation for optional " Yinghai Lu
2015-07-06 23:38 ` [PATCH 06/36] PCI: Reorder resources list for must/optional resources Yinghai Lu
2015-07-06 23:38 ` [PATCH 07/36] PCI: Remove duplicated code for resource sorting Yinghai Lu
2015-07-06 23:38 ` [PATCH 08/36] PCI: Rename pdev_sort_resources to pdev_check_resources Yinghai Lu
2015-07-06 23:38 ` [PATCH 09/36] PCI: Treat ROM resource as optional during realloc Yinghai Lu
2015-07-06 23:39 ` [PATCH 10/36] PCI: Add debug printout during releasing partial must/optinal assigned resources Yinghai Lu
2015-07-06 23:39 ` [PATCH 11/36] PCI: Simplify res reference using in __assign_resourcs_sorted Yinghai Lu
2015-07-06 23:39 ` [PATCH 12/36] PCI: Separate realloc list checking after allocation Yinghai Lu
2015-07-06 23:39 ` [PATCH 13/36] PCI: Add __add_to_list() Yinghai Lu
2015-07-06 23:39 ` [PATCH 14/36] PCI: Separate must_add assigning to another function Yinghai Lu
2015-07-06 23:39 ` [PATCH 15/36] PCI: Bail out early if there is no addon Yinghai Lu
2015-07-06 23:39 ` [PATCH 16/36] PCI: Add alt_size allocation support Yinghai Lu
2015-07-06 23:39 ` [PATCH 17/36] PCI: Add support for more than two alt_size under same bridge Yinghai Lu
2015-07-15  3:07   ` Yijing Wang
2015-07-15  5:08     ` Yinghai Lu
2015-07-15  5:16       ` Yijing Wang
2015-07-06 23:39 ` [PATCH 18/36] PCI: Better support for two alt_size Yinghai Lu
2015-07-06 23:39 ` [PATCH 19/36] resources: Split out __allocate_resource() Yinghai Lu
2015-07-06 23:39 ` [PATCH 20/36] resources: Make allocate_resource return just fit resource Yinghai Lu
2015-07-06 23:39 ` [PATCH 21/36] PCI: Check pref compatible bit for mem64 resource of pcie device Yinghai Lu
2015-07-06 23:39 ` [PATCH 22/36] PCI: Only treat non-pef mmio64 as pref if all bridges has MEM_64 Yinghai Lu
2015-07-06 23:39 ` [PATCH 23/36] PCI: Add has_mem64 for host_bridge Yinghai Lu
2015-07-06 23:39 ` [PATCH 24/36] PCI: Only treat non-pef mmio64 as pref if host-bridge has_mem64 Yinghai Lu
2015-07-06 23:39 ` [PATCH 25/36] PCI: Restore pref mmio allocation logic for hostbridge without mmio64 Yinghai Lu
2015-07-06 23:39 ` [PATCH 26/36] sparc/PCI: Add mem64 resource parsing for root bus Yinghai Lu
2015-07-06 23:39 ` [PATCH 27/36] sparc/PCI: Add IORESOURCE_MEM_64 for 64-bit resource in of parsing Yinghai Lu
2015-07-06 23:39   ` Yinghai Lu
2015-07-06 23:39 ` [PATCH 28/36] powerpc/PCI: " Yinghai Lu
2015-07-06 23:39 ` [PATCH 29/36] of/PCI: Add IORESOURCE_MEM_64 for 64-bit resource Yinghai Lu
2015-07-06 23:39   ` Yinghai Lu
2015-07-10 20:21   ` Rob Herring
2015-07-06 23:39 ` [PATCH 30/36] PCI: Treat optional as must in first try for bridge rescan Yinghai Lu
2015-07-06 23:39 ` [PATCH 31/36] PCI: Get new realloc size for bridge for last try Yinghai Lu
2015-07-06 23:39 ` [PATCH 32/36] PCI: Don't release sibiling bridge resources during hotplug Yinghai Lu
2015-07-06 23:39 ` [PATCH 33/36] PCI: Don't release fixed resource for realloc Yinghai Lu
2015-07-06 23:39 ` [PATCH 34/36] PCI: Set resource to FIXED for lsi devices Yinghai Lu
2015-07-06 23:39 ` [PATCH 35/36] PCI, x86: Add pci=assign_pref_bars to re-allocate pref bars Yinghai Lu
2015-07-06 23:39 ` [PATCH 36/36] PCI: Don't set flags to 0 when assign resource fail Yinghai Lu
2015-07-09  3:30   ` Wei Yang [this message]
2015-07-09  5:01     ` Yinghai Lu
2015-07-09  6:04       ` Wei Yang
2015-07-09 16:20         ` Yinghai Lu
2015-07-10  2:30           ` Wei Yang
2015-07-10  2:48             ` Yinghai Lu
2015-07-10  5:49               ` Yinghai Lu
2015-07-11  0:03                 ` Wei Yang
2015-07-11  0:42                   ` Yinghai Lu
2015-07-11  1:37                     ` Wei Yang

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=20150709033030.GA7079@richard \
    --to=weiyang@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=davem@davemloft.net \
    --cc=david.ahern@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@iam.tj \
    --cc=wangyijing@huawei.com \
    --cc=yinghai@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.