From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Thu, 21 Sep 2017 14:42:04 +0200
Subject: net: use trylock in icmp_sk
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git
Git-commit: 80836b63c32c5e4a98d69ba7476b9f0552033695
Patch-mainline: Queued in subsystem maintainer repository
References: SLE12 Realtime Extension
The locking path can be recursive (same as for sk->sk_lock.slock) and
therefore we need a trylock version for the locallock, too.
Cc: rt-stable@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Mike Galbraith <mgalbraith@suse.de>
---
net/ipv4/icmp.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -218,12 +218,16 @@ static inline struct sock *icmp_xmit_loc
{
struct sock *sk;
+ if (!local_trylock(icmp_sk_lock))
+ return NULL;
+
sk = icmp_sk(net);
if (unlikely(!spin_trylock(&sk->sk_lock.slock))) {
/* This can happen if the output path signals a
* dst_link_failure() for an outgoing ICMP packet.
*/
+ local_unlock(icmp_sk_lock);
return NULL;
}
return sk;
@@ -232,6 +236,7 @@ static inline struct sock *icmp_xmit_loc
static inline void icmp_xmit_unlock(struct sock *sk)
{
spin_unlock(&sk->sk_lock.slock);
+ local_unlock(icmp_sk_lock);
}
int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
@@ -421,7 +426,6 @@ static void icmp_reply(struct icmp_bxm *
/* Needed by both icmp_global_allow and icmp_xmit_lock */
local_bh_disable();
- local_lock(icmp_sk_lock);
/* global icmp_msgs_per_sec */
if (!icmpv4_global_allow(net, type, code))
@@ -466,7 +470,6 @@ static void icmp_reply(struct icmp_bxm *
out_unlock:
icmp_xmit_unlock(sk);
out_bh_enable:
- local_unlock(icmp_sk_lock);
local_bh_enable();
}
@@ -662,7 +665,6 @@ void icmp_send(struct sk_buff *skb_in, i
/* Needed by both icmp_global_allow and icmp_xmit_lock */
local_bh_disable();
- local_lock(icmp_sk_lock);
/* Check global sysctl_icmp_msgs_per_sec ratelimit, unless
* incoming dev is loopback. If outgoing dev change to not be
@@ -751,7 +753,6 @@ void icmp_send(struct sk_buff *skb_in, i
out_unlock:
icmp_xmit_unlock(sk);
out_bh_enable:
- local_unlock(icmp_sk_lock);
local_bh_enable();
out:;
}