Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp335413lqg; Thu, 11 Apr 2024 04:47:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjBFDb2Zj2ZJPnG+UYC8N/hv6VL0qBZSLj7x4w8VaQ+c48OGfrAdac0QbApaNhJ9es3ACaTtUZOTULcVdRvqLTqql/SyTCGTqNf6x1Ww== X-Google-Smtp-Source: AGHT+IFB8H1sdDDoKzin/RlamNH1SCGMS+8qXpucF3CG9QhKav62hGC17SarEb/GppECKZzn8ByJ X-Received: by 2002:a05:6870:414b:b0:22e:9e7:8b2a with SMTP id r11-20020a056870414b00b0022e09e78b2amr5621189oad.0.1712836028870; Thu, 11 Apr 2024 04:47:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712836028; cv=pass; d=google.com; s=arc-20160816; b=oLx4f0Oc4GBv7WnjLRblrq1onwJk6rL4gWRt50U5Q3m17G7NkemALpcb1xSNFdE0xf y3N3zpFuDmqv8RRJ1/njdzPIB3L0NNThCNP0jbIP/qOQ+d/pYmWqoJno54kxLf48oUXG 8gddBk4mphH4b7g2scel8StHQhJcxjTyUJ0t2Kh+Cy3PThswU9PZxNIiMwGGCtq31MiL sTkGGbPHfg4FZVaw02r6VfqZo7MwHxlZz+qelIT6pIN3mkGwGBqtm6+sCmTgu78/g70M ub5loIFwK1HG8ObRzx3LHHGxgltLbGjo4TmHmLGDfaIbepZ93xyFRl8r84/38wlFLEXh ouPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=IpHn6vPDFG3Y+AIIP+Dl72/a4yBMV8TAG9Ctok/Iuqc=; fh=l55LBwCPu+wSDalSufX0aRSb1ticG861yGU2rLmDH4k=; b=rZ5yuFI5H7C6N4d0xfMoGnxXdCNshIf7FYp9hR8X8AjTq6SkT+ZAGYFkKnC1xADEro cPpMwKOeOY8ueiZc+igq/yBo3gW3GeRhfiPQn7Pk5dOqprV+XY7n0Fj2Z+5zv1tbnHon aqRlQoZZFADhN0wWLY6LHkHqreopGlJybOA/jUIZffSnVTrNzAInQrjX3YenerpOTzIW AptrvX7Osoeh8luBujkWs6Cr3NxfEx9R63MDvjb0D+U1mhTyKg013T9XSjfFBtoNC44S G4/lGwmWoVKCw1LKbjPEWzeZk9gPgKfiJGa5oXDf1SQPKeEGrX07LtKzQxOZ9garg/Pp 9AfA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=bp.renesas.com dmarc=pass fromdomain=bp.renesas.com); spf=pass (google.com: domain of linux-kernel+bounces-140373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v13-20020a05622a014d00b004366653d0casi896232qtw.793.2024.04.11.04.47.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 04:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=bp.renesas.com dmarc=pass fromdomain=bp.renesas.com); spf=pass (google.com: domain of linux-kernel+bounces-140373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 735961C219EA for ; Thu, 11 Apr 2024 11:47:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C729114E2D0; Thu, 11 Apr 2024 11:45:11 +0000 (UTC) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED66C14BF8B; Thu, 11 Apr 2024 11:45:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712835911; cv=none; b=K9TimfLhnIQDWkDRTcpWoidnXBmZg+oVCcAIqbysSffyqEBQlpUOk+i+oOLLhO0v9e5gWunT++qJ+JIZwyhAgMhwvzxGKEwwP0dAFz0jZ2jYFEYp+jS5L+gc5SBiG5z4x9PNtHcMA7AJZluqnya2Qn/6G3vJyQx1x6C6SUYTQUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712835911; c=relaxed/simple; bh=MmDI+q4/9jb1kLuiW8i7oMnpEAKfa1V2ExzQEeIkyYw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IaQquIr1YO/TUgj5LFjVd012S8IlvQWAwGWZAN1Yzkpy5l26M79/aPUk9vNZDoVl7ZsawFxhrqxwqZVs0V/8HlzJ+53Ke9GV8Si0SvjwVBryolpDbkPLl984JSNlAikYVq2JA++lMI/soW3UH8aURQ/DMzqKEjl831VzpZ6Zfzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.07,193,1708354800"; d="scan'208";a="205076272" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 11 Apr 2024 20:45:03 +0900 Received: from renesas-deb12.cephei.uk (unknown [10.226.93.85]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id A6C0042017DE; Thu, 11 Apr 2024 20:44:59 +0900 (JST) From: Paul Barker To: Sergey Shtylyov , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Geert Uytterhoeven Cc: Paul Barker , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 2/4] net: ravb: Allow RX loop to move past DMA mapping errors Date: Thu, 11 Apr 2024 12:44:31 +0100 Message-Id: <20240411114434.26186-3-paul.barker.ct@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240411114434.26186-1-paul.barker.ct@bp.renesas.com> References: <20240411114434.26186-1-paul.barker.ct@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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; + /* Descriptor type must be checked before all other reads */ dma_rmb(); desc_status = desc->msc; @@ -959,9 +963,6 @@ static bool ravb_rx_rcar(struct net_device *ndev, int *quota, int q) rx_packets++; stats->rx_bytes += pkt_len; } - - entry = (++priv->cur_rx[q]) % priv->num_rx_ring[q]; - desc = &priv->rx_ring[q].ex_desc[entry]; } /* Refill the RX ring buffers. */ -- 2.39.2