0727d3
From 70108ff9ffe77062116e47670c0e0c2396529f88 Mon Sep 17 00:00:00 2001
0727d3
From: Leonardo Bras <leobras@redhat.com>
0727d3
Date: Mon, 20 Jun 2022 02:39:45 -0300
0727d3
Subject: [PATCH 26/37] migration: Change zero_copy_send from migration
0727d3
 parameter to migration capability
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: [26/26] ea61e6cbdbe47611bd22d18988e1c4c4e8357cc3
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
When originally implemented, zero_copy_send was designed as a Migration
0727d3
paramenter.
0727d3
0727d3
But taking into account how is that supposed to work, and how
0727d3
the difference between a capability and a parameter, it only makes sense
0727d3
that zero-copy-send would work better as a capability.
0727d3
0727d3
Taking into account how recently the change got merged, it was decided
0727d3
that it's still time to make it right, and convert zero_copy_send into
0727d3
a Migration capability.
0727d3
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
Reviewed-by: Juan Quintela <quintela@redhat.com>
0727d3
Acked-by: Markus Armbruster <armbru@redhat.com>
0727d3
Acked-by: Peter Xu <peterx@redhat.com>
0727d3
Signed-off-by: Juan Quintela <quintela@redhat.com>
0727d3
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
0727d3
  dgilbert: always define the capability, even on non-Linux but error if
0727d3
set; avoids build problems with the capability
0727d3
(cherry picked from commit 1abaec9a1b2c23f7aa94709a422128d9e42c3e0b)
0727d3
Signed-off-by: Leonardo Bras <leobras@redhat.com>
0727d3
---
0727d3
 migration/migration.c | 58 +++++++++++++++++++------------------------
0727d3
 monitor/hmp-cmds.c    |  6 -----
0727d3
 qapi/migration.json   | 33 +++++++-----------------
0727d3
 3 files changed, 34 insertions(+), 63 deletions(-)
0727d3
0727d3
diff --git a/migration/migration.c b/migration/migration.c
0727d3
index 5357efd348..c8aa55d2fe 100644
0727d3
--- a/migration/migration.c
0727d3
+++ b/migration/migration.c
0727d3
@@ -162,7 +162,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
0727d3
     MIGRATION_CAPABILITY_COMPRESS,
0727d3
     MIGRATION_CAPABILITY_XBZRLE,
0727d3
     MIGRATION_CAPABILITY_X_COLO,
0727d3
-    MIGRATION_CAPABILITY_VALIDATE_UUID);
0727d3
+    MIGRATION_CAPABILITY_VALIDATE_UUID,
0727d3
+    MIGRATION_CAPABILITY_ZERO_COPY_SEND);
0727d3
 
0727d3
 bool migrate_pre_2_2;
0727d3
 
0727d3
@@ -888,10 +889,6 @@ 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
@@ -1249,6 +1246,24 @@ static bool migrate_caps_check(bool *cap_list,
0727d3
         }
0727d3
     }
0727d3
 
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND] &&
0727d3
+        (!cap_list[MIGRATION_CAPABILITY_MULTIFD] ||
0727d3
+         migrate_use_compression() ||
0727d3
+         migrate_use_tls())) {
0727d3
+        error_setg(errp,
0727d3
+                   "Zero copy only available for non-compressed non-TLS multifd migration");
0727d3
+        return false;
0727d3
+    }
0727d3
+#else
0727d3
+    if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) {
0727d3
+        error_setg(errp,
0727d3
+                   "Zero copy currently only available on Linux");
0727d3
+        return false;
0727d3
+    }
0727d3
+#endif
0727d3
+
0727d3
+
0727d3
     /* incoming side only */
0727d3
     if (runstate_check(RUN_STATE_INMIGRATE) &&
0727d3
         !migrate_multifd_is_allowed() &&
0727d3
@@ -1471,16 +1486,6 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)
0727d3
         error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
0727d3
         return false;
0727d3
     }
0727d3
-#ifdef CONFIG_LINUX
0727d3
-    if (params->zero_copy_send &&
0727d3
-        (!migrate_use_multifd() ||
0727d3
-         params->multifd_compression != MULTIFD_COMPRESSION_NONE ||
0727d3
-         (params->tls_creds && *params->tls_creds))) {
0727d3
-        error_setg(errp,
0727d3
-                   "Zero copy only available for non-compressed non-TLS multifd migration");
0727d3
-        return false;
0727d3
-    }
0727d3
-#endif
0727d3
     return true;
0727d3
 }
0727d3
 
0727d3
@@ -1554,11 +1559,6 @@ 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
@@ -1671,11 +1671,6 @@ 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
@@ -2573,7 +2568,7 @@ bool migrate_use_zero_copy_send(void)
0727d3
 
0727d3
     s = migrate_get_current();
0727d3
 
0727d3
-    return s->parameters.zero_copy_send;
0727d3
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND];
0727d3
 }
0727d3
 #endif
0727d3
 
0727d3
@@ -4236,10 +4231,6 @@ 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
@@ -4277,6 +4268,10 @@ static Property migration_properties[] = {
0727d3
     DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD),
0727d3
     DEFINE_PROP_MIG_CAP("x-background-snapshot",
0727d3
             MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT),
0727d3
+#ifdef CONFIG_LINUX
0727d3
+    DEFINE_PROP_MIG_CAP("x-zero-copy-send",
0727d3
+            MIGRATION_CAPABILITY_ZERO_COPY_SEND),
0727d3
+#endif
0727d3
 
0727d3
     DEFINE_PROP_END_OF_LIST(),
0727d3
 };
0727d3
@@ -4337,9 +4332,6 @@ 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/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
0727d3
index e02da5008b..2669156b28 100644
0727d3
--- a/monitor/hmp-cmds.c
0727d3
+++ b/monitor/hmp-cmds.c
0727d3
@@ -1297,12 +1297,6 @@ 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 59b5c5780b..fe70a0c4b2 100644
0727d3
--- a/qapi/migration.json
0727d3
+++ b/qapi/migration.json
0727d3
@@ -452,6 +452,13 @@
0727d3
 #                       procedure starts. The VM RAM is saved with running VM.
0727d3
 #                       (since 6.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
+#                  (since 7.1)
0727d3
+#
0727d3
 # Features:
0727d3
 # @unstable: Members @x-colo and @x-ignore-shared are experimental.
0727d3
 #
0727d3
@@ -465,7 +472,8 @@
0727d3
            'block', 'return-path', 'pause-before-switchover', 'multifd',
0727d3
            'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate',
0727d3
            { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] },
0727d3
-           'validate-uuid', 'background-snapshot'] }
0727d3
+           'validate-uuid', 'background-snapshot',
0727d3
+           'zero-copy-send'] }
0727d3
 
0727d3
 ##
0727d3
 # @MigrationCapabilityStatus:
0727d3
@@ -730,12 +738,6 @@
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
@@ -776,7 +778,6 @@
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
@@ -903,13 +904,6 @@
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
@@ -964,7 +958,6 @@
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
@@ -1111,13 +1104,6 @@
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
@@ -1170,7 +1156,6 @@
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