From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ly7Tp-0006qT-7Z for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:45:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ly7Tk-0006on-1y for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:45:24 -0400 Received: from [199.232.76.173] (port=54604 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ly7Tj-0006od-Q9 for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:45:19 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:49324) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ly7Tj-00015Y-2N for qemu-devel@nongnu.org; Sun, 26 Apr 2009 12:45:19 -0400 Message-ID: <49F48F86.6020801@web.de> Date: Sun, 26 Apr 2009 18:44:54 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <49F451B9.8040205@web.de> <49F45CDB.205@redhat.com> <49F485DC.2080702@web.de> <49F48A01.4090308@redhat.com> In-Reply-To: <49F48A01.4090308@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigA435C080BAFBE39BF1E521E9" Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH v3] kvm: Avoid COW if KVM MMU is asynchronous List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: qemu-devel , Gleb Natapov This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigA435C080BAFBE39BF1E521E9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Avi Kivity wrote: > Jan Kiszka wrote: >> 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. >> >> =20 >> last_ram_offset +=3D size; >> =20 >> + if (kvm_enabled()) >> + kvm_setup_guest_memory(new_block->host, size); >> + >> return new_block->offset; >> } >> =20 >=20 > I feel a little bad about picking such small nits, but the if statement= > requires braces. >=20 No problem. I'm in "trivial editing mode" ATM anyway. Thanks, Jan ----------> 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 --- 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..9281bd7 100644 --- a/exec.c +++ b/exec.c @@ -2484,6 +2484,9 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size) =20 last_ram_offset +=3D size; =20 + if (kvm_enabled()) { + kvm_setup_guest_memory(new_block->host, size); + } return new_block->offset; } =20 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; } =20 +void kvm_setup_guest_memory(void *start, size_t size) +{ + if (!kvm_has_sync_mmu()) { +#ifdef MADV_DONTFORK + int ret =3D 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); =20 int kvm_has_sync_mmu(void); =20 +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= ); =20 --------------enigA435C080BAFBE39BF1E521E9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkn0j5cACgkQniDOoMHTA+ktrACfU1bkqgQwBy9VBkNUCX1IzOlb 6RMAnRcraz0rXGff3+TZcKfJT6MuMYiX =vX65 -----END PGP SIGNATURE----- --------------enigA435C080BAFBE39BF1E521E9--