diff mbox series

[net-next] net: sysfs: fix locking in carrier read

Message ID 20231206172122.859df6ba937f.I9c80608bcfbab171943ff4942b52dbd5e97fe06e@changeid (mailing list archive)
State Accepted
Commit bf17b36ccdd5b7b9dd482d7753bcb9aff2d21d39
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: sysfs: fix locking in carrier read | 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: 1117 this patch: 1117
netdev/cc_maintainers fail 2 blamed authors not CCed: kuba@kernel.org jiri@resnulli.us; 4 maintainers not CCed: kuba@kernel.org edumazet@google.com pabeni@redhat.com jiri@resnulli.us
netdev/build_clang success Errors and warnings before: 1143 this patch: 1143
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1144 this patch: 1144
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 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

Commit Message

Johannes Berg Dec. 6, 2023, 4:21 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

My previous patch added a call to linkwatch_sync_dev(),
but that of course needs to be called under RTNL, which
I missed earlier, but now saw RCU warnings from.

Fix that by acquiring the RTNL in a similar fashion to
how other files do it here.

Fixes: facd15dfd691 ("net: core: synchronize link-watch when carrier is queried")
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 net/core/net-sysfs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 9, 2023, 12:20 a.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 Dec 2023 17:21:23 +0100 you wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> My previous patch added a call to linkwatch_sync_dev(),
> but that of course needs to be called under RTNL, which
> I missed earlier, but now saw RCU warnings from.
> 
> Fix that by acquiring the RTNL in a similar fashion to
> how other files do it here.
> 
> [...]

Here is the summary with links:
  - [net-next] net: sysfs: fix locking in carrier read
    https://git.kernel.org/netdev/net-next/c/bf17b36ccdd5

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index d9b33e923b18..a09d507c5b03 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -193,6 +193,10 @@  static ssize_t carrier_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
 	struct net_device *netdev = to_net_dev(dev);
+	int ret = -EINVAL;
+
+	if (!rtnl_trylock())
+		return restart_syscall();
 
 	if (netif_running(netdev)) {
 		/* Synchronize carrier state with link watch,
@@ -200,10 +204,11 @@  static ssize_t carrier_show(struct device *dev,
 		 */
 		linkwatch_sync_dev(netdev);
 
-		return sysfs_emit(buf, fmt_dec, !!netif_carrier_ok(netdev));
+		ret = sysfs_emit(buf, fmt_dec, !!netif_carrier_ok(netdev));
 	}
+	rtnl_unlock();
 
-	return -EINVAL;
+	return ret;
 }
 static DEVICE_ATTR_RW(carrier);