Skip to contentSkip to conversation

cpu: hotplug: preserve per instance callback errors

PATCH Applied Bradley Morgan 2 participants 4 messages Jun 19 – Jun 21

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

PATCH 1/2 cpu: hotplug: preserve per instance callback errors

cpuhp_invoke_callback() unwinds earlier callbacks for the same hotplug state when one instance fails. The rollback path currently reuses ret, so a successful rollback can hide the original error and make the failed transition look successful.

Keep the rollback result separate from the original error.

Fixes 724a86881d03 ("smp/hotplug: Callback vs state-machine consistency")
---
 kernel/cpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/cpu.c +4 -4
index f975bb34915b..0f32086f9ed4 100644
@@ -174,7 +174,7 @@ static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,
 	struct cpuhp_step *step = cpuhp_get_step(state);
 	int (*cbm)(unsigned int cpu, struct hlist_node *node);
 	int (*cb)(unsigned int cpu);
-	int ret, cnt;
+	int ret, cnt, rollback_ret;
 
 	if (st->fail == state) {
 		st->fail = CPUHP_INVALID;
@@ -238,12 +238,12 @@ static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,
 			break;
 
 		trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node);
-		ret = cbm(cpu, node);
-		trace_cpuhp_exit(cpu, st->state, state, ret);
+		rollback_ret = cbm(cpu, node);
+		trace_cpuhp_exit(cpu, st->state, state, rollback_ret);
 		/*
 		 * Rollback must not fail,
 		 */
-		WARN_ON_ONCE(ret);
+		WARN_ON_ONCE(rollback_ret);
 	}
 	return ret;
 }
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 cpu: hotplug: bound hotplug states sysfs output

states_show() adds CPU hotplug state names into a single sysfs buffer using sprintf(). With enough registered states, this can write past the end of the PAGE_SIZE buffer.

Use sysfs_emit_at() so output is bounded.

Fixes 98f8cdce1db5 ("cpu/hotplug: Add sysfs state interface")
---
 kernel/cpu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/cpu.c +3 -4
index 0f32086f9ed4..dec58e19329b 100644
@@ -2857,7 +2857,7 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
 static ssize_t states_show(struct device *dev,
 				 struct device_attribute *attr, char *buf)
 {
-	ssize_t cur, res = 0;
+	ssize_t res = 0;
 	int i;
 
 	mutex_lock(&cpuhp_state_mutex);
@@ -2865,9 +2865,8 @@ static ssize_t states_show(struct device *dev,
 		struct cpuhp_step *sp = cpuhp_get_step(i);
 
 		if (sp->name) {
-			cur = sprintf(buf, "%3d: %s\n", i, sp->name);
-			buf += cur;
-			res += cur;
+			res += sysfs_emit_at(buf, res, "%3d: %s\n",
+					     i, sp->name);
 		}
 	}
 	mutex_unlock(&cpuhp_state_mutex);
Signature · 1 line
2.53.0
merge bot Applied
#2 lore raw

[tip: smp/urgent] cpu: hotplug: Bound hotplug states sysfs output

The following commit has been merged into the smp/urgent branch of tip:

The following commit has been merged into the smp/urgent branch of tip:

Commit-ID:     86f436567f2516a0083b210bedc933544826a2c3
Gitweb:        https://git.kernel.org/tip/86f436567f2516a0083b210bedc933544826a2c3
Author:        Bradley Morgan <[email protected]>
AuthorDate:    Fri, 19 Jun 2026 16:37:18 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 21 Jun 2026 20:44:00 +02:00

cpu: hotplug: Bound hotplug states sysfs output

states_show() adds CPU hotplug state names into a single sysfs buffer using sprintf(). With enough registered states, this can write past the end of the PAGE_SIZE buffer.

Use sysfs_emit_at() so output is bounded.

Fixes 98f8cdce1db5 ("cpu/hotplug: Add sysfs state interface")
---
 kernel/cpu.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/cpu.c +4 -8
index 3ed24c7..77fdb20 100644
@@ -2865,21 +2865,17 @@ static const struct attribute_group cpuhp_cpu_attr_group = {
 	.name = "hotplug",
 };
 
-static ssize_t states_show(struct device *dev,
-				 struct device_attribute *attr, char *buf)
+static ssize_t states_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-	ssize_t cur, res = 0;
+	ssize_t res = 0;
 	int i;
 
 	mutex_lock(&cpuhp_state_mutex);
 	for (i = CPUHP_OFFLINE; i <= CPUHP_ONLINE; i++) {
 		struct cpuhp_step *sp = cpuhp_get_step(i);
 
-		if (sp->name) {
-			cur = sprintf(buf, "%3d: %s\n", i, sp->name);
-			buf += cur;
-			res += cur;
-		}
+		if (sp->name)
+			res += sysfs_emit_at(buf, res, "%3d: %s\n", i, sp->name);
 	}
 	mutex_unlock(&cpuhp_state_mutex);
 	return res;
merge bot Applied
#3 lore raw

[tip: smp/urgent] cpu: hotplug: Preserve per instance callback errors

In reply to Bradley Morgan
The following commit has been merged into the smp/urgent branch of tip:

The following commit has been merged into the smp/urgent branch of tip:

Commit-ID:     673db10729fb121ea1b16fe57791a0cb9eac1eb5
Gitweb:        https://git.kernel.org/tip/673db10729fb121ea1b16fe57791a0cb9eac1eb5
Author:        Bradley Morgan <[email protected]>
AuthorDate:    Fri, 19 Jun 2026 16:37:17 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 21 Jun 2026 20:44:00 +02:00

cpu: hotplug: Preserve per instance callback errors

cpuhp_invoke_callback() unwinds earlier callbacks for the same hotplug state when one instance fails. The rollback path currently reuses ret, so a successful rollback can hide the original error and make the failed transition look successful.

Keep the rollback result separate from the original error.

Fixes 724a86881d03 ("smp/hotplug: Callback vs state-machine consistency")
---
 kernel/cpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/cpu.c +4 -4
index 8df2d77..3ed24c7 100644
@@ -175,7 +175,7 @@ static int cpuhp_invoke_callback(unsigned int cpu, enum cpuhp_state state,
 	struct cpuhp_step *step = cpuhp_get_step(state);
 	int (*cbm)(unsigned int cpu, struct hlist_node *node);
 	int (*cb)(unsigned int cpu);
-	int ret, cnt;
+	int ret, cnt, rollback_ret;
 
 	if (st->fail == state) {
 		st->fail = CPUHP_INVALID;
@@ -239,12 +239,12 @@ err:
 			break;
 
 		trace_cpuhp_multi_enter(cpu, st->target, state, cbm, node);
-		ret = cbm(cpu, node);
-		trace_cpuhp_exit(cpu, st->state, state, ret);
+		rollback_ret = cbm(cpu, node);
+		trace_cpuhp_exit(cpu, st->state, state, rollback_ret);
 		/*
 		 * Rollback must not fail,
 		 */
-		WARN_ON_ONCE(ret);
+		WARN_ON_ONCE(rollback_ret);
 	}
 	return ret;
 }