[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/63] vdpa: Restore hash calculation state
From: |
Michael S. Tsirkin |
Subject: |
[PULL 19/63] vdpa: Restore hash calculation state |
Date: |
Tue, 7 Nov 2023 05:10:53 -0500 |
From: Hawkins Jiawei <yin31149@gmail.com>
This patch introduces vhost_vdpa_net_load_rss() to restore
the hash calculation state at device's startup.
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Message-Id:
<dbf699acff8c226596136a55a6abe35ebfeac8b0.1698194366.git.yin31149@gmail.com>
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.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;
}
--
MST
- [PULL 08/63] Add virtio-sound device stub, (continued)
- [PULL 10/63] virtio-sound: handle control messages and streams, Michael S. Tsirkin, 2023/11/07
- [PULL 13/63] virtio-sound: handle VIRTIO_SND_R_PCM_SET_PARAMS, Michael S. Tsirkin, 2023/11/07
- [PULL 09/63] Add virtio-sound-pci device, Michael S. Tsirkin, 2023/11/07
- [PULL 14/63] virtio-sound: handle VIRTIO_SND_R_PCM_PREPARE, Michael S. Tsirkin, 2023/11/07
- [PULL 15/63] virtio-sound: handle VIRTIO_SND_R_PCM_RELEASE, Michael S. Tsirkin, 2023/11/07
- [PULL 19/63] vdpa: Restore hash calculation state,
Michael S. Tsirkin <=
- [PULL 16/63] virtio-sound: implement audio output (TX), Michael S. Tsirkin, 2023/11/07
- [PULL 17/63] virtio-sound: implement audio capture (RX), Michael S. Tsirkin, 2023/11/07
- [PULL 20/63] vdpa: Allow VIRTIO_NET_F_HASH_REPORT in SVQ, Michael S. Tsirkin, 2023/11/07
- [PULL 18/63] docs/system: add basic virtio-snd documentation, Michael S. Tsirkin, 2023/11/07
- [PULL 22/63] vdpa: Restore receive-side scaling state, Michael S. Tsirkin, 2023/11/07
- [PULL 21/63] vdpa: Add SetSteeringEBPF method for NetClientState, Michael S. Tsirkin, 2023/11/07
- [PULL 24/63] tests: test-smp-parse: Add the test for cores/threads per socket helpers, Michael S. Tsirkin, 2023/11/07
- [PULL 26/63] tests: bios-tables-test: Add test for smbios type4 count, Michael S. Tsirkin, 2023/11/07
- [PULL 27/63] tests: bios-tables-test: Add ACPI table binaries for smbios type4 count test, Michael S. Tsirkin, 2023/11/07
- [PULL 25/63] tests: bios-tables-test: Prepare the ACPI table change for smbios type4 count test, Michael S. Tsirkin, 2023/11/07