linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] PCI: dwc: support remove
@ 2019-02-26 11:55 Jisheng Zhang
  2019-02-26 11:56 ` [PATCH 1/5] PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:55 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

Currently, the PCI dwc host users don't support the remove, but nothing
prevent us from supporting it. To achieve this goal, we need to ensure
we can do necessary clean up work.

Jisheng Zhang (5):
  PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid
  PCI: dwc: free the page for MSI irq in dw_pcie_free_msi()
  PCI: dwc: free msi in the error code path of dw_pcie_host_init()
  PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code
  PCI: dwc: save root bus for driver remove

 .../pci/controller/dwc/pcie-designware-host.c | 38 ++++++++++---------
 drivers/pci/controller/dwc/pcie-designware.h  |  2 +
 2 files changed, 23 insertions(+), 17 deletions(-)

-- 
2.20.1


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

* [PATCH 1/5] PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
@ 2019-02-26 11:56 ` Jisheng Zhang
  2019-02-26 11:56 ` [PATCH 2/5] PCI: dwc: free the page for MSI irq in dw_pcie_free_msi() Jisheng Zhang
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:56 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

we should check msi_irq before calling irq_set_chained_handler() and
irq_set_handler_data().

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 0c18ab63811f..a94d3530b694 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -298,8 +298,10 @@ int dw_pcie_allocate_domains(struct pcie_port *pp)
 
 void dw_pcie_free_msi(struct pcie_port *pp)
 {
-	irq_set_chained_handler(pp->msi_irq, NULL);
-	irq_set_handler_data(pp->msi_irq, NULL);
+	if (pp->msi_irq) {
+		irq_set_chained_handler(pp->msi_irq, NULL);
+		irq_set_handler_data(pp->msi_irq, NULL);
+	}
 
 	irq_domain_remove(pp->msi_domain);
 	irq_domain_remove(pp->irq_domain);
-- 
2.20.1


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

* [PATCH 2/5] PCI: dwc: free the page for MSI irq in dw_pcie_free_msi()
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
  2019-02-26 11:56 ` [PATCH 1/5] PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
@ 2019-02-26 11:56 ` Jisheng Zhang
  2019-02-26 11:57 ` [PATCH 3/5] PCI: dwc: free msi in the error code path of dw_pcie_host_init() Jisheng Zhang
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:56 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

To avoid memory leak, we need to free the page for MSI in
dw_pcie_free_msi().

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 3 +++
 drivers/pci/controller/dwc/pcie-designware.h      | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index a94d3530b694..abe3ff5f0867 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -305,6 +305,8 @@ void dw_pcie_free_msi(struct pcie_port *pp)
 
 	irq_domain_remove(pp->msi_domain);
 	irq_domain_remove(pp->irq_domain);
+
+	__free_page(pp->msi_page);
 }
 
 void dw_pcie_msi_init(struct pcie_port *pp)
@@ -322,6 +324,7 @@ void dw_pcie_msi_init(struct pcie_port *pp)
 		return;
 	}
 	msi_target = (u64)pp->msi_data;
+	pp->msi_page = page;
 
 	/* Program the msi_data */
 	dw_pcie_wr_own_conf(pp, PCIE_MSI_ADDR_LO, 4,
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index f6fb65a40f10..3be7ca9f1fc3 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -179,6 +179,7 @@ struct pcie_port {
 	struct irq_domain	*irq_domain;
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
+	struct page		*msi_page;
 	u32			num_vectors;
 	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
-- 
2.20.1


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

* [PATCH 3/5] PCI: dwc: free msi in the error code path of dw_pcie_host_init()
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
  2019-02-26 11:56 ` [PATCH 1/5] PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
  2019-02-26 11:56 ` [PATCH 2/5] PCI: dwc: free the page for MSI irq in dw_pcie_free_msi() Jisheng Zhang
@ 2019-02-26 11:57 ` Jisheng Zhang
  2019-02-26 11:58 ` [PATCH 4/5] PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:57 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

If we ever did some msi related initializations, we need to call
dw_pcie_free_msi() in the error code path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index abe3ff5f0867..66569d0f3ab9 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -482,7 +482,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (pp->ops->host_init) {
 		ret = pp->ops->host_init(pp);
 		if (ret)
-			goto error;
+			goto err_free_msi;
 	}
 
 	pp->root_bus_nr = pp->busn->start;
@@ -496,7 +496,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 
 	ret = pci_scan_root_bus_bridge(bridge);
 	if (ret)
-		goto error;
+		goto err_free_msi;
 
 	bus = bridge->bus;
 
@@ -512,6 +512,9 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	pci_bus_add_devices(bus);
 	return 0;
 
+err_free_msi:
+	if (IS_ENABLED(CONFIG_PCI_MSI) && !pp->ops->msi_host_init)
+		dw_pcie_free_msi(pp);
 error:
 	pci_free_host_bridge(bridge);
 	return ret;
-- 
2.20.1


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

* [PATCH 4/5] PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
                   ` (2 preceding siblings ...)
  2019-02-26 11:57 ` [PATCH 3/5] PCI: dwc: free msi in the error code path of dw_pcie_host_init() Jisheng Zhang
@ 2019-02-26 11:58 ` Jisheng Zhang
  2019-02-26 11:59 ` [PATCH 5/5] PCI: dwc: save root bus for driver remove Jisheng Zhang
  2019-02-26 21:11 ` [PATCH 0/5] PCI: dwc: support remove Bjorn Helgaas
  5 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:58 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

Use devm_pci_alloc_host_bridge() to simplify the error code path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 .../pci/controller/dwc/pcie-designware-host.c | 21 +++++++------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 66569d0f3ab9..4831c12fee93 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -357,7 +357,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		dev_err(dev, "Missing *config* reg space\n");
 	}
 
-	bridge = pci_alloc_host_bridge(0);
+	bridge = devm_pci_alloc_host_bridge(dev, 0);
 	if (!bridge)
 		return -ENOMEM;
 
@@ -368,7 +368,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 
 	ret = devm_request_pci_bus_resources(dev, &bridge->windows);
 	if (ret)
-		goto error;
+		return ret;
 
 	/* Get the I/O and memory ranges from DT */
 	resource_list_for_each_entry_safe(win, tmp, &bridge->windows) {
@@ -412,8 +412,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 						resource_size(pp->cfg));
 		if (!pci->dbi_base) {
 			dev_err(dev, "Error with ioremap\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -424,8 +423,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 					pp->cfg0_base, pp->cfg0_size);
 		if (!pp->va_cfg0_base) {
 			dev_err(dev, "Error with ioremap in function\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -435,8 +433,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 						pp->cfg1_size);
 		if (!pp->va_cfg1_base) {
 			dev_err(dev, "Error with ioremap\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -459,14 +456,14 @@ int dw_pcie_host_init(struct pcie_port *pp)
 			    pp->num_vectors == 0) {
 				dev_err(dev,
 					"Invalid number of vectors\n");
-				goto error;
+				return -EINVAL;
 			}
 		}
 
 		if (!pp->ops->msi_host_init) {
 			ret = dw_pcie_allocate_domains(pp);
 			if (ret)
-				goto error;
+				return ret;
 
 			if (pp->msi_irq)
 				irq_set_chained_handler_and_data(pp->msi_irq,
@@ -475,7 +472,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		} else {
 			ret = pp->ops->msi_host_init(pp);
 			if (ret < 0)
-				goto error;
+				return ret;
 		}
 	}
 
@@ -515,8 +512,6 @@ int dw_pcie_host_init(struct pcie_port *pp)
 err_free_msi:
 	if (IS_ENABLED(CONFIG_PCI_MSI) && !pp->ops->msi_host_init)
 		dw_pcie_free_msi(pp);
-error:
-	pci_free_host_bridge(bridge);
 	return ret;
 }
 
-- 
2.20.1


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

* [PATCH 5/5] PCI: dwc: save root bus for driver remove
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
                   ` (3 preceding siblings ...)
  2019-02-26 11:58 ` [PATCH 4/5] PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
@ 2019-02-26 11:59 ` Jisheng Zhang
  2019-02-26 21:11 ` [PATCH 0/5] PCI: dwc: support remove Bjorn Helgaas
  5 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-26 11:59 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

Currently dwc host doesn't support the remove, but nothing prevent us
from supporting it. Save the root bus for clean up work in driver
remove code path.

After this patch, the dwc host users could implement its remove as:

static int foo_pcie_remove(struct platform_device *pdev)
{
	...
	pci_stop_root_bus(pp->root_bus);
	pci_remove_root_bus(pp->root_bus);
	dw_pcie_free_msi(pp);
	...
}

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 1 +
 drivers/pci/controller/dwc/pcie-designware.h      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 4831c12fee93..ca45a4471ca0 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -496,6 +496,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		goto err_free_msi;
 
 	bus = bridge->bus;
+	pp->root_bus = bus;
 
 	if (pp->ops->scan_bus)
 		pp->ops->scan_bus(pp);
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 3be7ca9f1fc3..cd92ded606c6 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -182,6 +182,7 @@ struct pcie_port {
 	struct page		*msi_page;
 	u32			num_vectors;
 	u32			irq_mask[MAX_MSI_CTRLS];
+	struct pci_bus		*root_bus;
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
-- 
2.20.1


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

* Re: [PATCH 0/5] PCI: dwc: support remove
  2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
                   ` (4 preceding siblings ...)
  2019-02-26 11:59 ` [PATCH 5/5] PCI: dwc: save root bus for driver remove Jisheng Zhang
@ 2019-02-26 21:11 ` Bjorn Helgaas
  2019-02-27  6:48   ` Jisheng Zhang
  5 siblings, 1 reply; 8+ messages in thread
From: Bjorn Helgaas @ 2019-02-26 21:11 UTC (permalink / raw)
  To: Jisheng Zhang
  Cc: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, linux-pci,
	linux-kernel, linux-arm-kernel

On Tue, Feb 26, 2019 at 5:55 AM Jisheng Zhang
<Jisheng.Zhang@synaptics.com> wrote:
>
> Currently, the PCI dwc host users don't support the remove, but nothing
> prevent us from supporting it. To achieve this goal, we need to ensure
> we can do necessary clean up work.
>
> Jisheng Zhang (5):
>   PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid
>   PCI: dwc: free the page for MSI irq in dw_pcie_free_msi()
>   PCI: dwc: free msi in the error code path of dw_pcie_host_init()
>   PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code
>   PCI: dwc: save root bus for driver remove

If you post a v2 of this series, please:

Capitalize the first word of each subject, e.g., "PCI: dwc: Fix
dw_pcie_free_msi() if msi_irq is invalid"
s/irq/IRQ/
s/msi/MSI/

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

* Re: [PATCH 0/5] PCI: dwc: support remove
  2019-02-26 21:11 ` [PATCH 0/5] PCI: dwc: support remove Bjorn Helgaas
@ 2019-02-27  6:48   ` Jisheng Zhang
  0 siblings, 0 replies; 8+ messages in thread
From: Jisheng Zhang @ 2019-02-27  6:48 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, linux-pci,
	linux-kernel, linux-arm-kernel

On Tue, 26 Feb 2019 15:11:03 -0600 Bjorn Helgaas wrote:

> 
> 
> On Tue, Feb 26, 2019 at 5:55 AM Jisheng Zhang
> <Jisheng.Zhang@synaptics.com> wrote:
> >
> > Currently, the PCI dwc host users don't support the remove, but nothing
> > prevent us from supporting it. To achieve this goal, we need to ensure
> > we can do necessary clean up work.
> >
> > Jisheng Zhang (5):
> >   PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid
> >   PCI: dwc: free the page for MSI irq in dw_pcie_free_msi()
> >   PCI: dwc: free msi in the error code path of dw_pcie_host_init()
> >   PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code
> >   PCI: dwc: save root bus for driver remove  
> 
> If you post a v2 of this series, please:
> 
> Capitalize the first word of each subject, e.g., "PCI: dwc: Fix
> dw_pcie_free_msi() if msi_irq is invalid"
> s/irq/IRQ/
> s/msi/MSI/

Thanks for the review. Will do when post a v2. I'm still trying to
collect more code review comments.

Thanks

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

end of thread, other threads:[~2019-02-27  6:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-26 11:55 [PATCH 0/5] PCI: dwc: support remove Jisheng Zhang
2019-02-26 11:56 ` [PATCH 1/5] PCI: dwc: fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
2019-02-26 11:56 ` [PATCH 2/5] PCI: dwc: free the page for MSI irq in dw_pcie_free_msi() Jisheng Zhang
2019-02-26 11:57 ` [PATCH 3/5] PCI: dwc: free msi in the error code path of dw_pcie_host_init() Jisheng Zhang
2019-02-26 11:58 ` [PATCH 4/5] PCI: dwc: use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
2019-02-26 11:59 ` [PATCH 5/5] PCI: dwc: save root bus for driver remove Jisheng Zhang
2019-02-26 21:11 ` [PATCH 0/5] PCI: dwc: support remove Bjorn Helgaas
2019-02-27  6:48   ` Jisheng Zhang

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