[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [COMMIT d761a5e] kvm: Avoid COW if KVM MMU is asynchronou

From: Anthony Liguori
Subject: [Qemu-commits] [COMMIT d761a5e] kvm: Avoid COW if KVM MMU is asynchronous
Date: Fri, 01 May 2009 15:05:17 -0000

From: Jan Kiszka <address@hidden>

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 <address@hidden>
Signed-off-by: Anthony Liguori <address@hidden>

diff --git a/exec.c b/exec.c
index 2effd04..c649381 100644
--- a/exec.c
+++ b/exec.c
@@ -2484,6 +2484,9 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size)
     last_ram_offset += size;
+    if (kvm_enabled())
+        kvm_setup_guest_memory(new_block->host, size);
     return new_block->offset;
diff --git a/kvm-all.c b/kvm-all.c
index 0da5c7a..36659a9 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -773,6 +773,24 @@ int kvm_has_sync_mmu(void)
     return 0;
+void kvm_setup_guest_memory(void *start, size_t size)
+    if (!kvm_has_sync_mmu()) {
+        int ret = madvise(start, size, MADV_DONTFORK);
+        if (ret) {
+            perror("madvice");
+            exit(1);
+        }
+        fprintf(stderr,
+                "Need MADV_DONTFORK in absence of synchronous KVM MMU\n");
+        exit(1);
+    }
 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
                                                  target_ulong pc)
diff --git a/kvm.h b/kvm.h
index 803a874..0ea2426 100644
--- a/kvm.h
+++ b/kvm.h
@@ -48,6 +48,8 @@ int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t 
 int kvm_has_sync_mmu(void);
+void kvm_setup_guest_memory(void *start, size_t size);
 int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);
 int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]