All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] cpu: hotplug: preserve per instance callback errors
@ 2026-06-19 16:37 Bradley Morgan
  2026-06-19 16:37 ` [PATCH 2/2] cpu: hotplug: bound hotplug states sysfs output Bradley Morgan
  0 siblings, 1 reply; 2+ messages in thread
From: Bradley Morgan @ 2026-06-19 16:37 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra; +Cc: linux-kernel, Bradley Morgan, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 kernel/cpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index f975bb34915b..0f32086f9ed4 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -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;
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] cpu: hotplug: bound hotplug states sysfs output
  2026-06-19 16:37 [PATCH 1/2] cpu: hotplug: preserve per instance callback errors Bradley Morgan
@ 2026-06-19 16:37 ` Bradley Morgan
  0 siblings, 0 replies; 2+ messages in thread
From: Bradley Morgan @ 2026-06-19 16:37 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra; +Cc: linux-kernel, Bradley Morgan, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Bradley Morgan <include@grrlz.net>
---
 kernel/cpu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 0f32086f9ed4..dec58e19329b 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -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);
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-19 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-19 16:37 [PATCH 1/2] cpu: hotplug: preserve per instance callback errors Bradley Morgan
2026-06-19 16:37 ` [PATCH 2/2] cpu: hotplug: bound hotplug states sysfs output Bradley Morgan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.