From: Paul Barker <paul.barker.ct@bp.renesas.com>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>,
"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>,
netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net 2/4] net: ravb: Allow RX loop to move past DMA mapping errors
Date: Mon, 15 Apr 2024 08:12:06 +0100 [thread overview]
Message-ID: <d1ec92db-eefe-465a-9eb5-3a57c22b86c3@bp.renesas.com> (raw)
In-Reply-To: <20240414121719.GB2860391@ragnatech.se>
[-- Attachment #1.1.1: Type: text/plain, Size: 4809 bytes --]
On 14/04/2024 13:17, Niklas Söderlund wrote:
> Hi Paul,
>
> Thanks for your patch.
>
> On 2024-04-11 12:44:31 +0100, Paul Barker wrote:
>> The RX loops in ravb_rx_gbeth() and ravb_rx_rcar() skip to the next loop
>> interation if a zero-length descriptor is seen (indicating a DMA mapping
>> error). However, the current rx descriptor index `priv->cur_rx[q]` was
>> incremented at the end of the loop and so would not be incremented when
>> we skip to the next loop iteration. This would cause the loop to keep
>> seeing the same zero-length descriptor instead of moving on to the next
>> descriptor.
>>
>> As the loop counter `i` still increments, the loop would eventually
>> terminate so there is no risk of being stuck here forever - but we
>> should still fix this to avoid wasting cycles.
>>
>> To fix this, the rx descriptor index is incremented at the top of the
>> loop, in the for statement itself. The assignments of `entry` and `desc`
>> are brought into the loop to avoid the need for duplication.
>>
>> Fixes: d8b48911fd24 ("ravb: fix ring memory allocation")
>> Signed-off-by: Paul Barker <paul.barker.ct@bp.renesas.com>
>> ---
>> drivers/net/ethernet/renesas/ravb_main.c | 25 ++++++++++++------------
>> 1 file changed, 13 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
>> index 70f2900648d4..028ab5c6aaf7 100644
>> --- a/drivers/net/ethernet/renesas/ravb_main.c
>> +++ b/drivers/net/ethernet/renesas/ravb_main.c
>> @@ -775,12 +775,15 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
>> int limit;
>> int i;
>>
>> - entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>> limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q];
>> stats = &priv->stats[q];
>>
>> - desc = &priv->rx_ring[q].desc[entry];
>> - for (i = 0; i < limit && rx_packets < *quota && desc->die_dt != DT_FEMPTY; i++) {
>> + for (i = 0; i < limit && rx_packets < *quota; i++, priv->cur_rx[q]++) {
>> + entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>> + desc = &priv->rx_ring[q].desc[entry];
>> + if (desc->die_dt == DT_FEMPTY)
>> + break;
>> +
>> /* Descriptor type must be checked before all other reads */
>> dma_rmb();
>> desc_status = desc->msc;
>> @@ -848,9 +851,6 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
>> break;
>> }
>> }
>> -
>> - entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q];
>> - desc = &priv->rx_ring[q].desc[entry];
>> }
>>
>> /* Refill the RX ring buffers. */
>> @@ -891,7 +891,6 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
>> {
>> struct ravb_private *priv = netdev_priv(ndev);
>> const struct ravb_hw_info *info = priv->info;
>> - int entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>> struct net_device_stats *stats = &priv->stats[q];
>> struct ravb_ex_rx_desc *desc;
>> struct sk_buff *skb;
>> @@ -900,12 +899,17 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q)
>> int rx_packets = 0;
>> u8 desc_status;
>> u16 pkt_len;
>> + int entry;
>> int limit;
>> int i;
>>
>> limit = priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q];
>> - desc = &priv->rx_ring[q].ex_desc[entry];
>> - for (i = 0; i < limit && rx_packets < *quota && desc->die_dt != DT_FEMPTY; i++) {
>> + for (i = 0; i < limit && rx_packets < *quota; i++, priv->cur_rx[q]++) {
>> + entry = priv->cur_rx[q] % priv->num_rx_ring[q];
>> + desc = &priv->rx_ring[q].ex_desc[entry];
>> + if (desc->die_dt == DT_FEMPTY)
>> + break;
>
> I really like moving the assignment of entry and desc to the top of the
> loop. But I don't like the loop limits as it's hard, at least for me, to
> immediately see what's going on. How about,
>
> limit = min(priv->dirty_rx[q] + priv->num_rx_ring[q] - priv->cur_rx[q], *quota);
>
> for (i = 0; i < limit; i++) {
> entry = priv->cur_rx[q] % priv->num_rx_ring[q];
> desc = &priv->rx_ring[q].ex_desc[entry];
>
> /* There are no more valid descriptors after an empty one. */
> if (desc->die_dt == DT_FEMPTY)
> break;
>
> ...
> }
We need to count received packets separately from the number of
descriptors processed, as done in the previous commit in this series,
so we can't just have a single check against limit.
We also need to increment priv->cur_rx[q]. If we put `priv->cur_rx[q]++`
at the end of the loop then we're back to having to worry about it when
we have a continue statement.
We could move the `rx_packets < *quota` check inside the loop itself,
but I don't see that as any clearer myself.
Thanks,
--
Paul Barker
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2024-04-15 7:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-11 11:44 [PATCH net 0/4] ravb Ethernet driver bugfixes Paul Barker
2024-04-11 11:44 ` [PATCH net 1/4] net: ravb: Count packets instead of descriptors in R-Car RX path Paul Barker
2024-04-11 16:23 ` Sergey Shtylyov
2024-04-14 12:08 ` Niklas Söderlund
2024-04-15 7:04 ` Paul Barker
2024-04-15 9:44 ` Niklas Söderlund
2024-04-11 11:44 ` [PATCH net 2/4] net: ravb: Allow RX loop to move past DMA mapping errors Paul Barker
2024-04-11 16:37 ` Sergey Shtylyov
2024-04-14 12:17 ` Niklas Söderlund
2024-04-15 7:12 ` Paul Barker [this message]
2024-04-15 9:52 ` Niklas Söderlund
2024-04-11 11:44 ` [PATCH net 3/4] net: ravb: Fix GbEth jumbo packet RX checksum handling Paul Barker
2024-04-11 16:50 ` Sergey Shtylyov
2024-04-11 11:44 ` [PATCH net 4/4] net: ravb: Fix RX byte accounting for jumbo packets Paul Barker
2024-04-11 17:56 ` Sergey Shtylyov
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=d1ec92db-eefe-465a-9eb5-3a57c22b86c3@bp.renesas.com \
--to=paul.barker.ct@bp.renesas.com \
--cc=davem@davemloft.net \
--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=netdev@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=pabeni@redhat.com \
--cc=s.shtylyov@omp.ru \
/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®