net, socket, socket_wq: fix missing initialization of flags
Subsystems (3)
PATCH 1/1 net, socket, socket_wq: fix missing initialization of flags
Commit ceb5d58b2170 ("net: fix sock_wake_async() rcu protection") from the current 4.4 release cycle introduces a new flags member in struct socket_wq and moved SOCKWQ_ASYNC_NOSPACE and SOCKWQ_ASYNC_WAITDATA from struct socket's flags member into that new place.
Unfortunately, the new flags field is never initialized properly, at least not for the struct socket_wq instance created in sock_alloc_inode().
One particular issue I encountered because of this is that my GNU Emacs failed to draw anything on my desktop -- i.e. what I got is a transparent window, including the title bar. Bisection lead to the commit mentioned above and further investigation by means of strace told me that Emacs is indeed speaking to my Xorg through an O_ASYNC AF_UNIX socket. This is reproducible 100% of times and the fact that properly initializing the struct socket_wq ->flags fixes the issue leads me to the conclusion that somehow SOCKWQ_ASYNC_NOSPACE got set in the uninitialized ->flags, preventing my Emacs from receiving any SIGIO's due to send space becoming available again and it got stuck.
Make sock_alloc_inode() set the newly created struct socket_wq's ->flags member to zero.
--- net/socket.c | 1 + 1 file changed, 1 insertion(+)
net/socket.c +1 -0
@@ -257,6 +257,7 @@ static struct inode *sock_alloc_inode(struct super_block *sb) }init_waitqueue_head (&wq->wait); wq->fasync_list =NULL ; + wq->flags =0 ;RCU_INIT_POINTER (ei->socket.wq, wq); ei->socket.state =SS_UNCONNECTED ;
Signature · 1 line
2.6.4
Quoted 34 lines · Nicolai Stange
Fixes ceb5d58b2170 ("net: fix sock_wake_async() rcu protection")Commit
ceb5d58b2170("net: fixsock_wake_async()rcu protection") from the current 4.4 release cycle introduces a new flags member in structsocket_wqand movedSOCKWQ_ASYNC_NOSPACEandSOCKWQ_ASYNC_WAITDATAfrom struct socket's flags member into that new place.Unfortunately, the new flags field is never initialized properly, at least not for the struct
socket_wqinstance created insock_alloc_inode().One particular issue I encountered because of this is that my GNU Emacs failed to draw anything on my desktop -- i.e. what I got is a transparent window, including the title bar. Bisection lead to the commit mentioned above and further investigation by means of strace told me that Emacs is indeed speaking to my Xorg through an
O_ASYNCAF_UNIXsocket. This is reproducible 100% of times and the fact that properly initializing the structsocket_wq->flags fixes the issue leads me to the conclusion that somehowSOCKWQ_ASYNC_NOSPACEgot set in the uninitialized ->flags, preventing my Emacs from receiving any SIGIO's due to send space becoming available again and it got stuck.Make
sock_alloc_inode()set the newly created struct socket_wq's ->flags member to zero.Signed-off-by Nicolai Stange <[email protected]>--- net/socket.c | 1 + 1 file changed, 1 insertion(+)net/socket.c +0
-0
net/socket.c static struct inode *sock_alloc_inode(struct super_block *sb) · line 263
Quoted 7 lines
net/socket.c +1
-0@@ -257,6 +257,7 @@ static struct inode *sock_alloc_inode(struct super_block *sb) }init_waitqueue_head (&wq->wait); wq->fasync_list =NULL ; + wq->flags =0 ;RCU_INIT_POINTER (ei->socket.wq, wq); ei->socket.state =SS_UNCONNECTED ;
Thanks a lot Nicolai for finding this.
I completely overlooked this initial value.
I checked other places where 'struct socket_wq' were allocated and they look fine.
PATCH v2 1/1 net, socket, socket_wq: fix missing initialization of flags
Commit ceb5d58b2170 ("net: fix sock_wake_async() rcu protection") from the current 4.4 release cycle introduced a new flags member in struct socket_wq and moved SOCKWQ_ASYNC_NOSPACE and SOCKWQ_ASYNC_WAITDATA from struct socket's flags member into that new place.
Unfortunately, the new flags field is never initialized properly, at least not for the struct socket_wq instance created in sock_alloc_inode().
One particular issue I encountered because of this is that my GNU Emacs failed to draw anything on my desktop -- i.e. what I got is a transparent window, including the title bar. Bisection lead to the commit mentioned above and further investigation by means of strace told me that Emacs is indeed speaking to my Xorg through an O_ASYNC AF_UNIX socket. This is reproducible 100% of times and the fact that properly initializing the struct socket_wq ->flags fixes the issue leads me to the conclusion that somehow SOCKWQ_ASYNC_WAITDATA got set in the uninitialized ->flags, preventing my Emacs from receiving any SIGIO's due to data becoming available and it got stuck.
Make sock_alloc_inode() set the newly created struct socket_wq's ->flags member to zero.
---
Changes to V1 (only commit message changes):
- Uhm, I misread sock_wake_async(). The meaning of the flags is actually inverted. My Ghostmacs wasn't waiting for free send space, but some received data becoming available. This makes indeed more sense and I replaced "SOCKWQ_ASYNC_NOSPACE" by "SOCKWQ_ASYNC_WAITDATA" in my speculative explanation above.
- Furthermore I fixed some minor grammar issues.
Sorry for any inconvenience this late-night induced brainfart might have caused at your side...
net/socket.c | 1 + 1 file changed, 1 insertion(+)
net/socket.c +1 -0
@@ -257,6 +257,7 @@ static struct inode *sock_alloc_inode(struct super_block *sb) }init_waitqueue_head (&wq->wait); wq->fasync_list =NULL ; + wq->flags =0 ;RCU_INIT_POINTER (ei->socket.wq, wq); ei->socket.state =SS_UNCONNECTED ;
Signature · 1 line
2.6.4
Quoted 4 lines · Nicolai Stange
Fixes ceb5d58b2170 ("net: fix sock_wake_async() rcu protection")Sorry for any inconvenience this late-night induced brainfart might have caused at your side...
Not really, because I read the source code and saw the bug there ;)
From: Nicolai Stange <[email protected]>
Date: Tue, 29 Dec 2015 13:29:55 +0100
Quoted 21 lines
Fixes ceb5d58b2170 ("net: fix sock_wake_async() rcu protection")Commit
ceb5d58b2170("net: fixsock_wake_async()rcu protection") from the current 4.4 release cycle introduced a new flags member in structsocket_wqand movedSOCKWQ_ASYNC_NOSPACEandSOCKWQ_ASYNC_WAITDATAfrom struct socket's flags member into that new place.Unfortunately, the new flags field is never initialized properly, at least not for the struct
socket_wqinstance created insock_alloc_inode().One particular issue I encountered because of this is that my GNU Emacs failed to draw anything on my desktop -- i.e. what I got is a transparent window, including the title bar. Bisection lead to the commit mentioned above and further investigation by means of strace told me that Emacs is indeed speaking to my Xorg through an
O_ASYNCAF_UNIXsocket. This is reproducible 100% of times and the fact that properly initializing the structsocket_wq->flags fixes the issue leads me to the conclusion that somehowSOCKWQ_ASYNC_WAITDATAgot set in the uninitialized ->flags, preventing my Emacs from receiving any SIGIO's due to data becoming available and it got stuck.
Quoted 4 lines
Make
sock_alloc_inode()set the newly created struct socket_wq's ->flags member to zero.Signed-off-by Nicolai Stange <[email protected]>
Applied, but please in the future please put the Fixes: tag right above the first signoff/ack, like this:
Quoted 27 lines · David Miller
From: Nicolai Stange <[email protected]>
Date: Tue, 29 Dec 2015 13:29:55 +0100Quoted 24 lines
Fixes ceb5d58b2170 ("net: fix sock_wake_async() rcu protection")Commit
ceb5d58b2170("net: fixsock_wake_async()rcu protection") from the current 4.4 release cycle introduced a new flags member in structsocket_wqand movedSOCKWQ_ASYNC_NOSPACEandSOCKWQ_ASYNC_WAITDATAfrom struct socket's flags member into that new place.Unfortunately, the new flags field is never initialized properly, at least not for the struct
socket_wqinstance created insock_alloc_inode().One particular issue I encountered because of this is that my GNU Emacs failed to draw anything on my desktop -- i.e. what I got is a transparent window, including the title bar. Bisection lead to the commit mentioned above and further investigation by means of strace told me that Emacs is indeed speaking to my Xorg through an
O_ASYNCAF_UNIXsocket. This is reproducible 100% of times and the fact that properly initializing the structsocket_wq->flags fixes the issue leads me to the conclusion that somehowSOCKWQ_ASYNC_WAITDATAgot set in the uninitialized ->flags, preventing my Emacs from receiving any SIGIO's due to data becoming available and it got stuck.Make
sock_alloc_inode()set the newly created struct socket_wq's ->flags member to zero.
Quoted 7 lines
Quoted 1 line
Signed-off-by Nicolai Stange <[email protected]>Applied, but please in the future please put the Fixes: tag right above the first signoff/ack, like this:
Fixes ceb5d58b2170 ("net: fix sock_wake_async() rcu protection")Signed-off-by Nicolai Stange <[email protected]>
Thank you very much!
Regarding the correct position of the "Fixes:" tag: lesson learned.