From nobody Thu Nov 13 20:42:53 2025 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=1582739369; cv=none; d=zohomail.com; s=zohoarc; b=bi+z35BoiqWEhptz9+83Zvzd5mVGDXlwwdkmr0DX4NJk8AIAyci+xi1AgbmDhLlABfxqg0SUTsA2Qm+FEgwl62qSPzYJcz0j2RPmp++so/EVmv0YZz+LbIvDEbzseGxrcaQnPwz7fxvmE/Hi0JE+jitCrjgcfAHaS7lkT/QMx8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582739369; 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=zQeuKwZcZJtFN51AuoWn1tzXUO2w2XK219Hx5VK9dDM=; b=lzBiPQyj3jbRPukxY0CTT+zxEbbsT+t1d7GVZezkf6GSlA4sFUaSNA/mwWim9Juc5vJFnB8Y22yQ5sKcUlZdShsB3iaWRbyG+qAa0QMN+2ofnVVekzRFriAvuirikq/2hRMTcHa7iwuhKC/Ryyt3GV/21bFKRHIE8HconDNASLk= 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 1582739369896507.03402030213465; Wed, 26 Feb 2020 09:49:29 -0800 (PST) Received: from localhost ([::1]:47922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70oK-0005X3-RB for importer@patchew.org; Wed, 26 Feb 2020 12:49:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57684) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70nE-0004EB-8R for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j70nD-0003Tw-4l for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:20 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43575) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j70nC-0003Ro-Un for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:19 -0500 Received: by mail-wr1-x442.google.com with SMTP id c13so3426459wrq.10 for ; Wed, 26 Feb 2020 09:48:18 -0800 (PST) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id b21sm3930520wmd.37.2020.02.26.09.48.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Feb 2020 09:48:17 -0800 (PST) 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=zQeuKwZcZJtFN51AuoWn1tzXUO2w2XK219Hx5VK9dDM=; b=becty6s6zXK4X46476UGZjUW+eHEuoh6TBoUhiqJXC/v6K+k3NXuDv2Q9VtRtBCrHg G4xrJwIFZxG8r1X/TT82v871tUde9j425cFjsWwF+/BfygYV/Rp1DDYev8md/TKdZESx jh9cXCrFO7n+vH/7C+FCgGKeVbXwEIb0POemmUImhFCsqOG5nDqix9ufgujdIx0H3sNV WMzzL/b4Kay4tw+1rVcS4S+AtNwzrHsLSY09INiNLvUaV4KQU5HIe0QAUjikRdXXxjn4 PjTSXprpQqRU2bhnoos6i9LX8sASZb4gZoBQ9/HkHDGtC1wPc5k5FcJ0whjStE9tacPB +2iA== 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=zQeuKwZcZJtFN51AuoWn1tzXUO2w2XK219Hx5VK9dDM=; b=sreAiYyYhGHMYtCdpmYqj16ib/uk6UrIz/Y0n5vX/biDi1HTgfG2hmsA8qJRwGWAc4 vOC5fcJU5ctFievZxiEbNx8HPjdetmm1RFk+i0gvMLxEL/cC9XAXI3WuypkwPPWbVN74 2LBxW46RHp1NkOKU8de9VbOlxHYW4ej409HKXF5yCCFBzRkuA/OQXtb2mgW3b8POn13P RSfGYSPU2PCPId0pqXAdU1m6JmgGDOByyf38srNxeAY9e+3th7MA1ihEc+c4LIRWqnU/ G8bDmB94LKXsR6ZUd4LVD4AjIkBlCb0S9N+x2B/5hQfEj/EGW4P70H6nWC+67Y9rX2md JeAg== X-Gm-Message-State: APjAAAWnQ6Q9Xm38nYKFHnOTv8tEiLiWF9gMeUqTfIglsY0yc1acaTZr qZxwt82DldT7MgA4VyJtMYFZGHEaJFQ= X-Google-Smtp-Source: APXvYqwBq64IryB9WziasFH1cKya2C1doINUXwrAol1IeEzI26G9p6Jw+ClPc6H4xBNHtjMdGOUTWw== X-Received: by 2002:a5d:66c6:: with SMTP id k6mr2841961wrw.343.1582739297794; Wed, 26 Feb 2020 09:48:17 -0800 (PST) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH 1/3] virtio-net: introduce RSS RX steering feature Date: Wed, 26 Feb 2020 19:48:07 +0200 Message-Id: <20200226174809.9675-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200226174809.9675-1-yuri.benditovich@daynix.com> References: <20200226174809.9675-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" Signed-off-by: Yuri Benditovich --- include/standard-headers/linux/virtio_net.h | 37 +++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard= -headers/linux/virtio_net.h index 260c3681d7..3bc100afe3 100644 --- a/include/standard-headers/linux/virtio_net.h +++ b/include/standard-headers/linux/virtio_net.h @@ -57,6 +57,7 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ =20 +#define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ #define VIRTIO_NET_F_STANDBY 62 /* Act as standby for another device * with the same MAC. */ @@ -69,6 +70,16 @@ #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ =20 +#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 { /* The config defining mac address (if VIRTIO_NET_F_MAC) */ uint8_t mac[ETH_ALEN]; @@ -92,6 +103,14 @@ struct virtio_net_config { * Any other value stands for unknown. */ uint8_t duplex; + + /* maximal size of RSS key */ + uint8_t rss_max_key_size; + /* maximal 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; =20 /* @@ -237,15 +256,29 @@ struct virtio_net_ctrl_mac { * Accordingly, driver should not transmit new packets on virtqueues othe= r than * specified. */ +#define VIRTIO_NET_CTRL_MQ 4 + #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 + #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1 + +/* for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET */ struct virtio_net_ctrl_mq { __virtio16 virtqueue_pairs; }; =20 -#define VIRTIO_NET_CTRL_MQ 4 - #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 =20 +/* for VIRTIO_NET_CTRL_MQ_RSS_CONFIG */ +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*/]; +}; + /* * Control network offloads * --=20 2.17.1 From nobody Thu Nov 13 20:42:53 2025 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=1582739438; cv=none; d=zohomail.com; s=zohoarc; b=bpybn9jSVeLaXvAgk9rfKnRskbKTH+8SG0uKwqCytg6CouUHOKvRtUdIx53IwRe+e+TBdrtlZBMdpD2QS9s8kpPFUp9+3utgrq7LJfPXvHwbbkS1go+9fzhaiM1EapFEgJC4F3fg7+i0SwoahwkFfLt6DR+mYkhvRAQxSAOAyUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582739438; 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=diw+JS49+LbjrCNUzMh7AJLEbY4phRKQDrtBj2e3Vcg=; b=EClVe99otSJhavmWYfPWZejFHZ3iw6CzAvrxmowMC0BCHm8Fmfbb+YrtCy7BCDzuzeRjlnICzPw0JCmqxS3IdV5prGNug0aF8dtr5MvyYELXstD89XnB/t0bQVpmdB3LR+uQuIlY6uDXnLeaaQvjBaKEEqMPSwT99eFgnMam+yM= 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 1582739438812809.4873959074284; Wed, 26 Feb 2020 09:50:38 -0800 (PST) Received: from localhost ([::1]:47954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70pR-0007Q2-Jf for importer@patchew.org; Wed, 26 Feb 2020 12:50:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57712) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70nG-0004G5-CL for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j70nE-0003Wz-L5 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:22 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46432) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j70nE-0003Us-EA for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:20 -0500 Received: by mail-wr1-x441.google.com with SMTP id j7so4138495wrp.13 for ; Wed, 26 Feb 2020 09:48:20 -0800 (PST) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id b21sm3930520wmd.37.2020.02.26.09.48.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Feb 2020 09:48:18 -0800 (PST) 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=diw+JS49+LbjrCNUzMh7AJLEbY4phRKQDrtBj2e3Vcg=; b=Z3LhaOKO0znyoZHeArm0eyi6w7B/PcsLdsvFnzEGXcIOC7uJEbQ4oMgxy69gMlW4sk 9npE2FtbvaCodcom4H2YrfWNqOHs5WWQuBfl9K6lOC9XK8EEOPNRrQK0pm0DuNnUVy4m 8kDEOlpFqMkyDkABX/apGJRb3gdLABBjQ9v6EHPOxmTlkVi7VKpqH0KsFNLzw303faXi UOfxld2WIJ/bCC3ryj13kjuYdjn3P0Sr/l8VhjA3btVnObb7yjrFFyKs7rF8Zm5/XGOp aYC/kS8F7DAhI8eOqI7cFRnjMcEAfW1ootRgVq8FKDZwnwKgPDoZ3JmKIbJmaQCls3TP a/fA== 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=diw+JS49+LbjrCNUzMh7AJLEbY4phRKQDrtBj2e3Vcg=; b=Hx/tvzOjpshubWLjcRoXljl1adUDv7aBgLn1KRO4SVHxHsIpF0qlpFc/u28va1OJuK Z/SZN4ZXJu06wnKV8nnoUq1Ra2IKAm6Snkk0AZqcNEYJa9nTpED5515wzncS1lCN+zBc 5kTAnyd+/hJppD0oxq0l3XgqB5NGfJ35hVNGtPfOjZ17p2bkxN6WrGptYNmeqbXQnKGk gr3xFBcLyfqf116Re0zTa7D/nI1w8is4dTxp8UmW+gSTA5R7XtyZk0hOsRxDgQfRefco yQWTdNo7jMo/uWxgYDzoHoEVRJJSoR4k5bKQayRIKHj7qxM6YJshkRtVQiinfYt5RnpU Xoaw== X-Gm-Message-State: APjAAAUpeI7LL5IYFZgwyDzRRfnIulaj9AiszLPTuVGdv+BUtlrVraKh 5Uoyj+3EY4pjjPRGP3SuJ3WdJiFD7Lw= X-Google-Smtp-Source: APXvYqzYI+qciAZMwIUrFqnoJH3YwAKSdZZQQeLPP4zI0r1VRn3XaC8Kp2vhlQ1jjrl1cFTwrF0r2w== X-Received: by 2002:adf:ea4a:: with SMTP id j10mr6490245wrn.119.1582739298862; Wed, 26 Feb 2020 09:48:18 -0800 (PST) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH 2/3] virtio-net: implement RSS configuration command Date: Wed, 26 Feb 2020 19:48:08 +0200 Message-Id: <20200226174809.9675-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200226174809.9675-1-yuri.benditovich@daynix.com> References: <20200226174809.9675-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" Optionally report RSS feature. Handle RSS configuration command and keep RSS parameters in virtio-net device context. Signed-off-by: Yuri Benditovich --- hw/net/trace-events | 3 + hw/net/virtio-net.c | 148 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 11 +++ 3 files changed, 153 insertions(+), 9 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index 4939321493..0f47b7c450 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -371,6 +371,9 @@ virtio_net_announce_notify(void) "" virtio_net_announce_timer(int round) "%d" virtio_net_handle_announce(int round) "%d" virtio_net_post_load_device(void) +virtio_net_rss_disable(void) +virtio_net_rss_error(int error_case) "case %d" +virtio_net_rss_enable(uint32_t p1, uint16_t p2, uint8_t p3) "hashes 0x%x, = table of %d, key of %d" =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 d7d3ad6dc7..c5d21675a9 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -77,6 +77,16 @@ 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 @@ -108,6 +118,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, supported_hash_types)}, {} }; =20 @@ -138,6 +150,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, = uint8_t *config) memcpy(netcfg.mac, n->mac, ETH_ALEN); virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); netcfg.duplex =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 @@ -701,6 +718,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 @@ -860,6 +878,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, @@ -1136,25 +1155,134 @@ 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; + int err; + + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + err =3D 1; + 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 =3D 2; + 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 =3D 3; + goto error; + } + if (n->rss_data.indirections_len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { + err =3D 4; + 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 =3D 5; + goto error; + } + offset +=3D size_get; + size_get =3D sizeof(uint16_t) * n->rss_data.indirections_len; + s =3D iov_to_buf(iov, iov_cnt, offset, n->rss_data.indirections, size_= get); + if (s !=3D size_get) { + err =3D 10; + goto error; + } + for (i =3D 0; i < n->rss_data.indirections_len; ++i) { + uint16_t val =3D n->rss_data.indirections[i]; + n->rss_data.indirections[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 =3D 11; + goto error; + } + queues =3D virtio_lduw_p(vdev, &temp.us); + if (queues =3D=3D 0 || queues > n->max_queues) { + err =3D 12; + goto error; + } + if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { + err =3D 13; + goto error; + } + if (!temp.b && n->rss_data.hash_types) { + err =3D 20; + 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 =3D 21; + 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: + warn_report("%s: error_case %d", __func__, err); + trace_virtio_net_rss_error(err); + virtio_net_disable_rss(n); + return 0; +} + static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, struct iovec *iov, unsigned int iov_cnt) { VirtIODevice *vdev =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 || @@ -3209,6 +3337,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..cf16f5192e 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -126,6 +126,9 @@ typedef struct VirtioNetRscChain { /* Maximum packet size we can receive from tap device: header + 64k */ #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB)) =20 +#define VIRTIO_NET_RSS_MAX_KEY_SIZE 40 +#define VIRTIO_NET_RSS_MAX_TABLE_LEN 128 + typedef struct VirtIONetQueue { VirtQueue *rx_vq; VirtQueue *tx_vq; @@ -199,6 +202,14 @@ struct VirtIONet { bool failover; DeviceListener primary_listener; Notifier migration_state; + struct { + bool enabled; + uint32_t hash_types; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; + uint16_t indirections_len; + uint16_t default_queue; + } rss_data; }; =20 void virtio_net_set_netclient_name(VirtIONet *n, const char *name, --=20 2.17.1 From nobody Thu Nov 13 20:42:53 2025 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=1582739469; cv=none; d=zohomail.com; s=zohoarc; b=mRHno1Y976ZjSlsG/daiI56mnq3QPIWPiQLE+uiZXQk0pngY3/EhN6K9N7JPDeH6CfkEJgV/B1jlaS2PbROq5M7uZEO8H7/VUV0i01EL+rm9XIj8TWqeIxPBdk6u3KL4dWv/PLtKH8OpPOYxkIsFiCoGHbGvRSAYD8Xyx+/LgAE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582739469; 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=r8QR8/6myPTxOG/zE+PYfWVRq8kuB57xhUuFMpl5zoU=; b=R2StRXDOvPdKvxIyLOd8fIZfXRjIcY4Zrgvg4TDWvWj2zaRwzzCsdxUgAc09fnhb4dISzeUH0Q5BJhlHlDFOY50aLmjcpnHHy78+SWEqx9/OZW5TO7tSPvDbQyys80GuPXoSnPhvy9iBMABCFFZcxOe/2ZZvdqfsNsvArlvkeDY= 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 1582739469884642.3313521324596; Wed, 26 Feb 2020 09:51:09 -0800 (PST) Received: from localhost ([::1]:47956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70pw-00084W-N0 for importer@patchew.org; Wed, 26 Feb 2020 12:51:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57721) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j70nG-0004GW-Qb for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j70nF-0003YX-Ja for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:22 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j70nF-0003X5-BQ for qemu-devel@nongnu.org; Wed, 26 Feb 2020 12:48:21 -0500 Received: by mail-wm1-x343.google.com with SMTP id a9so161489wmj.3 for ; Wed, 26 Feb 2020 09:48:21 -0800 (PST) Received: from f2.redhat.com (bzq-79-177-42-131.red.bezeqint.net. [79.177.42.131]) by smtp.gmail.com with ESMTPSA id b21sm3930520wmd.37.2020.02.26.09.48.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Feb 2020 09:48:19 -0800 (PST) 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=r8QR8/6myPTxOG/zE+PYfWVRq8kuB57xhUuFMpl5zoU=; b=Q0nzSmbagsa28z8upqGzL53/jCwIGUtuB14n7TTcKheNrFC+dgXIsd2m04f2ZFlFaJ sJJRSmBE8EnHgS51EIgMGvBRRpQQw2P4x9sqBnBAf8A2UxxzHbjEUV9ZkeXcv/IYFR+6 Zqel1MoXFD9gLs+wUUdK6eJ5Toj2ZiSfS9ZZDw3FaAh7BdDJculYfH5TzJ1XiQTc4HA3 O2UOnROgySfjj3xfNydaj00Y/xkdPxQcBH7H2XOHOjZin2hy4lEHAr5OR7fTbrdxCSmB ESLke0z4Pa5ZU+vlRQMK3L4hZ3xkUexchTDxtigD59K2Z2bVvI+VKF+kAfFIW0c5u2pz +8Cw== 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=r8QR8/6myPTxOG/zE+PYfWVRq8kuB57xhUuFMpl5zoU=; b=b96NX9KIBXrrZwD9wllRKfReFDUAopYHGugO/lEqG50bpA2NJc0Jzk++6BtYx09o54 4Uk0ZWTc5O/5fiAkN9YRGHt2evy+BGqIl3rRBO54H7wY+olM53hRgeGn3H0if0nPscp5 Cv+Mo7mZekhov91H7b6DxBR/9cEPFXmXDWwA5KqJ4jy30OqTO2EIRAC47KPVX+4xcq/J eSalLSy9k/YlPtsyxdBHsM4szDBniDOJYNP4mu1wB46WNjogCZxWNGw6bVGiQQbAYqz7 yDaj+PM3o8BQAO6ZTYTZ1HnLxEFtD+T2xx8hqRVGdIx8OUGDtlBxsDsc9Xl1NfgoFF2b Sr7g== X-Gm-Message-State: APjAAAUmOiSlAtCbxamzL3QJNBANlJXbPwZfLkvJkCRSE8ORE9ZlTXpa OoPVBfWyFIrzamh8XDEasPpof5sQ2gM= X-Google-Smtp-Source: APXvYqxjPbr1gw1aUsNXO4/FaNzbDnBB2OZ6s9dzD1WDgFo4zEXUe75OGyLhqTWCPEDH6KQGPdh3uQ== X-Received: by 2002:a1c:2b44:: with SMTP id r65mr49474wmr.72.1582739300028; Wed, 26 Feb 2020 09:48:20 -0800 (PST) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH 3/3] virtio-net: implement RX RSS processing Date: Wed, 26 Feb 2020 19:48:09 +0200 Message-Id: <20200226174809.9675-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200226174809.9675-1-yuri.benditovich@daynix.com> References: <20200226174809.9675-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 86 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c5d21675a9..adf7b88d7a 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 @@ -1515,8 +1516,78 @@ 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) +{ + uint32_t mask; + if (isip4) { + if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) { + return NetPktRssIpV4Tcp; + } + if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) { + return NetPktRssIpV4Udp; + } + if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { + return NetPktRssIpV4; + } + } else if (isip6) { + mask =3D VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYP= E_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->rss_data.pkt; + uint8_t net_hash_type; + uint32_t hash; + bool isip4, isip6, isudp, istcp; + net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, + size - n->host_hdr_len); + net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp); + if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) { + istcp =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[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); @@ -1530,6 +1601,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; @@ -1624,7 +1703,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, @@ -3200,6 +3279,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->rss_data.pkt, false); } =20 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) @@ -3236,6 +3317,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev, Error **errp) g_free(n->vqs); qemu_del_nic(n->nic); virtio_net_rsc_cleanup(n); + net_rx_pkt_uninit(n->rss_data.pkt); virtio_cleanup(vdev); } =20 diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index cf16f5192e..45670dd054 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -209,6 +209,7 @@ struct VirtIONet { uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; uint16_t indirections_len; uint16_t default_queue; + struct NetRxPkt *pkt; } rss_data; }; =20 --=20 2.17.1