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

29b115
From d6500340dc3c1152b5efe04ef3daa50c17a55e30 Mon Sep 17 00:00:00 2001
29b115
From: Leonardo Bras <leobras@redhat.com>
29b115
Date: Fri, 13 May 2022 03:28:33 -0300
29b115
Subject: [PATCH 10/18] migration: Add zero-copy-send parameter for QMP/HMP for
29b115
 Linux
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Leonardo Brás <leobras@redhat.com>
29b115
RH-MergeRequest: 95: MSG_ZEROCOPY + Multifd
29b115
RH-Commit: [4/11] 514d98d595992c53ff98de750035e080ded8972e (LeoBras/centos-qemu-kvm)
29b115
RH-Bugzilla: 1968509
29b115
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
29b115
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
29b115
RH-Acked-by: Peter Xu <peterx@redhat.com>
29b115
29b115
Add property that allows zero-copy migration of memory pages
29b115
on the sending side, and also includes a helper function
29b115
migrate_use_zero_copy_send() to check if it's enabled.
29b115
29b115
No code is introduced to actually do the migration, but it allow
29b115
future implementations to enable/disable this feature.
29b115
29b115
On non-Linux builds this parameter is compiled-out.
29b115
29b115
Signed-off-by: Leonardo Bras <leobras@redhat.com>
29b115
Reviewed-by: Peter Xu <peterx@redhat.com>
29b115
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
29b115
Reviewed-by: Juan Quintela <quintela@redhat.com>
29b115
Acked-by: Markus Armbruster <armbru@redhat.com>
29b115
Message-Id: <20220513062836.965425-5-leobras@redhat.com>
29b115
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
29b115
(cherry picked from commit abb6295b3ace5d17c3a65936913fc346616dbf14)
29b115
Signed-off-by: Leonardo Bras <leobras@redhat.com>
29b115
---
29b115
 migration/migration.c | 32 ++++++++++++++++++++++++++++++++
29b115
 migration/migration.h |  5 +++++
29b115
 migration/socket.c    | 11 +++++++++--
29b115
 monitor/hmp-cmds.c    |  6 ++++++
29b115
 qapi/migration.json   | 24 ++++++++++++++++++++++++
29b115
 5 files changed, 76 insertions(+), 2 deletions(-)
29b115
29b115
diff --git a/migration/migration.c b/migration/migration.c
29b115
index 695f0f2900..0a6b3b9f4d 100644
29b115
--- a/migration/migration.c
29b115
+++ b/migration/migration.c
29b115
@@ -899,6 +899,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
29b115
     params->multifd_zlib_level = s->parameters.multifd_zlib_level;
29b115
     params->has_multifd_zstd_level = true;
29b115
     params->multifd_zstd_level = s->parameters.multifd_zstd_level;
29b115
+#ifdef CONFIG_LINUX
29b115
+    params->has_zero_copy_send = true;
29b115
+    params->zero_copy_send = s->parameters.zero_copy_send;
29b115
+#endif
29b115
     params->has_xbzrle_cache_size = true;
29b115
     params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
29b115
     params->has_max_postcopy_bandwidth = true;
29b115
@@ -1555,6 +1559,11 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
29b115
     if (params->has_multifd_compression) {
29b115
         dest->multifd_compression = params->multifd_compression;
29b115
     }
29b115
+#ifdef CONFIG_LINUX
29b115
+    if (params->has_zero_copy_send) {
29b115
+        dest->zero_copy_send = params->zero_copy_send;
29b115
+    }
29b115
+#endif
29b115
     if (params->has_xbzrle_cache_size) {
29b115
         dest->xbzrle_cache_size = params->xbzrle_cache_size;
29b115
     }
29b115
@@ -1667,6 +1676,11 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
29b115
     if (params->has_multifd_compression) {
29b115
         s->parameters.multifd_compression = params->multifd_compression;
29b115
     }
29b115
+#ifdef CONFIG_LINUX
29b115
+    if (params->has_zero_copy_send) {
29b115
+        s->parameters.zero_copy_send = params->zero_copy_send;
29b115
+    }
29b115
+#endif
29b115
     if (params->has_xbzrle_cache_size) {
29b115
         s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
29b115
         xbzrle_cache_resize(params->xbzrle_cache_size, errp);
29b115
@@ -2557,6 +2571,17 @@ int migrate_multifd_zstd_level(void)
29b115
     return s->parameters.multifd_zstd_level;
29b115
 }
29b115
 
29b115
+#ifdef CONFIG_LINUX
29b115
+bool migrate_use_zero_copy_send(void)
29b115
+{
29b115
+    MigrationState *s;
29b115
+
29b115
+    s = migrate_get_current();
29b115
+
29b115
+    return s->parameters.zero_copy_send;
29b115
+}
29b115
+#endif
29b115
+
29b115
 int migrate_use_xbzrle(void)
29b115
 {
29b115
     MigrationState *s;
29b115
@@ -4200,6 +4225,10 @@ static Property migration_properties[] = {
29b115
     DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
29b115
                       parameters.multifd_zstd_level,
29b115
                       DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
29b115
+#ifdef CONFIG_LINUX
29b115
+    DEFINE_PROP_BOOL("zero_copy_send", MigrationState,
29b115
+                      parameters.zero_copy_send, false),
29b115
+#endif
29b115
     DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
29b115
                       parameters.xbzrle_cache_size,
29b115
                       DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
29b115
@@ -4297,6 +4326,9 @@ static void migration_instance_init(Object *obj)
29b115
     params->has_multifd_compression = true;
29b115
     params->has_multifd_zlib_level = true;
29b115
     params->has_multifd_zstd_level = true;
29b115
+#ifdef CONFIG_LINUX
29b115
+    params->has_zero_copy_send = true;
29b115
+#endif
29b115
     params->has_xbzrle_cache_size = true;
29b115
     params->has_max_postcopy_bandwidth = true;
29b115
     params->has_max_cpu_throttle = true;
29b115
diff --git a/migration/migration.h b/migration/migration.h
29b115
index 2de861df01..5bcb7628ef 100644
29b115
--- a/migration/migration.h
29b115
+++ b/migration/migration.h
29b115
@@ -376,6 +376,11 @@ MultiFDCompression migrate_multifd_compression(void);
29b115
 int migrate_multifd_zlib_level(void);
29b115
 int migrate_multifd_zstd_level(void);
29b115
 
29b115
+#ifdef CONFIG_LINUX
29b115
+bool migrate_use_zero_copy_send(void);
29b115
+#else
29b115
+#define migrate_use_zero_copy_send() (false)
29b115
+#endif
29b115
 int migrate_use_xbzrle(void);
29b115
 uint64_t migrate_xbzrle_cache_size(void);
29b115
 bool migrate_colo_enabled(void);
29b115
diff --git a/migration/socket.c b/migration/socket.c
29b115
index 05705a32d8..3754d8f72c 100644
29b115
--- a/migration/socket.c
29b115
+++ b/migration/socket.c
29b115
@@ -74,9 +74,16 @@ static void socket_outgoing_migration(QIOTask *task,
29b115
 
29b115
     if (qio_task_propagate_error(task, &err)) {
29b115
         trace_migration_socket_outgoing_error(error_get_pretty(err));
29b115
-    } else {
29b115
-        trace_migration_socket_outgoing_connected(data->hostname);
29b115
+           goto out;
29b115
     }
29b115
+
29b115
+    trace_migration_socket_outgoing_connected(data->hostname);
29b115
+
29b115
+    if (migrate_use_zero_copy_send()) {
29b115
+        error_setg(&err, "Zero copy send not available in migration");
29b115
+    }
29b115
+
29b115
+out:
29b115
     migration_channel_connect(data->s, sioc, data->hostname, err);
29b115
     object_unref(OBJECT(sioc));
29b115
 }
29b115
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
29b115
index 634968498b..55b48d3733 100644
29b115
--- a/monitor/hmp-cmds.c
29b115
+++ b/monitor/hmp-cmds.c
29b115
@@ -1309,6 +1309,12 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
29b115
         p->has_multifd_zstd_level = true;
29b115
         visit_type_uint8(v, param, &p->multifd_zstd_level, &err;;
29b115
         break;
29b115
+#ifdef CONFIG_LINUX
29b115
+    case MIGRATION_PARAMETER_ZERO_COPY_SEND:
29b115
+        p->has_zero_copy_send = true;
29b115
+        visit_type_bool(v, param, &p->zero_copy_send, &err;;
29b115
+        break;
29b115
+#endif
29b115
     case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
29b115
         p->has_xbzrle_cache_size = true;
29b115
         if (!visit_type_size(v, param, &cache_size, &err)) {
29b115
diff --git a/qapi/migration.json b/qapi/migration.json
29b115
index 27d7b28158..4d833ecdd6 100644
29b115
--- a/qapi/migration.json
29b115
+++ b/qapi/migration.json
29b115
@@ -741,6 +741,13 @@
29b115
 #                      will consume more CPU.
29b115
 #                      Defaults to 1. (Since 5.0)
29b115
 #
29b115
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
29b115
+#                  When true, enables a zero-copy mechanism for sending
29b115
+#                  memory pages, if host supports it.
29b115
+#                  Requires that QEMU be permitted to use locked memory
29b115
+#                  for guest RAM pages.
29b115
+#                  Defaults to false. (Since 7.1)
29b115
+#
29b115
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
29b115
 #                        aliases for the purpose of dirty bitmap migration.  Such
29b115
 #                        aliases may for example be the corresponding names on the
29b115
@@ -780,6 +787,7 @@
29b115
            'xbzrle-cache-size', 'max-postcopy-bandwidth',
29b115
            'max-cpu-throttle', 'multifd-compression',
29b115
            'multifd-zlib-level' ,'multifd-zstd-level',
29b115
+           { 'name': 'zero-copy-send', 'if' : 'CONFIG_LINUX'},
29b115
            'block-bitmap-mapping' ] }
29b115
 
29b115
 ##
29b115
@@ -906,6 +914,13 @@
29b115
 #                      will consume more CPU.
29b115
 #                      Defaults to 1. (Since 5.0)
29b115
 #
29b115
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
29b115
+#                  When true, enables a zero-copy mechanism for sending
29b115
+#                  memory pages, if host supports it.
29b115
+#                  Requires that QEMU be permitted to use locked memory
29b115
+#                  for guest RAM pages.
29b115
+#                  Defaults to false. (Since 7.1)
29b115
+#
29b115
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
29b115
 #                        aliases for the purpose of dirty bitmap migration.  Such
29b115
 #                        aliases may for example be the corresponding names on the
29b115
@@ -960,6 +975,7 @@
29b115
             '*multifd-compression': 'MultiFDCompression',
29b115
             '*multifd-zlib-level': 'uint8',
29b115
             '*multifd-zstd-level': 'uint8',
29b115
+            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
29b115
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
29b115
 
29b115
 ##
29b115
@@ -1106,6 +1122,13 @@
29b115
 #                      will consume more CPU.
29b115
 #                      Defaults to 1. (Since 5.0)
29b115
 #
29b115
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
29b115
+#                  When true, enables a zero-copy mechanism for sending
29b115
+#                  memory pages, if host supports it.
29b115
+#                  Requires that QEMU be permitted to use locked memory
29b115
+#                  for guest RAM pages.
29b115
+#                  Defaults to false. (Since 7.1)
29b115
+#
29b115
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
29b115
 #                        aliases for the purpose of dirty bitmap migration.  Such
29b115
 #                        aliases may for example be the corresponding names on the
29b115
@@ -1158,6 +1181,7 @@
29b115
             '*multifd-compression': 'MultiFDCompression',
29b115
             '*multifd-zlib-level': 'uint8',
29b115
             '*multifd-zstd-level': 'uint8',
29b115
+            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
29b115
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
29b115
 
29b115
 ##
29b115
-- 
29b115
2.35.3
29b115