From: Andrew Lunn <andrew@lunn.ch>
To: Vladimir Oltean <vladimir.oltean@nxp.com>
Cc: "mattias.forsblad@gmail.com" <mattias.forsblad@gmail.com>,
netdev <netdev@vger.kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
Christian Marangi <ansuelsmth@gmail.com>
Subject: Re: [PATCH rfc v0 2/9] net: dsa: qca8k: Move completion into DSA core
Date: Wed, 21 Sep 2022 02:19:54 +0200 [thread overview]
Message-ID: <YypYqqwgllmcPJZj@lunn.ch> (raw)
In-Reply-To: <20220920144303.c5kxvbxlwf6jdx2g@skbuf>
On Tue, Sep 20, 2022 at 02:43:04PM +0000, Vladimir Oltean wrote:
> On Tue, Sep 20, 2022 at 12:18:46AM +0200, Andrew Lunn wrote:
> > @@ -248,8 +248,6 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
> >
> > skb->dev = priv->mgmt_master;
> >
> > - reinit_completion(&mgmt_eth_data->rw_done);
> > -
> > /* Increment seq_num and set it in the mdio pkt */
> > mgmt_eth_data->seq++;
> > qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq);
> > @@ -257,8 +255,8 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
> >
> > dev_queue_xmit(skb);
> >
> > - ret = wait_for_completion_timeout(&mgmt_eth_data->rw_done,
> > - QCA8K_ETHERNET_TIMEOUT);
> > + ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
> > + QCA8K_ETHERNET_TIMEOUT);
> >
> > *val = mgmt_eth_data->data[0];
> > if (len > QCA_HDR_MGMT_DATA1_LEN)
>
> Replacing the pattern above with this pattern:
>
> int dsa_inband_wait_for_completion(struct dsa_inband *inband, int timeout_ms)
> {
> unsigned long jiffies = msecs_to_jiffies(timeout_ms);
>
> reinit_completion(&inband->completion);
>
> return wait_for_completion_timeout(&inband->completion, jiffies);
> }
>
> is buggy because we reinitialize the completion later than the original
> code used to. We now call reinit_completion() from a code path that
> races with the handler that is supposed to call dsa_inband_complete().
I've been thinking about this a bit. And i think the bug is in the old
code.
As soon as we call reinit_completion(), a late arriving packet can
trigger the completion. Note that the sequence number has not been
incremented yet. So that late arriving packet can pass the sequence
number test, and the results will be copied and complete() called.
qca8k_read_eth() can continue, increment the sequence number, call
wait_for_completion_timeout() and immediately exit, returning the
contents of the late arriving reply.
To make this safe:
1) The sequence number needs to be incremented before
reinit_completion(). That closes one race
2) If the sequence numbers don't match, silently drop the packet, it
is either later, or bogus. Hopefully the correct reply packet will
come along soon and trigger the completion.
I've also got some of this wrong in my code.
Andrew
next prev parent reply other threads:[~2022-09-21 0:20 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-19 11:08 [PATCH net-next v14 0/7] net: dsa: qca8k, mv88e6xxx: rmon: Add RMU support Mattias Forsblad
2022-09-19 11:08 ` [PATCH net-next v14 1/7] net: dsa: mv88e6xxx: Add RMU enable for select switches Mattias Forsblad
2022-09-19 11:08 ` [PATCH net-next v14 2/7] net: dsa: Add convenience functions for frame handling Mattias Forsblad
2022-09-19 22:14 ` Vladimir Oltean
2022-09-19 22:22 ` Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 0/9] DSA: Move parts of inband signalling into the DSA Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 1/9] net: dsa: qca8k: Fix inconsistent use of jiffies vs milliseconds Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 2/9] net: dsa: qca8k: Move completion into DSA core Andrew Lunn
2022-09-20 14:43 ` Vladimir Oltean
2022-09-21 0:19 ` Andrew Lunn [this message]
2022-09-21 0:22 ` Vladimir Oltean
2022-09-19 22:18 ` [PATCH rfc v0 3/9] net: dsa: qca8K: Move queuing for request frame into the core Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 4/9] net: dsa: qca8k: dsa_inband_request: More normal return values Andrew Lunn
2022-09-19 23:02 ` Vladimir Oltean
2022-09-19 23:21 ` Andrew Lunn
2022-09-19 23:16 ` Vladimir Oltean
2022-09-19 22:18 ` [PATCH rfc v0 5/9] net: dsa: qca8k: Move request sequence number handling into core Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 6/9] net: dsa: qca8k: Refactor sequence number mismatch to use error code Andrew Lunn
2022-09-19 23:30 ` Vladimir Oltean
2022-09-20 0:05 ` Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 7/9] net: dsa: qca8k: Pass error code from reply decoder to requester Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 8/9] net: dsa: qca8k: Pass response buffer via dsa_rmu_request Andrew Lunn
2022-09-20 0:27 ` Vladimir Oltean
2022-09-20 12:33 ` Andrew Lunn
2022-09-19 22:18 ` [PATCH rfc v0 9/9] net: dsa: qca8k: Move inband mutex into DSA core Andrew Lunn
2022-09-20 3:19 ` Christian Marangi
2022-09-20 15:48 ` Andrew Lunn
2022-09-19 11:08 ` [PATCH net-next v14 3/7] net: dsa: Introduce dsa tagger data operation Mattias Forsblad
2022-09-19 22:00 ` Vladimir Oltean
2022-09-20 6:41 ` Mattias Forsblad
2022-09-20 10:31 ` Vladimir Oltean
2022-09-20 11:10 ` Mattias Forsblad
2022-09-19 11:08 ` [PATCH net-next v14 4/7] net: dsa: mv88e6xxxx: Add RMU functionality Mattias Forsblad
2022-09-19 22:39 ` Vladimir Oltean
2022-09-20 11:53 ` Mattias Forsblad
2022-09-20 12:22 ` Vladimir Oltean
2022-09-19 11:08 ` [PATCH net-next v14 5/7] net: dsa: mv88e6xxx: rmu: Add functionality to get RMON Mattias Forsblad
2022-09-19 22:49 ` Vladimir Oltean
2022-09-20 12:26 ` Mattias Forsblad
2022-09-20 13:10 ` Vladimir Oltean
2022-09-20 13:40 ` Mattias Forsblad
2022-09-20 21:04 ` Andrew Lunn
2022-09-21 5:35 ` Mattias Forsblad
2022-09-21 15:50 ` Andrew Lunn
2022-09-22 11:48 ` Vladimir Oltean
2022-09-22 12:45 ` Andrew Lunn
2022-09-22 13:04 ` Vladimir Oltean
2022-09-22 17:27 ` Andrew Lunn
2022-09-19 11:08 ` [PATCH net-next v14 6/7] net: dsa: mv88e6xxx: rmon: Use RMU for reading RMON data Mattias Forsblad
2022-09-19 11:08 ` [PATCH net-next v14 7/7] net: dsa: qca8k: Use new convenience functions Mattias Forsblad
2022-09-19 11:23 ` Christian Marangi
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=YypYqqwgllmcPJZj@lunn.ch \
--to=andrew@lunn.ch \
--cc=ansuelsmth@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=mattias.forsblad@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=vladimir.oltean@nxp.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).