af_unix: Introduce per-netns socket hash table.
Subsystems (3)
v2 cover af_unix: Introduce per-netns socket hash table.
This series replaces unix_socket_table with a per-netns hash table and reduces lock contention and time on iterating over the list.
Note the 3rd-6th patches can be a single patch, but for ease of review, they are split into small changes without breakage.
Changes:
v2:
3rd:
* Update changelog
* Remove holes from per-netns hash table structure
* Use kvmalloc_array() instead of kmalloc() (Eric Dumazet)
* Remove unnecessary parts in af_unix_init() (Eric Dumazet)
* Move err_sysctl label into ifdef block (kernel test robot)
* Remove struct netns_unix from struct net if CONFIG_UNIX is disabled
4th:
* Use spin_lock_nested() (kernel test robot)
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (6):
af_unix: Clean up some sock_net() uses.
af_unix: Include the whole hash table size in UNIX_HASH_SIZE.
af_unix: Define a per-netns hash table.
af_unix: Acquire/Release per-netns hash table's locks.
af_unix: Put a socket into a per-netns hash table.
af_unix: Remove unix_table_locks.
include/net/af_unix.h | 5 +- include/net/net_namespace.h | 2 + include/net/netns/unix.h | 6 + net/unix/af_unix.c | 216 +++++++++++++++++++----------------- net/unix/diag.c | 46 ++++---- 5 files changed, 145 insertions(+), 130 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/6 af_unix: Clean up some sock_net() uses.
Some functions define a net pointer only for one-shot use. Others call sock_net() redundantly even when a net pointer is available. Let's fix these and make the code simpler.
--- net/unix/af_unix.c | 33 ++++++++++++++------------------- net/unix/diag.c | 3 +-- 2 files changed, 15 insertions(+), 21 deletions(-)
net/unix/af_unix.c +14 -19
@@ -932,7 +932,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,memset (&u->scm_stat,0 ,sizeof (struct scm_stat ));unix_insert_unbound_socket (sk); -sock_prot_inuse_add (sock_net (sk), sk->sk_prot,1 ); +sock_prot_inuse_add (net, sk->sk_prot,1 );return sk;
@@ -1293,9 +1293,8 @@ static void unix_state_double_unlock(struct sock *sk1, struct sock *sk2)static int unix_dgram_connect (struct socket *sock,struct sockaddr *addr,int alen,int flags) { -struct sock *sk = sock->sk; -struct net *net =sock_net (sk);struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; +struct sock *sk = sock->sk;struct sock *other;int err;
@@ -1316,7 +1315,7 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr, } restart: - other =unix_find_other (net, sunaddr, alen, sock->type); + other =unix_find_other (sock_net (sk), sunaddr, alen, sock->type);if (IS_ERR (other)) { err =PTR_ERR (other); goto out;
@@ -1404,15 +1403,13 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags) {struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; -struct sock *sk = sock->sk; -struct net *net =sock_net (sk); +struct sock *sk = sock->sk, *newsk =NULL , *other =NULL ;struct unix_sock *u =unix_sk (sk), *newu, *otheru; -struct sock *newsk =NULL ; -struct sock *other =NULL ; +struct net *net =sock_net (sk);struct sk_buff *skb =NULL ; -int st; -int err;long timeo; +int err; +int st; err =unix_validate_addr (sunaddr, addr_len);if (err)
@@ -1432,7 +1429,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,*/ /* create new sock for complete connection */ - newsk =unix_create1 (sock_net (sk),NULL ,0 , sock->type); + newsk =unix_create1 (net,NULL ,0 , sock->type);if (IS_ERR (newsk)) { err =PTR_ERR (newsk); newsk =NULL ;
@@ -1840,17 +1837,15 @@ static void scm_stat_del(struct sock *sk, struct sk_buff *skb)static int unix_dgram_sendmsg (struct socket *sock,struct msghdr *msg,size_t len) { -struct sock *sk = sock->sk; -struct net *net =sock_net (sk); -struct unix_sock *u =unix_sk (sk); DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name); -struct sock *other =NULL ; -int err; -struct sk_buff *skb; -long timeo; +struct sock *sk = sock->sk, *other =NULL ; +struct unix_sock *u =unix_sk (sk);struct scm_cookie scm; +struct sk_buff *skb;int data_len =0 ;int sk_locked; +long timeo; +int err;wait_for_unix_gc (); err =scm_send (sock, msg, &scm, false);
@@ -1917,7 +1912,7 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,if (sunaddr ==NULL ) goto out_free; - other =unix_find_other (net, sunaddr, msg->msg_namelen, + other =unix_find_other (sock_net (sk), sunaddr, msg->msg_namelen, sk->sk_type);if (IS_ERR (other)) { err =PTR_ERR (other);
net/unix/diag.c +1 -2
@@ -308,7 +308,6 @@ static int unix_diag_get_exact(struct sk_buff *in_skb,static int unix_diag_handler_dump (struct sk_buff *skb,struct nlmsghdr *h) {int hdrlen =sizeof (struct unix_diag_req ); -struct net *net =sock_net (skb->sk);if (nlmsg_len (h) < hdrlen)return -EINVAL ;
@@ -317,7 +316,7 @@ static int unix_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)struct netlink_dump_control c = { .dump = unix_diag_dump, }; -return netlink_dump_start (net->diag_nlsk, skb, h, &c); +return netlink_dump_start (sock_net (skb->sk)->diag_nlsk, skb, h, &c); }else return unix_diag_get_exact (skb, h,nlmsg_data (h)); }
Signature · 1 line
2.30.2
PATCH v2 2/6 af_unix: Include the whole hash table size in UNIX_HASH_SIZE.
In reply to Kuniyuki IwashimaCurrently, the size of AF_UNIX hash table is UNIX_HASH_SIZE * 2, the first half for bind()ed sockets and the second half for unbound ones. UNIX_HASH_SIZE * 2 is used to define the table and iterate over it.
In some places, we use ARRAY_SIZE(unix_socket_table) instead of UNIX_HASH_SIZE * 2. However, we cannot use it anymore because we will allocate the hash table dynamically. Then, we would have to add UNIX_HASH_SIZE * 2 in many places, which would be troublesome.
This patch adapts the UNIX_HASH_SIZE definition to include bound and unbound sockets and defines a new UNIX_HASH_MOD macro to ease calculations.
--- include/net/af_unix.h | 7 ++++--- net/unix/af_unix.c | 18 +++++++++--------- net/unix/diag.c | 6 ++---- 3 files changed, 15 insertions(+), 16 deletions(-)
include/net/af_unix.h +4 -3
@@ -16,12 +16,13 @@ void wait_for_unix_gc(void);struct sock *unix_get_socket (struct file *filp);struct sock *unix_peer_get (struct sock *sk); -#define UNIX_HASH_SIZE 256 +#define UNIX_HASH_MOD (256 - 1) +#define UNIX_HASH_SIZE (256 * 2)#define UNIX_HASH_BITS 8extern unsigned int unix_tot_inflight; -extern spinlock_t unix_table_locks[2 *UNIX_HASH_SIZE ]; -extern struct hlist_head unix_socket_table[2 *UNIX_HASH_SIZE ]; +extern spinlock_t unix_table_locks[UNIX_HASH_SIZE ]; +extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE ];struct unix_address {refcount_t refcnt;
net/unix/af_unix.c +9 -9
@@ -118,9 +118,9 @@#include "scm.h" -spinlock_t unix_table_locks[2 *UNIX_HASH_SIZE ]; +spinlock_t unix_table_locks[UNIX_HASH_SIZE ];EXPORT_SYMBOL_GPL (unix_table_locks); -struct hlist_head unix_socket_table[2 *UNIX_HASH_SIZE ]; +struct hlist_head unix_socket_table[UNIX_HASH_SIZE ];EXPORT_SYMBOL_GPL (unix_socket_table);static atomic_long_t unix_nr_socks;
@@ -137,12 +137,12 @@ static unsigned int unix_unbound_hash(struct sock *sk) hash ^= hash >>8 ; hash ^= sk->sk_type; -return UNIX_HASH_SIZE + (hash & (UNIX_HASH_SIZE -1 )); +return UNIX_HASH_MOD +1 + (hash &UNIX_HASH_MOD ); }static unsigned int unix_bsd_hash (struct inode *i) { -return i->i_ino & (UNIX_HASH_SIZE -1 ); +return i->i_ino &UNIX_HASH_MOD ; } static unsigned int unix_abstract_hash(struct sockaddr_un *sunaddr,
@@ -155,14 +155,14 @@ static unsigned int unix_abstract_hash(struct sockaddr_un *sunaddr, hash ^= hash >>8 ; hash ^= type; -return hash & (UNIX_HASH_SIZE -1 ); +return hash &UNIX_HASH_MOD ; }static void unix_table_double_lock (unsigned int hash1,unsigned int hash2) {/* hash1 and hash2 is never the same because -* one is between 0 and UNIX_HASH_SIZE - 1, and -* another is between UNIX_HASH_SIZE and UNIX_HASH_SIZE * 2. +* one is between 0 and UNIX_HASH_MOD, and +* another is between UNIX_HASH_MOD + 1 and UNIX_HASH_SIZE - 1. */ if (hash1 > hash2)swap (hash1, hash2);
@@ -3239,7 +3239,7 @@ static struct sock *unix_get_first(struct seq_file *seq, loff_t *pos)unsigned long bucket =get_bucket (*pos);struct sock *sk; -while (bucket <ARRAY_SIZE (unix_socket_table)) { +while (bucket <UNIX_HASH_SIZE ) {spin_lock (&unix_table_locks[bucket]); sk =unix_from_bucket (seq, pos);
@@ -3666,7 +3666,7 @@ static int __init af_unix_init(void) BUILD_BUG_ON(sizeof(struct unix_skb_parms) > sizeof_field(struct sk_buff, cb)); -for (i =0 ; i <2 *UNIX_HASH_SIZE ; i++) +for (i =0 ; i <UNIX_HASH_SIZE ; i++)spin_lock_init (&unix_table_locks[i]); rc =proto_register (&unix_dgram_proto,1 );
net/unix/diag.c +2 -4
@@ -204,9 +204,7 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) s_slot = cb->args[0 ]; num = s_num = cb->args[1 ]; -for (slot = s_slot; - slot <ARRAY_SIZE (unix_socket_table); - s_num =0 , slot++) { +for (slot = s_slot; slot <UNIX_HASH_SIZE ; s_num =0 , slot++) {struct sock *sk; num =0 ;
@@ -242,7 +240,7 @@ static struct sock *unix_lookup_by_ino(unsigned int ino)struct sock *sk;int i; -for (i =0 ; i <ARRAY_SIZE (unix_socket_table); i++) { +for (i =0 ; i <UNIX_HASH_SIZE ; i++) {spin_lock (&unix_table_locks[i]);sk_for_each (sk, &unix_socket_table[i])if (ino ==sock_i_ino (sk)) {
Signature · 1 line
2.30.2
PATCH v2 3/6 af_unix: Define a per-netns hash table.
In reply to Kuniyuki IwashimaThis commit adds a per netns hash table for AF_UNIX, which size is fixed as UNIX_HASH_SIZE for now.
The first implementation defines a per-netns hash table as a single array of lock and list:
struct unix_hashbucket {
spinlock_t lock;
struct hlist_head head;
};
struct netns_unix {
struct unix_hashbucket *hash;
...
};But, Eric pointed out memory cost that the structure has holes because of sizeof(spinlock_t), which is 4 (or more if LOCKDEP is enabled). [0] It could be expensive on a host with thousands of netns and few AF_UNIX sockets. For this reason, a per-netns hash table uses two dense arrays.
struct unix_table {
spinlock_t *locks;
struct hlist_head *buckets;
};
struct netns_unix {
struct unix_table table;
...
};Note the length of the list has a significant impact rather than lock contention, so having shared locks can be an option. But, per-netns locks and lists still perform better than the global locks and per-netns lists. [1]
Also, this patch adds a change so that struct netns_unix disappears from struct net if CONFIG_UNIX is disabled.
[0]: https://lore.kernel.org/netdev/CANn89iLVxO5aqx16azNU7p7Z-nz5NrnM5QTqOzueVxEnkVTxyg@mail.gmail.com/
[1]: https://lore.kernel.org/netdev/[email protected]/
--- include/net/net_namespace.h | 2 ++ include/net/netns/unix.h | 6 ++++++ net/unix/af_unix.c | 38 +++++++++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 6 deletions(-)
include/net/net_namespace.h +2 -0
@@ -120,7 +120,9 @@ struct net {struct netns_core core;struct netns_mib mib;struct netns_packet packet; +#if IS_ENABLED (CONFIG_UNIX )struct netns_unix unx; +#endif struct netns_nexthop nexthop;struct netns_ipv4 ipv4;#if IS_ENABLED (CONFIG_IPV6 )
include/net/netns/unix.h +6 -0
@@ -5,8 +5,14 @@#ifndef __NETNS_UNIX_H__#define __NETNS_UNIX_H__ +struct unix_table { +spinlock_t *locks; +struct hlist_head *buckets; +}; +struct ctl_table_header ;struct netns_unix { +struct unix_table table;int sysctl_max_dgram_qlen;struct ctl_table_header *ctl; };
net/unix/af_unix.c +32 -6
@@ -3559,7 +3559,7 @@ static const struct net_proto_family unix_family_ops = {static int __net_init unix_net_init (struct net *net) { -int error = -ENOMEM ; +int i; net->unx.sysctl_max_dgram_qlen =10 ;if (unix_sysctl_register (net))
@@ -3567,18 +3567,44 @@ static int __net_init unix_net_init(struct net *net)#ifdef CONFIG_PROC_FS if (!proc_create_net ("unix" ,0 , net->proc_net, &unix_seq_ops, -sizeof (struct seq_net_private ))) { -unix_sysctl_unregister (net); - goto out; +sizeof (struct seq_net_private ))) + goto err_sysctl; +#endif + + net->unx.table.locks =kvmalloc_array (UNIX_HASH_SIZE , +sizeof (spinlock_t),GFP_KERNEL ); +if (!net->unx.table.locks) + goto err_proc; + + net->unx.table.buckets =kvmalloc_array (UNIX_HASH_SIZE , +sizeof (struct hlist_head ), +GFP_KERNEL ); +if (!net->unx.table.buckets) + goto free_locks; + +for (i =0 ; i <UNIX_HASH_SIZE ; i++) { +spin_lock_init (&net->unx.table.locks[i]); +INIT_HLIST_HEAD (&net->unx.table.buckets[i]); } + +return 0 ; + +free_locks: +kvfree (net->unx.table.locks); +err_proc: +#ifdef CONFIG_PROC_FS +remove_proc_entry ("unix" , net->proc_net); +err_sysctl:#endif - error =0 ; +unix_sysctl_unregister (net); out: -return error; +return -ENOMEM ; } static void __net_exit unix_net_exit(struct net *net) { +kvfree (net->unx.table.buckets); +kvfree (net->unx.table.locks);unix_sysctl_unregister (net);remove_proc_entry ("unix" , net->proc_net); }
Signature · 1 line
2.30.2
PATCH v2 4/6 af_unix: Acquire/Release per-netns hash table's locks.
In reply to Kuniyuki IwashimaThis commit adds extra spin_lock/spin_unlock() for a per-netns hash table inside the existing ones for unix_table_locks.
As of this commit, sockets are still linked in the global hash table. After putting sockets in a per-netns hash table and removing the old one in the next patch, we remove the global locks in the last patch.
--- net/unix/af_unix.c | 75 +++++++++++++++++++++++++++++++--------------- net/unix/diag.c | 23 +++++++++----- 2 files changed, 66 insertions(+), 32 deletions(-)
net/unix/af_unix.c +51 -24
@@ -158,7 +158,8 @@ static unsigned int unix_abstract_hash(struct sockaddr_un *sunaddr,return hash &UNIX_HASH_MOD ; } -static void unix_table_double_lock (unsigned int hash1,unsigned int hash2) +static void unix_table_double_lock (struct net *net, +unsigned int hash1,unsigned int hash2) {/* hash1 and hash2 is never the same because * one is between 0 and UNIX_HASH_MOD, and
@@ -169,10 +170,17 @@ static void unix_table_double_lock(unsigned int hash1, unsigned int hash2)spin_lock (&unix_table_locks[hash1]);spin_lock_nested (&unix_table_locks[hash2],SINGLE_DEPTH_NESTING ); + +spin_lock (&net->unx.table.locks[hash1]); +spin_lock_nested (&net->unx.table.locks[hash2],SINGLE_DEPTH_NESTING ); } -static void unix_table_double_unlock (unsigned int hash1,unsigned int hash2) +static void unix_table_double_unlock (struct net *net, +unsigned int hash1,unsigned int hash2) { +spin_unlock (&net->unx.table.locks[hash1]); +spin_unlock (&net->unx.table.locks[hash2]); +spin_unlock (&unix_table_locks[hash1]);spin_unlock (&unix_table_locks[hash2]); }
@@ -316,17 +324,21 @@ static void __unix_set_addr_hash(struct sock *sk, struct unix_address *addr,__unix_insert_socket (sk); } -static void unix_remove_socket (struct sock *sk) +static void unix_remove_socket (struct net *net,struct sock *sk) {spin_lock (&unix_table_locks[sk->sk_hash]); +spin_lock (&net->unx.table.locks[sk->sk_hash]);__unix_remove_socket (sk); +spin_unlock (&net->unx.table.locks[sk->sk_hash]);spin_unlock (&unix_table_locks[sk->sk_hash]); } -static void unix_insert_unbound_socket (struct sock *sk) +static void unix_insert_unbound_socket (struct net *net,struct sock *sk) {spin_lock (&unix_table_locks[sk->sk_hash]); +spin_lock (&net->unx.table.locks[sk->sk_hash]);__unix_insert_socket (sk); +spin_unlock (&net->unx.table.locks[sk->sk_hash]);spin_unlock (&unix_table_locks[sk->sk_hash]); }
@@ -356,28 +368,33 @@ static inline struct sock *unix_find_socket_byname(struct net *net,struct sock *s;spin_lock (&unix_table_locks[hash]); +spin_lock (&net->unx.table.locks[hash]); s =__unix_find_socket_byname (net, sunname, len, hash);if (s)sock_hold (s); +spin_unlock (&net->unx.table.locks[hash]);spin_unlock (&unix_table_locks[hash]);return s; } -static struct sock *unix_find_socket_byinode (struct inode *i) +static struct sock *unix_find_socket_byinode (struct net *net,struct inode *i) {unsigned int hash =unix_bsd_hash (i);struct sock *s;spin_lock (&unix_table_locks[hash]); +spin_lock (&net->unx.table.locks[hash]);sk_for_each (s, &unix_socket_table[hash]) {struct dentry *dentry =unix_sk (s)->path.dentry;if (dentry &&d_backing_inode (dentry) == i) {sock_hold (s); +spin_unlock (&net->unx.table.locks[hash]);spin_unlock (&unix_table_locks[hash]);return s; } } +spin_unlock (&net->unx.table.locks[hash]);spin_unlock (&unix_table_locks[hash]);return NULL ; }
@@ -576,12 +593,12 @@ static void unix_sock_destructor(struct sock *sk)static void unix_release_sock (struct sock *sk,int embrion) {struct unix_sock *u =unix_sk (sk); -struct path path;struct sock *skpair;struct sk_buff *skb; +struct path path;int state; -unix_remove_socket (sk); +unix_remove_socket (sock_net (sk), sk);/* Clear state */ unix_state_lock (sk);
@@ -930,7 +947,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,init_waitqueue_head (&u->peer_wait);init_waitqueue_func_entry (&u->peer_wake, unix_dgram_peer_wake_relay);memset (&u->scm_stat,0 ,sizeof (struct scm_stat )); -unix_insert_unbound_socket (sk); +unix_insert_unbound_socket (net, sk);sock_prot_inuse_add (net, sk->sk_prot,1 );
@@ -1015,7 +1032,7 @@ static struct sock *unix_find_bsd(struct net *net, struct sockaddr_un *sunaddr,if (!S_ISSOCK (inode->i_mode)) goto path_put; - sk =unix_find_socket_byinode (inode); + sk =unix_find_socket_byinode (net, inode);if (!sk) goto path_put;
@@ -1074,6 +1091,7 @@ static int unix_autobind(struct sock *sk) {unsigned int new_hash, old_hash = sk->sk_hash;struct unix_sock *u =unix_sk (sk); +struct net *net =sock_net (sk);struct unix_address *addr;u32 lastnum, ordernum;int err;
@@ -1102,11 +1120,10 @@ static int unix_autobind(struct sock *sk)sprintf (addr->name->sun_path +1 ,"%05x" , ordernum); new_hash =unix_abstract_hash (addr->name, addr->len, sk->sk_type); -unix_table_double_lock (old_hash, new_hash); +unix_table_double_lock (net, old_hash, new_hash); -if (__unix_find_socket_byname (sock_net (sk), addr->name, addr->len, - new_hash)) { -unix_table_double_unlock (old_hash, new_hash); +if (__unix_find_socket_byname (net, addr->name, addr->len, new_hash)) { +unix_table_double_unlock (net, old_hash, new_hash);/* __unix_find_socket_byname() may take long time if many names * are already in use.
@@ -1124,7 +1141,7 @@ static int unix_autobind(struct sock *sk) }__unix_set_addr_hash (sk, addr, new_hash); -unix_table_double_unlock (old_hash, new_hash); +unix_table_double_unlock (net, old_hash, new_hash); err =0 ; out:mutex_unlock (&u->bindlock);
@@ -1138,6 +1155,7 @@ static int unix_bind_bsd(struct sock *sk, struct sockaddr_un *sunaddr, (SOCK_INODE (sk->sk_socket)->i_mode & ~current_umask ());unsigned int new_hash, old_hash = sk->sk_hash;struct unix_sock *u =unix_sk (sk); +struct net *net =sock_net (sk);struct user_namespace *ns;// barf... struct unix_address *addr;struct dentry *dentry;
@@ -1178,11 +1196,11 @@ static int unix_bind_bsd(struct sock *sk, struct sockaddr_un *sunaddr, goto out_unlock; new_hash =unix_bsd_hash (d_backing_inode (dentry)); -unix_table_double_lock (old_hash, new_hash); +unix_table_double_lock (net, old_hash, new_hash); u->path.mnt =mntget (parent.mnt); u->path.dentry =dget (dentry);__unix_set_addr_hash (sk, addr, new_hash); -unix_table_double_unlock (old_hash, new_hash); +unix_table_double_unlock (net, old_hash, new_hash);mutex_unlock (&u->bindlock);done_path_create (&parent, dentry);return 0 ;
@@ -1205,6 +1223,7 @@ static int unix_bind_abstract(struct sock *sk, struct sockaddr_un *sunaddr, {unsigned int new_hash, old_hash = sk->sk_hash;struct unix_sock *u =unix_sk (sk); +struct net *net =sock_net (sk);struct unix_address *addr;int err;
@@ -1222,19 +1241,18 @@ static int unix_bind_abstract(struct sock *sk, struct sockaddr_un *sunaddr, } new_hash =unix_abstract_hash (addr->name, addr->len, sk->sk_type); -unix_table_double_lock (old_hash, new_hash); +unix_table_double_lock (net, old_hash, new_hash); -if (__unix_find_socket_byname (sock_net (sk), addr->name, addr->len, - new_hash)) +if (__unix_find_socket_byname (net, addr->name, addr->len, new_hash)) goto out_spin;__unix_set_addr_hash (sk, addr, new_hash); -unix_table_double_unlock (old_hash, new_hash); +unix_table_double_unlock (net, old_hash, new_hash);mutex_unlock (&u->bindlock);return 0 ; out_spin: -unix_table_double_unlock (old_hash, new_hash); +unix_table_double_unlock (net, old_hash, new_hash); err = -EADDRINUSE ; out_mutex:mutex_unlock (&u->bindlock);
@@ -3237,15 +3255,18 @@ static struct sock *unix_from_bucket(struct seq_file *seq, loff_t *pos)static struct sock *unix_get_first (struct seq_file *seq,loff_t *pos) {unsigned long bucket =get_bucket (*pos); +struct net *net =seq_file_net (seq);struct sock *sk;while (bucket <UNIX_HASH_SIZE ) {spin_lock (&unix_table_locks[bucket]); +spin_lock (&net->unx.table.locks[bucket]); sk =unix_from_bucket (seq, pos);if (sk)return sk; +spin_unlock (&net->unx.table.locks[bucket]);spin_unlock (&unix_table_locks[bucket]); *pos =set_bucket_offset (++bucket,1 );
@@ -3258,11 +3279,13 @@ static struct sock *unix_get_next(struct seq_file *seq, struct sock *sk, loff_t *pos) {unsigned long bucket =get_bucket (*pos); +struct net *net =seq_file_net (seq);for (sk =sk_next (sk); sk; sk =sk_next (sk)) -if (sock_net (sk) ==seq_file_net (seq)) +if (sock_net (sk) == net)return sk; +spin_unlock (&net->unx.table.locks[bucket]);spin_unlock (&unix_table_locks[bucket]); *pos =set_bucket_offset (++bucket,1 );
@@ -3292,8 +3315,10 @@ static void unix_seq_stop(struct seq_file *seq, void *v) {struct sock *sk = v; -if (sk) +if (sk) { +spin_unlock (&seq_file_net (seq)->unx.table.locks[sk->sk_hash]);spin_unlock (&unix_table_locks[sk->sk_hash]); + } }static int unix_seq_show (struct seq_file *seq,void *v)
@@ -3381,6 +3406,7 @@ static int bpf_iter_unix_hold_batch(struct seq_file *seq, struct sock *start_sk) {struct bpf_unix_iter_state *iter = seq->private; +struct net *net =seq_file_net (seq);unsigned int expected =1 ;struct sock *sk;
@@ -3388,7 +3414,7 @@ static int bpf_iter_unix_hold_batch(struct seq_file *seq, struct sock *start_sk) iter->batch[iter->end_sk++] = start_sk;for (sk =sk_next (start_sk); sk; sk =sk_next (sk)) { -if (sock_net (sk) !=seq_file_net (seq)) +if (sock_net (sk) != net)continue ;if (iter->end_sk < iter->max_sk) {
@@ -3399,6 +3425,7 @@ static int bpf_iter_unix_hold_batch(struct seq_file *seq, struct sock *start_sk) expected++; } +spin_unlock (&net->unx.table.locks[start_sk->sk_hash]);spin_unlock (&unix_table_locks[start_sk->sk_hash]);return expected;
net/unix/diag.c +15 -8
@@ -195,9 +195,9 @@ static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, struct unix_diag_rstatic int unix_diag_dump (struct sk_buff *skb,struct netlink_callback *cb) { -struct unix_diag_req *req; -int num, s_num, slot, s_slot;struct net *net =sock_net (skb->sk); +int num, s_num, slot, s_slot; +struct unix_diag_req *req; req =nlmsg_data (cb->nlh);
@@ -209,6 +209,7 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) num =0 ;spin_lock (&unix_table_locks[slot]); +spin_lock (&net->unx.table.locks[slot]);sk_for_each (sk, &unix_socket_table[slot]) {if (!net_eq (sock_net (sk), net))continue ;
@@ -220,12 +221,14 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, NLM_F_MULTI) < 0) { +spin_unlock (&net->unx.table.locks[slot]);spin_unlock (&unix_table_locks[slot]); goto done; } next: num++; } +spin_unlock (&net->unx.table.locks[slot]);spin_unlock (&unix_table_locks[slot]); } done:
@@ -235,19 +238,22 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)return skb->len; } -static struct sock *unix_lookup_by_ino (unsigned int ino) +static struct sock *unix_lookup_by_ino (struct net *net,unsigned int ino) {struct sock *sk;int i;for (i =0 ; i <UNIX_HASH_SIZE ; i++) {spin_lock (&unix_table_locks[i]); +spin_lock (&net->unx.table.locks[i]);sk_for_each (sk, &unix_socket_table[i])if (ino ==sock_i_ino (sk)) {sock_hold (sk); +spin_unlock (&net->unx.table.locks[i]);spin_unlock (&unix_table_locks[i]);return sk; } +spin_unlock (&net->unx.table.locks[i]);spin_unlock (&unix_table_locks[i]); }return NULL ;
@@ -257,16 +263,17 @@ static int unix_diag_get_exact(struct sk_buff *in_skb,const struct nlmsghdr *nlh, struct unix_diag_req *req) { - int err = -EINVAL; -struct sock *sk; -struct sk_buff *rep; -unsigned int extra_len; struct net *net = sock_net(in_skb->sk); +unsigned int extra_len; +struct sk_buff *rep; +struct sock *sk; +int err; + err = -EINVAL ;if (req->udiag_ino ==0 ) goto out_nosk; - sk =unix_lookup_by_ino (req->udiag_ino); + sk =unix_lookup_by_ino (net, req->udiag_ino); err = -ENOENT ;if (sk ==NULL ) goto out_nosk;
Signature · 1 line
2.30.2
PATCH v2 5/6 af_unix: Put a socket into a per-netns hash table.
In reply to Kuniyuki IwashimaThis commit replaces the global hash table with a per-netns one and removes the global one.
We now link a socket in each netns's hash table so we can save some netns comparisons when iterating through a hash bucket.
--- include/net/af_unix.h | 1 - net/unix/af_unix.c | 50 +++++++++++++++++-------------------------- net/unix/diag.c | 9 +++----- 3 files changed, 23 insertions(+), 37 deletions(-)
include/net/af_unix.h +0 -1
@@ -22,7 +22,6 @@ struct sock *unix_peer_get(struct sock *sk);extern unsigned int unix_tot_inflight;extern spinlock_t unix_table_locks[UNIX_HASH_SIZE ]; -extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE ];struct unix_address {refcount_t refcnt;
net/unix/af_unix.c +20 -30
143 lines not on this page · raw message
net/unix/diag.c +3 -6
@@ -210,9 +210,7 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) num =0 ;spin_lock (&unix_table_locks[slot]);spin_lock (&net->unx.table.locks[slot]); -sk_for_each (sk, &unix_socket_table[slot]) { -if (!net_eq (sock_net (sk), net)) -continue ; +sk_for_each (sk, &net->unx.table.buckets[slot]) {if (num < s_num) goto next;if (!(req->udiag_states & (1 << sk->sk_state)))
@@ -246,13 +244,14 @@ static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino)for (i =0 ; i <UNIX_HASH_SIZE ; i++) {spin_lock (&unix_table_locks[i]);spin_lock (&net->unx.table.locks[i]); -sk_for_each (sk, &unix_socket_table[i]) +sk_for_each (sk, &net->unx.table.buckets[i]) {if (ino ==sock_i_ino (sk)) {sock_hold (sk);spin_unlock (&net->unx.table.locks[i]);spin_unlock (&unix_table_locks[i]);return sk; } + }spin_unlock (&net->unx.table.locks[i]);spin_unlock (&unix_table_locks[i]); }
@@ -277,8 +276,6 @@ static int unix_diag_get_exact(struct sk_buff *in_skb, err = -ENOENT ;if (sk ==NULL ) goto out_nosk; -if (!net_eq (sock_net (sk), net)) - goto out; err =sock_diag_check_cookie (sk, req->udiag_cookie);if (err)
Signature · 1 line
2.30.2
PATCH v2 6/6 af_unix: Remove unix_table_locks.
In reply to Kuniyuki Iwashimaunix_table_locks are to protect the global hash table, unix_socket_table. The previous commit removed it, so let's clean up the unnecessary locks.
Here is a test result on EC2 c5.9xlarge where 10 processes run concurrently in different netns and bind 100,000 sockets for each.
without this series : 1m 38s
with this series : 11s
It is ~10x faster because the global hash table is split into 10 netns in this case.
--- include/net/af_unix.h | 1 - net/unix/af_unix.c | 30 ++---------------------------- net/unix/diag.c | 5 ----- 3 files changed, 2 insertions(+), 34 deletions(-)
include/net/af_unix.h +0 -1
@@ -21,7 +21,6 @@ struct sock *unix_peer_get(struct sock *sk);#define UNIX_HASH_BITS 8extern unsigned int unix_tot_inflight; -extern spinlock_t unix_table_locks[UNIX_HASH_SIZE ];struct unix_address {refcount_t refcnt;
net/unix/af_unix.c +2 -28
@@ -118,8 +118,6 @@#include "scm.h" -spinlock_t unix_table_locks[UNIX_HASH_SIZE ]; -EXPORT_SYMBOL_GPL (unix_table_locks);static atomic_long_t unix_nr_socks;/* SMP locking strategy:
@@ -166,9 +164,6 @@ static void unix_table_double_lock(struct net *net,if (hash1 > hash2)swap (hash1, hash2); -spin_lock (&unix_table_locks[hash1]); -spin_lock_nested (&unix_table_locks[hash2],SINGLE_DEPTH_NESTING ); -spin_lock (&net->unx.table.locks[hash1]);spin_lock_nested (&net->unx.table.locks[hash2],SINGLE_DEPTH_NESTING ); }
@@ -178,9 +173,6 @@ static void unix_table_double_unlock(struct net *net, {spin_unlock (&net->unx.table.locks[hash1]);spin_unlock (&net->unx.table.locks[hash2]); - -spin_unlock (&unix_table_locks[hash1]); -spin_unlock (&unix_table_locks[hash2]); }#ifdef CONFIG_SECURITY_NETWORK
@@ -324,20 +316,16 @@ static void __unix_set_addr_hash(struct net *net, struct sock *sk,static void unix_remove_socket (struct net *net,struct sock *sk) { -spin_lock (&unix_table_locks[sk->sk_hash]);spin_lock (&net->unx.table.locks[sk->sk_hash]);__unix_remove_socket (sk);spin_unlock (&net->unx.table.locks[sk->sk_hash]); -spin_unlock (&unix_table_locks[sk->sk_hash]); }static void unix_insert_unbound_socket (struct net *net,struct sock *sk) { -spin_lock (&unix_table_locks[sk->sk_hash]);spin_lock (&net->unx.table.locks[sk->sk_hash]);__unix_insert_socket (net, sk);spin_unlock (&net->unx.table.locks[sk->sk_hash]); -spin_unlock (&unix_table_locks[sk->sk_hash]); } static struct sock *__unix_find_socket_byname(struct net *net,
@@ -362,13 +350,11 @@ static inline struct sock *unix_find_socket_byname(struct net *net, {struct sock *s; -spin_lock (&unix_table_locks[hash]);spin_lock (&net->unx.table.locks[hash]); s =__unix_find_socket_byname (net, sunname, len, hash);if (s)sock_hold (s);spin_unlock (&net->unx.table.locks[hash]); -spin_unlock (&unix_table_locks[hash]);return s; }
@@ -377,7 +363,6 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)unsigned int hash =unix_bsd_hash (i);struct sock *s; -spin_lock (&unix_table_locks[hash]);spin_lock (&net->unx.table.locks[hash]);sk_for_each (s, &net->unx.table.buckets[hash]) {struct dentry *dentry =unix_sk (s)->path.dentry;
@@ -385,12 +370,10 @@ static struct sock *unix_find_socket_byinode(struct net *net, struct inode *i)if (dentry &&d_backing_inode (dentry) == i) {sock_hold (s);spin_unlock (&net->unx.table.locks[hash]); -spin_unlock (&unix_table_locks[hash]);return s; } }spin_unlock (&net->unx.table.locks[hash]); -spin_unlock (&unix_table_locks[hash]);return NULL ; }
@@ -3253,7 +3236,6 @@ static struct sock *unix_get_first(struct seq_file *seq, loff_t *pos)struct sock *sk;while (bucket <UNIX_HASH_SIZE ) { -spin_lock (&unix_table_locks[bucket]);spin_lock (&net->unx.table.locks[bucket]); sk =unix_from_bucket (seq, pos);
@@ -3261,7 +3243,6 @@ static struct sock *unix_get_first(struct seq_file *seq, loff_t *pos)return sk;spin_unlock (&net->unx.table.locks[bucket]); -spin_unlock (&unix_table_locks[bucket]); *pos =set_bucket_offset (++bucket,1 ); }
@@ -3280,7 +3261,6 @@ static struct sock *unix_get_next(struct seq_file *seq, struct sock *sk,spin_unlock (&seq_file_net (seq)->unx.table.locks[bucket]); -spin_unlock (&unix_table_locks[bucket]); *pos =set_bucket_offset (++bucket,1 );
@@ -3309,10 +3289,8 @@ static void unix_seq_stop(struct seq_file *seq, void *v) {struct sock *sk = v; -if (sk) { +if (sk)spin_unlock (&seq_file_net (seq)->unx.table.locks[sk->sk_hash]); -spin_unlock (&unix_table_locks[sk->sk_hash]); - } }static int unix_seq_show (struct seq_file *seq,void *v)
@@ -3416,7 +3394,6 @@ static int bpf_iter_unix_hold_batch(struct seq_file *seq, struct sock *start_sk) }spin_unlock (&seq_file_net (seq)->unx.table.locks[start_sk->sk_hash]); -spin_unlock (&unix_table_locks[start_sk->sk_hash]);return expected; }
@@ -3705,13 +3682,10 @@ static void __init bpf_iter_register(void)static int __init af_unix_init (void ) { -int i, rc =-1 ; +int rc =-1 ; BUILD_BUG_ON(sizeof(struct unix_skb_parms) > sizeof_field(struct sk_buff, cb)); -for (i =0 ; i <UNIX_HASH_SIZE ; i++) -spin_lock_init (&unix_table_locks[i]); - rc =proto_register (&unix_dgram_proto,1 );if (rc !=0 ) {pr_crit ("%s: Cannot create unix_sock SLAB cache!\n" , __func__);
net/unix/diag.c +0 -5
@@ -208,7 +208,6 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)struct sock *sk; num =0 ; -spin_lock (&unix_table_locks[slot]);spin_lock (&net->unx.table.locks[slot]);sk_for_each (sk, &net->unx.table.buckets[slot]) {if (num < s_num)
@@ -220,14 +219,12 @@ static int unix_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) cb->nlh->nlmsg_seq, NLM_F_MULTI) < 0) {spin_unlock (&net->unx.table.locks[slot]); -spin_unlock (&unix_table_locks[slot]); goto done; } next: num++; }spin_unlock (&net->unx.table.locks[slot]); -spin_unlock (&unix_table_locks[slot]); } done: cb->args[0 ] = slot;
@@ -242,7 +239,6 @@ static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino)int i;for (i =0 ; i <UNIX_HASH_SIZE ; i++) { -spin_lock (&unix_table_locks[i]);spin_lock (&net->unx.table.locks[i]);sk_for_each (sk, &net->unx.table.buckets[i]) {if (ino ==sock_i_ino (sk)) {
@@ -253,7 +249,6 @@ static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino) } }spin_unlock (&net->unx.table.locks[i]); -spin_unlock (&unix_table_locks[i]); }return NULL ; }
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH v2 net-next 6/6] af_unix: Remove unix_table_locks.
Thank you for the patch! Yet something to improve:
Hi Kuniyuki,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git dbca1596bbb08318f5e3b3b99f8ca0a0d3830a65 config: arc-defconfig (https://download.01.org/0day-ci/archive/20220621/[email protected]/config) compiler: arc-elf-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f2cd3aee6929543114a0728717969d9bb2f6fa90
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 git checkout f2cd3aee6929543114a0728717969d9bb2f6fa90
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
net/unix/diag.c: In function 'unix_lookup_by_ino':
>> net/unix/diag.c:247:46: error: 'unix_table_locks' undeclared (first use in this function); did you mean 'unix_state_lock'?
247 | spin_unlock(&unix_table_locks[i]);
| ^~~~~~~~~~~~~~~~
| unix_state_lock net/unix/diag.c:247:46: note: each undeclared identifier is reported only once for each function it appears in
vim +247 net/unix/diag.c
22931d3b906cd0 Pavel Emelyanov 2011-12-15 235
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 236 static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino)
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 237 {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 238 struct sock *sk;
afd20b9290e184 Kuniyuki Iwashima 2021-11-24 239 int i;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 240
614d83f20d005b Kuniyuki Iwashima 2022-06-20 241 for (i = 0; i < UNIX_HASH_SIZE; i++) {
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 242 spin_lock(&net->unx.table.locks[i]);
868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 243 sk_for_each(sk, &net->unx.table.buckets[i]) {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 244 if (ino == sock_i_ino(sk)) {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 245 sock_hold(sk);
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 246 spin_unlock(&net->unx.table.locks[i]);
afd20b9290e184 Kuniyuki Iwashima 2021-11-24 @247 spin_unlock(&unix_table_locks[i]);
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 248 return sk;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 249 }
868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 250 }
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 251 spin_unlock(&net->unx.table.locks[i]);
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 252 }
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 253 return NULL;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 254 }5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 255
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
Re: [PATCH v2 net-next 6/6] af_unix: Remove unix_table_locks.
From: kernel test robot <[email protected]> Date: Tue, 21 Jun 2022 05:39:37 +0800
Quoted 24 lines
Hi Kuniyuki,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git dbca1596bbb08318f5e3b3b99f8ca0a0d3830a65 config: arc-defconfig (https://download.01.org/0day-ci/archive/20220621/202206210532.q32y1W52-lkp(a)intel.com/config) compiler: arc-elf-gcc (GCC) 11.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f2cd3aee6929543114a0728717969d9bb2f6fa90
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 git checkoutf2cd3aee6929543114a0728717969d9bb2f6fa90
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bashIf you fix the issue, kindly add following tag where applicable
Reported-by kernel test robot <[email protected]>
Quoted 8 lines
All errors (new ones prefixed by >>):
net/unix/diag.c: In function 'unix_lookup_by_ino':Quoted 1 line
Quoted 1 line
net/unix/diag.c:247:46: error: 'unix_table_locks' undeclared (first use in this function); did you mean 'unix_state_lock'?247 | spin_unlock(&unix_table_locks[i]); | ^~~~~~~~~~~~~~~~ | unix_state_lock
net/unix/diag.c:247:46: note: each undeclared identifier is reported only once for each function it appears in
I'm sorry, CONFIG_UNIX_DIAG was not set in my .config. I'll respin v3.
Best regards,
Kuniyuki
Quoted 27 lines
vim +247
net/unix/diag.c22931d3b906cd0 Pavel Emelyanov 2011-12-15 235 a50feb1de03567 Kuniyuki Iwashima 2022-06-20 236 static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino) 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 237 { 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 238 struct sock *sk; afd20b9290e184 Kuniyuki Iwashima 2021-11-24 239 int i; 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 240 614d83f20d005b Kuniyuki Iwashima 2022-06-20 241 for (i = 0; i < UNIX_HASH_SIZE; i++) { a50feb1de03567 Kuniyuki Iwashima 2022-06-20 242 spin_lock(&net->unx.table.locks[i]); 868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 243 sk_for_each(sk, &net->unx.table.buckets[i]) { 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 244 if (ino == sock_i_ino(sk)) { 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 245 sock_hold(sk); a50feb1de03567 Kuniyuki Iwashima 2022-06-20 246 spin_unlock(&net->unx.table.locks[i]); afd20b9290e184 Kuniyuki Iwashima 2021-11-24 @247 spin_unlock(&unix_table_locks[i]); 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 248 return sk; 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 249 } 868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 250 } a50feb1de03567 Kuniyuki Iwashima 2022-06-20 251 spin_unlock(&net->unx.table.locks[i]); 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 252 } 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 253 return NULL; 5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 254 }
5d3cae8bc39dd3Pavel Emelyanov 2011-12-15 255Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botRe: [PATCH v2 net-next 6/6] af_unix: Remove unix_table_locks.
In reply to Kuniyuki IwashimaThank you for the patch! Yet something to improve:
Hi Kuniyuki,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git dbca1596bbb08318f5e3b3b99f8ca0a0d3830a65 config: i386-randconfig-a012-20220620 (https://download.01.org/0day-ci/archive/20220621/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project af6d2a0b6825e71965f3e2701a63c239fa0ad70f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f2cd3aee6929543114a0728717969d9bb2f6fa90
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Kuniyuki-Iwashima/af_unix-Introduce-per-netns-socket-hash-table/20220621-025503 git checkout f2cd3aee6929543114a0728717969d9bb2f6fa90
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
>> net/unix/diag.c:247:18: error: use of undeclared identifier 'unix_table_locks'
spin_unlock(&unix_table_locks[i]);
^1 error generated.
vim +/unix_table_locks +247 net/unix/diag.c
22931d3b906cd0 Pavel Emelyanov 2011-12-15 235
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 236 static struct sock *unix_lookup_by_ino(struct net *net, unsigned int ino)
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 237 {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 238 struct sock *sk;
afd20b9290e184 Kuniyuki Iwashima 2021-11-24 239 int i;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 240
614d83f20d005b Kuniyuki Iwashima 2022-06-20 241 for (i = 0; i < UNIX_HASH_SIZE; i++) {
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 242 spin_lock(&net->unx.table.locks[i]);
868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 243 sk_for_each(sk, &net->unx.table.buckets[i]) {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 244 if (ino == sock_i_ino(sk)) {
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 245 sock_hold(sk);
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 246 spin_unlock(&net->unx.table.locks[i]);
afd20b9290e184 Kuniyuki Iwashima 2021-11-24 @247 spin_unlock(&unix_table_locks[i]);
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 248 return sk;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 249 }
868a38bbd9ad2a Kuniyuki Iwashima 2022-06-20 250 }
a50feb1de03567 Kuniyuki Iwashima 2022-06-20 251 spin_unlock(&net->unx.table.locks[i]);
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 252 }
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 253 return NULL;
5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 254 }5d3cae8bc39dd3 Pavel Emelyanov 2011-12-15 255
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp