@@ -347,6 +347,47 @@ static bool klp_try_switch_task(struct task_struct *task)
347347
348348}
349349
350+ /*
351+ * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set.
352+ * Kthreads with TIF_PATCH_PENDING set are woken up.
353+ */
354+ static void klp_send_signals (void )
355+ {
356+ struct task_struct * g , * task ;
357+
358+ if (klp_signals_cnt == SIGNALS_TIMEOUT )
359+ pr_notice ("signaling remaining tasks\n" );
360+
361+ read_lock (& tasklist_lock );
362+ for_each_process_thread (g , task ) {
363+ if (!klp_patch_pending (task ))
364+ continue ;
365+
366+ /*
367+ * There is a small race here. We could see TIF_PATCH_PENDING
368+ * set and decide to wake up a kthread or send a fake signal.
369+ * Meanwhile the task could migrate itself and the action
370+ * would be meaningless. It is not serious though.
371+ */
372+ if (task -> flags & PF_KTHREAD ) {
373+ /*
374+ * Wake up a kthread which sleeps interruptedly and
375+ * still has not been migrated.
376+ */
377+ wake_up_state (task , TASK_INTERRUPTIBLE );
378+ } else {
379+ /*
380+ * Send fake signal to all non-kthread tasks which are
381+ * still not migrated.
382+ */
383+ spin_lock_irq (& task -> sighand -> siglock );
384+ signal_wake_up (task , 0 );
385+ spin_unlock_irq (& task -> sighand -> siglock );
386+ }
387+ }
388+ read_unlock (& tasklist_lock );
389+ }
390+
350391/*
351392 * Try to switch all remaining tasks to the target patch state by walking the
352393 * stacks of sleeping tasks and looking for any to-be-patched or
@@ -586,47 +627,6 @@ void klp_copy_process(struct task_struct *child)
586627 /* TIF_PATCH_PENDING gets copied in setup_thread_stack() */
587628}
588629
589- /*
590- * Sends a fake signal to all non-kthread tasks with TIF_PATCH_PENDING set.
591- * Kthreads with TIF_PATCH_PENDING set are woken up.
592- */
593- void klp_send_signals (void )
594- {
595- struct task_struct * g , * task ;
596-
597- if (klp_signals_cnt == SIGNALS_TIMEOUT )
598- pr_notice ("signaling remaining tasks\n" );
599-
600- read_lock (& tasklist_lock );
601- for_each_process_thread (g , task ) {
602- if (!klp_patch_pending (task ))
603- continue ;
604-
605- /*
606- * There is a small race here. We could see TIF_PATCH_PENDING
607- * set and decide to wake up a kthread or send a fake signal.
608- * Meanwhile the task could migrate itself and the action
609- * would be meaningless. It is not serious though.
610- */
611- if (task -> flags & PF_KTHREAD ) {
612- /*
613- * Wake up a kthread which sleeps interruptedly and
614- * still has not been migrated.
615- */
616- wake_up_state (task , TASK_INTERRUPTIBLE );
617- } else {
618- /*
619- * Send fake signal to all non-kthread tasks which are
620- * still not migrated.
621- */
622- spin_lock_irq (& task -> sighand -> siglock );
623- signal_wake_up (task , 0 );
624- spin_unlock_irq (& task -> sighand -> siglock );
625- }
626- }
627- read_unlock (& tasklist_lock );
628- }
629-
630630/*
631631 * Drop TIF_PATCH_PENDING of all tasks on admin's request. This forces an
632632 * existing transition to finish.
0 commit comments