From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494707; cv=none; d=zohomail.com; s=zohoarc; b=IBX/zPVDhZTqdZlms2rXC5y6N5Gtp061m9dUzSOKIF4T5zpt+uzMXhtKibILo7ArgELMfqMXc+DUzFNcsDqLO8R75erz4LrcHYqh1lifSaw+fYxTfepFUooYz+39egNvjbarEXefkc0NdRkGcC2wlSilYHi7U7Vy0/Jykd1Q5fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494707; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=O0gbhhNXKqovD8z2owZu41rSHwkPJ8sCWBwXndaIn/A=; b=kbDP+Hjyz4yucMTZjwNpJUaNdaiuTZev3LtylyLr9x6kjFDSk6P9AofLKsYlUEwTwEo6sAKE/n6TqLcCqMDqAmmaBSEybE7OELCL0XsCfUq6kEukWUxN5LrBcLM5BUYVCKWNqLh0fEga1DfpAlS+OpjlEg5+6G146IJTV29MXgs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494707586969.0780832434018; Sun, 29 Mar 2020 08:11:47 -0700 (PDT) Received: from localhost ([::1]:38510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZbF-000174-Vn for importer@patchew.org; Sun, 29 Mar 2020 11:11:46 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- 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 =20 +/* 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 performa= nce 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 --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494712; cv=none; d=zohomail.com; s=zohoarc; b=b66SrU3fZqni6MIAPTYXi4cpBmJJw+ZfG5k8jdPEoJhCmjd6WB6tplIGTDiyz6o5YUq4/d167HGhJwBpuaCDrZE7ojD/hv33ypI0hVcNkeJVqm3KXMtDq0ehT2n5swpRrLokHxkPtFda0iTqJnCs8QqXq8fRgwZKbxsrRe5UPis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494712; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=hzTgDmc2l99dgxfuy3BlzwK5Gs4fbq/Tfv23wV/AqwI=; b=Hg3B6GP9CvyBTMwgXzh3Naznv3UVmDDgKpkD2g9JB4Xq3sLXP84KjA7h1QrVNJzvZXCz/gqvCGH90M+oX+zRMR9F5IbP7EzhCepXPWE78LYq/xX2nv9aSS9ntx6fGlW470IDSoTbH6mAKfJvXfRO4EhcFApyUc9ZZWK86u0FtYo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494712899680.7300561739521; Sun, 29 Mar 2020 08:11:52 -0700 (PDT) Received: from localhost ([::1]:38512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZbL-0001IM-80 for importer@patchew.org; Sun, 29 Mar 2020 11:11:51 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Optionally report RSS feature. Handle RSS configuration command and keep RSS parameters in virtio-net device context. Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- 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" =20 # 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 =20 +#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) =20 @@ -173,6 +183,8 @@ static VirtIOFeature feature_sizes[] =3D { .end =3D endof(struct virtio_net_config, mtu)}, {.flags =3D 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, .end =3D endof(struct virtio_net_config, duplex)}, + {.flags =3D 1ULL << VIRTIO_NET_F_RSS, + .end =3D endof(struct virtio_net_config_with_rss, supported_hash_type= s)}, {} }; =20 @@ -195,28 +207,33 @@ static int vq2q(int queue_index) static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) { VirtIONet *n =3D 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 =3D 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 =3D n->net_conf.duplex; + netcfg.rss_max_key_size =3D 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); } =20 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *confi= g) { VirtIONet *n =3D VIRTIO_NET(vdev); - struct virtio_net_config netcfg =3D {}; + struct virtio_net_config_with_rss netcfg =3D {}; =20 memcpy(&netcfg, config, n->config_size); =20 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 *v= dev, uint64_t features, return features; } =20 + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); features =3D vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features =3D features; =20 @@ -925,6 +943,7 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) } =20 virtio_net_set_multiqueue(n, + virtio_has_feature(features, VIRTIO_NET_F_RS= S) || virtio_has_feature(features, VIRTIO_NET_F_MQ= )); =20 virtio_net_set_mrg_rx_bufs(n, @@ -1201,25 +1220,152 @@ static int virtio_net_handle_announce(VirtIONet *n= , uint8_t cmd, } } =20 +static void virtio_net_disable_rss(VirtIONet *n) +{ + if (n->rss_data.enabled) { + trace_virtio_net_rss_disable(); + } + n->rss_data.enabled =3D false; +} + +static uint16_t virtio_net_handle_rss(VirtIONet *n, + struct iovec *iov, unsigned int iov_= cnt) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + struct virtio_net_rss_config cfg; + size_t s, offset =3D 0, size_get; + uint16_t queues, i; + struct { + uint16_t us; + uint8_t b; + } QEMU_PACKED temp; + const char *err_msg =3D ""; + uint32_t err_value =3D 0; + + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + err_msg =3D "RSS is not negotiated"; + goto error; + } + size_get =3D offsetof(struct virtio_net_rss_config, indirection_table); + s =3D iov_to_buf(iov, iov_cnt, offset, &cfg, size_get); + if (s !=3D size_get) { + err_msg =3D "Short command buffer"; + err_value =3D (uint32_t)s; + goto error; + } + n->rss_data.hash_types =3D virtio_ldl_p(vdev, &cfg.hash_types); + n->rss_data.indirections_len =3D + 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 =3D "Invalid size of indirection table"; + err_value =3D n->rss_data.indirections_len; + goto error; + } + if (n->rss_data.indirections_len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { + err_msg =3D "Too large indirection table"; + err_value =3D n->rss_data.indirections_len; + goto error; + } + n->rss_data.default_queue =3D + virtio_lduw_p(vdev, &cfg.unclassified_queue); + if (n->rss_data.default_queue >=3D n->max_queues) { + err_msg =3D "Invalid default queue"; + err_value =3D n->rss_data.default_queue; + goto error; + } + offset +=3D size_get; + size_get =3D sizeof(uint16_t) * n->rss_data.indirections_len; + g_free(n->rss_data.indirections_table); + n->rss_data.indirections_table =3D g_malloc(size_get); + if (!n->rss_data.indirections_table) { + err_msg =3D "Can't allocate indirections table"; + err_value =3D n->rss_data.indirections_len; + goto error; + } + s =3D iov_to_buf(iov, iov_cnt, offset, + n->rss_data.indirections_table, size_get); + if (s !=3D size_get) { + err_msg =3D "Short indirection table buffer"; + err_value =3D (uint32_t)s; + goto error; + } + for (i =3D 0; i < n->rss_data.indirections_len; ++i) { + uint16_t val =3D n->rss_data.indirections_table[i]; + n->rss_data.indirections_table[i] =3D virtio_lduw_p(vdev, &val); + } + offset +=3D size_get; + size_get =3D sizeof(temp); + s =3D iov_to_buf(iov, iov_cnt, offset, &temp, size_get); + if (s !=3D size_get) { + err_msg =3D "Can't get queues"; + err_value =3D (uint32_t)s; + goto error; + } + queues =3D virtio_lduw_p(vdev, &temp.us); + if (queues =3D=3D 0 || queues > n->max_queues) { + err_msg =3D "Invalid number of queues"; + err_value =3D queues; + goto error; + } + if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { + err_msg =3D "Invalid key size"; + err_value =3D temp.b; + goto error; + } + if (!temp.b && n->rss_data.hash_types) { + err_msg =3D "No key provided"; + err_value =3D 0; + goto error; + } + if (!temp.b && !n->rss_data.hash_types) { + virtio_net_disable_rss(n); + return queues; + } + offset +=3D size_get; + size_get =3D temp.b; + s =3D iov_to_buf(iov, iov_cnt, offset, n->rss_data.key, size_get); + if (s !=3D size_get) { + err_msg =3D "Can get key buffer"; + err_value =3D (uint32_t)s; + goto error; + } + n->rss_data.enabled =3D 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 =3D VIRTIO_DEVICE(n); - struct virtio_net_ctrl_mq mq; - size_t s; uint16_t queues; =20 - s =3D iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); - if (s !=3D sizeof(mq)) { - return VIRTIO_NET_ERR; - } + virtio_net_disable_rss(n); + if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { + queues =3D virtio_net_handle_rss(n, iov, iov_cnt); + } else if (cmd =3D=3D 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 =3D iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); + if (s !=3D sizeof(mq)) { + return VIRTIO_NET_ERR; + } + queues =3D virtio_lduw_p(vdev, &mq.virtqueue_pairs); =20 - if (cmd !=3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + } else { return VIRTIO_NET_ERR; } =20 - queues =3D 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); } =20 @@ -3274,6 +3421,8 @@ static Property virtio_net_properties[] =3D { 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, fal= se), + 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)) =20 +#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; }; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494827; cv=none; d=zohomail.com; s=zohoarc; b=fUNPynN8avnaRQaxi+FhlhxvWl/AlQhO3KrFIJvyKM1uVv2lbJEXjMk6ntLW7eWSeJX1RZmkIOHB8QGLADloP0JhJyQTyI1eO7thOiWt/GK9FFz8TFMuYKzByB6PAI73k8XukZZK40nZkN9kG+ziC/YRosUA+H/nI7DdYB18oSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494827; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=WOUtMRnFxKV7Y8XZ7UkZhOgeNFYtSpzSIraASB9IW38=; b=iEk5edc6MP6MvBnbsqtuzyjmI7QEjIIBp991YICE1zCr+hKRd36Gqtj0sq4w/+RgazXS1n12AbC4GyNNk/QzgpwiJYsZgMTNsbi2SNI8rN5IWJCg4ikISoF8U2Rg43Q9Lxc6R1ek9VPgtsdutelVnhTfO5+76BEFWPy1I9x+bkw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494827971283.0283213906797; Sun, 29 Mar 2020 08:13:47 -0700 (PDT) Received: from localhost ([::1]:38538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZdC-0004To-Nh for importer@patchew.org; Sun, 29 Mar 2020 11:13:46 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Michael S. Tsirkin --- 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" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -1598,8 +1599,80 @@ static int receive_filter(VirtIONet *n, const uint8_= t *buf, int size) return 0; } =20 +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 =3D 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 =3D VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYP= E_UDPv6; + if (isudp && (types & mask)) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ? + NetPktRssIpV6UdpEx : NetPktRssIpV6Udp; + } + mask =3D 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 =3D qemu_get_nic_opaque(nc); + unsigned int index =3D nc->queue_index, new_index; + struct NetRxPkt *pkt =3D 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 =3D isudp =3D false; + } + if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) { + istcp =3D isudp =3D false; + } + net_hash_type =3D 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 =3D net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); + new_index =3D hash & (n->rss_data.indirections_len - 1); + new_index =3D n->rss_data.indirections_table[new_index]; + if (index =3D=3D new_index) { + return -1; + } + return new_index; +} + static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *b= uf, - size_t size) + size_t size, bool no_rss) { VirtIONet *n =3D qemu_get_nic_opaque(nc); VirtIONetQueue *q =3D virtio_net_get_subqueue(nc); @@ -1613,6 +1686,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState= *nc, const uint8_t *buf, return -1; } =20 + if (!no_rss && n->rss_data.enabled) { + int index =3D virtio_net_process_rss(nc, buf, size); + if (index >=3D 0) { + NetClientState *nc2 =3D 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_l= en)) { return 0; @@ -1707,7 +1788,7 @@ static ssize_t virtio_net_do_receive(NetClientState *= nc, const uint8_t *buf, { RCU_READ_LOCK_GUARD(); =20 - return virtio_net_receive_rcu(nc, buf, size); + return virtio_net_receive_rcu(nc, buf, size, false); } =20 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, @@ -3283,6 +3364,8 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) =20 QTAILQ_INIT(&n->rsc_chains); n->qdev =3D dev; + + net_rx_pkt_init(&n->rx_pkt, false); } =20 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); } =20 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; }; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494820; cv=none; d=zohomail.com; s=zohoarc; b=DyRL+ykUTbju5D8uoFStru7bJz97zYwWO5WAO5BAnBYPQ3KKlAbRc37AKtGZAgVTDbxWXomFnFaiLobIQUpZq5m6MIxQ81ww2Huu7KWH9OoS+eYCrn4+5X3iMY2u0mgbaMWbFMvjLFGxoSZmKunkRMxMPauTWx5l7MOAaFz+teI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494820; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6H29QJg5B7bgS/AMKBONCsgkT/bfdiwpiQn7qsNuQ08=; b=JrEioYRHyO255tYIrFC7jjTjOeXEMVz8i1BIDcnzG/dK/GSWqRI0YRgUgxY2zrWfeJeVu4sYX3TEMhr72E8ZzJSdMSJ1JhPRkkM/1bRsR4XztORPTFIAIXiaW55WrbjRht0R1GCUwCWkZ6OdtMjt/bjGs0+N1kfWwkg9RQwQ2lY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494820987920.8335996414344; Sun, 29 Mar 2020 08:13:40 -0700 (PDT) Received: from localhost ([::1]:38536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZd5-0004GY-KA for importer@patchew.org; Sun, 29 Mar 2020 11:13:39 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- 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; =20 +/* 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); =20 @@ -254,7 +262,8 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, in= t len) =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); assert(len =3D=3D sizeof(struct virtio_net_hdr_mrg_rxbuf) || - len =3D=3D sizeof(struct virtio_net_hdr)); + len =3D=3D sizeof(struct virtio_net_hdr) || + len =3D=3D sizeof(struct virtio_net_hdr_v1_hash)); =20 tap_fd_set_vnet_hdr_len(s->fd, len); s->host_vnet_hdr_len =3D len; --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494984; cv=none; d=zohomail.com; s=zohoarc; b=nZNVdzeUorWD028BZ1Mc717VJHAhs1Yc6siG6CNCHS5rU4CLtW2vsqe5eiOHE1RK4VDydB/chCY+e2BYFJflhvgGOAEq69pVIs+PM3WUE+9Z++oP365iNRGmfimsML+0x/IQqWwgGnmlSq1EuZeQEQafPhKVzLW9cQx9IjGYofY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494984; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=0AgrHwe7+u0B2MfHFgcrrKyy4F0DXEK/+Q2DWgHDYg0=; b=O5sp8+nkm47YjWf5XuW+KNJuOwKFjybJ8zPNX+MNNukt2XVv4NuWlb1HJ3s/bfSiOGm/fd77t9CjEveVBWv/Zy/kJDUj/llsoqCoVkBDBgSCMh3x29VeTD3OOTGn3KgHVSThosOBayf8h2wk1rgqSbA7RGY3geD0vf02j88j6Sw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494984063614.7363636491895; Sun, 29 Mar 2020 08:16:24 -0700 (PDT) Received: from localhost ([::1]:38586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZfi-00081R-Ie for importer@patchew.org; Sun, 29 Mar 2020 11:16:22 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Michael S. Tsirkin --- 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[] =3D { .end =3D endof(struct virtio_net_config, mtu)}, {.flags =3D 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, .end =3D endof(struct virtio_net_config, duplex)}, - {.flags =3D 1ULL << VIRTIO_NET_F_RSS, + {.flags =3D (1ULL << VIRTIO_NET_F_RSS) | (1ULL << VIRTIO_NET_F_HASH_RE= PORT), .end =3D endof(struct virtio_net_config_with_rss, supported_hash_type= s)}, {} }; @@ -218,7 +218,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, u= int8_t *config) netcfg.cfg.duplex =3D n->net_conf.duplex; netcfg.rss_max_key_size =3D 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) } =20 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, i= nt mergeable_rx_bufs, n->mergeable_rx_bufs =3D mergeable_rx_bufs; =20 if (version_1) { - n->guest_hdr_len =3D sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->guest_hdr_len =3D hash_report ? + sizeof(struct virtio_net_hdr_v1_hash) : + sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->rss_data.populate_hash =3D !!hash_report; } else { n->guest_hdr_len =3D n->mergeable_rx_bufs ? sizeof(struct virtio_net_hdr_mrg_rxbuf) : @@ -773,6 +777,8 @@ static uint64_t virtio_net_get_features(VirtIODevice *v= dev, 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); } =20 if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { @@ -785,6 +791,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *v= dev, uint64_t features, } =20 virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); features =3D vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features =3D features; =20 @@ -951,12 +958,15 @@ static void virtio_net_set_features(VirtIODevice *vde= v, 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= )); =20 n->rsc4_enabled =3D virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT)= && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO4); n->rsc6_enabled =3D virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT)= && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO6); + n->rss_data.redirect =3D virtio_has_feature(features, VIRTIO_NET_F_RSS= ); =20 if (n->has_vnet_hdr) { n->curr_guest_offloads =3D @@ -1230,7 +1240,9 @@ static void virtio_net_disable_rss(VirtIONet *n) } =20 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 =3D 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 =3D ""; uint32_t err_value =3D 0; =20 - if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + if (do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { err_msg =3D "RSS is not negotiated"; goto error; } + if (!do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT= )) { + err_msg =3D "Hash report is not negotiated"; + goto error; + } size_get =3D offsetof(struct virtio_net_rss_config, indirection_table); s =3D iov_to_buf(iov, iov_cnt, offset, &cfg, size_get); if (s !=3D size_get) { @@ -1258,6 +1274,9 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, n->rss_data.indirections_len =3D virtio_lduw_p(vdev, &cfg.indirection_table_mask); n->rss_data.indirections_len++; + if (!do_rss) { + n->rss_data.indirections_len =3D 1; + } if (!is_power_of_2(n->rss_data.indirections_len)) { err_msg =3D "Invalid size of indirection table"; err_value =3D n->rss_data.indirections_len; @@ -1268,8 +1287,8 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value =3D n->rss_data.indirections_len; goto error; } - n->rss_data.default_queue =3D - virtio_lduw_p(vdev, &cfg.unclassified_queue); + n->rss_data.default_queue =3D do_rss ? + virtio_lduw_p(vdev, &cfg.unclassified_queue) : 0; if (n->rss_data.default_queue >=3D n->max_queues) { err_msg =3D "Invalid default queue"; err_value =3D n->rss_data.default_queue; @@ -1303,7 +1322,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value =3D (uint32_t)s; goto error; } - queues =3D virtio_lduw_p(vdev, &temp.us); + queues =3D do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_queues; if (queues =3D=3D 0 || queues > n->max_queues) { err_msg =3D "Invalid number of queues"; err_value =3D queues; @@ -1349,8 +1368,12 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_= t cmd, uint16_t queues; =20 virtio_net_disable_rss(n); + if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_HASH_CONFIG) { + queues =3D virtio_net_handle_rss(n, iov, iov_cnt, false); + return queues ? VIRTIO_NET_OK : VIRTIO_NET_ERR; + } if (cmd =3D=3D VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { - queues =3D virtio_net_handle_rss(n, iov, iov_cnt); + queues =3D virtio_net_handle_rss(n, iov, iov_cnt, true); } else if (cmd =3D=3D 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; } =20 +static void virtio_set_packet_hash(const uint8_t *buf, uint8_t report, + uint32_t hash) +{ + struct virtio_net_hdr_v1_hash *hdr =3D (void *)buf; + hdr->hash_value =3D hash; + hdr->hash_report =3D report; +} + static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, size_t size) { VirtIONet *n =3D qemu_get_nic_opaque(nc); - unsigned int index =3D nc->queue_index, new_index; + unsigned int index =3D nc->queue_index, new_index =3D index; struct NetRxPkt *pkt =3D n->rx_pkt; uint8_t net_hash_type; uint32_t hash; bool isip4, isip6, isudp, istcp; + static const uint8_t reports[NetPktRssIpV6UdpEx + 1] =3D { + 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 + }; =20 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 *n= c, const uint8_t *buf, net_hash_type =3D 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; } =20 hash =3D net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); - new_index =3D hash & (n->rss_data.indirections_len - 1); - new_index =3D n->rss_data.indirections_table[new_index]; - if (index =3D=3D 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 =3D hash & (n->rss_data.indirections_len - 1); + new_index =3D n->rss_data.indirections_table[new_index]; + } + + return (index =3D=3D new_index) ? -1 : new_index; } =20 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *b= uf, @@ -1744,6 +1794,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState= *nc, const uint8_t *buf, } =20 receive_header(n, sg, elem->in_num, buf, size); + if (n->rss_data.populate_hash) { + offset =3D sizeof(mhdr); + iov_from_buf(sg, elem->in_num, offset, + buf + offset, n->host_hdr_len - sizeof(mhdr)); + } offset =3D n->host_hdr_len; total +=3D n->guest_hdr_len; guest_offset =3D 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_R= EPORT)); =20 /* 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 *de= v, Error **errp) =20 n->vqs[0].tx_waiting =3D 0; n->tx_burst =3D 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 =3D 1; /* for compatibility */ =20 n->mac_table.macs =3D g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); @@ -3507,6 +3564,8 @@ static Property virtio_net_properties[] =3D { DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, fal= se), 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 { =20 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; --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494899; cv=none; d=zohomail.com; s=zohoarc; b=Zou/NhoDB5SSHA7waK2CUNpCk6ze02Y2uHJ3afkZuzWlt/Tv+xb50W+iZuhRes7Gh1Imxq2hQX/1AF5On+pn/EQG/res1uzw3/wHQYQQlqFSpUkh5HjjUoLKw6DvAANTsCaxLdAgVTW+8qHM04x5OIIuIt/dFzUIK5rO8k2nYwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494899; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bKbcDZF4VvCdwc1Z3LgA0n0/o1l3SD8mbWQhoT1XpcI=; b=mjyzXSx82drHlGMtZywyqoDvceJDpTcBaY0dqkNlwC+kMNh3j3KG5K4uzcl3jHtSJV7CitJaSPPATT5Ty9KZlexiKWj2PZ1OiOdmo0IH40ZARZ7Hu2u1LSOnA5KCuBlHr37mMYZhJV2jYHyM78B/52ylOlXC2bZNreG3AiQ+wgw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494899550190.20028009470082; Sun, 29 Mar 2020 08:14:59 -0700 (PDT) Received: from localhost ([::1]:38554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZeM-0006Wq-7T for importer@patchew.org; Sun, 29 Mar 2020 11:14:58 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Similar to VMSTATE_VARRAY_UINT32_ALLOC, but the size is 16-bit field. Signed-off-by: Michael S. Tsirkin Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- 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 =3D vmstate_offset_pointer(_state, _field, _type), \ } =20 +#define VMSTATE_VARRAY_UINT16_ALLOC(_field, _state, _field_num, _version, = _info, _type) {\ + .name =3D (stringify(_field)), \ + .version_id =3D (_version), \ + .num_offset =3D vmstate_offset_value(_state, _field_num, uint16_t),\ + .info =3D &(_info), \ + .size =3D sizeof(_type), \ + .flags =3D VMS_VARRAY_UINT16 | VMS_POINTER | VMS_ALLOC, \ + .offset =3D vmstate_offset_pointer(_state, _field, _type), \ +} + #define VMSTATE_VARRAY_UINT16_UNSAFE(_field, _state, _field_num, _version,= _info, _type) {\ .name =3D (stringify(_field)), \ .version_id =3D (_version), \ --=20 2.17.1 From nobody Sat May 4 00:34:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1585494819; cv=none; d=zohomail.com; s=zohoarc; b=EpBh8uyg57IZUfJhhCOyMDnzWfg/IV7/S0kehSJfcV7QLRYCJQep2u1aA9NJxLwIEIF66YbN6uN+NnzDTbqTg7qtDoR9IwS7PJ8VM1pqi4blckuey0bZnTvxnEHZYSEuj8f+WreJsYZwU4a+VoZ3R3nKfMYMiVmY70o36KoKuvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585494819; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=EH6oNg+1XnVlYF4aQzYUAyrXIjqeHFa39k5bqe6Q+YA=; b=U+EC11pRHShj1BSeEqP7xrvZcVxowTpzC+5EKf70U56APDBodJLFYpFYbf7kGYKcwArbm5g0Kec+fmvECB5FRLKe6TLL+7ECvs1UjdfTimDuLSEZW6B7sNaHpMCnArhcZvpjduMVNJBXPSDxyJlzM76R+kKGce7mm7Z/IY18/MA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585494819977266.68926950254684; Sun, 29 Mar 2020 08:13:39 -0700 (PDT) Received: from localhost ([::1]:38534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIZd4-0004Ff-GA for importer@patchew.org; Sun, 29 Mar 2020 11:13:38 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Save and restore RSS/hash report configuration. Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- 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) } } =20 + 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; } =20 @@ -3019,6 +3026,32 @@ static const VMStateDescription vmstate_virtio_net_h= as_vnet =3D { }, }; =20 +static bool virtio_net_rss_needed(void *opaque) +{ + return VIRTIO_NET(opaque)->rss_data.enabled; +} + +static const VMStateDescription vmstate_virtio_net_rss =3D { + .name =3D "virtio-net-device/rss", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D virtio_net_rss_needed, + .fields =3D (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 =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, @@ -3069,6 +3102,10 @@ static const VMStateDescription vmstate_virtio_net_d= evice =3D { has_ctrl_guest_offloads), VMSTATE_END_OF_LIST() }, + .subsections =3D (const VMStateDescription * []) { + &vmstate_virtio_net_rss, + NULL + } }; =20 static NetClientInfo net_virtio_info =3D { --=20 2.17.1