linux-uconsole/kernel/sched
Eric Biggers e50fe1de2f UPSTREAM: wait: add wake_up_pollfree()
commit 42288cb44c upstream.

Several ->poll() implementations are special in that they use a
waitqueue whose lifetime is the current task, rather than the struct
file as is normally the case.  This is okay for blocking polls, since a
blocking poll occurs within one task; however, non-blocking polls
require another solution.  This solution is for the queue to be cleared
before it is freed, using 'wake_up_poll(wq, EPOLLHUP | POLLFREE);'.

However, that has a bug: wake_up_poll() calls __wake_up() with
nr_exclusive=1.  Therefore, if there are multiple "exclusive" waiters,
and the wakeup function for the first one returns a positive value, only
that one will be called.  That's *not* what's needed for POLLFREE;
POLLFREE is special in that it really needs to wake up everyone.

Considering the three non-blocking poll systems:

- io_uring poll doesn't handle POLLFREE at all, so it is broken anyway.

- aio poll is unaffected, since it doesn't support exclusive waits.
  However, that's fragile, as someone could add this feature later.

- epoll doesn't appear to be broken by this, since its wakeup function
  returns 0 when it sees POLLFREE.  But this is fragile.

Although there is a workaround (see epoll), it's better to define a
function which always sends POLLFREE to all waiters.  Add such a
function.  Also make it verify that the queue really becomes empty after
all waiters have been woken up.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20211209010455.42744-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 185125206
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I4f69da5bbbad53975024d027fa1bbe22522c6efe
2021-12-14 13:54:22 +01:00
..
autogroup.c
autogroup.h
clock.c
completion.c
core.c UPSTREAM: sched/core: Mitigate race cpus_share_cache()/update_top_cache_domain() 2021-12-01 11:10:58 +00:00
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq.c ANDROID: android: Export symbols for invoking cpufreq_update_util() 2021-06-29 10:44:12 +00:00
cpufreq_schedutil.c ANDROID: sched: Add vendor hooks to compute new cpu freq. 2021-04-23 18:42:38 -07:00
cpupri.c ANDROID: sched: Export symbol for vendor RT hook funcion 2021-01-12 12:57:37 -08:00
cpupri.h
cputime.c ANDROID: vendor_hooks: Add hooks for account irqtime process tick 2021-05-13 08:26:15 +00:00
deadline.c This is the 5.10.65 stable release 2021-09-15 14:16:47 +02:00
debug.c This is the 5.10.44 stable release 2021-06-16 13:14:03 +02:00
fair.c Revert "sched/fair: Keep load_avg and load_sum synced" 2021-11-16 21:07:58 +00:00
features.h Revert "Revert "sched,fair: Alternative sched_slice()"" 2021-05-21 13:17:06 -07:00
idle.c Merge 5.10.20 into android12-5.10 2021-03-07 12:33:33 +01:00
isolation.c
loadavg.c
Makefile
membarrier.c sched/membarrier: fix missing local execution of ipi_sync_rq_state() 2021-03-17 17:06:35 +01:00
pelt.c ANDROID: sched: add a helper function to change PELT half-life 2021-08-07 00:03:23 +08:00
pelt.h sched/fair: Fix util_est UTIL_AVG_UNCHANGED handling 2021-06-16 12:01:46 +02:00
psi.c Merge branch 'android12-5.10' into android12-5.10-lts 2021-07-15 17:17:09 +02:00
rt.c ANDROID: vendor_hooks: Add hooks to record the time of the process in various states 2021-11-11 22:15:49 +08:00
sched-pelt.h ANDROID: sched: pelt: Fix the PELT arrays 2021-03-04 11:53:51 +00:00
sched.h sched/deadline: Fix reset_on_fork reporting of DL tasks 2021-09-15 09:50:24 +02:00
smp.h
stats.c
stats.h
stop_task.c
swait.c
topology.c ANDROID: vendor_hooks: Add hooks for scheduler 2021-03-16 09:08:22 +00:00
wait.c UPSTREAM: wait: add wake_up_pollfree() 2021-12-14 13:54:22 +01:00
wait_bit.c