From: Brian Norris <briannorris@chromium.org>
To: Ganapathi Bhat <gbhat@marvell.com>
Cc: linux-wireless@vger.kernel.org, Cathy Luo <cluo@marvell.com>,
Xinming Hu <huxm@marvell.com>, Zhiyuan Yang <yangzy@marvell.com>,
James Cao <jcao@marvell.com>,
Mangesh Malusare <mmangesh@marvell.com>,
Douglas Anderson <dianders@chromium.org>,
Karthik Ananthapadmanabha <karthida@marvell.com>
Subject: Re: [PATCH 1/3] mwifiex: cleanup rx_pkt_lock usage in 11n_rxreorder.c
Date: Wed, 1 Nov 2017 14:28:54 -0700 [thread overview]
Message-ID: <20171101212853.GA89416@google.com> (raw)
In-Reply-To: <1509442967-14149-2-git-send-email-gbhat@marvell.com>
Hi,
On Tue, Oct 31, 2017 at 03:12:45PM +0530, Ganapathi Bhat wrote:
> From: Karthik Ananthapadmanabha <karthida@marvell.com>
>
> Fix the incorrect usage of rx_pkt_lock spinlock. Realsing the
> spinlock while the element is still in process is unsafe. The
> lock must be released only after the element processing is
> complete.
>
> Signed-off-by: Karthik Ananthapadmanabha <karthida@marvell.com>
> Signed-off-by: Ganapathi Bhat <gbhat@marvell.com>
> ---
> drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> index 1edcdda..0149c4a 100644
> --- a/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> +++ b/drivers/net/wireless/marvell/mwifiex/11n_rxreorder.c
> @@ -124,9 +124,10 @@ static int mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv, void *payload)
> rx_tmp_ptr = tbl->rx_reorder_ptr[i];
> tbl->rx_reorder_ptr[i] = NULL;
> }
> - spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
So, what is this lock protecting? Is it for protecting the packet
itself, or for protecting the ring buffer? As I read it, it's just the
latter, since once we've removed it from the ring buffer (and are about
to dispatch it up toward the networking layer), it's handled only by a
single context (or else, protected via some other common lock(s)).
If I'm correct above, then I think the current code here is actually
safe, since it holds the lock while removing from the ring buffer --
after it's removed from the ring, there's no way another thread can find
this payload, and so we can release the lock.
On a related note: I don't actually see the ring buffer *insertion*
being protected by this rx_pkt_lock, so is it really useful? See
mwifiex_11n_rx_reorder_pkt(). Perhaps the correct lock is actually
rx_reorder_tbl_lock()? Except that serves multiple purposes it seems...
Another thought: from what I can tell, all of these operations are
*only* performed on the main thread, so there's actually no concurrency
involved at all. So we also could probably drop this lock entirely...
I guess the real point is: can you explain better what you intend this
lock to do? Then we can review whether you're accomplishing your
intention, or whether we should improve the usage of this lock in some
other way, or perhaps even kill it entirely.
Thanks,
Brian
> if (rx_tmp_ptr)
> mwifiex_11n_dispatch_pkt(priv, rx_tmp_ptr);
> +
> + spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
> }
>
> spin_lock_irqsave(&priv->rx_pkt_lock, flags);
> @@ -167,8 +168,8 @@ static int mwifiex_11n_dispatch_pkt(struct mwifiex_private *priv, void *payload)
> }
> rx_tmp_ptr = tbl->rx_reorder_ptr[i];
> tbl->rx_reorder_ptr[i] = NULL;
> - spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
> mwifiex_11n_dispatch_pkt(priv, rx_tmp_ptr);
> + spin_unlock_irqrestore(&priv->rx_pkt_lock, flags);
> }
>
> spin_lock_irqsave(&priv->rx_pkt_lock, flags);
> --
> 1.9.1
>
next prev parent reply other threads:[~2017-11-01 21:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-31 9:42 [PATCH 0/3] mwifiex: fix usage issues with spinlocks Ganapathi Bhat
2017-10-31 9:42 ` [PATCH 1/3] mwifiex: cleanup rx_pkt_lock usage in 11n_rxreorder.c Ganapathi Bhat
2017-11-01 21:28 ` Brian Norris [this message]
2017-11-02 10:30 ` [EXT] " Ganapathi Bhat
2017-11-07 0:42 ` Doug Anderson
2017-11-07 2:25 ` Brian Norris
2017-11-07 16:25 ` Ganapathi Bhat
2017-11-07 21:15 ` Doug Anderson
2017-12-07 10:29 ` Ganapathi Bhat
2018-06-25 9:49 ` Ganapathi Bhat
2017-11-07 21:13 ` Doug Anderson
2017-10-31 9:42 ` [PATCH 2/3] mwifiex: cleanup tx_ba_stream_tbl_lock usage Ganapathi Bhat
2017-10-31 9:42 ` [PATCH 3/3] mwifiex: cleanup rx_reorder_tbl_lock usage Ganapathi Bhat
2017-11-07 2:30 ` Brian Norris
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=20171101212853.GA89416@google.com \
--to=briannorris@chromium.org \
--cc=cluo@marvell.com \
--cc=dianders@chromium.org \
--cc=gbhat@marvell.com \
--cc=huxm@marvell.com \
--cc=jcao@marvell.com \
--cc=karthida@marvell.com \
--cc=linux-wireless@vger.kernel.org \
--cc=mmangesh@marvell.com \
--cc=yangzy@marvell.com \
/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).