From nobody Mon May 6 07:43:44 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=1584355359; cv=none; d=zohomail.com; s=zohoarc; b=MlqOylTu8PsLqhOHEHhC/MHo3dt/NgtiOvbgwizqqRIBEjgCRpB9fOHlyZHQApmQ6Btx+h6GZeFvwLz+hkK5LJcxhtMp9sYt/picjAUQksQsKVrHIlSWtaoIlciK8GD6sQo3+TSA4WONNvI1WL7sniZOmWsOva9UPGwCcRQYQVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584355359; 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=YcLIB7dBXV/bVyi5d/BsdhBYl4/wC1PUKRRjN6dE0k4lVoqmCeBL0C4sRcN1XeBt7P8m/h5wlv6oRfUsg+K9j+OWfZh9tz4rh3kellomyWjXMCdkX+1PLt+7SrP5463mqo3K6FyehiemE0uTDri8JxuB4IpD1mxvzbhDKQdacjo= 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 1584355359769709.5469666927956; Mon, 16 Mar 2020 03:42:39 -0700 (PDT) Received: from localhost ([::1]:36810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDnCg-0000Wf-9m for importer@patchew.org; Mon, 16 Mar 2020 06:42:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38042) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgq-00061D-7I for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgo-0003Vi-Vk for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:44 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:37334) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgo-0003IM-Oo for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:42 -0400 Received: by mail-wm1-x344.google.com with SMTP id a141so17289197wme.2 for ; Mon, 16 Mar 2020 03:09:42 -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 l7sm22083171wrw.33.2020.03.16.03.09.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09:40 -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=msL8DEQlvZ1Rs3XEr82evKNVqTPFKnKxfjkdLyy618FEHCRN0tIu/b/Frp9ATQs7bK wuPfyoHKUH9hJ8tACQWogGu7K3n3g/YcCwFrgHrtqmvqEgYSKHyjRBamliBIxAdtsmlg kl5gIz1qW9hB/coHFGWg5OKMImgq8P/vTObqY4ax4467wq7Wb4KPJMaabPvmZc2ZHwDu S1dM0qIyQnXexBXtQhVMfKci9tx3XQX5fyzgycyFbDCiHA2/0sl8n/u2xzsZOdgCIZ7Z D3a3LxOC6fRRtitZyovL8Ktvt2o2DTh11xyundsUphT0VbltXF1Ie3DKl0xRElPZK408 +iPQ== 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=I+lUEGw5QHLYR625MMLMRzy/tZ9o87iUrUE1yQh3ecvcCdEhf/BRL6VXKOhPfut1YP Gd74ZtuimHT2e6X0U/Am1jL651VPxQP8qYzI0JemT4XIh7bDMVOR+Y0pOqmn2rd/exvK YTkfq1CXuDb0Z7beRwJVXVrTyGEkpkbOWmVi8DmAL7yuO1BT+7p8FmxSpXH9FeB2czha OvKEIwmhj9LwX4qT1qlYltVmrPAdfiMx54qcQ/QVsLFYkY8KMPoHHBmviCBldFnBuE2p bJbC1zv3GaO4Hlu1GASm6I2e49Lkkuhxti37cI/GbwKRpKQLF/IxnSbVFn+A4KS0wLnB sUEw== X-Gm-Message-State: ANhLgQ1JafTfVGfw7NLTAs5ZIsc56701qDSFjPqi7wZhIIxF66VAM1xC 4heHxDiZrgA6Sq2wWIqV7KAfQCePyVEjjA== X-Google-Smtp-Source: ADFU+vtgtxCGE9sI/h1KrB0e+kHzn+iNoDh8xmeBXDVpAv2xUZiCs5TAl3nyD4oQOIIIetZOqSBYUw== X-Received: by 2002:a1c:668a:: with SMTP id a132mr18495986wmc.126.1584353381367; Mon, 16 Mar 2020 03:09:41 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 1/6] virtio-net: introduce RSS and hash report features Date: Mon, 16 Mar 2020 12:09:28 +0200 Message-Id: <20200316100933.11499-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-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" 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 May 6 07:43:44 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=1584356084; cv=none; d=zohomail.com; s=zohoarc; b=HtOJApCQ3Ro3klBMIPy7T+NDiP096Rfvjz+joaL91AsLwBFPqJx6tGOkHTNasRfqAr4qXyLswPOSfPVvW9Hf6iXDuJF3XciF6xJWBfpjV0EsWjDP+81imHC6IEDeny5EsdAaG/ogcRDtUgR0bYXe14IVcK+PSMPhQqFouvdXN8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584356084; 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=RpM1DhZ1gVnEqcgBO/wdPaWAEvwvm2ojMM129mDvGAU=; b=UuMmXYZtdbrXHXbKoI2vjsVz2rwEA4UTwzyTAPFnFXbqeNivJcrYJVWTEkyoEg5+7wuDzfdeU6KeuwrcPIYColwboO+lYk1aObE6l19SXzHiggeIH3UH1I9Sz2/mE12Vh1/Cuw/6F1f7wpN/GPESkgVj2ELBxTy9iqzksXMyQnI= 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 158435608435536.22122426745932; Mon, 16 Mar 2020 03:54:44 -0700 (PDT) Received: from localhost ([::1]:36924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDnOM-0004oA-LN for importer@patchew.org; Mon, 16 Mar 2020 06:54:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38383) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgx-00063x-4x for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgq-0003lM-Df for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:51 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:39281) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgq-0003bb-4n for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:44 -0400 Received: by mail-wm1-x344.google.com with SMTP id f7so17287835wml.4 for ; Mon, 16 Mar 2020 03:09:44 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id l7sm22083171wrw.33.2020.03.16.03.09.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09:42 -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=RpM1DhZ1gVnEqcgBO/wdPaWAEvwvm2ojMM129mDvGAU=; b=eFp1/D+Zf3czFCfm921iKGjXmntTba4iQvdZ+qeBCjsMYt/xqMJ0SRh1Z1lwbEKwW6 qBeA7VhrfouApXFKvClx4xnakuX2dnoaWHaunsAeaVh1QCuewMFe51BaH5kTMoap0M+0 JjP+ECQK1G9IPCUqbYlSzGS83WCLJTNSB2lyAqFhPv13gmkFE5zAukB3T43PxSffpfOU 22mEPT9d3/icr5+6c+UqCObRj/HTc+2UfxKce0TikeRtT6Ng7m1V5VNeH1OQtkSwHDas 3MmFL2oOSTxcyKFSM3ffc6WjnBb3wjnL9WxnsL/T3GNTLKM6Ikur8/hIfJ4YbWIjqalv mpVg== 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=RpM1DhZ1gVnEqcgBO/wdPaWAEvwvm2ojMM129mDvGAU=; b=fKBZyY4JFVEAvZ7iayjf3Eub6QRJCVTRIVbSXUe6q6w9xRLjMZy2PslGdIOlYR6iHp kriBxOar2eJRzDZYkMtQAeFDRkHuZQXiYQH8Vqu0w8oXVeTLlpjMa7BAJvFq9sRFRM8r z/gxFp4uaX2B1wp28tjsKOgflMqyU0XJPlVOlAFDbJzqVfZ2cskoPMaZSqhc7dEk/bOz NAyMvsyzA0bltUEKgdehFtAJBeLrGaVi68lac8VwCUmYlddQEki9m8QXvqIcLLzhq1AN pDZBGuUya3LEoyIzT8gs5UH8jvkZnpPLhaA04NcXyds3FbnFdStkbuLphWR9XjxzczSw XYDw== X-Gm-Message-State: ANhLgQ0yk92i3tz3QaCGEP10Vm6tqHvbHq4qU7nnKYs0zyBAKDPl6Nxm iKzFK4iuftqmAWSxmjwsG+EMdwVVXGUhJA== X-Google-Smtp-Source: ADFU+vv/K7IGpFkJyEQiaeD6HaUNz7M5XL7sw7BZWB+OPe3CXBG0Rotj8LWbZ8uNdArRnNL2+bJeYg== X-Received: by 2002:a7b:cc04:: with SMTP id f4mr26636639wmh.134.1584353382645; Mon, 16 Mar 2020 03:09:42 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 2/6] virtio-net: implement RSS configuration command Date: Mon, 16 Mar 2020 12:09:29 +0200 Message-Id: <20200316100933.11499-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-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" 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..a4d3cda2ef 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]; + uint32_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 May 6 07:43:44 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=1584353824; cv=none; d=zohomail.com; s=zohoarc; b=d2ret47EBP7lD5xqPk1OSpuF24QjhS+VVfJRSfypj8fNrJ58E5x25NKsbSehStLJ9xYCn2D6Dya4A3iyo0Q6TkbHToeOwxUYc73cTFi07XrlJn9Ok6WnItXkDmT8uR+D6oWwyG+NgssdXiZgfnXP/4Y/ZLbnDbatgPh/MTIywdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584353824; 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=4+SaDq9fFx2PIa1PKkImSDWRMz7fp6eFu/sa1+8mhiU=; b=Lwmmgzw2Pj0rxfawbEqkCsRWdjPfCzk5BWGHSD+5RhdUgdDSfNpNRkhBYb+IAYlPkIbl3BWOVm0xgPpSJeLQHBhtIuldLb//xBJwWrVEA1hw+ufBGmjrNhslaqZ4rUeP60DhsFMNO5YnNwX0aFNE3wJxQtnzDWYlq3lTtA15YYs= 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 1584353824095541.4631270699479; Mon, 16 Mar 2020 03:17:04 -0700 (PDT) Received: from localhost ([::1]:36572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmnu-0007z3-3k for importer@patchew.org; Mon, 16 Mar 2020 06:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgs-000629-Mw for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgr-0003w3-An for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:46 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37632) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgr-0003lI-28 for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:45 -0400 Received: by mail-wr1-x441.google.com with SMTP id 6so20377349wre.4 for ; Mon, 16 Mar 2020 03:09:44 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id l7sm22083171wrw.33.2020.03.16.03.09.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4+SaDq9fFx2PIa1PKkImSDWRMz7fp6eFu/sa1+8mhiU=; b=OyweBN1uVdLk1yweIJzlEEyx4gxjOVSMMp4aAEtnlPDbJ36Hs2XPQwgm2b8GjkOBM1 0wVUxwd67a2Bj74RECUxzDL58X6rg4yTaj/AEXMgVOWn7Sj28nK43VpTDNxFRrTjh/Ev 8uok4SYfNaG9seGOBJhg6cziw5prf2EQRqov6BzCvOS0+9axX1x1jn0oivoecqAogzZe AJXh5agVv0MSunu4SOsN6+/ZyAVqVUl/ZGIYotdGRZAKpUcY13XwJCSfPhMijjBceSd4 VTsb1vOjIOJv+XP9qGlpsIJ4tagWBIm45C4o0U6hM9kAsPlyFIp2uqNqsdSyByi3PkiK sADg== 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=4+SaDq9fFx2PIa1PKkImSDWRMz7fp6eFu/sa1+8mhiU=; b=PSzWVPDxErIs3VGcYeeU0jt31XFnbscF0JmYSswCTTHP0G7zRjcMhid2d/OtsJ1G2K /QmOYMSpHu5G1POloCvRRH7P9JLUVdq52B+DXgsm9X31lU5dv8XZWsQv9G4ceEDgrwm8 eu8UdceqbvM8F9JBa0INyX0fAKNXWPRerQLADWRFaPqhDu162QAxCqIbkMmjjOHbFJ7Y eTZUsImmCC5XyuYv8nIvu657R03UhpdnVKTSwO/EtGJhP5j5+PCR13TZ3NHyXEiHVy2V UtB3sUhktg8jNT5/noYEv2LQzSU1L5/OgNvb6bPcfvfL2TMPdwbJPPteWmQPdxE8i0h0 OjgA== X-Gm-Message-State: ANhLgQ2JTs4qdHkEKf+kmPYhsM9ryP71jdUZsxJu6yUPpTXhxjYYZKrz aZcXgMMiZoY1Kj2Rlt0/uqY+2ivlbiQyhw== X-Google-Smtp-Source: ADFU+vttoyckYKLUDcbjflI4Y7Bt8AbsbmOkx26gL3Pxphbjzg5u3c+mBBh1dYHYa9um9LN2dRafZQ== X-Received: by 2002:adf:ce8e:: with SMTP id r14mr4505501wrn.415.1584353383756; Mon, 16 Mar 2020 03:09:43 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 3/6] virtio-net: implement RX RSS processing Date: Mon, 16 Mar 2020 12:09:30 +0200 Message-Id: <20200316100933.11499-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-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" 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 a4d3cda2ef..c92697bfd5 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 May 6 07:43:44 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=1584358368; cv=none; d=zohomail.com; s=zohoarc; b=geo2dfFcPUII9UlQiFb7+E0uSOf3NwaXbhM+oUM9DES4sM5+FRFEwyUitN4+ZGa512lT8g2cqlF+BLYFFESuR9qVC2Pd3JGO+PhkvCm3LmYAwhpY0S/EU4Om9wnzzu3213uUq/1/NoQ2SDNzZaSWPP7SFqliMkJwDYm9zmN2YL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584358368; 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=JVsnvejn+5HovHJ/xwoT1fWS7joy1HxTcqB7roAB/g8LgAeAT9rMkiZFf6lFDrlqbbvh9Dg4wsxgiJ4RL1Ii6RlVkegRnVn0ctDqC6AS3u7Gsruet7AoOHxSV/MW5FtjrApLwAJBovoSZbC2H1p2DMLzC/0i1tGF3zwmHj/Im9w= 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 1584358368688488.2377274376204; Mon, 16 Mar 2020 04:32:48 -0700 (PDT) Received: from localhost ([::1]:37262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDnzC-0001rK-V1 for importer@patchew.org; Mon, 16 Mar 2020 07:32:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38282) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgv-000635-CH for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgu-0004LW-75 for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:49 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:40168) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgt-0003zS-V4 for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:48 -0400 Received: by mail-wm1-x343.google.com with SMTP id z12so8107477wmf.5 for ; Mon, 16 Mar 2020 03:09:47 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id l7sm22083171wrw.33.2020.03.16.03.09.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09: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=6H29QJg5B7bgS/AMKBONCsgkT/bfdiwpiQn7qsNuQ08=; b=w+Svhp4cGh5E4G64FVtLDqRzoo9jo6hTS5Mtm6YdRuvLH7sVjCIjXBsJFqEQG+qD7D NjF4pOrrmcOW4ItqTVoxnL/TMI2ymHKhSdbR4K7kFjrgWLTlZbdmvt2zLgk87SQcO3VF UHYQqgkBsVY1T5XN4TpftCaIDc646eYgIIZIFuH0c90nLnK3639Vr8mb5IIz0oXSEi9S Zy7JodrXqz6zQV8vyWnbHfOOfV7kJt06wfwbfxGXsrMPRq8kUyJ8LD9X2NnI4+XZEoF0 eytsfT2esSnkt/vcsAQkj0NOt2F/BodvvVDTgFoytezV8w6gxJaZNpZboIKnUKNaiQhv ycoA== 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=TXCaPgB/IDG3bz1tOdRclLnqpaI8lNtEvqHU8TAMq96F8VoRKQPKRlmOh0Sg4S4nKp lc/OAqnk6OGOjx+khfX7untEYCeCOQ6XQzZLhnPtBtop++Dzyy8Mx97MRbBFqovoyMAQ 9Rdd9/24hOLWuDQg6GFyV2oys2uuj4BgKrINshSEEDroalLyKuuLtS6VcRvoxZfKNoaX HJmqv8alT357sx9PefpcU6Y98JczR+4OEhx1m0YLNP/3nyPY+76dRvzDEvaBbXIB7GOp g8LiE7wduyiVzYVljouHMs++lwl1InOZHBxfpTuhmwAni7QQuRJclsARwZA3tVQipQPr K2Bg== X-Gm-Message-State: ANhLgQ3duV42GnHRZJetugr9aNzVjW9E1i9VXsRfDAYQKs33DurlvFHV TxbxJmFielqR1DUwN343vpmxfM55Njvq1A== X-Google-Smtp-Source: ADFU+vuXByjITBfw2urnYct3pk7FPEG9hsldv4bbJLUH3odgAyGaE/i9Jh/tBaOiohze0LTgfTst7A== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr2648250wmi.72.1584353385175; Mon, 16 Mar 2020 03:09:45 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 4/6] tap: allow extended virtio header with hash info Date: Mon, 16 Mar 2020 12:09:31 +0200 Message-Id: <20200316100933.11499-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-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" 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 May 6 07:43:44 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=1584354527; cv=none; d=zohomail.com; s=zohoarc; b=WSHuEJ1bvDYok4WtpM1vnSV2MOi4JZ8KWV78shMszhyJFnx33AF6LJJg4xKjogvX2+pEiBxEQWcuhMlctfBofC8qryTxeCsW60mAmMOJWBdXALI+kkdlWllG7N2LjfHBGcpgJR+i4/HVxS4OeosNCO3rgD11ZHBXrtbG+3sPuLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584354527; 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=c1wTfXu/2hbExbmLg7C4XuLU62RQFo9tK0K81KxmXHM=; b=b0BBmvcPms6x4XXQ/1Ha0ENth668mIaYkIG26zc2NQ56g4mBhMVe1bNxxQ9SfCvoYYtR4Yn+0FRAPeK30muzBaXHkhlnYzczW476j6/fud6btkSZwDCNNJV4p0+C6h5xebel3G14TEnSQX6BESybXktP1qx6dsDgo3jJU00fwjk= 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 1584354527688982.5539652526605; Mon, 16 Mar 2020 03:28:47 -0700 (PDT) Received: from localhost ([::1]:36680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmzG-0003zW-2k for importer@patchew.org; Mon, 16 Mar 2020 06:28:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38347) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgw-00063b-Gb for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgu-0004Nh-GN for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:50 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:39280) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgu-0004FG-6z for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:48 -0400 Received: by mail-wm1-x341.google.com with SMTP id f7so17288097wml.4 for ; Mon, 16 Mar 2020 03:09:48 -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 l7sm22083171wrw.33.2020.03.16.03.09.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c1wTfXu/2hbExbmLg7C4XuLU62RQFo9tK0K81KxmXHM=; b=MUUD3KIPu5J28Ne7jIrSrZKZ6YDPuL1UyCJhzp/vPG3gJU0DVRkDlzIWP/RX3BpvpH g28cscDZ3VtyfB7hFfzmMTikoWKL5GxD1w9chtOS6BAPFtdA0JFNv8/dz+8e3W51mvI7 QUEMDNjrujbLU7l9glqsBvQSJVYyQd5qJB92ggVAm6NNPtk8btVXmw4jTWp5InzL5F1x 8ntjvmmwuz9ZnfSfeaPkGatLAeeCBmALC2C4C7yDoJTsGQe+/nOekUHRkPMbvp/zUxRc UeRTcq8cJjjO/w1mF6+nct8dHaZViqVUodZ+p55l8SxMz3h4dBnNAzOp4+LnF+aOaNLE RAcg== 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=c1wTfXu/2hbExbmLg7C4XuLU62RQFo9tK0K81KxmXHM=; b=iLm9fpcFHK+6Gx13QovVhKstOnGO6Ek4WB5s8khCCAGyOlgt8Bm4AGquBXpUTneOMK HFIjYyujTRKeJw6My+sLYx0ZpoqagVJ5FPBQ7IYJADUI6pEvmFDNxkMugqiyy2v+ex1H uTpu/Ehtvpbc1vT7xzZ+/RV0Mht58UCg0chnPO28jONKUm3HKBmFDlrZQ4Szi+Nd6KCq ZqgedookX1LJhQL/spFVFOxPr3Ph7GNfyCP7KfrRClw2yOesje6NYtHGpyYpHcuUh9JY qHUi3S1g//6wJRLY+IqfBM3fhq+7S49gk25+oYrYwQJLFqqOt1jC1NsLqbhoRNDNO7bs hV0g== X-Gm-Message-State: ANhLgQ2pynbXiBB7OYGNA0rY1PlrV0fqEg3WwMZF+sKgPMEG0X8hSwU5 rzSFkeWB1fo4y8hsBy6I16p5/rREq1qmzA== X-Google-Smtp-Source: ADFU+vs2dErK4xDpNUS1FuEgUI02mz0eThomvm/jO/PHRFcOH1LfezyUFdlWeQsxLoMPJNQN8IqUgw== X-Received: by 2002:a7b:ce94:: with SMTP id q20mr26050931wmj.157.1584353386666; Mon, 16 Mar 2020 03:09:46 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 5/6] virtio-net: reference implementation of hash report Date: Mon, 16 Mar 2020 12:09:32 +0200 Message-Id: <20200316100933.11499-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-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" 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 c92697bfd5..a5b99167b1 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]; uint32_t indirections_len; --=20 2.17.1 From nobody Mon May 6 07:43:44 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=1584356756; cv=none; d=zohomail.com; s=zohoarc; b=OMF0RzYhwV1+PcXiQQ6x3jICBCedLdyqYCC1QgeIs4toWUnoiKBmhfHtMgT5vX/CLq00dXX/rs9Zw+MBMtTuyIvvVRsK+0sf0dCm1Ppalb0XxUaLL97Ni808Z9F4msqQMhSvAbSQ3nLTWQEfqvqSuLHw9IC8G4b+XyKHkBTZoDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584356756; 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=0PD+9CT/Xt0zgE5b0vEiJJ+90ECqaJXhO+EHUt2RRT8=; b=DgIBZzLGeWANq3Tz+9BpfsHx9MBsLrtivrExCMzUPbWXRzWhO1Ahc47PygOvUJv2Z4O516XhwdPf8q/1Iw0CqJLyAhM1oJ+MSbhAuklDNvR90MSEF+RwuCSuVGj6nVnSBEcPKcMkjEK47o9ig+8qp6jTacrSW9D1uwPk1BAgtB0= 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 1584356756792898.6742836385582; Mon, 16 Mar 2020 04:05:56 -0700 (PDT) Received: from localhost ([::1]:37028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDnZD-0000Tt-2k for importer@patchew.org; Mon, 16 Mar 2020 07:05:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38419) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmgx-00064H-Us for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDmgw-0004ld-PM for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:51 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:36344) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDmgw-0004ME-IM for qemu-devel@nongnu.org; Mon, 16 Mar 2020 06:09:50 -0400 Received: by mail-wr1-x444.google.com with SMTP id s5so20437694wrg.3 for ; Mon, 16 Mar 2020 03:09:50 -0700 (PDT) Received: from f2.redhat.com (bzq-79-183-43-120.red.bezeqint.net. [79.183.43.120]) by smtp.gmail.com with ESMTPSA id l7sm22083171wrw.33.2020.03.16.03.09.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Mar 2020 03:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0PD+9CT/Xt0zgE5b0vEiJJ+90ECqaJXhO+EHUt2RRT8=; b=hXenj+NNyw/BK0hLhzXx4lInYXCPHi9x5fN3yg0SZClVTFrOa61AK8iSyg87/ieZWJ 6eLxAjZcNVQAjxhv9Dmc54kuMFjAns30uGTFYX5W2PVIvqf0xqOwIUnaiQ0sq07oQBag EpvwA64wnrK47eYbKXGVlzNighUkonzK7lr3a0L/5Se6bKAIs/VRjle2AD+DPv+H6v2A m/hXGapxisfyeT8S/FPXHJQ8bVX8d3sKaPBiw7T4O/kpJUMinz1jZBdf9eWIAUB4Lyoj Z055Mj3pKalLdzUhrAiRiZjP04p0vr/j/eUvaj9CCakDe1bnGT3uIZuqJxn7ssZmKOQ+ skmQ== 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=0PD+9CT/Xt0zgE5b0vEiJJ+90ECqaJXhO+EHUt2RRT8=; b=YQutqsdOxJYVHcmHePACl4v7SXicmq+fEPzfERtW0auIIHpCv7M6zLeXsEJSL1rPus Lg9fq0KjpKKgtno8LgKLv7V/Pp7uiczNjRbOOSiQG4UPte+yN9XEc1PLyOflO2TYI9MF 00hG+mIqxqmGzcODmxHxxpqw1o10L0JvqFx6GvTziFpSyrp4F64Hf3Y979fKlNfxSg4e kElILjZpQn5l2uM/hua1tCyj4UGytA3T/tq7Iskktqv6VTtZYEx9IJ6p1MVmJZ8NGTJK xkCC2vE7UVP8bC19kuVmkPtRgciNpaLJvh+ZDlGXc489xv3FqXRcZBJQGUTXlP5M4Ac4 Urcw== X-Gm-Message-State: ANhLgQ3hneV1Q3dUSMSRR5aVh1pRD3HJeW+eAmg9DjFNA2Kll/O+9vC9 0vII0PRldDvZbXlMGwCuRtFU1vbBa+L77g== X-Google-Smtp-Source: ADFU+vsJc9u0CKcm6DtRSRUN+Dgj2TMNVLPf3NncsVKC0NGZhRrZquVhNdCZifihON349Os8pyF4CA== X-Received: by 2002:a5d:67ca:: with SMTP id n10mr28633972wrw.268.1584353387743; Mon, 16 Mar 2020 03:09:47 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v4 6/6] virtio-net: add migration support for RSS and hash report Date: Mon, 16 Mar 2020 12:09:33 +0200 Message-Id: <20200316100933.11499-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200316100933.11499-1-yuri.benditovich@daynix.com> References: <20200316100933.11499-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @daynix-com.20150623.gappssmtp.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Save and restore RSS/hash report configuration. Signed-off-by: Yuri Benditovich Reviewed-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a0614ad4e6..f343762a0f 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,24 @@ static const VMStateDescription vmstate_virtio_net_h= as_vnet =3D { }, }; =20 +static const VMStateDescription vmstate_rss =3D { + .name =3D "vmstate_rss", + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(enabled, VirtioNetRssData), + VMSTATE_BOOL(redirect, VirtioNetRssData), + VMSTATE_BOOL(populate_hash, VirtioNetRssData), + VMSTATE_UINT32(hash_types, VirtioNetRssData), + VMSTATE_UINT32(indirections_len, VirtioNetRssData), + VMSTATE_UINT16(default_queue, VirtioNetRssData), + VMSTATE_UINT8_ARRAY(key, VirtioNetRssData, + VIRTIO_NET_RSS_MAX_KEY_SIZE), + VMSTATE_VARRAY_UINT32_ALLOC(indirections_table, VirtioNetRssData, + 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, @@ -3067,6 +3092,7 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { vmstate_virtio_net_tx_waiting), VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, has_ctrl_guest_offloads), + VMSTATE_STRUCT(rss_data, VirtIONet, 1, vmstate_rss, VirtioNetRssDa= ta), VMSTATE_END_OF_LIST() }, }; --=20 2.17.1