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

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