qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	Leonardo Bras Soares Passos <lsoaresp@redhat.com>,
	peterx@redhat.com, Juan Quintela <quintela@redhat.com>
Subject: [PATCH 1/5] migration: Fix possible deadloop of ram save process
Date: Tue, 20 Sep 2022 18:37:56 -0400	[thread overview]
Message-ID: <20220920223800.47467-2-peterx@redhat.com> (raw)
In-Reply-To: <20220920223800.47467-1-peterx@redhat.com>

When starting ram saving procedure (especially at the completion phase),
always set last_seen_block to non-NULL to make sure we can always correctly
detect the case where "we've migrated all the dirty pages".

Then we'll guarantee both last_seen_block and pss.block will be valid
always before the loop starts.

See the comment in the code for some details.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/ram.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index dc1de9ddbc..1d42414ecc 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2546,14 +2546,22 @@ static int ram_find_and_save_block(RAMState *rs)
         return pages;
     }
 
+    /*
+     * Always keep last_seen_block/last_page valid during this procedure,
+     * because find_dirty_block() relies on these values (e.g., we compare
+     * last_seen_block with pss.block to see whether we searched all the
+     * ramblocks) to detect the completion of migration.  Having NULL value
+     * of last_seen_block can conditionally cause below loop to run forever.
+     */
+    if (!rs->last_seen_block) {
+        rs->last_seen_block = QLIST_FIRST_RCU(&ram_list.blocks);
+        rs->last_page = 0;
+    }
+
     pss.block = rs->last_seen_block;
     pss.page = rs->last_page;
     pss.complete_round = false;
 
-    if (!pss.block) {
-        pss.block = QLIST_FIRST_RCU(&ram_list.blocks);
-    }
-
     do {
         again = true;
         found = get_queued_page(rs, &pss);
-- 
2.32.0



  reply	other threads:[~2022-09-21  0:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-20 22:37 [PATCH 0/5] migration: Bug fixes (prepare for preempt-full) Peter Xu
2022-09-20 22:37 ` Peter Xu [this message]
2022-09-22 14:49   ` [PATCH 1/5] migration: Fix possible deadloop of ram save process Dr. David Alan Gilbert
2022-09-22 15:25     ` Peter Xu
2022-09-22 16:41       ` Dr. David Alan Gilbert
2022-10-04 14:25         ` Peter Xu
2022-10-04 15:02           ` Dr. David Alan Gilbert
2022-09-20 22:37 ` [PATCH 2/5] migration: Fix race on qemu_file_shutdown() Peter Xu
2022-09-22 15:43   ` Dr. David Alan Gilbert
2022-09-22 16:58   ` Daniel P. Berrangé
2022-09-22 19:37     ` Peter Xu
2022-09-23  7:14       ` Daniel P. Berrangé
2022-09-23 18:27         ` Peter Xu
2022-09-20 22:37 ` [PATCH 3/5] migration: Disallow xbzrle with postcopy Peter Xu
2022-09-22 15:56   ` Dr. David Alan Gilbert
2022-09-22 19:28     ` Peter Xu
2022-09-20 22:37 ` [PATCH 4/5] migration: Disallow postcopy preempt to be used with compress Peter Xu
2022-09-22 16:29   ` Dr. David Alan Gilbert
2022-09-20 22:38 ` [PATCH 5/5] migration: Use non-atomic ops for clear log bitmap Peter Xu

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=20220920223800.47467-2-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lsoaresp@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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).