Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

binder: use wake_up_pollfree()

wake_up_poll() uses nr_exclusive=1, so it's not guaranteed to wake up
all exclusive waiters. Yet, POLLFREE *must* wake up all waiters. epoll
and aio poll are fortunately not affected by this, but it's very
fragile. Thus, the new function wake_up_pollfree() has been introduced.

Convert binder to use wake_up_pollfree().

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Fixes: f5cb779ba163 ("ANDROID: binder: remove waitqueue when thread exits.")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20211209010455.42744-3-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

+9 -12
+9 -12
drivers/android/binder.c
··· 4422 4422 __release(&t->lock); 4423 4423 4424 4424 /* 4425 - * If this thread used poll, make sure we remove the waitqueue 4426 - * from any epoll data structures holding it with POLLFREE. 4427 - * waitqueue_active() is safe to use here because we're holding 4428 - * the inner lock. 4425 + * If this thread used poll, make sure we remove the waitqueue from any 4426 + * poll data structures holding it. 4429 4427 */ 4430 - if ((thread->looper & BINDER_LOOPER_STATE_POLL) && 4431 - waitqueue_active(&thread->wait)) { 4432 - wake_up_poll(&thread->wait, EPOLLHUP | POLLFREE); 4433 - } 4428 + if (thread->looper & BINDER_LOOPER_STATE_POLL) 4429 + wake_up_pollfree(&thread->wait); 4434 4430 4435 4431 binder_inner_proc_unlock(thread->proc); 4436 4432 4437 4433 /* 4438 - * This is needed to avoid races between wake_up_poll() above and 4439 - * and ep_remove_waitqueue() called for other reasons (eg the epoll file 4440 - * descriptor being closed); ep_remove_waitqueue() holds an RCU read 4441 - * lock, so we can be sure it's done after calling synchronize_rcu(). 4434 + * This is needed to avoid races between wake_up_pollfree() above and 4435 + * someone else removing the last entry from the queue for other reasons 4436 + * (e.g. ep_remove_wait_queue() being called due to an epoll file 4437 + * descriptor being closed). Such other users hold an RCU read lock, so 4438 + * we can be sure they're done after we call synchronize_rcu(). 4442 4439 */ 4443 4440 if (thread->looper & BINDER_LOOPER_STATE_POLL) 4444 4441 synchronize_rcu();