Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp2010563lqp; Tue, 16 Apr 2024 05:04:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKNkKjQSBrAYFRMb3m0gd7GMRTgDa5y+MLPenVqxW2I7qMz6LzfFMP8r1pZMHQc5dfYxaWEnAfGP98D/48E640tkPxyZ/1vbduUnH1Qg== X-Google-Smtp-Source: AGHT+IGu2GNbepVAcRnIFJLiCQ4mgeV3J8Rgw8V9/uZIcCTk/Kjqp3jZYdmFMALr1VclRKpOO5nW X-Received: by 2002:a05:620a:2212:b0:78d:77e4:25a0 with SMTP id m18-20020a05620a221200b0078d77e425a0mr12733994qkh.78.1713269080364; Tue, 16 Apr 2024 05:04:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713269080; cv=pass; d=google.com; s=arc-20160816; b=JNBDorIbW5AaftrUaBLbFdoRPVq1YBfCeVPy+IZjb8rA0qjRHZZzhWv5edrWiDapWk iy3Z+NqfGm8JVdPdqjtKTk4M61jWl0BAMLqywyqx3h0PmX3JiHd9XAmMdGEXbC4F+jgC Y8+4yt6bgNrmyawIb3ucE+hZ/2QmapZXVQubEcQ+Gl4lNYGmU6rukatxXOAh9dIs8gdT 7ePK3w3L+SkSZOCRqHEeeakwBWdypXqcCXCRqw7FNZPO8nsF1XH6vSq6S6hV8aFuZKPF U/xZBg9TO8jluGF9Mm4KhGt562jdY1bmPAvCwGaIaLSpdNnBDQzq7CG/RKl+hLWsmSGP 2P0A== 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=5tQv4R1rTdxubikHNgnBmuLSwf8XMhN5gmPH2eLYNc4=; fh=iDCzsdFwsWJFQNkU5jtQEScRkZQmxU6Yvae2ZkYJQ3M=; b=Sujb2uZn/Wv1stgP3BW2u3tO/yJUcmdgYgKXfGM0QPiddz4wTJKxDSlxuv/Xw2NYS6 za8uvfV/4svOLOZbnzjJxCfdIAoPJ/IV8eyBsdbYLE+fG3eVI+gxx7hFIbiIGbJUrLoL w1U6kR7g7ONxDnZ/BOq+lfq5pTdMuM/82tpBzW25ld64gp1jXsXvyFiiFqq6stV+VC4M 5p52DL7kHtEbkcEGbNyqE5znFMLwd+bflgog/aWB7Xn3V0HACYdL2b8uRCce0WTN70k6 yLwASO3kI0fU7oQousw5i6hNqhIEbbN/yQNWsQM/bU0+NfM/eoK6vRhrkaJ4JMqwkHS/ NgpA==; 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-146742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146742-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 g2-20020a05620a108200b0078ec5584babsi11743633qkk.334.2024.04.16.05.04.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 05:04:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146742-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-146742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146742-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 1C5F81C212B4 for ; Tue, 16 Apr 2024 12:04:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D634212BF29; Tue, 16 Apr 2024 12:03:50 +0000 (UTC) Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07B9412B145; Tue, 16 Apr 2024 12:03:45 +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=1713269030; cv=none; b=X1exkNOig+dlkJCBu4I0zl9gdbPVamyedmqQVcGGKefugxBzZIXs+DK86V8/o43Tjv4pAu6ZXkAPf6tVEKCbLgkHqh7DQCIwFhPXLIKHEnoIjmW+F9XU33Xsn/Dp6+x1JsUEWA8g98uDbWhP0H5R6RZpIYPftdNZicLLY57r+QI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713269030; c=relaxed/simple; bh=CASeUJf1k7le4H22BeIUR9Go94eNU9yShJnelWUCkUc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P4mU4Y8qjGOV0YCCrgIjujSSxDPmRnBZy6+VG6SFbXfGgK0K7J5o2Rr91U6zwOwFZxiNymTTRr9SduvI/KMrUEW8hEinViukhddo0cbeOyNVB8CL2fmwKYqtwyzt76c5L3PvMNgyDl1qyfeAnFBmYktlhVCg4bqb7ZlhZlyjoAE= 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,205,1708354800"; d="scan'208";a="205570153" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 16 Apr 2024 21:03:39 +0900 Received: from renesas-deb12.cephei.uk (unknown [10.226.93.86]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 4918A40078C7; Tue, 16 Apr 2024 21:03:34 +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 , Claudiu Beznea , Biju Das , YueHaibing , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net PATCH v3 2/4] net: ravb: Allow RX loop to move past DMA mapping errors Date: Tue, 16 Apr 2024 13:02:52 +0100 Message-Id: <20240416120254.2620-3-paul.barker.ct@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240416120254.2620-1-paul.barker.ct@bp.renesas.com> References: <20240416120254.2620-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 iteration 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 Reviewed-by: Sergey Shtylyov --- Changes v2->v3: * Move comparison of `rx_packets` against `*quota` inside the loop. Changes v1->v2: * Fix typos in commit message. * Add Sergey's Reviewed-by tag. 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 7d231d011bff..3b870926af14 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; i++, priv->cur_rx[q]++) { + entry = priv->cur_rx[q] % priv->num_rx_ring[q]; + desc = &priv->rx_ring[q].desc[entry]; + if (rx_packets == *quota || 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; unsigned int limit, i; @@ -901,10 +900,15 @@ 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; 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; i++, priv->cur_rx[q]++) { + entry = priv->cur_rx[q] % priv->num_rx_ring[q]; + desc = &priv->rx_ring[q].ex_desc[entry]; + if (rx_packets == *quota || desc->die_dt == DT_FEMPTY) + break; + /* Descriptor type must be checked before all other reads */ dma_rmb(); desc_status = desc->msc; @@ -958,9 +962,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