Skip to content

Commit e6934f3

Browse files
committed
Merge branch 'listener-refactoring-preparations'
Eric Dumazet says: ==================== tcp: listener refactoring preparations This patch series makes changes to TCP/DCCP stacks so that we can switch listener code to lockless mode. This is done by marking const the listener socket in all appropriate paths. FastOpen code had to be changed to not dynamically allocate a very small structure to make code simpler for following changes. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4c7e622 + 0536fcc commit e6934f3

24 files changed

+118
-151
lines changed

include/linux/tcp.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -382,25 +382,11 @@ static inline bool tcp_passive_fastopen(const struct sock *sk)
382382
tcp_sk(sk)->fastopen_rsk != NULL);
383383
}
384384

385-
extern void tcp_sock_destruct(struct sock *sk);
386-
387-
static inline int fastopen_init_queue(struct sock *sk, int backlog)
385+
static inline void fastopen_queue_tune(struct sock *sk, int backlog)
388386
{
389-
struct request_sock_queue *queue =
390-
&inet_csk(sk)->icsk_accept_queue;
391-
392-
if (queue->fastopenq == NULL) {
393-
queue->fastopenq = kzalloc(
394-
sizeof(struct fastopen_queue),
395-
sk->sk_allocation);
396-
if (queue->fastopenq == NULL)
397-
return -ENOMEM;
398-
399-
sk->sk_destruct = tcp_sock_destruct;
400-
spin_lock_init(&queue->fastopenq->lock);
401-
}
402-
queue->fastopenq->max_qlen = backlog;
403-
return 0;
387+
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
388+
389+
queue->fastopenq.max_qlen = backlog;
404390
}
405391

406392
static inline void tcp_saved_syn_free(struct tcp_sock *tp)

include/net/inet6_connection_sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int inet6_csk_bind_conflict(const struct sock *sk,
2626
const struct inet_bind_bucket *tb, bool relax);
2727

2828
struct dst_entry *inet6_csk_route_req(const struct sock *sk, struct flowi6 *fl6,
29-
const struct request_sock *req);
29+
const struct request_sock *req, u8 proto);
3030

3131
struct request_sock *inet6_csk_search_req(struct sock *sk,
3232
const __be16 rport,

include/net/inet_connection_sock.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct inet_connection_sock_af_ops {
4141
int (*rebuild_header)(struct sock *sk);
4242
void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
4343
int (*conn_request)(struct sock *sk, struct sk_buff *skb);
44-
struct sock *(*syn_recv_sock)(struct sock *sk, struct sk_buff *skb,
44+
struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
4545
struct request_sock *req,
4646
struct dst_entry *dst);
4747
u16 net_header_len;
@@ -268,7 +268,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum);
268268

269269
struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
270270
const struct request_sock *req);
271-
struct dst_entry *inet_csk_route_child_sock(struct sock *sk, struct sock *newsk,
271+
struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
272+
struct sock *newsk,
272273
const struct request_sock *req);
273274

274275
static inline void inet_csk_reqsk_queue_add(struct sock *sk,

include/net/inet_hashtables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static inline int inet_sk_listen_hashfn(const struct sock *sk)
199199
}
200200

201201
/* Caller must disable local BH processing. */
202-
int __inet_inherit_port(struct sock *sk, struct sock *child);
202+
int __inet_inherit_port(const struct sock *sk, struct sock *child);
203203

204204
void inet_put_port(struct sock *sk);
205205

include/net/request_sock.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct request_sock_ops {
3434
char *slab_name;
3535
int (*rtx_syn_ack)(const struct sock *sk,
3636
struct request_sock *req);
37-
void (*send_ack)(struct sock *sk, struct sk_buff *skb,
37+
void (*send_ack)(const struct sock *sk, struct sk_buff *skb,
3838
struct request_sock *req);
39-
void (*send_reset)(struct sock *sk,
39+
void (*send_reset)(const struct sock *sk,
4040
struct sk_buff *skb);
4141
void (*destructor)(struct request_sock *req);
4242
void (*syn_ack_timeout)(const struct request_sock *req);
@@ -129,9 +129,8 @@ struct listen_sock {
129129
atomic_t qlen_dec; /* qlen = qlen_inc - qlen_dec */
130130
atomic_t young_dec;
131131

132-
u8 max_qlen_log ____cacheline_aligned_in_smp;
133-
u8 synflood_warned;
134-
/* 2 bytes hole, try to use */
132+
u32 max_qlen_log ____cacheline_aligned_in_smp;
133+
u32 synflood_warned;
135134
u32 hash_rnd;
136135
u32 nr_table_entries;
137136
struct request_sock *syn_table[0];
@@ -181,11 +180,8 @@ struct request_sock_queue {
181180
struct request_sock *rskq_accept_tail;
182181
u8 rskq_defer_accept;
183182
struct listen_sock *listen_opt;
184-
struct fastopen_queue *fastopenq; /* This is non-NULL iff TFO has been
185-
* enabled on this listener. Check
186-
* max_qlen != 0 in fastopen_queue
187-
* to determine if TFO is enabled
188-
* right at this moment.
183+
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
184+
* if TFO is enabled.
189185
*/
190186

191187
/* temporary alignment, our goal is to get rid of this lock */

include/net/sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ static inline int sk_memalloc_socks(void)
759759

760760
#endif
761761

762-
static inline gfp_t sk_gfp_atomic(struct sock *sk, gfp_t gfp_mask)
762+
static inline gfp_t sk_gfp_atomic(const struct sock *sk, gfp_t gfp_mask)
763763
{
764764
return GFP_ATOMIC | (sk->sk_allocation & __GFP_MEMALLOC);
765765
}

include/net/tcp.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ void tcp_wfree(struct sk_buff *skb);
365365
void tcp_write_timer_handler(struct sock *sk);
366366
void tcp_delack_timer_handler(struct sock *sk);
367367
int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg);
368-
int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
369-
const struct tcphdr *th, unsigned int len);
368+
int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb);
370369
void tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
371370
const struct tcphdr *th, unsigned int len);
372371
void tcp_rcv_space_adjust(struct sock *sk);
@@ -451,11 +450,11 @@ void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb);
451450
void tcp_v4_mtu_reduced(struct sock *sk);
452451
void tcp_req_err(struct sock *sk, u32 seq);
453452
int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb);
454-
struct sock *tcp_create_openreq_child(struct sock *sk,
453+
struct sock *tcp_create_openreq_child(const struct sock *sk,
455454
struct request_sock *req,
456455
struct sk_buff *skb);
457456
void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst);
458-
struct sock *tcp_v4_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
457+
struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
459458
struct request_sock *req,
460459
struct dst_entry *dst);
461460
int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
@@ -492,8 +491,9 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb);
492491

493492
/* syncookies: remember time of last synqueue overflow
494493
* But do not dirty this field too often (once per second is enough)
494+
* It is racy as we do not hold a lock, but race is very minor.
495495
*/
496-
static inline void tcp_synq_overflow(struct sock *sk)
496+
static inline void tcp_synq_overflow(const struct sock *sk)
497497
{
498498
unsigned long last_overflow = tcp_sk(sk)->rx_opt.ts_recent_stamp;
499499
unsigned long now = jiffies;
@@ -520,8 +520,7 @@ static inline u32 tcp_cookie_time(void)
520520

521521
u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
522522
u16 *mssp);
523-
__u32 cookie_v4_init_sequence(struct sock *sk, const struct sk_buff *skb,
524-
__u16 *mss);
523+
__u32 cookie_v4_init_sequence(const struct sk_buff *skb, __u16 *mss);
525524
__u32 cookie_init_timestamp(struct request_sock *req);
526525
bool cookie_timestamp_decode(struct tcp_options_received *opt);
527526
bool cookie_ecn_ok(const struct tcp_options_received *opt,
@@ -534,8 +533,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb);
534533

535534
u32 __cookie_v6_init_sequence(const struct ipv6hdr *iph,
536535
const struct tcphdr *th, u16 *mssp);
537-
__u32 cookie_v6_init_sequence(struct sock *sk, const struct sk_buff *skb,
538-
__u16 *mss);
536+
__u32 cookie_v6_init_sequence(const struct sk_buff *skb, __u16 *mss);
539537
#endif
540538
/* tcp_output.c */
541539

@@ -1710,10 +1708,10 @@ struct tcp_request_sock_ops {
17101708
const struct sock *sk_listener,
17111709
struct sk_buff *skb);
17121710
#ifdef CONFIG_SYN_COOKIES
1713-
__u32 (*cookie_init_seq)(struct sock *sk, const struct sk_buff *skb,
1711+
__u32 (*cookie_init_seq)(const struct sk_buff *skb,
17141712
__u16 *mss);
17151713
#endif
1716-
struct dst_entry *(*route_req)(struct sock *sk, struct flowi *fl,
1714+
struct dst_entry *(*route_req)(const struct sock *sk, struct flowi *fl,
17171715
const struct request_sock *req,
17181716
bool *strict);
17191717
__u32 (*init_seq)(const struct sk_buff *skb);
@@ -1726,14 +1724,16 @@ struct tcp_request_sock_ops {
17261724

17271725
#ifdef CONFIG_SYN_COOKIES
17281726
static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops,
1729-
struct sock *sk, struct sk_buff *skb,
1727+
const struct sock *sk, struct sk_buff *skb,
17301728
__u16 *mss)
17311729
{
1732-
return ops->cookie_init_seq(sk, skb, mss);
1730+
tcp_synq_overflow(sk);
1731+
NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
1732+
return ops->cookie_init_seq(skb, mss);
17331733
}
17341734
#else
17351735
static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops,
1736-
struct sock *sk, struct sk_buff *skb,
1736+
const struct sock *sk, struct sk_buff *skb,
17371737
__u16 *mss)
17381738
{
17391739
return 0;

net/core/request_sock.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ int reqsk_queue_alloc(struct request_sock_queue *queue,
5959

6060
get_random_bytes(&lopt->hash_rnd, sizeof(lopt->hash_rnd));
6161
spin_lock_init(&queue->syn_wait_lock);
62+
63+
spin_lock_init(&queue->fastopenq.lock);
64+
queue->fastopenq.rskq_rst_head = NULL;
65+
queue->fastopenq.rskq_rst_tail = NULL;
66+
queue->fastopenq.qlen = 0;
67+
queue->fastopenq.max_qlen = 0;
68+
6269
queue->rskq_accept_head = NULL;
6370
lopt->nr_table_entries = nr_table_entries;
6471
lopt->max_qlen_log = ilog2(nr_table_entries);
@@ -174,7 +181,7 @@ void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
174181
struct sock *lsk = req->rsk_listener;
175182
struct fastopen_queue *fastopenq;
176183

177-
fastopenq = inet_csk(lsk)->icsk_accept_queue.fastopenq;
184+
fastopenq = &inet_csk(lsk)->icsk_accept_queue.fastopenq;
178185

179186
tcp_sk(sk)->fastopen_rsk = NULL;
180187
spin_lock_bh(&fastopenq->lock);

net/dccp/dccp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void dccp_v4_send_check(struct sock *sk, struct sk_buff *skb);
229229
int dccp_retransmit_skb(struct sock *sk);
230230

231231
void dccp_send_ack(struct sock *sk);
232-
void dccp_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
232+
void dccp_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
233233
struct request_sock *rsk);
234234

235235
void dccp_send_sync(struct sock *sk, const u64 seq,
@@ -270,13 +270,13 @@ int dccp_reqsk_init(struct request_sock *rq, struct dccp_sock const *dp,
270270

271271
int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb);
272272

273-
struct sock *dccp_create_openreq_child(struct sock *sk,
273+
struct sock *dccp_create_openreq_child(const struct sock *sk,
274274
const struct request_sock *req,
275275
const struct sk_buff *skb);
276276

277277
int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
278278

279-
struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
279+
struct sock *dccp_v4_request_recv_sock(const struct sock *sk, struct sk_buff *skb,
280280
struct request_sock *req,
281281
struct dst_entry *dst);
282282
struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,

net/dccp/ipv4.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ static inline u64 dccp_v4_init_sequence(const struct sk_buff *skb)
390390
*
391391
* This is the equivalent of TCP's tcp_v4_syn_recv_sock
392392
*/
393-
struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb,
393+
struct sock *dccp_v4_request_recv_sock(const struct sock *sk,
394+
struct sk_buff *skb,
394395
struct request_sock *req,
395396
struct dst_entry *dst)
396397
{
@@ -527,7 +528,7 @@ static int dccp_v4_send_response(const struct sock *sk, struct request_sock *req
527528
return err;
528529
}
529530

530-
static void dccp_v4_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
531+
static void dccp_v4_ctl_send_reset(const struct sock *sk, struct sk_buff *rxskb)
531532
{
532533
int err;
533534
const struct iphdr *rxiph;

0 commit comments

Comments
 (0)