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

TOMOYO Linux Cross Reference
Linux/net/rds/loop.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/loop.c (Version linux-6.12-rc7) and /net/rds/loop.c (Version linux-5.14.21)


  1 /*                                                  1 /*
  2  * Copyright (c) 2006, 2017 Oracle and/or its       2  * Copyright (c) 2006, 2017 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 <net/net_namespace.h>                     36 #include <net/net_namespace.h>
 37 #include <net/netns/generic.h>                     37 #include <net/netns/generic.h>
 38 #include <linux/ipv6.h>                            38 #include <linux/ipv6.h>
 39                                                    39 
 40 #include "rds_single_path.h"                       40 #include "rds_single_path.h"
 41 #include "rds.h"                                   41 #include "rds.h"
 42 #include "loop.h"                                  42 #include "loop.h"
 43                                                    43 
 44 static DEFINE_SPINLOCK(loop_conns_lock);           44 static DEFINE_SPINLOCK(loop_conns_lock);
 45 static LIST_HEAD(loop_conns);                      45 static LIST_HEAD(loop_conns);
 46 static atomic_t rds_loop_unloading = ATOMIC_IN     46 static atomic_t rds_loop_unloading = ATOMIC_INIT(0);
 47                                                    47 
 48 static void rds_loop_set_unloading(void)           48 static void rds_loop_set_unloading(void)
 49 {                                                  49 {
 50         atomic_set(&rds_loop_unloading, 1);        50         atomic_set(&rds_loop_unloading, 1);
 51 }                                                  51 }
 52                                                    52 
 53 static bool rds_loop_is_unloading(struct rds_c     53 static bool rds_loop_is_unloading(struct rds_connection *conn)
 54 {                                                  54 {
 55         return atomic_read(&rds_loop_unloading     55         return atomic_read(&rds_loop_unloading) != 0;
 56 }                                                  56 }
 57                                                    57 
 58 /*                                                 58 /*
 59  * This 'loopback' transport is a special case     59  * This 'loopback' transport is a special case for flows that originate
 60  * and terminate on the same machine.              60  * and terminate on the same machine.
 61  *                                                 61  *
 62  * Connection build-up notices if the destinat     62  * Connection build-up notices if the destination address is thought of
 63  * as a local address by a transport.  At that     63  * as a local address by a transport.  At that time it decides to use the
 64  * loopback transport instead of the bound tra     64  * loopback transport instead of the bound transport of the sending socket.
 65  *                                                 65  *
 66  * The loopback transport's sending path just      66  * The loopback transport's sending path just hands the sent rds_message
 67  * straight to the receiving path via an embed     67  * straight to the receiving path via an embedded rds_incoming.
 68  */                                                68  */
 69                                                    69 
 70 /*                                                 70 /*
 71  * Usually a message transits both the sender      71  * Usually a message transits both the sender and receiver's conns as it
 72  * flows to the receiver.  In the loopback cas     72  * flows to the receiver.  In the loopback case, though, the receive path
 73  * is handed the sending conn so the sense of      73  * is handed the sending conn so the sense of the addresses is reversed.
 74  */                                                74  */
 75 static int rds_loop_xmit(struct rds_connection     75 static int rds_loop_xmit(struct rds_connection *conn, struct rds_message *rm,
 76                          unsigned int hdr_off,     76                          unsigned int hdr_off, unsigned int sg,
 77                          unsigned int off)         77                          unsigned int off)
 78 {                                                  78 {
 79         struct scatterlist *sgp = &rm->data.op     79         struct scatterlist *sgp = &rm->data.op_sg[sg];
 80         int ret = sizeof(struct rds_header) +      80         int ret = sizeof(struct rds_header) +
 81                         be32_to_cpu(rm->m_inc.     81                         be32_to_cpu(rm->m_inc.i_hdr.h_len);
 82                                                    82 
 83         /* Do not send cong updates to loopbac     83         /* Do not send cong updates to loopback */
 84         if (rm->m_inc.i_hdr.h_flags & RDS_FLAG     84         if (rm->m_inc.i_hdr.h_flags & RDS_FLAG_CONG_BITMAP) {
 85                 rds_cong_map_updated(conn->c_f     85                 rds_cong_map_updated(conn->c_fcong, ~(u64) 0);
 86                 ret = min_t(int, ret, sgp->len     86                 ret = min_t(int, ret, sgp->length - conn->c_xmit_data_off);
 87                 goto out;                          87                 goto out;
 88         }                                          88         }
 89                                                    89 
 90         BUG_ON(hdr_off || sg || off);              90         BUG_ON(hdr_off || sg || off);
 91                                                    91 
 92         rds_inc_init(&rm->m_inc, conn, &conn->     92         rds_inc_init(&rm->m_inc, conn, &conn->c_laddr);
 93         /* For the embedded inc. Matching put      93         /* For the embedded inc. Matching put is in loop_inc_free() */
 94         rds_message_addref(rm);                    94         rds_message_addref(rm);
 95                                                    95 
 96         rds_recv_incoming(conn, &conn->c_laddr     96         rds_recv_incoming(conn, &conn->c_laddr, &conn->c_faddr, &rm->m_inc,
 97                           GFP_KERNEL);             97                           GFP_KERNEL);
 98                                                    98 
 99         rds_send_drop_acked(conn, be64_to_cpu(     99         rds_send_drop_acked(conn, be64_to_cpu(rm->m_inc.i_hdr.h_sequence),
100                             NULL);                100                             NULL);
101                                                   101 
102         rds_inc_put(&rm->m_inc);                  102         rds_inc_put(&rm->m_inc);
103 out:                                              103 out:
104         return ret;                               104         return ret;
105 }                                                 105 }
106                                                   106 
107 /*                                                107 /*
108  * See rds_loop_xmit(). Since our inc is embed    108  * See rds_loop_xmit(). Since our inc is embedded in the rm, we
109  * make sure the rm lives at least until the i    109  * make sure the rm lives at least until the inc is done.
110  */                                               110  */
111 static void rds_loop_inc_free(struct rds_incom    111 static void rds_loop_inc_free(struct rds_incoming *inc)
112 {                                                 112 {
113         struct rds_message *rm = container_of(    113         struct rds_message *rm = container_of(inc, struct rds_message, m_inc);
114                                                   114 
115         rds_message_put(rm);                      115         rds_message_put(rm);
116 }                                                 116 }
117                                                   117 
118 /* we need to at least give the thread somethi    118 /* we need to at least give the thread something to succeed */
119 static int rds_loop_recv_path(struct rds_conn_    119 static int rds_loop_recv_path(struct rds_conn_path *cp)
120 {                                                 120 {
121         return 0;                                 121         return 0;
122 }                                                 122 }
123                                                   123 
124 struct rds_loop_connection {                      124 struct rds_loop_connection {
125         struct list_head loop_node;               125         struct list_head loop_node;
126         struct rds_connection *conn;              126         struct rds_connection *conn;
127 };                                                127 };
128                                                   128 
129 /*                                                129 /*
130  * Even the loopback transport needs to keep t    130  * Even the loopback transport needs to keep track of its connections,
131  * so it can call rds_conn_destroy() on them o    131  * so it can call rds_conn_destroy() on them on exit. N.B. there are
132  * 1+ loopback addresses (127.*.*.*) so it's n    132  * 1+ loopback addresses (127.*.*.*) so it's not a bug to have
133  * multiple loopback conns allocated, although    133  * multiple loopback conns allocated, although rather useless.
134  */                                               134  */
135 static int rds_loop_conn_alloc(struct rds_conn    135 static int rds_loop_conn_alloc(struct rds_connection *conn, gfp_t gfp)
136 {                                                 136 {
137         struct rds_loop_connection *lc;           137         struct rds_loop_connection *lc;
138         unsigned long flags;                      138         unsigned long flags;
139                                                   139 
140         lc = kzalloc(sizeof(struct rds_loop_co    140         lc = kzalloc(sizeof(struct rds_loop_connection), gfp);
141         if (!lc)                                  141         if (!lc)
142                 return -ENOMEM;                   142                 return -ENOMEM;
143                                                   143 
144         INIT_LIST_HEAD(&lc->loop_node);           144         INIT_LIST_HEAD(&lc->loop_node);
145         lc->conn = conn;                          145         lc->conn = conn;
146         conn->c_transport_data = lc;              146         conn->c_transport_data = lc;
147                                                   147 
148         spin_lock_irqsave(&loop_conns_lock, fl    148         spin_lock_irqsave(&loop_conns_lock, flags);
149         list_add_tail(&lc->loop_node, &loop_co    149         list_add_tail(&lc->loop_node, &loop_conns);
150         spin_unlock_irqrestore(&loop_conns_loc    150         spin_unlock_irqrestore(&loop_conns_lock, flags);
151                                                   151 
152         return 0;                                 152         return 0;
153 }                                                 153 }
154                                                   154 
155 static void rds_loop_conn_free(void *arg)         155 static void rds_loop_conn_free(void *arg)
156 {                                                 156 {
157         struct rds_loop_connection *lc = arg;     157         struct rds_loop_connection *lc = arg;
158         unsigned long flags;                      158         unsigned long flags;
159                                                   159 
160         rdsdebug("lc %p\n", lc);                  160         rdsdebug("lc %p\n", lc);
161         spin_lock_irqsave(&loop_conns_lock, fl    161         spin_lock_irqsave(&loop_conns_lock, flags);
162         list_del(&lc->loop_node);                 162         list_del(&lc->loop_node);
163         spin_unlock_irqrestore(&loop_conns_loc    163         spin_unlock_irqrestore(&loop_conns_lock, flags);
164         kfree(lc);                                164         kfree(lc);
165 }                                                 165 }
166                                                   166 
167 static int rds_loop_conn_path_connect(struct r    167 static int rds_loop_conn_path_connect(struct rds_conn_path *cp)
168 {                                                 168 {
169         rds_connect_complete(cp->cp_conn);        169         rds_connect_complete(cp->cp_conn);
170         return 0;                                 170         return 0;
171 }                                                 171 }
172                                                   172 
173 static void rds_loop_conn_path_shutdown(struct    173 static void rds_loop_conn_path_shutdown(struct rds_conn_path *cp)
174 {                                                 174 {
175 }                                                 175 }
176                                                   176 
177 void rds_loop_exit(void)                          177 void rds_loop_exit(void)
178 {                                                 178 {
179         struct rds_loop_connection *lc, *_lc;     179         struct rds_loop_connection *lc, *_lc;
180         LIST_HEAD(tmp_list);                      180         LIST_HEAD(tmp_list);
181                                                   181 
182         rds_loop_set_unloading();                 182         rds_loop_set_unloading();
183         synchronize_rcu();                        183         synchronize_rcu();
184         /* avoid calling conn_destroy with irq    184         /* avoid calling conn_destroy with irqs off */
185         spin_lock_irq(&loop_conns_lock);          185         spin_lock_irq(&loop_conns_lock);
186         list_splice(&loop_conns, &tmp_list);      186         list_splice(&loop_conns, &tmp_list);
187         INIT_LIST_HEAD(&loop_conns);              187         INIT_LIST_HEAD(&loop_conns);
188         spin_unlock_irq(&loop_conns_lock);        188         spin_unlock_irq(&loop_conns_lock);
189                                                   189 
190         list_for_each_entry_safe(lc, _lc, &tmp    190         list_for_each_entry_safe(lc, _lc, &tmp_list, loop_node) {
191                 WARN_ON(lc->conn->c_passive);     191                 WARN_ON(lc->conn->c_passive);
192                 rds_conn_destroy(lc->conn);       192                 rds_conn_destroy(lc->conn);
193         }                                         193         }
194 }                                                 194 }
195                                                   195 
196 static void rds_loop_kill_conns(struct net *ne    196 static void rds_loop_kill_conns(struct net *net)
197 {                                                 197 {
198         struct rds_loop_connection *lc, *_lc;     198         struct rds_loop_connection *lc, *_lc;
199         LIST_HEAD(tmp_list);                      199         LIST_HEAD(tmp_list);
200                                                   200 
201         spin_lock_irq(&loop_conns_lock);          201         spin_lock_irq(&loop_conns_lock);
202         list_for_each_entry_safe(lc, _lc, &loo    202         list_for_each_entry_safe(lc, _lc, &loop_conns, loop_node)  {
203                 struct net *c_net = read_pnet(    203                 struct net *c_net = read_pnet(&lc->conn->c_net);
204                                                   204 
205                 if (net != c_net)                 205                 if (net != c_net)
206                         continue;                 206                         continue;
207                 list_move_tail(&lc->loop_node,    207                 list_move_tail(&lc->loop_node, &tmp_list);
208         }                                         208         }
209         spin_unlock_irq(&loop_conns_lock);        209         spin_unlock_irq(&loop_conns_lock);
210                                                   210 
211         list_for_each_entry_safe(lc, _lc, &tmp    211         list_for_each_entry_safe(lc, _lc, &tmp_list, loop_node) {
212                 WARN_ON(lc->conn->c_passive);     212                 WARN_ON(lc->conn->c_passive);
213                 rds_conn_destroy(lc->conn);       213                 rds_conn_destroy(lc->conn);
214         }                                         214         }
215 }                                                 215 }
216                                                   216 
217 static void __net_exit rds_loop_exit_net(struc    217 static void __net_exit rds_loop_exit_net(struct net *net)
218 {                                                 218 {
219         rds_loop_kill_conns(net);                 219         rds_loop_kill_conns(net);
220 }                                                 220 }
221                                                   221 
222 static struct pernet_operations rds_loop_net_o    222 static struct pernet_operations rds_loop_net_ops = {
223         .exit = rds_loop_exit_net,                223         .exit = rds_loop_exit_net,
224 };                                                224 };
225                                                   225 
226 int rds_loop_net_init(void)                       226 int rds_loop_net_init(void)
227 {                                                 227 {
228         return register_pernet_device(&rds_loo    228         return register_pernet_device(&rds_loop_net_ops);
229 }                                                 229 }
230                                                   230 
231 void rds_loop_net_exit(void)                      231 void rds_loop_net_exit(void)
232 {                                                 232 {
233         unregister_pernet_device(&rds_loop_net    233         unregister_pernet_device(&rds_loop_net_ops);
234 }                                                 234 }
235                                                   235 
236 /*                                                236 /*
237  * This is missing .xmit_* because loop doesn'    237  * This is missing .xmit_* because loop doesn't go through generic
238  * rds_send_xmit() and doesn't call rds_recv_i    238  * rds_send_xmit() and doesn't call rds_recv_incoming().  .listen_stop and
239  * .laddr_check are missing because transport.    239  * .laddr_check are missing because transport.c doesn't iterate over
240  * rds_loop_transport.                            240  * rds_loop_transport.
241  */                                               241  */
242 struct rds_transport rds_loop_transport = {       242 struct rds_transport rds_loop_transport = {
243         .xmit                   = rds_loop_xmi    243         .xmit                   = rds_loop_xmit,
244         .recv_path              = rds_loop_rec    244         .recv_path              = rds_loop_recv_path,
245         .conn_alloc             = rds_loop_con    245         .conn_alloc             = rds_loop_conn_alloc,
246         .conn_free              = rds_loop_con    246         .conn_free              = rds_loop_conn_free,
247         .conn_path_connect      = rds_loop_con    247         .conn_path_connect      = rds_loop_conn_path_connect,
248         .conn_path_shutdown     = rds_loop_con    248         .conn_path_shutdown     = rds_loop_conn_path_shutdown,
249         .inc_copy_to_user       = rds_message_    249         .inc_copy_to_user       = rds_message_inc_copy_to_user,
250         .inc_free               = rds_loop_inc    250         .inc_free               = rds_loop_inc_free,
251         .t_name                 = "loopback",     251         .t_name                 = "loopback",
252         .t_type                 = RDS_TRANS_LO    252         .t_type                 = RDS_TRANS_LOOP,
253         .t_unloading            = rds_loop_is_    253         .t_unloading            = rds_loop_is_unloading,
254 };                                                254 };
255                                                   255 

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