History

Revert "net: Add a second bind table hashed by port and address"

This reverts: commit d5a42de8bdbe ("net: Add a second bind table hashed by port and address") commit 538aaf9b2383 ("selftests: Add test for timing a bind request to a port with a populated bhash entry") Link: https://lore.kernel.org/netdev/20220520001834.2247810-1-kuba@kernel.org/ There are a few things that need to be fixed here: * Updating bhash2 in cases where the socket's rcv saddr changes * Adding bhash2 hashbucket locks Links to syzbot reports: https://lore.kernel.org/netdev/00000000000022208805e0df247a@google.com/ https://lore.kernel.org/netdev/0000000000003f33bc05dfaf44fe@google.com/

Joanne Koong committed 4 years ago

Commit 593d1eb1 parent 219b51a10 files · +83 −611Browse files

Showing the changes to include (3 of 10 files). Show all

Unified · Split

3 files
  1. include/net/inet_connection_sock.h +0 −3
  2. include/net/inet_hashtables.h +1 −67
  3. include/net/sock.h +0 −14
include/net/inet_connection_sock.h+0−3
@@ -25,7 +25,6 @@ · 24 unmodified lines
2525 #undef INET_CSK_CLEAR_TIMERS
2626
2727 struct inet_bind_bucket;
28−struct inet_bind2_bucket;
2928 struct tcp_congestion_ops;
3029
3130 /*
@@ -58,7 +57,6 @@ struct inet_connection_sock_af_ops { · 26 unmodified lines
5857 *
5958 * @icsk_accept_queue: FIFO of established children
6059 * @icsk_bind_hash: Bind node
61− * @icsk_bind2_hash: Bind node in the bhash2 table
6260 * @icsk_timeout: Timeout
6361 * @icsk_retransmit_timer: Resend (no ack)
6462 * @icsk_rto: Retransmit timeout
@@ -85,7 +83,6 @@ struct inet_connection_sock { · 20 unmodified lines
8583 struct inet_sock icsk_inet;
8684 struct request_sock_queue icsk_accept_queue;
8785 struct inet_bind_bucket *icsk_bind_hash;
88− struct inet_bind2_bucket *icsk_bind2_hash;
8986 unsigned long icsk_timeout;
9087 struct timer_list icsk_retransmit_timer;
9188 struct timer_list icsk_delack_timer;
include/net/inet_hashtables.h+1−67
@@ -90,32 +90,11 @@ struct inet_bind_bucket { · 89 unmodified lines
9090 struct hlist_head owners;
9191 };
9292
93−struct inet_bind2_bucket {
94− possible_net_t ib_net;
95− int l3mdev;
96− unsigned short port;
97− union {
98−#if IS_ENABLED(CONFIG_IPV6)
99− struct in6_addr v6_rcv_saddr;
100−#endif
101− __be32 rcv_saddr;
102− };
103− /* Node in the inet2_bind_hashbucket chain */
104− struct hlist_node node;
105− /* List of sockets hashed to this bucket */
106− struct hlist_head owners;
107−};
108−
10993 static inline struct net *ib_net(struct inet_bind_bucket *ib)
11094 {
11195 return read_pnet(&ib->ib_net);
11296 }
11397
114−static inline struct net *ib2_net(struct inet_bind2_bucket *ib)
115−{
116− return read_pnet(&ib->ib_net);
117−}
118−
11998 #define inet_bind_bucket_for_each(tb, head) \
12099 hlist_for_each_entry(tb, head, node)
121100
@@ -124,15 +103,6 @@ struct inet_bind_hashbucket { · 2 unmodified lines
124103 struct hlist_head chain;
125104 };
126105
127−/* This is synchronized using the inet_bind_hashbucket's spinlock.
128− * Instead of having separate spinlocks, the inet_bind2_hashbucket can share
129− * the inet_bind_hashbucket's given that in every case where the bhash2 table
130− * is useful, a lookup in the bhash table also occurs.
131− */
132−struct inet_bind2_hashbucket {
133− struct hlist_head chain;
134−};
135−
136106 /* Sockets can be hashed in established or listening table.
137107 * We must use different 'nulls' end-of-chain value for all hash buckets :
138108 * A socket might transition from ESTABLISH to LISTEN state without
@@ -164,12 +134,6 @@ struct inet_hashinfo { · 25 unmodified lines
164134 */
165135 struct kmem_cache *bind_bucket_cachep;
166136 struct inet_bind_hashbucket *bhash;
167− /* The 2nd binding table hashed by port and address.
168− * This is used primarily for expediting the resolution of bind
169− * conflicts.
170− */
171− struct kmem_cache *bind2_bucket_cachep;
172− struct inet_bind2_hashbucket *bhash2;
173137 unsigned int bhash_size;
174138
175139 /* The 2nd listener table hashed by local port and address */
@@ -229,36 +193,6 @@ inet_bind_bucket_create(struct kmem_cache *cachep, struct net *net, · 53 unmodified lines
229193 void inet_bind_bucket_destroy(struct kmem_cache *cachep,
230194 struct inet_bind_bucket *tb);
231195
232−static inline bool check_bind_bucket_match(struct inet_bind_bucket *tb,
233− struct net *net,
234− const unsigned short port,
235− int l3mdev)
236−{
237− return net_eq(ib_net(tb), net) && tb->port == port &&
238− tb->l3mdev == l3mdev;
239−}
240−
241−struct inet_bind2_bucket *
242−inet_bind2_bucket_create(struct kmem_cache *cachep, struct net *net,
243− struct inet_bind2_hashbucket *head,
244− const unsigned short port, int l3mdev,
245− const struct sock *sk);
246−
247−void inet_bind2_bucket_destroy(struct kmem_cache *cachep,
248− struct inet_bind2_bucket *tb);
249−
250−struct inet_bind2_bucket *
251−inet_bind2_bucket_find(struct inet_hashinfo *hinfo, struct net *net,
252− const unsigned short port, int l3mdev,
253− struct sock *sk,
254− struct inet_bind2_hashbucket **head);
255−
256−bool check_bind2_bucket_match_nulladdr(struct inet_bind2_bucket *tb,
257− struct net *net,
258− const unsigned short port,
259− int l3mdev,
260− const struct sock *sk);
261−
262196 static inline u32 inet_bhashfn(const struct net *net, const __u16 lport,
263197 const u32 bhash_size)
264198 {
@@ -266,7 +200,7 @@ static inline u32 inet_bhashfn(const struct net *net, const __u16 lport, · 1 unmodified line
266200 }
267201
268202 void inet_bind_hash(struct sock *sk, struct inet_bind_bucket *tb,
269− struct inet_bind2_bucket *tb2, const unsigned short snum);
203+ const unsigned short snum);
270204
271205 /* Caller must disable local BH processing. */
272206 int __inet_inherit_port(const struct sock *sk, struct sock *child);
include/net/sock.h+0−14
@@ -348,7 +348,6 @@ struct sk_filter; · 347 unmodified lines
348348 * @sk_txtime_report_errors: set report errors mode for SO_TXTIME
349349 * @sk_txtime_unused: unused txtime flags
350350 * @ns_tracker: tracker for netns reference
351− * @sk_bind2_node: bind node in the bhash2 table
352351 */
353352 struct sock {
354353 /*
@@ -538,7 +537,6 @@ struct sock { · 183 unmodified lines
538537 #endif
539538 struct rcu_head sk_rcu;
540539 netns_tracker ns_tracker;
541− struct hlist_node sk_bind2_node;
542540 };
543541
544542 enum sk_pacing {
@@ -819,16 +817,6 @@ static inline void sk_add_bind_node(struct sock *sk, · 274 unmodified lines
819817 hlist_add_head(&sk->sk_bind_node, list);
820818 }
821819
822−static inline void __sk_del_bind2_node(struct sock *sk)
823−{
824− __hlist_del(&sk->sk_bind2_node);
825−}
826−
827−static inline void sk_add_bind2_node(struct sock *sk, struct hlist_head *list)
828−{
829− hlist_add_head(&sk->sk_bind2_node, list);
830−}
831−
832820 #define sk_for_each(__sk, list) \
833821 hlist_for_each_entry(__sk, list, sk_node)
834822 #define sk_for_each_rcu(__sk, list) \
@@ -846,8 +834,6 @@ static inline void sk_add_bind2_node(struct sock *sk, struct hlist_head *list) · 11 unmodified lines
846834 hlist_for_each_entry_safe(__sk, tmp, list, sk_node)
847835 #define sk_for_each_bound(__sk, list) \
848836 hlist_for_each_entry(__sk, list, sk_bind_node)
849−#define sk_for_each_bound_bhash2(__sk, list) \
850− hlist_for_each_entry(__sk, list, sk_bind2_node)
851837
852838 /**
853839 * sk_for_each_entry_offset_rcu - iterate over a list at a given struct offset