[PATCH v4 4/4] PCI: cadence: Check link is up before sending IRQ from EP

Subsystems: pci native host bridge and endpoint drivers, pci subsystem, the rest

STALE2915d

4 messages, 3 authors, 2018-10-16 · open the first message on its own page

[PATCH v4 4/4] PCI: cadence: Check link is up before sending IRQ from EP

From: Alan Douglas <hidden>
Date: 2018-10-11 16:17:17

If EP attempts to send an IRQ (legacy, MSI or MSI-X) while the
link is not up, return -EINVAL

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")
Signed-off-by: Alan Douglas <redacted>
---
 drivers/pci/controller/pcie-cadence-ep.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c
index b762214..3667d70 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -370,6 +370,12 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn,
 				  u16 interrupt_num)
 {
 	struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
+	u32 link_status;
+
+	/* Can't send an IRQ if the link is down. */
+	link_status = cdns_pcie_readl(&ep->pcie, CDNS_PCIE_LM_BASE);
+	if (!(link_status & 0x1))
+		return -EINVAL;
 
 	switch (type) {
 	case PCI_EPC_IRQ_LEGACY:
-- 
1.9.0

Re: [PATCH v4 4/4] PCI: cadence: Check link is up before sending IRQ from EP

From: Bjorn Helgaas <helgaas@kernel.org>
Date: 2018-10-15 21:30:39

On Thu, Oct 11, 2018 at 05:16:57PM +0100, Alan Douglas wrote:
quoted hunk
If EP attempts to send an IRQ (legacy, MSI or MSI-X) while the
link is not up, return -EINVAL

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")
Signed-off-by: Alan Douglas <redacted>
---
 drivers/pci/controller/pcie-cadence-ep.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c
index b762214..3667d70 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -370,6 +370,12 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn,
 				  u16 interrupt_num)
 {
 	struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
+	u32 link_status;
+
+	/* Can't send an IRQ if the link is down. */
+	link_status = cdns_pcie_readl(&ep->pcie, CDNS_PCIE_LM_BASE);
+	if (!(link_status & 0x1))
+		return -EINVAL;
This looks racy.  What happens if the link goes down right after the
CDNS_PCIE_LM_BASE read, but before we get here?
 	switch (type) {
 	case PCI_EPC_IRQ_LEGACY:
-- 
1.9.0

Re: [PATCH v4 4/4] PCI: cadence: Check link is up before sending IRQ from EP

From: Lorenzo Pieralisi <hidden>
Date: 2018-10-16 13:53:32

On Mon, Oct 15, 2018 at 04:30:35PM -0500, Bjorn Helgaas wrote:
On Thu, Oct 11, 2018 at 05:16:57PM +0100, Alan Douglas wrote:
quoted
If EP attempts to send an IRQ (legacy, MSI or MSI-X) while the
link is not up, return -EINVAL

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")
Signed-off-by: Alan Douglas <redacted>
---
 drivers/pci/controller/pcie-cadence-ep.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c
index b762214..3667d70 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -370,6 +370,12 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn,
 				  u16 interrupt_num)
 {
 	struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
+	u32 link_status;
+
+	/* Can't send an IRQ if the link is down. */
+	link_status = cdns_pcie_readl(&ep->pcie, CDNS_PCIE_LM_BASE);
+	if (!(link_status & 0x1))
+		return -EINVAL;
This looks racy.  What happens if the link goes down right after the
CDNS_PCIE_LM_BASE read, but before we get here?
I agree with Bjorn, this check does not seem very useful and honestly
I think this patch should be dropped, I should not have queued it in
the first place.

I wonder whether something can actually be done in the EP subsystem
to handle this in a cleaner way.

Unless I hear a compelling reason to keep it in the patch queue I
would drop this patch.

Lorenzo

RE: [PATCH v4 4/4] PCI: cadence: Check link is up before sending IRQ from EP

From: Alan Douglas <hidden>
Date: 2018-10-16 14:01:29

Hi,

On 16 October 2018 14:53, Lorenzo Pieralisi [off-list ref] wrote:
On Mon, Oct 15, 2018 at 04:30:35PM -0500, Bjorn Helgaas wrote:
quoted
On Thu, Oct 11, 2018 at 05:16:57PM +0100, Alan Douglas wrote:
quoted
If EP attempts to send an IRQ (legacy, MSI or MSI-X) while the
link is not up, return -EINVAL

Fixes: 37dddf14f1ae ("PCI: cadence: Add EndPoint Controller driver for Cadence PCIe controller")
Signed-off-by: Alan Douglas <redacted>
---
 drivers/pci/controller/pcie-cadence-ep.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c
index b762214..3667d70 100644
--- a/drivers/pci/controller/pcie-cadence-ep.c
+++ b/drivers/pci/controller/pcie-cadence-ep.c
@@ -370,6 +370,12 @@ static int cdns_pcie_ep_raise_irq(struct pci_epc *epc, u8 fn,
 				  u16 interrupt_num)
 {
 	struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
+	u32 link_status;
+
+	/* Can't send an IRQ if the link is down. */
+	link_status = cdns_pcie_readl(&ep->pcie, CDNS_PCIE_LM_BASE);
+	if (!(link_status & 0x1))
+		return -EINVAL;
This looks racy.  What happens if the link goes down right after the
CDNS_PCIE_LM_BASE read, but before we get here?
I agree with Bjorn, this check does not seem very useful and honestly
I think this patch should be dropped, I should not have queued it in
the first place.

I wonder whether something can actually be done in the EP subsystem
to handle this in a cleaner way.

Unless I hear a compelling reason to keep it in the patch queue I
would drop this patch.

Lorenzo
Makes sense to me, I was just preparing a reply.  I need to find
a fix that will work for all cases, possibly using the handshake
for the D0->D3 Config write which should precede the link down. At
the moment I think we need to insist that the link is always up while
the EP driver is loaded.

Alan

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help