Skip to contentSkip to conversation

"af_unix: conditionally use freezable blocking calls in read" is wrong

DISCUSSION Al Viro 4 participants 5 messages Dec 4, 2016 – Dec 6, 2016

Subsystems (2)
lore
Share & tools
lore

Al Viro

author
#0 lore raw

Could we please kill that kludge? "af_unix: use freezable blocking
calls in read" had been wrong to start with; having a method make assumptions of that sort ("nobody will call me while holding locks I hadn't thought of") is asking for serious trouble. splice is just a place where lockdep has caught that - we *can't* assume that nobody will ever call kernel_recvmsg() while holding some locks.

	I've run into that converting AF_UNIX to generic_file_splice_read();

I can kludge around that ("freezable unless ->msg_iter is ITER_PIPE"), but that only delays trouble.

Note that the only other user of freezable_schedule_timeout() is
a very different story - it's a kernel thread, which *does* have a guaranteed locking environment. Making such assumptions in unix_stream_recvmsg(), OTOH, is insane...

maintainer
#1 lore raw

From: Al Viro <[email protected]>
Date: Sun, 4 Dec 2016 21:04:55 +0000

Quoted 7 lines

Could we please kill that kludge? "af_unix: use freezable blocking
calls in read" had been wrong to start with; having a method make assumptions of that sort ("nobody will call me while holding locks I hadn't thought of") is asking for serious trouble. splice is just a place where lockdep has caught that - we *can't* assume that nobody will ever call kernel_recvmsg() while holding some locks.

Quoted 8 lines
	I've run into that converting AF_UNIX to generic_file_splice_read();

I can kludge around that ("freezable unless ->msg_iter is ITER_PIPE"), but that only delays trouble.

Note that the only other user of freezable_schedule_timeout() is
a very different story - it's a kernel thread, which *does* have a guaranteed locking environment. Making such assumptions in unix_stream_recvmsg(), OTOH, is insane...

We have to otherwise Android phones drain their batteries in 10 minutes.

I'm not going to revert this and be responsible for that.

So you have to find a way to make the freezable calls legitimate.

author
#2 lore raw
Quoted 9 lines · David Miller
Quoted 8 lines
	I've run into that converting AF_UNIX to generic_file_splice_read();

I can kludge around that ("freezable unless ->msg_iter is ITER_PIPE"), but that only delays trouble.

Note that the only other user of freezable_schedule_timeout() is
a very different story - it's a kernel thread, which *does* have a guaranteed locking environment. Making such assumptions in unix_stream_recvmsg(), OTOH, is insane...

Quoted 6 lines

We have to otherwise Android phones drain their batteries in 10 minutes.

I'm not going to revert this and be responsible for that.

So you have to find a way to make the freezable calls legitimate.

Oh, well... As I said, I can kludge around that - call from generic_file_splice_read() can be distinguished by looking at the ->msg_iter->type; it still means unpleasantness for kernel_recvmsg() users - in effect, it can only be called with locks held if you know that the socket is not an AF_UNIX one.

BTW, how do they deal with plain pipes?

#3 lore raw
Quoted 17 lines · Al Viro
Quoted 9 lines · David Miller
Quoted 8 lines
    I've run into that converting AF_UNIX to generic_file_splice_read();

I can kludge around that ("freezable unless ->msg_iter is ITER_PIPE"), but that only delays trouble.

Note that the only other user of freezable_schedule_timeout() is
a very different story - it's a kernel thread, which *does* have a guaranteed locking environment. Making such assumptions in unix_stream_recvmsg(), OTOH, is insane...

Quoted 6 lines

We have to otherwise Android phones drain their batteries in 10 minutes.

I'm not going to revert this and be responsible for that.

So you have to find a way to make the freezable calls legitimate.

Quoted 7 lines

Oh, well... As I said, I can kludge around that - call from generic_file_splice_read() can be distinguished by looking at the ->msg_iter->type; it still means unpleasantness for kernel_recvmsg() users - in effect, it can only be called with locks held if you know that the socket is not an AF_UNIX one.

BTW, how do they deal with plain pipes?

I suppose this question is for Colin. ;)

#4 lore raw
Quoted 11 lines · Cong Wang
Quoted 10 lines · Al Viro
Quoted 9 lines · David Miller
Quoted 8 lines
    I've run into that converting AF_UNIX to generic_file_splice_read();

I can kludge around that ("freezable unless ->msg_iter is ITER_PIPE"), but that only delays trouble.

Note that the only other user of freezable_schedule_timeout() is
a very different story - it's a kernel thread, which *does* have a guaranteed locking environment. Making such assumptions in unix_stream_recvmsg(), OTOH, is insane...

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

We have to otherwise Android phones drain their batteries in 10 minutes.

I'm not going to revert this and be responsible for that.

This is an optimization for going in and out of suspend without context switching through blocked processes, reverting it will not cause batteries to drain in 10 minutes. On my phone, it would cause ~83 context switches on each transition in and out of suspend, which sometimes happens every 1-5 seconds on noisy networks, but more normally happens on the order of minutes.

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

So you have to find a way to make the freezable calls legitimate.

Oh, well... As I said, I can kludge around that - call from generic_file_splice_read() can be distinguished by looking at the ->msg_iter->type; it still means unpleasantness for kernel_recvmsg() users - in effect, it can only be called with locks held if you know that the socket is not an AF_UNIX one.

Quoted 3 lines
Quoted 1 line

BTW, how do they deal with plain pipes?

I suppose this question is for Colin. ;)

The original patch set is at https://lkml.org/lkml/2013/4/29/495. It was targeted to the sites on which many threads were blocked on an Android device, pipe_wait didn't show up high on the list (there is only 1 thread blocked on pipe_wait on my phone right now), so I didn't look at it.