PCI: don't UNSET valid resources when reassign fails
PATCH v2 1/1 PCI: don't UNSET valid resources when reassign fails
Commit bd064f0a sets IORESOURCE_UNSET flag if resources can not be assgined. Part of these changes breaks resource assignment.
If resource is too big, PCI core assgins basic part first and extends (reassigns) it to include optional part (notably SR-IOV resources). In this case, IORESOURCE_UNSET should not be set if resource is properly assigned before reassigning. Otherwise, these resources are never updated to hardware and we will see errors like this:
pci 0003:00:00.0: can't enable device: BAR 15 [mem size 0x0c000000 64bit pref] not assigned pci 0003:00:00.0: Error enabling bridge (-22), continuing
---
Changed from v1: don't clear IORESOURCE_UNSET unconditionally
--- drivers/pci/setup-res.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/pci/setup-res.c +10 -3
@@ -321,9 +321,14 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz {struct resource *res = dev->resource + resno;resource_size_t new_size; -int ret; +int ret, valid; + +if (!(res->flags &IORESOURCE_UNSET )) { + valid =1 ; + res->flags |=IORESOURCE_UNSET ; + }else + valid =0 ; - res->flags |=IORESOURCE_UNSET ;if (!res->parent) {dev_info (&dev->dev,"BAR %d: can't reassign an unassigned resource %pR\n" , resno, res);
@@ -339,7 +344,9 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsizdev_info (&dev->dev,"BAR %d: reassigned %pR\n" , resno, res);if (resno <PCI_BRIDGE_RESOURCES )pci_update_resource (dev, resno); - } + }else if (valid) + res->flags &= ~IORESOURCE_UNSET ; +return ret; }
Signature · 1 line
1.8.3.1
Bjorn Helgaas
maintainerQuoted 9 lines · Guo Chao
Commit
bd064f0asetsIORESOURCE_UNSETflag if resources can not be assgined. Part of these changes breaks resource assignment.If resource is too big, PCI core assgins basic part first and extends (reassigns) it to include optional part (notably SR-IOV resources). In this case,
IORESOURCE_UNSETshould not be set if resource is properly assigned before reassigning. Otherwise, these resources are never updated to hardware and we will see errors like this:
Quoted 4 lines
pci 0003:00:00.0: can't enable device: BAR 15 [mem size 0x0c000000 64bit pref] not assigned pci 0003:00:00.0: Error enabling bridge (-22), continuingSigned-off-by Guo Chao <[email protected]>
I propose the following simpler patch. Can you verify that it works for you?
commit 57ece376a3b9e013277032f473197052f1144142
Author: Guo Chao <[email protected]> Date: Thu Jul 3 18:30:29 2014 -0600
PCI: Keep original resource if we fail to expand it
If we have space assigned to a resource, we try to expand the resource (e.g., to accommodate SR-IOV resources), and the expansion attempt fails, we should keep the original assignment.
After bd064f0a231a ("PCI: Mark resources as IORESOURCE_UNSET if we can't assign them"), we left the resource marked IORESOURCE_UNSET when the expansion failed, even if it had originally been set. That caused errors like this:
pci 0003:00:00.0: can't enable device: BAR 15 [mem size 0x0c000000 64bit pref] not assigned pci 0003:00:00.0: Error enabling bridge (-22), continuing
Fix this by restoring the original flags when reassignment fails.
drivers/pci/setup-res.c +7 -0
@@ -320,9 +320,11 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz resource_size_t min_align) {struct resource *res = dev->resource + resno; +unsigned long flags;resource_size_t new_size;int ret; + flags = res->flags; res->flags |=IORESOURCE_UNSET ;if (!res->parent) { dev_info(&dev->dev, "BAR %d: can't reassign an unassigned resource %pR\n",
@@ -339,7 +341,12 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsizdev_info (&dev->dev,"BAR %d: reassigned %pR\n" , resno, res);if (resno <PCI_BRIDGE_RESOURCES )pci_update_resource (dev, resno); + }else { + res->flags = flags; +dev_info (&dev->dev,"BAR %d: %pR (failed to expand by %#llx)\n" , + resno, res, addsize); } +return ret; }
Quoted 10 lines · Bjorn Helgaas
Quoted 9 lines · Guo Chao
Commit
bd064f0asetsIORESOURCE_UNSETflag if resources can not be assgined. Part of these changes breaks resource assignment.If resource is too big, PCI core assgins basic part first and extends (reassigns) it to include optional part (notably SR-IOV resources). In this case,
IORESOURCE_UNSETshould not be set if resource is properly assigned before reassigning. Otherwise, these resources are never updated to hardware and we will see errors like this:
Quoted 7 lines
Quoted 4 lines
pci 0003:00:00.0: can't enable device: BAR 15 [mem size 0x0c000000 64bit pref] not assigned pci 0003:00:00.0: Error enabling bridge (-22), continuingSigned-off-by Guo Chao <[email protected]>I propose the following simpler patch. Can you verify that it works for you?
Hi Bjorn:
Sure it works.
(Sorry for this late response. The machine is out of reach for past few days.)
Thanks,
Guo Chao
Quoted 58 lines
commit
57ece376a3b9e013277032f473197052f1144142Author: Guo Chao <[email protected]> Date: Thu Jul 3 18:30:29 2014 -0600PCI: Keep original resource if we fail to expand it
If we have space assigned to a resource, we try to expand the resource (e.g., to accommodate SR-IOV resources), and the expansion attempt fails, we should keep the original assignment.
After
bd064f0a231a("PCI: Mark resources asIORESOURCE_UNSETif we can't assign them"), we left the resource markedIORESOURCE_UNSETwhen the expansion failed, even if it had originally been set. That caused errors like this:pci 0003:00:00.0: can't enable device: BAR 15 [mem size
0x0c00000064bit pref] not assigned pci 0003:00:00.0: Error enabling bridge (-22), continuingFix this by restoring the original flags when reassignment fails.
[bhelgaas: reworked to simplify, changelog]Fixes bd064f0a231a ("PCI: Mark resources as IORESOURCE_UNSET if we can't assign them")Signed-off-by Guo Chao <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>CC [email protected] # v3.15+drivers/pci/setup-res.c +7
-0@@ -320,9 +320,11 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz resource_size_t min_align) {struct resource *res = dev->resource + resno; +unsigned long flags;resource_size_t new_size;int ret; + flags = res->flags; res->flags |=IORESOURCE_UNSET ;if (!res->parent) { dev_info(&dev->dev, "BAR %d: can't reassign an unassigned resource %pR\n",@@ -339,7 +341,12 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsizdev_info (&dev->dev,"BAR %d: reassigned %pR\n" , resno, res);if (resno <PCI_BRIDGE_RESOURCES )pci_update_resource (dev, resno); + }else { + res->flags = flags; +dev_info (&dev->dev,"BAR %d: %pR (failed to expand by %#llx)\n" , + resno, res, addsize); } +return ret; }