Skip to content

Commit 512137e

Browse files
Erik Hugnedavem330
authored andcommitted
tipc: remove interface state mirroring in bearer
struct 'tipc_bearer' is a generic representation of the underlying media type, and exists in a one-to-one relationship to each interface TIPC is using. The struct contains a 'blocked' flag that mirrors the operational and execution state of the represented interface, and is updated through notification calls from the latter. The users of tipc_bearer are checking this flag before each attempt to send a packet via the interface. This state mirroring serves no purpose in the current code base. TIPC links will not discover a media failure any faster through this mechanism, and in reality the flag only adds overhead at packet sending and reception. Furthermore, the fact that the flag needs to be protected by a spinlock aggregated into tipc_bearer has turned out to cause a serious and completely unnecessary deadlock problem. CPU0 CPU1 ---- ---- Time 0: bearer_disable() link_timeout() Time 1: spin_lock_bh(&b_ptr->lock) tipc_link_push_queue() Time 2: tipc_link_delete() tipc_bearer_blocked(b_ptr) Time 3: k_cancel_timer(&req->timer) spin_lock_bh(&b_ptr->lock) Time 4: del_timer_sync(&req->timer) I.e., del_timer_sync() on CPU0 never returns, because the timer handler on CPU1 is waiting for the bearer lock. We eliminate the 'blocked' flag from struct tipc_bearer, along with all tests on this flag. This not only resolves the deadlock, but also simplifies and speeds up the data path execution of TIPC. It also fits well into our ongoing effort to make the locking policy simpler and more manageable. An effect of this change is that we can get rid of functions such as tipc_bearer_blocked(), tipc_continue() and tipc_block_bearer(). We replace the latter with a new function, tipc_reset_bearer(), which resets all links associated to the bearer immediately after an interface goes down. A user might notice one slight change in link behaviour after this change. When an interface goes down, (e.g. through a NETDEV_DOWN event) all attached links will be reset immediately, instead of leaving it to each link to detect the failure through a timer-driven mechanism. We consider this an improvement, and see no obvious risks with the new behavior. Signed-off-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Paul Gortmaker <Paul.Gortmaker@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b73e9e3 commit 512137e

7 files changed

Lines changed: 28 additions & 117 deletions

File tree

‎net/tipc/bcast.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,6 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
621621
if (!p)
622622
break; /* No more bearers to try */
623623

624-
if (tipc_bearer_blocked(p)) {
625-
if (!s || tipc_bearer_blocked(s))
626-
continue; /* Can't use either bearer */
627-
b = s;
628-
}
629-
630624
tipc_nmap_diff(&bcbearer->remains, &b->nodes,
631625
&bcbearer->remains_new);
632626
if (bcbearer->remains_new.count == bcbearer->remains.count)

‎net/tipc/bearer.c‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -275,31 +275,6 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
275275
tipc_disc_remove_dest(b_ptr->link_req);
276276
}
277277

278-
/*
279-
* Interrupt enabling new requests after bearer blocking:
280-
* See bearer_send().
281-
*/
282-
void tipc_continue(struct tipc_bearer *b)
283-
{
284-
spin_lock_bh(&b->lock);
285-
b->blocked = 0;
286-
spin_unlock_bh(&b->lock);
287-
}
288-
289-
/*
290-
* tipc_bearer_blocked - determines if bearer is currently blocked
291-
*/
292-
int tipc_bearer_blocked(struct tipc_bearer *b)
293-
{
294-
int res;
295-
296-
spin_lock_bh(&b->lock);
297-
res = b->blocked;
298-
spin_unlock_bh(&b->lock);
299-
300-
return res;
301-
}
302-
303278
/**
304279
* tipc_enable_bearer - enable bearer with the given name
305280
*/
@@ -420,17 +395,16 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
420395
}
421396

422397
/**
423-
* tipc_block_bearer - Block the bearer, and reset all its links
398+
* tipc_reset_bearer - Reset all links established over this bearer
424399
*/
425-
int tipc_block_bearer(struct tipc_bearer *b_ptr)
400+
int tipc_reset_bearer(struct tipc_bearer *b_ptr)
426401
{
427402
struct tipc_link *l_ptr;
428403
struct tipc_link *temp_l_ptr;
429404

430405
read_lock_bh(&tipc_net_lock);
431-
pr_info("Blocking bearer <%s>\n", b_ptr->name);
406+
pr_info("Resetting bearer <%s>\n", b_ptr->name);
432407
spin_lock_bh(&b_ptr->lock);
433-
b_ptr->blocked = 1;
434408
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
435409
struct tipc_node *n_ptr = l_ptr->owner;
436410

@@ -456,7 +430,6 @@ static void bearer_disable(struct tipc_bearer *b_ptr)
456430

457431
pr_info("Disabling bearer <%s>\n", b_ptr->name);
458432
spin_lock_bh(&b_ptr->lock);
459-
b_ptr->blocked = 1;
460433
b_ptr->media->disable_media(b_ptr);
461434
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
462435
tipc_link_delete(l_ptr);

‎net/tipc/bearer.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ struct tipc_media {
108108
* struct tipc_bearer - TIPC bearer structure
109109
* @usr_handle: pointer to additional media-specific information about bearer
110110
* @mtu: max packet size bearer can support
111-
* @blocked: non-zero if bearer is blocked
112111
* @lock: spinlock for controlling access to bearer
113112
* @addr: media-specific address associated with bearer
114113
* @name: bearer name (format = media:interface)
@@ -130,7 +129,6 @@ struct tipc_media {
130129
struct tipc_bearer {
131130
void *usr_handle; /* initalized by media */
132131
u32 mtu; /* initalized by media */
133-
int blocked; /* initalized by media */
134132
struct tipc_media_addr addr; /* initalized by media */
135133
char name[TIPC_MAX_BEARER_NAME];
136134
spinlock_t lock;
@@ -163,8 +161,7 @@ int tipc_register_media(struct tipc_media *m_ptr);
163161

164162
void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
165163

166-
int tipc_block_bearer(struct tipc_bearer *b_ptr);
167-
void tipc_continue(struct tipc_bearer *tb_ptr);
164+
int tipc_reset_bearer(struct tipc_bearer *b_ptr);
168165

169166
int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority);
170167
int tipc_disable_bearer(const char *name);
@@ -194,7 +191,6 @@ void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest);
194191
struct tipc_bearer *tipc_bearer_find(const char *name);
195192
struct tipc_bearer *tipc_bearer_find_interface(const char *if_name);
196193
struct tipc_media *tipc_media_find(const char *name);
197-
int tipc_bearer_blocked(struct tipc_bearer *b_ptr);
198194
void tipc_bearer_stop(void);
199195

200196
/**

‎net/tipc/discover.c‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr)
239239
/* Accept discovery message & send response, if necessary */
240240
link_fully_up = link_working_working(link);
241241

242-
if ((type == DSC_REQ_MSG) && !link_fully_up && !b_ptr->blocked) {
242+
if ((type == DSC_REQ_MSG) && !link_fully_up) {
243243
rbuf = tipc_disc_init_msg(DSC_RESP_MSG, orig, b_ptr);
244244
if (rbuf) {
245245
tipc_bearer_send(b_ptr, rbuf, &media_addr);
@@ -287,16 +287,6 @@ void tipc_disc_remove_dest(struct tipc_link_req *req)
287287
disc_update(req);
288288
}
289289

290-
/**
291-
* disc_send_msg - send link setup request message
292-
* @req: ptr to link request structure
293-
*/
294-
static void disc_send_msg(struct tipc_link_req *req)
295-
{
296-
if (!req->bearer->blocked)
297-
tipc_bearer_send(req->bearer, req->buf, &req->dest);
298-
}
299-
300290
/**
301291
* disc_timeout - send a periodic link setup request
302292
* @req: ptr to link request structure
@@ -322,7 +312,8 @@ static void disc_timeout(struct tipc_link_req *req)
322312
* hold at fast polling rate if don't have any associated nodes,
323313
* otherwise hold at slow polling rate
324314
*/
325-
disc_send_msg(req);
315+
tipc_bearer_send(req->bearer, req->buf, &req->dest);
316+
326317

327318
req->timer_intv *= 2;
328319
if (req->num_nodes)
@@ -368,7 +359,7 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest,
368359
k_init_timer(&req->timer, (Handler)disc_timeout, (unsigned long)req);
369360
k_start_timer(&req->timer, req->timer_intv);
370361
b_ptr->link_req = req;
371-
disc_send_msg(req);
362+
tipc_bearer_send(req->bearer, req->buf, &req->dest);
372363
return 0;
373364
}
374365

‎net/tipc/eth_media.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ static int enable_media(struct tipc_bearer *tb_ptr)
199199
tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_ETH;
200200
tb_ptr->bcast_addr.broadcast = 1;
201201
tb_ptr->mtu = dev->mtu;
202-
tb_ptr->blocked = 0;
203202
eth_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr);
204203
return 0;
205204
}
@@ -263,20 +262,11 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
263262
switch (evt) {
264263
case NETDEV_CHANGE:
265264
if (netif_carrier_ok(dev))
266-
tipc_continue(eb_ptr->bearer);
267-
else
268-
tipc_block_bearer(eb_ptr->bearer);
269-
break;
270-
case NETDEV_UP:
271-
tipc_continue(eb_ptr->bearer);
272-
break;
265+
break;
273266
case NETDEV_DOWN:
274-
tipc_block_bearer(eb_ptr->bearer);
275-
break;
276267
case NETDEV_CHANGEMTU:
277268
case NETDEV_CHANGEADDR:
278-
tipc_block_bearer(eb_ptr->bearer);
279-
tipc_continue(eb_ptr->bearer);
269+
tipc_reset_bearer(eb_ptr->bearer);
280270
break;
281271
case NETDEV_UNREGISTER:
282272
case NETDEV_CHANGENAME:

‎net/tipc/ib_media.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ static int enable_media(struct tipc_bearer *tb_ptr)
192192
tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_IB;
193193
tb_ptr->bcast_addr.broadcast = 1;
194194
tb_ptr->mtu = dev->mtu;
195-
tb_ptr->blocked = 0;
196195
ib_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr);
197196
return 0;
198197
}
@@ -256,20 +255,11 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,
256255
switch (evt) {
257256
case NETDEV_CHANGE:
258257
if (netif_carrier_ok(dev))
259-
tipc_continue(ib_ptr->bearer);
260-
else
261-
tipc_block_bearer(ib_ptr->bearer);
262-
break;
263-
case NETDEV_UP:
264-
tipc_continue(ib_ptr->bearer);
265-
break;
258+
break;
266259
case NETDEV_DOWN:
267-
tipc_block_bearer(ib_ptr->bearer);
268-
break;
269260
case NETDEV_CHANGEMTU:
270261
case NETDEV_CHANGEADDR:
271-
tipc_block_bearer(ib_ptr->bearer);
272-
tipc_continue(ib_ptr->bearer);
262+
tipc_reset_bearer(ib_ptr->bearer);
273263
break;
274264
case NETDEV_UNREGISTER:
275265
case NETDEV_CHANGENAME:

‎net/tipc/link.c‎

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,7 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf)
790790
return link_send_long_buf(l_ptr, buf);
791791

792792
/* Packet can be queued or sent. */
793-
if (likely(!tipc_bearer_blocked(l_ptr->b_ptr) &&
794-
!link_congested(l_ptr))) {
793+
if (likely(!link_congested(l_ptr))) {
795794
link_add_to_outqueue(l_ptr, buf, msg);
796795

797796
tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
@@ -957,14 +956,13 @@ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf,
957956

958957
if (likely(!link_congested(l_ptr))) {
959958
if (likely(msg_size(msg) <= l_ptr->max_pkt)) {
960-
if (likely(!tipc_bearer_blocked(l_ptr->b_ptr))) {
961-
link_add_to_outqueue(l_ptr, buf, msg);
962-
tipc_bearer_send(l_ptr->b_ptr, buf,
963-
&l_ptr->media_addr);
964-
l_ptr->unacked_window = 0;
965-
return res;
966-
}
967-
} else
959+
link_add_to_outqueue(l_ptr, buf, msg);
960+
tipc_bearer_send(l_ptr->b_ptr, buf,
961+
&l_ptr->media_addr);
962+
l_ptr->unacked_window = 0;
963+
return res;
964+
}
965+
else
968966
*used_max_pkt = l_ptr->max_pkt;
969967
}
970968
return tipc_link_send_buf(l_ptr, buf); /* All other cases */
@@ -1013,8 +1011,7 @@ int tipc_link_send_sections_fast(struct tipc_port *sender,
10131011
}
10141012

10151013
/* Exit if link (or bearer) is congested */
1016-
if (link_congested(l_ptr) ||
1017-
tipc_bearer_blocked(l_ptr->b_ptr)) {
1014+
if (link_congested(l_ptr)) {
10181015
res = link_schedule_port(l_ptr,
10191016
sender->ref, res);
10201017
goto exit;
@@ -1281,9 +1278,6 @@ void tipc_link_push_queue(struct tipc_link *l_ptr)
12811278
{
12821279
u32 res;
12831280

1284-
if (tipc_bearer_blocked(l_ptr->b_ptr))
1285-
return;
1286-
12871281
do {
12881282
res = tipc_link_push_packet(l_ptr);
12891283
} while (!res);
@@ -1370,26 +1364,15 @@ void tipc_link_retransmit(struct tipc_link *l_ptr, struct sk_buff *buf,
13701364

13711365
msg = buf_msg(buf);
13721366

1373-
if (tipc_bearer_blocked(l_ptr->b_ptr)) {
1374-
if (l_ptr->retransm_queue_size == 0) {
1375-
l_ptr->retransm_queue_head = msg_seqno(msg);
1376-
l_ptr->retransm_queue_size = retransmits;
1377-
} else {
1378-
pr_err("Unexpected retransmit on link %s (qsize=%d)\n",
1379-
l_ptr->name, l_ptr->retransm_queue_size);
1367+
/* Detect repeated retransmit failures */
1368+
if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1369+
if (++l_ptr->stale_count > 100) {
1370+
link_retransmit_failure(l_ptr, buf);
1371+
return;
13801372
}
1381-
return;
13821373
} else {
1383-
/* Detect repeated retransmit failures on unblocked bearer */
1384-
if (l_ptr->last_retransmitted == msg_seqno(msg)) {
1385-
if (++l_ptr->stale_count > 100) {
1386-
link_retransmit_failure(l_ptr, buf);
1387-
return;
1388-
}
1389-
} else {
1390-
l_ptr->last_retransmitted = msg_seqno(msg);
1391-
l_ptr->stale_count = 1;
1392-
}
1374+
l_ptr->last_retransmitted = msg_seqno(msg);
1375+
l_ptr->stale_count = 1;
13931376
}
13941377

13951378
while (retransmits && (buf != l_ptr->next_out) && buf) {
@@ -1861,12 +1844,6 @@ void tipc_link_send_proto_msg(struct tipc_link *l_ptr, u32 msg_typ,
18611844
skb_copy_to_linear_data(buf, msg, sizeof(l_ptr->proto_msg));
18621845
buf->priority = TC_PRIO_CONTROL;
18631846

1864-
/* Defer message if bearer is already blocked */
1865-
if (tipc_bearer_blocked(l_ptr->b_ptr)) {
1866-
l_ptr->proto_msg_queue = buf;
1867-
return;
1868-
}
1869-
18701847
tipc_bearer_send(l_ptr->b_ptr, buf, &l_ptr->media_addr);
18711848
l_ptr->unacked_window = 0;
18721849
kfree_skb(buf);

0 commit comments

Comments
 (0)