From patchwork Wed Oct 25 01:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 13435381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3AFACC25B6E for ; Wed, 25 Oct 2023 01:03:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvSIC-0005AL-Td; Tue, 24 Oct 2023 21:02:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvSIA-0005A9-Vo for qemu-devel@nongnu.org; Tue, 24 Oct 2023 21:02:38 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvSI9-0007XJ-2W for qemu-devel@nongnu.org; Tue, 24 Oct 2023 21:02:38 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-68fb85afef4so4387878b3a.1 for ; Tue, 24 Oct 2023 18:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698195756; x=1698800556; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WRR6oQ/x6XwW2GrevfWEufzkvx9Ekrh4jY/lT89RnKI=; b=Fy9wsTHouX3gA1MiW4vYFkQOjogB5xrbn4T+Kqwz6zK7HdKs/QXm9f2VoOixmUGiaq fgYhNhwN/3wGChgvNsEbCz8j8vSwMVgHzVMIell0kotLmM7yiYyFDSHrd6DtxC3RuBkr FqaVfvO3u73AXQOPuBccVjGW+TeN/A87gFtLZ4+uqO/KN+L081AIN7K2xEJsL9EzvlDo iBXc7Wt32WoQ0TNEwapaL5WRNYWUcLMBRsLiQBhS34fOPDKZojVml9GTJjUTZYfl/lpw hzOFkqL2Yj/6Jov3ax1iysbs1IrW7jc0Yp/KOUp+PWs7IAhx+3uZgneV+mrDFZFlJ7C/ llaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698195756; x=1698800556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WRR6oQ/x6XwW2GrevfWEufzkvx9Ekrh4jY/lT89RnKI=; b=WpxzLxTVmV3XtfU2X0Ug4unRqtSx2SUnHL0cNTvZY3NZNoZM7lUqBJ0P/15IWDGH2z 9mP88VpYHktktFb/RQLpt2RuV+6zFYTAXcEWLyIXJAff+5IOJ5jt06+gkrNlCKg2YXVo A02GdoL1nv6GxGD6EQXXeiabYg0nux23S0RFir1I0CcPwViUPEFVXoVZRvfEZgQd/Ib4 XB1wjqHVXuKJ443zyrccEXczI0hvvQhpVAwf3QkGdzud9/hF2Z51RXoWRZcLhMzstjXD R8erf0y7pYiBY1dDkllREI+1KW7Gm5u+v+05BgCzFnsypH0N0Q7UF33hnhnOYryXV51E /gGQ== X-Gm-Message-State: AOJu0YzeFkZVGZyQAtkZYgNyDfigYL5kqj8HzDRYazLDz1wDHBj5W//d p+JevZi62lrrO4Ic9PnNVHU= X-Google-Smtp-Source: AGHT+IFTnBcSPVQEOwBhB8aLfL64/lKfYAn+Ejl1fvNJcuyg8R9U2ZX+LrjerUp4aP5RiGyzsYOAYQ== X-Received: by 2002:a05:6a21:595:b0:15b:c800:48af with SMTP id lw21-20020a056a21059500b0015bc80048afmr4192797pzb.23.1698195755539; Tue, 24 Oct 2023 18:02:35 -0700 (PDT) Received: from localhost ([183.242.254.166]) by smtp.gmail.com with ESMTPSA id fb22-20020a056a002d9600b006be17e60708sm8177250pfb.204.2023.10.24.18.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 18:02:35 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH v4 1/2] vdpa: Restore hash calculation state Date: Wed, 25 Oct 2023 09:02:24 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=yin31149@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This patch introduces vhost_vdpa_net_load_rss() to restore the hash calculation state at device's startup. Signed-off-by: Hawkins Jiawei Acked-by: Eugenio Pérez --- v4: - fix some typos pointed out by Michael - zero the `cfg` fields at the definition suggested by Michael v3: https://patchwork.kernel.org/project/qemu-devel/patch/b7cd0c8d6a58b16b086f11714d2908ad35c67caa.1697902949.git.yin31149@gmail.com/ - remove the `do_rss` argument in vhost_vdpa_net_load_rss() - zero reserved fields in "cfg" manually instead of using memset() to prevent compiler "array-bounds" warning v2: https://lore.kernel.org/all/f5ffad10699001107022851e0560cb394039d6b0.1693297766.git.yin31149@gmail.com/ - resolve conflict with updated patch "vdpa: Send all CVQ state load commands in parallel" - move the `table` declaration at the beginning of the vhost_vdpa_net_load_rss() RFC: https://lore.kernel.org/all/a54ca70b12ebe2f3c391864e41241697ab1aba30.1691762906.git.yin31149@gmail.com/ net/vhost-vdpa.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7a226c93bc..e59d40b8ae 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -818,6 +818,88 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n, return 0; } +static int vhost_vdpa_net_load_rss(VhostVDPAState *s, const VirtIONet *n, + struct iovec *out_cursor, + struct iovec *in_cursor) +{ + struct virtio_net_rss_config cfg = {}; + ssize_t r; + g_autofree uint16_t *table = NULL; + + /* + * According to VirtIO standard, "Initially the device has all hash + * types disabled and reports only VIRTIO_NET_HASH_REPORT_NONE.". + * + * Therefore, there is no need to send this CVQ command if the + * driver disables the all hash types, which aligns with + * the device's defaults. + * + * Note that the device's defaults can mismatch the driver's + * configuration only at live migration. + */ + if (!n->rss_data.enabled || + n->rss_data.hash_types == VIRTIO_NET_HASH_REPORT_NONE) { + return 0; + } + + table = g_malloc_n(n->rss_data.indirections_len, + sizeof(n->rss_data.indirections_table[0])); + cfg.hash_types = cpu_to_le32(n->rss_data.hash_types); + + /* + * According to VirtIO standard, "Field reserved MUST contain zeroes. + * It is defined to make the structure to match the layout of + * virtio_net_rss_config structure, defined in 5.1.6.5.7.". + * + * Therefore, we need to zero the fields in + * struct virtio_net_rss_config, which corresponds to the + * `reserved` field in struct virtio_net_hash_config. + * + * Note that all other fields are zeroed at their definitions, + * except for the `indirection_table` field, where the actual data + * is stored in the `table` variable to ensure compatibility + * with RSS case. Therefore, we need to zero the `table` variable here. + */ + table[0] = 0; + + /* + * Considering that virtio_net_handle_rss() currently does not restore + * the hash key length parsed from the CVQ command sent from the guest + * into n->rss_data and uses the maximum key length in other code, so + * we also employ the maximum key length here. + */ + cfg.hash_key_length = sizeof(n->rss_data.key); + + const struct iovec data[] = { + { + .iov_base = &cfg, + .iov_len = offsetof(struct virtio_net_rss_config, + indirection_table), + }, { + .iov_base = table, + .iov_len = n->rss_data.indirections_len * + sizeof(n->rss_data.indirections_table[0]), + }, { + .iov_base = &cfg.max_tx_vq, + .iov_len = offsetof(struct virtio_net_rss_config, hash_key_data) - + offsetof(struct virtio_net_rss_config, max_tx_vq), + }, { + .iov_base = (void *)n->rss_data.key, + .iov_len = sizeof(n->rss_data.key), + } + }; + + r = vhost_vdpa_net_load_cmd(s, out_cursor, in_cursor, + VIRTIO_NET_CTRL_MQ, + VIRTIO_NET_CTRL_MQ_HASH_CONFIG, + data, ARRAY_SIZE(data)); + if (unlikely(r < 0)) { + return r; + } + + return 0; +} + static int vhost_vdpa_net_load_mq(VhostVDPAState *s, const VirtIONet *n, struct iovec *out_cursor, @@ -843,6 +925,15 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s, return r; } + if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_HASH_REPORT)) { + return 0; + } + + r = vhost_vdpa_net_load_rss(s, n, out_cursor, in_cursor); + if (unlikely(r < 0)) { + return r; + } + return 0; } From patchwork Wed Oct 25 01:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hawkins Jiawei X-Patchwork-Id: 13435380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 39024C25B6D for ; Wed, 25 Oct 2023 01:03:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvSIG-0005Au-W0; Tue, 24 Oct 2023 21:02:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvSIF-0005Ai-7s for qemu-devel@nongnu.org; Tue, 24 Oct 2023 21:02:43 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvSID-0007Xb-J7 for qemu-devel@nongnu.org; Tue, 24 Oct 2023 21:02:42 -0400 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3577ce73552so17754475ab.2 for ; Tue, 24 Oct 2023 18:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698195760; x=1698800560; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bjDDGokUOw6r/LVFqprMKqogFb3FbKI48l2UTMka15Q=; b=Z1uK4rX6Y7jhgGgZFcONtsQAYGcMrtZHmDsV1AbSIlxQWRgiZvy/x2QlmVBaF5aeTL V7+c+/WyIwCN4+E+hMO/q6RWDlWxnUT3vexgrtLKvARHdRmT2U4BczbP66aoO2pmD0f5 tr7njlZbDmSGvKAQBqEApfHtipIKftgss8+b5Vxbu7b8moHcNBIilD6yy1l4YSadmay1 Vy6wz4Thpk//ajGvZZFbekqu0jbo7nGEFgCuvIMKcbFnF1sO4GViPX4KbD4OizUeNn+8 FWoI6saIwfn04Dcaa7JnXlbfYVqKFtNqvYpgzIUwczkzHVWYTVuY3tREl+4cCiPeSwbu TiGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698195760; x=1698800560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bjDDGokUOw6r/LVFqprMKqogFb3FbKI48l2UTMka15Q=; b=eed38X/vG6l7OO6z+M8YDjSS3QkOKBAgLbOD1RGLzj0wfx4qSyNVNbakrR8SHdOsVG NQR3NQS7v8xOmrDKyl3AtmAdVCkh5rkmABF1WGnAH8TVkY1LwWqilBgpubeqXumhBW6k ogzjkhGCnpj6m+AdyE5YtvkyR7tJJl6mwJXjP4MrRDfreP9POgC31okCtrzw29kpn/1W kYtHda1tw/xkIygS+UQuw0m1iZMCVr6k8iCcrwcrCnndG3QKtVYfxXRo0f05FrsnK13a AqdqPjDo2Dw2JW/000oJb0/SrFzApajr7jeK79vJHbPsxUQwoJ0GU8djM9z4x0dCIPuq 4Kmw== X-Gm-Message-State: AOJu0Yx0aro16d5HHeuxGZFFSW8WzWCyAf/gkc/BUySqZHBIBMklA89h YM0cAz0tuj+IlrmiroTqzME= X-Google-Smtp-Source: AGHT+IGR1rn3K4uDqRq63fkCjWKk1hdgF0JN4ffq60uM5nwGjrS6bgl/2SZXS5e0abzVQHMGyJ+eVQ== X-Received: by 2002:a92:d2d2:0:b0:357:70f3:c431 with SMTP id w18-20020a92d2d2000000b0035770f3c431mr15361733ilg.9.1698195759888; Tue, 24 Oct 2023 18:02:39 -0700 (PDT) Received: from localhost ([183.242.254.166]) by smtp.gmail.com with ESMTPSA id by2-20020a056a02058200b0058c1383fa8bsm6761233pgb.0.2023.10.24.18.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 18:02:39 -0700 (PDT) From: Hawkins Jiawei To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com Subject: [PATCH v4 2/2] vdpa: Allow VIRTIO_NET_F_HASH_REPORT in SVQ Date: Wed, 25 Oct 2023 09:02:25 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=yin31149@gmail.com; helo=mail-il1-x134.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Enable SVQ with VIRTIO_NET_F_HASH_REPORT feature. Signed-off-by: Hawkins Jiawei Acked-by: Eugenio Pérez --- v4: - no changes v3: https://lore.kernel.org/all/c3b69f0a65600722c1e4d3aa14d53a71e8ffb888.1697902949.git.yin31149@gmail.com/ - no code changes v2: https://lore.kernel.org/all/a67d4abc2c8c5c7636addc729daa5432fa8193bd.1693297766.git.yin31149@gmail.com/ net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index e59d40b8ae..54f748d49d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -121,6 +121,7 @@ static const uint64_t vdpa_svq_device_features = BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | /* VHOST_F_LOG_ALL is exposed by SVQ */ BIT_ULL(VHOST_F_LOG_ALL) | + BIT_ULL(VIRTIO_NET_F_HASH_REPORT) | BIT_ULL(VIRTIO_NET_F_RSC_EXT) | BIT_ULL(VIRTIO_NET_F_STANDBY) | BIT_ULL(VIRTIO_NET_F_SPEED_DUPLEX);