From patchwork Thu Oct 22 16:43:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 54BB3B7BB0 for ; Fri, 23 Oct 2009 04:23:15 +1100 (EST) Received: from localhost ([127.0.0.1]:44436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N11NY-0000I1-Hr for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2009 13:23:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N10ph-0002C5-KS for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:48:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N10pe-00026P-1V for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:48:13 -0400 Received: from [199.232.76.173] (port=56651 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N10pd-000268-GY for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:48:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50730) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N10pc-0003b5-PG for qemu-devel@nongnu.org; Thu, 22 Oct 2009 12:48:09 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGji8V008273; Thu, 22 Oct 2009 12:45:45 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9MGjhZt008053; Thu, 22 Oct 2009 12:45:44 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id D7A3745C15; Thu, 22 Oct 2009 17:43:50 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2009 17:43:49 +0100 Message-Id: <1256229830-28066-19-git-send-email-markmc@redhat.com> In-Reply-To: <1256229830-28066-1-git-send-email-markmc@redhat.com> References: <1256229830-28066-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin , Sridhar Samudrala Subject: [Qemu-devel] [PATCH 18/19] Enable UFO on virtio-net and tap devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Sridhar Samudrala Enable UFO on the host tap device if supported and allow setting UFO on virtio-net in the guest. Signed-off-by: Sridhar Samudrala Signed-off-by: Mark McLoughlin --- hw/virtio-net.c | 11 +++++++++-- net.c | 36 ++++++++++++++++++++++++++++++++---- net.h | 3 ++- tap-linux.h | 1 + 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index e00c404..31ac9ef 100644 --- a/hw/virtio-net.c +++ b/hw/virtio-net.c @@ -157,6 +157,11 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) features |= (1 << VIRTIO_NET_F_GUEST_TSO4); features |= (1 << VIRTIO_NET_F_GUEST_TSO6); features |= (1 << VIRTIO_NET_F_GUEST_ECN); + + if (tap_has_ufo(n->vc->peer)) { + features |= (1 << VIRTIO_NET_F_GUEST_UFO); + features |= (1 << VIRTIO_NET_F_HOST_UFO); + } } return features; @@ -188,7 +193,8 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) (features >> VIRTIO_NET_F_GUEST_CSUM) & 1, (features >> VIRTIO_NET_F_GUEST_TSO4) & 1, (features >> VIRTIO_NET_F_GUEST_TSO6) & 1, - (features >> VIRTIO_NET_F_GUEST_ECN) & 1); + (features >> VIRTIO_NET_F_GUEST_ECN) & 1, + (features >> VIRTIO_NET_F_GUEST_UFO) & 1); } } @@ -748,7 +754,8 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) (n->vdev.features >> VIRTIO_NET_F_GUEST_CSUM) & 1, (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO4) & 1, (n->vdev.features >> VIRTIO_NET_F_GUEST_TSO6) & 1, - (n->vdev.features >> VIRTIO_NET_F_GUEST_ECN) & 1); + (n->vdev.features >> VIRTIO_NET_F_GUEST_ECN) & 1, + (n->vdev.features >> VIRTIO_NET_F_GUEST_UFO) & 1); } } diff --git a/net.c b/net.c index 746a3d6..3e54c53 100644 --- a/net.c +++ b/net.c @@ -1280,6 +1280,10 @@ void do_info_usernet(Monitor *mon) #endif /* CONFIG_SLIRP */ #if defined(_WIN32) +int tap_has_ufo(VLANClientState *vc) +{ + return 0; +} int tap_has_vnet_hdr(VLANClientState *vc) { return 0; @@ -1287,7 +1291,8 @@ int tap_has_vnet_hdr(VLANClientState *vc) void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) { } -void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +void tap_set_offload(VLANClientState *vc, int csum, int tso4, + int tso6, int ecn, int ufo) { } #else /* !defined(_WIN32) */ @@ -1307,6 +1312,7 @@ typedef struct TAPState { unsigned int write_poll : 1; unsigned int has_vnet_hdr : 1; unsigned int using_vnet_hdr : 1; + unsigned int has_ufo: 1; } TAPState; static int launch_script(const char *setup_script, const char *ifname, int fd); @@ -1494,6 +1500,15 @@ static int tap_set_sndbuf(TAPState *s, QemuOpts *opts) return 0; } +int tap_has_ufo(VLANClientState *vc) +{ + TAPState *s = vc->opaque; + + assert(vc->type == NET_CLIENT_TYPE_TAP); + + return s->has_ufo; +} + int tap_has_vnet_hdr(VLANClientState *vc) { TAPState *s = vc->opaque; @@ -1527,7 +1542,8 @@ static int tap_probe_vnet_hdr(int fd) return ifr.ifr_flags & IFF_VNET_HDR; } -void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) +void tap_set_offload(VLANClientState *vc, int csum, int tso4, + int tso6, int ecn, int ufo) { TAPState *s = vc->opaque; unsigned int offload = 0; @@ -1540,11 +1556,16 @@ void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn) offload |= TUN_F_TSO6; if ((tso4 || tso6) && ecn) offload |= TUN_F_TSO_ECN; + if (ufo) + offload |= TUN_F_UFO; } if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) { - fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n", - strerror(errno)); + offload &= ~TUN_F_UFO; + if (ioctl(s->fd, TUNSETOFFLOAD, offload) != 0) { + fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n", + strerror(errno)); + } } } @@ -1572,6 +1593,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, int vnet_hdr) { TAPState *s; + unsigned int offload; s = qemu_mallocz(sizeof(TAPState)); s->fd = fd; @@ -1581,6 +1603,12 @@ static TAPState *net_tap_fd_init(VLANState *vlan, vlan, NULL, model, name, NULL, tap_receive, tap_receive_raw, tap_receive_iov, tap_cleanup, s); + s->has_ufo = 0; + /* Check if tap supports UFO */ + offload = TUN_F_CSUM | TUN_F_UFO; + if (ioctl(s->fd, TUNSETOFFLOAD, offload) == 0) + s->has_ufo = 1; + tap_set_offload(s->vc, 0, 0, 0, 0, 0); tap_read_poll(s, 1); return s; } diff --git a/net.h b/net.h index a0f0359..7e6cbf4 100644 --- a/net.h +++ b/net.h @@ -168,8 +168,9 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, NetCleanup *cleanup, void *opaque); +int tap_has_ufo(VLANClientState *vc); int tap_has_vnet_hdr(VLANClientState *vc); void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); -void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn); +void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo); #endif diff --git a/tap-linux.h b/tap-linux.h index 241cf83..d81c650 100644 --- a/tap-linux.h +++ b/tap-linux.h @@ -36,6 +36,7 @@ #define TUN_F_TSO4 0x02 /* I can handle TSO for IPv4 packets */ #define TUN_F_TSO6 0x04 /* I can handle TSO for IPv6 packets */ #define TUN_F_TSO_ECN 0x08 /* I can handle TSO with ECN bits. */ +#define TUN_F_UFO 0x10 /* I can handle UFO packets */ struct virtio_net_hdr {