]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - kernel/kthread.c
UBUNTU: Ubuntu-5.11.0-19.20
[mirror_ubuntu-hirsute-kernel.git] / kernel / kthread.c
index 1578973c57409cceab891f4f36820a2025dc6b1c..4d0fbd84686d6c71bc487208427624bcb2466484 100644 (file)
@@ -84,6 +84,25 @@ static inline struct kthread *to_kthread(struct task_struct *k)
        return (__force void *)k->set_child_tid;
 }
 
+/*
+ * Variant of to_kthread() that doesn't assume @p is a kthread.
+ *
+ * Per construction; when:
+ *
+ *   (p->flags & PF_KTHREAD) && p->set_child_tid
+ *
+ * the task is both a kthread and struct kthread is persistent. However
+ * PF_KTHREAD on it's own is not, kernel_thread() can exec() (See umh.c and
+ * begin_new_exec()).
+ */
+static inline struct kthread *__to_kthread(struct task_struct *p)
+{
+       void *kthread = (__force void *)p->set_child_tid;
+       if (kthread && !(p->flags & PF_KTHREAD))
+               kthread = NULL;
+       return kthread;
+}
+
 void free_kthread_struct(struct task_struct *k)
 {
        struct kthread *kthread;
@@ -168,8 +187,9 @@ EXPORT_SYMBOL_GPL(kthread_freezable_should_stop);
  */
 void *kthread_func(struct task_struct *task)
 {
-       if (task->flags & PF_KTHREAD)
-               return to_kthread(task)->threadfn;
+       struct kthread *kthread = __to_kthread(task);
+       if (kthread)
+               return kthread->threadfn;
        return NULL;
 }
 EXPORT_SYMBOL_GPL(kthread_func);
@@ -199,10 +219,11 @@ EXPORT_SYMBOL_GPL(kthread_data);
  */
 void *kthread_probe_data(struct task_struct *task)
 {
-       struct kthread *kthread = to_kthread(task);
+       struct kthread *kthread = __to_kthread(task);
        void *data = NULL;
 
-       copy_from_kernel_nofault(&data, &kthread->data, sizeof(data));
+       if (kthread)
+               copy_from_kernel_nofault(&data, &kthread->data, sizeof(data));
        return data;
 }
 
@@ -355,6 +376,17 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
         * new kernel thread.
         */
        if (unlikely(wait_for_completion_killable(&done))) {
+               int i = 0;
+
+               /*
+                * I got SIGKILL, but wait for 10 more seconds for completion
+                * unless chosen by the OOM killer. This delay is there as a
+                * workaround for boot failure caused by SIGKILL upon device
+                * driver initialization timeout.
+                */
+               while (i++ < 10 && !test_tsk_thread_flag(current, TIF_MEMDIE))
+                       if (wait_for_completion_timeout(&done, HZ))
+                               goto ready;
                /*
                 * If I was SIGKILLed before kthreadd (or new kernel thread)
                 * calls complete(), leave the cleanup of this structure to
@@ -368,6 +400,7 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
                 */
                wait_for_completion(&done);
        }
+ready:
        task = create->result;
        if (!IS_ERR(task)) {
                static const struct sched_param param = { .sched_priority = 0 };
@@ -514,9 +547,9 @@ void kthread_set_per_cpu(struct task_struct *k, int cpu)
        set_bit(KTHREAD_IS_PER_CPU, &kthread->flags);
 }
 
-bool kthread_is_per_cpu(struct task_struct *k)
+bool kthread_is_per_cpu(struct task_struct *p)
 {
-       struct kthread *kthread = to_kthread(k);
+       struct kthread *kthread = __to_kthread(p);
        if (!kthread)
                return false;