From patchwork Wed Mar 11 12:35:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDAC3924 for ; Wed, 11 Mar 2020 12:36:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9479720873 for ; Wed, 11 Mar 2020 12:36:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="joJOcC0L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9479720873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0az-000650-PA for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:36:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45173) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aD-0004T2-Hi for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aC-0002ns-7G for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:33 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:38075) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aC-0002mn-0h for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:32 -0400 Received: by mail-wm1-x341.google.com with SMTP id n2so1929481wmc.3 for ; Wed, 11 Mar 2020 05:35:31 -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=MD48WZYaJiiFtb9BWvJPqIeuYzfyj+64eoP1t2H2QsM=; b=joJOcC0LAv5jCnUop5hEuWrtd8CWLsaD/OeS/nxgdmAGz7UjIRufR2EMBltl3JOiLj SWUv9LrRWmuUeAO2WoldYcFRpOP+kQ2jfK10HXSXtehXLuQYad/dLKvHGIQthrvbjcdN xDTULmDH+6YX/O6ql1K3WHcqzobvxiCPlnewg7KzGRygGWWyle8I2G86NSNSHKYeJ5uV zJGTrC3cJjJoFmqLmOLeV87d2N/JXVvfjCCkNCT5uf29GwB6TCva/4fFqEs/RqDWti5V Y2PL9Yrd08VaYpOIm4/Us018UtcWOPWQouRbjzXY45YGyPma+A1tZHWQ/WnYzRv7DeQz GE/g== 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=MD48WZYaJiiFtb9BWvJPqIeuYzfyj+64eoP1t2H2QsM=; b=f7EIjhPUmDLGFMQjuaRngtqTiJAjD6DbxZZ3jgOwKBQ/t4cmNeqZAHdOMmyxj40TVE doZb5pMRA48UArridINhEK4GyKcWW7cjo+Bz4SBY21KgS+RqhaAV7Lch7LLkIVB2cA4n y69PkDt8QSCpvDxOnJdMTrONw+f/+f26YXY2u2dUg7JwlbQBljqlE/vZTjGts87SNk90 WTu1CKqX1BYNIcb/qFZ/tNLui+HiPVEDxVrAB8XRqH8WNGtdeWlaJBaxGSZ6CY7ZEH3i kxs5flVJiRIiY7XGEO4+mRGCt60ffOOp7dywMMU2U5etfvYaZ2ta7sdLz/2JIvU0V/8G Kfyw== X-Gm-Message-State: ANhLgQ2nezuXHUz24QZTjDZjIMZ6sVKtkgoRlOtk6WnYBh4ELlcw9c8k vkhTYXPxweFPQqJRejBOrugannG1fdxXgg== X-Google-Smtp-Source: ADFU+vudVPemo5RGiBsa8QZWAJGa4nHmVI0LmTEAjJZCP4LVzlUag1p6oPeqy5vK1poMQtVmQQCk4Q== X-Received: by 2002:a05:600c:2c10:: with SMTP id q16mr3713973wmg.69.1583930129350; Wed, 11 Mar 2020 05:35:29 -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 o11sm61480696wrn.6.2020.03.11.05.35.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:28 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 1/6] virtio-net: introduce RSS and hash report features Date: Wed, 11 Mar 2020 14:35:13 +0200 Message-Id: <20200311123518.4025-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 3627bb1717..9545b0e84f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -71,6 +71,101 @@ #define VIRTIO_NET_IP6_ADDR_SIZE 32 /* ipv6 saddr + daddr */ #define VIRTIO_NET_MAX_IP6_PAYLOAD VIRTIO_NET_MAX_TCP_PAYLOAD +/* TODO: remove after virtio-net header update */ +#if !defined(VIRTIO_NET_RSS_HASH_TYPE_IPv4) +#define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ +#define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ + +/* supported/enabled hash types */ +#define VIRTIO_NET_RSS_HASH_TYPE_IPv4 (1 << 0) +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4 (1 << 1) +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4 (1 << 2) +#define VIRTIO_NET_RSS_HASH_TYPE_IPv6 (1 << 3) +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6 (1 << 4) +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6 (1 << 5) +#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX (1 << 6) +#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX (1 << 7) +#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX (1 << 8) + +#define __le16 uint16_t +#define __le32 uint32_t +#define __u8 uint8_t +#define __u16 uint16_t +#define __u32 uint32_t + +struct virtio_net_config_with_rss { + /* The config defining mac address (if VIRTIO_NET_F_MAC) */ + __u8 mac[ETH_ALEN]; + /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ + __u16 status; + /* + * Maximum number of each of transmit and receive queues; + * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. + * Legal values are between 1 and 0x8000 + */ + __u16 max_virtqueue_pairs; + /* Default maximum transmit unit advice */ + __u16 mtu; + /* + * speed, in units of 1Mb. All values 0 to INT_MAX are legal. + * Any other value stands for unknown. + */ + __u32 speed; + /* + * 0x00 - half duplex + * 0x01 - full duplex + * Any other value stands for unknown. + */ + __u8 duplex; + /* maximum size of RSS key */ + __u8 rss_max_key_size; + /* maximum number of indirection table entries */ + __le16 rss_max_indirection_table_length; + /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */ + __le32 supported_hash_types; +} __attribute__((packed)); + +#define virtio_net_config virtio_net_config_with_rss + +struct virtio_net_hdr_v1_hash { + struct virtio_net_hdr_v1 hdr; + __le32 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 + __le16 hash_report; + __le16 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 { + __le32 hash_types; + __le16 indirection_table_mask; + __le16 unclassified_queue; + __le16 indirection_table[1/* + indirection_table_mask */]; + __le16 max_tx_vq; + __u8 hash_key_length; + __u8 hash_key_data[/* hash_key_length */]; +}; + +#define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1 +#define VIRTIO_NET_CTRL_MQ_HASH_CONFIG 2 + +#endif + /* Purge coalesced packets timer interval, This value affects the performance a lot, and should be tuned carefully, '300000'(300us) is the recommended value to pass the WHQL test, '50000' can gain 2x netperf throughput with From patchwork Wed Mar 11 12:35:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E5E917D5 for ; Wed, 11 Mar 2020 12:36:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E84FB20873 for ; Wed, 11 Mar 2020 12:36:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="wbTAMAnZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E84FB20873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0b5-0006A2-73 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:36:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45182) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aE-0004T4-12 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aC-0002np-78 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:33 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aB-0002mb-W4 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:32 -0400 Received: by mail-wr1-x442.google.com with SMTP id m9so2362931wro.12 for ; Wed, 11 Mar 2020 05:35:31 -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=CeJ8yzcUlsEMpe3g5WA0yYMk3APcOPfzJcFhE4rWVYY=; b=wbTAMAnZoVrW3KKQSbnSZoE4CxlnfdaAvt04ilHqDI3/R+HcNj/cjcSMHVYScjbYOb UmL5Ok5CDUAi2wLJSuGgzcZ8SP8k9WrWzxBgSIh1T9gyZUI8HCB/Xd3P4MnF7FjWrfOQ km4tpQmp5y4cPbwLMXD9LOCLHXnhde+bSqCNPu4Zv/+Jh08VpXW4chufUHVVJel5fdIp spyw/g7EqtpDLmA+FQp3HuZVrPMdWnUaXIUJOH0Kq5htinM6X3gkUwVybryMFJZdusMf x1enfUDqvSexr7Zow5uHlZTwL8QDpmEE0WDurR0y/GWKLAY5NcxqtGwtO5Lx+dfAoEWP wsYg== 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=CeJ8yzcUlsEMpe3g5WA0yYMk3APcOPfzJcFhE4rWVYY=; b=hyESYsF3Sx/pGNKhpTOrP7hv/9SlFOtN2wH6KvYBKb7j2EcUDHvcoq8vj4wOq48dpo aw/aHLxe1WKOOmFDB7yX+yDUvTl9WtrWAU8qWgGCFKdTM8rp60ElCnX03rljXOSvYDdN gnchfNpGO60p96qgaEjF9vw6NHfs7OiykgKq7/VAqsyhhCuzuyzJVJTiQBuGglD6vybB Bp2tM/midwGnd97Pf/jeT7r/zYtSNXwfcxOfPeCDB7DpNEaVUD4d8f9ZJ7mvKwNQ6Kxh f43w40NvJHCteagO4MCaVOZL3NI1q8ROdaT5nTS/EVFijWAvsTAEBbWHGcJhKEMwc4XF hMeQ== X-Gm-Message-State: ANhLgQ2nj3IAQivZ4iWNz2n/MRS/egapIwHsLXZe+s+R25Zo30tlYrpZ rhdSJqGs48//U2v8P4lqfOQ7hC83pggS7Q== X-Google-Smtp-Source: ADFU+vtV4V1hCjSUwu3O8WSQk3CfHWhSlicwTPbQHpGWXieuo8/fOami9f/vqeYP3OHVi0vS7PIWKw== X-Received: by 2002:a5d:4582:: with SMTP id p2mr4375939wrq.80.1583930130436; Wed, 11 Mar 2020 05:35:30 -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 o11sm61480696wrn.6.2020.03.11.05.35.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:30 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 2/6] virtio-net: implement RSS configuration command Date: Wed, 11 Mar 2020 14:35:14 +0200 Message-Id: <20200311123518.4025-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 158 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 16 ++++ 3 files changed, 168 insertions(+), 9 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index a1da98a643..a84b9c3d9f 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -371,6 +371,9 @@ virtio_net_announce_notify(void) "" virtio_net_announce_timer(int round) "%d" virtio_net_handle_announce(int round) "%d" virtio_net_post_load_device(void) +virtio_net_rss_disable(void) +virtio_net_rss_error(const char *msg, uint32_t value) "%s, value 0x%08x" +virtio_net_rss_enable(uint32_t p1, uint16_t p2, uint8_t p3) "hashes 0x%x, table of %d, key of %d" # tulip.c tulip_reg_write(uint64_t addr, const char *name, int size, uint64_t val) "addr 0x%02"PRIx64" (%s) size %d value 0x%08"PRIx64 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9545b0e84f..1747b8dca7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -172,6 +172,16 @@ struct virtio_net_rss_config { tso/gso/gro 'off'. */ #define VIRTIO_NET_RSC_DEFAULT_INTERVAL 300000 +#define VIRTIO_NET_RSS_SUPPORTED_HASHES (VIRTIO_NET_RSS_HASH_TYPE_IPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_TCPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_UDPv4 | \ + VIRTIO_NET_RSS_HASH_TYPE_IPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_TCPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_UDPv6 | \ + VIRTIO_NET_RSS_HASH_TYPE_IP_EX | \ + VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | \ + VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) + /* temporary until standard header include it */ #if !defined(VIRTIO_NET_HDR_F_RSC_INFO) @@ -203,6 +213,8 @@ static VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, .end = endof(struct virtio_net_config, duplex)}, + {.flags = 1ULL << VIRTIO_NET_F_RSS, + .end = endof(struct virtio_net_config, supported_hash_types)}, {} }; @@ -233,6 +245,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 = n->net_conf.duplex; + netcfg.rss_max_key_size = VIRTIO_NET_RSS_MAX_KEY_SIZE; + virtio_stw_p(vdev, &netcfg.rss_max_indirection_table_length, + VIRTIO_NET_RSS_MAX_TABLE_LEN); + virtio_stl_p(vdev, &netcfg.supported_hash_types, + VIRTIO_NET_RSS_SUPPORTED_HASHES); memcpy(config, &netcfg, n->config_size); } @@ -796,6 +813,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, return features; } + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); features = vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features = features; @@ -955,6 +973,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) } virtio_net_set_multiqueue(n, + virtio_has_feature(features, VIRTIO_NET_F_RSS) || virtio_has_feature(features, VIRTIO_NET_F_MQ)); virtio_net_set_mrg_rx_bufs(n, @@ -1231,25 +1250,144 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } +static void virtio_net_disable_rss(VirtIONet *n) +{ + if (n->rss_data.enabled) { + trace_virtio_net_rss_disable(); + } + n->rss_data.enabled = false; +} + +static uint16_t virtio_net_handle_rss(VirtIONet *n, + struct iovec *iov, unsigned int iov_cnt) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + struct virtio_net_rss_config cfg; + size_t s, offset = 0, size_get; + uint16_t queues, i; + struct { + uint16_t us; + uint8_t b; + } QEMU_PACKED temp; + const char *err_msg = ""; + uint32_t err_value = 0; + + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + err_msg = "RSS is not negotiated"; + goto error; + } + size_get = offsetof(struct virtio_net_rss_config, indirection_table); + s = iov_to_buf(iov, iov_cnt, offset, &cfg, size_get); + if (s != size_get) { + err_msg = "Short command buffer"; + err_value = (uint32_t)s; + goto error; + } + n->rss_data.hash_types = virtio_ldl_p(vdev, &cfg.hash_types); + n->rss_data.indirections_len = + virtio_lduw_p(vdev, &cfg.indirection_table_mask); + n->rss_data.indirections_len++; + if (!is_power_of_2(n->rss_data.indirections_len)) { + err_msg = "Invalid size of indirection table"; + err_value = n->rss_data.indirections_len; + goto error; + } + if (n->rss_data.indirections_len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { + err_msg = "Too large indirection table"; + err_value = n->rss_data.indirections_len; + goto error; + } + n->rss_data.default_queue = + virtio_lduw_p(vdev, &cfg.unclassified_queue); + if (n->rss_data.default_queue >= n->max_queues) { + err_msg = "Invalid default queue"; + err_value = n->rss_data.default_queue; + goto error; + } + offset += size_get; + size_get = sizeof(uint16_t) * n->rss_data.indirections_len; + s = iov_to_buf(iov, iov_cnt, offset, n->rss_data.indirections, size_get); + if (s != size_get) { + err_msg = "Short indirection table buffer"; + err_value = (uint32_t)s; + goto error; + } + for (i = 0; i < n->rss_data.indirections_len; ++i) { + uint16_t val = n->rss_data.indirections[i]; + n->rss_data.indirections[i] = virtio_lduw_p(vdev, &val); + } + offset += size_get; + size_get = sizeof(temp); + s = iov_to_buf(iov, iov_cnt, offset, &temp, size_get); + if (s != size_get) { + err_msg = "Can't get queues"; + err_value = (uint32_t)s; + goto error; + } + queues = virtio_lduw_p(vdev, &temp.us); + if (queues == 0 || queues > n->max_queues) { + err_msg = "Invalid number of queues"; + err_value = queues; + goto error; + } + if (temp.b > VIRTIO_NET_RSS_MAX_KEY_SIZE) { + err_msg = "Invalid key size"; + err_value = temp.b; + goto error; + } + if (!temp.b && n->rss_data.hash_types) { + err_msg = "No key provided"; + err_value = 0; + goto error; + } + if (!temp.b && !n->rss_data.hash_types) { + virtio_net_disable_rss(n); + return queues; + } + offset += size_get; + size_get = temp.b; + s = iov_to_buf(iov, iov_cnt, offset, n->rss_data.key, size_get); + if (s != size_get) { + err_msg = "Can get key buffer"; + err_value = (uint32_t)s; + goto error; + } + n->rss_data.enabled = true; + trace_virtio_net_rss_enable(n->rss_data.hash_types, + n->rss_data.indirections_len, + temp.b); + return queues; +error: + trace_virtio_net_rss_error(err_msg, err_value); + virtio_net_disable_rss(n); + return 0; +} + static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, struct iovec *iov, unsigned int iov_cnt) { VirtIODevice *vdev = VIRTIO_DEVICE(n); - struct virtio_net_ctrl_mq mq; - size_t s; uint16_t queues; - s = iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); - if (s != sizeof(mq)) { - return VIRTIO_NET_ERR; - } + virtio_net_disable_rss(n); + if (cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { + queues = virtio_net_handle_rss(n, iov, iov_cnt); + } else if (cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + struct virtio_net_ctrl_mq mq; + size_t s; + if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_MQ)) { + return VIRTIO_NET_ERR; + } + s = iov_to_buf(iov, iov_cnt, 0, &mq, sizeof(mq)); + if (s != sizeof(mq)) { + return VIRTIO_NET_ERR; + } + queues = virtio_lduw_p(vdev, &mq.virtqueue_pairs); - if (cmd != VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { + } else { return VIRTIO_NET_ERR; } - queues = virtio_lduw_p(vdev, &mq.virtqueue_pairs); - if (queues < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN || queues > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX || queues > n->max_queues || @@ -3304,6 +3442,8 @@ static Property virtio_net_properties[] = { DEFINE_PROP_BIT64("ctrl_guest_offloads", VirtIONet, host_features, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false), + DEFINE_PROP_BIT64("rss", VirtIONet, host_features, + VIRTIO_NET_F_RSS, false), DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 96c68d4a92..ebd81e29eb 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -126,6 +126,18 @@ typedef struct VirtioNetRscChain { /* Maximum packet size we can receive from tap device: header + 64k */ #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB)) +#define VIRTIO_NET_RSS_MAX_KEY_SIZE 40 +#define VIRTIO_NET_RSS_MAX_TABLE_LEN 128 + +typedef struct VirtioNetRssData { + bool enabled; + uint32_t hash_types; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; + uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; + uint16_t indirections_len; + uint16_t default_queue; +} VirtioNetRssData; + typedef struct VirtIONetQueue { VirtQueue *rx_vq; VirtQueue *tx_vq; @@ -199,6 +211,10 @@ struct VirtIONet { bool failover; DeviceListener primary_listener; Notifier migration_state; + union { + VirtioNetRssData rss_data; + uint8_t rss_data_migration[sizeof(VirtioNetRssData)]; + }; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, From patchwork Wed Mar 11 12:35:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A17C6924 for ; Wed, 11 Mar 2020 12:38:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7897C208E4 for ; Wed, 11 Mar 2020 12:38:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="qHWMv3w/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7897C208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0ct-00016d-JV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:38:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45189) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aE-0004T5-EI for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aD-0002q0-2Z for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:34 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40048) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aC-0002o4-Rz for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:33 -0400 Received: by mail-wr1-x443.google.com with SMTP id p2so2391376wrw.7 for ; Wed, 11 Mar 2020 05:35:32 -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=zArtgZUYsJa+PnubPQn1wsJ3yIzET/oT3p8qfcQh/w4=; b=qHWMv3w/NCuc2N5snbqHo2yLzgBfJwgPAkn5FxTn53Zf8927/i+Is4OVkJ0RWCp4E9 y13ZeNHy5ZKj20pAaZO6ZX4yWc60zDWsLjJS0U59Z2DF+f0NXTJrKG2RIouPrW0+Zn1k urNf+yYw5jSd2o9g4nfKarPM9JEDN0f650YH0D8BzPBH/hxblnpw4yvVKe+qyNtou9WD 8+C8Yj3YUcgVOhZyq/XrTX7lxrp7jd4jqwPLQgk+sK5xZu2pmspokxQGVGpu3GVYIgiK rnka/c1+k6F1ZDnWYJA/WoP61XLnKiBUbSSGr04qUDctxoBr1W2BPJ3K10EJTKopejtZ 5nNg== 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=zArtgZUYsJa+PnubPQn1wsJ3yIzET/oT3p8qfcQh/w4=; b=ejyMn/10es3fg9GvDbNnZBhGS0vGhd3Oj1WtrLWA0Wu9w5eGpK63UEjXHcGT/gO2W6 3K/U6G5/9N1CBMmCI7+w93Hq0RtzSygZAo/oS2GKVL1x1+otgJ2LiorVKO3ASRxHV3lS qPtrraGefXlzNl81SQ0xSKzvsrlktoi3TfT/qbGrHSHwSZGeUKcZmkZJQMPdVsgDfUMm a5s3Oo9fCE+SPeO/0f1QibV6GB/LIBmJ5hwdpcGQ4Zc0rSiyoRWRp17vgOT+Ut8UHIiA 0MxO6YTztycd6NTGfliWzIi9Mk9Ch3V3qdTO+TYqBZemfvCqu9yl5Oa6zEHyTjJAmBQa r8tw== X-Gm-Message-State: ANhLgQ1c2aUzyqx1QI8rWbkDi7DadBTPPdukwmCkfnS2ldKxU+i4ksD+ LayKeFZ0kS2Gq+8gyVKpNAWedERgcuRJYA== X-Google-Smtp-Source: ADFU+vuMP9l5tPVqgaTgmUpLNj1nnjvYdjW2+5dgp8INuMCqlMAxf4PxLo3tKkenWltr397OzZ6ZZQ== X-Received: by 2002:a05:6000:12d2:: with SMTP id l18mr4175837wrx.240.1583930131534; Wed, 11 Mar 2020 05:35:31 -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 o11sm61480696wrn.6.2020.03.11.05.35.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:31 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 3/6] virtio-net: implement RX RSS processing Date: Wed, 11 Mar 2020 14:35:15 +0200 Message-Id: <20200311123518.4025-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 1747b8dca7..b9654cce91 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -42,6 +42,7 @@ #include "trace.h" #include "monitor/qdev.h" #include "hw/pci/pci.h" +#include "net_rx_pkt.h" #define VIRTIO_NET_VM_VERSION 11 @@ -1620,8 +1621,80 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) return 0; } +static uint8_t virtio_net_get_hash_type(bool isip4, + bool isip6, + bool isudp, + bool istcp, + uint32_t types) +{ + if (isip4) { + if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) { + return NetPktRssIpV4Tcp; + } + if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) { + return NetPktRssIpV4Udp; + } + if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { + return NetPktRssIpV4; + } + } else if (isip6) { + uint32_t mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | + VIRTIO_NET_RSS_HASH_TYPE_TCPv6; + + if (istcp && (types & mask)) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ? + NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp; + } + mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6; + if (isudp && (types & mask)) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ? + NetPktRssIpV6UdpEx : NetPktRssIpV6Udp; + } + mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6; + if (types & mask) { + return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ? + NetPktRssIpV6Ex : NetPktRssIpV6; + } + } + return 0xff; +} + +static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, + size_t size) +{ + VirtIONet *n = qemu_get_nic_opaque(nc); + unsigned int index = nc->queue_index, new_index; + struct NetRxPkt *pkt = n->rx_pkt; + uint8_t net_hash_type; + uint32_t hash; + bool isip4, isip6, isudp, istcp; + + net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, + size - n->host_hdr_len); + net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp); + if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) { + istcp = isudp = false; + } + if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) { + istcp = isudp = false; + } + net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp, + n->rss_data.hash_types); + if (net_hash_type > NetPktRssIpV6UdpEx) { + return n->rss_data.default_queue; + } + + hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); + new_index = hash & (n->rss_data.indirections_len - 1); + new_index = n->rss_data.indirections[new_index]; + if (index == new_index) { + return -1; + } + return new_index; +} + static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, - size_t size) + size_t size, bool no_rss) { VirtIONet *n = qemu_get_nic_opaque(nc); VirtIONetQueue *q = virtio_net_get_subqueue(nc); @@ -1635,6 +1708,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, return -1; } + if (!no_rss && n->rss_data.enabled) { + int index = virtio_net_process_rss(nc, buf, size); + if (index >= 0) { + NetClientState *nc2 = qemu_get_subqueue(n->nic, index); + return virtio_net_receive_rcu(nc2, buf, size, true); + } + } + /* hdr_len refers to the header we supply to the guest */ if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) { return 0; @@ -1729,7 +1810,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf, { RCU_READ_LOCK_GUARD(); - return virtio_net_receive_rcu(nc, buf, size); + return virtio_net_receive_rcu(nc, buf, size, false); } static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain, @@ -3305,6 +3386,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) QTAILQ_INIT(&n->rsc_chains); n->qdev = dev; + + net_rx_pkt_init(&n->rx_pkt, false); } static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) @@ -3341,6 +3424,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->rx_pkt); virtio_cleanup(vdev); } diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index ebd81e29eb..0fd960b1a0 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -215,6 +215,7 @@ struct VirtIONet { VirtioNetRssData rss_data; uint8_t rss_data_migration[sizeof(VirtioNetRssData)]; }; + struct NetRxPkt *rx_pkt; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, From patchwork Wed Mar 11 12:35:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14BB6924 for ; Wed, 11 Mar 2020 12:38:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CEAAC208E4 for ; Wed, 11 Mar 2020 12:38:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="pgXSAguh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEAAC208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0cs-000134-1u for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:38:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45222) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aG-0004VG-Ic for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aE-0002v3-G3 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:36 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:52761) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aE-0002r7-88 for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:34 -0400 Received: by mail-wm1-x343.google.com with SMTP id 11so1903826wmo.2 for ; Wed, 11 Mar 2020 05:35:34 -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=rJL1RNdlPcn1wmG8Cpvg0Q4rTgcAIE328OuO5WJ/WoA=; b=pgXSAguhzuBHpYDVJmmCE0f9L4RwfUNpMf2UmK2ZcRR8DiTbeYX30LyVZhmoi7iQGv cEwiHv3U3zAR6vEzOc+/1wh/jk9hdptuBZATotuDr7L/04wMDn2bvWMN/XtbLWGC0GoL X7jpUEYZAsGzmjEbjNOTcXKzJlgarAwRmHNjRXSIqmKKaaaNdDQ8ixAE+iLvj/mYOqg2 LE0nKNRhg4wZ+HvgKuQ0jYSxbJA+DMjlowBQNZPTtvuTtFZPKXd8FOREu3SHGcOemHGw kBf40uTWZ8KSbD131G7Abe+QtFoPhSngE/vnGjeeqcCbt2jF8NWfuNHfllPH4zf5qe20 g8Ug== 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=rJL1RNdlPcn1wmG8Cpvg0Q4rTgcAIE328OuO5WJ/WoA=; b=PFvBV853JjzNENBrmEn86afimpfGKpeZc0lI0CPI2mylQ3iB52GwAQt/t24wy3W7Hj V8f4ps+pztOk7Fg8WOfllFEPE979zhIKbykz2Y/mqiUc/HhNdIFFppZ31hcBvTbPzfIQ 7+LT0hN8dwtIoAV4wOVuTKECJFznxXPirUu0m4HDsVdvwgVDhf6VjL8x7ydxeFdGRvmv yYARsIuiy6cHe6GRAM+RYM/21UC/9ePcigT7guQaV4kl8SJgZVMS0g6FD8hUk5PCN6KY xobGY1eTeST6gsjF2yZq+TxFbDbwtb1X/MVSQi9+YJxZKWX6QAYeBimcOh6s0/3fZY07 xfcA== X-Gm-Message-State: ANhLgQ3bWuJHVeam1jxr+gCiKPCyBP5l1bhXLzRE4mTpLmk71+8RHA5x 357KE4NhtJY9GUwv/wfa2KFFfMjx0/gkmA== X-Google-Smtp-Source: ADFU+vuPR3swT6Yy7oJ1tKr3ws9QYaB7D1R+/cFSYqN93m66rXTK8oLDoLe8c4VRBkt1ahxD2rSGaw== X-Received: by 2002:a1c:ed17:: with SMTP id l23mr3450477wmh.163.1583930132699; Wed, 11 Mar 2020 05:35:32 -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 o11sm61480696wrn.6.2020.03.11.05.35.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:32 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 4/6] virtio-net: reference implementation of hash report Date: Wed, 11 Mar 2020 14:35:16 +0200 Message-Id: <20200311123518.4025-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Suggest VIRTIO_NET_F_HASH_REPORT if specified in device parameters. If the VIRTIO_NET_F_HASH_REPORT is set, the device extends configuration space. If the feature is negotiated, the packet layout is extended to accomodate the hash information. In this case deliver packet's hash value and report type in virtio header extension. Use for configuration the same procedure as already used for RSS. We add two fields in rss_data that controls what the device does with the calculated hash if rss_data.enabled is set. If field 'populate' is set the hash is set in the packet, if field 'redirect' is set the hash is used to decide the queue to place the packet to. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 98 ++++++++++++++++++++++++++++------ include/hw/virtio/virtio-net.h | 2 + 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b9654cce91..7b6a929e8c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -214,7 +214,7 @@ static VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_net_config, mtu)}, {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, .end = endof(struct virtio_net_config, duplex)}, - {.flags = 1ULL << VIRTIO_NET_F_RSS, + {.flags = (1ULL << VIRTIO_NET_F_RSS) | (1ULL << VIRTIO_NET_F_HASH_REPORT), .end = endof(struct virtio_net_config, supported_hash_types)}, {} }; @@ -248,7 +248,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) netcfg.duplex = n->net_conf.duplex; netcfg.rss_max_key_size = VIRTIO_NET_RSS_MAX_KEY_SIZE; virtio_stw_p(vdev, &netcfg.rss_max_indirection_table_length, - VIRTIO_NET_RSS_MAX_TABLE_LEN); + virtio_host_has_feature(vdev, VIRTIO_NET_F_RSS) ? + VIRTIO_NET_RSS_MAX_TABLE_LEN : 1); virtio_stl_p(vdev, &netcfg.supported_hash_types, VIRTIO_NET_RSS_SUPPORTED_HASHES); memcpy(config, &netcfg, n->config_size); @@ -674,7 +675,7 @@ static int peer_has_ufo(VirtIONet *n) } static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, - int version_1) + int version_1, int hash_report) { int i; NetClientState *nc; @@ -682,7 +683,10 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, n->mergeable_rx_bufs = mergeable_rx_bufs; if (version_1) { - n->guest_hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->guest_hdr_len = hash_report ? + sizeof(struct virtio_net_hdr_v1_hash) : + sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->rss_data.populate_hash = true; } else { n->guest_hdr_len = n->mergeable_rx_bufs ? sizeof(struct virtio_net_hdr_mrg_rxbuf) : @@ -803,6 +807,8 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4); virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6); virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN); + + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); } if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { @@ -815,6 +821,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, } virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); features = vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features = features; @@ -981,12 +988,15 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) virtio_has_feature(features, VIRTIO_NET_F_MRG_RXBUF), virtio_has_feature(features, - VIRTIO_F_VERSION_1)); + VIRTIO_F_VERSION_1), + virtio_has_feature(features, + VIRTIO_NET_F_HASH_REPORT)); n->rsc4_enabled = virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT) && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO4); n->rsc6_enabled = virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT) && virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO6); + n->rss_data.redirect = virtio_has_feature(features, VIRTIO_NET_F_RSS); if (n->has_vnet_hdr) { n->curr_guest_offloads = @@ -1260,7 +1270,9 @@ static void virtio_net_disable_rss(VirtIONet *n) } static uint16_t virtio_net_handle_rss(VirtIONet *n, - struct iovec *iov, unsigned int iov_cnt) + struct iovec *iov, + unsigned int iov_cnt, + bool do_rss) { VirtIODevice *vdev = VIRTIO_DEVICE(n); struct virtio_net_rss_config cfg; @@ -1273,10 +1285,14 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, const char *err_msg = ""; uint32_t err_value = 0; - if (!virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { + if (do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_RSS)) { err_msg = "RSS is not negotiated"; goto error; } + if (!do_rss && !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) { + err_msg = "Hash report is not negotiated"; + goto error; + } size_get = offsetof(struct virtio_net_rss_config, indirection_table); s = iov_to_buf(iov, iov_cnt, offset, &cfg, size_get); if (s != size_get) { @@ -1288,6 +1304,9 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, n->rss_data.indirections_len = virtio_lduw_p(vdev, &cfg.indirection_table_mask); n->rss_data.indirections_len++; + if (!do_rss) { + n->rss_data.indirections_len = 1; + } if (!is_power_of_2(n->rss_data.indirections_len)) { err_msg = "Invalid size of indirection table"; err_value = n->rss_data.indirections_len; @@ -1298,8 +1317,8 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = n->rss_data.indirections_len; goto error; } - n->rss_data.default_queue = - virtio_lduw_p(vdev, &cfg.unclassified_queue); + n->rss_data.default_queue = do_rss ? + virtio_lduw_p(vdev, &cfg.unclassified_queue) : 0; if (n->rss_data.default_queue >= n->max_queues) { err_msg = "Invalid default queue"; err_value = n->rss_data.default_queue; @@ -1315,7 +1334,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, } for (i = 0; i < n->rss_data.indirections_len; ++i) { uint16_t val = n->rss_data.indirections[i]; - n->rss_data.indirections[i] = virtio_lduw_p(vdev, &val); + n->rss_data.indirections[i] = do_rss ? virtio_lduw_p(vdev, &val) : 0; } offset += size_get; size_get = sizeof(temp); @@ -1325,7 +1344,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = (uint32_t)s; goto error; } - queues = virtio_lduw_p(vdev, &temp.us); + queues = do_rss ? virtio_lduw_p(vdev, &temp.us) : n->curr_queues; if (queues == 0 || queues > n->max_queues) { err_msg = "Invalid number of queues"; err_value = queues; @@ -1371,8 +1390,12 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd, uint16_t queues; virtio_net_disable_rss(n); + if (cmd == VIRTIO_NET_CTRL_MQ_HASH_CONFIG) { + queues = virtio_net_handle_rss(n, iov, iov_cnt, false); + return queues ? VIRTIO_NET_OK : VIRTIO_NET_ERR; + } if (cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) { - queues = virtio_net_handle_rss(n, iov, iov_cnt); + queues = virtio_net_handle_rss(n, iov, iov_cnt, true); } else if (cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { struct virtio_net_ctrl_mq mq; size_t s; @@ -1659,6 +1682,14 @@ static uint8_t virtio_net_get_hash_type(bool isip4, return 0xff; } +static void virtio_set_packet_hash(const uint8_t *buf, uint8_t report, + uint32_t hash) +{ + struct virtio_net_hdr_v1_hash *hdr = (void *)buf; + hdr->hash_value = hash; + hdr->hash_report = report; +} + static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, size_t size) { @@ -1668,6 +1699,17 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, uint8_t net_hash_type; uint32_t hash; bool isip4, isip6, isudp, istcp; + static const uint8_t reports[NetPktRssIpV6UdpEx + 1] = { + VIRTIO_NET_HASH_REPORT_IPv4, + VIRTIO_NET_HASH_REPORT_TCPv4, + VIRTIO_NET_HASH_REPORT_TCPv6, + VIRTIO_NET_HASH_REPORT_IPv6, + VIRTIO_NET_HASH_REPORT_IPv6_EX, + VIRTIO_NET_HASH_REPORT_TCPv6_EX, + VIRTIO_NET_HASH_REPORT_UDPv4, + VIRTIO_NET_HASH_REPORT_UDPv6, + VIRTIO_NET_HASH_REPORT_UDPv6_EX + }; net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len, size - n->host_hdr_len); @@ -1681,12 +1723,25 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf, net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp, n->rss_data.hash_types); if (net_hash_type > NetPktRssIpV6UdpEx) { - return n->rss_data.default_queue; + if (n->rss_data.populate_hash) { + virtio_set_packet_hash(buf, VIRTIO_NET_HASH_REPORT_NONE, 0); + } + return n->rss_data.redirect ? n->rss_data.default_queue : -1; } hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key); - new_index = hash & (n->rss_data.indirections_len - 1); - new_index = n->rss_data.indirections[new_index]; + + if (n->rss_data.populate_hash) { + virtio_set_packet_hash(buf, reports[net_hash_type], hash); + } + + if (n->rss_data.redirect) { + new_index = hash & (n->rss_data.indirections_len - 1); + new_index = n->rss_data.indirections[new_index]; + } else { + new_index = index; + } + if (index == new_index) { return -1; } @@ -1766,6 +1821,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, } receive_header(n, sg, elem->in_num, buf, size); + if (n->rss_data.populate_hash) { + offset = sizeof(mhdr); + iov_from_buf(sg, elem->in_num, offset, + buf + offset, n->host_hdr_len - sizeof(mhdr)); + } offset = n->host_hdr_len; total += n->guest_hdr_len; guest_offset = n->guest_hdr_len; @@ -2758,7 +2818,9 @@ static int virtio_net_post_load_device(void *opaque, int version_id) trace_virtio_net_post_load_device(); virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, - VIRTIO_F_VERSION_1)); + VIRTIO_F_VERSION_1), + virtio_vdev_has_feature(vdev, + VIRTIO_NET_F_HASH_REPORT)); /* MAC_TABLE_ENTRIES may be different from the saved image */ if (n->mac_table.in_use > MAC_TABLE_ENTRIES) { @@ -3374,7 +3436,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->vqs[0].tx_waiting = 0; n->tx_burst = n->net_conf.txburst; - virtio_net_set_mrg_rx_bufs(n, 0, 0); + virtio_net_set_mrg_rx_bufs(n, 0, 0, 0); n->promisc = 1; /* for compatibility */ n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); @@ -3528,6 +3590,8 @@ static Property virtio_net_properties[] = { DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false), DEFINE_PROP_BIT64("rss", VirtIONet, host_features, VIRTIO_NET_F_RSS, false), + DEFINE_PROP_BIT64("hash", VirtIONet, host_features, + VIRTIO_NET_F_HASH_REPORT, false), DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 0fd960b1a0..b66f478dfb 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -131,6 +131,8 @@ typedef struct VirtioNetRscChain { typedef struct VirtioNetRssData { bool enabled; + bool redirect; + bool populate_hash; uint32_t hash_types; uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN]; From patchwork Wed Mar 11 12:35:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 185FF17D5 for ; Wed, 11 Mar 2020 12:36:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2B1220873 for ; Wed, 11 Mar 2020 12:36:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="D47Obv3h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2B1220873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0b5-00068o-0r for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:36:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45215) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aG-0004Ux-7P for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aF-00030K-7j for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:36 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aF-0002uz-0a for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:35 -0400 Received: by mail-wr1-x442.google.com with SMTP id v9so2376426wrf.10 for ; Wed, 11 Mar 2020 05:35:34 -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=RyiOiALmhWsHVTIBl5Km4kIgRAnoyapoCqy8nj7ptkc=; b=D47Obv3h8rRmWFVldTsXG95HpX6R4rRykcZGxKQf99wmVrz45YcqSnLzB4Bj5ZaPGE 9lYYs1F+6dT+svD+svyy6a1az1C4E7BfZt5hnAATDGifW47FTruzI9CSDQl4D4qbSk71 gEJjGyD4CZmhzsaivDY6Y9VTFLRp5ZVg4xzhJ035ajvE7pBUmRhbvisJ0pUQ2JZp08H3 6VP2vKcO5yjrbyHKsqXABjaU8SlcsdO4kzc+vI2x4fnhqunq2AywBK5obLyOQRBhT1WV eqxatr3BljvV0Uhc3u68azsgTJWFaLqIpfWXY+3o+fN28ovM/YwEAIrhzeMEjgju5L6c xdRg== 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=RyiOiALmhWsHVTIBl5Km4kIgRAnoyapoCqy8nj7ptkc=; b=RWQyzliFNcusLmMi0kyZfWvt1LTT/otZ2OaYfzxDwohbaBH+wFK2eRhNJ1qk8bzcsm RoYsJOqz0Ul4Lo5of32wtoRsMR2xgWZP7Ob3QthtBS0+hMDEPBN165UUmCFVNkTbNPGr f8XLb+ntxg4F3ICR2TUG0EYfs5QH6Vdq8jOJe3QP48gmQgsB1ansIA1O4CB5wZKqBCZL yEO6iZromoryt06H1Fa5RvZTr42cMHgEGjKepNjTjROfjsvr/Q4Limc12Fm6FrWWJe8N TnLyucbMX2oWAXNlVP6fhahpdk7sCFPoTkNbGriLA4uaOL6p49z58cN35CUZgQsr8KIZ JrtA== X-Gm-Message-State: ANhLgQ0icRYdTaLOFWaz0of3vb8F8myZY7sOk6bgeEb2mqM+ayRab10O KZ0mOlOJObBwVHuSDaa58ixBmGX1duQDwQ== X-Google-Smtp-Source: ADFU+vv4+ILwiY6BdOSSg6pKdHprsLF3+LTCpLq6Hc8VC2xzpjyMlOa6U3sGzO6jPk2W123nobiLGA== X-Received: by 2002:a5d:5488:: with SMTP id h8mr4155130wrv.387.1583930133944; Wed, 11 Mar 2020 05:35:33 -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 o11sm61480696wrn.6.2020.03.11.05.35.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:33 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 5/6] virtio-net: add migration support for RSS and hast report Date: Wed, 11 Mar 2020 14:35:17 +0200 Message-Id: <20200311123518.4025-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Save and restore RSS/hash report configuration. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7b6a929e8c..c8d97d45cd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2869,6 +2869,13 @@ static int virtio_net_post_load_device(void *opaque, int version_id) } } + if (n->rss_data.enabled) { + trace_virtio_net_rss_enable(n->rss_data.hash_types, + n->rss_data.indirections_len, + sizeof(n->rss_data.key)); + } else { + trace_virtio_net_rss_disable(); + } return 0; } @@ -3094,6 +3101,8 @@ static const VMStateDescription vmstate_virtio_net_device = { vmstate_virtio_net_tx_waiting), VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet, has_ctrl_guest_offloads), + VMSTATE_UINT8_ARRAY(rss_data_migration, VirtIONet, + sizeof(VirtioNetRssData)), VMSTATE_END_OF_LIST() }, }; From patchwork Wed Mar 11 12:35:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 11431577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DC9A1874 for ; Wed, 11 Mar 2020 12:38:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04BC7208E4 for ; Wed, 11 Mar 2020 12:38:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=daynix-com.20150623.gappssmtp.com header.i=@daynix-com.20150623.gappssmtp.com header.b="WAFQ7Dtu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04BC7208E4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0cu-00017E-6O for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Mar 2020 08:38:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45235) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jC0aH-0004X7-LV for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jC0aG-00036R-JK for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:37 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:52760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jC0aG-00034G-DO for qemu-devel@nongnu.org; Wed, 11 Mar 2020 08:35:36 -0400 Received: by mail-wm1-x341.google.com with SMTP id 11so1903959wmo.2 for ; Wed, 11 Mar 2020 05:35:36 -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=WAFQ7DtuG/qez7AE0Fv/S0S1knqoJH5Ekmjkul7RbNswktSaNxg2a09vIesnQ12HEC f8wTPzgXX6elXvXX9va2WJ9ml2eYpAiiLZ/IMoyYldSVCIMnnLr69X6OvH/5Qm/tJYMh lcpWclJgRMRR0d3H/R127BkHtcEn0ded6zi+MiXIKaCUmhi6gYLBu9MlUCSMWp6ufKOS bv6Mm9F3GqDtNNjztBW64xOK1TlYVUhlEgVYcNAJBD2OZGh5ngH6qvYtFOTxtl8uZFB7 QowttBDEQevQYjGWFHsrph9WZjEz4AjrtDqw/VK5zO2zu4HQEWrqy7KVl4B1tbF6Fg18 oJwg== 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=fnSgL0rtbGE9GTC0p5er3LQt6qHxvhArZiz0DrVGfCSPQOUJKxIyw/poUKUJbb/D14 FyM8U/ZP/nS9Mu6flwu4RUsNwResiaPZLpOBcIWH2t5WpN/X1iiwJG0oepE46gs6yhgo 2t1BVlcdQWXBft2gMXP3v2WpoKXu0AVDQojw1IXQq4+kWa5/ikiXezbkpXr1+FO6Jwfu loyb6oGzHw0KhI/r9ZKKOXUHZ7MXkRNN4m8+aM7WG7EgOKDIYkUzFierNrU3ZlUHbF36 jiHz4StX5ChFiFLFb+RefTwmTaJzeXHV+l14eXPOFxeNzeTvsP74vvw1SlU9arqVux0S wwIQ== X-Gm-Message-State: ANhLgQ03z9MYxciE869V33xmTI/Z8I5SxtrXtvj9YRG6zvUCuffzwYB5 uU7qYYje8C9nc6kbs4m0LutED53LWp4FYA== X-Google-Smtp-Source: ADFU+vteUVcnFxFFap7IB/b/mUOcsgw2fMnfhtg3G0KDq3qwXrsJ4e22e58RiKOGw8C6QyFZF4qoDw== X-Received: by 2002:a05:600c:4107:: with SMTP id j7mr3653442wmi.169.1583930135314; Wed, 11 Mar 2020 05:35:35 -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 o11sm61480696wrn.6.2020.03.11.05.35.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 05:35:34 -0700 (PDT) From: Yuri Benditovich To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH v3 6/6] tap: allow extended virtio header with hash info Date: Wed, 11 Mar 2020 14:35:18 +0200 Message-Id: <20200311123518.4025-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311123518.4025-1-yuri.benditovich@daynix.com> References: <20200311123518.4025-1-yuri.benditovich@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yan@daynix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Yuri Benditovich --- net/tap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/tap.c b/net/tap.c index 6207f61f84..47de7fdeb6 100644 --- a/net/tap.c +++ b/net/tap.c @@ -63,6 +63,14 @@ typedef struct TAPState { Notifier exit; } TAPState; +/* TODO: remove when virtio_net.h updated */ +struct virtio_net_hdr_v1_hash { + struct virtio_net_hdr_v1 hdr; + uint32_t hash_value; + uint16_t hash_report; + uint16_t padding; +}; + static void launch_script(const char *setup_script, const char *ifname, int fd, Error **errp); @@ -254,7 +262,8 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) assert(nc->info->type == NET_CLIENT_DRIVER_TAP); assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) || - len == sizeof(struct virtio_net_hdr)); + len == sizeof(struct virtio_net_hdr) || + len == sizeof(struct virtio_net_hdr_v1_hash)); tap_fd_set_vnet_hdr_len(s->fd, len); s->host_vnet_hdr_len = len;