Skip to content

Commit 06afd2c

Browse files
Sebastian Andrzej Siewiorkuba-moo
authored andcommitted
hsr: Synchronize sending frames to have always incremented outgoing seq nr.
Sending frames via the hsr (master) device requires a sequence number which is tracked in hsr_priv::sequence_nr and protected by hsr_priv::seqnr_lock. Each time a new frame is sent, it will obtain a new id and then send it via the slave devices. Each time a packet is sent (via hsr_forward_do()) the sequence number is checked via hsr_register_frame_out() to ensure that a frame is not handled twice. This make sense for the receiving side to ensure that the frame is not injected into the stack twice after it has been received from both slave ports. There is no locking to cover the sending path which means the following scenario is possible: CPU0 CPU1 hsr_dev_xmit(skb1) hsr_dev_xmit(skb2) fill_frame_info() fill_frame_info() hsr_fill_frame_info() hsr_fill_frame_info() handle_std_frame() handle_std_frame() skb1's sequence_nr = 1 skb2's sequence_nr = 2 hsr_forward_do() hsr_forward_do() hsr_register_frame_out(, 2) // okay, send) hsr_register_frame_out(, 1) // stop, lower seq duplicate Both skbs (or their struct hsr_frame_info) received an unique id. However since skb2 was sent before skb1, the higher sequence number was recorded in hsr_register_frame_out() and the late arriving skb1 was dropped and never sent. This scenario has been observed in a three node HSR setup, with node1 + node2 having ping and iperf running in parallel. From time to time ping reported a missing packet. Based on tracing that missing ping packet did not leave the system. It might be possible (didn't check) to drop the sequence number check on the sending side. But if the higher sequence number leaves on wire before the lower does and the destination receives them in that order and it will drop the packet with the lower sequence number and never inject into the stack. Therefore it seems the only way is to lock the whole path from obtaining the sequence number and sending via dev_queue_xmit() and assuming the packets leave on wire in the same order (and don't get reordered by the NIC). Cover the whole path for the master interface from obtaining the ID until after it has been forwarded via hsr_forward_skb() to ensure the skbs are sent to the NIC in the order of the assigned sequence numbers. Fixes: f421436 ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)") Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d5c7652 commit 06afd2c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

net/hsr/hsr_device.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
219219
skb->dev = master->dev;
220220
skb_reset_mac_header(skb);
221221
skb_reset_mac_len(skb);
222+
spin_lock_bh(&hsr->seqnr_lock);
222223
hsr_forward_skb(skb, master);
224+
spin_unlock_bh(&hsr->seqnr_lock);
223225
} else {
224226
dev_core_stats_tx_dropped_inc(dev);
225227
dev_kfree_skb_any(skb);
@@ -306,7 +308,6 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
306308
hsr_stag->sequence_nr = htons(hsr->sequence_nr);
307309
hsr->sequence_nr++;
308310
}
309-
spin_unlock_bh(&hsr->seqnr_lock);
310311

311312
hsr_stag->tlv.HSR_TLV_type = type;
312313
/* TODO: Why 12 in HSRv0? */
@@ -317,11 +318,13 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
317318
hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
318319
ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr);
319320

320-
if (skb_put_padto(skb, ETH_ZLEN))
321+
if (skb_put_padto(skb, ETH_ZLEN)) {
322+
spin_unlock_bh(&hsr->seqnr_lock);
321323
return;
324+
}
322325

323326
hsr_forward_skb(skb, master);
324-
327+
spin_unlock_bh(&hsr->seqnr_lock);
325328
return;
326329
}
327330

@@ -360,9 +363,8 @@ static void send_prp_supervision_frame(struct hsr_port *master,
360363
return;
361364
}
362365

363-
spin_unlock_bh(&hsr->seqnr_lock);
364-
365366
hsr_forward_skb(skb, master);
367+
spin_unlock_bh(&hsr->seqnr_lock);
366368
}
367369

368370
/* Announce (supervision frame) timer function

net/hsr/hsr_forward.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,9 @@ static void handle_std_frame(struct sk_buff *skb,
509509
frame->is_from_san = true;
510510
} else {
511511
/* Sequence nr for the master node */
512-
spin_lock_bh(&hsr->seqnr_lock);
512+
lockdep_assert_held(&hsr->seqnr_lock);
513513
frame->sequence_nr = hsr->sequence_nr;
514514
hsr->sequence_nr++;
515-
spin_unlock_bh(&hsr->seqnr_lock);
516515
}
517516
}
518517

0 commit comments

Comments
 (0)