All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Coia Prant" <coiaprant@gmail.com>
Cc: olteanv@gmail.com, linux-phy@lists.infradead.org,
	neil.armstrong@linaro.org, devicetree@vger.kernel.org,
	robh@kernel.org, vkoul@kernel.org, conor+dt@kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
Date: Tue, 08 Sep 2026 15:40:50 +0000	[thread overview]
Message-ID: <20260908154108.6864E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907153713.2572547-9-coiaprant@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in xpcs_rk_create allows a concurrent unbind of the supplier to free the MDIO bus, leading to a Use-After-Free.
- [Medium] Incorrect LIFO teardown ordering in devres clock cleanup action violates proper device initialization and PM hierarchy rules.
--

commit 7142dbf6b28b5ee94d0edc969bcf16d1183a5f41
Author: Coia Prant <coiaprant@gmail.com>

net: pcs: xpcs: add Rockchip RK3568 platform glue driver

This commit adds a platform glue driver for the Synopsys DesignWare xpcs
integrated in the Rockchip RK3568 SoC. It creates a virtual mdio bus to
translate mdio operations to apb3 memory-mapped register accesses.

Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part2%20V1.1-20210301.pdf (Page 2078)

> diff --git a/drivers/net/pcs/pcs-xpcs-rk.c b/drivers/net/pcs/pcs-xpcs-rk.c
> new file mode 100644
> index 0000000000000..68bcaa1a5cbbf
> --- /dev/null
> +++ b/drivers/net/pcs/pcs-xpcs-rk.c
[ ... ]
> +static void xpcs_rk_exit_clk(void *data)
> +{
> +	struct dw_xpcs_rk *pxpcs = data;
> +	struct device *dev = &pxpcs->pdev->dev;
> +
> +	clk_disable_unprepare(pxpcs->eee_clk);
> +
> +	pm_runtime_force_suspend(dev);

[Severity: Medium]
Does this sequence result in the clock being disabled before the device is
suspended?

In xpcs_rk_init_clk(), eee_clk is enabled first, followed by a call to
pm_runtime_enable(), allowing the device to become runtime active. During 
teardown, pm_runtime_force_suspend() invokes xpcs_rk_pm_runtime_suspend()
to disable csr_clk.

Calling clk_disable_unprepare() for eee_clk before pm_runtime_force_suspend() 
violates last-in, first-out ordering, disabling the prerequisite clock while
the device is still considered active. Should pm_runtime_force_suspend() be
called prior to disabling the eee_clk?

> +}
[ ... ]
> +struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *np)
> +{
[ ... ]
> +	device_lock(&pdev->dev);
> +	pxpcs = platform_get_drvdata(pdev);
> +	if (!pxpcs || !pxpcs->bus) {
> +		device_unlock(&pdev->dev);
> +		put_device(&pdev->dev);
> +		return ERR_PTR(-EPROBE_DEFER);
> +	}
> +
> +	xpcs = xpcs_create_mdiodev(pxpcs->bus, (int)port);
> +	device_unlock(&pdev->dev);

[Severity: High]
Does dropping the device lock here introduce a time-of-check to time-of-use
race condition?

If a concurrent unbind of the rk_xpcs-dwxpcs supplier driver occurs 
immediately after device_unlock() but before device_link_add(), the unbind 
would trigger devres cleanup, freeing the mdio bus.

> +	if (IS_ERR(xpcs)) {
> +		put_device(&pdev->dev);
> +		return xpcs;
> +	}
> +
> +	if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {

Since device_link_add() permits linking to devices without drivers, it could
succeed even if the supplier was just unbound. The consumer driver would then
resume probing with the returned xpcs pointer referencing a freed mdio bus,
leading to a use-after-free when the mac driver attempts to read or write
pcs registers.

Could the device_link_add() call be moved inside the lock block protected
by device_lock() to safely establish the dependency before the lock is
released?

> +		xpcs_destroy(xpcs);
> +		put_device(&pdev->dev);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	put_device(&pdev->dev);
> +	return xpcs;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260907153713.2572547-2-coiaprant@gmail.com?part=7

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Coia Prant" <coiaprant@gmail.com>
Cc: olteanv@gmail.com, linux-phy@lists.infradead.org,
	neil.armstrong@linaro.org, devicetree@vger.kernel.org,
	robh@kernel.org, vkoul@kernel.org, conor+dt@kernel.org,
	wsa+renesas@sang-engineering.com
Subject: Re: [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver
Date: Tue, 08 Sep 2026 15:40:50 +0000	[thread overview]
Message-ID: <20260908154108.6864E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907153713.2572547-9-coiaprant@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in xpcs_rk_create allows a concurrent unbind of the supplier to free the MDIO bus, leading to a Use-After-Free.
- [Medium] Incorrect LIFO teardown ordering in devres clock cleanup action violates proper device initialization and PM hierarchy rules.
--

commit 7142dbf6b28b5ee94d0edc969bcf16d1183a5f41
Author: Coia Prant <coiaprant@gmail.com>

net: pcs: xpcs: add Rockchip RK3568 platform glue driver

This commit adds a platform glue driver for the Synopsys DesignWare xpcs
integrated in the Rockchip RK3568 SoC. It creates a virtual mdio bus to
translate mdio operations to apb3 memory-mapped register accesses.

Link: https://dl.radxa.com/rock3/docs/hw/datasheet/Rockchip%20RK3568%20TRM%20Part2%20V1.1-20210301.pdf (Page 2078)

> diff --git a/drivers/net/pcs/pcs-xpcs-rk.c b/drivers/net/pcs/pcs-xpcs-rk.c
> new file mode 100644
> index 0000000000000..68bcaa1a5cbbf
> --- /dev/null
> +++ b/drivers/net/pcs/pcs-xpcs-rk.c
[ ... ]
> +static void xpcs_rk_exit_clk(void *data)
> +{
> +	struct dw_xpcs_rk *pxpcs = data;
> +	struct device *dev = &pxpcs->pdev->dev;
> +
> +	clk_disable_unprepare(pxpcs->eee_clk);
> +
> +	pm_runtime_force_suspend(dev);

[Severity: Medium]
Does this sequence result in the clock being disabled before the device is
suspended?

In xpcs_rk_init_clk(), eee_clk is enabled first, followed by a call to
pm_runtime_enable(), allowing the device to become runtime active. During 
teardown, pm_runtime_force_suspend() invokes xpcs_rk_pm_runtime_suspend()
to disable csr_clk.

Calling clk_disable_unprepare() for eee_clk before pm_runtime_force_suspend() 
violates last-in, first-out ordering, disabling the prerequisite clock while
the device is still considered active. Should pm_runtime_force_suspend() be
called prior to disabling the eee_clk?

> +}
[ ... ]
> +struct dw_xpcs *xpcs_rk_create(struct device *dev, struct device_node *np)
> +{
[ ... ]
> +	device_lock(&pdev->dev);
> +	pxpcs = platform_get_drvdata(pdev);
> +	if (!pxpcs || !pxpcs->bus) {
> +		device_unlock(&pdev->dev);
> +		put_device(&pdev->dev);
> +		return ERR_PTR(-EPROBE_DEFER);
> +	}
> +
> +	xpcs = xpcs_create_mdiodev(pxpcs->bus, (int)port);
> +	device_unlock(&pdev->dev);

[Severity: High]
Does dropping the device lock here introduce a time-of-check to time-of-use
race condition?

If a concurrent unbind of the rk_xpcs-dwxpcs supplier driver occurs 
immediately after device_unlock() but before device_link_add(), the unbind 
would trigger devres cleanup, freeing the mdio bus.

> +	if (IS_ERR(xpcs)) {
> +		put_device(&pdev->dev);
> +		return xpcs;
> +	}
> +
> +	if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {

Since device_link_add() permits linking to devices without drivers, it could
succeed even if the supplier was just unbound. The consumer driver would then
resume probing with the returned xpcs pointer referencing a freed mdio bus,
leading to a use-after-free when the mac driver attempts to read or write
pcs registers.

Could the device_link_add() call be moved inside the lock block protected
by device_lock() to safely establish the dependency before the lock is
released?

> +		xpcs_destroy(xpcs);
> +		put_device(&pdev->dev);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	put_device(&pdev->dev);
> +	return xpcs;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260907153713.2572547-2-coiaprant@gmail.com?part=7

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

  reply	other threads:[~2026-09-08 15:41 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 15:37 [PATCH net-next v4 00/10] net: pcs: add basic support for RK3568 XPCS Coia Prant
2026-09-07 15:37 ` Coia Prant
2026-09-07 15:37 ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 01/10] net: stmmac: move XPCS lifetime management to platform drivers Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 14:51     ` Coia Prant
2026-09-13 14:51       ` Coia Prant
2026-09-13 14:51       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 02/10] dt-bindings: phy: rockchip: naneng-combphy: add rockchip,sgmii-mac-sel property Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 03/10] phy: rockchip: naneng-combphy: add SGMII MAC selection for RK3568 Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 15:11     ` Coia Prant
2026-09-13 15:11       ` Coia Prant
2026-09-13 15:11       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 04/10] dt-bindings: net: pcs: add rockchip,rk3568-xpcs support Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 15:30     ` Coia Prant
2026-09-13 15:30       ` Coia Prant
2026-09-13 15:30       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 05/10] arm64: dts: rockchip: rk3568: add XPCS and fixed-clock nodes Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-08 15:39   ` sashiko-bot
2026-09-08 15:39     ` sashiko-bot
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 15:47     ` Coia Prant
2026-09-13 15:47       ` Coia Prant
2026-09-13 15:47       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 06/10] net: pcs: xpcs: add ANRESTART support for SGMII link recovery Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-08 15:40   ` sashiko-bot
2026-09-08 15:40     ` sashiko-bot
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 15:58     ` Coia Prant
2026-09-13 15:58       ` Coia Prant
2026-09-13 15:58       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 07/10] net: pcs: xpcs: add Rockchip RK3568 platform glue driver Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-08 15:40   ` sashiko-bot [this message]
2026-09-08 15:40     ` sashiko-bot
2026-09-13 17:02     ` Coia Prant
2026-09-13 17:02       ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 17:00     ` Coia Prant
2026-09-13 17:00       ` Coia Prant
2026-09-13 17:00       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 08/10] net: stmmac: dwmac-rk: add SGMII support for RK3568 Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 17:54     ` Coia Prant
2026-09-13 17:54       ` Coia Prant
2026-09-13 17:54       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 09/10] arm64: dts: rockchip: rk3568-photonicat: enable SGMII LAN port Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:13   ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-12 20:13     ` Jakub Kicinski
2026-09-13 18:05     ` Coia Prant
2026-09-13 18:05       ` Coia Prant
2026-09-13 18:05       ` Coia Prant
2026-09-07 15:37 ` [PATCH net-next v4 10/10] MAINTAINERS: add entry for Rockchip XPCS driver Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-07 15:37   ` Coia Prant
2026-09-12 20:14 ` [PATCH net-next v4 00/10] net: pcs: add basic support for RK3568 XPCS Jakub Kicinski
2026-09-12 20:14   ` Jakub Kicinski
2026-09-12 20:14   ` Jakub Kicinski
2026-09-12 20:33   ` Coia Prant
2026-09-12 20:33     ` Coia Prant
2026-09-12 20:33     ` Coia Prant

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=20260908154108.6864E1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=coiaprant@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.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 \
    --cc=wsa+renesas@sang-engineering.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 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.