All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"David Hildenbrand" <david@redhat.com>
Subject: [PULL 23/33] softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal()
Date: Tue, 15 Jun 2021 15:38:45 +0200	[thread overview]
Message-ID: <20210615133855.775687-24-pbonzini@redhat.com> (raw)
In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com>

From: David Hildenbrand <david@redhat.com>

Let's pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal(),
preparing for passing additional flags.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com> for memory backend and machine core
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20210510114328.21835-7-david@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/exec/ram_addr.h |  2 +-
 softmmu/memory.c        |  4 ++--
 softmmu/physmem.c       | 29 ++++++++++++-----------------
 3 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index a7e3378340..6d4513f8e2 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -122,7 +122,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
-RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr,
+RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr,
                          Error **errp);
 RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size,
                                     void (*resized)(const char*,
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 5c0ff76c06..f0161515e9 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1546,7 +1546,7 @@ void memory_region_init_ram_flags_nomigrate(MemoryRegion *mr,
     mr->ram = true;
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &err);
+    mr->ram_block = qemu_ram_alloc(size, ram_flags, mr, &err);
     if (err) {
         mr->size = int128_zero();
         object_unparent(OBJECT(mr));
@@ -1702,7 +1702,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr,
     mr->terminates = true;
     mr->rom_device = true;
     mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc(size, false,  mr, &err);
+    mr->ram_block = qemu_ram_alloc(size, 0, mr, &err);
     if (err) {
         mr->size = int128_zero();
         object_unparent(OBJECT(mr));
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 2f106d0680..f7adf544df 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -2128,12 +2128,15 @@ 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,
+                                  void *host, uint32_t ram_flags,
                                   MemoryRegion *mr, Error **errp)
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
 
+    assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0);
+    assert(!host ^ (ram_flags & RAM_PREALLOC));
+
     size = HOST_PAGE_ALIGN(size);
     max_size = HOST_PAGE_ALIGN(max_size);
     new_block = g_malloc0(sizeof(*new_block));
@@ -2145,15 +2148,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     new_block->fd = -1;
     new_block->page_size = qemu_real_host_page_size;
     new_block->host = host;
-    if (host) {
-        new_block->flags |= RAM_PREALLOC;
-    }
-    if (share) {
-        new_block->flags |= RAM_SHARED;
-    }
-    if (resizeable) {
-        new_block->flags |= RAM_RESIZEABLE;
-    }
+    new_block->flags = ram_flags;
     ram_block_add(new_block, &local_err);
     if (local_err) {
         g_free(new_block);
@@ -2166,15 +2161,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                    MemoryRegion *mr, Error **errp)
 {
-    return qemu_ram_alloc_internal(size, size, NULL, host, false,
-                                   false, mr, errp);
+    return qemu_ram_alloc_internal(size, size, NULL, host, RAM_PREALLOC, mr,
+                                   errp);
 }
 
-RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share,
+RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags,
                          MemoryRegion *mr, Error **errp)
 {
-    return qemu_ram_alloc_internal(size, size, NULL, NULL, false,
-                                   share, mr, errp);
+    assert((ram_flags & ~RAM_SHARED) == 0);
+    return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, errp);
 }
 
 RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz,
@@ -2183,8 +2178,8 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz,
                                                      void *host),
                                      MemoryRegion *mr, Error **errp)
 {
-    return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true,
-                                   false, mr, errp);
+    return qemu_ram_alloc_internal(size, maxsz, resized, NULL,
+                                   RAM_RESIZEABLE, mr, errp);
 }
 
 static void reclaim_ramblock(RAMBlock *block)
-- 
2.31.1




  parent reply	other threads:[~2021-06-15 14:02 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15 13:38 [PULL 00/33] Misc patches for 2021-06-15 Paolo Bonzini
2021-06-15 13:38 ` [PULL 01/33] vnc: avoid deprecation warnings for SASL on OS X Paolo Bonzini
2021-06-15 13:38 ` [PULL 02/33] vl: Fix an assert failure in error path Paolo Bonzini
2021-06-15 13:38 ` [PULL 03/33] qemu-config: use qemu_opts_from_qdict Paolo Bonzini
2021-06-15 13:38 ` [PULL 04/33] block/scsi: correctly emulate the VPD block limits page Paolo Bonzini
2021-06-15 13:38 ` [PULL 05/33] runstate: Initialize Error * to NULL Paolo Bonzini
2021-06-15 13:38 ` [PULL 06/33] esp: only assert INTR_DC interrupt flag if selection fails Paolo Bonzini
2021-06-15 13:38 ` [PULL 07/33] esp: only set ESP_RSEQ at the start of the select sequence Paolo Bonzini
2021-06-15 13:38 ` [PULL 08/33] esp: allow non-DMA callback in esp_transfer_data() initial transfer Paolo Bonzini
2021-06-15 13:38 ` [PULL 09/33] esp: handle non-DMA transfers from the target one byte at a time Paolo Bonzini
2021-06-15 13:38 ` [PULL 10/33] esp: ensure PDMA write transfers are flushed from the FIFO to the target immediately Paolo Bonzini
2021-06-15 13:38 ` [PULL 11/33] esp: revert 75ef849696 "esp: correctly fill bus id with requested lun" Paolo Bonzini
2021-06-15 13:38 ` [PULL 12/33] esp: correctly accumulate extended messages for PDMA Paolo Bonzini
2021-06-15 13:38 ` [PULL 13/33] esp: fix migration version check in esp_is_version_5() Paolo Bonzini
2021-06-15 13:38 ` [PULL 14/33] esp: store lun coming from the MESSAGE OUT phase Paolo Bonzini
2021-06-15 13:38 ` [PULL 15/33] softmmu/physmem: Mark shared anonymous memory RAM_SHARED Paolo Bonzini
2021-06-15 13:38 ` [PULL 16/33] softmmu/physmem: Fix ram_block_discard_range() to handle shared anonymous memory Paolo Bonzini
2021-06-15 13:38 ` [PULL 17/33] softmmu/physmem: Fix qemu_ram_remap() " Paolo Bonzini
2021-06-15 13:38 ` [PULL 18/33] util/mmap-alloc: Factor out calculation of the pagesize for the guard page Paolo Bonzini
2021-06-15 13:38 ` [PULL 19/33] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() Paolo Bonzini
2021-06-15 13:38 ` [PULL 20/33] util/mmap-alloc: Factor out activating of memory to mmap_activate() Paolo Bonzini
2021-06-15 13:38 ` [PULL 21/33] softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() Paolo Bonzini
2021-06-15 13:38 ` [PULL 22/33] softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate() Paolo Bonzini
2021-06-15 13:38 ` Paolo Bonzini [this message]
2021-06-15 13:38 ` [PULL 24/33] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap() Paolo Bonzini
2021-06-15 13:38 ` [PULL 25/33] memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() Paolo Bonzini
2021-06-15 13:38 ` [PULL 26/33] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux Paolo Bonzini
2021-06-15 13:38 ` [PULL 27/33] hostmem: Wire up RAM_NORESERVE via "reserve" property Paolo Bonzini
2021-06-15 13:38 ` [PULL 28/33] qmp: Clarify memory backend properties returned via query-memdev Paolo Bonzini
2021-06-15 13:38 ` [PULL 29/33] qmp: Include "share" property of memory backends Paolo Bonzini
2021-06-15 13:38 ` [PULL 30/33] hmp: Print "share" property of memory backends with "info memdev" Paolo Bonzini
2021-06-15 13:38 ` [PULL 31/33] qmp: Include "reserve" property of memory backends Paolo Bonzini
2021-06-15 13:38 ` [PULL 32/33] hmp: Print "reserve" property of memory backends with "info memdev" Paolo Bonzini
2021-06-15 13:38 ` [PULL 33/33] configure: map x32 to cpu_family x86_64 for meson Paolo Bonzini
2021-06-15 14:17 ` [PULL 00/33] Misc patches for 2021-06-15 Peter Maydell
2021-06-15 16:52   ` Philippe Mathieu-Daudé
2021-06-17 10:06     ` Alex Bennée
2021-06-17 12:55       ` Paolo Bonzini
2021-06-17 15:34       ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210615133855.775687-24-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=david@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.