diff mbox series

[v1,4/5] migration/ram: Rely on used_length for uffd_change_protection()

Message ID 20230105124528.93813-5-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
ram_mig_ram_block_resized() will abort migration (including background
snapshots) when resizing a RAMBlock. ram_block_populate_read() will only
populate RAM up to used_length, so at least for anonymous memory
protecting everything between used_length and max_length won't
actually be protected and is just a NOP.

So let's only protect everything up to used_length.

Note: it still makes sense to register uffd-wp for max_length, such
that RAM_UF_WRITEPROTECT is independent of a changing used_length.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 migration/ram.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Juan Quintela Feb. 2, 2023, 11:18 a.m. UTC | #1
David Hildenbrand <david@redhat.com> wrote:
> ram_mig_ram_block_resized() will abort migration (including background
> snapshots) when resizing a RAMBlock. ram_block_populate_read() will only
> populate RAM up to used_length, so at least for anonymous memory
> protecting everything between used_length and max_length won't
> actually be protected and is just a NOP.
>
> So let's only protect everything up to used_length.
>
> Note: it still makes sense to register uffd-wp for max_length, such
> that RAM_UF_WRITEPROTECT is independent of a changing used_length.
>
> 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 6a3dbee2c3..73a443f683 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1901,7 +1901,7 @@  int ram_write_tracking_start(void)
 
         /* Apply UFFD write protection to the block memory range */
         if (uffd_change_protection(rs->uffdio_fd, block->host,
-                block->max_length, true, false)) {
+                                   block->used_length, true, false)) {
             goto fail;
         }