socket: Avoid possible race between netmsg_so_notify() and sowakeup()
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 19 Jul 2013 08:40:07 +0000 (16:40 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 19 Jul 2013 08:40:07 +0000 (16:40 +0800)
commitccae972d65bbf7c434fd030a3f6dd886e57cbc3d
tree5645b71f707bebd68dd81a5cc7af323db2b249da
parentd491f445f1ae01e5a5554b9c1ded1d5c7b06778b
socket: Avoid possible race between netmsg_so_notify() and sowakeup()

The race is concerning SSB_MEVENT setup and testing.  Originally:

             CPU X                          CPU Y
    get token                                 :
    if (predict cond false) {                 :
           :                        set predict cond true
           :                        if (SSB_MEVENT) {
           :                            get token
           :                            wake up notifies
           :                            rel token
           :                        }
        queue notify                          :
        set SSB_MEVENT                        :
    }                                         :
    rel token

This commit always set SSB_MEVENT before predict testing, after getting
the socket token, so the race could be avoided.

Reviewed-by: dillon@
sys/kern/uipc_msg.c