Skip to contentSkip to conversation

PCI: apple: Initialize pcie->nvecs before using it

PATCH Applied Sven Peter 5 participants 5 messages Mar 11, 2023 – Jun 24, 2023

Subsystems (3)
lore
Share & tools
lore

Sven Peter

author
#0 lore raw

PATCH 1/1 PCI: apple: Initialize pcie->nvecs before using it

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")
---
 drivers/pci/controller/pcie-apple.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +5 -1
index 66f37e403a09..8b7b084cf287 100644
@@ -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)
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Sven Peter

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.

Quoted 2 lines
Fixes 476c41ed4597 ("PCI: apple: Implement MSI support")

Is mise le meas/Regards,

Eric Curtin

Quoted 32 lines
---
 drivers/pci/controller/pcie-apple.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +5 -2
index 66f37e403a09..8b7b084cf287 100644
@@ -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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Sven Peter

Whoops!

Quoted 42 lines · Sven Peter

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

---
drivers/pci/controller/pcie-apple.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/pcie-apple.c +5 -1
index 66f37e403a09..8b7b084cf287 100644
@@ -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)
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Sven Peter
Quoted 11 lines · Sven Peter

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.

Quoted 2 lines
Fixes 476c41ed4597 ("PCI: apple: Implement MSI support")

Huh, how embarrassing... :-/

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw
In reply to Sven Peter

Hello,

Quoted 9 lines

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