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