Skip to contentSkip to conversation

irqchip/mmp: A pair of robustness fixed

PATCH In review Lubomir Rintel 3 participants 8 messages Feb 19, 2020 – Mar 9, 2020 irqchip drivers

lore
Share & tools
lore
#0 lore raw

cover irqchip/mmp: A pair of robustness fixed

Hi,

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Thanks,
Lubo

#1 lore raw

PATCH 1/2 irqchip/mmp: Safeguard against multiple root intc initialization

We can only handle one root ICU. Let's warn if someone messes up and adds multiple in the devicetree.

---
 drivers/irqchip/irq-mmp.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/irqchip/irq-mmp.c +15 -0
index 4a74ac7b7c42e..f597d96409a1f 100644
@@ -250,6 +250,11 @@ void __init icu_init_irq(void)
 	int irq;
 
 	max_icu_nr = 1;
+	if (mmp_icu_base) {
+		pr_err("ICU already initialized\n");
+		return;
+	}
+
 	mmp_icu_base = ioremap(0xd4282000, 0x1000);
 	icu_data[0].conf_enable = mmp_conf.conf_enable;
 	icu_data[0].conf_disable = mmp_conf.conf_disable;
@@ -273,6 +278,11 @@ void __init mmp2_init_icu(void)
 	int irq, end;
 
 	max_icu_nr = 8;
+	if (mmp_icu_base) {
+		pr_err("ICU already initialized\n");
+		return;
+	}
+
 	mmp_icu_base = ioremap(0xd4282000, 0x1000);
 	icu_data[0].conf_enable = mmp2_conf.conf_enable;
 	icu_data[0].conf_disable = mmp2_conf.conf_disable;
@@ -380,6 +390,11 @@ static int __init mmp_init_bases(struct device_node *node)
 		return ret;
 	}
 
+	if (mmp_icu_base) {
+		pr_err("ICU already initialized\n");
+		return -EEXIST;
+	}
+
 	mmp_icu_base = of_iomap(node, 0);
 	if (!mmp_icu_base) {
 		pr_err("Failed to get interrupt controller register\n");
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/2 irqchip/mmp: Avoid overflowing icu_data[]

In reply to Lubomir Rintel

In case someone messes up and adds too many interrupt muxes in the device tree, icu_data would overflow into things that follow it in bss, likely mmp_icu2_base and mmp_icu_base.

Let's add a safeguard, so that we fail gracefully instead of panicking at some later point for reasons that are then not immediately clear.

---
 drivers/irqchip/irq-mmp.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/irqchip/irq-mmp.c +5 -0
index f597d96409a1f..c7ef2cea1c020 100644
@@ -505,6 +505,11 @@ static int __init mmp2_mux_of_init(struct device_node *node,
 		return -ENODEV;
 
 	i = max_icu_nr;
+	if (i >= MAX_ICU_NR) {
+		pr_err("Too many interrupt muxes\n");
+		return -EINVAL;
+	}
+
 	ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
 				   &nr_irqs);
 	if (ret) {
Signature · 1 line
2.24.1
#3 lore raw
In reply to Lubomir Rintel

On Wed, 19 Feb 2020 09:00:22 +0100
Lubomir Rintel <[email protected]> wrote:

[+RobH]

Lubomir,

Quoted 4 lines

Hi,

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Can't we instead make sure our DT infrastructure checks for these? I'm very reluctant to add more "DT validation" to the kernel, as it feels like the wrong place to do this.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#4 lore raw
Quoted 7 lines · Marc Zyngier

On Wed, 19 Feb 2020 09:00:22 +0100
Lubomir Rintel <[email protected]> wrote:

[+RobH]

Lubomir,

Quoted 8 lines
Quoted 4 lines

Hi,

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Can't we instead make sure our DT infrastructure checks for these? I'm very reluctant to add more "DT validation" to the kernel, as it feels like the wrong place to do this.

These are not really problems of the DT infrastructure. It's that the driver has some constrains resulting from use of global data ([PATCH 1]) and statically sized arrays ([PATCH 2]) without enforcing them.

It's probably easier to mess up DT than to mess up board files, but regardless of that, being a little defensive and checking the bounds of arrays is probably a good programming practice anyways.

Thank you
Lubo

#5 lore raw
Quoted 11 lines · Lubomir Rintel
Quoted 9 lines · Marc Zyngier

On Wed, 19 Feb 2020 09:00:22 +0100
Lubomir Rintel <[email protected]> wrote:

[+RobH]

Lubomir,

Quoted 2 lines

Hi,

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Can't we instead make sure our DT infrastructure checks for these? I'm very reluctant to add more "DT validation" to the kernel, as it feels like the wrong place to do this.

These are not really problems of the DT infrastructure.

They are. The DT bindings describes the constraints (or at least should), and the DT infrastructure could, at least in theory, check them at compile time. Adding the checks to the kernel defeats the single benefit of DT, which is independence from the kernel.

Quoted 5 lines

It's that the driver has some constrains resulting from use of global data ([PATCH 1]) and statically sized arrays ([PATCH 2]) without enforcing them.

It's probably easier to mess up DT than to mess up board files,

No, both models can be just as easily broken if people write them without thinking twice.

Quoted 2 lines

but regardless of that, being a little defensive and checking the bounds of arrays is probably a good programming practice anyways.

Is there even any example of such broken DT in the tree?

	M.
Signature · 1 line
Jazz is not dead, it just smells funny.
#6 lore raw
Quoted 33 lines · Marc Zyngier
Quoted 11 lines · Lubomir Rintel
Quoted 9 lines · Marc Zyngier

On Wed, 19 Feb 2020 09:00:22 +0100
Lubomir Rintel <[email protected]> wrote:

[+RobH]

Lubomir,

Quoted 2 lines

Hi,

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Can't we instead make sure our DT infrastructure checks for these? I'm very reluctant to add more "DT validation" to the kernel, as it feels like the wrong place to do this.

These are not really problems of the DT infrastructure.

They are. The DT bindings describes the constraints (or at least should), and the DT infrastructure could, at least in theory, check them at compile time. Adding the checks to the kernel defeats the single benefit of DT, which is independence from the kernel.

Quoted 5 lines

It's that the driver has some constrains resulting from use of global data ([PATCH 1]) and statically sized arrays ([PATCH 2]) without enforcing them.

It's probably easier to mess up DT than to mess up board files,

Quoted 7 lines

No, both models can be just as easily broken if people write them without thinking twice.

Quoted 2 lines

but regardless of that, being a little defensive and checking the bounds of arrays is probably a good programming practice anyways.

Is there even any example of such broken DT in the tree?

No, this didn't occur with a FDT build from the kernel tree.

The device tree from Open Firmware that is used on the OLPC XO-4 machine is broken in this way (but it also needs many more fixes in order to be able to run mainline kernels).

Lubo

Quoted 5 lines
	M.
Signature · 1 line
Jazz is not dead, it just smells funny.
#7 lore raw
In reply to Marc Zyngier
Quoted 8 lines · Marc Zyngier

On Wed, 19 Feb 2020 09:00:22 +0100
Lubomir Rintel <[email protected]> wrote:

[+RobH]

Lubomir,

Quoted 8 lines
Quoted 4 lines

Hi,

please consider applying these two patches. Thery are not strictly necessary, but improve diagnostics in case the DT is faulty.

Can't we instead make sure our DT infrastructure checks for these? I'm very reluctant to add more "DT validation" to the kernel, as it feels like the wrong place to do this.

We don't really have a way to say a binding can only occur once or N times in a DT. We'd have to have an SoC schema that listed out all the nodes in the DT and forbid any additional nodes. I don't think that's too useful as if there's only 1 instance for a given schema, then the schema is not too useful as the schema has a equal chance of being wrong.

Is there something inherent about the h/w that prevents more than one instance? If support of more than one instance is a kernel limitation (because no current SoC needs more than 1), then shouldn't the kernel protect against this?

Rob