[PATCH v5 2/4] livepatch: Retry klp_synchronize_transition() if it fails

From: Binoy Ravindran via B4 Relay

Date: Sat Dec 05 2026 - 13:09:36 EST


From: Binoy Ravindran <binoy@xxxxxx>

schedule_on_each_cpu() returns -ENOMEM when it cannot allocate its work
items, before it queues any of them. klp_synchronize_transition() ignores
the error, so it can return without waiting. The transition relies on the
wait in several places, including the two that the following patches add
before func->transition is set and before the transition completes.

Retry until the wait succeeds. The callers can sleep, since
schedule_on_each_cpu() itself sleeps.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Binoy Ravindran <binoy@xxxxxx>
---
kernel/livepatch/transition.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c
index 2351a19ac2a9e..33095e888e10c 100644
--- a/kernel/livepatch/transition.c
+++ b/kernel/livepatch/transition.c
@@ -10,6 +10,7 @@
#include <linux/cpu.h>
#include <linux/stacktrace.h>
#include <linux/static_call.h>
+#include <linux/delay.h>
#include "core.h"
#include "patch.h"
#include "transition.h"
@@ -71,7 +72,13 @@ static void klp_sync(struct work_struct *work)
*/
static void klp_synchronize_transition(void)
{
- schedule_on_each_cpu(klp_sync);
+ /*
+ * schedule_on_each_cpu() fails only when it cannot allocate its work
+ * items, before it queues any of them. The callers rely on the wait,
+ * so retry until it succeeds.
+ */
+ while (schedule_on_each_cpu(klp_sync))
+ msleep(20);
}

/*

--
2.39.5