From patchwork Mon May 20 08:18:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 244866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D0572C008F for ; Mon, 20 May 2013 18:18:27 +1000 (EST) Received: from localhost ([::1]:34014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeLIX-0008M1-KL for incoming@patchwork.ozlabs.org; Mon, 20 May 2013 04:18:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeLIE-0008L1-Ew for qemu-devel@nongnu.org; Mon, 20 May 2013 04:18:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UeLIB-0007oU-CQ for qemu-devel@nongnu.org; Mon, 20 May 2013 04:18:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31242) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeLIB-0007oH-4b for qemu-devel@nongnu.org; Mon, 20 May 2013 04:18:03 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4K8HvOQ032689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 20 May 2013 04:17:57 -0400 Received: from redhat.com (vpn-202-132.tlv.redhat.com [10.35.202.132]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r4K8HqeJ021644; Mon, 20 May 2013 04:17:53 -0400 Date: Mon, 20 May 2013 11:18:14 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20130520081814.GA8162@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Jason Wang , Gerd Hoffmann , Paolo Bonzini , Amos Kong , Andreas =?iso-8859-1?Q?F=E4rber?= , KONRAD Frederic Subject: [Qemu-devel] [PATCH v5] virtio-net: dynamic network offloads configuration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Dmitry Fleytman Virtio-net driver currently negotiates network offloads on startup via features mechanism and have no ability to disable and re-enable offloads later. This patch introduced a new control command that allows to configure device network offloads state dynamically. The patch also introduces a new feature flag VIRTIO_NET_F_CTRL_GUEST_OFFLOADS. Signed-off-by: Dmitry Fleytman Signed-off-by: Michael S. Tsirkin --- changes from v4: rebased to latest master I know it's late in the cycle, but it was posted well before the freeze, and apparently was forgotten, and since it's a known WHQL blocker I think we should add this - the sooner latest windows drivers pass WHQL and update to a configuration that can handle e.g. flexible BAR sizes, the better. So I rebased this patch myself, but don't have the latest windows driver bits to test it. Dmitry, could you please test and report on list? Thanks! hw/net/virtio-net.c | 99 +++++++++++++++++++++++++++++++++++------- include/hw/i386/pc.h | 4 ++ include/hw/virtio/virtio-net.h | 13 ++++++ 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index bed0822..1ea9556 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -359,6 +359,34 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev) return features; } +static void virtio_net_apply_guest_offloads(VirtIONet *n) +{ + tap_set_offload(qemu_get_subqueue(n->nic, 0)->peer, + !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_CSUM)), + !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)), + !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)), + !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)), + !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO))); +} + +static uint64_t virtio_net_guest_offloads_by_features(uint32_t features) +{ + static const uint64_t guest_offloads_mask = + (1ULL << VIRTIO_NET_F_GUEST_CSUM) | + (1ULL << VIRTIO_NET_F_GUEST_TSO4) | + (1ULL << VIRTIO_NET_F_GUEST_TSO6) | + (1ULL << VIRTIO_NET_F_GUEST_ECN) | + (1ULL << VIRTIO_NET_F_GUEST_UFO); + + return guest_offloads_mask & features; +} + +static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + return virtio_net_guest_offloads_by_features(vdev->guest_features); +} + static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) { VirtIONet *n = VIRTIO_NET(vdev); @@ -369,12 +397,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features) virtio_net_set_mrg_rx_bufs(n, !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF))); if (n->has_vnet_hdr) { - tap_set_offload(qemu_get_subqueue(n->nic, 0)->peer, - (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_UFO) & 1); + n->curr_guest_offloads = + virtio_net_guest_offloads_by_features(features); + virtio_net_apply_guest_offloads(n); } for (i = 0; i < n->max_queues; i++) { @@ -420,6 +445,43 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, return VIRTIO_NET_OK; } +static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd, + struct iovec *iov, unsigned int iov_cnt) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + uint64_t offloads; + size_t s; + + if (!((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features)) { + return VIRTIO_NET_ERR; + } + + s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads)); + if (s != sizeof(offloads)) { + return VIRTIO_NET_ERR; + } + + if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) { + uint64_t supported_offloads; + + if (!n->has_vnet_hdr) { + return VIRTIO_NET_ERR; + } + + supported_offloads = virtio_net_supported_guest_offloads(n); + if (offloads & ~supported_offloads) { + return VIRTIO_NET_ERR; + } + + n->curr_guest_offloads = offloads; + virtio_net_apply_guest_offloads(n); + + return VIRTIO_NET_OK; + } else { + return VIRTIO_NET_ERR; + } +} + static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, struct iovec *iov, unsigned int iov_cnt) { @@ -590,6 +652,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt); } else if (ctrl.class == VIRTIO_NET_CTRL_MQ) { status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt); + } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) { + status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt); } s = iov_from_buf(elem.in_sg, elem.in_num, 0, &status, sizeof(status)); @@ -1110,6 +1174,10 @@ static void virtio_net_save(QEMUFile *f, void *opaque) qemu_put_be32(f, n->vqs[i].tx_waiting); } } + + if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) { + qemu_put_be64(f, n->curr_guest_offloads); + } } static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) @@ -1167,15 +1235,6 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) error_report("virtio-net: saved image requires vnet_hdr=on"); return -1; } - - if (n->has_vnet_hdr) { - tap_set_offload(qemu_get_queue(n->nic)->peer, - (vdev->guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1, - (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO4) & 1, - (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO6) & 1, - (vdev->guest_features >> VIRTIO_NET_F_GUEST_ECN) & 1, - (vdev->guest_features >> VIRTIO_NET_F_GUEST_UFO) & 1); - } } if (version_id >= 9) { @@ -1209,6 +1268,16 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) } } + if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) { + n->curr_guest_offloads = qemu_get_be64(f); + } else { + n->curr_guest_offloads = virtio_net_supported_guest_offloads(n); + } + + if (peer_has_vnet_hdr(n)) { + virtio_net_apply_guest_offloads(n); + } + virtio_net_set_queues(n); /* Find the first multicast entry in the saved MAC filter */ diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 2bd7090..93d8357 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -217,6 +217,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); .property = "vectors",\ /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\ .value = stringify(0xFFFFFFFF),\ + },{ \ + .driver = "virtio-net-pci", \ + .property = "ctrl_guest_offloads", \ + .value = "off", \ },{\ .driver = "e1000",\ .property = "romfile",\ diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index beeead7..b315ac9 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -31,6 +31,8 @@ /* The feature bitmap for virtio net */ #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ +#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload + * configuration support */ #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ @@ -190,6 +192,7 @@ typedef struct VirtIONet { size_t config_size; char *netclient_name; char *netclient_type; + uint64_t curr_guest_offloads; } VirtIONet; #define VIRTIO_NET_CTRL_MAC 1 @@ -229,6 +232,15 @@ struct virtio_net_ctrl_mq { #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 +/* + * Control network offloads + * + * Dynamic offloads are available with the + * VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit. + */ +#define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5 + #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0 + #define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \ DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \ DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \ @@ -249,6 +261,7 @@ struct virtio_net_ctrl_mq { DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \ DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true), \ DEFINE_PROP_BIT("ctrl_mac_addr", _state, _field, VIRTIO_NET_F_CTRL_MAC_ADDR, true), \ + DEFINE_PROP_BIT("ctrl_guest_offloads", _state, _field, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), \ DEFINE_PROP_BIT("mq", _state, _field, VIRTIO_NET_F_MQ, false) #define DEFINE_VIRTIO_NET_PROPERTIES(_state, _field) \