Skip to contentSkip to conversation

PCI: xilinx: use fwnode_irq_get() for INTx IRQ lookup

PATCH In review Rosen Penev 3 participants 7 messages Jul 16 – Aug 3

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: xilinx: use fwnode_irq_get() for INTx IRQ lookup

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

Unlike irq_of_parse_and_map(), fwnode_irq_get() returns a positive IRQ or a negative errno and never 0 (it rewrites 0 to -EINVAL). Store the result in an int and check for irq < 0, returning the error (including -EPROBE_DEFER). This also adds the error handling the previous code lacked, where irq_of_parse_and_map() failures were passed straight into devm_request_irq().

Built for ARM (multi_v7_defconfig + CONFIG_PCIE_XILINX) with LLVM=1; drivers/pci/controller/pcie-xilinx.o compiles cleanly.

Assisted-by opencode:hy3-free

---
v2: use dev_err_probe to handle EPROBE_DEFER.

 drivers/pci/controller/pcie-xilinx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pci/controller/pcie-xilinx.c +8 -7
index 4aa139abac16..58532296182f 100644
@@ -20,10 +20,10 @@
 #include <linux/of_address.h>
 #include <linux/of_pci.h>
 #include <linux/of_platform.h>
-#include <linux/of_irq.h>
 #include <linux/pci.h>
 #include <linux/pci-ecam.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 
 #include "../pci.h"
 
@@ -535,7 +535,7 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
 	struct device *dev = pcie->dev;
 	struct device_node *node = dev->of_node;
 	struct resource regs;
-	unsigned int irq;
+	int irq;
 	int err;
 
 	err = of_address_to_resource(node, 0, &regs);
@@ -548,7 +548,10 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
 	if (IS_ERR(pcie->reg_base))
 		return PTR_ERR(pcie->reg_base);
 
-	irq = irq_of_parse_and_map(node, 0);
+	irq = fwnode_irq_get(dev_fwnode(dev), 0);
+	if (irq < 0)
+		return irq;
+
 	err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
 			       IRQF_SHARED | IRQF_NO_THREAD,
 			       "xilinx-pcie", pcie);
@@ -585,10 +588,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 
 	err = xilinx_pcie_parse_dt(pcie);
-	if (err) {
-		dev_err(dev, "Parsing DT failed\n");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(dev, err, "Parsing DT failed\n");
 
 	xilinx_pcie_init_port(pcie);
 
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver requests a shared IRQ before it masks hardware interrupts and before it allocates its IRQ domains, creating a race condition that can lead to an interrupt storm. --

--- Patch [1]: [PATCHv2] PCI: xilinx: use fwnode_irq_get() for INTx IRQ lookup --- commit 02b4ee51408c6b762dcc417c028ea4f662761599
Author: Rosen Penev <[email protected]>

PCI: xilinx: use fwnode_irq_get() for INTx IRQ lookup

This commit replaces irq_of_parse_and_map() with fwnode_irq_get() for looking up the INTx IRQ, checking the return value to properly propagate errors such as -EPROBE_DEFER.

Quoted 5 lines
drivers/pci/controller/pcie-xilinx.c +0 -0
@@ -548,7 +548,10 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
 	if (IS_ERR(pcie->reg_base))

drivers/pci/controller/pcie-xilinx.c static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie) · line 557

Quoted 10 lines
drivers/pci/controller/pcie-xilinx.c +4 -1
 		return PTR_ERR(pcie->reg_base);
 
-	irq = irq_of_parse_and_map(node, 0);
+	irq = fwnode_irq_get(dev_fwnode(dev), 0);
+	if (irq < 0)
+		return irq;
+
 	err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
 			       IRQF_SHARED | IRQF_NO_THREAD,
 			       "xilinx-pcie", pcie);

[Severity: High]
This is a pre-existing issue, but does requesting the shared IRQ here create a race condition?

Looking at xilinx_pcie_probe(), xilinx_pcie_parse_dt() is called before xilinx_pcie_init_port() masks the hardware interrupts, and before xilinx_pcie_init_irq_domain() allocates the MSI and legacy IRQ domains.

If the shared IRQ fires before the domains are created, xilinx_pcie_intr_handler() will execute with pcie->msi_domain and pcie->leg_domain as NULL.

In that scenario, generic_handle_domain_irq() will return -EINVAL, leaving the level-triggered interrupt unserviced. Because the handler returns IRQ_HANDLED, could this immediately re-enter the handler and cause an unhandled interrupt storm?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Rosen Penev
Quoted 4 lines · Rosen Penev

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

What is the benefit of using fwnode API for OF only driver?

- Mani

Quoted 70 lines

Unlike irq_of_parse_and_map(), fwnode_irq_get() returns a positive IRQ or a negative errno and never 0 (it rewrites 0 to -EINVAL). Store the result in an int and check for irq < 0, returning the error (including -EPROBE_DEFER). This also adds the error handling the previous code lacked, where irq_of_parse_and_map() failures were passed straight into devm_request_irq().

Built for ARM (multi_v7_defconfig + CONFIG_PCIE_XILINX) with LLVM=1; drivers/pci/controller/pcie-xilinx.o compiles cleanly.

Assisted-by opencode:hy3-free

---
v2: use dev_err_probe to handle EPROBE_DEFER.

 drivers/pci/controller/pcie-xilinx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pci/controller/pcie-xilinx.c +8 -7
index 4aa139abac16..58532296182f 100644
@@ -20,10 +20,10 @@
 #include <linux/of_address.h>
 #include <linux/of_pci.h>
 #include <linux/of_platform.h>
-#include <linux/of_irq.h>
 #include <linux/pci.h>
 #include <linux/pci-ecam.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 
 #include "../pci.h"
 
@@ -535,7 +535,7 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
 	struct device *dev = pcie->dev;
 	struct device_node *node = dev->of_node;
 	struct resource regs;
-	unsigned int irq;
+	int irq;
 	int err;
 
 	err = of_address_to_resource(node, 0, &regs);
@@ -548,7 +548,10 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
 	if (IS_ERR(pcie->reg_base))
 		return PTR_ERR(pcie->reg_base);
 
-	irq = irq_of_parse_and_map(node, 0);
+	irq = fwnode_irq_get(dev_fwnode(dev), 0);
+	if (irq < 0)
+		return irq;
+
 	err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
 			       IRQF_SHARED | IRQF_NO_THREAD,
 			       "xilinx-pcie", pcie);
@@ -585,10 +588,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
 	pcie->dev = dev;
 
 	err = xilinx_pcie_parse_dt(pcie);
-	if (err) {
-		dev_err(dev, "Parsing DT failed\n");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(dev, err, "Parsing DT failed\n");
 
 	xilinx_pcie_init_port(pcie);
 
Signature · 1 line
2.55.0
Signature · 1 line
மணிவண்ணன் சதாசிவம்
#3 lore raw
Quoted 8 lines · Manivannan Sadhasivam
Quoted 4 lines · Rosen Penev

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

What is the benefit of using fwnode API for OF only driver?

I get conflicting information. Apparently of_irq_get needs a call to irq_dispose_mapping but fwnode_irq_get does not. irq_of_parse_and_map definitely does.

Quoted 76 lines

- Mani

Quoted 68 lines

Unlike irq_of_parse_and_map(), fwnode_irq_get() returns a positive IRQ or a negative errno and never 0 (it rewrites 0 to -EINVAL). Store the result in an int and check for irq < 0, returning the error (including -EPROBE_DEFER). This also adds the error handling the previous code lacked, where irq_of_parse_and_map() failures were passed straight into devm_request_irq().

Built for ARM (multi_v7_defconfig + CONFIG_PCIE_XILINX) with LLVM=1; drivers/pci/controller/pcie-xilinx.o compiles cleanly.

Assisted-by opencode:hy3-free

---
v2: use dev_err_probe to handle EPROBE_DEFER.

 drivers/pci/controller/pcie-xilinx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pci/controller/pcie-xilinx.c +8 -8
index 4aa139abac16..58532296182f 100644
@@ -20,10 +20,10 @@
 #include <linux/of_address.h>
 #include <linux/of_pci.h>
 #include <linux/of_platform.h>
-#include <linux/of_irq.h>
 #include <linux/pci.h>
 #include <linux/pci-ecam.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 
 #include "../pci.h"
 
@@ -535,7 +535,7 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
      struct device *dev = pcie->dev;
      struct device_node *node = dev->of_node;
      struct resource regs;
-     unsigned int irq;
+     int irq;
      int err;
 
      err = of_address_to_resource(node, 0, &regs);
@@ -548,7 +548,10 @@ static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
      if (IS_ERR(pcie->reg_base))
              return PTR_ERR(pcie->reg_base);
 
-     irq = irq_of_parse_and_map(node, 0);
+     irq = fwnode_irq_get(dev_fwnode(dev), 0);
+     if (irq < 0)
+             return irq;
+
      err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
                             IRQF_SHARED | IRQF_NO_THREAD,
                             "xilinx-pcie", pcie);
@@ -585,10 +588,8 @@ static int xilinx_pcie_probe(struct platform_device *pdev)
      pcie->dev = dev;
 
      err = xilinx_pcie_parse_dt(pcie);
-     if (err) {
-             dev_err(dev, "Parsing DT failed\n");
-             return err;
-     }
+     if (err)
+             return dev_err_probe(dev, err, "Parsing DT failed\n");
 
      xilinx_pcie_init_port(pcie);
 
--
Quoted 2 lines

2.55.0

--
மணிவண்ணன் சதாசிவம்

#4 lore raw
Quoted 11 lines · Rosen Penev
Quoted 8 lines · Manivannan Sadhasivam
Quoted 4 lines · Rosen Penev

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

What is the benefit of using fwnode API for OF only driver?

I get conflicting information. Apparently of_irq_get needs a call to irq_dispose_mapping but fwnode_irq_get does not.

That's not true. fwnode_irq_get() becomes a wrapper to of_irq_get() if OF is used. So both needs a call to irq_dispose_mapping() in the error path.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#5 lore raw
Quoted 10 lines · Manivannan Sadhasivam
Quoted 8 lines · Rosen Penev
Quoted 7 lines · Manivannan Sadhasivam
Quoted 4 lines · Rosen Penev

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

What is the benefit of using fwnode API for OF only driver?

I get conflicting information. Apparently of_irq_get needs a call to irq_dispose_mapping but fwnode_irq_get does not.

That's not true. fwnode_irq_get() becomes a wrapper to of_irq_get() if OF is used. So both needs a call to irq_dispose_mapping() in the error path.

I don't see irq_dispose_mapping() for fwnode_irq_get() in the codebase.

Quoted 5 lines

- Mani

--
மணிவண்ணன் சதாசிவம்

#6 lore raw
Quoted 11 lines · Rosen Penev
Quoted 10 lines · Manivannan Sadhasivam
Quoted 8 lines · Rosen Penev
Quoted 7 lines · Manivannan Sadhasivam
Quoted 4 lines · Rosen Penev

Replace irq_of_parse_and_map() with fwnode_irq_get(dev_fwnode(dev), 0) in xilinx_pcie_parse_dt(). For an OF-backed device this is equivalent to the previous call, but uses the generic firmware-node API.

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

What is the benefit of using fwnode API for OF only driver?

I get conflicting information. Apparently of_irq_get needs a call to irq_dispose_mapping but fwnode_irq_get does not.

That's not true. fwnode_irq_get() becomes a wrapper to of_irq_get() if OF is used. So both needs a call to irq_dispose_mapping() in the error path.

I don't see irq_dispose_mapping() for fwnode_irq_get() in the codebase.

That doesn't matter. You need to check with irqchip maintainers and see if those drivers need fix or not.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்