Skip to content

Commit e08a9fa

Browse files
hyperenjukuba-moo
authored andcommitted
vhost_net: fix sleeping with preempt-disabled in vhost_net_busy_poll()
syzbot reported "sleeping function called from invalid context" in vhost_net_busy_poll(). Commit 0308813 ("vhost_net: basic polling support") introduced a busy-poll loop and preempt_{disable,enable}() around it, where each iteration calls a sleepable function inside the loop. The purpose of disabling preemption was to keep local_clock()-based timeout accounting on a single CPU, rather than as a requirement of busy-poll itself: https://lore.kernel.org/[email protected] From this perspective, migrate_disable() is sufficient here, so replace preempt_disable() with migrate_disable(), avoiding sleepable accesses from a preempt-disabled context. Fixes: 0308813 ("vhost_net: basic polling support") Tested-by: [email protected] Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/T/ Signed-off-by: Kohei Enju <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 076b8ca commit e08a9fa

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/vhost/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,
560560
busyloop_timeout = poll_rx ? rvq->busyloop_timeout:
561561
tvq->busyloop_timeout;
562562

563-
preempt_disable();
563+
migrate_disable();
564564
endtime = busy_clock() + busyloop_timeout;
565565

566566
while (vhost_can_busy_poll(endtime)) {
@@ -577,7 +577,7 @@ static void vhost_net_busy_poll(struct vhost_net *net,
577577
cpu_relax();
578578
}
579579

580-
preempt_enable();
580+
migrate_enable();
581581

582582
if (poll_rx || sock_has_rx_data(sock))
583583
vhost_net_busy_poll_try_queue(net, vq);

0 commit comments

Comments
 (0)