From: Jacob Keller <jacob.e.keller@intel.com>
To: Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
Andrew Lunn <andrew@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
"Geert Uytterhoeven" <geert+renesas@glider.be>
Cc: <netdev@vger.kernel.org>, <linux-renesas-soc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Michael Dege <michael.dege@renesas.com>,
Christian Mardmoeller <christian.mardmoeller@renesas.com>,
Dennis Ostermann <dennis.ostermann@renesas.com>
Subject: Re: [PATCH 1/5] net: renesas: rswitch: fix possible early skb release
Date: Tue, 3 Dec 2024 16:22:37 -0800 [thread overview]
Message-ID: <a163255c-da64-43f9-b99e-719608ac661d@intel.com> (raw)
In-Reply-To: <20241202134904.3882317-2-nikita.yoush@cogentembedded.com>
On 12/2/2024 5:49 AM, Nikita Yushchenko wrote:
> When sending frame split into multiple descriptors, hardware processes
> descriptors one by one, including writing back DT values. The first
> descriptor could be already marked as completed when processing of
> next descriptors for the same frame is still in progress.
>
> Although only the last descriptor is configured to generate interrupt,
> completion of the first descriptor could be noticed by the driver when
> handling interrupt for the previous frame.
>
> Currently, driver stores skb in the entry that corresponds to the first
> descriptor. This results into skb could be unmapped and freed when
> hardware did not complete the send yet. This opens a window for
> corrupting the data being sent.
>
> Fix this by saving skb in the entry that corresponds to the last
> descriptor used to send the frame.
>
> Fixes: d2c96b9d5f83 ("net: rswitch: Add jumbo frames handling for TX")
> Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
> ---
> drivers/net/ethernet/renesas/rswitch.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c
> index b80aa27a7214..32b32aa7e01f 100644
> --- a/drivers/net/ethernet/renesas/rswitch.c
> +++ b/drivers/net/ethernet/renesas/rswitch.c
> @@ -1681,8 +1681,9 @@ static netdev_tx_t rswitch_start_xmit(struct sk_buff *skb, struct net_device *nd
> if (dma_mapping_error(ndev->dev.parent, dma_addr_orig))
> goto err_kfree;
>
> - gq->skbs[gq->cur] = skb;
> - gq->unmap_addrs[gq->cur] = dma_addr_orig;
> + /* Stored the skb at the last descriptor to avoid skb free before hardware completes send */
> + gq->skbs[(gq->cur + nr_desc - 1) % gq->ring_size] = skb;
> + gq->unmap_addrs[(gq->cur + nr_desc - 1) % gq->ring_size] = dma_addr_orig;
>
nr_desc is non-zero, so if nr_desc was 1, then this would point to
gq->cur + 0 mod ring_size, i.e. gq->cur.
I might have possibly computed that separately as a local variable since
this expression is repeated twice, but I don't think thats going to do
too much for readability either way.
Ok
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
> /* DT_FSTART should be set at last. So, this is reverse order. */
> for (i = nr_desc; i-- > 0; ) {
next prev parent reply other threads:[~2024-12-04 0:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 13:48 [PATCH 0/5] net: renesas: rswitch: several fixes Nikita Yushchenko
2024-12-02 13:49 ` [PATCH 1/5] net: renesas: rswitch: fix possible early skb release Nikita Yushchenko
2024-12-04 0:22 ` Jacob Keller [this message]
2024-12-02 13:49 ` [PATCH 2/5] net: renesas: rswitch: fix leaked pointer on error path Nikita Yushchenko
2024-12-04 0:23 ` Jacob Keller
2024-12-05 3:40 ` Jakub Kicinski
2024-12-05 3:46 ` Nikita Yushchenko
2024-12-06 0:47 ` Jakub Kicinski
2024-12-06 18:17 ` Nikita Yushchenko
2024-12-02 13:49 ` [PATCH 3/5] net: renesas: rswitch: avoid use-after-put for a device tree node Nikita Yushchenko
2024-12-04 0:24 ` Jacob Keller
2024-12-02 13:49 ` [PATCH 4/5] net: renesas: rswitch: do not deinit disabled ports Nikita Yushchenko
2024-12-04 0:27 ` Jacob Keller
2024-12-02 13:49 ` [PATCH 5/5] net: renesas: rswitch: remove speed from gwca structure Nikita Yushchenko
2024-12-04 0:28 ` Jacob Keller
2024-12-04 0:18 ` [PATCH 0/5] net: renesas: rswitch: several fixes Jacob Keller
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=a163255c-da64-43f9-b99e-719608ac661d@intel.com \
--to=jacob.e.keller@intel.com \
--cc=andrew@lunn.ch \
--cc=christian.mardmoeller@renesas.com \
--cc=davem@davemloft.net \
--cc=dennis.ostermann@renesas.com \
--cc=edumazet@google.com \
--cc=geert+renesas@glider.be \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=michael.dege@renesas.com \
--cc=netdev@vger.kernel.org \
--cc=nikita.yoush@cogentembedded.com \
--cc=pabeni@redhat.com \
--cc=yoshihiro.shimoda.uh@renesas.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
all inboxes | Powered by JetHome®