~ [ 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 (Version linux-6.12-rc7) and /net/rds/tcp.c (Version linux-4.11.12)


  1 /*                                                  1 /*
  2  * Copyright (c) 2006, 2018 Oracle and/or its  !!   2  * Copyright (c) 2006 Oracle.  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>                      << 
 41                                                    40 
 42 #include "rds.h"                                   41 #include "rds.h"
 43 #include "tcp.h"                                   42 #include "tcp.h"
 44                                                    43 
 45 /* only for info exporting */                      44 /* only for info exporting */
 46 static DEFINE_SPINLOCK(rds_tcp_tc_list_lock);      45 static DEFINE_SPINLOCK(rds_tcp_tc_list_lock);
 47 static LIST_HEAD(rds_tcp_tc_list);                 46 static LIST_HEAD(rds_tcp_tc_list);
 48                                                << 
 49 /* rds_tcp_tc_count counts only IPv4 connectio << 
 50  * rds6_tcp_tc_count counts both IPv4 and IPv6 << 
 51  */                                            << 
 52 static unsigned int rds_tcp_tc_count;              47 static unsigned int rds_tcp_tc_count;
 53 #if IS_ENABLED(CONFIG_IPV6)                    << 
 54 static unsigned int rds6_tcp_tc_count;         << 
 55 #endif                                         << 
 56                                                    48 
 57 /* Track rds_tcp_connection structs so they ca     49 /* Track rds_tcp_connection structs so they can be cleaned up */
 58 static DEFINE_SPINLOCK(rds_tcp_conn_lock);         50 static DEFINE_SPINLOCK(rds_tcp_conn_lock);
 59 static LIST_HEAD(rds_tcp_conn_list);               51 static LIST_HEAD(rds_tcp_conn_list);
 60 static atomic_t rds_tcp_unloading = ATOMIC_INI << 
 61                                                    52 
 62 static struct kmem_cache *rds_tcp_conn_slab;       53 static struct kmem_cache *rds_tcp_conn_slab;
 63                                                    54 
 64 static int rds_tcp_skbuf_handler(const struct  !!  55 static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write,
 65                                  void *buffer, !!  56                                  void __user *buffer, size_t *lenp,
                                                   >>  57                                  loff_t *fpos);
 66                                                    58 
 67 static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBU     59 static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBUF;
 68 static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBU     60 static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBUF;
 69                                                    61 
 70 static struct ctl_table rds_tcp_sysctl_table[]     62 static struct ctl_table rds_tcp_sysctl_table[] = {
 71 #define RDS_TCP_SNDBUF  0                          63 #define RDS_TCP_SNDBUF  0
 72         {                                          64         {
 73                 .procname       = "rds_tcp_snd     65                 .procname       = "rds_tcp_sndbuf",
 74                 /* data is per-net pointer */      66                 /* data is per-net pointer */
 75                 .maxlen         = sizeof(int),     67                 .maxlen         = sizeof(int),
 76                 .mode           = 0644,            68                 .mode           = 0644,
 77                 .proc_handler   = rds_tcp_skbu     69                 .proc_handler   = rds_tcp_skbuf_handler,
 78                 .extra1         = &rds_tcp_min     70                 .extra1         = &rds_tcp_min_sndbuf,
 79         },                                         71         },
 80 #define RDS_TCP_RCVBUF  1                          72 #define RDS_TCP_RCVBUF  1
 81         {                                          73         {
 82                 .procname       = "rds_tcp_rcv     74                 .procname       = "rds_tcp_rcvbuf",
 83                 /* data is per-net pointer */      75                 /* data is per-net pointer */
 84                 .maxlen         = sizeof(int),     76                 .maxlen         = sizeof(int),
 85                 .mode           = 0644,            77                 .mode           = 0644,
 86                 .proc_handler   = rds_tcp_skbu     78                 .proc_handler   = rds_tcp_skbuf_handler,
 87                 .extra1         = &rds_tcp_min     79                 .extra1         = &rds_tcp_min_rcvbuf,
 88         },                                         80         },
                                                   >>  81         { }
 89 };                                                 82 };
 90                                                    83 
 91 u32 rds_tcp_write_seq(struct rds_tcp_connectio !!  84 /* doing it this way avoids calling tcp_sk() */
                                                   >>  85 void rds_tcp_nonagle(struct socket *sock)
                                                   >>  86 {
                                                   >>  87         mm_segment_t oldfs = get_fs();
                                                   >>  88         int val = 1;
                                                   >>  89 
                                                   >>  90         set_fs(KERNEL_DS);
                                                   >>  91         sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
                                                   >>  92                               sizeof(val));
                                                   >>  93         set_fs(oldfs);
                                                   >>  94 }
                                                   >>  95 
                                                   >>  96 u32 rds_tcp_snd_nxt(struct rds_tcp_connection *tc)
 92 {                                                  97 {
 93         /* seq# of the last byte of data in tc !!  98         return tcp_sk(tc->t_sock->sk)->snd_nxt;
 94         return tcp_sk(tc->t_sock->sk)->write_s << 
 95 }                                                  99 }
 96                                                   100 
 97 u32 rds_tcp_snd_una(struct rds_tcp_connection     101 u32 rds_tcp_snd_una(struct rds_tcp_connection *tc)
 98 {                                                 102 {
 99         return tcp_sk(tc->t_sock->sk)->snd_una    103         return tcp_sk(tc->t_sock->sk)->snd_una;
100 }                                                 104 }
101                                                   105 
102 void rds_tcp_restore_callbacks(struct socket *    106 void rds_tcp_restore_callbacks(struct socket *sock,
103                                struct rds_tcp_    107                                struct rds_tcp_connection *tc)
104 {                                                 108 {
105         rdsdebug("restoring sock %p callbacks     109         rdsdebug("restoring sock %p callbacks from tc %p\n", sock, tc);
106         write_lock_bh(&sock->sk->sk_callback_l    110         write_lock_bh(&sock->sk->sk_callback_lock);
107                                                   111 
108         /* done under the callback_lock to ser    112         /* done under the callback_lock to serialize with write_space */
109         spin_lock(&rds_tcp_tc_list_lock);         113         spin_lock(&rds_tcp_tc_list_lock);
110         list_del_init(&tc->t_list_item);          114         list_del_init(&tc->t_list_item);
111 #if IS_ENABLED(CONFIG_IPV6)                    !! 115         rds_tcp_tc_count--;
112         rds6_tcp_tc_count--;                   << 
113 #endif                                         << 
114         if (!tc->t_cpath->cp_conn->c_isv6)     << 
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         lock_sock(osock->sk);
168         /* reset receive side state for rds_tc    169         /* reset receive side state for rds_tcp_data_recv() for osock  */
169         cancel_delayed_work_sync(&cp->cp_send_    170         cancel_delayed_work_sync(&cp->cp_send_w);
170         cancel_delayed_work_sync(&cp->cp_recv_    171         cancel_delayed_work_sync(&cp->cp_recv_w);
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         rds_tcp_tc_count++;
203         rds6_tcp_tc_count++;                   << 
204 #endif                                         << 
205         if (!tc->t_cpath->cp_conn->c_isv6)     << 
206                 rds_tcp_tc_count++;            << 
207         spin_unlock(&rds_tcp_tc_list_lock);       203         spin_unlock(&rds_tcp_tc_list_lock);
208                                                   204 
209         /* accepted sockets need our listen da    205         /* accepted sockets need our listen data ready undone */
210         if (sock->sk->sk_data_ready == rds_tcp    206         if (sock->sk->sk_data_ready == rds_tcp_listen_data_ready)
211                 sock->sk->sk_data_ready = sock    207                 sock->sk->sk_data_ready = sock->sk->sk_user_data;
212                                                   208 
213         tc->t_sock = sock;                        209         tc->t_sock = sock;
214         tc->t_cpath = cp;                         210         tc->t_cpath = cp;
215         tc->t_orig_data_ready = sock->sk->sk_d    211         tc->t_orig_data_ready = sock->sk->sk_data_ready;
216         tc->t_orig_write_space = sock->sk->sk_    212         tc->t_orig_write_space = sock->sk->sk_write_space;
217         tc->t_orig_state_change = sock->sk->sk    213         tc->t_orig_state_change = sock->sk->sk_state_change;
218                                                   214 
219         sock->sk->sk_user_data = cp;              215         sock->sk->sk_user_data = cp;
220         sock->sk->sk_data_ready = rds_tcp_data    216         sock->sk->sk_data_ready = rds_tcp_data_ready;
221         sock->sk->sk_write_space = rds_tcp_wri    217         sock->sk->sk_write_space = rds_tcp_write_space;
222         sock->sk->sk_state_change = rds_tcp_st    218         sock->sk->sk_state_change = rds_tcp_state_change;
223                                                   219 
224         write_unlock_bh(&sock->sk->sk_callback    220         write_unlock_bh(&sock->sk->sk_callback_lock);
225 }                                                 221 }
226                                                   222 
227 /* Handle RDS_INFO_TCP_SOCKETS socket option.  << 
228  * connections for backward compatibility.     << 
229  */                                            << 
230 static void rds_tcp_tc_info(struct socket *rds    223 static void rds_tcp_tc_info(struct socket *rds_sock, unsigned int len,
231                             struct rds_info_it    224                             struct rds_info_iterator *iter,
232                             struct rds_info_le    225                             struct rds_info_lengths *lens)
233 {                                                 226 {
234         struct rds_info_tcp_socket tsinfo;        227         struct rds_info_tcp_socket tsinfo;
235         struct rds_tcp_connection *tc;            228         struct rds_tcp_connection *tc;
236         unsigned long flags;                      229         unsigned long flags;
                                                   >> 230         struct sockaddr_in sin;
                                                   >> 231         int sinlen;
                                                   >> 232         struct socket *sock;
237                                                   233 
238         spin_lock_irqsave(&rds_tcp_tc_list_loc    234         spin_lock_irqsave(&rds_tcp_tc_list_lock, flags);
239                                                   235 
240         if (len / sizeof(tsinfo) < rds_tcp_tc_    236         if (len / sizeof(tsinfo) < rds_tcp_tc_count)
241                 goto out;                         237                 goto out;
242                                                   238 
243         list_for_each_entry(tc, &rds_tcp_tc_li    239         list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) {
244                 struct inet_sock *inet = inet_ << 
245                                                << 
246                 if (tc->t_cpath->cp_conn->c_is << 
247                         continue;              << 
248                                                   240 
249                 tsinfo.local_addr = inet->inet !! 241                 sock = tc->t_sock;
250                 tsinfo.local_port = inet->inet !! 242                 if (sock) {
251                 tsinfo.peer_addr = inet->inet_ !! 243                         sock->ops->getname(sock, (struct sockaddr *)&sin,
252                 tsinfo.peer_port = inet->inet_ !! 244                                            &sinlen, 0);
                                                   >> 245                         tsinfo.local_addr = sin.sin_addr.s_addr;
                                                   >> 246                         tsinfo.local_port = sin.sin_port;
                                                   >> 247                         sock->ops->getname(sock, (struct sockaddr *)&sin,
                                                   >> 248                                            &sinlen, 1);
                                                   >> 249                         tsinfo.peer_addr = sin.sin_addr.s_addr;
                                                   >> 250                         tsinfo.peer_port = sin.sin_port;
                                                   >> 251                 }
253                                                   252 
254                 tsinfo.hdr_rem = tc->t_tinc_hd    253                 tsinfo.hdr_rem = tc->t_tinc_hdr_rem;
255                 tsinfo.data_rem = tc->t_tinc_d    254                 tsinfo.data_rem = tc->t_tinc_data_rem;
256                 tsinfo.last_sent_nxt = tc->t_l    255                 tsinfo.last_sent_nxt = tc->t_last_sent_nxt;
257                 tsinfo.last_expected_una = tc-    256                 tsinfo.last_expected_una = tc->t_last_expected_una;
258                 tsinfo.last_seen_una = tc->t_l    257                 tsinfo.last_seen_una = tc->t_last_seen_una;
259                 tsinfo.tos = tc->t_cpath->cp_c << 
260                                                   258 
261                 rds_info_copy(iter, &tsinfo, s    259                 rds_info_copy(iter, &tsinfo, sizeof(tsinfo));
262         }                                         260         }
263                                                   261 
264 out:                                              262 out:
265         lens->nr = rds_tcp_tc_count;              263         lens->nr = rds_tcp_tc_count;
266         lens->each = sizeof(tsinfo);              264         lens->each = sizeof(tsinfo);
267                                                   265 
268         spin_unlock_irqrestore(&rds_tcp_tc_lis    266         spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags);
269 }                                                 267 }
270                                                   268 
271 #if IS_ENABLED(CONFIG_IPV6)                    !! 269 static int rds_tcp_laddr_check(struct net *net, __be32 addr)
272 /* Handle RDS6_INFO_TCP_SOCKETS socket option. << 
273  * IPv6 connections. IPv4 connection address i << 
274  * address.                                    << 
275  */                                            << 
276 static void rds6_tcp_tc_info(struct socket *so << 
277                              struct rds_info_i << 
278                              struct rds_info_l << 
279 {                                              << 
280         struct rds6_info_tcp_socket tsinfo6;   << 
281         struct rds_tcp_connection *tc;         << 
282         unsigned long flags;                   << 
283                                                << 
284         spin_lock_irqsave(&rds_tcp_tc_list_loc << 
285                                                << 
286         if (len / sizeof(tsinfo6) < rds6_tcp_t << 
287                 goto out;                      << 
288                                                << 
289         list_for_each_entry(tc, &rds_tcp_tc_li << 
290                 struct sock *sk = tc->t_sock-> << 
291                 struct inet_sock *inet = inet_ << 
292                                                << 
293                 tsinfo6.local_addr = sk->sk_v6 << 
294                 tsinfo6.local_port = inet->ine << 
295                 tsinfo6.peer_addr = sk->sk_v6_ << 
296                 tsinfo6.peer_port = inet->inet << 
297                                                << 
298                 tsinfo6.hdr_rem = tc->t_tinc_h << 
299                 tsinfo6.data_rem = tc->t_tinc_ << 
300                 tsinfo6.last_sent_nxt = tc->t_ << 
301                 tsinfo6.last_expected_una = tc << 
302                 tsinfo6.last_seen_una = tc->t_ << 
303                                                << 
304                 rds_info_copy(iter, &tsinfo6,  << 
305         }                                      << 
306                                                << 
307 out:                                           << 
308         lens->nr = rds6_tcp_tc_count;          << 
309         lens->each = sizeof(tsinfo6);          << 
310                                                << 
311         spin_unlock_irqrestore(&rds_tcp_tc_lis << 
312 }                                              << 
313 #endif                                         << 
314                                                << 
315 int rds_tcp_laddr_check(struct net *net, const << 
316                         __u32 scope_id)        << 
317 {                                                 270 {
318         struct net_device *dev = NULL;         !! 271         if (inet_addr_type(net, addr) == RTN_LOCAL)
319 #if IS_ENABLED(CONFIG_IPV6)                    << 
320         int ret;                               << 
321 #endif                                         << 
322                                                << 
323         if (ipv6_addr_v4mapped(addr)) {        << 
324                 if (inet_addr_type(net, addr-> << 
325                         return 0;              << 
326                 return -EADDRNOTAVAIL;         << 
327         }                                      << 
328                                                << 
329         /* If the scope_id is specified, check << 
330          * hosted on the specified interface.  << 
331          */                                    << 
332         if (scope_id != 0) {                   << 
333                 rcu_read_lock();               << 
334                 dev = dev_get_by_index_rcu(net << 
335                 /* scope_id is not valid... */ << 
336                 if (!dev) {                    << 
337                         rcu_read_unlock();     << 
338                         return -EADDRNOTAVAIL; << 
339                 }                              << 
340                 rcu_read_unlock();             << 
341         }                                      << 
342 #if IS_ENABLED(CONFIG_IPV6)                    << 
343         ret = ipv6_chk_addr(net, addr, dev, 0) << 
344         if (ret)                               << 
345                 return 0;                         272                 return 0;
346 #endif                                         << 
347         return -EADDRNOTAVAIL;                    273         return -EADDRNOTAVAIL;
348 }                                                 274 }
349                                                   275 
350 static void rds_tcp_conn_free(void *arg)       << 
351 {                                              << 
352         struct rds_tcp_connection *tc = arg;   << 
353         unsigned long flags;                   << 
354                                                << 
355         rdsdebug("freeing tc %p\n", tc);       << 
356                                                << 
357         spin_lock_irqsave(&rds_tcp_conn_lock,  << 
358         if (!tc->t_tcp_node_detached)          << 
359                 list_del(&tc->t_tcp_node);     << 
360         spin_unlock_irqrestore(&rds_tcp_conn_l << 
361                                                << 
362         kmem_cache_free(rds_tcp_conn_slab, tc) << 
363 }                                              << 
364                                                << 
365 static int rds_tcp_conn_alloc(struct rds_conne    276 static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
366 {                                                 277 {
367         struct rds_tcp_connection *tc;            278         struct rds_tcp_connection *tc;
368         int i, j;                              !! 279         int i;
369         int ret = 0;                           << 
370                                                   280 
371         for (i = 0; i < RDS_MPATH_WORKERS; i++    281         for (i = 0; i < RDS_MPATH_WORKERS; i++) {
372                 tc = kmem_cache_alloc(rds_tcp_    282                 tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
373                 if (!tc) {                     !! 283                 if (!tc)
374                         ret = -ENOMEM;         !! 284                         return -ENOMEM;
375                         goto fail;             !! 285 
376                 }                              << 
377                 mutex_init(&tc->t_conn_path_lo    286                 mutex_init(&tc->t_conn_path_lock);
378                 tc->t_sock = NULL;                287                 tc->t_sock = NULL;
379                 tc->t_tinc = NULL;                288                 tc->t_tinc = NULL;
380                 tc->t_tinc_hdr_rem = sizeof(st    289                 tc->t_tinc_hdr_rem = sizeof(struct rds_header);
381                 tc->t_tinc_data_rem = 0;          290                 tc->t_tinc_data_rem = 0;
382                                                   291 
383                 conn->c_path[i].cp_transport_d    292                 conn->c_path[i].cp_transport_data = tc;
384                 tc->t_cpath = &conn->c_path[i]    293                 tc->t_cpath = &conn->c_path[i];
385                 tc->t_tcp_node_detached = true << 
386                                                   294 
                                                   >> 295                 spin_lock_irq(&rds_tcp_conn_lock);
                                                   >> 296                 list_add_tail(&tc->t_tcp_node, &rds_tcp_conn_list);
                                                   >> 297                 spin_unlock_irq(&rds_tcp_conn_lock);
387                 rdsdebug("rds_conn_path [%d] t    298                 rdsdebug("rds_conn_path [%d] tc %p\n", i,
388                          conn->c_path[i].cp_tr    299                          conn->c_path[i].cp_transport_data);
389         }                                         300         }
390         spin_lock_irq(&rds_tcp_conn_lock);     !! 301 
391         for (i = 0; i < RDS_MPATH_WORKERS; i++ !! 302         return 0;
392                 tc = conn->c_path[i].cp_transp !! 303 }
393                 tc->t_tcp_node_detached = fals !! 304 
394                 list_add_tail(&tc->t_tcp_node, !! 305 static void rds_tcp_conn_free(void *arg)
395         }                                      !! 306 {
396         spin_unlock_irq(&rds_tcp_conn_lock);   !! 307         struct rds_tcp_connection *tc = arg;
397 fail:                                          !! 308         unsigned long flags;
398         if (ret) {                             !! 309         rdsdebug("freeing tc %p\n", tc);
399                 for (j = 0; j < i; j++)        !! 310 
400                         rds_tcp_conn_free(conn !! 311         spin_lock_irqsave(&rds_tcp_conn_lock, flags);
401         }                                      !! 312         list_del(&tc->t_tcp_node);
402         return ret;                            !! 313         spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
                                                   >> 314 
                                                   >> 315         kmem_cache_free(rds_tcp_conn_slab, tc);
403 }                                                 316 }
404                                                   317 
405 static bool list_has_conn(struct list_head *li    318 static bool list_has_conn(struct list_head *list, struct rds_connection *conn)
406 {                                                 319 {
407         struct rds_tcp_connection *tc, *_tc;      320         struct rds_tcp_connection *tc, *_tc;
408                                                   321 
409         list_for_each_entry_safe(tc, _tc, list    322         list_for_each_entry_safe(tc, _tc, list, t_tcp_node) {
410                 if (tc->t_cpath->cp_conn == co    323                 if (tc->t_cpath->cp_conn == conn)
411                         return true;              324                         return true;
412         }                                         325         }
413         return false;                             326         return false;
414 }                                                 327 }
415                                                   328 
416 static void rds_tcp_set_unloading(void)        << 
417 {                                              << 
418         atomic_set(&rds_tcp_unloading, 1);     << 
419 }                                              << 
420                                                << 
421 static bool rds_tcp_is_unloading(struct rds_co << 
422 {                                              << 
423         return atomic_read(&rds_tcp_unloading) << 
424 }                                              << 
425                                                << 
426 static void rds_tcp_destroy_conns(void)           329 static void rds_tcp_destroy_conns(void)
427 {                                                 330 {
428         struct rds_tcp_connection *tc, *_tc;      331         struct rds_tcp_connection *tc, *_tc;
429         LIST_HEAD(tmp_list);                      332         LIST_HEAD(tmp_list);
430                                                   333 
431         /* avoid calling conn_destroy with irq    334         /* avoid calling conn_destroy with irqs off */
432         spin_lock_irq(&rds_tcp_conn_lock);        335         spin_lock_irq(&rds_tcp_conn_lock);
433         list_for_each_entry_safe(tc, _tc, &rds    336         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
434                 if (!list_has_conn(&tmp_list,     337                 if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
435                         list_move_tail(&tc->t_    338                         list_move_tail(&tc->t_tcp_node, &tmp_list);
436         }                                         339         }
437         spin_unlock_irq(&rds_tcp_conn_lock);      340         spin_unlock_irq(&rds_tcp_conn_lock);
438                                                   341 
439         list_for_each_entry_safe(tc, _tc, &tmp    342         list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)
440                 rds_conn_destroy(tc->t_cpath->    343                 rds_conn_destroy(tc->t_cpath->cp_conn);
441 }                                                 344 }
442                                                   345 
443 static void rds_tcp_exit(void);                   346 static void rds_tcp_exit(void);
444                                                   347 
445 static u8 rds_tcp_get_tos_map(u8 tos)          << 
446 {                                              << 
447         /* all user tos mapped to default 0 fo << 
448         return 0;                              << 
449 }                                              << 
450                                                << 
451 struct rds_transport rds_tcp_transport = {        348 struct rds_transport rds_tcp_transport = {
452         .laddr_check            = rds_tcp_ladd    349         .laddr_check            = rds_tcp_laddr_check,
453         .xmit_path_prepare      = rds_tcp_xmit    350         .xmit_path_prepare      = rds_tcp_xmit_path_prepare,
454         .xmit_path_complete     = rds_tcp_xmit    351         .xmit_path_complete     = rds_tcp_xmit_path_complete,
455         .xmit                   = rds_tcp_xmit    352         .xmit                   = rds_tcp_xmit,
456         .recv_path              = rds_tcp_recv    353         .recv_path              = rds_tcp_recv_path,
457         .conn_alloc             = rds_tcp_conn    354         .conn_alloc             = rds_tcp_conn_alloc,
458         .conn_free              = rds_tcp_conn    355         .conn_free              = rds_tcp_conn_free,
459         .conn_path_connect      = rds_tcp_conn    356         .conn_path_connect      = rds_tcp_conn_path_connect,
460         .conn_path_shutdown     = rds_tcp_conn    357         .conn_path_shutdown     = rds_tcp_conn_path_shutdown,
461         .inc_copy_to_user       = rds_tcp_inc_    358         .inc_copy_to_user       = rds_tcp_inc_copy_to_user,
462         .inc_free               = rds_tcp_inc_    359         .inc_free               = rds_tcp_inc_free,
463         .stats_info_copy        = rds_tcp_stat    360         .stats_info_copy        = rds_tcp_stats_info_copy,
464         .exit                   = rds_tcp_exit    361         .exit                   = rds_tcp_exit,
465         .get_tos_map            = rds_tcp_get_ << 
466         .t_owner                = THIS_MODULE,    362         .t_owner                = THIS_MODULE,
467         .t_name                 = "tcp",          363         .t_name                 = "tcp",
468         .t_type                 = RDS_TRANS_TC    364         .t_type                 = RDS_TRANS_TCP,
469         .t_prefer_loopback      = 1,              365         .t_prefer_loopback      = 1,
470         .t_mp_capable           = 1,              366         .t_mp_capable           = 1,
471         .t_unloading            = rds_tcp_is_u << 
472 };                                                367 };
473                                                   368 
474 static unsigned int rds_tcp_netid;                369 static unsigned int rds_tcp_netid;
475                                                   370 
476 /* per-network namespace private data for this    371 /* per-network namespace private data for this module */
477 struct rds_tcp_net {                              372 struct rds_tcp_net {
478         struct socket *rds_tcp_listen_sock;       373         struct socket *rds_tcp_listen_sock;
479         struct work_struct rds_tcp_accept_w;      374         struct work_struct rds_tcp_accept_w;
480         struct ctl_table_header *rds_tcp_sysct    375         struct ctl_table_header *rds_tcp_sysctl;
481         struct ctl_table *ctl_table;              376         struct ctl_table *ctl_table;
482         int sndbuf_size;                          377         int sndbuf_size;
483         int rcvbuf_size;                          378         int rcvbuf_size;
484 };                                                379 };
485                                                   380 
486 /* All module specific customizations to the R    381 /* All module specific customizations to the RDS-TCP socket should be done in
487  * rds_tcp_tune() and applied after socket cre    382  * rds_tcp_tune() and applied after socket creation.
488  */                                               383  */
489 bool rds_tcp_tune(struct socket *sock)         !! 384 void rds_tcp_tune(struct socket *sock)
490 {                                                 385 {
491         struct sock *sk = sock->sk;               386         struct sock *sk = sock->sk;
492         struct net *net = sock_net(sk);           387         struct net *net = sock_net(sk);
493         struct rds_tcp_net *rtn;               !! 388         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
494                                                   389 
495         tcp_sock_set_nodelay(sock->sk);        !! 390         rds_tcp_nonagle(sock);
496         lock_sock(sk);                            391         lock_sock(sk);
497         /* TCP timer functions might access ne << 
498          * a process which created this net na << 
499          */                                    << 
500         if (!sk->sk_net_refcnt) {              << 
501                 if (!maybe_get_net(net)) {     << 
502                         release_sock(sk);      << 
503                         return false;          << 
504                 }                              << 
505                 /* Update ns_tracker to curren << 
506                 __netns_tracker_free(net, &sk- << 
507                                                << 
508                 sk->sk_net_refcnt = 1;         << 
509                 netns_tracker_alloc(net, &sk-> << 
510                 sock_inuse_add(net, 1);        << 
511         }                                      << 
512         rtn = net_generic(net, rds_tcp_netid); << 
513         if (rtn->sndbuf_size > 0) {               392         if (rtn->sndbuf_size > 0) {
514                 sk->sk_sndbuf = rtn->sndbuf_si    393                 sk->sk_sndbuf = rtn->sndbuf_size;
515                 sk->sk_userlocks |= SOCK_SNDBU    394                 sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
516         }                                         395         }
517         if (rtn->rcvbuf_size > 0) {               396         if (rtn->rcvbuf_size > 0) {
518                 sk->sk_rcvbuf = rtn->rcvbuf_si !! 397                 sk->sk_sndbuf = rtn->rcvbuf_size;
519                 sk->sk_userlocks |= SOCK_RCVBU    398                 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
520         }                                         399         }
521         release_sock(sk);                         400         release_sock(sk);
522         return true;                           << 
523 }                                                 401 }
524                                                   402 
525 static void rds_tcp_accept_worker(struct work_    403 static void rds_tcp_accept_worker(struct work_struct *work)
526 {                                                 404 {
527         struct rds_tcp_net *rtn = container_of    405         struct rds_tcp_net *rtn = container_of(work,
528                                                   406                                                struct rds_tcp_net,
529                                                   407                                                rds_tcp_accept_w);
530                                                   408 
531         while (rds_tcp_accept_one(rtn->rds_tcp    409         while (rds_tcp_accept_one(rtn->rds_tcp_listen_sock) == 0)
532                 cond_resched();                   410                 cond_resched();
533 }                                                 411 }
534                                                   412 
535 void rds_tcp_accept_work(struct sock *sk)         413 void rds_tcp_accept_work(struct sock *sk)
536 {                                                 414 {
537         struct net *net = sock_net(sk);           415         struct net *net = sock_net(sk);
538         struct rds_tcp_net *rtn = net_generic(    416         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
539                                                   417 
540         queue_work(rds_wq, &rtn->rds_tcp_accep    418         queue_work(rds_wq, &rtn->rds_tcp_accept_w);
541 }                                                 419 }
542                                                   420 
543 static __net_init int rds_tcp_init_net(struct     421 static __net_init int rds_tcp_init_net(struct net *net)
544 {                                                 422 {
545         struct rds_tcp_net *rtn = net_generic(    423         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
546         struct ctl_table *tbl;                    424         struct ctl_table *tbl;
547         int err = 0;                              425         int err = 0;
548                                                   426 
549         memset(rtn, 0, sizeof(*rtn));             427         memset(rtn, 0, sizeof(*rtn));
550                                                   428 
551         /* {snd, rcv}buf_size default to 0, wh    429         /* {snd, rcv}buf_size default to 0, which implies we let the
552          * stack pick the value, and permit au    430          * stack pick the value, and permit auto-tuning of buffer size.
553          */                                       431          */
554         if (net == &init_net) {                   432         if (net == &init_net) {
555                 tbl = rds_tcp_sysctl_table;       433                 tbl = rds_tcp_sysctl_table;
556         } else {                                  434         } else {
557                 tbl = kmemdup(rds_tcp_sysctl_t    435                 tbl = kmemdup(rds_tcp_sysctl_table,
558                               sizeof(rds_tcp_s    436                               sizeof(rds_tcp_sysctl_table), GFP_KERNEL);
559                 if (!tbl) {                       437                 if (!tbl) {
560                         pr_warn("could not set !! 438                         pr_warn("could not set allocate syctl table\n");
561                         return -ENOMEM;           439                         return -ENOMEM;
562                 }                                 440                 }
563                 rtn->ctl_table = tbl;             441                 rtn->ctl_table = tbl;
564         }                                         442         }
565         tbl[RDS_TCP_SNDBUF].data = &rtn->sndbu    443         tbl[RDS_TCP_SNDBUF].data = &rtn->sndbuf_size;
566         tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbu    444         tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbuf_size;
567         rtn->rds_tcp_sysctl = register_net_sys !! 445         rtn->rds_tcp_sysctl = register_net_sysctl(net, "net/rds/tcp", tbl);
568                                                << 
569         if (!rtn->rds_tcp_sysctl) {               446         if (!rtn->rds_tcp_sysctl) {
570                 pr_warn("could not register sy    447                 pr_warn("could not register sysctl\n");
571                 err = -ENOMEM;                    448                 err = -ENOMEM;
572                 goto fail;                        449                 goto fail;
573         }                                         450         }
574                                                !! 451         rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net);
575 #if IS_ENABLED(CONFIG_IPV6)                    << 
576         rtn->rds_tcp_listen_sock = rds_tcp_lis << 
577 #else                                          << 
578         rtn->rds_tcp_listen_sock = rds_tcp_lis << 
579 #endif                                         << 
580         if (!rtn->rds_tcp_listen_sock) {          452         if (!rtn->rds_tcp_listen_sock) {
581                 pr_warn("could not set up IPv6 !! 453                 pr_warn("could not set up listen sock\n");
582                                                !! 454                 unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
583 #if IS_ENABLED(CONFIG_IPV6)                    !! 455                 rtn->rds_tcp_sysctl = NULL;
584                 /* Try IPv4 as some systems di !! 456                 err = -EAFNOSUPPORT;
585                 rtn->rds_tcp_listen_sock = rds !! 457                 goto fail;
586                 if (!rtn->rds_tcp_listen_sock) << 
587 #endif                                         << 
588                         unregister_net_sysctl_ << 
589                         rtn->rds_tcp_sysctl =  << 
590                         err = -EAFNOSUPPORT;   << 
591                         goto fail;             << 
592 #if IS_ENABLED(CONFIG_IPV6)                    << 
593                 }                              << 
594 #endif                                         << 
595         }                                         458         }
596         INIT_WORK(&rtn->rds_tcp_accept_w, rds_    459         INIT_WORK(&rtn->rds_tcp_accept_w, rds_tcp_accept_worker);
597         return 0;                                 460         return 0;
598                                                   461 
599 fail:                                             462 fail:
600         if (net != &init_net)                     463         if (net != &init_net)
601                 kfree(tbl);                       464                 kfree(tbl);
602         return err;                               465         return err;
603 }                                                 466 }
604                                                   467 
                                                   >> 468 static void __net_exit rds_tcp_exit_net(struct net *net)
                                                   >> 469 {
                                                   >> 470         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
                                                   >> 471 
                                                   >> 472         if (rtn->rds_tcp_sysctl)
                                                   >> 473                 unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
                                                   >> 474 
                                                   >> 475         if (net != &init_net && rtn->ctl_table)
                                                   >> 476                 kfree(rtn->ctl_table);
                                                   >> 477 
                                                   >> 478         /* If rds_tcp_exit_net() is called as a result of netns deletion,
                                                   >> 479          * the rds_tcp_kill_sock() device notifier would already have cleaned
                                                   >> 480          * up the listen socket, thus there is no work to do in this function.
                                                   >> 481          *
                                                   >> 482          * If rds_tcp_exit_net() is called as a result of module unload,
                                                   >> 483          * i.e., due to rds_tcp_exit() -> unregister_pernet_subsys(), then
                                                   >> 484          * we do need to clean up the listen socket here.
                                                   >> 485          */
                                                   >> 486         if (rtn->rds_tcp_listen_sock) {
                                                   >> 487                 struct socket *lsock = rtn->rds_tcp_listen_sock;
                                                   >> 488 
                                                   >> 489                 rtn->rds_tcp_listen_sock = NULL;
                                                   >> 490                 rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
                                                   >> 491         }
                                                   >> 492 }
                                                   >> 493 
                                                   >> 494 static struct pernet_operations rds_tcp_net_ops = {
                                                   >> 495         .init = rds_tcp_init_net,
                                                   >> 496         .exit = rds_tcp_exit_net,
                                                   >> 497         .id = &rds_tcp_netid,
                                                   >> 498         .size = sizeof(struct rds_tcp_net),
                                                   >> 499 };
                                                   >> 500 
                                                   >> 501 /* explicitly send a RST on each socket, thereby releasing any socket refcnts
                                                   >> 502  * that may otherwise hold up netns deletion.
                                                   >> 503  */
                                                   >> 504 static void rds_tcp_conn_paths_destroy(struct rds_connection *conn)
                                                   >> 505 {
                                                   >> 506         struct rds_conn_path *cp;
                                                   >> 507         struct rds_tcp_connection *tc;
                                                   >> 508         int i;
                                                   >> 509         struct sock *sk;
                                                   >> 510 
                                                   >> 511         for (i = 0; i < RDS_MPATH_WORKERS; i++) {
                                                   >> 512                 cp = &conn->c_path[i];
                                                   >> 513                 tc = cp->cp_transport_data;
                                                   >> 514                 if (!tc->t_sock)
                                                   >> 515                         continue;
                                                   >> 516                 sk = tc->t_sock->sk;
                                                   >> 517                 sk->sk_prot->disconnect(sk, 0);
                                                   >> 518                 tcp_done(sk);
                                                   >> 519         }
                                                   >> 520 }
                                                   >> 521 
605 static void rds_tcp_kill_sock(struct net *net)    522 static void rds_tcp_kill_sock(struct net *net)
606 {                                                 523 {
607         struct rds_tcp_connection *tc, *_tc;      524         struct rds_tcp_connection *tc, *_tc;
608         LIST_HEAD(tmp_list);                      525         LIST_HEAD(tmp_list);
609         struct rds_tcp_net *rtn = net_generic(    526         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
610         struct socket *lsock = rtn->rds_tcp_li    527         struct socket *lsock = rtn->rds_tcp_listen_sock;
611                                                   528 
612         rtn->rds_tcp_listen_sock = NULL;          529         rtn->rds_tcp_listen_sock = NULL;
613         rds_tcp_listen_stop(lsock, &rtn->rds_t    530         rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
614         spin_lock_irq(&rds_tcp_conn_lock);        531         spin_lock_irq(&rds_tcp_conn_lock);
615         list_for_each_entry_safe(tc, _tc, &rds    532         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
616                 struct net *c_net = read_pnet( !! 533                 struct net *c_net = tc->t_cpath->cp_conn->c_net;
617                                                   534 
618                 if (net != c_net)              !! 535                 if (net != c_net || !tc->t_sock)
619                         continue;                 536                         continue;
620                 if (!list_has_conn(&tmp_list,  !! 537                 if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
621                         list_move_tail(&tc->t_    538                         list_move_tail(&tc->t_tcp_node, &tmp_list);
622                 } else {                       << 
623                         list_del(&tc->t_tcp_no << 
624                         tc->t_tcp_node_detache << 
625                 }                              << 
626         }                                         539         }
627         spin_unlock_irq(&rds_tcp_conn_lock);      540         spin_unlock_irq(&rds_tcp_conn_lock);
628         list_for_each_entry_safe(tc, _tc, &tmp !! 541         list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node) {
                                                   >> 542                 rds_tcp_conn_paths_destroy(tc->t_cpath->cp_conn);
629                 rds_conn_destroy(tc->t_cpath->    543                 rds_conn_destroy(tc->t_cpath->cp_conn);
                                                   >> 544         }
630 }                                                 545 }
631                                                   546 
632 static void __net_exit rds_tcp_exit_net(struct << 
633 {                                              << 
634         struct rds_tcp_net *rtn = net_generic( << 
635                                                << 
636         rds_tcp_kill_sock(net);                << 
637                                                << 
638         if (rtn->rds_tcp_sysctl)               << 
639                 unregister_net_sysctl_table(rt << 
640                                                << 
641         if (net != &init_net)                  << 
642                 kfree(rtn->ctl_table);         << 
643 }                                              << 
644                                                << 
645 static struct pernet_operations rds_tcp_net_op << 
646         .init = rds_tcp_init_net,              << 
647         .exit = rds_tcp_exit_net,              << 
648         .id = &rds_tcp_netid,                  << 
649         .size = sizeof(struct rds_tcp_net),    << 
650 };                                             << 
651                                                << 
652 void *rds_tcp_listen_sock_def_readable(struct     547 void *rds_tcp_listen_sock_def_readable(struct net *net)
653 {                                                 548 {
654         struct rds_tcp_net *rtn = net_generic(    549         struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
655         struct socket *lsock = rtn->rds_tcp_li    550         struct socket *lsock = rtn->rds_tcp_listen_sock;
656                                                   551 
657         if (!lsock)                               552         if (!lsock)
658                 return NULL;                      553                 return NULL;
659                                                   554 
660         return lsock->sk->sk_user_data;           555         return lsock->sk->sk_user_data;
661 }                                                 556 }
662                                                   557 
                                                   >> 558 static int rds_tcp_dev_event(struct notifier_block *this,
                                                   >> 559                              unsigned long event, void *ptr)
                                                   >> 560 {
                                                   >> 561         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
                                                   >> 562 
                                                   >> 563         /* rds-tcp registers as a pernet subys, so the ->exit will only
                                                   >> 564          * get invoked after network acitivity has quiesced. We need to
                                                   >> 565          * clean up all sockets  to quiesce network activity, and use
                                                   >> 566          * the unregistration of the per-net loopback device as a trigger
                                                   >> 567          * to start that cleanup.
                                                   >> 568          */
                                                   >> 569         if (event == NETDEV_UNREGISTER_FINAL &&
                                                   >> 570             dev->ifindex == LOOPBACK_IFINDEX)
                                                   >> 571                 rds_tcp_kill_sock(dev_net(dev));
                                                   >> 572 
                                                   >> 573         return NOTIFY_DONE;
                                                   >> 574 }
                                                   >> 575 
                                                   >> 576 static struct notifier_block rds_tcp_dev_notifier = {
                                                   >> 577         .notifier_call        = rds_tcp_dev_event,
                                                   >> 578         .priority = -10, /* must be called after other network notifiers */
                                                   >> 579 };
                                                   >> 580 
663 /* when sysctl is used to modify some kernel s    581 /* when sysctl is used to modify some kernel socket parameters,this
664  * function  resets the RDS connections in tha    582  * function  resets the RDS connections in that netns  so that we can
665  * restart with new parameters.  The assumptio    583  * restart with new parameters.  The assumption is that such reset
666  * events are few and far-between.                584  * events are few and far-between.
667  */                                               585  */
668 static void rds_tcp_sysctl_reset(struct net *n    586 static void rds_tcp_sysctl_reset(struct net *net)
669 {                                                 587 {
670         struct rds_tcp_connection *tc, *_tc;      588         struct rds_tcp_connection *tc, *_tc;
671                                                   589 
672         spin_lock_irq(&rds_tcp_conn_lock);        590         spin_lock_irq(&rds_tcp_conn_lock);
673         list_for_each_entry_safe(tc, _tc, &rds    591         list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
674                 struct net *c_net = read_pnet( !! 592                 struct net *c_net = tc->t_cpath->cp_conn->c_net;
675                                                   593 
676                 if (net != c_net || !tc->t_soc    594                 if (net != c_net || !tc->t_sock)
677                         continue;                 595                         continue;
678                                                   596 
679                 /* reconnect with new paramete    597                 /* reconnect with new parameters */
680                 rds_conn_path_drop(tc->t_cpath !! 598                 rds_conn_path_drop(tc->t_cpath);
681         }                                         599         }
682         spin_unlock_irq(&rds_tcp_conn_lock);      600         spin_unlock_irq(&rds_tcp_conn_lock);
683 }                                                 601 }
684                                                   602 
685 static int rds_tcp_skbuf_handler(const struct  !! 603 static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write,
686                                  void *buffer, !! 604                                  void __user *buffer, size_t *lenp,
                                                   >> 605                                  loff_t *fpos)
687 {                                                 606 {
688         struct net *net = current->nsproxy->ne    607         struct net *net = current->nsproxy->net_ns;
689         int err;                                  608         int err;
690                                                   609 
691         err = proc_dointvec_minmax(ctl, write,    610         err = proc_dointvec_minmax(ctl, write, buffer, lenp, fpos);
692         if (err < 0) {                            611         if (err < 0) {
693                 pr_warn("Invalid input. Must b    612                 pr_warn("Invalid input. Must be >= %d\n",
694                         *(int *)(ctl->extra1))    613                         *(int *)(ctl->extra1));
695                 return err;                       614                 return err;
696         }                                         615         }
697         if (write)                                616         if (write)
698                 rds_tcp_sysctl_reset(net);        617                 rds_tcp_sysctl_reset(net);
699         return 0;                                 618         return 0;
700 }                                                 619 }
701                                                   620 
702 static void rds_tcp_exit(void)                    621 static void rds_tcp_exit(void)
703 {                                                 622 {
704         rds_tcp_set_unloading();               << 
705         synchronize_rcu();                     << 
706         rds_info_deregister_func(RDS_INFO_TCP_    623         rds_info_deregister_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
707 #if IS_ENABLED(CONFIG_IPV6)                    !! 624         unregister_pernet_subsys(&rds_tcp_net_ops);
708         rds_info_deregister_func(RDS6_INFO_TCP !! 625         if (unregister_netdevice_notifier(&rds_tcp_dev_notifier))
709 #endif                                         !! 626                 pr_warn("could not unregister rds_tcp_dev_notifier\n");
710         unregister_pernet_device(&rds_tcp_net_ << 
711         rds_tcp_destroy_conns();                  627         rds_tcp_destroy_conns();
712         rds_trans_unregister(&rds_tcp_transpor    628         rds_trans_unregister(&rds_tcp_transport);
713         rds_tcp_recv_exit();                      629         rds_tcp_recv_exit();
714         kmem_cache_destroy(rds_tcp_conn_slab);    630         kmem_cache_destroy(rds_tcp_conn_slab);
715 }                                                 631 }
716 module_exit(rds_tcp_exit);                        632 module_exit(rds_tcp_exit);
717                                                   633 
718 static int __init rds_tcp_init(void)           !! 634 static int rds_tcp_init(void)
719 {                                                 635 {
720         int ret;                                  636         int ret;
721                                                   637 
722         rds_tcp_conn_slab = KMEM_CACHE(rds_tcp !! 638         rds_tcp_conn_slab = kmem_cache_create("rds_tcp_connection",
                                                   >> 639                                               sizeof(struct rds_tcp_connection),
                                                   >> 640                                               0, 0, NULL);
723         if (!rds_tcp_conn_slab) {                 641         if (!rds_tcp_conn_slab) {
724                 ret = -ENOMEM;                    642                 ret = -ENOMEM;
725                 goto out;                         643                 goto out;
726         }                                         644         }
727                                                   645 
728         ret = rds_tcp_recv_init();                646         ret = rds_tcp_recv_init();
729         if (ret)                                  647         if (ret)
730                 goto out_slab;                    648                 goto out_slab;
731                                                   649 
732         ret = register_pernet_device(&rds_tcp_ !! 650         ret = register_pernet_subsys(&rds_tcp_net_ops);
733         if (ret)                                  651         if (ret)
734                 goto out_recv;                    652                 goto out_recv;
735                                                   653 
                                                   >> 654         ret = register_netdevice_notifier(&rds_tcp_dev_notifier);
                                                   >> 655         if (ret) {
                                                   >> 656                 pr_warn("could not register rds_tcp_dev_notifier\n");
                                                   >> 657                 goto out_pernet;
                                                   >> 658         }
                                                   >> 659 
736         rds_trans_register(&rds_tcp_transport)    660         rds_trans_register(&rds_tcp_transport);
737                                                   661 
738         rds_info_register_func(RDS_INFO_TCP_SO    662         rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
739 #if IS_ENABLED(CONFIG_IPV6)                    << 
740         rds_info_register_func(RDS6_INFO_TCP_S << 
741 #endif                                         << 
742                                                   663 
743         goto out;                                 664         goto out;
                                                   >> 665 
                                                   >> 666 out_pernet:
                                                   >> 667         unregister_pernet_subsys(&rds_tcp_net_ops);
744 out_recv:                                         668 out_recv:
745         rds_tcp_recv_exit();                      669         rds_tcp_recv_exit();
746 out_slab:                                         670 out_slab:
747         kmem_cache_destroy(rds_tcp_conn_slab);    671         kmem_cache_destroy(rds_tcp_conn_slab);
748 out:                                              672 out:
749         return ret;                               673         return ret;
750 }                                                 674 }
751 module_init(rds_tcp_init);                        675 module_init(rds_tcp_init);
752                                                   676 
753 MODULE_AUTHOR("Oracle Corporation <rds-devel@o    677 MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>");
754 MODULE_DESCRIPTION("RDS: TCP transport");         678 MODULE_DESCRIPTION("RDS: TCP transport");
755 MODULE_LICENSE("Dual BSD/GPL");                   679 MODULE_LICENSE("Dual BSD/GPL");
                                                   >> 680 
756                                                   681 

~ [ 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