From patchwork Mon Mar 9 08:34:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11426351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E63B14E3 for ; Mon, 9 Mar 2020 08:37:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 14E6020828 for ; Mon, 9 Mar 2020 08:37:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="cOiMMd/f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14E6020828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDv4-0006Bg-7g for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Mar 2020 04:37:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47253) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDsC-0007Zn-VK for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBDsB-0007Jf-K3 for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBDsB-0007Ib-Dh for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:51 -0400 Received: by mail-wr1-x443.google.com with SMTP id n15so9834985wrw.13 for ; Mon, 09 Mar 2020 01:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MD48WZYaJiiFtb9BWvJPqIeuYzfyj+64eoP1t2H2QsM=; b=cOiMMd/fFhW+XVawA2sXDUUPZiw7x2HFB7voEIJqUQIe6fpLtX64cUq4rwJdrHuuj4 lAafYGrCVF2WUbrJ3QV4ltf4goi+Q2VeuII2oUerejOBeadRjSZJS2M/AsAi1j8eEs2c ahBP0obtlrZ89agupANcru8baXLqViRwAIOipocfQQahIibWoFwv1YrSpx+aNa5oKEZp P4zKJ4BmGeR8lQfXa67DIi47wdV4Z1QLnccc/0nlppEyTWZUElcW0yiNLZbi2eSFqrCl dPoKP0W50n5fvt/gm0Q86r1vxzQjaCxSasYEfHXuq8ZZv1HOrK0Poh7P/hv5IgS9S2eH 6WqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MD48WZYaJiiFtb9BWvJPqIeuYzfyj+64eoP1t2H2QsM=; b=GlTu1P0Pm5PrAkJGnZjat/e4FLYMR1S3OhYIqcPNXabWK8cgcK/hd/YjeLOid9lUUl QCZePo9zjkQJffNYOcyLEtUYgVy4y1kUfUQ9SgVyrE+ILraROJu6MbRLtezjeS9uH48s oPri6XgwqzLDZ26liKBwuK11MGVFUpz6SLUJQVxJBhf238ZDwhKxnmnnR5Oi2oKm7zFe 3el6iYe10N/e0yTDvY6byq+1ZCea349mesawlk1wgjGTeXmEmXdPFrc6zyMsUDDbxHik zhQd+WjcDu6ap1tp4VHKSSS94T1g9SeYrPoZgGR7kRsxL2faaM/S+rcNKahd/vkirgPJ 4XRg== X-Gm-Message-State: ANhLgQ2EDSv0/6E4tgPV/KNOn4iL48vS3vAmEdQsGvllcI/MSR0/jeXA C0K1QIK2pEohB432k0ZPkeYYMSJ+oA4sCQ== X-Google-Smtp-Source: ADFU+vtRGnbbMYemX9B1Gp/bPQ2JHkdwh+fltXhVAzgewEbbHYwtwtnhwq3Mgd91fB567vU2/kHBvA== X-Received: by 2002:a5d:65c5:: with SMTP id e5mr3545340wrw.161.1583742889160; Mon, 09 Mar 2020 01:34:49 -0700 (PDT) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id h3sm63749726wrb.23.2020.03.09.01.34.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 01:34:48 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v2 1/4] virtio-net: introduce RSS and hash report features Date: Mon, 9 Mar 2020 10:34:35 +0200 Message-Id: <20200309083438.2389-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309083438.2389-1-yuri.benditovich@daynix.com> References: <20200309083438.2389-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3627bb1717..9545b0e84f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -71,6 +71,101 @@ #define VIRTIO_NET_IP6_ADDR_SIZE 32 /* ipv6 saddr + daddr */ #define VIRTIO_NET_MAX_IP6_PAYLOAD VIRTIO_NET_MAX_TCP_PAYLOAD +/* TODO: remove after virtio-net header update */ +#if !defined(VIRTIO_NET_RSS_HASH_TYPE_IPv4) +#define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ +#define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ + +/* supported/enabled hash types */ +#define VIRTIO_NET_RSS_HASH_TYPE_IPv4 (1 << 0) +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4 (1 << 1) +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4 (1 << 2) +#define VIRTIO_NET_RSS_HASH_TYPE_IPv6 (1 << 3) +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6 (1 << 4) +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6 (1 << 5) +#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX (1 << 6) +#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX (1 << 7) +#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX (1 << 8) + +#define __le16 uint16_t +#define __le32 uint32_t +#define __u8 uint8_t +#define __u16 uint16_t +#define __u32 uint32_t + +struct virtio_net_config_with_rss { + /* The config defining mac address (if VIRTIO_NET_F_MAC) */ + __u8 mac[ETH_ALEN]; + /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ + __u16 status; + /* + * Maximum number of each of transmit and receive queues; + * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. + * Legal values are between 1 and 0x8000 + */ + __u16 max_virtqueue_pairs; + /* Default maximum transmit unit advice */ + __u16 mtu; + /* + * speed, in units of 1Mb. All values 0 to INT_MAX are legal. + * Any other value stands for unknown. + */ + __u32 speed; + /* + * 0x00 - half duplex + * 0x01 - full duplex + * Any other value stands for unknown. + */ + __u8 duplex; + /* maximum size of RSS key */ + __u8 rss_max_key_size; + /* maximum number of indirection table entries */ + __le16 rss_max_indirection_table_length; + /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */ + __le32 supported_hash_types; +} __attribute__((packed)); + +#define virtio_net_config virtio_net_config_with_rss + +struct virtio_net_hdr_v1_hash { + struct virtio_net_hdr_v1 hdr; + __le32 hash_value; +#define VIRTIO_NET_HASH_REPORT_NONE 0 +#define VIRTIO_NET_HASH_REPORT_IPv4 1 +#define VIRTIO_NET_HASH_REPORT_TCPv4 2 +#define VIRTIO_NET_HASH_REPORT_UDPv4 3 +#define VIRTIO_NET_HASH_REPORT_IPv6 4 +#define VIRTIO_NET_HASH_REPORT_TCPv6 5 +#define VIRTIO_NET_HASH_REPORT_UDPv6 6 +#define VIRTIO_NET_HASH_REPORT_IPv6_EX 7 +#define VIRTIO_NET_HASH_REPORT_TCPv6_EX 8 +#define VIRTIO_NET_HASH_REPORT_UDPv6_EX 9 + __le16 hash_report; + __le16 padding; +}; + +/* + * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as + * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures + * the receive steering to use a hash calculated for incoming packet + * to decide on receive virtqueue to place the packet. The command + * also provides parameters to calculate a hash and receive virtqueue. + */ +struct virtio_net_rss_config { + __le32 hash_types; + __le16 indirection_table_mask; + __le16 unclassified_queue; + __le16 indirection_table[1/* + indirection_table_mask */]; + __le16 max_tx_vq; + __u8 hash_key_length; + __u8 hash_key_data[/* hash_key_length */]; +}; + +#define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1 +#define VIRTIO_NET_CTRL_MQ_HASH_CONFIG 2 + +#endif + /* Purge coalesced packets timer interval, This value affects the performance a lot, and should be tuned carefully, '300000'(300us) is the recommended value to pass the WHQL test, '50000' can gain 2x netperf throughput with From patchwork Mon Mar 9 08:34:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11426369 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A889D14E3 for ; Mon, 9 Mar 2020 08:39:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FA9C2072A for ; Mon, 9 Mar 2020 08:39:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="kRExvKYe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FA9C2072A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDwj-0001Gp-Lk for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Mar 2020 04:39:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47263) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDsD-0007bv-Or for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBDsC-0007KH-36 for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:53 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46629) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBDsB-0007JS-Rs for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:52 -0400 Received: by mail-wr1-x441.google.com with SMTP id n15so9835079wrw.13 for ; Mon, 09 Mar 2020 01:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sQsNWCobnmXTK/R2xUJv6I/7W7Ysw1UAgVvh6gnFET8=; b=kRExvKYe2hGBZH4xZqZ0bUVX0y73JNC2Luwxfu8jcozwKhHjzxX7OhcFMAbEpgqvLf oFbWzEfRfLw+u4eLBmQXWEaoanDPGaFb2cSsGPAEvfGbqN1b/5b2s9UjlP7fKDPXh+hV rnWZu9hw3aKe7jYNfglhs0WSd2M6NXE7rIivmFhEQyaJaXc6uyHKfZAofafu52LXDwEA tFvKycoQQKRgSEa6CPPxq13KIb2CEqnDWMXV87qbnNPN0Pi9E3rteOApgd1xLcz/GwcA HRHY0+MlF2GwQL/bgqjxstsPUU5aLXPrpi+Kk9uza0iS8qy22CGxc+Tx53EtpnqLTG7u +0zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sQsNWCobnmXTK/R2xUJv6I/7W7Ysw1UAgVvh6gnFET8=; b=I5jOk3fpJz5oHLl7qc0eaeqokg6Q7iLHV6jYBBICGDcCnQdVJXqkfmOSFrevA1pRY8 0E/k+I/0AfpX9iGomLIqQ7DbIR1ZfMCTGzJVgXk8DUfnpOreNu5zEdj+9FZRtV6VFQ5k 8sgEKOznjf1BOmEcGv2e1p4tqB48AMes82m7OeXFPZsuKrk1F8O7DjBV5w4rOz3E9IRz eGTG/mm75n/F0kbVEL40EcR6f9W0t4QS2ahoyPA74usN1+qMbY0JgV23vp9N0m1SYjMK prFflgOkjbLC7fXDI9cdMcUeSxnhFi6AJ8ovhtymxEyNgQoIDHzy5I55otepwB5yKBHJ 9IhA== X-Gm-Message-State: ANhLgQ1uR36WcI/AkmHE/zuaf1Jw7IyE7XXb9NDrwK6qshlWY9JxBXyO ZuSdU7UJTNetYKXON2D5UEV3lKMpUatn5Q== X-Google-Smtp-Source: ADFU+vtN51Kz2IboCKPentUkhFuNfSxQyhFoFGOoF5J7DSPyT5v791LHAiVEfBbg3HlSIAxu43wHew== X-Received: by 2002:adf:f9cd:: with SMTP id w13mr19463345wrr.406.1583742890451; Mon, 09 Mar 2020 01:34:50 -0700 (PDT) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id h3sm63749726wrb.23.2020.03.09.01.34.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 01:34:49 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v2 2/4] virtio-net: implement RSS configuration command Date: Mon, 9 Mar 2020 10:34:36 +0200 Message-Id: <20200309083438.2389-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309083438.2389-1-yuri.benditovich@daynix.com> References: <20200309083438.2389-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Optionally report RSS feature. Handle RSS configuration command and keep RSS parameters in virtio-net device context. Signed-off-by: Yuri Benditovich --- hw/net/trace-events | 3 + hw/net/virtio-net.c | 148 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 11 +++ 3 files changed, 153 insertions(+), 9 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index a1da98a643..9823480d91 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -371,6 +371,9 @@ virtio_net_announce_notify(void) "" virtio_net_announce_timer(int round) "%d" virtio_net_handle_announce(int round) "%d" virtio_net_post_load_device(void) +virtio_net_rss_disable(void) +virtio_net_rss_error(int error_case) "case %d" +virtio_net_rss_enable(uint32_t p1, uint16_t p2, uint8_t p3) "hashes 0x%x, table of %d, key of %d" # tulip.c tulip_reg_write(uint64_t addr, const char *name, int size, uint64_t val) "addr 0x%02"PRIx64" (%s) size %d value 0x%08"PRIx64 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9545b0e84f..27071eccd2 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -172,6 +172,16 @@ struct virtio_net_rss_config { tso/gso/gro 'off'. */ #define VIRTIO_NET_RSC_DEFAULT_INTERVAL 300000 +#define VIRTIO_NET_RSS_SUPPORTED_HASHES (VIRTIO_NET_RSS_HASH_TYPE_IPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_TCPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_UDPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_IPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_TCPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_UDPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_IP_EX | \ + VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | \ + VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) + /* temporary until standard header include it */ #if !defined(VIRTIO_NET_HDR_F_RSC_INFO) @@ -203,6 +213,8 @@ static VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, .end = endof(struct virtio_net_config, duplex)}, + {.flags = 1ULL << VIRTIO_NET_F_RSS, + .end = endof(struct virtio_net_config, supported_hash_types)}, {} }; @@ -233,6 +245,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) memcpy(netcfg.mac, n->mac, ETH_ALEN); virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); netcfg.duplex = n->net_conf.duplex; + netcfg.rss_max_key_size = VIRTIO_NET_RSS_MAX_KEY_SIZE; + virtio_stw_p(vdev, &netcfg.rss_max_indirection_table_length, + VIRTIO_NET_RSS_MAX_TABLE_LEN); + virtio_stl_p(vdev, &netcfg.supported_hash_types, + VIRTIO_NET_RSS_SUPPORTED_HASHES); memcpy(config, &netcfg, n->config_size); } @@ -796,6 +813,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, return features; } + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); features = vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features = features; @@ -955,6 +973,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) } virtio_net_set_multiqueue(n, + virtio_has_feature(features, VIRTIO_NET_F_RSS) || virtio_has_feature(features, VIRTIO_NET_F_MQ)); virtio_net_set_mrg_rx_bufs(n, @@ -1231,25 +1250,134 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } +static void virtio_net_disable_rss(VirtIONet *n) +{ + if (n->rss_data.enabled) { + trace_virtio_net_rss_disable(); + } + n->rss_data.enabled = false; +} + +static uint16_t virtio_net_handle_rss(VirtIONet *n, + struct iovec *iov, unsigned int iov_cnt) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + struct virtio_net_rss_config cfg; + size_t s, offset = 0, size_get; + uint16_t queues, i; + struct { + uint16_t us; + uint8_t b; + } QEMU_PACKED temp; + int err; + + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + err = 1; + goto error; + } + size_get = offsetof(struct virtio_net_rss_config, indirection_table); + s = iov_to_buf(iov, iov_cnt, offset, &cfg, size_get); + if (s != size_get) { + err = 2; + goto error; + } + n->rss_data.hash_types = virtio_ldl_p(vdev, &cfg.hash_types); + n->rss_data.indirections_len = + virtio_lduw_p(vdev, &cfg.indirection_table_mask); + n->rss_data.indirections_len++; + if (!is_power_of_2(n->rss_data.indirections_len)) { + err = 3; + goto error; + } + if (n->rss_data.indirections_len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { + err = 4; + goto error; + } + n->rss_data.default_queue = + virtio_lduw_p(vdev, &cfg.unclassified_queue); + if (n->rss_data.default_queue >= n->max_queues) { + err = 5; + goto error; + } + offset += size_get; + size_get = sizeof(uint16_t) * n->rss_data.indirections_len; + s = iov_to_buf(iov, iov_cnt, offset, n->rss_data.indirections, size_get); + if (s != size_get) { + err = 10; + goto error; + } + for (i = 0; i < n->rss_data.indirections_len; ++i) { + uint16_t val = n->rss_data.indirections[i]; + n->rss_data.indirections[i] = virtio_lduw_p(vdev, &val); + } + offset += size_get; + size_get = sizeof(temp); + s = iov_to_buf(iov, iov_cnt, offset, &temp, size_get); + if (s != size_get) { + err = 11; + goto error; + } + queues = virtio_lduw_p(vdev, &temp.us); + if (queues == 0 || queues > n->max_queues) { + err = 12; + goto error; + } + if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { + err = 13; + goto error; + } + if (!temp.b && n->rss_data.hash_types) { + err = 20; + goto error; + } + if (!temp.b && !n->rss_data.hash_types) { + virtio_net_disable_rss(n); + return queues; + } + offset += size_get; + size_get = temp.b; + s = iov_to_buf(iov, iov_cnt, offset, n->rss_data.key, size_get); + if (s != size_get) { + err = 21; + goto error; + } + n->rss_data.enabled = true; + trace_virtio_net_rss_enable(n->rss_data.hash_types, + n->rss_data.indirections_len, + temp.b); + return queues; +error: + warn_report("%s: error_case %d", __func__, err); + trace_virtio_net_rss_error(err); + virtio_net_disable_rss(n); + return 0; +} + static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, struct iovec *iov, unsigned int iov_cnt) { VirtIODevice *vdev = VIRTIO_DEVICE(n); - struct virtio_net_ctrl_mq mq; - size_t s; uint16_t queues; - s = iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); - if (s != sizeof(mq)) { - return VIRTIO_NET_ERR; - } + virtio_net_disable_rss(n); + if (cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { + queues = virtio_net_handle_rss(n, iov, iov_cnt); + } else if (cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + struct virtio_net_ctrl_mq mq; + size_t s; + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MQ)) { + return VIRTIO_NET_ERR; + } + s = iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); + if (s != sizeof(mq)) { + return VIRTIO_NET_ERR; + } + queues = virtio_lduw_p(vdev, &mq.virtqueue_pairs); - if (cmd != VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + } else { return VIRTIO_NET_ERR; } - queues = virtio_lduw_p(vdev, &mq.virtqueue_pairs); - if (queues < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || queues > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX || queues > n->max_queues || @@ -3304,6 +3432,8 @@ static Property virtio_net_properties[] = { DEFINE_PROP_BIT64("ctrl_guest_offloads", VirtIONet, host_features, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false), + DEFINE_PROP_BIT64("rss", VirtIONet, host_features, + VIRTIO_NET_F_RSS, false), DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 96c68d4a92..cf16f5192e 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -126,6 +126,9 @@ typedef struct VirtioNetRscChain { /* Maximum packet size we can receive from tap device: header + 64k */ #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB)) +#define VIRTIO_NET_RSS_MAX_KEY_SIZE 40 +#define VIRTIO_NET_RSS_MAX_TABLE_LEN 128 + typedef struct VirtIONetQueue { VirtQueue *rx_vq; VirtQueue *tx_vq; @@ -199,6 +202,14 @@ struct VirtIONet { bool failover; DeviceListener primary_listener; Notifier migration_state; + struct { + bool enabled; + uint32_t hash_types; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; + uint16_t indirections_len; + uint16_t default_queue; + } rss_data; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, From patchwork Mon Mar 9 08:34:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11426385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B21014B7 for ; Mon, 9 Mar 2020 08:45:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F04220828 for ; Mon, 9 Mar 2020 08:45:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="AzQp7wlG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F04220828 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBE23-0000wl-E7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Mar 2020 04:45:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDsE-0007dl-FQ for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBDsD-0007MZ-3u for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:54 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38939) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBDsC-0007Kj-TC for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:53 -0400 Received: by mail-wr1-x442.google.com with SMTP id r15so4817921wrx.6 for ; Mon, 09 Mar 2020 01:34:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GtBl5NGPRd3fWz+5/kWPEnRPZvuPWKDkS2vvT0gB+Y8=; b=AzQp7wlG4j1Vug7B6otwVfXrbmxO6FKa1Hdz1wLgzXVqpnRcBbV4602Fy2km70c9KH J5qq6BOgA5QJIfYliiOeFEu3L+00Szawzay6+c43eb4T+TXYccjdU+NcvRMyh69cbAda hiY56rTNDMDCWo5UMp5uPNVWFqIXiRbo12Q1BBRcu1mumqIZdVKeRstlqHAkkyav9zSJ 8n5kgpPgtz1Jff8PBBAOJL4TMCnyFzsl4Ic7Z/bZ64D0hlbMLr5oWFIgSLCQpqbSjJ6J QFPmolf26nk8DkVXreRQAMY75ZLcgrutLorLjL+AdcnlDyNYBiTvnknd3yRov2LL3CyG EpHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GtBl5NGPRd3fWz+5/kWPEnRPZvuPWKDkS2vvT0gB+Y8=; b=Tit7IXJ+vLBWPDAHydeQRXfzOarPkMgv+93A+yMXIMZeYeTF3jWkGLZ9pj8tR0UbIg DtR0RNCrfp/T5Jbn7yVUV4AEAnR8VEijUdFE5ZHlfLTiCR6aCAGkDtRYIB9CPnOgDXSC wTqf4XkErwBaRLalq8KsBEbkzJ265BjmIvJtrYqZs/HdHnilVO5XieCl21jh84tQtdPl KLNBOCANGSu6zhBV61/qq4o4vMCu9ZyOgQ0sq4ar8pXkI+RA3jKos26aaioZ9mF1/3hh 10UiOHHy2WhBdSDsZwdVKqd/S5mestn+IlFgvJtYmPRqfrqlRbgLU6EQGJIF8nFeX0HW dOUw== X-Gm-Message-State: ANhLgQ3qhx6VaBwFDfGq84ogDX1ryrC3R2zYI/aoWiUmwnwrC3mEVkBL LmpYwaPDpLbnmEocmSz6UD4w2y35UFKZ8A== X-Google-Smtp-Source: ADFU+vvN56lUur+d0DJwlbJkjVd/SFS8A+y6mIhn3EQOfwCYwlWEdan96nmfk7BGKJBaIuybEoC13w== X-Received: by 2002:adf:de10:: with SMTP id b16mr18932617wrm.145.1583742891592; Mon, 09 Mar 2020 01:34:51 -0700 (PDT) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id h3sm63749726wrb.23.2020.03.09.01.34.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 01:34:51 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v2 3/4] virtio-net: implement RX RSS processing Date: Mon, 9 Mar 2020 10:34:37 +0200 Message-Id: <20200309083438.2389-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309083438.2389-1-yuri.benditovich@daynix.com> References: <20200309083438.2389-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 86 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 27071eccd2..abc41fdb16 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -42,6 +42,7 @@ #include "trace.h" #include "monitor/qdev.h" #include "hw/pci/pci.h" +#include "net_rx_pkt.h" #define VIRTIO_NET_VM_VERSION 11 @@ -1610,8 +1611,78 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) return 0; } +static uint8_t virtio_net_get_hash_type(bool isip4, + bool isip6, + bool isudp, + bool istcp, + uint32_t types) +{ + uint32_t mask; + if (isip4) { + if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) { + return NetPktRssIpV4Tcp; + } + if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) { + return NetPktRssIpV4Udp; + } + if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { + return NetPktRssIpV4; + } + } else if (isip6) { + mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYPE_TCPv6; + if (istcp && (types & mask)) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ? + NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp; + } + mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6; + if (isudp && (types & mask)) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ? + NetPktRssIpV6UdpEx : NetPktRssIpV6Udp; + } + mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6; + if (types & mask) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ? + NetPktRssIpV6Ex : NetPktRssIpV6; + } + } + return 0xff; +} + +static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, + size_t size) +{ + VirtIONet *n = qemu_get_nic_opaque(nc); + unsigned int index = nc->queue_index, new_index; + struct NetRxPkt *pkt = n->rss_data.pkt; + uint8_t net_hash_type; + uint32_t hash; + bool isip4, isip6, isudp, istcp; + net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, + size - n->host_hdr_len); + net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp); + if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) { + istcp = isudp = false; + } + if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) { + istcp = isudp = false; + } + net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp, + n->rss_data.hash_types); + if (net_hash_type > NetPktRssIpV6UdpEx) { + return n->rss_data.default_queue; + } + + hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); + new_index = hash & (n->rss_data.indirections_len - 1); + new_index = n->rss_data.indirections[new_index]; + if (index == new_index) { + return -1; + } + return new_index; +} + static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, - size_t size) + size_t size, bool no_rss) { VirtIONet *n = qemu_get_nic_opaque(nc); VirtIONetQueue *q = virtio_net_get_subqueue(nc); @@ -1625,6 +1696,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, return -1; } + if (!no_rss && n->rss_data.enabled) { + int index = virtio_net_process_rss(nc, buf, size); + if (index >= 0) { + NetClientState *nc2 = qemu_get_subqueue(n->nic, index); + return virtio_net_receive_rcu(nc2, buf, size, true); + } + } + /* hdr_len refers to the header we supply to the guest */ if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) { return 0; @@ -1719,7 +1798,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf, { RCU_READ_LOCK_GUARD(); - return virtio_net_receive_rcu(nc, buf, size); + return virtio_net_receive_rcu(nc, buf, size, false); } static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, @@ -3295,6 +3374,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) QTAILQ_INIT(&n->rsc_chains); n->qdev = dev; + + net_rx_pkt_init(&n->rss_data.pkt, false); } static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) @@ -3331,6 +3412,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) g_free(n->vqs); qemu_del_nic(n->nic); virtio_net_rsc_cleanup(n); + net_rx_pkt_uninit(n->rss_data.pkt); virtio_cleanup(vdev); } diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index cf16f5192e..45670dd054 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -209,6 +209,7 @@ struct VirtIONet { uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; uint16_t indirections_len; uint16_t default_queue; + struct NetRxPkt *pkt; } rss_data; }; From patchwork Mon Mar 9 08:34:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11426387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60E5614E3 for ; Mon, 9 Mar 2020 08:46:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37E6820637 for ; Mon, 9 Mar 2020 08:46:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="qnltBC7y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37E6820637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBE3G-0002ek-DQ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Mar 2020 04:46:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47285) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBDsF-0007fo-6b for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBDsE-0007Ol-3X for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:55 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39817) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBDsD-0007NG-SL for qemu-devel@nongnu.org; Mon, 09 Mar 2020 04:34:54 -0400 Received: by mail-wm1-x342.google.com with SMTP id f7so4204401wml.4 for ; Mon, 09 Mar 2020 01:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qwff9geVcA9Ofl81vgC89M4fcI3BmCYQGSyZyytOdBU=; b=qnltBC7yVakg4nqdoErtT2D3DClG3hrzoJeqQTbHxsSu6xjOcKmoRlZoyUPJ/FuZqC NtkbhXIliOaIO0fHOMAus7ReOo5jdLrtZVUlnxgwGzfB6dRiz3QJfYDHqfvnLwOWnK6V 4M+SEu2cj9x5ywQOJYGMVxXWJ798wxHglx8kfpioHz5LDSktiS1abDLX4N1fgXCKDT8a kfPEYmQKllM5e5FoQGGPyPEX9sN1v95+olwZRd5jN8Zx4dTijR3iwhzQATOX0SAvzY/F 0X0u84WfK5QF6vLkKBJaUHBQgCPbrautaeppeblHpvnKxu6P1DLgkN+d3MnzbAqjTdda mfGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qwff9geVcA9Ofl81vgC89M4fcI3BmCYQGSyZyytOdBU=; b=M56f2I0/15gOD1pmyIVc+Rmf2r+ho6V8nPfegzEQXC7zqIkM07ZGjKsu78dFIXYfqz dgd+mb74VC5xMmIohllLQnrYhKsDPItnbRQr6sp+Zxhywjv9NhmaYDtgSevD81Ms9IH+ 3r6jaRwbD6YPvW4pczwtSx7jdirIDqmBBPpDjbW+tRm9aYKReHzJG0Fob/OgO1dpMM5z Fsfz27HjYIO9diiiNPVIrlll7C/R+uYRfnmXpHkvI0ghFXiwbls25z8DRX+pT2mtDVrU 7FQodxTMq5iXfBNHHh0h03FeXYKCvKISklMNnDQWRPhD6nlScyZIWE7vNwOSlyZdVAXp PqAA== X-Gm-Message-State: ANhLgQ08XUKM5YOxIhOl6S7UuJ4e9fvlev2C0Nk2EU19HL/zrlgV3ZVP 6/FpoJ85liwRcfs/dvBJ8L6Jgp4wbUVi7w== X-Google-Smtp-Source: ADFU+vsWax8EvBxUUSu4b017CHsX2Y62Vq1glMujvpYYGxwHtHTxCn7b1dX/DC4aO8gS4rHq52CESQ== X-Received: by 2002:a1c:e341:: with SMTP id a62mr7003260wmh.121.1583742892693; Mon, 09 Mar 2020 01:34:52 -0700 (PDT) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id h3sm63749726wrb.23.2020.03.09.01.34.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 01:34:52 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v2 4/4] virtio-net: block migration if RSS feature negotiated Date: Mon, 9 Mar 2020 10:34:38 +0200 Message-Id: <20200309083438.2389-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309083438.2389-1-yuri.benditovich@daynix.com> References: <20200309083438.2389-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Block migration for reference implementation of RSS feature in QEMU. When we add support for RSS on backend side, we'll implement migration of current RSS settings. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 18 ++++++++++++++++++ include/hw/virtio/virtio-net.h | 1 + 2 files changed, 19 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index abc41fdb16..943d1931a2 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -37,6 +37,7 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/blocker.h" #include "standard-headers/linux/ethtool.h" #include "sysemu/sysemu.h" #include "trace.h" @@ -627,6 +628,12 @@ static void virtio_net_reset(VirtIODevice *vdev) n->announce_timer.round = 0; n->status &= ~VIRTIO_NET_S_ANNOUNCE; + if (n->migration_blocker) { + migrate_del_blocker(n->migration_blocker); + error_free(n->migration_blocker); + n->migration_blocker = NULL; + } + /* Flush any MAC and VLAN filter table state */ n->mac_table.in_use = 0; n->mac_table.first_multi = 0; @@ -1003,6 +1010,17 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) vhost_net_ack_features(get_vhost_net(nc->peer), features); } + if (virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + if (!n->migration_blocker) { + error_setg(&n->migration_blocker, "virtio-net: RSS negotiated"); + migrate_add_blocker(n->migration_blocker, &err); + if (err) { + error_report_err(err); + err = NULL; + } + } + } + if (virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) { memset(n->vlans, 0, MAX_VLAN >> 3); } else { diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 45670dd054..fba768ba9b 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -180,6 +180,7 @@ struct VirtIONet { virtio_net_conf net_conf; NICConf nic_conf; DeviceState *qdev; + Error *migration_blocker; int multiqueue; uint16_t max_queues; uint16_t curr_queues;