[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v3 18/27] multi-process: setup memory manager for remote device
From: |
Stefan Hajnoczi |
Subject: |
[PULL v3 18/27] multi-process: setup memory manager for remote device |
Date: |
Fri, 5 Feb 2021 16:44:50 +0000 |
From: Jagannathan Raman <jag.raman@oracle.com>
SyncSysMemMsg message format is defined. It is used to send
file descriptors of the RAM regions to remote device.
RAM on the remote device is configured with a set of file descriptors.
Old RAM regions are deleted and new regions, each with an fd, is
added to the RAM.
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-id:
7d2d1831d812e85f681e7a8ab99e032cf4704689.1611938319.git.jag.raman@oracle.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
MAINTAINERS | 2 +
include/hw/remote/memory.h | 19 ++++++++++
include/hw/remote/mpqemu-link.h | 10 +++++
hw/remote/memory.c | 65 +++++++++++++++++++++++++++++++++
hw/remote/mpqemu-link.c | 11 ++++++
hw/remote/meson.build | 2 +
6 files changed, 109 insertions(+)
create mode 100644 include/hw/remote/memory.h
create mode 100644 hw/remote/memory.c
diff --git a/MAINTAINERS b/MAINTAINERS
index e37fc4b226..88732e51a2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3209,6 +3209,8 @@ F: hw/remote/mpqemu-link.c
F: include/hw/remote/mpqemu-link.h
F: hw/remote/message.c
F: hw/remote/remote-obj.c
+F: include/hw/remote/memory.h
+F: hw/remote/memory.c
Build and test automation
-------------------------
diff --git a/include/hw/remote/memory.h b/include/hw/remote/memory.h
new file mode 100644
index 0000000000..bc2e30945f
--- /dev/null
+++ b/include/hw/remote/memory.h
@@ -0,0 +1,19 @@
+/*
+ * Memory manager for remote device
+ *
+ * Copyright © 2018, 2021 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_MEMORY_H
+#define REMOTE_MEMORY_H
+
+#include "exec/hwaddr.h"
+#include "hw/remote/mpqemu-link.h"
+
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp);
+
+#endif
diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h
index cac699cb42..6ee5bc5751 100644
--- a/include/hw/remote/mpqemu-link.h
+++ b/include/hw/remote/mpqemu-link.h
@@ -14,6 +14,7 @@
#include "qom/object.h"
#include "qemu/thread.h"
#include "io/channel.h"
+#include "exec/hwaddr.h"
#define REMOTE_MAX_FDS 8
@@ -30,9 +31,16 @@
*
*/
typedef enum {
+ MPQEMU_CMD_SYNC_SYSMEM,
MPQEMU_CMD_MAX,
} MPQemuCmd;
+typedef struct {
+ hwaddr gpas[REMOTE_MAX_FDS];
+ uint64_t sizes[REMOTE_MAX_FDS];
+ off_t offsets[REMOTE_MAX_FDS];
+} SyncSysmemMsg;
+
/**
* MPQemuMsg:
* @cmd: The remote command
@@ -43,12 +51,14 @@ typedef enum {
* MPQemuMsg Format of the message sent to the remote device from QEMU.
*
*/
+
typedef struct {
int cmd;
size_t size;
union {
uint64_t u64;
+ SyncSysmemMsg sync_sysmem;
} data;
int fds[REMOTE_MAX_FDS];
diff --git a/hw/remote/memory.c b/hw/remote/memory.c
new file mode 100644
index 0000000000..32085b1e05
--- /dev/null
+++ b/hw/remote/memory.c
@@ -0,0 +1,65 @@
+/*
+ * Memory manager for remote device
+ *
+ * Copyright © 2018, 2021 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "hw/remote/memory.h"
+#include "exec/address-spaces.h"
+#include "exec/ram_addr.h"
+#include "qapi/error.h"
+
+static void remote_sysmem_reset(void)
+{
+ MemoryRegion *sysmem, *subregion, *next;
+
+ sysmem = get_system_memory();
+
+ QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next)
{
+ if (subregion->ram) {
+ memory_region_del_subregion(sysmem, subregion);
+ object_unparent(OBJECT(subregion));
+ }
+ }
+}
+
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
+{
+ ERRP_GUARD();
+ SyncSysmemMsg *sysmem_info = &msg->data.sync_sysmem;
+ MemoryRegion *sysmem, *subregion;
+ static unsigned int suffix;
+ int region;
+
+ sysmem = get_system_memory();
+
+ remote_sysmem_reset();
+
+ for (region = 0; region < msg->num_fds; region++) {
+ g_autofree char *name;
+ subregion = g_new(MemoryRegion, 1);
+ name = g_strdup_printf("remote-mem-%u", suffix++);
+ memory_region_init_ram_from_fd(subregion, NULL,
+ name, sysmem_info->sizes[region],
+ true, msg->fds[region],
+ sysmem_info->offsets[region],
+ errp);
+
+ if (*errp) {
+ g_free(subregion);
+ remote_sysmem_reset();
+ return;
+ }
+
+ memory_region_add_subregion(sysmem, sysmem_info->gpas[region],
+ subregion);
+
+ }
+}
diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c
index 0d1899fd94..4ee1128285 100644
--- a/hw/remote/mpqemu-link.c
+++ b/hw/remote/mpqemu-link.c
@@ -201,5 +201,16 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
}
}
+ /* Verify message specific fields. */
+ switch (msg->cmd) {
+ case MPQEMU_CMD_SYNC_SYSMEM:
+ if (msg->num_fds == 0 || msg->size != sizeof(SyncSysmemMsg)) {
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+
return true;
}
diff --git a/hw/remote/meson.build b/hw/remote/meson.build
index 71d0a5689e..64da16c1de 100644
--- a/hw/remote/meson.build
+++ b/hw/remote/meson.build
@@ -5,4 +5,6 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true:
files('mpqemu-link.c'))
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c'))
remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c'))
+specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c'))
+
softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss)
--
2.29.2
- [PULL v3 10/27] multi-process: Add config option for multi-process QEMU, (continued)
- [PULL v3 10/27] multi-process: Add config option for multi-process QEMU, Stefan Hajnoczi, 2021/02/05
- [PULL v3 11/27] multi-process: setup PCI host bridge for remote device, Stefan Hajnoczi, 2021/02/05
- [PULL v3 12/27] multi-process: setup a machine object for remote device process, Stefan Hajnoczi, 2021/02/05
- [PULL v3 13/27] io: add qio_channel_writev_full_all helper, Stefan Hajnoczi, 2021/02/05
- [PULL v3 14/27] io: add qio_channel_readv_full_all_eof & qio_channel_readv_full_all helpers, Stefan Hajnoczi, 2021/02/05
- [PULL v3 15/27] multi-process: define MPQemuMsg format and transmission functions, Stefan Hajnoczi, 2021/02/05
- [PULL v3 17/27] multi-process: Associate fd of a PCIDevice with its object, Stefan Hajnoczi, 2021/02/05
- [PULL v3 16/27] multi-process: Initialize message handler in remote device, Stefan Hajnoczi, 2021/02/05
- [PULL v3 18/27] multi-process: setup memory manager for remote device,
Stefan Hajnoczi <=
- [PULL v3 19/27] multi-process: introduce proxy object, Stefan Hajnoczi, 2021/02/05
- [PULL v3 20/27] multi-process: add proxy communication functions, Stefan Hajnoczi, 2021/02/05
- [PULL v3 21/27] multi-process: Forward PCI config space acceses to the remote process, Stefan Hajnoczi, 2021/02/05
- [PULL v3 22/27] multi-process: PCI BAR read/write handling for proxy & remote endpoints, Stefan Hajnoczi, 2021/02/05
- [PULL v3 23/27] multi-process: Synchronize remote memory, Stefan Hajnoczi, 2021/02/05
- [PULL v3 24/27] multi-process: create IOHUB object to handle irq, Stefan Hajnoczi, 2021/02/05
- [PULL v3 25/27] multi-process: Retrieve PCI info from remote process, Stefan Hajnoczi, 2021/02/05
- [PULL v3 26/27] multi-process: perform device reset in the remote process, Stefan Hajnoczi, 2021/02/05
- [PULL v3 27/27] docs: fix Parallels Image "dirty bitmap" section, Stefan Hajnoczi, 2021/02/05
- Re: [PULL v3 00/27] Block patches, Peter Maydell, 2021/02/05