[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 29/45] postcopy: ram_enable_notify to switch on u
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v5 29/45] postcopy: ram_enable_notify to switch on userfault |
Date: |
Wed, 25 Feb 2015 16:51:52 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
Mark the area of RAM as 'userfault'
Start up a fault-thread to handle any userfaults we might receive
from it (to be filled in later)
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/migration/migration.h | 3 ++
include/migration/postcopy-ram.h | 6 ++++
migration/postcopy-ram.c | 69 +++++++++++++++++++++++++++++++++++++++-
savevm.c | 9 ++++++
4 files changed, 86 insertions(+), 1 deletion(-)
diff --git a/include/migration/migration.h b/include/migration/migration.h
index d09561e..821d561 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -84,6 +84,9 @@ struct MigrationIncomingState {
PostcopyState postcopy_state;
+ QemuThread fault_thread;
+ QemuSemaphore fault_thread_sem;
+
/* For the kernel to send us notifications */
int userfault_fd;
QEMUFile *return_path;
diff --git a/include/migration/postcopy-ram.h b/include/migration/postcopy-ram.h
index 305c26b..fbb2a93 100644
--- a/include/migration/postcopy-ram.h
+++ b/include/migration/postcopy-ram.h
@@ -19,6 +19,12 @@
bool postcopy_ram_supported_by_host(void);
/*
+ * Make all of RAM sensitive to accesses to areas that haven't yet been written
+ * and wire up anything necessary to deal with it.
+ */
+int postcopy_ram_enable_notify(MigrationIncomingState *mis);
+
+/*
* Initialise postcopy-ram, setting the RAM to a state where we can go into
* postcopy later; must be called prior to any precopy.
* called from arch_init's similarly named ram_postcopy_incoming_init
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index dbe1892..33dd332 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -498,9 +498,71 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState
*mis)
return 0;
}
+/*
+ * Mark the given area of RAM as requiring notification to unwritten areas
+ * Used as a callback on qemu_ram_foreach_block.
+ * host_addr: Base of area to mark
+ * offset: Offset in the whole ram arena
+ * length: Length of the section
+ * opaque: MigrationIncomingState pointer
+ * Returns 0 on success
+ */
+static int ram_block_enable_notify(const char *block_name, void *host_addr,
+ ram_addr_t offset, ram_addr_t length,
+ void *opaque)
+{
+ MigrationIncomingState *mis = opaque;
+ struct uffdio_register reg_struct;
+
+ reg_struct.range.start = (uint64_t)(uintptr_t)host_addr;
+ reg_struct.range.len = (uint64_t)length;
+ reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING;
+
+ /* Now tell our userfault_fd that it's responsible for this area */
+ if (ioctl(mis->userfault_fd, UFFDIO_REGISTER, ®_struct)) {
+ perror("ram_block_enable_notify userfault register");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Handle faults detected by the USERFAULT markings
+ */
+static void *postcopy_ram_fault_thread(void *opaque)
+{
+ MigrationIncomingState *mis = (MigrationIncomingState *)opaque;
+
+ fprintf(stderr, "postcopy_ram_fault_thread\n");
+ /* TODO: In later patch */
+ qemu_sem_post(&mis->fault_thread_sem);
+ while (1) {
+ /* TODO: In later patch */
+ }
+
+ return NULL;
+}
+
+int postcopy_ram_enable_notify(MigrationIncomingState *mis)
+{
+ /* Create the fault handler thread and wait for it to be ready */
+ qemu_sem_init(&mis->fault_thread_sem, 0);
+ qemu_thread_create(&mis->fault_thread, "postcopy/fault",
+ postcopy_ram_fault_thread, mis, QEMU_THREAD_JOINABLE);
+ qemu_sem_wait(&mis->fault_thread_sem);
+ qemu_sem_destroy(&mis->fault_thread_sem);
+
+ /* Mark so that we get notified of accesses to unwritten areas */
+ if (qemu_ram_foreach_block(ram_block_enable_notify, mis)) {
+ return -1;
+ }
+
+ return 0;
+}
+
#else
/* No target OS support, stubs just fail */
-
bool postcopy_ram_supported_by_host(void)
{
error_report("%s: No OS support", __func__);
@@ -541,6 +603,11 @@ int postcopy_ram_discard_range(MigrationIncomingState
*mis, uint8_t *start,
{
assert(0);
}
+
+int postcopy_ram_enable_notify(MigrationIncomingState *mis)
+{
+ assert(0);
+}
#endif
/* ------------------------------------------------------------------------- */
diff --git a/savevm.c b/savevm.c
index 6857660..014ba08 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1317,6 +1317,15 @@ static int
loadvm_postcopy_handle_listen(MigrationIncomingState *mis)
return -1;
}
+ /*
+ * Sensitise RAM - can now generate requests for blocks that don't exist
+ * However, at this point the CPU shouldn't be running, and the IO
+ * shouldn't be doing anything yet so don't actually expect requests
+ */
+ if (postcopy_ram_enable_notify(mis)) {
+ return -1;
+ }
+
/* TODO start up the postcopy listening thread */
return 0;
}
--
2.1.0
- [Qemu-devel] [PATCH v5 18/45] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream, (continued)
- [Qemu-devel] [PATCH v5 18/45] MIG_CMD_PACKAGED: Send a packaged chunk of migration stream, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 16/45] Add migration-capability boolean for postcopy-ram., Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 17/45] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages., Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 21/45] Add Linux userfaultfd header, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 20/45] Modify savevm handlers for postcopy, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 24/45] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 22/45] postcopy: OS support test, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 23/45] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 25/45] qemu_savevm_state_complete: Postcopy changes, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 26/45] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 29/45] postcopy: ram_enable_notify to switch on userfault,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v5 28/45] postcopy: Incoming initialisation, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 27/45] Postcopy: Maintain sentmap and calculate discard, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 30/45] Postcopy: Postcopy startup in migration thread, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 31/45] Postcopy end in migration_thread, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 32/45] Page request: Add MIG_RP_CMD_REQ_PAGES reverse command, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 33/45] Page request: Process incoming page request, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 34/45] Page request: Consume pages off the post-copy queue, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 35/45] postcopy_ram.c: place_page and helpers, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 36/45] Postcopy: Use helpers to map pages during migration, Dr. David Alan Gilbert (git), 2015/02/25
- [Qemu-devel] [PATCH v5 38/45] Don't sync dirty bitmaps in postcopy, Dr. David Alan Gilbert (git), 2015/02/25