@@ -1696,6 +1696,16 @@ void release_sock(struct sock *sk);
SINGLE_DEPTH_NESTING)
#define bh_unlock_sock(__sk) spin_unlock(&((__sk)->sk_lock.slock))
+/* nolock helpers */
+#define bh_lock_sock_on_nolock(__sk) do { \
+ if ((__sk)->sk_no_lock) \
+ spin_lock_bh(&(__sk)->sk_lock.slock); \
+} while (0)
+#define bh_unlock_sock_on_nolock(__sk) do { \
+ if ((__sk)->sk_no_lock) \
+ spin_unlock_bh(&(__sk)->sk_lock.slock); \
+} while (0)
+
bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock);
/**
@@ -126,8 +126,11 @@ static void vcc_release_cb(struct sock *sk)
{
struct atm_vcc *vcc = atm_sk(sk);
- if (vcc->release_cb)
+ if (vcc->release_cb) {
+ bh_lock_sock_on_nolock(sk);
vcc->release_cb(vcc);
+ bh_lock_sock_on_nolock(sk);
+ }
}
static struct proto vcc_proto = {
@@ -1100,6 +1100,7 @@ void tcp_release_cb(struct sock *sk)
* But following code is meant to be called from BH handlers,
* so we should keep BH disabled, but early release socket ownership
*/
+ bh_lock_sock_on_nolock(sk);
sock_release_ownership(sk);
if (flags & TCPF_WRITE_TIMER_DEFERRED) {
@@ -1114,6 +1115,7 @@ void tcp_release_cb(struct sock *sk)
inet_csk(sk)->icsk_af_ops->mtu_reduced(sk);
__sock_put(sk);
}
+ bh_unlock_sock_on_nolock(sk);
}
EXPORT_SYMBOL(tcp_release_cb);
@@ -3065,6 +3065,8 @@ static void mptcp_release_cb(struct sock *sk)
{
struct mptcp_sock *msk = mptcp_sk(sk);
+ bh_lock_sock_on_nolock(sk);
+
for (;;) {
unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED) |
msk->push_pending;
@@ -3103,6 +3105,7 @@ static void mptcp_release_cb(struct sock *sk)
__mptcp_error_report(sk);
__mptcp_update_rmem(sk);
+ bh_unlock_sock_on_nolock(sk);
}
/* MP_JOIN client subflow must wait for 4th ack before sending any data:
@@ -201,10 +201,12 @@ static void smc_release_cb(struct sock *sk)
{
struct smc_sock *smc = smc_sk(sk);
+ bh_lock_sock_on_nolock(sk);
if (smc->conn.tx_in_release_sock) {
smc_tx_pending(&smc->conn);
smc->conn.tx_in_release_sock = false;
}
+ bh_unlock_sock_on_nolock(sk);
}
struct proto smc_proto = {
Add helpers that allow ->release_cb() to acquire the socket bh lock when needed. For normal sockets, ->release_cb() is always invoked with that lock held. For nolock sockets it will not be held, so provide an easy way to acquire it when necessary. Signed-off-by: Jens Axboe <axboe@kernel.dk> --- include/net/sock.h | 10 ++++++++++ net/atm/common.c | 5 ++++- net/ipv4/tcp_output.c | 2 ++ net/mptcp/protocol.c | 3 +++ net/smc/af_smc.c | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-)