* source to the destination before all the data has been copied.
*/
-#include <glib.h>
-#include <stdio.h>
-#include <unistd.h>
+#include "qemu/osdep.h"
#include "qemu-common.h"
#include "migration/migration.h"
#include "migration/postcopy-ram.h"
#include "sysemu/sysemu.h"
+#include "sysemu/balloon.h"
#include "qemu/error-report.h"
#include "trace.h"
#if defined(__linux__)
#include <poll.h>
-#include <sys/eventfd.h>
-#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
-#include <sys/types.h>
#include <asm/types.h> /* for __u64 */
#endif
-#if defined(__linux__) && defined(__NR_userfaultfd)
+#if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
+#include <sys/eventfd.h>
#include <linux/userfaultfd.h>
static bool ufd_version_check(int ufd)
return true;
}
+/*
+ * Check for things that postcopy won't support; returns 0 if the block
+ * is fine.
+ */
+static int check_range(const char *block_name, void *host_addr,
+ ram_addr_t offset, ram_addr_t length, void *opaque)
+{
+ RAMBlock *rb = qemu_ram_block_by_name(block_name);
+
+ if (qemu_ram_pagesize(rb) > getpagesize()) {
+ error_report("Postcopy doesn't support large page sizes yet (%s)",
+ block_name);
+ return -E2BIG;
+ }
+
+ return 0;
+}
+
/*
* Note: This has the side effect of munlock'ing all of RAM, that's
* normally fine since if the postcopy succeeds it gets turned back on at the
goto out;
}
+ /* Check for anything about the RAMBlocks we don't support */
+ if (qemu_ram_foreach_block(check_range, NULL)) {
+ /* check_range will have printed its own error */
+ goto out;
+ }
+
ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
if (ufd == -1) {
error_report("%s: userfaultfd not available: %s", __func__,
* We turned off hugepage for the precopy stage with postcopy enabled
* we can turn it back on now.
*/
- if (qemu_madvise(host_addr, length, QEMU_MADV_HUGEPAGE)) {
- error_report("%s HUGEPAGE: %s", __func__, strerror(errno));
- return -1;
- }
+ qemu_madvise(host_addr, length, QEMU_MADV_HUGEPAGE);
/*
* We can also turn off userfault now since we should have all the
mis->have_fault_thread = false;
}
+ qemu_balloon_inhibit(false);
+
if (enable_mlock) {
if (os_mlock() < 0) {
error_report("mlock: %s", strerror(errno));
* do delete areas of the page, even if THP thinks a hugepage would
* be a good idea, so force hugepages off.
*/
- if (qemu_madvise(host_addr, length, QEMU_MADV_NOHUGEPAGE)) {
- error_report("%s: NOHUGEPAGE: %s", __func__, strerror(errno));
- return -1;
- }
+ qemu_madvise(host_addr, length, QEMU_MADV_NOHUGEPAGE);
return 0;
}
while (true) {
ram_addr_t rb_offset;
- ram_addr_t in_raspace;
struct pollfd pfd[2];
/*
rb = qemu_ram_block_from_host(
(void *)(uintptr_t)msg.arg.pagefault.address,
- true, &in_raspace, &rb_offset);
+ true, &rb_offset);
if (!rb) {
error_report("postcopy_ram_fault_thread: Fault outside guest: %"
PRIx64, (uint64_t)msg.arg.pagefault.address);
return -1;
}
+ /*
+ * Ballooning can mark pages as absent while we're postcopying
+ * that would cause false userfaults.
+ */
+ qemu_balloon_inhibit(true);
+
trace_postcopy_ram_enable_notify();
return 0;
mis->postcopy_tmp_page = mmap(NULL, getpagesize(),
PROT_READ | PROT_WRITE, MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
- if (!mis->postcopy_tmp_page) {
+ if (mis->postcopy_tmp_page == MAP_FAILED) {
+ mis->postcopy_tmp_page = NULL;
error_report("%s: %s", __func__, strerror(errno));
return NULL;
}
if (pds->cur_entry == MAX_DISCARDS_PER_COMMAND) {
/* Full set, ship it! */
- qemu_savevm_send_postcopy_ram_discard(ms->file, pds->ramblock_name,
+ qemu_savevm_send_postcopy_ram_discard(ms->to_dst_file,
+ pds->ramblock_name,
pds->cur_entry,
pds->start_list,
pds->length_list);
{
/* Anything unsent? */
if (pds->cur_entry) {
- qemu_savevm_send_postcopy_ram_discard(ms->file, pds->ramblock_name,
+ qemu_savevm_send_postcopy_ram_discard(ms->to_dst_file,
+ pds->ramblock_name,
pds->cur_entry,
pds->start_list,
pds->length_list);