From patchwork Sun Mar 29 15:09:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464071 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 BDF4C1668 for ; Sun, 29 Mar 2020 15:11:08 +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 507CE206F6 for ; Sun, 29 Mar 2020 15:11:08 +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="coKMMCyL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 507CE206F6 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]:38510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZad-000174-Ck for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:11:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38423) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZg-0007hk-Jz for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZf-0006ik-HU for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:08 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39821) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZf-0006iT-Bs for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:07 -0400 Received: by mail-wr1-x444.google.com with SMTP id p10so17868821wrt.6 for ; Sun, 29 Mar 2020 08:10:07 -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=O0gbhhNXKqovD8z2owZu41rSHwkPJ8sCWBwXndaIn/A=; b=coKMMCyLiayixMsGIiKDBVR/3Y/gX40JNOYnknkXe4Wct0gSa7OemQwlmC6oSJyCsg UwejKNMISwqLDbGsy8q+4f8+mg7uI/K1RM9uWPWz4WKhGYYyJiNN0TkujIdRapIXI/6r J38bGsgZSPHrd8VwKNMwaMk5nT+gFQ9stRVEGBA3Z0EgC9a7tWomZ5ClqyEA5h6G9V+T QzSBU8wPlJAcaaF3s+BVVyl0pykmz07/udBW9PpTvPEUzcOl7ZM/7if2Ehk85X53niju 2jx6OF1aBs98OIbedABRoy3BTn+XuMgGG+iAnsG4Nc5TfGa/pXZr8iuGbMPTtD+zTPa7 x3Pw== 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=O0gbhhNXKqovD8z2owZu41rSHwkPJ8sCWBwXndaIn/A=; b=B2ZCgDtU+DJ3eR+HPk9BhGO9TpJc7JWubJyi44hJk59kkbQ4n4DAqSg5msz3SQyyG2 JOx8ldBfVVm5Q7kOZ4NFTqMZnabCxXJs1qSvyJ6GhUT7verZYfvRj1jPDftvpkIcJ/yF ZARemMD0wfyGzYGCUArmEHC8BNnmx5q9YNRtKuE8Hq1j7E4EZvOxlKEKe1eGJRezoajP rDsEJLvmfFCncN+wFdUcZzl/7yiKyT4ix5ZIqOFgCPxPmGf50LPVMelUbIij3+gNIOdz kd3kkvxDxay0kkNBX0ciOV5LvD5PrZRO5kg+IbhQhJ4Kq1bFwJnxWhO0nlg4Dvcr/R8K 0yCg== X-Gm-Message-State: ANhLgQ0P3dS2U4E/vvoLSAeLfFkgCYiGBDWQPPOiYEY6AtpocydvAIDJ B0VAKDhaJpv3qBvMOXNqqmXA6PuqxpT1Qw== X-Google-Smtp-Source: ADFU+vvModLcf/7y28bcWnXCZC+3CTilc6VaRlEzC7lS9xSiXL5ZIm4h6V2ck65w8/K3EKnXMzaGKA== X-Received: by 2002:adf:82c5:: with SMTP id 63mr10055848wrc.312.1585494606061; Sun, 29 Mar 2020 08:10:06 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:05 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 1/7] virtio-net: introduce RSS and hash report features Date: Sun, 29 Mar 2020 18:09:47 +0300 Message-Id: <20200329150953.23812-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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::444 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 | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3627bb1717..90b01221e9 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -71,6 +71,71 @@ #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) + +struct virtio_net_config_with_rss { + struct virtio_net_config cfg; + /* maximum size of RSS key */ + uint8_t rss_max_key_size; + /* maximum number of indirection table entries */ + uint16_t rss_max_indirection_table_length; + /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */ + uint32_t supported_hash_types; +} QEMU_PACKED; + +struct virtio_net_hdr_v1_hash { + struct virtio_net_hdr_v1 hdr; + uint32_t 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 + uint16_t hash_report; + uint16_t 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 { + uint32_t hash_types; + uint16_t indirection_table_mask; + uint16_t unclassified_queue; + uint16_t indirection_table[1/* + indirection_table_mask */]; + uint16_t max_tx_vq; + uint8_t hash_key_length; + uint8_t 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 Sun Mar 29 15:09:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464073 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 E3B40913 for ; Sun, 29 Mar 2020 15:11:14 +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 A8EF1206F6 for ; Sun, 29 Mar 2020 15:11:14 +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="QMeYTymJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A8EF1206F6 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]:38512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZaj-0001IM-Ne for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:11:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38435) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZi-0007kH-LQ for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZg-0006jo-Qy for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:10 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:37972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZg-0006jV-K1 for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:08 -0400 Received: by mail-wm1-x342.google.com with SMTP id f6so11732752wmj.3 for ; Sun, 29 Mar 2020 08:10:08 -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=hzTgDmc2l99dgxfuy3BlzwK5Gs4fbq/Tfv23wV/AqwI=; b=QMeYTymJzeHsBFFxkcsD4WPEluZ6wRYoekEY1Ev8WmtZALu2UusrYtT9H4hOoF5mA5 EkTqS/aXm9qEYl7MLkv4dr50UqYfz5za47qMqpf7OySOypODY0/UETR4mnmW5vR21+Em ho/F7S0qSHt0tc8/m3ywrnfhaq+SmfLx8BNa2dv6e+FvGchbBsO+scHvJIMbqb++y5Kq dilzl37mDdg6WZKlPAv1BLlTcelTKLDjxOXrwp18cJZ0DkzaoHstFAH3tbMgAc96K+Vx yoTCrmdg+GY3BiAgCwkLxSwOx/LU+qKYi+Rvza44xnbYPXK3nICMMhrM2pjKYwKYJkLm xoFQ== 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=hzTgDmc2l99dgxfuy3BlzwK5Gs4fbq/Tfv23wV/AqwI=; b=dsH4uJLZmUfZsbhGlqIGsSU4qk423vOcla8BdWe6zDMHtG3sMXAHgELwpczedvlNHV C7NDlNLV5RjyZOelB1fjHCWLPT0n946TLdxF4qtrcthyRDV36jPGcRsjG/6ofTnTf4AZ e3jgK/C7LmgW6aLZo9+e5Vo2SrgT9ZWYNIrNQ4R+HtlkWEq9hs+3V0xizkYo+dcFTUln CpFrjy6nlBxPmKRPhhhh9sojsQadRI/MhTgf/DTKCNLpV8SKJTfW2BKeLcU3u44MjIld OlRY7tPZexu0b+vlWJmFN1hRQAaCCjUWJfQ5xvQ/Szq0ZraRPg/2gd41FoebVEbspJLi 6pAw== X-Gm-Message-State: ANhLgQ3zqD+kN+xkBbPr6n1/8Vj9AjPgr+hf6jrgPDzvJi65rC4tUUId 2moDWYL/h1e9PqPuTdwZQIhN49BiS9JrpQ== X-Google-Smtp-Source: ADFU+vuQjKpS3ZNihhbLv/DutmxBw1J7s+ajX6ewKF464SSNDbaK9rOyXTedFf4INqfQS6/PTEc0Pw== X-Received: by 2002:a1c:f70a:: with SMTP id v10mr8610588wmh.72.1585494607262; Sun, 29 Mar 2020 08:10:07 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:06 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 2/7] virtio-net: implement RSS configuration command Date: Sun, 29 Mar 2020 18:09:48 +0300 Message-Id: <20200329150953.23812-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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" 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 | 189 +++++++++++++++++++++++++++++---- include/hw/virtio/virtio-net.h | 13 +++ 3 files changed, 185 insertions(+), 20 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index a1da98a643..a84b9c3d9f 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(const char *msg, uint32_t value) "%s, value 0x%08x" +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 90b01221e9..6d21922746 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -142,6 +142,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) @@ -173,6 +183,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_with_rss, supported_hash_types)}, {} }; @@ -195,28 +207,33 @@ static int vq2q(int queue_index) static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) { VirtIONet *n = VIRTIO_NET(vdev); - struct virtio_net_config netcfg; - - virtio_stw_p(vdev, &netcfg.status, n->status); - virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues); - virtio_stw_p(vdev, &netcfg.mtu, n->net_conf.mtu); - memcpy(netcfg.mac, n->mac, ETH_ALEN); - virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); - netcfg.duplex = n->net_conf.duplex; + struct virtio_net_config_with_rss netcfg; + + virtio_stw_p(vdev, &netcfg.cfg.status, n->status); + virtio_stw_p(vdev, &netcfg.cfg.max_virtqueue_pairs, n->max_queues); + virtio_stw_p(vdev, &netcfg.cfg.mtu, n->net_conf.mtu); + memcpy(netcfg.cfg.mac, n->mac, ETH_ALEN); + virtio_stl_p(vdev, &netcfg.cfg.speed, n->net_conf.speed); + netcfg.cfg.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); } static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) { VirtIONet *n = VIRTIO_NET(vdev); - struct virtio_net_config netcfg = {}; + struct virtio_net_config_with_rss netcfg = {}; memcpy(&netcfg, config, n->config_size); if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR) && !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1) && - memcmp(netcfg.mac, n->mac, ETH_ALEN)) { - memcpy(n->mac, netcfg.mac, ETH_ALEN); + memcmp(netcfg.cfg.mac, n->mac, ETH_ALEN)) { + memcpy(n->mac, netcfg.cfg.mac, ETH_ALEN); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); } } @@ -766,6 +783,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; @@ -925,6 +943,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, @@ -1201,25 +1220,152 @@ 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; + const char *err_msg = ""; + uint32_t err_value = 0; + + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + err_msg = "RSS is not negotiated"; + 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_msg = "Short command buffer"; + err_value = (uint32_t)s; + 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_msg = "Invalid size of indirection table"; + err_value = n->rss_data.indirections_len; + goto error; + } + if (n->rss_data.indirections_len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { + err_msg = "Too large indirection table"; + err_value = n->rss_data.indirections_len; + goto error; + } + n->rss_data.default_queue = + virtio_lduw_p(vdev, &cfg.unclassified_queue); + if (n->rss_data.default_queue >= n->max_queues) { + err_msg = "Invalid default queue"; + err_value = n->rss_data.default_queue; + goto error; + } + offset += size_get; + size_get = sizeof(uint16_t) * n->rss_data.indirections_len; + g_free(n->rss_data.indirections_table); + n->rss_data.indirections_table = g_malloc(size_get); + if (!n->rss_data.indirections_table) { + err_msg = "Can't allocate indirections table"; + err_value = n->rss_data.indirections_len; + goto error; + } + s = iov_to_buf(iov, iov_cnt, offset, + n->rss_data.indirections_table, size_get); + if (s != size_get) { + err_msg = "Short indirection table buffer"; + err_value = (uint32_t)s; + goto error; + } + for (i = 0; i < n->rss_data.indirections_len; ++i) { + uint16_t val = n->rss_data.indirections_table[i]; + n->rss_data.indirections_table[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_msg = "Can't get queues"; + err_value = (uint32_t)s; + goto error; + } + queues = virtio_lduw_p(vdev, &temp.us); + if (queues == 0 || queues > n->max_queues) { + err_msg = "Invalid number of queues"; + err_value = queues; + goto error; + } + if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { + err_msg = "Invalid key size"; + err_value = temp.b; + goto error; + } + if (!temp.b && n->rss_data.hash_types) { + err_msg = "No key provided"; + err_value = 0; + 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_msg = "Can get key buffer"; + err_value = (uint32_t)s; + 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: + trace_virtio_net_rss_error(err_msg, err_value); + 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 || @@ -3173,6 +3319,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); + g_free(n->rss_data.indirections_table); virtio_cleanup(vdev); } @@ -3274,6 +3421,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..d3fad7c8f3 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -126,6 +126,18 @@ 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 VirtioNetRssData { + bool enabled; + uint32_t hash_types; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + uint16_t indirections_len; + uint16_t *indirections_table; + uint16_t default_queue; +} VirtioNetRssData; + typedef struct VirtIONetQueue { VirtQueue *rx_vq; VirtQueue *tx_vq; @@ -199,6 +211,7 @@ struct VirtIONet { bool failover; DeviceListener primary_listener; Notifier migration_state; + VirtioNetRssData rss_data; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, From patchwork Sun Mar 29 15:09:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464079 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 6E93B1668 for ; Sun, 29 Mar 2020 15:13:27 +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 448A6206F6 for ; Sun, 29 Mar 2020 15:13:27 +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="jnSFZbxv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 448A6206F6 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]:38538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZcs-0004To-D4 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:13:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38442) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZj-0007mU-RX for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZi-0006m0-Cj for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:11 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:37973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZi-0006kw-5x for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:10 -0400 Received: by mail-wm1-x343.google.com with SMTP id f6so11732813wmj.3 for ; Sun, 29 Mar 2020 08:10:10 -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=WOUtMRnFxKV7Y8XZ7UkZhOgeNFYtSpzSIraASB9IW38=; b=jnSFZbxvlHVeDSnRLKOogAulIP+ejSP7CuAszns1LJAIeYNHfZ1Nn8ab0BZQjqghGm a5kECLeU/GQsPLgGTVI0STbc+IL+ypm7hh3f9dkqipXFkppT8P351kPVdNs0+9stTiae gllLxhj03Cxev/jN6hwGzbp7no1jxrOvJlVQS15q1KPjAHt9rRSmo5YYaYEcB+UtXMv7 fhw0dzcLiYQrHaljqac250hvyuXvmP/WfnYVc3ggeYWRIB2aqTBjJMRcaNpISof7ofWF /UDELHFHaSQ68ouIDh6huep4jvD1RQjarE2turQIyEWz+q1UQHRo3Xgz0SUGmjrqoEA8 rYFg== 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=WOUtMRnFxKV7Y8XZ7UkZhOgeNFYtSpzSIraASB9IW38=; b=sq76M/HMQV2FkVZrjw7QpqZxY+H5LaN4BZLZ249xXMbooqy1ZexRGuFVjO/Kb7vT6d B8w3nrMlsElv1SWcnDiVQABmG41EuBw1DOPtL0y16OL5bhM8Orcw9XzJAsigkj93Iox7 tvSu1okvfdOO/bymzwEYAM9FIRtdWhncTmC9xsm4wqqBvJDyumBgtJyRV+Xsu1yinDY8 Nzjg75fuTw0tziVGKLvrQzsd5Ic02Yd8sFFYKxd37uJZmwfMyta3NQPVG8PQUJgCDRUp 4Pwa9d816RZDYLc1IWFRZIYCDsgmPvpxzi5200fa3EXnKAr0zLdXTocH8hUAjl9+EifR VWGw== X-Gm-Message-State: ANhLgQ2lA26f4+sdG90GU+842dL4FIQ9AjgTd+x2v9kXkvn2Xk8GuFlc qJfMgBtAPug0jy1R5BilHf9d/1Gzn7RvvA== X-Google-Smtp-Source: ADFU+vvJIAMVTTUEBXe749OTOHbQ3XcD5OwFEsSVAfk11wLZvqW9v5jMC8KgRaz+XmUKKGMZfeGkhQ== X-Received: by 2002:a7b:c105:: with SMTP id w5mr2266938wmi.168.1585494608529; Sun, 29 Mar 2020 08:10:08 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:08 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 3/7] virtio-net: implement RX RSS processing Date: Sun, 29 Mar 2020 18:09:49 +0300 Message-Id: <20200329150953.23812-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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::343 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 | 88 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6d21922746..de2d68d4ca 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 @@ -1598,8 +1599,80 @@ 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) +{ + 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) { + uint32_t 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->rx_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_table[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); @@ -1613,6 +1686,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; @@ -1707,7 +1788,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, @@ -3283,6 +3364,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) QTAILQ_INIT(&n->rsc_chains); n->qdev = dev; + + net_rx_pkt_init(&n->rx_pkt, false); } static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) @@ -3320,6 +3403,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) qemu_del_nic(n->nic); virtio_net_rsc_cleanup(n); g_free(n->rss_data.indirections_table); + net_rx_pkt_uninit(n->rx_pkt); virtio_cleanup(vdev); } diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index d3fad7c8f3..5081f3c52a 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -212,6 +212,7 @@ struct VirtIONet { DeviceListener primary_listener; Notifier migration_state; VirtioNetRssData rss_data; + struct NetRxPkt *rx_pkt; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, From patchwork Sun Mar 29 15:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464077 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 6EC6C913 for ; Sun, 29 Mar 2020 15:13:17 +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 45020206F6 for ; Sun, 29 Mar 2020 15:13:17 +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="UVh4WUij" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45020206F6 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]:38536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZci-0004GY-Cr for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:13:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38453) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZk-0007nq-Jo for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZj-0006nB-Du for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:12 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZj-0006mL-7a for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:11 -0400 Received: by mail-wr1-x444.google.com with SMTP id m17so17823860wrw.11 for ; Sun, 29 Mar 2020 08:10:11 -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=6H29QJg5B7bgS/AMKBONCsgkT/bfdiwpiQn7qsNuQ08=; b=UVh4WUij5fWwaB4E2nyzgrcyB5apVx1mXWyxUpXssPCpNfl8Rrpwrr0butWVGRpWEA Y3ZOtbbZOJsnQGKawwq0oll8fpOEGLeG2hKX1M4kGIfMUHoaIKOWw6oF7DQVeN7vut2G 9BeOOoxYJ6khgw/Kbvwy1CH6IXxJFPmQT4Pr6dKHvwK399cG4JB5T1xAeR3dbViC10GQ BwyagtiTeo3hkTloQjKXUJ/ZysOAPXaeYyE2bRP07pJSuoAgz84eTvrhF5af3BX+2qtK UB57hYfXrN+y01TsntV/M2UQT3fXIFNELhkJ8AFPxW/RbPnv5nnWfmWKLaBLekFgM1Bz z6ng== 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=6H29QJg5B7bgS/AMKBONCsgkT/bfdiwpiQn7qsNuQ08=; b=AReJBSVBQi3zlkhzumTc6bqr5NIODv/YD+uzNjX+HkEsh+8fc9ruldsusaCmDRayif +X12kmY9dhnhK+lel3NkSZ8KtLiqfNCYh1qwmKXilMt/iTuTtNW7T0Eqt77x/lZnZRn6 ZF1iVHF03xOfAArQQSTpCSUAMb2ZhKohCCdrdQuRZLBbx/larYrafWhNyGeYdnu0CdnD PWeuDwwyma5FiMUPkbh1wnNomtp9lfjVFsJrmDDEi88Kq6suYXnfiP2HE5lrKNIV48dc ceKKep85imloStI5hAbVyYS6v7cmauLgdMIeupS2+WJJykTBE+u1wDZqQ0EbG6cKXUg5 EheQ== X-Gm-Message-State: ANhLgQ0nkUvjrIKoOCP1LZBC8KQ5fAtU+UdxSDLBIzpaSwoBbzvaHCpE CgO++z//H7GotUShxAyivygej7tjpzwGHw== X-Google-Smtp-Source: ADFU+vuRIrvcMRuGGl8ciVQ1ek+fGMp21HLObHU/3pzUMTBN3oxxD66tp9j8q0XRUyEXNPEucd2BBg== X-Received: by 2002:a5d:6992:: with SMTP id g18mr10449960wru.426.1585494609942; Sun, 29 Mar 2020 08:10:09 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:09 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 4/7] tap: allow extended virtio header with hash info Date: Sun, 29 Mar 2020 18:09:50 +0300 Message-Id: <20200329150953.23812-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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::444 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 --- net/tap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/tap.c b/net/tap.c index 6207f61f84..47de7fdeb6 100644 --- a/net/tap.c +++ b/net/tap.c @@ -63,6 +63,14 @@ typedef struct TAPState { Notifier exit; } TAPState; +/* TODO: remove when virtio_net.h updated */ +struct virtio_net_hdr_v1_hash { + struct virtio_net_hdr_v1 hdr; + uint32_t hash_value; + uint16_t hash_report; + uint16_t padding; +}; + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -254,7 +262,8 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) assert(nc->info->type == NET_CLIENT_DRIVER_TAP); assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) || - len == sizeof(struct virtio_net_hdr)); + len == sizeof(struct virtio_net_hdr) || + len == sizeof(struct virtio_net_hdr_v1_hash)); tap_fd_set_vnet_hdr_len(s->fd, len); s->host_vnet_hdr_len = len; From patchwork Sun Mar 29 15:09:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464085 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 771AE92C for ; Sun, 29 Mar 2020 15:16:13 +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 ED29B20578 for ; Sun, 29 Mar 2020 15:16:12 +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="SJCZGKF7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED29B20578 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]:38586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZfX-00081R-SM for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:16:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38475) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZm-0007rx-UT for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZl-0006rG-3S for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:14 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:40414) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZk-0006ot-Rb for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:13 -0400 Received: by mail-wr1-x441.google.com with SMTP id u10so17865749wro.7 for ; Sun, 29 Mar 2020 08:10:12 -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=0AgrHwe7+u0B2MfHFgcrrKyy4F0DXEK/+Q2DWgHDYg0=; b=SJCZGKF7/lVmF1PYjezFX/2W7hDZy9LNYGKJ7sRqK1JqIO3uyFTv8BoF6AToJw5qEL ZyKQMWKBmlMQ66UxQmK1YINzWnFLZt4Gf6QiwWyBPobbntyI7zYlCskmaC7Zpz/k+GF+ 5JpMdyLbpBcaEdxtIx1Z6ctH3gPPFfhWWTVmy6mRUj/8Ycd80VitYFg1RFtFqx3dNC1U h9lTCX5MbQvqH9OMmXSpogpeQbzOld1QsmXf5j1kuK7mODF8loorYUcSlHUS6tDEfOAJ lHanDG5dBj9zshRgOZDXVJfnvBG7HzrJHcBLAi+qV+WoL06j72uAYY3tyJCB6Raj9FlW GxcQ== 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=0AgrHwe7+u0B2MfHFgcrrKyy4F0DXEK/+Q2DWgHDYg0=; b=mBiNkYrFi29gyKPvT96eJWWCYKaoU4QfEhXbUzTiOYkh3pWr6hRABsGU/v1Kn43l8c p9eiE/GkoNx7IdsE4/NJwIY9PbjOrTpCZDHq2OopcyWEX91Ivtjnxe+NvTZrdmf9G9gr 5B/V/vXFchVnewCaSrz0dW1Hclf3O2N2MApvRxnJtet0+2Lh+BoffIZR0AHfjD8+0eN6 TDOyqP8N5BMMGLvCTRUP4vlOJ97jgrdkF3IdoejJx18Jr/27XIk7xf8GNZ3h40BClPaC 8CH7qjmzEkOmH3PoxzcQcq5v89zjv1vhIV01KfD3kPoZ2orXUEROBHCWYuMCymSiCaS+ m34g== X-Gm-Message-State: ANhLgQ2eEuxZftOVzGMdfXJcWO8qCAFB4k7Xe7Jwe3brc7J8BSXZS5HL Lc5kytrXDXTertzxycJdtLa2FPc6syFkzA== X-Google-Smtp-Source: ADFU+vvQFETRY5PRf80c8g8r8F+5SwtKPN2plngMFJ+TjJL1+bDuaKo1i3L5xNwpo6W4Lv2G+BrlxA== X-Received: by 2002:adf:f646:: with SMTP id x6mr10155420wrp.19.1585494611193; Sun, 29 Mar 2020 08:10:11 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:10 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 5/7] virtio-net: reference implementation of hash report Date: Sun, 29 Mar 2020 18:09:51 +0300 Message-Id: <20200329150953.23812-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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" Suggest VIRTIO_NET_F_HASH_REPORT if specified in device parameters. If the VIRTIO_NET_F_HASH_REPORT is set, the device extends configuration space. If the feature is negotiated, the packet layout is extended to accomodate the hash information. In this case deliver packet's hash value and report type in virtio header extension. Use for configuration the same procedure as already used for RSS. We add two fields in rss_data that controls what the device does with the calculated hash if rss_data.enabled is set. If field 'populate' is set the hash is set in the packet, if field 'redirect' is set the hash is used to decide the queue to place the packet to. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 99 +++++++++++++++++++++++++++------- include/hw/virtio/virtio-net.h | 2 + 2 files changed, 81 insertions(+), 20 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index de2d68d4ca..61c956d0ff 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -184,7 +184,7 @@ 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, + {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL << VIRTIO_NET_F_HASH_REPORT), .end = endof(struct virtio_net_config_with_rss, supported_hash_types)}, {} }; @@ -218,7 +218,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) netcfg.cfg.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_host_has_feature(vdev, VIRTIO_NET_F_RSS) ? + VIRTIO_NET_RSS_MAX_TABLE_LEN : 1); virtio_stl_p(vdev, &netcfg.supported_hash_types, VIRTIO_NET_RSS_SUPPORTED_HASHES); memcpy(config, &netcfg, n->config_size); @@ -644,7 +645,7 @@ static int peer_has_ufo(VirtIONet *n) } static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, - int version_1) + int version_1, int hash_report) { int i; NetClientState *nc; @@ -652,7 +653,10 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, n->mergeable_rx_bufs = mergeable_rx_bufs; if (version_1) { - n->guest_hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->guest_hdr_len = hash_report ? + sizeof(struct virtio_net_hdr_v1_hash) : + sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->rss_data.populate_hash = !!hash_report; } else { n->guest_hdr_len = n->mergeable_rx_bufs ? sizeof(struct virtio_net_hdr_mrg_rxbuf) : @@ -773,6 +777,8 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4); virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6); virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN); + + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); } if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { @@ -785,6 +791,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, } virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); features = vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features = features; @@ -951,12 +958,15 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) virtio_has_feature(features, VIRTIO_NET_F_MRG_RXBUF), virtio_has_feature(features, - VIRTIO_F_VERSION_1)); + VIRTIO_F_VERSION_1), + virtio_has_feature(features, + VIRTIO_NET_F_HASH_REPORT)); n->rsc4_enabled = virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT) && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO4); n->rsc6_enabled = virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT) && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO6); + n->rss_data.redirect = virtio_has_feature(features, VIRTIO_NET_F_RSS); if (n->has_vnet_hdr) { n->curr_guest_offloads = @@ -1230,7 +1240,9 @@ static void virtio_net_disable_rss(VirtIONet *n) } static uint16_t virtio_net_handle_rss(VirtIONet *n, - struct iovec *iov, unsigned int iov_cnt) + struct iovec *iov, + unsigned int iov_cnt, + bool do_rss) { VirtIODevice *vdev = VIRTIO_DEVICE(n); struct virtio_net_rss_config cfg; @@ -1243,10 +1255,14 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, const char *err_msg = ""; uint32_t err_value = 0; - if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + if (do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { err_msg = "RSS is not negotiated"; goto error; } + if (!do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) { + err_msg = "Hash report is not negotiated"; + 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) { @@ -1258,6 +1274,9 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, n->rss_data.indirections_len = virtio_lduw_p(vdev, &cfg.indirection_table_mask); n->rss_data.indirections_len++; + if (!do_rss) { + n->rss_data.indirections_len = 1; + } if (!is_power_of_2(n->rss_data.indirections_len)) { err_msg = "Invalid size of indirection table"; err_value = n->rss_data.indirections_len; @@ -1268,8 +1287,8 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = n->rss_data.indirections_len; goto error; } - n->rss_data.default_queue = - virtio_lduw_p(vdev, &cfg.unclassified_queue); + n->rss_data.default_queue = do_rss ? + virtio_lduw_p(vdev, &cfg.unclassified_queue) : 0; if (n->rss_data.default_queue >= n->max_queues) { err_msg = "Invalid default queue"; err_value = n->rss_data.default_queue; @@ -1303,7 +1322,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = (uint32_t)s; goto error; } - queues = virtio_lduw_p(vdev, &temp.us); + queues = do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_queues; if (queues == 0 || queues > n->max_queues) { err_msg = "Invalid number of queues"; err_value = queues; @@ -1349,8 +1368,12 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, uint16_t queues; virtio_net_disable_rss(n); + if (cmd == VIRTIO_NET_CTRL_MQ_HASH_CONFIG) { + queues = virtio_net_handle_rss(n, iov, iov_cnt, false); + return queues ? VIRTIO_NET_OK : VIRTIO_NET_ERR; + } if (cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { - queues = virtio_net_handle_rss(n, iov, iov_cnt); + queues = virtio_net_handle_rss(n, iov, iov_cnt, true); } else if (cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { struct virtio_net_ctrl_mq mq; size_t s; @@ -1637,15 +1660,34 @@ static uint8_t virtio_net_get_hash_type(bool isip4, return 0xff; } +static void virtio_set_packet_hash(const uint8_t *buf, uint8_t report, + uint32_t hash) +{ + struct virtio_net_hdr_v1_hash *hdr = (void *)buf; + hdr->hash_value = hash; + hdr->hash_report = report; +} + 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; + unsigned int index = nc->queue_index, new_index = index; struct NetRxPkt *pkt = n->rx_pkt; uint8_t net_hash_type; uint32_t hash; bool isip4, isip6, isudp, istcp; + static const uint8_t reports[NetPktRssIpV6UdpEx + 1] = { + VIRTIO_NET_HASH_REPORT_IPv4, + VIRTIO_NET_HASH_REPORT_TCPv4, + VIRTIO_NET_HASH_REPORT_TCPv6, + VIRTIO_NET_HASH_REPORT_IPv6, + VIRTIO_NET_HASH_REPORT_IPv6_EX, + VIRTIO_NET_HASH_REPORT_TCPv6_EX, + VIRTIO_NET_HASH_REPORT_UDPv4, + VIRTIO_NET_HASH_REPORT_UDPv6, + VIRTIO_NET_HASH_REPORT_UDPv6_EX + }; net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, size - n->host_hdr_len); @@ -1659,16 +1701,24 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, 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; + if (n->rss_data.populate_hash) { + virtio_set_packet_hash(buf, VIRTIO_NET_HASH_REPORT_NONE, 0); + } + return n->rss_data.redirect ? n->rss_data.default_queue : -1; } 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_table[new_index]; - if (index == new_index) { - return -1; + + if (n->rss_data.populate_hash) { + virtio_set_packet_hash(buf, reports[net_hash_type], hash); } - return new_index; + + if (n->rss_data.redirect) { + new_index = hash & (n->rss_data.indirections_len - 1); + new_index = n->rss_data.indirections_table[new_index]; + } + + return (index == new_index) ? -1 : new_index; } static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, @@ -1744,6 +1794,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, } receive_header(n, sg, elem->in_num, buf, size); + if (n->rss_data.populate_hash) { + offset = sizeof(mhdr); + iov_from_buf(sg, elem->in_num, offset, + buf + offset, n->host_hdr_len - sizeof(mhdr)); + } offset = n->host_hdr_len; total += n->guest_hdr_len; guest_offset = n->guest_hdr_len; @@ -2736,7 +2791,9 @@ static int virtio_net_post_load_device(void *opaque, int version_id) trace_virtio_net_post_load_device(); virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, - VIRTIO_F_VERSION_1)); + VIRTIO_F_VERSION_1), + virtio_vdev_has_feature(vdev, + VIRTIO_NET_F_HASH_REPORT)); /* MAC_TABLE_ENTRIES may be different from the saved image */ if (n->mac_table.in_use > MAC_TABLE_ENTRIES) { @@ -3352,7 +3409,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->vqs[0].tx_waiting = 0; n->tx_burst = n->net_conf.txburst; - virtio_net_set_mrg_rx_bufs(n, 0, 0); + virtio_net_set_mrg_rx_bufs(n, 0, 0, 0); n->promisc = 1; /* for compatibility */ n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); @@ -3507,6 +3564,8 @@ static Property virtio_net_properties[] = { 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("hash", VirtIONet, host_features, + VIRTIO_NET_F_HASH_REPORT, 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 5081f3c52a..a45ef8278e 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -131,6 +131,8 @@ typedef struct VirtioNetRscChain { typedef struct VirtioNetRssData { bool enabled; + bool redirect; + bool populate_hash; uint32_t hash_types; uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; uint16_t indirections_len; From patchwork Sun Mar 29 15:09:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464083 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 5DE7D1668 for ; Sun, 29 Mar 2020 15:14:45 +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 33F3720578 for ; Sun, 29 Mar 2020 15:14:45 +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="fejrOI5s" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33F3720578 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]:38554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZe8-0006Wq-DA for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:14:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZm-0007rT-Ld for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZl-0006sP-M3 for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:14 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZl-0006qy-G1 for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:13 -0400 Received: by mail-wr1-x441.google.com with SMTP id m11so11984703wrx.10 for ; Sun, 29 Mar 2020 08:10:13 -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=bKbcDZF4VvCdwc1Z3LgA0n0/o1l3SD8mbWQhoT1XpcI=; b=fejrOI5seWvIG/Q9LmOlTQjNz3G/dSKFn6twWJXwCyXxCUwoXl7pumgnVuFekVaEGJ ySQ0AvtB0UFcBeWm1DVEc1f/11TmrvsN8oR7Pqbbkk7poNVAyl3eJaRz0ToBR81WpMh1 2liQcwk3QXQeIdNxWtFbI2RT4sv7nHeR6119c3ZGgorSmYDXJ6g4y/s8kiHzsWB4tTZj iLGKSFI3Gfn8K28m1EiKXRWBvCTyTDvaMiqlJsYUtyYyRgjWfUSQZY14Sj5uXXpbuJv9 cxa7aBSiejZ2O1Gr5+d+/BuZRNuuZqRd5rvdKHBuTT9NyIVIpShMqSm3wG1j+KMHtvVg y/yg== 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=bKbcDZF4VvCdwc1Z3LgA0n0/o1l3SD8mbWQhoT1XpcI=; b=X9vVyUn7HzgDxZpc04hAXcEyedR5UhtsdvPGvRUgWVumWYyxsU9BPRKRPOi1sfMoBa dJuiYnacaQjeXcPwKEJQwwJU84VIX4aloKakPz0cfAso04+kW8N4T+zCJ5rGXKEHdt3n lRU+6nsBj8ZQ8GjQiRM5Gv+6EwOGGQtHWTC/k/zhWLgOOzWEGyZvsjS7ZzEPfyCRgsQa VIhs+469DT+eZ+YoX/oxGAua6zoNeJEbCNUQ6OV+eCcVpinl5V6/Mf1eAw28WR4mnaWn CyO4MbaHdERemCbj/wvvR4RzNAlV3sSMFPcc55qVV0xyDCG+bzlIT7m25Ghh9l5xM/R7 M37A== X-Gm-Message-State: ANhLgQ3ikThochMYRi4r9Q2n60XSGZ4ky5HAwkS9Ki6WsAOWAGD9y2Xo jDzQMA/pOHOqGPFHyknZGWMSIkL/b5wgTA== X-Google-Smtp-Source: ADFU+vtYJjlZauEf5fLVogYeIwgOod16FUfVvl1Nm+1FfwgzQ3xbCnSJeL8osUzC/tnsMz1iQzpLqQ== X-Received: by 2002:a5d:5106:: with SMTP id s6mr10064485wrt.24.1585494612395; Sun, 29 Mar 2020 08:10:12 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:11 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 6/7] vmstate.h: provide VMSTATE_VARRAY_UINT16_ALLOC macro Date: Sun, 29 Mar 2020 18:09:52 +0300 Message-Id: <20200329150953.23812-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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" Similar to VMSTATE_VARRAY_UINT32_ALLOC, but the size is 16-bit field. Signed-off-by: Michael S. Tsirkin Signed-off-by: Yuri Benditovich --- include/migration/vmstate.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 30667631bc..baaefb6b9b 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -432,6 +432,16 @@ extern const VMStateInfo vmstate_info_qlist; .offset = vmstate_offset_pointer(_state, _field, _type), \ } +#define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, _info, _type) {\ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .num_offset = vmstate_offset_value(_state, _field_num, uint16_t),\ + .info = &(_info), \ + .size = sizeof(_type), \ + .flags = VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ + .offset = vmstate_offset_pointer(_state, _field, _type), \ +} + #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version, _info, _type) {\ .name = (stringify(_field)), \ .version_id = (_version), \ From patchwork Sun Mar 29 15:09:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11464075 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 2FC901668 for ; Sun, 29 Mar 2020 15:13:17 +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 01A3A206F6 for ; Sun, 29 Mar 2020 15:13:17 +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="l+p8tCTC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01A3A206F6 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]:38534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZci-0004Ff-5j for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Mar 2020 11:13:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38493) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZZo-0007v5-C0 for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIZZn-0006tn-4E for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:16 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:37900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIZZm-0006sz-UF for qemu-devel@nongnu.org; Sun, 29 Mar 2020 11:10:15 -0400 Received: by mail-wr1-x443.google.com with SMTP id s1so17870732wrv.5 for ; Sun, 29 Mar 2020 08:10:14 -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=EH6oNg+1XnVlYF4aQzYUAyrXIjqeHFa39k5bqe6Q+YA=; b=l+p8tCTCfgIFRgyf2arLgXub8SgWRWX0+CbhLsbIIro3jZd4RcG5oRdz0KxlCoWc2r cw26mFOTpGQVCg450SemUV8jKcMLpXFk5cpg6kMAjAKoeH3LHqQEzAFTCAzYxou6mYTs IcaHNhVJkFpXgIRUbhCYEN3O+VDXNaMe9gqwScA9zEr2dnm97zVYLUGSb98n7gvtN+2t V/rA/OtOaaS607/NHn1raAGrUA0S1SJUpQMc2CxkPbYr1MPg3JjK4KOXY5lmssMr1Oog WcGg76iIaTboaCShaNEtIDSLKt+mDracNNmYC31YwlqZo6h5pqifzMXQ+KcEZBb79jmH Vm5g== 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=EH6oNg+1XnVlYF4aQzYUAyrXIjqeHFa39k5bqe6Q+YA=; b=QSmOxck8vFDUWVvGrGivRAJLYkEX/d1HrUiD8E0ePkCPYKRB3QiLmpQyx54I0VwGp2 LuYJIakJg2jr54JEi5wYQQZT2cqsgDnpKnYQHFKY9EUcCJolZwz+7WD7eahJl0pXHQAf Cfr/2cPIVzPdD7OfoD9coaBWvnsLmQbuyOeltMKcLQG1ZK74aZaMaYk1TC5B3Q2jNnHR 2Iwd9oxdnuz0YwNX6w82xwWJxMewpHVvQr4/aREDju0x47+d0Bcl4BVWiMdr6GocpjQq QKNKuMqeQnfMuuRpZMtOCUQN8KifjUUVrx+Ma1ULn1qWGncHQbTIOzMAm1IfwxEfcNn8 Ze3w== X-Gm-Message-State: ANhLgQ08s4QMOUm/QArSI7hYVLa7g8e3G1ayhaN+2sO28j+dd1V/kAfh Lt1N5soEI/vFUL58/XcRoQJsEYg+dYr/KQ== X-Google-Smtp-Source: ADFU+vslU04nEm8SoW6S7e1PbNm+/qe/nnMF9+VGeXLR6DPEhvUAj3d8jgkJN1yEzExov5hgx8RYtQ== X-Received: by 2002:adf:9e94:: with SMTP id a20mr10593777wrf.334.1585494613725; Sun, 29 Mar 2020 08:10:13 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-67-107.red.bezeqint.net. [79.183.67.107]) by smtp.gmail.com with ESMTPSA id s2sm5477874wmh.37.2020.03.29.08.10.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Mar 2020 08:10:13 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v7 7/7] virtio-net: add migration support for RSS and hash report Date: Sun, 29 Mar 2020 18:09:53 +0300 Message-Id: <20200329150953.23812-8-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200329150953.23812-1-yuri.benditovich@daynix.com> References: <20200329150953.23812-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" Save and restore RSS/hash report configuration. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 61c956d0ff..8e09aa0b99 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2842,6 +2842,13 @@ static int virtio_net_post_load_device(void *opaque, int version_id) } } + if (n->rss_data.enabled) { + trace_virtio_net_rss_enable(n->rss_data.hash_types, + n->rss_data.indirections_len, + sizeof(n->rss_data.key)); + } else { + trace_virtio_net_rss_disable(); + } return 0; } @@ -3019,6 +3026,32 @@ static const VMStateDescription vmstate_virtio_net_has_vnet = { }, }; +static bool virtio_net_rss_needed(void *opaque) +{ + return VIRTIO_NET(opaque)->rss_data.enabled; +} + +static const VMStateDescription vmstate_virtio_net_rss = { + .name = "virtio-net-device/rss", + .version_id = 1, + .minimum_version_id = 1, + .needed = virtio_net_rss_needed, + .fields = (VMStateField[]) { + VMSTATE_BOOL(rss_data.enabled, VirtIONet), + VMSTATE_BOOL(rss_data.redirect, VirtIONet), + VMSTATE_BOOL(rss_data.populate_hash, VirtIONet), + VMSTATE_UINT32(rss_data.hash_types, VirtIONet), + VMSTATE_UINT16(rss_data.indirections_len, VirtIONet), + VMSTATE_UINT16(rss_data.default_queue, VirtIONet), + VMSTATE_UINT8_ARRAY(rss_data.key, VirtIONet, + VIRTIO_NET_RSS_MAX_KEY_SIZE), + VMSTATE_VARRAY_UINT16_ALLOC(rss_data.indirections_table, VirtIONet, + rss_data.indirections_len, 0, + vmstate_info_uint16, uint16_t), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_net_device = { .name = "virtio-net-device", .version_id = VIRTIO_NET_VM_VERSION, @@ -3069,6 +3102,10 @@ static const VMStateDescription vmstate_virtio_net_device = { has_ctrl_guest_offloads), VMSTATE_END_OF_LIST() }, + .subsections = (const VMStateDescription * []) { + &vmstate_virtio_net_rss, + NULL + } }; static NetClientInfo net_virtio_info = {