kvm/migration: support KVM_CLEAR_DIRTY_LOG
v2 cover kvm/migration: support KVM_CLEAR_DIRTY_LOG
This is v2 of the QEMU's KVM_CLEAR_DIRTY_LOG series. The major reason for the repost is due to the new kvm capability recently introduced in Linux 5.2-rc1 which is released just one day ago while the old cap is obsolete now, so we'll need a linux header update.
v2:
- rebase, add r-bs from Paolo
- added a few patches
- linux-headers: Update to Linux 5.2-rc1
this is needed because we've got a new cap in kvm
- checkpatch: Allow SPDX-License-Identifier
picked up the standalone patch into the series in case it got lost
- hmp: Expose manual_dirty_log_protect via "info kvm"
qmp: Expose manual_dirty_log_protect via "query-kvm" add interface to detect the new kvm capability
- switched default chunk size to 128M
Performance update is here:
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg03621.html
Summary
=====================
This series allows QEMU to start using the new KVM_CLEAR_DIRTY_LOG interface. For more on KVM_CLEAR_DIRTY_LOG itself, please refer to:
https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/api.txt#L3810
The QEMU work (which is this series) is pushed too, please find the tree here:
https://github.com/xzpeter/qemu/tree/kvm-clear-dirty-log
Meanwhile, For anyone who really wants to try this out, please also upgrade the host kernel to linux 5.2-rc1.
Design
===================
I started with a naive/stupid design that I always pass all 1's to the KVM for a memory range to clear all the dirty bits within that memory range, but then I encountered guest oops - it's simply because we can't clear any dirty bit from QEMU if we are not _sure_ that the bit is dirty in the kernel. Otherwise we might accidentally clear a bit that we don't even know of (e.g., the bit was clear in migration's dirty bitmap in QEMU) but actually that page was just being written so QEMU will never remember to migrate that new page again.
The new design is focused on a dirty bitmap cache within the QEMU kvm layer (which is per kvm memory slot). With that we know what's dirty in the kernel previously (note! the kernel bitmap is still growing all the time so the cache will only be a subset of the realtime kernel bitmap but that's far enough for us) and with that we'll be sure to not accidentally clear unknown dirty pages.
With this method, we can also avoid race when multiple users (e.g., DIRTY_MEMORY_VGA and DIRTY_MEMORY_MIGRATION) want to clear the bit for multiple time. If without the kvm memory slot cached dirty bitmap we won't be able to know which bit has been cleared and then if we send the CLEAR operation upon the same bit twice (or more) we can still face the same issue to clear something accidentally while we shouldn't.
Summary: we really need to be careful on what bit to clear otherwise we can face anything after the migration completes. And I hope this series has considered all about this.
Besides the new KVM cache layer and the new ioctl support, this series introduced the memory_region_clear_dirty_bitmap() in the memory API layer to allow clearing dirty bits of a specific memory range within the memory region.
Implementations
============================
Patch 1-3: these should be nothing directly related to the series but
they are things I found during working on it. They can be picked even earlier if reviewers are happy with them.
Patch 4: pre-work on bitmap operations, and within the patch I added
the first unit test for utils/bitmap.c.
Patch 5-6: the new memory API interface. Since no one is providing
log_clear() yet so it's not working yet. Note that this only splits the dirty clear operation from sync but it hasn't yet been splitted into smaller chunk so it's not really helpful for us yet.
Patch 7-10: kvm support of KVM_CLEAR_DIRTY_LOG.
Patch 11: do the log_clear() splitting for the case of migration.
Also a new parameter is introduced to define the block size of the small chunks (the unit to clear dirty bits)
Tests
===========================
- make check
- migrate idle/memory-heavy guests
(Not yet tested with huge guests but it'll be more than welcomed if
someone has the resource and wants to give it a shot)
Please have a look, thanks.
Peter Xu (15):
checkpatch: Allow SPDX-License-Identifier
linux-headers: Update to Linux 5.2-rc1
migration: No need to take rcu during sync_dirty_bitmap
memory: Remove memory_region_get_dirty()
memory: Don't set migration bitmap when without migration
bitmap: Add bitmap_copy_with_{src|dst}_offset()
memory: Pass mr into snapshot_and_clear_dirty
memory: Introduce memory listener hook log_clear()
kvm: Update comments for sync_dirty_bitmap
kvm: Persistent per kvmslot dirty bitmap
kvm: Introduce slots lock for memory listener
kvm: Support KVM_CLEAR_DIRTY_LOG
qmp: Expose manual_dirty_log_protect via "query-kvm"
hmp: Expose manual_dirty_log_protect via "info kvm"
migration: Split log_clear() into smaller chunks
accel/kvm/kvm-all.c | 292 +++++++++++++++--- accel/kvm/trace-events | 1 + exec.c | 15 +- hmp.c | 2 + include/exec/memory.h | 36 ++- include/exec/ram_addr.h | 91 +++++- include/qemu/bitmap.h | 9 + .../infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h | 15 +- include/standard-headers/drm/drm_fourcc.h | 114 ++++++- include/standard-headers/linux/ethtool.h | 48 ++- .../linux/input-event-codes.h | 9 +- include/standard-headers/linux/input.h | 6 +- include/standard-headers/linux/pci_regs.h | 140 +++++---- .../standard-headers/linux/virtio_config.h | 6 + include/standard-headers/linux/virtio_gpu.h | 12 +- include/standard-headers/linux/virtio_ring.h | 10 - .../standard-headers/rdma/vmw_pvrdma-abi.h | 1 + include/sysemu/kvm.h | 2 + include/sysemu/kvm_int.h | 4 + linux-headers/asm-arm/unistd-common.h | 32 ++ linux-headers/asm-arm64/kvm.h | 43 +++ linux-headers/asm-arm64/unistd.h | 2 + linux-headers/asm-generic/mman-common.h | 4 +- linux-headers/asm-generic/unistd.h | 170 ++++++++-- linux-headers/asm-mips/mman.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 30 ++ linux-headers/asm-mips/unistd_n64.h | 10 + linux-headers/asm-mips/unistd_o32.h | 40 +++ linux-headers/asm-powerpc/kvm.h | 48 +++ linux-headers/asm-powerpc/unistd_32.h | 40 +++ linux-headers/asm-powerpc/unistd_64.h | 21 ++ linux-headers/asm-s390/kvm.h | 5 +- linux-headers/asm-s390/unistd_32.h | 43 +++ linux-headers/asm-s390/unistd_64.h | 24 ++ linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 40 +++ linux-headers/asm-x86/unistd_64.h | 10 + linux-headers/asm-x86/unistd_x32.h | 10 + linux-headers/linux/kvm.h | 15 +- linux-headers/linux/mman.h | 4 + linux-headers/linux/psci.h | 7 + linux-headers/linux/psp-sev.h | 18 +- linux-headers/linux/vfio.h | 4 + linux-headers/linux/vfio_ccw.h | 12 + memory.c | 64 +++- migration/migration.c | 4 + migration/migration.h | 27 ++ migration/ram.c | 45 +++ migration/trace-events | 1 + qapi/misc.json | 6 +- qmp.c | 1 + scripts/checkpatch.pl | 3 +- tests/Makefile.include | 2 + tests/test-bitmap.c | 81 +++++ util/bitmap.c | 73 +++++ 55 files changed, 1542 insertions(+), 215 deletions(-) create mode 100644 tests/test-bitmap.c
Signature · 1 line
2.17.1
PATCH v2 1/15 checkpatch: Allow SPDX-License-Identifier
According to: https://spdx.org/ids-how, let's still allow QEMU to use the SPDX license identifier:
// SPDX-License-Identifier: ***
--- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
@@ -1949,7 +1949,8 @@ sub process { } # no C99 // comments - if ($line =~ m{//}) { + if ($line =~ m{//} && + $rawline !~ m{// SPDX-License-Identifier: }) { ERROR("do not use C99 // comments\n" . $herecurr); } # Remove C99 comments.
Signature · 1 line
2.17.1
PATCH v2 2/15 linux-headers: Update to Linux 5.2-rc1
In reply to Peter Xu--- .../infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h | 15 +- include/standard-headers/drm/drm_fourcc.h | 114 +++++++++++- include/standard-headers/linux/ethtool.h | 48 +++-- .../linux/input-event-codes.h | 9 +- include/standard-headers/linux/input.h | 6 +- include/standard-headers/linux/pci_regs.h | 140 ++++++++------- .../standard-headers/linux/virtio_config.h | 6 + include/standard-headers/linux/virtio_gpu.h | 12 +- include/standard-headers/linux/virtio_ring.h | 10 -- .../standard-headers/rdma/vmw_pvrdma-abi.h | 1 + linux-headers/asm-arm/unistd-common.h | 32 ++++ linux-headers/asm-arm64/kvm.h | 43 +++++ linux-headers/asm-arm64/unistd.h | 2 + linux-headers/asm-generic/mman-common.h | 4 +- linux-headers/asm-generic/unistd.h | 170 ++++++++++++++---- linux-headers/asm-mips/mman.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 30 ++++ linux-headers/asm-mips/unistd_n64.h | 10 ++ linux-headers/asm-mips/unistd_o32.h | 40 +++++ linux-headers/asm-powerpc/kvm.h | 48 +++++ linux-headers/asm-powerpc/unistd_32.h | 40 +++++ linux-headers/asm-powerpc/unistd_64.h | 21 +++ linux-headers/asm-s390/kvm.h | 5 +- linux-headers/asm-s390/unistd_32.h | 43 +++++ linux-headers/asm-s390/unistd_64.h | 24 +++ linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 40 +++++ linux-headers/asm-x86/unistd_64.h | 10 ++ linux-headers/asm-x86/unistd_x32.h | 10 ++ linux-headers/linux/kvm.h | 15 +- linux-headers/linux/mman.h | 4 + linux-headers/linux/psci.h | 7 + linux-headers/linux/psp-sev.h | 18 +- linux-headers/linux/vfio.h | 4 + linux-headers/linux/vfio_ccw.h | 12 ++ 35 files changed, 854 insertions(+), 144 deletions(-)
include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h +10 -5
@@ -57,7 +57,8 @@#define PVRDMA_ROCEV1_VERSION 17#define PVRDMA_ROCEV2_VERSION 18 -#define PVRDMA_VERSION PVRDMA_ROCEV2_VERSION +#define PVRDMA_PPN64_VERSION 19 +#define PVRDMA_VERSION PVRDMA_PPN64_VERSION#define PVRDMA_BOARD_ID 1#define PVRDMA_REV_ID 1
@@ -279,8 +280,10 @@ struct pvrdma_device_shared_region {/* W: Async ring page info. */ struct pvrdma_ring_page_info cq_ring_pages;/* W: CQ ring page info. */ -uint32_t uar_pfn;/* W: UAR pageframe. */ -uint32_t pad2;/* Pad to 8-byte align. */ +union { +uint32_t uar_pfn;/* W: UAR pageframe. */ +uint64_t uar_pfn64;/* W: 64-bit UAR page frame. */ + };struct pvrdma_device_caps caps;/* R: Device capabilities. */ };
@@ -411,8 +414,10 @@ struct pvrdma_cmd_query_pkey_resp {struct pvrdma_cmd_create_uc {struct pvrdma_cmd_hdr hdr; -uint32_t pfn;/* UAR page frame number */ -uint8_t reserved[4 ]; +union { +uint32_t pfn;/* UAR page frame number */ +uint64_t pfn64;/* 64-bit UAR page frame number */ + }; };struct pvrdma_cmd_create_uc_resp {
include/standard-headers/drm/drm_fourcc.h +113 -1
166 lines not on this page · raw message
include/standard-headers/linux/ethtool.h +38 -10
86 lines not on this page · raw message
include/standard-headers/linux/input-event-codes.h +7 -2
@@ -439,10 +439,12 @@#define KEY_TITLE 0x171#define KEY_SUBTITLE 0x172#define KEY_ANGLE 0x173 -#define KEY_ZOOM 0x174 +#define KEY_FULL_SCREEN 0x174/* AC View Toggle */ +#define KEY_ZOOM KEY_FULL_SCREEN#define KEY_MODE 0x175#define KEY_KEYBOARD 0x176 -#define KEY_SCREEN 0x177 +#define KEY_ASPECT_RATIO 0x177/* HUTRR37: Aspect */ +#define KEY_SCREEN KEY_ASPECT_RATIO#define KEY_PC 0x178/* Media Select Computer */ #define KEY_TV 0x179/* Media Select TV */ #define KEY_TV2 0x17a/* Media Select Cable */
@@ -604,6 +606,7 @@#define KEY_SCREENSAVER 0x245/* AL Screen Saver */ #define KEY_VOICECOMMAND 0x246/* Listening Voice Command */ #define KEY_ASSISTANT 0x247/* AL Context-aware desktop assistant */ +#define KEY_KBD_LAYOUT_NEXT 0x248/* AC Next Keyboard Layout Select */ #define KEY_BRIGHTNESS_MIN 0x250/* Set Brightness to Minimum */ #define KEY_BRIGHTNESS_MAX 0x251/* Set Brightness to Maximum */
@@ -716,6 +719,8 @@* the situation described above. */ #define REL_RESERVED 0x0a +#define REL_WHEEL_HI_RES 0x0b +#define REL_HWHEEL_HI_RES 0x0c#define REL_MAX 0x0f#define REL_CNT (REL_MAX+1)
include/standard-headers/linux/input.h +5 -1
@@ -23,13 +23,17 @@*/ struct input_event { -#if (HOST_LONG_BITS !=32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL) +#if (HOST_LONG_BITS !=32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL__)struct timeval time;#define input_event_sec time.tv_sec#define input_event_usec time.tv_usec#else unsigned long __sec; +#if defined(__sparc__) && defined(__arch64__) +unsigned int __usec; +#else unsigned long __usec; +#endif #define input_event_sec __sec#define input_event_usec __usec#endif
include/standard-headers/linux/pci_regs.h +73 -67
245 lines not on this page · raw message
include/standard-headers/linux/virtio_config.h +6 -0
@@ -78,6 +78,12 @@/* This feature indicates support for the packed virtqueue layout. */ #define VIRTIO_F_RING_PACKED 34 +/* +* This feature indicates that memory accesses by the driver and the +* device are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 +/* * Does the device support Single Root I/O Virtualization? */
include/standard-headers/linux/virtio_gpu.h +10 -2
@@ -40,8 +40,16 @@#include "standard-headers/linux/types.h" -#define VIRTIO_GPU_F_VIRGL 0 -#define VIRTIO_GPU_F_EDID 1 +/* +* VIRTIO_GPU_CMD_CTX_* +* VIRTIO_GPU_CMD_*_3D +*/ +#define VIRTIO_GPU_F_VIRGL 0 + +/* +* VIRTIO_GPU_CMD_GET_EDID +*/ +#define VIRTIO_GPU_F_EDID 1enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
include/standard-headers/linux/virtio_ring.h +0 -10
@@ -211,14 +211,4 @@ struct vring_packed_desc { uint16_t flags; }; -struct vring_packed { -unsigned int num; - -struct vring_packed_desc *desc; - -struct vring_packed_desc_event *driver; - -struct vring_packed_desc_event *device; -}; -#endif /* _LINUX_VIRTIO_RING_H */
include/standard-headers/rdma/vmw_pvrdma-abi.h +1 -0
@@ -78,6 +78,7 @@ enum pvrdma_wr_opcode {PVRDMA_WR_MASKED_ATOMIC_FETCH_AND_ADD ,PVRDMA_WR_BIND_MW ,PVRDMA_WR_REG_SIG_MR , + PVRDMA_WR_ERROR, }; enum pvrdma_wc_status {
linux-headers/asm-arm/unistd-common.h +32 -0
@@ -356,5 +356,37 @@#define __NR_statx (__NR_SYSCALL_BASE + 397)#define __NR_rseq (__NR_SYSCALL_BASE + 398)#define __NR_io_pgetevents (__NR_SYSCALL_BASE + 399) +#define __NR_migrate_pages (__NR_SYSCALL_BASE + 400) +#define __NR_kexec_file_load (__NR_SYSCALL_BASE + 401) +#define __NR_clock_gettime64 (__NR_SYSCALL_BASE + 403) +#define __NR_clock_settime64 (__NR_SYSCALL_BASE + 404) +#define __NR_clock_adjtime64 (__NR_SYSCALL_BASE + 405) +#define __NR_clock_getres_time64 (__NR_SYSCALL_BASE + 406) +#define __NR_clock_nanosleep_time64 (__NR_SYSCALL_BASE + 407) +#define __NR_timer_gettime64 (__NR_SYSCALL_BASE + 408) +#define __NR_timer_settime64 (__NR_SYSCALL_BASE + 409) +#define __NR_timerfd_gettime64 (__NR_SYSCALL_BASE + 410) +#define __NR_timerfd_settime64 (__NR_SYSCALL_BASE + 411) +#define __NR_utimensat_time64 (__NR_SYSCALL_BASE + 412) +#define __NR_pselect6_time64 (__NR_SYSCALL_BASE + 413) +#define __NR_ppoll_time64 (__NR_SYSCALL_BASE + 414) +#define __NR_io_pgetevents_time64 (__NR_SYSCALL_BASE + 416) +#define __NR_recvmmsg_time64 (__NR_SYSCALL_BASE + 417) +#define __NR_mq_timedsend_time64 (__NR_SYSCALL_BASE + 418) +#define __NR_mq_timedreceive_time64 (__NR_SYSCALL_BASE + 419) +#define __NR_semtimedop_time64 (__NR_SYSCALL_BASE + 420) +#define __NR_rt_sigtimedwait_time64 (__NR_SYSCALL_BASE + 421) +#define __NR_futex_time64 (__NR_SYSCALL_BASE + 422) +#define __NR_sched_rr_get_interval_time64 (__NR_SYSCALL_BASE + 423) +#define __NR_pidfd_send_signal (__NR_SYSCALL_BASE + 424) +#define __NR_io_uring_setup (__NR_SYSCALL_BASE + 425) +#define __NR_io_uring_enter (__NR_SYSCALL_BASE + 426) +#define __NR_io_uring_register (__NR_SYSCALL_BASE + 427) +#define __NR_open_tree (__NR_SYSCALL_BASE + 428) +#define __NR_move_mount (__NR_SYSCALL_BASE + 429) +#define __NR_fsopen (__NR_SYSCALL_BASE + 430) +#define __NR_fsconfig (__NR_SYSCALL_BASE + 431) +#define __NR_fsmount (__NR_SYSCALL_BASE + 432) +#define __NR_fspick (__NR_SYSCALL_BASE + 433)#endif /* _ASM_ARM_UNISTD_COMMON_H */
linux-headers/asm-arm64/kvm.h +43 -0
61 lines not on this page · raw message
linux-headers/asm-arm64/unistd.h +2 -0
@@ -17,5 +17,7 @@#define __ARCH_WANT_RENAMEAT#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#define __ARCH_WANT_TIME32_SYSCALLS#include <asm-generic/unistd.h>
linux-headers/asm-generic/mman-common.h +1 -3
@@ -15,9 +15,7 @@#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -#define MAP_SHARED 0x01/* Share changes */ -#define MAP_PRIVATE 0x02/* Changes are private */ -#define MAP_SHARED_VALIDATE 0x03/* share + validate extension flags */ +/* 0x01 - 0x03 are defined in linux/mman.h */ #define MAP_TYPE 0x0f/* Mask for type of mapping */ #define MAP_FIXED 0x10/* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20/* don't use a file */
linux-headers/asm-generic/unistd.h +137 -33
317 lines not on this page · raw message
linux-headers/asm-mips/mman.h +1 -3
@@ -27,9 +27,7 @@/* * Flags for mmap */ -#define MAP_SHARED 0x001/* Share changes */ -#define MAP_PRIVATE 0x002/* Changes are private */ -#define MAP_SHARED_VALIDATE 0x003/* share + validate extension flags */ +/* 0x01 - 0x03 are defined in linux/mman.h */ #define MAP_TYPE 0x00f/* Mask for type of mapping */ #define MAP_FIXED 0x010/* Interpret addr exactly */
linux-headers/asm-mips/unistd_n32.h +30 -0
@@ -333,6 +333,36 @@#define __NR_statx (__NR_Linux + 330)#define __NR_rseq (__NR_Linux + 331)#define __NR_io_pgetevents (__NR_Linux + 332) +#define __NR_clock_gettime64 (__NR_Linux + 403) +#define __NR_clock_settime64 (__NR_Linux + 404) +#define __NR_clock_adjtime64 (__NR_Linux + 405) +#define __NR_clock_getres_time64 (__NR_Linux + 406) +#define __NR_clock_nanosleep_time64 (__NR_Linux + 407) +#define __NR_timer_gettime64 (__NR_Linux + 408) +#define __NR_timer_settime64 (__NR_Linux + 409) +#define __NR_timerfd_gettime64 (__NR_Linux + 410) +#define __NR_timerfd_settime64 (__NR_Linux + 411) +#define __NR_utimensat_time64 (__NR_Linux + 412) +#define __NR_pselect6_time64 (__NR_Linux + 413) +#define __NR_ppoll_time64 (__NR_Linux + 414) +#define __NR_io_pgetevents_time64 (__NR_Linux + 416) +#define __NR_recvmmsg_time64 (__NR_Linux + 417) +#define __NR_mq_timedsend_time64 (__NR_Linux + 418) +#define __NR_mq_timedreceive_time64 (__NR_Linux + 419) +#define __NR_semtimedop_time64 (__NR_Linux + 420) +#define __NR_rt_sigtimedwait_time64 (__NR_Linux + 421) +#define __NR_futex_time64 (__NR_Linux + 422) +#define __NR_sched_rr_get_interval_time64 (__NR_Linux + 423) +#define __NR_pidfd_send_signal (__NR_Linux + 424) +#define __NR_io_uring_setup (__NR_Linux + 425) +#define __NR_io_uring_enter (__NR_Linux + 426) +#define __NR_io_uring_register (__NR_Linux + 427) +#define __NR_open_tree (__NR_Linux + 428) +#define __NR_move_mount (__NR_Linux + 429) +#define __NR_fsopen (__NR_Linux + 430) +#define __NR_fsconfig (__NR_Linux + 431) +#define __NR_fsmount (__NR_Linux + 432) +#define __NR_fspick (__NR_Linux + 433)#endif /* _ASM_MIPS_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +10 -0
@@ -329,6 +329,16 @@#define __NR_statx (__NR_Linux + 326)#define __NR_rseq (__NR_Linux + 327)#define __NR_io_pgetevents (__NR_Linux + 328) +#define __NR_pidfd_send_signal (__NR_Linux + 424) +#define __NR_io_uring_setup (__NR_Linux + 425) +#define __NR_io_uring_enter (__NR_Linux + 426) +#define __NR_io_uring_register (__NR_Linux + 427) +#define __NR_open_tree (__NR_Linux + 428) +#define __NR_move_mount (__NR_Linux + 429) +#define __NR_fsopen (__NR_Linux + 430) +#define __NR_fsconfig (__NR_Linux + 431) +#define __NR_fsmount (__NR_Linux + 432) +#define __NR_fspick (__NR_Linux + 433)#endif /* _ASM_MIPS_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +40 -0
@@ -369,6 +369,46 @@#define __NR_statx (__NR_Linux + 366)#define __NR_rseq (__NR_Linux + 367)#define __NR_io_pgetevents (__NR_Linux + 368) +#define __NR_semget (__NR_Linux + 393) +#define __NR_semctl (__NR_Linux + 394) +#define __NR_shmget (__NR_Linux + 395) +#define __NR_shmctl (__NR_Linux + 396) +#define __NR_shmat (__NR_Linux + 397) +#define __NR_shmdt (__NR_Linux + 398) +#define __NR_msgget (__NR_Linux + 399) +#define __NR_msgsnd (__NR_Linux + 400) +#define __NR_msgrcv (__NR_Linux + 401) +#define __NR_msgctl (__NR_Linux + 402) +#define __NR_clock_gettime64 (__NR_Linux + 403) +#define __NR_clock_settime64 (__NR_Linux + 404) +#define __NR_clock_adjtime64 (__NR_Linux + 405) +#define __NR_clock_getres_time64 (__NR_Linux + 406) +#define __NR_clock_nanosleep_time64 (__NR_Linux + 407) +#define __NR_timer_gettime64 (__NR_Linux + 408) +#define __NR_timer_settime64 (__NR_Linux + 409) +#define __NR_timerfd_gettime64 (__NR_Linux + 410) +#define __NR_timerfd_settime64 (__NR_Linux + 411) +#define __NR_utimensat_time64 (__NR_Linux + 412) +#define __NR_pselect6_time64 (__NR_Linux + 413) +#define __NR_ppoll_time64 (__NR_Linux + 414) +#define __NR_io_pgetevents_time64 (__NR_Linux + 416) +#define __NR_recvmmsg_time64 (__NR_Linux + 417) +#define __NR_mq_timedsend_time64 (__NR_Linux + 418) +#define __NR_mq_timedreceive_time64 (__NR_Linux + 419) +#define __NR_semtimedop_time64 (__NR_Linux + 420) +#define __NR_rt_sigtimedwait_time64 (__NR_Linux + 421) +#define __NR_futex_time64 (__NR_Linux + 422) +#define __NR_sched_rr_get_interval_time64 (__NR_Linux + 423) +#define __NR_pidfd_send_signal (__NR_Linux + 424) +#define __NR_io_uring_setup (__NR_Linux + 425) +#define __NR_io_uring_enter (__NR_Linux + 426) +#define __NR_io_uring_register (__NR_Linux + 427) +#define __NR_open_tree (__NR_Linux + 428) +#define __NR_move_mount (__NR_Linux + 429) +#define __NR_fsopen (__NR_Linux + 430) +#define __NR_fsconfig (__NR_Linux + 431) +#define __NR_fsmount (__NR_Linux + 432) +#define __NR_fspick (__NR_Linux + 433)#endif /* _ASM_MIPS_UNISTD_O32_H */
linux-headers/asm-powerpc/kvm.h +48 -0
68 lines not on this page · raw message
linux-headers/asm-powerpc/unistd_32.h +40 -0
@@ -376,6 +376,46 @@#define __NR_pkey_mprotect 386#define __NR_rseq 387#define __NR_io_pgetevents 388 +#define __NR_semget 393 +#define __NR_semctl 394 +#define __NR_shmget 395 +#define __NR_shmctl 396 +#define __NR_shmat 397 +#define __NR_shmdt 398 +#define __NR_msgget 399 +#define __NR_msgsnd 400 +#define __NR_msgrcv 401 +#define __NR_msgctl 402 +#define __NR_clock_gettime64 403 +#define __NR_clock_settime64 404 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres_time64 406 +#define __NR_clock_nanosleep_time64 407 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime64 409 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime64 411 +#define __NR_utimensat_time64 412 +#define __NR_pselect6_time64 413 +#define __NR_ppoll_time64 414 +#define __NR_io_pgetevents_time64 416 +#define __NR_recvmmsg_time64 417 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_timedreceive_time64 419 +#define __NR_semtimedop_time64 420 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_futex_time64 422 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433#endif /* _ASM_POWERPC_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +21 -0
@@ -367,6 +367,27 @@#define __NR_pkey_mprotect 386#define __NR_rseq 387#define __NR_io_pgetevents 388 +#define __NR_semtimedop 392 +#define __NR_semget 393 +#define __NR_semctl 394 +#define __NR_shmget 395 +#define __NR_shmctl 396 +#define __NR_shmat 397 +#define __NR_shmdt 398 +#define __NR_msgget 399 +#define __NR_msgsnd 400 +#define __NR_msgrcv 401 +#define __NR_msgctl 402 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433#endif /* _ASM_POWERPC_UNISTD_64_H */
linux-headers/asm-s390/kvm.h +4 -1
@@ -152,7 +152,10 @@ struct kvm_s390_vm_cpu_subfunc {__u8 pcc[16 ];/* with MSA4 */ __u8 ppno[16 ];/* with MSA5 */ __u8 kma[16 ];/* with MSA8 */ -__u8 reserved[1808 ]; +__u8 kdsa[16 ];/* with MSA9 */ +__u8 sortl[32 ];/* with STFLE.150 */ +__u8 dfltcc[32 ];/* with STFLE.151 */ +__u8 reserved[1728 ]; };/* kvm attributes for crypto */
linux-headers/asm-s390/unistd_32.h +43 -0
48 lines not on this page · raw message
linux-headers/asm-s390/unistd_64.h +24 -0
@@ -330,5 +330,29 @@#define __NR_kexec_file_load 381#define __NR_io_pgetevents 382#define __NR_rseq 383 +#define __NR_pkey_mprotect 384 +#define __NR_pkey_alloc 385 +#define __NR_pkey_free 386 +#define __NR_semtimedop 392 +#define __NR_semget 393 +#define __NR_semctl 394 +#define __NR_shmget 395 +#define __NR_shmctl 396 +#define __NR_shmat 397 +#define __NR_shmdt 398 +#define __NR_msgget 399 +#define __NR_msgsnd 400 +#define __NR_msgrcv 401 +#define __NR_msgctl 402 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433#endif /* _ASM_S390_UNISTD_64_H */
linux-headers/asm-x86/kvm.h +1 -0
@@ -381,6 +381,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0)#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1)#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) +#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3)#define KVM_STATE_NESTED_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_RUN_PENDING 0x00000002
linux-headers/asm-x86/unistd_32.h +40 -0
@@ -384,5 +384,45 @@#define __NR_arch_prctl 384#define __NR_io_pgetevents 385#define __NR_rseq 386 +#define __NR_semget 393 +#define __NR_semctl 394 +#define __NR_shmget 395 +#define __NR_shmctl 396 +#define __NR_shmat 397 +#define __NR_shmdt 398 +#define __NR_msgget 399 +#define __NR_msgsnd 400 +#define __NR_msgrcv 401 +#define __NR_msgctl 402 +#define __NR_clock_gettime64 403 +#define __NR_clock_settime64 404 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres_time64 406 +#define __NR_clock_nanosleep_time64 407 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime64 409 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime64 411 +#define __NR_utimensat_time64 412 +#define __NR_pselect6_time64 413 +#define __NR_ppoll_time64 414 +#define __NR_io_pgetevents_time64 416 +#define __NR_recvmmsg_time64 417 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_timedreceive_time64 419 +#define __NR_semtimedop_time64 420 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_futex_time64 422 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433#endif /* _ASM_X86_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +10 -0
@@ -336,5 +336,15 @@#define __NR_statx 332#define __NR_io_pgetevents 333#define __NR_rseq 334 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433#endif /* _ASM_X86_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +10 -0
@@ -289,6 +289,16 @@#define __NR_statx (__X32_SYSCALL_BIT + 332)#define __NR_io_pgetevents (__X32_SYSCALL_BIT + 333)#define __NR_rseq (__X32_SYSCALL_BIT + 334) +#define __NR_pidfd_send_signal (__X32_SYSCALL_BIT + 424) +#define __NR_io_uring_setup (__X32_SYSCALL_BIT + 425) +#define __NR_io_uring_enter (__X32_SYSCALL_BIT + 426) +#define __NR_io_uring_register (__X32_SYSCALL_BIT + 427) +#define __NR_open_tree (__X32_SYSCALL_BIT + 428) +#define __NR_move_mount (__X32_SYSCALL_BIT + 429) +#define __NR_fsopen (__X32_SYSCALL_BIT + 430) +#define __NR_fsconfig (__X32_SYSCALL_BIT + 431) +#define __NR_fsmount (__X32_SYSCALL_BIT + 432) +#define __NR_fspick (__X32_SYSCALL_BIT + 433)#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/kvm.h +13 -2
@@ -986,8 +986,13 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163#define KVM_CAP_EXCEPTION_PAYLOAD 164#define KVM_CAP_ARM_VM_IPA_SIZE 165 -#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 +#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166/* Obsolete */ #define KVM_CAP_HYPERV_CPUID 167 +#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 168 +#define KVM_CAP_PPC_IRQ_XIVE 169 +#define KVM_CAP_ARM_SVE 170 +#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171 +#define KVM_CAP_ARM_PTRAUTH_GENERIC 172#ifdef KVM_CAP_IRQ_ROUTING
@@ -1145,6 +1150,7 @@ struct kvm_dirty_tlb {#define KVM_REG_SIZE_U256 0x0050000000000000ULL#define KVM_REG_SIZE_U512 0x0060000000000000ULL#define KVM_REG_SIZE_U1024 0x0070000000000000ULL +#define KVM_REG_SIZE_U2048 0x0080000000000000ULLstruct kvm_reg_list {__u64 n;/* number of regs */
@@ -1211,6 +1217,8 @@ enum kvm_device_type {#define KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_ARM_VGIC_ITS,#define KVM_DEV_TYPE_ARM_VGIC_ITS KVM_DEV_TYPE_ARM_VGIC_ITS + KVM_DEV_TYPE_XIVE, +#define KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_MAX, };
@@ -1434,12 +1442,15 @@ struct kvm_enc_region {#define KVM_GET_NESTED_STATE _IOWR(KVMIO, 0xbe, struct kvm_nested_state)#define KVM_SET_NESTED_STATE _IOW(KVMIO, 0xbf, struct kvm_nested_state) -/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT */ +/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT_2 */ #define KVM_CLEAR_DIRTY_LOG _IOWR(KVMIO, 0xc0, struct kvm_clear_dirty_log)/* Available with KVM_CAP_HYPERV_CPUID */ #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) +/* Available with KVM_CAP_ARM_SVE */ +#define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
linux-headers/linux/mman.h +4 -0
@@ -12,6 +12,10 @@#define OVERCOMMIT_ALWAYS 1#define OVERCOMMIT_NEVER 2 +#define MAP_SHARED 0x01/* Share changes */ +#define MAP_PRIVATE 0x02/* Changes are private */ +#define MAP_SHARED_VALIDATE 0x03/* share + validate extension flags */ +/* * Huge page size encoding when MAP_HUGETLB is specified, and a huge page * size other than the default is desired. See hugetlb_encode.h.
linux-headers/linux/psci.h +7 -0
@@ -49,8 +49,11 @@#define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10)#define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14) +#define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) +#define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18)#define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) +#define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18)/* PSCI v0.2 power state encoding for CPU_SUSPEND function */ #define PSCI_0_2_POWER_STATE_ID_MASK 0xffff
@@ -97,6 +100,10 @@#define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK \ (0x1 << PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT) +#define PSCI_1_0_OS_INITIATED BIT(0) +#define PSCI_1_0_SUSPEND_MODE_PC 0 +#define PSCI_1_0_SUSPEND_MODE_OSI 1 +/* PSCI return values (inclusive of all PSCI versions) */ #define PSCI_RET_SUCCESS 0#define PSCI_RET_NOT_SUPPORTED -1
linux-headers/linux/psp-sev.h +14 -4
@@ -6,8 +6,7 @@* * Author: Brijesh Singh <[email protected]> * -* SEV spec 0.14 is available at: -* http://support.amd.com/TechDocs/55766_SEV-KM%20API_Specification.pdf +* SEV API specification is available at: https://developer.amd.com/sev/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as
@@ -30,7 +29,8 @@ enum {SEV_PDH_GEN ,SEV_PDH_CERT_EXPORT ,SEV_PEK_CERT_IMPORT , -SEV_GET_ID , +SEV_GET_ID ,/* This command is deprecated, use SEV_GET_ID2 */ +SEV_GET_ID2 , SEV_MAX, };
@@ -125,7 +125,7 @@ struct sev_user_data_pdh_cert_export { } __attribute__((packed));/** -* struct sev_user_data_get_id - GET_ID command parameters +* struct sev_user_data_get_id - GET_ID command parameters (deprecated) * * @socket1: Buffer to pass unique ID of first socket * @socket2: Buffer to pass unique ID of second socket
@@ -135,6 +135,16 @@ struct sev_user_data_get_id {__u8 socket2[64 ];/* Out */ } __attribute__((packed)); +/** +* struct sev_user_data_get_id2 - GET_ID command parameters +* @address: Buffer to store unique ID +* @length: length of the unique ID +*/ +struct sev_user_data_get_id2 { +__u64 address;/* In */ +__u32 length;/* In/Out */ +} __attribute__((packed)); +/** * struct sev_issue_cmd - SEV ioctl parameters *
linux-headers/linux/vfio.h +4 -0
@@ -353,6 +353,10 @@ struct vfio_region_gfx_edid {#define VFIO_DEVICE_GFX_LINK_STATE_DOWN 2 }; +#define VFIO_REGION_TYPE_CCW (2) +/* ccw sub-types */ +#define VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD (1) +/* * 10de vendor sub-type *
linux-headers/linux/vfio_ccw.h +12 -0
@@ -12,6 +12,7 @@#include <linux/types.h> +/* used for START SUBCHANNEL, always present */ struct ccw_io_region {#define ORB_AREA_SIZE 12__u8 orb_area[ORB_AREA_SIZE ];
@@ -22,4 +23,15 @@ struct ccw_io_region {__u32 ret_code; } __attribute__((packed)); +/* +* used for processing commands that trigger asynchronous actions +* Note: this is controlled by a capability +*/ +#define VFIO_CCW_ASYNC_CMD_HSCH (1 << 0) +#define VFIO_CCW_ASYNC_CMD_CSCH (1 << 1) +struct ccw_cmd_region { +__u32 command; +__u32 ret_code; +} __attribute__((packed)); +#endif
Signature · 1 line
2.17.1
PATCH v2 3/15 migration: No need to take rcu during sync_dirty_bitmap
In reply to Peter Xucpu_physical_memory_sync_dirty_bitmap() has one RAMBlock* as parameter, which means that it must be with RCU read lock held already. Taking it again inside seems redundant. Removing it. Instead comment on the functions about the RCU read lock.
--- include/exec/ram_addr.h | 5 +---- migration/ram.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)
include/exec/ram_addr.h +1 -4
@@ -408,6 +408,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, } +/* Must be with rcu read lock held */ static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, ram_addr_t start,
@@ -431,8 +432,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, DIRTY_MEMORY_BLOCK_SIZE);unsigned long page =BIT_WORD (start >>TARGET_PAGE_BITS ); -rcu_read_lock (); - src =atomic_rcu_read ( &ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION ])->blocks;
@@ -452,8 +451,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, idx++; } } - -rcu_read_unlock (); }else {ram_addr_t offset = rb->offset;
migration/ram.c +1 -0
@@ -1678,6 +1678,7 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs,return ret; } +/* Must be with rcu read lock held */ static void migration_bitmap_sync_range (RAMState *rs,RAMBlock *rb,ram_addr_t length) {
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 03/15] migration: No need to take rcu during sync_dirty_bitmap
Quoted 17 lines · Peter Xu
cpu_physical_memory_sync_dirty_bitmap()has one RAMBlock* as parameter, which means that it must be with RCU read lock held already. Taking it again inside seems redundant. Removing it. Instead comment on the functions about the RCU read lock.Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Peter Xu <[email protected]>--- include/exec/ram_addr.h | 5 +---- migration/ram.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)include/exec/ram_addr.h +0
-0
include/exec/ram_addr.h static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, · line 411
Quoted 4 lines
include/exec/ram_addr.h +1
-0@@ -408,6 +408,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, } +/* Must be with rcu read lock held */
The usual way to spell this is "Called within RCU critical section.", otherwise the patch looks good.
Paolo
Quoted 34 lines
include/exec/ram_addr.h +0
-4static inline uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, ram_addr_t start,@@ -431,8 +432,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, DIRTY_MEMORY_BLOCK_SIZE);unsigned long page =BIT_WORD (start >>TARGET_PAGE_BITS ); -rcu_read_lock (); - src =atomic_rcu_read ( &ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION ])->blocks;@@ -452,8 +451,6 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, idx++; } } - -rcu_read_unlock (); }else {ram_addr_t offset = rb->offset;migration/ram.c +1
-0@@ -1678,6 +1678,7 @@ static inline bool migration_bitmap_clear_dirty(RAMState *rs,return ret; } +/* Must be with rcu read lock held */ static void migration_bitmap_sync_range (RAMState *rs,RAMBlock *rb,ram_addr_t length) {
Re: [Qemu-devel] [PATCH v2 03/15] migration: No need to take rcu during sync_dirty_bitmap
Quoted 21 lines · Paolo Bonzini
Quoted 20 lines · Peter Xu
cpu_physical_memory_sync_dirty_bitmap()has one RAMBlock* as parameter, which means that it must be with RCU read lock held already. Taking it again inside seems redundant. Removing it. Instead comment on the functions about the RCU read lock.Reviewed-by Paolo Bonzini <[email protected]>Signed-off-by Peter Xu <[email protected]>--- include/exec/ram_addr.h | 5 +---- migration/ram.c | 1 + 2 files changed, 2 insertions(+), 4 deletions(-)include/exec/ram_addr.h +0
-0@@ -408,6 +408,7 @@ static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, }
Quoted 4 lines
include/exec/ram_addr.h static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, · line 411
Quoted 1 line
include/exec/ram_addr.h +1
-0+/* Must be with rcu read lock held */ The usual way to spell this is "Called within RCU critical section.", otherwise the patch looks good.
Sure, I'm switching to this with the r-b kept.
Thanks,
Signature · 1 line
Peter Xu
PATCH v2 4/15 memory: Remove memory_region_get_dirty()
In reply to Peter XuIt's never used anywhere.
--- include/exec/memory.h | 17 ----------------- memory.c | 8 -------- 2 files changed, 25 deletions(-)
include/exec/memory.h +0 -17
@@ -1254,23 +1254,6 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize,*/ void memory_region_set_log (MemoryRegion *mr,bool log,unsigned client); -/** -* memory_region_get_dirty: Check whether a range of bytes is dirty -* for a specified client. -* -* Checks whether a range of bytes has been written to since the last -* call to memory_region_reset_dirty() with the same @client. Dirty logging -* must be enabled. -* -* @mr: the memory region being queried. -* @addr: the address (relative to the start of the region) being queried. -* @size: the size of the range being queried. -* @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or -* %DIRTY_MEMORY_VGA. -*/ -bool memory_region_get_dirty (MemoryRegion *mr,hwaddr addr, -hwaddr size,unsigned client); -/** * memory_region_set_dirty: Mark a range of bytes as dirty in a memory region. *
memory.c +0 -8
@@ -2027,14 +2027,6 @@ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client)memory_region_transaction_commit (); } -bool memory_region_get_dirty (MemoryRegion *mr,hwaddr addr, -hwaddr size,unsigned client) -{ -assert (mr->ram_block); -return cpu_physical_memory_get_dirty (memory_region_get_ram_addr (mr) + addr, - size, client); -} -void memory_region_set_dirty (MemoryRegion *mr,hwaddr addr,hwaddr size) {
Signature · 1 line
2.17.1
PATCH v2 5/15 memory: Don't set migration bitmap when without migration
In reply to Peter XuSimilar to 9460dee4b2 ("memory: do not touch code dirty bitmap unless TCG is enabled", 2015-06-05) but for the migration bitmap - we can skip the MIGRATION bitmap update if migration not enabled.
--- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 12 +++++++++++- memory.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
include/exec/memory.h +2 -0
@@ -46,6 +46,8 @@OBJECT_GET_CLASS (IOMMUMemoryRegionClass, (obj), \ TYPE_IOMMU_MEMORY_REGION) +extern bool global_dirty_log; +typedef struct MemoryRegionOps MemoryRegionOps ;typedef struct MemoryRegionMmio MemoryRegionMmio ;
include/exec/ram_addr.h +11 -1
@@ -348,8 +348,13 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,if (bitmap[k]) {unsigned long temp =leul_to_cpu (bitmap[k]); -atomic_or (&blocks[DIRTY_MEMORY_MIGRATION ][idx][offset], temp);atomic_or (&blocks[DIRTY_MEMORY_VGA ][idx][offset], temp); + +if (global_dirty_log) { +atomic_or (&blocks[DIRTY_MEMORY_MIGRATION ][idx][offset], + temp); + } +if (tcg_enabled ()) {atomic_or (&blocks[DIRTY_MEMORY_CODE ][idx][offset], temp); }
@@ -366,6 +371,11 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,xen_hvm_modified_memory (start, pages <<TARGET_PAGE_BITS ); }else {uint8_t clients =tcg_enabled () ?DIRTY_CLIENTS_ALL :DIRTY_CLIENTS_NOCODE ; + +if (!global_dirty_log) { + clients &= ~(1 <<DIRTY_MEMORY_MIGRATION ); + } +/* * bitmap-traveling is faster than memory-traveling (for addr...) * especially when most of the memory is not dirty.
memory.c +1 -1
@@ -38,7 +38,7 @@static unsigned memory_region_transaction_depth;static bool memory_region_update_pending;static bool ioeventfd_update_pending; -static bool global_dirty_log = false; +bool global_dirty_log; static QTAILQ_HEAD(, MemoryListener) memory_listeners =QTAILQ_HEAD_INITIALIZER (memory_listeners);
Signature · 1 line
2.17.1
PATCH v2 6/15 bitmap: Add bitmap_copy_with_{src|dst}_offset()
In reply to Peter XuThese helpers copy the source bitmap to destination bitmap with a shift either on the src or dst bitmap.
Meanwhile, we never have bitmap tests but we should.
This patch also introduces the initial test cases for utils/bitmap.c but it only tests the newly introduced functions.
--- include/qemu/bitmap.h | 9 +++++ tests/Makefile.include | 2 ++ tests/test-bitmap.c | 81 ++++++++++++++++++++++++++++++++++++++++++ util/bitmap.c | 73 +++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 tests/test-bitmap.c
include/qemu/bitmap.h +9 -0
@@ -41,6 +41,10 @@* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area * bitmap_to_le(dst, src, nbits) Convert bitmap to little endian * bitmap_from_le(dst, src, nbits) Convert bitmap from little endian +* bitmap_copy_with_src_offset(dst, src, offset, nbits) +* *dst = *src (with an offset upon src) +* bitmap_copy_with_dst_offset(dst, src, offset, nbits) +* *dst = *src (with an offset upon dst) */ /*
@@ -271,4 +275,9 @@ void bitmap_to_le(unsigned long *dst, const unsigned long *src,void bitmap_from_le (unsigned long *dst,const unsigned long *src,long nbits); +void bitmap_copy_with_src_offset (unsigned long *dst,const unsigned long *src, +long offset,long nbits); +void bitmap_copy_with_dst_offset (unsigned long *dst,const unsigned long *src, +long shift,long nbits); +#endif /* BITMAP_H */
tests/Makefile.include +2 -0
@@ -64,6 +64,7 @@ check-unit-y += tests/test-opts-visitor$(EXESUF) check-unit-$(CONFIG_BLOCK) += tests/test-coroutine$(EXESUF) check-unit-y += tests/test-visitor-serialization$(EXESUF) check-unit-y += tests/test-iov$(EXESUF) +check-unit-y += tests/test-bitmap$(EXESUF) check-unit-$(CONFIG_BLOCK) += tests/test-aio$(EXESUF) check-unit-$(CONFIG_BLOCK) += tests/test-aio-multithread$(EXESUF) check-unit-$(CONFIG_BLOCK) += tests/test-throttle$(EXESUF)
@@ -529,6 +530,7 @@ tests/test-image-locking$(EXESUF): tests/test-image-locking.o $(test-block-obj-y tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(test-crypto-obj-y) +tests/test-bitmap$(EXESUF): tests/test-bitmap.o $(test-util-obj-y) tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migration/page_cache.o $(test-util-obj-y) tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-util-obj-y)
tests/test-bitmap.c new file +81 -0
81 lines not on this page · raw message
util/bitmap.c +73 -0
76 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 7/15 memory: Pass mr into snapshot_and_clear_dirty
In reply to Peter XuAlso we change the 2nd parameter of it to be the relative offset within the memory region. This is to be used in follow up patches.
--- exec.c | 3 ++- include/exec/ram_addr.h | 2 +- memory.c | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-)
exec.c +2 -1
@@ -1387,9 +1387,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start, }DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty - (ram_addr_t start,ram_addr_t length,unsigned client) +(MemoryRegion *mr,hwaddr addr,hwaddr length,unsigned client) {DirtyMemoryBlocks *blocks; +ram_addr_t start =memory_region_get_ram_addr (mr) + addr;unsigned long align =1UL << (TARGET_PAGE_BITS +BITS_PER_LEVEL );ram_addr_t first =QEMU_ALIGN_DOWN (start, align);ram_addr_t last =QEMU_ALIGN_UP (start + length, align);
include/exec/ram_addr.h +1 -1
@@ -403,7 +403,7 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start, unsigned client);DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirty - (ram_addr_t start,ram_addr_t length,unsigned client); +(MemoryRegion *mr,ram_addr_t start,hwaddr length,unsigned client); bool cpu_physical_memory_snapshot_get_dirty(DirtyBitmapSnapshot *snap, ram_addr_t start,
memory.c +1 -2
@@ -2071,8 +2071,7 @@ DirtyBitmapSnapshot *memory_region_snapshot_and_clear_dirty(MemoryRegion *mr, {assert (mr->ram_block);memory_region_sync_dirty_bitmap (mr); -return cpu_physical_memory_snapshot_and_clear_dirty ( -memory_region_get_ram_addr (mr) + addr, size, client); +return cpu_physical_memory_snapshot_and_clear_dirty (mr, addr, size, client); } bool memory_region_snapshot_get_dirty(MemoryRegion *mr, DirtyBitmapSnapshot *snap,
Signature · 1 line
2.17.1
PATCH v2 8/15 memory: Introduce memory listener hook log_clear()
In reply to Peter XuIntroduce a new memory region listener hook log_clear() to allow the listeners to hook onto the points where the dirty bitmap is cleared by the bitmap users.
Previously log_sync() contains two operations:
- dirty bitmap collection, and,
- dirty bitmap clear on remote site.
Let's take KVM as example - log_sync() for KVM will first copy the kernel dirty bitmap to userspace, and at the same time we'll clear the dirty bitmap there along with re-protecting all the guest pages again.
We add this new log_clear() interface only to split the old log_sync() into two separated procedures:
- use log_sync() to collect the collection only, and,
- use log_clear() to clear the remote dirty bitmap.
With the new interface, the memory listener users will still be able to decide how to implement the log synchronization procedure, e.g., they can still only provide log_sync() method only and put all the two procedures within log_sync() (that's how the old KVM works before KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is introduced). However with this new interface the memory listener users will start to have a chance to postpone the log clear operation explicitly if the module supports. That can really benefit users like KVM at least for host kernels that support KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
There are three places that can clear dirty bits in any one of the dirty bitmap in the ram_list.dirty_memory[3] array:
cpu_physical_memory_snapshot_and_clear_dirty cpu_physical_memory_test_and_clear_dirty cpu_physical_memory_sync_dirty_bitmap
Currently we hook directly into each of the functions to notify about the log_clear().
--- exec.c | 12 ++++++++++ include/exec/memory.h | 17 ++++++++++++++ include/exec/ram_addr.h | 3 +++ memory.c | 51 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+)
exec.c +12 -0
@@ -1355,6 +1355,8 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,DirtyMemoryBlocks *blocks;unsigned long end, page;bool dirty = false; +RAMBlock *ramblock; +uint64_t mr_offset, mr_size;if (length ==0 ) {return false;
@@ -1366,6 +1368,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start,rcu_read_lock (); blocks =atomic_rcu_read (&ram_list.dirty_memory[client]); + ramblock =qemu_get_ram_block (start); +/* Range sanity check on the ramblock */ +assert (start >= ramblock->offset && + start + length <= ramblock->offset + ramblock->used_length);while (page < end) {unsigned long idx = page /DIRTY_MEMORY_BLOCK_SIZE ;
@@ -1377,6 +1383,10 @@ bool cpu_physical_memory_test_and_clear_dirty(ram_addr_t start, page += num; } + mr_offset = (ram_addr_t)(page <<TARGET_PAGE_BITS ) - ramblock->offset; + mr_size = (end - page) <<TARGET_PAGE_BITS ; +memory_region_clear_dirty_bitmap (ramblock->mr, mr_offset, mr_size); +rcu_read_unlock ();if (dirty &&tcg_enabled ()) {
@@ -1432,6 +1442,8 @@ DirtyBitmapSnapshot *cpu_physical_memory_snapshot_and_clear_dirtytlb_reset_dirty_range_all (start, length); } +memory_region_clear_dirty_bitmap (mr, addr, length); +return snap; }
include/exec/memory.h +17 -0
@@ -416,6 +416,7 @@ struct MemoryListener {void (*log_stop)(MemoryListener *listener,MemoryRegionSection *section,int old,int new);void (*log_sync)(MemoryListener *listener,MemoryRegionSection *section); +void (*log_clear)(MemoryListener *listener,MemoryRegionSection *section);void (*log_global_start)(MemoryListener *listener);void (*log_global_stop)(MemoryListener *listener); void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section,
@@ -1269,6 +1270,22 @@ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client);void memory_region_set_dirty (MemoryRegion *mr,hwaddr addr,hwaddr size); +/** +* memory_region_clear_dirty_bitmap - clear dirty bitmap for memory range +* +* This function is called when the caller wants to clear the remote +* dirty bitmap of a memory range within the memory region. This can +* be used by e.g. KVM to manually clear dirty log when +* KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is declared support by the host +* kernel. +* +* @mr: the memory region to clear the dirty log upon +* @start: start address offset within the memory region +* @len: length of the memory region to clear dirty bitmap +*/ +void memory_region_clear_dirty_bitmap (MemoryRegion *mr,hwaddr start, +hwaddr len); +/** * memory_region_snapshot_and_clear_dirty: Get a snapshot of the dirty * bitmap and clear it.
include/exec/ram_addr.h +3 -0
@@ -461,6 +461,9 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, idx++; } } + +/* TODO: split the huge bitmap into smaller chunks */ +memory_region_clear_dirty_bitmap (rb->mr, start, length); }else {ram_addr_t offset = rb->offset;
memory.c +51 -0
57 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 9/15 kvm: Update comments for sync_dirty_bitmap
In reply to Peter XuIt's obviously obsolete. Do some update.
--- accel/kvm/kvm-all.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
accel/kvm/kvm-all.c +6 -6
@@ -473,13 +473,13 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,#define ALIGN (x, y) (((x)+(y)-1) & ~((y)-1))/** -* kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space -* This function updates qemu's dirty bitmap using -* memory_region_set_dirty(). This means all bits are set -* to dirty. +* kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * -* @start_add: start of logged region. -* @end_addr: end of logged region. +* This function will first try to fetch dirty bitmap from the kernel, +* and then updates qemu's dirty bitmap. +* +* @kml: the KVM memory listener object +* @section: the memory section to sync the dirty bitmap with */ static int kvm_physical_sync_dirty_bitmap (KVMMemoryListener *kml,MemoryRegionSection *section)
Signature · 1 line
2.17.1
PATCH v2 10/15 kvm: Persistent per kvmslot dirty bitmap
In reply to Peter XuWhen synchronizing dirty bitmap from kernel KVM we do it in a per-kvmslot fashion and we allocate the userspace bitmap for each of the ioctl. This patch instead make the bitmap cache be persistent then we don't need to g_malloc0() every time.
More importantly, the cached per-kvmslot dirty bitmap will be further used when we want to add support for the KVM_CLEAR_DIRTY_LOG and this cached bitmap will be used to guarantee we won't clear any unknown dirty bits otherwise that can be a severe data loss issue for migration code.
--- accel/kvm/kvm-all.c | 39 +++++++++++++++++++++------------------ include/sysemu/kvm_int.h | 2 ++ 2 files changed, 23 insertions(+), 18 deletions(-)
accel/kvm/kvm-all.c +21 -18
@@ -497,31 +497,14 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,return 0 ; } -/* XXX bad kernel interface alert -* For dirty bitmap, kernel allocates array of size aligned to -* bits-per-long. But for case when the kernel is 64bits and -* the userspace is 32bits, userspace can't align to the same -* bits-per-long, since sizeof(long) is different between kernel -* and user space. This way, userspace will provide buffer which -* may be 4 bytes less than the kernel will use, resulting in -* userspace memory corruption (which is not detectable by valgrind -* too, in most cases). -* So for now, let's align to 64 instead of HOST_LONG_BITS here, in -* a hope that sizeof(long) won't become >8 any time soon. -*/ - size =ALIGN (((mem->memory_size) >>TARGET_PAGE_BITS ), -/*HOST_LONG_BITS*/ 64 ) /8 ; - d.dirty_bitmap =g_malloc0 (size); - + d.dirty_bitmap = mem->dirty_bmap; d.slot = mem->slot | (kml->as_id <<16 );if (kvm_vm_ioctl (s,KVM_GET_DIRTY_LOG , &d) ==-1 ) {DPRINTF ("ioctl failed %d\n" , errno); -g_free (d.dirty_bitmap);return -1 ; }kvm_get_dirty_pages_log_range (section, d.dirty_bitmap); -g_free (d.dirty_bitmap); }return 0 ;
@@ -765,6 +748,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,MemoryRegion *mr = section->mr;bool writeable = !mr->readonly && !mr->rom_device;hwaddr start_addr, size; +unsigned long bmap_size;void *ram;if (!memory_region_is_ram (mr)) {
@@ -796,6 +780,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, }/* unregister the slot */ +g_free (mem->dirty_bmap); + mem->dirty_bmap =NULL ; mem->memory_size =0 ; mem->flags =0 ; err =kvm_set_user_memory_region (kml, mem, false);
@@ -807,12 +793,29 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,return ; } +/* +* XXX bad kernel interface alert For dirty bitmap, kernel +* allocates array of size aligned to bits-per-long. But for case +* when the kernel is 64bits and the userspace is 32bits, +* userspace can't align to the same bits-per-long, since +* sizeof(long) is different between kernel and user space. This +* way, userspace will provide buffer which may be 4 bytes less +* than the kernel will use, resulting in userspace memory +* corruption (which is not detectable by valgrind too, in most +* cases). So for now, let's align to 64 instead of +* HOST_LONG_BITS here, in a hope that sizeof(long) won't become +* >8 any time soon. +*/ + bmap_size =ALIGN ((size >>TARGET_PAGE_BITS ), +/*HOST_LONG_BITS*/ 64 ) /8 ; +/* register the new slot */ mem =kvm_alloc_slot (kml); mem->memory_size = size; mem->start_addr = start_addr; mem->ram = ram; mem->flags =kvm_mem_flags (mr); + mem->dirty_bmap =g_malloc0 (bmap_size); err =kvm_set_user_memory_region (kml, mem, true);if (err) {
include/sysemu/kvm_int.h +2 -0
@@ -21,6 +21,8 @@ typedef struct KVMSlotint slot;int flags;int old_flags; +/* Dirty bitmap cache for the slot */ +unsigned long *dirty_bmap; } KVMSlot; typedef struct KVMMemoryListener {
Signature · 1 line
2.17.1
PATCH v2 11/15 kvm: Introduce slots lock for memory listener
In reply to Peter XuIntroduce KVMMemoryListener.slots_lock to protect the slots inside the kvm memory listener. Currently it is close to useless because all the KVM code path now is always protected by the BQL. But it'll start to make sense in follow up patches where we might do remote dirty bitmap clear and also we'll update the per-slot cached dirty bitmap even without the BQL. So let's prepare for it.
We can also use per-slot lock for above reason but it seems to be an overkill. Let's just use this bigger one (which covers all the slots of a single address space) but anyway this lock is still much smaller than the BQL.
--- accel/kvm/kvm-all.c | 58 +++++++++++++++++++++++++++++++--------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 48 insertions(+), 12 deletions(-)
accel/kvm/kvm-all.c +46 -12
@@ -138,6 +138,9 @@ static const KVMCapabilityInfo kvm_required_capabilites[] = { KVM_CAP_LAST_INFO }; +#define kvm_slots_lock (kml) qemu_mutex_lock(&(kml)->slots_lock) +#define kvm_slots_unlock (kml) qemu_mutex_unlock(&(kml)->slots_lock) +int kvm_get_max_memslots (void ) {KVMState *s =KVM_STATE (current_machine->accelerator);
@@ -165,6 +168,7 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)return 1 ; } +/* Must be with slots_lock held */ static KVMSlot *kvm_get_free_slot (KVMMemoryListener *kml) {KVMState *s = kvm_state;
@@ -182,10 +186,17 @@ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml)bool kvm_has_free_slot (MachineState *ms) {KVMState *s =KVM_STATE (ms->accelerator); +bool result; +KVMMemoryListener *kml = &s->memory_listener; + +kvm_slots_lock (kml); + result = !!kvm_get_free_slot (kml); +kvm_slots_unlock (kml); -return kvm_get_free_slot (&s->memory_listener); +return result; } +/* Must be with slots_lock held */ static KVMSlot *kvm_alloc_slot (KVMMemoryListener *kml) {KVMSlot *slot =kvm_get_free_slot (kml);
@@ -244,18 +255,21 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram, hwaddr *phys_addr) {KVMMemoryListener *kml = &s->memory_listener; -int i; +int i, ret =0 ; +kvm_slots_lock (kml);for (i =0 ; i < s->nr_slots; i++) {KVMSlot *mem = &kml->slots[i];if (ram >= mem->ram && ram < mem->ram + mem->memory_size) { *phys_addr = mem->start_addr + (ram - mem->ram); -return 1 ; + ret =1 ; +break ; } } +kvm_slots_unlock (kml); -return 0 ; +return ret; }static int kvm_set_user_memory_region (KVMMemoryListener *kml,KVMSlot *slot,bool new)
@@ -391,6 +405,7 @@ static int kvm_mem_flags(MemoryRegion *mr)return flags; } +/* Must be with slots_lock held */ static int kvm_slot_update_flags (KVMMemoryListener *kml,KVMSlot *mem,MemoryRegion *mr) {
@@ -409,19 +424,26 @@ static int kvm_section_update_flags(KVMMemoryListener *kml, {hwaddr start_addr, size;KVMSlot *mem; +int ret =0 ; size =kvm_align_section (section, &start_addr);if (!size) {return 0 ; } +kvm_slots_lock (kml); + mem =kvm_lookup_matching_slot (kml, start_addr, size);if (!mem) {/* We don't have a slot if we want to trap every access. */ -return 0 ; + goto out; } -return kvm_slot_update_flags (kml, mem, section->mr); + ret =kvm_slot_update_flags (kml, mem, section->mr); + +out: +kvm_slots_unlock (kml); +return ret; } static void kvm_log_start(MemoryListener *listener,
@@ -478,6 +500,8 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,* This function will first try to fetch dirty bitmap from the kernel, * and then updates qemu's dirty bitmap. * +* NOTE: caller must be with kml->slots_lock held. +* * @kml: the KVM memory listener object * @section: the memory section to sync the dirty bitmap with */
@@ -488,26 +512,28 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml,struct kvm_dirty_log d = {};KVMSlot *mem;hwaddr start_addr, size; +int ret =0 ; size =kvm_align_section (section, &start_addr);if (size) { mem =kvm_lookup_matching_slot (kml, start_addr, size);if (!mem) {/* We don't have a slot if we want to trap every access. */ -return 0 ; + goto out; } d.dirty_bitmap = mem->dirty_bmap; d.slot = mem->slot | (kml->as_id <<16 );if (kvm_vm_ioctl (s,KVM_GET_DIRTY_LOG , &d) ==-1 ) {DPRINTF ("ioctl failed %d\n" , errno); -return -1 ; + ret =-1 ; + goto out; }kvm_get_dirty_pages_log_range (section, d.dirty_bitmap); } - -return 0 ; +out: +return ret; } static void kvm_coalesce_mmio_region(MemoryListener *listener,
@@ -770,10 +796,12 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram =memory_region_get_ram_ptr (mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); +kvm_slots_lock (kml); +if (!add) { mem =kvm_lookup_matching_slot (kml, start_addr, size);if (!mem) { -return ; + goto out; }if (mem->flags &KVM_MEM_LOG_DIRTY_PAGES ) {kvm_physical_sync_dirty_bitmap (kml, section);
@@ -790,7 +818,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, __func__, strerror(-err));abort (); } -return ; + goto out; }/*
@@ -823,6 +851,9 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, strerror(-err));abort (); } + +out: +kvm_slots_unlock (kml); } static void kvm_region_add(MemoryListener *listener,
@@ -849,7 +880,9 @@ static void kvm_log_sync(MemoryListener *listener,KVMMemoryListener *kml =container_of (listener, KVMMemoryListener, listener);int r; +kvm_slots_lock (kml); r =kvm_physical_sync_dirty_bitmap (kml, section); +kvm_slots_unlock (kml);if (r <0 ) {abort (); }
@@ -929,6 +962,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, {int i; +qemu_mutex_init (&kml->slots_lock); kml->slots =g_malloc0 (s->nr_slots *sizeof (KVMSlot)); kml->as_id = as_id;
include/sysemu/kvm_int.h +2 -0
@@ -27,6 +27,8 @@ typedef struct KVMSlottypedef struct KVMMemoryListener {MemoryListener listener; +/* Protects the slots and all inside them */ +QemuMutex slots_lock;KVMSlot *slots;int as_id; }KVMMemoryListener ;
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 11/15] kvm: Introduce slots lock for memory listener
Quoted 1 line · Peter Xu
+/* Must be with
slots_lockheld */
Perhaps "Called with KVMMemoryListener slots_lock held."?
Paolo
Quoted 1 line
static KVMSlot *kvm_alloc_slot(KVMMemoryListener *kml)
Re: [Qemu-devel] [PATCH v2 11/15] kvm: Introduce slots lock for memory listener
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Peter Xu
+/* Must be with
slots_lockheld */Perhaps "Called with KVMMemoryListener
slots_lockheld."?
Yes sounds better. I'm replacing the old comments with "Called with KVMMemoryListener.slots_lock held" (with the dot).
Thanks,
Signature · 1 line
Peter Xu
PATCH v2 12/15 kvm: Support KVM_CLEAR_DIRTY_LOG
In reply to Peter XuFirstly detect the interface using KVM_CAP_MANUAL_DIRTY_LOG_PROTECT and mark it. When failed to enable the new feature we'll fall back to the old sync.
Provide the log_clear() hook for the memory listeners for both address spaces of KVM (normal system memory, and SMM) and deliever the clear message to kernel.
--- accel/kvm/kvm-all.c | 180 +++++++++++++++++++++++++++++++++++++++++ accel/kvm/trace-events | 1 + 2 files changed, 181 insertions(+)
accel/kvm/kvm-all.c +180 -0
@@ -91,6 +91,7 @@ struct KVMStateint many_ioeventfds;int intx_set_mask;bool sync_mmu; +bool manual_dirty_log_protect;/* The man page (and posix) say ioctl numbers are signed int, but * they're not. Linux, glibc and *BSD all treat ioctl numbers as * unsigned, and treating them as signed here can break things */
@@ -536,6 +537,157 @@ out:return ret; } +/* Alignment requirement for KVM_CLEAR_DIRTY_LOG - 64 pages */ +#define KVM_CLEAR_LOG_SHIFT 6 +#define KVM_CLEAR_LOG_ALIGN (qemu_real_host_page_size << KVM_CLEAR_LOG_SHIFT) +#define KVM_CLEAR_LOG_MASK (-KVM_CLEAR_LOG_ALIGN) + +/** +* kvm_physical_log_clear - Clear the kernel's dirty bitmap for range +* +* NOTE: this will be a no-op if we haven't enabled manual dirty log +* protection in the host kernel because in that case this operation +* will be done within log_sync(). +* +* @kml: the kvm memory listener +* @section: the memory range to clear dirty bitmap +*/ +static int kvm_physical_log_clear (KVMMemoryListener *kml, +MemoryRegionSection *section) +{ +KVMState *s = kvm_state; +struct kvm_clear_dirty_log d; +uint64_t start, end, bmap_start, start_delta, bmap_npages, size; +unsigned long *bmap_clear =NULL , psize = qemu_real_host_page_size; +KVMSlot *mem =NULL ; +int ret, i; + +if (!s->manual_dirty_log_protect) { +/* No need to do explicit clear */ +return 0 ; + } + + start = section->offset_within_address_space; + size =int128_get64 (section->size); + +if (!size) { +/* Nothing more we can do... */ +return 0 ; + } + +kvm_slots_lock (kml); + +/* Find any possible slot that covers the section */ +for (i =0 ; i < s->nr_slots; i++) { + mem = &kml->slots[i]; +if (mem->start_addr <= start && + start + size <= mem->start_addr + mem->memory_size) { +break ; + } + } + +/* +* We should always find one memslot until this point, otherwise +* there could be something wrong from the upper layer +*/ +assert (mem && i != s->nr_slots); + +/* +* We need to extend either the start or the size or both to +* satisfy the KVM interface requirement. Firstly, do the start +* page alignment on 64 host pages +*/ + bmap_start = (start - mem->start_addr) &KVM_CLEAR_LOG_MASK ; + start_delta = start - mem->start_addr - bmap_start; + bmap_start /= psize; + +/* +* The kernel interface has restriction on the size too, that either: +* +* (1) the size is 64 host pages aligned (just like the start), or +* (2) the size fills up until the end of the KVM memslot. +*/ + bmap_npages =DIV_ROUND_UP (size + start_delta,KVM_CLEAR_LOG_ALIGN ) + <<KVM_CLEAR_LOG_SHIFT ; + end = mem->memory_size / psize; +if (bmap_npages > end - bmap_start) { + bmap_npages = end - bmap_start; + } + start_delta /= psize; + +/* +* Prepare the bitmap to clear dirty bits. Here we must guarantee +* that we won't clear any unknown dirty bits otherwise we might +* accidentally clear some set bits which are not yet synced from +* the kernel into QEMU's bitmap, then we'll lose track of the +* guest modifications upon those pages (which can directly lead +* to guest data loss or panic after migration). +* +* Layout of the KVMSlot.dirty_bmap: +* +* |<-------- bmap_npages -----------..>| +* [1] +* start_delta size +* |----------------|-------------|------------------|------------| +* ^ ^ ^ ^ +* | | | | +* start bmap_start (start) end +* of memslot of memslot +* +* [1] bmap_npages can be aligned to either 64 pages or the end of slot +*/ + +assert (bmap_start %BITS_PER_LONG ==0 ); +if (start_delta) { +/* Slow path - we need to manipulate a temp bitmap */ + bmap_clear =bitmap_new (bmap_npages); +bitmap_copy_with_src_offset (bmap_clear, mem->dirty_bmap, + bmap_start, start_delta + size / psize); +/* +* We need to fill the holes at start because that was not +* specified by the caller and we extended the bitmap only for +* 64 pages alignment +*/ +bitmap_clear (bmap_clear,0 , start_delta); + d.dirty_bitmap = bmap_clear; + }else { +/* Fast path - start address aligns well with BITS_PER_LONG */ + d.dirty_bitmap = mem->dirty_bmap +BIT_WORD (bmap_start); + } + + d.first_page = bmap_start; +/* It should never overflow. If it happens, say something */ +assert (bmap_npages <=UINT32_MAX ); + d.num_pages = bmap_npages; + d.slot = mem->slot | (kml->as_id <<16 ); + +if (kvm_vm_ioctl (s,KVM_CLEAR_DIRTY_LOG , &d) ==-1 ) { + ret = -errno; +error_report ("%s: KVM_CLEAR_DIRTY_LOG failed, slot=%d, " +"start=0x%" PRIx64", size=0x%" PRIx32", errno=%d" , + __func__, d.slot, (uint64_t )d.first_page, + (uint32_t )d.num_pages, ret); + }else { + ret =0 ; +trace_kvm_clear_dirty_log (d.slot, d.first_page, d.num_pages); + } + +/* +* After we have updated the remote dirty bitmap, we update the +* cached bitmap as well for the memslot, then if another user +* clears the same region we know we shouldn't clear it again on +* the remote otherwise it's data loss as well. +*/ +bitmap_clear (mem->dirty_bmap, bmap_start + start_delta, + size / psize); +/* This handles the NULL case well */ +g_free (bmap_clear); + +kvm_slots_unlock (kml); + +return ret; +} +static void kvm_coalesce_mmio_region (MemoryListener *listener,MemoryRegionSection *secion,hwaddr start,hwaddr size)
@@ -888,6 +1040,22 @@ static void kvm_log_sync(MemoryListener *listener, } } +static void kvm_log_clear (MemoryListener *listener, +MemoryRegionSection *section) +{ +KVMMemoryListener *kml =container_of (listener, KVMMemoryListener, listener); +int r; + + r =kvm_physical_log_clear (kml, section); +if (r <0 ) { +error_report_once ("%s: kvm log clear failed: mr=%s " +"offset=%" HWADDR_PRIx" size=%" PRIx64, __func__, + section->mr->name, section->offset_within_region, +int128_get64 (section->size)); +abort (); + } +} + static void kvm_mem_ioeventfd_add(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data,
@@ -975,6 +1143,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, kml->listener.log_start = kvm_log_start; kml->listener.log_stop = kvm_log_stop; kml->listener.log_sync = kvm_log_sync; + kml->listener.log_clear = kvm_log_clear; kml->listener.priority =10 ;memory_listener_register (&kml->listener, as);
@@ -1699,6 +1868,17 @@ static int kvm_init(MachineState *ms) s->coalesced_pio = s->coalesced_mmio &&kvm_check_extension (s,KVM_CAP_COALESCED_PIO ); + s->manual_dirty_log_protect = +kvm_check_extension (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ); +if (s->manual_dirty_log_protect) { + ret =kvm_vm_enable_cap (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ,0 ,1 ); +if (ret) { +warn_report ("Trying to enable KVM_CAP_MANUAL_DIRTY_LOG_PROTECT " +"but failed. Falling back to the legacy mode. " ); + s->manual_dirty_log_protect = false; + } + } +#ifdef KVM_CAP_VCPU_EVENTS s->vcpu_events =kvm_check_extension (s,KVM_CAP_VCPU_EVENTS );#endif
accel/kvm/trace-events +1 -0
@@ -15,4 +15,5 @@ kvm_irqchip_release_virq(int virq) "virq %d" kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=0x%x assign: %d size: %d match: %d" kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) "fd: %d @0x%x val=0x%x assign: %d size: %d match: %d" kvm_set_user_memory(uint32_t slot, uint32_t flags, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, int ret) "Slot#%d flags=0x%x gpa=0x%"PRIx64 " size=0x%"PRIx64 " ua=0x%"PRIx64 " ret=%d" +kvm_clear_dirty_log(uint32_t slot, uint64_t start, uint32_t size) "slot#%"PRId32" start 0x%"PRIx64" size 0x%"PRIx32
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 12/15] kvm: Support KVM_CLEAR_DIRTY_LOG
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 1876
Quoted 6 lines · Peter Xu
accel/kvm/kvm-all.c +6
-0+ s->manual_dirty_log_protect = +kvm_check_extension (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ); +if (s->manual_dirty_log_protect) { + ret =kvm_vm_enable_cap (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ,0 ,1 ); +if (ret) { + warn_report("Trying to enable KVM_CAP_MANUAL_DIRTY_LOG_PROTECT "
Please use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 in the error too (and in the commit message).
Paolo
Quoted 3 lines
accel/kvm/kvm-all.c +3
-0+ "but failed. Falling back to the legacy mode. "); + s->manual_dirty_log_protect = false; + }
Re: [Qemu-devel] [PATCH v2 12/15] kvm: Support KVM_CLEAR_DIRTY_LOG
Quoted 10 lines · Paolo Bonzini
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 1876
Quoted 6 lines · Peter Xu
accel/kvm/kvm-all.c +6
-0+ s->manual_dirty_log_protect = +kvm_check_extension (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ); +if (s->manual_dirty_log_protect) { + ret =kvm_vm_enable_cap (s,KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 ,0 ,1 ); +if (ret) { + warn_report("Trying to enable KVM_CAP_MANUAL_DIRTY_LOG_PROTECT "Please use
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2in the error too (and in the commit message).
Oops I did miss these, actually I also noticed some commit messages that mentioned the wrong capability name and I'll change them too (e.g., in patch 8 where the new memory API is introduced).
Thanks,
Signature · 1 line
Peter Xu
PATCH v2 13/15 qmp: Expose manual_dirty_log_protect via "query-kvm"
In reply to Peter XuExpose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
--- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 2 ++ qapi/misc.json | 6 +++++- qmp.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)
accel/kvm/kvm-all.c +5 -0
@@ -169,6 +169,11 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)return 1 ; } +bool kvm_manual_dirty_log_protect_enabled (void ) +{ +return kvm_state && kvm_state->manual_dirty_log_protect; +} +/* Must be with slots_lock held */ static KVMSlot *kvm_get_free_slot (KVMMemoryListener *kml) {
include/sysemu/kvm.h +2 -0
@@ -547,4 +547,6 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);int kvm_get_one_reg (CPUState *cs,uint64_t id,void *target);struct ppc_radix_page_info *kvm_get_radix_page_info (void );int kvm_get_max_memslots (void ); +bool kvm_manual_dirty_log_protect_enabled (void ); +#endif
qapi/misc.json +5 -1
@@ -253,9 +253,13 @@ # # @present: true if KVM acceleration is built into this executable # +# @manual-dirty-log-protect: true if manual dirty log protect is enabled +# # Since: 0.14.0 ## -{ 'struct': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } +{ 'struct': 'KvmInfo', 'data': + {'enabled': 'bool', 'present': 'bool', + 'manual-dirty-log-protect': 'bool' } } ## # @query-kvm:
qmp.c +1 -0
@@ -73,6 +73,7 @@ KvmInfo *qmp_query_kvm(Error **errp) info->enabled =kvm_enabled (); info->present =kvm_available (); + info->manual_dirty_log_protect =kvm_manual_dirty_log_protect_enabled ();return info; }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 13/15] qmp: Expose manual_dirty_log_protect via "query-kvm"
Quoted 4 lines · Peter Xu
Expose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
Signed-off-by Peter Xu <[email protected]>
Is this useful? We could I guess make a migration capability in order to benchmark with the old code, but otherwise I would just make this a "hidden" optimization just like many others (same for patch 14).
In other words, there are many other capabilities that we could inform the user about, I don't see what makes manual_dirty_log_protect special.
Paolo
Quoted 66 lines
--- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 2 ++ qapi/misc.json | 6 +++++- qmp.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +5
-0@@ -169,6 +169,11 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)return 1 ; } +bool kvm_manual_dirty_log_protect_enabled (void ) +{ +return kvm_state && kvm_state->manual_dirty_log_protect; +} +/* Must be with slots_lock held */ static KVMSlot *kvm_get_free_slot (KVMMemoryListener *kml) {include/sysemu/kvm.h +2
-0@@ -547,4 +547,6 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);int kvm_get_one_reg (CPUState *cs,uint64_t id,void *target);struct ppc_radix_page_info *kvm_get_radix_page_info (void );int kvm_get_max_memslots (void ); +bool kvm_manual_dirty_log_protect_enabled (void ); +#endif qapi/misc.json +5
-1@@ -253,9 +253,13 @@ # # @present: true if KVM acceleration is built into this executable # +# @manual-dirty-log-protect: true if manual dirty log protect is enabled +# # Since: 0.14.0 ## -{ 'struct': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } +{ 'struct': 'KvmInfo', 'data': + {'enabled': 'bool', 'present': 'bool', + 'manual-dirty-log-protect': 'bool' } } ## # @query-kvm:qmp.c +1
-0@@ -73,6 +73,7 @@ KvmInfo *qmp_query_kvm(Error **errp) info->enabled =kvm_enabled (); info->present =kvm_available (); + info->manual_dirty_log_protect =kvm_manual_dirty_log_protect_enabled ();return info; }
Re: [Qemu-devel] [PATCH v2 13/15] qmp: Expose manual_dirty_log_protect via "query-kvm"
Quoted 4 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 3 lines · Peter Xu
Expose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Xu <[email protected]>Is this useful? We could I guess make a migration capability in order to benchmark with the old code, but otherwise I would just make this a "hidden" optimization just like many others (same for patch 14).
In other words, there are many other capabilities that we could inform the user about, I don't see what makes
manual_dirty_log_protectspecial.
Yes agreed, if your kernel has it then just use it.
Dave
Quoted 61 lines
Paolo
Quoted 59 lines
--- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 2 ++ qapi/misc.json | 6 +++++- qmp.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)accel/kvm/kvm-all.c +5
-0@@ -169,6 +169,11 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)return 1 ; } +bool kvm_manual_dirty_log_protect_enabled (void ) +{ +return kvm_state && kvm_state->manual_dirty_log_protect; +} +/* Must be with slots_lock held */ static KVMSlot *kvm_get_free_slot (KVMMemoryListener *kml) {include/sysemu/kvm.h +2
-0@@ -547,4 +547,6 @@ int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source);int kvm_get_one_reg (CPUState *cs,uint64_t id,void *target);struct ppc_radix_page_info *kvm_get_radix_page_info (void );int kvm_get_max_memslots (void ); +bool kvm_manual_dirty_log_protect_enabled (void ); +#endif qapi/misc.json +5
-1@@ -253,9 +253,13 @@ # # @present: true if KVM acceleration is built into this executable # +# @manual-dirty-log-protect: true if manual dirty log protect is enabled +# # Since: 0.14.0 ## -{ 'struct': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } +{ 'struct': 'KvmInfo', 'data': + {'enabled': 'bool', 'present': 'bool', + 'manual-dirty-log-protect': 'bool' } } ## # @query-kvm:qmp.c +0
-0@@ -73,6 +73,7 @@ KvmInfo *qmp_query_kvm(Error **errp)
Quoted 8 lines
qmp.c KvmInfo *qmp_query_kvm(Error **errp) · line 79
Quoted 7 lines
qmp.c +1
-0info->enabled =kvm_enabled (); info->present =kvm_available (); + info->manual_dirty_log_protect =kvm_manual_dirty_log_protect_enabled ();return info; }
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH v2 13/15] qmp: Expose manual_dirty_log_protect via "query-kvm"
In reply to Paolo BonziniQuoted 4 lines · Paolo Bonzini
Quoted 3 lines · Peter Xu
Expose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Xu <[email protected]>Is this useful? We could I guess make a migration capability in order to benchmark with the old code, but otherwise I would just make this a "hidden" optimization just like many others (same for patch 14).
In other words, there are many other capabilities that we could inform the user about, I don't see what makes
manual_dirty_log_protectspecial.
Yes this is mostly used for me to make sure the new capability is enabled when comparing with the old code. I added QMP part too because otherwise I'll need to justify why I only add HMP...
But I agree with above - let's drop these two QMP/HMP patches.
Thanks,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v2 13/15] qmp: Expose manual_dirty_log_protect via "query-kvm"
In reply to Peter XuQuoted 14 lines · Peter Xu
Expose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
Signed-off-by Peter Xu <[email protected]>--- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 2 ++ qapi/misc.json | 6 +++++- qmp.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)+++
b/qapi/misc.json
qapi/misc.json line 257
Quoted 5 lines
qapi/misc.json +2
-0@@ -253,9 +253,13 @@ # # @present: true if KVM acceleration is built into this executable # +# @manual-dirty-log-protect: true if manual dirty log protect is enabled +#
If we want this exposed (and Paolo is right that we might not), it needs '(since 4.1)' designation.
Quoted 22 lines
qapi/misc.json +3
-1# Since: 0.14.0 ## -{ 'struct': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} } +{ 'struct': 'KvmInfo', 'data': + {'enabled': 'bool', 'present': 'bool', + 'manual-dirty-log-protect': 'bool' } } ## # @query-kvm:qmp.c +1
-0@@ -73,6 +73,7 @@ KvmInfo *qmp_query_kvm(Error **errp) info->enabled =kvm_enabled (); info->present =kvm_available (); + info->manual_dirty_log_protect =kvm_manual_dirty_log_protect_enabled ();return info; }
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 13/15] qmp: Expose manual_dirty_log_protect via "query-kvm"
Quoted 13 lines · Eric Blake
Quoted 11 lines · Peter Xu
Expose the new capability via "query-kvm" QMP command too so we know whether that's turned on on the source VM when we want.
Signed-off-by Peter Xu <[email protected]>--- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 2 ++ qapi/misc.json | 6 +++++- qmp.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-)
Quoted 10 lines
qapi/misc.json line 257
Quoted 7 lines
+++
b/qapi/misc.jsonqapi/misc.json +2
-0@@ -253,9 +253,13 @@ # # @present: true if KVM acceleration is built into this executable # +# @manual-dirty-log-protect: true if manual dirty log protect is enabled +#If we want this exposed (and Paolo is right that we might not), it needs '(since 4.1)' designation.
Yes I'll drop them. Still, thanks to review the grammar part (as always).
Signature · 1 line
Peter Xu
PATCH v2 14/15 hmp: Expose manual_dirty_log_protect via "info kvm"
In reply to Peter Xu--- hmp.c | 2 ++ 1 file changed, 2 insertions(+)
hmp.c +2 -0
@@ -102,6 +102,8 @@ void hmp_info_kvm(Monitor *mon, const QDict *qdict) }else {monitor_printf (mon,"not compiled\n" ); } +monitor_printf (mon,"kvm manual dirty logging: %s\n" , + info->manual_dirty_log_protect ?"enabled" :"disabled" );qapi_free_KvmInfo (info); }
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH v2 14/15] hmp: Expose manual_dirty_log_protect via "info kvm"
Quoted 11 lines · Peter Xu
Signed-off-by Peter Xu <[email protected]>--- hmp.c | 2 ++ 1 file changed, 2 insertions(+)hmp.c +0
-0
hmp.c void hmp_info_kvm(Monitor *mon, const QDict *qdict) · line 109
Quoted 8 lines
hmp.c +2
-0@@ -102,6 +102,8 @@ void hmp_info_kvm(Monitor *mon, const QDict *qdict) }else {monitor_printf (mon,"not compiled\n" ); } +monitor_printf (mon,"kvm manual dirty logging: %s\n" , + info->manual_dirty_log_protect ?"enabled" :"disabled" );qapi_free_KvmInfo (info); }
Same here of course.
Paolo
PATCH v2 15/15 migration: Split log_clear() into smaller chunks
In reply to Peter XuCurrently we are doing log_clear() right after log_sync() which mostly keeps the old behavior when log_clear() was still part of log_sync().
This patch tries to further optimize the migration log_clear() code path to split huge log_clear()s into smaller chunks.
We do this by spliting the whole guest memory region into memory chunks, whose size is decided by MigrationState.clear_bitmap_shift (an example will be given below). With that, we don't do the dirty bitmap clear operation on the remote node (e.g., KVM) when we fetch the dirty bitmap, instead we explicitly clear the dirty bitmap for the memory chunk for each of the first time we send a page in that chunk.
Here comes an example.
Assuming the guest has 64G memory, then before this patch the KVM ioctl KVM_CLEAR_DIRTY_LOG will be a single one covering 64G memory. If after the patch, let's assume when the clear bitmap shift is 18, then the memory chunk size on x86_64 will be 1UL<<18 * 4K = 1GB. Then instead of sending a big 64G ioctl, we'll send 64 small ioctls, each of the ioctl will cover 1G of the guest memory. For each of the 64 small ioctls, we'll only send if any of the page in that small chunk was going to be sent right away.
--- include/exec/ram_addr.h | 75 +++++++++++++++++++++++++++++++++++++++-- migration/migration.c | 4 +++ migration/migration.h | 27 +++++++++++++++ migration/ram.c | 44 ++++++++++++++++++++++++ migration/trace-events | 1 + 5 files changed, 149 insertions(+), 2 deletions(-)
include/exec/ram_addr.h +73 -2
@@ -50,8 +50,69 @@ struct RAMBlock {unsigned long *unsentmap;/* bitmap of already received pages in postcopy */ unsigned long *receivedmap; + +/* +* bitmap of already cleared dirty bitmap. Set this up to +* non-NULL to enable the capability to postpone and split +* clearing of dirty bitmap on the remote node (e.g., KVM). The +* bitmap will be set only when doing global sync. +* +* NOTE: this bitmap is different comparing to the other bitmaps +* in that one bit can represent multiple guest pages (which is +* decided by the `clear_bmap_shift' variable below). On +* destination side, this should always be NULL, and the variable +* `clear_bmap_shift' is meaningless. +*/ +unsigned long *clear_bmap; +uint8_t clear_bmap_shift; }; +/** +* clear_bmap_size: calculate clear bitmap size +* +* @pages: number of guest pages +* @shift: guest page number shift +* +* Returns: number of bits for the clear bitmap +*/ +static inline long clear_bmap_size (uint64_t pages,uint8_t shift) +{ +return DIV_ROUND_UP (pages,1UL << shift); +} + +/** +* clear_bmap_set: set clear bitmap for the page range +* +* @rb: the ramblock to operate on +* @start: the start page number +* @size: number of pages to set in the bitmap +* +* Returns: None +*/ +static inline void clear_bmap_set (RAMBlock *rb,uint64_t start, +uint64_t npages) +{ +uint8_t shift = rb->clear_bmap_shift; + +bitmap_set_atomic (rb->clear_bmap, start >> shift, +clear_bmap_size (npages, shift)); +} + +/** +* clear_bmap_test_and_clear: test clear bitmap for the page, clear if set +* +* @rb: the ramblock to operate on +* @page: the page number to check +* +* Returns: true if the bit was set, false otherwise +*/ +static inline bool clear_bmap_test_and_clear (RAMBlock *rb,uint64_t page) +{ +uint8_t shift = rb->clear_bmap_shift; + +return bitmap_test_and_clear_atomic (rb->clear_bmap, page >> shift,1 ); +} +static inline bool offset_in_ramblock (RAMBlock *b,ram_addr_t offset) {return (b && b->host && offset < b->used_length) ? true : false;
@@ -462,8 +523,18 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, } } -/* TODO: split the huge bitmap into smaller chunks */ -memory_region_clear_dirty_bitmap (rb->mr, start, length); +if (rb->clear_bmap) { +/* +* Postpone the dirty bitmap clear to the point before we +* really send the pages, also we will split the clear +* dirty procedure into smaller chunks. +*/ +clear_bmap_set (rb, start >>TARGET_PAGE_BITS , + length >>TARGET_PAGE_BITS ); + }else { +/* Slow path - still do that in a huge chunk */ +memory_region_clear_dirty_bitmap (rb->mr, start, length); + } }else {ram_addr_t offset = rb->offset;
migration/migration.c +4 -0
@@ -3362,6 +3362,8 @@ void migration_global_dump(Monitor *mon) ms->send_section_footer ? "on" : "off");monitor_printf (mon,"decompress-error-check: %s\n" , ms->decompress_error_check ?"on" :"off" ); +monitor_printf (mon,"clear-bitmap-shift: %u\n" , + ms->clear_bitmap_shift); }#define DEFINE_PROP_MIG_CAP (name, x) \
@@ -3376,6 +3378,8 @@ static Property migration_properties[] = { send_section_footer, true),DEFINE_PROP_BOOL ("decompress-error-check" , MigrationState, decompress_error_check, true), +DEFINE_PROP_UINT8 ("x-clear-bitmap-shift" , MigrationState, + clear_bitmap_shift,CLEAR_BITMAP_SHIFT_DEFAULT ),/* Migration parameters */ DEFINE_PROP_UINT8("x-compress-level", MigrationState,
migration/migration.h +27 -0
@@ -27,6 +27,23 @@ struct PostcopyBlocktimeContext;#define MIGRATION_RESUME_ACK_VALUE (1) +/* +* 1<<6=64 pages -> 256K chunk when page size is 4K. This gives us +* the benefit that all the chunks are 64 pages aligned then the +* bitmaps are always aligned to LONG. +*/ +#define CLEAR_BITMAP_SHIFT_MIN 6 +/* +* 1<<18=256K pages -> 1G chunk when page size is 4K. This is the +* default value to use if no one specified. +*/ +#define CLEAR_BITMAP_SHIFT_DEFAULT 18 +/* +* 1<<31=2G pages -> 8T chunk when page size is 4K. This should be +* big enough and make sure we won't overflow easily. +*/ +#define CLEAR_BITMAP_SHIFT_MAX 31 +/* State for the incoming migration */ struct MigrationIncomingState {QEMUFile *from_src_file;
@@ -233,6 +250,16 @@ struct MigrationState* do not trigger spurious decompression errors. */ bool decompress_error_check; + +/* +* This decides the size of guest memory chunk that will be used +* to track dirty bitmap clearing. The size of memory chunk will +* be GUEST_PAGE_SIZE << N. Say, N=0 means we will clear dirty +* bitmap for each page to send (1<<0=1); N=10 means we will clear +* dirty bitmap only once for 1<<10=1K continuous guest pages +* (which is in 4M chunk). +*/ +uint8_t clear_bitmap_shift; };void migrate_set_state (int *state,int old_state,int new_state);
migration/ram.c +44 -0
71 lines not on this page · raw message
migration/trace-events +1 -0
@@ -79,6 +79,7 @@ get_queued_page(const char *block_name, uint64_t tmp_offset, unsigned long page_ get_queued_page_not_dirty(const char *block_name, uint64_t tmp_offset, unsigned long page_abs, int sent) "%s/0x%" PRIx64 " page_abs=0x%lx (sent=%d)" migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64 +migration_bitmap_clear_dirty(char *str, uint64_t start, uint64_t size, unsigned long page) "rb %s start 0x%"PRIx64" size 0x%"PRIx64" page 0x%lx" migration_throttle(void) "" multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %d packet number %" PRIu64 " pages %d flags 0x%x next packet size %d" multifd_recv_sync_main(long packet_num) "packet num %ld"
Signature · 1 line
2.17.1
Quoted 172 lines · Peter Xu
This is v2 of the QEMU's
KVM_CLEAR_DIRTY_LOGseries. The major reason for the repost is due to the new kvm capability recently introduced in Linux 5.2-rc1 which is released just one day ago while the old cap is obsolete now, so we'll need a linux header update.v2:
- rebase, add r-bs from Paolo
- added a few patches
- linux-headers: Update to Linux 5.2-rc1
this is needed because we've got a new cap in kvm
- checkpatch: Allow SPDX-License-Identifier
picked up the standalone patch into the series in case it got lost
- hmp: Exposemanual_dirty_log_protectvia "info kvm"
qmp: Exposemanual_dirty_log_protectvia "query-kvm" add interface to detect the new kvm capability
- switched default chunk size to 128MPerformance update is here:
https://lists.gnu.org/archive/html/qemu-devel/2019-05/msg03621.html
Summary
=====================This series allows QEMU to start using the new
KVM_CLEAR_DIRTY_LOGinterface. For more onKVM_CLEAR_DIRTY_LOGitself, please refer to:https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/api.txt#L3810
The QEMU work (which is this series) is pushed too, please find the tree here:
https://github.com/xzpeter/qemu/tree/kvm-clear-dirty-log
Meanwhile, For anyone who really wants to try this out, please also upgrade the host kernel to linux 5.2-rc1.
Design
===================I started with a naive/stupid design that I always pass all 1's to the KVM for a memory range to clear all the dirty bits within that memory range, but then I encountered guest oops - it's simply because we can't clear any dirty bit from QEMU if we are not _sure_ that the bit is dirty in the kernel. Otherwise we might accidentally clear a bit that we don't even know of (e.g., the bit was clear in migration's dirty bitmap in QEMU) but actually that page was just being written so QEMU will never remember to migrate that new page again.
The new design is focused on a dirty bitmap cache within the QEMU kvm layer (which is per kvm memory slot). With that we know what's dirty in the kernel previously (note! the kernel bitmap is still growing all the time so the cache will only be a subset of the realtime kernel bitmap but that's far enough for us) and with that we'll be sure to not accidentally clear unknown dirty pages.
With this method, we can also avoid race when multiple users (e.g.,
DIRTY_MEMORY_VGAandDIRTY_MEMORY_MIGRATION) want to clear the bit for multiple time. If without the kvm memory slot cached dirty bitmap we won't be able to know which bit has been cleared and then if we send the CLEAR operation upon the same bit twice (or more) we can still face the same issue to clear something accidentally while we shouldn't.Summary: we really need to be careful on what bit to clear otherwise we can face anything after the migration completes. And I hope this series has considered all about this.
Besides the new KVM cache layer and the new ioctl support, this series introduced the
memory_region_clear_dirty_bitmap()in the memory API layer to allow clearing dirty bits of a specific memory range within the memory region.Implementations
============================Patch 1-3: these should be nothing directly related to the series but
they are things I found during working on it. They can be picked even earlier if reviewers are happy with them.Patch 4: pre-work on bitmap operations, and within the patch I added
the first unit test forutils/bitmap.c.Patch 5-6: the new memory API interface. Since no one is providing
log_clear()yet so it's not working yet. Note that this only splits the dirty clear operation from sync but it hasn't yet been splitted into smaller chunk so it's not really helpful for us yet.Patch 7-10: kvm support of
KVM_CLEAR_DIRTY_LOG.Patch 11: do the
log_clear()splitting for the case of migration.
Also a new parameter is introduced to define the block size of the small chunks (the unit to clear dirty bits)Tests
===========================- make check
- migrate idle/memory-heavy guests(Not yet tested with huge guests but it'll be more than welcomed if
someone has the resource and wants to give it a shot)Please have a look, thanks.
Peter Xu (15):
checkpatch: Allow SPDX-License-Identifier
linux-headers: Update to Linux 5.2-rc1
migration: No need to take rcu duringsync_dirty_bitmap
memory: Removememory_region_get_dirty()
memory: Don't set migration bitmap when without migration
bitmap: Add bitmap_copy_with_{src|dst}_offset()
memory: Pass mr intosnapshot_and_clear_dirty
memory: Introduce memory listener hooklog_clear()
kvm: Update comments forsync_dirty_bitmap
kvm: Persistent per kvmslot dirty bitmap
kvm: Introduce slots lock for memory listener
kvm: SupportKVM_CLEAR_DIRTY_LOG
qmp: Exposemanual_dirty_log_protectvia "query-kvm"
hmp: Exposemanual_dirty_log_protectvia "info kvm"
migration: Splitlog_clear()into smaller chunksaccel/kvm/kvm-all.c | 292 +++++++++++++++--- accel/kvm/trace-events | 1 + exec.c | 15 +- hmp.c | 2 + include/exec/memory.h | 36 ++- include/exec/ram_addr.h | 91 +++++- include/qemu/bitmap.h | 9 + .../infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h | 15 +- include/standard-headers/drm/drm_fourcc.h | 114 ++++++- include/standard-headers/linux/ethtool.h | 48 ++- .../linux/input-event-codes.h | 9 +- include/standard-headers/linux/input.h | 6 +- include/standard-headers/linux/pci_regs.h | 140 +++++---- .../standard-headers/linux/virtio_config.h | 6 + include/standard-headers/linux/virtio_gpu.h | 12 +- include/standard-headers/linux/virtio_ring.h | 10 - .../standard-headers/rdma/vmw_pvrdma-abi.h | 1 + include/sysemu/kvm.h | 2 + include/sysemu/kvm_int.h | 4 + linux-headers/asm-arm/unistd-common.h | 32 ++ linux-headers/asm-arm64/kvm.h | 43 +++ linux-headers/asm-arm64/unistd.h | 2 + linux-headers/asm-generic/mman-common.h | 4 +- linux-headers/asm-generic/unistd.h | 170 ++++++++-- linux-headers/asm-mips/mman.h | 4 +- linux-headers/asm-mips/unistd_n32.h | 30 ++ linux-headers/asm-mips/unistd_n64.h | 10 + linux-headers/asm-mips/unistd_o32.h | 40 +++ linux-headers/asm-powerpc/kvm.h | 48 +++ linux-headers/asm-powerpc/unistd_32.h | 40 +++ linux-headers/asm-powerpc/unistd_64.h | 21 ++ linux-headers/asm-s390/kvm.h | 5 +- linux-headers/asm-s390/unistd_32.h | 43 +++ linux-headers/asm-s390/unistd_64.h | 24 ++ linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 40 +++ linux-headers/asm-x86/unistd_64.h | 10 + linux-headers/asm-x86/unistd_x32.h | 10 + linux-headers/linux/kvm.h | 15 +- linux-headers/linux/mman.h | 4 + linux-headers/linux/psci.h | 7 + linux-headers/linux/psp-sev.h | 18 +- linux-headers/linux/vfio.h | 4 + linux-headers/linux/vfio_ccw.h | 12 + memory.c | 64 +++- migration/migration.c | 4 + migration/migration.h | 27 ++ migration/ram.c | 45 +++ migration/trace-events | 1 +
Quoted 9 lines
qapi/misc.json | 6 +- qmp.c | 1 + scripts/checkpatch.pl | 3 +- tests/Makefile.include | 2 + tests/test-bitmap.c | 81 +++++ util/bitmap.c | 73 +++++ 55 files changed, 1542 insertions(+), 215 deletions(-) create mode 100644 tests/test-bitmap.c
I queued patches 1-2, I expect the rest to go in through the migration tree.
Paolo