[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset
From: |
Jag Raman |
Subject: |
Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset |
Date: |
Tue, 12 May 2020 07:56:33 -0400 |
> On May 12, 2020, at 4:48 AM, Daniel P. Berrangé <address@hidden> wrote:
>
> On Wed, Apr 22, 2020 at 09:13:36PM -0700, address@hidden wrote:
>> From: Jagannathan Raman <address@hidden>
>>
>> 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.
>
> Can you elaborate on why remote processes require the RAM to be offset
> from zero ?
Hi Daniel,
As it turns out, the RAM is scattered across the physical address space
(system_memory) of QEMU. Therefore, the system memory is composed
of multiple sections of RAM, and some sections start at a non-zero RAM
offset.
As a result, the remote process needs the ability to map these RAM
sections into system_memory.
Thank you!
--
Jag
>
> NB, I'm not objecting - I'm just curious to understand more.
>
>>
>> Signed-off-by: Jagannathan Raman <address@hidden>
>> Signed-off-by: John G Johnson <address@hidden>
>> Signed-off-by: Elena Ufimtseva <address@hidden>
>> Reviewed-by: Dr. David Alan Gilbert <address@hidden>
>> ---
>> 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(-)
>>
>> diff --git a/exec.c b/exec.c
>> index 2874bb5088..d0ac9545f4 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -1801,6 +1801,7 @@ static void *file_ram_alloc(RAMBlock *block,
>> ram_addr_t memory,
>> int fd,
>> bool truncate,
>> + off_t offset,
>> Error **errp)
>> {
>> void *area;
>> @@ -1851,7 +1852,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");
>> @@ -2283,7 +2285,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;
>> @@ -2328,7 +2330,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;
>> @@ -2358,7 +2361,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 5e59a3d8d7..1b9f489ff0 100644
>> --- a/include/exec/ram_addr.h
>> +++ b/include/exec/ram_addr.h
>> @@ -121,7 +121,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 e786266b92..4f579858bc 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 601b749906..f5fec476b7 100644
>> --- a/memory.c
>> +++ b/memory.c
>> @@ -1596,7 +1596,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 27dcccd8ec..a28f7025f0 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 062236a1ab..4c6b9e90c6 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -209,7 +209,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;
>> --
>> 2.25.GIT
>>
>
> Regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
>
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Stefan Hajnoczi, 2020/05/12
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Daniel P . Berrangé, 2020/05/12
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset,
Jag Raman <=
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Stefan Hajnoczi, 2020/05/13
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Igor Mammedov, 2020/05/13
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Jag Raman, 2020/05/13
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Igor Mammedov, 2020/05/14
- Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset, Dr. David Alan Gilbert, 2020/05/14