* [Qemu-devel] [PULL 00/13] Net patches
@ 2012-09-10 9:55 Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops Stefan Hajnoczi
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-09-10 9:55 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Stefan Hajnoczi, qemu-devel
Fixes for hung NICs, USB network interface packet dropping, and inefficient
netdev socket non-blocking I/O.
The following changes since commit 0c267217ca9985e6d118ec8368bebd382db7a099:
musicpal: Fix flash mapping (2012-09-08 10:17:57 +0000)
are available in the git repository at:
git://github.com/stefanha/qemu.git net
for you to fetch changes up to 0eb160d10e4f55cb5430ca3b6eb049977d0ce643:
net: EAGAIN handling for net/socket.c TCP (2012-09-10 08:12:34 +0100)
----------------------------------------------------------------
Bo Yang (1):
eepro100: Fix network hang when rx buffers run out
Paolo Bonzini (3):
net: notify iothread after flushing queue
e1000: flush queue whenever can_receive can go from false to true
xen: flush queue when getting an event
Stefan Hajnoczi (9):
net: add receive_disabled logic to iov delivery path
net: do not report queued packets as sent
net: add -netdev options to man page
net: clean up usbnet_receive()
net: fix usbnet_receive() packet drops
net: broadcast hub packets if at least one port can receive
net: asynchronous send/receive infrastructure for net/socket.c
net: EAGAIN handling for net/socket.c UDP
net: EAGAIN handling for net/socket.c TCP
hw/e1000.c | 4 ++
hw/eepro100.c | 4 +-
hw/usb/dev-network.c | 49 ++++++++++++++--------
hw/virtio-net.c | 4 --
hw/xen_nic.c | 1 +
net.c | 22 ++++++++--
net/hub.c | 6 +--
net/queue.c | 40 +++++++++---------
net/queue.h | 2 +-
net/socket.c | 110 +++++++++++++++++++++++++++++++++++++++++++-------
qemu-options.hx | 7 ++++
11 files changed, 186 insertions(+), 63 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops
2012-09-10 9:55 [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
@ 2012-09-10 9:55 ` Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 13/13] net: EAGAIN handling for net/socket.c TCP Stefan Hajnoczi
2012-09-14 7:36 ` [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-09-10 9:55 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel, Stefan Hajnoczi
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
The USB network interface has a single buffer which the guest reads
from. This patch prevents multiple calls to usbnet_receive() from
clobbering the input buffer. Instead we queue packets until buffer
space becomes available again.
This is inspired by virtio-net and e1000 rxbuf handling.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
hw/usb/dev-network.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 0b5cb71..e4a4359 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1001,6 +1001,13 @@ static int rndis_keepalive_response(USBNetState *s,
return 0;
}
+/* Prepare to receive the next packet */
+static void usb_net_reset_in_buf(USBNetState *s)
+{
+ s->in_ptr = s->in_len = 0;
+ qemu_flush_queued_packets(&s->nic->nc);
+}
+
static int rndis_parse(USBNetState *s, uint8_t *data, int length)
{
uint32_t msg_type;
@@ -1025,7 +1032,8 @@ static int rndis_parse(USBNetState *s, uint8_t *data, int length)
case RNDIS_RESET_MSG:
rndis_clear_responsequeue(s);
- s->out_ptr = s->in_ptr = s->in_len = 0;
+ s->out_ptr = 0;
+ usb_net_reset_in_buf(s);
return rndis_reset_response(s, (rndis_reset_msg_type *) data);
case RNDIS_KEEPALIVE_MSG:
@@ -1135,7 +1143,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
int ret = USB_RET_NAK;
if (s->in_ptr > s->in_len) {
- s->in_ptr = s->in_len = 0;
+ usb_net_reset_in_buf(s);
ret = USB_RET_NAK;
return ret;
}
@@ -1152,7 +1160,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
if (s->in_ptr >= s->in_len &&
(is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) {
/* no short packet necessary */
- s->in_ptr = s->in_len = 0;
+ usb_net_reset_in_buf(s);
}
#ifdef TRAFFIC_DEBUG
@@ -1263,6 +1271,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz
return -1;
}
+ /* Only accept packet if input buffer is empty */
+ if (s->in_len > 0) {
+ return 0;
+ }
+
if (is_rndis(s)) {
struct rndis_packet_msg_type *msg;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 13/13] net: EAGAIN handling for net/socket.c TCP
2012-09-10 9:55 [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops Stefan Hajnoczi
@ 2012-09-10 9:55 ` Stefan Hajnoczi
2012-09-14 7:36 ` [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-09-10 9:55 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel, Stefan Hajnoczi
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Replace spinning send_all() with a proper non-blocking send. When the
socket write buffer limit is reached, we should stop trying to send and
wait for the socket to become writable again.
Non-blocking TCP sockets can return in two different ways when the write
buffer limit is reached:
1. ret = -1 and errno = EAGAIN/EWOULDBLOCK. No data has been written.
2. ret < total_size. Short write, only part of the message was
transmitted.
Handle both cases and keep track of how many bytes have been written in
s->send_index. (This includes the 'length' header before the actual
payload buffer.)
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
net/socket.c | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)
diff --git a/net/socket.c b/net/socket.c
index e5e4e8d..c3e55b8 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -32,6 +32,7 @@
#include "qemu-error.h"
#include "qemu-option.h"
#include "qemu_socket.h"
+#include "iov.h"
typedef struct NetSocketState {
NetClientState nc;
@@ -40,6 +41,7 @@ typedef struct NetSocketState {
int state; /* 0 = getting length, 1 = getting data */
unsigned int index;
unsigned int packet_len;
+ unsigned int send_index; /* number of bytes sent (only SOCK_STREAM) */
uint8_t buf[4096];
struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
IOHandler *send_fn; /* differs between SOCK_STREAM/SOCK_DGRAM */
@@ -88,15 +90,39 @@ static void net_socket_writable(void *opaque)
qemu_flush_queued_packets(&s->nc);
}
-/* XXX: we consider we can send the whole packet without blocking */
static ssize_t net_socket_receive(NetClientState *nc, const uint8_t *buf, size_t size)
{
NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
- uint32_t len;
- len = htonl(size);
+ uint32_t len = htonl(size);
+ struct iovec iov[] = {
+ {
+ .iov_base = &len,
+ .iov_len = sizeof(len),
+ }, {
+ .iov_base = (void *)buf,
+ .iov_len = size,
+ },
+ };
+ size_t remaining;
+ ssize_t ret;
+
+ remaining = iov_size(iov, 2) - s->send_index;
+ ret = iov_send(s->fd, iov, 2, s->send_index, remaining);
- send_all(s->fd, (const uint8_t *)&len, sizeof(len));
- return send_all(s->fd, buf, size);
+ if (ret == -1 && errno == EAGAIN) {
+ ret = 0; /* handled further down */
+ }
+ if (ret == -1) {
+ s->send_index = 0;
+ return -errno;
+ }
+ if (ret < (ssize_t)remaining) {
+ s->send_index += ret;
+ net_socket_write_poll(s, true);
+ return 0;
+ }
+ s->send_index = 0;
+ return size;
}
static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, size_t size)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PULL 00/13] Net patches
2012-09-10 9:55 [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 13/13] net: EAGAIN handling for net/socket.c TCP Stefan Hajnoczi
@ 2012-09-14 7:36 ` Stefan Hajnoczi
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-09-14 7:36 UTC (permalink / raw)
To: Anthony Liguori; +Cc: Stefan Hajnoczi, qemu-devel
On Mon, Sep 10, 2012 at 10:55 AM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> Fixes for hung NICs, USB network interface packet dropping, and inefficient
> netdev socket non-blocking I/O.
>
> The following changes since commit 0c267217ca9985e6d118ec8368bebd382db7a099:
>
> musicpal: Fix flash mapping (2012-09-08 10:17:57 +0000)
>
> are available in the git repository at:
>
> git://github.com/stefanha/qemu.git net
>
> for you to fetch changes up to 0eb160d10e4f55cb5430ca3b6eb049977d0ce643:
>
> net: EAGAIN handling for net/socket.c TCP (2012-09-10 08:12:34 +0100)
Please disregard this thread, there has been an issue with my mail queue.
I am going to resend this pull request to make sure all mails are
properly delivered.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops
2012-09-14 8:46 Stefan Hajnoczi
@ 2012-09-14 8:46 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2012-09-14 8:46 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel, Stefan Hajnoczi
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
The USB network interface has a single buffer which the guest reads
from. This patch prevents multiple calls to usbnet_receive() from
clobbering the input buffer. Instead we queue packets until buffer
space becomes available again.
This is inspired by virtio-net and e1000 rxbuf handling.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
hw/usb/dev-network.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 0b5cb71..e4a4359 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1001,6 +1001,13 @@ static int rndis_keepalive_response(USBNetState *s,
return 0;
}
+/* Prepare to receive the next packet */
+static void usb_net_reset_in_buf(USBNetState *s)
+{
+ s->in_ptr = s->in_len = 0;
+ qemu_flush_queued_packets(&s->nic->nc);
+}
+
static int rndis_parse(USBNetState *s, uint8_t *data, int length)
{
uint32_t msg_type;
@@ -1025,7 +1032,8 @@ static int rndis_parse(USBNetState *s, uint8_t *data, int length)
case RNDIS_RESET_MSG:
rndis_clear_responsequeue(s);
- s->out_ptr = s->in_ptr = s->in_len = 0;
+ s->out_ptr = 0;
+ usb_net_reset_in_buf(s);
return rndis_reset_response(s, (rndis_reset_msg_type *) data);
case RNDIS_KEEPALIVE_MSG:
@@ -1135,7 +1143,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
int ret = USB_RET_NAK;
if (s->in_ptr > s->in_len) {
- s->in_ptr = s->in_len = 0;
+ usb_net_reset_in_buf(s);
ret = USB_RET_NAK;
return ret;
}
@@ -1152,7 +1160,7 @@ static int usb_net_handle_datain(USBNetState *s, USBPacket *p)
if (s->in_ptr >= s->in_len &&
(is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) {
/* no short packet necessary */
- s->in_ptr = s->in_len = 0;
+ usb_net_reset_in_buf(s);
}
#ifdef TRAFFIC_DEBUG
@@ -1263,6 +1271,11 @@ static ssize_t usbnet_receive(NetClientState *nc, const uint8_t *buf, size_t siz
return -1;
}
+ /* Only accept packet if input buffer is empty */
+ if (s->in_len > 0) {
+ return 0;
+ }
+
if (is_rndis(s)) {
struct rndis_packet_msg_type *msg;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-14 8:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-10 9:55 [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops Stefan Hajnoczi
2012-09-10 9:55 ` [Qemu-devel] [PATCH 13/13] net: EAGAIN handling for net/socket.c TCP Stefan Hajnoczi
2012-09-14 7:36 ` [Qemu-devel] [PULL 00/13] Net patches Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2012-09-14 8:46 Stefan Hajnoczi
2012-09-14 8:46 ` [Qemu-devel] [PATCH 09/13] net: fix usbnet_receive() packet drops Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).