From patchwork Wed Mar 18 09:15:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444779 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 3A5726CA for ; Wed, 18 Mar 2020 09:16:32 +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 0F4502076D for ; Wed, 18 Mar 2020 09:16:31 +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="Dw59BCmz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F4502076D 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]:47410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUoQ-000412-PQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:16:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39561) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUni-0003Ca-1N for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnf-0004Jx-Tx for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:45 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51610) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUnf-0004FH-N4 for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:43 -0400 Received: by mail-wm1-x341.google.com with SMTP id c187so1030586wme.1 for ; Wed, 18 Mar 2020 02:15:43 -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=Dw59BCmzSPI+59GOxbUFxTZHpic7buzKM5DcEoKdtNT5S+QlAbmSY9vku+G+fyX3Sq nDkr40B+L/6CeTd7AzfxEyqwQ/HOT1RQ0oq7vxz1d6cDfhfs2El3Lw1WugVg8wEyjWQM OQHa2pvEOQ/Re3ao44yqxGxa+XYEtSIREY2lV0TSh6/Fd9ZlRXZWsQRUQ7CiC93VHRj+ ZmF+OiLUf1Vj9rduI8lR0jnY8qzC01dko4drE6e7KFXzvq6chbfv4begm0wmmMLGqhKw PcYcpHAIMy+zYqkaKWrFVAIMQhKnVqWKglXFy4ycyMoTrT6L0j/wBu5L0eI2R4nIuaod CNYQ== 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=AHRVvcmF895rOdMt6brI4zuNyAxkUJLohV/UKxI2n/OHOLXGv1N8sYxOrhQ1ANICJg eUFI5MI9w3ryT6Ebae1IoKrDeJwMkqWsyBoTiC6DroB3FScBdcyAcZ5xsecHffwfzwjV PCNf8wvYi7qB4ROdAM2fVWgEKJuoFnMQYFD3DiLpsl06rz9R9P2p+Mnj8QBVWSflQWA7 lm2LFQ3fS2uK0cgTOWXwnFFwrSQfNH5+4Q2oXPbRnreXD7oElp/mqGHKjcOhwdu8CXJr 6bIH/qWNJI52HkgH6712EZ0V4tzXAds6gmJDqvKgRK/xxZcwmCjHP+WkXt8PsOi7aQ9P DzdQ== X-Gm-Message-State: ANhLgQ3LqUg8faaM7Ca3NfVbjMlhySbwA+oDf5kglW+YO3QC+QMbTRNI EBVEGutWHnpYGUQMRWaPxhUllQz+nqLIgw== X-Google-Smtp-Source: ADFU+vtf2ahG1VuiUWmzvCj40ATa/7SJBSCn5V7/hv+RjBtTF1JTweG52YU6jyAqGeuXUs5k1mdkRw== X-Received: by 2002:a1c:8097:: with SMTP id b145mr4339935wmd.159.1584522941959; Wed, 18 Mar 2020 02:15:41 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:41 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 1/7] virtio-net: introduce RSS and hash report features Date: Wed, 18 Mar 2020 11:15:19 +0200 Message-Id: <20200318091525.27044-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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::341 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 Wed Mar 18 09:15:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444781 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 C240C1820 for ; Wed, 18 Mar 2020 09:16:32 +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 86CB02076D for ; Wed, 18 Mar 2020 09:16:32 +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="MxQxBjEk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86CB02076D 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]:47412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUoR-00042K-N7 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:16:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39586) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUnj-0003Co-SZ for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUni-0004Rk-3i for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:47 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44053) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUnh-0004Pl-Qd for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:46 -0400 Received: by mail-wr1-x444.google.com with SMTP id y2so13797209wrn.11 for ; Wed, 18 Mar 2020 02:15:45 -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=MxQxBjEkK/HEJbZKagg/z2k+KNhH8dkUyxrNsdy/RmSMYHyeQ1pP5OAavMs7ghPHrb LQ43MKst5cpKP64J5GOHDblw7EbluUV+EjW5yCnNIKfe6pLmOennEZLnoB0gVwll3Re0 Y/KlSCjjajYQ95ZhBB2EfE8RvPEC+lGaoGfzNVPv4xvIw3wRCMau16lfv82S8LT4wZGk SHIqGQ1bN4uTSTaM+keyeackE/e3B3rv5cNpQ5apBScGvC42xzvmkolkYFxUrTH2vviB WZ+XQjOMrlePb+bMC6gIE74L/YSbuOha2lG/lozaImkdua2798oUYbUop3G3suh6JUE7 V0Vg== 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=an8zfy2ROqjB5tzCNCDzJelDBdNi9Le4XzfeMzBI2nO5agpYSXHoSHQo4wWtp9LSS3 27uTt/pa0b8pu+V0xWMBjXbq9XNjrZfwYbU+Ps7zgq3d1BZdHz8LYuIdC1Prb0FR7tVF FpcMEi/8uDY0KrF4e7uxfAZ58WsTwV7GhM8F6O59FyzKeOwjGifWSIKBdQCp9eLoRoNL ziPW+C0jj11x9lUr50sL9oqyRKNaZc/EbMg6YxOKAgpKYvl4nTZ7VhnebegTMNUKEYWl awLUAJcPzHxW7t+SyaKyDHI3awEz7FuPb4IsmcqkNGJPbqtCUPx2XVj4FGZocAABb5ul UReQ== X-Gm-Message-State: ANhLgQ1qMp26jwRG629+QOCE+Hkz9Da7jGv3F5P5J4sGaMWF7nJFNlyK Ezet3X+jH6LF9UYTVOzrU784ZjKuv9/CjQ== X-Google-Smtp-Source: ADFU+vtX6CmScsa3uFg5a0u6wRx5Fh7gTR8qWAUo6HMdsmWRZWMdrUGxUYOkhg2zx1PwUEUo34/Uew== X-Received: by 2002:adf:9b96:: with SMTP id d22mr4752174wrc.249.1584522943679; Wed, 18 Mar 2020 02:15:43 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:43 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 2/7] virtio-net: implement RSS configuration command Date: Wed, 18 Mar 2020 11:15:20 +0200 Message-Id: <20200318091525.27044-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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" 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 Wed Mar 18 09:15:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444791 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 4493517E6 for ; Wed, 18 Mar 2020 09:19:28 +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 19D2E2076D for ; Wed, 18 Mar 2020 09:19:28 +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="jFLsF/m8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19D2E2076D 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]:47436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUrH-0007TP-6B for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:19:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39610) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUnl-0003Cq-KK for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnj-0004Vl-Bq for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:49 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34547) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUni-0004QF-DF for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:46 -0400 Received: by mail-wm1-x343.google.com with SMTP id x3so1799413wmj.1 for ; Wed, 18 Mar 2020 02:15:46 -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=jFLsF/m8MohivTPb5X9fsYo/cxeE6jmvuUaCSw8JcC17C9s0uhpbhE6YYHXjNLwPSE 0sHNk03AR/yGvX2pGgAjf6qMCXaQd3CYBAKJ6wwvqsFrYCWrIvQkBdb4nlFZY6468jga t77fFoXU79KXI3rN3LHOzMozUUfW9L1RMR00YQC0/rdtdyebvxbvn62DY3bwBbQTxbS2 c9qDJcU2mKbFaOCgC6M1k+XBCy9ROv4Jpatg0WTYQgQGmmj9mbRXSvX0bpiQ5az/Bp8E F9sdCYX6i/WuKcTR+jL9kpxZC9sL7EnJFI1Ao1ClBXHLc4qUhUDcK8RLGRD4jn5fElMf LgeA== 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=oyM9nEhYh2qWuf9eRKmI7Hbe7XRrVL/qSBZLfYieleuis7yFrE3koVOQn7/s8WyRKp EfkXXpKohSgQEQDjNgz+HCNkRdFBKZXqE6+7mYdlUM8iqVVKnsJvHDLnVCxUKy9DNkns fwkbM6VvBn1s+JtJYbLBrzpMqSnP1VBjipBXf8u+2ADxjrGqwKd0DgIIS0KzAOPV3MCC jtH0ZDxGLt3Wp8j18GKQJhLOjqivRCU+pA1L7j5GMViyagIZRa680UZB4i+jK4HdLpk2 5u2RPBmS9HaWqADWVeLuwnTPRVFIrkyflyOenhY3cWN8KmRGkuwOiPUU4G8iSzZ/gMZb 5GcA== X-Gm-Message-State: ANhLgQ3Jt5C1Y2nq4NmSz9tbKf5koMlVSdR8QGD2O6jKQ+wkHCXed0kP 8YeGhdtySl1TIpeJ7mi21HHbNV+7fAdlKQ== X-Google-Smtp-Source: ADFU+vs/Y8CEc9rCyr/OGhcgouUi4Bgq9Q+bnONR69TFOLsMuL5IkKooulaHfJJgUFSKJITMtA5QnA== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr4363593wmc.82.1584522944916; Wed, 18 Mar 2020 02:15:44 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:44 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 3/7] virtio-net: implement RX RSS processing Date: Wed, 18 Mar 2020 11:15:21 +0200 Message-Id: <20200318091525.27044-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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 Wed Mar 18 09:15:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444785 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 E35E217E6 for ; Wed, 18 Mar 2020 09:17:50 +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 B77682076F for ; Wed, 18 Mar 2020 09:17:50 +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="H5BXjcLv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B77682076F 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]:47422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUph-0005iG-Sv for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:17:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39611) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUnl-0003Cr-Km for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnj-0004ZW-Ue for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:49 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUnj-0004Vf-NC for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:47 -0400 Received: by mail-wr1-x442.google.com with SMTP id w16so12878435wrv.13 for ; Wed, 18 Mar 2020 02:15:47 -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=H5BXjcLvnHEd8F94FZZPv9SVa9ngDmG5O3TxqCfbNOmXNpfM/30W95f0hyPjLxlFdz xYCaT45MUJc/cWZdkxEdgG3C9dHWJRsdIBuOF1y78R7ZnrOGMtO8cqb3T1SpceqK2DPu jY1p0o2QJi3iBD5GpP0KsxGV7TVTa2YlVbkemy3cMVjBeMRLs8l1cvfEjSNJWI2+IyGs pCoorzBKxuAlUTxUwxTk8swAfvgj6UmaxayS1zduCdD0j62j2MZx9b1pP53yKLrVpfyg uJAo11Zhst2HpfXeiktT4HhXn7CXPwu9XckvdSwp5IKLocTw3myMeBDczbAhaUdNFF3+ gUaw== 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=momyeEe2k567PW1Mnir6L1c6HgliBDDnKeWFxzN/PeIVJufrvBxOi3uH0eMuB/ibqP U32TAfrXLyHFFhhaLiJtwXU46PKX2QOyKpXVgr3t2QvnyaxY1GOTn41RTUrNdEFNajZG l7G2CqexJ9XYSK7V0N60fU7phT27lt9kWqOiZ3HC3UxSX9IScE1fZKI7xYnmCsoDIDmj 1ePFh8i75EUhpWaIgUmh37S0J9mvmKuVfI2Spydi2MwxllZPRiElU73nnufEuYHzp0b4 I6+ZFwEvi/jkzVktXcwYIzHOyMGahzSXu66H7bjErTgI0eXcEtvskQe5ZW8mxUFDcdbb tKIQ== X-Gm-Message-State: ANhLgQ0FxGlI5B3dNKm9KCI+8oCqllsZQW7rnZRij7/HF7TEPiU00QuL twDYlPRvnpU7h/XIId02M9NV+7qmc2xClw== X-Google-Smtp-Source: ADFU+vuaXt6VoNU6fpSxWwzynf8kWmbWVihE5qxnQdQjzdIKsXKsDgQujMh7M8cj/EzVRqZAAJLkKg== X-Received: by 2002:adf:e5d2:: with SMTP id a18mr4583929wrn.334.1584522946494; Wed, 18 Mar 2020 02:15:46 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:45 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 4/7] tap: allow extended virtio header with hash info Date: Wed, 18 Mar 2020 11:15:22 +0200 Message-Id: <20200318091525.27044-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Wed Mar 18 09:15:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444793 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 8251D17E6 for ; Wed, 18 Mar 2020 09:20:42 +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 4714E2076D for ; Wed, 18 Mar 2020 09:20:42 +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="yzoaakXw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4714E2076D 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]:47458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUsT-0000oE-8d for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:20:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39659) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUno-0003Do-Gu for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnl-0004eX-RT for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:45068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUnl-0004bI-Jn for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:49 -0400 Received: by mail-wr1-x443.google.com with SMTP id i9so1426461wrx.12 for ; Wed, 18 Mar 2020 02:15:49 -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=yOupkg2tDjhA9k/ASRMhbHI4PkMh+TlmWpBkkRpxw3U=; b=yzoaakXwJIVeVKeJyp52SullH1hFFPmjVdNJZiWo97XRtoQnOt33TRN0GxShqHzYFX ecAN0XZgyIhbkds+BysTixPC2aNKq/DYPbi5K2BGlojrfocGIs9M4oTBzujpXWw+Lp0h WM8q8w+5TOH/12R3IYrpcjevj4cPiRjfqk8JNNKicM725MMZ94kdD2fEFWCzHYJd9dvS D3Kik/IhrJ5Itw4+LktOrY6E3CtW1tCYcNutKwAAw4CJWtf054BXYujUd4T2GxUfwq3h EqU3PUyGfxKdcMlNxgahw4W7sLs0ZYCuLz5g6/OMDzWs6gQHY3M50urhXBxmcht5uOiw PSNQ== 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=yOupkg2tDjhA9k/ASRMhbHI4PkMh+TlmWpBkkRpxw3U=; b=VUZDbrEDVtZavvmmoGkQdftnB+mxF4y4BnizrWrAOsDqsYJzwRg0DfeluKa3SnKbbN VUarWYhk6678Hf5z7DcGTq/SGa2ezDR8L4fAw7xuUtzdLX6mLmQ2lcnRW/6TxWoT0xNU D+4FNjq/gKvJWVihSiKUnMUss+uuh6CIbGJKjMmyFBUzRoolbaAQrgTN+F+Kq8tliLDK nthMnhsEQ2lt16pijcDTCb4sSP6B37bDTI/wWDJAef/rsL4hey5Oqdgr/sE8iJWPoBRY PQ2Br53O5Pktveyqj3piq/hwNfNETmqfbnh3ML1Ti1/eeza952vwgttmpHl88y+4pmGw n3Sw== X-Gm-Message-State: ANhLgQ0FKOd3QnaObpq/b961lVzXoBsGcaQpVSqpvWjo6AFp4n8FoF4W PcGkiIU2u9qciH8MvPYETqbqXXB5AEDleQ== X-Google-Smtp-Source: ADFU+vssJUhvsGzPdEI2AUCzHFe7bZy55UQWjRYthpb5pdK3N7H2EPUuJzjCZqdliuDr4UL55jHtHw== X-Received: by 2002:adf:b641:: with SMTP id i1mr4548852wre.18.1584522947741; Wed, 18 Mar 2020 02:15:47 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:47 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 5/7] virtio-net: reference implementation of hash report Date: Wed, 18 Mar 2020 11:15:23 +0200 Message-Id: <20200318091525.27044-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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" 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..a0614ad4e6 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 = true; } 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 Wed Mar 18 09:15:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444789 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 4329717E6 for ; Wed, 18 Mar 2020 09:19:25 +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 175AD2076D for ; Wed, 18 Mar 2020 09:19:24 +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="iVi20NzL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 175AD2076D 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]:47434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUrE-0007Ow-6L for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:19:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39660) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUno-0003Dp-H3 for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnm-0004j6-Fq for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUnm-0004db-9p for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:50 -0400 Received: by mail-wr1-x443.google.com with SMTP id w10so459067wrm.4 for ; Wed, 18 Mar 2020 02:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iSTHopC4uU4kCN0tyvTPrIHil1hTQrwxVdvmrqy4gWI=; b=iVi20NzLZuFLq14Y4QKwctB5HM/MiBsnCU+HI+sDEqncEk2nN6/In3kXqGHXC+4Xa7 ad89QvTDKdpAh7CJbDkGfmbCzxEMI+LlqfXWBq0sjAY3J2rrkv82w9dcKnyzKhjyGjMu ciUGBF6J2o2aOxUpz8017tYcBfdrAToJIWdDg8HF7/gSZPrEmFnoPRctEQPEoTY7qg/2 Ml1SItowVAtyxyz2fkzFISl1wEs6sV1KyR12tHXNhRxb0o6W3NORvJIJryu+rNxqV6AN 57s1OxSiqMQC114fu7OxOhyvkYFnO7ZJltUewYGjNeeUd1Ldvlkv5gy+haUFTi9pt2HC Boew== 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=iSTHopC4uU4kCN0tyvTPrIHil1hTQrwxVdvmrqy4gWI=; b=HJPzUsYS06qku408t+4WF6/Hv3G0Hkt0qSKjICDWS3myf7kdG+qNqRE7liTlzni5TD VSfX7PQyMq819yPCDXksTz/bKbH1bq6V+RgzqD47qBeEB9jQffU5lPygBqAA1O3aqZvB dmcPNeripUQGh3xUYZcMrbXO+NUYFla8ridAk2bv7ppBDirrqTwUiSkua2kcDo9DY0Og tdyYrnKgfKI5MbK5elw3OZea7fxH86iWcwSOAMn2JtaQs80U7Y6BbNGwQL2x+52PSkAO Fue5VsIZ1DUoG8elKgh4SHlUOqpMzzp8skNAdNEZGbZE/lxstgsa5Z/QiQgMowqbFnZx fHfA== X-Gm-Message-State: ANhLgQ3AfwqPo/pSm9gUi2XMOF7mOdxWPG5pNHDl2GbTrVECHErhsxFX /RvcaMMyAFVCAkGtzEzJ0WPP0fmAqXt2mA== X-Google-Smtp-Source: ADFU+vtWtAAYpwPWG8NLxGEOhQ0Rb8TFwwrJkAsNnPmkcMelNuqS9jyM06A472DUutmncSNMhfPXBg== X-Received: by 2002:adf:eac7:: with SMTP id o7mr4739785wrn.292.1584522949109; Wed, 18 Mar 2020 02:15:49 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:48 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 6/7] vmstate.h: provide VMSTATE_VARRAY_UINT16_ALLOC macro Date: Wed, 18 Mar 2020 11:15:24 +0200 Message-Id: <20200318091525.27044-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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" Similar to VMSTATE_VARRAY_UINT32_ALLOC, but the size is 16-bit field. Signed-off-by: Yuri Benditovich Signed-off-by: Michael S. Tsirkin Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela --- 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 Wed Mar 18 09:15:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11444795 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 58C5C6CA for ; Wed, 18 Mar 2020 09:20:43 +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 2F5EC2076D for ; Wed, 18 Mar 2020 09:20:43 +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="YjjS6Efj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F5EC2076D 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]:47460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUsU-0000pY-5U for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 Mar 2020 05:20:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39687) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUnp-0003F5-MP for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUno-0004sR-LG for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:53 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40613) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUno-0004ml-EQ for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:52 -0400 Received: by mail-wm1-x341.google.com with SMTP id z12so2335115wmf.5 for ; Wed, 18 Mar 2020 02:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v8SYlyFWHibMbzw5x9/Oky71TcnVdLOahGjn4df4QAU=; b=YjjS6EfjtvisDjroCFTSc9vhLIDSTXCO3bilV6VM/f8t6RAgU5+tg4LCUPe0u3vroj Q4WiCXdNzdEMqwF0pB6pkdAIikKKqqkzHrVEAzDr94CT/oO3/iIVqtrP4X+OKRD/Z0lw VqCyMBo0CKX4rojQUUGVXOQeU2zco5qMBiEiBMtRGnatoiQ8OompkgnufzuXICyTnNvH ri0Xqocmn837S28LWGWfI1UqQxOoXjHwifrfRH/dOWN+g8Kq/6E93gyt8MSAe2g8ASg5 SGCOXDCWGtuVneqq7EQu7PyXVlrsSLnd64hXNUqAAMGNqLytclqHGE6OoiZQzDXaCtx5 4DNg== 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=v8SYlyFWHibMbzw5x9/Oky71TcnVdLOahGjn4df4QAU=; b=uNtHK4kjk1IS39jq4U3f0exTaxkSoiU95rC7Ys0I2u/j0z3K6HbZAwxjvjPPWcb2Hh AK4iL1Bj1gKK9eZZqkhbyXCSZo6OxWKbina00/kpv9XFCZIS01tu7z2sjaWtngL8nFH9 H4CNmHdSQ+M5rvt1LHhWJgwyP7ExhQhSw/RV2WRnjggnSYBH7BBRXOZ/8bSJuDyadIrW RTTzajAqz2DkB1KrhHxT2ZHruHvW5Hkskb2haTSsrLcjN7fZjLCYwHcyH+tVmsXAdJOB IIs7yPI2fT1EBL0jOZ4vTM8MORThyWxH2cQD0Wy38f+rqGdCvdOydUj02Fa8pXp8S0yf VrXw== X-Gm-Message-State: ANhLgQ0ydjT0+5h95IKaQNHgPToxEUZ5yNZ8ZD4pEL2LvUQaYblCYLpO ZV+AOTnVwvkA05JY5XMA7Z+7nJc2r1AQ0A== X-Google-Smtp-Source: ADFU+vvfcYVmUqX5mlgjYgUP1miBwlrf413OxxZJv3oiHJKUYYK4A4DPlrsVQ/XLz2Pnvr5IP020vQ== X-Received: by 2002:a1c:2dc7:: with SMTP id t190mr4254586wmt.137.1584522950384; Wed, 18 Mar 2020 02:15:50 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:49 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 7/7] virtio-net: add migration support for RSS and hash report Date: Wed, 18 Mar 2020 11:15:25 +0200 Message-Id: <20200318091525.27044-8-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-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::341 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a0614ad4e6..0b058aae9f 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,24 @@ static const VMStateDescription vmstate_virtio_net_has_vnet = { }, }; +static const VMStateDescription vmstate_rss = { + .name = "vmstate_rss", + .fields = (VMStateField[]) { + VMSTATE_BOOL(enabled, VirtioNetRssData), + VMSTATE_BOOL(redirect, VirtioNetRssData), + VMSTATE_BOOL(populate_hash, VirtioNetRssData), + VMSTATE_UINT32(hash_types, VirtioNetRssData), + VMSTATE_UINT16(indirections_len, VirtioNetRssData), + VMSTATE_UINT16(default_queue, VirtioNetRssData), + VMSTATE_UINT8_ARRAY(key, VirtioNetRssData, + VIRTIO_NET_RSS_MAX_KEY_SIZE), + VMSTATE_VARRAY_UINT16_ALLOC(indirections_table, VirtioNetRssData, + 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, @@ -3067,6 +3092,7 @@ static const VMStateDescription vmstate_virtio_net_device = { vmstate_virtio_net_tx_waiting), VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, has_ctrl_guest_offloads), + VMSTATE_STRUCT(rss_data, VirtIONet, 1, vmstate_rss, VirtioNetRssData), VMSTATE_END_OF_LIST() }, };