~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/rds/tcp.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/rds/tcp.c (Architecture m68k) and /net/rds/tcp.c (Architecture mips)


  1 /*                                                  1 /*
  2  * Copyright (c) 2006, 2018 Oracle and/or its       2  * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
  3  *                                                  3  *
  4  * This software is available to you under a c      4  * This software is available to you under a choice of one of two
  5  * licenses.  You may choose to be licensed un      5  * licenses.  You may choose to be licensed under the terms of the GNU
  6  * General Public License (GPL) Version 2, ava      6  * General Public License (GPL) Version 2, available from the file
  7  * COPYING in the main directory of this sourc      7  * COPYING in the main directory of this source tree, or the
  8  * OpenIB.org BSD license below:                    8  * OpenIB.org BSD license below:
  9  *                                                  9  *
 10  *     Redistribution and use in source and bi     10  *     Redistribution and use in source and binary forms, with or
 11  *     without modification, are permitted pro     11  *     without modification, are permitted provided that the following
 12  *     conditions are met:                         12  *     conditions are met:
 13  *                                                 13  *
 14  *      - Redistributions of source code must      14  *      - Redistributions of source code must retain the above
 15  *        copyright notice, this list of condi     15  *        copyright notice, this list of conditions and the following
 16  *        disclaimer.                              16  *        disclaimer.
 17  *                                                 17  *
 18  *      - Redistributions in binary form must      18  *      - Redistributions in binary form must reproduce the above
 19  *        copyright notice, this list of condi     19  *        copyright notice, this list of conditions and the following
 20  *        disclaimer in the documentation and/     20  *        disclaimer in the documentation and/or other materials
 21  *        provided with the distribution.          21  *        provided with the distribution.
 22  *                                                 22  *
 23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT W     23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMIT     24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR P     25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTH     26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER L     27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARIS     28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 29  * CONNECTION WITH THE SOFTWARE OR THE USE OR      29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 30  * SOFTWARE.                                       30  * SOFTWARE.
 31  *                                                 31  *
 32  */                                                32  */
 33 #include <linux/kernel.h>                          33 #include <linux/kernel.h>
 34 #include <linux/slab.h>                            34 #include <linux/slab.h>
 35 #include <linux/in.h>                              35 #include <linux/in.h>
 36 #include <linux/module.h>                          36 #include <linux/module.h>
 37 #include <net/tcp.h>                               37 #include <net/tcp.h>
 38 #include <net/net_namespace.h>                     38 #include <net/net_namespace.h>
 39 #include <net/netns/generic.h>                     39 #include <net/netns/generic.h>
 40 #include <net/addrconf.h>                          40 #include <net/addrconf.h>
 41                                                    41 
 42 #include "rds.h"                                   42 #include "rds.h"
 43 #include "tcp.h"                                   43 #include "tcp.h"
 44                                                    44 
 45 /* only for info exporting */                      45 /* only for info exporting */
 46 static DEFINE_SPINLOCK(rds_tcp_tc_list_lock);      46 static DEFINE_SPINLOCK(rds_tcp_tc_list_lock);
 47 static LIST_HEAD(rds_tcp_tc_list);                 47 static LIST_HEAD(rds_tcp_tc_list);
 48                                                    48 
 49 /* rds_tcp_tc_count counts only IPv4 connectio     49 /* rds_tcp_tc_count counts only IPv4 connections.
 50  * rds6_tcp_tc_count counts both IPv4 and IPv6     50  * rds6_tcp_tc_count counts both IPv4 and IPv6 connections.
 51  */                                                51  */
 52 static unsigned int rds_tcp_tc_count;              52 static unsigned int rds_tcp_tc_count;
 53 #if IS_ENABLED(CONFIG_IPV6)                        53 #if IS_ENABLED(CONFIG_IPV6)
 54 static unsigned int rds6_tcp_tc_count;             54 static unsigned int rds6_tcp_tc_count;
 55 #endif                                             55 #endif
 56                                                    56 
 57 /* Track rds_tcp_connection structs so they ca     57 /* Track rds_tcp_connection structs so they can be cleaned up */
 58 static DEFINE_SPINLOCK(rds_tcp_conn_lock);         58 static DEFINE_SPINLOCK(rds_tcp_conn_lock);
 59 static LIST_HEAD(rds_tcp_conn_list);               59 static LIST_HEAD(rds_tcp_conn_list);
 60 static atomic_t rds_tcp_unloading = ATOMIC_INI     60 static atomic_t rds_tcp_unloading = ATOMIC_INIT(0);
 61                                                    61 
 62 static struct kmem_cache *rds_tcp_conn_slab;       62 static struct kmem_cache *rds_tcp_conn_slab;
 63                                                    63 
 64 static int rds_tcp_skbuf_handler(const struct      64 static int rds_tcp_skbuf_handler(const struct ctl_table *ctl, int write,
 65                                  void *buffer,     65                                  void *buffer, size_t *lenp, loff_t *fpos);
 66                                                    66 
 67 static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBU     67 static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBUF;
 68 static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBU     68 static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBUF;
 69                                                    69 
 70 static struct ctl_table rds_tcp_sysctl_table[]     70 static struct ctl_table rds_tcp_sysctl_table[] = {
 71 #define RDS_TCP_SNDBUF  0                          71 #define RDS_TCP_SNDBUF  0
 72         {                                          72         {
 73                 .procname       = "rds_tcp_snd     73                 .procname       = "rds_tcp_sndbuf",
 74                 /* data is per-net pointer */      74                 /* data is per-net pointer */
 75                 .maxlen         = sizeof(int),     75                 .maxlen         = sizeof(int),
 76                 .mode           = 0644,            76                 .mode           = 0644,
 77                 .proc_handler   = rds_tcp_skbu     77                 .proc_handler   = rds_tcp_skbuf_handler,
 78                 .extra1         = &rds_tcp_min     78                 .extra1         = &rds_tcp_min_sndbuf,
 79         },                                         79         },
 80 #define RDS_TCP_RCVBUF  1                          80 #define RDS_TCP_RCVBUF  1
 81         {                                          81         {
 82                 .procname       = "rds_tcp_rcv     82                 .procname       = "rds_tcp_rcvbuf",
 83                 /* data is per-net pointer */      83                 /* data is per-net pointer */
 84                 .maxlen         = sizeof(int),     84                 .maxlen         = sizeof(int),
 85                 .mode           = 0644,            85                 .mode           = 0644,
 86                 .proc_handler   = rds_tcp_skbu     86                 .proc_handler   = rds_tcp_skbuf_handler,
 87                 .extra1         = &rds_tcp_min     87                 .extra1         = &rds_tcp_min_rcvbuf,
 88         },                                         88         },
 89 };                                                 89 };
 90                                                    90 
 91 u32 rds_tcp_write_seq(struct rds_tcp_connectio     91 u32 rds_tcp_write_seq(struct rds_tcp_connection *tc)
 92 {                                                  92 {
 93         /* seq# of the last byte of data in tc     93         /* seq# of the last byte of data in tcp send buffer */
 94         return tcp_sk(tc->t_sock->sk)->write_s     94         return tcp_sk(tc->t_sock->sk)->write_seq;
 95 }                                                  95 }
 96                                                    96 
 97 u32 rds_tcp_snd_una(struct rds_tcp_connection      97 u32 rds_tcp_snd_una(struct rds_tcp_connection *tc)
 98 {                                                  98 {
 99         return tcp_sk(tc->t_sock->sk)->snd_una     99         return tcp_sk(tc->t_sock->sk)->snd_una;
100 }                                                 100 }
101                                                   101 
102 void rds_tcp_restore_callbacks(struct socket *    102 void rds_tcp_restore_callbacks(struct socket *sock,
103                                struct rds_tcp_    103                                struct rds_tcp_connection *tc)
104 {                                                 104 {
105         rdsdebug("restoring sock %p callbacks     105         rdsdebug("restoring sock %p callbacks from tc %p\n", sock, tc);
106         write_lock_bh(&sock->sk->sk_callback_l    106         write_lock_bh(&sock->sk->sk_callback_lock);
107                                                   107 
108         /* done under the callback_lock to ser    108         /* done under the callback_lock to serialize with write_space */
109         spin_lock(&rds_tcp_tc_list_lock);         109         spin_lock(&rds_tcp_tc_list_lock);
110         list_del_init(&tc->t_list_item);          110         list_del_init(&tc->t_list_item);
111 #if IS_ENABLED(CONFIG_IPV6)                       111 #if IS_ENABLED(CONFIG_IPV6)
112         rds6_tcp_tc_count--;                      112         rds6_tcp_tc_count--;
113 #endif                                            113 #endif
114         if (!tc->t_cpath->cp_conn->c_isv6)        114         if (!tc->t_cpath->cp_conn->c_isv6)
115                 rds_tcp_tc_count--;               115                 rds_tcp_tc_count--;
116         spin_unlock(&rds_tcp_tc_list_lock);       116         spin_unlock(&rds_tcp_tc_list_lock);
117                                                   117 
118         tc->t_sock = NULL;                        118         tc->t_sock = NULL;
119                                                   119 
120         sock->sk->sk_write_space = tc->t_orig_    120         sock->sk->sk_write_space = tc->t_orig_write_space;
121         sock->sk->sk_data_ready = tc->t_orig_d    121         sock->sk->sk_data_ready = tc->t_orig_data_ready;
122         sock->sk->sk_state_change = tc->t_orig    122         sock->sk->sk_state_change = tc->t_orig_state_change;
123         sock->sk->sk_user_data = NULL;            123         sock->sk->sk_user_data = NULL;
124                                                   124 
125         write_unlock_bh(&sock->sk->sk_callback    125         write_unlock_bh(&sock->sk->sk_callback_lock);
126 }                                                 126 }
127                                                   127 
128 /*                                                128 /*
129  * rds_tcp_reset_callbacks() switches the to t    129  * rds_tcp_reset_callbacks() switches the to the new sock and
130  * returns the existing tc->t_sock.               130  * returns the existing tc->t_sock.
131  *                                                131  *
132  * The only functions that set tc->t_sock are     132  * The only functions that set tc->t_sock are rds_tcp_set_callbacks
133  * and rds_tcp_reset_callbacks.  Send and rece    133  * and rds_tcp_reset_callbacks.  Send and receive trust that
134  * it is set.  The absence of RDS_CONN_UP bit     134  * it is set.  The absence of RDS_CONN_UP bit protects those paths
135  * from being called while it isn't set.          135  * from being called while it isn't set.
136  */                                               136  */
137 void rds_tcp_reset_callbacks(struct socket *so    137 void rds_tcp_reset_callbacks(struct socket *sock,
138                              struct rds_conn_p    138                              struct rds_conn_path *cp)
139 {                                                 139 {
140         struct rds_tcp_connection *tc = cp->cp    140         struct rds_tcp_connection *tc = cp->cp_transport_data;
141         struct socket *osock = tc->t_sock;        141         struct socket *osock = tc->t_sock;
142                                                   142 
143         if (!osock)                               143         if (!osock)
144                 goto newsock;                     144                 goto newsock;
145                                                   145 
146         /* Need to resolve a duelling SYN betw    146         /* Need to resolve a duelling SYN between peers.
147          * We have an outstanding SYN to this     147          * We have an outstanding SYN to this peer, which may
148          * potentially have transitioned to th    148          * potentially have transitioned to the RDS_CONN_UP state,
149          * so we must quiesce any send threads    149          * so we must quiesce any send threads before resetting
150          * cp_transport_data. We quiesce these    150          * cp_transport_data. We quiesce these threads by setting
151          * cp_state to something other than RD    151          * cp_state to something other than RDS_CONN_UP, and then
152          * waiting for any existing threads in    152          * waiting for any existing threads in rds_send_xmit to
153          * complete release_in_xmit(). (Subseq    153          * complete release_in_xmit(). (Subsequent threads entering
154          * rds_send_xmit() will bail on !rds_c    154          * rds_send_xmit() will bail on !rds_conn_up().
155          *                                        155          *
156          * However an incoming syn-ack at this    156          * However an incoming syn-ack at this point would end up
157          * marking the conn as RDS_CONN_UP, an    157          * marking the conn as RDS_CONN_UP, and would again permit
158          * rds_send_xmi() threads through, so     158          * rds_send_xmi() threads through, so ideally we would
159          * synchronize on RDS_CONN_UP after lo    159          * synchronize on RDS_CONN_UP after lock_sock(), but cannot
160          * do that: waiting on !RDS_IN_XMIT af    160          * do that: waiting on !RDS_IN_XMIT after lock_sock() may
161          * end up deadlocking with tcp_sendmsg    161          * end up deadlocking with tcp_sendmsg(), and the RDS_IN_XMIT
162          * would not get set. As a result, we     162          * would not get set. As a result, we set c_state to
163          * RDS_CONN_RESETTTING, to ensure that    163          * RDS_CONN_RESETTTING, to ensure that rds_tcp_state_change
164          * cannot mark rds_conn_path_up() in t    164          * cannot mark rds_conn_path_up() in the window before lock_sock()
165          */                                       165          */
166         atomic_set(&cp->cp_state, RDS_CONN_RES    166         atomic_set(&cp->cp_state, RDS_CONN_RESETTING);
167         wait_event(cp->cp_waitq, !test_bit(RDS    167         wait_event(cp->cp_waitq, !test_bit(RDS_IN_XMIT, &cp->cp_flags));
168         /* reset receive side state for rds_tc    168         /* reset receive side state for rds_tcp_data_recv() for osock  */
169         cancel_delayed_work_sync(&cp->cp_send_    169         cancel_delayed_work_sync(&cp->cp_send_w);
170         cancel_delayed_work_sync(&cp->cp_recv_    170         cancel_delayed_work_sync(&cp->cp_recv_w);
171         lock_sock(osock->sk);                     171         lock_sock(osock->sk);
172         if (tc->t_tinc) {                         172         if (tc->t_tinc) {
173                 rds_inc_put(&tc->t_tinc->ti_in    173                 rds_inc_put(&tc->t_tinc->ti_inc);
174                 tc->t_tinc = NULL;                174                 tc->t_tinc = NULL;
175         }                                         175         }
176         tc->t_tinc_hdr_rem = sizeof(struct rds    176         tc->t_tinc_hdr_rem = sizeof(struct rds_header);
177         tc->t_tinc_data_rem = 0;                  177         tc->t_tinc_data_rem = 0;
178         rds_tcp_restore_callbacks(osock, tc);     178         rds_tcp_restore_callbacks(osock, tc);
179         release_sock(osock->sk);                  179         release_sock(osock->sk);
180         sock_release(osock);                      180         sock_release(osock);
181 newsock:                                          181 newsock:
182         rds_send_path_reset(cp);                  182         rds_send_path_reset(cp);
183         lock_sock(sock->sk);                      183         lock_sock(sock->sk);
184         rds_tcp_set_callbacks(sock, cp);          184         rds_tcp_set_callbacks(sock, cp);
185         release_sock(sock->sk);                   185         release_sock(sock->sk);
186 }                                                 186 }
187                                                   187 
188 /* Add tc to rds_tcp_tc_list and set tc->t_soc    188 /* Add tc to rds_tcp_tc_list and set tc->t_sock. See comments
189  * above rds_tcp_reset_callbacks for notes abo    189  * above rds_tcp_reset_callbacks for notes about synchronization
190  * with data path                                 190  * with data path
191  */                                               191  */
192 void rds_tcp_set_callbacks(struct socket *sock    192 void rds_tcp_set_callbacks(struct socket *sock, struct rds_conn_path *cp)
193 {                                                 193 {
194         struct rds_tcp_connection *tc = cp->cp    194         struct rds_tcp_connection *tc = cp->cp_transport_data;
195                                                   195 
196         rdsdebug("setting sock %p callbacks to    196         rdsdebug("setting sock %p callbacks to tc %p\n", sock, tc);
197         write_lock_bh(&sock->sk->sk_callback_l    197         write_lock_bh(&sock->sk->sk_callback_lock);
198                                                   198 
199         /* done under the callback_lock to ser    199         /* done under the callback_lock to serialize with write_space */
200         spin_lock(&rds_tcp_tc_list_lock);         200         spin_lock(&rds_tcp_tc_list_lock);
201         list_add_tail(&tc->t_list_item, &rds_t    201         list_add_tail(&tc->t_list_item, &rds_tcp_tc_list);
202 #if IS_ENABLED(CONFIG_IPV6)                       202 #if IS_ENABLED(CONFIG_IPV6)
203         rds6_tcp_tc_count++;                      203         rds6_tcp_tc_count++;
204 #endif                                            204 #endif
205         if (!tc->t_cpath->cp_conn->c_isv6)        205         if (!tc->t_cpath->cp_conn->c_isv6)
206                 rds_tcp_tc_count++;               206                 rds_tcp_tc_count++;
207         spin_unlock(&rds_tcp_tc_list_lock);       207         spin_unlock(&rds_tcp_tc_list_lock);
208                                                   208 
209         /* accepted sockets need our listen da    209         /* accepted sockets need our listen data ready undone */
210         if (sock->sk->sk_data_ready == rds_tcp    210         if (sock->sk->sk_data_ready == rds_tcp_listen_data_ready)
211                 sock->sk->sk_data_ready = sock    211                 sock->sk->sk_data_ready = sock->sk->sk_user_data;
212                                                   212 
213         tc->t_sock = sock;                        213         tc->t_sock = sock;
214         tc->t_cpath = cp;                         214         tc->t_cpath = cp;
215         tc->t_orig_data_ready = sock->sk->sk_d    215         tc->t_orig_data_ready = sock->sk->sk_data_ready;
216         tc->t_orig_write_space = sock->sk->sk_    216         tc->t_orig_write_space = sock->sk->sk_write_space;
217         tc->t_orig_state_change = sock->sk->sk    217         tc->t_orig_state_change = sock->sk->sk_state_change;
218                                                   218 
219         sock->sk->sk_user_data = cp;              219         sock->sk->sk_user_data = cp;
220         sock->sk->sk_data_ready = rds_tcp_data    220         sock->sk->sk_data_ready = rds_tcp_data_ready;
221         sock->sk->sk_write_space = rds_tcp_wri    221         sock->sk->sk_write_space = rds_tcp_write_space;
222         sock->sk->sk_state_change = rds_tcp_st    222         sock->sk->sk_state_change = rds_tcp_state_change;
223                                                   223 
224         write_unlock_bh(&sock->sk->sk_callback    224         write_unlock_bh(&sock->sk->sk_callback_lock);
225 }                                                 225 }
226                                                   226 
227 /* Handle RDS_INFO_TCP_SOCKETS socket option.     227 /* Handle RDS_INFO_TCP_SOCKETS socket option.  It only returns IPv4
228  * connections for backward compatibility.        228  * connections for backward compatibility.
229  */                                               229  */
230 static void rds_tcp_tc_info(struct socket *rds    230 static void rds_tcp_tc_info(struct socket *rds_sock, unsigned int len,
231                             struct rds_info_it    231                             struct rds_info_iterator *iter,
232                             struct rds_info_le    232                             struct rds_info_lengths *lens)
233 {                                                 233 {
234         struct rds_info_tcp_socket tsinfo;        234         struct rds_info_tcp_socket tsinfo;
235         struct rds_tcp_connection *tc;            235         struct rds_tcp_connection *tc;
236         unsigned long flags;                      236         unsigned long flags;
237                                                   237 
238         spin_lock_irqsave(&rds_tcp_tc_list_loc    238         spin_lock_irqsave(&rds_tcp_tc_list_lock, flags);
239                                                   239 
240         if (len / sizeof(tsinfo) < rds_tcp_tc_    240         if (len / sizeof(tsinfo) < rds_tcp_tc_count)
241                 goto out;                         241                 goto out;
242                                                   242 
243         list_for_each_entry(tc, &rds_tcp_tc_li    243         list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) {
244                 struct inet_sock *inet = inet_    244                 struct inet_sock *inet = inet_sk(tc->t_sock->sk);
245                                                   245 
246                 if (tc->t_cpath->cp_conn->c_is    246                 if (tc->t_cpath->cp_conn->c_isv6)
247                         continue;                 247                         continue;
248                                                   248 
249                 tsinfo.local_addr = inet->inet    249                 tsinfo.local_addr = inet->inet_saddr;
250                 tsinfo.local_port = inet->inet    250                 tsinfo.local_port = inet->inet_sport;
251                 tsinfo.peer_addr = inet->inet_    251                 tsinfo.peer_addr = inet->inet_daddr;
252                 tsinfo.peer_port = inet->inet_    252                 tsinfo.peer_port = inet->inet_dport;
253                                                   253 
254                 tsinfo.hdr_rem = tc->t_tinc_hd    254                 tsinfo.hdr_rem = tc->t_tinc_hdr_rem;
255                 tsinfo.data_rem = tc->t_tinc_d    255                 tsinfo.data_rem = tc->t_tinc_data_rem;
256                 tsinfo.last_sent_nxt = tc->t_l    256                 tsinfo.last_sent_nxt = tc->t_last_sent_nxt;
257                 tsinfo.last_expected_una = tc-    257                 tsinfo.last_expected_una = tc->t_last_expected_una;
258                 tsinfo.last_seen_una = tc->t_l    258                 tsinfo.last_seen_una = tc->t_last_seen_una;
259                 tsinfo.tos = tc->t_cpath->cp_c    259                 tsinfo.tos = tc->t_cpath->cp_conn->c_tos;
260                                                   260 
261                 rds_info_copy(iter, &tsinfo, s    261                 rds_info_copy(iter, &tsinfo, sizeof(tsinfo));
262         }                                         262         }
263                                                   263 
264 out:                                              264 out:
265         lens->nr = rds_tcp_tc_count;              265         lens->nr = rds_tcp_tc_count;
266         lens->each = sizeof(tsinfo);              266         lens->each = sizeof(tsinfo);
267                                                   267 
268         spin_unlock_irqrestore(&rds_tcp_tc_lis    268         spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags);
269 }                                                 269 }
270                                                   270 
271 #if IS_ENABLED(CONFIG_IPV6)                       271 #if IS_ENABLED(CONFIG_IPV6)
272 /* Handle RDS6_INFO_TCP_SOCKETS socket option.    272 /* Handle RDS6_INFO_TCP_SOCKETS socket option. It returns both IPv4 and
273  * IPv6 connections. IPv4 connection address i    273  * IPv6 connections. IPv4 connection address is returned in an IPv4 mapped
274  * address.                                       274  * address.
275  */                                               275  */
276 static void rds6_tcp_tc_info(struct socket *so    276 static void rds6_tcp_tc_info(struct socket *sock, unsigned int len,
277                              struct rds_info_i    277                              struct rds_info_iterator *iter,
278                              struct rds_info_l    278                              struct rds_info_lengths *lens)
279 {                                                 279 {
280         struct rds6_info_tcp_socket tsinfo6;      280         struct rds6_info_tcp_socket tsinfo6;
281         struct rds_tcp_connection *tc;            281         struct rds_tcp_connection *tc;
282         unsigned long flags;                      282         unsigned long flags;
283                                                   283 
284         spin_lock_irqsave(&rds_tcp_tc_list_loc    284         spin_lock_irqsave(&rds_tcp_tc_list_lock, flags);
285                                                   285 
286         if (len / sizeof(tsinfo6) < rds6_tcp_t    286         if (len / sizeof(tsinfo6) < rds6_tcp_tc_count)
287                 goto out;                         287                 goto out;
288                                                   288 
289         list_for_each_entry(tc, &rds_tcp_tc_li    289         list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) {
290                 struct sock *sk = tc->t_sock->    290                 struct sock *sk = tc->t_sock->sk;
291                 struct inet_sock *inet = inet_    291                 struct inet_sock *inet = inet_sk(sk);
292                                                   292 
293                 tsinfo6.local_addr = sk->sk_v6    293                 tsinfo6.local_addr = sk->sk_v6_rcv_saddr;
294                 tsinfo6.local_port = inet->ine    294                 tsinfo6.local_port = inet->inet_sport;
295                 tsinfo6.peer_addr = sk->sk_v6_    295                 tsinfo6.peer_addr = sk->sk_v6_daddr;
296                 tsinfo6.peer_port = inet->inet    296                 tsinfo6.peer_port = inet->inet_dport;
297                                                   297 
298                 tsinfo6.hdr_rem = tc->t_tinc_h    298                 tsinfo6.hdr_rem = tc->t_tinc_hdr_rem;
299                 tsinfo6.data_rem = tc->t_tinc_    299                 tsinfo6.data_rem = tc->t_tinc_data_rem;
300                 tsinfo6.last_sent_nxt = tc->t_    300                 tsinfo6.last_sent_nxt = tc->t_last_sent_nxt;
301                 tsinfo6.last_expected_una = tc    301                 tsinfo6.last_expected_una = tc->t_last_expected_una;
302                 tsinfo6.last_seen_una = tc->t_    302                 tsinfo6.last_seen_una = tc->t_last_seen_una;
303                                                   303 
304                 rds_info_copy(iter, &tsinfo6,     304                 rds_info_copy(iter, &tsinfo6, sizeof(tsinfo6));
305         }                                         305         }
306                                                   306 
307 out:                                              307 out:
308         lens->nr = rds6_tcp_tc_count;             308         lens->nr = rds6_tcp_tc_count;
309         lens->each = sizeof(tsinfo6);             309         lens->each = sizeof(tsinfo6);
310                                                   310 
311         spin_unlock_irqrestore(&rds_tcp_tc_lis    311         spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags);
312 }                                                 312 }
313 #endif                                            313 #endif
314                                                   314 
315 int rds_tcp_laddr_check(struct net *net, const    315 int rds_tcp_laddr_check(struct net *net, const struct in6_addr *addr,
316                         __u32 scope_id)           316                         __u32 scope_id)
317 {                                                 317 {
318         struct net_device *dev = NULL;            318         struct net_device *dev = NULL;
319 #if IS_ENABLED(CONFIG_IPV6)                       319 #if IS_ENABLED(CONFIG_IPV6)
320         int ret;                                  320         int ret;
321 #endif                                            321 #endif
322                                                   322 
323         if (ipv6_addr_v4mapped(addr)) {           323         if (ipv6_addr_v4mapped(addr)) {
324                 if (inet_addr_type(net, addr->    324                 if (inet_addr_type(net, addr->s6_addr32[3]) == RTN_LOCAL)
325                         return 0;                 325                         return 0;
326                 return -EADDRNOTAVAIL;            326                 return -EADDRNOTAVAIL;
327         }                                         327         }
328                                                   328 
329         /* If the scope_id is specified, check    329         /* If the scope_id is specified, check only those addresses
330          * hosted on the specified interface.     330          * hosted on the specified interface.
331          */                                       331          */
332         if (scope_id != 0) {                      332         if (scope_id != 0) {
333                 rcu_read_lock();                  333                 rcu_read_lock();
334                 dev = dev_get_by_index_rcu(net    334                 dev = dev_get_by_index_rcu(net, scope_id);
335                 /* scope_id is not valid... */    335                 /* scope_id is not valid... */
336                 if (!dev) {                       336                 if (!dev) {
337                         rcu_read_unlock();        337                         rcu_read_unlock();
338                         return -EADDRNOTAVAIL;    338                         return -EADDRNOTAVAIL;
339                 }                                 339                 }
340                 rcu_read_unlock();                340                 rcu_read_unlock();
341         }                                         341         }
342 #if IS_ENABLED(CONFIG_IPV6)                       342 #if IS_ENABLED(CONFIG_IPV6)
343         ret = ipv6_chk_addr(net, addr, dev, 0)    343         ret = ipv6_chk_addr(net, addr, dev, 0);
344         if (ret)                                  344         if (ret)
345                 return 0;                         345                 return 0;
346 #endif                                            346 #endif
347         return -EADDRNOTAVAIL;                    347         return -EADDRNOTAVAIL;
348 }                                                 348 }
349                                                   349 
350 static void rds_tcp_conn_free(void *arg)          350 static void rds_tcp_conn_free(void *arg)
351 {                                                 351 {
352         struct rds_tcp_connection *tc = arg;      352         struct rds_tcp_connection *tc = arg;
353         unsigned long flags;                      353         unsigned long flags;
354                                                   354 
355         rdsdebug("freeing tc %p\n", tc);          355         rdsdebug("freeing tc %p\n", tc);
356                                                   356 
357         spin_lock_irqsave(&rds_tcp_conn_lock,     357         spin_lock_irqsave(&rds_tcp_conn_lock, flags);
358         if (!tc->t_tcp_node_detached)             358         if (!tc->t_tcp_node_detached)
359                 list_del(&tc->t_tcp_node);        359                 list_del(&tc->t_tcp_node);
360         spin_unlock_irqrestore(&rds_tcp_conn_l    360         spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
361                                                   361 
362         kmem_cache_free(rds_tcp_conn_slab, tc)    362         kmem_cache_free(rds_tcp_conn_slab, tc);
363 }                                                 363 }
364                                                   364 
365 static int rds_tcp_conn_alloc(struct rds_conne    365 static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
366 {                                                 366 {
367         struct rds_tcp_connection *tc;            367         struct rds_tcp_connection *tc;
368         int i, j;                                 368         int i, j;
369         int ret = 0;                              369         int ret = 0;
370                                                   370 
371         for (i = 0; i < RDS_MPATH_WORKERS; i++    371         for (i = 0; i < RDS_MPATH_WORKERS; i++) {
372                 tc = kmem_cache_alloc(rds_tcp_    372                 tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
373                 if (!tc) {                        373                 if (!tc) {
374                         ret = -ENOMEM;            374                         ret = -ENOMEM;
375                         goto fail;                375                         goto fail;
376                 }                                 376                 }
377                 mutex_init(&tc->t_conn_path_lo    377                 mutex_init(&tc->t_conn_path_lock);
378                 tc->t_sock = NULL;                378                 tc->t_sock = NULL;
379                 tc->t_tinc = NULL;                379                 tc->t_tinc = NULL;
380                 tc->t_tinc_hdr_rem = sizeof(st    380                 tc->t_tinc_hdr_rem = sizeof(struct rds_header);
381                 tc->t_tinc_data_rem = 0;          381                 tc->t_tinc_data_rem = 0;
382                                                   382 
383                 conn->c_path[i].cp_transport_d    383                 conn->c_path[i].cp_transport_data = tc;
384                 tc->t_cpath = &conn->c_path[i]    384                 tc->t_cpath = &conn->c_path[i];
385                 tc->t_tcp_node_detached = true    385                 tc->t_tcp_node_detached = true;
386                                                   386 
387                 rdsdebug("rds_conn_path [%d] t    387                 rdsdebug("rds_conn_path [%d] tc %p\n", i,
388                          conn->c_path[i].cp_tr    388                          conn->c_path[i].cp_transport_data);
389         }                                         389         }
390         spin_lock_irq(&rds_tcp_conn_lock);        390         spin_lock_irq(&rds_tcp_conn_lock);
391         for (i = 0; i < RDS_MPATH_WORKERS; i++    391         for (i = 0; i < RDS_MPATH_WORKERS; i++) {
392                 tc = conn->c_path[i].cp_transp    392                 tc = conn->c_path[i].cp_transport_data;
393                 tc->t_tcp_node_detached = fals    393                 tc->t_tcp_node_detached = false;
394                 list_add_tail(&tc->t_tcp_node,    394                 list_add_tail(&tc->t_tcp_node, &rds_tcp_conn_list);
395         }                                         395         }
396         spin_unlock_irq(&rds_tcp_conn_lock);      396         spin_unlock_irq(&rds_tcp_conn_lock);
397 fail:                                             397 fail:
398         if (ret) {                                398         if (ret) {
399                 for (j = 0; j < i; j++)           399                 for (j = 0; j < i; j++)
400                         rds_tcp_conn_free(conn    400                         rds_tcp_conn_free(conn->c_path[j].cp_transport_data);
401         }                                         401         }
402         return ret;                               402         return ret;
403 }                                                 403 }
404                                                   404 
405 static bool list_has_conn(struct list_head *li    405 static bool list_has_conn(struct list_head *list, struct rds_connection *conn)
406 {                                                 406 {
407         struct rds_tcp_connection *tc, *_tc;      407         struct rds_tcp_connection *tc, *_tc;
408                                                   408 
409         list_for_each_entry_safe(tc, _tc, list    409         list_for_each_entry_safe(tc, _tc, list, t_tcp_node) {
410                 if (tc->t_cpath->cp_conn == co    410                 if (tc->t_cpath->cp_conn == conn)
411                         return true;              411                         return true;
412         }                                         412         }
413         return false;                             413         return false;
414 }                                                 414 }
415                                                   415 
416 static void rds_tcp_set_unloading(void)           416 static void rds_tcp_set_unloading(void)
417 {                                                 417 {
418         atomic_set(&rds_tcp_unloading, 1);        418         atomic_set(&rds_tcp_unloading, 1);
419 }                                                 419 }
420                                                   420 
421 static bool rds_tcp_is_unloading(struct rds_co    421 static bool rds_tcp_is_unloading(struct rds_connection *conn)
422 {                                                 422 {
423         return atomic_read(&rds_tcp_unloading)    423         return atomic_read(&rds_tcp_unloading) != 0;
424 }                                                 424 }
425                                                   425 
426 static void rds_tcp_destroy_conns(void)           426 static void rds_tcp_destroy_conns(void)
427 {                                                 427 {
428         struct rds_tcp_connection *tc, *_tc;      428         struct rds_tcp_connection *tc, *_tc;
429         LIST_HEAD(tmp_list);                      429         LIST_HEAD(tmp_list);
430                                                   430 
431         /* avoid calling conn_destroy with irq    431         /* avoid calling conn_destroy with irqs off */
432         spin_lock_irq(&rds_tcp_conn_lock);        432         spin_lock_irq(&rds_tcp_conn_lock);
433         list_for_each_entry_safe(tc, _tc, &rds    433         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
434                 if (!list_has_conn(&tmp_list,     434                 if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
435                         list_move_tail(&tc->t_    435                         list_move_tail(&tc->t_tcp_node, &tmp_list);
436         }                                         436         }
437         spin_unlock_irq(&rds_tcp_conn_lock);      437         spin_unlock_irq(&rds_tcp_conn_lock);
438                                                   438 
439         list_for_each_entry_safe(tc, _tc, &tmp    439         list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)
440                 rds_conn_destroy(tc->t_cpath->    440                 rds_conn_destroy(tc->t_cpath->cp_conn);
441 }                                                 441 }
442                                                   442 
443 static void rds_tcp_exit(void);                   443 static void rds_tcp_exit(void);
444                                                   444 
445 static u8 rds_tcp_get_tos_map(u8 tos)             445 static u8 rds_tcp_get_tos_map(u8 tos)
446 {                                                 446 {
447         /* all user tos mapped to default 0 fo    447         /* all user tos mapped to default 0 for TCP transport */
448         return 0;                                 448         return 0;
449 }                                                 449 }
450                                                   450 
451 struct rds_transport rds_tcp_transport = {        451 struct rds_transport rds_tcp_transport = {
452         .laddr_check            = rds_tcp_ladd    452         .laddr_check            = rds_tcp_laddr_check,
453         .xmit_path_prepare      = rds_tcp_xmit    453         .xmit_path_prepare      = rds_tcp_xmit_path_prepare,
454         .xmit_path_complete     = rds_tcp_xmit    454         .xmit_path_complete     = rds_tcp_xmit_path_complete,
455         .xmit                   = rds_tcp_xmit    455         .xmit                   = rds_tcp_xmit,
456         .recv_path              = rds_tcp_recv    456         .recv_path              = rds_tcp_recv_path,
457         .conn_alloc             = rds_tcp_conn    457         .conn_alloc             = rds_tcp_conn_alloc,
458         .conn_free              = rds_tcp_conn    458         .conn_free              = rds_tcp_conn_free,
459         .conn_path_connect      = rds_tcp_conn    459         .conn_path_connect      = rds_tcp_conn_path_connect,
460         .conn_path_shutdown     = rds_tcp_conn    460         .conn_path_shutdown     = rds_tcp_conn_path_shutdown,
461         .inc_copy_to_user       = rds_tcp_inc_    461         .inc_copy_to_user       = rds_tcp_inc_copy_to_user,
462         .inc_free               = rds_tcp_inc_    462         .inc_free               = rds_tcp_inc_free,
463         .stats_info_copy        = rds_tcp_stat    463         .stats_info_copy        = rds_tcp_stats_info_copy,
464         .exit                   = rds_tcp_exit    464         .exit                   = rds_tcp_exit,
465         .get_tos_map            = rds_tcp_get_    465         .get_tos_map            = rds_tcp_get_tos_map,
466         .t_owner                = THIS_MODULE,    466         .t_owner                = THIS_MODULE,
467         .t_name                 = "tcp",          467         .t_name                 = "tcp",
468         .t_type                 = RDS_TRANS_TC    468         .t_type                 = RDS_TRANS_TCP,
469         .t_prefer_loopback      = 1,              469         .t_prefer_loopback      = 1,
470         .t_mp_capable           = 1,              470         .t_mp_capable           = 1,
471         .t_unloading            = rds_tcp_is_u    471         .t_unloading            = rds_tcp_is_unloading,
472 };                                                472 };
473                                                   473 
474 static unsigned int rds_tcp_netid;                474 static unsigned int rds_tcp_netid;
475                                                   475 
476 /* per-network namespace private data for this    476 /* per-network namespace private data for this module */
477 struct rds_tcp_net {                              477 struct rds_tcp_net {
478         struct socket *rds_tcp_listen_sock;       478         struct socket *rds_tcp_listen_sock;
479         struct work_struct rds_tcp_accept_w;      479         struct work_struct rds_tcp_accept_w;
480         struct ctl_table_header *rds_tcp_sysct    480         struct ctl_table_header *rds_tcp_sysctl;
481         struct ctl_table *ctl_table;              481         struct ctl_table *ctl_table;
482         int sndbuf_size;                          482         int sndbuf_size;
483         int rcvbuf_size;                          483         int rcvbuf_size;
484 };                                                484 };
485                                                   485 
486 /* All module specific customizations to the R    486 /* All module specific customizations to the RDS-TCP socket should be done in
487  * rds_tcp_tune() and applied after socket cre    487  * rds_tcp_tune() and applied after socket creation.
488  */                                               488  */
489 bool rds_tcp_tune(struct socket *sock)            489 bool rds_tcp_tune(struct socket *sock)
490 {                                                 490 {
491         struct sock *sk = sock->sk;               491         struct sock *sk = sock->sk;
492         struct net *net = sock_net(sk);           492         struct net *net = sock_net(sk);
493         struct rds_tcp_net *rtn;                  493         struct rds_tcp_net *rtn;
494                                                   494 
495         tcp_sock_set_nodelay(sock->sk);           495         tcp_sock_set_nodelay(sock->sk);
496         lock_sock(sk);                            496         lock_sock(sk);
497         /* TCP timer functions might access ne    497         /* TCP timer functions might access net namespace even after
498          * a process which created this net na    498          * a process which created this net namespace terminated.
499          */                                       499          */
500         if (!sk->sk_net_refcnt) {                 500         if (!sk->sk_net_refcnt) {
501                 if (!maybe_get_net(net)) {        501                 if (!maybe_get_net(net)) {
502                         release_sock(sk);         502                         release_sock(sk);
503                         return false;             503                         return false;
504                 }                                 504                 }
505                 /* Update ns_tracker to curren    505                 /* Update ns_tracker to current stack trace and refcounted tracker */
506                 __netns_tracker_free(net, &sk-    506                 __netns_tracker_free(net, &sk->ns_tracker, false);
507                                                   507 
508                 sk->sk_net_refcnt = 1;            508                 sk->sk_net_refcnt = 1;
509                 netns_tracker_alloc(net, &sk->    509                 netns_tracker_alloc(net, &sk->ns_tracker, GFP_KERNEL);
510                 sock_inuse_add(net, 1);           510                 sock_inuse_add(net, 1);
511         }                                         511         }
512         rtn = net_generic(net, rds_tcp_netid);    512         rtn = net_generic(net, rds_tcp_netid);
513         if (rtn->sndbuf_size > 0) {               513         if (rtn->sndbuf_size > 0) {
514                 sk->sk_sndbuf = rtn->sndbuf_si    514                 sk->sk_sndbuf = rtn->sndbuf_size;
515                 sk->sk_userlocks |= SOCK_SNDBU    515                 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
516         }                                         516         }
517         if (rtn->rcvbuf_size > 0) {               517         if (rtn->rcvbuf_size > 0) {
518                 sk->sk_rcvbuf = rtn->rcvbuf_si    518                 sk->sk_rcvbuf = rtn->rcvbuf_size;
519                 sk->sk_userlocks |= SOCK_RCVBU    519                 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
520         }                                         520         }
521         release_sock(sk);                         521         release_sock(sk);
522         return true;                              522         return true;
523 }                                                 523 }
524                                                   524 
525 static void rds_tcp_accept_worker(struct work_    525 static void rds_tcp_accept_worker(struct work_struct *work)
526 {                                                 526 {
527         struct rds_tcp_net *rtn = container_of    527         struct rds_tcp_net *rtn = container_of(work,
528                                                   528                                                struct rds_tcp_net,
529                                                   529                                                rds_tcp_accept_w);
530                                                   530 
531         while (rds_tcp_accept_one(rtn->rds_tcp    531         while (rds_tcp_accept_one(rtn->rds_tcp_listen_sock) == 0)
532                 cond_resched();                   532                 cond_resched();
533 }                                                 533 }
534                                                   534 
535 void rds_tcp_accept_work(struct sock *sk)         535 void rds_tcp_accept_work(struct sock *sk)
536 {                                                 536 {
537         struct net *net = sock_net(sk);           537         struct net *net = sock_net(sk);
538         struct rds_tcp_net *rtn = net_generic(    538         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
539                                                   539 
540         queue_work(rds_wq, &rtn->rds_tcp_accep    540         queue_work(rds_wq, &rtn->rds_tcp_accept_w);
541 }                                                 541 }
542                                                   542 
543 static __net_init int rds_tcp_init_net(struct     543 static __net_init int rds_tcp_init_net(struct net *net)
544 {                                                 544 {
545         struct rds_tcp_net *rtn = net_generic(    545         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
546         struct ctl_table *tbl;                    546         struct ctl_table *tbl;
547         int err = 0;                              547         int err = 0;
548                                                   548 
549         memset(rtn, 0, sizeof(*rtn));             549         memset(rtn, 0, sizeof(*rtn));
550                                                   550 
551         /* {snd, rcv}buf_size default to 0, wh    551         /* {snd, rcv}buf_size default to 0, which implies we let the
552          * stack pick the value, and permit au    552          * stack pick the value, and permit auto-tuning of buffer size.
553          */                                       553          */
554         if (net == &init_net) {                   554         if (net == &init_net) {
555                 tbl = rds_tcp_sysctl_table;       555                 tbl = rds_tcp_sysctl_table;
556         } else {                                  556         } else {
557                 tbl = kmemdup(rds_tcp_sysctl_t    557                 tbl = kmemdup(rds_tcp_sysctl_table,
558                               sizeof(rds_tcp_s    558                               sizeof(rds_tcp_sysctl_table), GFP_KERNEL);
559                 if (!tbl) {                       559                 if (!tbl) {
560                         pr_warn("could not set    560                         pr_warn("could not set allocate sysctl table\n");
561                         return -ENOMEM;           561                         return -ENOMEM;
562                 }                                 562                 }
563                 rtn->ctl_table = tbl;             563                 rtn->ctl_table = tbl;
564         }                                         564         }
565         tbl[RDS_TCP_SNDBUF].data = &rtn->sndbu    565         tbl[RDS_TCP_SNDBUF].data = &rtn->sndbuf_size;
566         tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbu    566         tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbuf_size;
567         rtn->rds_tcp_sysctl = register_net_sys    567         rtn->rds_tcp_sysctl = register_net_sysctl_sz(net, "net/rds/tcp", tbl,
568                                                   568                                                      ARRAY_SIZE(rds_tcp_sysctl_table));
569         if (!rtn->rds_tcp_sysctl) {               569         if (!rtn->rds_tcp_sysctl) {
570                 pr_warn("could not register sy    570                 pr_warn("could not register sysctl\n");
571                 err = -ENOMEM;                    571                 err = -ENOMEM;
572                 goto fail;                        572                 goto fail;
573         }                                         573         }
574                                                   574 
575 #if IS_ENABLED(CONFIG_IPV6)                       575 #if IS_ENABLED(CONFIG_IPV6)
576         rtn->rds_tcp_listen_sock = rds_tcp_lis    576         rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, true);
577 #else                                             577 #else
578         rtn->rds_tcp_listen_sock = rds_tcp_lis    578         rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, false);
579 #endif                                            579 #endif
580         if (!rtn->rds_tcp_listen_sock) {          580         if (!rtn->rds_tcp_listen_sock) {
581                 pr_warn("could not set up IPv6    581                 pr_warn("could not set up IPv6 listen sock\n");
582                                                   582 
583 #if IS_ENABLED(CONFIG_IPV6)                       583 #if IS_ENABLED(CONFIG_IPV6)
584                 /* Try IPv4 as some systems di    584                 /* Try IPv4 as some systems disable IPv6 */
585                 rtn->rds_tcp_listen_sock = rds    585                 rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, false);
586                 if (!rtn->rds_tcp_listen_sock)    586                 if (!rtn->rds_tcp_listen_sock) {
587 #endif                                            587 #endif
588                         unregister_net_sysctl_    588                         unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
589                         rtn->rds_tcp_sysctl =     589                         rtn->rds_tcp_sysctl = NULL;
590                         err = -EAFNOSUPPORT;      590                         err = -EAFNOSUPPORT;
591                         goto fail;                591                         goto fail;
592 #if IS_ENABLED(CONFIG_IPV6)                       592 #if IS_ENABLED(CONFIG_IPV6)
593                 }                                 593                 }
594 #endif                                            594 #endif
595         }                                         595         }
596         INIT_WORK(&rtn->rds_tcp_accept_w, rds_    596         INIT_WORK(&rtn->rds_tcp_accept_w, rds_tcp_accept_worker);
597         return 0;                                 597         return 0;
598                                                   598 
599 fail:                                             599 fail:
600         if (net != &init_net)                     600         if (net != &init_net)
601                 kfree(tbl);                       601                 kfree(tbl);
602         return err;                               602         return err;
603 }                                                 603 }
604                                                   604 
605 static void rds_tcp_kill_sock(struct net *net)    605 static void rds_tcp_kill_sock(struct net *net)
606 {                                                 606 {
607         struct rds_tcp_connection *tc, *_tc;      607         struct rds_tcp_connection *tc, *_tc;
608         LIST_HEAD(tmp_list);                      608         LIST_HEAD(tmp_list);
609         struct rds_tcp_net *rtn = net_generic(    609         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
610         struct socket *lsock = rtn->rds_tcp_li    610         struct socket *lsock = rtn->rds_tcp_listen_sock;
611                                                   611 
612         rtn->rds_tcp_listen_sock = NULL;          612         rtn->rds_tcp_listen_sock = NULL;
613         rds_tcp_listen_stop(lsock, &rtn->rds_t    613         rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
614         spin_lock_irq(&rds_tcp_conn_lock);        614         spin_lock_irq(&rds_tcp_conn_lock);
615         list_for_each_entry_safe(tc, _tc, &rds    615         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
616                 struct net *c_net = read_pnet(    616                 struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net);
617                                                   617 
618                 if (net != c_net)                 618                 if (net != c_net)
619                         continue;                 619                         continue;
620                 if (!list_has_conn(&tmp_list,     620                 if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) {
621                         list_move_tail(&tc->t_    621                         list_move_tail(&tc->t_tcp_node, &tmp_list);
622                 } else {                          622                 } else {
623                         list_del(&tc->t_tcp_no    623                         list_del(&tc->t_tcp_node);
624                         tc->t_tcp_node_detache    624                         tc->t_tcp_node_detached = true;
625                 }                                 625                 }
626         }                                         626         }
627         spin_unlock_irq(&rds_tcp_conn_lock);      627         spin_unlock_irq(&rds_tcp_conn_lock);
628         list_for_each_entry_safe(tc, _tc, &tmp    628         list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)
629                 rds_conn_destroy(tc->t_cpath->    629                 rds_conn_destroy(tc->t_cpath->cp_conn);
630 }                                                 630 }
631                                                   631 
632 static void __net_exit rds_tcp_exit_net(struct    632 static void __net_exit rds_tcp_exit_net(struct net *net)
633 {                                                 633 {
634         struct rds_tcp_net *rtn = net_generic(    634         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
635                                                   635 
636         rds_tcp_kill_sock(net);                   636         rds_tcp_kill_sock(net);
637                                                   637 
638         if (rtn->rds_tcp_sysctl)                  638         if (rtn->rds_tcp_sysctl)
639                 unregister_net_sysctl_table(rt    639                 unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
640                                                   640 
641         if (net != &init_net)                     641         if (net != &init_net)
642                 kfree(rtn->ctl_table);            642                 kfree(rtn->ctl_table);
643 }                                                 643 }
644                                                   644 
645 static struct pernet_operations rds_tcp_net_op    645 static struct pernet_operations rds_tcp_net_ops = {
646         .init = rds_tcp_init_net,                 646         .init = rds_tcp_init_net,
647         .exit = rds_tcp_exit_net,                 647         .exit = rds_tcp_exit_net,
648         .id = &rds_tcp_netid,                     648         .id = &rds_tcp_netid,
649         .size = sizeof(struct rds_tcp_net),       649         .size = sizeof(struct rds_tcp_net),
650 };                                                650 };
651                                                   651 
652 void *rds_tcp_listen_sock_def_readable(struct     652 void *rds_tcp_listen_sock_def_readable(struct net *net)
653 {                                                 653 {
654         struct rds_tcp_net *rtn = net_generic(    654         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
655         struct socket *lsock = rtn->rds_tcp_li    655         struct socket *lsock = rtn->rds_tcp_listen_sock;
656                                                   656 
657         if (!lsock)                               657         if (!lsock)
658                 return NULL;                      658                 return NULL;
659                                                   659 
660         return lsock->sk->sk_user_data;           660         return lsock->sk->sk_user_data;
661 }                                                 661 }
662                                                   662 
663 /* when sysctl is used to modify some kernel s    663 /* when sysctl is used to modify some kernel socket parameters,this
664  * function  resets the RDS connections in tha    664  * function  resets the RDS connections in that netns  so that we can
665  * restart with new parameters.  The assumptio    665  * restart with new parameters.  The assumption is that such reset
666  * events are few and far-between.                666  * events are few and far-between.
667  */                                               667  */
668 static void rds_tcp_sysctl_reset(struct net *n    668 static void rds_tcp_sysctl_reset(struct net *net)
669 {                                                 669 {
670         struct rds_tcp_connection *tc, *_tc;      670         struct rds_tcp_connection *tc, *_tc;
671                                                   671 
672         spin_lock_irq(&rds_tcp_conn_lock);        672         spin_lock_irq(&rds_tcp_conn_lock);
673         list_for_each_entry_safe(tc, _tc, &rds    673         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
674                 struct net *c_net = read_pnet(    674                 struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net);
675                                                   675 
676                 if (net != c_net || !tc->t_soc    676                 if (net != c_net || !tc->t_sock)
677                         continue;                 677                         continue;
678                                                   678 
679                 /* reconnect with new paramete    679                 /* reconnect with new parameters */
680                 rds_conn_path_drop(tc->t_cpath    680                 rds_conn_path_drop(tc->t_cpath, false);
681         }                                         681         }
682         spin_unlock_irq(&rds_tcp_conn_lock);      682         spin_unlock_irq(&rds_tcp_conn_lock);
683 }                                                 683 }
684                                                   684 
685 static int rds_tcp_skbuf_handler(const struct     685 static int rds_tcp_skbuf_handler(const struct ctl_table *ctl, int write,
686                                  void *buffer,    686                                  void *buffer, size_t *lenp, loff_t *fpos)
687 {                                                 687 {
688         struct net *net = current->nsproxy->ne    688         struct net *net = current->nsproxy->net_ns;
689         int err;                                  689         int err;
690                                                   690 
691         err = proc_dointvec_minmax(ctl, write,    691         err = proc_dointvec_minmax(ctl, write, buffer, lenp, fpos);
692         if (err < 0) {                            692         if (err < 0) {
693                 pr_warn("Invalid input. Must b    693                 pr_warn("Invalid input. Must be >= %d\n",
694                         *(int *)(ctl->extra1))    694                         *(int *)(ctl->extra1));
695                 return err;                       695                 return err;
696         }                                         696         }
697         if (write)                                697         if (write)
698                 rds_tcp_sysctl_reset(net);        698                 rds_tcp_sysctl_reset(net);
699         return 0;                                 699         return 0;
700 }                                                 700 }
701                                                   701 
702 static void rds_tcp_exit(void)                    702 static void rds_tcp_exit(void)
703 {                                                 703 {
704         rds_tcp_set_unloading();                  704         rds_tcp_set_unloading();
705         synchronize_rcu();                        705         synchronize_rcu();
706         rds_info_deregister_func(RDS_INFO_TCP_    706         rds_info_deregister_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
707 #if IS_ENABLED(CONFIG_IPV6)                       707 #if IS_ENABLED(CONFIG_IPV6)
708         rds_info_deregister_func(RDS6_INFO_TCP    708         rds_info_deregister_func(RDS6_INFO_TCP_SOCKETS, rds6_tcp_tc_info);
709 #endif                                            709 #endif
710         unregister_pernet_device(&rds_tcp_net_    710         unregister_pernet_device(&rds_tcp_net_ops);
711         rds_tcp_destroy_conns();                  711         rds_tcp_destroy_conns();
712         rds_trans_unregister(&rds_tcp_transpor    712         rds_trans_unregister(&rds_tcp_transport);
713         rds_tcp_recv_exit();                      713         rds_tcp_recv_exit();
714         kmem_cache_destroy(rds_tcp_conn_slab);    714         kmem_cache_destroy(rds_tcp_conn_slab);
715 }                                                 715 }
716 module_exit(rds_tcp_exit);                        716 module_exit(rds_tcp_exit);
717                                                   717 
718 static int __init rds_tcp_init(void)              718 static int __init rds_tcp_init(void)
719 {                                                 719 {
720         int ret;                                  720         int ret;
721                                                   721 
722         rds_tcp_conn_slab = KMEM_CACHE(rds_tcp    722         rds_tcp_conn_slab = KMEM_CACHE(rds_tcp_connection, 0);
723         if (!rds_tcp_conn_slab) {                 723         if (!rds_tcp_conn_slab) {
724                 ret = -ENOMEM;                    724                 ret = -ENOMEM;
725                 goto out;                         725                 goto out;
726         }                                         726         }
727                                                   727 
728         ret = rds_tcp_recv_init();                728         ret = rds_tcp_recv_init();
729         if (ret)                                  729         if (ret)
730                 goto out_slab;                    730                 goto out_slab;
731                                                   731 
732         ret = register_pernet_device(&rds_tcp_    732         ret = register_pernet_device(&rds_tcp_net_ops);
733         if (ret)                                  733         if (ret)
734                 goto out_recv;                    734                 goto out_recv;
735                                                   735 
736         rds_trans_register(&rds_tcp_transport)    736         rds_trans_register(&rds_tcp_transport);
737                                                   737 
738         rds_info_register_func(RDS_INFO_TCP_SO    738         rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
739 #if IS_ENABLED(CONFIG_IPV6)                       739 #if IS_ENABLED(CONFIG_IPV6)
740         rds_info_register_func(RDS6_INFO_TCP_S    740         rds_info_register_func(RDS6_INFO_TCP_SOCKETS, rds6_tcp_tc_info);
741 #endif                                            741 #endif
742                                                   742 
743         goto out;                                 743         goto out;
744 out_recv:                                         744 out_recv:
745         rds_tcp_recv_exit();                      745         rds_tcp_recv_exit();
746 out_slab:                                         746 out_slab:
747         kmem_cache_destroy(rds_tcp_conn_slab);    747         kmem_cache_destroy(rds_tcp_conn_slab);
748 out:                                              748 out:
749         return ret;                               749         return ret;
750 }                                                 750 }
751 module_init(rds_tcp_init);                        751 module_init(rds_tcp_init);
752                                                   752 
753 MODULE_AUTHOR("Oracle Corporation <rds-devel@o    753 MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>");
754 MODULE_DESCRIPTION("RDS: TCP transport");         754 MODULE_DESCRIPTION("RDS: TCP transport");
755 MODULE_LICENSE("Dual BSD/GPL");                   755 MODULE_LICENSE("Dual BSD/GPL");
756                                                   756 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php