Skip to content

Commit a8f072c

Browse files
htejunoleg-nesterov
authored andcommitted
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: Tejun Heo <tj@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
1 parent 0b1007c commit a8f072c

4 files changed

Lines changed: 67 additions & 60 deletions

File tree

‎fs/exec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ static int zap_process(struct task_struct *start, int exit_code)
17721772

17731773
t = start;
17741774
do {
1775-
task_clear_group_stop_pending(t);
1775+
task_clear_jobctl_stop_pending(t);
17761776
if (t != current && t->mm) {
17771777
sigaddset(&t->pending.signal, SIGKILL);
17781778
signal_wake_up(t, 1);

‎include/linux/sched.h‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ struct task_struct {
12821282
int exit_state;
12831283
int exit_code, exit_signal;
12841284
int pdeath_signal; /* The signal sent when the parent dies */
1285-
unsigned int group_stop; /* GROUP_STOP_*, siglock protected */
1285+
unsigned int jobctl; /* JOBCTL_*, siglock protected */
12861286
/* ??? */
12871287
unsigned int personality;
12881288
unsigned did_exec:1;
@@ -1803,15 +1803,21 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
18031803
#define used_math() tsk_used_math(current)
18041804

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

1814-
extern void task_clear_group_stop_pending(struct task_struct *task);
1810+
#define JOBCTL_STOP_DEQUEUED_BIT 16 /* stop signal dequeued */
1811+
#define JOBCTL_STOP_PENDING_BIT 17 /* task should stop for group stop */
1812+
#define JOBCTL_STOP_CONSUME_BIT 18 /* consume group stop count */
1813+
#define JOBCTL_TRAPPING_BIT 21 /* switching to TRACED */
1814+
1815+
#define JOBCTL_STOP_DEQUEUED (1 << JOBCTL_STOP_DEQUEUED_BIT)
1816+
#define JOBCTL_STOP_PENDING (1 << JOBCTL_STOP_PENDING_BIT)
1817+
#define JOBCTL_STOP_CONSUME (1 << JOBCTL_STOP_CONSUME_BIT)
1818+
#define JOBCTL_TRAPPING (1 << JOBCTL_TRAPPING_BIT)
1819+
1820+
extern void task_clear_jobctl_stop_pending(struct task_struct *task);
18151821

18161822
#ifdef CONFIG_PREEMPT_RCU
18171823

‎kernel/ptrace.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ void __ptrace_unlink(struct task_struct *child)
7777
spin_lock(&child->sighand->siglock);
7878

7979
/*
80-
* Reinstate GROUP_STOP_PENDING if group stop is in effect and
80+
* Reinstate JOBCTL_STOP_PENDING if group stop is in effect and
8181
* @child isn't dead.
8282
*/
8383
if (!(child->flags & PF_EXITING) &&
8484
(child->signal->flags & SIGNAL_STOP_STOPPED ||
8585
child->signal->group_stop_count))
86-
child->group_stop |= GROUP_STOP_PENDING;
86+
child->jobctl |= JOBCTL_STOP_PENDING;
8787

8888
/*
8989
* If transition to TASK_STOPPED is pending or in TASK_TRACED, kick
9090
* @child in the butt. Note that @resume should be used iff @child
9191
* is in TASK_TRACED; otherwise, we might unduly disrupt
9292
* TASK_KILLABLE sleeps.
9393
*/
94-
if (child->group_stop & GROUP_STOP_PENDING || task_is_traced(child))
94+
if (child->jobctl & JOBCTL_STOP_PENDING || task_is_traced(child))
9595
signal_wake_up(child, task_is_traced(child));
9696

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

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

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

‎kernel/signal.c‎

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
124124

125125
static int recalc_sigpending_tsk(struct task_struct *t)
126126
{
127-
if ((t->group_stop & GROUP_STOP_PENDING) ||
127+
if ((t->jobctl & JOBCTL_STOP_PENDING) ||
128128
PENDING(&t->pending, &t->blocked) ||
129129
PENDING(&t->signal->shared_pending, &t->blocked)) {
130130
set_tsk_thread_flag(t, TIF_SIGPENDING);
@@ -224,47 +224,48 @@ static inline void print_dropped_signal(int sig)
224224
}
225225

226226
/**
227-
* task_clear_group_stop_trapping - clear group stop trapping bit
227+
* task_clear_jobctl_trapping - clear jobctl trapping bit
228228
* @task: target task
229229
*
230-
* If GROUP_STOP_TRAPPING is set, a ptracer is waiting for us. Clear it
231-
* and wake up the ptracer. Note that we don't need any further locking.
232-
* @task->siglock guarantees that @task->parent points to the ptracer.
230+
* If JOBCTL_TRAPPING is set, a ptracer is waiting for us to enter TRACED.
231+
* Clear it and wake up the ptracer. Note that we don't need any further
232+
* locking. @task->siglock guarantees that @task->parent points to the
233+
* ptracer.
233234
*
234235
* CONTEXT:
235236
* Must be called with @task->sighand->siglock held.
236237
*/
237-
static void task_clear_group_stop_trapping(struct task_struct *task)
238+
static void task_clear_jobctl_trapping(struct task_struct *task)
238239
{
239-
if (unlikely(task->group_stop & GROUP_STOP_TRAPPING)) {
240-
task->group_stop &= ~GROUP_STOP_TRAPPING;
240+
if (unlikely(task->jobctl & JOBCTL_TRAPPING)) {
241+
task->jobctl &= ~JOBCTL_TRAPPING;
241242
__wake_up_sync_key(&task->parent->signal->wait_chldexit,
242243
TASK_UNINTERRUPTIBLE, 1, task);
243244
}
244245
}
245246

246247
/**
247-
* task_clear_group_stop_pending - clear pending group stop
248+
* task_clear_jobctl_stop_pending - clear pending group stop
248249
* @task: target task
249250
*
250251
* Clear group stop states for @task.
251252
*
252253
* CONTEXT:
253254
* Must be called with @task->sighand->siglock held.
254255
*/
255-
void task_clear_group_stop_pending(struct task_struct *task)
256+
void task_clear_jobctl_stop_pending(struct task_struct *task)
256257
{
257-
task->group_stop &= ~(GROUP_STOP_PENDING | GROUP_STOP_CONSUME |
258-
GROUP_STOP_DEQUEUED);
258+
task->jobctl &= ~(JOBCTL_STOP_PENDING | JOBCTL_STOP_CONSUME |
259+
JOBCTL_STOP_DEQUEUED);
259260
}
260261

261262
/**
262263
* task_participate_group_stop - participate in a group stop
263264
* @task: task participating in a group stop
264265
*
265-
* @task has GROUP_STOP_PENDING set and is participating in a group stop.
266+
* @task has %JOBCTL_STOP_PENDING set and is participating in a group stop.
266267
* Group stop states are cleared and the group stop count is consumed if
267-
* %GROUP_STOP_CONSUME was set. If the consumption completes the group
268+
* %JOBCTL_STOP_CONSUME was set. If the consumption completes the group
268269
* stop, the appropriate %SIGNAL_* flags are set.
269270
*
270271
* CONTEXT:
@@ -277,11 +278,11 @@ void task_clear_group_stop_pending(struct task_struct *task)
277278
static bool task_participate_group_stop(struct task_struct *task)
278279
{
279280
struct signal_struct *sig = task->signal;
280-
bool consume = task->group_stop & GROUP_STOP_CONSUME;
281+
bool consume = task->jobctl & JOBCTL_STOP_CONSUME;
281282

282-
WARN_ON_ONCE(!(task->group_stop & GROUP_STOP_PENDING));
283+
WARN_ON_ONCE(!(task->jobctl & JOBCTL_STOP_PENDING));
283284

284-
task_clear_group_stop_pending(task);
285+
task_clear_jobctl_stop_pending(task);
285286

286287
if (!consume)
287288
return false;
@@ -604,7 +605,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
604605
* is to alert stop-signal processing code when another
605606
* processor has come along and cleared the flag.
606607
*/
607-
current->group_stop |= GROUP_STOP_DEQUEUED;
608+
current->jobctl |= JOBCTL_STOP_DEQUEUED;
608609
}
609610
if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
610611
/*
@@ -809,7 +810,7 @@ static int prepare_signal(int sig, struct task_struct *p, int from_ancestor_ns)
809810
rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending);
810811
t = p;
811812
do {
812-
task_clear_group_stop_pending(t);
813+
task_clear_jobctl_stop_pending(t);
813814
rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
814815
wake_up_state(t, __TASK_STOPPED);
815816
} while_each_thread(p, t);
@@ -925,7 +926,7 @@ static void complete_signal(int sig, struct task_struct *p, int group)
925926
signal->group_stop_count = 0;
926927
t = p;
927928
do {
928-
task_clear_group_stop_pending(t);
929+
task_clear_jobctl_stop_pending(t);
929930
sigaddset(&t->pending.signal, SIGKILL);
930931
signal_wake_up(t, 1);
931932
} while_each_thread(p, t);
@@ -1160,7 +1161,7 @@ int zap_other_threads(struct task_struct *p)
11601161
p->signal->group_stop_count = 0;
11611162

11621163
while_each_thread(p, t) {
1163-
task_clear_group_stop_pending(t);
1164+
task_clear_jobctl_stop_pending(t);
11641165
count++;
11651166

11661167
/* 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)
17381739
* clear now. We act as if SIGCONT is received after TASK_TRACED
17391740
* is entered - ignore it.
17401741
*/
1741-
if (why == CLD_STOPPED && (current->group_stop & GROUP_STOP_PENDING))
1742+
if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING))
17421743
gstop_done = task_participate_group_stop(current);
17431744

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

17531754
/*
1754-
* We're committing to trapping. Clearing GROUP_STOP_TRAPPING and
1755+
* We're committing to trapping. Clearing JOBCTL_TRAPPING and
17551756
* transition to TASK_TRACED should be atomic with respect to
1756-
* siglock. This hsould be done after the arch hook as siglock is
1757+
* siglock. This should be done after the arch hook as siglock is
17571758
* released and regrabbed across it.
17581759
*/
1759-
task_clear_group_stop_trapping(current);
1760+
task_clear_jobctl_trapping(current);
17601761

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

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

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

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

1893-
current->group_stop &= ~GROUP_STOP_SIGMASK;
1894-
current->group_stop |= signr | gstop;
1894+
current->jobctl &= ~JOBCTL_STOP_SIGMASK;
1895+
current->jobctl |= signr | gstop;
18951896
sig->group_stop_count = 1;
18961897
for (t = next_thread(current); t != current;
18971898
t = next_thread(t)) {
1898-
t->group_stop &= ~GROUP_STOP_SIGMASK;
1899+
t->jobctl &= ~JOBCTL_STOP_SIGMASK;
18991900
/*
19001901
* Setting state to TASK_STOPPED for a group
19011902
* stop is always done with the siglock held,
19021903
* so this check has no races.
19031904
*/
19041905
if (!(t->flags & PF_EXITING) && !task_is_stopped(t)) {
1905-
t->group_stop |= signr | gstop;
1906+
t->jobctl |= signr | gstop;
19061907
sig->group_stop_count++;
19071908
signal_wake_up(t, 0);
19081909
}
@@ -1943,23 +1944,23 @@ static int do_signal_stop(int signr)
19431944

19441945
spin_lock_irq(&current->sighand->siglock);
19451946
} else {
1946-
ptrace_stop(current->group_stop & GROUP_STOP_SIGMASK,
1947+
ptrace_stop(current->jobctl & JOBCTL_STOP_SIGMASK,
19471948
CLD_STOPPED, 0, NULL);
19481949
current->exit_code = 0;
19491950
}
19501951

19511952
/*
1952-
* GROUP_STOP_PENDING could be set if another group stop has
1953+
* JOBCTL_STOP_PENDING could be set if another group stop has
19531954
* started since being woken up or ptrace wants us to transit
19541955
* between TASK_STOPPED and TRACED. Retry group stop.
19551956
*/
1956-
if (current->group_stop & GROUP_STOP_PENDING) {
1957-
WARN_ON_ONCE(!(current->group_stop & GROUP_STOP_SIGMASK));
1957+
if (current->jobctl & JOBCTL_STOP_PENDING) {
1958+
WARN_ON_ONCE(!(current->jobctl & JOBCTL_STOP_SIGMASK));
19581959
goto retry;
19591960
}
19601961

19611962
/* PTRACE_ATTACH might have raced with task killing, clear trapping */
1962-
task_clear_group_stop_trapping(current);
1963+
task_clear_jobctl_trapping(current);
19631964

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

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

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

2256-
if (unlikely(tsk->group_stop & GROUP_STOP_PENDING) &&
2257+
if (unlikely(tsk->jobctl & JOBCTL_STOP_PENDING) &&
22572258
task_participate_group_stop(tsk))
22582259
group_stop = CLD_STOPPED;
22592260
out:

0 commit comments

Comments
 (0)