|
|
357786 |
From 754dd8f2bfcfd5c98710e910f6343b32af7cd3af Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: "plai@redhat.com" <plai@redhat.com>
|
|
|
357786 |
Date: Fri, 31 Aug 2018 16:25:54 +0200
|
|
|
357786 |
Subject: [PATCH 12/29] memory, exec: switch file ram allocation functions to
|
|
|
357786 |
'flags' parameters
|
|
|
357786 |
|
|
|
357786 |
RH-Author: plai@redhat.com
|
|
|
357786 |
Message-id: <1535732759-22481-5-git-send-email-plai@redhat.com>
|
|
|
357786 |
Patchwork-id: 82005
|
|
|
357786 |
O-Subject: [RHEL7.6 PATCH BZ 1539280 4/9] memory, exec: switch file ram allocation functions to 'flags' parameters
|
|
|
357786 |
Bugzilla: 1539280
|
|
|
357786 |
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
|
|
|
357786 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
From: Junyan He <junyan.he@intel.com>
|
|
|
357786 |
|
|
|
357786 |
As more flag parameters besides the existing 'share' are going to be
|
|
|
357786 |
added to following functions
|
|
|
357786 |
memory_region_init_ram_from_file
|
|
|
357786 |
qemu_ram_alloc_from_fd
|
|
|
357786 |
qemu_ram_alloc_from_file
|
|
|
357786 |
let's switch them to use the 'flags' parameters so as to ease future
|
|
|
357786 |
flag additions.
|
|
|
357786 |
|
|
|
357786 |
The existing 'share' flag is converted to the RAM_SHARED bit in ram_flags,
|
|
|
357786 |
and other flag bits are ignored by above functions right now.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Junyan He <junyan.he@intel.com>
|
|
|
357786 |
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
|
|
|
357786 |
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
357786 |
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
|
|
|
357786 |
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
357786 |
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
|
|
|
357786 |
(cherry picked from commit cbfc01710362f3de6fca3010a17b0e1c866fc181)
|
|
|
357786 |
Signed-off-by: Paul Lai <plai@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
Resolved Conflicts:
|
|
|
357786 |
include/exec/ram_addr.h
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
backends/hostmem-file.c | 3 ++-
|
|
|
357786 |
exec.c | 10 +++++-----
|
|
|
357786 |
include/exec/memory.h | 7 +++++--
|
|
|
357786 |
include/exec/ram_addr.h | 25 +++++++++++++++++++++++--
|
|
|
357786 |
memory.c | 8 +++++---
|
|
|
357786 |
numa.c | 2 +-
|
|
|
357786 |
6 files changed, 41 insertions(+), 14 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
|
|
|
357786 |
index 134b08d..34c68bb 100644
|
|
|
357786 |
--- a/backends/hostmem-file.c
|
|
|
357786 |
+++ b/backends/hostmem-file.c
|
|
|
357786 |
@@ -58,7 +58,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
|
|
|
357786 |
path = object_get_canonical_path(OBJECT(backend));
|
|
|
357786 |
memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
|
|
|
357786 |
path,
|
|
|
357786 |
- backend->size, fb->align, backend->share,
|
|
|
357786 |
+ backend->size, fb->align,
|
|
|
357786 |
+ backend->share ? RAM_SHARED : 0,
|
|
|
357786 |
fb->mem_path, errp);
|
|
|
357786 |
g_free(path);
|
|
|
357786 |
}
|
|
|
357786 |
diff --git a/exec.c b/exec.c
|
|
|
357786 |
index f21be9c..295142b 100644
|
|
|
357786 |
--- a/exec.c
|
|
|
357786 |
+++ b/exec.c
|
|
|
357786 |
@@ -2038,7 +2038,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
|
|
|
357786 |
|
|
|
357786 |
#ifdef __linux__
|
|
|
357786 |
RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
- bool share, int fd,
|
|
|
357786 |
+ uint32_t ram_flags, int fd,
|
|
|
357786 |
Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
RAMBlock *new_block;
|
|
|
357786 |
@@ -2080,14 +2080,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
new_block->mr = mr;
|
|
|
357786 |
new_block->used_length = size;
|
|
|
357786 |
new_block->max_length = size;
|
|
|
357786 |
- new_block->flags = share ? RAM_SHARED : 0;
|
|
|
357786 |
+ new_block->flags = ram_flags;
|
|
|
357786 |
new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
|
|
|
357786 |
if (!new_block->host) {
|
|
|
357786 |
g_free(new_block);
|
|
|
357786 |
return NULL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- ram_block_add(new_block, &local_err, share);
|
|
|
357786 |
+ ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED);
|
|
|
357786 |
if (local_err) {
|
|
|
357786 |
g_free(new_block);
|
|
|
357786 |
error_propagate(errp, local_err);
|
|
|
357786 |
@@ -2099,7 +2099,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
|
|
|
357786 |
|
|
|
357786 |
RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
- bool share, const char *mem_path,
|
|
|
357786 |
+ uint32_t ram_flags, const char *mem_path,
|
|
|
357786 |
Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
int fd;
|
|
|
357786 |
@@ -2111,7 +2111,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
return NULL;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
|
|
|
357786 |
+ block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
|
|
|
357786 |
if (!block) {
|
|
|
357786 |
if (created) {
|
|
|
357786 |
unlink(mem_path);
|
|
|
357786 |
diff --git a/include/exec/memory.h b/include/exec/memory.h
|
|
|
357786 |
index db46501..b3abe61 100644
|
|
|
357786 |
--- a/include/exec/memory.h
|
|
|
357786 |
+++ b/include/exec/memory.h
|
|
|
357786 |
@@ -527,6 +527,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
|
|
|
357786 |
void *host),
|
|
|
357786 |
Error **errp);
|
|
|
357786 |
#ifdef __linux__
|
|
|
357786 |
+
|
|
|
357786 |
/**
|
|
|
357786 |
* memory_region_init_ram_from_file: Initialize RAM memory region with a
|
|
|
357786 |
* mmap-ed backend.
|
|
|
357786 |
@@ -538,7 +539,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
|
|
|
357786 |
* @size: size of the region.
|
|
|
357786 |
* @align: alignment of the region base address; if 0, the default alignment
|
|
|
357786 |
* (getpagesize()) will be used.
|
|
|
357786 |
- * @share: %true if memory must be mmaped with the MAP_SHARED flag
|
|
|
357786 |
+ * @ram_flags: Memory region features:
|
|
|
357786 |
+ * - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag
|
|
|
357786 |
+ * Other bits are ignored now.
|
|
|
357786 |
* @path: the path in which to allocate the RAM.
|
|
|
357786 |
* @errp: pointer to Error*, to store an error if it happens.
|
|
|
357786 |
*
|
|
|
357786 |
@@ -550,7 +553,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
|
|
|
357786 |
const char *name,
|
|
|
357786 |
uint64_t size,
|
|
|
357786 |
uint64_t align,
|
|
|
357786 |
- bool share,
|
|
|
357786 |
+ uint32_t ram_flags,
|
|
|
357786 |
const char *path,
|
|
|
357786 |
Error **errp);
|
|
|
357786 |
|
|
|
357786 |
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
|
|
|
357786 |
index cf2446a..67e163e 100644
|
|
|
357786 |
--- a/include/exec/ram_addr.h
|
|
|
357786 |
+++ b/include/exec/ram_addr.h
|
|
|
357786 |
@@ -72,12 +72,33 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
|
|
|
357786 |
|
|
|
357786 |
long qemu_getrampagesize(void);
|
|
|
357786 |
unsigned long last_ram_page(void);
|
|
|
357786 |
+
|
|
|
357786 |
+/**
|
|
|
357786 |
+ * qemu_ram_alloc_from_file,
|
|
|
357786 |
+ * qemu_ram_alloc_from_fd: Allocate a ram block from the specified backing
|
|
|
357786 |
+ * file or device
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * Parameters:
|
|
|
357786 |
+ * @size: the size in bytes of the ram block
|
|
|
357786 |
+ * @mr: the memory region where the ram block is
|
|
|
357786 |
+ * @ram_flags: specify the properties of the ram block, which can be one
|
|
|
357786 |
+ * or bit-or of following values
|
|
|
357786 |
+ * - RAM_SHARED: mmap the backing file or device with MAP_SHARED
|
|
|
357786 |
+ * Other bits are ignored.
|
|
|
357786 |
+ * @mem_path or @fd: specify the backing file or device
|
|
|
357786 |
+ * @errp: pointer to Error*, to store an error if it happens
|
|
|
357786 |
+ *
|
|
|
357786 |
+ * Return:
|
|
|
357786 |
+ * On success, return a pointer to the ram block.
|
|
|
357786 |
+ * On failure, return NULL.
|
|
|
357786 |
+ */
|
|
|
357786 |
RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
- bool share, const char *mem_path,
|
|
|
357786 |
+ uint32_t ram_flags, const char *mem_path,
|
|
|
357786 |
Error **errp);
|
|
|
357786 |
RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
|
|
|
357786 |
- bool share, int fd,
|
|
|
357786 |
+ uint32_t ram_flags, int fd,
|
|
|
357786 |
Error **errp);
|
|
|
357786 |
+
|
|
|
357786 |
RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
|
|
|
357786 |
MemoryRegion *mr, Error **errp);
|
|
|
357786 |
RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr,
|
|
|
357786 |
diff --git a/memory.c b/memory.c
|
|
|
357786 |
index e70b64b..7b47f53 100644
|
|
|
357786 |
--- a/memory.c
|
|
|
357786 |
+++ b/memory.c
|
|
|
357786 |
@@ -1552,7 +1552,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
|
|
|
357786 |
const char *name,
|
|
|
357786 |
uint64_t size,
|
|
|
357786 |
uint64_t align,
|
|
|
357786 |
- bool share,
|
|
|
357786 |
+ uint32_t ram_flags,
|
|
|
357786 |
const char *path,
|
|
|
357786 |
Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
@@ -1561,7 +1561,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
|
|
|
357786 |
mr->terminates = true;
|
|
|
357786 |
mr->destructor = memory_region_destructor_ram;
|
|
|
357786 |
mr->align = align;
|
|
|
357786 |
- mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp);
|
|
|
357786 |
+ mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, errp);
|
|
|
357786 |
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -1577,7 +1577,9 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
|
|
|
357786 |
mr->ram = true;
|
|
|
357786 |
mr->terminates = true;
|
|
|
357786 |
mr->destructor = memory_region_destructor_ram;
|
|
|
357786 |
- mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
|
|
|
357786 |
+ mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
|
|
|
357786 |
+ share ? RAM_SHARED : 0,
|
|
|
357786 |
+ fd, errp);
|
|
|
357786 |
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
|
|
|
357786 |
}
|
|
|
357786 |
#endif
|
|
|
357786 |
diff --git a/numa.c b/numa.c
|
|
|
357786 |
index bb8f773..e78fba5 100644
|
|
|
357786 |
--- a/numa.c
|
|
|
357786 |
+++ b/numa.c
|
|
|
357786 |
@@ -456,7 +456,7 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
|
|
|
357786 |
if (mem_path) {
|
|
|
357786 |
#ifdef __linux__
|
|
|
357786 |
Error *err = NULL;
|
|
|
357786 |
- memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, false,
|
|
|
357786 |
+ memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0,
|
|
|
357786 |
mem_path, &err;;
|
|
|
357786 |
if (err) {
|
|
|
357786 |
error_report_err(err);
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|