* Denis Plotnikov (dplotni...@virtuozzo.com) wrote: > Signed-off-by: Denis Plotnikov <dplotni...@virtuozzo.com> > --- > migration/ram.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ > migration/ram.h | 3 +++ > 2 files changed, 57 insertions(+) > > diff --git a/migration/ram.c b/migration/ram.c > index 27d3403435..ce3dead932 100644 > --- a/migration/ram.c > +++ b/migration/ram.c > @@ -1555,6 +1555,60 @@ void ram_block_list_destroy(void) > } > } > > +static int mem_protect(void *addr, uint64_t length, int prot) > +{ > + int ret = mprotect(addr, length, prot); > + > + if (ret < 0) { > + error_report("%s: Can't change protection on ram block at %p", > + __func__, addr); > + } > + > + return ret; > +} > + > +static int ram_set_ro(void *addr, uint64_t length) > +{ > + return mem_protect(addr, length, PROT_READ); > +} > + > +static int ram_set_rw(void *addr, uint64_t length) > +{ > + return mem_protect(addr, length, PROT_READ | PROT_WRITE); > +} > + > +int ram_block_list_set_readonly(void) > +{ > + RAMBlock *block = NULL; > + RamBlockList *block_list = ram_bgs_block_list_get(); > + int ret = 0; > + > + QLIST_FOREACH(block, block_list, bgs_next) { > + ret = ram_set_ro(block->host, block->used_length); > + if (ret) { > + break; > + } > + } > + > + return ret; > +} > + > +int ram_block_list_set_writable(void) > +{ > + RAMBlock *block = NULL; > + RamBlockList *block_list = ram_bgs_block_list_get(); > + int ret = 0; > + > + QLIST_FOREACH(block, block_list, bgs_next) { > + ret = ram_set_rw(block->host, block->used_length); > + if (ret) { > + break; > + } > + }
Do you need to keep track of who was writeable previously to avoid changing blocks that should be read-only, Or are all RAMBlocks currently mapped rw? Dave > + return ret; > +} > + > static void ram_page_buffer_decrease_used(void) > { > qemu_event_reset(&ram_state->page_buffer.used_decreased); > diff --git a/migration/ram.h b/migration/ram.h > index 7c802c1d7f..4c463597a5 100644 > --- a/migration/ram.h > +++ b/migration/ram.h > @@ -71,4 +71,7 @@ RAMBlock *ram_bgs_block_find(uint8_t *address, ram_addr_t > *page_offset); > void *ram_page_buffer_get(void); > int ram_page_buffer_free(void *buffer); > > +int ram_block_list_set_readonly(void); > +int ram_block_list_set_writable(void); > + > #endif > -- > 2.17.0 > -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK