public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Raju.Rangoju@amd.com
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
	andrew+netdev@lunn.ch, pabeni@redhat.com,
	Thomas.Lendacky@amd.com, maxime.chevallier@bootlin.com,
	edumazet@google.com, linux-kernel@vger.kernel.org
Subject: Re: [net] amd-xgbe: synchronize KR training with device operations
Date: Tue, 17 Mar 2026 13:08:05 +0100	[thread overview]
Message-ID: <20260317120805.163436-1-pabeni@redhat.com> (raw)
In-Reply-To: <20260313134210.3824872-1-Raju.Rangoju@amd.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
amd-xgbe: synchronize KR training with device operations

This commit adds synchronization to prevent device operations from
interrupting active KR training by introducing a mailbox mutex and waiting
for KR training completion before proceeding with stop/rate change
operations.

> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
> index 23beea48ae26..3913eb7e1da3 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c

[ ... ]

> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
> index b8cf6ccfe641..142eb952a29c 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c

[ ... ]

> @@ -2095,12 +2095,57 @@ static void xgbe_phy_pll_ctrl(struct xgbe_prv_data *pdata, bool enable)
>  	usleep_range(100, 200);
>  }
>
> +static bool xgbe_phy_port_is_inphi(struct xgbe_prv_data *pdata)
> +{
> +	struct xgbe_phy_data *phy_data = pdata->phy_data;
> +
> +	/* Re-driver models 4223 && 4227 are supported Inphi models */
> +	return phy_data->redrv &&
> +	       (phy_data->redrv_model == XGBE_PHY_REDRV_MODEL_4223 ||
> +		phy_data->redrv_model == XGBE_PHY_REDRV_MODEL_4227);
> +}
> +
> +void xgbe_check_kr_training_in_progress(struct xgbe_prv_data *pdata)
> +{
> +	struct xgbe_phy_data *phy_data = pdata->phy_data;
> +	unsigned long kr_timeout;
> +	int wait;
> +
> +	/* Only wait for KR training in specific conditions:
> +	 *  - Inphi re-driver is present, OR
> +	 *  - Currently in KR mode with autoneg enabled
> +	 */
> +	if (!xgbe_phy_port_is_inphi(pdata) &&
> +	    !(phy_data->cur_mode == XGBE_MODE_KR &&
> +	      pdata->phy.autoneg == AUTONEG_ENABLE))
> +		return;
> +
> +	wait = XGBE_KR_TRAINING_WAIT_ITER;
> +	while (wait--) {
> +		/* Check if we've exceeded the AN timeout window */
> +		kr_timeout = pdata->kr_start_time +
> +			msecs_to_jiffies(XGBE_AN_MS_TIMEOUT +
> +					XGBE_KR_TRAINING_WAIT_MS);
> +		if (time_after(jiffies, kr_timeout))
> +			break;
> +
> +		/* Training is complete - no need to wait */
> +		if (pdata->an_result == XGBE_AN_COMPLETE)
> +			return;
> +
> +		usleep_range(10000, 11000);
> +	}
> +}
> +
>  static void xgbe_phy_perform_ratechange(struct xgbe_prv_data *pdata,
> -					enum xgbe_mb_cmd cmd, enum xgbe_mb_subcmd sub_cmd)
> +					enum xgbe_mb_cmd cmd,
> +					enum xgbe_mb_subcmd sub_cmd)
>  {
>  	unsigned int s0 = 0;
>  	unsigned int wait;
>
> +	xgbe_check_kr_training_in_progress(pdata);
> +
>  	/* Disable PLL re-initialization during FW command processing */
>  	xgbe_phy_pll_ctrl(pdata, false);
>
> @@ -2115,7 +2160,9 @@ static void xgbe_phy_perform_ratechange(struct xgbe_prv_data *pdata,
>  	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, COMMAND, cmd);
>  	XP_SET_BITS(s0, XP_DRIVER_SCRATCH_0, SUB_COMMAND, sub_cmd);
>
> -	/* Issue the command */
> +	/* Acquire mailbox lock for firmware command */
> +	guard(mutex)(&pdata->mailbox_lock);
> +

Can this cause a recursive deadlock? xgbe_phy_perform_ratechange() acquires
mailbox_lock, but when called with sub_cmd XGBE_MB_SUBCMD_RX_ADAP, it goes
through do_rx_adaptation which calls xgbe_phy_rx_adaptation().

xgbe_phy_rx_adaptation() has two code paths that both lead back to
xgbe_phy_perform_ratechange():

Path 1:
    xgbe_phy_rx_adaptation()
        -> xgbe_phy_rrc()
            -> xgbe_phy_perform_ratechange(pdata, XGBE_MB_CMD_RRC, ...)
                -> guard(mutex)(&pdata->mailbox_lock)  // deadlock

Path 2:
    xgbe_phy_rx_adaptation()
        -> xgbe_rx_adaptation()
            -> xgbe_set_rx_adap_mode()
                -> xgbe_phy_perform_ratechange(...)
                    -> guard(mutex)(&pdata->mailbox_lock)  // deadlock

Since kernel mutexes are not recursive, attempting to lock an already-held
mutex from the same thread causes a permanent deadlock.

>  	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_0, s0);
>  	XP_IOWRITE(pdata, XP_DRIVER_SCRATCH_1, 0);
>  	XP_IOWRITE_BITS(pdata, XP_DRIVER_INT_REQ, REQUEST, 1);

[ ... ]


  reply	other threads:[~2026-03-17 12:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-13 13:42 [PATCH net] amd-xgbe: synchronize KR training with device operations Raju Rangoju
2026-03-17 12:08 ` Paolo Abeni [this message]
2026-03-17 12:09 ` Paolo Abeni

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=20260317120805.163436-1-pabeni@redhat.com \
    --to=pabeni@redhat.com \
    --cc=Raju.Rangoju@amd.com \
    --cc=Thomas.Lendacky@amd.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    /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