Skip to contentSkip to conversation

Net patches for QEMU 2.0

GIT PULL Applied Stefan Hajnoczi 2 participants 3 messages Mar 12, 2014 Networking

lore
Share & tools
lore
#0 lore raw

The following changes since commit 239618707637ec87eba8c452d2b2f75dc5ca20c7:

Merge remote-tracking branch 'remotes/kvm/uq/master' into staging (2014-03-11 19:39:17 +0000)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/net-pull-request

for you to fetch changes up to 68e5ec64009812dbaa03ed9cfded9344986f5304:

tap: avoid deadlocking rx (2014-03-12 10:12:00 +0100)

----------------------------------------------------------------
Net patches

----------------------------------------------------------------
Stefan Hajnoczi (1):
tap: avoid deadlocking rx

 net/tap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.5.3
#1 lore raw

[Qemu-devel] [PULL 1/1] tap: avoid deadlocking rx

The net subsystem has a control flow mechanism so peer NetClientStates can tell each other to stop sending packets. This is used to stop monitoring the tap file descriptor for incoming packets if the guest rx ring has no spare buffers.

There is a corner case when tap_can_send() is true at the beginning of an event loop iteration but becomes false before the tap_send() fd handler is invoked.

tap_send() will read the packet from the tap file descriptor and attempt to send it. The net queue will hold on to the packet and return 0, indicating that further I/O is not possible. tap then stops monitoring the file descriptor for reads.

This is unlike the normal case where tap_can_send() is the same before and during the event loop iteration. The event loop would simply not monitor the file descriptor if tap_can_send() returns true. Upon next iteration it would check tap_can_send() again and begin monitoring if we can send.

The deadlock happens because tap_send() explicitly disabled read_poll. This is done with the expectation that the peer will call qemu_net_queue_flush(). But hw/net/virtio-net.c does not monitor vm_running transitions and issue the flush. Hence we're left with a broken tap device.

---
 net/tap.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/tap.c +5 -2
index 2d5099b..8847ce1 100644
@@ -190,7 +190,7 @@ static void tap_send(void *opaque)
     TAPState *s = opaque;
     int size;
 
-    do {
+    while (qemu_can_send_packet(&s->nc)) {
         uint8_t *buf = s->buf;
 
         size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
@@ -206,8 +206,11 @@ static void tap_send(void *opaque)
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, false);
+            break;
+        } else if (size < 0) {
+            break;
         }
-    } while (size > 0 && qemu_can_send_packet(&s->nc));
+    }
 }
 
 static bool tap_has_ufo(NetClientState *nc)
Signature · 1 line
1.8.5.3
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 4 lines · Stefan Hajnoczi

The following changes since commit 239618707637ec87eba8c452d2b2f75dc5ca20c7:

Merge remote-tracking branch 'remotes/kvm/uq/master' into staging (2014-03-11 19:39:17 +0000)

Quoted 8 lines

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/net-pull-request

for you to fetch changes up to 68e5ec64009812dbaa03ed9cfded9344986f5304:

tap: avoid deadlocking rx (2014-03-12 10:12:00 +0100)

Applied, thanks.
-- PMM