Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp904978lqp; Sun, 14 Apr 2024 05:17:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZRG9VgpTUkJyw6QHAUgNcX+ObIcPXnUC9kAWjKpUrQPXixwGyJcuHQLhCtFfYWwJ6qZePLXcUVvwKjML99qLxsuVd2mYQTunLm+HO6w== X-Google-Smtp-Source: AGHT+IEft/1uHSb/WQF9Cks0j3gdGi2W5h5+mp58xmLRxiQA2Q0xQDhQ1O9sBG2bZZzVDZGAXwYQ X-Received: by 2002:a17:906:c113:b0:a52:1b82:9948 with SMTP id do19-20020a170906c11300b00a521b829948mr9369595ejc.8.1713097060764; Sun, 14 Apr 2024 05:17:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713097060; cv=pass; d=google.com; s=arc-20160816; b=R9XDvr6h/qWRNIx1RiRUCz5diMgONYGaUSqEeOT3Ng73ruI/UTzwPxbhOf+WKVjybi eNic0Aa4322haQolRlTdy06KmXKVFw6t2Y65t+Rxbt1+MIqV+0uPBI+Pilo6t4fE68HR Ekfn4wfYrcG7Cc6rd+fnnpgjeV7YQpnb7ptzqsnNQlEDcQ/uKoza+zSn0EMRYgPaGQmU qQPM71UOZ65g7BpQ8MPGuscvm4idqCYGFfb98ow7akK0ncvmztlWrav/qT9i7Pwa+OTg 6oYeg5DD6bzDWPPv1ZIthk7LQ+S3UAviSrX3hrNZcMp8EcngMmiYBcG/4BQRH3o5Yz4X vddA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=RKm9SRPHzGh7i5KA9jjXdJiE10zpNkW/BL5dL5EFRys=; fh=LbA1AiCJIYDpy+C6TAfuko8HF2F2WoixWGNfqbi6gRk=; b=cEf4bO+8DFWk2J+0t3RcdTuN7kjZcnWekm25ArbH6+Kc7WODdN/UVqRg8w5d4UsOna Ka9yTvR8VfvUsA2Dl23JK5YMfv2UnE5U+FucgYcU8a/Cp1J8dZNT/Xci2DiEHQHJLT+1 lH13cpc2+/OVqp8V5Kw9vFDRBvFjNgAQb/g29toFGUSkwioqYb0o51XsIO8JGuhIrkCb MJafPGH/+UCZi92j8BtQWgyW+mZfxhIpXw5sZ41XSgLkv1TU/8rgcL17il3SdrrWnhL0 RylI+3kMMOnAMP8n5Q703mSd7H22ptYIq/Mj6pAD4M/iZlPUd7CZbK+2ea3RE8VwhY3K dWRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ragnatech.se header.s=fm1 header.b=x+Ov1Cp4; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ndCiiagD; arc=pass (i=1 spf=pass spfdomain=ragnatech.se dkim=pass dkdomain=ragnatech.se dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=ragnatech.se); spf=pass (google.com: domain of linux-kernel+bounces-144135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144135-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ragnatech.se Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 25-20020a508e19000000b0056e69cc6b20si3607095edw.267.2024.04.14.05.17.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 05:17:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ragnatech.se header.s=fm1 header.b=x+Ov1Cp4; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ndCiiagD; arc=pass (i=1 spf=pass spfdomain=ragnatech.se dkim=pass dkdomain=ragnatech.se dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=ragnatech.se); spf=pass (google.com: domain of linux-kernel+bounces-144135-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144135-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ragnatech.se 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4CDA11F217CC for ; Sun, 14 Apr 2024 12:17:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC36243165; Sun, 14 Apr 2024 12:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="x+Ov1Cp4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ndCiiagD" Received: from wflow2-smtp.messagingengine.com (wflow2-smtp.messagingengine.com [64.147.123.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4E5B1DFFC; Sun, 14 Apr 2024 12:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.137 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713097047; cv=none; b=azsiyeXub8BHEVaw1+Vr9rTlD/VXRJHRTaR4i3WmWwfeqRR774D4bVClLkgsulkiKb/44apV8MNSFrnhCBa2iXXBB6MG4jC1ORmqjM+t2Q3AvvfME4TIur3zJhgqO/IONQ+HcV05nDmkJpRJERYhUM0SqEPTJ1sZ5UjgSQg5n/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713097047; c=relaxed/simple; bh=wL+WFy4GoNoaKZAqu+EsyXXdksBpg/OLkVQWR8iJ990=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dSVqGrrNsyTJeq6HF5VANFQnQQemdB3urbG+CyZs0LdQZ9s+cI9xSy54qaKxpvleOnhj5dW2OKNqbuH/hA37BH1CCSR0k6hbPhK0eU/GrOsMdNel4xFP8F13mfu/5TKFJFnFbnZHPy1MXNodJ3R8M4XbmnynON4JHVmstFEVdrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=x+Ov1Cp4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ndCiiagD; arc=none smtp.client-ip=64.147.123.137 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailflow.west.internal (Postfix) with ESMTP id 328EB2CC035B; Sun, 14 Apr 2024 08:17:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 14 Apr 2024 08:17:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1713097042; x=1713100642; bh=RKm9SRPHzGh7i5KA9jjXdJiE10zpNkW/BL5dL5EFRys=; b= x+Ov1Cp42k3HQVSo+EaeT/zy78QdYE+MK6igj5CVIs5yYSpDXDy5FbMSVPHea/By bd4E+LWUKjtHspCLEOTJ2ayqP5PNvMD+5AzPGt8HrgmEf3ycRr6q2W1mIQEpTDAO XbhQuw48DgrDkqOyK7glWStjQwbcY7Swc+miNNRc5Ff4vUPV/PlClyXn2i880OWG 9zKFB+vgnHJv0LAESfiWfwvQw8cXMhqrNLdanOeBRRLNhJ5OkM41QEwml/8q++Zn 8AuReHTtI+CDXEYZ973NJw/PkO5WPi+jo7ocftSzmQTzT0Zq8UCt+fId5zW0U+V+ h4xA1QCx7IfpIORgD+ebWg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1713097042; x= 1713100642; bh=RKm9SRPHzGh7i5KA9jjXdJiE10zpNkW/BL5dL5EFRys=; b=n dCiiagDN5EOx9qGL3bfjqp17kA+GuPuhjPiNX5etXpXlyXU/sYFhCQI7jyLDtF5O SEYk/xjMFqcROpDafJ89rXhz2h7Hd0tsDPWZSaDuMDXeQHQO4XbIIhsRAMgTjb/o WsifhYkeMYsr4rrR39ZNiHV46LM2swcqlNDaqYFmCOdBMJaYNpEOEA+BuzKrWdss iuaa5nuPzbx/lf+ggFzwD7GSHFCdf/YOvbL04dM31zJW2N39eVhvW7zEvzKVnjq3 6S4pZsNK7rF0PAG93epIp9HEsiffwHGlGPrUGJBdhTydrIXGSJesjl6b8LNA2NLz IV8J3S8IzCsb9ejZ40CKg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeiledghedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpefpihhk lhgrshcuufpnuggvrhhluhhnugcuoehnihhklhgrshdrshhouggvrhhluhhnugdorhgvnh gvshgrshesrhgrghhnrghtvggthhdrshgvqeenucggtffrrghtthgvrhhnpeefhfellefh ffejgfefudfggeejlefhveehieekhfeulefgtdefueehffdtvdelieenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehnihhklhgrshdrshhouggv rhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgv X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 14 Apr 2024 08:17:21 -0400 (EDT) Date: Sun, 14 Apr 2024 14:17:19 +0200 From: Niklas =?utf-8?Q?S=C3=B6derlund?= To: Paul Barker Cc: Sergey Shtylyov , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Geert Uytterhoeven , 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 Message-ID: <20240414121719.GB2860391@ragnatech.se> References: <20240411114434.26186-1-paul.barker.ct@bp.renesas.com> <20240411114434.26186-3-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-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240411114434.26186-3-paul.barker.ct@bp.renesas.com> 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 > --- > 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; ... } > + > /* 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 > -- Kind Regards, Niklas Söderlund