*/
#include "qemu/osdep.h"
-
-#include "qemu-common.h"
-#include "migration/migration.h"
-#include "migration/postcopy-ram.h"
+#include "exec/target_page.h"
+#include "migration.h"
+#include "qemu-file.h"
+#include "savevm.h"
+#include "postcopy-ram.h"
+#include "ram.h"
#include "sysemu/sysemu.h"
#include "sysemu/balloon.h"
#include "qemu/error-report.h"
struct PostcopyDiscardState {
const char *ramblock_name;
- uint64_t offset; /* Bitmap entry for the 1st bit of this RAMBlock */
uint16_t cur_entry;
/*
* Start and length of a discard range (bytes)
/* Callback from postcopy_ram_supported_by_host block iterator.
*/
-static int test_range_shared(const char *block_name, void *host_addr,
+static int test_ramblock_postcopiable(const char *block_name, void *host_addr,
ram_addr_t offset, ram_addr_t length, void *opaque)
{
- if (qemu_ram_is_shared(qemu_ram_block_by_name(block_name))) {
+ RAMBlock *rb = qemu_ram_block_by_name(block_name);
+ size_t pagesize = qemu_ram_pagesize(rb);
+
+ if (qemu_ram_is_shared(rb)) {
error_report("Postcopy on shared RAM (%s) is not yet supported",
block_name);
return 1;
}
+
+ if (length % pagesize) {
+ error_report("Postcopy requires RAM blocks to be a page size multiple,"
+ " block %s is 0x" RAM_ADDR_FMT " bytes with a "
+ "page size of 0x%zx", block_name, length, pagesize);
+ return 1;
+ }
return 0;
}
struct uffdio_range range_struct;
uint64_t feature_mask;
- if ((1ul << qemu_target_page_bits()) > pagesize) {
+ if (qemu_target_page_size() > pagesize) {
error_report("Target page size bigger than host page size");
goto out;
}
}
/* We don't support postcopy with shared RAM yet */
- if (qemu_ram_foreach_block(test_range_shared, NULL)) {
+ if (qemu_ram_foreach_block(test_ramblock_postcopiable, NULL)) {
goto out;
}
static int init_range(const char *block_name, void *host_addr,
ram_addr_t offset, ram_addr_t length, void *opaque)
{
- MigrationIncomingState *mis = opaque;
-
trace_postcopy_init_range(block_name, host_addr, offset, length);
/*
* - we're going to get the copy from the source anyway.
* (Precopy will just overwrite this data, so doesn't need the discard)
*/
- if (ram_discard_range(mis, block_name, 0, length)) {
+ if (ram_discard_range(block_name, 0, length)) {
return -1;
}
*/
int postcopy_ram_incoming_init(MigrationIncomingState *mis, size_t ram_pages)
{
- if (qemu_ram_foreach_block(init_range, mis)) {
+ if (qemu_ram_foreach_block(init_range, NULL)) {
return -1;
}
}
postcopy_state_set(POSTCOPY_INCOMING_END);
- migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0);
if (mis->postcopy_tmp_page) {
munmap(mis->postcopy_tmp_page, mis->largest_page_size);
* returns: a new PDS.
*/
PostcopyDiscardState *postcopy_discard_send_init(MigrationState *ms,
- unsigned long offset,
const char *name)
{
PostcopyDiscardState *res = g_malloc0(sizeof(PostcopyDiscardState));
if (res) {
res->ramblock_name = name;
- res->offset = offset;
}
return res;
void postcopy_discard_send_range(MigrationState *ms, PostcopyDiscardState *pds,
unsigned long start, unsigned long length)
{
- size_t tp_bits = qemu_target_page_bits();
+ size_t tp_size = qemu_target_page_size();
/* Convert to byte offsets within the RAM block */
- pds->start_list[pds->cur_entry] = (start - pds->offset) << tp_bits;
- pds->length_list[pds->cur_entry] = length << tp_bits;
+ pds->start_list[pds->cur_entry] = start * tp_size;
+ pds->length_list[pds->cur_entry] = length * tp_size;
trace_postcopy_discard_send_range(pds->ramblock_name, start, length);
pds->cur_entry++;
pds->nsentwords++;
g_free(pds);
}
+
+/*
+ * Current state of incoming postcopy; note this is not part of
+ * MigrationIncomingState since it's state is used during cleanup
+ * at the end as MIS is being freed.
+ */
+static PostcopyState incoming_postcopy_state;
+
+PostcopyState postcopy_state_get(void)
+{
+ return atomic_mb_read(&incoming_postcopy_state);
+}
+
+/* Set the state and return the old state */
+PostcopyState postcopy_state_set(PostcopyState new_state)
+{
+ return atomic_xchg(&incoming_postcopy_state, new_state);
+}