Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8f072c1 authored by Tejun Heo's avatar Tejun Heo Committed by Oleg Nesterov
Browse files

job control: rename signal->group_stop and flags to jobctl and update them



signal->group_stop currently hosts mostly group stop related flags;
however, it's gonna be used for wider purposes and the GROUP_STOP_
flag prefix becomes confusing.  Rename signal->group_stop to
signal->jobctl and rename all GROUP_STOP_* flags to JOBCTL_*.

Bit position macros JOBCTL_*_BIT are defined and JOBCTL_* flags are
defined in terms of them to allow using bitops later.

While at it, reassign JOBCTL_TRAPPING to bit 22 to better accomodate
future additions.

This doesn't cause any functional change.

-v2: JOBCTL_*_BIT macros added as suggested by Linus.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
parent 0b1007c3
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1772,7 +1772,7 @@ static int zap_process(struct task_struct *start, int exit_code)


	t = start;
	t = start;
	do {
	do {
		task_clear_group_stop_pending(t);
		task_clear_jobctl_stop_pending(t);
		if (t != current && t->mm) {
		if (t != current && t->mm) {
			sigaddset(&t->pending.signal, SIGKILL);
			sigaddset(&t->pending.signal, SIGKILL);
			signal_wake_up(t, 1);
			signal_wake_up(t, 1);
+14 −8
Original line number Original line Diff line number Diff line
@@ -1282,7 +1282,7 @@ struct task_struct {
	int exit_state;
	int exit_state;
	int exit_code, exit_signal;
	int exit_code, exit_signal;
	int pdeath_signal;  /*  The signal sent when the parent dies  */
	int pdeath_signal;  /*  The signal sent when the parent dies  */
	unsigned int group_stop;	/* GROUP_STOP_*, siglock protected */
	unsigned int jobctl;	/* JOBCTL_*, siglock protected */
	/* ??? */
	/* ??? */
	unsigned int personality;
	unsigned int personality;
	unsigned did_exec:1;
	unsigned did_exec:1;
@@ -1803,15 +1803,21 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
#define used_math() tsk_used_math(current)
#define used_math() tsk_used_math(current)


/*
/*
 * task->group_stop flags
 * task->jobctl flags
 */
 */
#define GROUP_STOP_SIGMASK	0xffff    /* signr of the last group stop */
#define JOBCTL_STOP_SIGMASK	0xffff	/* signr of the last group stop */
#define GROUP_STOP_PENDING	(1 << 16) /* task should stop for group stop */
#define GROUP_STOP_CONSUME	(1 << 17) /* consume group stop count */
#define GROUP_STOP_TRAPPING	(1 << 18) /* switching from STOPPED to TRACED */
#define GROUP_STOP_DEQUEUED	(1 << 19) /* stop signal dequeued */


extern void task_clear_group_stop_pending(struct task_struct *task);
#define JOBCTL_STOP_DEQUEUED_BIT 16	/* stop signal dequeued */
#define JOBCTL_STOP_PENDING_BIT	17	/* task should stop for group stop */
#define JOBCTL_STOP_CONSUME_BIT	18	/* consume group stop count */
#define JOBCTL_TRAPPING_BIT	21	/* switching to TRACED */

#define JOBCTL_STOP_DEQUEUED	(1 << JOBCTL_STOP_DEQUEUED_BIT)
#define JOBCTL_STOP_PENDING	(1 << JOBCTL_STOP_PENDING_BIT)
#define JOBCTL_STOP_CONSUME	(1 << JOBCTL_STOP_CONSUME_BIT)
#define JOBCTL_TRAPPING		(1 << JOBCTL_TRAPPING_BIT)

extern void task_clear_jobctl_stop_pending(struct task_struct *task);


#ifdef CONFIG_PREEMPT_RCU
#ifdef CONFIG_PREEMPT_RCU


+6 −6
Original line number Original line Diff line number Diff line
@@ -77,13 +77,13 @@ void __ptrace_unlink(struct task_struct *child)
	spin_lock(&child->sighand->siglock);
	spin_lock(&child->sighand->siglock);


	/*
	/*
	 * Reinstate GROUP_STOP_PENDING if group stop is in effect and
	 * Reinstate JOBCTL_STOP_PENDING if group stop is in effect and
	 * @child isn't dead.
	 * @child isn't dead.
	 */
	 */
	if (!(child->flags & PF_EXITING) &&
	if (!(child->flags & PF_EXITING) &&
	    (child->signal->flags & SIGNAL_STOP_STOPPED ||
	    (child->signal->flags & SIGNAL_STOP_STOPPED ||
	     child->signal->group_stop_count))
	     child->signal->group_stop_count))
		child->group_stop |= GROUP_STOP_PENDING;
		child->jobctl |= JOBCTL_STOP_PENDING;


	/*
	/*
	 * If transition to TASK_STOPPED is pending or in TASK_TRACED, kick
	 * If transition to TASK_STOPPED is pending or in TASK_TRACED, kick
@@ -91,7 +91,7 @@ void __ptrace_unlink(struct task_struct *child)
	 * is in TASK_TRACED; otherwise, we might unduly disrupt
	 * is in TASK_TRACED; otherwise, we might unduly disrupt
	 * TASK_KILLABLE sleeps.
	 * TASK_KILLABLE sleeps.
	 */
	 */
	if (child->group_stop & GROUP_STOP_PENDING || task_is_traced(child))
	if (child->jobctl & JOBCTL_STOP_PENDING || task_is_traced(child))
		signal_wake_up(child, task_is_traced(child));
		signal_wake_up(child, task_is_traced(child));


	spin_unlock(&child->sighand->siglock);
	spin_unlock(&child->sighand->siglock);
@@ -226,7 +226,7 @@ static int ptrace_attach(struct task_struct *task)
	spin_lock(&task->sighand->siglock);
	spin_lock(&task->sighand->siglock);


	/*
	/*
	 * If the task is already STOPPED, set GROUP_STOP_PENDING and
	 * If the task is already STOPPED, set JOBCTL_STOP_PENDING and
	 * TRAPPING, and kick it so that it transits to TRACED.  TRAPPING
	 * TRAPPING, and kick it so that it transits to TRACED.  TRAPPING
	 * will be cleared if the child completes the transition or any
	 * will be cleared if the child completes the transition or any
	 * event which clears the group stop states happens.  We'll wait
	 * event which clears the group stop states happens.  We'll wait
@@ -243,7 +243,7 @@ static int ptrace_attach(struct task_struct *task)
	 * in and out of STOPPED are protected by siglock.
	 * in and out of STOPPED are protected by siglock.
	 */
	 */
	if (task_is_stopped(task)) {
	if (task_is_stopped(task)) {
		task->group_stop |= GROUP_STOP_PENDING | GROUP_STOP_TRAPPING;
		task->jobctl |= JOBCTL_STOP_PENDING | JOBCTL_TRAPPING;
		signal_wake_up(task, 1);
		signal_wake_up(task, 1);
	}
	}


@@ -257,7 +257,7 @@ static int ptrace_attach(struct task_struct *task)
out:
out:
	if (!retval)
	if (!retval)
		wait_event(current->signal->wait_chldexit,
		wait_event(current->signal->wait_chldexit,
			   !(task->group_stop & GROUP_STOP_TRAPPING));
			   !(task->jobctl & JOBCTL_TRAPPING));
	return retval;
	return retval;
}
}


+46 −45
Original line number Original line Diff line number Diff line
@@ -124,7 +124,7 @@ static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)


static int recalc_sigpending_tsk(struct task_struct *t)
static int recalc_sigpending_tsk(struct task_struct *t)
{
{
	if ((t->group_stop & GROUP_STOP_PENDING) ||
	if ((t->jobctl & JOBCTL_STOP_PENDING) ||
	    PENDING(&t->pending, &t->blocked) ||
	    PENDING(&t->pending, &t->blocked) ||
	    PENDING(&t->signal->shared_pending, &t->blocked)) {
	    PENDING(&t->signal->shared_pending, &t->blocked)) {
		set_tsk_thread_flag(t, TIF_SIGPENDING);
		set_tsk_thread_flag(t, TIF_SIGPENDING);
@@ -224,27 +224,28 @@ static inline void print_dropped_signal(int sig)
}
}


/**
/**
 * task_clear_group_stop_trapping - clear group stop trapping bit
 * task_clear_jobctl_trapping - clear jobctl trapping bit
 * @task: target task
 * @task: target task
 *
 *
 * If GROUP_STOP_TRAPPING is set, a ptracer is waiting for us.  Clear it
 * If JOBCTL_TRAPPING is set, a ptracer is waiting for us to enter TRACED.
 * and wake up the ptracer.  Note that we don't need any further locking.
 * Clear it and wake up the ptracer.  Note that we don't need any further
 * @task->siglock guarantees that @task->parent points to the ptracer.
 * locking.  @task->siglock guarantees that @task->parent points to the
 * ptracer.
 *
 *
 * CONTEXT:
 * CONTEXT:
 * Must be called with @task->sighand->siglock held.
 * Must be called with @task->sighand->siglock held.
 */
 */
static void task_clear_group_stop_trapping(struct task_struct *task)
static void task_clear_jobctl_trapping(struct task_struct *task)
{
{
	if (unlikely(task->group_stop & GROUP_STOP_TRAPPING)) {
	if (unlikely(task->jobctl & JOBCTL_TRAPPING)) {
		task->group_stop &= ~GROUP_STOP_TRAPPING;
		task->jobctl &= ~JOBCTL_TRAPPING;
		__wake_up_sync_key(&task->parent->signal->wait_chldexit,
		__wake_up_sync_key(&task->parent->signal->wait_chldexit,
				   TASK_UNINTERRUPTIBLE, 1, task);
				   TASK_UNINTERRUPTIBLE, 1, task);
	}
	}
}
}


/**
/**
 * task_clear_group_stop_pending - clear pending group stop
 * task_clear_jobctl_stop_pending - clear pending group stop
 * @task: target task
 * @task: target task
 *
 *
 * Clear group stop states for @task.
 * Clear group stop states for @task.
@@ -252,19 +253,19 @@ static void task_clear_group_stop_trapping(struct task_struct *task)
 * CONTEXT:
 * CONTEXT:
 * Must be called with @task->sighand->siglock held.
 * Must be called with @task->sighand->siglock held.
 */
 */
void task_clear_group_stop_pending(struct task_struct *task)
void task_clear_jobctl_stop_pending(struct task_struct *task)
{
{
	task->group_stop &= ~(GROUP_STOP_PENDING | GROUP_STOP_CONSUME |
	task->jobctl &= ~(JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME |
			      GROUP_STOP_DEQUEUED);
			  JOBCTL_STOP_DEQUEUED);
}
}


/**
/**
 * task_participate_group_stop - participate in a group stop
 * task_participate_group_stop - participate in a group stop
 * @task: task participating in a group stop
 * @task: task participating in a group stop
 *
 *
 * @task has GROUP_STOP_PENDING set and is participating in a group stop.
 * @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
 * Group stop states are cleared and the group stop count is consumed if
 * Group stop states are cleared and the group stop count is consumed if
 * %GROUP_STOP_CONSUME was set.  If the consumption completes the group
 * %JOBCTL_STOP_CONSUME was set.  If the consumption completes the group
 * stop, the appropriate %SIGNAL_* flags are set.
 * stop, the appropriate %SIGNAL_* flags are set.
 *
 *
 * CONTEXT:
 * CONTEXT:
@@ -277,11 +278,11 @@ void task_clear_group_stop_pending(struct task_struct *task)
static bool task_participate_group_stop(struct task_struct *task)
static bool task_participate_group_stop(struct task_struct *task)
{
{
	struct signal_struct *sig = task->signal;
	struct signal_struct *sig = task->signal;
	bool consume = task->group_stop & GROUP_STOP_CONSUME;
	bool consume = task->jobctl & JOBCTL_STOP_CONSUME;


	WARN_ON_ONCE(!(task->group_stop & GROUP_STOP_PENDING));
	WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING));


	task_clear_group_stop_pending(task);
	task_clear_jobctl_stop_pending(task);


	if (!consume)
	if (!consume)
		return false;
		return false;
@@ -604,7 +605,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
		 * is to alert stop-signal processing code when another
		 * is to alert stop-signal processing code when another
		 * processor has come along and cleared the flag.
		 * processor has come along and cleared the flag.
		 */
		 */
		current->group_stop |= GROUP_STOP_DEQUEUED;
		current->jobctl |= JOBCTL_STOP_DEQUEUED;
	}
	}
	if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
	if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
		/*
		/*
@@ -809,7 +810,7 @@ static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns)
		rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending);
		rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending);
		t = p;
		t = p;
		do {
		do {
			task_clear_group_stop_pending(t);
			task_clear_jobctl_stop_pending(t);
			rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
			rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
			wake_up_state(t, __TASK_STOPPED);
			wake_up_state(t, __TASK_STOPPED);
		} while_each_thread(p, t);
		} while_each_thread(p, t);
@@ -925,7 +926,7 @@ static void complete_signal(int sig, struct task_struct *p, int group)
			signal->group_stop_count = 0;
			signal->group_stop_count = 0;
			t = p;
			t = p;
			do {
			do {
				task_clear_group_stop_pending(t);
				task_clear_jobctl_stop_pending(t);
				sigaddset(&t->pending.signal, SIGKILL);
				sigaddset(&t->pending.signal, SIGKILL);
				signal_wake_up(t, 1);
				signal_wake_up(t, 1);
			} while_each_thread(p, t);
			} while_each_thread(p, t);
@@ -1160,7 +1161,7 @@ int zap_other_threads(struct task_struct *p)
	p->signal->group_stop_count = 0;
	p->signal->group_stop_count = 0;


	while_each_thread(p, t) {
	while_each_thread(p, t) {
		task_clear_group_stop_pending(t);
		task_clear_jobctl_stop_pending(t);
		count++;
		count++;


		/* Don't bother with already dead threads */
		/* Don't bother with already dead threads */
@@ -1738,7 +1739,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info)
	 * clear now.  We act as if SIGCONT is received after TASK_TRACED
	 * clear now.  We act as if SIGCONT is received after TASK_TRACED
	 * is entered - ignore it.
	 * is entered - ignore it.
	 */
	 */
	if (why == CLD_STOPPED && (current->group_stop & GROUP_STOP_PENDING))
	if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING))
		gstop_done = task_participate_group_stop(current);
		gstop_done = task_participate_group_stop(current);


	current->last_siginfo = info;
	current->last_siginfo = info;
@@ -1751,12 +1752,12 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info)
	set_current_state(TASK_TRACED);
	set_current_state(TASK_TRACED);


	/*
	/*
	 * We're committing to trapping.  Clearing GROUP_STOP_TRAPPING and
	 * We're committing to trapping.  Clearing JOBCTL_TRAPPING and
	 * transition to TASK_TRACED should be atomic with respect to
	 * transition to TASK_TRACED should be atomic with respect to
	 * siglock.  This hsould be done after the arch hook as siglock is
	 * siglock.  This should be done after the arch hook as siglock is
	 * released and regrabbed across it.
	 * released and regrabbed across it.
	 */
	 */
	task_clear_group_stop_trapping(current);
	task_clear_jobctl_trapping(current);


	spin_unlock_irq(&current->sighand->siglock);
	spin_unlock_irq(&current->sighand->siglock);
	read_lock(&tasklist_lock);
	read_lock(&tasklist_lock);
@@ -1792,9 +1793,9 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info)
		 *
		 *
		 * If @gstop_done, the ptracer went away between group stop
		 * If @gstop_done, the ptracer went away between group stop
		 * completion and here.  During detach, it would have set
		 * completion and here.  During detach, it would have set
		 * GROUP_STOP_PENDING on us and we'll re-enter TASK_STOPPED
		 * JOBCTL_STOP_PENDING on us and we'll re-enter
		 * in do_signal_stop() on return, so notifying the real
		 * TASK_STOPPED in do_signal_stop() on return, so notifying
		 * parent of the group stop completion is enough.
		 * the real parent of the group stop completion is enough.
		 */
		 */
		if (gstop_done)
		if (gstop_done)
			do_notify_parent_cldstop(current, false, why);
			do_notify_parent_cldstop(current, false, why);
@@ -1856,14 +1857,14 @@ static int do_signal_stop(int signr)
{
{
	struct signal_struct *sig = current->signal;
	struct signal_struct *sig = current->signal;


	if (!(current->group_stop & GROUP_STOP_PENDING)) {
	if (!(current->jobctl & JOBCTL_STOP_PENDING)) {
		unsigned int gstop = GROUP_STOP_PENDING | GROUP_STOP_CONSUME;
		unsigned int gstop = JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME;
		struct task_struct *t;
		struct task_struct *t;


		/* signr will be recorded in task->group_stop for retries */
		/* signr will be recorded in task->jobctl for retries */
		WARN_ON_ONCE(signr & ~GROUP_STOP_SIGMASK);
		WARN_ON_ONCE(signr & ~JOBCTL_STOP_SIGMASK);


		if (!likely(current->group_stop & GROUP_STOP_DEQUEUED) ||
		if (!likely(current->jobctl & JOBCTL_STOP_DEQUEUED) ||
		    unlikely(signal_group_exit(sig)))
		    unlikely(signal_group_exit(sig)))
			return 0;
			return 0;
		/*
		/*
@@ -1890,19 +1891,19 @@ static int do_signal_stop(int signr)
		else
		else
			WARN_ON_ONCE(!task_ptrace(current));
			WARN_ON_ONCE(!task_ptrace(current));


		current->group_stop &= ~GROUP_STOP_SIGMASK;
		current->jobctl &= ~JOBCTL_STOP_SIGMASK;
		current->group_stop |= signr | gstop;
		current->jobctl |= signr | gstop;
		sig->group_stop_count = 1;
		sig->group_stop_count = 1;
		for (t = next_thread(current); t != current;
		for (t = next_thread(current); t != current;
		     t = next_thread(t)) {
		     t = next_thread(t)) {
			t->group_stop &= ~GROUP_STOP_SIGMASK;
			t->jobctl &= ~JOBCTL_STOP_SIGMASK;
			/*
			/*
			 * Setting state to TASK_STOPPED for a group
			 * Setting state to TASK_STOPPED for a group
			 * stop is always done with the siglock held,
			 * stop is always done with the siglock held,
			 * so this check has no races.
			 * so this check has no races.
			 */
			 */
			if (!(t->flags & PF_EXITING) && !task_is_stopped(t)) {
			if (!(t->flags & PF_EXITING) && !task_is_stopped(t)) {
				t->group_stop |= signr | gstop;
				t->jobctl |= signr | gstop;
				sig->group_stop_count++;
				sig->group_stop_count++;
				signal_wake_up(t, 0);
				signal_wake_up(t, 0);
			}
			}
@@ -1943,23 +1944,23 @@ static int do_signal_stop(int signr)


		spin_lock_irq(&current->sighand->siglock);
		spin_lock_irq(&current->sighand->siglock);
	} else {
	} else {
		ptrace_stop(current->group_stop & GROUP_STOP_SIGMASK,
		ptrace_stop(current->jobctl & JOBCTL_STOP_SIGMASK,
			    CLD_STOPPED, 0, NULL);
			    CLD_STOPPED, 0, NULL);
		current->exit_code = 0;
		current->exit_code = 0;
	}
	}


	/*
	/*
	 * GROUP_STOP_PENDING could be set if another group stop has
	 * JOBCTL_STOP_PENDING could be set if another group stop has
	 * started since being woken up or ptrace wants us to transit
	 * started since being woken up or ptrace wants us to transit
	 * between TASK_STOPPED and TRACED.  Retry group stop.
	 * between TASK_STOPPED and TRACED.  Retry group stop.
	 */
	 */
	if (current->group_stop & GROUP_STOP_PENDING) {
	if (current->jobctl & JOBCTL_STOP_PENDING) {
		WARN_ON_ONCE(!(current->group_stop & GROUP_STOP_SIGMASK));
		WARN_ON_ONCE(!(current->jobctl & JOBCTL_STOP_SIGMASK));
		goto retry;
		goto retry;
	}
	}


	/* PTRACE_ATTACH might have raced with task killing, clear trapping */
	/* PTRACE_ATTACH might have raced with task killing, clear trapping */
	task_clear_group_stop_trapping(current);
	task_clear_jobctl_trapping(current);


	spin_unlock_irq(&current->sighand->siglock);
	spin_unlock_irq(&current->sighand->siglock);


@@ -2078,8 +2079,8 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
		if (unlikely(signr != 0))
		if (unlikely(signr != 0))
			ka = return_ka;
			ka = return_ka;
		else {
		else {
			if (unlikely(current->group_stop &
			if (unlikely(current->jobctl & JOBCTL_STOP_PENDING) &&
				     GROUP_STOP_PENDING) && do_signal_stop(0))
			    do_signal_stop(0))
				goto relock;
				goto relock;


			signr = dequeue_signal(current, &current->blocked,
			signr = dequeue_signal(current, &current->blocked,
@@ -2253,7 +2254,7 @@ void exit_signals(struct task_struct *tsk)
	signotset(&unblocked);
	signotset(&unblocked);
	retarget_shared_pending(tsk, &unblocked);
	retarget_shared_pending(tsk, &unblocked);


	if (unlikely(tsk->group_stop & GROUP_STOP_PENDING) &&
	if (unlikely(tsk->jobctl & JOBCTL_STOP_PENDING) &&
	    task_participate_group_stop(tsk))
	    task_participate_group_stop(tsk))
		group_stop = CLD_STOPPED;
		group_stop = CLD_STOPPED;
out:
out: