From nobody Tue May 14 20:20:57 2024 Delivered-To: importer@patchew.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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693298949; cv=none; d=zohomail.com; s=zohoarc; b=hks9NsMEz1/nRhprp84cF1HeheaiHFeeX/t98gUGAfcC6jK8xmlgAT9+Jz/19qZQAx3j2jYpcfOWIQU05dK8xdNTW2+cl2ZfVnAucHwfzCJukW1xddQuyYFPqxXCZpNXLgMJZjLFD+oD2viqb9rBPlthbcz16/flX2rZeJ2Sljc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693298949; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7A8bb42jd+n02BsnrgotugyR8FDt67yG4EBeqWrPXHM=; b=mwn8wKoBEzzLCsTOs/vrT7UTBht7HgAi/F2rQXgWY6g+6/tGZxLrmxJnAxwhoN/b/25MO/NtNio5GQrAlGLSsh9OxVn+MONOZB6llyxNf/5BJv9G0cdd1n7tCHXgqxmyST+4xMJnqvgL1qNFD/2/f0Ju8+sK8a5og968pyMrdlI= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693298949914777.2859454172859; Tue, 29 Aug 2023 01:49:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qauOz-0008LW-3b; Tue, 29 Aug 2023 04:48: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 1qauOr-0008Ka-R1 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 04:48:40 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qauOm-0007lQ-Nl for qemu-devel@nongnu.org; Tue, 29 Aug 2023 04:48:37 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-26814e27a9eso2167008a91.0 for ; Tue, 29 Aug 2023 01:48:31 -0700 (PDT) Received: from localhost ([183.242.254.166]) by smtp.gmail.com with ESMTPSA id mq3-20020a17090b380300b002682523653asm8410789pjb.49.2023.08.29.01.48.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 01:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693298910; x=1693903710; 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=7A8bb42jd+n02BsnrgotugyR8FDt67yG4EBeqWrPXHM=; b=BNH8pkY8AzYXfpkkQ5pMXf3lqexDHx0Pz+xWneUKknfWcgNJhWTJWxJY980Ctoxbm5 yfRMyLxZ6eN+DMOg3uEibA4swSV+QR8MWE1JVn57iNfbr/MfwOyjZUxHhugSNv7oJVr0 uG34B14dPwcURHC4GKhS9dcJ1rNOhspSmdZfUx+SfUqqBWyLRR430xoFZWPeOsXL/moS xStxNm3cXtPwXqayYf/KqmsjfOnns6/IFxEeeYRNmFrQ6v4GCIMJNLpZHZZhWFv+Qu/y MBeyxEGs4OLlf60ysKEHApkMWCFlacqGGx4D8YgHxneO3bJ4xxDRfWZT/i3sZEhNStE3 umLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693298910; x=1693903710; 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=7A8bb42jd+n02BsnrgotugyR8FDt67yG4EBeqWrPXHM=; b=cekv6sTMkmyQWtcJB/VnF9FhK5c5C+BbnNvj4YBNHEGnkaOfoer4jqNNoilbBjrYqw L1+tAwDhc6c473HT3ilXXfrD4P3Es+cZehqF0cO+8aubri23zanKSeC/8djSSGxv4D3o Zt1GUYo0yey+BjEfykWQbOQMLgIMIx25mXOOQHf3KlUktpoOY4SWoaF+SSEhL6klraMg kflm6JRRuOFd+2DNmuiBJRAJ1sn+mr0IHlVFSI9R04YsQ1XcmzJEeehXTT71nqItabPP 2ESeYux2PfLv8rke07CZoBCouUpJN/VOoi23Iy3rNH76bQu/a2ZAwyLrMyrOAXGVbWu/ FmIg== X-Gm-Message-State: AOJu0Yzrcbq4tAOd6yGx9fSrZkJs1fXXcL4WsKhGcQVRZVma88BRUZbB BiJdN2bNZJtwhEi6NHMMkdKqyLg0gdPb4J+h X-Google-Smtp-Source: AGHT+IGbaQ1y2JPC+W4mjzJ4LEda9xODHd5f2bvpczAUAvTdKE1EXBPGxbTVPCxe6Aw9eMdnzgGEMg== X-Received: by 2002:a17:90b:4a02:b0:26b:5205:525e with SMTP id kk2-20020a17090b4a0200b0026b5205525emr19650903pjb.42.1693298909963; Tue, 29 Aug 2023 01:48:29 -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 v2 1/2] vdpa: Restore hash calculation state Date: Tue, 29 Aug 2023 16:48:15 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=yin31149@gmail.com; helo=mail-pj1-x1029.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1693298950804100001 Content-Type: text/plain; charset="utf-8" This patch introduces vhost_vdpa_net_load_rss() to restore the hash calculation state at device's startup. Note that vhost_vdpa_net_load_rss() has `do_rss` argument, which allows future code to reuse this function to restore the receive-side scaling state when the VIRTIO_NET_F_RSS feature is enabled in SVQ. Currently, vhost_vdpa_net_load_rss() could only be invoked when `do_rss` is set to false. Signed-off-by: Hawkins Jiawei --- Question: It seems 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 for `hash_key_length` field in VIRTIO_NET_CTRL_MQ_HASH_CONFIG command sent to device, is it okay to also use the maximum key length as its value? Or should we introduce the `hash_key_length` field in n->rss_data structure to record the key length from guest and use this value? ChangeLog: v2: - 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.1= 691762906.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 818464b702..139bb79468 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -805,6 +805,88 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, = const VirtIONet *n, return 0; } =20 +static int vhost_vdpa_net_load_rss(VhostVDPAState *s, const VirtIONet *n, + struct iovec *out_cursor, + struct iovec *in_cursor, bool do_rss) +{ + struct virtio_net_rss_config cfg; + ssize_t r; + g_autofree uint16_t *table =3D 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 disable 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 =3D=3D VIRTIO_NET_HASH_REPORT_NONE) { + return 0; + } + + cfg.hash_types =3D 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_conf= ig, + * which corresponds the `reserved` field in + * struct virtio_net_hash_config. + */ + memset(&cfg.indirection_table_mask, 0, + sizeof_field(struct virtio_net_hash_config, reserved)); + + table =3D g_malloc_n(n->rss_data.indirections_len, + sizeof(n->rss_data.indirections_table[0])); + for (int i =3D 0; i < n->rss_data.indirections_len; ++i) { + table[i] =3D cpu_to_le16(n->rss_data.indirections_table[i]); + } + + /* + * Consider 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 al= so + * employthe the maxium key length here. + */ + cfg.hash_key_length =3D sizeof(n->rss_data.key); + + const struct iovec data[] =3D { + { + .iov_base =3D &cfg, + .iov_len =3D offsetof(struct virtio_net_rss_config, + indirection_table), + }, { + .iov_base =3D table, + .iov_len =3D n->rss_data.indirections_len * + sizeof(n->rss_data.indirections_table[0]), + }, { + .iov_base =3D &cfg.max_tx_vq, + .iov_len =3D offsetof(struct virtio_net_rss_config, hash_key_d= ata) - + offsetof(struct virtio_net_rss_config, max_tx_vq), + }, { + .iov_base =3D (void *)n->rss_data.key, + .iov_len =3D sizeof(n->rss_data.key), + } + }; + + r =3D 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, @@ -830,6 +912,15 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s, return r; } =20 + if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_HASH_REPORT)= ) { + return 0; + } + + r =3D vhost_vdpa_net_load_rss(s, n, out_cursor, in_cursor, false); + if (unlikely(r < 0)) { + return r; + } + return 0; } =20 --=20 2.25.1 From nobody Tue May 14 20:20:57 2024 Delivered-To: importer@patchew.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; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693298960; cv=none; d=zohomail.com; s=zohoarc; b=Hf4LOsElzYxXNlXjrOoVIy5D3S39sOLt/H4ICaYPZNbOjVs+FC0Pp6w3D9sVSK9LA5dZ5tYzBdN8cDcxUKzjY02zCAdHd0xboqDVt0K3fMsgIT3e2oL8Udbv8yW1x+7KpAP29JXMvQehVVxk+73gNAu5Lh/Unl6UqOUDGO3yQyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693298960; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vtTvXcgjRorRBn8kaBMTkcM6K2Ovcp/xG38XsSvb3SE=; b=AC3CYZt5ecyFuH+9GA/J8ldNNH8qu+N8IMU+6/3wxn7k2eVxP9MrcKZRt8JO8lHVCr/YgsMwhv9wFJ+1SvkmH52WrzinLoZPmCSbTJF6JwYgQQmvsiKQM74KzIYdPSdSrkxhIPvTDXWBMjKHDr96lNQzqqJrE+kiCMzykje/dzY= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693298960954258.124356387037; Tue, 29 Aug 2023 01:49:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qauOx-0008L2-2X; Tue, 29 Aug 2023 04:48:43 -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 1qauOt-0008Kb-83 for qemu-devel@nongnu.org; Tue, 29 Aug 2023 04:48:40 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qauOq-0007n0-Kg for qemu-devel@nongnu.org; Tue, 29 Aug 2023 04:48:38 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-26d4e1ba2dbso2289418a91.1 for ; Tue, 29 Aug 2023 01:48:36 -0700 (PDT) Received: from localhost ([183.242.254.166]) by smtp.gmail.com with ESMTPSA id fz23-20020a17090b025700b0026b4decfe59sm8603881pjb.31.2023.08.29.01.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 01:48:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693298915; x=1693903715; 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=vtTvXcgjRorRBn8kaBMTkcM6K2Ovcp/xG38XsSvb3SE=; b=lspylYwTvP8kcQQ0oiQQan47AuH/YXSgekWDHXh8BmqqIUUdBhij2Z1DYli1g+U3+F Nz0WbzXLFvxv3wYvs39BiUiK6zqSfBOhrwVjPP9iZzKLvoITB3tzWLV7Noymd1sJZ/dS 5jDvm3lUhWncPYL2eDFHbgZiTKbbKVx+K6vRJYVw0zpv+jdaoRT4yihnKdC2w1VXFFtb X8adnFsbr3GUvqLa6qOYFcbwu4Lmz7DKv7KL6UBENbiMEpJEzbxUtDf8t4fZM+rz79Bc EBxFCqAY2PiQeXN7/JD2H35uU8DhKYm4JGIpqB4Hy7nIrx20tn1MwNqf0MxweZpSykT4 JbjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693298915; x=1693903715; 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=vtTvXcgjRorRBn8kaBMTkcM6K2Ovcp/xG38XsSvb3SE=; b=f4e59Sp7rinIarSW466RKi2M5k1tuDWgLj2gRhbypvDVK74xYkwrCI+eC5ywg00rMa niOmAmib/k64mpeTMCGLtSMcP/mMNTy171ZCyvXyJaK9WaiXcUJoIgzXgNN3ADvdh5V/ M7qtIWcqmbXxP8vSMNKKa2hL5ePuNZr/MiMF+aa3ybcqpHXnwSuK2G8x1Kq2gcGeE4wp HqRwHpPZl0NFAJJpBixlhgCwk6oclqbnbdqsLrs6sLd149d3HHeVNn3+Bmjj4bLtOyLA BbVB5g+VW66Ux3sGM+Y070HyeqjcVM2fgmyd+0PUUd8ozQE3HWabF7JUhe1VL33E9Fvq 3c0Q== X-Gm-Message-State: AOJu0YwNqsKbun4TY5y1kvsK3CQEpeckQQ0+CmXvJ/5RVr0ozJm6tCq9 NIBF60NDKPB0go/MXqTtCK8= X-Google-Smtp-Source: AGHT+IFPrANE1dbUiFZ+ZTrAbNL7n/NOmmkAj+ffAA7pjFDcnngS3OTsuhrANl0LtNF+lhO3fwUBtw== X-Received: by 2002:a17:90a:fd14:b0:26d:ae3:f6a7 with SMTP id cv20-20020a17090afd1400b0026d0ae3f6a7mr21530688pjb.21.1693298914942; Tue, 29 Aug 2023 01:48:34 -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 v2 2/2] vdpa: Allow VIRTIO_NET_F_HASH_REPORT in SVQ Date: Tue, 29 Aug 2023 16:48:16 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=yin31149@gmail.com; helo=mail-pj1-x102e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1693298962769100001 Content-Type: text/plain; charset="utf-8" Enable SVQ with VIRTIO_NET_F_HASH_REPORT feature. Signed-off-by: Hawkins Jiawei --- net/vhost-vdpa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 139bb79468..b29f84f54c 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -118,6 +118,7 @@ static const uint64_t vdpa_svq_device_features =3D 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); --=20 2.25.1