Skip to content

Commit 33d60fb

Browse files
q2venkuba-moo
authored andcommitted
sock: Use sock_owned_by_user_nocheck() instead of sk_lock.owned.
This patch moves sock_release_ownership() down in include/net/sock.h and replaces some sk_lock.owned tests with sock_owned_by_user_nocheck(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent be31582 commit 33d60fb

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

include/net/sock.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,16 +1635,6 @@ static inline void sk_mem_uncharge(struct sock *sk, int size)
16351635
__sk_mem_reclaim(sk, SK_RECLAIM_CHUNK);
16361636
}
16371637

1638-
static inline void sock_release_ownership(struct sock *sk)
1639-
{
1640-
if (sk->sk_lock.owned) {
1641-
sk->sk_lock.owned = 0;
1642-
1643-
/* The sk_lock has mutex_unlock() semantics: */
1644-
mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
1645-
}
1646-
}
1647-
16481638
/*
16491639
* Macro so as to not evaluate some arguments when
16501640
* lockdep is not enabled.
@@ -1771,12 +1761,23 @@ static inline bool sock_owned_by_user_nocheck(const struct sock *sk)
17711761
return sk->sk_lock.owned;
17721762
}
17731763

1764+
static inline void sock_release_ownership(struct sock *sk)
1765+
{
1766+
if (sock_owned_by_user_nocheck(sk)) {
1767+
sk->sk_lock.owned = 0;
1768+
1769+
/* The sk_lock has mutex_unlock() semantics: */
1770+
mutex_release(&sk->sk_lock.dep_map, _RET_IP_);
1771+
}
1772+
}
1773+
17741774
/* no reclassification while locks are held */
17751775
static inline bool sock_allow_reclassification(const struct sock *csk)
17761776
{
17771777
struct sock *sk = (struct sock *)csk;
17781778

1779-
return !sk->sk_lock.owned && !spin_is_locked(&sk->sk_lock.slock);
1779+
return !sock_owned_by_user_nocheck(sk) &&
1780+
!spin_is_locked(&sk->sk_lock.slock);
17801781
}
17811782

17821783
struct sock *sk_alloc(struct net *net, int family, gfp_t priority,

net/core/sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ void lock_sock_nested(struct sock *sk, int subclass)
32923292

32933293
might_sleep();
32943294
spin_lock_bh(&sk->sk_lock.slock);
3295-
if (sk->sk_lock.owned)
3295+
if (sock_owned_by_user_nocheck(sk))
32963296
__lock_sock(sk);
32973297
sk->sk_lock.owned = 1;
32983298
spin_unlock_bh(&sk->sk_lock.slock);
@@ -3323,7 +3323,7 @@ bool __lock_sock_fast(struct sock *sk) __acquires(&sk->sk_lock.slock)
33233323
might_sleep();
33243324
spin_lock_bh(&sk->sk_lock.slock);
33253325

3326-
if (!sk->sk_lock.owned) {
3326+
if (!sock_owned_by_user_nocheck(sk)) {
33273327
/*
33283328
* Fast path return with bottom halves disabled and
33293329
* sock::sk_lock.slock held.

net/llc/llc_proc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int llc_seq_core_show(struct seq_file *seq, void *v)
195195
timer_pending(&llc->pf_cycle_timer.timer),
196196
timer_pending(&llc->rej_sent_timer.timer),
197197
timer_pending(&llc->busy_state_timer.timer),
198-
!!sk->sk_backlog.tail, !!sk->sk_lock.owned);
198+
!!sk->sk_backlog.tail, sock_owned_by_user_nocheck(sk));
199199
out:
200200
return 0;
201201
}

0 commit comments

Comments
 (0)