* [PATCH] Use guards in virtio-net for easier upstream merging
@ 2008-12-03 20:32 Anthony Liguori
2008-12-04 12:06 ` Mark McLoughlin
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Liguori @ 2008-12-03 20:32 UTC (permalink / raw)
To: kvm; +Cc: Avi Kivity, Anthony Liguori
This gets virtio-net into an upstream acceptable state. This includes
introducing USE_KVM guards for IO thread notification (where did
qemu_service_io() go?). It also includes introducing TAP_VNET_HDR which is for
code that relies on the tap vnet support that is not currently in upstream QEMU.
Finally, it drops packets if not ready to receive. This is unnecessary in
kvm-userspace but necessary in QEMU.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 6493ff6..b53feb3 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -15,7 +15,11 @@
#include "net.h"
#include "qemu-timer.h"
#include "virtio-net.h"
+#ifdef USE_KVM
#include "qemu-kvm.h"
+#endif
+
+//#define TAP_VNET_HDR
typedef struct VirtIONet
{
@@ -49,9 +53,10 @@ static void virtio_net_update_config(VirtIODevice *vdev, uint8_t *config)
static uint32_t virtio_net_get_features(VirtIODevice *vdev)
{
+ uint32_t features = (1 << VIRTIO_NET_F_MAC);
+#ifdef TAP_VNET_HDR
VirtIONet *n = to_virtio_net(vdev);
VLANClientState *host = n->vc->vlan->first_client;
- uint32_t features = (1 << VIRTIO_NET_F_MAC);
if (tap_has_vnet_hdr(host)) {
tap_using_vnet_hdr(host, 1);
@@ -66,6 +71,7 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev)
features |= (1 << VIRTIO_NET_F_MRG_RXBUF);
/* Kernel can't actually handle UFO in software currently. */
}
+#endif
return features;
}
@@ -73,10 +79,13 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev)
static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
{
VirtIONet *n = to_virtio_net(vdev);
+#ifdef TAP_VNET_HDR
VLANClientState *host = n->vc->vlan->first_client;
+#endif
n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF));
+#ifdef TAP_VNET_HDR
if (!tap_has_vnet_hdr(host) || !host->set_offload)
return;
@@ -85,16 +94,19 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
(features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
(features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
(features >> VIRTIO_NET_F_GUEST_ECN) & 1);
+#endif
}
/* RX */
static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
{
+#ifdef USE_KVM
/* We now have RX buffers, signal to the IO thread to break out of the
select to re-poll the tap file descriptor */
if (kvm_enabled())
qemu_kvm_notify_work();
+#endif
}
static int virtio_net_can_receive(void *opaque)
@@ -116,6 +128,7 @@ static int virtio_net_can_receive(void *opaque)
return 1;
}
+#ifdef TAP_VNET_HDR
/* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
* it never finds out that the packets don't have valid checksums. This
* causes dhclient to get upset. Fedora's carried a patch for ages to
@@ -143,6 +156,7 @@ static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
hdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM;
}
}
+#endif
static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
{
@@ -168,11 +182,13 @@ static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
hdr->flags = 0;
hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
+#ifdef TAP_VNET_HDR
if (tap_has_vnet_hdr(n->vc->vlan->first_client)) {
memcpy(hdr, buf, sizeof(*hdr));
offset = sizeof(*hdr);
work_around_broken_dhclient(hdr, buf + offset, size - offset);
}
+#endif
/* We only ever receive a struct virtio_net_hdr from the tapfd,
* but we may be passing along a larger header to the guest.
@@ -189,6 +205,9 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
int hdr_len, offset, i;
+ if (!virtio_net_can_receive(opaque))
+ return;
+
/* hdr_len refers to the header we supply to the guest */
hdr_len = n->mergeable_rx_bufs ?
sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
@@ -253,7 +272,11 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
{
VirtQueueElement elem;
+#ifdef TAP_VNET_HDR
int has_vnet_hdr = tap_has_vnet_hdr(n->vc->vlan->first_client);
+#else
+ int has_vnet_hdr = 0;
+#endif
if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
return;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Use guards in virtio-net for easier upstream merging
2008-12-03 20:32 [PATCH] Use guards in virtio-net for easier upstream merging Anthony Liguori
@ 2008-12-04 12:06 ` Mark McLoughlin
2008-12-04 15:09 ` Anthony Liguori
0 siblings, 1 reply; 3+ messages in thread
From: Mark McLoughlin @ 2008-12-04 12:06 UTC (permalink / raw)
To: Anthony Liguori; +Cc: kvm, Avi Kivity
On Wed, 2008-12-03 at 14:32 -0600, Anthony Liguori wrote:
> @@ -189,6 +205,9 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
> struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
> int hdr_len, offset, i;
>
> + if (!virtio_net_can_receive(opaque))
> + return;
Should pass the buffer size to virtio_net_can_receive() to limit the
work virtqueue_avail_bytes() has to do.
Cheers,
Mark.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use guards in virtio-net for easier upstream merging
2008-12-04 12:06 ` Mark McLoughlin
@ 2008-12-04 15:09 ` Anthony Liguori
0 siblings, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2008-12-04 15:09 UTC (permalink / raw)
To: Mark McLoughlin; +Cc: kvm, Avi Kivity
Mark McLoughlin wrote:
> On Wed, 2008-12-03 at 14:32 -0600, Anthony Liguori wrote:
>
>
>> @@ -189,6 +205,9 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
>> struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
>> int hdr_len, offset, i;
>>
>> + if (!virtio_net_can_receive(opaque))
>> + return;
>>
>
> Should pass the buffer size to virtio_net_can_receive() to limit the
> work virtqueue_avail_bytes() has to do.
>
Sure, I have to resubmit anyway because I left tap_vnet disable (didn't
refresh before sending patch-doh!).
Regards,
Anthony Liguori
> Cheers,
> Mark.
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-04 15:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03 20:32 [PATCH] Use guards in virtio-net for easier upstream merging Anthony Liguori
2008-12-04 12:06 ` Mark McLoughlin
2008-12-04 15:09 ` Anthony Liguori
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).