Skip to contentSkip to conversation

migration: Introduce side channel for RAM

RFC PATCH Superseded Lei Li 2 participants 19 messages Sep 25, 2013 – Oct 3, 2013 Kbuild

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Lei Li

author
#0 lore raw

cover migration: Introduce side channel for RAM

This RFC patch series tries to introduce a mechanism using side channel pipe for RAM via SCM_RIGHTS with unix domain socket protocol migration.

This side channel will be used for the page flipping by vmsplice, which will be the internal mechanism for localhost migration that we are trying to add. The previous patch series for localhost migration as link,

http://lists.nongnu.org/archive/html/qemu-devel/2013-08/msg02916.html

After this series, will adjust the process of current migration for the localhost migration and involve the vmsplice based on the previous patch set as link above.

Please let me know if it is the proper way for it or there is anything need to be improved. Your suggestions and comments are very welcome, and thanks for Paolo for his review and useful suggestions.

Lei Li (8):
migration-local: add pipe protocol for QEMUFileOps
migration-local: add qemu_fopen_pipe()
migration-local: add send_pipefd()
migration-local: add recv_pipefd()
QAPI: introduce magration capability unix_page_flipping
migration: add migrate_unix_page_flipping()
migration-unix: side channel support on unix outgoing
migration-unix: side channel support on unix incoming

 Makefile.target               |    1 +
 include/migration/migration.h |    3 +
 include/migration/qemu-file.h |    4 +
 migration-local.c             |  247 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   48 +++++++-
 migration.c                   |    9 ++
 qapi-schema.json              |    8 +-
 7 files changed, 315 insertions(+), 5 deletions(-)
 create mode 100644 migration-local.c
author
#1 lore raw

PATCH 1/8 migration-local: add pipe protocol for QEMUFileOps

This patch adds QEMUFileOps with pipe protocol, will be used to transmit RAM for localhost migration. The source process would put buffer, correspondingly the destination process would get buffer. The read side of the pipe file descriptor would be passed to destination process via SCM_RIGHTS.

---
 Makefile.target   |    1 +
 migration-local.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 migration-local.c
Makefile.target +1 -0
index 9a49852..ae66fef 100644
@@ -121,6 +121,7 @@ obj-$(CONFIG_KVM) += kvm-all.o
 obj-y += memory.o savevm.o cputlb.o
 obj-y += memory_mapping.o
 obj-y += dump.o
+obj-y += migration-local.o
 LIBS+=$(libs_softmmu)
 
 # xen support
migration-local.c new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#3 lore raw

PATCH 3/8 migration-local: add send_pipefd()

In reply to Lei Li

This patch adds send_pipefd() to pass the pipe file descriptor to destination process.

---
 include/migration/qemu-file.h |    1 +
 migration-local.c             |   57 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
include/migration/qemu-file.h +1 -0
index 39ad0bd..5fad65f 100644
@@ -101,6 +101,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 QEMUFile *qemu_fopen_pipe(int sockfd, const char *mode);
 
+int send_pipefd(int sockfd, int pipefd);
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
migration-local.c +57 -0

60 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#4 lore raw

PATCH 4/8 migration-local: add recv_pipefd()

In reply to Lei Li

This patch adds recv_pipefd() to receive the pipe file descriptor that passed by source process.

---
 include/migration/qemu-file.h |    1 +
 migration-local.c             |   56 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)
include/migration/qemu-file.h +1 -0
index 5fad65f..e4df258 100644
@@ -102,6 +102,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
 QEMUFile *qemu_fopen_pipe(int sockfd, const char *mode);
 
 int send_pipefd(int sockfd, int pipefd);
+int recv_pipefd(int sockfd);
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
migration-local.c +56 -0

59 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#5 lore raw

PATCH 5/8 QAPI: introduce magration capability unix_page_flipping

In reply to Lei Li

Introduce unix_page_flipping to MigrationCapability for localhost migration.

---
 qapi-schema.json |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
qapi-schema.json +7 -1
index 145eca8..f63dab4 100644
@@ -629,10 +629,16 @@
 # @auto-converge: If enabled, QEMU will automatically throttle down the guest
 #          to speed up convergence of RAM migration. (since 1.6)
 #
+# @unix-page-flipping: If enabled, QEMU will support localhost migration. This
+#          feature allows live upgrade of a running QEMU instance by doing localhost
+#          migration with page flipping. It requires the source and destination
+#          are both on localhost. Disabled by default. (since 1.7)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
-  'data': ['xbzrle', 'x-rdma-pin-all', 'auto-converge', 'zero-blocks'] }
+  'data': ['xbzrle', 'x-rdma-pin-all', 'auto-converge', 'zero-blocks',
+           'unix-page-flipping'] }
 
 ##
 # @MigrationCapabilityStatus
Signature · 1 line
1.7.7.6
author
#6 lore raw

PATCH 6/8 migration: add migrate_unix_page_flipping()

In reply to Lei Li

Add migrate_unix_page_flipping() to check if MIGRATION_CAPABILITY_UNIX_PAGE_FLIPPING is enabled.

---
 include/migration/migration.h |    3 +++
 migration.c                   |    9 +++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)
include/migration/migration.h +3 -0
index 140e6b4..7e5d01a 100644
@@ -131,10 +131,13 @@ void migrate_add_blocker(Error *reason);
 void migrate_del_blocker(Error *reason);
 
 bool migrate_rdma_pin_all(void);
+
 bool migrate_zero_blocks(void);
 
 bool migrate_auto_converge(void);
 
+bool migrate_unix_page_flipping(void);
+
 int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
 int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
migration.c +9 -0
index 200d404..825a455 100644
@@ -540,6 +540,15 @@ int64_t migrate_xbzrle_cache_size(void)
     return s->xbzrle_cache_size;
 }
 
+bool migrate_unix_page_flipping(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_UNIX_PAGE_FLIPPING];
+}
+
 /* migration thread support */
 
 static void *migration_thread(void *opaque)
Signature · 1 line
1.7.7.6
author
#7 lore raw

PATCH 7/8 migration-unix: side channel support on unix outgoing

In reply to Lei Li

This patch adds side channel support on the outgoing of unix migration. It will create a pipe and pass the read pipe fd to destination process by send_pipefd(). If the pipe fd was passed successfully, the qemu_fopen_pipe will be called with write mode to send RAM to the write pipe fd.

---
 migration-unix.c |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)
migration-unix.c +31 -3
index 651fc5b..0bfc1c7 100644
@@ -33,16 +33,44 @@
 static void unix_wait_for_connect(int fd, void *opaque)
 {
     MigrationState *s = opaque;
+    int pipefd[2];
 
     if (fd < 0) {
         DPRINTF("migrate connect error\n");
-        s->file = NULL;
-        migrate_fd_error(s);
+        goto fail;
     } else {
         DPRINTF("migrate connect success\n");
-        s->file = qemu_fopen_socket(fd, "wb");
+
+        if (s->enabled_capabilities[MIGRATION_CAPABILITY_UNIX_PAGE_FLIPPING]) {
+            if (pipe(pipefd) < 0) {
+                DPRINTF("qemu_fopen_pipe: %s", strerror(errno));
+                goto fail;
+            }
+
+            /* Send pipefd[0] to destination QEMU process */
+            if (send_pipefd(fd, pipefd[0]) < 0) {
+                DPRINTF("failed to pass pipe\n");
+                goto fail;
+            }
+
+            s->file = qemu_fopen_pipe(pipefd[1], "w");
+        } else {
+            s->file = qemu_fopen_socket(fd, "wb");
+        }
+
+        if (s->file == NULL) {
+            DPRINTF("failed to open migration target");
+            migrate_fd_error(s);
+            return;
+        }
+
         migrate_fd_connect(s);
+        return;
     }
+
+fail:
+    s->file = NULL;
+    migrate_fd_error(s);
 }
 
 void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp)
Signature · 1 line
1.7.7.6
author
#8 lore raw

PATCH 8/8 migration-unix: side channel support on unix incoming

In reply to Lei Li

Add side channel support on incoming part of unix migration to enable localhost migration with page flipping approach. If there is a pipe available by checking recv_pipefd(), it will fetch the pipe file descriptor and open it by qemu_fopen_pipe() with read mode for the pipe protocol introduced.

---
 migration-unix.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
migration-unix.c +13 -1
index 0bfc1c7..878e063 100644
@@ -85,6 +85,7 @@ static void unix_accept_incoming_migration(void *opaque)
     int s = (intptr_t)opaque;
     QEMUFile *f;
     int c;
+    int pipefd;
 
     do {
         c = qemu_accept(s, (struct sockaddr *)&addr, &addrlen);
@@ -99,7 +100,18 @@ static void unix_accept_incoming_migration(void *opaque)
         goto out;
     }
 
-    f = qemu_fopen_socket(c, "rb");
+    /* Check if there is a pipe fd to be recevied for a page-flipping
+     * migration */
+
+    pipefd = recv_pipefd(c);
+    if (pipefd > 0) {
+        DPRINTF("receive pipe file descriptor successfully\n");
+
+        f = qemu_fopen_pipe(pipefd, "r");
+    } else {
+        f = qemu_fopen_socket(c, "rb");
+    }
+
     if (f == NULL) {
         fprintf(stderr, "could not qemu_fopen socket\n");
         goto out;
Signature · 1 line
1.7.7.6
author
#2 lore raw

PATCH 2/8 migration-loca: add qemu_fopen_pipe()

In reply to Lei Li

Add qemu_fopen_pipe() to open QEMUFileOps pipe_write_ops and pipe_read_ops introduced for pipe protocol.

---
 include/migration/qemu-file.h |    2 ++
 migration-local.c             |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)
include/migration/qemu-file.h +2 -0
index 0f757fb..39ad0bd 100644
@@ -99,6 +99,8 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode);
 QEMUFile *qemu_fdopen(int fd, const char *mode);
 QEMUFile *qemu_fopen_socket(int fd, const char *mode);
 QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
+QEMUFile *qemu_fopen_pipe(int sockfd, const char *mode);
+
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
migration-local.c +20 -0
index 1fb62b6..d90b2ff 100644
@@ -112,3 +112,23 @@ static const QEMUFileOps pipe_write_ops = {
     //.save_page  = qemu_local_save_ram,
     .close      = qemu_local_close
 };
+
+QEMUFile *qemu_fopen_pipe(int pipefd, const char *mode)
+{
+    QEMUFilePipe *s;
+
+    if (qemu_file_mode_is_not_valid(mode)) {
+        return NULL;
+    }
+
+    s = g_malloc0(sizeof(QEMUFilePipe));
+    s->pipefd = pipefd;
+
+    if (mode[0] == 'w') {
+        s->file = qemu_fopen_ops(s, &pipe_write_ops);
+    } else {
+        s->file = qemu_fopen_ops(s, &pipe_read_ops);
+    }
+
+    return s->file;
+}
Signature · 1 line
1.7.7.6
#9 lore raw
In reply to Lei Li

Il 25/09/2013 16:32, Lei Li ha scritto:

Quoted 30 lines

This RFC patch series tries to introduce a mechanism using side channel pipe for RAM via SCM_RIGHTS with unix domain socket protocol migration.

This side channel will be used for the page flipping by vmsplice, which will be the internal mechanism for localhost migration that we are trying to add. The previous patch series for localhost migration as link,

http://lists.nongnu.org/archive/html/qemu-devel/2013-08/msg02916.html

After this series, will adjust the process of current migration for the localhost migration and involve the vmsplice based on the previous patch set as link above.

Please let me know if it is the proper way for it or there is anything need to be improved. Your suggestions and comments are very welcome, and thanks for Paolo for his review and useful suggestions.

Lei Li (8):
migration-local: add pipe protocol for QEMUFileOps
migration-local: add qemu_fopen_pipe()
migration-local: add send_pipefd()
migration-local: add recv_pipefd()
QAPI: introduce magration capability unix_page_flipping
migration: add migrate_unix_page_flipping()
migration-unix: side channel support on unix outgoing
migration-unix: side channel support on unix incoming

Quoted 10 lines
 Makefile.target               |    1 +
 include/migration/migration.h |    3 +
 include/migration/qemu-file.h |    4 +
 migration-local.c             |  247 +++++++++++++++++++++++++++++++++++++++++
 migration-unix.c              |   48 +++++++-
 migration.c                   |    9 ++
 qapi-schema.json              |    8 +-
 7 files changed, 315 insertions(+), 5 deletions(-)
 create mode 100644 migration-local.c

Yes, this is much closer!

There are two problems to be fixed, but it is getting there.

First, it breaks migration from old QEMU to new QEMU, and also migration where the source uses "unix:" and the destination uses "fd:" migration (this should work as long as page flipping is disabled). The problem is that recv_pipefd() "eats" one byte, and old versions of QEMU do not send that byte.

The second problem is that you are not really using a side channel; you are still using the QEMUFile and relying on the normal migration code to send pages on the pipe. This will not be possible when you use vmsplice.

Both problems can be addressed with a single change in your approach:
always use the Unix socket QEMUFile but, if page flipping is enabled, only transmit page addresses on the socket; page data will be on the pipe. You can use hooks such as before_ram_iterate, save_page and hook_ram_load to do all your customizations: send the pipe file descriptor, read the pipe file descriptor, and use the pipe as a side channel.

To fix the first problem, you can use the before_ram_iterate callback to send the fd, and the hook_ram_load callback to receive it. The before_ram_iterate callback can write a special 8-byte record (with the RAM_SAVE_FLAG_HOOK set) that will trigger the hook, followed by send_pipefd(). The load_hook callback is called after the first 8-byte record is sent, and can just do recv_pipefd().

To fix the second problem, and really use the pipe as a side channel, you can use the save_page QEMUFile callback on the send side. This callback must return RAM_SAVE_CONTROL_NOT_SUPP if page flipping is disabled. If it is enabled, it should write another 8-byte record with the RAM_SAVE_FLAG_HOOK bit, this time with the address of the page on the Unix socket; then write the page data on the pipe, and return 0. On the receive side, the 8-byte page address will once more cause the load_hook callback to be called. This time you already have a file descriptor, so you do not need to call recv_pipefd(): you just extract the page address from the 8-byte record and read the page data from the pipe.

The basis of your code will still be the socket-based QEMUFile, but you'll need your own QEMUFile since you're adding Unix-specific functionality. For this it is not a problem to have two copies the QEMUFile code for sockets, one in savevm.c and one in migration-unix.c.
It's a very small amount of code.

Paolo

author
#10 lore raw
Quoted 43 lines · Paolo Bonzini

Il 25/09/2013 16:32, Lei Li ha scritto:

Quoted 38 lines

This RFC patch series tries to introduce a mechanism using side channel pipe for RAM via SCM_RIGHTS with unix domain socket protocol migration.

This side channel will be used for the page flipping by vmsplice, which will be the internal mechanism for localhost migration that we are trying to add. The previous patch series for localhost migration as link,

http://lists.nongnu.org/archive/html/qemu-devel/2013-08/msg02916.html

After this series, will adjust the process of current migration for the localhost migration and involve the vmsplice based on the previous patch set as link above.

Please let me know if it is the proper way for it or there is anything need to be improved. Your suggestions and comments are very welcome, and thanks for Paolo for his review and useful suggestions.

Lei Li (8):
migration-local: add pipe protocol for QEMUFileOps
migration-local: add qemu_fopen_pipe()
migration-local: add send_pipefd()
migration-local: add recv_pipefd()
QAPI: introduce magration capability unix_page_flipping
migration: add migrate_unix_page_flipping()
migration-unix: side channel support on unix outgoing
migration-unix: side channel support on unix incoming

  Makefile.target               |    1 +
  include/migration/migration.h |    3 +
  include/migration/qemu-file.h |    4 +
  migration-local.c             |  247 +++++++++++++++++++++++++++++++++++++++++
  migration-unix.c              |   48 +++++++-
  migration.c                   |    9 ++
  qapi-schema.json              |    8 +-
  7 files changed, 315 insertions(+), 5 deletions(-)
Quoted 2 lines

create mode 100644 migration-local.c

Yes, this is much closer!

Quoted 7 lines

There are two problems to be fixed, but it is getting there.

First, it breaks migration from old QEMU to new QEMU, and also migration where the source uses "unix:" and the destination uses "fd:" migration (this should work as long as page flipping is disabled). The problem is that recv_pipefd() "eats" one byte, and old versions of QEMU do not send that byte.

Hi Paolo,

I didn't consider this, thanks for pointing it out!

Quoted 3 lines

The second problem is that you are not really using a side channel; you are still using the QEMUFile and relying on the normal migration code to send pages on the pipe. This will not be possible when you use vmsplice.

Yes, you are right, and I am trying to involve the vmsplice.

Quoted 16 lines

Both problems can be addressed with a single change in your approach:
always use the Unix socket QEMUFile but, if page flipping is enabled, only transmit page addresses on the socket; page data will be on the pipe. You can use hooks such as before_ram_iterate, save_page and hook_ram_load to do all your customizations: send the pipe file descriptor, read the pipe file descriptor, and use the pipe as a side channel.

To fix the first problem, you can use the before_ram_iterate callback to send the fd, and the hook_ram_load callback to receive it. The before_ram_iterate callback can write a special 8-byte record (with the RAM_SAVE_FLAG_HOOK set) that will trigger the hook, followed by send_pipefd(). The load_hook callback is called after the first 8-byte record is sent, and can just do recv_pipefd().

Quoted 11 lines

To fix the second problem, and really use the pipe as a side channel, you can use the save_page QEMUFile callback on the send side. This callback must return RAM_SAVE_CONTROL_NOT_SUPP if page flipping is disabled. If it is enabled, it should write another 8-byte record with the RAM_SAVE_FLAG_HOOK bit, this time with the address of the page on the Unix socket; then write the page data on the pipe, and return 0. On the receive side, the 8-byte page address will once more cause the load_hook callback to be called. This time you already have a file descriptor, so you do not need to call recv_pipefd(): you just extract the page address from the 8-byte record and read the page data from the pipe.

Thanks for your comprehensive suggestions, really nice ideas!

Quoted 5 lines

The basis of your code will still be the socket-based QEMUFile, but you'll need your own QEMUFile since you're adding Unix-specific functionality. For this it is not a problem to have two copies the QEMUFile code for sockets, one in savevm.c and one in migration-unix.c.

Have two copies of the QEMUFile code for sockets, do you mean in my own QEMUFile, say QEMUFilePipe, includes both the copy of QEMUFileSocket code (like get_fd, get_buffer, writev_buffer..) and the Unix-specific functionality code that override these three hooks like your suggestions above?

I guess 'migration-unix.c' you typed is 'migration-local.c', right?

Quoted 4 lines

It's a very small amount of code.

Paolo

Signature · 1 line
Lei
#11 lore raw

Il 26/09/2013 14:44, Lei Li ha scritto:

Quoted 11 lines
Quoted 5 lines

The basis of your code will still be the socket-based QEMUFile, but you'll need your own QEMUFile since you're adding Unix-specific functionality. For this it is not a problem to have two copies the QEMUFile code for sockets, one in savevm.c and one in migration-unix.c.

Have two copies of the QEMUFile code for sockets, do you mean in my own QEMUFile, say QEMUFilePipe, includes both the copy of QEMUFileSocket code (like get_fd, get_buffer, writev_buffer..) and the Unix-specific functionality code that override these three hooks like your suggestions above?

Yes (the name could be either QEMUFilePipe or QEMUFileUnix, I guess).

Quoted 1 line

I guess 'migration-unix.c' you typed is 'migration-local.c', right?

I wasn't sure of the reason why 'migration-unix.c' and 'migration-local.c' were split, since now the choice is done with a capability rather than a different protocol.

Thanks,

Paolo

author
#12 lore raw
In reply to Lei Li
Quoted 55 lines · Lei Li
Quoted 44 lines · Paolo Bonzini

Il 25/09/2013 16:32, Lei Li ha scritto:

Quoted 39 lines

This RFC patch series tries to introduce a mechanism using side channel pipe for RAM via SCM_RIGHTS with unix domain socket protocol migration.

This side channel will be used for the page flipping by vmsplice, which will be the internal mechanism for localhost migration that we are trying to add. The previous patch series for localhost migration as link,

http://lists.nongnu.org/archive/html/qemu-devel/2013-08/msg02916.html

After this series, will adjust the process of current migration for the localhost migration and involve the vmsplice based on the previous patch set as link above.

Please let me know if it is the proper way for it or there is anything need to be improved. Your suggestions and comments are very welcome, and thanks for Paolo for his review and useful suggestions.

Lei Li (8):
migration-local: add pipe protocol for QEMUFileOps
migration-local: add qemu_fopen_pipe()
migration-local: add send_pipefd()
migration-local: add recv_pipefd()
QAPI: introduce magration capability unix_page_flipping
migration: add migrate_unix_page_flipping()
migration-unix: side channel support on unix outgoing
migration-unix: side channel support on unix incoming

  Makefile.target               |    1 +
  include/migration/migration.h |    3 +
  include/migration/qemu-file.h |    4 +
  migration-local.c             |  247 
+++++++++++++++++++++++++++++++++++++++++
  migration-unix.c              |   48 +++++++-
  migration.c                   |    9 ++
  qapi-schema.json              |    8 +-
  7 files changed, 315 insertions(+), 5 deletions(-)
Quoted 2 lines

create mode 100644 migration-local.c

Yes, this is much closer!

Quoted 7 lines

There are two problems to be fixed, but it is getting there.

First, it breaks migration from old QEMU to new QEMU, and also migration where the source uses "unix:" and the destination uses "fd:" migration (this should work as long as page flipping is disabled). The problem is that recv_pipefd() "eats" one byte, and old versions of QEMU do not send that byte.

Hi Paolo,

Quoted 23 lines

I didn't consider this, thanks for pointing it out!

Quoted 3 lines

The second problem is that you are not really using a side channel; you are still using the QEMUFile and relying on the normal migration code to send pages on the pipe. This will not be possible when you use vmsplice.

Yes, you are right, and I am trying to involve the vmsplice.

Quoted 15 lines

Both problems can be addressed with a single change in your approach:
always use the Unix socket QEMUFile but, if page flipping is enabled, only transmit page addresses on the socket; page data will be on the pipe. You can use hooks such as before_ram_iterate, save_page and hook_ram_load to do all your customizations: send the pipe file descriptor, read the pipe file descriptor, and use the pipe as a side channel.

To fix the first problem, you can use the before_ram_iterate callback to send the fd, and the hook_ram_load callback to receive it. The before_ram_iterate callback can write a special 8-byte record (with the RAM_SAVE_FLAG_HOOK set) that will trigger the hook, followed by send_pipefd(). The load_hook callback is called after the first 8-byte record is sent, and can just do recv_pipefd().

Hi Paolo,

When debugging the code, I realized that this problem might still exist. In the incoming part, it will qemu_fopen_pipe() in unix_accept_incoming_migration first to enable the load_hook callback, the check action of this RAM_SAVE_FLAG_HOOK flags would lead to 8 bytes taken. Turns out, it will break normal unix migration (without unix-page-flipping), because no matter normal unix migration or unix-page-flipping migration, the incoming side has to check this 8-byes flags first to decide whether the load_hook is called, and normal unix migration did not send this 8-byte flags.

I wonder if I didn't understand your suggestion correctly?

Quoted 35 lines
Quoted 12 lines

To fix the second problem, and really use the pipe as a side channel, you can use the save_page QEMUFile callback on the send side. This callback must return RAM_SAVE_CONTROL_NOT_SUPP if page flipping is disabled. If it is enabled, it should write another 8-byte record with the RAM_SAVE_FLAG_HOOK bit, this time with the address of the page on the Unix socket; then write the page data on the pipe, and return 0. On the receive side, the 8-byte page address will once more cause the load_hook callback to be called. This time you already have a file descriptor, so you do not need to call recv_pipefd(): you just extract the page address from the 8-byte record and read the page data from the pipe.

Thanks for your comprehensive suggestions, really nice ideas!

Quoted 5 lines

The basis of your code will still be the socket-based QEMUFile, but you'll need your own QEMUFile since you're adding Unix-specific functionality. For this it is not a problem to have two copies the QEMUFile code for sockets, one in savevm.c and one in migration-unix.c.

Have two copies of the QEMUFile code for sockets, do you mean in my own QEMUFile, say QEMUFilePipe, includes both the copy of QEMUFileSocket code (like get_fd, get_buffer, writev_buffer..) and the Unix-specific functionality code that override these three hooks like your suggestions above?

I guess 'migration-unix.c' you typed is 'migration-local.c', right?

Quoted 4 lines

It's a very small amount of code.

Paolo

Signature · 1 line
Lei
#13 lore raw

Il 03/10/2013 06:03, Lei Li ha scritto:

Quoted 4 lines
Quoted 1 line
Quoted 1 line

Hi Paolo,

Quoted 9 lines

When debugging the code, I realized that this problem might still exist. In the incoming part, it will qemu_fopen_pipe() in unix_accept_incoming_migration first to enable the load_hook callback, the check action of this RAM_SAVE_FLAG_HOOK flags would lead to 8 bytes taken. Turns out, it will break normal unix migration (without unix-page-flipping), because no matter normal unix migration or unix-page-flipping migration, the incoming side has to check this 8-byes flags first to decide whether the load_hook is called, and normal unix migration did not send this 8-byte flags.

Why is the load_hook callback being called at all without page flipping?
Without page flipping, the before_iterate and save_page hook will
return immediately (or depending on your code they may never be called), so the RAM_SAVE_FLAG_HOOK will never be written to the Unix socket.

Quoted 1 line

I wonder if I didn't understand your suggestion correctly?

Perhaps you want to discuss this tomorrow morning on #qemu?

Paolo

author
#14 lore raw
Quoted 12 lines · Paolo Bonzini

Il 03/10/2013 06:03, Lei Li ha scritto:

Quoted 11 lines

Hi Paolo,

When debugging the code, I realized that this problem might still exist. In the incoming part, it will qemu_fopen_pipe() in unix_accept_incoming_migration first to enable the load_hook callback, the check action of this RAM_SAVE_FLAG_HOOK flags would lead to 8 bytes taken. Turns out, it will break normal unix migration (without unix-page-flipping), because no matter normal unix migration or unix-page-flipping migration, the incoming side has to check this 8-byes flags first to decide whether the load_hook is called, and normal unix migration did not send this 8-byte flags.

Quoted 4 lines

Why is the load_hook callback being called at all without page flipping?
Without page flipping, the before_iterate and save_page hook will
return immediately (or depending on your code they may never be called), so the RAM_SAVE_FLAG_HOOK will never be written to the Unix socket.

The load_hook callback is only be called if the RAM_SAVE_FLAG_HOOK is received. To check this flags, it means there would be a check action first in unix_accept_incoming_migration(), like:

f = qemu_fopen_pipe(c, "rb");
flags = qemu_get_be64(f);

if (flags == RAM_SAVE_FLAG_HOOK) {
    load_hook();
    ...
}

Otherwise, the incoming side has no idea whether the special 8-bytes record (RAM_SAVE_FLAG_HOOK) is sent.

In unix-page-flipping migration, it is OK. Without page flipping, since the RAM_SAVE_FLAG_HOOK is not be written to the Unix socket, but the incoming side will still check it, that will lead to the unexpected 8-bytes taken.

If the logic and the way to deal with it above is correct according to your suggestion, how about:

1) Use another Unix socket to deal with this flags and pipe fd passing. or 2) Use a new prefix URI for the incoming.

Quoted 3 lines
Quoted 2 lines

I wonder if I didn't understand your suggestion correctly?

Perhaps you want to discuss this tomorrow morning on #qemu?

I joined the #qemu channel just now, seems you were not there. I guess it's your lunch time right now. :)

Quoted 3 lines

Paolo

Signature · 1 line
Lei
#15 lore raw

Il 03/10/2013 12:28, Lei Li ha scritto:

Quoted 8 lines

The load_hook callback is only be called if the RAM_SAVE_FLAG_HOOK is received.
To check this flags, it means there would be a check action first in unix_accept_incoming_migration(), like:

f = qemu_fopen_pipe(c, "rb");
flags = qemu_get_be64(f);

Quoted 7 lines
if (flags == RAM_SAVE_FLAG_HOOK) {
    load_hook();
    ...
}

Otherwise, the incoming side has no idea whether the special 8-bytes record (RAM_SAVE_FLAG_HOOK) is sent.

No, ram_load is taking care of checking for RAM_SAVE_FLAG_HOOK. If before_iterate writes the 8 bytes (followed by passing the fd for the pipe's read-side via SCM_RIGHTS), ram_load will call load_hook before it loads any page and load_hook will fetch the fd.

Subsequent calls to load_hook will match data written by the sender's save_page hook (so they contain a RAM address, with the 4k page data sent on the pipe).

Paolo

author
#16 lore raw
Quoted 13 lines · Paolo Bonzini

Il 03/10/2013 12:28, Lei Li ha scritto:

Quoted 12 lines

The load_hook callback is only be called if the RAM_SAVE_FLAG_HOOK is received.
To check this flags, it means there would be a check action first in unix_accept_incoming_migration(), like:

f = qemu_fopen_pipe(c, "rb");
flags = qemu_get_be64(f);

if (flags == RAM_SAVE_FLAG_HOOK) {
     load_hook();
     ...
}
Quoted 6 lines
Quoted 2 lines

Otherwise, the incoming side has no idea whether the special 8-bytes record (RAM_SAVE_FLAG_HOOK) is sent.

No, ram_load is taking care of checking for RAM_SAVE_FLAG_HOOK. If before_iterate writes the 8 bytes (followed by passing the fd for the pipe's read-side via SCM_RIGHTS), ram_load will call load_hook before it loads any page and load_hook will fetch the fd.

If let ram_load take care of checking for RAM_SAVE_FLAG_HOOK, then in unix_accept_incoming_migration(), how to decide which QEMUFile should be opened? Since there would be two types of QEMUFile, one is the original QEMUFile opened by qemu_fopen_socket() for normal Unix migration, the other is opened by qemu_fopen_pipe() for unix-page-flipping migration.

Or, were you suggesting replace this qemu_fopen_socket() with the qemu_fopen_pipe(), which also contain the copy of the QEMUFile code for Unix sockets?

Quoted 7 lines

Subsequent calls to load_hook will match data written by the sender's save_page hook (so they contain a RAM address, with the 4k page data sent on the pipe).

Paolo

Signature · 1 line
Lei
#17 lore raw

Il 03/10/2013 15:29, Lei Li ha scritto:

Quoted 28 lines · Paolo Bonzini
Quoted 13 lines

Il 03/10/2013 12:28, Lei Li ha scritto:

Quoted 12 lines

The load_hook callback is only be called if the RAM_SAVE_FLAG_HOOK is received.
To check this flags, it means there would be a check action first in unix_accept_incoming_migration(), like:

f = qemu_fopen_pipe(c, "rb");
flags = qemu_get_be64(f);

if (flags == RAM_SAVE_FLAG_HOOK) {
     load_hook();
     ...
}
Quoted 7 lines
Quoted 3 lines

Otherwise, the incoming side has no idea whether the special 8-bytes record
(RAM_SAVE_FLAG_HOOK) is sent.

No, ram_load is taking care of checking for RAM_SAVE_FLAG_HOOK. If before_iterate writes the 8 bytes (followed by passing the fd for the pipe's read-side via SCM_RIGHTS), ram_load will call load_hook before it loads any page and load_hook will fetch the fd.

If let ram_load take care of checking for RAM_SAVE_FLAG_HOOK, then in unix_accept_incoming_migration(), how to decide which QEMUFile should be opened? Since there would be two types of QEMUFile, one is the original QEMUFile opened by qemu_fopen_socket() for normal Unix migration, the other is opened by qemu_fopen_pipe() for unix-page-flipping migration.

Quoted 3 lines

Or, were you suggesting replace this qemu_fopen_socket() with the qemu_fopen_pipe(), which also contain the copy of the QEMUFile code for Unix sockets?

Yes (though I'd call it qemu_fopen_socket_local() or something like that).

On the incoming side, if non-page-flipping was enabled you will use the normal RAM loading code, if page-flipping was enabled you will get load_hook calls.

Paolo

Quoted 9 lines
Quoted 7 lines

Subsequent calls to load_hook will match data written by the sender's save_page hook (so they contain a RAM address, with the 4k page data sent on the pipe).

Paolo

author
#18 lore raw
Quoted 28 lines · Paolo Bonzini

Il 03/10/2013 15:29, Lei Li ha scritto:

Quoted 27 lines · Paolo Bonzini
Quoted 13 lines

Il 03/10/2013 12:28, Lei Li ha scritto:

Quoted 12 lines

The load_hook callback is only be called if the RAM_SAVE_FLAG_HOOK is received.
To check this flags, it means there would be a check action first in unix_accept_incoming_migration(), like:

f = qemu_fopen_pipe(c, "rb");
flags = qemu_get_be64(f);

if (flags == RAM_SAVE_FLAG_HOOK) {
      load_hook();
      ...
}
Quoted 7 lines
Quoted 3 lines

Otherwise, the incoming side has no idea whether the special 8-bytes record
(RAM_SAVE_FLAG_HOOK) is sent.

No, ram_load is taking care of checking for RAM_SAVE_FLAG_HOOK. If before_iterate writes the 8 bytes (followed by passing the fd for the pipe's read-side via SCM_RIGHTS), ram_load will call load_hook before it loads any page and load_hook will fetch the fd.

If let ram_load take care of checking for RAM_SAVE_FLAG_HOOK, then in unix_accept_incoming_migration(), how to decide which QEMUFile should be opened? Since there would be two types of QEMUFile, one is the original QEMUFile opened by qemu_fopen_socket() for normal Unix migration, the other is opened by qemu_fopen_pipe() for unix-page-flipping migration.

Quoted 8 lines
Quoted 3 lines

Or, were you suggesting replace this qemu_fopen_socket() with the qemu_fopen_pipe(), which also contain the copy of the QEMUFile code for Unix sockets?

Yes (though I'd call it qemu_fopen_socket_local() or something like that).

On the incoming side, if non-page-flipping was enabled you will use the normal RAM loading code, if page-flipping was enabled you will get load_hook calls.

Ah, I see. :)
qemu_fopen_socket_local() sounds good, thanks!

Quoted 9 lines

Paolo

Quoted 7 lines
Quoted 6 lines

Subsequent calls to load_hook will match data written by the sender's save_page hook (so they contain a RAM address, with the 4k page data sent on the pipe).

Paolo

Signature · 1 line
Lei