This simplifies signalfd code, by avoiding it to remain attached to the sighand during its lifetime. In this way, the signalfd remain attached to the sighand only during poll(2) (and select and epoll) and read(2). This also allows to remove all the custom "tsk == current" checks in kernel/signal.c, since dequeue_signal() will only be called by "current". I think this is also what Ben was suggesting time ago. The external effect of this, is that a thread can extract only its own private signals and the group ones. I think this is an acceptable behaviour, in that those are the signals the thread would be able to fetch w/out signalfd.
Showing the changes to include/linux (3 of 8 files). Show all
Unified · Split
| @@ -86,7 +86,7 @@ extern struct nsproxy init_nsproxy; · 85 unmodified lines | ||
| 86 | 86 | .count = ATOMIC_INIT(1), \ |
| 87 | 87 | .action = { { { .sa_handler = NULL, } }, }, \ |
| 88 | 88 | .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \ |
| 89 | − .signalfd_list = LIST_HEAD_INIT(sighand.signalfd_list), \ | |
| 89 | + .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \ | |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | extern struct group_info init_groups; |
| @@ -438,7 +438,7 @@ struct sighand_struct { · 437 unmodified lines | ||
| 438 | 438 | atomic_t count; |
| 439 | 439 | struct k_sigaction action[_NSIG]; |
| 440 | 440 | spinlock_t siglock; |
| 441 | − struct list_head signalfd_list; | |
| 441 | + wait_queue_head_t signalfd_wqh; | |
| 442 | 442 | }; |
| 443 | 443 | |
| 444 | 444 | struct pacct_struct { |
| @@ -45,49 +45,17 @@ struct signalfd_siginfo { · 44 unmodified lines | ||
| 45 | 45 | #ifdef CONFIG_SIGNALFD |
| 46 | 46 | |
| 47 | 47 | /* |
| 48 | − * Deliver the signal to listening signalfd. This must be called | |
| 49 | − * with the sighand lock held. Same are the following that end up | |
| 50 | − * calling signalfd_deliver(). | |
| 51 | − */ | |
| 52 | −void signalfd_deliver(struct task_struct *tsk, int sig); | |
| 53 | − | |
| 54 | −/* | |
| 55 | − * No need to fall inside signalfd_deliver() if no signal listeners | |
| 56 | − * are available. | |
| 48 | + * Deliver the signal to listening signalfd. | |
| 57 | 49 | */ |
| 58 | 50 | static inline void signalfd_notify(struct task_struct *tsk, int sig) |
| 59 | 51 | { |
| 60 | − if (unlikely(!list_empty(&tsk->sighand->signalfd_list))) | |
| 61 | − signalfd_deliver(tsk, sig); | |
| 62 | −} | |
| 63 | − | |
| 64 | −/* | |
| 65 | − * The signal -1 is used to notify the signalfd that the sighand | |
| 66 | − * is on its way to be detached. | |
| 67 | − */ | |
| 68 | −static inline void signalfd_detach_locked(struct task_struct *tsk) | |
| 69 | −{ | |
| 70 | − if (unlikely(!list_empty(&tsk->sighand->signalfd_list))) | |
| 71 | − signalfd_deliver(tsk, -1); | |
| 72 | −} | |
| 73 | − | |
| 74 | −static inline void signalfd_detach(struct task_struct *tsk) | |
| 75 | −{ | |
| 76 | − struct sighand_struct *sighand = tsk->sighand; | |
| 77 | − | |
| 78 | − if (unlikely(!list_empty(&sighand->signalfd_list))) { | |
| 79 | − spin_lock_irq(&sighand->siglock); | |
| 80 | − signalfd_deliver(tsk, -1); | |
| 81 | − spin_unlock_irq(&sighand->siglock); | |
| 82 | − } | |
| 52 | + if (unlikely(waitqueue_active(&tsk->sighand->signalfd_wqh))) | |
| 53 | + wake_up(&tsk->sighand->signalfd_wqh); | |
| 83 | 54 | } |
| 84 | 55 | |
| 85 | 56 | #else /* CONFIG_SIGNALFD */ |
| 86 | 57 | |
| 87 | −#define signalfd_deliver(t, s) do { } while (0) | |
| 88 | −#define signalfd_notify(t, s) do { } while (0) | |
| 89 | −#define signalfd_detach_locked(t) do { } while (0) | |
| 90 | −#define signalfd_detach(t) do { } while (0) | |
| 58 | +static inline void signalfd_notify(struct task_struct *tsk, int sig) { } | |
| 91 | 59 | |
| 92 | 60 | #endif /* CONFIG_SIGNALFD */ |
| 93 | 61 | |