Message ID | 3bf3631115123d4a6a360b41ef0aaa47b40ff08d.1567534653.git.jag.raman@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Initial support of multi-process qemu | expand |
* Jagannathan Raman (jag.raman@oracle.com) wrote: > Allow RAM MemoryRegion to be created from an offset in a file, instead > of allocating at offset of 0 by default. This is needed to synchronize > RAM between QEMU & remote process. > This will be needed for the following patches. > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> > --- > exec.c | 11 +++++++---- > include/exec/ram_addr.h | 2 +- > include/qemu/mmap-alloc.h | 3 ++- > memory.c | 2 +- > util/mmap-alloc.c | 7 ++++--- > util/oslib-posix.c | 2 +- > 6 files changed, 16 insertions(+), 11 deletions(-) I'm surprised this doesn't change something in vhost-user.c:vhost_user_set_mem_table so that the vhost-user client knows what it's mapping? Dave > diff --git a/exec.c b/exec.c > index 3e78de3..b3f1aa9 100644 > --- a/exec.c > +++ b/exec.c > @@ -1885,6 +1885,7 @@ static void *file_ram_alloc(RAMBlock *block, > ram_addr_t memory, > int fd, > bool truncate, > + off_t offset, > Error **errp) > { > MachineState *ms = MACHINE(qdev_get_machine()); > @@ -1936,7 +1937,8 @@ static void *file_ram_alloc(RAMBlock *block, > } > > area = qemu_ram_mmap(fd, memory, block->mr->align, > - block->flags & RAM_SHARED, block->flags & RAM_PMEM); > + block->flags & RAM_SHARED, block->flags & RAM_PMEM, > + offset); > if (area == MAP_FAILED) { > error_setg_errno(errp, errno, > "unable to map backing store for guest RAM"); > @@ -2325,7 +2327,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) > #ifdef CONFIG_POSIX > RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > uint32_t ram_flags, int fd, > - Error **errp) > + off_t offset, Error **errp) > { > RAMBlock *new_block; > Error *local_err = NULL; > @@ -2370,7 +2372,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > new_block->used_length = size; > new_block->max_length = size; > new_block->flags = ram_flags; > - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); > + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, > + errp); > if (!new_block->host) { > g_free(new_block); > return NULL; > @@ -2400,7 +2403,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, > return NULL; > } > > - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); > + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); > if (!block) { > if (created) { > unlink(mem_path); > diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h > index b7b2e60..15837a1 100644 > --- a/include/exec/ram_addr.h > +++ b/include/exec/ram_addr.h > @@ -164,7 +164,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, > Error **errp); > RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > uint32_t ram_flags, int fd, > - Error **errp); > + off_t offset, Error **errp); > > RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, > MemoryRegion *mr, Error **errp); > diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h > index e786266..4f57985 100644 > --- a/include/qemu/mmap-alloc.h > +++ b/include/qemu/mmap-alloc.h > @@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd, > size_t size, > size_t align, > bool shared, > - bool is_pmem); > + bool is_pmem, > + off_t start); > > void qemu_ram_munmap(int fd, void *ptr, size_t size); > > diff --git a/memory.c b/memory.c > index 5d8c9a9..debed5e 100644 > --- a/memory.c > +++ b/memory.c > @@ -1622,7 +1622,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, > mr->destructor = memory_region_destructor_ram; > mr->ram_block = qemu_ram_alloc_from_fd(size, mr, > share ? RAM_SHARED : 0, > - fd, &err); > + fd, 0, &err); > mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; > if (err) { > mr->size = int128_zero(); > diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c > index f7f177d..4b727bd 100644 > --- a/util/mmap-alloc.c > +++ b/util/mmap-alloc.c > @@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd, > size_t size, > size_t align, > bool shared, > - bool is_pmem) > + bool is_pmem, > + off_t start) > { > int flags; > int map_sync_flags = 0; > @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, > offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; > > ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, > - flags | map_sync_flags, fd, 0); > + flags | map_sync_flags, fd, start); > > if (ptr == MAP_FAILED && map_sync_flags) { > if (errno == ENOTSUP) { > @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, > * we will remove these flags to handle compatibility. > */ > ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, > - flags, fd, 0); > + flags, fd, start); > } > > if (ptr == MAP_FAILED) { > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > index fe0309c..f6a243f 100644 > --- a/util/oslib-posix.c > +++ b/util/oslib-posix.c > @@ -204,7 +204,7 @@ void *qemu_memalign(size_t alignment, size_t size) > void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) > { > size_t align = QEMU_VMALLOC_ALIGN; > - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); > + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); > > if (ptr == MAP_FAILED) { > return NULL; > -- > 1.8.3.1 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
On 9/4/2019 4:11 AM, Dr. David Alan Gilbert wrote: > * Jagannathan Raman (jag.raman@oracle.com) wrote: >> Allow RAM MemoryRegion to be created from an offset in a file, instead >> of allocating at offset of 0 by default. This is needed to synchronize >> RAM between QEMU & remote process. >> This will be needed for the following patches. >> >> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> >> Signed-off-by: John G Johnson <john.g.johnson@oracle.com> >> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> >> --- >> exec.c | 11 +++++++---- >> include/exec/ram_addr.h | 2 +- >> include/qemu/mmap-alloc.h | 3 ++- >> memory.c | 2 +- >> util/mmap-alloc.c | 7 ++++--- >> util/oslib-posix.c | 2 +- >> 6 files changed, 16 insertions(+), 11 deletions(-) > > I'm surprised this doesn't change something in > vhost-user.c:vhost_user_set_mem_table so that the vhost-user client > knows what it's mapping? Hi Dave, vhost-user does not use the functions addressed in this patch for mapping the RAM onto the remote process. It calls mmap() for this purpose (vu_set_mem_table_exec()). Thanks! -- Jag > > Dave > >> diff --git a/exec.c b/exec.c >> index 3e78de3..b3f1aa9 100644 >> --- a/exec.c >> +++ b/exec.c >> @@ -1885,6 +1885,7 @@ static void *file_ram_alloc(RAMBlock *block, >> ram_addr_t memory, >> int fd, >> bool truncate, >> + off_t offset, >> Error **errp) >> { >> MachineState *ms = MACHINE(qdev_get_machine()); >> @@ -1936,7 +1937,8 @@ static void *file_ram_alloc(RAMBlock *block, >> } >> >> area = qemu_ram_mmap(fd, memory, block->mr->align, >> - block->flags & RAM_SHARED, block->flags & RAM_PMEM); >> + block->flags & RAM_SHARED, block->flags & RAM_PMEM, >> + offset); >> if (area == MAP_FAILED) { >> error_setg_errno(errp, errno, >> "unable to map backing store for guest RAM"); >> @@ -2325,7 +2327,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) >> #ifdef CONFIG_POSIX >> RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, >> uint32_t ram_flags, int fd, >> - Error **errp) >> + off_t offset, Error **errp) >> { >> RAMBlock *new_block; >> Error *local_err = NULL; >> @@ -2370,7 +2372,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, >> new_block->used_length = size; >> new_block->max_length = size; >> new_block->flags = ram_flags; >> - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); >> + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, >> + errp); >> if (!new_block->host) { >> g_free(new_block); >> return NULL; >> @@ -2400,7 +2403,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, >> return NULL; >> } >> >> - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); >> + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); >> if (!block) { >> if (created) { >> unlink(mem_path); >> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h >> index b7b2e60..15837a1 100644 >> --- a/include/exec/ram_addr.h >> +++ b/include/exec/ram_addr.h >> @@ -164,7 +164,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, >> Error **errp); >> RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, >> uint32_t ram_flags, int fd, >> - Error **errp); >> + off_t offset, Error **errp); >> >> RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, >> MemoryRegion *mr, Error **errp); >> diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h >> index e786266..4f57985 100644 >> --- a/include/qemu/mmap-alloc.h >> +++ b/include/qemu/mmap-alloc.h >> @@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd, >> size_t size, >> size_t align, >> bool shared, >> - bool is_pmem); >> + bool is_pmem, >> + off_t start); >> >> void qemu_ram_munmap(int fd, void *ptr, size_t size); >> >> diff --git a/memory.c b/memory.c >> index 5d8c9a9..debed5e 100644 >> --- a/memory.c >> +++ b/memory.c >> @@ -1622,7 +1622,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, >> mr->destructor = memory_region_destructor_ram; >> mr->ram_block = qemu_ram_alloc_from_fd(size, mr, >> share ? RAM_SHARED : 0, >> - fd, &err); >> + fd, 0, &err); >> mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; >> if (err) { >> mr->size = int128_zero(); >> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c >> index f7f177d..4b727bd 100644 >> --- a/util/mmap-alloc.c >> +++ b/util/mmap-alloc.c >> @@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd, >> size_t size, >> size_t align, >> bool shared, >> - bool is_pmem) >> + bool is_pmem, >> + off_t start) >> { >> int flags; >> int map_sync_flags = 0; >> @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, >> offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; >> >> ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, >> - flags | map_sync_flags, fd, 0); >> + flags | map_sync_flags, fd, start); >> >> if (ptr == MAP_FAILED && map_sync_flags) { >> if (errno == ENOTSUP) { >> @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, >> * we will remove these flags to handle compatibility. >> */ >> ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, >> - flags, fd, 0); >> + flags, fd, start); >> } >> >> if (ptr == MAP_FAILED) { >> diff --git a/util/oslib-posix.c b/util/oslib-posix.c >> index fe0309c..f6a243f 100644 >> --- a/util/oslib-posix.c >> +++ b/util/oslib-posix.c >> @@ -204,7 +204,7 @@ void *qemu_memalign(size_t alignment, size_t size) >> void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) >> { >> size_t align = QEMU_VMALLOC_ALIGN; >> - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); >> + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); >> >> if (ptr == MAP_FAILED) { >> return NULL; >> -- >> 1.8.3.1 >> > -- > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK >
* Jag Raman (jag.raman@oracle.com) wrote: > > > On 9/4/2019 4:11 AM, Dr. David Alan Gilbert wrote: > > * Jagannathan Raman (jag.raman@oracle.com) wrote: > > > Allow RAM MemoryRegion to be created from an offset in a file, instead > > > of allocating at offset of 0 by default. This is needed to synchronize > > > RAM between QEMU & remote process. > > > This will be needed for the following patches. > > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com> > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com> > > > --- > > > exec.c | 11 +++++++---- > > > include/exec/ram_addr.h | 2 +- > > > include/qemu/mmap-alloc.h | 3 ++- > > > memory.c | 2 +- > > > util/mmap-alloc.c | 7 ++++--- > > > util/oslib-posix.c | 2 +- > > > 6 files changed, 16 insertions(+), 11 deletions(-) > > > > I'm surprised this doesn't change something in > > vhost-user.c:vhost_user_set_mem_table so that the vhost-user client > > knows what it's mapping? > > Hi Dave, > > vhost-user does not use the functions addressed in this patch for > mapping the RAM onto the remote process. It calls mmap() for this > purpose (vu_set_mem_table_exec()). It should at least check that the file it's sending over set-mem-table has a 0 offset, otherwise things could get confused if someone tries to run a vhost-user device on a system that's also running multi-process (which should be a whole world of fun!) dave > Thanks! > -- > Jag > > > > > Dave > > > > > diff --git a/exec.c b/exec.c > > > index 3e78de3..b3f1aa9 100644 > > > --- a/exec.c > > > +++ b/exec.c > > > @@ -1885,6 +1885,7 @@ static void *file_ram_alloc(RAMBlock *block, > > > ram_addr_t memory, > > > int fd, > > > bool truncate, > > > + off_t offset, > > > Error **errp) > > > { > > > MachineState *ms = MACHINE(qdev_get_machine()); > > > @@ -1936,7 +1937,8 @@ static void *file_ram_alloc(RAMBlock *block, > > > } > > > area = qemu_ram_mmap(fd, memory, block->mr->align, > > > - block->flags & RAM_SHARED, block->flags & RAM_PMEM); > > > + block->flags & RAM_SHARED, block->flags & RAM_PMEM, > > > + offset); > > > if (area == MAP_FAILED) { > > > error_setg_errno(errp, errno, > > > "unable to map backing store for guest RAM"); > > > @@ -2325,7 +2327,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) > > > #ifdef CONFIG_POSIX > > > RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > > > uint32_t ram_flags, int fd, > > > - Error **errp) > > > + off_t offset, Error **errp) > > > { > > > RAMBlock *new_block; > > > Error *local_err = NULL; > > > @@ -2370,7 +2372,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > > > new_block->used_length = size; > > > new_block->max_length = size; > > > new_block->flags = ram_flags; > > > - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); > > > + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, > > > + errp); > > > if (!new_block->host) { > > > g_free(new_block); > > > return NULL; > > > @@ -2400,7 +2403,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, > > > return NULL; > > > } > > > - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); > > > + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); > > > if (!block) { > > > if (created) { > > > unlink(mem_path); > > > diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h > > > index b7b2e60..15837a1 100644 > > > --- a/include/exec/ram_addr.h > > > +++ b/include/exec/ram_addr.h > > > @@ -164,7 +164,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, > > > Error **errp); > > > RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, > > > uint32_t ram_flags, int fd, > > > - Error **errp); > > > + off_t offset, Error **errp); > > > RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, > > > MemoryRegion *mr, Error **errp); > > > diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h > > > index e786266..4f57985 100644 > > > --- a/include/qemu/mmap-alloc.h > > > +++ b/include/qemu/mmap-alloc.h > > > @@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd, > > > size_t size, > > > size_t align, > > > bool shared, > > > - bool is_pmem); > > > + bool is_pmem, > > > + off_t start); > > > void qemu_ram_munmap(int fd, void *ptr, size_t size); > > > diff --git a/memory.c b/memory.c > > > index 5d8c9a9..debed5e 100644 > > > --- a/memory.c > > > +++ b/memory.c > > > @@ -1622,7 +1622,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, > > > mr->destructor = memory_region_destructor_ram; > > > mr->ram_block = qemu_ram_alloc_from_fd(size, mr, > > > share ? RAM_SHARED : 0, > > > - fd, &err); > > > + fd, 0, &err); > > > mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; > > > if (err) { > > > mr->size = int128_zero(); > > > diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c > > > index f7f177d..4b727bd 100644 > > > --- a/util/mmap-alloc.c > > > +++ b/util/mmap-alloc.c > > > @@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd, > > > size_t size, > > > size_t align, > > > bool shared, > > > - bool is_pmem) > > > + bool is_pmem, > > > + off_t start) > > > { > > > int flags; > > > int map_sync_flags = 0; > > > @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, > > > offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; > > > ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, > > > - flags | map_sync_flags, fd, 0); > > > + flags | map_sync_flags, fd, start); > > > if (ptr == MAP_FAILED && map_sync_flags) { > > > if (errno == ENOTSUP) { > > > @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, > > > * we will remove these flags to handle compatibility. > > > */ > > > ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, > > > - flags, fd, 0); > > > + flags, fd, start); > > > } > > > if (ptr == MAP_FAILED) { > > > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > > > index fe0309c..f6a243f 100644 > > > --- a/util/oslib-posix.c > > > +++ b/util/oslib-posix.c > > > @@ -204,7 +204,7 @@ void *qemu_memalign(size_t alignment, size_t size) > > > void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) > > > { > > > size_t align = QEMU_VMALLOC_ALIGN; > > > - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); > > > + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); > > > if (ptr == MAP_FAILED) { > > > return NULL; > > > -- > > > 1.8.3.1 > > > > > -- > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK > > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
diff --git a/exec.c b/exec.c index 3e78de3..b3f1aa9 100644 --- a/exec.c +++ b/exec.c @@ -1885,6 +1885,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { MachineState *ms = MACHINE(qdev_get_machine()); @@ -1936,7 +1937,8 @@ static void *file_ram_alloc(RAMBlock *block, } area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED, block->flags & RAM_PMEM); + block->flags & RAM_SHARED, block->flags & RAM_PMEM, + offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2325,7 +2327,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) #ifdef CONFIG_POSIX RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp) + off_t offset, Error **errp) { RAMBlock *new_block; Error *local_err = NULL; @@ -2370,7 +2372,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, new_block->used_length = size; new_block->max_length = size; new_block->flags = ram_flags; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, + errp); if (!new_block->host) { g_free(new_block); return NULL; @@ -2400,7 +2403,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b7b2e60..15837a1 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -164,7 +164,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp); + off_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index e786266..4f57985 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, - bool is_pmem); + bool is_pmem, + off_t start); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/memory.c b/memory.c index 5d8c9a9..debed5e 100644 --- a/memory.c +++ b/memory.c @@ -1622,7 +1622,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, 0, &err); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; if (err) { mr->size = int128_zero(); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index f7f177d..4b727bd 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, - bool is_pmem) + bool is_pmem, + off_t start) { int flags; int map_sync_flags = 0; @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags | map_sync_flags, fd, 0); + flags | map_sync_flags, fd, start); if (ptr == MAP_FAILED && map_sync_flags) { if (errno == ENOTSUP) { @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, * we will remove these flags to handle compatibility. */ ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags, fd, 0); + flags, fd, start); } if (ptr == MAP_FAILED) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index fe0309c..f6a243f 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -204,7 +204,7 @@ void *qemu_memalign(size_t alignment, size_t size) void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); if (ptr == MAP_FAILED) { return NULL;