public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Siddharth Vadapalli <s-vadapalli@ti.com>
To: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Cc: Tom Rini <trini@konsulko.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>,
	MD Danish Anwar <danishanwar@ti.com>,
	Jai Luthra <j-luthra@ti.com>,
	Siddharth Vadapalli <s-vadapalli@ti.com>,
	Nishanth Menon <nm@ti.com>, Udit Kumar <u-kumar1@ti.com>,
	Suman Anna <s-anna@ti.com>, <u-boot@lists.denx.de>,
	<u-boot@ew.tq-group.com>
Subject: Re: [PATCH 1/5] net: eth-uclass: guard against reentrant eth_init()/eth_halt() calls
Date: Fri, 26 Apr 2024 13:39:34 +0530	[thread overview]
Message-ID: <2d0e7f23-54a9-4435-bb2e-e22378331ccf@ti.com> (raw)
In-Reply-To: <de7fe2da7ae4a85252d63904fae61585e4641936.1714117337.git.matthias.schiffer@ew.tq-group.com>

On Fri, Apr 26, 2024 at 10:02:24AM +0200, Matthias Schiffer wrote:
> With netconsole, any log message can result in an eth_init(), possibly
> causing an reentrant call into eth_init() if a driver's ops print
> anything:
> 
>     eth_init() -> driver.start() -> printf() -> netconsole -> eth_init()
>     eth_halt() -> driver.stop() -> printf() -> netconsole -> eth_init()
> 
> Rather than expecting every single Ethernet driver to handle this case,
> prevent the reentrant calls in eth_init() and eth_halt().
> 
> The issue was noticed on an AM62x board, where a bootm after
> simultaneous netconsole and TFTP would result in a crash.

Link: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1350550/sk-am62a-lp-am65_cpsw_nuss_port-error-in-u-boot-while-using-netconsole-functionality/

> 
> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
> ---
>  net/eth-uclass.c | 40 ++++++++++++++++++++++++++++++++--------
>  1 file changed, 32 insertions(+), 8 deletions(-)
> 
> diff --git a/net/eth-uclass.c b/net/eth-uclass.c
> index 3d0ec91dfa4..193218a328b 100644
> --- a/net/eth-uclass.c
> +++ b/net/eth-uclass.c
> @@ -48,6 +48,8 @@ struct eth_uclass_priv {
>  
>  /* eth_errno - This stores the most recent failure code from DM functions */
>  static int eth_errno;
> +/* Are we currently in eth_init() or eth_halt()? */
> +static bool in_init_halt;
>  
>  /* board-specific Ethernet Interface initializations. */
>  __weak int board_interface_eth_init(struct udevice *dev,
> @@ -285,11 +287,19 @@ U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
>  
>  int eth_init(void)
>  {
> -	char *ethact = env_get("ethact");
> -	char *ethrotate = env_get("ethrotate");
>  	struct udevice *current = NULL;
>  	struct udevice *old_current;
>  	int ret = -ENODEV;
> +	char *ethrotate;
> +	char *ethact;
> +
> +	if (in_init_halt)
> +		return -EBUSY;
> +
> +	in_init_halt = true;
> +
> +	ethact = env_get("ethact");
> +	ethrotate = env_get("ethrotate");
>  
>  	/*
>  	 * When 'ethrotate' variable is set to 'no' and 'ethact' variable
> @@ -298,8 +308,10 @@ int eth_init(void)
>  	if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0)) {
>  		if (ethact) {
>  			current = eth_get_dev_by_name(ethact);
> -			if (!current)
> -				return -EINVAL;
> +			if (!current) {
> +				ret = -EINVAL;
> +				goto end;
> +			}
>  		}
>  	}
>  
> @@ -307,7 +319,8 @@ int eth_init(void)
>  		current = eth_get_dev();
>  		if (!current) {
>  			log_err("No ethernet found.\n");
> -			return -ENODEV;
> +			ret = -ENODEV;
> +			goto end;
>  		}
>  	}
>  
> @@ -324,7 +337,8 @@ int eth_init(void)
>  
>  					priv->state = ETH_STATE_ACTIVE;
>  					priv->running = true;
> -					return 0;
> +					ret = 0;
> +					goto end;
>  				}
>  			} else {
>  				ret = eth_errno;
> @@ -344,6 +358,8 @@ int eth_init(void)
>  		current = eth_get_dev();
>  	} while (old_current != current);
>  
> +end:
> +	in_init_halt = false;
>  	return ret;
>  }
>  
> @@ -352,17 +368,25 @@ void eth_halt(void)
>  	struct udevice *current;
>  	struct eth_device_priv *priv;
>  
> +	if (in_init_halt)
> +		return;
> +
> +	in_init_halt = true;
> +
>  	current = eth_get_dev();
>  	if (!current)
> -		return;
> +		goto end;
>  
>  	priv = dev_get_uclass_priv(current);
>  	if (!priv || !priv->running)
> -		return;
> +		goto end;
>  
>  	eth_get_ops(current)->stop(current);
>  	priv->state = ETH_STATE_PASSIVE;
>  	priv->running = false;
> +
> +end:
> +	in_init_halt = false;
>  }
>  
>  int eth_is_active(struct udevice *dev)
> -- 
> TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
> Amtsgericht München, HRB 105018
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> https://www.tq-group.com/
> 

  parent reply	other threads:[~2024-04-26  8:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26  8:02 [PATCH 1/5] net: eth-uclass: guard against reentrant eth_init()/eth_halt() calls Matthias Schiffer
2024-04-26  8:02 ` [PATCH 2/5] net: ti: am65-cpsw-nuss: avoid errors due to imbalanced start()/stop() Matthias Schiffer
2024-04-26  8:02 ` [PATCH 3/5] net: ti: am65-cpsw-nuss: fix error handling for "RX dma add buf failed" Matthias Schiffer
2024-04-26  8:02 ` [PATCH 4/5] dma: ti: k3-udma: add missing <net.h> include Matthias Schiffer
2024-04-26  8:02 ` [PATCH 5/5] dma: ti: k3-udma: invalidate prepared buffers before pushing to recv ring Matthias Schiffer
2024-05-03 18:42   ` Sverdlin, Alexander
2024-04-26  8:09 ` Siddharth Vadapalli [this message]
2024-05-15 23:28 ` [PATCH 1/5] net: eth-uclass: guard against reentrant eth_init()/eth_halt() calls Tom Rini

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=2d0e7f23-54a9-4435-bb2e-e22378331ccf@ti.com \
    --to=s-vadapalli@ti.com \
    --cc=danishanwar@ti.com \
    --cc=j-luthra@ti.com \
    --cc=joe.hershberger@ni.com \
    --cc=matthias.schiffer@ew.tq-group.com \
    --cc=nm@ti.com \
    --cc=rfried.dev@gmail.com \
    --cc=s-anna@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@ew.tq-group.com \
    --cc=u-boot@lists.denx.de \
    --cc=u-kumar1@ti.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