diff mbox series

[net-next] net: phy: realtek: make sure paged read is protected by mutex

Message ID 792b8c0d1fc194e2b53cb09d45a234bc668e34c6.1728057091.git.daniel@makrotopia.org (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phy: realtek: make sure paged read is protected by mutex | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-06--15-00 (tests: 775)

Commit Message

Daniel Golle Oct. 4, 2024, 3:52 p.m. UTC
As we cannot rely on phy_read_paged function before the PHY is
identified, the paged read in rtlgen_supports_2_5gbps needs to be open
coded as it is being called by the match_phy_device function, ie. before
.read_page and .write_page have been populated.

Make sure it is also protected by the MDIO bus mutex and use
rtl821x_write_page instead of 3 individually locked MDIO bus operations.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/phy/realtek.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Andrew Lunn Oct. 4, 2024, 9:25 p.m. UTC | #1
On Fri, Oct 04, 2024 at 04:52:04PM +0100, Daniel Golle wrote:
> As we cannot rely on phy_read_paged function before the PHY is
> identified, the paged read in rtlgen_supports_2_5gbps needs to be open
> coded as it is being called by the match_phy_device function, ie. before
> .read_page and .write_page have been populated.
> 
> Make sure it is also protected by the MDIO bus mutex and use
> rtl821x_write_page instead of 3 individually locked MDIO bus operations.

match_phy_device() as far as i know, is only used during bus probe,
when trying to match a driver to a device. What are you trying to lock
against during probe?

	Andrew
Daniel Golle Oct. 4, 2024, 10:02 p.m. UTC | #2
On Fri, Oct 04, 2024 at 11:25:29PM +0200, Andrew Lunn wrote:
> On Fri, Oct 04, 2024 at 04:52:04PM +0100, Daniel Golle wrote:
> > As we cannot rely on phy_read_paged function before the PHY is
> > identified, the paged read in rtlgen_supports_2_5gbps needs to be open
> > coded as it is being called by the match_phy_device function, ie. before
> > .read_page and .write_page have been populated.
> > 
> > Make sure it is also protected by the MDIO bus mutex and use
> > rtl821x_write_page instead of 3 individually locked MDIO bus operations.
> 
> match_phy_device() as far as i know, is only used during bus probe,
> when trying to match a driver to a device. What are you trying to lock
> against during probe?

The idea is to reduce the amount of unnecessary lock/unlock cycles (1 vs
3). Of course, we could just omit locking entirely here, but that seemed
a bit wild to me, and even if it would work in that specific case, it
just serve as a bad example.
Andrew Lunn Oct. 5, 2024, 2:20 p.m. UTC | #3
On Fri, Oct 04, 2024 at 11:02:13PM +0100, Daniel Golle wrote:
> On Fri, Oct 04, 2024 at 11:25:29PM +0200, Andrew Lunn wrote:
> > On Fri, Oct 04, 2024 at 04:52:04PM +0100, Daniel Golle wrote:
> > > As we cannot rely on phy_read_paged function before the PHY is
> > > identified, the paged read in rtlgen_supports_2_5gbps needs to be open
> > > coded as it is being called by the match_phy_device function, ie. before
> > > .read_page and .write_page have been populated.
> > > 
> > > Make sure it is also protected by the MDIO bus mutex and use
> > > rtl821x_write_page instead of 3 individually locked MDIO bus operations.
> > 
> > match_phy_device() as far as i know, is only used during bus probe,
> > when trying to match a driver to a device. What are you trying to lock
> > against during probe?
> 
> The idea is to reduce the amount of unnecessary lock/unlock cycles (1 vs
> 3). Of course, we could just omit locking entirely here, but that seemed
> a bit wild to me, and even if it would work in that specific case, it
> just serve as a bad example.

I would just comment the requirement that it can only be used during
probe, and remove all the locks.

	Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index 3941cfa1c5f2..c4d0d93523ad 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -1030,9 +1030,11 @@  static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
 {
 	int val;
 
-	phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61);
-	val = phy_read(phydev, 0x13);
-	phy_write(phydev, RTL821x_PAGE_SELECT, 0);
+	mutex_lock(&phydev->mdio.bus->mdio_lock);
+	rtl821x_write_page(phydev, 0xa61);
+	val = __phy_read(phydev, 0x13);
+	rtl821x_write_page(phydev, 0);
+	mutex_unlock(&phydev->mdio.bus->mdio_lock);
 
 	return val >= 0 && val & MDIO_PMA_SPEED_2_5G;
 }