linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] PCI/AER: Fix pci_ops return NULL when hotplug a pci bus doing aer error inject
@ 2012-09-12 12:33 Yijing Wang
  2012-09-12 12:33 ` [PATCH v2 2/4] PCI/AER: clean all untracked pci_ops_aer when rmmod aer_inject Yijing Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Yijing Wang @ 2012-09-12 12:33 UTC (permalink / raw)
  To: Bjorn Helgaas, Huang Ying, Chen Gong
  Cc: jiang.liu, Hanjun Guo, linux-pci, Yijing Wang

When we inject aer errors to the target pcie device by aer_inject module, the pci_ops of pci
bus which the target device is on will be assigned to pci_ops_aer.So if the target pci device
is a bridge, once we hot-remove and hot-add the bridge, the newly created child bus's pci_ops
will be assigned to pci_ops_aer too.Now every access to the child bus's devices will result to
system panic, because it get a NULL pci_ops in pci_read_aer/pci_write_aer.

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Reviewed-by: Sven Dietrich <Sven.Dietrich@huawei.com>
---
 drivers/pci/pcie/aer/aer_inject.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/pcie/aer/aer_inject.c b/drivers/pci/pcie/aer/aer_inject.c
index 4e24cb8..0816483 100644
--- a/drivers/pci/pcie/aer/aer_inject.c
+++ b/drivers/pci/pcie/aer/aer_inject.c
@@ -109,6 +109,19 @@ static struct aer_error *__find_aer_error_by_dev(struct pci_dev *dev)
 	return __find_aer_error((u16)domain, dev->bus->number, dev->devfn);
 }
 
+static bool pci_is_upstream_bus(struct pci_bus *bus, struct pci_bus *up_bus)
+{
+	struct pci_bus *pbus = bus->parent;
+
+	while (pbus) {
+		if (pbus == up_bus)
+			return true;
+		pbus = pbus->parent;
+	}
+
+	return false;
+}
+
 /* inject_lock must be held before calling */
 static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
 {
@@ -118,6 +131,13 @@ static struct pci_ops *__find_pci_bus_ops(struct pci_bus *bus)
 		if (bus_ops->bus == bus)
 			return bus_ops->ops;
 	}
+
+	/* can't find bus_ops, fall back to get bus_ops of upstream bus */
+	list_for_each_entry(bus_ops, &pci_bus_ops_list, list) {
+		if (pci_is_upstream_bus(bus, bus_ops->bus))
+			return bus_ops->ops;
+	}
+
 	return NULL;
 }
 
@@ -208,6 +228,7 @@ static int pci_read_aer(struct pci_bus *bus, unsigned int devfn, int where,
 	}
 out:
 	ops = __find_pci_bus_ops(bus);
+	BUG_ON(!ops);
 	spin_unlock_irqrestore(&inject_lock, flags);
 	return ops->read(bus, devfn, where, size, val);
 }
@@ -243,6 +264,7 @@ int pci_write_aer(struct pci_bus *bus, unsigned int devfn, int where, int size,
 	}
 out:
 	ops = __find_pci_bus_ops(bus);
+	BUG_ON(!ops);
 	spin_unlock_irqrestore(&inject_lock, flags);
 	return ops->write(bus, devfn, where, size, val);
 }
@@ -506,6 +528,7 @@ static struct miscdevice aer_inject_device = {
 	.fops = &aer_inject_fops,
 };
 
+
 static int __init aer_inject_init(void)
 {
 	return misc_register(&aer_inject_device);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-09-14  1:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-12 12:33 [PATCH v2 1/4] PCI/AER: Fix pci_ops return NULL when hotplug a pci bus doing aer error inject Yijing Wang
2012-09-12 12:33 ` [PATCH v2 2/4] PCI/AER: clean all untracked pci_ops_aer when rmmod aer_inject Yijing Wang
2012-09-13  1:43   ` Huang Ying
2012-09-13 10:54     ` Yijing Wang
2012-09-14  0:56       ` Huang Ying
2012-09-14  1:29         ` Yijing Wang
2012-09-12 12:33 ` [PATCH v2 3/4] PCI/AER: Clean pci_bus_ops when related pci bus was removed Yijing Wang
2012-09-12 12:33 ` [PATCH v2 4/4] PCI/AER: fix a small race condition window when rmmod aer_inject Yijing Wang
2012-09-13  1:29   ` Huang Ying
2012-09-13 10:59     ` Yijing Wang

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).