diff options
author | Martin Lau <kafai@fb.com> | 2014-06-09 23:06:42 -0700 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2014-08-06 18:07:37 +0100 |
commit | 0be53320ade39c226e9781c7ad72671625df6edf (patch) | |
tree | 024e2d2fa0045d463506eaf6b5673fb22be4a58f | |
parent | 1179c8f1caca90caf4ce0eec54b499de4f1551c4 (diff) | |
download | lwn-0be53320ade39c226e9781c7ad72671625df6edf.tar.gz lwn-0be53320ade39c226e9781c7ad72671625df6edf.zip |
ring-buffer: Fix polling on trace_pipe
commit 97b8ee845393701edc06e27ccec2876ff9596019 upstream.
ring_buffer_poll_wait() should always put the poll_table to its wait_queue
even there is immediate data available. Otherwise, the following epoll and
read sequence will eventually hang forever:
1. Put some data to make the trace_pipe ring_buffer read ready first
2. epoll_ctl(efd, EPOLL_CTL_ADD, trace_pipe_fd, ee)
3. epoll_wait()
4. read(trace_pipe_fd) till EAGAIN
5. Add some more data to the trace_pipe ring_buffer
6. epoll_wait() -> this epoll_wait() will block forever
~ During the epoll_ctl(efd, EPOLL_CTL_ADD,...) call in step 2,
ring_buffer_poll_wait() returns immediately without adding poll_table,
which has poll_table->_qproc pointing to ep_poll_callback(), to its
wait_queue.
~ During the epoll_wait() call in step 3 and step 6,
ring_buffer_poll_wait() cannot add ep_poll_callback() to its wait_queue
because the poll_table->_qproc is NULL and it is how epoll works.
~ When there is new data available in step 6, ring_buffer does not know
it has to call ep_poll_callback() because it is not in its wait queue.
Hence, block forever.
Other poll implementation seems to call poll_wait() unconditionally as the very
first thing to do. For example, tcp_poll() in tcp.c.
Link: http://lkml.kernel.org/p/20140610060637.GA14045@devbig242.prn2.facebook.com
Fixes: 2a2cc8f7c4d0 "ftrace: allow the event pipe to be polled"
Reviewed-by: Chris Mason <clm@fb.com>
Signed-off-by: Martin Lau <kafai@fb.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
[bwh: Backported to 3.2: the poll implementation looks rather different
but does have a conditional return before and after the poll_wait() call;
delete the return before it.]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | kernel/trace/trace.c | 2 |
1 files changed, 0 insertions, 2 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index c5a12a7d1287..0c348a63be49 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3244,8 +3244,6 @@ tracing_poll_pipe(struct file *filp, poll_table *poll_table) */ return POLLIN | POLLRDNORM; } else { - if (!trace_empty(iter)) - return POLLIN | POLLRDNORM; poll_wait(filp, &trace_wait, poll_table); if (!trace_empty(iter)) return POLLIN | POLLRDNORM; |