Skip to contentSkip to conversation

irqchip/gic-v3-its: Fix OF node reference leak

PATCH Superseded Yuho Choi 3 participants 4 messages Jun 19 – Jun 26

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 irqchip/gic-v3-its: Fix OF node reference leak

of_get_cpu_node() returns a referenced device node. In its_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.

Store the NUMA node locally and call of_node_put() before either continuing with collection setup or returning early for a NUMA mismatch.

Fixes 920181ce8469 ("irqchip/gic-v3-its: Add ability to resend MAPC on resume")
---
 drivers/irqchip/irq-gic-v3-its.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
index b57d81ad33a0..f82035eb77e5 100644
@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)
 	/* avoid cross node collections and its mapping */
 	if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
 		struct device_node *cpu_node;
+		int cpu_nid;
 
 		cpu_node = of_get_cpu_node(cpu, NULL);
+		cpu_nid = of_node_to_nid(cpu_node);
+		of_node_put(cpu_node);
+
 		if (its->numa_node != NUMA_NO_NODE &&
-			its->numa_node != of_node_to_nid(cpu_node))
+		    its->numa_node != cpu_nid)
 			return;
 	}
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 25 lines · Yuho Choi

of_get_cpu_node() returns a referenced device node. In its_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.

Store the NUMA node locally and call of_node_put() before either continuing with collection setup or returning early for a NUMA mismatch.

Fixes 920181ce8469 ("irqchip/gic-v3-its: Add ability to resend MAPC on resume")
---
 drivers/irqchip/irq-gic-v3-its.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -0
index b57d81ad33a0..f82035eb77e5 100644
@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)
 	/* avoid cross node collections and its mapping */
 	if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
 		struct device_node *cpu_node;
+		int cpu_nid;
 

drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3304

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +4 -1
 		cpu_node = of_get_cpu_node(cpu, NULL);
+		cpu_nid = of_node_to_nid(cpu_node);
+		of_node_put(cpu_node);
+
 		if (its->numa_node != NUMA_NO_NODE &&
-			its->numa_node != of_node_to_nid(cpu_node))
+		    its->numa_node != cpu_nid)
 			return;
 	}
 

Please consider using the cleanup infrastructure instead, something like the untested hack below.

Thanks,

	M.
drivers/irqchip/irq-gic-v3-its.c +2 -3
index 291d7668cc8da..947a15bb42012 100644
@@ -3290,11 +3290,10 @@ static void its_cpu_init_collection(struct its_node *its)
 
 	/* avoid cross node collections and its mapping */
 	if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
-		struct device_node *cpu_node;
+		struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL);
 
-		cpu_node = of_get_cpu_node(cpu, NULL);
 		if (its->numa_node != NUMA_NO_NODE &&
-			its->numa_node != of_node_to_nid(cpu_node))
+		    its->numa_node != of_node_to_nid(cpu_node))
 			return;
 	}
 
Signature · 1 line
Jazz isn't dead. It just smells funny.
Reviewed-by
#2 lore raw
Quoted 8 lines · Marc Zyngier
Quoted 6 lines · Yuho Choi

of_get_cpu_node() returns a referenced device node. In its_cpu_init_collection(), the node is only used to get the CPU NUMA node for the Cavium 23144 workaround, but the reference is never dropped.

Quoted 4 lines
Quoted 4 lines

Store the NUMA node locally and call of_node_put() before either continuing with collection setup or returning early for a NUMA mismatch.

Fixes 920181ce8469 ("irqchip/gic-v3-its: Add ability to resend MAPC on resume")

It looks to me that this issue was introduced in fbf8f40e1658 ("irqchip/gicv3-its: numa: Enable workaround for Cavium thunderx erratum 23144"). What am I missing?

Quoted 37 lines
Quoted 15 lines
---
 drivers/irqchip/irq-gic-v3-its.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +1 -0
index b57d81ad33a0..f82035eb77e5 100644
@@ -3291,10 +3291,14 @@ static void its_cpu_init_collection(struct its_node *its)
 	/* avoid cross node collections and its mapping */
 	if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
 		struct device_node *cpu_node;
+		int cpu_nid;
 

drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3304

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +4 -1
 		cpu_node = of_get_cpu_node(cpu, NULL);
+		cpu_nid = of_node_to_nid(cpu_node);
+		of_node_put(cpu_node);
+
 		if (its->numa_node != NUMA_NO_NODE &&
-			its->numa_node != of_node_to_nid(cpu_node))
+		    its->numa_node != cpu_nid)
 			return;
 	}
 

Please consider using the cleanup infrastructure instead, something like the untested hack below.

drivers/irqchip/irq-gic-v3-its.c +0 -0
index 291d7668cc8da..947a15bb42012 100644
@@ -3290,11 +3290,10 @@ static void its_cpu_init_collection(struct its_node *its)
 
 	/* avoid cross node collections and its mapping */
 	if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {

drivers/irqchip/irq-gic-v3-its.c static void its_cpu_init_collection(struct its_node *its) · line 3299

Quoted 10 lines
drivers/irqchip/irq-gic-v3-its.c +2 -3
-		struct device_node *cpu_node;
+		struct device_node *cpu_node __free(device_node) = of_get_cpu_node(cpu, NULL);
 
-		cpu_node = of_get_cpu_node(cpu, NULL);
 		if (its->numa_node != NUMA_NO_NODE &&
-			its->numa_node != of_node_to_nid(cpu_node))
+		    its->numa_node != of_node_to_nid(cpu_node))
 			return;
 	}
 

Thanks,
Zenghui

author
#3 lore raw

Thanks for the review!

Quoted 4 lines

It looks to me that this issue was introduced in fbf8f40e1658 ("irqchip/gicv3-its: numa: Enable workaround for Cavium thunderx erratum 23144"). What am I missing?

You are right; I used the wrong Fixes tag. I will update the fix commit in v2.

Quoted 2 lines
Quoted 2 lines

Please consider using the cleanup infrastructure instead, something like the untested hack below.

Sure, I'll update this in v2 and resend it.

Thanks,
Yuho