Commit 6f0437e8de95aebbd9e66af4d074c0d5119d86b7
Committed by
Anthony Liguori
1 parent
8563d5b3
kvm: Avoid COW if KVM MMU is asynchronous
Avi Kivity wrote: > Suggest wrapping in a function and hiding it deep inside kvm-all.c. > Done in v2: ----------> If the KVM MMU is asynchronous (kernel does not support MMU_NOTIFIER), we have to avoid COW for the guest memory. Otherwise we risk serious breakage when guest pages change there physical locations due to COW after fork. Seen when forking smbd during runtime via -smb. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
3 changed files
with
23 additions
and
0 deletions
exec.c
kvm-all.c
... | ... | @@ -773,6 +773,24 @@ int kvm_has_sync_mmu(void) |
773 | 773 | return 0; |
774 | 774 | } |
775 | 775 | |
776 | +void kvm_setup_guest_memory(void *start, size_t size) | |
777 | +{ | |
778 | + if (!kvm_has_sync_mmu()) { | |
779 | +#ifdef MADV_DONTFORK | |
780 | + int ret = madvise(start, size, MADV_DONTFORK); | |
781 | + | |
782 | + if (ret) { | |
783 | + perror("madvice"); | |
784 | + exit(1); | |
785 | + } | |
786 | +#else | |
787 | + fprintf(stderr, | |
788 | + "Need MADV_DONTFORK in absence of synchronous KVM MMU\n"); | |
789 | + exit(1); | |
790 | +#endif | |
791 | + } | |
792 | +} | |
793 | + | |
776 | 794 | #ifdef KVM_CAP_SET_GUEST_DEBUG |
777 | 795 | struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env, |
778 | 796 | target_ulong pc) | ... | ... |
kvm.h
... | ... | @@ -48,6 +48,8 @@ int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size); |
48 | 48 | |
49 | 49 | int kvm_has_sync_mmu(void); |
50 | 50 | |
51 | +void kvm_setup_guest_memory(void *start, size_t size); | |
52 | + | |
51 | 53 | int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); |
52 | 54 | int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); |
53 | 55 | ... | ... |