All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Robin <benjamin.robin@bootlin.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-phy@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org,
	olteanv@gmail.com
Subject: Re: [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link
Date: Thu, 03 Dec 2026 16:56:15 +0100	[thread overview]
Message-ID: <DAkQasmQTcaIDEGTabrLdA@bootlin.com> (raw)
In-Reply-To: <sashiko-outbox-246108@kernel.org>

On Wednesday, December 2, 2026 at 4:31 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] phy: cadence-torrent: NULL pointer dereference in
>   tp_dp_find_used_lanes()
> - [High] phy: cadence-torrent: uninitialized dp_pll and ref_clk in
>   tp_phy_configure()
> - [Medium] phy: cadence-torrent: link->num_lanes set to 0 in
>   tp_dp_find_used_lanes()
> --
> 
> commit 26b8eac666ec602cc77dee851e18adb2e17e76e7
> Author: Benjamin Robin <benjamin.robin@bootlin.com>
> 
> phy: cadence-torrent: allow config on an already-configured DP link
> 
> This commit removes the early return for already-configured PHYs in
> tp_phy_configure() and reads the active DisplayPort lane count from the
> PHY_RESET register during probe when the PHY is already configured.
> 
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 3b4d52ee7a531..0cbbedeefd87a 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> > @@ -1310,6 +1310,27 @@ static int tp_dp_verify_config(const struct tp_link *link,
> >  	return 0;
> >  }
> >  
> > +static void tp_dp_find_used_lanes(const struct tp_data *tp_data, struct tp_link *link)
> > +{
> > +	u32 mlane = link->mlane;
> > +	u32 used_lanes_mask;
> > +	u32 all_lane_mask;
> > +	u32 value;
> > +
> > +	all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
> > +	value = tp_reg_dptx_read(tp_data, PHY_RESET);
> > +
> > +	/* only keep the lanes not in reset */
> > +	used_lanes_mask = value & all_lane_mask;
> > +
> > +	/* only keep the lanes with Tx differential output not into electrical idle */
> > +	used_lanes_mask &= (~(value >> PMA_TX_ELEC_IDLE_SHIFT)) & all_lane_mask;
> > +
> > +	/* update the number of used lanes */
> > +	used_lanes_mask >>= mlane;
> > +	link->num_lanes = __ffs(~used_lanes_mask);
> > +}
> 
> [Severity: Medium]
> Can tp_dp_find_used_lanes() overwrite link->num_lanes with 0 when all
> DisplayPort lanes are held in reset or electrical idle at probe time?

Yes it could, and this should not be an issue, except for the bug described
below.

> In a multi-link setup where the bootloader only configured the non-DP link,
> tp_is_already_configured() still returns true because the shared
> PHY_PMA_CMN_CTRL1 bit 0 is set, while the DP lanes in PHY_RESET have
> used_lanes_mask == 0 and __ffs(~used_lanes_mask) == 0.  If the system
> suspends and resumes before DP link training updates link->num_lanes,
> tp_resume_noirq() -> tp_configure_links() loops over 0 .. link->num_lanes - 1
> and skips programming the per-lane PMA TX/RX CDB registers for the DP link.

In v3 it will not skip programming the per-lane PMA TX/RX CDB registers for
the DP link since max_lanes will be used instead of num_lanes.
So this part of the issue will be fixed.
 
> > @@ -1433,9 +1454,6 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
> >  
> >  	guard(mutex)(&tp_data->lock);
> >  
> > -	if (tp_data->already_configured)
> > -		return 0;
> > -
> >  	if (link->phy_type != TYPE_DP)
> >  		return -EINVAL;
> 
> [Severity: High]
> Will tp_phy_configure() fail with -ETIMEDOUT when opts->dp.set_rate is set
> on an already-configured PHY because tp_data->dp_pll and
> tp_data->ref_clk_rate were never initialized?

In v3 set_rate will be disabled if ref_clks_initialized is false because
already_configured was true. This is technically impossible to configure
the DP rate if the reference clock frequency is unknown.
In practice U-boot does not configure the torrent PHY for DisplayPort link
so already_configured is false in this case.
 
> When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
> both tp_ref_clks_init() and tp_configure_links() (which calls
> cdns_torrent_dp_get_pll()), leaving tp_data->dp_pll and
> tp_data->ref_clk_rate at 0.  When tp_phy_configure() calls
> tp_dp_set_rate() -> tp_dp_configure_rate(), pll_mask is 0 after the lanes
> have already been put into POWERSTATE_A3:
> 
> drivers/phy/cadence/phy-cadence-torrent.c:tp_dp_configure_rate() {
> 	...
> 	pll_mask = tp_data->dp_pll;
> 	...
> 	tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
> 	...
> 	ret = read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) != 0, 0,
> 				POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
> 	...
> }
> 
> Because (val & (pll_mask << 2)) != 0 is always false, tp_dp_configure_rate()
> times out and leaves the DisplayPort lanes powered down.  Later in the
> series, commit "phy: cadence-torrent: rewrite Torrent PHY driver" replaces
> dp_pll with 1U << link->std_idx, but tp_ref_clks_init() and
> tp_init_plls_data() are still skipped when tp_data->already_configured is
> true, leaving pll->ref_clk_khz at 0 in tp_write_pll_regs().
> 
> [ ... ]
> 
> > @@ -2750,6 +2778,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> >  		ret = tp_ref_clks_init(tp_data);
> >  		if (ret)
> >  			goto cleanup;
> > +	} else {
> > +		tp_init_already_configured_links_opts(tp_data);
> >  	}
> >  
> >  	ret = tp_dp_reg_base_init(pdev, tp_data);
> 
> [Severity: High]
> Does calling tp_init_already_configured_links_opts() before
> tp_dp_reg_base_init() cause a NULL pointer dereference on tp_data->base?
> 
> When tp_data->already_configured is true and a TYPE_DP link is present,
> tp_init_already_configured_links_opts() -> tp_dp_find_used_lanes() ->
> tp_reg_dptx_read() reads from tp_data->base + PHY_RESET, but tp_data->base
> is only ioremapped in tp_dp_reg_base_init() immediately afterwards.

Yes it does... It will be fixed in v3


-- 
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com




WARNING: multiple messages have this Message-ID (diff)
From: Benjamin Robin <benjamin.robin@bootlin.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-phy@lists.infradead.org, robh@kernel.org,
	conor+dt@kernel.org, vkoul@kernel.org, neil.armstrong@linaro.org,
	olteanv@gmail.com
Subject: Re: [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link
Date: Thu, 03 Dec 2026 16:56:15 +0100	[thread overview]
Message-ID: <DAkQasmQTcaIDEGTabrLdA@bootlin.com> (raw)
In-Reply-To: <sashiko-outbox-246108@kernel.org>

On Wednesday, December 2, 2026 at 4:31 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [High] phy: cadence-torrent: NULL pointer dereference in
>   tp_dp_find_used_lanes()
> - [High] phy: cadence-torrent: uninitialized dp_pll and ref_clk in
>   tp_phy_configure()
> - [Medium] phy: cadence-torrent: link->num_lanes set to 0 in
>   tp_dp_find_used_lanes()
> --
> 
> commit 26b8eac666ec602cc77dee851e18adb2e17e76e7
> Author: Benjamin Robin <benjamin.robin@bootlin.com>
> 
> phy: cadence-torrent: allow config on an already-configured DP link
> 
> This commit removes the early return for already-configured PHYs in
> tp_phy_configure() and reads the active DisplayPort lane count from the
> PHY_RESET register during probe when the PHY is already configured.
> 
> > diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> > index 3b4d52ee7a531..0cbbedeefd87a 100644
> > --- a/drivers/phy/cadence/phy-cadence-torrent.c
> > +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> > @@ -1310,6 +1310,27 @@ static int tp_dp_verify_config(const struct tp_link *link,
> >  	return 0;
> >  }
> >  
> > +static void tp_dp_find_used_lanes(const struct tp_data *tp_data, struct tp_link *link)
> > +{
> > +	u32 mlane = link->mlane;
> > +	u32 used_lanes_mask;
> > +	u32 all_lane_mask;
> > +	u32 value;
> > +
> > +	all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
> > +	value = tp_reg_dptx_read(tp_data, PHY_RESET);
> > +
> > +	/* only keep the lanes not in reset */
> > +	used_lanes_mask = value & all_lane_mask;
> > +
> > +	/* only keep the lanes with Tx differential output not into electrical idle */
> > +	used_lanes_mask &= (~(value >> PMA_TX_ELEC_IDLE_SHIFT)) & all_lane_mask;
> > +
> > +	/* update the number of used lanes */
> > +	used_lanes_mask >>= mlane;
> > +	link->num_lanes = __ffs(~used_lanes_mask);
> > +}
> 
> [Severity: Medium]
> Can tp_dp_find_used_lanes() overwrite link->num_lanes with 0 when all
> DisplayPort lanes are held in reset or electrical idle at probe time?

Yes it could, and this should not be an issue, except for the bug described
below.

> In a multi-link setup where the bootloader only configured the non-DP link,
> tp_is_already_configured() still returns true because the shared
> PHY_PMA_CMN_CTRL1 bit 0 is set, while the DP lanes in PHY_RESET have
> used_lanes_mask == 0 and __ffs(~used_lanes_mask) == 0.  If the system
> suspends and resumes before DP link training updates link->num_lanes,
> tp_resume_noirq() -> tp_configure_links() loops over 0 .. link->num_lanes - 1
> and skips programming the per-lane PMA TX/RX CDB registers for the DP link.

In v3 it will not skip programming the per-lane PMA TX/RX CDB registers for
the DP link since max_lanes will be used instead of num_lanes.
So this part of the issue will be fixed.
 
> > @@ -1433,9 +1454,6 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
> >  
> >  	guard(mutex)(&tp_data->lock);
> >  
> > -	if (tp_data->already_configured)
> > -		return 0;
> > -
> >  	if (link->phy_type != TYPE_DP)
> >  		return -EINVAL;
> 
> [Severity: High]
> Will tp_phy_configure() fail with -ETIMEDOUT when opts->dp.set_rate is set
> on an already-configured PHY because tp_data->dp_pll and
> tp_data->ref_clk_rate were never initialized?

In v3 set_rate will be disabled if ref_clks_initialized is false because
already_configured was true. This is technically impossible to configure
the DP rate if the reference clock frequency is unknown.
In practice U-boot does not configure the torrent PHY for DisplayPort link
so already_configured is false in this case.
 
> When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
> both tp_ref_clks_init() and tp_configure_links() (which calls
> cdns_torrent_dp_get_pll()), leaving tp_data->dp_pll and
> tp_data->ref_clk_rate at 0.  When tp_phy_configure() calls
> tp_dp_set_rate() -> tp_dp_configure_rate(), pll_mask is 0 after the lanes
> have already been put into POWERSTATE_A3:
> 
> drivers/phy/cadence/phy-cadence-torrent.c:tp_dp_configure_rate() {
> 	...
> 	pll_mask = tp_data->dp_pll;
> 	...
> 	tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
> 	...
> 	ret = read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) != 0, 0,
> 				POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
> 	...
> }
> 
> Because (val & (pll_mask << 2)) != 0 is always false, tp_dp_configure_rate()
> times out and leaves the DisplayPort lanes powered down.  Later in the
> series, commit "phy: cadence-torrent: rewrite Torrent PHY driver" replaces
> dp_pll with 1U << link->std_idx, but tp_ref_clks_init() and
> tp_init_plls_data() are still skipped when tp_data->already_configured is
> true, leaving pll->ref_clk_khz at 0 in tp_write_pll_regs().
> 
> [ ... ]
> 
> > @@ -2750,6 +2778,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> >  		ret = tp_ref_clks_init(tp_data);
> >  		if (ret)
> >  			goto cleanup;
> > +	} else {
> > +		tp_init_already_configured_links_opts(tp_data);
> >  	}
> >  
> >  	ret = tp_dp_reg_base_init(pdev, tp_data);
> 
> [Severity: High]
> Does calling tp_init_already_configured_links_opts() before
> tp_dp_reg_base_init() cause a NULL pointer dereference on tp_data->base?
> 
> When tp_data->already_configured is true and a TYPE_DP link is present,
> tp_init_already_configured_links_opts() -> tp_dp_find_used_lanes() ->
> tp_reg_dptx_read() reads from tp_data->base + PHY_RESET, but tp_data->base
> is only ioremapped in tp_dp_reg_base_init() immediately afterwards.

Yes it does... It will be fixed in v3


-- 
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com




-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-12-03 15:56 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:24   ` sashiko-bot
2026-12-02 15:24     ` sashiko-bot
2026-12-03 13:59     ` Benjamin Robin
2026-12-03 13:59       ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 02/22] drm/bridge: cdns-mhdp8546: Power on/off the PHY in probe/remove Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 03/22] dt-bindings: phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 05/22] phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-04 11:50   ` Swapnil Kashinath Jakhade
2026-12-04 11:50     ` Swapnil Kashinath Jakhade
2026-12-04 14:00     ` Benjamin Robin
2026-12-04 14:00       ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 08/22] phy: cadence-torrent: replace regmap with readw/writew Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 10/22] phy: cadence-torrent: drop diag_tx_drv from DP voltage coeff Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:28   ` sashiko-bot
2026-12-02 15:28     ` sashiko-bot
2026-12-03 15:11     ` Benjamin Robin
2026-12-03 15:11       ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider() Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 13/22] phy: cadence-torrent: rework subnode parsing and lane validation Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
2026-12-02 15:08   ` Benjamin Robin
2026-12-02 15:24   ` sashiko-bot
2026-12-02 15:24     ` sashiko-bot
2026-12-03 14:27     ` Benjamin Robin
2026-12-03 14:27       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 15/22] phy: cadence-torrent: factor out DP PLL frequency update Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 16/22] phy: cadence-torrent: store clock and reset handles only on success Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:37   ` sashiko-bot
2026-12-02 15:37     ` sashiko-bot
2026-12-03 17:16     ` Benjamin Robin
2026-12-03 17:16       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:31   ` sashiko-bot
2026-12-02 15:31     ` sashiko-bot
2026-12-03 15:56     ` Benjamin Robin [this message]
2026-12-03 15:56       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 19/22] phy: cadence-torrent: track current DP link bit rate Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:34   ` sashiko-bot
2026-12-02 15:34     ` sashiko-bot
2026-12-03 17:04     ` Benjamin Robin
2026-12-03 17:04       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:38   ` sashiko-bot
2026-12-02 15:38     ` sashiko-bot
2026-12-02 17:18     ` Benjamin Robin
2026-12-02 17:18       ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY Benjamin Robin
2026-12-02 15:09   ` Benjamin Robin
2026-12-02 15:30   ` sashiko-bot
2026-12-02 15:30     ` sashiko-bot
2026-12-03 15:16     ` Benjamin Robin
2026-12-03 15:16       ` Benjamin Robin

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=DAkQasmQTcaIDEGTabrLdA@bootlin.com \
    --to=benjamin.robin@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.