postcopy outgoing: add postcopy capability

Added postcopy capability to migrate command with postcopy mode enabled

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- use migration capability instead of -p option

Chnages v1 -> v2:
- catch up for qapi change
postcopy: implement outgoing part of postcopy live migration

This patch implements postcopy live migration for outgoing part

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- manual rebase
- simplification

Changes v3 -> v4:
- ram_save_block wrong comparison

Changes v2 -> v3:
- modify savevm_ram_handlers instead of if (postcopy)
- code simplification

Changes v1 -> v2:
- fix parameter to qemu_fdopen()
- handle QEMU_UMEM_REQ_EOC properly
  when PO_STATE_ALL_PAGES_SENT, QEMU_UMEM_REQ_EOC request was ignored.
  handle properly it.
- flush on-demand page unconditionally
- improve postcopy_outgoing_ram_save_live and postcopy_outgoing_begin()
- use qemu_fopen_fd
- use memory api instead of obsolete api
- segv in postcopy_outgoing_check_all_ram_sent()
- catch up qapi change
postcopy/outgoing: add no background capability to disable background transfer

This is for benchmark purpose

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- use migration capability instead of -n option

Changes v3 -> v4:
- manual rebase
postcopy/outgoing: implement forward/backword prefault

When page is requested, send surrounding pages are also sent.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
arch_init: factor out setting last_block, last_offset

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
postcopy/outgoing: add move background capability

When movebg mode is enabled, the point to send background page is set
to the next page to on-demand page.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v4 -> v5:
- use migration capability instead of -m option
arch_init: factor out ram_load

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
arch_init: export ram_save_iterate()

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
arch_init: export migration_bitmap_sync and helper method to get bitmap

Those migration bitmap operation will be used by postcopy.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
postcopy: pre+post optimization incoming side

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v3 -> v4:
- optimization dirty bitmap scanning
- squashed page removing
postcopy/incoming: optimization direct reply when page is precopied

When guest page is faulted and the page is already precopied,
not wait for faulting thread, but directly reply. So latency will be improved.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
Changes v3 -> v4:
- It should check clean_bitmap not phys_requested for marked_clean.
postcopy/outgoing: introduce precopy_count parameter

Precopy with this loop number before postcopy mode.
This will be implemented by the next patch.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
postcopy: pre+post optimization outgoing side

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
arch_init: debug message

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
migration: enable debug

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
savevm: debug message

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
migration-postcopy.c: enable debug message

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
umem.c: enable debug message

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Revert "kvm: support using KVM_MEM_READONLY flag for regions"

This reverts commit 235e8982ad393e5611cb892df54881c872eea9e1.

Conflicts:
	kvm-all.c