qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Avi Kivity <avi@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>, qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH v2] kvm: Avoid COW if KVM MMU is asynchronous
Date: Sun, 26 Apr 2009 18:03:40 +0200	[thread overview]
Message-ID: <49F485DC.2080702@web.de> (raw)
In-Reply-To: <49F45CDB.205@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2094 bytes --]

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>
---

 exec.c    |    3 +++
 kvm-all.c |   18 ++++++++++++++++++
 kvm.h     |    2 ++
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/exec.c b/exec.c
index 23013fb..81c6a29 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 1128bee..f36b39b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -783,6 +783,24 @@ int kvm_has_sync_mmu(void)
     return 0;
 }
 
+void kvm_setup_guest_memory(void *start, size_t size)
+{
+    if (!kvm_has_sync_mmu()) {
+#ifdef MADV_DONTFORK
+        int ret = madvise(start, size, MADV_DONTFORK);
+
+        if (ret) {
+            perror("madvice");
+            exit(1);
+        }
+#else
+        fprintf(stderr,
+                "Need MADV_DONTFORK in absence of synchronous KVM MMU\n");
+        exit(1);
+#endif
+    }
+}
+
 #ifdef KVM_CAP_SET_GUEST_DEBUG
 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 size);
 
 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);
 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

  reply	other threads:[~2009-04-26 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-26 12:21 [Qemu-devel] [PATCH] kvm: Avoid COW if KVM MMU is asynchronous Jan Kiszka
2009-04-26 13:08 ` Avi Kivity
2009-04-26 16:03   ` Jan Kiszka [this message]
2009-04-26 16:21     ` [Qemu-devel] [PATCH v2] " Avi Kivity
2009-04-26 16:44       ` [Qemu-devel] [PATCH v3] " Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49F485DC.2080702@web.de \
    --to=jan.kiszka@web.de \
    --cc=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).