All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Hyman Huang <huangy81@chinatelecom.cn>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	Peter Xu <peterx@redhat.com>
Subject: [PULL 12/12] KVM: Fix dirty ring mmap incorrect size due to renaming accident
Date: Wed, 23 Jun 2021 14:14:24 +0200	[thread overview]
Message-ID: <20210623121424.1259496-13-pbonzini@redhat.com> (raw)
In-Reply-To: <20210623121424.1259496-1-pbonzini@redhat.com>

From: Peter Xu <peterx@redhat.com>

Found this when I wanted to try the per-vcpu dirty rate series out, then I
found that it's not really working and it can quickly hang death a guest.  I
found strange errors (e.g. guest crash after migration) happens even without
the per-vcpu dirty rate series.

When merging dirty ring, probably no one notice that the trivial renaming diff
[1] missed two existing references of kvm_dirty_ring_sizes; they do matter
since otherwise we'll mmap() a shorter range of memory after the renaming.

I think it didn't SIGBUS for me easily simply because some other stuff within
qemu mmap()ed right after the dirty rings (e.g. when testing 4096 slots, it
aligned with one small page on x86), so when we access the rings we've been
reading/writting to random memory elsewhere of qemu.

Fix the two sizes when map/unmap the shared dirty gfn memory.

[1] https://lore.kernel.org/qemu-devel/dac5f0c6-1bca-3daf-e5d2-6451dbbaca93@redhat.com/

Cc: Hyman Huang <huangy81@chinatelecom.cn>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20210609014355.217110-1-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 accel/kvm/kvm-all.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index c7ec538850..e5b10dd129 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -411,7 +411,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
     }
 
     if (cpu->kvm_dirty_gfns) {
-        ret = munmap(cpu->kvm_dirty_gfns, s->kvm_dirty_ring_size);
+        ret = munmap(cpu->kvm_dirty_gfns, s->kvm_dirty_ring_bytes);
         if (ret < 0) {
             goto err;
         }
@@ -495,7 +495,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
 
     if (s->kvm_dirty_ring_size) {
         /* Use MAP_SHARED to share pages with the kernel */
-        cpu->kvm_dirty_gfns = mmap(NULL, s->kvm_dirty_ring_size,
+        cpu->kvm_dirty_gfns = mmap(NULL, s->kvm_dirty_ring_bytes,
                                    PROT_READ | PROT_WRITE, MAP_SHARED,
                                    cpu->kvm_fd,
                                    PAGE_SIZE * KVM_DIRTY_LOG_PAGE_OFFSET);
-- 
2.31.1



  parent reply	other threads:[~2021-06-23 12:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 12:14 [PULL 00/12] Misc, mostly meson patches for 2021-06-23 Paolo Bonzini
2021-06-23 12:14 ` [PULL 01/12] target/i386: kvm: add support for TSC scaling Paolo Bonzini
2021-06-23 12:14 ` [PULL 02/12] meson: drop unused CONFIG_GCRYPT_HMAC Paolo Bonzini
2021-06-23 12:14 ` [PULL 03/12] configure: drop unused variables for xts Paolo Bonzini
2021-06-23 12:14 ` [PULL 04/12] meson: remove preadv from summary Paolo Bonzini
2021-06-23 12:14 ` [PULL 05/12] tests: remove QCRYPTO_HAVE_TLS_TEST_SUPPORT Paolo Bonzini
2021-06-23 12:14 ` [PULL 06/12] configure, meson: convert crypto detection to meson Paolo Bonzini
2021-06-23 12:14 ` [PULL 07/12] configure, meson: convert libtasn1 " Paolo Bonzini
2021-06-23 12:14 ` [PULL 08/12] configure, meson: convert pam " Paolo Bonzini
2021-06-23 12:14 ` [PULL 09/12] configure, meson: convert libusb " Paolo Bonzini
2021-06-25  2:09   ` 罗勇刚(Yonggang Luo)
2021-06-25  8:50     ` Paolo Bonzini
2021-06-23 12:14 ` [PULL 10/12] configure, meson: convert libcacard " Paolo Bonzini
2021-06-23 12:14 ` [PULL 11/12] configure, meson: convert libusbredir " Paolo Bonzini
2021-06-23 12:14 ` Paolo Bonzini [this message]
2021-06-24 19:09 ` [PULL 00/12] Misc, mostly meson patches for 2021-06-23 Peter Maydell
2021-06-24 21:04   ` Paolo Bonzini
2021-06-25  8:09     ` Peter Maydell
2021-06-25  8:48       ` Paolo Bonzini

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=20210623121424.1259496-13-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=huangy81@chinatelecom.cn \
    --cc=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.