linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: apple: Initialize pcie->nvecs before using it
@ 2023-03-11 13:34 Sven Peter
  2023-03-11 14:10 ` Eric Curtin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sven Peter @ 2023-03-11 13:34 UTC (permalink / raw)
  To: Alyssa Rosenzweig, Marc Zyngier
  Cc: Sven Peter, Lorenzo Pieralisi, Krzysztof Wilczyński,
	Rob Herring, Bjorn Helgaas, linux-pci, asahi, linux-kernel

apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of
MSIs available for each port. It is however called before apple_msi_init
which actually initializes pcie->nvecs.
Luckily, pcie->nvecs is part of kzalloc-ed structure and thus
initialized as zero. ilog2(0) happens to be 0xffffffff which then just
configures more MSIs in hardware than we actually have. This doesn't
break anything because we never hand out those vectors.
Let's swap the order of the two calls so that we use the correctly
initialized value.

Fixes: 476c41ed4597 ("PCI: apple: Implement MSI support")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/pci/controller/pcie-apple.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
index 66f37e403a09..8b7b084cf287 100644
--- a/drivers/pci/controller/pcie-apple.c
+++ b/drivers/pci/controller/pcie-apple.c
@@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 	cfg->priv = pcie;
 	INIT_LIST_HEAD(&pcie->ports);
 
+	ret = apple_msi_init(pcie);
+	if (ret)
+		return ret;
+
 	for_each_child_of_node(dev->of_node, of_port) {
 		ret = apple_pcie_setup_port(pcie, of_port);
 		if (ret) {
@@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
 		}
 	}
 
-	return apple_msi_init(pcie);
+	return 0;
 }
 
 static int apple_pcie_probe(struct platform_device *pdev)
-- 
2.25.1


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

* Re: [PATCH] PCI: apple: Initialize pcie->nvecs before using it
  2023-03-11 13:34 [PATCH] PCI: apple: Initialize pcie->nvecs before using it Sven Peter
@ 2023-03-11 14:10 ` Eric Curtin
  2023-03-11 14:34 ` alyssa
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Curtin @ 2023-03-11 14:10 UTC (permalink / raw)
  To: Sven Peter
  Cc: Alyssa Rosenzweig, Marc Zyngier, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas, linux-pci,
	asahi, linux-kernel

On Sat, 11 Mar 2023 at 13:41, Sven Peter <sven@svenpeter.dev> wrote:
>
> apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of
> MSIs available for each port. It is however called before apple_msi_init
> which actually initializes pcie->nvecs.
> Luckily, pcie->nvecs is part of kzalloc-ed structure and thus
> initialized as zero. ilog2(0) happens to be 0xffffffff which then just
> configures more MSIs in hardware than we actually have. This doesn't
> break anything because we never hand out those vectors.
> Let's swap the order of the two calls so that we use the correctly
> initialized value.
>
> Fixes: 476c41ed4597 ("PCI: apple: Implement MSI support")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

Reviewed-by: Eric Curtin <ecurtin@redhat.com>

Is mise le meas/Regards,

Eric Curtin

> ---
>  drivers/pci/controller/pcie-apple.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> index 66f37e403a09..8b7b084cf287 100644
> --- a/drivers/pci/controller/pcie-apple.c
> +++ b/drivers/pci/controller/pcie-apple.c
> @@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
>         cfg->priv = pcie;
>         INIT_LIST_HEAD(&pcie->ports);
>
> +       ret = apple_msi_init(pcie);
> +       if (ret)
> +               return ret;
> +
>         for_each_child_of_node(dev->of_node, of_port) {
>                 ret = apple_pcie_setup_port(pcie, of_port);
>                 if (ret) {
> @@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
>                 }
>         }
>
> -       return apple_msi_init(pcie);
> +       return 0;
>  }
>
>  static int apple_pcie_probe(struct platform_device *pdev)
> --
> 2.25.1
>
>


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

* Re: [PATCH] PCI: apple: Initialize pcie->nvecs before using it
  2023-03-11 13:34 [PATCH] PCI: apple: Initialize pcie->nvecs before using it Sven Peter
  2023-03-11 14:10 ` Eric Curtin
@ 2023-03-11 14:34 ` alyssa
  2023-03-11 19:12 ` Marc Zyngier
  2023-06-24 17:04 ` Krzysztof Wilczyński
  3 siblings, 0 replies; 5+ messages in thread
From: alyssa @ 2023-03-11 14:34 UTC (permalink / raw)
  To: Sven Peter, Marc Zyngier
  Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
	Bjorn Helgaas, linux-pci, asahi, linux-kernel

Whoops!

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>

March 11, 2023 8:34 AM, "Sven Peter" <sven@svenpeter.dev> wrote:

> apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of
> MSIs available for each port. It is however called before apple_msi_init
> which actually initializes pcie->nvecs.
> Luckily, pcie->nvecs is part of kzalloc-ed structure and thus
> initialized as zero. ilog2(0) happens to be 0xffffffff which then just
> configures more MSIs in hardware than we actually have. This doesn't
> break anything because we never hand out those vectors.
> Let's swap the order of the two calls so that we use the correctly
> initialized value.
> 
> Fixes: 476c41ed4597 ("PCI: apple: Implement MSI support")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
> drivers/pci/controller/pcie-apple.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> index 66f37e403a09..8b7b084cf287 100644
> --- a/drivers/pci/controller/pcie-apple.c
> +++ b/drivers/pci/controller/pcie-apple.c
> @@ -783,6 +783,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
> cfg->priv = pcie;
> INIT_LIST_HEAD(&pcie->ports);
> 
> + ret = apple_msi_init(pcie);
> + if (ret)
> + return ret;
> +
> for_each_child_of_node(dev->of_node, of_port) {
> ret = apple_pcie_setup_port(pcie, of_port);
> if (ret) {
> @@ -792,7 +796,7 @@ static int apple_pcie_init(struct pci_config_window *cfg)
> }
> }
> 
> - return apple_msi_init(pcie);
> + return 0;
> }
> 
> static int apple_pcie_probe(struct platform_device *pdev)
> -- 
> 2.25.1

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

* Re: [PATCH] PCI: apple: Initialize pcie->nvecs before using it
  2023-03-11 13:34 [PATCH] PCI: apple: Initialize pcie->nvecs before using it Sven Peter
  2023-03-11 14:10 ` Eric Curtin
  2023-03-11 14:34 ` alyssa
@ 2023-03-11 19:12 ` Marc Zyngier
  2023-06-24 17:04 ` Krzysztof Wilczyński
  3 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2023-03-11 19:12 UTC (permalink / raw)
  To: Sven Peter
  Cc: Alyssa Rosenzweig, Lorenzo Pieralisi, Krzysztof Wilczyński,
	Rob Herring, Bjorn Helgaas, linux-pci, asahi, linux-kernel

On Sat, 11 Mar 2023 13:34:53 +0000,
Sven Peter <sven@svenpeter.dev> wrote:
> 
> apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of
> MSIs available for each port. It is however called before apple_msi_init
> which actually initializes pcie->nvecs.
> Luckily, pcie->nvecs is part of kzalloc-ed structure and thus
> initialized as zero. ilog2(0) happens to be 0xffffffff which then just
> configures more MSIs in hardware than we actually have. This doesn't
> break anything because we never hand out those vectors.
> Let's swap the order of the two calls so that we use the correctly
> initialized value.
> 
> Fixes: 476c41ed4597 ("PCI: apple: Implement MSI support")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>

Huh, how embarrassing... :-/

Reviewed-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

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

* Re: [PATCH] PCI: apple: Initialize pcie->nvecs before using it
  2023-03-11 13:34 [PATCH] PCI: apple: Initialize pcie->nvecs before using it Sven Peter
                   ` (2 preceding siblings ...)
  2023-03-11 19:12 ` Marc Zyngier
@ 2023-06-24 17:04 ` Krzysztof Wilczyński
  3 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Wilczyński @ 2023-06-24 17:04 UTC (permalink / raw)
  To: Sven Peter
  Cc: Alyssa Rosenzweig, Marc Zyngier, Lorenzo Pieralisi, Rob Herring,
	Bjorn Helgaas, linux-pci, asahi, linux-kernel

Hello,

> apple_pcie_setup_port computes ilog2(pcie->nvecs) to setup the number of
> MSIs available for each port. It is however called before apple_msi_init
> which actually initializes pcie->nvecs.
> Luckily, pcie->nvecs is part of kzalloc-ed structure and thus
> initialized as zero. ilog2(0) happens to be 0xffffffff which then just
> configures more MSIs in hardware than we actually have. This doesn't
> break anything because we never hand out those vectors.
> Let's swap the order of the two calls so that we use the correctly
> initialized value.

Applied to controller/apple, thank you!

[1/1] PCI: apple: Initialize pcie->nvecs before use
      https://git.kernel.org/pci/pci/c/328a16477027

	Krzysztof

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

end of thread, other threads:[~2023-06-24 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11 13:34 [PATCH] PCI: apple: Initialize pcie->nvecs before using it Sven Peter
2023-03-11 14:10 ` Eric Curtin
2023-03-11 14:34 ` alyssa
2023-03-11 19:12 ` Marc Zyngier
2023-06-24 17:04 ` Krzysztof Wilczyński

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