cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-memory-exec-switch-file-ram-allocation-functions-to-.patch

26ba25
From 6a5885e65ce9daac0464a78c93a10c36f41b28ce Mon Sep 17 00:00:00 2001
26ba25
From: "plai@redhat.com" <plai@redhat.com>
26ba25
Date: Mon, 7 Jan 2019 17:02:17 +0000
26ba25
Subject: [PATCH 16/22] memory, exec: switch file ram allocation functions to
26ba25
 'flags' parameters
26ba25
26ba25
RH-Author: plai@redhat.com
26ba25
Message-id: <1546880543-24860-5-git-send-email-plai@redhat.com>
26ba25
Patchwork-id: 83889
26ba25
O-Subject: [RHEL8.0 qemu-kvm PATCH v7 04/10] memory, exec: switch file ram allocation functions to 'flags' parameters
26ba25
Bugzilla: 1539285
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
26ba25
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
26ba25
26ba25
From: Junyan He <junyan.he@intel.com>
26ba25
26ba25
As more flag parameters besides the existing 'share' are going to be
26ba25
added to following functions
26ba25
memory_region_init_ram_from_file
26ba25
qemu_ram_alloc_from_fd
26ba25
qemu_ram_alloc_from_file
26ba25
let's switch them to use the 'flags' parameters so as to ease future
26ba25
flag additions.
26ba25
26ba25
The existing 'share' flag is converted to the RAM_SHARED bit in ram_flags,
26ba25
and other flag bits are ignored by above functions right now.
26ba25
26ba25
Signed-off-by: Junyan He <junyan.he@intel.com>
26ba25
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
26ba25
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
26ba25
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26ba25
(cherry picked from commit cbfc01710362f3de6fca3010a17b0e1c866fc181)
26ba25
Signed-off-by: Paul Lai <plai@redhat.com>
26ba25
26ba25
Resovled Conflicts:
26ba25
	include/exec/ram_addr.h
26ba25
	memory.c
26ba25
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 backends/hostmem-file.c |  3 ++-
26ba25
 exec.c                  | 10 +++++-----
26ba25
 include/exec/memory.h   |  7 +++++--
26ba25
 include/exec/ram_addr.h | 25 +++++++++++++++++++++++--
26ba25
 memory.c                |  8 +++++---
26ba25
 numa.c                  |  2 +-
26ba25
 6 files changed, 41 insertions(+), 14 deletions(-)
26ba25
26ba25
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
26ba25
index 134b08d..34c68bb 100644
26ba25
--- a/backends/hostmem-file.c
26ba25
+++ b/backends/hostmem-file.c
26ba25
@@ -58,7 +58,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
26ba25
         path = object_get_canonical_path(OBJECT(backend));
26ba25
         memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
26ba25
                                  path,
26ba25
-                                 backend->size, fb->align, backend->share,
26ba25
+                                 backend->size, fb->align,
26ba25
+                                 backend->share ? RAM_SHARED : 0,
26ba25
                                  fb->mem_path, errp);
26ba25
         g_free(path);
26ba25
     }
26ba25
diff --git a/exec.c b/exec.c
26ba25
index b66377c..8d58e8f 100644
26ba25
--- a/exec.c
26ba25
+++ b/exec.c
26ba25
@@ -2042,7 +2042,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
26ba25
 
26ba25
 #ifdef __linux__
26ba25
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
26ba25
-                                 bool share, int fd,
26ba25
+                                 uint32_t ram_flags, int fd,
26ba25
                                  Error **errp)
26ba25
 {
26ba25
     RAMBlock *new_block;
26ba25
@@ -2084,14 +2084,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
26ba25
     new_block->mr = mr;
26ba25
     new_block->used_length = size;
26ba25
     new_block->max_length = size;
26ba25
-    new_block->flags = share ? RAM_SHARED : 0;
26ba25
+    new_block->flags = ram_flags;
26ba25
     new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
26ba25
     if (!new_block->host) {
26ba25
         g_free(new_block);
26ba25
         return NULL;
26ba25
     }
26ba25
 
26ba25
-    ram_block_add(new_block, &local_err, share);
26ba25
+    ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED);
26ba25
     if (local_err) {
26ba25
         g_free(new_block);
26ba25
         error_propagate(errp, local_err);
26ba25
@@ -2103,7 +2103,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
26ba25
 
26ba25
 
26ba25
 RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
26ba25
-                                   bool share, const char *mem_path,
26ba25
+                                   uint32_t ram_flags, const char *mem_path,
26ba25
                                    Error **errp)
26ba25
 {
26ba25
     int fd;
26ba25
@@ -2115,7 +2115,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
26ba25
         return NULL;
26ba25
     }
26ba25
 
26ba25
-    block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
26ba25
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
26ba25
     if (!block) {
26ba25
         if (created) {
26ba25
             unlink(mem_path);
26ba25
diff --git a/include/exec/memory.h b/include/exec/memory.h
26ba25
index db46501..b3abe61 100644
26ba25
--- a/include/exec/memory.h
26ba25
+++ b/include/exec/memory.h
26ba25
@@ -527,6 +527,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
26ba25
                                                        void *host),
26ba25
                                        Error **errp);
26ba25
 #ifdef __linux__
26ba25
+
26ba25
 /**
26ba25
  * memory_region_init_ram_from_file:  Initialize RAM memory region with a
26ba25
  *                                    mmap-ed backend.
26ba25
@@ -538,7 +539,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
26ba25
  * @size: size of the region.
26ba25
  * @align: alignment of the region base address; if 0, the default alignment
26ba25
  *         (getpagesize()) will be used.
26ba25
- * @share: %true if memory must be mmaped with the MAP_SHARED flag
26ba25
+ * @ram_flags: Memory region features:
26ba25
+ *             - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag
26ba25
+ *             Other bits are ignored now.
26ba25
  * @path: the path in which to allocate the RAM.
26ba25
  * @errp: pointer to Error*, to store an error if it happens.
26ba25
  *
26ba25
@@ -550,7 +553,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
26ba25
                                       const char *name,
26ba25
                                       uint64_t size,
26ba25
                                       uint64_t align,
26ba25
-                                      bool share,
26ba25
+                                      uint32_t ram_flags,
26ba25
                                       const char *path,
26ba25
                                       Error **errp);
26ba25
 
26ba25
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
26ba25
index cf2446a..67e163e 100644
26ba25
--- a/include/exec/ram_addr.h
26ba25
+++ b/include/exec/ram_addr.h
26ba25
@@ -72,12 +72,33 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
26ba25
 
26ba25
 long qemu_getrampagesize(void);
26ba25
 unsigned long last_ram_page(void);
26ba25
+
26ba25
+/**
26ba25
+ * qemu_ram_alloc_from_file,
26ba25
+ * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
26ba25
+ *                          file or device
26ba25
+ *
26ba25
+ * Parameters:
26ba25
+ *  @size: the size in bytes of the ram block
26ba25
+ *  @mr: the memory region where the ram block is
26ba25
+ *  @ram_flags: specify the properties of the ram block, which can be one
26ba25
+ *              or bit-or of following values
26ba25
+ *              - RAM_SHARED: mmap the backing file or device with MAP_SHARED
26ba25
+ *              Other bits are ignored.
26ba25
+ *  @mem_path or @fd: specify the backing file or device
26ba25
+ *  @errp: pointer to Error*, to store an error if it happens
26ba25
+ *
26ba25
+ * Return:
26ba25
+ *  On success, return a pointer to the ram block.
26ba25
+ *  On failure, return NULL.
26ba25
+ */
26ba25
 RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
26ba25
-                                   bool share, const char *mem_path,
26ba25
+                                   uint32_t ram_flags, const char *mem_path,
26ba25
                                    Error **errp);
26ba25
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
26ba25
-                                 bool share, int fd,
26ba25
+                                 uint32_t ram_flags, int fd,
26ba25
                                  Error **errp);
26ba25
+
26ba25
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
26ba25
                                   MemoryRegion *mr, Error **errp);
26ba25
 RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr,
26ba25
diff --git a/memory.c b/memory.c
26ba25
index 1a99b9c..4974f97 100644
26ba25
--- a/memory.c
26ba25
+++ b/memory.c
26ba25
@@ -1564,7 +1564,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
26ba25
                                       const char *name,
26ba25
                                       uint64_t size,
26ba25
                                       uint64_t align,
26ba25
-                                      bool share,
26ba25
+                                      uint32_t ram_flags,
26ba25
                                       const char *path,
26ba25
                                       Error **errp)
26ba25
 {
26ba25
@@ -1574,7 +1574,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
26ba25
     mr->terminates = true;
26ba25
     mr->destructor = memory_region_destructor_ram;
26ba25
     mr->align = align;
26ba25
-    mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, &err;;
26ba25
+    mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, &err;;
26ba25
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
26ba25
     if (err) {
26ba25
         mr->size = int128_zero();
26ba25
@@ -1596,7 +1596,9 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
26ba25
     mr->ram = true;
26ba25
     mr->terminates = true;
26ba25
     mr->destructor = memory_region_destructor_ram;
26ba25
-    mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, &err;;
26ba25
+    mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
26ba25
+                                           share ? RAM_SHARED : 0,
26ba25
+                                           fd, &err;;
26ba25
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
26ba25
     if (err) {
26ba25
         mr->size = int128_zero();
26ba25
diff --git a/numa.c b/numa.c
26ba25
index a767a9d..6ea8a86 100644
26ba25
--- a/numa.c
26ba25
+++ b/numa.c
26ba25
@@ -456,7 +456,7 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
26ba25
     if (mem_path) {
26ba25
 #ifdef __linux__
26ba25
         Error *err = NULL;
26ba25
-        memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, false,
26ba25
+        memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0,
26ba25
                                          mem_path, &err;;
26ba25
         if (err) {
26ba25
             error_report_err(err);
26ba25
-- 
26ba25
1.8.3.1
26ba25