hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/kthread.c
....@@ -264,7 +264,6 @@
264264
265265 static int kthread(void *_create)
266266 {
267
- static const struct sched_param param = { .sched_priority = 0 };
268267 /* Copy data: it's on kthread's stack */
269268 struct kthread_create_info *create = _create;
270269 int (*threadfn)(void *data) = create->threadfn;
....@@ -294,13 +293,6 @@
294293 init_completion(&self->exited);
295294 init_completion(&self->parked);
296295 current->vfork_done = &self->exited;
297
-
298
- /*
299
- * The new thread inherited kthreadd's priority and CPU mask. Reset
300
- * back to default in case they have been changed.
301
- */
302
- sched_setscheduler_nocheck(current, SCHED_NORMAL, &param);
303
- set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_KTHREAD));
304296
305297 /* OK, tell user we're spawned, wait for stop or wakeup */
306298 __set_current_state(TASK_UNINTERRUPTIBLE);
....@@ -399,6 +391,7 @@
399391 }
400392 task = create->result;
401393 if (!IS_ERR(task)) {
394
+ static const struct sched_param param = { .sched_priority = 0 };
402395 char name[TASK_COMM_LEN];
403396
404397 /*
....@@ -407,6 +400,13 @@
407400 */
408401 vsnprintf(name, sizeof(name), namefmt, args);
409402 set_task_comm(task, name);
403
+ /*
404
+ * root may have changed our (kthreadd's) priority or CPU mask.
405
+ * The kernel thread should not inherit these properties.
406
+ */
407
+ sched_setscheduler_nocheck(task, SCHED_NORMAL, &param);
408
+ set_cpus_allowed_ptr(task,
409
+ housekeeping_cpumask(HK_FLAG_KTHREAD));
410410 }
411411 kfree(create);
412412 return task;