Skip to contentSkip to conversation

cgroup/cpuset: Free sched domains on rebuild guard failure

PATCH Applied Guopeng Zhang 4 participants 4 messages May 28 – Jun 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup/cpuset: Free sched domains on rebuild guard failure

From: Guopeng Zhang <[email protected]>

generate_sched_domains() returns sched-domain masks and optional attributes that are normally handed to partition_sched_domains(), which takes ownership of them.

rebuild_sched_domains_locked() has a WARN guard after generate_sched_domains() and before partition_sched_domains() to avoid passing offline CPUs into the scheduler domain rebuild path. If that guard fires, the function currently returns directly without freeing the generated doms and attr.

Free the generated sched-domain masks and attributes before returning from the guard failure path.

---
 kernel/cgroup/cpuset.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +4 -1
index 51327333980a..c5fdebc205d8 100644
@@ -1004,8 +1004,11 @@ void rebuild_sched_domains_locked(void)
 	* prevent the panic.
 	*/
 	for (i = 0; doms && i < ndoms; i++) {
-		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
+		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask))) {
+			free_sched_domains(doms, ndoms);
+			kfree(attr);
 			return;
+		}
 	}
 
 	/* Have scheduler rebuild the domains */
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Guopeng Zhang

From: Guopeng Zhang <[email protected]>

generate_sched_domains() returns sched-domain masks and optional attributes that are normally handed to partition_sched_domains(), which takes ownership of them.

rebuild_sched_domains_locked() has a WARN guard after generate_sched_domains() and before partition_sched_domains() to avoid passing offline CPUs into the scheduler domain rebuild path. If that guard fires, the function currently returns directly without freeing the generated doms and attr.

Free the generated sched-domain masks and attributes before returning from the guard failure path.

---
  kernel/cgroup/cpuset.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +0 -0
index 51327333980a..c5fdebc205d8 100644
@@ -1004,8 +1004,11 @@ void rebuild_sched_domains_locked(void)
  	* prevent the panic.
  	*/

kernel/cgroup/cpuset.c void rebuild_sched_domains_locked(void) · line 1014

Quoted 10 lines
kernel/cgroup/cpuset.c +4 -1
  	for (i = 0; doms && i < ndoms; i++) {
-		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
+		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask))) {
+			free_sched_domains(doms, ndoms);
+			kfree(attr);
  			return;
+		}
  	}
 
  	/* Have scheduler rebuild the domains */

This WARN_ON_ONCE() is mainly used to catch bug during code update. It shouldn't be triggered in normal use. Anyway, it is a nice-to-have fix.

reviewer
#3 lore raw
In reply to Guopeng Zhang
Quoted 27 lines · Guopeng Zhang

From: Guopeng Zhang <[email protected]>

generate_sched_domains() returns sched-domain masks and optional attributes that are normally handed to partition_sched_domains(), which takes ownership of them.

rebuild_sched_domains_locked() has a WARN guard after generate_sched_domains() and before partition_sched_domains() to avoid passing offline CPUs into the scheduler domain rebuild path. If that guard fires, the function currently returns directly without freeing the generated doms and attr.

Free the generated sched-domain masks and attributes before returning from the guard failure path.

---
 kernel/cgroup/cpuset.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +0 -0
index 51327333980a..c5fdebc205d8 100644
@@ -1004,8 +1004,11 @@ void rebuild_sched_domains_locked(void)
 	* prevent the panic.
 	*/

kernel/cgroup/cpuset.c void rebuild_sched_domains_locked(void) · line 1014

Quoted 10 lines
kernel/cgroup/cpuset.c +4 -1
 	for (i = 0; doms && i < ndoms; i++) {
-		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
+		if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask))) {
+			free_sched_domains(doms, ndoms);
+			kfree(attr);
 			return;
+		}
 	}
 
 	/* Have scheduler rebuild the domains */

Thank you. This helps prevent a memory leak in this abnormal scenario. I should have included it when I originally added this check.

Signature · 2 lines
Best regards,
Ridong