smc: use RCU version of lower netdev searching
PATCH 1/1 smc: use RCU version of lower netdev searching
From: Cong Wang <[email protected]>
Both netdev_walk_all_lower_dev() and netdev_lower_get_next() have a RCU version, which are netdev_walk_all_lower_dev_rcu() and netdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers like smc_connect().
--- net/smc/smc_core.c | 6 +++--- net/smc/smc_pnet.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)
net/smc/smc_core.c +3 -3
@@ -1850,9 +1850,9 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) } priv.data = (void *)&ini->vlan_id; -rtnl_lock (); -netdev_walk_all_lower_dev (ndev, smc_vlan_by_tcpsk_walk, &priv); -rtnl_unlock (); +rcu_read_lock (); +netdev_walk_all_lower_dev_rcu (ndev, smc_vlan_by_tcpsk_walk, &priv); +rcu_read_unlock (); out_rel:dst_release (dst);
net/smc/smc_pnet.c +7 -7
@@ -29,7 +29,6 @@#include "smc_ism.h" #include "smc_core.h" -static struct net_device *__pnet_find_base_ndev (struct net_device *ndev);static struct net_device *pnet_find_base_ndev (struct net_device *ndev);static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX +1 ] = {
@@ -791,7 +790,7 @@ static void smc_pnet_add_base_pnetid(struct net *net, struct net_device *dev, {struct net_device *base_dev; - base_dev =__pnet_find_base_ndev (dev); + base_dev =pnet_find_base_ndev (dev);if (base_dev->flags &IFF_UP && !smc_pnetid_by_dev_port (base_dev->dev.parent, base_dev->dev_port, ndev_pnetid)) {
@@ -857,7 +856,7 @@ static int smc_pnet_netdev_event(struct notifier_block *this,smc_pnet_add_base_pnetid (net, event_dev, ndev_pnetid);return NOTIFY_OK ;case NETDEV_DOWN : - event_dev =__pnet_find_base_ndev (event_dev); + event_dev =pnet_find_base_ndev (event_dev);if (!smc_pnetid_by_dev_port (event_dev->dev.parent, event_dev->dev_port, ndev_pnetid)) {/* remove from PNETIDs list */
@@ -925,7 +924,6 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev) {int i, nest_lvl; -ASSERT_RTNL (); nest_lvl = ndev->lower_level;for (i =0 ; i < nest_lvl; i++) {struct list_head *lower = &ndev->adj_list.lower;
@@ -933,7 +931,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)if (list_empty (lower))break ; lower = lower->next; - ndev =netdev_lower_get_next (ndev, &lower); + ndev =netdev_next_lower_dev_rcu (ndev, &lower); +if (!ndev) +break ; }return ndev; }
@@ -945,9 +945,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)*/ static struct net_device *pnet_find_base_ndev (struct net_device *ndev) { -rtnl_lock (); +rcu_read_lock (); ndev =__pnet_find_base_ndev (ndev); -rtnl_unlock (); +rcu_read_unlock ();return ndev; }
Signature · 1 line
2.34.1
D. Wythe
maintainerQuoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().
Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for IPPROTO_SMC.
Thanks,
D. Wythe
Quoted 83 lines
--- net/smc/smc_core.c | 6 +++--- net/smc/smc_pnet.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)net/smc/smc_core.c +3
-3@@ -1850,9 +1850,9 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) } priv.data = (void *)&ini->vlan_id; -rtnl_lock (); -netdev_walk_all_lower_dev (ndev, smc_vlan_by_tcpsk_walk, &priv); -rtnl_unlock (); +rcu_read_lock (); +netdev_walk_all_lower_dev_rcu (ndev, smc_vlan_by_tcpsk_walk, &priv); +rcu_read_unlock (); out_rel:dst_release (dst);net/smc/smc_pnet.c +7
-7@@ -29,7 +29,6 @@#include "smc_ism.h" #include "smc_core.h" -static struct net_device *__pnet_find_base_ndev (struct net_device *ndev);static struct net_device *pnet_find_base_ndev (struct net_device *ndev);static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX +1 ] = {@@ -791,7 +790,7 @@ static void smc_pnet_add_base_pnetid(struct net *net, struct net_device *dev, {struct net_device *base_dev; - base_dev =__pnet_find_base_ndev (dev); + base_dev =pnet_find_base_ndev (dev);if (base_dev->flags &IFF_UP && !smc_pnetid_by_dev_port (base_dev->dev.parent, base_dev->dev_port, ndev_pnetid)) {@@ -857,7 +856,7 @@ static int smc_pnet_netdev_event(struct notifier_block *this,smc_pnet_add_base_pnetid (net, event_dev, ndev_pnetid);return NOTIFY_OK ;case NETDEV_DOWN : - event_dev =__pnet_find_base_ndev (event_dev); + event_dev =pnet_find_base_ndev (event_dev);if (!smc_pnetid_by_dev_port (event_dev->dev.parent, event_dev->dev_port, ndev_pnetid)) {/* remove from PNETIDs list */ @@ -925,7 +924,6 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev) {int i, nest_lvl; -ASSERT_RTNL (); nest_lvl = ndev->lower_level;for (i =0 ; i < nest_lvl; i++) {struct list_head *lower = &ndev->adj_list.lower;@@ -933,7 +931,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)if (list_empty (lower))break ; lower = lower->next; - ndev =netdev_lower_get_next (ndev, &lower); + ndev =netdev_next_lower_dev_rcu (ndev, &lower); +if (!ndev) +break ; }return ndev; }@@ -945,9 +945,9 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)*/ static struct net_device *pnet_find_base_ndev (struct net_device *ndev) { -rtnl_lock (); +rcu_read_lock (); ndev =__pnet_find_base_ndev (ndev); -rtnl_unlock (); +rcu_read_unlock ();return ndev; }
Quoted 22 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>
Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.
If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
And you don't even need to bother sock lock annotations for this specific case at all (I can't say any other case).
Thanks.
D. Wythe
maintainerQuoted 23 lines · Cong Wang
Quoted 22 lines · D. Wythe
Quoted 17 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>
Quoted 7 lines
Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Quoted 4 lines
And you don't even need to bother sock lock annotations for this specific case at all (I can't say any other case).
Thanks.
Quoted 30 lines · D. Wythe
Quoted 27 lines · Cong Wang
Quoted 25 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.
Quoted 6 lines
Quoted 3 lines
If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Sure, but what questions do you have here? To me, the lockdep output is self-explained. Please kindly let me know if you have any troubles understanding it, I am always happy to help.
Thanks.
D. Wythe
maintainerQuoted 35 lines · Cong Wang
Quoted 34 lines · D. Wythe
Quoted 30 lines · Cong Wang
Quoted 22 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
Quoted 8 lines
Quoted 2 lines
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Sure, but what questions do you have here? To me, the lockdep output is self-explained. Please kindly let me know if you have any troubles understanding it, I am always happy to help.
Thanks.
Just explain (https://syzkaller.appspot.com/bug?extid=c75d1de73d3b8b76272f)
-> #1 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x3a/0xf0 net/core/sock.c:3543
lock_sock include/net/sock.h:1607 [inline]
sockopt_lock_sock net/core/sock.c:1061 [inline]
sockopt_lock_sock+0x54/0x70 net/core/sock.c:1052
do_ipv6_setsockopt+0x216a/0x47b0 net/ipv6/ipv6_sockglue.c:567
ipv6_setsockopt+0xe3/0x1a0 net/ipv6/ipv6_sockglue.c:993
udpv6_setsockopt+0x7d/0xd0 net/ipv6/udp.c:1702
do_sock_setsockopt+0x222/0x480 net/socket.c:2324
__sys_setsockopt+0x1a4/0x270 net/socket.c:2347
__do_sys_setsockopt net/socket.c:2356 [inline]
__se_sys_setsockopt net/socket.c:2353 [inline]
__x64_sys_setsockopt+0xbd/0x160 net/socket.c:2353
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7fWhy is that udpv6_setsockopt was reported here.
D.
Paolo Abeni
maintainerHi,
Quoted 64 lines · D. Wythe
Quoted 35 lines · Cong Wang
Quoted 34 lines · D. Wythe
Quoted 30 lines · Cong Wang
Quoted 22 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
Quoted 8 lines
Quoted 2 lines
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Sure, but what questions do you have here? To me, the lockdep output is self-explained. Please kindly let me know if you have any troubles understanding it, I am always happy to help.
Thanks.
Just explain (https://syzkaller.appspot.com/bug?extid=c75d1de73d3b8b76272f)
-> #1 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x3a/0xf0 net/core/sock.c:3543 lock_sock include/net/sock.h:1607 [inline] sockopt_lock_sock net/core/sock.c:1061 [inline] sockopt_lock_sock+0x54/0x70 net/core/sock.c:1052 do_ipv6_setsockopt+0x216a/0x47b0 net/ipv6/ipv6_sockglue.c:567 ipv6_setsockopt+0xe3/0x1a0 net/ipv6/ipv6_sockglue.c:993 udpv6_setsockopt+0x7d/0xd0 net/ipv6/udp.c:1702 do_sock_setsockopt+0x222/0x480 net/socket.c:2324 __sys_setsockopt+0x1a4/0x270 net/socket.c:2347 __do_sys_setsockopt net/socket.c:2356 [inline] __se_sys_setsockopt net/socket.c:2353 [inline] __x64_sys_setsockopt+0xbd/0x160 net/socket.c:2353 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Quoted 1 line
Why is that
udpv6_setsockoptwas reported here.
If I read correctly, your doubt is somewhat alike the following: the SMC code does not call UDP sockopt-related function, so the above stacktrace refers to a non SMC socket and the reported splat is really harmless, as no deadlock will really happens (UDP sockets do not acquire nested rtnl lock, smc does not acquire nested socket lock).
Still the splat happens we need - or at least we should - address it, because this splat prevents syzkaller from finding other possibly more significant issues.
One way for addressing the splat would be adding the proper annotation to the socket lock. Another way is the present patch, which looks legit to me and should give performances benefit (every time we don't need to acquire the rtnl lock is a win!)
@Wythe: does the above clarify a bit?
Thanks!
Paolo
D. Wythe
maintainerQuoted 72 lines · Paolo Abeni
Hi,
Quoted 64 lines · D. Wythe
Quoted 35 lines · Cong Wang
Quoted 34 lines · D. Wythe
Quoted 30 lines · Cong Wang
Quoted 22 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
Quoted 8 lines
Quoted 2 lines
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Sure, but what questions do you have here? To me, the lockdep output is self-explained. Please kindly let me know if you have any troubles understanding it, I am always happy to help.
Thanks.
Just explain (https://syzkaller.appspot.com/bug?extid=c75d1de73d3b8b76272f)
-> #1 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x3a/0xf0 net/core/sock.c:3543 lock_sock include/net/sock.h:1607 [inline] sockopt_lock_sock net/core/sock.c:1061 [inline] sockopt_lock_sock+0x54/0x70 net/core/sock.c:1052 do_ipv6_setsockopt+0x216a/0x47b0 net/ipv6/ipv6_sockglue.c:567 ipv6_setsockopt+0xe3/0x1a0 net/ipv6/ipv6_sockglue.c:993 udpv6_setsockopt+0x7d/0xd0 net/ipv6/udp.c:1702 do_sock_setsockopt+0x222/0x480 net/socket.c:2324 __sys_setsockopt+0x1a4/0x270 net/socket.c:2347 __do_sys_setsockopt net/socket.c:2356 [inline] __se_sys_setsockopt net/socket.c:2353 [inline] __x64_sys_setsockopt+0xbd/0x160 net/socket.c:2353 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7fQuoted 1 line
Why is that
udpv6_setsockoptwas reported here.If I read correctly, your doubt is somewhat alike the following: the SMC code does not call UDP sockopt-related function, so the above stacktrace refers to a non SMC socket and the reported splat is really harmless, as no deadlock will really happens (UDP sockets do not acquire nested rtnl lock, smc does not acquire nested socket lock).
Still the splat happens we need - or at least we should - address it, because this splat prevents syzkaller from finding other possibly more significant issues.
Quoted 7 lines
One way for addressing the splat would be adding the proper annotation to the socket lock. Another way is the present patch, which looks legit to me and should give performances benefit (every time we don't need to acquire the rtnl lock is a win!)
@Wythe: does the above clarify a bit?
Thanks!
Paolo
Hi Paolo,
Thanks for your explanation. I did not question the value of this patch, I just think that it did not fix a deadlock issue as it described. What it really does is to avoid a false position from syzbot, and also has brought potential performance benefits, which I totally agree with.
Last week, we also discussed this issue with Eric. In fact, we already have a patch
that addresses this problem by modifying the lockdep class of IPPROTO_SMC. However,
I'm not entirely satisfied with this change because I prefer that IPPROTO_SMC socks remain consistent with other AF_INET socks. So, it appears that this patch is the best solution now.
Anyway, I support this patch now. But I believe the description needs to be more accurate.
Thanks,
D. Wythe
Quoted 92 lines · D. Wythe
Quoted 72 lines · Paolo Abeni
Hi,
Quoted 64 lines · D. Wythe
Quoted 35 lines · Cong Wang
Quoted 34 lines · D. Wythe
Quoted 30 lines · Cong Wang
Quoted 22 lines · D. Wythe
Quoted 9 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Quoted 8 lines
Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>Quoted 3 lines
Haven't looked at your code yet, but the issue you fixed doesn't exist. The real reason is that we lacks some lockdep annotations for
IPPROTO_SMC.If you look at the code, it is not about sock lock annotations, it is about RTNL lock which of course has annotations.
Quoted 8 lines
Quoted 2 lines
If so, please explain the deadlock issue mentioned in sysbot and how it triggers deadlocks.
Sure, but what questions do you have here? To me, the lockdep output is self-explained. Please kindly let me know if you have any troubles understanding it, I am always happy to help.
Thanks.
Just explain (https://syzkaller.appspot.com/bug?extid=c75d1de73d3b8b76272f)
-> #1 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x3a/0xf0 net/core/sock.c:3543 lock_sock include/net/sock.h:1607 [inline] sockopt_lock_sock net/core/sock.c:1061 [inline] sockopt_lock_sock+0x54/0x70 net/core/sock.c:1052 do_ipv6_setsockopt+0x216a/0x47b0 net/ipv6/ipv6_sockglue.c:567 ipv6_setsockopt+0xe3/0x1a0 net/ipv6/ipv6_sockglue.c:993 udpv6_setsockopt+0x7d/0xd0 net/ipv6/udp.c:1702 do_sock_setsockopt+0x222/0x480 net/socket.c:2324 __sys_setsockopt+0x1a4/0x270 net/socket.c:2347 __do_sys_setsockopt net/socket.c:2356 [inline] __se_sys_setsockopt net/socket.c:2353 [inline] __x64_sys_setsockopt+0xbd/0x160 net/socket.c:2353 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7fQuoted 1 line
Why is that
udpv6_setsockoptwas reported here.If I read correctly, your doubt is somewhat alike the following: the SMC code does not call UDP sockopt-related function, so the above stacktrace refers to a non SMC socket and the reported splat is really harmless, as no deadlock will really happens (UDP sockets do not acquire nested rtnl lock, smc does not acquire nested socket lock).
Still the splat happens we need - or at least we should - address it, because this splat prevents syzkaller from finding other possibly more significant issues.
Quoted 7 lines
One way for addressing the splat would be adding the proper annotation to the socket lock. Another way is the present patch, which looks legit to me and should give performances benefit (every time we don't need to acquire the rtnl lock is a win!)
@Wythe: does the above clarify a bit?
Thanks!
Paolo
Hi Paolo,
Thanks for your explanation. I did not question the value of this patch, I just think that it did not fix a deadlock issue as it described. What it really does is to avoid a false position from syzbot, and also has brought potential performance benefits, which I totally agree with.
Quoted 10 lines
Last week, we also discussed this issue with Eric. In fact, we already have a patch
that addresses this problem by modifying the lockdep class ofIPPROTO_SMC. However,
I'm not entirely satisfied with this change because I prefer thatIPPROTO_SMCsocks remain consistent with otherAF_INETsocks. So, it appears that this patch is the best solution now.Anyway, I support this patch now. But I believe the description needs to be more accurate.
Thanks,
D. Wythe
I like the idea with the RCU version and it might solve the issue what the syzbot reported. However, I also agree with D. Wythe on lack of accurate description regarding this issue itself. That means where is the knot and how the RCU version solves the knot. That would also help people solve the similar problem later. @Cong Wang, could you please add a bit more description I mentioned above?
Thanks,
Wenjia
Quoted 28 lines · Cong Wang
From: Cong Wang <[email protected]>
Both
netdev_walk_all_lower_dev()andnetdev_lower_get_next()have a RCU version, which arenetdev_walk_all_lower_dev_rcu()andnetdev_next_lower_dev_rcu(). Switching to the RCU version would eliminate the need for RTL lock, thus could amend the deadlock complaints from syzbot. And it could also potentially speed up its callers likesmc_connect().Reported-by [email protected]Cc Wenjia Zhang <[email protected]>Cc Jan Karcher <[email protected]>Cc "D. Wythe" <[email protected]>Cc Tony Lu <[email protected]>Cc Wen Gu <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/smc/smc_core.c | 6 +++--- net/smc/smc_pnet.c | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-)net/smc/smc_core.c +0
-0
net/smc/smc_core.c int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) · line 1854
Quoted 8 lines
net/smc/smc_core.c +2
-3@@ -1850,9 +1850,9 @@ int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) } priv.data = (void *)&ini->vlan_id; -rtnl_lock (); -netdev_walk_all_lower_dev (ndev, smc_vlan_by_tcpsk_walk, &priv); -rtnl_unlock (); +rcu_read_lock (); +netdev_walk_all_lower_dev_rcu (ndev, smc_vlan_by_tcpsk_walk, &priv);
It seems smc_vlan_by_tcpsk_walk() depends on RTNL.
We should at least add a READ_ONCE() in is_vlan_dev() :
return READ_ONCE(dev->priv_flags) & IFF_802_1Q_VLAN;
Quoted 4 lines
net/smc/smc_core.c +1
-0+rcu_read_unlock (); out_rel: