Skip to contentSkip to conversation

PCI: stop crashing in pci_release_resource v2

PATCH In review Christian König 3 participants 5 messages Feb 21, 2018 – Mar 2, 2018 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: stop crashing in pci_release_resource v2

Is it entirely possible that the BIOS wasn't able to assign resources to a device. In this case don't crash in pci_release_resource() when we try to resize the resource.

v2: keep printing the info that we try to release the BAR

---
 drivers/pci/setup-res.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/setup-res.c +4 -0
index e815111f3f81..c0f091614805 100644
@@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
 	struct resource *res = dev->resource + resno;
 
 	dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
+
+	if (!res->parent)
+		return;
+
 	release_resource(res);
 	res->end = resource_size(res) - 1;
 	res->start = 0;
Signature · 1 line
2.14.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Wed, Feb 21, 2018 at 11:07 AM, Christian K=C3=B6nig…

Is it entirely possible that the BIOS wasn't able to assign resources to a device. In this case don't crash in pci_release_resource() when we try to resize the resource.

v2: keep printing the info that we try to release the BAR

FWIW,

drivers/pci/setup-res.c void pci_release_resource(struct pci_dev *dev, int r=

Quoted 11 lines
---
 drivers/pci/setup-res.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/setup-res.c +0 -0
index e815111f3f81..c0f091614805 100644
@@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int r=

esno)

Quoted 11 lines
drivers/pci/setup-res.c +4 -1
        struct resource *res =3D dev->resource + resno;
 
        dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
+
+       if (!res->parent)
+               return;
+
        release_resource(res);
        res->end =3D resource_size(res) - 1;
        res->start =3D 0;
--
Quoted 2 lines

2.14.1

--=20
With Best Regards,
Andy Shevchenko

#2 lore raw
In reply to Christian König
Quoted 8 lines · Christian König

Is it entirely possible that the BIOS wasn't able to assign resources to a device. In this case don't crash in pci_release_resource() when we try to resize the resource.

v2: keep printing the info that we try to release the BAR

I think we probably want this in v4.16, since it seems to be a fix for 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs"), which appeared in v4.15.

What does the crash look like? I might include a few lines in the changelog to help people find the fix.

I added a Fixes: tag and Andy's Reviewed-by already.

Quoted 22 lines
---
 drivers/pci/setup-res.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/setup-res.c +4 -0
index e815111f3f81..c0f091614805 100644
@@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
 	struct resource *res = dev->resource + resno;
 
 	dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
+
+	if (!res->parent)
+		return;
+
 	release_resource(res);
 	res->end = resource_size(res) - 1;
 	res->start = 0;
Signature · 1 line
2.14.1
#3 lore raw
In reply to Christian König
Quoted 8 lines · Christian König

Is it entirely possible that the BIOS wasn't able to assign resources to a device. In this case don't crash in pci_release_resource() when we try to resize the resource.

v2: keep printing the info that we try to release the BAR

I was hoping for a dmesg snippet, but I added a Fixes: tag and applied this to for-linus for v4.16.

Quoted 22 lines
---
 drivers/pci/setup-res.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/setup-res.c +4 -0
index e815111f3f81..c0f091614805 100644
@@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
 	struct resource *res = dev->resource + resno;
 
 	dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
+
+	if (!res->parent)
+		return;
+
 	release_resource(res);
 	res->end = resource_size(res) - 1;
 	res->start = 0;
Signature · 1 line
2.14.1
#4 lore raw

Am 01.03.2018 um 19:49 schrieb Bjorn Helgaas:

Quoted 11 lines · Christian König
Quoted 8 lines

Is it entirely possible that the BIOS wasn't able to assign resources to a device. In this case don't crash in pci_release_resource() when we try to resize the resource.

v2: keep printing the info that we try to release the BAR

I was hoping for a dmesg snippet, but I added a Fixes: tag and applied this to for-linus for v4.16.

Sorry, been on vacation and missed your mail.

I don't have a dmesg of hand either, cause the reporter provided only a mail with a picture of the crash :)

But he confirmed that the patch worked.

Thanks,
Christian.

Quoted 23 lines
Quoted 23 lines
---
  drivers/pci/setup-res.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/pci/setup-res.c +4 -0
index e815111f3f81..c0f091614805 100644
@@ -402,6 +402,10 @@ void pci_release_resource(struct pci_dev *dev, int resno)
  	struct resource *res = dev->resource + resno;
 
  	dev_info(&dev->dev, "BAR %d: releasing %pR\n", resno, res);
+
+	if (!res->parent)
+		return;
+
  	release_resource(res);
  	res->end = resource_size(res) - 1;
  	res->start = 0;
Signature · 1 line
2.14.1