Skip to content

Commit 4005f5c

Browse files
zx2c4davem330
authored andcommitted
wireguard: send/receive: cond_resched() when processing worker ringbuffers
Users with pathological hardware reported CPU stalls on CONFIG_ PREEMPT_VOLUNTARY=y, because the ringbuffers would stay full, meaning these workers would never terminate. That turned out not to be okay on systems without forced preemption, which Sultan observed. This commit adds a cond_resched() to the bottom of each loop iteration, so that these workers don't hog the core. Note that we don't need this on the napi poll worker, since that terminates after its budget is expended. Suggested-by: Sultan Alsawaf <[email protected]> Reported-by: Wang Jian <[email protected]> Fixes: e7096c1 ("net: WireGuard secure network tunnel") Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b673e24 commit 4005f5c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

drivers/net/wireguard/receive.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ void wg_packet_decrypt_worker(struct work_struct *work)
516516
&PACKET_CB(skb)->keypair->receiving)) ?
517517
PACKET_STATE_CRYPTED : PACKET_STATE_DEAD;
518518
wg_queue_enqueue_per_peer_napi(skb, state);
519+
if (need_resched())
520+
cond_resched();
519521
}
520522
}
521523

drivers/net/wireguard/send.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ void wg_packet_tx_worker(struct work_struct *work)
281281

282282
wg_noise_keypair_put(keypair, false);
283283
wg_peer_put(peer);
284+
if (need_resched())
285+
cond_resched();
284286
}
285287
}
286288

@@ -304,6 +306,8 @@ void wg_packet_encrypt_worker(struct work_struct *work)
304306
}
305307
wg_queue_enqueue_per_peer(&PACKET_PEER(first)->tx_queue, first,
306308
state);
309+
if (need_resched())
310+
cond_resched();
307311
}
308312
}
309313

0 commit comments

Comments
 (0)