From nobody Mon Apr 29 13:58:23 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=1584705642; cv=none; d=zohomail.com; s=zohoarc; b=hhJkCDhEjEihuDmvBLyWeWb3Ug05gARlHRDnwsshm25uvwjhcrm0qKpKPOsm9vDwzskdOOR2xFiXVQRCtAFhwdQieIddUeq5bfTdZUfIW0+Cf7dU4TYjjMFnZsIMWPv4L/2j9Jg9JrNuLyUE1xL9wcIDRsiZRM4zwW8oyvoGdDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705642; 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=RcUb3mAitFMdcpVqyctgrSPoKT/RKIqqgAaIsy197x6xwEqiiPrkuokW+p8j473dCKoQzRr0Unm0PK7TCdVBdrDSKgKAeUJoguqu3VBi7h5FXZUlnglohquNQCj2Q+gtjR63aNX01ZPjjchF/zsU9cWNfsTOmV9zMDZBfDlSTUU= 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 1584705642442533.7230697812333; Fri, 20 Mar 2020 05:00:42 -0700 (PDT) Received: from localhost ([::1]:51458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGKM-0003kB-5n for importer@patchew.org; Fri, 20 Mar 2020 08:00:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52610) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHq-0007h1-ND for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHp-0000FD-IZ for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:02 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:34238) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHp-0000Es-DO for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:01 -0400 Received: by mail-wr1-x441.google.com with SMTP id z15so7102203wrl.1 for ; Fri, 20 Mar 2020 04:58:01 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.57.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:57:59 -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=UKrJ5LW9zQda7WCcSMyzCeaKakrZkcHk4BrznxfZ489EtB8n0b0d+i/3969dZsmemk j/TSZrauTDX+gjim/Xiwp1nTrT6w3CQOT3oS3LNIRl4rQ/XOmwh6idzBMpsvOq7WYtOR 6zGnWS3FhFepRUpcPzHJYQw2j1Ya8+3mddAb+5OYnmr8o9Mlxxuw0IAT9hopGo0fhahI Dy3miMDhnSzqyoCKlJVF9hWEHXB6ydLv5T8GKUC/S1Au9iNHzGhErpFLAr4xQfu6nOXX LyZLGpvM4jIliTjDFiB/nmOJxVenwSsOXjff0uU+XMmSUHbCqiFWsgP/TZBcwXr847Kz OhpA== 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=PlSdM55cE5syHQpWjHbDmDegpxuVf2LIdw8xVGR60V/151TGr0cB+IdZBIP9Zwin+e pNnfzBX44axL0ZI4jxAf11uzaubLnDptOC7TEGdOlkanoshm9X/X82kauZsI0vHlQC9w /KN691gXNm8m0BzcrkxW1W1lo9ZMtIlUSFYotBxJkj/boEIMzg6ACFRgU08Nk7P6MRTe 4LSaonlWgOsnhDJwFvzltyvlzhCtKJAHkbN3yCVz6SzQL2Dbg627wijw35u+KIkw1OOL BgtP9ClUf4lqdQ4nRcrXpZlH3/DW9SdcHimG75z5teXMGGYwTwZF4LHgrsEjgn/Mq9Wh dCeA== X-Gm-Message-State: ANhLgQ0pI9Y+2+9vVA0IVEGjNSSrhNUFCUyBmb5+lcmwU746NJ6QaVh4 rLzHqscp5sFkKUcobzTLbT35sx8GCD4vmw== X-Google-Smtp-Source: ADFU+vt5bb913x8d1VIh37F6gfPUcpiuDqvcWap0UCMStFUc46J0c01wjmUQQY4ojZLdMzgQvjoF9g== X-Received: by 2002:adf:a490:: with SMTP id g16mr10543639wrb.42.1584705480116; Fri, 20 Mar 2020 04:58:00 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 1/7] virtio-net: introduce RSS and hash report features Date: Fri, 20 Mar 2020 13:57:45 +0200 Message-Id: <20200320115751.19446-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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" 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 Mon Apr 29 13:58:23 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=1584705553; cv=none; d=zohomail.com; s=zohoarc; b=XVP8UGSKZNtUXw5Xp4211RlL06pNn9KIVia+lhtO6MS7zg1LZlYK3HOcOqS2yG9Dj6DTaKeGjX47h/k7gZCwbLuFJe2pupuOuVymUZ5piNmzCcdgSaSSuyAuJnY2rCc8SqSpmFOs15yZ2/dY4gfn4m990/Xn6elLiT4Su8CXPRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705553; 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=YSTPTYPTC97I9DxWMg029tCHTJZFh0xnOGIoOeFFCRoQdDHmZVG5oHWrx16qCyRqfgBAFJS1VtNbBWq93beB125EW8Lj65JKPzTDURO8FLTpQBu+J8tdJz8X8Lq16DLfiTsEV2UKXxCSh6VNpjx52EXRwpYBEaKojKpTcmZCi3Q= 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 1584705553649479.73123521054345; Fri, 20 Mar 2020 04:59:13 -0700 (PDT) Received: from localhost ([::1]:51387 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGIy-00011n-56 for importer@patchew.org; Fri, 20 Mar 2020 07:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52626) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHt-0007ih-7f for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHr-0000Gl-30 for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:05 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHq-0000FW-SN for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:03 -0400 Received: by mail-wr1-x442.google.com with SMTP id h6so7075495wrs.6 for ; Fri, 20 Mar 2020 04:58:02 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58:00 -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=hWH13zRVqxuQFNBXgLPyA3E8EXZGEQKPCiy0ea/H9Aagb4wtmOYAODGUvyOQPhUn6a H78RZS8WImt3wi0/n6PqeGUOHBNOfLdwBI4QaPf+msqvlXiGjrlNcZHhPvfcNaYHKnOu HNgUY5nb6aIo/9AG872pEqNU+XJd/0sGLUnXWR9dHzni/FsW2+BJXs/LHlYbWMyXRzxY 0QTVsMFdQAyTZ7VooNMVhtdBotK3akK4OZ5Ad/AnWBfc3QElV4l4tE9esQwObkLltjuj NOen/zI0P9io8PjQgZLodvlRfTcatlY8TMMiNcg8IcnZunxzs3HEJXHFPxL2SO4WO1c8 YTWA== 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=meBEIHgogD/0m8VzmMu/mfhvtoX1oOzpoDhyn/8wkAtHe2mY4lTxalr7R/xl62uJjE 0mSCLv4+CsnsaAMACsQ4D6Dumh7Ug/WPa9pZKxuJaXJk2lUduj0jXGa+gN375xa4tWPJ +5GxHyvynpFOmoh/Zqkjx6IkChJwxTHX+IMdwfeUb/cOzyztZLQ0T5yAH14VRUC+V5od PUUrxClBp1U7o+47jsb+Bf8M7+nrMflLE1LCCww4K5ez8xi40p9KOaDw1W9zL7InU0EU Ca5HE5G7toGkgyk/WYVmGlgqs3UvGs4QlPqDc9nTHYIcIv3jih/CYHYrg1MnZ47OCdeg Dc5A== X-Gm-Message-State: ANhLgQ2qSEAtTtI79y0begPt+7wwrhXdD0uhg85pOmuzpQH2qmfOLA4O aqTdiapHWjZOOwPQArINvWNN9VcdjyFbIw== X-Google-Smtp-Source: ADFU+vtV1VMmxUyNwk+onftFQUlqjBUMXyOroY8/s08iRzZ36ie/RnqS2QzrFv5QPZBPKyeFz9d8AA== X-Received: by 2002:a5d:474c:: with SMTP id o12mr10810508wrs.156.1584705481437; Fri, 20 Mar 2020 04:58:01 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 2/7] virtio-net: implement RSS configuration command Date: Fri, 20 Mar 2020 13:57:46 +0200 Message-Id: <20200320115751.19446-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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+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 Mon Apr 29 13:58:23 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=1584705831; cv=none; d=zohomail.com; s=zohoarc; b=B3blzZ+iqD9TIrTXw6rZNVDiugBeFVI7ic1YGpclJTuIJs6KKqxrIuUys5Ff8kpz9k8f+XMOGpnZRkSRxSSgzSO5TyQCF/9OqrP3rMWZN88mnX6vUCNIyZC3n7WxlFCr0E4pYOMQbuPPx40x4QhHf2njw7NEZzClKrHeRW0FA0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705831; 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=VQQcjzaeBhRlCcvqQo7Pp2Aj2Za2lAaZPx+OKebF+YX5FBPf9eZ3n38SADFwUmmDTHsbiWbOPbB2OnLqTvMmbCJwPvu9olqZGEDCzX0i3S4NYGrECLzJoagxLvRJVvQDH44QyTf3wDvzXdHXj/ChvVPUrRJSqWqE5gWu0ts8w70= 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 1584705831879496.6691549678824; Fri, 20 Mar 2020 05:03:51 -0700 (PDT) Received: from localhost ([::1]:51568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGKY-00044S-Jp for importer@patchew.org; Fri, 20 Mar 2020 08:00:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52632) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHt-0007jA-KD for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHs-0000I5-9z for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:05 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:39955) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHs-0000Gz-3e for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:04 -0400 Received: by mail-wm1-x344.google.com with SMTP id a81so227850wmf.5 for ; Fri, 20 Mar 2020 04:58:04 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58:02 -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=l3aEuyvviKZ1VNKuQM7YmXy/hTxq6TpX/yZGb8g2XLg58AaIfB4V47Ht2GVad556fj wpDl8J6g99Qe1aOOrdKaCedKuJYVM9PYCN4VchYqZZwTFZxtkpjisbA7VE6kHrhnjxYD ZIKHonj9LJjMpJfMufP60my/VE30AD6q3MS4kSIS6RZhGXleWh1FYDzjG9B84p1bGrNX cD/SdGMyFfv8sleHyU1KmtDYnwji3BmAq8V6VX7ewIC+5SaufdDVc/RYSV9CNaiyOml+ r1+DlAj9t+1DLOsiY6N5+Qvli9Mg8yl29oGR3x/8qp/o4+HIEeQ/j4dCt/l2Wh7ikHVS qOdA== 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=DAa6/upEx9FKMzuVm151qWB8/DIxG96JqQbgo3V7wxnZPFcawZNc0eOcy7JaLm/8kg td63XsBKwL45muYP7n2rtiZuAUO1k6eNcIx2dvccxYqghtHiIRAcOgkd3pInNc6PXeAv QA9Dcbj+7rn1WZYu1kT/BIp8+UzEk1TP1kZQ2KesjfTZvGxVNulgo/5VXhoNDP8F2jz9 Jrr5V2XlrGmlHfa+opLT2hAaOWuZfcvS/DKKjccMWddzG/hHAZHuSMnLsOB90Rf7d072 iykEkVqfvkexRTLGbVNnSP77SG9HU8gEHkwP/pSDBGVJobGY30+f0KL+dvcKLRutkryA LsJA== X-Gm-Message-State: ANhLgQ0+gXt8//0XF9iMhNTNB21qapCM+OH9M/Yg/70D6VAU+hx5TFKk w+GZryr4SNLz/lrHVYBjklg8F+rT+Jxe5w== X-Google-Smtp-Source: ADFU+vsMih/Z1Hzhy5UAWRBdehN8Os4rSMDHr5OcPCGv5XMG0QHFQBWdDsJPcjGDu0uLwCGw7GpXfA== X-Received: by 2002:a1c:b7c2:: with SMTP id h185mr10074369wmf.67.1584705482684; Fri, 20 Mar 2020 04:58:02 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 3/7] virtio-net: implement RX RSS processing Date: Fri, 20 Mar 2020 13:57:47 +0200 Message-Id: <20200320115751.19446-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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::344 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 Mon Apr 29 13:58:23 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=1584705552; cv=none; d=zohomail.com; s=zohoarc; b=PYUqP1dcxPvRE1y/cfnDlXuvEotd8cT3ab2XTyENs5X6oXBazYw8zFtRd2sgSQLyxHCyysO/i+uy1QGelgOhRiC4RXx1a0MRx2l+LmwUd1qeAJDLbLS8WAPlfcaMQOha8prp3e2Zw5Aes6QRO57r8F/z9i81ssBMn6RkSSZ3Qos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705552; 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=OXsuGbdtTPkBZhQVsqjJrYRp/tvsKIfzwoAEj9QRfCIuz9Oa/yS8LklpjGe9RHiS/CIFFB0SISdoVy/Y7nzAFd+abtMf+stIHiuagAUEHB3wAICj059cUZXF4miIW8HdKN8+JdJg6f/nDNLWj9t0uXjL2IOtG9e/vfiL5R6w7Pw= 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 1584705552382545.0603919336547; Fri, 20 Mar 2020 04:59:12 -0700 (PDT) Received: from localhost ([::1]:51384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGIw-0000yL-Qx for importer@patchew.org; Fri, 20 Mar 2020 07:59:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52637) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHu-0007jl-6H for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHt-0000JO-AO for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:06 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:41633) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHt-0000Ip-4r for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:05 -0400 Received: by mail-wr1-x443.google.com with SMTP id h9so7074115wrc.8 for ; Fri, 20 Mar 2020 04:58:05 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58:03 -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=c1LnulymITYbvXEwWx+Tc0cFxZLPNjB2tqhHQfUwvY1P8qYR9aZe0fZLQXc79KVlFv 3jFeV0Kwi28jxCnZ3doO4WQ8TbUotP3c2MOmstCYZ/6mg6CBBehvPKZBTAzVxjEsN/nM W5cHsrKNlxFgSoAbuIwnMSZp2uEJrtBPcPruA/Ilrs/dLgp3ADspy5l9WP3GVeCVvOFK A4+Fnppq0A8uiM+jWREy6SrkJFkblIAZE7Uz4twEjEEz3QOLaRCSzLEZpwFAyeFcg0YZ G0s3ZuaziBddqyhoEl0Cb3dustHsCFqyLDPwR5bKM9AUbrIQeGoxtpErYbZIU1Bqek+Q bkaA== 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=oahBTtEEBU/FtSQZE4AzDCjMi1rtzDT2MakIMn6A1Q1hif2IESZPJZLX8zDeWD8k3o jcBbhGSyMiKtcX9Muvz4UA0OaOi6GE0yP8ZFLl+Hyh1M07Hp5kway/Yrh/1WbO6ghcvw aaFUHi0Ns3vsTMvvE7GBdbSAEbkCb8Gwoe5JFCH5yHwRxmXKMKdd41Cy386mn5Ij5zQF 1zFfpcRbLyDXoCuarEcTDdig2qgc0i7i8vunzmL0A3MQ7EFoFXd0KYZ8A/0GWgeEoxIX TyCu9+fLfVkp5z34t3sTMzGr4Jpk996Gj42iOwj4rYZbu2GBWpQNX1fVsoO3eHSgKZRK W0lg== X-Gm-Message-State: ANhLgQ0+oHgLgk2ENV/RIG/Y7gDNrdq+N7UZvdLptu8ZzNqtybct8lWv FeRKhdfNbeGX6s85T/j7jFWQ8ye+EeOuJA== X-Google-Smtp-Source: ADFU+vu+D7v2zsf+dcj7YlUxiaNkLA1N8YO1nIz4AOdjM9g0se6bzehefE+O/b+dntl1XduP13vsUg== X-Received: by 2002:a5d:644c:: with SMTP id d12mr10810610wrw.54.1584705483988; Fri, 20 Mar 2020 04:58:03 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 4/7] tap: allow extended virtio header with hash info Date: Fri, 20 Mar 2020 13:57:48 +0200 Message-Id: <20200320115751.19446-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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" 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 Mon Apr 29 13:58:23 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=1584705818; cv=none; d=zohomail.com; s=zohoarc; b=OgZ09arzmfEXobqSzjH/Xt5WBN3HX0wWS4zyp7GtIq4rZGN7WqGta9QhI470meHZDrdXS6w6I+qVrCeMKMG4DQY1wr90OYsjDcn0adiKldnDWmn41kwj9uM5+pS1hVhdjjHYyiv7RDe9ygvfkN8PAcdQ6SgCmFBfuvxhqXX6LY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705818; 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=yOupkg2tDjhA9k/ASRMhbHI4PkMh+TlmWpBkkRpxw3U=; b=Uq2ZP8P5WUmk6ctgCLymRmHX02X66GYHZJxZBHTfQHzAofoqNZlbI33goJaRtb6gYwsTNT1GDc+P/L7iV2UlxlWpWOUYd3xStSJWOca7dHAfxBS6ZXSeZgtFtpKVkgEIlnG5Wl2XQkVGOsoS5Zs4UFd9nyF1/qvrCkvpaur14Q8= 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 1584705818369245.1353688661526; Fri, 20 Mar 2020 05:03:38 -0700 (PDT) Received: from localhost ([::1]:51762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGNF-0006ud-1a for importer@patchew.org; Fri, 20 Mar 2020 08:03:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52669) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHx-0007m6-2y for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHv-0000KU-2k for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:09 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:33294) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHu-0000Jv-Ri for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:07 -0400 Received: by mail-wm1-x343.google.com with SMTP id r7so7071368wmg.0 for ; Fri, 20 Mar 2020 04:58:06 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58:04 -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=Sn5IOewDEAPX8s3C8Ml1ASAToxLM4/6Qz/US9I7XjYOI5AwA5s/YbVPU0ar6zE3/d4 N50wmeGkO7FB+EUkYmGhTOWnYbDdgVhMJEF3Mgk1lVDVjZd7bcVC7XA/A678AMoeX+W9 JEpeoCgkqhtwOcKNAtI1CwB3FtPQGDFrOmM0ysX07QjZNAMtkbsaSQiPAUekAOIS4Tl7 GOtTd1mYVWRZkbqPyVKRnWr9KxN+dEZ1jtX5GNLbkjJ+4eYSqSkOzsBK/ltPmBBuuRyl tICkl+UTWcoU4+dPWdVP2l0FRX4/4Dsv5EsoQowzpury+eFqkBLOJ1CK3MAI5/SdJ2Wt a2UQ== 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=qTWHomR/u0CSV/NBZcuGugG6XZlyFQIC442Pfq9UkyJHRZ4hUYS6rcN9SAN3s9konX 6FRrwhpYEK+ZtyiNwfzIAeyi8MhW/47QKV1mpl4vhCgrNMoTIclc7aSOHBCr9Qda1ayA Olkg+HehgP1nhDTKhPblSG3KRxDTxpvHM2SuMhIRcF6tOLN4TFQScHAdhJSOhFHcn0QY S0hOdWDAqxaD4OUgCACHlkbMlq8OpLWNxIBfV+Iiq6M5HVpKXivKCQYYThJk+G/RUpeO nIfwkDUc/3Aky0qOZZPVschuFOGtMcbFvIxfi9b24Nr6GDbpiqybYba/Eb2pYgA/ySHU kDWg== X-Gm-Message-State: ANhLgQ1KdqwfAEUDwnFckuFW23ehJwa7YHhvbyd6OL1V70BhFgrXzznH d1L/Angn/QVwYtT3QqvXhngsvnqJf3m5kg== X-Google-Smtp-Source: ADFU+vt+viySfJpkjWB3yhZ3Hn799Pb+T1oJ/3n5JsL4IYwQbRpq+RkLWIsCeAcKNClRM8dyzX8sYg== X-Received: by 2002:a1c:4805:: with SMTP id v5mr9556977wma.98.1584705485248; Fri, 20 Mar 2020 04:58:05 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 5/7] virtio-net: reference implementation of hash report Date: Fri, 20 Mar 2020 13:57:49 +0200 Message-Id: <20200320115751.19446-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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" 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..a0614ad4e6 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 true; } 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 Mon Apr 29 13:58:23 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=1584705756; cv=none; d=zohomail.com; s=zohoarc; b=SK6P3+N6Ow53h4fAnby9OeF9Y+wtazxu/uWgSxtMoJXenrQqckY39LY4VEv6aKXk2bw9MlDoQOYszNv5J0S0LcqvRxfem5zpzHzBEA+O7jvNnteGODP09bnrV/ahsdu7ckzXpZNKYFM30fsWRKZACiSc9T4sfqvVcNXmGFaO8yk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705756; 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=AFee3GUYsoNs8qQG1tr+fj+xESgGdcKaXM0S2fBcQ2FNFLbC9PcsyOB+RbldvPXGUcYtG178Il9fX3DOZnxtCkrAJN0q+UJEROGjkTfkQRYl4E6f1MmwBOOw/upqNHZH36YRziEXJQE0VE2/q+XN660Vkbtt6UYunE9D0t/O834= 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 1584705756662353.8595429574451; Fri, 20 Mar 2020 05:02:36 -0700 (PDT) Received: from localhost ([::1]:51606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGMF-0005cs-2q for importer@patchew.org; Fri, 20 Mar 2020 08:02:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52666) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHw-0007lc-Qw for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHv-0000LC-Ts for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:08 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:37834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHv-0000KY-O6 for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:07 -0400 Received: by mail-wm1-x341.google.com with SMTP id d1so5987226wmb.2 for ; Fri, 20 Mar 2020 04:58:07 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58: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=bKbcDZF4VvCdwc1Z3LgA0n0/o1l3SD8mbWQhoT1XpcI=; b=KUfOlH05cZMFhpAA+7tZvez+zR989Mxvm2TMXdK/iXYrhe4m2bAdFgT8LeAq6Jbdwi gncQmGBRVg+oHp2BCaAmkenyHYIaBh+Idvgen2SL0Ed+XEqb3gsi3rTnHkEJgcPCSHt1 5+YHku7BFU2oVqraq3eLhleJ3PmGer5KFE6xkl0yOO+mW7PkiLlmiweBFal7ymWYLti0 OPprc9NG7+D4fQO9Dk4FLtQyJU/pNjFH0+5ck9wJLESVr2pvqzLvXrdqYvAM+CoYi57d 7oYte8SXdDYtyPIng+y28I/dzkGdRFZdbMclM6cxIzUnuqNs0tnvM56VosBLwBZvez5B i42A== 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=TG6iskAH+SWjLlE2B7WbTcTvnvs/66f/UGymN9QnaAIdWzu9Aeut1msXODpz8vAAxM XNW5VXMqUYd+785lY/GoGy6gDpU0NHNi93zwo76Uy6kijNz46ub6AiOfUmyW98B20fIa DIrpA5EZeNLBHypoVyufJlhXXNP22kJDWtgwh/TfK4I9JRb/VTXhx7L+WmlspbvzSYGD 6ygEgymPScNQntSXHUn/9eQnJ75jCA1Xs+nSAklkNYX4H5B46unjpA3ahwfV4YdMu/d9 HRrvzUSlhdR3mqLzIdqwlItneZDVosanzjsK1FGw1nd4boLIf5mzLsxMJ34aMes+76si EDNg== X-Gm-Message-State: ANhLgQ2mFCxcsQ3p8wLPjfvW4qgWV1GxCuVXbVacZQU7x/+97niCAAzb XQi3HSljF3blQkrZc3SIm7okSxsuNklDkA== X-Google-Smtp-Source: ADFU+vuu9lTd6iZFTm0b7Asl0ZbQhcg72oVB41DSOFTcaGKm5Fnd7aJHW3zCnv0FTMrNM/bC1uKHLg== X-Received: by 2002:a05:600c:4145:: with SMTP id h5mr9664567wmm.3.1584705486512; Fri, 20 Mar 2020 04:58:06 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 6/7] vmstate.h: provide VMSTATE_VARRAY_UINT16_ALLOC macro Date: Fri, 20 Mar 2020 13:57:50 +0200 Message-Id: <20200320115751.19446-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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+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 Mon Apr 29 13:58:23 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=1584705557; cv=none; d=zohomail.com; s=zohoarc; b=NDMI66K7AM2Lwm3oUbv+7DtvQ06B+IZN+MbK2POjjIT5u+xwJVZQ743evdrIAHa3ouY85YiIDJovg4t83P57oEKyZK61vJDkaDQAlPg39Eo+PnOA5LU0+8hm5ZySVj9q9LSblEklU+BFyt9ZIJyT1sQ3or/ScXw4CH7sKwRQr1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584705557; 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=UxM/OE0A6aXJDzzbaw2R6dqzUVrzzPfxWU/B31t6IyQ=; b=kezlgdKLRaOTAimOfGD1i5EWWdqxcp7UrJcecgZqC91L2/oW2ViUT4HXOSq6M1yYva5fjkaGon1307Mkt1R57lGXPzkRnVr2zxmb69jalS70jiQW4Z0i3wK6vwEnt81jLy6JUb1t0A+5Gm+j5I4aFJi1Ou2vRuRNMe+5iuPRotU= 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 1584705557043705.4281115450117; Fri, 20 Mar 2020 04:59:17 -0700 (PDT) Received: from localhost ([::1]:51388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGJ1-0001FD-P2 for importer@patchew.org; Fri, 20 Mar 2020 07:59:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52687) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFGHy-0007ps-HT for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFGHx-0000Lu-7f for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:10 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34188) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFGHx-0000LT-1l for qemu-devel@nongnu.org; Fri, 20 Mar 2020 07:58:09 -0400 Received: by mail-wm1-x342.google.com with SMTP id 26so2851774wmk.1 for ; Fri, 20 Mar 2020 04:58:08 -0700 (PDT) Received: from f2.redhat.com (bzq-79-179-79-224.red.bezeqint.net. [79.179.79.224]) by smtp.gmail.com with ESMTPSA id c18sm6637645wrx.5.2020.03.20.04.58.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Mar 2020 04:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UxM/OE0A6aXJDzzbaw2R6dqzUVrzzPfxWU/B31t6IyQ=; b=vA0GSordADU74TKFIX1NZNTRSqjUY+NH16BHViQCO1/My1K52HXqKhY6MFTlnho3Dh d7/nZiC0mm9aHrJBS0I41xqfJkGzJMVts23qqN21Nl3pNvgrvkWwwI+G5HMHttcwTVKO CUNW83xXbQoRc7dKRXOyuWvQ++IL4ToIRzOQO5jD27KnGiggXt5q49C3mfzHqjZMtOvE w6SjV43WfY0/34RcP1nLSolgx9LntuME/7HDdn6f425gisJqfoQGZHEgxrgE3VRlZZYY Z8fMiTUZ3Zu2l0sJVX2jQAgn8hyF2utDX7FkmBMfyN4St9VA+4JgI0Mao2QXojCvpc0T +kUg== 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=UxM/OE0A6aXJDzzbaw2R6dqzUVrzzPfxWU/B31t6IyQ=; b=rOcSgCcQxIrNP1v4Vi6bojJ5VJp3ctmpuTUTN1eEupY67Rmhc8U0kI6jxZ+QqGZXvL 3LcofF6aviruu/NFn786HHSsGLnwTLzJvp3hUXG5G4ZasTwUuIegoDBngc9V/XI4OMbt 5nTjTEx+DVBgtUfgXOCx48VQA8pVZeutwPFqs2bcgmDFOOqzvL18NrYe2uWIBU49yDoW bi5xkcjRGiT8QwZcIxfDCqbI52wVJ4qoYvqwl5MEuh478iidkGGW96qGSATWLZMJbfpV 0P18SAqrhNyF2E3Ai+r6BigVTiJTg2FsBFqqusx+DVsd2lJjlyXy37eT56DjFeidQyHc xNbA== X-Gm-Message-State: ANhLgQ0UpvwFhrpudHzXzWlMTw9EwGQ1dmPL+9xmd6j7fPlhRi3rFuzV nwZ+8wzkFaH+5USV7WLh7Xv+iem2GjVSOA== X-Google-Smtp-Source: ADFU+vt6L1jRZxzIdsgyF3sAioQ7VImmSQvVm+PSias4Y6cf/I57+3D8w64THPY5UkCpnKPNQEeQKw== X-Received: by 2002:a1c:a4c1:: with SMTP id n184mr9745917wme.27.1584705487825; Fri, 20 Mar 2020 04:58:07 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v6 7/7] virtio-net: add migration support for RSS and hash report Date: Fri, 20 Mar 2020 13:57:51 +0200 Message-Id: <20200320115751.19446-8-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200320115751.19446-1-yuri.benditovich@daynix.com> References: <20200320115751.19446-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" Save and restore RSS/hash report configuration. Signed-off-by: Yuri Benditovich Reviewed-by: Juan Quintela 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 a0614ad4e6..7de7587abd 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