netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Ioana Ciornei <ioana.ciornei@nxp.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	Ioana Radulescu <ruxandra.radulescu@nxp.com>
Subject: Re: [PATCH 3/3] dpaa2-eth: Avoid unbounded while loops
Date: Fri, 4 Oct 2019 20:18:28 +0200	[thread overview]
Message-ID: <20191004181828.GB9935@lunn.ch> (raw)
In-Reply-To: <1570180893-9538-4-git-send-email-ioana.ciornei@nxp.com>

On Fri, Oct 04, 2019 at 12:21:33PM +0300, Ioana Ciornei wrote:
> From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
> 
> Throughout the driver there are several places where we wait
> indefinitely for DPIO portal commands to be executed, while
> the portal returns a busy response code.
> 
> Even though in theory we are guaranteed the portals become
> available eventually, in practice the QBMan hardware module
> may become unresponsive in various corner cases.
> 
> Make sure we can never get stuck in an infinite while loop
> by adding a retry counter for all portal commands.
> 
> Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
>  drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 30 ++++++++++++++++++++----
>  drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h |  8 +++++++
>  2 files changed, 33 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
> index 2c5072fa9aa0..29702756734c 100644
> --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
> +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
> @@ -221,6 +221,7 @@ static void xdp_release_buf(struct dpaa2_eth_priv *priv,
>  			    struct dpaa2_eth_channel *ch,
>  			    dma_addr_t addr)
>  {
> +	int retries = 0;
>  	int err;
>  
>  	ch->xdp.drop_bufs[ch->xdp.drop_cnt++] = addr;
> @@ -229,8 +230,11 @@ static void xdp_release_buf(struct dpaa2_eth_priv *priv,
>  
>  	while ((err = dpaa2_io_service_release(ch->dpio, priv->bpid,
>  					       ch->xdp.drop_bufs,
> -					       ch->xdp.drop_cnt)) == -EBUSY)
> +					       ch->xdp.drop_cnt)) == -EBUSY) {
> +		if (retries++ >= DPAA2_ETH_SWP_BUSY_RETRIES)
> +			break;
>  		cpu_relax();
> +	}
>  
>  	if (err) {
>  		free_bufs(priv, ch->xdp.drop_bufs, ch->xdp.drop_cnt);
> @@ -458,7 +462,7 @@ static int consume_frames(struct dpaa2_eth_channel *ch,
>  	struct dpaa2_eth_fq *fq = NULL;
>  	struct dpaa2_dq *dq;
>  	const struct dpaa2_fd *fd;
> -	int cleaned = 0;
> +	int cleaned = 0, retries = 0;
>  	int is_last;
>  
>  	do {
> @@ -469,6 +473,11 @@ static int consume_frames(struct dpaa2_eth_channel *ch,
>  			 * the store until we get some sort of valid response
>  			 * token (either a valid frame or an "empty dequeue")
>  			 */
> +			if (retries++ >= DPAA2_ETH_SWP_BUSY_RETRIES) {
> +				netdev_err_once(priv->net_dev,
> +						"Unable to read a valid dequeue response\n");
> +				return 0;
> +			}
>  			continue;

Hi Ioana

It seems a bit odd that here you could return -ETIMEDOUT, but you
print an error, and return 0. But in the two cases above in void
functions, you don't print anything.

Please at least return -ETIMEDOUT when you can.

       Andrew

  reply	other threads:[~2019-10-04 18:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04  9:21 [PATCH 0/3] dpaa2-eth: misc cleanup Ioana Ciornei
2019-10-04  9:21 ` [PATCH 1/3] dpaa2-eth: Cleanup dead code Ioana Ciornei
2019-10-04  9:21 ` [PATCH 2/3] dpaa2-eth: Fix minor bug in ethtool stats reporting Ioana Ciornei
2019-10-04  9:21 ` [PATCH 3/3] dpaa2-eth: Avoid unbounded while loops Ioana Ciornei
2019-10-04 18:18   ` Andrew Lunn [this message]
2019-10-07 10:49     ` Ioana Ciornei

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=20191004181828.GB9935@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=ioana.ciornei@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=ruxandra.radulescu@nxp.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;
as well as URLs for NNTP newsgroup(s).