Blame SOURCES/kvm-migration-Add-zero-copy-send-parameter-for-QMP-HMP-f.patch

0727d3
From 2a84bf822cae38f67458043cd379a22e0fd22485 Mon Sep 17 00:00:00 2001
0727d3
From: Leonardo Bras <leobras@redhat.com>
0727d3
Date: Wed, 18 May 2022 02:52:25 -0300
0727d3
Subject: [PATCH 19/37] migration: Add zero-copy-send parameter for QMP/HMP for
0727d3
 Linux
0727d3
MIME-Version: 1.0
0727d3
Content-Type: text/plain; charset=UTF-8
0727d3
Content-Transfer-Encoding: 8bit
0727d3
0727d3
RH-Author: Leonardo Brás <leobras@redhat.com>
0727d3
RH-MergeRequest: 191: MSG_ZEROCOPY + Multifd @ rhel8.7
0727d3
RH-Commit: [19/26] 44ec703088cad75fd6e504958527e81d3261c9df
0727d3
RH-Bugzilla: 2072049
0727d3
RH-Acked-by: Peter Xu <peterx@redhat.com>
0727d3
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
0727d3
Add property that allows zero-copy migration of memory pages
0727d3
on the sending side, and also includes a helper function
0727d3
migrate_use_zero_copy_send() to check if it's enabled.
0727d3
0727d3
No code is introduced to actually do the migration, but it allow
0727d3
future implementations to enable/disable this feature.
0727d3
0727d3
On non-Linux builds this parameter is compiled-out.
0727d3
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
Reviewed-by: Peter Xu <peterx@redhat.com>
0727d3
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
0727d3
Reviewed-by: Juan Quintela <quintela@redhat.com>
0727d3
Acked-by: Markus Armbruster <armbru@redhat.com>
0727d3
Message-Id: <20220513062836.965425-5-leobras@redhat.com>
0727d3
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
(cherry picked from commit abb6295b3ace5d17c3a65936913fc346616dbf14)
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
---
0727d3
 migration/migration.c | 32 ++++++++++++++++++++++++++++++++
0727d3
 migration/migration.h |  5 +++++
0727d3
 migration/socket.c    | 11 +++++++++--
0727d3
 monitor/hmp-cmds.c    |  6 ++++++
0727d3
 qapi/migration.json   | 24 ++++++++++++++++++++++++
0727d3
 5 files changed, 76 insertions(+), 2 deletions(-)
0727d3
0727d3
diff --git a/migration/migration.c b/migration/migration.c
0727d3
index 8a13294da6..b0fc3f68bd 100644
0727d3
--- a/migration/migration.c
0727d3
+++ b/migration/migration.c
0727d3
@@ -888,6 +888,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
0727d3
     params->multifd_zlib_level = s->parameters.multifd_zlib_level;
0727d3
     params->has_multifd_zstd_level = true;
0727d3
     params->multifd_zstd_level = s->parameters.multifd_zstd_level;
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    params->has_zero_copy_send = true;
0727d3
+    params->zero_copy_send = s->parameters.zero_copy_send;
0727d3
+#endif
0727d3
     params->has_xbzrle_cache_size = true;
0727d3
     params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
0727d3
     params->has_max_postcopy_bandwidth = true;
0727d3
@@ -1541,6 +1545,11 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
0727d3
     if (params->has_multifd_compression) {
0727d3
         dest->multifd_compression = params->multifd_compression;
0727d3
     }
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    if (params->has_zero_copy_send) {
0727d3
+        dest->zero_copy_send = params->zero_copy_send;
0727d3
+    }
0727d3
+#endif
0727d3
     if (params->has_xbzrle_cache_size) {
0727d3
         dest->xbzrle_cache_size = params->xbzrle_cache_size;
0727d3
     }
0727d3
@@ -1653,6 +1662,11 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
0727d3
     if (params->has_multifd_compression) {
0727d3
         s->parameters.multifd_compression = params->multifd_compression;
0727d3
     }
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    if (params->has_zero_copy_send) {
0727d3
+        s->parameters.zero_copy_send = params->zero_copy_send;
0727d3
+    }
0727d3
+#endif
0727d3
     if (params->has_xbzrle_cache_size) {
0727d3
         s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
0727d3
         xbzrle_cache_resize(params->xbzrle_cache_size, errp);
0727d3
@@ -2543,6 +2557,17 @@ int migrate_multifd_zstd_level(void)
0727d3
     return s->parameters.multifd_zstd_level;
0727d3
 }
0727d3
 
0727d3
+#ifdef CONFIG_LINUX
0727d3
+bool migrate_use_zero_copy_send(void)
0727d3
+{
0727d3
+    MigrationState *s;
0727d3
+
0727d3
+    s = migrate_get_current();
0727d3
+
0727d3
+    return s->parameters.zero_copy_send;
0727d3
+}
0727d3
+#endif
0727d3
+
0727d3
 int migrate_use_xbzrle(void)
0727d3
 {
0727d3
     MigrationState *s;
0727d3
@@ -4193,6 +4218,10 @@ static Property migration_properties[] = {
0727d3
     DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
0727d3
                       parameters.multifd_zstd_level,
0727d3
                       DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    DEFINE_PROP_BOOL("zero_copy_send", MigrationState,
0727d3
+                      parameters.zero_copy_send, false),
0727d3
+#endif
0727d3
     DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
0727d3
                       parameters.xbzrle_cache_size,
0727d3
                       DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
0727d3
@@ -4290,6 +4319,9 @@ static void migration_instance_init(Object *obj)
0727d3
     params->has_multifd_compression = true;
0727d3
     params->has_multifd_zlib_level = true;
0727d3
     params->has_multifd_zstd_level = true;
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    params->has_zero_copy_send = true;
0727d3
+#endif
0727d3
     params->has_xbzrle_cache_size = true;
0727d3
     params->has_max_postcopy_bandwidth = true;
0727d3
     params->has_max_cpu_throttle = true;
0727d3
diff --git a/migration/migration.h b/migration/migration.h
0727d3
index d016cedd9d..908098939f 100644
0727d3
--- a/migration/migration.h
0727d3
+++ b/migration/migration.h
0727d3
@@ -339,6 +339,11 @@ MultiFDCompression migrate_multifd_compression(void);
0727d3
 int migrate_multifd_zlib_level(void);
0727d3
 int migrate_multifd_zstd_level(void);
0727d3
 
0727d3
+#ifdef CONFIG_LINUX
0727d3
+bool migrate_use_zero_copy_send(void);
0727d3
+#else
0727d3
+#define migrate_use_zero_copy_send() (false)
0727d3
+#endif
0727d3
 int migrate_use_xbzrle(void);
0727d3
 uint64_t migrate_xbzrle_cache_size(void);
0727d3
 bool migrate_colo_enabled(void);
0727d3
diff --git a/migration/socket.c b/migration/socket.c
0727d3
index 05705a32d8..3754d8f72c 100644
0727d3
--- a/migration/socket.c
0727d3
+++ b/migration/socket.c
0727d3
@@ -74,9 +74,16 @@ static void socket_outgoing_migration(QIOTask *task,
0727d3
 
0727d3
     if (qio_task_propagate_error(task, &err)) {
0727d3
         trace_migration_socket_outgoing_error(error_get_pretty(err));
0727d3
-    } else {
0727d3
-        trace_migration_socket_outgoing_connected(data->hostname);
0727d3
+           goto out;
0727d3
     }
0727d3
+
0727d3
+    trace_migration_socket_outgoing_connected(data->hostname);
0727d3
+
0727d3
+    if (migrate_use_zero_copy_send()) {
0727d3
+        error_setg(&err, "Zero copy send not available in migration");
0727d3
+    }
0727d3
+
0727d3
+out:
0727d3
     migration_channel_connect(data->s, sioc, data->hostname, err);
0727d3
     object_unref(OBJECT(sioc));
0727d3
 }
0727d3
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
0727d3
index 2669156b28..e02da5008b 100644
0727d3
--- a/monitor/hmp-cmds.c
0727d3
+++ b/monitor/hmp-cmds.c
0727d3
@@ -1297,6 +1297,12 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
0727d3
         p->has_multifd_zstd_level = true;
0727d3
         visit_type_uint8(v, param, &p->multifd_zstd_level, &err;;
0727d3
         break;
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    case MIGRATION_PARAMETER_ZERO_COPY_SEND:
0727d3
+        p->has_zero_copy_send = true;
0727d3
+        visit_type_bool(v, param, &p->zero_copy_send, &err;;
0727d3
+        break;
0727d3
+#endif
0727d3
     case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
0727d3
         p->has_xbzrle_cache_size = true;
0727d3
         if (!visit_type_size(v, param, &cache_size, &err)) {
0727d3
diff --git a/qapi/migration.json b/qapi/migration.json
0727d3
index bbfd48cf0b..59b5c5780b 100644
0727d3
--- a/qapi/migration.json
0727d3
+++ b/qapi/migration.json
0727d3
@@ -730,6 +730,13 @@
0727d3
 #                      will consume more CPU.
0727d3
 #                      Defaults to 1. (Since 5.0)
0727d3
 #
0727d3
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
0727d3
+#                  When true, enables a zero-copy mechanism for sending
0727d3
+#                  memory pages, if host supports it.
0727d3
+#                  Requires that QEMU be permitted to use locked memory
0727d3
+#                  for guest RAM pages.
0727d3
+#                  Defaults to false. (Since 7.1)
0727d3
+#
0727d3
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
0727d3
 #                        aliases for the purpose of dirty bitmap migration.  Such
0727d3
 #                        aliases may for example be the corresponding names on the
0727d3
@@ -769,6 +776,7 @@
0727d3
            'xbzrle-cache-size', 'max-postcopy-bandwidth',
0727d3
            'max-cpu-throttle', 'multifd-compression',
0727d3
            'multifd-zlib-level' ,'multifd-zstd-level',
0727d3
+           { 'name': 'zero-copy-send', 'if' : 'CONFIG_LINUX'},
0727d3
            'block-bitmap-mapping' ] }
0727d3
 
0727d3
 ##
0727d3
@@ -895,6 +903,13 @@
0727d3
 #                      will consume more CPU.
0727d3
 #                      Defaults to 1. (Since 5.0)
0727d3
 #
0727d3
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
0727d3
+#                  When true, enables a zero-copy mechanism for sending
0727d3
+#                  memory pages, if host supports it.
0727d3
+#                  Requires that QEMU be permitted to use locked memory
0727d3
+#                  for guest RAM pages.
0727d3
+#                  Defaults to false. (Since 7.1)
0727d3
+#
0727d3
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
0727d3
 #                        aliases for the purpose of dirty bitmap migration.  Such
0727d3
 #                        aliases may for example be the corresponding names on the
0727d3
@@ -949,6 +964,7 @@
0727d3
             '*multifd-compression': 'MultiFDCompression',
0727d3
             '*multifd-zlib-level': 'uint8',
0727d3
             '*multifd-zstd-level': 'uint8',
0727d3
+            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
0727d3
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
0727d3
 
0727d3
 ##
0727d3
@@ -1095,6 +1111,13 @@
0727d3
 #                      will consume more CPU.
0727d3
 #                      Defaults to 1. (Since 5.0)
0727d3
 #
0727d3
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
0727d3
+#                  When true, enables a zero-copy mechanism for sending
0727d3
+#                  memory pages, if host supports it.
0727d3
+#                  Requires that QEMU be permitted to use locked memory
0727d3
+#                  for guest RAM pages.
0727d3
+#                  Defaults to false. (Since 7.1)
0727d3
+#
0727d3
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
0727d3
 #                        aliases for the purpose of dirty bitmap migration.  Such
0727d3
 #                        aliases may for example be the corresponding names on the
0727d3
@@ -1147,6 +1170,7 @@
0727d3
             '*multifd-compression': 'MultiFDCompression',
0727d3
             '*multifd-zlib-level': 'uint8',
0727d3
             '*multifd-zstd-level': 'uint8',
0727d3
+            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
0727d3
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
0727d3
 
0727d3
 ##
0727d3
-- 
0727d3
2.35.3
0727d3