Skip to content

Commit a38a647

Browse files
author
Peter Zijlstra
committed
unwind: Fix unwind_deferred_request() vs NMI
task_work_add(RWA_RESUME) isn't NMI-safe, use TWA_NMI_CURRENT when used from NMI context. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Link: https://patch.msgid.link/20250924080119.005422353@infradead.org
1 parent ae577ea commit a38a647

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

kernel/unwind/deferred.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void unwind_deferred_task_exit(struct task_struct *task)
231231
int unwind_deferred_request(struct unwind_work *work, u64 *cookie)
232232
{
233233
struct unwind_task_info *info = &current->unwind_info;
234+
int twa_mode = TWA_RESUME;
234235
unsigned long old, bits;
235236
unsigned long bit;
236237
int ret;
@@ -246,8 +247,11 @@ int unwind_deferred_request(struct unwind_work *work, u64 *cookie)
246247
* Trigger a warning to make it obvious that an architecture
247248
* is using this in NMI when it should not be.
248249
*/
249-
if (WARN_ON_ONCE(!CAN_USE_IN_NMI && in_nmi()))
250-
return -EINVAL;
250+
if (in_nmi()) {
251+
if (WARN_ON_ONCE(!CAN_USE_IN_NMI))
252+
return -EINVAL;
253+
twa_mode = TWA_NMI_CURRENT;
254+
}
251255

252256
/* Do not allow cancelled works to request again */
253257
bit = READ_ONCE(work->bit);
@@ -285,7 +289,7 @@ int unwind_deferred_request(struct unwind_work *work, u64 *cookie)
285289
}
286290

287291
/* The work has been claimed, now schedule it. */
288-
ret = task_work_add(current, &info->work, TWA_RESUME);
292+
ret = task_work_add(current, &info->work, twa_mode);
289293

290294
if (WARN_ON_ONCE(ret))
291295
WRITE_ONCE(info->unwind_mask, 0);

0 commit comments

Comments
 (0)