qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* QEMU RAM allocation function fails
@ 2020-11-05 19:50 Wayne Li
  2020-11-05 19:58 ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 3+ messages in thread
From: Wayne Li @ 2020-11-05 19:50 UTC (permalink / raw)
  To: QEMU Developers

Dear QEMU list members,

We developed a virtual machine that runs on QEMU.  This virtual
machine is pretty much an emulated P4080 processor with some
peripherals attached.  Initializing one of these peripherals, i.e. the
RAM, seems to be having problems.  I use the function
"memory_region_init_ram" to initialize the RAM and farther down the
call stack I see that the "qemu_ram_alloc" function returns an address
of 0 proving the RAM allocation wasn't successful.  Here is the block
of code in question copied from the file memory.c:

void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr,
                                             Object *owner,
                                             const char *name,
                                             uint64_t size,
                                             bool share,
                                             Error **errp)
{
    memory_region_init(mr, owner, name, size);
    mr->ram = true;
    mr->terminates = true;
    mr->destructor = memory_region_destructor_ram;
    mr->ram_block = qemu_ram_alloc(size, share, mr, errp);
    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
}

Tracing farther into the "qemu_ram_alloc" function reveals that the
function fails because inside the "qemu_ram_alloc_internal" function
in file exec.c, the function "ram_block_add" fails.  Interestingly, a
local_err object is populated here and the msg field in this object is
populated with the String "cannot set up guest memory 'ram0': Invalid
argument".  Here is the block of code in question copied from the file
exec.c:

RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
                                  void (*resized)(const char*,
                                                  uint64_t length,
                                                  void *host),
                                  void *host, bool resizeable, bool share,
                                  MemoryRegion *mr, Error **errp)
{
    RAMBlock *new_block;
    Error *local_err = NULL;

    size = HOST_PAGE_ALIGN(size);
    max_size = HOST_PAGE_ALIGN(max_size);
    new_block = g_malloc0(sizeof(*new_block));
    new_block->mr = mr;
    new_block->resized = resized;
    new_block->used_length = size;
    new_block->max_length = max_size;
    assert(max_size >= size);
    new_block->fd = -1;
    new_block->page_size = getpagesize();
    new_block->host = host;
    if (host) {
        new_block->flags |= RAM_PREALLOC;
    }
    if (resizeable) {
        new_block->flags |= RAM_RESIZEABLE;
    }
    ram_block_add(new_block, &local_err, share);
    if (local_err) {
        g_free(new_block);
        error_propagate(errp, local_err);
        return NULL;
    }
    return new_block;
}

Anyway, our VM runs fine until it tries to access the RAM region so
this is a pretty critical problem for us to solve.  Does anyone know
much about these QEMU functions?  What could be causing these RAM
initialzation functions to fail in this way?

-Thanks, Wayne Li


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-05 20:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-05 19:50 QEMU RAM allocation function fails Wayne Li
2020-11-05 19:58 ` Dr. David Alan Gilbert
2020-11-05 20:08   ` Wayne Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).