Blame SOURCES/kvm-migration-Change-zero_copy_send-from-migration-param.patch

1be5c7
From 70108ff9ffe77062116e47670c0e0c2396529f88 Mon Sep 17 00:00:00 2001
1be5c7
From: Leonardo Bras <leobras@redhat.com>
1be5c7
Date: Mon, 20 Jun 2022 02:39:45 -0300
1be5c7
Subject: [PATCH 26/37] migration: Change zero_copy_send from migration
1be5c7
 parameter to migration capability
1be5c7
MIME-Version: 1.0
1be5c7
Content-Type: text/plain; charset=UTF-8
1be5c7
Content-Transfer-Encoding: 8bit
1be5c7
1be5c7
RH-Author: Leonardo Brás <leobras@redhat.com>
1be5c7
RH-MergeRequest: 191: MSG_ZEROCOPY + Multifd @ rhel8.7
1be5c7
RH-Commit: [26/26] ea61e6cbdbe47611bd22d18988e1c4c4e8357cc3
1be5c7
RH-Bugzilla: 2072049
1be5c7
RH-Acked-by: Peter Xu <peterx@redhat.com>
1be5c7
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
1be5c7
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1be5c7
1be5c7
When originally implemented, zero_copy_send was designed as a Migration
1be5c7
paramenter.
1be5c7
1be5c7
But taking into account how is that supposed to work, and how
1be5c7
the difference between a capability and a parameter, it only makes sense
1be5c7
that zero-copy-send would work better as a capability.
1be5c7
1be5c7
Taking into account how recently the change got merged, it was decided
1be5c7
that it's still time to make it right, and convert zero_copy_send into
1be5c7
a Migration capability.
1be5c7
1be5c7
Signed-off-by: Leonardo Bras <leobras@redhat.com>
1be5c7
Reviewed-by: Juan Quintela <quintela@redhat.com>
1be5c7
Acked-by: Markus Armbruster <armbru@redhat.com>
1be5c7
Acked-by: Peter Xu <peterx@redhat.com>
1be5c7
Signed-off-by: Juan Quintela <quintela@redhat.com>
1be5c7
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1be5c7
  dgilbert: always define the capability, even on non-Linux but error if
1be5c7
set; avoids build problems with the capability
1be5c7
(cherry picked from commit 1abaec9a1b2c23f7aa94709a422128d9e42c3e0b)
1be5c7
Signed-off-by: Leonardo Bras <leobras@redhat.com>
1be5c7
---
1be5c7
 migration/migration.c | 58 +++++++++++++++++++------------------------
1be5c7
 monitor/hmp-cmds.c    |  6 -----
1be5c7
 qapi/migration.json   | 33 +++++++-----------------
1be5c7
 3 files changed, 34 insertions(+), 63 deletions(-)
1be5c7
1be5c7
diff --git a/migration/migration.c b/migration/migration.c
1be5c7
index 5357efd348..c8aa55d2fe 100644
1be5c7
--- a/migration/migration.c
1be5c7
+++ b/migration/migration.c
1be5c7
@@ -162,7 +162,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
1be5c7
     MIGRATION_CAPABILITY_COMPRESS,
1be5c7
     MIGRATION_CAPABILITY_XBZRLE,
1be5c7
     MIGRATION_CAPABILITY_X_COLO,
1be5c7
-    MIGRATION_CAPABILITY_VALIDATE_UUID);
1be5c7
+    MIGRATION_CAPABILITY_VALIDATE_UUID,
1be5c7
+    MIGRATION_CAPABILITY_ZERO_COPY_SEND);
1be5c7
 
1be5c7
 bool migrate_pre_2_2;
1be5c7
 
1be5c7
@@ -888,10 +889,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
1be5c7
     params->multifd_zlib_level = s->parameters.multifd_zlib_level;
1be5c7
     params->has_multifd_zstd_level = true;
1be5c7
     params->multifd_zstd_level = s->parameters.multifd_zstd_level;
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    params->has_zero_copy_send = true;
1be5c7
-    params->zero_copy_send = s->parameters.zero_copy_send;
1be5c7
-#endif
1be5c7
     params->has_xbzrle_cache_size = true;
1be5c7
     params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
1be5c7
     params->has_max_postcopy_bandwidth = true;
1be5c7
@@ -1249,6 +1246,24 @@ static bool migrate_caps_check(bool *cap_list,
1be5c7
         }
1be5c7
     }
1be5c7
 
1be5c7
+#ifdef CONFIG_LINUX
1be5c7
+    if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND] &&
1be5c7
+        (!cap_list[MIGRATION_CAPABILITY_MULTIFD] ||
1be5c7
+         migrate_use_compression() ||
1be5c7
+         migrate_use_tls())) {
1be5c7
+        error_setg(errp,
1be5c7
+                   "Zero copy only available for non-compressed non-TLS multifd migration");
1be5c7
+        return false;
1be5c7
+    }
1be5c7
+#else
1be5c7
+    if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) {
1be5c7
+        error_setg(errp,
1be5c7
+                   "Zero copy currently only available on Linux");
1be5c7
+        return false;
1be5c7
+    }
1be5c7
+#endif
1be5c7
+
1be5c7
+
1be5c7
     /* incoming side only */
1be5c7
     if (runstate_check(RUN_STATE_INMIGRATE) &&
1be5c7
         !migrate_multifd_is_allowed() &&
1be5c7
@@ -1471,16 +1486,6 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)
1be5c7
         error_prepend(errp, "Invalid mapping given for block-bitmap-mapping: ");
1be5c7
         return false;
1be5c7
     }
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    if (params->zero_copy_send &&
1be5c7
-        (!migrate_use_multifd() ||
1be5c7
-         params->multifd_compression != MULTIFD_COMPRESSION_NONE ||
1be5c7
-         (params->tls_creds && *params->tls_creds))) {
1be5c7
-        error_setg(errp,
1be5c7
-                   "Zero copy only available for non-compressed non-TLS multifd migration");
1be5c7
-        return false;
1be5c7
-    }
1be5c7
-#endif
1be5c7
     return true;
1be5c7
 }
1be5c7
 
1be5c7
@@ -1554,11 +1559,6 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
1be5c7
     if (params->has_multifd_compression) {
1be5c7
         dest->multifd_compression = params->multifd_compression;
1be5c7
     }
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    if (params->has_zero_copy_send) {
1be5c7
-        dest->zero_copy_send = params->zero_copy_send;
1be5c7
-    }
1be5c7
-#endif
1be5c7
     if (params->has_xbzrle_cache_size) {
1be5c7
         dest->xbzrle_cache_size = params->xbzrle_cache_size;
1be5c7
     }
1be5c7
@@ -1671,11 +1671,6 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
1be5c7
     if (params->has_multifd_compression) {
1be5c7
         s->parameters.multifd_compression = params->multifd_compression;
1be5c7
     }
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    if (params->has_zero_copy_send) {
1be5c7
-        s->parameters.zero_copy_send = params->zero_copy_send;
1be5c7
-    }
1be5c7
-#endif
1be5c7
     if (params->has_xbzrle_cache_size) {
1be5c7
         s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
1be5c7
         xbzrle_cache_resize(params->xbzrle_cache_size, errp);
1be5c7
@@ -2573,7 +2568,7 @@ bool migrate_use_zero_copy_send(void)
1be5c7
 
1be5c7
     s = migrate_get_current();
1be5c7
 
1be5c7
-    return s->parameters.zero_copy_send;
1be5c7
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND];
1be5c7
 }
1be5c7
 #endif
1be5c7
 
1be5c7
@@ -4236,10 +4231,6 @@ static Property migration_properties[] = {
1be5c7
     DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState,
1be5c7
                       parameters.multifd_zstd_level,
1be5c7
                       DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL),
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    DEFINE_PROP_BOOL("zero_copy_send", MigrationState,
1be5c7
-                      parameters.zero_copy_send, false),
1be5c7
-#endif
1be5c7
     DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
1be5c7
                       parameters.xbzrle_cache_size,
1be5c7
                       DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE),
1be5c7
@@ -4277,6 +4268,10 @@ static Property migration_properties[] = {
1be5c7
     DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD),
1be5c7
     DEFINE_PROP_MIG_CAP("x-background-snapshot",
1be5c7
             MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT),
1be5c7
+#ifdef CONFIG_LINUX
1be5c7
+    DEFINE_PROP_MIG_CAP("x-zero-copy-send",
1be5c7
+            MIGRATION_CAPABILITY_ZERO_COPY_SEND),
1be5c7
+#endif
1be5c7
 
1be5c7
     DEFINE_PROP_END_OF_LIST(),
1be5c7
 };
1be5c7
@@ -4337,9 +4332,6 @@ static void migration_instance_init(Object *obj)
1be5c7
     params->has_multifd_compression = true;
1be5c7
     params->has_multifd_zlib_level = true;
1be5c7
     params->has_multifd_zstd_level = true;
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    params->has_zero_copy_send = true;
1be5c7
-#endif
1be5c7
     params->has_xbzrle_cache_size = true;
1be5c7
     params->has_max_postcopy_bandwidth = true;
1be5c7
     params->has_max_cpu_throttle = true;
1be5c7
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
1be5c7
index e02da5008b..2669156b28 100644
1be5c7
--- a/monitor/hmp-cmds.c
1be5c7
+++ b/monitor/hmp-cmds.c
1be5c7
@@ -1297,12 +1297,6 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1be5c7
         p->has_multifd_zstd_level = true;
1be5c7
         visit_type_uint8(v, param, &p->multifd_zstd_level, &err;;
1be5c7
         break;
1be5c7
-#ifdef CONFIG_LINUX
1be5c7
-    case MIGRATION_PARAMETER_ZERO_COPY_SEND:
1be5c7
-        p->has_zero_copy_send = true;
1be5c7
-        visit_type_bool(v, param, &p->zero_copy_send, &err;;
1be5c7
-        break;
1be5c7
-#endif
1be5c7
     case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1be5c7
         p->has_xbzrle_cache_size = true;
1be5c7
         if (!visit_type_size(v, param, &cache_size, &err)) {
1be5c7
diff --git a/qapi/migration.json b/qapi/migration.json
1be5c7
index 59b5c5780b..fe70a0c4b2 100644
1be5c7
--- a/qapi/migration.json
1be5c7
+++ b/qapi/migration.json
1be5c7
@@ -452,6 +452,13 @@
1be5c7
 #                       procedure starts. The VM RAM is saved with running VM.
1be5c7
 #                       (since 6.0)
1be5c7
 #
1be5c7
+# @zero-copy-send: Controls behavior on sending memory pages on migration.
1be5c7
+#                  When true, enables a zero-copy mechanism for sending
1be5c7
+#                  memory pages, if host supports it.
1be5c7
+#                  Requires that QEMU be permitted to use locked memory
1be5c7
+#                  for guest RAM pages.
1be5c7
+#                  (since 7.1)
1be5c7
+#
1be5c7
 # Features:
1be5c7
 # @unstable: Members @x-colo and @x-ignore-shared are experimental.
1be5c7
 #
1be5c7
@@ -465,7 +472,8 @@
1be5c7
            'block', 'return-path', 'pause-before-switchover', 'multifd',
1be5c7
            'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate',
1be5c7
            { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] },
1be5c7
-           'validate-uuid', 'background-snapshot'] }
1be5c7
+           'validate-uuid', 'background-snapshot',
1be5c7
+           'zero-copy-send'] }
1be5c7
 
1be5c7
 ##
1be5c7
 # @MigrationCapabilityStatus:
1be5c7
@@ -730,12 +738,6 @@
1be5c7
 #                      will consume more CPU.
1be5c7
 #                      Defaults to 1. (Since 5.0)
1be5c7
 #
1be5c7
-# @zero-copy-send: Controls behavior on sending memory pages on migration.
1be5c7
-#                  When true, enables a zero-copy mechanism for sending
1be5c7
-#                  memory pages, if host supports it.
1be5c7
-#                  Requires that QEMU be permitted to use locked memory
1be5c7
-#                  for guest RAM pages.
1be5c7
-#                  Defaults to false. (Since 7.1)
1be5c7
 #
1be5c7
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
1be5c7
 #                        aliases for the purpose of dirty bitmap migration.  Such
1be5c7
@@ -776,7 +778,6 @@
1be5c7
            'xbzrle-cache-size', 'max-postcopy-bandwidth',
1be5c7
            'max-cpu-throttle', 'multifd-compression',
1be5c7
            'multifd-zlib-level' ,'multifd-zstd-level',
1be5c7
-           { 'name': 'zero-copy-send', 'if' : 'CONFIG_LINUX'},
1be5c7
            'block-bitmap-mapping' ] }
1be5c7
 
1be5c7
 ##
1be5c7
@@ -903,13 +904,6 @@
1be5c7
 #                      will consume more CPU.
1be5c7
 #                      Defaults to 1. (Since 5.0)
1be5c7
 #
1be5c7
-# @zero-copy-send: Controls behavior on sending memory pages on migration.
1be5c7
-#                  When true, enables a zero-copy mechanism for sending
1be5c7
-#                  memory pages, if host supports it.
1be5c7
-#                  Requires that QEMU be permitted to use locked memory
1be5c7
-#                  for guest RAM pages.
1be5c7
-#                  Defaults to false. (Since 7.1)
1be5c7
-#
1be5c7
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
1be5c7
 #                        aliases for the purpose of dirty bitmap migration.  Such
1be5c7
 #                        aliases may for example be the corresponding names on the
1be5c7
@@ -964,7 +958,6 @@
1be5c7
             '*multifd-compression': 'MultiFDCompression',
1be5c7
             '*multifd-zlib-level': 'uint8',
1be5c7
             '*multifd-zstd-level': 'uint8',
1be5c7
-            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
1be5c7
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
1be5c7
 
1be5c7
 ##
1be5c7
@@ -1111,13 +1104,6 @@
1be5c7
 #                      will consume more CPU.
1be5c7
 #                      Defaults to 1. (Since 5.0)
1be5c7
 #
1be5c7
-# @zero-copy-send: Controls behavior on sending memory pages on migration.
1be5c7
-#                  When true, enables a zero-copy mechanism for sending
1be5c7
-#                  memory pages, if host supports it.
1be5c7
-#                  Requires that QEMU be permitted to use locked memory
1be5c7
-#                  for guest RAM pages.
1be5c7
-#                  Defaults to false. (Since 7.1)
1be5c7
-#
1be5c7
 # @block-bitmap-mapping: Maps block nodes and bitmaps on them to
1be5c7
 #                        aliases for the purpose of dirty bitmap migration.  Such
1be5c7
 #                        aliases may for example be the corresponding names on the
1be5c7
@@ -1170,7 +1156,6 @@
1be5c7
             '*multifd-compression': 'MultiFDCompression',
1be5c7
             '*multifd-zlib-level': 'uint8',
1be5c7
             '*multifd-zstd-level': 'uint8',
1be5c7
-            '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' },
1be5c7
             '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } }
1be5c7
 
1be5c7
 ##
1be5c7
-- 
1be5c7
2.35.3
1be5c7