Skip to contentSkip to conversation

ahci: enable migration

PATCH Superseded John Snow 2 participants 9 messages Feb 24, 2015 – Feb 26, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/5 libqos: Add migration helpers

In reply to John Snow

libqos.c:
-set_context for addressing which commands go where -migrate performs the actual migration

malloc.c:
- Structure of the allocator is adjusted slightly with
a second-tier malloc to make swapping around the allocators easy when we "migrate" the lists from the source to the destination.

---
 tests/libqos/libqos.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/libqos.h |  2 ++
 tests/libqos/malloc.c | 74 ++++++++++++++++++++++++++++++++++++++------------
 tests/libqos/malloc.h |  1 +
 4 files changed, 135 insertions(+), 17 deletions(-)
tests/libqos/libqos.c +75 -0
index 1a54a32..4602032 100644
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <glib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -62,6 +63,80 @@ void qtest_shutdown(QOSState *qs)
     g_free(qs);
 }
 
+void set_context(QOSState *s)
+{
+    global_qtest = s->qts;
+}
+
+static QDict *qmp_execute(const char *command)
+{
+    char *fmt;
+    QDict *rsp;
+
+    fmt = g_strdup_printf("{ 'execute': '%s' }", command);
+    rsp = qmp(fmt);
+    g_free(fmt);
+
+    return rsp;
+}
+
+void migrate(QOSState *from, QOSState *to)
+{
+    const char *s, *st;
+    QDict *rsp, *sub;
+    bool running;
+
+    set_context(from);
+
+    /* Is the machine currently running? */
+    rsp = qmp_execute("query-status");
+    g_assert(qdict_haskey(rsp, "return"));
+    sub = qdict_get_qdict(rsp, "return");
+    g_assert(qdict_haskey(sub, "running"));
+    running = qdict_get_bool(sub, "running");
+    QDECREF(rsp);
+
+    /* Issue the migrate command. */
+    s = "{ 'execute': 'migrate', 'arguments': { 'uri': 'tcp:127.0.0.1:1234' } }";
+    rsp = qmp(s);
+    g_assert(qdict_haskey(rsp, "return"));
+    QDECREF(rsp);
+
+    /* Wait for STOP event, but only if we were running: */
+    if (running) {
+        qmp_eventwait("STOP");
+    }
+
+    /* Poll until migration is completed. */
+    while (1) {
+        rsp = qmp_execute("query-migrate");
+        g_assert(qdict_haskey(rsp, "return"));
+        sub = qdict_get_qdict(rsp, "return");
+        g_assert(qdict_haskey(sub, "status"));
+        st = qdict_get_str(sub, "status");
+
+        /* "setup", "active", "completed", "failed", "cancelled" */
+        if (strcmp(st, "completed") == 0) {
+            QDECREF(rsp);
+            break;
+        }
+
+        if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0)) {
+            QDECREF(rsp);
+            continue;
+        }
+
+        fprintf(stderr, "Migration did not complete, status: %s\n", st);
+        g_assert_not_reached();
+    }
+
+    migrate_allocator(from->alloc, to->alloc);
+    set_context(to);
+
+    /* BUG? VM will emit a RESUME event regardless of running status. */
+    qmp_eventwait("RESUME");
+}
+
 int mkqcow2(const char *file, unsigned size_mb)
 {
     pid_t pid;
tests/libqos/libqos.h +2 -0
index f459783..42eca5e 100644
@@ -19,6 +19,8 @@ typedef struct QOSState {
 QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap);
 QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt, ...);
 void qtest_shutdown(QOSState *qs);
+void set_context(QOSState *s);
+void migrate(QOSState *from, QOSState *to);
 int mkqcow2(const char *file, unsigned size_mb);
 void prepare_blkdebug_script(const char *debug_fn, const char *event);
 
tests/libqos/malloc.c +57 -17

157 lines not on this page · raw message

tests/libqos/malloc.h +1 -0
index 71ac407..0c6c9b7 100644
@@ -31,6 +31,7 @@ void alloc_uninit(QGuestAllocator *allocator);
 /* Always returns page aligned values */
 uint64_t guest_alloc(QGuestAllocator *allocator, size_t size);
 void guest_free(QGuestAllocator *allocator, uint64_t addr);
+void migrate_allocator(QGuestAllocator *src, QGuestAllocator *dst);
 
 QGuestAllocator *alloc_init(uint64_t start, uint64_t end);
 QGuestAllocator *alloc_init_flags(QAllocOpts flags,
Signature · 1 line
1.9.3
author
#4 lore raw

PATCH 4/5 qtest/ahci: add migrate dma test

In reply to John Snow

Write to one guest, migrate, and then read from the other. adjust ahci_io to clear any buffers it creates, so that we can use ahci_io safely on both guests knowing we are using empty buffers and not accidentally re-using data.

---
 tests/ahci-test.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/libqos/ahci.c |  1 +
 2 files changed, 47 insertions(+)
tests/ahci-test.c +46 -0
index 4bd81fa..ec3e49e 100644
@@ -1085,6 +1085,51 @@ static void test_migrate_sanity(void)
     ahci_shutdown(dst);
 }
 
+/**
+ * DMA Migration test: Write a pattern, migrate, then read.
+ */
+static void test_migrate_dma(void)
+{
+    AHCIQState *src, *dst;
+    uint8_t px;
+    size_t bufsize = 4096;
+    unsigned char *tx = g_malloc(bufsize);
+    unsigned char *rx = g_malloc0(bufsize);
+    unsigned i;
+
+    src = ahci_boot_and_enable("-m 1024 -M q35 "
+                               "-hda %s ", tmp_path);
+    dst = ahci_boot("-m 1024 -M q35 "
+                    "-hda %s "
+                    "-incoming tcp:127.0.0.1:1234", tmp_path);
+
+    set_context(src->parent);
+
+    /* initialize */
+    px = ahci_port_select(src);
+    ahci_port_clear(src, px);
+
+    /* create pattern */
+    for (i = 0; i < bufsize; i++) {
+        tx[i] = (bufsize - i);
+    }
+
+    /* Write, migrate, then read. */
+    ahci_io(src, px, CMD_WRITE_DMA, tx, bufsize, 0);
+    ahci_migrate(src, dst);
+    ahci_io(dst, px, CMD_READ_DMA, rx, bufsize, 0);
+
+    /* Verify pattern */
+    g_assert_cmphex(memcmp(tx, rx, bufsize), ==, 0);
+
+    set_context(src->parent);
+    ahci_shutdown(src);
+    set_context(dst->parent);
+    ahci_shutdown(dst);
+    g_free(rx);
+    g_free(tx);
+}
+
 /******************************************************************************/
 /* AHCI I/O Test Matrix Definitions                                           */
 
@@ -1334,6 +1379,7 @@ int main(int argc, char **argv)
     qtest_add_func("/ahci/flush/retry", test_flush_retry);
 
     qtest_add_func("/ahci/migrate/sanity", test_migrate_sanity);
+    qtest_add_func("/ahci/migrate/dma", test_migrate_dma);
 
     ret = g_test_run();
 
tests/libqos/ahci.c +1 -0
index 8bb9e3e..4091fdd 100644
@@ -623,6 +623,7 @@ void ahci_io(AHCIQState *ahci, uint8_t port, uint8_t ide_cmd,
     g_assert(props);
     ptr = ahci_alloc(ahci, bufsize);
     g_assert(ptr);
+    qmemset(ptr, 0x00, bufsize);
 
     if (props->write) {
         memwrite(ptr, buffer, bufsize);
Signature · 1 line
1.9.3

John Snow

author
#0 lore raw

cover ahci: enable migration

The day we all feared is here, and I am proposing we allow the migration of the AHCI device. The series that precedes this which fixes AHCI migration has improved the stability of the device and as this test series proves, is stable.

I am justifying this checkin based on a series of ping-pong migration tests I ran under heavy load (using google's stressapptest) and saw over 300 successful migrations without a single failure.

This series does a few things:
(1) Add migration facilities to libqos
(2) Enable AHCI and ICH9 migration
(3) Add a series of migration tests to ahci-test

This patch has several dependencies:

(1) stefanha/block
(2) [PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI
(3) [PATCH 0/8] ahci: add more IO tests
(4) [PATCH 0/6] ahci: rerror/werror=stop resume tests

1, 3 and 4 are ahci-test framework dependencies, but 2 actually allows the AHCI migration to become stable.

John Snow (5):
libqos: Add migration helpers
ich9/ahci: Enable Migration
qtest/ahci: Add migration test
qtest/ahci: add migrate dma test
qtest/ahci: add flush migrate test

 hw/ide/ahci.c         |   1 -
 hw/ide/ich.c          |   1 -
 tests/ahci-test.c     | 184 +++++++++++++++++++++++++++++++++++++++++++++++++-
 tests/libqos/ahci.c   |   1 +
 tests/libqos/libqos.c |  75 ++++++++++++++++++++
 tests/libqos/libqos.h |   2 +
 tests/libqos/malloc.c |  74 +++++++++++++++-----
 tests/libqos/malloc.h |   1 +
 8 files changed, 319 insertions(+), 20 deletions(-)
Signature · 1 line
1.9.3
author
#2 lore raw

PATCH 2/5 ich9/ahci: Enable Migration

Lift the flag preventing the migration of the ICH9/AHCI devices.

---
 hw/ide/ahci.c | 1 -
 hw/ide/ich.c  | 1 -
 2 files changed, 2 deletions(-)
hw/ide/ahci.c +0 -1
index e1ae36f..66f47f2 100644
@@ -1421,7 +1421,6 @@ typedef struct SysbusAHCIState {
 
 static const VMStateDescription vmstate_sysbus_ahci = {
     .name = "sysbus-ahci",
-    .unmigratable = 1, /* Still buggy under I/O load */
     .fields = (VMStateField[]) {
         VMSTATE_AHCI(ahci, SysbusAHCIState),
         VMSTATE_END_OF_LIST()
hw/ide/ich.c +0 -1
index fb1d095..97c7af2 100644
@@ -82,7 +82,6 @@
 
 static const VMStateDescription vmstate_ich9_ahci = {
     .name = "ich9_ahci",
-    .unmigratable = 1, /* Still buggy under I/O load */
     .version_id = 1,
     .fields = (VMStateField[]) {
         VMSTATE_PCI_DEVICE(parent_obj, AHCIPCIState),
Signature · 1 line
1.9.3
author
#3 lore raw

PATCH 3/5 qtest/ahci: Add migration test

In reply to John Snow

Notes:

* The migration is performed on QOSState objects.

* The migration is performed in such a way that it does not assume consistency between the allocators attached to each. That is to say, you can use each QOSState object completely independently and then at an arbitrary point decide to migrate, and the destination object will now be consistent with the memory within the source guest. The source object that was migrated from will have a completely blank allocator.

ahci-test.c:
- verify_state is added
- ahci_migrate is added as a frontend to migrate
- test_migrate_sanity test case is added.

---
 tests/ahci-test.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
tests/ahci-test.c +85 -0
index f194cbc..4bd81fa 100644
@@ -71,6 +71,66 @@ static void string_bswap16(uint16_t *s, size_t bytes)
     }
 }
 
+/**
+ * Verify that the transfer did not corrupt our state at all.
+ */
+static void verify_state(AHCIQState *ahci)
+{
+    int i,j;
+    uint32_t ahci_fingerprint;
+    uint64_t hba_base;
+    AHCICommandHeader cmd;
+
+    ahci_fingerprint = qpci_config_readl(ahci->dev, PCI_VENDOR_ID);
+    g_assert_cmphex(ahci_fingerprint, ==, ahci->fingerprint);
+
+    /* If we haven't initialized, this is as much as can be validated. */
+    if (!ahci->hba_base) {
+        return;
+    }
+
+    hba_base = qpci_config_readl(ahci->dev, PCI_BASE_ADDRESS_5);
+    g_assert_cmphex(hba_base, ==, (uint64_t)ahci->hba_base);
+
+    g_assert_cmphex(ahci_rreg(ahci, AHCI_CAP), ==, ahci->cap);
+    g_assert_cmphex(ahci_rreg(ahci, AHCI_CAP2), ==, ahci->cap2);
+
+    for (i = 0; i < 32; i++) {
+        g_assert_cmphex(ahci_px_rreg(ahci, i, AHCI_PX_FB), ==,
+                        ahci->port[i].fb);
+        g_assert_cmphex(ahci_px_rreg(ahci, i, AHCI_PX_CLB), ==,
+                        ahci->port[i].clb);
+        for (j = 0; j < 32; j++) {
+            ahci_get_command_header(ahci, i, j, &cmd);
+            g_assert_cmphex(cmd.prdtl, ==, ahci->port[i].prdtl[j]);
+            g_assert_cmphex(cmd.ctba, ==, ahci->port[i].ctba[j]);
+        }
+    }
+}
+
+static void ahci_migrate(AHCIQState *from, AHCIQState *to)
+{
+    QOSState *tmp = to->parent;
+    QPCIDevice *dev = to->dev;
+
+    migrate(from->parent, to->parent);
+
+    /* We'd like for the AHCIState objects to still point
+     * to information specific to its specific parent
+     * instance, but otherwise just inherit the new data. */
+    memcpy(to, from, sizeof(AHCIQState));
+    to->parent = tmp;
+    to->dev = dev;
+
+    tmp = from->parent;
+    dev = from->dev;
+    memset(from, 0x00, sizeof(AHCIQState));
+    from->parent = tmp;
+    from->dev = dev;
+
+    verify_state(to);
+}
+
 /*** Test Setup & Teardown ***/
 
 /**
@@ -1002,6 +1062,29 @@ static void test_flush_retry(void)
     ahci_shutdown(ahci);
 }
 
+/**
+ * Basic sanity test to boot a machine, find an AHCI device, and shutdown.
+ */
+static void test_migrate_sanity(void)
+{
+    AHCIQState *src, *dst;
+
+    src = ahci_boot("-m 1024 -M q35 "
+                    "-hda %s ", tmp_path);
+    dst = ahci_boot("-m 1024 -M q35 "
+                    "-hda %s "
+                    "-incoming tcp:127.0.0.1:1234", tmp_path);
+
+    ahci_migrate(src, dst);
+    /* context is now implicitly 'dst' */
+
+    set_context(src->parent);
+    ahci_shutdown(src);
+
+    set_context(dst->parent);
+    ahci_shutdown(dst);
+}
+
 /******************************************************************************/
 /* AHCI I/O Test Matrix Definitions                                           */
 
@@ -1250,6 +1333,8 @@ int main(int argc, char **argv)
     qtest_add_func("/ahci/flush/simple", test_flush);
     qtest_add_func("/ahci/flush/retry", test_flush_retry);
 
+    qtest_add_func("/ahci/migrate/sanity", test_migrate_sanity);
+
     ret = g_test_run();
 
     /* Cleanup */
Signature · 1 line
1.9.3
author
#5 lore raw

PATCH 5/5 qtest/ahci: add flush migrate test

In reply to John Snow

Use blkdebug to inject an error on first flush, then attempt to flush on the first guest. When the error halts the VM, migrate to the second VM, and attempt to resume the command.

---
 tests/ahci-test.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)
tests/ahci-test.c +52 -1
index ec3e49e..1e568f5 100644
@@ -1043,7 +1043,7 @@ static void test_flush_retry(void)
                                 debug_path,
                                 tmp_path);
 
-    /* Issue Flush Command */
+    /* Issue Flush Command and wait for error */
     port = ahci_port_select(ahci);
     ahci_port_clear(ahci, port);
     cmd = ahci_command_create(CMD_FLUSH_CACHE);
@@ -1130,6 +1130,56 @@ static void test_migrate_dma(void)
     g_free(tx);
 }
 
+/**
+ * Migration test: Try to flush, migrate, then resume.
+ */
+static void test_flush_migrate(void)
+{
+    AHCIQState *src, *dst;
+    AHCICommand *cmd;
+    uint8_t px;
+    const char *s;
+
+    prepare_blkdebug_script(debug_path, "flush_to_disk");
+
+    src = ahci_boot_and_enable("-drive file=blkdebug:%s:%s,if=none,id=drive0,"
+                               "cache=writeback,rerror=stop,werror=stop "
+                               "-M q35 "
+                               "-device ide-hd,drive=drive0 ",
+                               debug_path, tmp_path);
+    dst = ahci_boot("-drive file=blkdebug:%s:%s,if=none,id=drive0,"
+                    "cache=writeback,rerror=stop,werror=stop "
+                    "-M q35 "
+                    "-device ide-hd,drive=drive0 "
+                    "-incoming tcp:127.0.0.1:1234", debug_path, tmp_path);
+
+    set_context(src->parent);
+
+    /* Issue Flush Command */
+    px = ahci_port_select(src);
+    ahci_port_clear(src, px);
+    cmd = ahci_command_create(CMD_FLUSH_CACHE);
+    ahci_command_commit(src, cmd, px);
+    ahci_command_issue_async(src, cmd);
+    qmp_eventwait("STOP");
+
+    /* Migrate over */
+    ahci_migrate(src, dst);
+    set_context(dst->parent);
+    verify_state(dst);
+
+    /* Complete the command */
+    s = "{'execute':'cont' }";
+    qmp_async(s);
+    qmp_eventwait("RESUME");
+    ahci_command_wait(dst, cmd);
+    ahci_command_verify(dst, cmd);
+
+    ahci_command_free(cmd);
+    ahci_shutdown(src);
+    ahci_shutdown(dst);
+}
+
 /******************************************************************************/
 /* AHCI I/O Test Matrix Definitions                                           */
 
@@ -1377,6 +1427,7 @@ int main(int argc, char **argv)
 
     qtest_add_func("/ahci/flush/simple", test_flush);
     qtest_add_func("/ahci/flush/retry", test_flush_retry);
+    qtest_add_func("/ahci/flush/migrate", test_flush_migrate);
 
     qtest_add_func("/ahci/migrate/sanity", test_migrate_sanity);
     qtest_add_func("/ahci/migrate/dma", test_migrate_dma);
Signature · 1 line
1.9.3
author
#6 lore raw
In reply to John Snow
Quoted 9 lines · John Snow

The day we all feared is here, and I am proposing we allow the migration of the AHCI device. The series that precedes this which fixes AHCI migration has improved the stability of the device and as this test series proves, is stable.

I am justifying this checkin based on a series of ping-pong migration tests I ran under heavy load (using google's stressapptest) and saw over 300 successful migrations without a single failure.

Quoted 8 lines

This series does a few things:
(1) Add migration facilities to libqos
(2) Enable AHCI and ICH9 migration
(3) Add a series of migration tests to ahci-test

This patch has several dependencies:

(1) stefanha/block

Update 2015-02-24: you can just base off of master now.

Quoted 24 lines

(2) [PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI
(3) [PATCH 0/8] ahci: add more IO tests
(4) [PATCH 0/6] ahci: rerror/werror=stop resume tests

1, 3 and 4 are ahci-test framework dependencies, but 2 actually allows the AHCI migration to become stable.

John Snow (5):
libqos: Add migration helpers
ich9/ahci: Enable Migration
qtest/ahci: Add migration test
qtest/ahci: add migrate dma test
qtest/ahci: add flush migrate test

  hw/ide/ahci.c         |   1 -
  hw/ide/ich.c          |   1 -
  tests/ahci-test.c     | 184 +++++++++++++++++++++++++++++++++++++++++++++++++-
  tests/libqos/ahci.c   |   1 +
  tests/libqos/libqos.c |  75 ++++++++++++++++++++
  tests/libqos/libqos.h |   2 +
  tests/libqos/malloc.c |  74 +++++++++++++++-----
  tests/libqos/malloc.h |   1 +
  8 files changed, 319 insertions(+), 20 deletions(-)
#7 lore raw
In reply to John Snow
Quoted 16 lines · John Snow

The day we all feared is here, and I am proposing we allow the migration of the AHCI device. The series that precedes this which fixes AHCI migration has improved the stability of the device and as this test series proves, is stable.

I am justifying this checkin based on a series of ping-pong migration tests I ran under heavy load (using google's stressapptest) and saw over 300 successful migrations without a single failure.

This series does a few things:
(1) Add migration facilities to libqos
(2) Enable AHCI and ICH9 migration
(3) Add a series of migration tests to ahci-test

This patch has several dependencies:

Quoted 7 lines

(1) stefanha/block
(2) [PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI
(3) [PATCH 0/8] ahci: add more IO tests
(4) [PATCH 0/6] ahci: rerror/werror=stop resume tests

1, 3 and 4 are ahci-test framework dependencies, but 2 actually allows the AHCI migration to become stable.

Does rerror/werror=stop work even for queued DMA reads/writes (I didn't try doing that, but I never even checked whether it just worked)?

Paolo

author
#8 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 21 lines · John Snow

The day we all feared is here, and I am proposing we allow the migration of the AHCI device. The series that precedes this which fixes AHCI migration has improved the stability of the device and as this test series proves, is stable.

I am justifying this checkin based on a series of ping-pong migration tests I ran under heavy load (using google's stressapptest) and saw over 300 successful migrations without a single failure.

This series does a few things:
(1) Add migration facilities to libqos
(2) Enable AHCI and ICH9 migration
(3) Add a series of migration tests to ahci-test

This patch has several dependencies:

(1) stefanha/block
(2) [PATCH v4 00/17] ide: rerror/werror migration fixes for IDE/ISA and AHCI
(3) [PATCH 0/8] ahci: add more IO tests
(4) [PATCH 0/6] ahci: rerror/werror=stop resume tests

Quoted 8 lines
Quoted 2 lines

1, 3 and 4 are ahci-test framework dependencies, but 2 actually allows the AHCI migration to become stable.

Does rerror/werror=stop work even for queued DMA reads/writes (I didn't try doing that, but I never even checked whether it just worked)?

Paolo

One more test case, coming up!

--js