2 * Postcopy migration for RAM
4 * Copyright 2013-2015 Red Hat, Inc. and/or its affiliates
7 * Dave Gilbert <dgilbert@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
15 * Postcopy is a migration technique where the execution flips from the
16 * source to the destination before all the data has been copied.
19 #include "qemu/osdep.h"
20 #include "exec/target_page.h"
21 #include "migration.h"
22 #include "qemu-file.h"
24 #include "postcopy-ram.h"
26 #include "sysemu/sysemu.h"
27 #include "sysemu/balloon.h"
28 #include "qemu/error-report.h"
31 /* Arbitrary limit on size of each discard command,
32 * keeps them around ~200 bytes
34 #define MAX_DISCARDS_PER_COMMAND 12
36 struct PostcopyDiscardState
{
37 const char *ramblock_name
;
40 * Start and length of a discard range (bytes)
42 uint64_t start_list
[MAX_DISCARDS_PER_COMMAND
];
43 uint64_t length_list
[MAX_DISCARDS_PER_COMMAND
];
44 unsigned int nsentwords
;
45 unsigned int nsentcmds
;
48 /* Postcopy needs to detect accesses to pages that haven't yet been copied
49 * across, and efficiently map new pages in, the techniques for doing this
50 * are target OS specific.
52 #if defined(__linux__)
55 #include <sys/ioctl.h>
56 #include <sys/syscall.h>
57 #include <asm/types.h> /* for __u64 */
60 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
61 #include <sys/eventfd.h>
62 #include <linux/userfaultfd.h>
66 * receive_ufd_features: check userfault fd features, to request only supported
67 * features in the future.
69 * Returns: true on success
71 * __NR_userfaultfd - should be checked before
72 * @features: out parameter will contain uffdio_api.features provided by kernel
75 static bool receive_ufd_features(uint64_t *features
)
77 struct uffdio_api api_struct
= {0};
81 /* if we are here __NR_userfaultfd should exists */
82 ufd
= syscall(__NR_userfaultfd
, O_CLOEXEC
);
84 error_report("%s: syscall __NR_userfaultfd failed: %s", __func__
,
90 api_struct
.api
= UFFD_API
;
91 api_struct
.features
= 0;
92 if (ioctl(ufd
, UFFDIO_API
, &api_struct
)) {
93 error_report("%s: UFFDIO_API failed: %s", __func__
,
99 *features
= api_struct
.features
;
107 * request_ufd_features: this function should be called only once on a newly
108 * opened ufd, subsequent calls will lead to error.
110 * Returns: true on succes
112 * @ufd: fd obtained from userfaultfd syscall
113 * @features: bit mask see UFFD_API_FEATURES
115 static bool request_ufd_features(int ufd
, uint64_t features
)
117 struct uffdio_api api_struct
= {0};
120 api_struct
.api
= UFFD_API
;
121 api_struct
.features
= features
;
122 if (ioctl(ufd
, UFFDIO_API
, &api_struct
)) {
123 error_report("%s failed: UFFDIO_API failed: %s", __func__
,
128 ioctl_mask
= (__u64
)1 << _UFFDIO_REGISTER
|
129 (__u64
)1 << _UFFDIO_UNREGISTER
;
130 if ((api_struct
.ioctls
& ioctl_mask
) != ioctl_mask
) {
131 error_report("Missing userfault features: %" PRIx64
,
132 (uint64_t)(~api_struct
.ioctls
& ioctl_mask
));
139 static bool ufd_check_and_apply(int ufd
, MigrationIncomingState
*mis
)
141 uint64_t asked_features
= 0;
142 static uint64_t supported_features
;
145 * it's not possible to
146 * request UFFD_API twice per one fd
147 * userfault fd features is persistent
149 if (!supported_features
) {
150 if (!receive_ufd_features(&supported_features
)) {
151 error_report("%s failed", __func__
);
157 * request features, even if asked_features is 0, due to
158 * kernel expects UFFD_API before UFFDIO_REGISTER, per
159 * userfault file descriptor
161 if (!request_ufd_features(ufd
, asked_features
)) {
162 error_report("%s failed: features %" PRIu64
, __func__
,
167 if (getpagesize() != ram_pagesize_summary()) {
168 bool have_hp
= false;
169 /* We've got a huge page */
170 #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
171 have_hp
= supported_features
& UFFD_FEATURE_MISSING_HUGETLBFS
;
174 error_report("Userfault on this host does not support huge pages");
181 /* Callback from postcopy_ram_supported_by_host block iterator.
183 static int test_ramblock_postcopiable(const char *block_name
, void *host_addr
,
184 ram_addr_t offset
, ram_addr_t length
, void *opaque
)
186 RAMBlock
*rb
= qemu_ram_block_by_name(block_name
);
187 size_t pagesize
= qemu_ram_pagesize(rb
);
189 if (qemu_ram_is_shared(rb
)) {
190 error_report("Postcopy on shared RAM (%s) is not yet supported",
195 if (length
% pagesize
) {
196 error_report("Postcopy requires RAM blocks to be a page size multiple,"
197 " block %s is 0x" RAM_ADDR_FMT
" bytes with a "
198 "page size of 0x%zx", block_name
, length
, pagesize
);
205 * Note: This has the side effect of munlock'ing all of RAM, that's
206 * normally fine since if the postcopy succeeds it gets turned back on at the
209 bool postcopy_ram_supported_by_host(MigrationIncomingState
*mis
)
211 long pagesize
= getpagesize();
213 bool ret
= false; /* Error unless we change it */
214 void *testarea
= NULL
;
215 struct uffdio_register reg_struct
;
216 struct uffdio_range range_struct
;
217 uint64_t feature_mask
;
219 if (qemu_target_page_size() > pagesize
) {
220 error_report("Target page size bigger than host page size");
224 ufd
= syscall(__NR_userfaultfd
, O_CLOEXEC
);
226 error_report("%s: userfaultfd not available: %s", __func__
,
231 /* Version and features check */
232 if (!ufd_check_and_apply(ufd
, mis
)) {
236 /* We don't support postcopy with shared RAM yet */
237 if (qemu_ram_foreach_block(test_ramblock_postcopiable
, NULL
)) {
242 * userfault and mlock don't go together; we'll put it back later if
246 error_report("%s: munlockall: %s", __func__
, strerror(errno
));
251 * We need to check that the ops we need are supported on anon memory
252 * To do that we need to register a chunk and see the flags that
255 testarea
= mmap(NULL
, pagesize
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
|
256 MAP_ANONYMOUS
, -1, 0);
257 if (testarea
== MAP_FAILED
) {
258 error_report("%s: Failed to map test area: %s", __func__
,
262 g_assert(((size_t)testarea
& (pagesize
-1)) == 0);
264 reg_struct
.range
.start
= (uintptr_t)testarea
;
265 reg_struct
.range
.len
= pagesize
;
266 reg_struct
.mode
= UFFDIO_REGISTER_MODE_MISSING
;
268 if (ioctl(ufd
, UFFDIO_REGISTER
, ®_struct
)) {
269 error_report("%s userfault register: %s", __func__
, strerror(errno
));
273 range_struct
.start
= (uintptr_t)testarea
;
274 range_struct
.len
= pagesize
;
275 if (ioctl(ufd
, UFFDIO_UNREGISTER
, &range_struct
)) {
276 error_report("%s userfault unregister: %s", __func__
, strerror(errno
));
280 feature_mask
= (__u64
)1 << _UFFDIO_WAKE
|
281 (__u64
)1 << _UFFDIO_COPY
|
282 (__u64
)1 << _UFFDIO_ZEROPAGE
;
283 if ((reg_struct
.ioctls
& feature_mask
) != feature_mask
) {
284 error_report("Missing userfault map features: %" PRIx64
,
285 (uint64_t)(~reg_struct
.ioctls
& feature_mask
));
293 munmap(testarea
, pagesize
);
302 * Setup an area of RAM so that it *can* be used for postcopy later; this
303 * must be done right at the start prior to pre-copy.
304 * opaque should be the MIS.
306 static int init_range(const char *block_name
, void *host_addr
,
307 ram_addr_t offset
, ram_addr_t length
, void *opaque
)
309 trace_postcopy_init_range(block_name
, host_addr
, offset
, length
);
312 * We need the whole of RAM to be truly empty for postcopy, so things
313 * like ROMs and any data tables built during init must be zero'd
314 * - we're going to get the copy from the source anyway.
315 * (Precopy will just overwrite this data, so doesn't need the discard)
317 if (ram_discard_range(block_name
, 0, length
)) {
325 * At the end of migration, undo the effects of init_range
326 * opaque should be the MIS.
328 static int cleanup_range(const char *block_name
, void *host_addr
,
329 ram_addr_t offset
, ram_addr_t length
, void *opaque
)
331 MigrationIncomingState
*mis
= opaque
;
332 struct uffdio_range range_struct
;
333 trace_postcopy_cleanup_range(block_name
, host_addr
, offset
, length
);
336 * We turned off hugepage for the precopy stage with postcopy enabled
337 * we can turn it back on now.
339 qemu_madvise(host_addr
, length
, QEMU_MADV_HUGEPAGE
);
342 * We can also turn off userfault now since we should have all the
343 * pages. It can be useful to leave it on to debug postcopy
344 * if you're not sure it's always getting every page.
346 range_struct
.start
= (uintptr_t)host_addr
;
347 range_struct
.len
= length
;
349 if (ioctl(mis
->userfault_fd
, UFFDIO_UNREGISTER
, &range_struct
)) {
350 error_report("%s: userfault unregister %s", __func__
, strerror(errno
));
359 * Initialise postcopy-ram, setting the RAM to a state where we can go into
360 * postcopy later; must be called prior to any precopy.
361 * called from arch_init's similarly named ram_postcopy_incoming_init
363 int postcopy_ram_incoming_init(MigrationIncomingState
*mis
, size_t ram_pages
)
365 if (qemu_ram_foreach_block(init_range
, NULL
)) {
373 * At the end of a migration where postcopy_ram_incoming_init was called.
375 int postcopy_ram_incoming_cleanup(MigrationIncomingState
*mis
)
377 trace_postcopy_ram_incoming_cleanup_entry();
379 if (mis
->have_fault_thread
) {
382 if (qemu_ram_foreach_block(cleanup_range
, mis
)) {
386 * Tell the fault_thread to exit, it's an eventfd that should
387 * currently be at 0, we're going to increment it to 1
390 atomic_set(&mis
->fault_thread_quit
, 1);
391 if (write(mis
->userfault_event_fd
, &tmp64
, 8) == 8) {
392 trace_postcopy_ram_incoming_cleanup_join();
393 qemu_thread_join(&mis
->fault_thread
);
395 /* Not much we can do here, but may as well report it */
396 error_report("%s: incrementing userfault_event_fd: %s", __func__
,
399 trace_postcopy_ram_incoming_cleanup_closeuf();
400 close(mis
->userfault_fd
);
401 close(mis
->userfault_event_fd
);
402 mis
->have_fault_thread
= false;
405 qemu_balloon_inhibit(false);
408 if (os_mlock() < 0) {
409 error_report("mlock: %s", strerror(errno
));
411 * It doesn't feel right to fail at this point, we have a valid
417 postcopy_state_set(POSTCOPY_INCOMING_END
);
419 if (mis
->postcopy_tmp_page
) {
420 munmap(mis
->postcopy_tmp_page
, mis
->largest_page_size
);
421 mis
->postcopy_tmp_page
= NULL
;
423 if (mis
->postcopy_tmp_zero_page
) {
424 munmap(mis
->postcopy_tmp_zero_page
, mis
->largest_page_size
);
425 mis
->postcopy_tmp_zero_page
= NULL
;
427 trace_postcopy_ram_incoming_cleanup_exit();
432 * Disable huge pages on an area
434 static int nhp_range(const char *block_name
, void *host_addr
,
435 ram_addr_t offset
, ram_addr_t length
, void *opaque
)
437 trace_postcopy_nhp_range(block_name
, host_addr
, offset
, length
);
440 * Before we do discards we need to ensure those discards really
441 * do delete areas of the page, even if THP thinks a hugepage would
442 * be a good idea, so force hugepages off.
444 qemu_madvise(host_addr
, length
, QEMU_MADV_NOHUGEPAGE
);
450 * Userfault requires us to mark RAM as NOHUGEPAGE prior to discard
451 * however leaving it until after precopy means that most of the precopy
454 int postcopy_ram_prepare_discard(MigrationIncomingState
*mis
)
456 if (qemu_ram_foreach_block(nhp_range
, mis
)) {
460 postcopy_state_set(POSTCOPY_INCOMING_DISCARD
);
466 * Mark the given area of RAM as requiring notification to unwritten areas
467 * Used as a callback on qemu_ram_foreach_block.
468 * host_addr: Base of area to mark
469 * offset: Offset in the whole ram arena
470 * length: Length of the section
471 * opaque: MigrationIncomingState pointer
472 * Returns 0 on success
474 static int ram_block_enable_notify(const char *block_name
, void *host_addr
,
475 ram_addr_t offset
, ram_addr_t length
,
478 MigrationIncomingState
*mis
= opaque
;
479 struct uffdio_register reg_struct
;
481 reg_struct
.range
.start
= (uintptr_t)host_addr
;
482 reg_struct
.range
.len
= length
;
483 reg_struct
.mode
= UFFDIO_REGISTER_MODE_MISSING
;
485 /* Now tell our userfault_fd that it's responsible for this area */
486 if (ioctl(mis
->userfault_fd
, UFFDIO_REGISTER
, ®_struct
)) {
487 error_report("%s userfault register: %s", __func__
, strerror(errno
));
490 if (!(reg_struct
.ioctls
& ((__u64
)1 << _UFFDIO_COPY
))) {
491 error_report("%s userfault: Region doesn't support COPY", __func__
);
499 * Handle faults detected by the USERFAULT markings
501 static void *postcopy_ram_fault_thread(void *opaque
)
503 MigrationIncomingState
*mis
= opaque
;
507 RAMBlock
*last_rb
= NULL
; /* last RAMBlock we sent part of */
509 trace_postcopy_ram_fault_thread_entry();
510 qemu_sem_post(&mis
->fault_thread_sem
);
513 ram_addr_t rb_offset
;
514 struct pollfd pfd
[2];
517 * We're mainly waiting for the kernel to give us a faulting HVA,
518 * however we can be told to quit via userfault_quit_fd which is
521 pfd
[0].fd
= mis
->userfault_fd
;
522 pfd
[0].events
= POLLIN
;
524 pfd
[1].fd
= mis
->userfault_event_fd
;
525 pfd
[1].events
= POLLIN
; /* Waiting for eventfd to go positive */
528 if (poll(pfd
, 2, -1 /* Wait forever */) == -1) {
529 error_report("%s: userfault poll: %s", __func__
, strerror(errno
));
533 if (pfd
[1].revents
) {
536 /* Consume the signal */
537 if (read(mis
->userfault_event_fd
, &tmp64
, 8) != 8) {
538 /* Nothing obviously nicer than posting this error. */
539 error_report("%s: read() failed", __func__
);
542 if (atomic_read(&mis
->fault_thread_quit
)) {
543 trace_postcopy_ram_fault_thread_quit();
548 ret
= read(mis
->userfault_fd
, &msg
, sizeof(msg
));
549 if (ret
!= sizeof(msg
)) {
550 if (errno
== EAGAIN
) {
552 * if a wake up happens on the other thread just after
553 * the poll, there is nothing to read.
558 error_report("%s: Failed to read full userfault message: %s",
559 __func__
, strerror(errno
));
562 error_report("%s: Read %d bytes from userfaultfd expected %zd",
563 __func__
, ret
, sizeof(msg
));
564 break; /* Lost alignment, don't know what we'd read next */
567 if (msg
.event
!= UFFD_EVENT_PAGEFAULT
) {
568 error_report("%s: Read unexpected event %ud from userfaultfd",
569 __func__
, msg
.event
);
570 continue; /* It's not a page fault, shouldn't happen */
573 rb
= qemu_ram_block_from_host(
574 (void *)(uintptr_t)msg
.arg
.pagefault
.address
,
577 error_report("postcopy_ram_fault_thread: Fault outside guest: %"
578 PRIx64
, (uint64_t)msg
.arg
.pagefault
.address
);
582 rb_offset
&= ~(qemu_ram_pagesize(rb
) - 1);
583 trace_postcopy_ram_fault_thread_request(msg
.arg
.pagefault
.address
,
584 qemu_ram_get_idstr(rb
),
588 * Send the request to the source - we want to request one
589 * of our host page sizes (which is >= TPS)
593 migrate_send_rp_req_pages(mis
, qemu_ram_get_idstr(rb
),
594 rb_offset
, qemu_ram_pagesize(rb
));
596 /* Save some space */
597 migrate_send_rp_req_pages(mis
, NULL
,
598 rb_offset
, qemu_ram_pagesize(rb
));
601 trace_postcopy_ram_fault_thread_exit();
605 int postcopy_ram_enable_notify(MigrationIncomingState
*mis
)
607 /* Open the fd for the kernel to give us userfaults */
608 mis
->userfault_fd
= syscall(__NR_userfaultfd
, O_CLOEXEC
| O_NONBLOCK
);
609 if (mis
->userfault_fd
== -1) {
610 error_report("%s: Failed to open userfault fd: %s", __func__
,
616 * Although the host check already tested the API, we need to
617 * do the check again as an ABI handshake on the new fd.
619 if (!ufd_check_and_apply(mis
->userfault_fd
, mis
)) {
623 /* Now an eventfd we use to tell the fault-thread to quit */
624 mis
->userfault_event_fd
= eventfd(0, EFD_CLOEXEC
);
625 if (mis
->userfault_event_fd
== -1) {
626 error_report("%s: Opening userfault_event_fd: %s", __func__
,
628 close(mis
->userfault_fd
);
632 qemu_sem_init(&mis
->fault_thread_sem
, 0);
633 qemu_thread_create(&mis
->fault_thread
, "postcopy/fault",
634 postcopy_ram_fault_thread
, mis
, QEMU_THREAD_JOINABLE
);
635 qemu_sem_wait(&mis
->fault_thread_sem
);
636 qemu_sem_destroy(&mis
->fault_thread_sem
);
637 mis
->have_fault_thread
= true;
639 /* Mark so that we get notified of accesses to unwritten areas */
640 if (qemu_ram_foreach_block(ram_block_enable_notify
, mis
)) {
645 * Ballooning can mark pages as absent while we're postcopying
646 * that would cause false userfaults.
648 qemu_balloon_inhibit(true);
650 trace_postcopy_ram_enable_notify();
655 static int qemu_ufd_copy_ioctl(int userfault_fd
, void *host_addr
,
656 void *from_addr
, uint64_t pagesize
, RAMBlock
*rb
)
660 struct uffdio_copy copy_struct
;
661 copy_struct
.dst
= (uint64_t)(uintptr_t)host_addr
;
662 copy_struct
.src
= (uint64_t)(uintptr_t)from_addr
;
663 copy_struct
.len
= pagesize
;
664 copy_struct
.mode
= 0;
665 ret
= ioctl(userfault_fd
, UFFDIO_COPY
, ©_struct
);
667 struct uffdio_zeropage zero_struct
;
668 zero_struct
.range
.start
= (uint64_t)(uintptr_t)host_addr
;
669 zero_struct
.range
.len
= pagesize
;
670 zero_struct
.mode
= 0;
671 ret
= ioctl(userfault_fd
, UFFDIO_ZEROPAGE
, &zero_struct
);
674 ramblock_recv_bitmap_set_range(rb
, host_addr
,
675 pagesize
/ qemu_target_page_size());
681 * Place a host page (from) at (host) atomically
682 * returns 0 on success
684 int postcopy_place_page(MigrationIncomingState
*mis
, void *host
, void *from
,
687 size_t pagesize
= qemu_ram_pagesize(rb
);
689 /* copy also acks to the kernel waking the stalled thread up
690 * TODO: We can inhibit that ack and only do it if it was requested
691 * which would be slightly cheaper, but we'd have to be careful
692 * of the order of updating our page state.
694 if (qemu_ufd_copy_ioctl(mis
->userfault_fd
, host
, from
, pagesize
, rb
)) {
696 error_report("%s: %s copy host: %p from: %p (size: %zd)",
697 __func__
, strerror(e
), host
, from
, pagesize
);
702 trace_postcopy_place_page(host
);
707 * Place a zero page at (host) atomically
708 * returns 0 on success
710 int postcopy_place_page_zero(MigrationIncomingState
*mis
, void *host
,
713 trace_postcopy_place_page_zero(host
);
715 if (qemu_ram_pagesize(rb
) == getpagesize()) {
716 if (qemu_ufd_copy_ioctl(mis
->userfault_fd
, host
, NULL
, getpagesize(),
719 error_report("%s: %s zero host: %p",
720 __func__
, strerror(e
), host
);
725 /* The kernel can't use UFFDIO_ZEROPAGE for hugepages */
726 if (!mis
->postcopy_tmp_zero_page
) {
727 mis
->postcopy_tmp_zero_page
= mmap(NULL
, mis
->largest_page_size
,
728 PROT_READ
| PROT_WRITE
,
729 MAP_PRIVATE
| MAP_ANONYMOUS
,
731 if (mis
->postcopy_tmp_zero_page
== MAP_FAILED
) {
733 mis
->postcopy_tmp_zero_page
= NULL
;
734 error_report("%s: %s mapping large zero page",
735 __func__
, strerror(e
));
738 memset(mis
->postcopy_tmp_zero_page
, '\0', mis
->largest_page_size
);
740 return postcopy_place_page(mis
, host
, mis
->postcopy_tmp_zero_page
,
748 * Returns a target page of memory that can be mapped at a later point in time
749 * using postcopy_place_page
750 * The same address is used repeatedly, postcopy_place_page just takes the
752 * Returns: Pointer to allocated page
755 void *postcopy_get_tmp_page(MigrationIncomingState
*mis
)
757 if (!mis
->postcopy_tmp_page
) {
758 mis
->postcopy_tmp_page
= mmap(NULL
, mis
->largest_page_size
,
759 PROT_READ
| PROT_WRITE
, MAP_PRIVATE
|
760 MAP_ANONYMOUS
, -1, 0);
761 if (mis
->postcopy_tmp_page
== MAP_FAILED
) {
762 mis
->postcopy_tmp_page
= NULL
;
763 error_report("%s: %s", __func__
, strerror(errno
));
768 return mis
->postcopy_tmp_page
;
772 /* No target OS support, stubs just fail */
773 bool postcopy_ram_supported_by_host(MigrationIncomingState
*mis
)
775 error_report("%s: No OS support", __func__
);
779 int postcopy_ram_incoming_init(MigrationIncomingState
*mis
, size_t ram_pages
)
781 error_report("postcopy_ram_incoming_init: No OS support");
785 int postcopy_ram_incoming_cleanup(MigrationIncomingState
*mis
)
791 int postcopy_ram_prepare_discard(MigrationIncomingState
*mis
)
797 int postcopy_ram_enable_notify(MigrationIncomingState
*mis
)
803 int postcopy_place_page(MigrationIncomingState
*mis
, void *host
, void *from
,
810 int postcopy_place_page_zero(MigrationIncomingState
*mis
, void *host
,
817 void *postcopy_get_tmp_page(MigrationIncomingState
*mis
)
825 /* ------------------------------------------------------------------------- */
828 * postcopy_discard_send_init: Called at the start of each RAMBlock before
829 * asking to discard individual ranges.
831 * @ms: The current migration state.
832 * @offset: the bitmap offset of the named RAMBlock in the migration
834 * @name: RAMBlock that discards will operate on.
836 * returns: a new PDS.
838 PostcopyDiscardState
*postcopy_discard_send_init(MigrationState
*ms
,
841 PostcopyDiscardState
*res
= g_malloc0(sizeof(PostcopyDiscardState
));
844 res
->ramblock_name
= name
;
851 * postcopy_discard_send_range: Called by the bitmap code for each chunk to
852 * discard. May send a discard message, may just leave it queued to
855 * @ms: Current migration state.
856 * @pds: Structure initialised by postcopy_discard_send_init().
857 * @start,@length: a range of pages in the migration bitmap in the
858 * RAM block passed to postcopy_discard_send_init() (length=1 is one page)
860 void postcopy_discard_send_range(MigrationState
*ms
, PostcopyDiscardState
*pds
,
861 unsigned long start
, unsigned long length
)
863 size_t tp_size
= qemu_target_page_size();
864 /* Convert to byte offsets within the RAM block */
865 pds
->start_list
[pds
->cur_entry
] = start
* tp_size
;
866 pds
->length_list
[pds
->cur_entry
] = length
* tp_size
;
867 trace_postcopy_discard_send_range(pds
->ramblock_name
, start
, length
);
871 if (pds
->cur_entry
== MAX_DISCARDS_PER_COMMAND
) {
872 /* Full set, ship it! */
873 qemu_savevm_send_postcopy_ram_discard(ms
->to_dst_file
,
884 * postcopy_discard_send_finish: Called at the end of each RAMBlock by the
885 * bitmap code. Sends any outstanding discard messages, frees the PDS
887 * @ms: Current migration state.
888 * @pds: Structure initialised by postcopy_discard_send_init().
890 void postcopy_discard_send_finish(MigrationState
*ms
, PostcopyDiscardState
*pds
)
892 /* Anything unsent? */
893 if (pds
->cur_entry
) {
894 qemu_savevm_send_postcopy_ram_discard(ms
->to_dst_file
,
902 trace_postcopy_discard_send_finish(pds
->ramblock_name
, pds
->nsentwords
,
909 * Current state of incoming postcopy; note this is not part of
910 * MigrationIncomingState since it's state is used during cleanup
911 * at the end as MIS is being freed.
913 static PostcopyState incoming_postcopy_state
;
915 PostcopyState
postcopy_state_get(void)
917 return atomic_mb_read(&incoming_postcopy_state
);
920 /* Set the state and return the old state */
921 PostcopyState
postcopy_state_set(PostcopyState new_state
)
923 return atomic_xchg(&incoming_postcopy_state
, new_state
);