brcmfmac: fix waitqueue_active without memory barrier in brcmfmac driver
authorKosuke Tatsukawa <tatsu@ab.jp.nec.com>
Thu, 10 Dec 2015 12:43:08 +0000 (13:43 +0100)
committerKalle Valo <kvalo@codeaurora.org>
Fri, 11 Dec 2015 11:51:59 +0000 (13:51 +0200)
commita7decc44a002dffe7ee6e361ddc703b8c3035d2c
tree39faea71068b91857aed31492444abd5aece8bbb
parentb0a790883ed4d12b2c6c0fd19cda421ba7bb84ca
brcmfmac: fix waitqueue_active without memory barrier in brcmfmac driver

brcmf_msgbuf_ioctl_resp_wake() seems to be missing a memory barrier
which might cause the waker to not notice the waiter and miss sending a
wake_up as in the following figure.

  brcmf_msgbuf_ioctl_resp_wake     brcmf_msgbuf_ioctl_resp_wait
------------------------------------------------------------------------
if (waitqueue_active(&msgbuf->ioctl_resp_wait))
/* The CPU might reorder the test for
   the waitqueue up here, before
   prior writes complete */
                       /* wait_event_timeout */
        /* __wait_event_timeout */
 /* ___wait_event */
 prepare_to_wait_event(&wq, &__wait,
   state);
 if (msgbuf->ctl_completed)
 ...
msgbuf->ctl_completed = true;
 schedule_timeout(__ret))
------------------------------------------------------------------------

There are three other place in drivers/net/wireless/brcm80211/brcmfmac/
which have similar code.  The attached patch removes the call to
waitqueue_active() leaving just wake_up() behind.  This fixes the
problem because the call to spin_lock_irqsave() in wake_up() will be an
ACQUIRE operation.

I found this issue when I was looking through the linux source code
for places calling waitqueue_active() before wake_up*(), but without
preceding memory barriers, after sending a patch to fix a similar
issue in drivers/tty/n_tty.c  (Details about the original issue can be
found here: https://lkml.org/lkml/2015/9/28/849).

Reviewed-by: Hante Meuleman <meuleman@broadcom.com>
Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Signed-off-by: Kosuke Tatsukawa <tatsu@ab.jp.nec.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c