Skip to content

Commit 36cb0e1

Browse files
committed
fork: Explicity test for idle tasks in copy_thread
The architectures ia64 and parisc have special handling for the idle thread in copy_process. Add a flag named idle to kernel_clone_args and use it to explicity test if an idle process is being created. Fullfill the expectations of the rest of the copy_thread implemetations and pass a function pointer in .stack from fork_idle(). This makes what is happening in copy_thread better defined, and is useful to make idle threads less special. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent c5febea commit 36cb0e1

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

arch/ia64/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
342342
ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
343343

344344
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
345-
if (unlikely(!user_stack_base)) {
345+
if (unlikely(args->idle)) {
346346
/* fork_idle() called us */
347347
return 0;
348348
}

arch/parisc/kernel/process.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
224224
if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
225225
/* kernel thread */
226226
memset(cregs, 0, sizeof(struct pt_regs));
227-
if (!usp) /* idle thread */
227+
if (args->idle) /* idle thread */
228228
return 0;
229229
/* Must exit via ret_from_kernel_thread in order
230230
* to call schedule_tail()

include/linux/sched/task.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct kernel_clone_args {
3333
int cgroup;
3434
int io_thread;
3535
int kthread;
36+
int idle;
3637
struct cgroup *cgrp;
3738
struct css_set *cset;
3839
};

kernel/fork.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,12 +2544,21 @@ static inline void init_idle_pids(struct task_struct *idle)
25442544
}
25452545
}
25462546

2547+
static int idle_dummy(void *dummy)
2548+
{
2549+
/* This function is never called */
2550+
return 0;
2551+
}
2552+
25472553
struct task_struct * __init fork_idle(int cpu)
25482554
{
25492555
struct task_struct *task;
25502556
struct kernel_clone_args args = {
25512557
.flags = CLONE_VM,
2558+
.stack = (unsigned long)&idle_dummy,
2559+
.stack_size = (unsigned long)NULL,
25522560
.kthread = 1,
2561+
.idle = 1,
25532562
};
25542563

25552564
task = copy_process(&init_struct_pid, 0, cpu_to_node(cpu), &args);

0 commit comments

Comments
 (0)