@@ -321,6 +321,8 @@ struct bpf_sk_storage;
321321 * @sk_clockid: clockid used by time-based scheduling (SO_TXTIME)
322322 * @sk_txtime_deadline_mode: set deadline mode for SO_TXTIME
323323 * @sk_txtime_unused: unused txtime flags
324+ * @sk_owner: reference to the real owner of the socket that calls
325+ * sock_lock_init_class_and_name().
324326 */
325327struct sock {
326328 /*
@@ -515,6 +517,10 @@ struct sock {
515517 struct bpf_sk_storage __rcu * sk_bpf_storage ;
516518#endif
517519 struct rcu_head sk_rcu ;
520+
521+ #if IS_ENABLED (CONFIG_PROVE_LOCKING ) && IS_ENABLED (CONFIG_MODULES )
522+ struct module * sk_owner ;
523+ #endif
518524};
519525
520526enum sk_pacing {
@@ -1525,6 +1531,35 @@ static inline void sock_release_ownership(struct sock *sk)
15251531 }
15261532}
15271533
1534+ #if IS_ENABLED (CONFIG_PROVE_LOCKING ) && IS_ENABLED (CONFIG_MODULES )
1535+ static inline void sk_owner_set (struct sock * sk , struct module * owner )
1536+ {
1537+ __module_get (owner );
1538+ sk -> sk_owner = owner ;
1539+ }
1540+
1541+ static inline void sk_owner_clear (struct sock * sk )
1542+ {
1543+ sk -> sk_owner = NULL ;
1544+ }
1545+
1546+ static inline void sk_owner_put (struct sock * sk )
1547+ {
1548+ module_put (sk -> sk_owner );
1549+ }
1550+ #else
1551+ static inline void sk_owner_set (struct sock * sk , struct module * owner )
1552+ {
1553+ }
1554+
1555+ static inline void sk_owner_clear (struct sock * sk )
1556+ {
1557+ }
1558+
1559+ static inline void sk_owner_put (struct sock * sk )
1560+ {
1561+ }
1562+ #endif
15281563/*
15291564 * Macro so as to not evaluate some arguments when
15301565 * lockdep is not enabled.
@@ -1534,13 +1569,14 @@ static inline void sock_release_ownership(struct sock *sk)
15341569 */
15351570#define sock_lock_init_class_and_name (sk , sname , skey , name , key ) \
15361571do { \
1572+ sk_owner_set(sk, THIS_MODULE); \
15371573 sk->sk_lock.owned = 0; \
15381574 init_waitqueue_head(&sk->sk_lock.wq); \
15391575 spin_lock_init(&(sk)->sk_lock.slock); \
15401576 debug_check_no_locks_freed((void *)&(sk)->sk_lock, \
1541- sizeof((sk)->sk_lock)); \
1577+ sizeof((sk)->sk_lock)); \
15421578 lockdep_set_class_and_name(&(sk)->sk_lock.slock, \
1543- (skey), (sname)); \
1579+ (skey), (sname)); \
15441580 lockdep_init_map(&(sk)->sk_lock.dep_map, (name), (key), 0); \
15451581} while (0)
15461582
0 commit comments