diff options
author | Ingo Molnar <mingo@kernel.org> | 2017-02-02 02:35:14 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2017-03-02 19:43:37 -0500 |
commit | c3edc4010e9d102eb7b8f17d15c2ebc425fed63c (patch) | |
tree | f49be469e5001e63d7b038bd9bac71ed7b63bd02 | |
parent | 11701c6768367294c5086738d49196192aaf3d60 (diff) |
sched/headers: Move task_struct::signal and task_struct::sighand types and accessors into <linux/sched/signal.h>
task_struct::signal and task_struct::sighand are pointers, which would normally make it
straightforward to not define those types in sched.h.
That is not so, because the types are accompanied by a myriad of APIs (macros and inline
functions) that dereference them.
Split the types and the APIs out of sched.h and move them into a new header, <linux/sched/signal.h>.
With this change sched.h does not know about 'struct signal' and 'struct sighand' anymore,
trying to put accessors into sched.h as a test fails the following way:
./include/linux/sched.h: In function ‘test_signal_types’:
./include/linux/sched.h:2461:18: error: dereferencing pointer to incomplete type ‘struct signal_struct’
^
This reduces the size and complexity of sched.h significantly.
Update all headers and .c code that relied on getting the signal handling
functionality from <linux/sched.h> to include <linux/sched/signal.h>.
The list of affected files in the preparatory patch was partly generated by
grepping for the APIs, and partly by doing coverage build testing, both
all[yes|mod|def|no]config builds on 64-bit and 32-bit x86, and an array of
cross-architecture builds.
Nevertheless some (trivial) build breakage is still expected related to rare
Kconfig combinations and in-flight patches to various kernel code, but most
of it should be handled by this patch.
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/arm/nwfpe/fpmodule.c | 2 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh4/fpu.c | 3 | ||||
-rw-r--r-- | drivers/net/tap.c | 2 | ||||
-rw-r--r-- | include/linux/sched.h | 499 | ||||
-rw-r--r-- | include/linux/sched/signal.h | 502 | ||||
-rw-r--r-- | kernel/cgroup/cgroup-v1.c | 1 | ||||
-rw-r--r-- | mm/vmalloc.c | 2 | ||||
-rw-r--r-- | net/smc/af_smc.c | 2 | ||||
-rw-r--r-- | net/smc/smc_clc.c | 2 | ||||
-rw-r--r-- | net/smc/smc_close.c | 2 | ||||
-rw-r--r-- | net/smc/smc_rx.c | 2 | ||||
-rw-r--r-- | net/smc/smc_tx.c | 2 |
12 files changed, 520 insertions, 501 deletions
diff --git a/arch/arm/nwfpe/fpmodule.c b/arch/arm/nwfpe/fpmodule.c index ec717c190e2c..1365e8650843 100644 --- a/arch/arm/nwfpe/fpmodule.c +++ b/arch/arm/nwfpe/fpmodule.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include <linux/types.h> | 31 | #include <linux/types.h> |
32 | #include <linux/kernel.h> | 32 | #include <linux/kernel.h> |
33 | #include <linux/signal.h> | 33 | #include <linux/signal.h> |
34 | #include <linux/sched.h> | 34 | #include <linux/sched/signal.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | 36 | ||
37 | #include <asm/thread_notify.h> | 37 | #include <asm/thread_notify.h> |
diff --git a/arch/sh/kernel/cpu/sh4/fpu.c b/arch/sh/kernel/cpu/sh4/fpu.c index 69ab4d3c8d41..95fd2dcb83da 100644 --- a/arch/sh/kernel/cpu/sh4/fpu.c +++ b/arch/sh/kernel/cpu/sh4/fpu.c | |||
@@ -10,8 +10,7 @@ | |||
10 | * | 10 | * |
11 | * FIXME! These routines have not been tested for big endian case. | 11 | * FIXME! These routines have not been tested for big endian case. |
12 | */ | 12 | */ |
13 | #include <linux/sched.h> | 13 | #include <linux/sched/signal.h> |
14 | #include <linux/signal.h> | ||
15 | #include <linux/io.h> | 14 | #include <linux/io.h> |
16 | #include <cpu/fpu.h> | 15 | #include <cpu/fpu.h> |
17 | #include <asm/processor.h> | 16 | #include <asm/processor.h> |
diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 35b55a2fa1a1..4d4173d25dd0 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c | |||
@@ -8,7 +8,7 @@ | |||
8 | #include <linux/module.h> | 8 | #include <linux/module.h> |
9 | #include <linux/skbuff.h> | 9 | #include <linux/skbuff.h> |
10 | #include <linux/cache.h> | 10 | #include <linux/cache.h> |
11 | #include <linux/sched.h> | 11 | #include <linux/sched/signal.h> |
12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/wait.h> | 14 | #include <linux/wait.h> |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 7934cd0acbc7..c1586104d4c0 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -71,6 +71,9 @@ struct blk_plug; | |||
71 | struct filename; | 71 | struct filename; |
72 | struct nameidata; | 72 | struct nameidata; |
73 | 73 | ||
74 | struct signal_struct; | ||
75 | struct sighand_struct; | ||
76 | |||
74 | extern unsigned long total_forks; | 77 | extern unsigned long total_forks; |
75 | extern int nr_threads; | 78 | extern int nr_threads; |
76 | DECLARE_PER_CPU(unsigned long, process_counts); | 79 | DECLARE_PER_CPU(unsigned long, process_counts); |
@@ -361,13 +364,6 @@ arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, | |||
361 | static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} | 364 | static inline void arch_pick_mmap_layout(struct mm_struct *mm) {} |
362 | #endif | 365 | #endif |
363 | 366 | ||
364 | struct sighand_struct { | ||
365 | atomic_t count; | ||
366 | struct k_sigaction action[_NSIG]; | ||
367 | spinlock_t siglock; | ||
368 | wait_queue_head_t signalfd_wqh; | ||
369 | }; | ||
370 | |||
371 | struct pacct_struct { | 367 | struct pacct_struct { |
372 | int ac_flag; | 368 | int ac_flag; |
373 | long ac_exitcode; | 369 | long ac_exitcode; |
@@ -486,195 +482,6 @@ struct thread_group_cputimer { | |||
486 | struct autogroup; | 482 | struct autogroup; |
487 | 483 | ||
488 | /* | 484 | /* |
489 | * NOTE! "signal_struct" does not have its own | ||
490 | * locking, because a shared signal_struct always | ||
491 | * implies a shared sighand_struct, so locking | ||
492 | * sighand_struct is always a proper superset of | ||
493 | * the locking of signal_struct. | ||
494 | */ | ||
495 | struct signal_struct { | ||
496 | atomic_t sigcnt; | ||
497 | atomic_t live; | ||
498 | int nr_threads; | ||
499 | struct list_head thread_head; | ||
500 | |||
501 | wait_queue_head_t wait_chldexit; /* for wait4() */ | ||
502 | |||
503 | /* current thread group signal load-balancing target: */ | ||
504 | struct task_struct *curr_target; | ||
505 | |||
506 | /* shared signal handling: */ | ||
507 | struct sigpending shared_pending; | ||
508 | |||
509 | /* thread group exit support */ | ||
510 | int group_exit_code; | ||
511 | /* overloaded: | ||
512 | * - notify group_exit_task when ->count is equal to notify_count | ||
513 | * - everyone except group_exit_task is stopped during signal delivery | ||
514 | * of fatal signals, group_exit_task processes the signal. | ||
515 | */ | ||
516 | int notify_count; | ||
517 | struct task_struct *group_exit_task; | ||
518 | |||
519 | /* thread group stop support, overloads group_exit_code too */ | ||
520 | int group_stop_count; | ||
521 | unsigned int flags; /* see SIGNAL_* flags below */ | ||
522 | |||
523 | /* | ||
524 | * PR_SET_CHILD_SUBREAPER marks a process, like a service | ||
525 | * manager, to re-parent orphan (double-forking) child processes | ||
526 | * to this process instead of 'init'. The service manager is | ||
527 | * able to receive SIGCHLD signals and is able to investigate | ||
528 | * the process until it calls wait(). All children of this | ||
529 | * process will inherit a flag if they should look for a | ||
530 | * child_subreaper process at exit. | ||
531 | */ | ||
532 | unsigned int is_child_subreaper:1; | ||
533 | unsigned int has_child_subreaper:1; | ||
534 | |||
535 | #ifdef CONFIG_POSIX_TIMERS | ||
536 | |||
537 | /* POSIX.1b Interval Timers */ | ||
538 | int posix_timer_id; | ||
539 | struct list_head posix_timers; | ||
540 | |||
541 | /* ITIMER_REAL timer for the process */ | ||
542 | struct hrtimer real_timer; | ||
543 | ktime_t it_real_incr; | ||
544 | |||
545 | /* | ||
546 | * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use | ||
547 | * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these | ||
548 | * values are defined to 0 and 1 respectively | ||
549 | */ | ||
550 | struct cpu_itimer it[2]; | ||
551 | |||
552 | /* | ||
553 | * Thread group totals for process CPU timers. | ||
554 | * See thread_group_cputimer(), et al, for details. | ||
555 | */ | ||
556 | struct thread_group_cputimer cputimer; | ||
557 | |||
558 | /* Earliest-expiration cache. */ | ||
559 | struct task_cputime cputime_expires; | ||
560 | |||
561 | struct list_head cpu_timers[3]; | ||
562 | |||
563 | #endif | ||
564 | |||
565 | struct pid *leader_pid; | ||
566 | |||
567 | #ifdef CONFIG_NO_HZ_FULL | ||
568 | atomic_t tick_dep_mask; | ||
569 | #endif | ||
570 | |||
571 | struct pid *tty_old_pgrp; | ||
572 | |||
573 | /* boolean value for session group leader */ | ||
574 | int leader; | ||
575 | |||
576 | struct tty_struct *tty; /* NULL if no tty */ | ||
577 | |||
578 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
579 | struct autogroup *autogroup; | ||
580 | #endif | ||
581 | /* | ||
582 | * Cumulative resource counters for dead threads in the group, | ||
583 | * and for reaped dead child processes forked by this group. | ||
584 | * Live threads maintain their own counters and add to these | ||
585 | * in __exit_signal, except for the group leader. | ||
586 | */ | ||
587 | seqlock_t stats_lock; | ||
588 | u64 utime, stime, cutime, cstime; | ||
589 | u64 gtime; | ||
590 | u64 cgtime; | ||
591 | struct prev_cputime prev_cputime; | ||
592 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; | ||
593 | unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; | ||
594 | unsigned long inblock, oublock, cinblock, coublock; | ||
595 | unsigned long maxrss, cmaxrss; | ||
596 | struct task_io_accounting ioac; | ||
597 | |||
598 | /* | ||
599 | * Cumulative ns of schedule CPU time fo dead threads in the | ||
600 | * group, not including a zombie group leader, (This only differs | ||
601 | * from jiffies_to_ns(utime + stime) if sched_clock uses something | ||
602 | * other than jiffies.) | ||
603 | */ | ||
604 | unsigned long long sum_sched_runtime; | ||
605 | |||
606 | /* | ||
607 | * We don't bother to synchronize most readers of this at all, | ||
608 | * because there is no reader checking a limit that actually needs | ||
609 | * to get both rlim_cur and rlim_max atomically, and either one | ||
610 | * alone is a single word that can safely be read normally. | ||
611 | * getrlimit/setrlimit use task_lock(current->group_leader) to | ||
612 | * protect this instead of the siglock, because they really | ||
613 | * have no need to disable irqs. | ||
614 | */ | ||
615 | struct rlimit rlim[RLIM_NLIMITS]; | ||
616 | |||
617 | #ifdef CONFIG_BSD_PROCESS_ACCT | ||
618 | struct pacct_struct pacct; /* per-process accounting information */ | ||
619 | #endif | ||
620 | #ifdef CONFIG_TASKSTATS | ||
621 | struct taskstats *stats; | ||
622 | #endif | ||
623 | #ifdef CONFIG_AUDIT | ||
624 | unsigned audit_tty; | ||
625 | struct tty_audit_buf *tty_audit_buf; | ||
626 | #endif | ||
627 | |||
628 | /* | ||
629 | * Thread is the potential origin of an oom condition; kill first on | ||
630 | * oom | ||
631 | */ | ||
632 | bool oom_flag_origin; | ||
633 | short oom_score_adj; /* OOM kill score adjustment */ | ||
634 | short oom_score_adj_min; /* OOM kill score adjustment min value. | ||
635 | * Only settable by CAP_SYS_RESOURCE. */ | ||
636 | struct mm_struct *oom_mm; /* recorded mm when the thread group got | ||
637 | * killed by the oom killer */ | ||
638 | |||
639 | struct mutex cred_guard_mutex; /* guard against foreign influences on | ||
640 | * credential calculations | ||
641 | * (notably. ptrace) */ | ||
642 | }; | ||
643 | |||
644 | /* | ||
645 | * Bits in flags field of signal_struct. | ||
646 | */ | ||
647 | #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ | ||
648 | #define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */ | ||
649 | #define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */ | ||
650 | #define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */ | ||
651 | /* | ||
652 | * Pending notifications to parent. | ||
653 | */ | ||
654 | #define SIGNAL_CLD_STOPPED 0x00000010 | ||
655 | #define SIGNAL_CLD_CONTINUED 0x00000020 | ||
656 | #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) | ||
657 | |||
658 | #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ | ||
659 | |||
660 | #define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \ | ||
661 | SIGNAL_STOP_CONTINUED) | ||
662 | |||
663 | static inline void signal_set_stop_flags(struct signal_struct *sig, | ||
664 | unsigned int flags) | ||
665 | { | ||
666 | WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP)); | ||
667 | sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags; | ||
668 | } | ||
669 | |||
670 | /* If true, all threads except ->group_exit_task have pending SIGKILL */ | ||
671 | static inline int signal_group_exit(const struct signal_struct *sig) | ||
672 | { | ||
673 | return (sig->flags & SIGNAL_GROUP_EXIT) || | ||
674 | (sig->group_exit_task != NULL); | ||
675 | } | ||
676 | |||
677 | /* | ||
678 | * Some day this will be a full-fledged user tracking system.. | 485 | * Some day this will be a full-fledged user tracking system.. |
679 | */ | 486 | */ |
680 | struct user_struct { | 487 | struct user_struct { |
@@ -2126,190 +1933,8 @@ extern int sched_fork(unsigned long clone_flags, struct task_struct *p); | |||
2126 | extern void sched_dead(struct task_struct *p); | 1933 | extern void sched_dead(struct task_struct *p); |
2127 | 1934 | ||
2128 | extern void proc_caches_init(void); | 1935 | extern void proc_caches_init(void); |
2129 | extern void flush_signals(struct task_struct *); | ||
2130 | extern void ignore_signals(struct task_struct *); | ||
2131 | extern void flush_signal_handlers(struct task_struct *, int force_default); | ||
2132 | extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); | ||
2133 | |||
2134 | static inline int kernel_dequeue_signal(siginfo_t *info) | ||
2135 | { | ||
2136 | struct task_struct *tsk = current; | ||
2137 | siginfo_t __info; | ||
2138 | int ret; | ||
2139 | |||
2140 | spin_lock_irq(&tsk->sighand->siglock); | ||
2141 | ret = dequeue_signal(tsk, &tsk->blocked, info ?: &__info); | ||
2142 | spin_unlock_irq(&tsk->sighand->siglock); | ||
2143 | |||
2144 | return ret; | ||
2145 | } | ||
2146 | |||
2147 | static inline void kernel_signal_stop(void) | ||
2148 | { | ||
2149 | spin_lock_irq(¤t->sighand->siglock); | ||
2150 | if (current->jobctl & JOBCTL_STOP_DEQUEUED) | ||
2151 | __set_current_state(TASK_STOPPED); | ||
2152 | spin_unlock_irq(¤t->sighand->siglock); | ||
2153 | |||
2154 | schedule(); | ||
2155 | } | ||
2156 | 1936 | ||
2157 | extern void release_task(struct task_struct * p); | 1937 | extern void release_task(struct task_struct * p); |
2158 | extern int send_sig_info(int, struct siginfo *, struct task_struct *); | ||
2159 | extern int force_sigsegv(int, struct task_struct *); | ||
2160 | extern int force_sig_info(int, struct siginfo *, struct task_struct *); | ||
2161 | extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); | ||
2162 | extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); | ||
2163 | extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *, | ||
2164 | const struct cred *, u32); | ||
2165 | extern int kill_pgrp(struct pid *pid, int sig, int priv); | ||
2166 | extern int kill_pid(struct pid *pid, int sig, int priv); | ||
2167 | extern int kill_proc_info(int, struct siginfo *, pid_t); | ||
2168 | extern __must_check bool do_notify_parent(struct task_struct *, int); | ||
2169 | extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); | ||
2170 | extern void force_sig(int, struct task_struct *); | ||
2171 | extern int send_sig(int, struct task_struct *, int); | ||
2172 | extern int zap_other_threads(struct task_struct *p); | ||
2173 | extern struct sigqueue *sigqueue_alloc(void); | ||
2174 | extern void sigqueue_free(struct sigqueue *); | ||
2175 | extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); | ||
2176 | extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); | ||
2177 | |||
2178 | #ifdef TIF_RESTORE_SIGMASK | ||
2179 | /* | ||
2180 | * Legacy restore_sigmask accessors. These are inefficient on | ||
2181 | * SMP architectures because they require atomic operations. | ||
2182 | */ | ||
2183 | |||
2184 | /** | ||
2185 | * set_restore_sigmask() - make sure saved_sigmask processing gets done | ||
2186 | * | ||
2187 | * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code | ||
2188 | * will run before returning to user mode, to process the flag. For | ||
2189 | * all callers, TIF_SIGPENDING is already set or it's no harm to set | ||
2190 | * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the | ||
2191 | * arch code will notice on return to user mode, in case those bits | ||
2192 | * are scarce. We set TIF_SIGPENDING here to ensure that the arch | ||
2193 | * signal code always gets run when TIF_RESTORE_SIGMASK is set. | ||
2194 | */ | ||
2195 | static inline void set_restore_sigmask(void) | ||
2196 | { | ||
2197 | set_thread_flag(TIF_RESTORE_SIGMASK); | ||
2198 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | ||
2199 | } | ||
2200 | static inline void clear_restore_sigmask(void) | ||
2201 | { | ||
2202 | clear_thread_flag(TIF_RESTORE_SIGMASK); | ||
2203 | } | ||
2204 | static inline bool test_restore_sigmask(void) | ||
2205 | { | ||
2206 | return test_thread_flag(TIF_RESTORE_SIGMASK); | ||
2207 | } | ||
2208 | static inline bool test_and_clear_restore_sigmask(void) | ||
2209 | { | ||
2210 | return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK); | ||
2211 | } | ||
2212 | |||
2213 | #else /* TIF_RESTORE_SIGMASK */ | ||
2214 | |||
2215 | /* Higher-quality implementation, used if TIF_RESTORE_SIGMASK doesn't exist. */ | ||
2216 | static inline void set_restore_sigmask(void) | ||
2217 | { | ||
2218 | current->restore_sigmask = true; | ||
2219 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | ||
2220 | } | ||
2221 | static inline void clear_restore_sigmask(void) | ||
2222 | { | ||
2223 | current->restore_sigmask = false; | ||
2224 | } | ||
2225 | static inline bool test_restore_sigmask(void) | ||
2226 | { | ||
2227 | return current->restore_sigmask; | ||
2228 | } | ||
2229 | static inline bool test_and_clear_restore_sigmask(void) | ||
2230 | { | ||
2231 | if (!current->restore_sigmask) | ||
2232 | return false; | ||
2233 | current->restore_sigmask = false; | ||
2234 | return true; | ||
2235 | } | ||
2236 | #endif | ||
2237 | |||
2238 | static inline void restore_saved_sigmask(void) | ||
2239 | { | ||
2240 | if (test_and_clear_restore_sigmask()) | ||
2241 | __set_current_blocked(¤t->saved_sigmask); | ||
2242 | } | ||
2243 | |||
2244 | static inline sigset_t *sigmask_to_save(void) | ||
2245 | { | ||
2246 | sigset_t *res = ¤t->blocked; | ||
2247 | if (unlikely(test_restore_sigmask())) | ||
2248 | res = ¤t->saved_sigmask; | ||
2249 | return res; | ||
2250 | } | ||
2251 | |||
2252 | static inline int kill_cad_pid(int sig, int priv) | ||
2253 | { | ||
2254 | return kill_pid(cad_pid, sig, priv); | ||
2255 | } | ||
2256 | |||
2257 | /* These can be the second arg to send_sig_info/send_group_sig_info. */ | ||
2258 | #define SEND_SIG_NOINFO ((struct siginfo *) 0) | ||
2259 | #define SEND_SIG_PRIV ((struct siginfo *) 1) | ||
2260 | #define SEND_SIG_FORCED ((struct siginfo *) 2) | ||
2261 | |||
2262 | /* | ||
2263 | * True if we are on the alternate signal stack. | ||
2264 | */ | ||
2265 | static inline int on_sig_stack(unsigned long sp) | ||
2266 | { | ||
2267 | /* | ||
2268 | * If the signal stack is SS_AUTODISARM then, by construction, we | ||
2269 | * can't be on the signal stack unless user code deliberately set | ||
2270 | * SS_AUTODISARM when we were already on it. | ||
2271 | * | ||
2272 | * This improves reliability: if user state gets corrupted such that | ||
2273 | * the stack pointer points very close to the end of the signal stack, | ||
2274 | * then this check will enable the signal to be handled anyway. | ||
2275 | */ | ||
2276 | if (current->sas_ss_flags & SS_AUTODISARM) | ||
2277 | return 0; | ||
2278 | |||
2279 | #ifdef CONFIG_STACK_GROWSUP | ||
2280 | return sp >= current->sas_ss_sp && | ||
2281 | sp - current->sas_ss_sp < current->sas_ss_size; | ||
2282 | #else | ||
2283 | return sp > current->sas_ss_sp && | ||
2284 | sp - current->sas_ss_sp <= current->sas_ss_size; | ||
2285 | #endif | ||
2286 | } | ||
2287 | |||
2288 | static inline int sas_ss_flags(unsigned long sp) | ||
2289 | { | ||
2290 | if (!current->sas_ss_size) | ||
2291 | return SS_DISABLE; | ||
2292 | |||
2293 | return on_sig_stack(sp) ? SS_ONSTACK : 0; | ||
2294 | } | ||
2295 | |||
2296 | static inline void sas_ss_reset(struct task_struct *p) | ||
2297 | { | ||
2298 | p->sas_ss_sp = 0; | ||
2299 | p->sas_ss_size = 0; | ||
2300 | p->sas_ss_flags = SS_DISABLE; | ||
2301 | } | ||
2302 | |||
2303 | static inline unsigned long sigsp(unsigned long sp, struct ksignal *ksig) | ||
2304 | { | ||
2305 | if (unlikely((ksig->ka.sa.sa_flags & SA_ONSTACK)) && ! sas_ss_flags(sp)) | ||
2306 | #ifdef CONFIG_STACK_GROWSUP | ||
2307 | return current->sas_ss_sp; | ||
2308 | #else | ||
2309 | return current->sas_ss_sp + current->sas_ss_size; | ||
2310 | #endif | ||
2311 | return sp; | ||
2312 | } | ||
2313 | 1938 | ||
2314 | #ifdef CONFIG_HAVE_COPY_THREAD_TLS | 1939 | #ifdef CONFIG_HAVE_COPY_THREAD_TLS |
2315 | extern int copy_thread_tls(unsigned long, unsigned long, unsigned long, | 1940 | extern int copy_thread_tls(unsigned long, unsigned long, unsigned long, |
@@ -2338,10 +1963,8 @@ static inline void exit_thread(struct task_struct *tsk) | |||
2338 | #endif | 1963 | #endif |
2339 | 1964 | ||
2340 | extern void exit_files(struct task_struct *); | 1965 | extern void exit_files(struct task_struct *); |
2341 | extern void __cleanup_sighand(struct sighand_struct *); | ||
2342 | 1966 | ||
2343 | extern void exit_itimers(struct signal_struct *); | 1967 | extern void exit_itimers(struct signal_struct *); |
2344 | extern void flush_itimer_signals(void); | ||
2345 | 1968 | ||
2346 | extern void do_group_exit(int); | 1969 | extern void do_group_exit(int); |
2347 | 1970 | ||
@@ -2376,81 +1999,6 @@ static inline unsigned long wait_task_inactive(struct task_struct *p, | |||
2376 | } | 1999 | } |
2377 | #endif | 2000 | #endif |
2378 | 2001 | ||
2379 | #define tasklist_empty() \ | ||
2380 | list_empty(&init_task.tasks) | ||
2381 | |||
2382 | #define next_task(p) \ | ||
2383 | list_entry_rcu((p)->tasks.next, struct task_struct, tasks) | ||
2384 | |||
2385 | #define for_each_process(p) \ | ||
2386 | for (p = &init_task ; (p = next_task(p)) != &init_task ; ) | ||
2387 | |||
2388 | extern bool current_is_single_threaded(void); | ||
2389 | |||
2390 | /* | ||
2391 | * Careful: do_each_thread/while_each_thread is a double loop so | ||
2392 | * 'break' will not work as expected - use goto instead. | ||
2393 | */ | ||
2394 | #define do_each_thread(g, t) \ | ||
2395 | for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do | ||
2396 | |||
2397 | #define while_each_thread(g, t) \ | ||
2398 | while ((t = next_thread(t)) != g) | ||
2399 | |||
2400 | #define __for_each_thread(signal, t) \ | ||
2401 | list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node) | ||
2402 | |||
2403 | #define for_each_thread(p, t) \ | ||
2404 | __for_each_thread((p)->signal, t) | ||
2405 | |||
2406 | /* Careful: this is a double loop, 'break' won't work as expected. */ | ||
2407 | #define for_each_process_thread(p, t) \ | ||
2408 | for_each_process(p) for_each_thread(p, t) | ||
2409 | |||
2410 | typedef int (*proc_visitor)(struct task_struct *p, void *data); | ||
2411 | void walk_process_tree(struct task_struct *top, proc_visitor, void *); | ||
2412 | |||
2413 | static inline int get_nr_threads(struct task_struct *tsk) | ||
2414 | { | ||
2415 | return tsk->signal->nr_threads; | ||
2416 | } | ||
2417 | |||
2418 | static inline bool thread_group_leader(struct task_struct *p) | ||
2419 | { | ||
2420 | return p->exit_signal >= 0; | ||
2421 | } | ||
2422 | |||
2423 | /* Do to the insanities of de_thread it is possible for a process | ||
2424 | * to have the pid of the thread group leader without actually being | ||
2425 | * the thread group leader. For iteration through the pids in proc | ||
2426 | * all we care about is that we have a task with the appropriate | ||
2427 | * pid, we don't actually care if we have the right task. | ||
2428 | */ | ||
2429 | static inline bool has_group_leader_pid(struct task_struct *p) | ||
2430 | { | ||
2431 | return task_pid(p) == p->signal->leader_pid; | ||
2432 | } | ||
2433 | |||
2434 | static inline | ||
2435 | bool same_thread_group(struct task_struct *p1, struct task_struct *p2) | ||
2436 | { | ||
2437 | return p1->signal == p2->signal; | ||
2438 | } | ||
2439 | |||
2440 | static inline struct task_struct *next_thread(const struct task_struct *p) | ||
2441 | { | ||
2442 | return list_entry_rcu(p->thread_group.next, | ||
2443 | struct task_struct, thread_group); | ||
2444 | } | ||
2445 | |||
2446 | static inline int thread_group_empty(struct task_struct *p) | ||
2447 | { | ||
2448 | return list_empty(&p->thread_group); | ||
2449 | } | ||
2450 | |||
2451 | #define delay_group_leader(p) \ | ||
2452 | (thread_group_leader(p) && !thread_group_empty(p)) | ||
2453 | |||
2454 | /* | 2002 | /* |
2455 | * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring | 2003 | * Protects ->fs, ->files, ->mm, ->group_info, ->comm, keyring |
2456 | * subscriptions and synchronises with wait4(). Also used in procfs. Also | 2004 | * subscriptions and synchronises with wait4(). Also used in procfs. Also |
@@ -2471,25 +2019,6 @@ static inline void task_unlock(struct task_struct *p) | |||
2471 | spin_unlock(&p->alloc_lock); | 2019 | spin_unlock(&p->alloc_lock); |
2472 | } | 2020 | } |
2473 | 2021 | ||
2474 | extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk, | ||
2475 | unsigned long *flags); | ||
2476 | |||
2477 | static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk, | ||
2478 | unsigned long *flags) | ||
2479 | { | ||
2480 | struct sighand_struct *ret; | ||
2481 | |||
2482 | ret = __lock_task_sighand(tsk, flags); | ||
2483 | (void)__cond_lock(&tsk->sighand->siglock, ret); | ||
2484 | return ret; | ||
2485 | } | ||
2486 | |||
2487 | static inline void unlock_task_sighand(struct task_struct *tsk, | ||
2488 | unsigned long *flags) | ||
2489 | { | ||
2490 | spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); | ||
2491 | } | ||
2492 | |||
2493 | #ifdef CONFIG_THREAD_INFO_IN_TASK | 2022 | #ifdef CONFIG_THREAD_INFO_IN_TASK |
2494 | 2023 | ||
2495 | static inline struct thread_info *task_thread_info(struct task_struct *task) | 2024 | static inline struct thread_info *task_thread_info(struct task_struct *task) |
@@ -2862,28 +2391,6 @@ static inline void mm_update_next_owner(struct mm_struct *mm) | |||
2862 | } | 2391 | } |
2863 | #endif /* CONFIG_MEMCG */ | 2392 | #endif /* CONFIG_MEMCG */ |
2864 | 2393 | ||
2865 | static inline unsigned long task_rlimit(const struct task_struct *tsk, | ||
2866 | unsigned int limit) | ||
2867 | { | ||
2868 | return READ_ONCE(tsk->signal->rlim[limit].rlim_cur); | ||
2869 | } | ||
2870 | |||
2871 | static inline unsigned long task_rlimit_max(const struct task_struct *tsk, | ||
2872 | unsigned int limit) | ||
2873 | { | ||
2874 | return READ_ONCE(tsk->signal->rlim[limit].rlim_max); | ||
2875 | } | ||
2876 | |||
2877 | static inline unsigned long rlimit(unsigned int limit) | ||
2878 | { | ||
2879 | return task_rlimit(current, limit); | ||
2880 | } | ||
2881 | |||
2882 | static inline unsigned long rlimit_max(unsigned int limit) | ||
2883 | { | ||
2884 | return task_rlimit_max(current, limit); | ||
2885 | } | ||
2886 | |||
2887 | #define SCHED_CPUFREQ_RT (1U << 0) | 2394 | #define SCHED_CPUFREQ_RT (1U << 0) |
2888 | #define SCHED_CPUFREQ_DL (1U << 1) | 2395 | #define SCHED_CPUFREQ_DL (1U << 1) |
2889 | #define SCHED_CPUFREQ_IOWAIT (1U << 2) | 2396 | #define SCHED_CPUFREQ_IOWAIT (1U << 2) |
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index c6958a53fef3..53fe5450f431 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h | |||
@@ -8,4 +8,506 @@ | |||
8 | #include <linux/sched/jobctl.h> | 8 | #include <linux/sched/jobctl.h> |
9 | #include <linux/sched/task.h> | 9 | #include <linux/sched/task.h> |
10 | 10 | ||
11 | /* | ||
12 | * Types defining task->signal and task->sighand and APIs using them: | ||
13 | */ | ||
14 | |||
15 | struct sighand_struct { | ||
16 | atomic_t count; | ||
17 | struct k_sigaction action[_NSIG]; | ||
18 | spinlock_t siglock; | ||
19 | wait_queue_head_t signalfd_wqh; | ||
20 | }; | ||
21 | |||
22 | /* | ||
23 | * NOTE! "signal_struct" does not have its own | ||
24 | * locking, because a shared signal_struct always | ||
25 | * implies a shared sighand_struct, so locking | ||
26 | * sighand_struct is always a proper superset of | ||
27 | * the locking of signal_struct. | ||
28 | */ | ||
29 | struct signal_struct { | ||
30 | atomic_t sigcnt; | ||
31 | atomic_t live; | ||
32 | int nr_threads; | ||
33 | struct list_head thread_head; | ||
34 | |||
35 | wait_queue_head_t wait_chldexit; /* for wait4() */ | ||
36 | |||
37 | /* current thread group signal load-balancing target: */ | ||
38 | struct task_struct *curr_target; | ||
39 | |||
40 | /* shared signal handling: */ | ||
41 | struct sigpending shared_pending; | ||
42 | |||
43 | /* thread group exit support */ | ||
44 | int group_exit_code; | ||
45 | /* overloaded: | ||
46 | * - notify group_exit_task when ->count is equal to notify_count | ||
47 | * - everyone except group_exit_task is stopped during signal delivery | ||
48 | * of fatal signals, group_exit_task processes the signal. | ||
49 | */ | ||
50 | int notify_count; | ||
51 | struct task_struct *group_exit_task; | ||
52 | |||
53 | /* thread group stop support, overloads group_exit_code too */ | ||
54 | int group_stop_count; | ||
55 | unsigned int flags; /* see SIGNAL_* flags below */ | ||
56 | |||
57 | /* | ||
58 | * PR_SET_CHILD_SUBREAPER marks a process, like a service | ||
59 | * manager, to re-parent orphan (double-forking) child processes | ||
60 | * to this process instead of 'init'. The service manager is | ||
61 | * able to receive SIGCHLD signals and is able to investigate | ||
62 | * the process until it calls wait(). All children of this | ||
63 | * process will inherit a flag if they should look for a | ||
64 | * child_subreaper process at exit. | ||
65 | */ | ||
66 | unsigned int is_child_subreaper:1; | ||
67 | unsigned int has_child_subreaper:1; | ||
68 | |||
69 | #ifdef CONFIG_POSIX_TIMERS | ||
70 | |||
71 | /* POSIX.1b Interval Timers */ | ||
72 | int posix_timer_id; | ||
73 | struct list_head posix_timers; | ||
74 | |||
75 | /* ITIMER_REAL timer for the process */ | ||
76 | struct hrtimer real_timer; | ||
77 | ktime_t it_real_incr; | ||
78 | |||
79 | /* | ||
80 | * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use | ||
81 | * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these | ||
82 | * values are defined to 0 and 1 respectively | ||
83 | */ | ||
84 | struct cpu_itimer it[2]; | ||
85 | |||
86 | /* | ||
87 | * Thread group totals for process CPU timers. | ||
88 | * See thread_group_cputimer(), et al, for details. | ||
89 | */ | ||
90 | struct thread_group_cputimer cputimer; | ||
91 | |||
92 | /* Earliest-expiration cache. */ | ||
93 | struct task_cputime cputime_expires; | ||
94 | |||
95 | struct list_head cpu_timers[3]; | ||
96 | |||
97 | #endif | ||
98 | |||
99 | struct pid *leader_pid; | ||
100 | |||
101 | #ifdef CONFIG_NO_HZ_FULL | ||
102 | atomic_t tick_dep_mask; | ||
103 | #endif | ||
104 | |||
105 | struct pid *tty_old_pgrp; | ||
106 | |||
107 | /* boolean value for session group leader */ | ||
108 | int leader; | ||
109 | |||
110 | struct tty_struct *tty; /* NULL if no tty */ | ||
111 | |||
112 | #ifdef CONFIG_SCHED_AUTOGROUP | ||
113 | struct autogroup *autogroup; | ||
114 | #endif | ||
115 | /* | ||
116 | * Cumulative resource counters for dead threads in the group, | ||
117 | * and for reaped dead child processes forked by this group. | ||
118 | * Live threads maintain their own counters and add to these | ||
119 | * in __exit_signal, except for the group leader. | ||
120 | */ | ||
121 | seqlock_t stats_lock; | ||
122 | u64 utime, stime, cutime, cstime; | ||
123 | u64 gtime; | ||
124 | u64 cgtime; | ||
125 | struct prev_cputime prev_cputime; | ||
126 | unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw; | ||
127 | unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt; | ||
128 | unsigned long inblock, oublock, cinblock, coublock; | ||
129 | unsigned long maxrss, cmaxrss; | ||
130 | struct task_io_accounting ioac; | ||
131 | |||
132 | /* | ||
133 | * Cumulative ns of schedule CPU time fo dead threads in the | ||
134 | * group, not including a zombie group leader, (This only differs | ||
135 | * from jiffies_to_ns(utime + stime) if sched_clock uses something | ||
136 | * other than jiffies.) | ||
137 | */ | ||
138 | unsigned long long sum_sched_runtime; | ||
139 | |||
140 | /* | ||
141 | * We don't bother to synchronize most readers of this at all, | ||
142 | * because there is no reader checking a limit that actually needs | ||
143 | * to get both rlim_cur and rlim_max atomically, and either one | ||
144 | * alone is a single word that can safely be read normally. | ||
145 | * getrlimit/setrlimit use task_lock(current->group_leader) to | ||
146 | * protect this instead of the siglock, because they really | ||
147 | * have no need to disable irqs. | ||
148 | */ | ||
149 | struct rlimit rlim[RLIM_NLIMITS]; | ||
150 | |||
151 | #ifdef CONFIG_BSD_PROCESS_ACCT | ||
152 | struct pacct_struct pacct; /* per-process accounting information */ | ||
153 | #endif | ||
154 | #ifdef CONFIG_TASKSTATS | ||
155 | struct taskstats *stats; | ||
156 | #endif | ||
157 | #ifdef CONFIG_AUDIT | ||
158 | unsigned audit_tty; | ||
159 | struct tty_audit_buf *tty_audit_buf; | ||
160 | #endif | ||
161 | |||
162 | /* | ||
163 | * Thread is the potential origin of an oom condition; kill first on | ||
164 | * oom | ||
165 | */ | ||
166 | bool oom_flag_origin; | ||
167 | short oom_score_adj; /* OOM kill score adjustment */ | ||
168 | short oom_score_adj_min; /* OOM kill score adjustment min value. | ||
169 | * Only settable by CAP_SYS_RESOURCE. */ | ||
170 | struct mm_struct *oom_mm; /* recorded mm when the thread group got | ||
171 | * killed by the oom killer */ | ||
172 | |||
173 | struct mutex cred_guard_mutex; /* guard against foreign influences on | ||
174 | * credential calculations | ||
175 | * (notably. ptrace) */ | ||
176 | }; | ||
177 | |||
178 | /* | ||
179 | * Bits in flags field of signal_struct. | ||
180 | */ | ||
181 | #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ | ||
182 | #define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */ | ||
183 | #define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */ | ||
184 | #define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */ | ||
185 | /* | ||
186 | * Pending notifications to parent. | ||
187 | */ | ||
188 | #define SIGNAL_CLD_STOPPED 0x00000010 | ||
189 | #define SIGNAL_CLD_CONTINUED 0x00000020 | ||
190 | #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED) | ||
191 | |||
192 | #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */ | ||
193 | |||
194 | #define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \ | ||
195 | SIGNAL_STOP_CONTINUED) | ||
196 | |||
197 | static inline void signal_set_stop_flags(struct signal_struct *sig, | ||
198 | unsigned int flags) | ||
199 | { | ||
200 | WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP)); | ||
201 | sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags; | ||
202 | } | ||
203 | |||
204 | /* If true, all threads except ->group_exit_task have pending SIGKILL */ | ||
205 | static inline int signal_group_exit(const struct signal_struct *sig) | ||
206 | { | ||
207 | return (sig->flags & SIGNAL_GROUP_EXIT) || | ||
208 | (sig->group_exit_task != NULL); | ||
209 | } | ||
210 | |||
211 | extern void flush_signals(struct task_struct *); | ||
212 | extern void ignore_signals(struct task_struct *); | ||
213 | extern void flush_signal_handlers(struct task_struct *, int force_default); | ||
214 | extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); | ||
215 | |||
216 | static inline int kernel_dequeue_signal(siginfo_t *info) | ||
217 | { | ||
218 | struct task_struct *tsk = current; | ||
219 | siginfo_t __info; | ||
220 | int ret; | ||
221 | |||
222 | spin_lock_irq(&tsk->sighand->siglock); | ||
223 | ret = dequeue_signal(tsk, &tsk->blocked, info ?: &__info); | ||
224 | spin_unlock_irq(&tsk->sighand->siglock); | ||
225 | |||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | static inline void kernel_signal_stop(void) | ||
230 | { | ||
231 | spin_lock_irq(¤t->sighand->siglock); | ||
232 | if (current->jobctl & JOBCTL_STOP_DEQUEUED) | ||
233 | __set_current_state(TASK_STOPPED); | ||
234 | spin_unlock_irq(¤t->sighand->siglock); | ||
235 | |||
236 | schedule(); | ||
237 | } | ||
238 | extern int send_sig_info(int, struct siginfo *, struct task_struct *); | ||
239 | extern int force_sigsegv(int, struct task_struct *); | ||
240 | extern int force_sig_info(int, struct siginfo *, struct task_struct *); | ||
241 | extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp); | ||
242 | extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid); | ||
243 | extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *, | ||
244 | const struct cred *, u32); | ||
245 | extern int kill_pgrp(struct pid *pid, int sig, int priv); | ||
246 | extern int kill_pid(struct pid *pid, int sig, int priv); | ||
247 | extern int kill_proc_info(int, struct siginfo *, pid_t); | ||
248 | extern __must_check bool do_notify_parent(struct task_struct *, int); | ||
249 | extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); | ||
250 | extern void force_sig(int, struct task_struct *); | ||
251 | extern int send_sig(int, struct task_struct *, int); | ||
252 | extern int zap_other_threads(struct task_struct *p); | ||
253 | extern struct sigqueue *sigqueue_alloc(void); | ||
254 | extern void sigqueue_free(struct sigqueue *); | ||
255 | extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); | ||
256 | extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); | ||
257 | |||
258 | #ifdef TIF_RESTORE_SIGMASK | ||
259 | /* | ||
260 | * Legacy restore_sigmask accessors. These are inefficient on | ||
261 | * SMP architectures because they require atomic operations. | ||
262 | */ | ||
263 | |||
264 | /** | ||
265 | * set_restore_sigmask() - make sure saved_sigmask processing gets done | ||
266 | * | ||
267 | * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code | ||
268 | * will run before returning to user mode, to process the flag. For | ||
269 | * all callers, TIF_SIGPENDING is already set or it's no harm to set | ||
270 | * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the | ||
271 | * arch code will notice on return to user mode, in case those bits | ||
272 | * are scarce. We set TIF_SIGPENDING here to ensure that the arch | ||
273 | * signal code always gets run when TIF_RESTORE_SIGMASK is set. | ||
274 | */ | ||
275 | static inline void set_restore_sigmask(void) | ||
276 | { | ||
277 | set_thread_flag(TIF_RESTORE_SIGMASK); | ||
278 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | ||
279 | } | ||
280 | static inline void clear_restore_sigmask(void) | ||
281 | { | ||
282 | clear_thread_flag(TIF_RESTORE_SIGMASK); | ||
283 | } | ||
284 | static inline bool test_restore_sigmask(void) | ||
285 | { | ||
286 | return test_thread_flag(TIF_RESTORE_SIGMASK); | ||
287 | } | ||
288 | static inline bool test_and_clear_restore_sigmask(void) | ||
289 | { | ||
290 | return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK); | ||
291 | } | ||
292 | |||
293 | #else /* TIF_RESTORE_SIGMASK */ | ||
294 | |||
295 | /* Higher-quality implementation, used if TIF_RESTORE_SIGMASK doesn't exist. */ | ||
296 | static inline void set_restore_sigmask(void) | ||
297 | { | ||
298 | current->restore_sigmask = true; | ||
299 | WARN_ON(!test_thread_flag(TIF_SIGPENDING)); | ||
300 | } | ||
301 | static inline void clear_restore_sigmask(void) | ||
302 | { | ||
303 | current->restore_sigmask = false; | ||
304 | } | ||
305 | static inline bool test_restore_sigmask(void) | ||
306 | { | ||
307 | return current->restore_sigmask; | ||
308 | } | ||
309 | static inline bool test_and_clear_restore_sigmask(void) | ||
310 | { | ||
311 | if (!current->restore_sigmask) | ||
312 | return false; | ||
313 | current->restore_sigmask = false; | ||
314 | return true; | ||
315 | } | ||
316 | #endif | ||
317 | |||
318 | static inline void restore_saved_sigmask(void) | ||
319 | { | ||
320 | if (test_and_clear_restore_sigmask()) | ||
321 | __set_current_blocked(¤t->saved_sigmask); | ||
322 | } | ||
323 | |||
324 | static inline sigset_t *sigmask_to_save(void) | ||
325 | { | ||
326 | sigset_t *res = ¤t->blocked; | ||
327 | if (unlikely(test_restore_sigmask())) | ||
328 | res = ¤t->saved_sigmask; | ||
329 | return res; | ||
330 | } | ||
331 | |||
332 | static inline int kill_cad_pid(int sig, int priv) | ||
333 | { | ||
334 | return kill_pid(cad_pid, sig, priv); | ||
335 | } | ||
336 | |||
337 | /* These can be the second arg to send_sig_info/send_group_sig_info. */ | ||
338 | #define SEND_SIG_NOINFO ((struct siginfo *) 0) | ||
339 | #define SEND_SIG_PRIV ((struct siginfo *) 1) | ||
340 | #define SEND_SIG_FORCED ((struct siginfo *) 2) | ||
341 | |||
342 | /* | ||
343 | * True if we are on the alternate signal stack. | ||
344 | */ | ||
345 | static inline int on_sig_stack(unsigned long sp) | ||
346 | { | ||
347 | /* | ||
348 | * If the signal stack is SS_AUTODISARM then, by construction, we | ||
349 | * can't be on the signal stack unless user code deliberately set | ||
350 | * SS_AUTODISARM when we were already on it. | ||
351 | * | ||
352 | * This improves reliability: if user state gets corrupted such that | ||
353 | * the stack pointer points very close to the end of the signal stack, | ||
354 | * then this check will enable the signal to be handled anyway. | ||
355 | */ | ||
356 | if (current->sas_ss_flags & SS_AUTODISARM) | ||
357 | return 0; | ||
358 | |||
359 | #ifdef CONFIG_STACK_GROWSUP | ||
360 | return sp >= current->sas_ss_sp && | ||
361 | sp - current->sas_ss_sp < current->sas_ss_size; | ||
362 | #else | ||
363 | return sp > current->sas_ss_sp && | ||
364 | sp - current->sas_ss_sp <= current->sas_ss_size; | ||
365 | #endif | ||
366 | } | ||
367 | |||
368 | static inline int sas_ss_flags(unsigned long sp) | ||
369 | { | ||
370 | if (!current->sas_ss_size) | ||
371 | return SS_DISABLE; | ||
372 | |||
373 | return on_sig_stack(sp) ? SS_ONSTACK : 0; | ||
374 | } | ||
375 | |||
376 | static inline void sas_ss_reset(struct task_struct *p) | ||
377 | { | ||
378 | p->sas_ss_sp = 0; | ||
379 | p->sas_ss_size = 0; | ||
380 | p->sas_ss_flags = SS_DISABLE; | ||
381 | } | ||
382 | |||
383 | static inline unsigned long sigsp(unsigned long sp, struct ksignal *ksig) | ||
384 | { | ||
385 | if (unlikely((ksig->ka.sa.sa_flags & SA_ONSTACK)) && ! sas_ss_flags(sp)) | ||
386 | #ifdef CONFIG_STACK_GROWSUP | ||
387 | return current->sas_ss_sp; | ||
388 | #else | ||
389 | return current->sas_ss_sp + current->sas_ss_size; | ||
390 | #endif | ||
391 | return sp; | ||
392 | } | ||
393 | |||
394 | extern void __cleanup_sighand(struct sighand_struct *); | ||
395 | extern void flush_itimer_signals(void); | ||
396 | |||
397 | #define tasklist_empty() \ | ||
398 | list_empty(&init_task.tasks) | ||
399 | |||
400 | #define next_task(p) \ | ||
401 | list_entry_rcu((p)->tasks.next, struct task_struct, tasks) | ||
402 | |||
403 | #define for_each_process(p) \ | ||
404 | for (p = &init_task ; (p = next_task(p)) != &init_task ; ) | ||
405 | |||
406 | extern bool current_is_single_threaded(void); | ||
407 | |||
408 | /* | ||
409 | * Careful: do_each_thread/while_each_thread is a double loop so | ||
410 | * 'break' will not work as expected - use goto instead. | ||
411 | */ | ||
412 | #define do_each_thread(g, t) \ | ||
413 | for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do | ||
414 | |||
415 | #define while_each_thread(g, t) \ | ||
416 | while ((t = next_thread(t)) != g) | ||
417 | |||
418 | #define __for_each_thread(signal, t) \ | ||
419 | list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node) | ||
420 | |||
421 | #define for_each_thread(p, t) \ | ||
422 | __for_each_thread((p)->signal, t) | ||
423 | |||
424 | /* Careful: this is a double loop, 'break' won't work as expected. */ | ||
425 | #define for_each_process_thread(p, t) \ | ||
426 | for_each_process(p) for_each_thread(p, t) | ||
427 | |||
428 | typedef int (*proc_visitor)(struct task_struct *p, void *data); | ||
429 | void walk_process_tree(struct task_struct *top, proc_visitor, void *); | ||
430 | |||
431 | static inline int get_nr_threads(struct task_struct *tsk) | ||
432 | { | ||
433 | return tsk->signal->nr_threads; | ||
434 | } | ||
435 | |||
436 | static inline bool thread_group_leader(struct task_struct *p) | ||
437 | { | ||
438 | return p->exit_signal >= 0; | ||
439 | } | ||
440 | |||
441 | /* Do to the insanities of de_thread it is possible for a process | ||
442 | * to have the pid of the thread group leader without actually being | ||
443 | * the thread group leader. For iteration through the pids in proc | ||
444 | * all we care about is that we have a task with the appropriate | ||
445 | * pid, we don't actually care if we have the right task. | ||
446 | */ | ||
447 | static inline bool has_group_leader_pid(struct task_struct *p) | ||
448 | { | ||
449 | return task_pid(p) == p->signal->leader_pid; | ||
450 | } | ||
451 | |||
452 | static inline | ||
453 | bool same_thread_group(struct task_struct *p1, struct task_struct *p2) | ||
454 | { | ||
455 | return p1->signal == p2->signal; | ||
456 | } | ||
457 | |||
458 | static inline struct task_struct *next_thread(const struct task_struct *p) | ||
459 | { | ||
460 | return list_entry_rcu(p->thread_group.next, | ||
461 | struct task_struct, thread_group); | ||
462 | } | ||
463 | |||
464 | static inline int thread_group_empty(struct task_struct *p) | ||
465 | { | ||
466 | return list_empty(&p->thread_group); | ||
467 | } | ||
468 | |||
469 | #define delay_group_leader(p) \ | ||
470 | (thread_group_leader(p) && !thread_group_empty(p)) | ||
471 | |||
472 | extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk, | ||
473 | unsigned long *flags); | ||
474 | |||
475 | static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk, | ||
476 | unsigned long *flags) | ||
477 | { | ||
478 | struct sighand_struct *ret; | ||
479 | |||
480 | ret = __lock_task_sighand(tsk, flags); | ||
481 | (void)__cond_lock(&tsk->sighand->siglock, ret); | ||
482 | return ret; | ||
483 | } | ||
484 | |||
485 | static inline void unlock_task_sighand(struct task_struct *tsk, | ||
486 | unsigned long *flags) | ||
487 | { | ||
488 | spin_unlock_irqrestore(&tsk->sighand->siglock, *flags); | ||
489 | } | ||
490 | |||
491 | static inline unsigned long task_rlimit(const struct task_struct *tsk, | ||
492 | unsigned int limit) | ||
493 | { | ||
494 | return READ_ONCE(tsk->signal->rlim[limit].rlim_cur); | ||
495 | } | ||
496 | |||
497 | static inline unsigned long task_rlimit_max(const struct task_struct *tsk, | ||
498 | unsigned int limit) | ||
499 | { | ||
500 | return READ_ONCE(tsk->signal->rlim[limit].rlim_max); | ||
501 | } | ||
502 | |||
503 | static inline unsigned long rlimit(unsigned int limit) | ||
504 | { | ||
505 | return task_rlimit(current, limit); | ||
506 | } | ||
507 | |||
508 | static inline unsigned long rlimit_max(unsigned int limit) | ||
509 | { | ||
510 | return task_rlimit_max(current, limit); | ||
511 | } | ||
512 | |||
11 | #endif /* _LINUX_SCHED_SIGNAL_H */ | 513 | #endif /* _LINUX_SCHED_SIGNAL_H */ |
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index fc34bcf2329f..08d2cb605101 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <linux/sort.h> | 5 | #include <linux/sort.h> |
6 | #include <linux/delay.h> | 6 | #include <linux/delay.h> |
7 | #include <linux/mm.h> | 7 | #include <linux/mm.h> |
8 | #include <linux/sched/signal.h> | ||
8 | #include <linux/slab.h> | 9 | #include <linux/slab.h> |
9 | #include <linux/vmalloc.h> | 10 | #include <linux/vmalloc.h> |
10 | #include <linux/delayacct.h> | 11 | #include <linux/delayacct.h> |
diff --git a/mm/vmalloc.c b/mm/vmalloc.c index be93949b4885..b4024d688f38 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c | |||
@@ -12,7 +12,7 @@ | |||
12 | #include <linux/mm.h> | 12 | #include <linux/mm.h> |
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/highmem.h> | 14 | #include <linux/highmem.h> |
15 | #include <linux/sched.h> | 15 | #include <linux/sched/signal.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/spinlock.h> | 17 | #include <linux/spinlock.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 5d4208ad029e..85837ab90e89 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <linux/inetdevice.h> | 27 | #include <linux/inetdevice.h> |
28 | #include <linux/workqueue.h> | 28 | #include <linux/workqueue.h> |
29 | #include <linux/in.h> | 29 | #include <linux/in.h> |
30 | #include <linux/sched/signal.h> | ||
31 | |||
30 | #include <net/sock.h> | 32 | #include <net/sock.h> |
31 | #include <net/tcp.h> | 33 | #include <net/tcp.h> |
32 | #include <net/smc.h> | 34 | #include <net/smc.h> |
diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c index cc6b6f8651eb..e41f594a1e1d 100644 --- a/net/smc/smc_clc.c +++ b/net/smc/smc_clc.c | |||
@@ -11,6 +11,8 @@ | |||
11 | 11 | ||
12 | #include <linux/in.h> | 12 | #include <linux/in.h> |
13 | #include <linux/if_ether.h> | 13 | #include <linux/if_ether.h> |
14 | #include <linux/sched/signal.h> | ||
15 | |||
14 | #include <net/sock.h> | 16 | #include <net/sock.h> |
15 | #include <net/tcp.h> | 17 | #include <net/tcp.h> |
16 | 18 | ||
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c index 03dfcc6b7661..67a71d170bed 100644 --- a/net/smc/smc_close.c +++ b/net/smc/smc_close.c | |||
@@ -9,6 +9,8 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/workqueue.h> | 11 | #include <linux/workqueue.h> |
12 | #include <linux/sched/signal.h> | ||
13 | |||
12 | #include <net/sock.h> | 14 | #include <net/sock.h> |
13 | 15 | ||
14 | #include "smc.h" | 16 | #include "smc.h" |
diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c index 5d1878732f46..c4ef9a4ec569 100644 --- a/net/smc/smc_rx.c +++ b/net/smc/smc_rx.c | |||
@@ -11,6 +11,8 @@ | |||
11 | 11 | ||
12 | #include <linux/net.h> | 12 | #include <linux/net.h> |
13 | #include <linux/rcupdate.h> | 13 | #include <linux/rcupdate.h> |
14 | #include <linux/sched/signal.h> | ||
15 | |||
14 | #include <net/sock.h> | 16 | #include <net/sock.h> |
15 | 17 | ||
16 | #include "smc.h" | 18 | #include "smc.h" |
diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index 6e73b28915ea..69a0013dd25c 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c | |||
@@ -15,6 +15,8 @@ | |||
15 | #include <linux/net.h> | 15 | #include <linux/net.h> |
16 | #include <linux/rcupdate.h> | 16 | #include <linux/rcupdate.h> |
17 | #include <linux/workqueue.h> | 17 | #include <linux/workqueue.h> |
18 | #include <linux/sched/signal.h> | ||
19 | |||
18 | #include <net/sock.h> | 20 | #include <net/sock.h> |
19 | 21 | ||
20 | #include "smc.h" | 22 | #include "smc.h" |