Skip to content

Commit a059ef8

Browse files
committed
Merge branch 'tpacket_snd-bugs' into main
Yun Lu says: ==================== fix two issues and optimize code on tpacket_snd() This series fix two issues and optimize the code on tpacket_snd(): 1, fix the SO_SNDTIMEO constraint not effective due to the changes in commit 581073f; 2, fix a soft lockup issue on a specific edge case, and also optimize the loop logic to be clearer and more obvious; --- Changes in v5: - Still combine fix and optimization together, change to while(1). Thanks: Willem de Bruijn. - Link to v4: https://lore.kernel.org/all/[email protected]/ Changes in v4: - Fix a typo and add the missing semicolon. Thanks: Simon Horman. - Split the second patch into two, one to fix, another to optimize. Thanks: Willem de Bruijn - Link to v3: https://lore.kernel.org/all/[email protected]/ Changes in v3: - Split in two different patches. - Simplify the code and reuse ph to continue. Thanks: Eric Dumazet. - Link to v2: https://lore.kernel.org/all/[email protected]/ Changes in v2: - Add a Fixes tag. - Link to v1: https://lore.kernel.org/all/[email protected]/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 5e28d5a + 55f0bfc commit a059ef8

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

net/packet/af_packet.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
27852785
int len_sum = 0;
27862786
int status = TP_STATUS_AVAILABLE;
27872787
int hlen, tlen, copylen = 0;
2788-
long timeo = 0;
2788+
long timeo;
27892789

27902790
mutex_lock(&po->pg_vec_lock);
27912791

@@ -2839,22 +2839,28 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
28392839
if ((size_max > dev->mtu + reserve + VLAN_HLEN) && !vnet_hdr_sz)
28402840
size_max = dev->mtu + reserve + VLAN_HLEN;
28412841

2842+
timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT);
28422843
reinit_completion(&po->skb_completion);
28432844

28442845
do {
28452846
ph = packet_current_frame(po, &po->tx_ring,
28462847
TP_STATUS_SEND_REQUEST);
28472848
if (unlikely(ph == NULL)) {
2848-
if (need_wait && skb) {
2849-
timeo = sock_sndtimeo(&po->sk, msg->msg_flags & MSG_DONTWAIT);
2849+
/* Note: packet_read_pending() might be slow if we
2850+
* have to call it as it's per_cpu variable, but in
2851+
* fast-path we don't have to call it, only when ph
2852+
* is NULL, we need to check the pending_refcnt.
2853+
*/
2854+
if (need_wait && packet_read_pending(&po->tx_ring)) {
28502855
timeo = wait_for_completion_interruptible_timeout(&po->skb_completion, timeo);
28512856
if (timeo <= 0) {
28522857
err = !timeo ? -ETIMEDOUT : -ERESTARTSYS;
28532858
goto out_put;
28542859
}
2855-
}
2856-
/* check for additional frames */
2857-
continue;
2860+
/* check for additional frames */
2861+
continue;
2862+
} else
2863+
break;
28582864
}
28592865

28602866
skb = NULL;
@@ -2943,14 +2949,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
29432949
}
29442950
packet_increment_head(&po->tx_ring);
29452951
len_sum += tp_len;
2946-
} while (likely((ph != NULL) ||
2947-
/* Note: packet_read_pending() might be slow if we have
2948-
* to call it as it's per_cpu variable, but in fast-path
2949-
* we already short-circuit the loop with the first
2950-
* condition, and luckily don't have to go that path
2951-
* anyway.
2952-
*/
2953-
(need_wait && packet_read_pending(&po->tx_ring))));
2952+
} while (1);
29542953

29552954
err = len_sum;
29562955
goto out_put;

0 commit comments

Comments
 (0)