From nobody Wed Sep 24 07:43:09 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=1584523182; cv=none; d=zohomail.com; s=zohoarc; b=SlgZSBfsI+H2xb9fYdVZ5585j9AnHCMvszKRoGD7hoTbKwFzqph+taEhK7O0H7GaDpvYbpQSGYuXhKzmvbeZ5EKtcFc1nF0POg7RAYo4yXymFVBydL9/7ZotTF0ZXBijz0q7QWJ2shssPVVjlPCCPacBBsIiQaOUDQq7XqzAHlU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584523182; 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=fT2fouoe+oDXpoB+RUJ70W672hGSsl2FlWoHmquseQotqwpxmXgE3159e8JkWaM1c6kAHbDzY7T7K/R50+d0HUT6JEsA8GnJKyb5tGbGRrqjsQK/+HrQn91sYVvyEy+kH48AlD7U+pmsfJT5DDhDde4/WAOoFh+S0FbxK16mxSo= 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 158452318221695.50419478714991; Wed, 18 Mar 2020 02:19:42 -0700 (PDT) Received: from localhost ([::1]:47436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUrV-0007TP-2f for importer@patchew.org; Wed, 18 Mar 2020 05:19:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39610) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEUnl-0003Cq-KK for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEUnj-0004Vl-Bq for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:49 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34547) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEUni-0004QF-DF for qemu-devel@nongnu.org; Wed, 18 Mar 2020 05:15:46 -0400 Received: by mail-wm1-x343.google.com with SMTP id x3so1799413wmj.1 for ; Wed, 18 Mar 2020 02:15:46 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id z22sm3062342wmi.1.2020.03.18.02.15.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Mar 2020 02:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WOUtMRnFxKV7Y8XZ7UkZhOgeNFYtSpzSIraASB9IW38=; b=jFLsF/m8MohivTPb5X9fsYo/cxeE6jmvuUaCSw8JcC17C9s0uhpbhE6YYHXjNLwPSE 0sHNk03AR/yGvX2pGgAjf6qMCXaQd3CYBAKJ6wwvqsFrYCWrIvQkBdb4nlFZY6468jga t77fFoXU79KXI3rN3LHOzMozUUfW9L1RMR00YQC0/rdtdyebvxbvn62DY3bwBbQTxbS2 c9qDJcU2mKbFaOCgC6M1k+XBCy9ROv4Jpatg0WTYQgQGmmj9mbRXSvX0bpiQ5az/Bp8E F9sdCYX6i/WuKcTR+jL9kpxZC9sL7EnJFI1Ao1ClBXHLc4qUhUDcK8RLGRD4jn5fElMf LgeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WOUtMRnFxKV7Y8XZ7UkZhOgeNFYtSpzSIraASB9IW38=; b=oyM9nEhYh2qWuf9eRKmI7Hbe7XRrVL/qSBZLfYieleuis7yFrE3koVOQn7/s8WyRKp EfkXXpKohSgQEQDjNgz+HCNkRdFBKZXqE6+7mYdlUM8iqVVKnsJvHDLnVCxUKy9DNkns fwkbM6VvBn1s+JtJYbLBrzpMqSnP1VBjipBXf8u+2ADxjrGqwKd0DgIIS0KzAOPV3MCC jtH0ZDxGLt3Wp8j18GKQJhLOjqivRCU+pA1L7j5GMViyagIZRa680UZB4i+jK4HdLpk2 5u2RPBmS9HaWqADWVeLuwnTPRVFIrkyflyOenhY3cWN8KmRGkuwOiPUU4G8iSzZ/gMZb 5GcA== X-Gm-Message-State: ANhLgQ3Jt5C1Y2nq4NmSz9tbKf5koMlVSdR8QGD2O6jKQ+wkHCXed0kP 8YeGhdtySl1TIpeJ7mi21HHbNV+7fAdlKQ== X-Google-Smtp-Source: ADFU+vs/Y8CEc9rCyr/OGhcgouUi4Bgq9Q+bnONR69TFOLsMuL5IkKooulaHfJJgUFSKJITMtA5QnA== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr4363593wmc.82.1584522944916; Wed, 18 Mar 2020 02:15:44 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com, quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v5 3/7] virtio-net: implement RX RSS processing Date: Wed, 18 Mar 2020 11:15:21 +0200 Message-Id: <20200318091525.27044-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200318091525.27044-1-yuri.benditovich@daynix.com> References: <20200318091525.27044-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+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 | 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