diff mbox series

[v1,2/5] migration/ram: Fix error handling in ram_write_tracking_start()

Message ID 20230105124528.93813-3-david@redhat.com
State New
Headers show
Series migration/ram: background snapshot fixes and optimiations | expand

Commit Message

David Hildenbrand Jan. 5, 2023, 12:45 p.m. UTC
If something goes wrong during uffd_change_protection(), we would miss
to unregister uffd-wp and not release our reference. Fix it by
performing the uffd_change_protection(true) last.

Note that a uffd_change_protection(false) on the recovery path without a
prior uffd_change_protection(false) is fine.

Fixes: 278e2f551a09 ("migration: support UFFD write fault processing in ram_save_iterate()")
Cc: qemu-stable@nongnu.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 migration/ram.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Juan Quintela Feb. 2, 2023, 11:16 a.m. UTC | #1
David Hildenbrand <david@redhat.com> wrote:
> If something goes wrong during uffd_change_protection(), we would miss
> to unregister uffd-wp and not release our reference. Fix it by
> performing the uffd_change_protection(true) last.
>
> Note that a uffd_change_protection(false) on the recovery path without a
> prior uffd_change_protection(false) is fine.
>
> Fixes: 278e2f551a09 ("migration: support UFFD write fault processing in ram_save_iterate()")
> Cc: qemu-stable@nongnu.org
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox series

Patch

diff --git a/migration/ram.c b/migration/ram.c
index b8f58d2a40..6e4e41952a 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1896,13 +1896,14 @@  int ram_write_tracking_start(void)
                 block->max_length, UFFDIO_REGISTER_MODE_WP, NULL)) {
             goto fail;
         }
+        block->flags |= RAM_UF_WRITEPROTECT;
+        memory_region_ref(block->mr);
+
         /* Apply UFFD write protection to the block memory range */
         if (uffd_change_protection(rs->uffdio_fd, block->host,
                 block->max_length, true, false)) {
             goto fail;
         }
-        block->flags |= RAM_UF_WRITEPROTECT;
-        memory_region_ref(block->mr);
 
         trace_ram_write_tracking_ramblock_start(block->idstr, block->page_size,
                 block->host, block->max_length);