netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend van Spriel <arend-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
To: Kosuke Tatsukawa <tatsu-zZGIbrA41Td8UrSeD/g0lQ@public.gmane.org>,
	Brett Rudley <brudley-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	"Franky (Zhenhui) Lin"
	<frankyl-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	Hante Meuleman <meuleman-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	Kalle Valo <kvalo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	Pieter-Paul Giesberts
	<pieterpg-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	"John W. Linville"
	<linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>,
	Markus Elfring
	<elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Cc: "linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"brcm80211-dev-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org"
	<brcm80211-dev-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	"netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH] brcmfmac: fix waitqueue_active without memory barrier in brcmfmac driver
Date: Sat, 10 Oct 2015 09:42:23 +0200	[thread overview]
Message-ID: <5618C15F.2030706@broadcom.com> (raw)
In-Reply-To: <17EC94B0A072C34B8DCF0D30AD16044A02874785-9lrffkYxhwTt6d3pZDjeaEtBU8KWyXPq@public.gmane.org>

On 10/09/2015 02:35 AM, Kosuke Tatsukawa wrote:
> 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).

I prefer to add proper barriers instead of removing waitqueue_active()
check. We will review your patch and submit it through our upstream process.

Regards,
Arend

> Signed-off-by: Kosuke Tatsukawa <tatsu-zZGIbrA41Td8UrSeD/g0lQ@public.gmane.org>
> ---
>   drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c |    3 +--
>   drivers/net/wireless/brcm80211/brcmfmac/sdio.c   |    6 ++----
>   drivers/net/wireless/brcm80211/brcmfmac/usb.c    |    3 +--
>   3 files changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
> index 7b2136c..648151e 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c
> @@ -473,8 +473,7 @@ static int brcmf_msgbuf_ioctl_resp_wait(struct brcmf_msgbuf *msgbuf)
>   static void brcmf_msgbuf_ioctl_resp_wake(struct brcmf_msgbuf *msgbuf)
>   {
>   	msgbuf->ctl_completed = true;
> -	if (waitqueue_active(&msgbuf->ioctl_resp_wait))
> -		wake_up(&msgbuf->ioctl_resp_wait);
> +	wake_up(&msgbuf->ioctl_resp_wait);
>   }
>   
>   
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
> index f990e3d..332c4c8 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
> @@ -1785,8 +1785,7 @@ static int brcmf_sdio_dcmd_resp_wait(struct brcmf_sdio *bus, uint *condition,
>   
>   static int brcmf_sdio_dcmd_resp_wake(struct brcmf_sdio *bus)
>   {
> -	if (waitqueue_active(&bus->dcmd_resp_wait))
> -		wake_up_interruptible(&bus->dcmd_resp_wait);
> +	wake_up_interruptible(&bus->dcmd_resp_wait);
>   
>   	return 0;
>   }
> @@ -2110,8 +2109,7 @@ static uint brcmf_sdio_readframes(struct brcmf_sdio *bus, uint maxframes)
>   static void
>   brcmf_sdio_wait_event_wakeup(struct brcmf_sdio *bus)
>   {
> -	if (waitqueue_active(&bus->ctrl_wait))
> -		wake_up_interruptible(&bus->ctrl_wait);
> +	wake_up_interruptible(&bus->ctrl_wait);
>   	return;
>   }
>   
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
> index daba86d..7f5889c 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
> @@ -184,8 +184,7 @@ static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info *devinfo)
>   
>   static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info *devinfo)
>   {
> -	if (waitqueue_active(&devinfo->ioctl_resp_wait))
> -		wake_up(&devinfo->ioctl_resp_wait);
> +	wake_up(&devinfo->ioctl_resp_wait);
>   }
>   
>   static void
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2015-10-10  7:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09  0:35 [PATCH] brcmfmac: fix waitqueue_active without memory barrier in brcmfmac driver Kosuke Tatsukawa
2015-10-09 19:44 ` Arend van Spriel
     [not found] ` <17EC94B0A072C34B8DCF0D30AD16044A02874785-9lrffkYxhwTt6d3pZDjeaEtBU8KWyXPq@public.gmane.org>
2015-10-10  7:42   ` Arend van Spriel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5618C15F.2030706@broadcom.com \
    --to=arend-dy08kvg/lbpwk0htik3j/w@public.gmane.org \
    --cc=brcm80211-dev-list-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=brudley-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=elfring-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=frankyl-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=kvalo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linville-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
    --cc=meuleman-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=pieterpg-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=tatsu-zZGIbrA41Td8UrSeD/g0lQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).