Skip to contentSkip to conversation

Initial support for multi-process qemu

PATCH RESEND Superseded [email protected] 12 participants 94 messages Apr 23, 2020 – May 14, 2020

Subsystems (3)

v6 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#14 lore raw

PATCH RESEND v6 4/36 multi-process: Refactor chardev functions out of vl.c

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Some of the initialization helper functions w.r.t chardev
in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.

---
 chardev/char.c         | 14 ++++++++++++++
 include/chardev/char.h |  2 ++
 softmmu/vl.c           | 14 --------------
 3 files changed, 16 insertions(+), 14 deletions(-)
chardev/char.c +14 -0
index e77564060d..47dcf93da7 100644
@@ -1196,3 +1196,17 @@ static void register_types(void)
 }
 
 type_init(register_types);
+
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
include/chardev/char.h +2 -0
index 00589a6025..0804e78f7a 100644
@@ -290,4 +290,6 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
 /* console.c */
 void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
+
 #endif
softmmu/vl.c +0 -14
index d1b32a33a2..6e35f3787d 100644
@@ -2038,20 +2038,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
     return qdev_device_help(opts);
 }
 
-static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return -1;
-        }
-        exit(0);
-    }
-    return 0;
-}
-
 #ifdef CONFIG_VIRTFS
 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
Signature · 1 line
2.25.GIT
#12 lore raw

PATCH RESEND v6 3/36 command-line: refractor parser code

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Refactor command-line parser code so that it could be used by other processes as well.

---
 MAINTAINERS          |  2 +
 Makefile.objs        |  2 +
 include/qemu-parse.h | 42 ++++++++++++++++++++
 qemu-parse.c         | 93 ++++++++++++++++++++++++++++++++++++++++++++
 softmmu/vl.c         | 84 +--------------------------------------
 5 files changed, 140 insertions(+), 83 deletions(-)
 create mode 100644 include/qemu-parse.h
 create mode 100644 qemu-parse.c
MAINTAINERS +2 -0
index 04b19ac56c..2e700e6e64 100644
@@ -2032,6 +2032,8 @@ F: tests/test-keyval.c
 F: tests/test-qemu-opts.c
 F: util/keyval.c
 F: util/qemu-option.c
+F: include/qemu-parse.h
+F: qemu-parse.c
 
 Coverity model
 M: Markus Armbruster <[email protected]>
Makefile.objs +2 -0
index bfb9271862..f29c60c59d 100644
@@ -78,6 +78,8 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 
 common-obj-$(CONFIG_FDT) += device_tree.o
 
+common-obj-y += qemu-parse.o
+
 common-obj-y += qapi/
 common-obj-y += util/machine-notify.o
 
include/qemu-parse.h new file +42 -0

42 lines not on this page · raw message

qemu-parse.c new file +93 -0

93 lines not on this page · raw message

softmmu/vl.c +1 -83

114 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#1 lore raw

PATCH RESEND v6 1/36 memory: alloc RAM from file at offset

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

---
 exec.c                    | 11 +++++++----
 include/exec/ram_addr.h   |  2 +-
 include/qemu/mmap-alloc.h |  3 ++-
 memory.c                  |  2 +-
 util/mmap-alloc.c         |  7 ++++---
 util/oslib-posix.c        |  2 +-
 6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index 2874bb5088..d0ac9545f4 100644
@@ -1801,6 +1801,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     void *area;
@@ -1851,7 +1852,8 @@ static void *file_ram_alloc(RAMBlock *block,
     }
 
     area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
     if (area == MAP_FAILED) {
         error_setg_errno(errp, errno,
                          "unable to map backing store for guest RAM");
@@ -2283,7 +2285,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 #ifdef CONFIG_POSIX
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
@@ -2328,7 +2330,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
     new_block->used_length = size;
     new_block->max_length = size;
     new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
     if (!new_block->host) {
         g_free(new_block);
         return NULL;
@@ -2358,7 +2361,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
     if (!block) {
         if (created) {
             unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d8d7..1b9f489ff0 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                    Error **errp);
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266b92..4f579858bc 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index 601b749906..f5fec476b7 100644
@@ -1596,7 +1596,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
     mr->destructor = memory_region_destructor_ram;
     mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                            share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
     if (err) {
         mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd8ec..a28f7025f0 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
 {
     int flags;
     int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
     offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
     ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
     if (ptr == MAP_FAILED && map_sync_flags) {
         if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
          * we will remove these flags to handle compatibility.
          */
         ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
     }
 
     if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 062236a1ab..4c6b9e90c6 100644
@@ -209,7 +209,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
 {
     size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
     if (ptr == MAP_FAILED) {
         return NULL;
Signature · 1 line
2.25.GIT
#0 lore raw

v6 cover Initial support for multi-process qemu

From: Elena Ufimtseva <[email protected]>

Hello

This is a resend of v6 patchset since we regrettably omitted few comments from v5 review in the previously sent series
(see in https://lists.gnu.org/archive/html/qemu-devel/2020-04/msg00828.html).
We also run more tests and fixed the build errors that were found in v6.

Started with the presentation in October 2017 made by Marc-Andre (Red Hat) and Konrad Wilk (Oracle) [1], and continued by Jag's BoF at KVM Forum 2018, the multi-process project is now available and presented in this patchset. This first series enables the emulation of lsi53c895a in a separate process.

We posted the Proof Of Concept patches [2] before the BoF session in 2018. Subsequently, we posted RFC v1 [3], RFC v2 [4], RFC v3 [5], RFC v4 [6] and v5 [7] of the patch series.

This is v6 of the patch series and it addresses the previous feedback from the community.
To make easier to review of the series, we have separated out some of the patches and will send them in the separate series. As per conversation we had during the last community call, the live migration support is taken out from this series as well as asynchronous communication.
The changes include the elimination of fork/exec of the remote process and instead using the orchestrator which is implemented in this series as a python script.

Following people contributed to this patchset:

John G Johnson <[email protected]>
Jagannathan Raman <[email protected]>
Elena Ufimtseva <[email protected]>
Kanth Ghatraju <[email protected]>
Konrad Wilk <[email protected]>

For full concept writeup about QEMU disaggregation, refer to docs/devel/qemu-multiprocess.rst. Please refer to docs/qemu-multiprocess.txt for usage information.

We will post separate patchsets for the following improvements for the experimental Qemu multi-process:
- Live migration;
- Asynchronous communication channel;
- Libvirt support;

We welcome all your ideas, concerns, and questions for this patchset.

Testing results

There is an error in travis-ci build test which does not get reproduced.

TEST iotest-qcow2: 041 [fail]

QEMU          -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64" -nodefaults -display none -accel qtest
QEMU_IMG      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-img" 
QEMU_IO       -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-io"  --cache writeback --aio threads -f qcow2
QEMU_NBD      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-nbd" 
IMGFMT        -- qcow2 (compat=1.1)
IMGPROTO      -- file
PLATFORM      -- Linux/x86_64 travis-job-fc4e2553-b470-4a8b-812e-a4fcf8ba094f 5.0.0-1031-gcp
TEST_DIR      -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch
SOCK_DIR      -- /tmp/tmp.LOmYANt5Od

SOCKET_SCM_HELPER -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/socket_scm_helper

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +12 -1
@@ -1,5 +1,29 @@
-..............................................................................................
+........................FF....................................................................
+======================================================================
+FAIL: test_with_other_parent (__main__.TestRepairQuorum)
+----------------------------------------------------------------------
+Traceback (most recent call last):
+  File "041", line 1049, in test_with_other_parent
+    self.assert_qmp(result, 'return', {})
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 821, in assert_qmp
+    result = self.dictpath(d, path)
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 797, in dictpath
+    self.fail('failed path traversal for "%s" in "%s"' % (path, str(d)))
+AssertionError: failed path traversal for "return" in "{'error': {'class': 'GenericError', 'desc': "UNIX socket path '/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch/nbd.sock' is too long"}}"

a
+
Not run: 220 259
Failures: 041
Failed 1 of 116 iotests
/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/Makefile.include:848: recipe for target 'check-tests/check-block.sh' failed
make: *** [check-tests/check-block.sh] Error 1
The command "if [ "$BUILD_RC" -eq 0 ] ; then

    ${TEST_CMD} ;
else
    $(exit $BUILD_RC);

fi

Thank you!

[1]: http://events17.linuxfoundation.org/sites/events/files/slides/KVM%20FORUM%20multi-process.pdf
[1]: https://www.youtube.com/watch?v=Kq1-coHh7lg
[2]: https://www.mail-archive.com/[email protected]/msg566538.html
[3]: https://www.mail-archive.com/[email protected]/msg602285.html
[4]: https://www.mail-archive.com/[email protected]/msg624877.html
[5]: https://www.mail-archive.com/[email protected]/msg642000.html
[6]: https://www.mail-archive.com/[email protected]/msg655118.html
[7]: https://www.mail-archive.com/[email protected]/msg682429.html

--
2.25.GIT

Elena Ufimtseva (18):
multi-process: Refactor machine_init and exit notifiers
command-line: refractor parser code
multi-process: Refactor chardev functions out of vl.c
multi-process: Refactor monitor functions out of vl.c
multi-process: add a command line option for debug file
multi-process: introduce proxy object
multi-process: Forward PCI config space acceses to the remote process
multi-process: Introduce build flags to separate remote process code
multi-process: add parse_cmdline in remote process
multi-process: add support to parse device option
multi-process: send heartbeat messages to remote
multi-process: handle heartbeat messages in remote process
multi-process: perform device reset in the remote process multi-process/mon: choose HMP commands based on target multi-process/mon: stub functions to enable QMP module for remote
process
multi-process/mon: enable QMP module support in the remote process multi-process/mon: Initialize QMP module for remote processes
multi-process: add configure and usage information

Jagannathan Raman (17):
memory: alloc RAM from file at offset
monitor: destaticize HMP commands
multi-process: Add stub functions to facilitate build of multi-process
multi-process: Add config option for multi-process QEMU
multi-process: build system for remote device process
multi-process: define mpqemu-link object
multi-process: add functions to synchronize proxy and remote endpoints
multi-process: setup PCI host bridge for remote device
multi-process: setup a machine object for remote device process
multi-process: setup memory manager for remote device
multi-process: remote process initialization
multi-process: Initialize Proxy Object's communication channel
multi-process: Connect Proxy Object with device in the remote process
multi-process: PCI BAR read/write handling for proxy & remote
endpoints
multi-process: Synchronize remote memory
multi-process: create IOHUB object to handle irq
multi-process: Retrieve PCI info from remote process

John G Johnson (1):
multi-process: add the concept description to
docs/devel/qemu-multiprocess

 MAINTAINERS                          |  39 ++
 Makefile                             |   2 +
 Makefile.objs                        |  41 ++
 Makefile.target                      | 104 ++-
 accel/Makefile.objs                  |   2 +
 accel/stubs/kvm-stub.c               |   5 +
 accel/stubs/tcg-stub.c               | 108 +++
 backends/Makefile.objs               |   2 +
 block/Makefile.objs                  |   5 +
 block/monitor/Makefile.objs          |   2 +
 chardev/char.c                       |  14 +
 configure                            |  15 +
 docs/devel/index.rst                 |   1 +
 docs/devel/multi-process.rst         | 957 +++++++++++++++++++++++++++
 docs/multi-process.rst               |  85 +++
 exec.c                               |  31 +-
 hmp-commands-info.hx                 |  10 +
 hmp-commands.hx                      |  25 +-
 hw/Makefile.objs                     |   7 +
 hw/block/Makefile.objs               |   2 +
 hw/core/Makefile.objs                |  19 +
 hw/nvram/Makefile.objs               |   2 +
 hw/pci/Makefile.objs                 |   4 +
 hw/proxy/memory-sync.c               | 217 ++++++
 hw/proxy/qemu-proxy.c                | 488 ++++++++++++++
 hw/scsi/Makefile.objs                |   2 +
 include/chardev/char.h               |   2 +
 include/exec/address-spaces.h        |   2 +
 include/exec/ram_addr.h              |   4 +-
 include/hw/pci/pci_ids.h             |   3 +
 include/hw/proxy/memory-sync.h       |  37 ++
 include/hw/proxy/qemu-proxy.h        |  79 +++
 include/io/mpqemu-link.h             | 192 ++++++
 include/monitor/monitor.h            |   3 +
 include/qemu-common.h                |   8 +
 include/qemu-parse.h                 |  42 ++
 include/qemu/log.h                   |   1 +
 include/qemu/mmap-alloc.h            |   3 +-
 include/remote/iohub.h               |  50 ++
 include/remote/machine.h             |  32 +
 include/remote/memory.h              |  20 +
 include/remote/pcihost.h             |  45 ++
 include/sysemu/sysemu.h              |   2 +
 io/Makefile.objs                     |   2 +
 io/mpqemu-link.c                     | 407 ++++++++++++
 memory.c                             |   2 +-
 migration/Makefile.objs              |   2 +
 monitor/Makefile.objs                |   4 +
 monitor/misc.c                       |  84 +--
 monitor/monitor-internal.h           |  38 ++
 monitor/monitor.c                    |  37 ++
 qapi/Makefile.objs                   |   2 +
 qemu-parse.c                         |  93 +++
 qom/Makefile.objs                    |   4 +
 remote/Makefile.objs                 |   6 +
 remote/iohub.c                       | 148 +++++
 remote/machine.c                     |  99 +++
 remote/memory.c                      |  63 ++
 remote/pcihost.c                     |  64 ++
 remote/remote-common.h               |  21 +
 remote/remote-main.c                 | 379 +++++++++++
 remote/remote-opts.c                 |  96 +++
 remote/remote-opts.h                 |  15 +
 rules.mak                            |   2 +-
 scripts/hxtool                       |  35 +-
 scripts/mpqemu-launcher-perf-mode.py |  92 +++
 scripts/mpqemu-launcher.py           |  53 ++
 softmmu/vl.c                         | 175 +----
 stubs/Makefile.objs                  |   3 +
 stubs/audio.c                        |  12 +
 stubs/gdbstub.c                      |  23 +
 stubs/get-fd.c                       |  10 +
 stubs/machine-init-add.c             |   7 +
 stubs/machine-init-done.c            |   5 +-
 stubs/machine-init-remove.c          |   8 +
 stubs/migration.c                    | 162 +++++
 stubs/monitor.c                      |  85 ++-
 stubs/net-stub.c                     | 100 +++
 stubs/qapi-misc.c                    |  41 ++
 stubs/qapi-target.c                  |  56 ++
 stubs/replay.c                       |  18 +
 stubs/ui-stub.c                      | 130 ++++
 stubs/vl-stub.c                      | 171 +++++
 stubs/vmstate.c                      |  19 +
 stubs/xen-mapcache.c                 |  22 +
 ui/Makefile.objs                     |   2 +
 util/Makefile.objs                   |   2 +
 util/log.c                           |   2 +
 util/machine-notify.c                |  69 ++
 util/mmap-alloc.c                    |   7 +-
 util/oslib-posix.c                   |   2 +-
 91 files changed, 5356 insertions(+), 237 deletions(-)
 create mode 100644 docs/devel/multi-process.rst
 create mode 100644 docs/multi-process.rst
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 hw/proxy/qemu-proxy.c
 create mode 100644 include/hw/proxy/memory-sync.h
 create mode 100644 include/hw/proxy/qemu-proxy.h
 create mode 100644 include/io/mpqemu-link.h
 create mode 100644 include/qemu-parse.h
 create mode 100644 include/remote/iohub.h
 create mode 100644 include/remote/machine.h
 create mode 100644 include/remote/memory.h
 create mode 100644 include/remote/pcihost.h
 create mode 100644 io/mpqemu-link.c
 create mode 100644 qemu-parse.c
 create mode 100644 remote/Makefile.objs
 create mode 100644 remote/iohub.c
 create mode 100644 remote/machine.c
 create mode 100644 remote/memory.c
 create mode 100644 remote/pcihost.c
 create mode 100644 remote/remote-common.h
 create mode 100644 remote/remote-main.c
 create mode 100644 remote/remote-opts.c
 create mode 100644 remote/remote-opts.h
 mode change 100644 => 100755 scripts/hxtool
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
 create mode 100644 stubs/audio.c
 create mode 100644 stubs/get-fd.c
 create mode 100644 stubs/machine-init-add.c
 create mode 100644 stubs/machine-init-remove.c
 create mode 100644 stubs/migration.c
 create mode 100644 stubs/net-stub.c
 create mode 100644 stubs/qapi-misc.c
 create mode 100644 stubs/qapi-target.c
 create mode 100644 stubs/ui-stub.c
 create mode 100644 stubs/vl-stub.c
 create mode 100644 stubs/xen-mapcache.c
 create mode 100644 util/machine-notify.c
Signature · 1 line
2.25.GIT
#52 lore raw

PATCH RESEND v6 19/36 multi-process: Connect Proxy Object with device in the remote process

From: Jagannathan Raman <[email protected]>

Send a message to the remote process to connect PCI device with the corresponding Proxy object in QEMU

---
 hw/proxy/qemu-proxy.c    | 34 +++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  5 +++++
 io/mpqemu-link.c         |  3 +++
 remote/remote-main.c     | 43 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+)
hw/proxy/qemu-proxy.c +34 -0
index 40bf56fd37..9b5e429a88 100644
@@ -17,11 +17,45 @@
 static void proxy_set_socket(Object *obj, const char *str, Error **errp)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+    DeviceState *dev = DEVICE(obj);
+    MPQemuMsg msg = { 0 };
+    int wait, fd[2];
 
     pdev->socket = atoi(str);
 
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        error_setg(errp, "Failed to create socket for device channel");
+        return;
+    }
+
+    wait = GET_REMOTE_WAIT;
+
+    msg.cmd = CONNECT_DEV;
+    msg.bytestream = 1;
+    msg.data2 = (uint8_t *)g_strdup(dev->id);
+    msg.size = sizeof(msg.data2);
+    msg.num_fds = 2;
+    msg.fds[0] = wait;
+    msg.fds[1] = fd[1];
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    if (wait_for_remote(wait)) {
+        error_setg(errp, "Failed to connect device to the remote");
+        close(fd[0]);
+    } else {
+        mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->dev,
+                            fd[0]);
+    }
+
+    PUT_REMOTE_WAIT(wait);
+
+    close(fd[1]);
+
+    g_free(msg.data2);
 }
 
 static void proxy_init(Object *obj)
include/io/mpqemu-link.h +5 -0
index 73cc59b874..ebae9afc45 100644
@@ -38,6 +38,7 @@
 typedef enum {
     INIT = 0,
     SYNC_SYSMEM,
+    CONNECT_DEV,
     MAX,
 } mpqemu_cmd_t;
 
@@ -120,8 +121,12 @@ struct MPQemuLinkState {
     GMainLoop *loop;
 
     MPQemuChannel *com;
+    MPQemuChannel *dev;
 
     mpqemu_link_callback callback;
+
+    void *opaque;
+    QemuThread thread;
 };
 
 MPQemuLinkState *mpqemu_link_create(void);
io/mpqemu-link.c +3 -0
index 3f81cef96e..f780b65181 100644
@@ -46,6 +46,9 @@ MPQemuLinkState *mpqemu_link_create(void)
     MPQemuLinkState *link = MPQEMU_LINK(object_new(TYPE_MPQEMU_LINK));
 
     link->com = NULL;
+    link->dev = NULL;
+
+    link->opaque = NULL;
 
     return link;
 }
remote/remote-main.c +43 -0

61 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#15 lore raw

PATCH RESEND v6 5/36 multi-process: Refactor monitor functions out of vl.c

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Some of the initialization helper functions w.r.t monitor
in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.

---
 include/monitor/monitor.h |  3 +++
 monitor/monitor.c         | 37 +++++++++++++++++++++++++++++++++++++
 softmmu/vl.c              | 35 -----------------------------------
 3 files changed, 40 insertions(+), 35 deletions(-)
include/monitor/monitor.h +3 -0
index 1018d754a6..3803e904f2 100644
@@ -48,4 +48,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+
 #endif /* MONITOR_H */
monitor/monitor.c +37 -0
index 125494410a..88423b38b6 100644
@@ -35,6 +35,8 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
+#include "qemu/cutils.h"
+#include "qemu/config-file.h"
 
 /*
  * To prevent flooding clients, events can be throttled. The
@@ -611,6 +613,41 @@ void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
 {
     Chardev *chr;
softmmu/vl.c +0 -35
index 6e35f3787d..abc746c1b5 100644
@@ -2045,41 +2045,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 }
 #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
 struct device_config {
     enum {
         DEV_USB,       /* -usbdevice     */
Signature · 1 line
2.25.GIT
#17 lore raw

PATCH RESEND v6 6/36 monitor: destaticize HMP commands

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

---
 hmp-commands.hx            |  4 +-
 monitor/misc.c             | 76 +++++++++++++++++++-------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++
 3 files changed, 78 insertions(+), 40 deletions(-)
hmp-commands.hx +2 -2
index 7f0f3974ad..02cae25c24 100644
@@ -11,7 +11,7 @@ HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
         .args_type  = "name:S?",
         .params     = "[cmd]",
         .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
         .flags      = "p",
     },
 
@@ -555,7 +555,7 @@ ERST
         .args_type  = "fmt:/,val:l",
         .params     = "/fmt expr",
         .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
     },
 
 SRST
monitor/misc.c +38 -38

301 lines not on this page · raw message

monitor/monitor-internal.h +38 -0
index 8f60ccc70a..bc8c9fa16b 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
 void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                  Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
 #endif
Signature · 1 line
2.25.GIT
#39 lore raw

PATCH RESEND v6 13/36 multi-process: setup PCI host bridge for remote device

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

PCI host bridge is setup for the remote device process. It is implemented using remote-pcihost object. It is an extension of the PCI host bridge setup by QEMU.
Remote-pcihost configures a PCI bus which could be used by the remote
PCI device to latch on to.

---
 MAINTAINERS              |  2 ++
 hw/pci/Makefile.objs     |  2 +-
 include/remote/pcihost.h | 45 ++++++++++++++++++++++++++++
 remote/Makefile.objs     |  1 +
 remote/pcihost.c         | 64 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+), 1 deletion(-)
 create mode 100644 include/remote/pcihost.h
 create mode 100644 remote/pcihost.c
MAINTAINERS +2 -0
index 93ad693da4..0cda5ee06a 100644
@@ -2859,6 +2859,8 @@ F: remote/Makefile.objs
 F: remote/remote-main.c
 F: include/io/mpqemu-link.h
 F: io/mpqemu-link.c
+F: include/remote/pcihost.h
+F: remote/pcihost.c
 
 Build and test automation
 -------------------------
hw/pci/Makefile.objs +1 -1
index 955be54472..90693a7695 100644
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
 
-remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o pci_host.o pcie_host.o
 remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
include/remote/pcihost.h new file +45 -0

45 lines not on this page · raw message

remote/Makefile.objs +1 -0
index a9b2256b2a..2757f5a265 100644
@@ -1 +1,2 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
remote/pcihost.c new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#56 lore raw

PATCH RESEND v6 21/36 multi-process: PCI BAR read/write handling for proxy & remote endpoints

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Proxy device object implements handler for PCI BAR writes and reads. The handler uses BAR_WRITE/BAR_READ message to communicate to the remote process with the BAR address and value to be written/read. The remote process implements handler for BAR_WRITE/BAR_READ message.

---
 hw/proxy/qemu-proxy.c         | 64 ++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 20 ++++++++-
 include/io/mpqemu-link.h      | 12 +++++
 io/mpqemu-link.c              |  6 +++
 remote/remote-main.c          | 84 +++++++++++++++++++++++++++++++++++
 5 files changed, 184 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +64 -0
index 87cf39c672..7fd0a312a5 100644
@@ -169,3 +169,67 @@ static void pci_proxy_dev_register_types(void)
 
 type_init(pci_proxy_dev_register_types)
 
+static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
+                                bool write, hwaddr addr, uint64_t *val,
+                                unsigned size, bool memory)
+{
+    MPQemuLinkState *mpqemu_link = dev->mpqemu_link;
+    MPQemuMsg msg;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.data1.bar_access.addr = mr->addr + addr;
+    msg.data1.bar_access.size = size;
+    msg.data1.bar_access.memory = memory;
+
+    if (write) {
+        msg.cmd = BAR_WRITE;
+        msg.data1.bar_access.val = *val;
+    } else {
+        wait = GET_REMOTE_WAIT;
+
+        msg.cmd = BAR_READ;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, mpqemu_link->dev);
+
+    if (!write) {
+        *val = wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+}
+
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size,
+                        pmr->memory);
+}
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+    uint64_t val;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size,
+                        pmr->memory);
+
+     return val;
+}
+
+const MemoryRegionOps proxy_default_ops = {
+    .read = proxy_default_bar_read,
+    .write = proxy_default_bar_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
include/hw/proxy/qemu-proxy.h +18 -2
index d7eaf26f29..9e4127eccb 100644
@@ -26,14 +26,25 @@
 #define PCI_PROXY_DEV_GET_CLASS(obj) \
             OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
 
-typedef struct PCIProxyDev {
+typedef struct PCIProxyDev PCIProxyDev;
+
+typedef struct ProxyMemoryRegion {
+    PCIProxyDev *dev;
+    MemoryRegion mr;
+    bool memory;
+    bool present;
+    uint8_t type;
+} ProxyMemoryRegion;
+
+struct PCIProxyDev {
     PCIDevice parent_dev;
 
     MPQemuLinkState *mpqemu_link;
 
     int socket;
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
 typedef struct PCIProxyDevClass {
     PCIDeviceClass parent_class;
@@ -43,4 +54,9 @@ typedef struct PCIProxyDevClass {
     char *command;
 } PCIProxyDevClass;
 
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size);
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size);
+
 #endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +12 -0
index 7228a1915e..41cf092f9e 100644
@@ -31,6 +31,8 @@
 /**
  * mpqemu_cmd_t:
  * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
+ * BAR_WRITE        Writes to PCI BAR region
+ * BAR_READ         Reads from PCI BAR region
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -41,6 +43,8 @@ typedef enum {
     CONNECT_DEV,
     PCI_CONFIG_WRITE,
     PCI_CONFIG_READ,
+    BAR_WRITE,
+    BAR_READ,
     MAX,
 } mpqemu_cmd_t;
 
@@ -56,6 +60,13 @@ typedef struct {
     ram_addr_t offsets[REMOTE_MAX_FDS];
 } sync_sysmem_msg_t;
 
+typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
 /**
  * MPQemuMsg:
  * @cmd: The remote command
@@ -78,6 +89,7 @@ typedef struct {
     union {
         uint64_t u64;
         sync_sysmem_msg_t sync_sysmem;
+        bar_access_msg_t bar_access;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
io/mpqemu-link.c +6 -0
index ef4a07b81a..5cb93fc47b 100644
@@ -387,6 +387,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
             return false;
         }
         break;
+    case BAR_WRITE:
+    case BAR_READ:
+        if (msg->size != sizeof(msg->data1)) {
+            return false;
+        }
+        break;
     default:
         break;
     }
remote/remote-main.c +84 -0

102 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#28 lore raw

PATCH RESEND v6 9/36 multi-process: Add config option for multi-process QEMU

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Add a configuration option to separate multi-process code

---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)
configure +11 -0
index 23b5e93752..913c78d4ef 100755
@@ -509,6 +509,7 @@ libpmem=""
 default_devices="yes"
 plugins="no"
 fuzzing="no"
+mpqemu="no"
 
 supported_cpu="no"
 supported_os="no"
@@ -1601,6 +1602,10 @@ for opt do
   ;;
   --gdb=*) gdb_bin="$optarg"
   ;;
+  --enable-mpqemu) mpqemu=yes
+  ;;
+  --disable-mpqemu) mpqemu=no
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1894,6 +1899,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   debug-mutex     mutex debugging support
   libpmem         libpmem support
   xkbcommon       xkbcommon support
+  mpqemu          multi-process QEMU support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -6733,6 +6739,7 @@ echo "default devices   $default_devices"
 echo "plugin support    $plugins"
 echo "fuzzing support   $fuzzing"
 echo "gdb               $gdb_bin"
+echo "multiprocess QEMU $mpqemu"
 
 if test "$supported_cpu" = "no"; then
     echo
@@ -7551,6 +7558,10 @@ if test "$libpmem" = "yes" ; then
   echo "CONFIG_LIBPMEM=y" >> $config_host_mak
 fi
 
+if test "$mpqemu" = "yes" ; then
+  echo "CONFIG_MPQEMU=y" >> $config_host_mak
+fi
+
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
Signature · 1 line
2.25.GIT
#21 lore raw

PATCH RESEND v6 7/36 multi-process: add a command line option for debug file

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Can be used with -d rdebug command options when starting qemu.

---
 include/qemu/log.h | 1 +
 util/log.c         | 2 ++
 2 files changed, 3 insertions(+)
include/qemu/log.h +1 -0
index f4724f7330..a039ddb61a 100644
@@ -64,6 +64,7 @@ static inline bool qemu_log_separate(void)
 #define CPU_LOG_PLUGIN     (1 << 18)
 /* LOG_STRACE is used for user-mode strace logging. */
 #define LOG_STRACE         (1 << 19)
+#define LOG_REMOTE_DEBUG   (1 << 20)
 
 /* Lock output for a series of related logs.  Since this is not needed
  * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
util/log.c +2 -0
index 2da6cb31dc..1f90e70cdd 100644
@@ -334,6 +334,8 @@ const QEMULogItem qemu_log_items[] = {
 #endif
     { LOG_STRACE, "strace",
       "log every user-mode syscall, its input, and its result" },
+    { LOG_REMOTE_DEBUG, "rdebug",
+      "log remote debug" },
     { 0, NULL, NULL },
 };
 
Signature · 1 line
2.25.GIT
#72 lore raw

PATCH RESEND v6 31/36 multi-process/mon: choose HMP commands based on target

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Add "targets" field to HMP command definition to select the targets which would be supported by each command

---
 hmp-commands-info.hx | 10 ++++++++++
 hmp-commands.hx      | 20 ++++++++++++++++++++
 scripts/hxtool       | 35 ++++++++++++++++++++++++++++++++++-
 3 files changed, 64 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 scripts/hxtool
hmp-commands-info.hx +10 -0
index ca5198438d..1fbca7a18d 100644
@@ -23,6 +23,7 @@ ERST
         .params     = "",
         .help       = "show the version of QEMU",
         .cmd        = hmp_info_version,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -50,6 +51,7 @@ ERST
         .params     = "",
         .help       = "show the character devices",
         .cmd        = hmp_info_chardev,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -65,6 +67,7 @@ ERST
         .help       = "show info of one block device or all block devices "
                       "(-n: show named nodes; -v: show details)",
         .cmd        = hmp_info_block,
+        .targets    = "scsi",
     },
 
 SRST
@@ -78,6 +81,7 @@ ERST
         .params     = "",
         .help       = "show block device statistics",
         .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
     },
 
 SRST
@@ -91,6 +95,7 @@ ERST
         .params     = "",
         .help       = "show progress of ongoing block device operations",
         .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
     },
 
 SRST
@@ -161,6 +166,7 @@ ERST
         .params     = "",
         .help       = "show the command line history",
         .cmd        = hmp_info_history,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -214,6 +220,7 @@ ERST
         .params     = "",
         .help       = "show PCI info",
         .cmd        = hmp_info_pci,
+        .targets    = "scsi",
     },
 
 SRST
@@ -598,6 +605,7 @@ ERST
         .params     = "",
         .help       = "show device tree",
         .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
     },
 
 SRST
@@ -611,6 +619,7 @@ ERST
         .params     = "",
         .help       = "show qdev device model list",
         .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
     },
 
 SRST
@@ -624,6 +633,7 @@ ERST
         .params     = "[path]",
         .help       = "show QOM composition tree",
         .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
hmp-commands.hx +20 -0
index 02cae25c24..1b60676d7c 100644
@@ -45,6 +45,7 @@ ERST
         .params     = "",
         .help       = "quit the emulator",
         .cmd        = hmp_quit,
+        .targets    = "scsi",
     },
 
 SRST
@@ -76,6 +77,7 @@ ERST
         .params     = "device size",
         .help       = "resize a block image",
         .cmd        = hmp_block_resize,
+        .targets    = "scsi",
     },
 
 SRST
@@ -92,6 +94,7 @@ ERST
         .params     = "device [speed [base]]",
         .help       = "copy data from a backing file into a block device",
         .cmd        = hmp_block_stream,
+        .targets    = "scsi",
     },
 
 SRST
@@ -105,6 +108,7 @@ ERST
         .params     = "device speed",
         .help       = "set maximum speed for a background block operation",
         .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
     },
 
 SRST
@@ -120,6 +124,7 @@ ERST
                       "\n\t\t\t if you want to abort the operation immediately"
                       "\n\t\t\t instead of keep running until data is in sync)",
         .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
     },
 
 SRST
@@ -133,6 +138,7 @@ ERST
         .params     = "device",
         .help       = "stop an active background block operation",
         .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
     },
 
 SRST
@@ -147,6 +153,7 @@ ERST
         .params     = "device",
         .help       = "pause an active background block operation",
         .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
     },
 
 SRST
@@ -160,6 +167,7 @@ ERST
         .params     = "device",
         .help       = "resume a paused background block operation",
         .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
     },
 
 SRST
@@ -173,6 +181,7 @@ ERST
         .params     = "[-f] device",
         .help       = "eject a removable medium (use -f to force it)",
         .cmd        = hmp_eject,
+        .targets    = "scsi",
     },
 
 SRST
@@ -186,6 +195,7 @@ ERST
         .params     = "device",
         .help       = "remove host block device",
         .cmd        = hmp_drive_del,
+        .targets    = "scsi",
     },
 
 SRST
@@ -204,6 +214,7 @@ ERST
         .params     = "device filename [format [read-only-mode]]",
         .help       = "change a removable medium, optional format",
         .cmd        = hmp_change,
+        .targets    = "scsi",
     },
 
 SRST
@@ -671,6 +682,7 @@ ERST
         .help       = "add device, like -device on the command line",
         .cmd        = hmp_device_add,
         .command_completion = device_add_completion,
+        .targets    = "scsi",
     },
 
 SRST
@@ -685,6 +697,7 @@ ERST
         .help       = "remove device",
         .cmd        = hmp_device_del,
         .command_completion = device_del_completion,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1264,6 +1277,7 @@ ERST
                       "The -c flag requests QEMU to compress backup data\n\t\t\t"
                       "(if the target format supports it).\n\t\t\t",
         .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
     },
 SRST
 ``drive_backup``
@@ -1280,6 +1294,7 @@ ERST
                       "[,readonly=on|off][,copy-on-read=on|off]",
         .help       = "add drive to PCI storage controller",
         .cmd        = hmp_drive_add,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1697,6 +1712,7 @@ ERST
         .help       = "add chardev",
         .cmd        = hmp_chardev_add,
         .command_completion = chardev_add_completion,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1710,6 +1726,7 @@ ERST
         .params     = "id args",
         .help       = "change chardev",
         .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1725,6 +1742,7 @@ ERST
         .help       = "remove chardev",
         .cmd        = hmp_chardev_remove,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1739,6 +1757,7 @@ ERST
         .help       = "send a break on chardev",
         .cmd        = hmp_chardev_send_break,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 SRST
@@ -1810,6 +1829,7 @@ ERST
         .params     = "[subcommand]",
         .help       = "show various information about the system state",
         .cmd        = hmp_info_help,
+        .targets    = "scsi",
         .sub_table  = hmp_info_cmds,
         .flags      = "p",
     },
scripts/hxtool +34 -1
old mode 100644
new mode 100755
index 7b1452f3cf..80c6845db1
@@ -10,7 +10,39 @@ hxtoh()
             SRST*|ERST*) flag=$(($flag^1))
             ;;
             *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
+            ;;
+        esac
+    done
+}
+
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            SRST*|ERST*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
             ;;
         esac
     done
@@ -18,6 +50,7 @@ hxtoh()
 
 case "$1" in
 "-h") hxtoh ;;
+"-tgt") hxtoh_tgt $2 ;;
 *) exit 1 ;;
 esac
 
Signature · 1 line
2.25.GIT
#58 lore raw

PATCH RESEND v6 22/36 multi-process: Synchronize remote memory

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Add memory-listener object which is used to keep the view of the RAM in sync between QEMU and remote process.
A MemoryListener is registered for system-memory AddressSpace. The listener sends SYNC_SYSMEM message to the remote process when memory listener commits the changes to memory, the remote process receives the message and processes it in the handler for SYNC_SYSMEM message.

---
 MAINTAINERS                    |   2 +
 Makefile.target                |   3 +
 hw/proxy/memory-sync.c         | 217 +++++++++++++++++++++++++++++++++
 hw/proxy/qemu-proxy.c          |   6 +
 include/hw/proxy/memory-sync.h |  37 ++++++
 include/hw/proxy/qemu-proxy.h  |   6 +
 remote/remote-main.c           |  11 ++
 7 files changed, 282 insertions(+)
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 include/hw/proxy/memory-sync.h
MAINTAINERS +2 -0
index 3da3dcd311..9ebb46722a 100644
@@ -2869,6 +2869,8 @@ F: remote/memory.c
 F: hw/proxy/Makefile.objs
 F: hw/proxy/qemu-proxy.c
 F: include/hw/proxy/qemu-proxy.h
+F: include/hw/proxy/memory-sync.h
+F: hw/proxy/memory-sync.c
 
 Build and test automation
 -------------------------
Makefile.target +3 -0
index 500fa07fda..c64d860895 100644
@@ -127,6 +127,9 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o
 obj-y += target/$(TARGET_BASE_ARCH)/
 obj-y += disas.o
 obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+endif
 LIBS := $(libs_cpu) $(LIBS)
 
 obj-$(CONFIG_PLUGIN) += plugins/
hw/proxy/memory-sync.c new file +217 -0

217 lines not on this page · raw message

hw/proxy/qemu-proxy.c +6 -0
index 7fd0a312a5..2ac4c1528a 100644
@@ -13,6 +13,8 @@
 #include "io/mpqemu-link.h"
 #include "hw/proxy/qemu-proxy.h"
 #include "hw/pci/pci.h"
+#include "hw/proxy/memory-sync.h"
+#include "qom/object.h"
 
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op)
@@ -138,6 +140,10 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
             error_propagate(errp, local_err);
         }
     }
+
+    dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
+
+    configure_memory_sync(dev->sync, dev->mpqemu_link);
 }
 
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
include/hw/proxy/memory-sync.h new file +37 -0
new file mode 100644
index 0000000000..d8329c9b52
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2018, 2020 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 MEMORY_SYNC_H
+#define MEMORY_SYNC_H
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "exec/memory.h"
+#include "io/mpqemu-link.h"
+
+#define TYPE_MEMORY_LISTENER "memory-listener"
+#define REMOTE_MEM_SYNC(obj) \
+            OBJECT_CHECK(RemoteMemSync, (obj), TYPE_MEMORY_LISTENER)
+
+typedef struct RemoteMemSync {
+    Object obj;
+
+    MemoryListener listener;
+
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
+    MPQemuLinkState *mpqemu_link;
+} RemoteMemSync;
+
+void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link);
+void deconfigure_memory_sync(RemoteMemSync *sync);
+
+#endif
include/hw/proxy/qemu-proxy.h +6 -0
index 9e4127eccb..6d14876ba9 100644
@@ -14,6 +14,7 @@
 
 #include "io/mpqemu-link.h"
 #include "hw/pci/pci.h"
+#include "hw/proxy/memory-sync.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -39,8 +40,13 @@ typedef struct ProxyMemoryRegion {
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
     MPQemuLinkState *mpqemu_link;
 
+    RemoteMemSync *sync;
+
     int socket;
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
remote/remote-main.c +11 -0
index 0990509f7a..90f241064f 100644
@@ -35,6 +35,7 @@
 #include "exec/ramlist.h"
 #include "remote/remote-common.h"
 #include "exec/memattrs.h"
+#include "exec/address-spaces.h"
 
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan);
@@ -231,6 +232,16 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
             goto finalize_loop;
         }
         break;
+    case SYNC_SYSMEM:
+        /*
+         * TODO: ensure no active DMA is happening when
+         * sysmem is being updated
+         */
+        remote_sysmem_reconfig(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#44 lore raw

PATCH RESEND v6 15/36 multi-process: setup memory manager for remote device

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

sync_sysmem_msg_t 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.

---
 MAINTAINERS              |  2 ++
 Makefile.target          |  2 ++
 exec.c                   | 17 +++++++++++
 include/exec/ram_addr.h  |  2 ++
 include/io/mpqemu-link.h | 12 ++++++++
 include/remote/memory.h  | 20 +++++++++++++
 io/mpqemu-link.c         | 13 +++++++++
 remote/memory.c          | 63 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 131 insertions(+)
 create mode 100644 include/remote/memory.h
 create mode 100644 remote/memory.c
MAINTAINERS +2 -0
index 09764e461c..98237fff62 100644
@@ -2863,6 +2863,8 @@ F: include/remote/pcihost.h
 F: remote/pcihost.c
 F: include/remote/machine.h
 F: remote/machine.c
+F: include/remote/memory.h
+F: remote/memory.c
 
 Build and test automation
 -------------------------
Makefile.target +2 -0
index 70fa1eeca5..500fa07fda 100644
@@ -143,6 +143,8 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
 endif
 
 #########################################################
exec.c +17 -0
index 5b1e414099..1e02e00f00 100644
@@ -2371,6 +2371,23 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
 
     return block;
 }
+
+void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size,
+                           ram_addr_t offset, Error **errp)
+{
+    char *name = g_strdup_printf("%d", fd);
+
+    memory_region_init(mr, NULL, name, size);
+    mr->ram = true;
+    mr->terminates = true;
+    mr->destructor = NULL;
+    mr->align = 0;
+    mr->ram_block = qemu_ram_alloc_from_fd(size, mr, RAM_SHARED, fd, offset,
+                                           errp);
+    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
+
+    g_free(name);
+}
 #endif
 
 static
include/exec/ram_addr.h +2 -0
index 1b9f489ff0..d9d7314f51 100644
@@ -122,6 +122,8 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
                                  off_t offset, Error **errp);
+void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size,
+                           ram_addr_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/io/mpqemu-link.h +12 -0
index ef95599bca..d46cb81058 100644
@@ -16,6 +16,8 @@
 
 #include "qom/object.h"
 #include "qemu/thread.h"
+#include "exec/cpu-common.h"
+#include "exec/hwaddr.h"
 
 #define TYPE_MPQEMU_LINK "mpqemu-link"
 #define MPQEMU_LINK(obj) \
@@ -27,15 +29,23 @@
 
 /**
  * mpqemu_cmd_t:
+ * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
  */
 typedef enum {
     INIT = 0,
+    SYNC_SYSMEM,
     MAX,
 } mpqemu_cmd_t;
 
+typedef struct {
+    hwaddr gpas[REMOTE_MAX_FDS];
+    uint64_t sizes[REMOTE_MAX_FDS];
+    ram_addr_t offsets[REMOTE_MAX_FDS];
+} sync_sysmem_msg_t;
+
 /**
  * MPQemuMsg:
  * @cmd: The remote command
@@ -49,6 +59,7 @@ typedef enum {
  * MPQemuMsg Format of the message sent to the remote device from QEMU.
  *
  */
+
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
@@ -56,6 +67,7 @@ typedef struct {
 
     union {
         uint64_t u64;
+        sync_sysmem_msg_t sync_sysmem;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
include/remote/memory.h new file +20 -0
new file mode 100644
index 0000000000..e2e479bb6f
@@ -0,0 +1,20 @@
+/*
+ * Memory manager for remote device
+ *
+ * Copyright © 2018, 2020 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 "qemu/osdep.h"
+#include "exec/hwaddr.h"
+#include "io/mpqemu-link.h"
+
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp);
+
+#endif
io/mpqemu-link.c +13 -0
index cc0a7aecd4..3f81cef96e 100644
@@ -368,6 +368,19 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
             }
         }
     }
+     /* Verify message specific fields. */
+    switch (msg->cmd) {
+    case SYNC_SYSMEM:
+        if (msg->num_fds == 0 || msg->bytestream != 0) {
+            return false;
+        }
+        if (msg->size != sizeof(msg->data1)) {
+            return false;
+        }
+        break;
+    default:
+        break;
+    }
 
     return true;
 }
remote/memory.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#46 lore raw

PATCH RESEND v6 16/36 multi-process: remote process initialization

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Adds the handler to process message from QEMU, Initialize remote process main loop, handles SYNC_SYSMEM message by updating its "system_memory" container using shared file descriptors received from QEMU.

---
 MAINTAINERS            |   1 +
 remote/remote-common.h |  21 +++++++++
 remote/remote-main.c   | 104 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 remote/remote-common.h
MAINTAINERS +1 -0
index 98237fff62..96f8d7ff19 100644
@@ -2857,6 +2857,7 @@ M: John G Johnson <[email protected]>
 S: Maintained
 F: remote/Makefile.objs
 F: remote/remote-main.c
+F: remote/remote-common.h
 F: include/io/mpqemu-link.h
 F: io/mpqemu-link.c
 F: include/remote/pcihost.h
remote/remote-common.h new file +21 -0
new file mode 100644
index 0000000000..12c8d066cf
@@ -0,0 +1,21 @@
+/*
+ * Remote device initialization
+ *
+ * Copyright © 2018, 2020 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_COMMON_H
+#define REMOTE_COMMON_H
+
+extern const char *__progname;
+
+#define PROC_INFO_LENGTH 1024
+gchar *print_pid_exec(gchar *str);
+
+#endif /* REMOTE_COMMON_H */
+
+
+
remote/remote-main.c +104 -0

122 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#74 lore raw

PATCH RESEND v6 33/36 multi-process/mon: enable QMP module support in the remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Build system changes to enable QMP module in the remote process

---
 Makefile.objs               | 10 ++++++++++
 Makefile.target             | 35 +++++++++++++++++++++++++++++++++--
 block/Makefile.objs         |  3 +++
 block/monitor/Makefile.objs |  2 ++
 hmp-commands.hx             |  1 +
 hw/core/Makefile.objs       |  1 +
 monitor/Makefile.objs       |  4 ++++
 monitor/misc.c              |  8 ++++++++
 qapi/Makefile.objs          |  2 ++
 qom/Makefile.objs           |  1 +
 stubs/monitor.c             |  1 +
 ui/Makefile.objs            |  2 ++
 12 files changed, 68 insertions(+), 2 deletions(-)
Makefile.objs +10 -0
index ff3f06b146..cdb55b2f82 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
 remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -45,6 +46,10 @@ remote-pci-obj-$(CONFIG_MPQEMU) += qemu-parse.o
 # remote-lsi-obj-y is code used to implement remote LSI device
 
 remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+remote-lsi-obj-$(CONFIG_MPQEMU) += block/
+
+#remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
 #######################################################################
 # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -113,6 +118,11 @@ common-obj-y += util/machine-notify.o
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
 #######################################################################
 # Target-independent parts used in system and user emulation
 common-obj-y += cpus-common.o
Makefile.target +33 -2
index adc76886f8..1e9e102df8 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
 endif
 
 #########################################################
@@ -204,6 +223,10 @@ endif
 generated-files-y += hmp-commands.h hmp-commands-info.h
 generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
 endif # CONFIG_SOFTMMU
 
 dummy := $(call unnest-vars,,obj-y)
@@ -289,10 +312,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
 hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
 clean: clean-target
 	rm -f *.a *~ $(PROGS)
 	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
 	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 ifdef CONFIG_TRACE_SYSTEMTAP
 	rm -f *.stp
block/Makefile.objs +3 -0
index 3e7513967c..734548d48f 100644
@@ -76,3 +76,6 @@ parallels.o-cflags := $(LIBXML2_CFLAGS)
 parallels.o-libs   := $(LIBXML2_LIBS)
 
 remote-pci-obj-$(CONFIG_MPQEMU) += stream.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi-sysemu.o
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += monitor/
block/monitor/Makefile.objs +2 -0
index 0a74f9a8b5..a0c898711f 100644
@@ -1 +1,3 @@
 common-obj-y += block-hmp-cmds.o
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += block-hmp-cmds.o
hmp-commands.hx +1 -0
index 1b60676d7c..54d01a055f 100644
@@ -12,6 +12,7 @@ HXCOMM HXCOMM can be used for comments, discarded from both rST and C.
         .params     = "[cmd]",
         .help       = "show the help",
         .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
hw/core/Makefile.objs +1 -0
index e3e80848c8..251b77bc4c 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
 remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
 remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
 remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index a8533c9dd7..b6949be297 100644
@@ -4,3 +4,7 @@ common-obj-y += qmp-cmds.o qmp-cmds-control.o
 common-obj-y += hmp-cmds.o
 
 storage-daemon-obj-y += monitor.o qmp.o qmp-cmds-control.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +8 -0
index c0eee6f4ab..edda4cce17 100644
@@ -1679,13 +1679,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
 
 /* Please update hmp-commands.hx when adding or changing commands */
 static HMPCommand hmp_info_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands-info.h"
+#else
 #include "hmp-commands-info.h"
+#endif
     { NULL, NULL, },
 };
 
 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
 HMPCommand hmp_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands.h"
+#else
 #include "hmp-commands.h"
+#endif
     { NULL, NULL, },
 };
 
qapi/Makefile.objs +2 -0
index 4673ab7490..f7433d6a73 100644
@@ -36,3 +36,5 @@ QAPI_MODULES_STORAGE_DAEMON = block-core char common control crypto
 QAPI_MODULES_STORAGE_DAEMON += introspect job qom sockets pragma transaction
 
 storage-daemon-obj-y += $(QAPI_MODULES_STORAGE_DAEMON:%=qapi-commands-%.o)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 7e9455db90..546f9fbde6 100644
@@ -6,3 +6,4 @@ storage-daemon-obj-y += qom-qmp-cmds.o
 
 remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
 remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
stubs/monitor.c +1 -0
index 79c5571b2d..b845a95d5c 100644
@@ -37,6 +37,7 @@
 #pragma weak monitor_printf
 #pragma weak monitor_cur_is_qmp
 #pragma weak qmp_device_list_properties
+#pragma weak monitor_fdsets_cleanup
 
 __thread Monitor *cur_mon;
 
ui/Makefile.objs +2 -0
index e6da6ff047..c3ac572d6b 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
 egl-helpers.o-libs += $(OPENGL_LIBS)
 egl-context.o-libs += $(OPENGL_LIBS)
 egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
2.25.GIT
#54 lore raw

PATCH RESEND v6 20/36 multi-process: Forward PCI config space acceses to the remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

The Proxy Object sends the PCI config space accesses as messages to the remote process over the communication channel

---
 hw/proxy/qemu-proxy.c    | 61 ++++++++++++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  8 ++++++
 io/mpqemu-link.c         |  6 ++++
 remote/remote-main.c     | 32 +++++++++++++++++++++
 4 files changed, 107 insertions(+)
hw/proxy/qemu-proxy.c +61 -0
index 9b5e429a88..87cf39c672 100644
@@ -14,6 +14,65 @@
 #include "hw/proxy/qemu-proxy.h"
 #include "hw/pci/pci.h"
 
+static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
+                          unsigned int op)
+{
+    MPQemuMsg msg;
+    struct conf_data_msg conf_data;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    conf_data.addr = addr;
+    conf_data.val = (op == PCI_CONFIG_WRITE) ? *val : 0;
+    conf_data.l = l;
+
+    msg.data2 = (uint8_t *)&conf_data;
+    if (!msg.data2) {
+        return -ENOMEM;
+    }
+
+    msg.size = sizeof(conf_data);
+    msg.cmd = op;
+    msg.bytestream = 1;
+
+    if (op == PCI_CONFIG_WRITE) {
+        msg.num_fds = 0;
+    } else {
+        /* TODO: Dont create fd each time for send. */
+        wait = GET_REMOTE_WAIT;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->dev);
+
+    if (op == PCI_CONFIG_READ) {
+        *val = (uint32_t)wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+
+    return 0;
+}
+
+static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len)
+{
+    uint32_t val;
+
+    (void)pci_default_read_config(d, addr, len);
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, len, PCI_CONFIG_READ);
+
+    return val;
+}
+
+static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,
+                                   int l)
+{
+    pci_default_write_config(d, addr, val, l);
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE);
+}
+
 static void proxy_set_socket(Object *obj, const char *str, Error **errp)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
@@ -86,6 +145,8 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->realize = pci_proxy_dev_realize;
+    k->config_read = pci_proxy_read_config;
+    k->config_write = pci_proxy_write_config;
 }
 
 static const TypeInfo pci_proxy_dev_type_info = {
include/io/mpqemu-link.h +8 -0
index ebae9afc45..7228a1915e 100644
@@ -39,9 +39,17 @@ typedef enum {
     INIT = 0,
     SYNC_SYSMEM,
     CONNECT_DEV,
+    PCI_CONFIG_WRITE,
+    PCI_CONFIG_READ,
     MAX,
 } mpqemu_cmd_t;
 
+struct conf_data_msg {
+    uint32_t addr;
+    uint32_t val;
+    int l;
+};
+
 typedef struct {
     hwaddr gpas[REMOTE_MAX_FDS];
     uint64_t sizes[REMOTE_MAX_FDS];
io/mpqemu-link.c +6 -0
index f780b65181..ef4a07b81a 100644
@@ -381,6 +381,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
             return false;
         }
         break;
+    case PCI_CONFIG_WRITE:
+    case PCI_CONFIG_READ:
+        if (msg->size != sizeof(struct conf_data_msg)) {
+            return false;
+        }
+        break;
     default:
         break;
     }
remote/remote-main.c +32 -0
index f541baae6a..834574e172 100644
@@ -53,6 +53,32 @@ gchar *print_pid_exec(gchar *str)
 
 #define LINK_TO_DEV(link) ((PCIDevice *)link->opaque)
 
+static void process_config_write(PCIDevice *dev, MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+
+    qemu_mutex_lock_iothread();
+    pci_default_write_config(dev, conf->addr, conf->val, conf->l);
+    qemu_mutex_unlock_iothread();
+}
+
+static void process_config_read(PCIDevice *dev, MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+    uint32_t val;
+    int wait;
+
+    wait = msg->fds[0];
+
+    qemu_mutex_lock_iothread();
+    val = pci_default_read_config(dev, conf->addr, conf->l);
+    qemu_mutex_unlock_iothread();
+
+    notify_proxy(wait, val);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
 static gpointer dev_thread(gpointer data)
 {
     MPQemuLinkState *link = data;
@@ -115,6 +141,12 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
     case CONNECT_DEV:
         process_connect_dev_msg(msg);
         break;
+    case PCI_CONFIG_WRITE:
+        process_config_write(LINK_TO_DEV(link), msg);
+        break;
+    case PCI_CONFIG_READ:
+        process_config_read(LINK_TO_DEV(link), msg);
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#50 lore raw

PATCH RESEND v6 18/36 multi-process: Initialize Proxy Object's communication channel

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Add "socket" object property which initializes the communication channel

---
 hw/proxy/qemu-proxy.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
hw/proxy/qemu-proxy.c +20 -0
index bf6c4117ef..40bf56fd37 100644
@@ -14,6 +14,25 @@
 #include "hw/proxy/qemu-proxy.h"
 #include "hw/pci/pci.h"
 
+static void proxy_set_socket(Object *obj, const char *str, Error **errp)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+
+    pdev->socket = atoi(str);
+
+    mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
+                        pdev->socket);
+}
+
+static void proxy_init(Object *obj)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+
+    pdev->mpqemu_link = mpqemu_link_create();
+
+    object_property_add_str(obj, "socket", NULL, proxy_set_socket, NULL);
+}
+
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
 {
     PCIProxyDev *dev = PCI_PROXY_DEV(device);
@@ -41,6 +60,7 @@ static const TypeInfo pci_proxy_dev_type_info = {
     .instance_size = sizeof(PCIProxyDev),
     .class_size    = sizeof(PCIProxyDevClass),
     .class_init    = pci_proxy_dev_class_init,
+    .instance_init = proxy_init,
     .interfaces = (InterfaceInfo[]) {
         { INTERFACE_CONVENTIONAL_PCI_DEVICE },
         { },
Signature · 1 line
2.25.GIT
#70 lore raw

PATCH RESEND v6 29/36 multi-process: handle heartbeat messages in remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

If the remote process is alive, it responds to proxy's heartbeat messages

---
 remote/remote-main.c | 5 +++++
 1 file changed, 5 insertions(+)
remote/remote-main.c +5 -0
index b37802151a..beac591fac 100644
@@ -216,6 +216,7 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
     g_autofree gchar *pid_exec = NULL;
 
     pid_exec = g_malloc(PROC_INFO_LENGTH);
+    int wait;
 
     if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
         goto finalize_loop;
@@ -269,6 +270,10 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
     case GET_PCI_INFO:
         process_get_pci_info_msg(link, msg);
         break;
+    case PROXY_PING:
+        wait = msg->fds[0];
+        notify_proxy(wait, 0);
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#61 lore raw

PATCH RESEND v6 23/36 multi-process: create IOHUB object to handle irq

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD ioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU.

---
 MAINTAINERS                   |   2 +
 Makefile.target               |   1 +
 hw/Makefile.objs              |   2 -
 hw/proxy/Makefile.objs        |   1 -
 hw/proxy/qemu-proxy.c         |  52 ++++++++++++
 include/hw/pci/pci_ids.h      |   3 +
 include/hw/proxy/qemu-proxy.h |   8 ++
 include/io/mpqemu-link.h      |   8 ++
 include/remote/iohub.h        |  50 ++++++++++++
 include/remote/machine.h      |   2 +
 io/mpqemu-link.c              |   1 +
 remote/Makefile.objs          |   1 +
 remote/iohub.c                | 148 ++++++++++++++++++++++++++++++++++
 remote/machine.c              |  15 ++++
 remote/remote-main.c          |   4 +
 15 files changed, 295 insertions(+), 3 deletions(-)
 delete mode 100644 hw/proxy/Makefile.objs
 create mode 100644 include/remote/iohub.h
 create mode 100644 remote/iohub.c
MAINTAINERS +2 -0
index 9ebb46722a..198c9f69bc 100644
@@ -2871,6 +2871,8 @@ F: hw/proxy/qemu-proxy.c
 F: include/hw/proxy/qemu-proxy.h
 F: include/hw/proxy/memory-sync.h
 F: hw/proxy/memory-sync.c
+F: include/remote/iohub.h
+F: remote/iohub.c
 
 Build and test automation
 -------------------------
Makefile.target +1 -0
index c64d860895..b956ab24f6 100644
@@ -129,6 +129,7 @@ obj-y += disas.o
 obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
 ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
 obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+obj-$(CONFIG_MPQEMU) += hw/proxy/qemu-proxy.o
 endif
 LIBS := $(libs_cpu) $(LIBS)
 
hw/Makefile.objs +0 -2
index 7b489b12a5..af9235b6f2 100644
@@ -45,8 +45,6 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
-common-obj-$(CONFIG_MPQEMU) += proxy/
-
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs deleted +0 -1
deleted file mode 100644
index eb81624cf8..0000000000
@@ -1 +0,0 @@
-common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c +52 -0

70 lines not on this page · raw message

include/hw/pci/pci_ids.h +3 -0
index 11f8ab7149..bd0c17dc78 100644
@@ -192,6 +192,9 @@
 #define PCI_DEVICE_ID_SUN_SIMBA          0x5000
 #define PCI_DEVICE_ID_SUN_SABRE          0xa000
 
+#define PCI_VENDOR_ID_ORACLE             0x108e
+#define PCI_DEVICE_ID_REMOTE_IOHUB       0xb000
+
 #define PCI_VENDOR_ID_CMD                0x1095
 #define PCI_DEVICE_ID_CMD_646            0x0646
 
include/hw/proxy/qemu-proxy.h +8 -0
index 6d14876ba9..0d8ec6d686 100644
@@ -12,9 +12,12 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
+#include <linux/kvm.h>
+
 #include "io/mpqemu-link.h"
 #include "hw/pci/pci.h"
 #include "hw/proxy/memory-sync.h"
+#include "qemu/event_notifier.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -47,6 +50,11 @@ struct PCIProxyDev {
 
     RemoteMemSync *sync;
 
+    struct kvm_irqfd irqfd;
+
+    EventNotifier intr;
+    EventNotifier resample;
+
     int socket;
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
include/io/mpqemu-link.h +8 -0
index 41cf092f9e..14e4be2bd0 100644
@@ -33,6 +33,8 @@
  * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
  * BAR_WRITE        Writes to PCI BAR region
  * BAR_READ         Reads from PCI BAR region
+ * SET_IRQFD        Sets the IRQFD to be used to raise interrupts directly
+ *                  from remote device
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -45,6 +47,7 @@ typedef enum {
     PCI_CONFIG_READ,
     BAR_WRITE,
     BAR_READ,
+    SET_IRQFD,
     MAX,
 } mpqemu_cmd_t;
 
@@ -81,6 +84,10 @@ typedef struct {
  *
  */
 
+typedef struct {
+    int intx;
+} set_irqfd_msg_t;
+
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
@@ -90,6 +97,7 @@ typedef struct {
         uint64_t u64;
         sync_sysmem_msg_t sync_sysmem;
         bar_access_msg_t bar_access;
+        set_irqfd_msg_t set_irqfd;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
include/remote/iohub.h new file +50 -0

50 lines not on this page · raw message

include/remote/machine.h +2 -0
index 7e9bdbe28e..300394a546 100644
@@ -16,11 +16,13 @@
 #include "hw/boards.h"
 #include "remote/pcihost.h"
 #include "qemu/notify.h"
+#include "remote/iohub.h"
 
 typedef struct RemMachineState {
     MachineState parent_obj;
 
     RemPCIHost *host;
+    RemoteIOHubState *iohub;
 } RemMachineState;
 
 #define TYPE_REMOTE_MACHINE "remote-machine"
io/mpqemu-link.c +1 -0
index 5cb93fc47b..ea519a980e 100644
@@ -389,6 +389,7 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
         break;
     case BAR_WRITE:
     case BAR_READ:
+    case SET_IRQFD:
         if (msg->size != sizeof(msg->data1)) {
             return false;
         }
remote/Makefile.objs +1 -0
index 55f405d048..ed3e5bd8c4 100644
@@ -2,3 +2,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
 remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
 remote-pci-obj-$(CONFIG_MPQEMU) += ../util/machine-notify.o
+remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o
remote/iohub.c new file +148 -0

148 lines not on this page · raw message

remote/machine.c +15 -0
index 97e4f194ea..d529f68660 100644
@@ -25,12 +25,16 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 #include "qemu/notify.h"
+#include "hw/pci/pci_host.h"
+#include "remote/iohub.h"
 
 static void remote_machine_init(Object *obj)
 {
     RemMachineState *s = REMOTE_MACHINE(obj);
     RemPCIHost *rem_host;
     MemoryRegion *system_memory, *system_io, *pci_memory;
+    PCIHostState *pci_host;
+    PCIDevice *pci_dev;
 
     Error *error_abort = NULL;
 
@@ -67,6 +71,17 @@ static void remote_machine_init(Object *obj)
     qemu_mutex_unlock_iothread();
 
     qdev_init_nofail(DEVICE(rem_host));
+
+    pci_host = PCI_HOST_BRIDGE(rem_host);
+    pci_dev = pci_create_simple_multifunction(pci_host->bus,
+                                              PCI_DEVFN(REMOTE_IOHUB_DEV,
+                                                        REMOTE_IOHUB_FUNC),
+                                              true, TYPE_REMOTE_IOHUB_DEVICE);
+
+    s->iohub = REMOTE_IOHUB_DEVICE(pci_dev);
+
+    pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
+                 s->iohub, REMOTE_IOHUB_NB_PIRQS);
 }
 
 static const TypeInfo remote_machine = {
remote/remote-main.c +4 -0
index 90f241064f..7cc1a60c3d 100644
@@ -36,6 +36,7 @@
 #include "remote/remote-common.h"
 #include "exec/memattrs.h"
 #include "exec/address-spaces.h"
+#include "remote/iohub.h"
 
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan);
@@ -242,6 +243,9 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
             goto finalize_loop;
         }
         break;
+    case SET_IRQFD:
+        process_set_irqfd_msg(LINK_TO_DEV(link), msg);
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#68 lore raw

PATCH RESEND v6 27/36 multi-process: add support to parse device option

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Enable remote process to parse device command line option

---
 remote/remote-opts.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
remote/remote-opts.c +10 -0
index cb7837bf13..f077221c71 100644
@@ -57,6 +57,13 @@ void parse_cmdline(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_device:
+                if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
+                                            optarg, true)) {
+                    error_report("Unable to process device command");
+                    exit(1);
+                }
+            break;
             default:
                 break;
             }
@@ -71,5 +78,8 @@ void parse_cmdline(int argc, char **argv, char **envp)
         exit(0);
     }
 
+    qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL,
+                      &error_fatal);
+
     return;
 }
Signature · 1 line
2.25.GIT
#71 lore raw

PATCH RESEND v6 30/36 multi-process: perform device reset in the remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Perform device reset in the remote process when QEMU performs device reset. This is required to reset the internal state (like registers, etc...) of emulated devices

---
 hw/proxy/qemu-proxy.c    | 25 +++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 remote/remote-main.c     | 13 +++++++++++++
 3 files changed, 39 insertions(+)
hw/proxy/qemu-proxy.c +25 -0
index 162014353f..cffc227acd 100644
@@ -291,14 +291,39 @@ static void pci_proxy_dev_exit(PCIDevice *pdev)
     stop_hb_timer(dev);
 }
 
+static void proxy_device_reset(DeviceState *dev)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+    MPQemuMsg msg;
+    int wait = -1;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.cmd = DEVICE_RESET;
+
+    wait = GET_REMOTE_WAIT;
+    msg.num_fds = 1;
+    msg.fds[0] = wait;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    (void)wait_for_remote(wait);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
 
     k->realize = pci_proxy_dev_realize;
     k->exit = pci_proxy_dev_exit;
     k->config_read = pci_proxy_read_config;
     k->config_write = pci_proxy_write_config;
+    dc->reset = proxy_device_reset;
 }
 
 static const TypeInfo pci_proxy_dev_type_info = {
include/io/mpqemu-link.h +1 -0
index 45ea1fcafa..22fb234744 100644
@@ -51,6 +51,7 @@ typedef enum {
     GET_PCI_INFO,
     RET_PCI_INFO,
     PROXY_PING,
+    DEVICE_RESET,
     MAX,
 } mpqemu_cmd_t;
 
remote/remote-main.c +13 -0
index beac591fac..562db4ccc3 100644
@@ -39,6 +39,7 @@
 #include "exec/address-spaces.h"
 #include "remote/iohub.h"
 #include "remote-opts.h"
+#include "sysemu/reset.h"
 
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan);
@@ -208,6 +209,15 @@ static void process_get_pci_info_msg(MPQemuLinkState *link, MPQemuMsg *msg)
     mpqemu_msg_send(&ret, link->dev);
 }
 
+static void process_device_reset_msg(MPQemuMsg *msg)
+{
+    qemu_devices_reset();
+
+    if (msg->num_fds == 1) {
+            notify_proxy(msg->fds[0], 0);
+    }
+}
+
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan)
 {
@@ -274,6 +284,9 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
         wait = msg->fds[0];
         notify_proxy(wait, 0);
         break;
+    case DEVICE_RESET:
+        process_device_reset_msg(msg);
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#66 lore raw

PATCH RESEND v6 25/36 multi-process: Introduce build flags to separate remote process code

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Introduce SCSI_PROCESS & REMOTE_PROCESS build flags to separate code that applies only to remote processes.

---
 Makefile.target | 4 ++++
 rules.mak       | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
Makefile.target +4 -0
index b956ab24f6..adc76886f8 100644
@@ -269,6 +269,10 @@ ifdef CONFIG_DARWIN
 	$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
 endif
 
+ifdef CONFIG_MPQEMU
+$(SCSI_DEV_BUILD): REMOTE_FLAGS = -DREMOTE_PROCESS -DSCSI_PROCESS
+endif
+
 $(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS)
 	$(call LINK, $(filter-out %.mak, $^))
 ifdef CONFIG_DARWIN
rules.mak +1 -1
index 694865b63e..257f07e322 100644
@@ -67,7 +67,7 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
 
 %.o: %.c
 	$(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
-	       $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
+	       $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) $(REMOTE_FLAGS) \
 	       -c -o $@ $<,"CC","$(TARGET_DIR)$@")
 %.o: %.rc
 	$(call quiet-command,$(WINDRES) -I. -o $@ $<,"RC","$(TARGET_DIR)$@")
Signature · 1 line
2.25.GIT
#75 lore raw

PATCH RESEND v6 34/36 multi-process/mon: Initialize QMP module for remote processes

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

---
 remote/remote-main.c | 13 +++++++++++++
 remote/remote-opts.c | 11 +++++++++++
 2 files changed, 24 insertions(+)
remote/remote-main.c +13 -0
index 562db4ccc3..199af144dd 100644
@@ -40,6 +40,9 @@
 #include "remote/iohub.h"
 #include "remote-opts.h"
 #include "sysemu/reset.h"
+#include "qemu-parse.h"
+#include "monitor/monitor.h"
+#include "chardev/char.h"
 
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan);
@@ -313,6 +316,8 @@ int main(int argc, char *argv[])
 
     module_call_init(MODULE_INIT_QOM);
 
+    monitor_init_globals();
+
     bdrv_init_with_whitelist();
 
     if (qemu_init_main_loop(&err)) {
@@ -330,6 +335,8 @@ int main(int argc, char *argv[])
 
     qemu_add_opts(&qemu_device_opts);
     qemu_add_opts(&qemu_drive_opts);
+    qemu_add_opts(&qemu_chardev_opts);
+    qemu_add_opts(&qemu_mon_opts);
     qemu_add_drive_opts(&qemu_legacy_drive_opts);
     qemu_add_drive_opts(&qemu_common_drive_opts);
     qemu_add_drive_opts(&qemu_drive_opts);
@@ -351,6 +358,12 @@ int main(int argc, char *argv[])
 
     parse_cmdline(argc - 2, argv + 2, NULL);
 
+    qemu_opts_foreach(qemu_find_opts("chardev"),
+                      chardev_init_func, NULL, &error_fatal);
+
+    qemu_opts_foreach(qemu_find_opts("mon"),
+                      mon_init_func, NULL, &error_fatal);
+
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
remote/remote-opts.c +11 -0
index f077221c71..ac3a9be6b8 100644
@@ -15,6 +15,7 @@
 #include "qemu-options.h"
 #include "qemu-parse.h"
 #include "remote-opts.h"
+#include "monitor/monitor.h"
 
 /*
  * In remote process, we parse only subset of options. The code
@@ -64,6 +65,16 @@ void parse_cmdline(int argc, char **argv, char **envp)
                     exit(1);
                 }
             break;
+            case QEMU_OPTION_qmp:
+                monitor_parse(optarg, "control", false);
+                break;
+            case QEMU_OPTION_monitor:
+                if (!strncmp(optarg, "stdio", 5)) {
+                    warn_report("STDIO not supported in remote process");
+                } else if (strncmp(optarg, "none", 4)) {
+                    monitor_parse(optarg, "readline", false);
+                }
+                break;
             default:
                 break;
             }
Signature · 1 line
2.25.GIT
#73 lore raw

PATCH RESEND v6 32/36 multi-process/mon: stub functions to enable QMP module for remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

QMP module doesn't need some functions to run independently on the remote processes. However, these functions are necessary for compilation. Therefore, these functions are stub'ed out. The stub functions raise an assert if QEMU is built in debug mode (--enable-debug).

---
 MAINTAINERS            |   4 +
 accel/stubs/tcg-stub.c |  10 +++
 configure              |   4 +
 include/qemu-common.h  |   8 ++
 stubs/gdbstub.c        |  23 ++++++
 stubs/migration.c      | 162 +++++++++++++++++++++++++++++++++++++++++
 stubs/monitor.c        |  31 ++++++++
 stubs/net-stub.c       |  69 ++++++++++++++++++
 stubs/qapi-misc.c      |  41 +++++++++++
 stubs/qapi-target.c    |  56 ++++++++++++++
 stubs/ui-stub.c        | 130 +++++++++++++++++++++++++++++++++
 stubs/vl-stub.c        |  92 +++++++++++++++++++++++
 12 files changed, 630 insertions(+)
 create mode 100644 stubs/migration.c
 create mode 100644 stubs/qapi-misc.c
 create mode 100644 stubs/qapi-target.c
 create mode 100644 stubs/ui-stub.c
MAINTAINERS +4 -0
index 6a4b5e16be..216291f545 100644
@@ -1996,6 +1996,8 @@ F: blockdev-hmp-cmds.c
 F: block/qapi.c
 F: qapi/block*.json
 F: qapi/transaction.json
+F: stubs/qapi-misc.c
+F: stubs/qapi-target.c
 T: git https://repo.or.cz/qemu/armbru.git block-next
 
 Dirty Bitmaps
@@ -2120,6 +2122,7 @@ F: ui/
 F: include/ui/
 F: qapi/ui.json
 F: util/drm.c
+F: stubs/ui-stub.c
 
 Cocoa graphics
 M: Peter Maydell <[email protected]>
@@ -2152,6 +2155,7 @@ F: include/monitor/hmp-target.h
 F: tests/qtest/test-hmp.c
 F: include/qemu/qemu-print.h
 F: util/qemu-print.c
+F: stubs/migration.c
 
 Network device backends
 M: Jason Wang <[email protected]>
accel/stubs/tcg-stub.c +10 -0
index 2e4e8741fb..cdbceb5fff 100644
@@ -119,4 +119,14 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)
 void page_collection_unlock(struct page_collection *set)
 {
 }
+
+void dump_exec_info(void)
+{
+    qemu_debug_assert(0);
+}
+
+void dump_opcount_info(void)
+{
+    qemu_debug_assert(0);
+}
 #endif
configure +4 -0
index 913c78d4ef..cd90cc5d02 100755
@@ -7562,6 +7562,10 @@ if test "$mpqemu" = "yes" ; then
   echo "CONFIG_MPQEMU=y" >> $config_host_mak
 fi
 
+if test "$debug" = "yes" ; then
+  echo "CONFIG_DEBUG=y" >> $config_host_mak
+fi
+
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
include/qemu-common.h +8 -0
index d0142f29ac..b76e309d98 100644
@@ -10,6 +10,8 @@
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
 
+#include <assert.h>
+
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /* Copyright string for -version arguments, About dialogs, etc */
@@ -135,4 +137,10 @@ void page_size_init(void);
  * returned. */
 bool dump_in_progress(void);
 
+#ifdef CONFIG_DEBUG
+#define qemu_debug_assert(x) assert(x)
+#else
+#define qemu_debug_assert(x)
+#endif
+
 #endif
stubs/gdbstub.c +23 -0
index 2b7aee50d3..1e65b54755 100644
@@ -1,6 +1,29 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "exec/gdbstub.h"       /* xml_builtin */
 
+#pragma weak gdbserver_start
+
 const char *const xml_builtin[][2] = {
   { NULL, NULL }
 };
+
+#ifdef CONFIG_USER_ONLY
+
+int gdbserver_start(int port)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+#else
+
+int gdbserver_start(const char *device)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+#endif
stubs/migration.c new file +162 -0

162 lines not on this page · raw message

stubs/monitor.c +31 -0
index 4613bc23e0..79c5571b2d 100644
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "monitor/monitor.h"
 #include "../monitor/monitor-internal.h"
@@ -10,6 +11,25 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/runstate.h"
 #include "monitor/hmp.h"
+#include "monitor/qdev.h"
+#include "sysemu/blockdev.h"
+#include "sysemu/sysemu.h"
+
+#include "qapi/qapi-types-block-core.h"
+#include "qapi/qapi-commands-block-core.h"
+#include "qapi/qapi-emit-events.h"
+
+#pragma weak cur_mon
+#pragma weak monitor_vprintf
+#pragma weak monitor_get_fd
+#pragma weak monitor_init
+#pragma weak qapi_event_emit
+#pragma weak monitor_get_cpu_index
+#pragma weak monitor_printf
+#pragma weak monitor_cur_is_qmp
+#pragma weak qmp_device_list_properties
+#pragma weak monitor_init_qmp
+#pragma weak monitor_init_hmp
 
 #pragma weak hmp_handle_error
 #pragma weak cur_mon
@@ -22,34 +42,45 @@ __thread Monitor *cur_mon;
 
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+    qemu_debug_assert(0);
     abort();
 }
 
 void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp)
 {
+    qemu_debug_assert(0);
 }
 
 void monitor_fdsets_cleanup(void)
 {
+    qemu_debug_assert(0);
 }
 
 int monitor_get_cpu_index(void)
 {
+    qemu_debug_assert(0);
+
     return -ENOSYS;
 }
 int monitor_printf(Monitor *mon, const char *fmt, ...)
 {
+    qemu_debug_assert(0);
+
     return -ENOSYS;
 }
 
 bool monitor_cur_is_qmp(void)
 {
+    qemu_debug_assert(0);
+
     return false;
 }
 
 ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
                                                    Error **errp)
 {
+    qemu_debug_assert(0);
+
     return NULL;
 }
 
stubs/net-stub.c +69 -0

78 lines not on this page · raw message

stubs/qapi-misc.c new file +41 -0

41 lines not on this page · raw message

stubs/qapi-target.c new file +56 -0

56 lines not on this page · raw message

stubs/ui-stub.c new file +130 -0

130 lines not on this page · raw message

stubs/vl-stub.c +92 -0

113 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#10 lore raw

PATCH RESEND v6 2/36 multi-process: Refactor machine_init and exit notifiers

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Relocate machine_int and exit notifiers into common code

---
 MAINTAINERS                 |  1 +
 Makefile.objs               |  1 +
 include/sysemu/sysemu.h     |  2 ++
 softmmu/vl.c                | 42 ----------------------
 stubs/Makefile.objs         |  2 ++
 stubs/machine-init-add.c    |  7 ++++
 stubs/machine-init-done.c   |  5 ++-
 stubs/machine-init-remove.c |  8 +++++
 util/machine-notify.c       | 69 +++++++++++++++++++++++++++++++++++++
 9 files changed, 92 insertions(+), 45 deletions(-)
 create mode 100644 stubs/machine-init-add.c
 create mode 100644 stubs/machine-init-remove.c
 create mode 100644 util/machine-notify.c
MAINTAINERS +1 -0
index 8cbc1fac2b..04b19ac56c 100644
@@ -2133,6 +2133,7 @@ F: util/qemu-timer.c
 F: softmmu/vl.c
 F: softmmu/main.c
 F: qapi/run-state.json
+F: util/machine-notify.c
 
 Human Monitor (HMP)
 M: Dr. David Alan Gilbert <[email protected]>
Makefile.objs +1 -0
index a7c967633a..bfb9271862 100644
@@ -79,6 +79,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 common-obj-$(CONFIG_FDT) += device_tree.o
 
 common-obj-y += qapi/
+common-obj-y += util/machine-notify.o
 
 endif # CONFIG_SOFTMMU
 
include/sysemu/sysemu.h +2 -0
index ef81302e1a..2438dd7bea 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
 extern bool machine_init_done;
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
 extern int autostart;
 
softmmu/vl.c +0 -42

60 lines not on this page · raw message

stubs/Makefile.objs +2 -0
index 45be5dc0ed..f884bb6180 100644
@@ -43,4 +43,6 @@ stub-obj-y += pci-host-piix.o
 stub-obj-y += ram-block.o
 stub-obj-y += ramfb.o
 stub-obj-y += fw_cfg.o
+stub-obj-y += machine-init-add.o
+stub-obj-y += machine-init-remove.o
 stub-obj-$(CONFIG_SOFTMMU) += semihost.o
stubs/machine-init-add.c new file +7 -0
new file mode 100644
index 0000000000..520dcb9801
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+}
+
stubs/machine-init-done.c +2 -3
index cd8e81392d..a34d838f7a 100644
@@ -3,6 +3,5 @@
 
 bool machine_init_done = true;
 
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-}
+NotifierList machine_init_done_notifiers =
+    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
stubs/machine-init-remove.c new file +8 -0
new file mode 100644
index 0000000000..30aee27c2d
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
+
+
util/machine-notify.c new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#30 lore raw

PATCH RESEND v6 10/36 multi-process: build system for remote device process

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Modify Makefile to support the building of the remote device process. Implements main() function of remote device process.

---
 MAINTAINERS             |  8 ++++++
 Makefile                |  2 ++
 Makefile.objs           | 27 ++++++++++++++++++
 Makefile.target         | 61 ++++++++++++++++++++++++++++++++++++++++-
 accel/Makefile.objs     |  2 ++
 backends/Makefile.objs  |  2 ++
 block/Makefile.objs     |  2 ++
 hw/Makefile.objs        |  7 +++++
 hw/block/Makefile.objs  |  2 ++
 hw/core/Makefile.objs   | 18 ++++++++++++
 hw/nvram/Makefile.objs  |  2 ++
 hw/pci/Makefile.objs    |  4 +++
 hw/scsi/Makefile.objs   |  2 ++
 migration/Makefile.objs |  2 ++
 qom/Makefile.objs       |  3 ++
 remote/Makefile.objs    |  1 +
 remote/remote-main.c    | 23 ++++++++++++++++
 stubs/replay.c          |  4 +++
 18 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 remote/Makefile.objs
 create mode 100644 remote/remote-main.c
MAINTAINERS +8 -0
index c5fba124e4..965f34d4f9 100644
@@ -2850,6 +2850,14 @@ S: Maintained
 F: hw/semihosting/
 F: include/hw/semihosting/
 
+Multi-process QEMU
+M: Jagannathan Raman <[email protected]>
+M: Elena Ufimtseva <[email protected]>
+M: John G Johnson <[email protected]>
+S: Maintained
+F: remote/Makefile.objs
+F: remote/remote-main.c
+
 Build and test automation
 -------------------------
 Build and test automation
Makefile +2 -0
index 8a9113e666..69337d6f8c 100644
@@ -474,6 +474,8 @@ dummy := $(call unnest-vars,, \
                 qom-obj-y \
                 io-obj-y \
                 common-obj-y \
+                remote-pci-obj-y \
+                remote-lsi-obj-y \
                 common-obj-m \
                 trace-obj-y)
 
Makefile.objs +27 -0
index f29c60c59d..f6654633b4 100644
@@ -21,6 +21,33 @@ block-obj-$(CONFIG_REPLICATION) += replication.o
 
 block-obj-m = block/
 
+#########################################################
+# remote-pci-obj-y is common code used by remote devices
+
+remote-pci-obj-$(CONFIG_MPQEMU) += hw/
+remote-pci-obj-$(CONFIG_MPQEMU) += qom/
+remote-pci-obj-$(CONFIG_MPQEMU) += backends/
+remote-pci-obj-$(CONFIG_MPQEMU) += block/
+remote-pci-obj-$(CONFIG_MPQEMU) += migration/
+remote-pci-obj-$(CONFIG_MPQEMU) += remote/
+remote-pci-obj-$(CONFIG_MPQEMU) += accel/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
+remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o
+remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o
+remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-parse.o
+
+##############################################################
+# remote-lsi-obj-y is code used to implement remote LSI device
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+
+#######################################################################
+# crypto-obj-y is code used by both qemu system emulation and qemu-img
+
 crypto-obj-y = crypto/
 
 io-obj-y = io/
Makefile.target +60 -1

100 lines not on this page · raw message

accel/Makefile.objs +2 -0
index 17e5ac6061..e312dd4f01 100644
@@ -3,3 +3,5 @@ obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += accel.o
backends/Makefile.objs +2 -0
index 28a847cd57..947cde39ac 100644
@@ -21,3 +21,5 @@ common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
 common-obj-$(CONFIG_GIO) += dbus-vmstate.o
 dbus-vmstate.o-cflags = $(GIO_CFLAGS)
 dbus-vmstate.o-libs = $(GIO_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o
block/Makefile.objs +2 -0
index 3635b6b4c1..3e7513967c 100644
@@ -74,3 +74,5 @@ io_uring.o-cflags  := $(LINUX_IO_URING_CFLAGS)
 io_uring.o-libs    := $(LINUX_IO_URING_LIBS)
 parallels.o-cflags := $(LIBXML2_CFLAGS)
 parallels.o-libs   := $(LIBXML2_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += stream.o
hw/Makefile.objs +7 -0
index 660e2b4373..af9235b6f2 100644
@@ -44,3 +44,10 @@ endif
 
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += core/
+remote-pci-obj-$(CONFIG_MPQEMU) += block/
+remote-pci-obj-$(CONFIG_MPQEMU) += pci/
+remote-pci-obj-$(CONFIG_MPQEMU) += nvram/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/
hw/block/Makefile.objs +2 -0
index 4b4a2b338d..0b4644f472 100644
@@ -16,3 +16,5 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
 
 obj-y += dataplane/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o
hw/core/Makefile.objs +18 -0
index 6215e7c208..e3e80848c8 100644
@@ -31,3 +31,21 @@ common-obj-$(CONFIG_OR_IRQ) += or-irq.o
 common-obj-$(CONFIG_SPLIT_IRQ) += split-irq.o
 common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
 common-obj-$(CONFIG_GENERIC_LOADER) += generic-loader.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev.o
+remote-pci-obj-$(CONFIG_MPQEMU) += bus.o
+remote-pci-obj-$(CONFIG_MPQEMU) += irq.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hotplug.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
+remote-pci-obj-$(CONFIG_MPQEMU) += fw-path-provider.o
+remote-pci-obj-$(CONFIG_MPQEMU) += reset.o
+remote-pci-obj-$(CONFIG_MPQEMU) += sysbus.o
+remote-pci-obj-$(CONFIG_MPQEMU) += loader.o
+remote-pci-obj-$(CONFIG_MPQEMU) += nmi.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o
+remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
+remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
+remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
hw/nvram/Makefile.objs +2 -0
index f3ad921382..4d2d809106 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_CHRP_NVRAM) += chrp_nvram.o
 common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
 common-obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o
 obj-$(CONFIG_PSERIES) += spapr_nvram.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += fw_cfg.o
hw/pci/Makefile.objs +4 -0
index c78f2fb24b..955be54472 100644
@@ -12,3 +12,7 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o
 
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o
+remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
hw/scsi/Makefile.objs +2 -0
index 54b36ed8b1..ef97770922 100644
@@ -13,3 +13,5 @@ obj-y += virtio-scsi.o virtio-scsi-dataplane.o
 obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o
 obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o
 endif
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += scsi-generic.o scsi-bus.o lsi53c895a.o scsi-disk.o emulation.o
migration/Makefile.objs +2 -0
index 0fc619e380..ad33d77d0b 100644
@@ -16,3 +16,5 @@ common-obj-$(CONFIG_RDMA) += rdma.o
 common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o
 
 rdma.o-libs := $(RDMA_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o
qom/Makefile.objs +3 -0
index 1b45d104ba..7e9455db90 100644
@@ -3,3 +3,6 @@ qom-obj-y += object_interfaces.o
 
 common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 storage-daemon-obj-y += qom-qmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
+remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
remote/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..a9b2256b2a
@@ -0,0 +1 @@
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
remote/remote-main.c new file +23 -0
new file mode 100644
index 0000000000..7c0764ad01
@@ -0,0 +1,23 @@
+/*
+ * Remote device initialization
+ *
+ * Copyright © 2018, 2020 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 <stdio.h>
+
+#include "qemu/module.h"
+
+int main(int argc, char *argv[])
+{
+    module_call_init(MODULE_INIT_QOM);
+
+    return 0;
+}
stubs/replay.c +4 -0
index 2e3feee6a9..9b53c0cb37 100644
@@ -102,3 +102,7 @@ int replay_get_instructions(void)
 void replay_account_executed_instructions(void)
 {
 }
+
+void replay_add_blocker(Error *reason)
+{
+}
Signature · 1 line
2.25.GIT
#76 lore raw

PATCH RESEND v6 35/36 multi-process: add the concept description to docs/devel/qemu-multiprocess

In reply to [email protected]

From: John G Johnson <[email protected]>

---
 MAINTAINERS                  |   1 +
 docs/devel/index.rst         |   1 +
 docs/devel/multi-process.rst | 957 +++++++++++++++++++++++++++++++++++
 3 files changed, 959 insertions(+)
 create mode 100644 docs/devel/multi-process.rst
MAINTAINERS +1 -0
index 216291f545..ed48615e15 100644
@@ -2879,6 +2879,7 @@ F: include/remote/iohub.h
 F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
+F: docs/devel/multi-process.rst
 
 Build and test automation
 -------------------------
docs/devel/index.rst +1 -0
index a9e1200dff..95cea0d474 100644
@@ -27,3 +27,4 @@ Contents:
    bitops
    reset
    s390-dasd-ipl
+   multi-process
docs/devel/multi-process.rst new file +957 -0

957 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#35 lore raw

PATCH RESEND v6 12/36 multi-process: add functions to synchronize proxy and remote endpoints

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

In some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process.

---
 include/io/mpqemu-link.h |  7 +++++
 io/mpqemu-link.c         | 61 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
include/io/mpqemu-link.h +7 -0
index af401e640c..ef95599bca 100644
@@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
 void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan);
 bool mpqemu_msg_valid(MPQemuMsg *msg);
 
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 #endif
io/mpqemu-link.c +61 -0

73 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#47 lore raw

PATCH RESEND v6 17/36 multi-process: introduce proxy object

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.

PCI Proxy Object registers as a PCI device with QEMU and forwards all PCI accesses to the remote process using the communication channel.

---
 MAINTAINERS                   |  3 ++
 hw/Makefile.objs              |  2 ++
 hw/proxy/Makefile.objs        |  1 +
 hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
 include/io/mpqemu-link.h      |  1 +
 6 files changed, 109 insertions(+)
 create mode 100644 hw/proxy/Makefile.objs
 create mode 100644 hw/proxy/qemu-proxy.c
 create mode 100644 include/hw/proxy/qemu-proxy.h
MAINTAINERS +3 -0
index 96f8d7ff19..3da3dcd311 100644
@@ -2866,6 +2866,9 @@ F: include/remote/machine.h
 F: remote/machine.c
 F: include/remote/memory.h
 F: remote/memory.c
+F: hw/proxy/Makefile.objs
+F: hw/proxy/qemu-proxy.c
+F: include/hw/proxy/qemu-proxy.h
 
 Build and test automation
 -------------------------
hw/Makefile.objs +2 -0
index af9235b6f2..7b489b12a5 100644
@@ -45,6 +45,8 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
+common-obj-$(CONFIG_MPQEMU) += proxy/
+
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..eb81624cf8
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +56 -0

56 lines not on this page · raw message

include/hw/proxy/qemu-proxy.h new file +46 -0

46 lines not on this page · raw message

include/io/mpqemu-link.h +1 -0
index d46cb81058..73cc59b874 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
+#include "sys/eventfd.h"
 #include "qom/object.h"
 #include "qemu/thread.h"
 #include "exec/cpu-common.h"
Signature · 1 line
2.25.GIT
#22 lore raw

PATCH RESEND v6 8/36 multi-process: Add stub functions to facilitate build of multi-process

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Add stub functions that are needed during compile time but not in runtime.
To avoid duplicate symbol while linking for monitor_get_fd, put in a separate file.

---
 MAINTAINERS            |  3 ++
 accel/stubs/kvm-stub.c |  5 +++
 accel/stubs/tcg-stub.c | 98 ++++++++++++++++++++++++++++++++++++++++++
 stubs/Makefile.objs    |  1 +
 stubs/audio.c          | 12 ++++++
 stubs/get-fd.c         | 10 +++++
 stubs/monitor.c        | 53 +++++++++++++++++++++--
 stubs/net-stub.c       | 31 +++++++++++++
 stubs/replay.c         | 14 ++++++
 stubs/vl-stub.c        | 79 ++++++++++++++++++++++++++++++++++
 stubs/vmstate.c        | 19 ++++++++
 stubs/xen-mapcache.c   | 22 ++++++++++
 12 files changed, 344 insertions(+), 3 deletions(-)
 create mode 100644 stubs/audio.c
 create mode 100644 stubs/get-fd.c
 create mode 100644 stubs/net-stub.c
 create mode 100644 stubs/vl-stub.c
 create mode 100644 stubs/xen-mapcache.c
MAINTAINERS +3 -0
index 2e700e6e64..c5fba124e4 100644
@@ -450,6 +450,7 @@ F: hw/pci-host/xen_igd_pt.c
 F: include/hw/block/dataplane/xen*
 F: include/hw/xen/
 F: include/sysemu/xen-mapcache.h
+F: stubs/xen-mapcache.c
 
 Guest CPU Cores (HAXM)
 ---------------------
@@ -1927,6 +1928,7 @@ F: include/hw/audio/
 F: tests/qtest/ac97-test.c
 F: tests/qtest/es1370-test.c
 F: tests/qtest/intel-hda-test.c
+F: stubs/audio.c
 
 Block layer core
 M: Kevin Wolf <[email protected]>
@@ -2159,6 +2161,7 @@ F: include/net/
 F: qemu-bridge-helper.c
 T: git https://github.com/jasowang/qemu.git net
 F: qapi/net.json
+F: stubs/net-stub.c
 
 Netmap network backend
 M: Luigi Rizzo <[email protected]>
accel/stubs/kvm-stub.c +5 -0
index 82f118d2df..baa6b38da4 100644
@@ -31,6 +31,7 @@ bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 bool kvm_ioeventfd_any_length_allowed;
 bool kvm_msi_use_devid;
+bool kvm_halt_in_kernel_allowed;
 
 int kvm_destroy_vcpu(CPUState *cpu)
 {
@@ -58,6 +59,10 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
 }
 
+void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu)
+{
+}
+
 int kvm_cpu_exec(CPUState *cpu)
 {
     abort();
accel/stubs/tcg-stub.c +98 -0

112 lines not on this page · raw message

stubs/Makefile.objs +1 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
 stub-obj-y += change-state-handler.o
 stub-obj-y += monitor.o
 stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
 stub-obj-y += notify-event.o
 stub-obj-y += qtest.o
 stub-obj-y += replay.o
stubs/audio.c new file +12 -0
new file mode 100644
index 0000000000..8ae3b0f568
@@ -0,0 +1,12 @@
+#include "qemu/osdep.h"
+#include "audio/audio.h"
+
+AudioState *audio_state_by_name(const char *name)
+{
+    return NULL;
+}
+
+const char *audio_get_id(QEMUSoundCard *card)
+{
+    return NULL;
+}
stubs/get-fd.c new file +10 -0
new file mode 100644
index 0000000000..6800dbe6d4
@@ -0,0 +1,10 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "monitor/monitor.h"
+#include "../monitor/monitor-internal.h"
+
+int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
+{
+    error_setg(errp, "only QEMU supports file descriptor passing");
+    return -1;
+}
stubs/monitor.c +50 -3

64 lines not on this page · raw message

stubs/net-stub.c new file +31 -0
new file mode 100644
index 0000000000..cb2274ba40
@@ -0,0 +1,31 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "net/net.h"
+
+int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
+                                 NetClientDriver type, int max)
+{
+    return -ENOSYS;
+}
+
+NetClientState *net_hub_port_find(int hub_id)
+{
+    return NULL;
+}
+
+int net_hub_id_for_client(NetClientState *nc, int *id)
+{
+    return -ENOSYS;
+}
+
+int qemu_show_nic_models(const char *arg, const char *const *models)
+{
+    return -ENOSYS;
+}
+
+int qemu_find_nic_model(NICInfo *nd, const char * const *models,
+                        const char *default_model)
+{
+    return -ENOSYS;
+}
+
stubs/replay.c +14 -0
index 5974ec1f50..2e3feee6a9 100644
@@ -88,3 +88,17 @@ int replay_read_random(void *buf, size_t len)
 {
     return 0;
 }
+
+bool replay_has_checkpoint(void)
+{
+    return false;
+}
+
+int replay_get_instructions(void)
+{
+    return 0;
+}
+
+void replay_account_executed_instructions(void)
+{
+}
stubs/vl-stub.c new file +79 -0

79 lines not on this page · raw message

stubs/vmstate.c +19 -0
index cc4fe41dfc..c7c015ac58 100644
@@ -1,7 +1,9 @@
 #include "qemu/osdep.h"
 #include "migration/vmstate.h"
+#include "migration/misc.h"
 
 const VMStateDescription vmstate_dummy = {};
+const VMStateInfo vmstate_info_timer;
 
 int vmstate_register_with_alias_id(VMStateIf *obj,
                                    uint32_t instance_id,
@@ -23,3 +25,20 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
 {
     return true;
 }
+
+void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
+{
+}
+
+void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev)
+{
+}
+
+void vmstate_register_ram_global(MemoryRegion *mr)
+{
+}
+
+bool migration_is_idle(void)
+{
+    return true;
+}
stubs/xen-mapcache.c new file +22 -0
new file mode 100644
index 0000000000..af5c031727
@@ -0,0 +1,22 @@
+#include "qemu/osdep.h"
+#include "exec/hwaddr.h"
+#include "exec/cpu-common.h"
+#include "sysemu/xen-mapcache.h"
+
+#ifdef CONFIG_XEN
+
+void xen_invalidate_map_cache_entry(uint8_t *buffer)
+{
+}
+
+uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, uint8_t lock, bool dma)
+{
+    return NULL;
+}
+
+ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
+{
+    return 0;
+}
+
+#endif
Signature · 1 line
2.25.GIT
#64 lore raw

PATCH RESEND v6 24/36 multi-process: Retrieve PCI info from remote process

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Retrieve PCI configuration info about the remote device and configure the Proxy PCI object based on the returned information

---
 hw/proxy/qemu-proxy.c    | 84 ++++++++++++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h | 10 +++++
 remote/remote-main.c     | 21 ++++++++++
 3 files changed, 115 insertions(+)
hw/proxy/qemu-proxy.c +84 -0
index a78694736b..730e28483e 100644
@@ -19,6 +19,8 @@
 #include "sysemu/kvm.h"
 #include "util/event_notifier-posix.c"
 
+static void probe_pci_info(PCIDevice *dev);
+
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op)
 {
@@ -182,8 +184,12 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
 {
     PCIProxyDev *dev = PCI_PROXY_DEV(device);
     PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    uint8_t *pci_conf = device->config;
     Error *local_err = NULL;
 
+    pci_conf[PCI_LATENCY_TIMER] = 0xff;
+    pci_conf[PCI_INTERRUPT_PIN] = 0x01;
+
     if (k->realize) {
         k->realize(dev, &local_err);
         if (local_err) {
@@ -196,6 +202,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     configure_memory_sync(dev->sync, dev->mpqemu_link);
 
     setup_irqfd(dev);
+
+    probe_pci_info(PCI_DEVICE(dev));
 }
 
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
@@ -291,3 +299,79 @@ const MemoryRegionOps proxy_default_ops = {
         .max_access_size = 1,
     },
 };
+
+static void probe_pci_info(PCIDevice *dev)
+{
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+    DeviceClass *dc = DEVICE_CLASS(pc);
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+    MPQemuLinkState *mpqemu_link = pdev->mpqemu_link;
+    MPQemuMsg msg, ret;
+    uint32_t orig_val, new_val, class;
+    uint8_t type;
+    int i, size;
+    char *name;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    msg.bytestream = 0;
+    msg.size = 0;
+    msg.cmd = GET_PCI_INFO;
+    mpqemu_msg_send(&msg, mpqemu_link->dev);
+
+    mpqemu_msg_recv(&ret, mpqemu_link->dev);
+
+    pc->vendor_id = ret.data1.ret_pci_info.vendor_id;
+    pc->device_id = ret.data1.ret_pci_info.device_id;
+    pc->class_id = ret.data1.ret_pci_info.class_id;
+    pc->subsystem_id = ret.data1.ret_pci_info.subsystem_id;
+
+    config_op_send(pdev, 11, &class, 1, PCI_CONFIG_READ);
+    switch (class) {
+    case PCI_BASE_CLASS_BRIDGE:
+        set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+        break;
+    case PCI_BASE_CLASS_STORAGE:
+        set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+        break;
+    case PCI_BASE_CLASS_NETWORK:
+        set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
+        break;
+    case PCI_BASE_CLASS_INPUT:
+        set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+        break;
+    case PCI_BASE_CLASS_DISPLAY:
+        set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+        break;
+    case PCI_BASE_CLASS_PROCESSOR:
+        set_bit(DEVICE_CATEGORY_CPU, dc->categories);
+        break;
+    default:
+        set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+        break;
+    }
+
+    for (i = 0; i < 6; i++) {
+        config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_READ);
+        new_val = 0xffffffff;
+        config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_WRITE);
+        config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_READ);
+        size = (~(new_val & 0xFFFFFFF0)) + 1;
+        config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_WRITE);
+        type = (new_val & 0x1) ?
+                   PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY;
+
+        if (size) {
+            pdev->region[i].dev = pdev;
+            pdev->region[i].present = true;
+            if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) {
+                pdev->region[i].memory = true;
+            }
+            name = g_strdup_printf("bar-region-%d", i);
+            memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev),
+                                  &proxy_default_ops, &pdev->region[i],
+                                  name, size);
+            pci_register_bar(dev, i, type, &pdev->region[i].mr);
+            g_free(name);
+        }
+    }
+}
include/io/mpqemu-link.h +10 -0
index 14e4be2bd0..102c736705 100644
@@ -48,6 +48,8 @@ typedef enum {
     BAR_WRITE,
     BAR_READ,
     SET_IRQFD,
+    GET_PCI_INFO,
+    RET_PCI_INFO,
     MAX,
 } mpqemu_cmd_t;
 
@@ -70,6 +72,13 @@ typedef struct {
     bool memory;
 } bar_access_msg_t;
 
+typedef struct {
+    uint16_t vendor_id;
+    uint16_t device_id;
+    uint16_t class_id;
+    uint16_t subsystem_id;
+} ret_pci_info_msg_t;
+
 /**
  * MPQemuMsg:
  * @cmd: The remote command
@@ -98,6 +107,7 @@ typedef struct {
         sync_sysmem_msg_t sync_sysmem;
         bar_access_msg_t bar_access;
         set_irqfd_msg_t set_irqfd;
+        ret_pci_info_msg_t ret_pci_info;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
remote/remote-main.c +21 -0
index 7cc1a60c3d..f5a479e9b2 100644
@@ -188,6 +188,24 @@ fail:
     PUT_REMOTE_WAIT(wait);
 }
 
+static void process_get_pci_info_msg(MPQemuLinkState *link, MPQemuMsg *msg)
+{
+    PCIDevice *pci_dev = LINK_TO_DEV(link);
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
+    MPQemuMsg ret = { 0 };
+
+    ret.cmd = RET_PCI_INFO;
+
+    ret.data1.ret_pci_info.vendor_id = pc->vendor_id;
+    ret.data1.ret_pci_info.device_id = pc->device_id;
+    ret.data1.ret_pci_info.class_id = pc->class_id;
+    ret.data1.ret_pci_info.subsystem_id = pc->subsystem_id;
+
+    ret.size = sizeof(ret.data1);
+
+    mpqemu_msg_send(&ret, link->dev);
+}
+
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan)
 {
@@ -246,6 +264,9 @@ static void process_msg(GIOCondition cond, MPQemuLinkState *link,
     case SET_IRQFD:
         process_set_irqfd_msg(LINK_TO_DEV(link), msg);
         break;
+    case GET_PCI_INFO:
+        process_get_pci_info_msg(link, msg);
+        break;
     default:
         error_setg(&err, "Unknown command in %s", print_pid_exec(pid_exec));
         goto finalize_loop;
Signature · 1 line
2.25.GIT
#32 lore raw

PATCH RESEND v6 11/36 multi-process: define mpqemu-link object

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

Defines mpqemu-link object which forms the communication link between QEMU & emulation program.
Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel.
Adds GMainLoop to handle events received on the communication channel.

---
 MAINTAINERS              |   2 +
 include/io/mpqemu-link.h | 127 ++++++++++++++++
 io/Makefile.objs         |   2 +
 io/mpqemu-link.c         | 312 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 443 insertions(+)
 create mode 100644 include/io/mpqemu-link.h
 create mode 100644 io/mpqemu-link.c
MAINTAINERS +2 -0
index 965f34d4f9..93ad693da4 100644
@@ -2857,6 +2857,8 @@ M: John G Johnson <[email protected]>
 S: Maintained
 F: remote/Makefile.objs
 F: remote/remote-main.c
+F: include/io/mpqemu-link.h
+F: io/mpqemu-link.c
 
 Build and test automation
 -------------------------
include/io/mpqemu-link.h new file +127 -0

127 lines not on this page · raw message

io/Makefile.objs +2 -0
index 9a20fce4ed..5875ab0697 100644
@@ -10,3 +10,5 @@ io-obj-y += channel-util.o
 io-obj-y += dns-resolver.o
 io-obj-y += net-listener.o
 io-obj-y += task.o
+
+io-obj-$(CONFIG_MPQEMU) += mpqemu-link.o
io/mpqemu-link.c new file +312 -0

312 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#67 lore raw

PATCH RESEND v6 26/36 multi-process: add parse_cmdline in remote process

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS          |  2 ++
 remote/Makefile.objs |  1 +
 remote/remote-main.c | 21 ++++++++++++-
 remote/remote-opts.c | 75 ++++++++++++++++++++++++++++++++++++++++++++
 remote/remote-opts.h | 15 +++++++++
 5 files changed, 113 insertions(+), 1 deletion(-)
 create mode 100644 remote/remote-opts.c
 create mode 100644 remote/remote-opts.h
MAINTAINERS +2 -0
index 198c9f69bc..6a4b5e16be 100644
@@ -2873,6 +2873,8 @@ F: include/hw/proxy/memory-sync.h
 F: hw/proxy/memory-sync.c
 F: include/remote/iohub.h
 F: remote/iohub.c
+F: remote/remote-opts.h
+F: remote/remote-opts.c
 
 Build and test automation
 -------------------------
remote/Makefile.objs +1 -0
index ed3e5bd8c4..74c3396786 100644
@@ -1,4 +1,5 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-opts.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
 remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
 remote-pci-obj-$(CONFIG_MPQEMU) += ../util/machine-notify.o
remote/remote-main.c +20 -1
index f5a479e9b2..b37802151a 100644
@@ -24,6 +24,7 @@
 #include "io/mpqemu-link.h"
 #include "qapi/error.h"
 #include "qemu/main-loop.h"
+#include "qemu/cutils.h"
 #include "sysemu/cpus.h"
 #include "qemu-common.h"
 #include "hw/pci/pci.h"
@@ -37,6 +38,7 @@
 #include "exec/memattrs.h"
 #include "exec/address-spaces.h"
 #include "remote/iohub.h"
+#include "remote-opts.h"
 
 static void process_msg(GIOCondition cond, MPQemuLinkState *link,
                         MPQemuChannel *chan);
@@ -289,6 +291,7 @@ finalize_loop:
 int main(int argc, char *argv[])
 {
     Error *err = NULL;
+    int fd = -1;
 
     module_call_init(MODULE_INIT_QOM);
 
@@ -307,6 +310,13 @@ int main(int argc, char *argv[])
 
     current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
 
+    qemu_add_opts(&qemu_device_opts);
+    qemu_add_opts(&qemu_drive_opts);
+    qemu_add_drive_opts(&qemu_legacy_drive_opts);
+    qemu_add_drive_opts(&qemu_common_drive_opts);
+    qemu_add_drive_opts(&qemu_drive_opts);
+    qemu_add_drive_opts(&bdrv_runtime_opts);
+
     mpqemu_link = mpqemu_link_create();
     if (!mpqemu_link) {
         printf("Could not create MPQemu link pid %d, exec_name %s",
@@ -314,7 +324,16 @@ int main(int argc, char *argv[])
         return -1;
     }
 
-    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO);
+    fd = qemu_parse_fd(argv[1]);
+    if (fd == -1) {
+        printf("Failed to parse fd for remote process pid %d, exec_name %s\n",
+               getpid(), __progname);
+        return -EINVAL;
+    }
+
+    parse_cmdline(argc - 2, argv + 2, NULL);
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
remote/remote-opts.c new file +75 -0

75 lines not on this page · raw message

remote/remote-opts.h new file +15 -0
new file mode 100644
index 0000000000..263d428060
@@ -0,0 +1,15 @@
+/*
+ * Copyright © 2018, 2020 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_OPTS_H
+#define REMOTE_OPTS_H
+
+void parse_cmdline(int argc, char **argv, char **envp);
+
+#endif
+
Signature · 1 line
2.25.GIT
#41 lore raw

PATCH RESEND v6 14/36 multi-process: setup a machine object for remote device process

In reply to [email protected]

From: Jagannathan Raman <[email protected]>

remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.

---
 MAINTAINERS                   |  2 +
 Makefile.objs                 |  1 +
 exec.c                        |  3 +-
 include/exec/address-spaces.h |  2 +
 include/remote/machine.h      | 30 +++++++++++++
 remote/Makefile.objs          |  2 +
 remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
 remote/remote-main.c          |  7 +++
 util/Makefile.objs            |  2 +
 9 files changed, 131 insertions(+), 2 deletions(-)
 create mode 100644 include/remote/machine.h
 create mode 100644 remote/machine.c
MAINTAINERS +2 -0
index 0cda5ee06a..09764e461c 100644
@@ -2861,6 +2861,8 @@ F: include/io/mpqemu-link.h
 F: io/mpqemu-link.c
 F: include/remote/pcihost.h
 F: remote/pcihost.c
+F: include/remote/machine.h
+F: remote/machine.c
 
 Build and test automation
 -------------------------
Makefile.objs +1 -0
index f6654633b4..ff3f06b146 100644
@@ -31,6 +31,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
+remote-pci-obj-$(CONFIG_MPQEMU) += util/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
exec.c +1 -2
index d0ac9545f4..5b1e414099 100644
@@ -161,7 +161,6 @@ typedef struct subpage_t {
 #define PHYS_SECTION_UNASSIGNED 0
 
 static void io_mem_init(void);
-static void memory_map_init(void);
 static void tcg_log_global_after_sync(MemoryListener *listener);
 static void tcg_commit(MemoryListener *listener);
 
@@ -2963,7 +2962,7 @@ static void tcg_commit(MemoryListener *listener)
     tlb_flush(cpuas->cpu);
 }
 
-static void memory_map_init(void)
+void memory_map_init(void)
 {
     system_memory = g_malloc(sizeof(*system_memory));
 
include/exec/address-spaces.h +2 -0
index db8bfa9a92..56a877b7ba 100644
@@ -33,6 +33,8 @@ MemoryRegion *get_system_memory(void);
  */
 MemoryRegion *get_system_io(void);
 
+void memory_map_init(void);
+
 extern AddressSpace address_space_memory;
 extern AddressSpace address_space_io;
 
include/remote/machine.h new file +30 -0
new file mode 100644
index 0000000000..7e9bdbe28e
@@ -0,0 +1,30 @@
+/*
+ * Remote machine configuration
+ *
+ * Copyright © 2018, 2020 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_MACHINE_H
+#define REMOTE_MACHINE_H
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "hw/boards.h"
+#include "remote/pcihost.h"
+#include "qemu/notify.h"
+
+typedef struct RemMachineState {
+    MachineState parent_obj;
+
+    RemPCIHost *host;
+} RemMachineState;
+
+#define TYPE_REMOTE_MACHINE "remote-machine"
+#define REMOTE_MACHINE(obj) \
+    OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE)
+
+#endif
remote/Makefile.objs +2 -0
index 2757f5a265..55f405d048 100644
@@ -1,2 +1,4 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
+remote-pci-obj-$(CONFIG_MPQEMU) += ../util/machine-notify.o
remote/machine.c new file +84 -0

84 lines not on this page · raw message

remote/remote-main.c +7 -0
index 7c0764ad01..ecf30e0cba 100644
@@ -14,10 +14,17 @@
 #include <stdio.h>
 
 #include "qemu/module.h"
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#include "hw/boards.h"
+#include "hw/qdev-core.h"
+#include "qemu/main-loop.h"
 
 int main(int argc, char *argv[])
 {
     module_call_init(MODULE_INIT_QOM);
 
+    current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
+
     return 0;
 }
util/Makefile.objs +2 -0
index fe339c2636..d8f0061157 100644
@@ -64,3 +64,5 @@ util-obj-$(CONFIG_GIO) += dbus.o
 dbus.o-cflags = $(GIO_CFLAGS)
 dbus.o-libs = $(GIO_LIBS)
 util-obj-$(CONFIG_USER_ONLY) += selfmap.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += notify.o
Signature · 1 line
2.25.GIT
#69 lore raw

PATCH RESEND v6 28/36 multi-process: send heartbeat messages to remote

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

In order to detect remote processes which are hung, the proxy periodically sends heartbeat messages to confirm if the remote process is alive

---
 hw/proxy/qemu-proxy.c         | 86 +++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |  3 ++
 include/io/mpqemu-link.h      |  1 +
 io/mpqemu-link.c              |  5 ++
 4 files changed, 95 insertions(+)
hw/proxy/qemu-proxy.c +86 -0
index 730e28483e..162014353f 100644
@@ -21,6 +21,78 @@
 
 static void probe_pci_info(PCIDevice *dev);
 
+static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
+{
+    /* TODO: Add proper handler. */
+    printf("Child (pid %d) is dead? Signal is %d, Exit code is %d.\n",
+           siginfo->si_pid, siginfo->si_signo, siginfo->si_code);
+}
+
+static void hb_msg(PCIProxyDev *dev)
+{
+    DeviceState *ds = DEVICE(dev);
+    MPQemuMsg msg = { 0 };
+    uint64_t ret;
+
+    if (event_notifier_get_fd(&dev->en_ping) == -1) {
+        return;
+    }
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.num_fds = 1;
+    msg.cmd = PROXY_PING;
+    msg.bytestream = 0;
+    msg.size = 0;
+    msg.fds[0] = event_notifier_get_fd(&dev->en_ping);
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->com);
+
+    ret = wait_for_remote(msg.fds[0]);
+
+    if (ret) {
+        printf("Lost contact with remote device %s\n", ds->id);
+        /* TODO: Initiate error recovery */
+    }
+}
+
+#define NOP_INTERVAL 1000
+
+static void remote_ping(void *opaque)
+{
+    PCIProxyDev *dev = opaque;
+
+    hb_msg(dev);
+
+    timer_mod(dev->hb_timer,
+              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+}
+
+static void start_hb_timer(PCIProxyDev *dev)
+{
+    dev->hb_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
+                                 remote_ping,
+                                 dev);
+
+    timer_mod(dev->hb_timer,
+              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+}
+
+static void stop_hb_timer(PCIProxyDev *dev)
+{
+    timer_del(dev->hb_timer);
+    timer_free(dev->hb_timer);
+}
+
+static void set_sigchld_handler(void)
+{
+    struct sigaction sa_sigterm;
+    memset(&sa_sigterm, 0, sizeof(sa_sigterm));
+    sa_sigterm.sa_sigaction = childsig_handler;
+    sa_sigterm.sa_flags = SA_SIGINFO | SA_NOCLDWAIT | SA_NOCLDSTOP;
+    sigaction(SIGCHLD, &sa_sigterm, NULL);
+}
+
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op)
 {
@@ -204,6 +276,19 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     setup_irqfd(dev);
 
     probe_pci_info(PCI_DEVICE(dev));
+
+    set_sigchld_handler();
+
+    event_notifier_init(&dev->en_ping, 0);
+
+    start_hb_timer(dev);
+}
+
+static void pci_proxy_dev_exit(PCIDevice *pdev)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(pdev);
+
+    stop_hb_timer(dev);
 }
 
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
@@ -211,6 +296,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
     k->realize = pci_proxy_dev_realize;
+    k->exit = pci_proxy_dev_exit;
     k->config_read = pci_proxy_read_config;
     k->config_write = pci_proxy_write_config;
 }
include/hw/proxy/qemu-proxy.h +3 -0
index 0d8ec6d686..26f0a41110 100644
@@ -55,6 +55,9 @@ struct PCIProxyDev {
     EventNotifier intr;
     EventNotifier resample;
 
+    EventNotifier en_ping;
+    QEMUTimer *hb_timer;
+
     int socket;
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
include/io/mpqemu-link.h +1 -0
index 102c736705..45ea1fcafa 100644
@@ -50,6 +50,7 @@ typedef enum {
     SET_IRQFD,
     GET_PCI_INFO,
     RET_PCI_INFO,
+    PROXY_PING,
     MAX,
 } mpqemu_cmd_t;
 
io/mpqemu-link.c +5 -0
index ea519a980e..91a3395566 100644
@@ -394,6 +394,11 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
             return false;
         }
         break;
+    case PROXY_PING:
+        if (msg->size != 0) {
+            return false;
+        }
+        break;
     default:
         break;
     }
Signature · 1 line
2.25.GIT
#77 lore raw

PATCH RESEND v6 36/36 multi-process: add configure and usage information

In reply to [email protected]

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS                          |  2 +
 docs/multi-process.rst               | 85 +++++++++++++++++++++++++
 scripts/mpqemu-launcher-perf-mode.py | 92 ++++++++++++++++++++++++++++
 scripts/mpqemu-launcher.py           | 53 ++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 docs/multi-process.rst
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
index ed48615e15..8ff3bfae6a 100644
@@ -2880,6 +2880,8 @@ F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
 F: docs/devel/multi-process.rst
+F: scripts/mpqemu-launcher.py
+F: scripts/mpqemu-launcher-perf-mode.py
 
 Build and test automation
 -------------------------
docs/multi-process.rst new file +85 -0

85 lines not on this page · raw message

scripts/mpqemu-launcher-perf-mode.py new file +92 -0

92 lines not on this page · raw message

scripts/mpqemu-launcher.py new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.25.GIT
#78 lore raw

Re: [PATCH RESEND v6 36/36] multi-process: add configure and usage information

Does multi-process support on Windows?
I found it use mmap and unix socket for inter-process communication, that may not support under Windows.
And also, can the python script be replaced by C implementation?

Quoted 359 lines · On Thu, Apr 23, 2020 at 12:38 PM <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS                          |  2 +
 docs/multi-process.rst               | 85 +++++++++++++++++++++++++
 scripts/mpqemu-launcher-perf-mode.py | 92 ++++++++++++++++++++++++++++
 scripts/mpqemu-launcher.py           | 53 ++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 docs/multi-process.rst
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
index ed48615e15..8ff3bfae6a 100644
@@ -2880,6 +2880,8 @@ F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
 F: docs/devel/multi-process.rst
+F: scripts/mpqemu-launcher.py
+F: scripts/mpqemu-launcher-perf-mode.py
 
 Build and test automation
 -------------------------
docs/multi-process.rst new file +21 -0
new file mode 100644
index 0000000000..8387d6c691
@@ -0,0 +1,85 @@
+Multi-process QEMU
+==================
+
+This document describes how to configure and use multi-process qemu.
+For the design document refer to docs/devel/qemu-multiprocess.
+
+1) Configuration
+----------------
+
+To enable support for multi-process add --enable-mpqemu
+to the list of options for the "configure" script.
+
+
+2) Usage
+--------
+
+Multi-process QEMU requires an orchestrator to launch. Please refer to a
+light-weight python based orchestrator for mpqemu in
+scripts/mpqemu-launcher.py to lauch QEMU in multi-process mode.
+
+scripts/mpqemu-launcher-perf-mode.py launches in "perf" mode. In this

mode,
+the same QEMU process connects to multiple remote devices, each emulated in

docs/multi-process.rst new file +3 -0
+a separate process.
+
+As of now, we only support the emulation of lsi53c895a in a separate

process.

docs/multi-process.rst new file +21 -0
+
+Following is a description of command-line used to launch mpqemu.
+
+* Orchestrator:
+
+  - The Orchestrator creates a unix socketpair
+
+  - It launches the remote process and passes one of the
+    sockets to it via command-line.
+
+  - It then launches QEMU and specifies the other socket as an option
+    to the Proxy device object
+
+* Remote Process:
+
+  - The first command-line option in the remote process is one of the
+    sockets created by the Orchestrator
+
+  - The remaining options are no different from how one launches QEMU with
+    devices. The only other requirement is each PCI device must have a
+    unique ID specified to it. This is needed to pair remote device with

the

docs/multi-process.rst new file +17 -0
+    Proxy object.
+
+  - Example command-line for the remote process is as follows:
+
+      /usr/bin/qemu-scsu-dev 4                                           \
+      -device lsi53c895a,id=lsi0                                         \
+      -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2           \
+      -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0
+
+* QEMU:
+
+  - Since parts of the RAM are shared between QEMU & remote process, a
+    memory-backend-memfd is required to facilitate this, as follows:
+
+    -object memory-backend-memfd,id=mem,size=2G
+
+  - A "pci-proxy-dev" device is created for each of the PCI devices

emulated
+ in the remote process. A "socket" sub-option specifies the other end
of
+ unix channel created by orchestrator. The "id" sub-option must be
specified

docs/multi-process.rst new file +9 -0
+    and should be the same as the "id" specified for the remote PCI device
+
+  - Example commandline for QEMU is as follows:
+
+      -device pci-proxy-dev,id=lsi0,socket=3
+
+* Monitor / QMP:
+
+  - The remote process supports QEMU monitor. It could be specified using

the

docs/multi-process.rst new file +3 -0
+    "-monitor" or "-qmp" command-line options
+
+  - As an example, one could connect to the monitor by adding the

following

docs/multi-process.rst new file +8 -0
+    to the command-line of the remote process
+
+      -monitor unix:/home/qmp-sock,server,nowait
+
+  - The user could connect to the monitor using the qmp script or using
+    "socat" as outlined below:
+
+      socat /home/qmp-sock stdio
scripts/mpqemu-launcher-perf-mode.py new file +92 -0
new file mode 100755
index 0000000000..2733424c76
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy_1, remote_1 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+proxy_2, remote_2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+proxy_3, remote_3 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd_1 = [ PROC_REMOTE,
      \
+                 str(remote_1.fileno()),
     \
+                 '-device', 'lsi53c895a,id=lsi1',
      \
+                 '-drive', 'id=drive_image1,'
      \
+                               'file=/build/ol7-nvme-test-1.qcow2',
      \
+                 '-device', 'scsi-hd,id=drive1,drive=drive_image1,'
      \
+                                'bus=lsi1.0,scsi-id=0',
      \
+               ]
+
+remote_cmd_2 = [ PROC_REMOTE,
      \
+                 str(remote_2.fileno()),
     \
+                 '-device', 'lsi53c895a,id=lsi2',
      \
+                 '-drive', 'id=drive_image2,'
      \
+                               'file=/build/ol7-nvme-test-2.qcow2',
      \
+                 '-device', 'scsi-hd,id=drive2,drive=drive_image2,'
      \
+                                'bus=lsi2.0,scsi-id=0'
     \
+               ]
+
+remote_cmd_3 = [ PROC_REMOTE,
      \
+                 str(remote_3.fileno()),
     \
+                 '-device', 'lsi53c895a,id=lsi3',
      \
+                 '-drive', 'id=drive_image3,'
      \
+                               'file=/build/ol7-nvme-test-3.qcow2',
      \
+                 '-device', 'scsi-hd,id=drive3,drive=drive_image3,'
      \
+                                'bus=lsi3.0,scsi-id=0'
     \
+               ]
+
+proxy_cmd = [ PROC_QEMU,
     \
+              '-name', 'OL7.4',
      \
+              '-machine', 'q35,accel=kvm',
     \
+              '-smp', 'sockets=1,cores=1,threads=1',
     \
+              '-m', '2048',
      \
+              '-object', 'memory-backend-memfd,id=sysmem-file,size=2G',
      \
+              '-numa', 'node,memdev=sysmem-file',
      \
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
      \
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
      \
+                            'file=/home/ol7-hdd-1.qcow2',
      \
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
     \
+                             'bus=virtio_scsi_pci0.0',
     \
+              '-boot', 'd',
      \
+              '-vnc', ':0',
      \
+              '-device', 'pci-proxy-dev,id=lsi1,'
      \
+                             'socket='+str(proxy_1.fileno()),
      \
+              '-device', 'pci-proxy-dev,id=lsi2,'
      \
+                             'socket='+str(proxy_2.fileno()),
      \
+              '-device', 'pci-proxy-dev,id=lsi3,'
      \
+                             'socket='+str(proxy_3.fileno())
     \
+            ]
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_1
+    print('Launching Remote process 1');
+    process = subprocess.Popen(remote_cmd_1, pass_fds=[remote_1.fileno()])
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_2
+    print('Launching Remote process 2');
+    process = subprocess.Popen(remote_cmd_2, pass_fds=[remote_2.fileno()])
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_3
+    print('Launching Remote process 3');
+    process = subprocess.Popen(remote_cmd_3, pass_fds=[remote_3.fileno()])
+    os._exit(0)
+
+
+print('Launching Proxy process');
+process = subprocess.Popen(proxy_cmd, pass_fds=[proxy_1.fileno(),
      \
+                           proxy_2.fileno(), proxy_3.fileno()])
scripts/mpqemu-launcher.py new file +16 -0
new file mode 100755
index 0000000000..81e370663e
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy, remote = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd = [ PROC_REMOTE,
      \
+               str(remote.fileno()),
     \
+               '-device', 'lsi53c895a,id=lsi1',
      \
+               '-drive',

'id=drive_image1,file=/build/ol7-nvme-test-1.qcow2', \
+ '-device',
'scsi-hd,id=drive1,drive=drive_image1,bus=lsi1.0,' \

scripts/mpqemu-launcher.py new file +3 -0
+                              'scsi-id=0',
     \
+               '-device', 'lsi53c895a,id=lsi2',
      \
+               '-drive',

'id=drive_image2,file=/build/ol7-nvme-test-2.qcow2', \
+ '-device',
'scsi-hd,id=drive2,drive=drive_image2,bus=lsi2.0,' \

scripts/mpqemu-launcher.py new file +18 -0
+                              'scsi-id=0'
      \
+             ]
+
+proxy_cmd = [ PROC_QEMU,
     \
+              '-name', 'OL7.4',
      \
+              '-machine', 'q35,accel=kvm',
     \
+              '-smp', 'sockets=1,cores=1,threads=1',
     \
+              '-m', '2048',
      \
+              '-object', 'memory-backend-memfd,id=sysmem-file,size=2G',
      \
+              '-numa', 'node,memdev=sysmem-file',
      \
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
      \
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
      \
+                            'file=/home/ol7-hdd-1.qcow2',
      \
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
     \
+                             'bus=virtio_scsi_pci0.0',
     \
+              '-boot', 'd',
      \
+              '-vnc', ':0',
      \
+              '-device',

'pci-proxy-dev,id=lsi1,socket='+str(proxy.fileno()), \
+ '-device',
'pci-proxy-dev,id=lsi2,socket='+str(proxy.fileno()) \

scripts/mpqemu-launcher.py new file +13 -1
+            ]
+
+
+pid = os.fork();
+
+if pid:
+    # In Proxy
+    print('Launching QEMU with Proxy object');
+    process = subprocess.Popen(proxy_cmd, pass_fds=[proxy.fileno()])
+else:
+    # In remote
+    print('Launching Remote process');
+    process = subprocess.Popen(remote_cmd, pass_fds=[remote.fileno()])
--

2.25.GIT

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#11 lore raw

Re: [PATCH RESEND v6 02/36] multi-process: Refactor machine_init and exit notifiers

In reply to [email protected]
Quoted 136 lines · On 4/23/20 6:13 AM, [email protected] wrote:

From: Elena Ufimtseva <[email protected]>

Relocate machine_int and exit notifiers into common code

---
  MAINTAINERS                 |  1 +
  Makefile.objs               |  1 +
  include/sysemu/sysemu.h     |  2 ++
  softmmu/vl.c                | 42 ----------------------
  stubs/Makefile.objs         |  2 ++
  stubs/machine-init-add.c    |  7 ++++
  stubs/machine-init-done.c   |  5 ++-
  stubs/machine-init-remove.c |  8 +++++
  util/machine-notify.c       | 69 +++++++++++++++++++++++++++++++++++++
  9 files changed, 92 insertions(+), 45 deletions(-)

create mode 100644 stubs/machine-init-add.c
create mode 100644 stubs/machine-init-remove.c
create mode 100644 util/machine-notify.c

MAINTAINERS +1 -0
index 8cbc1fac2b..04b19ac56c 100644
@@ -2133,6 +2133,7 @@ F: util/qemu-timer.c
  F: softmmu/vl.c
  F: softmmu/main.c
  F: qapi/run-state.json
+F: util/machine-notify.c
 
  Human Monitor (HMP)
  M: Dr. David Alan Gilbert <[email protected]>
Makefile.objs +1 -0
index a7c967633a..bfb9271862 100644
@@ -79,6 +79,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
  common-obj-$(CONFIG_FDT) += device_tree.o
 
  common-obj-y += qapi/
+common-obj-y += util/machine-notify.o
 
  endif # CONFIG_SOFTMMU
 
include/sysemu/sysemu.h +2 -0
index ef81302e1a..2438dd7bea 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
  void qemu_add_exit_notifier(Notifier *notify);
  void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
  extern bool machine_init_done;
 
  void qemu_add_machine_init_done_notifier(Notifier *notify);
  void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
  extern int autostart;
 
softmmu/vl.c +0 -42
index 32c0047889..39cbb6b50d 100644
@@ -172,12 +172,6 @@ int icount_align_option;
  QemuUUID qemu_uuid;
  bool qemu_uuid_set;
 
-static NotifierList exit_notifiers =
-    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
-
-static NotifierList machine_init_done_notifiers =
-    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
-
  bool xen_allowed;
  uint32_t xen_domid;
  enum xen_mode xen_mode = XEN_EMULATE;
@@ -2325,21 +2319,6 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
      return mc;
  }
 
-void qemu_add_exit_notifier(Notifier *notify)
-{
-    notifier_list_add(&exit_notifiers, notify);
-}
-
-void qemu_remove_exit_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_exit_notifiers(void)
-{
-    notifier_list_notify(&exit_notifiers, NULL);
-}
-
  static const char *pid_file;
  static Notifier qemu_unlink_pidfile_notifier;
 
@@ -2350,27 +2329,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
      }
  }
 
-bool machine_init_done;
-
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_list_add(&machine_init_done_notifiers, notify);
-    if (machine_init_done) {
-        notify->notify(notify, NULL);
-    }
-}
-
-void qemu_remove_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_machine_init_done_notifiers(void)
-{
-    machine_init_done = true;
-    notifier_list_notify(&machine_init_done_notifiers, NULL);
-}
-
  static const QEMUOption *lookup_opt(int argc, char **argv,
                                      const char **poptarg, int *poptind)
  {
stubs/Makefile.objs +0 -0
index 45be5dc0ed..f884bb6180 100644

stubs/Makefile.objs stub-obj-y += pci-host-piix.o · line 47

Quoted 5 lines
stubs/Makefile.objs +2 -0
@@ -43,4 +43,6 @@ stub-obj-y += pci-host-piix.o
  stub-obj-y += ram-block.o
  stub-obj-y += ramfb.o
  stub-obj-y += fw_cfg.o
+stub-obj-y += machine-init-add.o
+stub-obj-y += machine-init-remove.o

Trying to understand why we have this stub here...

So per commit 07a32d6b962 it is required by the chardev driver.

Marc-André, what do you think about extracting chardev_machine_*() to chardev/char-sysemu.c and simply add to chardev/Makefile:

chardev-obj-$(CONFIG_SOFTMMU) += char-sysemu.o

Quoted 117 lines
stubs/Makefile.objs +0 -0
  stub-obj-$(CONFIG_SOFTMMU) += semihost.o
stubs/machine-init-add.c new file +7 -0
new file mode 100644
index 0000000000..520dcb9801
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+}
+
stubs/machine-init-done.c +2 -3
index cd8e81392d..a34d838f7a 100644
@@ -3,6 +3,5 @@
 
  bool machine_init_done = true;
 
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-}
+NotifierList machine_init_done_notifiers =
+    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
stubs/machine-init-remove.c new file +8 -0
new file mode 100644
index 0000000000..30aee27c2d
@@ -0,0 +1,8 @@
+#include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
+
+
util/machine-notify.c new file +69 -0
new file mode 100644
index 0000000000..718af79335
@@ -0,0 +1,69 @@
+/*
+ * Machine notifiers.
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+
+static NotifierList machine_init_done_notifiers =
+    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
+
+static NotifierList exit_notifiers =
+    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
+
+bool machine_init_done;
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_list_add(&machine_init_done_notifiers, notify);
+    if (machine_init_done) {
+        notify->notify(notify, NULL);
+    }
+}
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_machine_init_done_notifiers(void)
+{
+    machine_init_done = true;
+    notifier_list_notify(&machine_init_done_notifiers, NULL);
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    notifier_list_add(&exit_notifiers, notify);
+}
+
+void qemu_remove_exit_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_exit_notifiers(void)
+{
+    notifier_list_notify(&exit_notifiers, NULL);
+}
#18 lore raw

Re: [PATCH RESEND v6 06/36] monitor: destaticize HMP commands

In reply to [email protected]

Why 'destaticize HMP commands'?

Quoted 11 lines · On 4/23/20 6:13 AM, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

---
  hmp-commands.hx            |  4 +-
  monitor/misc.c             | 76 +++++++++++++++++++-------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++
  3 files changed, 78 insertions(+), 40 deletions(-)
#19 lore raw

Re: [PATCH RESEND v6 06/36] monitor: destaticize HMP commands

Quoted 5 lines · Philippe Mathieu-Daudé

Why 'destaticize HMP commands’?

Hi Philippe,

Both QEMU & the remote process links the QMP code. QEMU uses all of the QMP commands, whereas, the remote process only uses a subset of this. Therefore, the ‘static’ functions which don’t have a reference cause build errors (like defined but not used). Therefore, we decided to destaticize the ones that are causing the build failure.

On a different note, Dave had previously suggested destacizing only the HMP functions used by the remote process. However, we found out that this is not possible because without all these functions, the build error still reproduces. We did confirm that all the functions we have destaticized are necessary to help with build of the remote process.

Thank you very much!
--
Jag

Quoted 13 lines · On 4/23/20 6:13 AM, [email protected] wrote:
Quoted 10 lines

From: Jagannathan Raman <[email protected]>

---
 hmp-commands.hx            |  4 +-
 monitor/misc.c             | 76 +++++++++++++++++++-------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++
 3 files changed, 78 insertions(+), 40 deletions(-)
#79 lore raw

Re: [PATCH RESEND v6 36/36] multi-process: add configure and usage information

In reply to 罗勇刚(Yonggang Luo)
Quoted 6 lines · 罗勇刚(Yonggang Luo)

Does multi-process support on Windows?
I found it use mmap and unix socket for inter-process communication, that may not support under Windows.

Hi Yonggang,

We have only tested this on Linux till now. Are you using QEMU with Windows?

Quoted 1 line

And also, can the python script be replaced by C implementation?

The functionality in the python script would eventually move to libvirt. The python script is a temporary measure.

Thank you very much!
—
Jag

Quoted 291 lines · On Thu, Apr 23, 2020 at 12:38 PM <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS                          |  2 +
 docs/multi-process.rst               | 85 +++++++++++++++++++++++++
 scripts/mpqemu-launcher-perf-mode.py | 92 ++++++++++++++++++++++++++++
 scripts/mpqemu-launcher.py           | 53 ++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 docs/multi-process.rst
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
index ed48615e15..8ff3bfae6a 100644
@@ -2880,6 +2880,8 @@ F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
 F: docs/devel/multi-process.rst
+F: scripts/mpqemu-launcher.py
+F: scripts/mpqemu-launcher-perf-mode.py
 
 Build and test automation
 -------------------------
docs/multi-process.rst new file +85 -0
new file mode 100644
index 0000000000..8387d6c691
@@ -0,0 +1,85 @@
+Multi-process QEMU
+==================
+
+This document describes how to configure and use multi-process qemu.
+For the design document refer to docs/devel/qemu-multiprocess.
+
+1) Configuration
+----------------
+
+To enable support for multi-process add --enable-mpqemu
+to the list of options for the "configure" script.
+
+
+2) Usage
+--------
+
+Multi-process QEMU requires an orchestrator to launch. Please refer to a
+light-weight python based orchestrator for mpqemu in
+scripts/mpqemu-launcher.py to lauch QEMU in multi-process mode.
+
+scripts/mpqemu-launcher-perf-mode.py launches in "perf" mode. In this mode,
+the same QEMU process connects to multiple remote devices, each emulated in
+a separate process.
+
+As of now, we only support the emulation of lsi53c895a in a separate process.
+
+Following is a description of command-line used to launch mpqemu.
+
+* Orchestrator:
+
+  - The Orchestrator creates a unix socketpair
+
+  - It launches the remote process and passes one of the
+    sockets to it via command-line.
+
+  - It then launches QEMU and specifies the other socket as an option
+    to the Proxy device object
+
+* Remote Process:
+
+  - The first command-line option in the remote process is one of the
+    sockets created by the Orchestrator
+
+  - The remaining options are no different from how one launches QEMU with
+    devices. The only other requirement is each PCI device must have a
+    unique ID specified to it. This is needed to pair remote device with the
+    Proxy object.
+
+  - Example command-line for the remote process is as follows:
+
+      /usr/bin/qemu-scsu-dev 4                                           \
+      -device lsi53c895a,id=lsi0                                         \
+      -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2           \
+      -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0
+
+* QEMU:
+
+  - Since parts of the RAM are shared between QEMU & remote process, a
+    memory-backend-memfd is required to facilitate this, as follows:
+
+    -object memory-backend-memfd,id=mem,size=2G
+
+  - A "pci-proxy-dev" device is created for each of the PCI devices emulated
+    in the remote process. A "socket" sub-option specifies the other end of
+    unix channel created by orchestrator. The "id" sub-option must be specified
+    and should be the same as the "id" specified for the remote PCI device
+
+  - Example commandline for QEMU is as follows:
+
+      -device pci-proxy-dev,id=lsi0,socket=3
+
+* Monitor / QMP:
+
+  - The remote process supports QEMU monitor. It could be specified using the
+    "-monitor" or "-qmp" command-line options
+
+  - As an example, one could connect to the monitor by adding the following
+    to the command-line of the remote process
+
+      -monitor unix:/home/qmp-sock,server,nowait
+
+  - The user could connect to the monitor using the qmp script or using
+    "socat" as outlined below:
+
+      socat /home/qmp-sock stdio
scripts/mpqemu-launcher-perf-mode.py new file +92 -0
new file mode 100755
index 0000000000..2733424c76
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy_1, remote_1 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+proxy_2, remote_2 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+proxy_3, remote_3 = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd_1 = [ PROC_REMOTE,                                                  \
+                 str(remote_1.fileno()),                                       \
+                 '-device', 'lsi53c895a,id=lsi1',                              \
+                 '-drive', 'id=drive_image1,'                                  \
+                               'file=/build/ol7-nvme-test-1.qcow2',            \
+                 '-device', 'scsi-hd,id=drive1,drive=drive_image1,'            \
+                                'bus=lsi1.0,scsi-id=0',                        \
+               ]
+
+remote_cmd_2 = [ PROC_REMOTE,                                                  \
+                 str(remote_2.fileno()),                                       \
+                 '-device', 'lsi53c895a,id=lsi2',                              \
+                 '-drive', 'id=drive_image2,'                                  \
+                               'file=/build/ol7-nvme-test-2.qcow2',            \
+                 '-device', 'scsi-hd,id=drive2,drive=drive_image2,'            \
+                                'bus=lsi2.0,scsi-id=0'                         \
+               ]
+
+remote_cmd_3 = [ PROC_REMOTE,                                                  \
+                 str(remote_3.fileno()),                                       \
+                 '-device', 'lsi53c895a,id=lsi3',                              \
+                 '-drive', 'id=drive_image3,'                                  \
+                               'file=/build/ol7-nvme-test-3.qcow2',            \
+                 '-device', 'scsi-hd,id=drive3,drive=drive_image3,'            \
+                                'bus=lsi3.0,scsi-id=0'                         \
+               ]
+
+proxy_cmd = [ PROC_QEMU,                                                       \
+              '-name', 'OL7.4',                                                \
+              '-machine', 'q35,accel=kvm',                                     \
+              '-smp', 'sockets=1,cores=1,threads=1',                           \
+              '-m', '2048',                                                    \
+              '-object', 'memory-backend-memfd,id=sysmem-file,size=2G',        \
+              '-numa', 'node,memdev=sysmem-file',                              \
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',                \
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'                \
+                            'file=/home/ol7-hdd-1.qcow2',                      \
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'               \
+                             'bus=virtio_scsi_pci0.0',                         \
+              '-boot', 'd',                                                    \
+              '-vnc', ':0',                                                    \
+              '-device', 'pci-proxy-dev,id=lsi1,'                              \
+                             'socket='+str(proxy_1.fileno()),                  \
+              '-device', 'pci-proxy-dev,id=lsi2,'                              \
+                             'socket='+str(proxy_2.fileno()),                  \
+              '-device', 'pci-proxy-dev,id=lsi3,'                              \
+                             'socket='+str(proxy_3.fileno())                   \
+            ]
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_1
+    print('Launching Remote process 1');
+    process = subprocess.Popen(remote_cmd_1, pass_fds=[remote_1.fileno()])
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_2
+    print('Launching Remote process 2');
+    process = subprocess.Popen(remote_cmd_2, pass_fds=[remote_2.fileno()])
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_3
+    print('Launching Remote process 3');
+    process = subprocess.Popen(remote_cmd_3, pass_fds=[remote_3.fileno()])
+    os._exit(0)
+
+
+print('Launching Proxy process');
+process = subprocess.Popen(proxy_cmd, pass_fds=[proxy_1.fileno(),              \
+                           proxy_2.fileno(), proxy_3.fileno()])
scripts/mpqemu-launcher.py new file +53 -0
new file mode 100755
index 0000000000..81e370663e
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy, remote = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd = [ PROC_REMOTE,                                                    \
+               str(remote.fileno()),                                           \
+               '-device', 'lsi53c895a,id=lsi1',                                \
+               '-drive', 'id=drive_image1,file=/build/ol7-nvme-test-1.qcow2',  \
+               '-device', 'scsi-hd,id=drive1,drive=drive_image1,bus=lsi1.0,'   \
+                              'scsi-id=0',                                     \
+               '-device', 'lsi53c895a,id=lsi2',                                \
+               '-drive', 'id=drive_image2,file=/build/ol7-nvme-test-2.qcow2',  \
+               '-device', 'scsi-hd,id=drive2,drive=drive_image2,bus=lsi2.0,'   \
+                              'scsi-id=0'                                      \
+             ]
+
+proxy_cmd = [ PROC_QEMU,                                                       \
+              '-name', 'OL7.4',                                                \
+              '-machine', 'q35,accel=kvm',                                     \
+              '-smp', 'sockets=1,cores=1,threads=1',                           \
+              '-m', '2048',                                                    \
+              '-object', 'memory-backend-memfd,id=sysmem-file,size=2G',        \
+              '-numa', 'node,memdev=sysmem-file',                              \
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',                \
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'                \
+                            'file=/home/ol7-hdd-1.qcow2',                      \
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'               \
+                             'bus=virtio_scsi_pci0.0',                         \
+              '-boot', 'd',                                                    \
+              '-vnc', ':0',                                                    \
+              '-device', 'pci-proxy-dev,id=lsi1,socket='+str(proxy.fileno()),  \
+              '-device', 'pci-proxy-dev,id=lsi2,socket='+str(proxy.fileno())   \
+            ]
+
+
+pid = os.fork();
+
+if pid:
+    # In Proxy
+    print('Launching QEMU with Proxy object');
+    process = subprocess.Popen(proxy_cmd, pass_fds=[proxy.fileno()])
+else:
+    # In remote
+    print('Launching Remote process');
+    process = subprocess.Popen(remote_cmd, pass_fds=[remote.fileno()])
Signature · 12 lines
2.25.GIT




-- 
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#20 lore raw

Re: [PATCH RESEND v6 06/36] monitor: destaticize HMP commands

In reply to Jag Raman
Quoted 11 lines · Jag Raman
Quoted 3 lines · Philippe Mathieu-Daudé

Why 'destaticize HMP commands’?

Hi Philippe,

Both QEMU & the remote process links the QMP code. QEMU uses all of the QMP commands, whereas, the remote process only uses a subset of this. Therefore, the ‘static’ functions which don’t have a reference cause build errors (like defined but not used). Therefore, we decided to destaticize the ones that are causing the build failure.

If you explain it, it is understandable. Worth a note in the commit description then :)

Quoted 25 lines

On a different note, Dave had previously suggested destacizing only the HMP functions used by the remote process. However, we found out that this is not possible because without all these functions, the build error still reproduces. We did confirm that all the functions we have destaticized are necessary to help with build of the remote process.

Thank you very much!
--
Jag

Quoted 13 lines · On 4/23/20 6:13 AM, [email protected] wrote:
Quoted 10 lines

From: Jagannathan Raman <[email protected]>

---
  hmp-commands.hx            |  4 +-
  monitor/misc.c             | 76 +++++++++++++++++++-------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++
  3 files changed, 78 insertions(+), 40 deletions(-)
#80 lore raw

Re: [PATCH RESEND v6 36/36] multi-process: add configure and usage information

In reply to Jag Raman
Quoted 5 lines · Jag Raman
Quoted 3 lines

On Apr 23, 2020, at 9:54 AM, 罗勇刚(Yonggang Luo) <[email protected]>

Quoted 1 line · wrote:
Quoted 9 lines
Quoted 2 lines

Does multi-process support on Windows?
I found it use mmap and unix socket for inter-process communication,

that may not support under Windows.

Hi Yonggang,

We have only tested this on Linux till now. Are you using QEMU with Windows?

Yeap, I am using QEMU with windows.

Quoted 395 lines
Quoted 2 lines

And also, can the python script be replaced by C implementation?

The functionality in the python script would eventually move to libvirt. The python
script is a temporary measure.

Does that means without libvirt, the QEMU can not be called directly?

Thank you very much!
—
Jag

Quoted 47 lines · On Thu, Apr 23, 2020 at 12:38 PM <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS                          |  2 +
 docs/multi-process.rst               | 85 +++++++++++++++++++++++++
 scripts/mpqemu-launcher-perf-mode.py | 92 ++++++++++++++++++++++++++++
 scripts/mpqemu-launcher.py           | 53 ++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 docs/multi-process.rst
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
index ed48615e15..8ff3bfae6a 100644
@@ -2880,6 +2880,8 @@ F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
 F: docs/devel/multi-process.rst
+F: scripts/mpqemu-launcher.py
+F: scripts/mpqemu-launcher-perf-mode.py
 
 Build and test automation
 -------------------------
docs/multi-process.rst new file +11 -0
new file mode 100644
index 0000000000..8387d6c691
@@ -0,0 +1,85 @@
+Multi-process QEMU
+==================
+
+This document describes how to configure and use multi-process qemu.
+For the design document refer to docs/devel/qemu-multiprocess.
+
+1) Configuration
+----------------
+
+To enable support for multi-process add --enable-mpqemu
+to the list of options for the "configure" script.

docs/multi-process.rst line 21

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+
+
+2) Usage
+--------
+
+Multi-process QEMU requires an orchestrator to launch. Please refer to a
+light-weight python based orchestrator for mpqemu in
+scripts/mpqemu-launcher.py to lauch QEMU in multi-process mode.
+
+scripts/mpqemu-launcher-perf-mode.py launches in "perf" mode. In this

mode,

docs/multi-process.rst line 22

Quoted 1 line
docs/multi-process.rst new file +1 -0
+the same QEMU process connects to multiple remote devices, each

emulated in

docs/multi-process.rst

Quoted 3 lines
docs/multi-process.rst new file +3 -0
+a separate process.
+
+As of now, we only support the emulation of lsi53c895a in a separate

process.

Quoted 9 lines
docs/multi-process.rst new file +9 -0
+
+Following is a description of command-line used to launch mpqemu.
+
+* Orchestrator:
+
+  - The Orchestrator creates a unix socketpair
+
+  - It launches the remote process and passes one of the
+    sockets to it via command-line.

docs/multi-process.rst

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+
+  - It then launches QEMU and specifies the other socket as an option
+    to the Proxy device object
+
+* Remote Process:
+
+  - The first command-line option in the remote process is one of the
+    sockets created by the Orchestrator
+
+  - The remaining options are no different from how one launches QEMU

with

docs/multi-process.rst line 46

Quoted 2 lines
docs/multi-process.rst new file +2 -0
+    devices. The only other requirement is each PCI device must have a
+    unique ID specified to it. This is needed to pair remote device

with the

docs/multi-process.rst

Quoted 5 lines
docs/multi-process.rst new file +5 -0
+    Proxy object.
+
+  - Example command-line for the remote process is as follows:
+
+      /usr/bin/qemu-scsu-dev 4

\

docs/multi-process.rst line 52

Quoted 1 line
docs/multi-process.rst new file +1 -0
+      -device lsi53c895a,id=lsi0

\

docs/multi-process.rst line 53

Quoted 1 line
docs/multi-process.rst new file +1 -0
+      -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2

\

docs/multi-process.rst

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+      -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0
+
+* QEMU:
+
+  - Since parts of the RAM are shared between QEMU & remote process, a
+    memory-backend-memfd is required to facilitate this, as follows:
+
+    -object memory-backend-memfd,id=mem,size=2G
+
+  - A "pci-proxy-dev" device is created for each of the PCI devices

emulated

docs/multi-process.rst line 64

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    in the remote process. A "socket" sub-option specifies the other

end of

docs/multi-process.rst line 65

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    unix channel created by orchestrator. The "id" sub-option must be

specified

docs/multi-process.rst line 66

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    and should be the same as the "id" specified for the remote PCI

device

docs/multi-process.rst

Quoted 8 lines
docs/multi-process.rst new file +8 -0
+
+  - Example commandline for QEMU is as follows:
+
+      -device pci-proxy-dev,id=lsi0,socket=3
+
+* Monitor / QMP:
+
+  - The remote process supports QEMU monitor. It could be specified

using the

docs/multi-process.rst

Quoted 3 lines
docs/multi-process.rst new file +3 -0
+    "-monitor" or "-qmp" command-line options
+
+  - As an example, one could connect to the monitor by adding the

following

Review

Quoted 9 lines
docs/multi-process.rst new file +8 -0
+    to the command-line of the remote process
+
+      -monitor unix:/home/qmp-sock,server,nowait
+
+  - The user could connect to the monitor using the qmp script or using
+    "socat" as outlined below:
+
+      socat /home/qmp-sock stdio
(quoted diff) +0 -0

b/scripts/mpqemu-launcher-perf-mode.py

Quoted 7 lines

new file mode 100755
index 0000000000..2733424c76

scripts/mpqemu-launcher-perf-mode.py new file +2 -0
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+

scripts/mpqemu-launcher-perf-mode.py line 12

Quoted 10 lines
scripts/mpqemu-launcher-perf-mode.py new file +10 -0
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy_1, remote_1 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 13

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+proxy_2, remote_2 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 14

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+proxy_3, remote_3 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 16

Quoted 2 lines
scripts/mpqemu-launcher-perf-mode.py new file +2 -0
+
+remote_cmd_1 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 17

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_1.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 18

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi1',
        \

scripts/mpqemu-launcher-perf-mode.py line 19

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 20

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-1.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 21

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive1,drive=drive_image1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 22

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi1.0,scsi-id=0',
        \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+remote_cmd_2 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 26

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_2.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 27

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi2',
        \

scripts/mpqemu-launcher-perf-mode.py line 28

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 29

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-2.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 30

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive2,drive=drive_image2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 31

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi2.0,scsi-id=0'
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+remote_cmd_3 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 35

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_3.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 36

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi3',
        \

scripts/mpqemu-launcher-perf-mode.py line 37

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 38

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-3.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 39

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive3,drive=drive_image3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 40

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi3.0,scsi-id=0'
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+proxy_cmd = [ PROC_QEMU,
       \

scripts/mpqemu-launcher-perf-mode.py line 44

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-name', 'OL7.4',
        \

scripts/mpqemu-launcher-perf-mode.py line 45

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-machine', 'q35,accel=kvm',
       \

scripts/mpqemu-launcher-perf-mode.py line 46

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-smp', 'sockets=1,cores=1,threads=1',
       \

scripts/mpqemu-launcher-perf-mode.py line 47

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-m', '2048',
        \

scripts/mpqemu-launcher-perf-mode.py line 48

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-object',

'memory-backend-memfd,id=sysmem-file,size=2G', \

scripts/mpqemu-launcher-perf-mode.py line 49

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-numa', 'node,memdev=sysmem-file',
        \

scripts/mpqemu-launcher-perf-mode.py line 50

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
        \

scripts/mpqemu-launcher-perf-mode.py line 51

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 52

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                            'file=/home/ol7-hdd-1.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 53

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
       \

scripts/mpqemu-launcher-perf-mode.py line 54

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'bus=virtio_scsi_pci0.0',
       \

scripts/mpqemu-launcher-perf-mode.py line 55

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-boot', 'd',
        \

scripts/mpqemu-launcher-perf-mode.py line 56

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-vnc', ':0',
        \

scripts/mpqemu-launcher-perf-mode.py line 57

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 58

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_1.fileno()),
        \

scripts/mpqemu-launcher-perf-mode.py line 59

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 60

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_2.fileno()),
        \

scripts/mpqemu-launcher-perf-mode.py line 61

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 62

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_3.fileno())
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+            ]
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_1
+    print('Launching Remote process 1');
+    process = subprocess.Popen(remote_cmd_1,

pass_fds=[remote_1.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_2
+    print('Launching Remote process 2');
+    process = subprocess.Popen(remote_cmd_2,

pass_fds=[remote_2.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_3
+    print('Launching Remote process 3');
+    process = subprocess.Popen(remote_cmd_3,

pass_fds=[remote_3.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 5 lines
scripts/mpqemu-launcher-perf-mode.py new file +5 -0
+    os._exit(0)
+
+
+print('Launching Proxy process');
+process = subprocess.Popen(proxy_cmd, pass_fds=[proxy_1.fileno(),
        \
Quoted 10 lines
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                           proxy_2.fileno(), proxy_3.fileno()])
scripts/mpqemu-launcher.py new file +3 -0
new file mode 100755
index 0000000000..81e370663e
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+import socket
+import os

scripts/mpqemu-launcher.py line 13

Quoted 10 lines
scripts/mpqemu-launcher.py new file +10 -0
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy, remote = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher.py line 14

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               str(remote.fileno()),
       \

scripts/mpqemu-launcher.py line 15

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device', 'lsi53c895a,id=lsi1',
        \

scripts/mpqemu-launcher.py line 16

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-drive',

'id=drive_image1,file=/build/ol7-nvme-test-1.qcow2', \

scripts/mpqemu-launcher.py line 17

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device',

'scsi-hd,id=drive1,drive=drive_image1,bus=lsi1.0,' \

scripts/mpqemu-launcher.py line 18

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                              'scsi-id=0',
       \

scripts/mpqemu-launcher.py line 19

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device', 'lsi53c895a,id=lsi2',
        \

scripts/mpqemu-launcher.py line 20

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-drive',

'id=drive_image2,file=/build/ol7-nvme-test-2.qcow2', \

scripts/mpqemu-launcher.py line 21

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device',

'scsi-hd,id=drive2,drive=drive_image2,bus=lsi2.0,' \

scripts/mpqemu-launcher.py line 22

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                              'scsi-id=0'
        \

scripts/mpqemu-launcher.py line 25

Quoted 3 lines
scripts/mpqemu-launcher.py new file +3 -0
+             ]
+
+proxy_cmd = [ PROC_QEMU,
       \

scripts/mpqemu-launcher.py line 26

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-name', 'OL7.4',
        \

scripts/mpqemu-launcher.py line 27

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-machine', 'q35,accel=kvm',
       \

scripts/mpqemu-launcher.py line 28

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-smp', 'sockets=1,cores=1,threads=1',
       \

scripts/mpqemu-launcher.py line 29

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-m', '2048',
        \

scripts/mpqemu-launcher.py line 30

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-object',

'memory-backend-memfd,id=sysmem-file,size=2G', \

scripts/mpqemu-launcher.py line 31

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-numa', 'node,memdev=sysmem-file',
        \

scripts/mpqemu-launcher.py line 32

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
        \

scripts/mpqemu-launcher.py line 33

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
        \

scripts/mpqemu-launcher.py line 34

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                            'file=/home/ol7-hdd-1.qcow2',
        \

scripts/mpqemu-launcher.py line 35

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
       \

scripts/mpqemu-launcher.py line 36

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                             'bus=virtio_scsi_pci0.0',
       \

scripts/mpqemu-launcher.py line 37

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-boot', 'd',
        \

scripts/mpqemu-launcher.py line 38

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-vnc', ':0',
        \

scripts/mpqemu-launcher.py line 39

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device',

'pci-proxy-dev,id=lsi1,socket='+str(proxy.fileno()), \

scripts/mpqemu-launcher.py line 40

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device',

'pci-proxy-dev,id=lsi2,socket='+str(proxy.fileno()) \

Quoted 26 lines
scripts/mpqemu-launcher.py new file +13 -1
+            ]
+
+
+pid = os.fork();
+
+if pid:
+    # In Proxy
+    print('Launching QEMU with Proxy object');
+    process = subprocess.Popen(proxy_cmd, pass_fds=[proxy.fileno()])
+else:
+    # In remote
+    print('Launching Remote process');
+    process = subprocess.Popen(remote_cmd, pass_fds=[remote.fileno()])
--

2.25.GIT

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#81 lore raw

Re: [PATCH RESEND v6 36/36] multi-process: add configure and usage information

In reply to Jag Raman
Quoted 14 lines · Jag Raman
Quoted 3 lines

On Apr 23, 2020, at 9:54 AM, 罗勇刚(Yonggang Luo) <[email protected]>

Quoted 3 lines · wrote:

Does multi-process support on Windows?
I found it use mmap and unix socket for inter-process communication,

that may not support under Windows.

Hi Yonggang,

We have only tested this on Linux till now. Are you using QEMU with Windows?

Quoted 7 lines
Quoted 1 line

And also, can the python script be replaced by C implementation?

The functionality in the python script would eventually move to libvirt. The python
script is a temporary measure.

I suggest use qemu as the driver like clang-cl, we preseve the options

currently avaiable in qemu
and then starting remote process by qemu directly, so we libvirt need to lauch with qemu

Quoted 386 lines

Thank you very much!
—
Jag

Quoted 47 lines · On Thu, Apr 23, 2020 at 12:38 PM <[email protected]> wrote:

From: Elena Ufimtseva <[email protected]>

---
 MAINTAINERS                          |  2 +
 docs/multi-process.rst               | 85 +++++++++++++++++++++++++
 scripts/mpqemu-launcher-perf-mode.py | 92 ++++++++++++++++++++++++++++
 scripts/mpqemu-launcher.py           | 53 ++++++++++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 docs/multi-process.rst
 create mode 100755 scripts/mpqemu-launcher-perf-mode.py
 create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
index ed48615e15..8ff3bfae6a 100644
@@ -2880,6 +2880,8 @@ F: remote/iohub.c
 F: remote/remote-opts.h
 F: remote/remote-opts.c
 F: docs/devel/multi-process.rst
+F: scripts/mpqemu-launcher.py
+F: scripts/mpqemu-launcher-perf-mode.py
 
 Build and test automation
 -------------------------
docs/multi-process.rst new file +11 -0
new file mode 100644
index 0000000000..8387d6c691
@@ -0,0 +1,85 @@
+Multi-process QEMU
+==================
+
+This document describes how to configure and use multi-process qemu.
+For the design document refer to docs/devel/qemu-multiprocess.
+
+1) Configuration
+----------------
+
+To enable support for multi-process add --enable-mpqemu
+to the list of options for the "configure" script.

docs/multi-process.rst line 21

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+
+
+2) Usage
+--------
+
+Multi-process QEMU requires an orchestrator to launch. Please refer to a
+light-weight python based orchestrator for mpqemu in
+scripts/mpqemu-launcher.py to lauch QEMU in multi-process mode.
+
+scripts/mpqemu-launcher-perf-mode.py launches in "perf" mode. In this

mode,

docs/multi-process.rst line 22

Quoted 1 line
docs/multi-process.rst new file +1 -0
+the same QEMU process connects to multiple remote devices, each

emulated in

docs/multi-process.rst

Quoted 3 lines
docs/multi-process.rst new file +3 -0
+a separate process.
+
+As of now, we only support the emulation of lsi53c895a in a separate

process.

Quoted 9 lines
docs/multi-process.rst new file +9 -0
+
+Following is a description of command-line used to launch mpqemu.
+
+* Orchestrator:
+
+  - The Orchestrator creates a unix socketpair
+
+  - It launches the remote process and passes one of the
+    sockets to it via command-line.

docs/multi-process.rst

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+
+  - It then launches QEMU and specifies the other socket as an option
+    to the Proxy device object
+
+* Remote Process:
+
+  - The first command-line option in the remote process is one of the
+    sockets created by the Orchestrator
+
+  - The remaining options are no different from how one launches QEMU

with

docs/multi-process.rst line 46

Quoted 2 lines
docs/multi-process.rst new file +2 -0
+    devices. The only other requirement is each PCI device must have a
+    unique ID specified to it. This is needed to pair remote device

with the

docs/multi-process.rst

Quoted 5 lines
docs/multi-process.rst new file +5 -0
+    Proxy object.
+
+  - Example command-line for the remote process is as follows:
+
+      /usr/bin/qemu-scsu-dev 4

\

docs/multi-process.rst line 52

Quoted 1 line
docs/multi-process.rst new file +1 -0
+      -device lsi53c895a,id=lsi0

\

docs/multi-process.rst line 53

Quoted 1 line
docs/multi-process.rst new file +1 -0
+      -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2

\

docs/multi-process.rst

Quoted 10 lines
docs/multi-process.rst new file +10 -0
+      -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0
+
+* QEMU:
+
+  - Since parts of the RAM are shared between QEMU & remote process, a
+    memory-backend-memfd is required to facilitate this, as follows:
+
+    -object memory-backend-memfd,id=mem,size=2G
+
+  - A "pci-proxy-dev" device is created for each of the PCI devices

emulated

docs/multi-process.rst line 64

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    in the remote process. A "socket" sub-option specifies the other

end of

docs/multi-process.rst line 65

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    unix channel created by orchestrator. The "id" sub-option must be

specified

docs/multi-process.rst line 66

Quoted 1 line
docs/multi-process.rst new file +1 -0
+    and should be the same as the "id" specified for the remote PCI

device

docs/multi-process.rst

Quoted 8 lines
docs/multi-process.rst new file +8 -0
+
+  - Example commandline for QEMU is as follows:
+
+      -device pci-proxy-dev,id=lsi0,socket=3
+
+* Monitor / QMP:
+
+  - The remote process supports QEMU monitor. It could be specified

using the

docs/multi-process.rst

Quoted 3 lines
docs/multi-process.rst new file +3 -0
+    "-monitor" or "-qmp" command-line options
+
+  - As an example, one could connect to the monitor by adding the

following

Review

Quoted 9 lines
docs/multi-process.rst new file +8 -0
+    to the command-line of the remote process
+
+      -monitor unix:/home/qmp-sock,server,nowait
+
+  - The user could connect to the monitor using the qmp script or using
+    "socat" as outlined below:
+
+      socat /home/qmp-sock stdio
(quoted diff) +0 -0

b/scripts/mpqemu-launcher-perf-mode.py

Quoted 7 lines

new file mode 100755
index 0000000000..2733424c76

scripts/mpqemu-launcher-perf-mode.py new file +2 -0
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+

scripts/mpqemu-launcher-perf-mode.py line 12

Quoted 10 lines
scripts/mpqemu-launcher-perf-mode.py new file +10 -0
+import socket
+import os
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy_1, remote_1 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 13

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+proxy_2, remote_2 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 14

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+proxy_3, remote_3 = socket.socketpair(socket.AF_UNIX,

socket.SOCK_STREAM)

scripts/mpqemu-launcher-perf-mode.py line 16

Quoted 2 lines
scripts/mpqemu-launcher-perf-mode.py new file +2 -0
+
+remote_cmd_1 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 17

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_1.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 18

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi1',
        \

scripts/mpqemu-launcher-perf-mode.py line 19

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 20

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-1.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 21

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive1,drive=drive_image1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 22

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi1.0,scsi-id=0',
        \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+remote_cmd_2 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 26

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_2.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 27

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi2',
        \

scripts/mpqemu-launcher-perf-mode.py line 28

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 29

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-2.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 30

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive2,drive=drive_image2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 31

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi2.0,scsi-id=0'
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+remote_cmd_3 = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher-perf-mode.py line 35

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 str(remote_3.fileno()),
       \

scripts/mpqemu-launcher-perf-mode.py line 36

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'lsi53c895a,id=lsi3',
        \

scripts/mpqemu-launcher-perf-mode.py line 37

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-drive', 'id=drive_image3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 38

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                               'file=/build/ol7-nvme-test-3.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 39

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                 '-device', 'scsi-hd,id=drive3,drive=drive_image3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 40

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                                'bus=lsi3.0,scsi-id=0'
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 3 lines
scripts/mpqemu-launcher-perf-mode.py new file +3 -0
+               ]
+
+proxy_cmd = [ PROC_QEMU,
       \

scripts/mpqemu-launcher-perf-mode.py line 44

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-name', 'OL7.4',
        \

scripts/mpqemu-launcher-perf-mode.py line 45

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-machine', 'q35,accel=kvm',
       \

scripts/mpqemu-launcher-perf-mode.py line 46

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-smp', 'sockets=1,cores=1,threads=1',
       \

scripts/mpqemu-launcher-perf-mode.py line 47

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-m', '2048',
        \

scripts/mpqemu-launcher-perf-mode.py line 48

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-object',

'memory-backend-memfd,id=sysmem-file,size=2G', \

scripts/mpqemu-launcher-perf-mode.py line 49

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-numa', 'node,memdev=sysmem-file',
        \

scripts/mpqemu-launcher-perf-mode.py line 50

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
        \

scripts/mpqemu-launcher-perf-mode.py line 51

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 52

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                            'file=/home/ol7-hdd-1.qcow2',
        \

scripts/mpqemu-launcher-perf-mode.py line 53

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
       \

scripts/mpqemu-launcher-perf-mode.py line 54

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'bus=virtio_scsi_pci0.0',
       \

scripts/mpqemu-launcher-perf-mode.py line 55

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-boot', 'd',
        \

scripts/mpqemu-launcher-perf-mode.py line 56

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-vnc', ':0',
        \

scripts/mpqemu-launcher-perf-mode.py line 57

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi1,'
        \

scripts/mpqemu-launcher-perf-mode.py line 58

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_1.fileno()),
        \

scripts/mpqemu-launcher-perf-mode.py line 59

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi2,'
        \

scripts/mpqemu-launcher-perf-mode.py line 60

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_2.fileno()),
        \

scripts/mpqemu-launcher-perf-mode.py line 61

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+              '-device', 'pci-proxy-dev,id=lsi3,'
        \

scripts/mpqemu-launcher-perf-mode.py line 62

Quoted 1 line
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                             'socket='+str(proxy_3.fileno())
       \

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+            ]
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_1
+    print('Launching Remote process 1');
+    process = subprocess.Popen(remote_cmd_1,

pass_fds=[remote_1.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_2
+    print('Launching Remote process 2');
+    process = subprocess.Popen(remote_cmd_2,

pass_fds=[remote_2.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 8 lines
scripts/mpqemu-launcher-perf-mode.py new file +8 -0
+    os._exit(0)
+
+
+pid = os.fork();
+if pid == 0:
+    # In remote_3
+    print('Launching Remote process 3');
+    process = subprocess.Popen(remote_cmd_3,

pass_fds=[remote_3.fileno()])

scripts/mpqemu-launcher-perf-mode.py

Quoted 5 lines
scripts/mpqemu-launcher-perf-mode.py new file +5 -0
+    os._exit(0)
+
+
+print('Launching Proxy process');
+process = subprocess.Popen(proxy_cmd, pass_fds=[proxy_1.fileno(),
        \
Quoted 10 lines
scripts/mpqemu-launcher-perf-mode.py new file +1 -0
+                           proxy_2.fileno(), proxy_3.fileno()])
scripts/mpqemu-launcher.py new file +3 -0
new file mode 100755
index 0000000000..81e370663e
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+import socket
+import os

scripts/mpqemu-launcher.py line 13

Quoted 10 lines
scripts/mpqemu-launcher.py new file +10 -0
+import subprocess
+import time
+
+PROC_QEMU='/usr/bin/qemu-system-x86_64'
+
+PROC_REMOTE='/usr/bin/qemu-scsi-dev'
+
+proxy, remote = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
+
+remote_cmd = [ PROC_REMOTE,
        \

scripts/mpqemu-launcher.py line 14

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               str(remote.fileno()),
       \

scripts/mpqemu-launcher.py line 15

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device', 'lsi53c895a,id=lsi1',
        \

scripts/mpqemu-launcher.py line 16

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-drive',

'id=drive_image1,file=/build/ol7-nvme-test-1.qcow2', \

scripts/mpqemu-launcher.py line 17

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device',

'scsi-hd,id=drive1,drive=drive_image1,bus=lsi1.0,' \

scripts/mpqemu-launcher.py line 18

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                              'scsi-id=0',
       \

scripts/mpqemu-launcher.py line 19

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device', 'lsi53c895a,id=lsi2',
        \

scripts/mpqemu-launcher.py line 20

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-drive',

'id=drive_image2,file=/build/ol7-nvme-test-2.qcow2', \

scripts/mpqemu-launcher.py line 21

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+               '-device',

'scsi-hd,id=drive2,drive=drive_image2,bus=lsi2.0,' \

scripts/mpqemu-launcher.py line 22

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                              'scsi-id=0'
        \

scripts/mpqemu-launcher.py line 25

Quoted 3 lines
scripts/mpqemu-launcher.py new file +3 -0
+             ]
+
+proxy_cmd = [ PROC_QEMU,
       \

scripts/mpqemu-launcher.py line 26

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-name', 'OL7.4',
        \

scripts/mpqemu-launcher.py line 27

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-machine', 'q35,accel=kvm',
       \

scripts/mpqemu-launcher.py line 28

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-smp', 'sockets=1,cores=1,threads=1',
       \

scripts/mpqemu-launcher.py line 29

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-m', '2048',
        \

scripts/mpqemu-launcher.py line 30

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-object',

'memory-backend-memfd,id=sysmem-file,size=2G', \

scripts/mpqemu-launcher.py line 31

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-numa', 'node,memdev=sysmem-file',
        \

scripts/mpqemu-launcher.py line 32

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device', 'virtio-scsi-pci,id=virtio_scsi_pci0',
        \

scripts/mpqemu-launcher.py line 33

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-drive', 'id=drive_image1,if=none,format=qcow2,'
        \

scripts/mpqemu-launcher.py line 34

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                            'file=/home/ol7-hdd-1.qcow2',
        \

scripts/mpqemu-launcher.py line 35

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device', 'scsi-hd,id=image1,drive=drive_image1,'
       \

scripts/mpqemu-launcher.py line 36

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+                             'bus=virtio_scsi_pci0.0',
       \

scripts/mpqemu-launcher.py line 37

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-boot', 'd',
        \

scripts/mpqemu-launcher.py line 38

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-vnc', ':0',
        \

scripts/mpqemu-launcher.py line 39

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device',

'pci-proxy-dev,id=lsi1,socket='+str(proxy.fileno()), \

scripts/mpqemu-launcher.py line 40

Quoted 1 line
scripts/mpqemu-launcher.py new file +1 -0
+              '-device',

'pci-proxy-dev,id=lsi2,socket='+str(proxy.fileno()) \

Quoted 26 lines
scripts/mpqemu-launcher.py new file +13 -1
+            ]
+
+
+pid = os.fork();
+
+if pid:
+    # In Proxy
+    print('Launching QEMU with Proxy object');
+    process = subprocess.Popen(proxy_cmd, pass_fds=[proxy.fileno()])
+else:
+    # In remote
+    print('Launching Remote process');
+    process = subprocess.Popen(remote_cmd, pass_fds=[remote.fileno()])
--

2.25.GIT

--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo

Signature · 6 lines
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
#82 lore raw
In reply to [email protected]
Quoted 19 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

There is an error in travis-ci build test which does not get reproduced.

TEST iotest-qcow2: 041 [fail]

QEMU          -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64" -nodefaults -display none -accel qtest
QEMU_IMG      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-img" 
QEMU_IO       -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-io"  --cache writeback --aio threads -f qcow2
QEMU_NBD      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-nbd" 
IMGFMT        -- qcow2 (compat=1.1)
IMGPROTO      -- file
PLATFORM      -- Linux/x86_64 travis-job-fc4e2553-b470-4a8b-812e-a4fcf8ba094f 5.0.0-1031-gcp
TEST_DIR      -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch
SOCK_DIR      -- /tmp/tmp.LOmYANt5Od

SOCKET_SCM_HELPER -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/socket_scm_helper

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +2 -1
@@ -1,5 +1,29 @@
-..............................................................................................
+........................FF....................................................................
+======================================================================

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad line 12

Quoted 10 lines
home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +10 -0
+FAIL: test_with_other_parent (__main__.TestRepairQuorum)
+----------------------------------------------------------------------
+Traceback (most recent call last):
+  File "041", line 1049, in test_with_other_parent
+    self.assert_qmp(result, 'return', {})
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 821, in assert_qmp
+    result = self.dictpath(d, path)
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 797, in dictpath
+    self.fail('failed path traversal for "%s" in "%s"' % (path, str(d)))
+AssertionError: failed path traversal for "return" in "{'error': {'class': 'GenericError', 'desc': "UNIX socket path '/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch/nbd.sock' is too long"}}"

UNIX Domain Socket paths have to be 108 characters or less. The path in the failed test case is 110 characters long. You could rename your branch to "mpqemu" to solve this failure.

Stefan

#83 lore raw
Quoted 26 lines · Stefan Hajnoczi
Quoted 25 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

There is an error in travis-ci build test which does not get reproduced.

TEST iotest-qcow2: 041 [fail]

QEMU          -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64" -nodefaults -display none -accel qtest
QEMU_IMG      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-img" 
QEMU_IO       -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-io"  --cache writeback --aio threads -f qcow2
QEMU_NBD      -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../qemu-nbd" 
IMGFMT        -- qcow2 (compat=1.1)
IMGPROTO      -- file
PLATFORM      -- Linux/x86_64 travis-job-fc4e2553-b470-4a8b-812e-a4fcf8ba094f 5.0.0-1031-gcp
TEST_DIR      -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch
SOCK_DIR      -- /tmp/tmp.LOmYANt5Od

SOCKET_SCM_HELPER -- /home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/socket_scm_helper

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +8 -1
@@ -1,5 +1,29 @@
-..............................................................................................
+........................FF....................................................................
+======================================================================
+FAIL: test_with_other_parent (__main__.TestRepairQuorum)
+----------------------------------------------------------------------
+Traceback (most recent call last):
+  File "041", line 1049, in test_with_other_parent
+    self.assert_qmp(result, 'return', {})
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 821, in assert_qmp
Quoted 8 lines

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad line 12

Quoted 4 lines
home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +4 -0
+    result = self.dictpath(d, path)
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 797, in dictpath
+    self.fail('failed path traversal for "%s" in "%s"' % (path, str(d)))
+AssertionError: failed path traversal for "return" in "{'error': {'class': 'GenericError', 'desc': "UNIX socket path '/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch/nbd.sock' is too long"}}"

UNIX Domain Socket paths have to be 108 characters or less. The path in the failed test case is 110 characters long. You could rename your branch to "mpqemu" to solve this failure.

Renaming is a pretty poor band-aid.

We should fix the i/o tests instead, so that they use a scratch dir under $TMP to store unix sockets needed by tests instead.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#84 lore raw
In reply to Stefan Hajnoczi
Quoted 6 lines · Stefan Hajnoczi
Quoted 4 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

There is an error in travis-ci build test which does not get reproduced.

TEST iotest-qcow2: 041 [fail]
QEMU -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64" -nodefaults -display none -accel qtest

Quoted 12 lines

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad line 12

Quoted 8 lines
home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +8 -0
+Traceback (most recent call last):
+  File "041", line 1049, in test_with_other_parent
+    self.assert_qmp(result, 'return', {})
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 821, in assert_qmp
+    result = self.dictpath(d, path)
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 797, in dictpath
+    self.fail('failed path traversal for "%s" in "%s"' % (path, str(d)))
+AssertionError: failed path traversal for "return" in "{'error': {'class': 'GenericError', 'desc': "UNIX socket path '/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch/nbd.sock' is too long"}}"

UNIX Domain Socket paths have to be 108 characters or less. The path in the failed test case is 110 characters long. You could rename your branch to "mpqemu" to solve this failure.

We recently fixed the iotests to prefer sticking NBD sockets under $SOCK_DIR (see commits f0e24942 and friends); did we miss test 41?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#13 lore raw

Re: [PATCH RESEND v6 03/36] command-line: refractor parser code

In reply to [email protected]
Quoted 4 lines · On Wed, Apr 22, 2020 at 09:13:38PM -0700, [email protected] wrote:

From: Elena Ufimtseva <[email protected]>

Refactor command-line parser code so that it could be used by other processes as well.

How will qemu-options-wrapper.h be handled for other processes? At the moment qemu-parse.c cannot be reused because it includes this file for the options list.

include/qemu-parse.h line 2

Quoted 8 lines
include/qemu-parse.h new file +2 -0
new file mode 100644
index 0000000000..156b238db6
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.

This code is extracted from vl.c so the copyright should be preserved and not replaced with yours.

You can add yours for changes that have been made.

include/qemu-parse.h line 10

Quoted 8 lines
include/qemu-parse.h new file +8 -0
+ *
+ * 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 VL_H
+#define VL_H

#define QEMU_PARSE_H

include/qemu-parse.h line 39

Quoted 4 lines
include/qemu-parse.h new file +4 -0
+
+int drive_init_func(void *opaque, QemuOpts *opts, Error **errp);
+
+int device_init_func(void *opaque, QemuOpts *opts, Error **errp);

What do drive_init_func() and device_init_func() have to do with lookup_opt()? I wouldn't expect to see them in this header file.

#16 lore raw

Re: [PATCH RESEND v6 05/36] multi-process: Refactor monitor functions out of vl.c

In reply to [email protected]
Quoted 11 lines · On Wed, Apr 22, 2020 at 09:13:40PM -0700, [email protected] wrote:

From: Elena Ufimtseva <[email protected]>

Some of the initialization helper functions w.r.t monitor
in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.

Quoted 5 lines
---
 include/monitor/monitor.h |  3 +++
 monitor/monitor.c         | 37 +++++++++++++++++++++++++++++++++++++
 softmmu/vl.c              | 35 -----------------------------------
 3 files changed, 40 insertions(+), 35 deletions(-)

Kevin Wolf recently had to solve a similar problem when introducing qemu-storage-daemon.

qemu-storage-daemon.c open-codes the command-line parsing instead of trying to reuse vl.c's code. The vl.c code is old and not very neat, unless other code depends on it I would suggest writing modern clean code like Kevin did instead of trying to keep using vl.c code.

Quoted 117 lines
include/monitor/monitor.h +3 -0
index 1018d754a6..3803e904f2 100644
@@ -48,4 +48,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+
 #endif /* MONITOR_H */
monitor/monitor.c +37 -0
index 125494410a..88423b38b6 100644
@@ -35,6 +35,8 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
+#include "qemu/cutils.h"
+#include "qemu/config-file.h"
 
 /*
  * To prevent flooding clients, events can be throttled. The
@@ -611,6 +613,41 @@ void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp)
 {
     Chardev *chr;
softmmu/vl.c +0 -35
index 6e35f3787d..abc746c1b5 100644
@@ -2045,41 +2045,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 }
 #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
 struct device_config {
     enum {
         DEV_USB,       /* -usbdevice     */
Signature · 1 line
2.25.GIT
#23 lore raw

Re: [PATCH RESEND v6 08/36] multi-process: Add stub functions to facilitate build of multi-process

In reply to [email protected]

stubs/Makefile.objs stub-obj-y += migr-blocker.o · line 26

Quoted 12 lines · On Wed, Apr 22, 2020 at 09:13:43PM -0700, [email protected] wrote:
stubs/Makefile.objs +1 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
 stub-obj-y += change-state-handler.o
 stub-obj-y += monitor.o
 stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
 stub-obj-y += notify-event.o
 stub-obj-y += qtest.o
 stub-obj-y += replay.o

audio.c, vl-stub.c, and xen-mapcache.c are added by this patch but not added to Makefile.objs? Can they be removed?

This entire patch requires justification. Stubs exist so that common code can be linked without optional features.

For example, common code may call into kvm but that callback isn't relevant when building with kvm accelerator support (e.g. say qemu-nbd). That's where the stub function comes in. It fulfills the dependency without dragging in the actual kvm accelerator code.

Adding lots of stubs suggests you are building QEMU in a new way that wasn't done before (this is true and expected for this patch series). I would like to understand the reason for these stubs though. For example, why do you need to stub audio?

Without a reason for each of these stubs we have no way of knowing if they are actually used/needed. Maybe an earlier version of the code needed it but the latest version of the patch no longer does...

Stefan

Reviewed-by on v6 9/36
#29 lore raw

Re: [PATCH RESEND v6 09/36] multi-process: Add config option for multi-process QEMU

In reply to [email protected]
Quoted 10 lines · On Wed, Apr 22, 2020 at 09:13:44PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Add a configuration option to separate multi-process code

---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)
#85 lore raw
In reply to Eric Blake
Quoted 31 lines · Eric Blake
Quoted 21 lines · Stefan Hajnoczi
Quoted 19 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

There is an error in travis-ci build test which does not get reproduced.

  TEST    iotest-qcow2: 041 [fail]
QEMU          -- "/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64"

home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/041.out.bad renamed from home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/041.out +4 -1
-nodefaults -display none -accel qtest
 
+Traceback (most recent call last):
+  File "041", line 1049, in test_with_other_parent
+    self.assert_qmp(result, 'return', {})
+  File

"/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 821, in assert_qmp
+    result = self.dictpath(d, path)
+  File "/home/travis/build/elena-ufimtseva/qemu-multiprocess/tests/qemu-iotests/iotests.py", line 797, in dictpath
+    self.fail('failed path traversal for "%s" in "%s"' % (path, str(d)))

Quoted 8 lines
Quoted 4 lines

+AssertionError: failed path traversal for "return" in "{'error':
{'class': 'GenericError', 'desc': "UNIX socket path '/home/travis/build/elena-ufimtseva/qemu-multiprocess/out-of-tree/build/dir/tests/qemu-iotests/scratch/nbd.sock' is too long"}}"

UNIX Domain Socket paths have to be 108 characters or less.  The path in the failed test case is 110 characters long.  You could rename your branch to "mpqemu" to solve this failure.

Quoted 2 lines

We recently fixed the iotests to prefer sticking NBD sockets under $SOCK_DIR (see commits f0e24942 and friends); did we miss test 41?

Looks more like I broke it. Oops. Will fix.

Max

#24 lore raw

Re: [PATCH RESEND v6 08/36] multi-process: Add stub functions to facilitate build of multi-process

In reply to Stefan Hajnoczi
Quoted 20 lines · Stefan Hajnoczi
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:43PM -0700, [email protected] wrote:
stubs/Makefile.objs +0 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
Quoted 7 lines

stub-obj-y += change-state-handler.o
stub-obj-y += monitor.o
stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
stub-obj-y += notify-event.o
stub-obj-y += qtest.o
stub-obj-y += replay.o

audio.c, vl-stub.c, and xen-mapcache.c are added by this patch but not added to Makefile.objs? Can they be removed?

Hey Stefan,

Sorry it’s not clear. but these files are referenced in Makefile.target.

Quoted 9 lines

This entire patch requires justification. Stubs exist so that common code can be linked without optional features.

For example, common code may call into kvm but that callback isn't relevant when building with kvm accelerator support (e.g. say qemu-nbd). That's where the stub function comes in. It fulfills the dependency without dragging in the actual kvm accelerator code.

Quoted 4 lines

Adding lots of stubs suggests you are building QEMU in a new way that wasn't done before (this is true and expected for this patch series). I would like to understand the reason for these stubs though. For example, why do you need to stub audio?

These stub functions are only used by the remote process, and not by QEMU itself.

Our goal is to ensure that the remote process is building the smallest set of files necessary and these stub functions are necessary to meet that goal.

For example, the remote process needs to build some of the functions defined in “hw/core/qdev-properties-system.c”. However, this file depends on audio.c (references audio_state_by_name()), which is not needed for the remote process. The alternative to stub functions would be to compile audio.c into the remote process, but that was not necessary in our judgement. When the project started out, we spent a lot of time figuring out which functions/files are necessary for the remote process, and we stubbed out the ones which are needed to resolve dependency during compilation, but not needed for functionality.

audio.c is just an example of tens of other places where we needed to make similar judgements.

Would you prefer if we moved these stub functions into a separate library (instead of stub-obj-y) which is only linked by the remote process?

--
Jag

Quoted 6 lines

Without a reason for each of these stubs we have no way of knowing if they are actually used/needed. Maybe an earlier version of the code needed it but the latest version of the patch no longer does...

Stefan

#31 lore raw

Re: [PATCH RESEND v6 10/36] multi-process: build system for remote device process

In reply to [email protected]
Quoted 23 lines · On Wed, Apr 22, 2020 at 09:13:45PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Modify Makefile to support the building of the remote device process. Implements main() function of remote device process.

---
 MAINTAINERS             |  8 ++++++
 Makefile                |  2 ++
 Makefile.objs           | 27 ++++++++++++++++++
 Makefile.target         | 61 ++++++++++++++++++++++++++++++++++++++++-
 accel/Makefile.objs     |  2 ++
 backends/Makefile.objs  |  2 ++
 block/Makefile.objs     |  2 ++
 hw/Makefile.objs        |  7 +++++
 hw/block/Makefile.objs  |  2 ++
 hw/core/Makefile.objs   | 18 ++++++++++++
 hw/nvram/Makefile.objs  |  2 ++
 hw/pci/Makefile.objs    |  4 +++
 hw/scsi/Makefile.objs   |  2 ++
Quoted 8 lines
 migration/Makefile.objs |  2 ++
 qom/Makefile.objs       |  3 ++
 remote/Makefile.objs    |  1 +
 remote/remote-main.c    | 23 ++++++++++++++++
 stubs/replay.c          |  4 +++
 18 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 remote/Makefile.objs
 create mode 100644 remote/remote-main.c

This approach is okay for now but will result in a lot of Makefile duplication in the long run.

Each hw .o file should specify its dependencies so that qemu-system-* and the remote executable can link in the needed files. The Kconfig system can also help with this by enabling/disabling features.

Then the Makefiles don't need to duplicate *-obj-y and remote-pci-*.

Quoted 6 lines
Makefile.objs +0 -0
index f29c60c59d..f6654633b4 100644
@@ -21,6 +21,33 @@ block-obj-$(CONFIG_REPLICATION) += replication.o
 

Makefile.objs block-obj-$(CONFIG_REPLICATION) += replication.o · line 31

Quoted 10 lines
Makefile.objs +8 -0
 block-obj-m = block/
 
+#########################################################
+# remote-pci-obj-y is common code used by remote devices
+
+remote-pci-obj-$(CONFIG_MPQEMU) += hw/
+remote-pci-obj-$(CONFIG_MPQEMU) += qom/
+remote-pci-obj-$(CONFIG_MPQEMU) += backends/
+remote-pci-obj-$(CONFIG_MPQEMU) += block/
+remote-pci-obj-$(CONFIG_MPQEMU) += migration/

In the future migration can be split into the QEMU and remote parts. The remote executable doesn't need all the live migration code.

Makefile.objs block-obj-$(CONFIG_REPLICATION) += replication.o · line 33

Quoted 2 lines
Makefile.objs +2 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += remote/
+remote-pci-obj-$(CONFIG_MPQEMU) += accel/

Devices do not execute guest code so they should not need accel/. kvm and tcg functions were stubbed out earlier in this patch series, so I'm surprised to see thing being built into the remote executable.

Quoted 7 lines
Makefile.objs +3 -0
@@ -121,6 +131,20 @@ LIBS := $(libs_cpu) $(LIBS)
 
 obj-$(CONFIG_PLUGIN) += plugins/
 
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/tcg-stub.o

Makefile.objs LIBS := $(libs_cpu) $(LIBS) · line 146

Quoted 10 lines
Makefile.objs +10 -0
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+endif

Stubs don't need to be explicitly included, they should be linked in via libqemustub.a.

Quoted 10 lines
remote/remote-main.c new file +4 -0
new file mode 100644
index 0000000000..7c0764ad01
@@ -0,0 +1,23 @@
+/*
+ * Remote device initialization
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.

remote/remote-main.c line 14

Quoted 10 lines
remote/remote-main.c new file +10 -0
+ *
+ * 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 <stdio.h>

This is already included by "qemu/osdep.h"

Quoted 14 lines
remote/remote-main.c new file +9 -0
+
+#include "qemu/module.h"
+
+int main(int argc, char *argv[])
+{
+    module_call_init(MODULE_INIT_QOM);
+
+    return 0;
+}
stubs/replay.c +0 -0
index 2e3feee6a9..9b53c0cb37 100644

stubs/replay.c int replay_get_instructions(void) · line 108

Quoted 7 lines
stubs/replay.c +4 -0
@@ -102,3 +102,7 @@ int replay_get_instructions(void)
 void replay_account_executed_instructions(void)
 {
 }
+
+void replay_add_blocker(Error *reason)
+{
+}

This can be moved to the stubs patch.

#25 lore raw

Re: [PATCH RESEND v6 08/36] multi-process: Add stub functions to facilitate build of multi-process

In reply to Jag Raman
Quoted 18 lines · Jag Raman
Quoted 17 lines · Stefan Hajnoczi
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:43PM -0700, [email protected] wrote:
stubs/Makefile.objs +0 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
Quoted 7 lines

stub-obj-y += change-state-handler.o
stub-obj-y += monitor.o
stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
stub-obj-y += notify-event.o
stub-obj-y += qtest.o
stub-obj-y += replay.o

audio.c, vl-stub.c, and xen-mapcache.c are added by this patch but not added to Makefile.objs? Can they be removed?

Quoted 3 lines

Hey Stefan,

Sorry it’s not clear. but these files are referenced in Makefile.target.

Why is the Makefile.target change not in this patch?

Please structure patch series as logical changes that can be reviewed sequentially. Not only is it hard for reviewers to understand what is going on but it probably also breaks bisectability if patches contain incomplete changes.

Quoted 31 lines
Quoted 9 lines

This entire patch requires justification. Stubs exist so that common code can be linked without optional features.

For example, common code may call into kvm but that callback isn't relevant when building with kvm accelerator support (e.g. say qemu-nbd). That's where the stub function comes in. It fulfills the dependency without dragging in the actual kvm accelerator code.

Quoted 4 lines

Adding lots of stubs suggests you are building QEMU in a new way that wasn't done before (this is true and expected for this patch series). I would like to understand the reason for these stubs though. For example, why do you need to stub audio?

These stub functions are only used by the remote process, and not by QEMU itself.

Our goal is to ensure that the remote process is building the smallest set of files necessary and these stub functions are necessary to meet that goal.

For example, the remote process needs to build some of the functions defined in “hw/core/qdev-properties-system.c”. However, this file depends on audio.c (references audio_state_by_name()), which is not needed for the remote process. The alternative to stub functions would be to compile audio.c into the remote process, but that was not necessary in our judgement. When the project started out, we spent a lot of time figuring out which functions/files are necessary for the remote process, and we stubbed out the ones which are needed to resolve dependency during compilation, but not needed for functionality.

Quoted 5 lines

audio.c is just an example of tens of other places where we needed to make similar judgements.

Would you prefer if we moved these stub functions into a separate library (instead of stub-obj-y) which is only linked by the remote process?

It's too bad that none of these judgements were documented. As a reviewer I have no idea what the justification for each individual stub was.

Some stubs are unavoidable but they also indicate that the code is tightly coupled where maybe it can be split up. The qdev-properties-system.c example you mentioned sounds like something that should be broken up into multiple files. Then stubs wouldn't be necessary.

That said, adding stubs doesn't place a great burden on anyone and I think they can be merged.

#86 lore raw
In reply to [email protected]
Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

We will post separate patchsets for the following improvements for the experimental Qemu multi-process:
- Live migration;
- Asynchronous communication channel;
- Libvirt support;

We welcome all your ideas, concerns, and questions for this patchset.

This patch series does two things:
1. It introduces the remote device infrastructure.
2. It creates the remote device program and the associated build changes (makefiles, stubs, etc).

There are many patches and it's likely that a bunch more revisions will be necessary before this can be merged.

I want to share an idea to reduce the scope and get patches merged more quickly. It looks like the series can be reduced to 21 patches using this approach.

I suggest dropping the remote device program from this patch series (and maybe never bringing it back). Instead, use the softmmu target for the remote device.

Why? Because the remote device program is just a QEMU that uses the remote machine type and has no vCPUs:

  $ qemu-system-x86_64 -chardev id=char0,... \
                       -M remote,chardev=char0 \
		       -device lsi53c810 \
		       -drive if=none,id=drive0,file=vm.img,format=raw \
		       -device scsi-hd,drive=drive0

This will use the remote machine type, interrupt controller, and PCI bus that you have created.

The remote machine type should default to no vCPUs and no memory creation (the memory comes via the mpqemu link communications channel).

At this point qemu-system-x86_64 contains a lot of code that you don't want in the final remote device program. Let's ignore that for a second.

Now you can submit a 21-patch series containing just the remote device infrastructure. This will be easier to merge.

Returning to code size, the next step is to reduce the binary. QEMU has a Kconfig-style system for optional features and dependencies. It's a better approach than creating a separate make target because it eliminates the duplication and mess in the makefiles.

For example, you can disable TCG and KVM so that your binary has no ability to execute guest code. Currently ./configure disallows this but I've tried it and it works.

You can add a new default-configs/ file that disables CONFIG_ISAPC, CONFIG_I440FX, etc. When you compile QEMU most of hw/ will not be built anymore. At this point you have a smaller binary that is still a softmmu target so the makefiles are shared with the regular qemu-system-x86_64.

There will be some code for which there is no Kconfig option yet. Further improvements can be made by adding Kconfig options for any code that you wish to eliminate. Instead of writing makefile changes like you did in this patch series you would be adding Kconfig options. The nice thing is that this work isn't specific to the remote device program
- anyone can use the new Kconfig options to reduce the size of their QEMU. So not only is it less messy than duplicating the makefiles, but it also benefits everyone.

The downside to doing this is that it will take a while to eliminate all code that you don't want via Kconfig. However, your initial patch series can be merged sooner and I think this direction is also cleaner.

I hope I've explained the idea properly :). We can continue reviewing the current series if you prefer, but I think it would be quicker to drop the remote device program.

Stefan

#87 lore raw
Quoted 75 lines · Stefan Hajnoczi
Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

We will post separate patchsets for the following improvements for the experimental Qemu multi-process:
- Live migration;
- Asynchronous communication channel;
- Libvirt support;

We welcome all your ideas, concerns, and questions for this patchset.

This patch series does two things:
1. It introduces the remote device infrastructure.
2. It creates the remote device program and the associated build changes (makefiles, stubs, etc).

There are many patches and it's likely that a bunch more revisions will be necessary before this can be merged.

I want to share an idea to reduce the scope and get patches merged more quickly. It looks like the series can be reduced to 21 patches using this approach.

I suggest dropping the remote device program from this patch series (and maybe never bringing it back). Instead, use the softmmu target for the remote device.

Why? Because the remote device program is just a QEMU that uses the remote machine type and has no vCPUs:

  $ qemu-system-x86_64 -chardev id=char0,... \
                       -M remote,chardev=char0 \
		       -device lsi53c810 \
		       -drive if=none,id=drive0,file=vm.img,format=raw \
		       -device scsi-hd,drive=drive0

This will use the remote machine type, interrupt controller, and PCI bus that you have created.

The remote machine type should default to no vCPUs and no memory creation (the memory comes via the mpqemu link communications channel).

At this point qemu-system-x86_64 contains a lot of code that you don't want in the final remote device program. Let's ignore that for a second.

Now you can submit a 21-patch series containing just the remote device infrastructure. This will be easier to merge.

Returning to code size, the next step is to reduce the binary. QEMU has a Kconfig-style system for optional features and dependencies. It's a better approach than creating a separate make target because it eliminates the duplication and mess in the makefiles.

For example, you can disable TCG and KVM so that your binary has no ability to execute guest code. Currently ./configure disallows this but I've tried it and it works.

You can add a new default-configs/ file that disables CONFIG_ISAPC, CONFIG_I440FX, etc. When you compile QEMU most of hw/ will not be built anymore. At this point you have a smaller binary that is still a softmmu target so the makefiles are shared with the regular qemu-system-x86_64.

There will be some code for which there is no Kconfig option yet. Further improvements can be made by adding Kconfig options for any code that you wish to eliminate. Instead of writing makefile changes like you did in this patch series you would be adding Kconfig options. The nice thing is that this work isn't specific to the remote device program
- anyone can use the new Kconfig options to reduce the size of their QEMU. So not only is it less messy than duplicating the makefiles, but it also benefits everyone.

The downside to doing this is that it will take a while to eliminate all code that you don't want via Kconfig. However, your initial patch series can be merged sooner and I think this direction is also cleaner.

Quoted 5 lines

I hope I've explained the idea properly :). We can continue reviewing the current series if you prefer, but I think it would be quicker to drop the remote device program.

Stefan

Building QEMU twices just to get the remote is however not very attractive. So how about making remote a special target? Either remote-softmmu/ or if impossible x86_64-remote-softmmu/

Signature · 1 line
MST
#26 lore raw

Re: [PATCH RESEND v6 08/36] multi-process: Add stub functions to facilitate build of multi-process

In reply to Stefan Hajnoczi
Quoted 25 lines · Stefan Hajnoczi
Quoted 20 lines · Jag Raman
Quoted 17 lines · Stefan Hajnoczi
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:43PM -0700, [email protected] wrote:
stubs/Makefile.objs +0 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
Quoted 7 lines

stub-obj-y += change-state-handler.o
stub-obj-y += monitor.o
stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
stub-obj-y += notify-event.o
stub-obj-y += qtest.o
stub-obj-y += replay.o

audio.c, vl-stub.c, and xen-mapcache.c are added by this patch but not added to Makefile.objs? Can they be removed?

Hey Stefan,

Quoted 8 lines
Quoted 1 line

Sorry it’s not clear. but these files are referenced in Makefile.target.

Why is the Makefile.target change not in this patch?

Please structure patch series as logical changes that can be reviewed sequentially. Not only is it hard for reviewers to understand what is going on but it probably also breaks bisectability if patches contain incomplete changes.

Hi Stefan,

We grouped all the stubs into a separate patch for ease of review. If you’re finding it hard to review this way, we’ll modify to ensure that the Makefile changes go along with the stubs.

--
Jag

Quoted 50 lines
Quoted 32 lines
Quoted 10 lines

This entire patch requires justification. Stubs exist so that common code can be linked without optional features.

For example, common code may call into kvm but that callback isn't relevant when building with kvm accelerator support (e.g. say qemu-nbd). That's where the stub function comes in. It fulfills the dependency without dragging in the actual kvm accelerator code.

Quoted 4 lines

Adding lots of stubs suggests you are building QEMU in a new way that wasn't done before (this is true and expected for this patch series). I would like to understand the reason for these stubs though. For example, why do you need to stub audio?

These stub functions are only used by the remote process, and not by QEMU itself.

Our goal is to ensure that the remote process is building the smallest set of files necessary and these stub functions are necessary to meet that goal.

For example, the remote process needs to build some of the functions defined in “hw/core/qdev-properties-system.c”. However, this file depends on audio.c (references audio_state_by_name()), which is not needed for the remote process. The alternative to stub functions would be to compile audio.c into the remote process, but that was not necessary in our judgement. When the project started out, we spent a lot of time figuring out which functions/files are necessary for the remote process, and we stubbed out the ones which are needed to resolve dependency during compilation, but not needed for functionality.

Quoted 5 lines

audio.c is just an example of tens of other places where we needed to make similar judgements.

Would you prefer if we moved these stub functions into a separate library (instead of stub-obj-y) which is only linked by the remote process?

It's too bad that none of these judgements were documented. As a reviewer I have no idea what the justification for each individual stub was.

Some stubs are unavoidable but they also indicate that the code is tightly coupled where maybe it can be split up. The qdev-properties-system.c example you mentioned sounds like something that should be broken up into multiple files. Then stubs wouldn't be necessary.

That said, adding stubs doesn't place a great burden on anyone and I think they can be merged.

#88 lore raw
In reply to Michael S. Tsirkin
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Stefan Hajnoczi
Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:35PM -0700, [email protected] wrote:

We will post separate patchsets for the following improvements for the experimental Qemu multi-process:
- Live migration;
- Asynchronous communication channel;
- Libvirt support;

We welcome all your ideas, concerns, and questions for this patchset.

This patch series does two things:
1. It introduces the remote device infrastructure.
2. It creates the remote device program and the associated build changes (makefiles, stubs, etc).

There are many patches and it's likely that a bunch more revisions will be necessary before this can be merged.

I want to share an idea to reduce the scope and get patches merged more quickly. It looks like the series can be reduced to 21 patches using this approach.

I suggest dropping the remote device program from this patch series (and maybe never bringing it back). Instead, use the softmmu target for the remote device.

Why? Because the remote device program is just a QEMU that uses the remote machine type and has no vCPUs:

  $ qemu-system-x86_64 -chardev id=char0,... \
                       -M remote,chardev=char0 \
		       -device lsi53c810 \
		       -drive if=none,id=drive0,file=vm.img,format=raw \
		       -device scsi-hd,drive=drive0

This will use the remote machine type, interrupt controller, and PCI bus that you have created.

The remote machine type should default to no vCPUs and no memory creation (the memory comes via the mpqemu link communications channel).

At this point qemu-system-x86_64 contains a lot of code that you don't want in the final remote device program. Let's ignore that for a second.

Now you can submit a 21-patch series containing just the remote device infrastructure. This will be easier to merge.

Returning to code size, the next step is to reduce the binary. QEMU has a Kconfig-style system for optional features and dependencies. It's a better approach than creating a separate make target because it eliminates the duplication and mess in the makefiles.

For example, you can disable TCG and KVM so that your binary has no ability to execute guest code. Currently ./configure disallows this but I've tried it and it works.

You can add a new default-configs/ file that disables CONFIG_ISAPC, CONFIG_I440FX, etc. When you compile QEMU most of hw/ will not be built anymore. At this point you have a smaller binary that is still a softmmu target so the makefiles are shared with the regular qemu-system-x86_64.

There will be some code for which there is no Kconfig option yet. Further improvements can be made by adding Kconfig options for any code that you wish to eliminate. Instead of writing makefile changes like you did in this patch series you would be adding Kconfig options. The nice thing is that this work isn't specific to the remote device program
- anyone can use the new Kconfig options to reduce the size of their QEMU. So not only is it less messy than duplicating the makefiles, but it also benefits everyone.

The downside to doing this is that it will take a while to eliminate all code that you don't want via Kconfig. However, your initial patch series can be merged sooner and I think this direction is also cleaner.

I hope I've explained the idea properly :). We can continue reviewing the current series if you prefer, but I think it would be quicker to drop the remote device program.

Quoted 5 lines
Quoted 1 line

Stefan

Building QEMU twices just to get the remote is however not very attractive. So how about making remote a special target? Either remote-softmmu/ or if impossible x86_64-remote-softmmu/

Yes, that's a good idea. It needs to be the full x86_64-remote-softmmu because hw/ code depends on the QEMU target :(.

To summarize the big advantage of this approach (besides reducing the patch series): the existing makefile rules for softmmu will be used to build the remote device program. No new main() and no new per-object file makefile rules are needed.

Stefan

#27 lore raw

Re: [PATCH RESEND v6 08/36] multi-process: Add stub functions to facilitate build of multi-process

In reply to Jag Raman
Quoted 31 lines · Jag Raman
Quoted 22 lines · Stefan Hajnoczi
Quoted 20 lines · Jag Raman
Quoted 17 lines · Stefan Hajnoczi
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:43PM -0700, [email protected] wrote:
stubs/Makefile.objs +0 -0
index f884bb6180..f74c7e927b 100644
@@ -20,6 +20,7 @@ stub-obj-y += migr-blocker.o
Quoted 7 lines

stub-obj-y += change-state-handler.o
stub-obj-y += monitor.o
stub-obj-y += monitor-core.o
+stub-obj-y += get-fd.o
stub-obj-y += notify-event.o
stub-obj-y += qtest.o
stub-obj-y += replay.o

audio.c, vl-stub.c, and xen-mapcache.c are added by this patch but not added to Makefile.objs? Can they be removed?

Hey Stefan,

Quoted 8 lines
Quoted 1 line

Sorry it’s not clear. but these files are referenced in Makefile.target.

Why is the Makefile.target change not in this patch?

Please structure patch series as logical changes that can be reviewed sequentially. Not only is it hard for reviewers to understand what is going on but it probably also breaks bisectability if patches contain incomplete changes.

Quoted 5 lines

Hi Stefan,

We grouped all the stubs into a separate patch for ease of review. If you’re finding it hard to review this way, we’ll modify to ensure that the Makefile changes go along with the stubs.

Grouping all the stubs into a single patch isn't a problem.

The issue is that some of the new .c files are not referenced by any makefile rules. They aren't being compiled and may contain syntax errors.

There is also no justification for these stubs so reviewers don't know why exactly they are needed. I would have liked to know what required the creation of each stub. If you don't remember the details anymore then let's not worry about it, but sometimes there are cleaner ways of resolving dependencies than adding stubs.

Stefan

#89 lore raw
In reply to Stefan Hajnoczi
Quoted 3 lines · Stefan Hajnoczi
Quoted 3 lines
Quoted 3 lines

I suggest dropping the remote device program from this patch series (and maybe never bringing it back). Instead, use the softmmu target for the remote device.

...

Quoted 7 lines
Quoted 4 lines

Building QEMU twices just to get the remote is however not very attractive. So how about making remote a special target? Either remote-softmmu/ or if impossible x86_64-remote-softmmu/

Yes, that's a good idea. It needs to be the full x86_64-remote-softmmu because hw/ code depends on the QEMU target :(.

BTW using QEMU as backend source also gives us goodies such as cross-version compatibility for free.

Signature · 1 line
MST
#90 lore raw
In reply to [email protected]

Hi,
Have you decided whether to drop the remote device program in favor of using a softmmu make target?

Is there anything in this series you'd like me to review before you send the next revision?

Stefan

#91 lore raw
Quoted 10 lines · Stefan Hajnoczi

Hi,
Have you decided whether to drop the remote device program in favor of using a softmmu make target?

Is there anything in this series you'd like me to review before you send the next revision?

Hi Stefan,

We are planning to drop the separate remote device program in the next revision. We are planning to use QEMU’s existing event loop instead of a separate event loop for the remote process, as well as the command line invocation you suggested in your feedback.

We hope the following core patches look good to you, by and large:
[PATCH RESEND v6 01/36] memory: alloc RAM from file at offset
[PATCH RESEND v6 11/36] multi-process: define mpqemu-link object
[PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints [PATCH RESEND v6 13/36] multi-process: setup PCI host bridge for remote device [PATCH RESEND v6 14/36] multi-process: setup a machine object for remote device process [PATCH RESEND v6 15/36] multi-process: setup memory manager for remote device [PATCH RESEND v6 17/36] multi-process: introduce proxy object
[PATCH RESEND v6 18/36] multi-process: Initialize Proxy Object's communication channel [PATCH RESEND v6 19/36] multi-process: Connect Proxy Object with device in the remote process [PATCH RESEND v6 20/36] multi-process: Forward PCI config space acceses to the remote process [PATCH RESEND v6 21/36] multi-process: PCI BAR read/write handling for proxy & remote endpoints [PATCH RESEND v6 22/36] multi-process: Synchronize remote memory
[PATCH RESEND v6 23/36] multi-process: create IOHUB object to handle irq
[PATCH RESEND v6 24/36] multi-process: Retrieve PCI info from remote process

Thank you very much!
—
Jag

Quoted 2 lines

Stefan

Reviewed-by on v6 1/36
#2 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to [email protected]
Quoted 10 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Quoted 8 lines
---
 exec.c                    | 11 +++++++----
 include/exec/ram_addr.h   |  2 +-
 include/qemu/mmap-alloc.h |  3 ++-
 memory.c                  |  2 +-
 util/mmap-alloc.c         |  7 ++++---
 util/oslib-posix.c        |  2 +-
 6 files changed, 16 insertions(+), 11 deletions(-)
#3 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to [email protected]
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

NB, I'm not objecting - I'm just curious to understand more.

Quoted 152 lines
---
 exec.c                    | 11 +++++++----
 include/exec/ram_addr.h   |  2 +-
 include/qemu/mmap-alloc.h |  3 ++-
 memory.c                  |  2 +-
 util/mmap-alloc.c         |  7 ++++---
 util/oslib-posix.c        |  2 +-
 6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index 2874bb5088..d0ac9545f4 100644
@@ -1801,6 +1801,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     void *area;
@@ -1851,7 +1852,8 @@ static void *file_ram_alloc(RAMBlock *block,
     }
 
     area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
     if (area == MAP_FAILED) {
         error_setg_errno(errp, errno,
                          "unable to map backing store for guest RAM");
@@ -2283,7 +2285,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 #ifdef CONFIG_POSIX
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
@@ -2328,7 +2330,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
     new_block->used_length = size;
     new_block->max_length = size;
     new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
     if (!new_block->host) {
         g_free(new_block);
         return NULL;
@@ -2358,7 +2361,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
     if (!block) {
         if (created) {
             unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d8d7..1b9f489ff0 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                    Error **errp);
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266b92..4f579858bc 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index 601b749906..f5fec476b7 100644
@@ -1596,7 +1596,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
     mr->destructor = memory_region_destructor_ram;
     mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                            share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
     if (err) {
         mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd8ec..a28f7025f0 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
 {
     int flags;
     int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
     offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
     ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
     if (ptr == MAP_FAILED && map_sync_flags) {
         if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
          * we will remove these flags to handle compatibility.
          */
         ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
     }
 
     if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 062236a1ab..4c6b9e90c6 100644
@@ -209,7 +209,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
 {
     size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
     if (ptr == MAP_FAILED) {
         return NULL;
Signature · 1 line
2.25.GIT

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#33 lore raw

Re: [PATCH RESEND v6 11/36] multi-process: define mpqemu-link object

In reply to [email protected]
Quoted 9 lines · On Wed, Apr 22, 2020 at 09:13:46PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Defines mpqemu-link object which forms the communication link between QEMU & emulation program.
Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel.
Adds GMainLoop to handle events received on the communication channel.

Quoted 3 lines

This will change a lot when integrated into the QEMU event loop so I've skipped a lot of the code.

QIOChannel is probably the appropriate object to use instead of directly accessing a file descriptor.

Quoted 16 lines
include/io/mpqemu-link.h new file +16 -0
+/**
+ * mpqemu_cmd_t:
+ *
+ * proc_cmd_t enum type to specify the command to be executed on the remote
+ * device.
+ */
+typedef enum {
+    INIT = 0,
+    MAX,
+} mpqemu_cmd_t;
+
+/**
+ * MPQemuMsg:
+ * @cmd: The remote command
+ * @bytestream: Indicates if the data to be shared is structured (data1)
+ *              or unstructured (data2)

include/io/mpqemu-link.h line 53

Quoted 10 lines
include/io/mpqemu-link.h new file +10 -0
+ * @size: Size of the data to be shared
+ * @data1: Structured data
+ * @fds: File descriptors to be shared with remote device
+ * @data2: Unstructured data
+ *
+ * MPQemuMsg Format of the message sent to the remote device from QEMU.
+ *
+ */
+typedef struct {
+    mpqemu_cmd_t cmd;

Please use an int field on the wire because the C standard says:

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

So the compiler may make this a char field (which would introduce padding before the bytestream field) but if a new enum constant FOO = 0x100 is added then the compiler might change the size to 16-bit.

Quoted 23 lines
io/mpqemu-link.c new file +23 -0
+int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    size_t fdsize;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->recv_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;

io/mpqemu-link.c line 162

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+    hdr.msg_iovlen = 1;
+    hdr.msg_control = &u;
+    hdr.msg_controllen = sizeof(u);
+
+    WITH_QEMU_LOCK_GUARD(lock) {
+        do {
+            rc = recvmsg(sock, &hdr, 0);
+        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+        if (rc < 0) {

Missing rc != MPQEMU_MSG_HDR_SIZE check. If this was a short read we should not attempt to parse uninitialized bytes in msg.

This is more defensive than relying on catching bogus input values later on and also protects against accidentally revealing uninitialized memory contents by observing our error handling response.

Quoted 16 lines
io/mpqemu-link.c new file +16 -0
+            qemu_log_mask(LOG_REMOTE_DEBUG, "%s - recvmsg rc is %d, "
+                          "errno is %d, sock %d\n", __func__, rc, errno, sock);
+            return rc;
+        }
+
+        msg->num_fds = 0;
+        for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+             chdr = CMSG_NXTHDR(&hdr, chdr)) {
+            if ((chdr->cmsg_level == SOL_SOCKET) &&
+                (chdr->cmsg_type == SCM_RIGHTS)) {
+                fdsize = chdr->cmsg_len - CMSG_LEN(0);
+                msg->num_fds = fdsize / sizeof(int);
+                if (msg->num_fds > REMOTE_MAX_FDS) {
+                    qemu_log_mask(LOG_REMOTE_DEBUG,
+                                  "%s: Max FDs exceeded\n", __func__);
+                    return -ERANGE;

io/mpqemu-link.c line 188

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+                }
+
+                memcpy(msg->fds, CMSG_DATA(chdr), fdsize);
+                break;
+            }
+        }
+
+        if (msg->bytestream) {
+            if (!msg->size) {
+                qemu_mutex_unlock(lock);

Duplicate unlock, we're already inside WITH_QEMU_LOCK_GUARD().

io/mpqemu-link.c line 192

Quoted 4 lines
io/mpqemu-link.c new file +4 -0
+                return -EINVAL;
+            }
+
+            msg->data2 = calloc(1, msg->size);

What is the maximum message size? Please pick one and enforce it to protect against huge allocations that cause us to run out of memory.

io/mpqemu-link.c line 195

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+            data = msg->data2;
+        } else {
+            data = (uint8_t *)&msg->data1;

Adding a uint8_t member to the union eliminates the need for a cast:

  union {
      uint64_t u64;
      uint8_t u8;
  } data1;

...

  data = &msg->data1.u8;

io/mpqemu-link.c line 202

Quoted 7 lines
io/mpqemu-link.c new file +7 -0
+        }
+
+        if (msg->size) {
+            do {
+                rc = read(sock, data, msg->size);
+            } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+        }

Short reads are an error. Please check that the sum of rc values is equal to msg->size.

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+    }
+    return rc;
+}

...

io/mpqemu-link.c line 287

Quoted 5 lines
io/mpqemu-link.c new file +5 -0
+bool mpqemu_msg_valid(MPQemuMsg *msg)
+{
+    if (msg->cmd >= MAX) {
+        return false;
+    }

Checking msg->cmd < 0 is also useful here, especially when the field type is changed to int.

#36 lore raw

Re: [PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints

In reply to [email protected]
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:47PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

In some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process.

Why are temporary eventfds used instead of sending a reply message from the remote device program back to QEMU?

Quoted 13 lines
---
 include/io/mpqemu-link.h |  7 +++++
 io/mpqemu-link.c         | 61 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
include/io/mpqemu-link.h +0 -0
index af401e640c..ef95599bca 100644

include/io/mpqemu-link.h void mpqemu_link_set_callback(MPQemuLinkState *s, · line 128

Quoted 5 lines
include/io/mpqemu-link.h +2 -0
@@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
 void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan);
 bool mpqemu_msg_valid(MPQemuMsg *msg);
 
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)

Hiding this in macros makes the code harder to understand.

Why is an eventfd necessary instead of a reply message? It's simpler and probably faster to use a reply message instead of creating and passing temporary eventfds.

Quoted 30 lines
include/io/mpqemu-link.h +5 -0
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 #endif
io/mpqemu-link.c +9 -0
index 48f53a8928..cc0a7aecd4 100644
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include <poll.h>
 
 #include "qemu/module.h"
 #include "io/mpqemu-link.h"
@@ -204,6 +205,66 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
     return rc;
 }
 
+/*
+ * wait_for_remote() Synchronizes QEMU and the remote process. The maximum
+ *                   wait time is 1s, after which the wait times out.
+ *                   The function alse returns a 64 bit return value after
+ *                   the wait. The function uses eventfd() to do the wait
+ *                   and pass the return values. eventfd() can't return a
+ *                   value of '0'. Therefore, all return values are offset
+ *                   by '1' at the sending end, and corrected at the

io/mpqemu-link.c int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) · line 225

Quoted 10 lines
io/mpqemu-link.c +10 -0
+ *                   receiving end.
+ */
+
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };
+    uint64_t val;
+    int ret;
+
+    ret = poll(&pfd, 1, 1000);

This 1 second blocking operation is not allowed in an event loop since it will stall any other event loop activity. If locks are held then other threads may also be stalled.

It's likely that this will need to change as part of the QEMU event loop integration. Caller code can be kept mostly unchanged if you use coroutines.

Quoted 48 lines
io/mpqemu-link.c +42 -0
+
+    switch (ret) {
+    case 0:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+        /* TODO: Kick-off error recovery */
+        return UINT64_MAX;
+    case -1:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+                      strerror(errno));
+        return UINT64_MAX;
+    default:
+        if (read(efd, &val, sizeof(val)) == -1) {
+            qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                          strerror(errno));
+            return UINT64_MAX;
+        }
+    }
+
+    /*
+     * The remote process could write a non-zero value
+     * to the eventfd to wake QEMU up. However, the drawback of using eventfd
+     * for this purpose is that a return value of zero wouldn't wake QEMU up.
+     * Therefore, we offset the return value by one at the remote process and
+     * correct it in the QEMU end.
+     */
+    val = (val == UINT64_MAX) ? val : (val - 1);
+
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == UINT64_MAX) ? val : (val + 1);
+    ssize_t len = -1;
+
+    len = write(efd, &val, sizeof(val));
+    if (len == -1 || len != sizeof(val)) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
 static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
 {
     g_assert(timeout);
Signature · 1 line
2.25.GIT
#40 lore raw

Re: [PATCH RESEND v6 13/36] multi-process: setup PCI host bridge for remote device

In reply to [email protected]
Quoted 20 lines · On Wed, Apr 22, 2020 at 09:13:48PM -0700, [email protected] wrote:
include/remote/pcihost.h new file +14 -0
new file mode 100644
index 0000000000..7aca9ccaf1
@@ -0,0 +1,45 @@
+/*
+ * PCI Host for remote device
+ *
+ * Copyright © 2018, 2020 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_PCIHOST_H
+#define REMOTE_PCIHOST_H
+
+#include <stddef.h>

include/remote/pcihost.h line 24

Quoted 10 lines
include/remote/pcihost.h new file +10 -0
+#include <stdint.h>
+
+#include "exec/memory.h"
+#include "hw/pci/pcie_host.h"
+
+#define TYPE_REMOTE_HOST_DEVICE "remote-pcihost"
+#define REMOTE_HOST_DEVICE(obj) \
+    OBJECT_CHECK(RemPCIHost, (obj), TYPE_REMOTE_HOST_DEVICE)
+
+typedef struct RemPCIHost {

Hmm...this object has no state or behavior specific to remote device emulation. Could you use an existing PCIe host instead? It's not clear to me that a new object is needed.

Quoted 7 lines
include/remote/pcihost.h new file +7 -0
+    /*< private >*/
+    PCIExpressHost parent_obj;
+    /*< public >*/
+
+    /*
+     * Memory Controller Hub (MCH) may not be necessary for the emulation
+     * program. The two important reasons for implementing a PCI host in the

include/remote/pcihost.h line 41

Quoted 10 lines
include/remote/pcihost.h new file +10 -0
+     * emulation program are:
+     * - Provide a PCI bus for IO devices
+     * - Enable translation of guest PA to the PCI bar regions
+     *
+     * For both the above mentioned purposes, it doesn't look like we would
+     * need the MCH
+     */
+
+    MemoryRegion *mr_pci_mem;
+    MemoryRegion *mr_sys_mem;

Unused?

include/remote/pcihost.h line 43

Quoted 2 lines
include/remote/pcihost.h new file +2 -0
+    MemoryRegion *mr_sys_io;
+} RemPCIHost;

The name "RemotePCIHost" would be consistent with the QOM type and the filename. It might seem trivial but when reading code that others have written every time the naming changes you need to figure out why (just an inconsistency or is this a different concept/abstraction?).

Quoted 17 lines
include/remote/pcihost.h new file +2 -0
+
+#endif
remote/Makefile.objs +1 -0
index a9b2256b2a..2757f5a265 100644
@@ -1 +1,2 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
remote/pcihost.c new file +2 -0
new file mode 100644
index 0000000000..dbe081903e
@@ -0,0 +1,64 @@
+/*
+ * Remote PCI host device

remote/pcihost.c line 12

Quoted 10 lines
remote/pcihost.c new file +10 -0
+ *
+ * Copyright © 2018, 2020 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 <sys/types.h>
+#include <unistd.h>

"qemu/osdep.h" already includes these headers.

Quoted 41 lines
remote/pcihost.c new file +41 -0
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_host.h"
+#include "hw/qdev-properties.h"
+#include "remote/pcihost.h"
+#include "exec/memory.h"
+
+static const char *remote_host_root_bus_path(PCIHostState *host_bridge,
+                                             PCIBus *rootbus)
+{
+    return "0000:00";
+}
+
+static void remote_host_realize(DeviceState *dev, Error **errp)
+{
+    char *busname = g_strdup_printf("remote-pci-%ld", (unsigned long)getpid());
+    PCIHostState *pci = PCI_HOST_BRIDGE(dev);
+    RemPCIHost *s = REMOTE_HOST_DEVICE(dev);
+
+    pci->bus = pci_root_bus_new(DEVICE(s), busname,
+                                s->mr_pci_mem, s->mr_sys_io,
+                                0, TYPE_PCIE_BUS);
+}
+
+static void remote_host_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
+
+    hc->root_bus_path = remote_host_root_bus_path;
+    dc->realize = remote_host_realize;
+
+    dc->user_creatable = false;
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+    dc->fw_name = "pci";
+}
+
+static const TypeInfo remote_host_info = {
+    .name = TYPE_REMOTE_HOST_DEVICE,
+    .parent = TYPE_PCIE_HOST_BRIDGE,

remote/pcihost.c line 64

Quoted 10 lines
remote/pcihost.c new file +10 -0
+    .instance_size = sizeof(RemPCIHost),
+    .class_init = remote_host_class_init,
+};
+
+static void remote_machine_register(void)
+{
+    type_register_static(&remote_host_info);
+}
+
+type_init(remote_machine_register)

The naming in this file is inconsistent:

remote_host_root_bus_path -> remote_pcihost_root_bus_path remote_machine_register -> remote_pcihost_register

I haven't listed all instances.

#42 lore raw

Re: [PATCH RESEND v6 14/36] multi-process: setup a machine object for remote device process

In reply to [email protected]
Quoted 9 lines · On Wed, Apr 22, 2020 at 09:13:49PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.

Quoted 9 lines
---
 MAINTAINERS                   |  2 +
 Makefile.objs                 |  1 +
 exec.c                        |  3 +-
 include/exec/address-spaces.h |  2 +
 include/remote/machine.h      | 30 +++++++++++++
 remote/Makefile.objs          |  2 +
 remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
 remote/remote-main.c          |  7 +++

Now that the separate remote emulation program is going away I think it makes sense to move the PCIe host and machine type into hw/:

hw/pci-host/remote.c <-- PCIe host
hw/i386/remote.c <-- machine type (could be moved again later if
other architectures are supported)

exec.c typedef struct subpage_t { · line 164

Quoted 9 lines
exec.c +0 -1
index d0ac9545f4..5b1e414099 100644
@@ -161,7 +161,6 @@ typedef struct subpage_t {
 #define PHYS_SECTION_UNASSIGNED 0
 
 static void io_mem_init(void);
-static void memory_map_init(void);

The memory_map_init() change is unnecessary once a softmmu target is used since it will be called from cpu_exec_init_all().

exec.c typedef struct subpage_t {

Quoted 10 lines
exec.c +10 -0
+static void remote_machine_init(Object *obj)
+{
+    RemMachineState *s = REMOTE_MACHINE(obj);
+    RemPCIHost *rem_host;
+    MemoryRegion *system_memory, *system_io, *pci_memory;
+
+    Error *error_abort = NULL;
+
+    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
+    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

Quoted 12 lines
exec.c +12 -0
+        error_report_err(error_abort);
+    }
+
+    memory_map_init();
+
+    system_memory = get_system_memory();
+    system_io = get_system_io();
+
+    pci_memory = g_new(MemoryRegion, 1);
+    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+
+    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));

exec.c

Quoted 10 lines
exec.c +10 -0
+
+    rem_host->mr_pci_mem = pci_memory;
+    rem_host->mr_sys_mem = system_memory;
+    rem_host->mr_sys_io = system_io;
+
+    s->host = rem_host;
+
+    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
+                              &error_abort);
+    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

exec.c

Quoted 5 lines
exec.c +5 -0
+        error_report_err(error_abort);
+        return;
+    }
+
+    qemu_mutex_lock_iothread();

This will be executed with the iothread lock held. There is no need to acquire it.

Quoted 5 lines
exec.c +5 -0
+    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
+    qemu_mutex_unlock_iothread();
+
+    qdev_init_nofail(DEVICE(rem_host));
+}
#4 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to Daniel P. Berrangé
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

Thank you!
--
Jag

Quoted 164 lines

NB, I'm not objecting - I'm just curious to understand more.

Quoted 152 lines

---

exec.c                    | 11 +++++++----
include/exec/ram_addr.h   |  2 +-
include/qemu/mmap-alloc.h |  3 ++-
memory.c                  |  2 +-
util/mmap-alloc.c         |  7 ++++---
util/oslib-posix.c        |  2 +-
6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index 2874bb5088..d0ac9545f4 100644
@@ -1801,6 +1801,7 @@ static void *file_ram_alloc(RAMBlock *block,
                            ram_addr_t memory,
                            int fd,
                            bool truncate,
+                            off_t offset,
                            Error **errp)
 {
    void *area;
@@ -1851,7 +1852,8 @@ static void *file_ram_alloc(RAMBlock *block,
    }
 
    area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
    if (area == MAP_FAILED) {
        error_setg_errno(errp, errno,
                         "unable to map backing store for guest RAM");
@@ -2283,7 +2285,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 #ifdef CONFIG_POSIX
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                 uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
 {
    RAMBlock *new_block;
    Error *local_err = NULL;
@@ -2328,7 +2330,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
    new_block->used_length = size;
    new_block->max_length = size;
    new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
    if (!new_block->host) {
        g_free(new_block);
        return NULL;
@@ -2358,7 +2361,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
        return NULL;
    }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
    if (!block) {
        if (created) {
            unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d8d7..1b9f489ff0 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                   Error **errp);
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                 uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                  MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266b92..4f579858bc 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                    size_t size,
                    size_t align,
                    bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index 601b749906..f5fec476b7 100644
@@ -1596,7 +1596,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
    mr->destructor = memory_region_destructor_ram;
    mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                           share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
    if (err) {
        mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd8ec..a28f7025f0 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                    size_t size,
                    size_t align,
                    bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
 {
    int flags;
    int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
    offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
    ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
    if (ptr == MAP_FAILED && map_sync_flags) {
        if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
         * we will remove these flags to handle compatibility.
         */
        ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
    }
 
    if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 062236a1ab..4c6b9e90c6 100644
@@ -209,7 +209,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
 {
    size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
    if (ptr == MAP_FAILED) {
        return NULL;
Signature · 1 line
2.25.GIT

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#34 lore raw

Re: [PATCH RESEND v6 11/36] multi-process: define mpqemu-link object

In reply to Stefan Hajnoczi
Quoted 18 lines · Stefan Hajnoczi
Quoted 9 lines · On Wed, Apr 22, 2020 at 09:13:46PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Defines mpqemu-link object which forms the communication link between QEMU & emulation program.
Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel.
Adds GMainLoop to handle events received on the communication channel.

Quoted 3 lines
Quoted 5 lines

This will change a lot when integrated into the QEMU event loop so I've skipped a lot of the code.

QIOChannel is probably the appropriate object to use instead of directly accessing a file descriptor.

OK, got it. Thanks!

Quoted 155 lines
Quoted 17 lines
include/io/mpqemu-link.h new file +16 -0
+/**
+ * mpqemu_cmd_t:
+ *
+ * proc_cmd_t enum type to specify the command to be executed on the remote
+ * device.
+ */
+typedef enum {
+    INIT = 0,
+    MAX,
+} mpqemu_cmd_t;
+
+/**
+ * MPQemuMsg:
+ * @cmd: The remote command
+ * @bytestream: Indicates if the data to be shared is structured (data1)
+ *              or unstructured (data2)

include/io/mpqemu-link.h line 53

Quoted 10 lines
include/io/mpqemu-link.h new file +10 -0
+ * @size: Size of the data to be shared
+ * @data1: Structured data
+ * @fds: File descriptors to be shared with remote device
+ * @data2: Unstructured data
+ *
+ * MPQemuMsg Format of the message sent to the remote device from QEMU.
+ *
+ */
+typedef struct {
+    mpqemu_cmd_t cmd;

Please use an int field on the wire because the C standard says:

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.

So the compiler may make this a char field (which would introduce padding before the bytestream field) but if a new enum constant FOO = 0x100 is added then the compiler might change the size to 16-bit.

Quoted 23 lines
io/mpqemu-link.c new file +23 -0
+int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    size_t fdsize;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->recv_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;

io/mpqemu-link.c line 162

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+    hdr.msg_iovlen = 1;
+    hdr.msg_control = &u;
+    hdr.msg_controllen = sizeof(u);
+
+    WITH_QEMU_LOCK_GUARD(lock) {
+        do {
+            rc = recvmsg(sock, &hdr, 0);
+        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+        if (rc < 0) {

Missing rc != MPQEMU_MSG_HDR_SIZE check. If this was a short read we should not attempt to parse uninitialized bytes in msg.

This is more defensive than relying on catching bogus input values later on and also protects against accidentally revealing uninitialized memory contents by observing our error handling response.

Quoted 16 lines
io/mpqemu-link.c new file +16 -0
+            qemu_log_mask(LOG_REMOTE_DEBUG, "%s - recvmsg rc is %d, "
+                          "errno is %d, sock %d\n", __func__, rc, errno, sock);
+            return rc;
+        }
+
+        msg->num_fds = 0;
+        for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+             chdr = CMSG_NXTHDR(&hdr, chdr)) {
+            if ((chdr->cmsg_level == SOL_SOCKET) &&
+                (chdr->cmsg_type == SCM_RIGHTS)) {
+                fdsize = chdr->cmsg_len - CMSG_LEN(0);
+                msg->num_fds = fdsize / sizeof(int);
+                if (msg->num_fds > REMOTE_MAX_FDS) {
+                    qemu_log_mask(LOG_REMOTE_DEBUG,
+                                  "%s: Max FDs exceeded\n", __func__);
+                    return -ERANGE;

io/mpqemu-link.c line 188

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+                }
+
+                memcpy(msg->fds, CMSG_DATA(chdr), fdsize);
+                break;
+            }
+        }
+
+        if (msg->bytestream) {
+            if (!msg->size) {
+                qemu_mutex_unlock(lock);

Duplicate unlock, we're already inside WITH_QEMU_LOCK_GUARD().

io/mpqemu-link.c line 192

Quoted 4 lines
io/mpqemu-link.c new file +4 -0
+                return -EINVAL;
+            }
+
+            msg->data2 = calloc(1, msg->size);

What is the maximum message size? Please pick one and enforce it to protect against huge allocations that cause us to run out of memory.

io/mpqemu-link.c line 195

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+            data = msg->data2;
+        } else {
+            data = (uint8_t *)&msg->data1;

Adding a uint8_t member to the union eliminates the need for a cast:

 union {
     uint64_t u64;
     uint8_t u8;

} data1;

...

data = &msg->data1.u8;

io/mpqemu-link.c line 202

Quoted 7 lines
io/mpqemu-link.c new file +7 -0
+        }
+
+        if (msg->size) {
+            do {
+                rc = read(sock, data, msg->size);
+            } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+        }

Short reads are an error. Please check that the sum of rc values is equal to msg->size.

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+    }
+    return rc;
+}

...

io/mpqemu-link.c line 287

Quoted 5 lines
io/mpqemu-link.c new file +5 -0
+bool mpqemu_msg_valid(MPQemuMsg *msg)
+{
+    if (msg->cmd >= MAX) {
+        return false;
+    }

Checking msg->cmd < 0 is also useful here, especially when the field type is changed to int.

#45 lore raw

Re: [PATCH RESEND v6 15/36] multi-process: setup memory manager for remote device

In reply to [email protected]

exec.c RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, · line 2375

Quoted 10 lines · On Wed, Apr 22, 2020 at 09:13:50PM -0700, [email protected] wrote:
exec.c +2 -0
index 5b1e414099..1e02e00f00 100644
@@ -2371,6 +2371,23 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
 
     return block;
 }
+
+void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size,

This looks like a memory_region_init_*() function, not a qemu_ram_*() function. Why is it being added to exec.c instead of memory.c?

exec.c RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, · line 2376

Quoted 1 line
exec.c +1 -0
+                           ram_addr_t offset, Error **errp)

qemu_ram_alloc_from_fd()'s offset argument has the off_t type. Why is ram_addr_t used here?

exec.c RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, · line 2380

Quoted 4 lines
exec.c +4 -0
+typedef struct {
+    hwaddr gpas[REMOTE_MAX_FDS];
+    uint64_t sizes[REMOTE_MAX_FDS];
+    ram_addr_t offsets[REMOTE_MAX_FDS];

Should this be off_t because it's the file offset, not a RAMBlock address?

exec.c RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, · line 2381

Quoted 1 line
exec.c +1 -0
+} sync_sysmem_msg_t;

QEMU coding style would name this struct SyncSysMemMsg.

Quoted 7 lines
exec.c +7 -0
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
+{
+    sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem;
+    MemoryRegion *sysmem, *subregion, *next;
+    Error *local_err = NULL;
+    int region;
+

exec.c RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,

Quoted 10 lines
exec.c +10 -0
+    sysmem = get_system_memory();
+
+    qemu_mutex_lock_iothread();
+
+    memory_region_transaction_begin();
+
+    QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) {
+        if (subregion->ram) {
+            memory_region_del_subregion(sysmem, subregion);
+            qemu_ram_free(subregion->ram_block);

subregion is leaked. qemu_ram_free() shouldn't be called directly. It's normally called from the MemoryRegion->destructor function but that wasn't set up by qemu_ram_init_from_fd().

Please check how MemoryRegion lifecycles should work, update qemu_ram_init_from_fd(), and update this function to avoid leaks.

exec.c

Quoted 8 lines
exec.c +8 -0
+        }
+    }
+
+    for (region = 0; region < msg->num_fds; region++) {
+        subregion = g_new(MemoryRegion, 1);
+        qemu_ram_init_from_fd(subregion, msg->fds[region],
+                              sysmem_info->sizes[region],
+                              sysmem_info->offsets[region], &local_err);

Where are is msg->fds[region] closed?

#43 lore raw

Re: [PATCH RESEND v6 14/36] multi-process: setup a machine object for remote device process

In reply to Stefan Hajnoczi
Quoted 24 lines · Stefan Hajnoczi
Quoted 10 lines · On Wed, Apr 22, 2020 at 09:13:49PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.

---

Quoted 8 lines
MAINTAINERS                   |  2 +
Makefile.objs                 |  1 +
exec.c                        |  3 +-
include/exec/address-spaces.h |  2 +
include/remote/machine.h      | 30 +++++++++++++
remote/Makefile.objs          |  2 +
remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++
remote/remote-main.c          |  7 +++
Quoted 6 lines

Now that the separate remote emulation program is going away I think it makes sense to move the PCIe host and machine type into hw/:

hw/pci-host/remote.c <-- PCIe host
hw/i386/remote.c <-- machine type (could be moved again later if
other architectures are supported)

OK, got it.

Quoted 8 lines
Quoted 8 lines
exec.c +0 -0
index d0ac9545f4..5b1e414099 100644
@@ -161,7 +161,6 @@ typedef struct subpage_t {
 #define PHYS_SECTION_UNASSIGNED 0
 
Quoted 5 lines

exec.c typedef struct subpage_t { · line 164

Quoted 2 lines
exec.c +0 -1
 static void io_mem_init(void);
-static void memory_map_init(void);

The memory_map_init() change is unnecessary once a softmmu target is used since it will be called from cpu_exec_init_all().

OK.

Quoted 13 lines

exec.c typedef struct subpage_t {

Quoted 11 lines
exec.c +10 -0
+static void remote_machine_init(Object *obj)
+{
+    RemMachineState *s = REMOTE_MACHINE(obj);
+    RemPCIHost *rem_host;
+    MemoryRegion *system_memory, *system_io, *pci_memory;
+
+    Error *error_abort = NULL;
+
+    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
+    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

OK, thanks!

Quoted 26 lines
Quoted 13 lines
exec.c +12 -0
+        error_report_err(error_abort);
+    }
+
+    memory_map_init();
+
+    system_memory = get_system_memory();
+    system_io = get_system_io();
+
+    pci_memory = g_new(MemoryRegion, 1);
+    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+
+    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));

exec.c

Quoted 10 lines
exec.c +10 -0
+
+    rem_host->mr_pci_mem = pci_memory;
+    rem_host->mr_sys_mem = system_memory;
+    rem_host->mr_sys_io = system_io;
+
+    s->host = rem_host;
+
+    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
+                              &error_abort);
+    if (error_abort) {

error_abort aborts the program so handling it is not necessary.

Quoted 8 lines

exec.c

Quoted 5 lines
exec.c +5 -0
+        error_report_err(error_abort);
+        return;
+    }
+
+    qemu_mutex_lock_iothread();

This will be executed with the iothread lock held. There is no need to acquire it.

Yes, this wouldn’t be necessary from QEMU’s main loop.

Thanks!
--
Jag

Quoted 6 lines
Quoted 6 lines
exec.c +5 -0
+    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
+    qemu_mutex_unlock_iothread();
+
+    qdev_init_nofail(DEVICE(rem_host));
+}
#48 lore raw

Re: [PATCH RESEND v6 17/36] multi-process: introduce proxy object

In reply to [email protected]
Quoted 3 lines · On Wed, Apr 22, 2020 at 09:13:52PM -0700, [email protected] wrote:

From: Elena Ufimtseva <[email protected]>

Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.

s/parent/child/

Quoted 3 lines

PCI Proxy Object registers as a PCI device with QEMU and forwards all PCI accesses to the remote process using the communication channel.

Please include that functionality in this patch. The code below just sets up a skeleton PCI device. There is no code that forwards accesses to the remote process.

Quoted 20 lines
---
 MAINTAINERS                   |  3 ++
 hw/Makefile.objs              |  2 ++
 hw/proxy/Makefile.objs        |  1 +
 hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
 include/io/mpqemu-link.h      |  1 +
 6 files changed, 109 insertions(+)
 create mode 100644 hw/proxy/Makefile.objs
 create mode 100644 hw/proxy/qemu-proxy.c
 create mode 100644 include/hw/proxy/qemu-proxy.h
MAINTAINERS +0 -0
index 96f8d7ff19..3da3dcd311 100644

MAINTAINERS F: include/remote/machine.h · line 2871

Quoted 6 lines
MAINTAINERS +3 -0
@@ -2866,6 +2866,9 @@ F: include/remote/machine.h
 F: remote/machine.c
 F: include/remote/memory.h
 F: remote/memory.c
+F: hw/proxy/Makefile.objs
+F: hw/proxy/qemu-proxy.c
+F: include/hw/proxy/qemu-proxy.h

It's a generic PCI device. hw/pci/proxy.c would be a good location for it.

By the way an alternative to the "proxy"/"remote" terminology is RemotePCIClient/RemotePCIServer. That makes it more obvious that "proxy" is related the "remote" feature. Feel free to keep the existing terminology, I just wanted to suggest another possibility.

Quoted 42 lines
MAINTAINERS +0 -0
 Build and test automation
 -------------------------
hw/Makefile.objs +2 -0
index af9235b6f2..7b489b12a5 100644
@@ -45,6 +45,8 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
+common-obj-$(CONFIG_MPQEMU) += proxy/
+
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..eb81624cf8
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +13 -0
new file mode 100644
index 0000000000..bf6c4117ef
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2018, 2020 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 "qapi/error.h"
+#include "io/mpqemu-link.h"

hw/proxy/qemu-proxy.c line 23

Quoted 10 lines
hw/proxy/qemu-proxy.c new file +10 -0
+#include "hw/proxy/qemu-proxy.h"
+#include "hw/pci/pci.h"
+
+static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(device);
+    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    Error *local_err = NULL;
+
+    if (k->realize) {

Will anything inherit from this class? I thought this is the remote PCI client that can acts as a stand-in for all remote PCI devices, so it's not clear why it's acting as a base class here.

include/io/mpqemu-link.h line 17

Quoted 9 lines
include/io/mpqemu-link.h +1 -0
index d46cb81058..73cc59b874 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
+#include "sys/eventfd.h"

Why? Nothing in this patch uses this header.

#37 lore raw

Re: [PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints

In reply to Stefan Hajnoczi
Quoted 13 lines · Stefan Hajnoczi
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:47PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

In some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process.

Why are temporary eventfds used instead of sending a reply message from the remote device program back to QEMU?

Originally, we were envisioning a scenario where the remote process would interrupt QEMU with a message. We used separate eventfds to distinguish the two.

Quoted 17 lines
Quoted 17 lines

---
include/io/mpqemu-link.h | 7 +++++
io/mpqemu-link.c | 61 ++++++++++++++++++++++++++++++++++++++++

2 files changed, 68 insertions(+)
include/io/mpqemu-link.h +0 -0
index af401e640c..ef95599bca 100644
@@ -124,4 +124,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
 void mpqemu_start_coms(MPQemuLinkState *s, MPQemuChannel* chan);
 bool mpqemu_msg_valid(MPQemuMsg *msg);
 
Quoted 8 lines

include/io/mpqemu-link.h void mpqemu_link_set_callback(MPQemuLinkState *s, · line 128

Quoted 2 lines
include/io/mpqemu-link.h +2 -0
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)

Hiding this in macros makes the code harder to understand.

Why is an eventfd necessary instead of a reply message? It's simpler and probably faster to use a reply message instead of creating and passing temporary eventfds.

OK, got it.

Quoted 46 lines
Quoted 31 lines
include/io/mpqemu-link.h +5 -0
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 #endif
io/mpqemu-link.c +9 -0
index 48f53a8928..cc0a7aecd4 100644
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include <poll.h>
 
 #include "qemu/module.h"
 #include "io/mpqemu-link.h"
@@ -204,6 +205,66 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
    return rc;
 }
 
+/*
+ * wait_for_remote() Synchronizes QEMU and the remote process. The maximum
+ *                   wait time is 1s, after which the wait times out.
+ *                   The function alse returns a 64 bit return value after
+ *                   the wait. The function uses eventfd() to do the wait
+ *                   and pass the return values. eventfd() can't return a
+ *                   value of '0'. Therefore, all return values are offset
+ *                   by '1' at the sending end, and corrected at the

io/mpqemu-link.c int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) · line 225

Quoted 10 lines
io/mpqemu-link.c +10 -0
+ *                   receiving end.
+ */
+
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };
+    uint64_t val;
+    int ret;
+
+    ret = poll(&pfd, 1, 1000);

This 1 second blocking operation is not allowed in an event loop since it will stall any other event loop activity. If locks are held then other threads may also be stalled.

Quoted 3 lines

It's likely that this will need to change as part of the QEMU event loop integration. Caller code can be kept mostly unchanged if you use coroutines.

In case the remote process has hung or terminated, the 1 second timeout ensures that the IO operation does not block for too long.

--
Jag

Quoted 49 lines
Quoted 49 lines
io/mpqemu-link.c +42 -0
+
+    switch (ret) {
+    case 0:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+        /* TODO: Kick-off error recovery */
+        return UINT64_MAX;
+    case -1:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+                      strerror(errno));
+        return UINT64_MAX;
+    default:
+        if (read(efd, &val, sizeof(val)) == -1) {
+            qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                          strerror(errno));
+            return UINT64_MAX;
+        }
+    }
+
+    /*
+     * The remote process could write a non-zero value
+     * to the eventfd to wake QEMU up. However, the drawback of using eventfd
+     * for this purpose is that a return value of zero wouldn't wake QEMU up.
+     * Therefore, we offset the return value by one at the remote process and
+     * correct it in the QEMU end.
+     */
+    val = (val == UINT64_MAX) ? val : (val - 1);
+
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == UINT64_MAX) ? val : (val + 1);
+    ssize_t len = -1;
+
+    len = write(efd, &val, sizeof(val));
+    if (len == -1 || len != sizeof(val)) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
 static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
 {
    g_assert(timeout);
Signature · 1 line
2.25.GIT
#51 lore raw

Re: [PATCH RESEND v6 18/36] multi-process: Initialize Proxy Object's communication channel

In reply to [email protected]
Quoted 17 lines · On Wed, Apr 22, 2020 at 09:13:53PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Add "socket" object property which initializes the communication channel

---
 hw/proxy/qemu-proxy.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
hw/proxy/qemu-proxy.c +0 -0
index bf6c4117ef..40bf56fd37 100644
@@ -14,6 +14,25 @@
 #include "hw/proxy/qemu-proxy.h"

hw/proxy/qemu-proxy.c line 24

Quoted 10 lines
hw/proxy/qemu-proxy.c +8 -0
 #include "hw/pci/pci.h"
 
+static void proxy_set_socket(Object *obj, const char *str, Error **errp)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+
+    pdev->socket = atoi(str);
+
+    mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
+                        pdev->socket);

If mpqemu_link objects are not going to use QOM's object-oriented features then a plain C struct is fine. There is no need to define a QOM type for mpqemu_link in an earlier patch.

hw/proxy/qemu-proxy.c line 33

Quoted 9 lines
hw/proxy/qemu-proxy.c +9 -0
+}
+
+static void proxy_init(Object *obj)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+
+    pdev->mpqemu_link = mpqemu_link_create();
+
+    object_property_add_str(obj, "socket", NULL, proxy_set_socket, NULL);

Please use a qdev property like vhost-vsock.c's vhostfd and call it either "fd" so it's clear this is the file descriptor.

monitor_fd_param() should be used to parse the fd string at .realize() time.

#49 lore raw

Re: [PATCH RESEND v6 17/36] multi-process: introduce proxy object

In reply to Stefan Hajnoczi
Quoted 49 lines · Stefan Hajnoczi
Quoted 3 lines · On Wed, Apr 22, 2020 at 09:13:52PM -0700, [email protected] wrote:

From: Elena Ufimtseva <[email protected]>

Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE.

s/parent/child/

Quoted 3 lines

PCI Proxy Object registers as a PCI device with QEMU and forwards all PCI accesses to the remote process using the communication channel.

Please include that functionality in this patch. The code below just sets up a skeleton PCI device. There is no code that forwards accesses to the remote process.

Quoted 23 lines

---

MAINTAINERS                   |  3 ++
hw/Makefile.objs              |  2 ++
hw/proxy/Makefile.objs        |  1 +
hw/proxy/qemu-proxy.c         | 56 +++++++++++++++++++++++++++++++++++
include/hw/proxy/qemu-proxy.h | 46 ++++++++++++++++++++++++++++
include/io/mpqemu-link.h      |  1 +
6 files changed, 109 insertions(+)

create mode 100644 hw/proxy/Makefile.objs
create mode 100644 hw/proxy/qemu-proxy.c
create mode 100644 include/hw/proxy/qemu-proxy.h

MAINTAINERS +0 -0
index 96f8d7ff19..3da3dcd311 100644
@@ -2866,6 +2866,9 @@ F: include/remote/machine.h

F: remote/machine.c
F: include/remote/memory.h
F: remote/memory.c

MAINTAINERS F: include/remote/machine.h · line 2871

Quoted 3 lines
MAINTAINERS +3 -0
+F: hw/proxy/Makefile.objs
+F: hw/proxy/qemu-proxy.c
+F: include/hw/proxy/qemu-proxy.h

It's a generic PCI device. hw/pci/proxy.c would be a good location for it.

Quoted 4 lines

By the way an alternative to the "proxy"/"remote" terminology is RemotePCIClient/RemotePCIServer. That makes it more obvious that "proxy" is related the "remote" feature. Feel free to keep the existing terminology, I just wanted to suggest another possibility.

OK, got it.

Quoted 49 lines
Quoted 49 lines

Build and test automation
-------------------------

hw/Makefile.objs +2 -0
index af9235b6f2..7b489b12a5 100644
@@ -45,6 +45,8 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
+common-obj-$(CONFIG_MPQEMU) += proxy/
+

remote-pci-obj-$(CONFIG_MPQEMU) += core/
remote-pci-obj-$(CONFIG_MPQEMU) += block/
remote-pci-obj-$(CONFIG_MPQEMU) += pci/

hw/proxy/Makefile.objs new file +1 -0
new file mode 100644
index 0000000000..eb81624cf8
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +19 -0
new file mode 100644
index 0000000000..bf6c4117ef
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2018, 2020 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 "qapi/error.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "hw/pci/pci.h"
+
+static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(device);
Quoted 8 lines

hw/proxy/qemu-proxy.c line 23

Quoted 4 lines
hw/proxy/qemu-proxy.c new file +4 -0
+    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    Error *local_err = NULL;
+
+    if (k->realize) {

Will anything inherit from this class? I thought this is the remote PCI client that can acts as a stand-in for all remote PCI devices, so it's not clear why it's acting as a base class here.

No one is inheriting from this class anymore. This is code from before when that was the case. We could remove this.

Quoted 9 lines
Quoted 9 lines
include/io/mpqemu-link.h +0 -0
index d46cb81058..73cc59b874 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
Quoted 3 lines

include/io/mpqemu-link.h line 17

Quoted 1 line
include/io/mpqemu-link.h +1 -0
+#include "sys/eventfd.h"

Why? Nothing in this patch uses this header.

OK, got it.

Thanks!
—
Jag

#53 lore raw

Re: [PATCH RESEND v6 19/36] multi-process: Connect Proxy Object with device in the remote process

In reply to [email protected]
Quoted 4 lines · On Wed, Apr 22, 2020 at 09:13:54PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Send a message to the remote process to connect PCI device with the corresponding Proxy object in QEMU

The CONNECT_DEV message is no longer necessary with a 1 socket per device architecture. Connecting to a specific UNIX domain socket (e.g. vm001/lsi-scsi-1.sock) already identifies which device the proxy wishes to talk to.

Each device should have an mpqemu link that accepts client connections. You can either do that in the main loop or you can use IOThread to run dedicated per-device threads.

Quoted 22 lines
---
 hw/proxy/qemu-proxy.c    | 34 +++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  5 +++++
 io/mpqemu-link.c         |  3 +++
 remote/remote-main.c     | 43 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 85 insertions(+)
hw/proxy/qemu-proxy.c +3 -0
index 40bf56fd37..9b5e429a88 100644
@@ -17,11 +17,45 @@
 static void proxy_set_socket(Object *obj, const char *str, Error **errp)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(obj);
+    DeviceState *dev = DEVICE(obj);
+    MPQemuMsg msg = { 0 };
+    int wait, fd[2];

hw/proxy/qemu-proxy.c line 32

Quoted 10 lines
hw/proxy/qemu-proxy.c +5 -0
 
     pdev->socket = atoi(str);
 
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        error_setg(errp, "Failed to create socket for device channel");
+        return;
+    }

This extra connection can be removed. The reasons for having it have gone away now that there is just 1 device per socket.

hw/proxy/qemu-proxy.c line 39

Quoted 7 lines
hw/proxy/qemu-proxy.c +7 -0
+
+    wait = GET_REMOTE_WAIT;
+
+    msg.cmd = CONNECT_DEV;
+    msg.bytestream = 1;
+    msg.data2 = (uint8_t *)g_strdup(dev->id);
+    msg.size = sizeof(msg.data2);

The g_strdup() is unnecessary, dev->id can be used directly.

Should msg.size be strlen(dev->id) instead of sizeof(msg.data2)?

Quoted 83 lines
hw/proxy/qemu-proxy.c +19 -0
+    msg.num_fds = 2;
+    msg.fds[0] = wait;
+    msg.fds[1] = fd[1];
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    if (wait_for_remote(wait)) {
+        error_setg(errp, "Failed to connect device to the remote");
+        close(fd[0]);
+    } else {
+        mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->dev,
+                            fd[0]);
+    }
+
+    PUT_REMOTE_WAIT(wait);
+
+    close(fd[1]);
+
+    g_free(msg.data2);
 }
 
 static void proxy_init(Object *obj)
include/io/mpqemu-link.h +5 -0
index 73cc59b874..ebae9afc45 100644
@@ -38,6 +38,7 @@
 typedef enum {
     INIT = 0,
     SYNC_SYSMEM,
+    CONNECT_DEV,
     MAX,
 } mpqemu_cmd_t;
 
@@ -120,8 +121,12 @@ struct MPQemuLinkState {
     GMainLoop *loop;
 
     MPQemuChannel *com;
+    MPQemuChannel *dev;
 
     mpqemu_link_callback callback;
+
+    void *opaque;
+    QemuThread thread;
 };
 
 MPQemuLinkState *mpqemu_link_create(void);
io/mpqemu-link.c +3 -0
index 3f81cef96e..f780b65181 100644
@@ -46,6 +46,9 @@ MPQemuLinkState *mpqemu_link_create(void)
     MPQemuLinkState *link = MPQEMU_LINK(object_new(TYPE_MPQEMU_LINK));
 
     link->com = NULL;
+    link->dev = NULL;
+
+    link->opaque = NULL;
 
     return link;
 }
remote/remote-main.c +7 -0
index dbd6ad2529..f541baae6a 100644
@@ -35,6 +35,9 @@
 #include "exec/ramlist.h"
 #include "remote/remote-common.h"
 
+static void process_msg(GIOCondition cond, MPQemuLinkState *link,
+                        MPQemuChannel *chan);
+
 static MPQemuLinkState *mpqemu_link;
 
 gchar *print_pid_exec(gchar *str)
@@ -48,6 +51,43 @@ gchar *print_pid_exec(gchar *str)
     return str;
 }
 
+#define LINK_TO_DEV(link) ((PCIDevice *)link->opaque)
+
+static gpointer dev_thread(gpointer data)
+{

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 67

Quoted 10 lines
remote/remote-main.c +10 -0
+    MPQemuLinkState *link = data;
+
+    mpqemu_start_coms(link, link->dev);
+
+    return NULL;
+}
+
+static void process_connect_dev_msg(MPQemuMsg *msg)
+{
+    char *devid = (char *)msg->data2;

Input validation is missing for this message. We may not have data2 or it may not have a NUL-terminator.

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 70

Quoted 3 lines
remote/remote-main.c +3 -0
+    MPQemuLinkState *link = NULL;
+    DeviceState *dev = NULL;
+    int wait = msg->fds[0];

msg->num_fds wasn't checked.

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 80

Quoted 10 lines
remote/remote-main.c +10 -0
+    int ret = 0;
+
+    dev = qdev_find_recursive(sysbus_get_default(), devid);
+    if (!dev) {
+        ret = 0xff;
+        goto exit;
+    }
+
+    link = mpqemu_link_create();
+    link->opaque = (void *)PCI_DEVICE(dev);

Missing check to see if dev is a PCIDevice subclass.

#55 lore raw

Re: [PATCH RESEND v6 20/36] multi-process: Forward PCI config space acceses to the remote process

In reply to [email protected]
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:55PM -0700, [email protected] wrote:
hw/proxy/qemu-proxy.c +5 -0
+static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
+                          unsigned int op)
+{
+    MPQemuMsg msg;
+    struct conf_data_msg conf_data;

hw/proxy/qemu-proxy.c line 31

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    conf_data.addr = addr;
+    conf_data.val = (op == PCI_CONFIG_WRITE) ? *val : 0;
+    conf_data.l = l;
+
+    msg.data2 = (uint8_t *)&conf_data;
+    if (!msg.data2) {
+        return -ENOMEM;

This can never happen since conf_data is on the stack.

Quoted 8 lines
hw/proxy/qemu-proxy.c +8 -0
+    }
+
+    msg.size = sizeof(conf_data);
+    msg.cmd = op;
+    msg.bytestream = 1;
+
+    if (op == PCI_CONFIG_WRITE) {
+        msg.num_fds = 0;

hw/proxy/qemu-proxy.c line 49

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    } else {
+        /* TODO: Dont create fd each time for send. */
+        wait = GET_REMOTE_WAIT;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->dev);
+
+    if (op == PCI_CONFIG_READ) {

Are you sure it's correct for writes to be posted instead of waiting for completion?

hw/proxy/qemu-proxy.c line 61

Quoted 12 lines
hw/proxy/qemu-proxy.c +12 -0
+        *val = (uint32_t)wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+
+    return 0;
+}
+
+static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len)
+{
+    uint32_t val;
+
+    (void)pci_default_read_config(d, addr, len);

Please add a comment explaining why this local read is necessary.

hw/proxy/qemu-proxy.c line 71

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, len, PCI_CONFIG_READ);
+
+    return val;
+}
+
+static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,
+                                   int l)
+{
+    pci_default_write_config(d, addr, val, l);

Please add a comment explaining why this local write is necessary.

Quoted 3 lines
hw/proxy/qemu-proxy.c +3 -0
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE);
+}

...

io/mpqemu-link.c bool mpqemu_msg_valid(MPQemuMsg *msg) · line 388

Quoted 13 lines
io/mpqemu-link.c +5 -0
index f780b65181..ef4a07b81a 100644
@@ -381,6 +381,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
             return false;
         }
         break;
+    case PCI_CONFIG_WRITE:
+    case PCI_CONFIG_READ:
+        if (msg->size != sizeof(struct conf_data_msg)) {
+            return false;
+        }

conf_data_msg.l is not validated.

Quoted 9 lines
io/mpqemu-link.c +1 -0
+        break;
     default:
         break;
     }
remote/remote-main.c +0 -0
index f541baae6a..834574e172 100644

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 60

Quoted 8 lines
remote/remote-main.c +5 -0
@@ -53,6 +53,32 @@ gchar *print_pid_exec(gchar *str)
 
 #define LINK_TO_DEV(link) ((PCIDevice *)link->opaque)
 
+static void process_config_write(PCIDevice *dev, MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+
+    qemu_mutex_lock_iothread();

The qemu_mutex_lock_iothread() can be dropped once this is integrated in to QEMU's event loop.

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 61

Quoted 1 line
remote/remote-main.c +1 -0
+    pci_default_write_config(dev, conf->addr, conf->val, conf->l);

It is not safe to call this function with arbitrary addr input values.

remote/remote-main.c gchar *print_pid_exec(gchar *str) · line 74

Quoted 13 lines
remote/remote-main.c +13 -0
+    qemu_mutex_unlock_iothread();
+}
+
+static void process_config_read(PCIDevice *dev, MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+    uint32_t val;
+    int wait;
+
+    wait = msg->fds[0];
+
+    qemu_mutex_lock_iothread();
+    val = pci_default_read_config(dev, conf->addr, conf->l);

It is not safe to call this function with arbitrary addr input values.

#57 lore raw

Re: [PATCH RESEND v6 21/36] multi-process: PCI BAR read/write handling for proxy & remote endpoints

In reply to [email protected]

hw/proxy/qemu-proxy.c static void pci_proxy_dev_register_types(void) · line 224

Quoted 9 lines · On Wed, Apr 22, 2020 at 09:13:56PM -0700, [email protected] wrote:
hw/proxy/qemu-proxy.c +9 -0
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+    uint64_t val;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size,
+                        pmr->memory);
+
+     return val;

Indentation is should be 4 spaces.

include/hw/proxy/qemu-proxy.h typedef struct PCIProxyDevClass { · line 60

Quoted 8 lines
include/hw/proxy/qemu-proxy.h +4 -0
@@ -43,4 +54,9 @@ typedef struct PCIProxyDevClass {
     char *command;
 } PCIProxyDevClass;
 
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size);
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size);

"default" is probably not appropriate here. This isn't a base class' default implementation that child classes override.

Quoted 4 lines
remote/remote-main.c +0 -0
@@ -114,6 +115,77 @@ exit:
     notify_proxy(wait, ret);
 }
 

remote/remote-main.c exit: · line 127

Quoted 10 lines
remote/remote-main.c +10 -0
+/* TODO: confirm memtx attrs. */
+static void process_bar_write(MPQemuMsg *msg, Error **errp)
+{
+    bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    AddressSpace *as =
+        bar_access->memory ? &address_space_memory : &address_space_io;
+    MemTxResult res;
+
+    assert(is_power_of_2(bar_access->size) &&
+           bar_access->size <= sizeof(uint64_t));

Please return an error instead of asserting. At the moment it doesn't matter much but this will be necessary so that a process hosting remote devices for multiple guests cannot be killed by one malicious guest.

remote/remote-main.c exit: · line 130

Quoted 3 lines
remote/remote-main.c +3 -0
+
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&bar_access->val, bar_access->size,

Missing uint64_t val to void* conversion code.

For example, if bar_access->size is 1 then this fails on big-endian hosts because &bar_access->val is the address of the most-significant byte in uint64_t val:

  uint64_t val = 1;

Now we have the following memory layout on big-endian hosts:

val = 00 00 00 00 00 00 00 01

        ^-------------- &val

We actually wanted a 1-byte write of 0x01 and not 0x00.

#59 lore raw

Re: [PATCH RESEND v6 22/36] multi-process: Synchronize remote memory

In reply to [email protected]
Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:57PM -0700, [email protected] wrote:
hw/proxy/memory-sync.c new file +1 -0
new file mode 100644
index 0000000000..b3f57747f3
@@ -0,0 +1,217 @@
+/*

hw/proxy/memory-sync.c line 11

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+ * Copyright © 2018, 2020 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 <sys/types.h>
+#include <stdio.h>
+#include <string.h>

These headers should already be included by "qemu/osdep.h".

Quoted 11 lines
hw/proxy/memory-sync.c new file +11 -0
+static void proxy_ml_region_addnop(MemoryListener *listener,
+                                   MemoryRegionSection *section)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    bool need_add = true;
+    uint64_t mrs_size, mrs_gpa, mrs_page;
+    uintptr_t mrs_host;
+    RAMBlock *mrs_rb;
+    MemoryRegionSection *prev_sec;
+
+    if (!(memory_region_is_ram(section->mr) &&

hw/proxy/memory-sync.c line 109

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+          !memory_region_is_rom(section->mr))) {
+        return;
+    }
+
+    mrs_rb = section->mr->ram_block;
+    mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb);
+    mrs_size = int128_get64(section->size);
+    mrs_gpa = section->offset_within_address_space;
+    mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) +
+               section->offset_within_region;

These variables are only used in the if (sync->n_mr_sections) case. This function could be split into a something like this:

static void proxy_ml_region_addnop(MemoryListener *listener,

                                     MemoryRegionSection *section)
      RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);

      if (!(memory_region_is_ram(section->mr) &&
            !memory_region_is_rom(section->mr))) {
          return;
      }

      if (try_merge(sync, section)) {
          return;
      }

      ...add new section...

}

And the try_merge() helper function has the rest of the code:

  /* Returns true if the section was merged */
  static bool try_merge(RemoteMemSync *sync, MemoryRegionSection *section)
  {
      if (sync->n_mr_sections == 0) {
          return false;
      }
      ...most of the code...

}

hw/proxy/memory-sync.c line 34

Quoted 2 lines
hw/proxy/memory-sync.c new file +2 -0
+
+    if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) {

0 is a valid fd number, the comparison should probably be < 0?

hw/proxy/memory-sync.c line 117

Quoted 6 lines
hw/proxy/memory-sync.c new file +6 -0
+        return;
+    }
+
+    mrs_host = mrs_host & ~(mrs_page - 1);
+    mrs_gpa = mrs_gpa & ~(mrs_page - 1);
+    mrs_size = ROUND_UP(mrs_size, mrs_page);

Why is it necessary to align to the RAM block's page size?

Can mrs_host and mrs_size be misaligned to the RAM block's page size?

Why round the *guest* physical address down using the *host* page size?

hw/proxy/memory-sync.c line 127

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+
+    if (sync->n_mr_sections) {
+        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
+        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
+        uint64_t prev_size = int128_get64(prev_sec->size);
+        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
+        uint64_t prev_host_start =
+            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
+            prev_sec->offset_within_region;
+        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);

Is it okay not to do the page alignment stuff for the previous MemoryRegionSection?

hw/proxy/memory-sync.c line 191

Quoted 4 lines
hw/proxy/memory-sync.c new file +4 -0
+void deconfigure_memory_sync(RemoteMemSync *sync)
+{
+    memory_listener_unregister(&sync->listener);
+}

This function is unused? It must be tied into the mpqemu_link lifecycle. It must be possible to hot plug/unplug proxy PCI devices without memory leaks or use-after-frees.

Quoted 15 lines
include/hw/proxy/memory-sync.h new file +9 -0
new file mode 100644
index 0000000000..d8329c9b52
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2018, 2020 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 MEMORY_SYNC_H

include/hw/proxy/memory-sync.h line 19

Quoted 10 lines
include/hw/proxy/memory-sync.h new file +10 -0
+#define MEMORY_SYNC_H
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "exec/memory.h"
+#include "io/mpqemu-link.h"
+
+#define TYPE_MEMORY_LISTENER "memory-listener"

This name is too generic. There is already a C struct called MemoryListener. Please call this class "remote-memory-sync".

I'm not sure if a QOM object is needed here. Can this just be a plain C struct? If you're not using QOM object-orientated features then there is no need to define a QOM object.

include/hw/proxy/memory-sync.h typedef struct ProxyMemoryRegion { · line 44

Quoted 6 lines
include/hw/proxy/memory-sync.h new file +2 -0
@@ -39,8 +40,13 @@ typedef struct ProxyMemoryRegion {
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;

Is it necessary to duplicate these fields here since a RemoteMemSync field is also being added and it contains these same fields?

#60 lore raw

Re: [PATCH RESEND v6 22/36] multi-process: Synchronize remote memory

Quoted 86 lines · * Stefan Hajnoczi ([email protected]) wrote:
Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:57PM -0700, [email protected] wrote:
hw/proxy/memory-sync.c new file +1 -0
new file mode 100644
index 0000000000..b3f57747f3
@@ -0,0 +1,217 @@
+/*

hw/proxy/memory-sync.c line 11

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+ * Copyright © 2018, 2020 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 <sys/types.h>
+#include <stdio.h>
+#include <string.h>

These headers should already be included by "qemu/osdep.h".

Quoted 11 lines
hw/proxy/memory-sync.c new file +11 -0
+static void proxy_ml_region_addnop(MemoryListener *listener,
+                                   MemoryRegionSection *section)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    bool need_add = true;
+    uint64_t mrs_size, mrs_gpa, mrs_page;
+    uintptr_t mrs_host;
+    RAMBlock *mrs_rb;
+    MemoryRegionSection *prev_sec;
+
+    if (!(memory_region_is_ram(section->mr) &&

hw/proxy/memory-sync.c line 109

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+          !memory_region_is_rom(section->mr))) {
+        return;
+    }
+
+    mrs_rb = section->mr->ram_block;
+    mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb);
+    mrs_size = int128_get64(section->size);
+    mrs_gpa = section->offset_within_address_space;
+    mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) +
+               section->offset_within_region;

These variables are only used in the if (sync->n_mr_sections) case. This function could be split into a something like this:

static void proxy_ml_region_addnop(MemoryListener *listener,

                                     MemoryRegionSection *section)
      RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);

      if (!(memory_region_is_ram(section->mr) &&
            !memory_region_is_rom(section->mr))) {
          return;
      }

      if (try_merge(sync, section)) {
          return;
      }

      ...add new section...

}

And the try_merge() helper function has the rest of the code:

  /* Returns true if the section was merged */
  static bool try_merge(RemoteMemSync *sync, MemoryRegionSection *section)
  {
      if (sync->n_mr_sections == 0) {
          return false;
      }
      ...most of the code...

}

hw/proxy/memory-sync.c line 34

Quoted 2 lines
hw/proxy/memory-sync.c new file +2 -0
+
+    if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) {

0 is a valid fd number, the comparison should probably be < 0?

hw/proxy/memory-sync.c line 117

Quoted 6 lines
hw/proxy/memory-sync.c new file +6 -0
+        return;
+    }
+
+    mrs_host = mrs_host & ~(mrs_page - 1);
+    mrs_gpa = mrs_gpa & ~(mrs_page - 1);
+    mrs_size = ROUND_UP(mrs_size, mrs_page);
Quoted 5 lines

Why is it necessary to align to the RAM block's page size?

Can mrs_host and mrs_size be misaligned to the RAM block's page size?

Why round the *guest* physical address down using the *host* page size?

That sounds like the type of magic we do for postcopy; where we can only 'place' pages atomically on a host page boundary.

Dave

Quoted 60 lines

hw/proxy/memory-sync.c line 127

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+
+    if (sync->n_mr_sections) {
+        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
+        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
+        uint64_t prev_size = int128_get64(prev_sec->size);
+        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
+        uint64_t prev_host_start =
+            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
+            prev_sec->offset_within_region;
+        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);

Is it okay not to do the page alignment stuff for the previous MemoryRegionSection?

hw/proxy/memory-sync.c line 191

Quoted 4 lines
hw/proxy/memory-sync.c new file +4 -0
+void deconfigure_memory_sync(RemoteMemSync *sync)
+{
+    memory_listener_unregister(&sync->listener);
+}

This function is unused? It must be tied into the mpqemu_link lifecycle. It must be possible to hot plug/unplug proxy PCI devices without memory leaks or use-after-frees.

Quoted 15 lines
include/hw/proxy/memory-sync.h new file +9 -0
new file mode 100644
index 0000000000..d8329c9b52
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2018, 2020 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 MEMORY_SYNC_H

include/hw/proxy/memory-sync.h line 19

Quoted 10 lines
include/hw/proxy/memory-sync.h new file +10 -0
+#define MEMORY_SYNC_H
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "exec/memory.h"
+#include "io/mpqemu-link.h"
+
+#define TYPE_MEMORY_LISTENER "memory-listener"

This name is too generic. There is already a C struct called MemoryListener. Please call this class "remote-memory-sync".

I'm not sure if a QOM object is needed here. Can this just be a plain C struct? If you're not using QOM object-orientated features then there is no need to define a QOM object.

Quoted 4 lines
include/hw/proxy/memory-sync.h new file +0 -0
@@ -39,8 +40,13 @@ typedef struct ProxyMemoryRegion {
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
Quoted 5 lines

include/hw/proxy/memory-sync.h typedef struct ProxyMemoryRegion { · line 44

Quoted 2 lines
include/hw/proxy/memory-sync.h new file +2 -0
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;

Is it necessary to duplicate these fields here since a RemoteMemSync field is also being added and it contains these same fields?

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#62 lore raw

Re: [PATCH RESEND v6 23/36] multi-process: create IOHUB object to handle irq

In reply to [email protected]
Quoted 18 lines · On Wed, Apr 22, 2020 at 09:13:58PM -0700, [email protected] wrote:
include/remote/iohub.h new file +12 -0
new file mode 100644
index 0000000000..7a488a8c38
@@ -0,0 +1,50 @@
+/*
+ * IO Hub for remote device
+ *
+ * Copyright © 2018, 2020 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_IOHUB_H
+#define REMOTE_IOHUB_H

include/remote/iohub.h line 22

Quoted 10 lines
include/remote/iohub.h new file +10 -0
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "qemu/event_notifier.h"
+#include "qemu/thread-posix.h"
+#include "io/mpqemu-link.h"
+
+#define REMOTE_IOHUB_NB_PIRQS    8

We only use pirqs 4-7 based on the (slot + intx) % 4 + 4 formula. Why is it necessary to reserve 8 irqs?

Quoted 6 lines
include/remote/iohub.h new file +6 -0
+
+#define REMOTE_IOHUB_DEV         31
+#define REMOTE_IOHUB_FUNC        0
+
+#define TYPE_REMOTE_IOHUB_DEVICE "remote-iohub"
+#define REMOTE_IOHUB_DEVICE(obj) \

include/remote/iohub.h line 38

Quoted 10 lines
include/remote/iohub.h new file +10 -0
+    OBJECT_CHECK(RemoteIOHubState, (obj), TYPE_REMOTE_IOHUB_DEVICE)
+
+typedef struct ResampleToken {
+    void *iohub;
+    int pirq;
+} ResampleToken;
+
+typedef struct RemoteIOHubState {
+    PCIDevice d;
+    uint8_t irq_num[PCI_SLOT_MAX][PCI_NUM_PINS];

This is a fixed mapping based on a formula. Is there any need to store it in an array?

io/mpqemu-link.c bool mpqemu_msg_valid(MPQemuMsg *msg) · line 393

Quoted 10 lines
io/mpqemu-link.c +1 -0
index 5cb93fc47b..ea519a980e 100644
@@ -389,6 +389,7 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)
         break;
     case BAR_WRITE:
     case BAR_READ:
+    case SET_IRQFD:
         if (msg->size != sizeof(msg->data1)) {

Wait, this is checking for sizeof(msg->data1) but the message defines its own struct!

io/mpqemu-link.c bool mpqemu_msg_valid(MPQemuMsg *msg)

Quoted 5 lines
io/mpqemu-link.c +5 -0
+void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
+{
+    RemMachineState *machine = REMOTE_MACHINE(current_machine);
+    RemoteIOHubState *iohub = machine->iohub;
+    int pirq = remote_iohub_map_irq(pci_dev, msg->data1.set_irqfd.intx);

intx has not been validated.

#65 lore raw

Re: [PATCH RESEND v6 24/36] multi-process: Retrieve PCI info from remote process

In reply to [email protected]
Quoted 20 lines · On Wed, Apr 22, 2020 at 09:13:59PM -0700, [email protected] wrote:
hw/proxy/qemu-proxy.c +16 -0
@@ -291,3 +299,79 @@ const MemoryRegionOps proxy_default_ops = {
         .max_access_size = 1,
     },
 };
+
+static void probe_pci_info(PCIDevice *dev)
+{
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+    DeviceClass *dc = DEVICE_CLASS(pc);
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+    MPQemuLinkState *mpqemu_link = pdev->mpqemu_link;
+    MPQemuMsg msg, ret;
+    uint32_t orig_val, new_val, class;
+    uint8_t type;
+    int i, size;
+    char *name;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    msg.bytestream = 0;
+    msg.size = 0;

hw/proxy/qemu-proxy.c const MemoryRegionOps proxy_default_ops = { · line 327

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+    msg.cmd = GET_PCI_INFO;
+    mpqemu_msg_send(&msg, mpqemu_link->dev);
+
+    mpqemu_msg_recv(&ret, mpqemu_link->dev);
+
+    pc->vendor_id = ret.data1.ret_pci_info.vendor_id;
+    pc->device_id = ret.data1.ret_pci_info.device_id;
+    pc->class_id = ret.data1.ret_pci_info.class_id;
+    pc->subsystem_id = ret.data1.ret_pci_info.subsystem_id;
+

Why introduce the GET_PCI_INFO/RET_PCI_INFO messages when the same information can already be fetched using PCI_CONFIG_READ?

hw/proxy/qemu-proxy.c const MemoryRegionOps proxy_default_ops = { · line 328

Quoted 1 line
hw/proxy/qemu-proxy.c +1 -0
+    config_op_send(pdev, 11, &class, 1, PCI_CONFIG_READ);

Please use constants like PCI_CLASS_DEVICE instead of magic numbers.

include/io/mpqemu-link.h typedef enum { · line 52

Quoted 10 lines
include/io/mpqemu-link.h +2 -0
index 14e4be2bd0..102c736705 100644
@@ -48,6 +48,8 @@ typedef enum {
     BAR_WRITE,
     BAR_READ,
     SET_IRQFD,
+    GET_PCI_INFO,
+    RET_PCI_INFO,

Ah, I see reply messages are being used after all. I suggest dropping the eventfd wait mechanism and using reply messages instead. Otherwise you need to duplicate the wait timeout for reply messages. Using temporary eventfds is more complex and maybe also slower.

#63 lore raw

Re: [PATCH RESEND v6 23/36] multi-process: create IOHUB object to handle irq

In reply to [email protected]
Quoted 22 lines · On Wed, Apr 22, 2020 at 09:13:58PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD ioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU.

---
 MAINTAINERS                   |   2 +
 Makefile.target               |   1 +
 hw/Makefile.objs              |   2 -
 hw/proxy/Makefile.objs        |   1 -
 hw/proxy/qemu-proxy.c         |  52 ++++++++++++
 include/hw/pci/pci_ids.h      |   3 +
 include/hw/proxy/qemu-proxy.h |   8 ++
 include/io/mpqemu-link.h      |   8 ++
 include/remote/iohub.h        |  50 ++++++++++++
 include/remote/machine.h      |   2 +
 io/mpqemu-link.c              |   1 +
Quoted 8 lines
 remote/Makefile.objs          |   1 +
 remote/iohub.c                | 148 ++++++++++++++++++++++++++++++++++
 remote/machine.c              |  15 ++++
 remote/remote-main.c          |   4 +
 15 files changed, 295 insertions(+), 3 deletions(-)
 delete mode 100644 hw/proxy/Makefile.objs
 create mode 100644 include/remote/iohub.h
 create mode 100644 remote/iohub.c

Does this mean MSI-X is not supported?

For legacy device emulation INTx is fine but for modern devices MSI-X is used for better performance (multiqueue, etc).

Stefan

#92 lore raw
In reply to Jag Raman
Quoted 16 lines · Jag Raman
Quoted 8 lines · Stefan Hajnoczi

Hi,
Have you decided whether to drop the remote device program in favor of using a softmmu make target?

Is there anything in this series you'd like me to review before you send the next revision?

Hi Stefan,

We are planning to drop the separate remote device program in the next revision. We are planning to use QEMU’s existing event loop instead of a separate event loop for the remote process, as well as the command line invocation you suggested in your feedback.

Quoted 15 lines

We hope the following core patches look good to you, by and large:
[PATCH RESEND v6 01/36] memory: alloc RAM from file at offset
[PATCH RESEND v6 11/36] multi-process: define mpqemu-link object
[PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints [PATCH RESEND v6 13/36] multi-process: setup PCI host bridge for remote device [PATCH RESEND v6 14/36] multi-process: setup a machine object for remote device process [PATCH RESEND v6 15/36] multi-process: setup memory manager for remote device [PATCH RESEND v6 17/36] multi-process: introduce proxy object
[PATCH RESEND v6 18/36] multi-process: Initialize Proxy Object's communication channel [PATCH RESEND v6 19/36] multi-process: Connect Proxy Object with device in the remote process [PATCH RESEND v6 20/36] multi-process: Forward PCI config space acceses to the remote process [PATCH RESEND v6 21/36] multi-process: PCI BAR read/write handling for proxy & remote endpoints [PATCH RESEND v6 22/36] multi-process: Synchronize remote memory
[PATCH RESEND v6 23/36] multi-process: create IOHUB object to handle irq
[PATCH RESEND v6 24/36] multi-process: Retrieve PCI info from remote process

I've completed the review of these patches. Looking forward to discussing more.

Stefan

#93 lore raw
Quoted 37 lines · Stefan Hajnoczi
Quoted 16 lines · Jag Raman
Quoted 8 lines · Stefan Hajnoczi

Hi,
Have you decided whether to drop the remote device program in favor of using a softmmu make target?

Is there anything in this series you'd like me to review before you send the next revision?

Hi Stefan,

We are planning to drop the separate remote device program in the next revision. We are planning to use QEMU’s existing event loop instead of a separate event loop for the remote process, as well as the command line invocation you suggested in your feedback.

Quoted 15 lines

We hope the following core patches look good to you, by and large:
[PATCH RESEND v6 01/36] memory: alloc RAM from file at offset
[PATCH RESEND v6 11/36] multi-process: define mpqemu-link object
[PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints [PATCH RESEND v6 13/36] multi-process: setup PCI host bridge for remote device [PATCH RESEND v6 14/36] multi-process: setup a machine object for remote device process [PATCH RESEND v6 15/36] multi-process: setup memory manager for remote device [PATCH RESEND v6 17/36] multi-process: introduce proxy object
[PATCH RESEND v6 18/36] multi-process: Initialize Proxy Object's communication channel [PATCH RESEND v6 19/36] multi-process: Connect Proxy Object with device in the remote process [PATCH RESEND v6 20/36] multi-process: Forward PCI config space acceses to the remote process [PATCH RESEND v6 21/36] multi-process: PCI BAR read/write handling for proxy & remote endpoints [PATCH RESEND v6 22/36] multi-process: Synchronize remote memory
[PATCH RESEND v6 23/36] multi-process: create IOHUB object to handle irq
[PATCH RESEND v6 24/36] multi-process: Retrieve PCI info from remote process

Quoted 2 lines

I've completed the review of these patches. Looking forward to discussing more.

Thank you very much, Stefan!

We will incorporate the feedback we received from your review.

Thanks!
--
Jag

Quoted 2 lines

Stefan

#5 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to Jag Raman
Quoted 16 lines · Jag Raman
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

Quoted 7 lines

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

To explain a bit more, my understanding is that the offset is specifically for mmap(2). As Jag alluded to, multiple sections can use a single backing RAM file. These sections have different offsets in the file.

Jag, maybe you can include a concrete explanation like the following in the commit description:

Launch QEMU like this:

qemu-system-x86_64 -mem-path /dev/shm -m 8G

There is only one RAM file descriptor:

  $ cat /proc/$(pidof qemu)/fd
  ...
  lrwx------. 1 stefanha stefanha 64 May 13 09:34 19 -> '/dev/shm/qemu_back_mem.pc.ram.7YAlqn (deleted)'

But the memory tree shows that single file is split into multiple ranges of guest physical address space:

(qemu) info mtree
memory-region: system 0000000000000000-ffffffffffffffff (prio 0, i/o): system

    0000000000000000-00000000bfffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-00000000bfffffff
    ...
    0000000100000000-000000023fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 00000000c0000000-00000001ffffffff

This means QEMU needs to send two regions to the remote device process. They both mmap the same file but from different starting file offsets.

Stefan

#38 lore raw

Re: [PATCH RESEND v6 12/36] multi-process: add functions to synchronize proxy and remote endpoints

In reply to Jag Raman
Quoted 14 lines · Jag Raman
Quoted 14 lines · Stefan Hajnoczi

io/mpqemu-link.c int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) · line 225

Quoted 7 lines · On Wed, Apr 22, 2020 at 09:13:47PM -0700, [email protected] wrote:
io/mpqemu-link.c +7 -0
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };
+    uint64_t val;
+    int ret;
+
+    ret = poll(&pfd, 1, 1000);

This 1 second blocking operation is not allowed in an event loop since it will stall any other event loop activity. If locks are held then other threads may also be stalled.

Quoted 6 lines
Quoted 3 lines

It's likely that this will need to change as part of the QEMU event loop integration. Caller code can be kept mostly unchanged if you use coroutines.

In case the remote process has hung or terminated, the 1 second timeout ensures that the IO operation does not block for too long.

Timeouts are fine. They just need to be integrated into the event loop instead of blocking it. That way other processing can continue while waiting for the remote device process to respond or time out.

Stefan

#6 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to Stefan Hajnoczi
Quoted 49 lines · On Wed, 13 May 2020 09:40:42 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 16 lines · Jag Raman
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

Quoted 7 lines

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

To explain a bit more, my understanding is that the offset is specifically for mmap(2). As Jag alluded to, multiple sections can use a single backing RAM file. These sections have different offsets in the file.

Jag, maybe you can include a concrete explanation like the following in the commit description:

Launch QEMU like this:

qemu-system-x86_64 -mem-path /dev/shm -m 8G

There is only one RAM file descriptor:

  $ cat /proc/$(pidof qemu)/fd
  ...
  lrwx------. 1 stefanha stefanha 64 May 13 09:34 19 -> '/dev/shm/qemu_back_mem.pc.ram.7YAlqn (deleted)'

But the memory tree shows that single file is split into multiple ranges of guest physical address space:

(qemu) info mtree
memory-region: system 0000000000000000-ffffffffffffffff (prio 0, i/o): system

Quoted 6 lines
    0000000000000000-00000000bfffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-00000000bfffffff
    ...
    0000000100000000-000000023fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 00000000c0000000-00000001ffffffff

This means QEMU needs to send two regions to the remote device process. They both mmap the same file but from different starting file offsets.

are we talking here about GPA offests her or about host offsets in mmaped host file? If it's the later then above mtree doesn't show true picture (those entries are just aliases), main guest RAM is allocated as a single continuous chunk (so far) which belongs to a memory-backend.

Quoted 1 line

Stefan

#7 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

Quoted 60 lines · Igor Mammedov
Quoted 53 lines · On Wed, 13 May 2020 09:40:42 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 16 lines · Jag Raman
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

Quoted 7 lines

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

To explain a bit more, my understanding is that the offset is specifically for mmap(2). As Jag alluded to, multiple sections can use a single backing RAM file. These sections have different offsets in the file.

Jag, maybe you can include a concrete explanation like the following in the commit description:

Launch QEMU like this:

qemu-system-x86_64 -mem-path /dev/shm -m 8G

There is only one RAM file descriptor:

 $ cat /proc/$(pidof qemu)/fd
 ...
 lrwx------. 1 stefanha stefanha 64 May 13 09:34 19 -> '/dev/shm/qemu_back_mem.pc.ram.7YAlqn (deleted)'

But the memory tree shows that single file is split into multiple ranges of guest physical address space:

(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-00000000bfffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-00000000bfffffff
...
0000000100000000-000000023fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 00000000c0000000-00000001ffffffff

Quoted 7 lines
Quoted 2 lines

This means QEMU needs to send two regions to the remote device process. They both mmap the same file but from different starting file offsets.

are we talking here about GPA offests her or about host offsets in mmaped host file? If it's the later then above mtree doesn't show true picture (those entries are just aliases), main guest RAM is allocated as a single continuous chunk (so far) which belongs to a memory-backend.

Thanks for the info about ‘mtree’ QMP option. We’ll use that to better explain the need for offset during memory allocation.

As we can observe from the ‘mtree’ output, different sections of system memory vector into the RAM. Since we have only one file descriptor available for all of RAM, we need to mmap() these sections at different offsets within the memory file.

Hey Igor, the offset passed into the mmap() syscall is the offset within host file. Thanks for pointing out that these are aliases. I believe the mmap() operation is equivalent to the “alias” operation within MemoryRegion framework. We are sending the ‘fd’, ‘offset’ within the fd and the size of these RAM regions to the remote device over the unix socket. Hopefully, this looks good to you.

Thanks!
--
Jag

Quoted 4 lines
Quoted 2 lines

Stefan

#8 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

Quoted 73 lines · On Wed, 13 May 2020 16:08:06 -0400 Jag Raman <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov
Quoted 53 lines · On Wed, 13 May 2020 09:40:42 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 16 lines · Jag Raman
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

Quoted 7 lines

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

To explain a bit more, my understanding is that the offset is specifically for mmap(2). As Jag alluded to, multiple sections can use a single backing RAM file. These sections have different offsets in the file.

Jag, maybe you can include a concrete explanation like the following in the commit description:

Launch QEMU like this:

qemu-system-x86_64 -mem-path /dev/shm -m 8G

There is only one RAM file descriptor:

 $ cat /proc/$(pidof qemu)/fd
 ...
 lrwx------. 1 stefanha stefanha 64 May 13 09:34 19 -> '/dev/shm/qemu_back_mem.pc.ram.7YAlqn (deleted)'

But the memory tree shows that single file is split into multiple ranges of guest physical address space:

(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-00000000bfffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-00000000bfffffff
...
0000000100000000-000000023fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 00000000c0000000-00000001ffffffff

Quoted 7 lines
Quoted 2 lines

This means QEMU needs to send two regions to the remote device process. They both mmap the same file but from different starting file offsets.

are we talking here about GPA offests her or about host offsets in mmaped host file? If it's the later then above mtree doesn't show true picture (those entries are just aliases), main guest RAM is allocated as a single continuous chunk (so far) which belongs to a memory-backend.

Thanks for the info about ‘mtree’ QMP option. We’ll use that to better explain the need for offset during memory allocation.

As we can observe from the ‘mtree’ output, different sections of system memory vector into the RAM. Since we have only one file descriptor available for all of RAM, we need to mmap() these sections at different offsets within the memory file.

Quoted 5 lines

Hey Igor, the offset passed into the mmap() syscall is the offset within host file. Thanks for pointing out that these are aliases. I believe the mmap() operation is equivalent to the “alias” operation within MemoryRegion framework. We are sending the ‘fd’, ‘offset’ within the fd and the size of these RAM regions to the remote device over the unix socket. Hopefully, this looks good to you.

could you point to a specific patch where on remote device that is being received and used?

Quoted 10 lines

Thanks!
--
Jag

Quoted 4 lines
Quoted 2 lines

Stefan

#9 lore raw

Re: [PATCH RESEND v6 01/36] memory: alloc RAM from file at offset

In reply to Jag Raman
Quoted 75 lines · * Jag Raman ([email protected]) wrote:
Quoted 60 lines · Igor Mammedov
Quoted 53 lines · On Wed, 13 May 2020 09:40:42 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 16 lines · Jag Raman
Quoted 13 lines · Daniel P. Berrangé
Quoted 5 lines · On Wed, Apr 22, 2020 at 09:13:36PM -0700, [email protected] wrote:

From: Jagannathan Raman <[email protected]>

Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.

Can you elaborate on why remote processes require the RAM to be offset from zero ?

Hi Daniel,

Quoted 7 lines

As it turns out, the RAM is scattered across the physical address space (system_memory) of QEMU. Therefore, the system memory is composed of multiple sections of RAM, and some sections start at a non-zero RAM offset.

As a result, the remote process needs the ability to map these RAM sections into system_memory.

To explain a bit more, my understanding is that the offset is specifically for mmap(2). As Jag alluded to, multiple sections can use a single backing RAM file. These sections have different offsets in the file.

Jag, maybe you can include a concrete explanation like the following in the commit description:

Launch QEMU like this:

qemu-system-x86_64 -mem-path /dev/shm -m 8G

There is only one RAM file descriptor:

 $ cat /proc/$(pidof qemu)/fd
 ...
 lrwx------. 1 stefanha stefanha 64 May 13 09:34 19 -> '/dev/shm/qemu_back_mem.pc.ram.7YAlqn (deleted)'

But the memory tree shows that single file is split into multiple ranges of guest physical address space:

(qemu) info mtree
memory-region: system
0000000000000000-ffffffffffffffff (prio 0, i/o): system
0000000000000000-00000000bfffffff (prio 0, i/o): alias ram-below-4g @pc.ram 0000000000000000-00000000bfffffff
...
0000000100000000-000000023fffffff (prio 0, i/o): alias ram-above-4g @pc.ram 00000000c0000000-00000001ffffffff

Quoted 7 lines
Quoted 2 lines

This means QEMU needs to send two regions to the remote device process. They both mmap the same file but from different starting file offsets.

are we talking here about GPA offests her or about host offsets in mmaped host file? If it's the later then above mtree doesn't show true picture (those entries are just aliases), main guest RAM is allocated as a single continuous chunk (so far) which belongs to a memory-backend.

Thanks for the info about ‘mtree’ QMP option. We’ll use that to better explain the need for offset during memory allocation.

As we can observe from the ‘mtree’ output, different sections of system memory vector into the RAM. Since we have only one file descriptor available for all of RAM, we need to mmap() these sections at different offsets within the memory file.

Quoted 5 lines

Hey Igor, the offset passed into the mmap() syscall is the offset within host file. Thanks for pointing out that these are aliases. I believe the mmap() operation is equivalent to the “alias” operation within MemoryRegion framework. We are sending the ‘fd’, ‘offset’ within the fd and the size of these RAM regions to the remote device over the unix socket. Hopefully, this looks good to you.

Vhost-user already does something similar; see it's vhost_user_fill_set_mem_table_msg:

            msg->payload.memory.regions[*fd_num].userspace_addr =
                reg->userspace_addr;
            msg->payload.memory.regions[*fd_num].memory_size =
                reg->memory_size;
            msg->payload.memory.regions[*fd_num].guest_phys_addr =
                reg->guest_phys_addr;
            msg->payload.memory.regions[*fd_num].mmap_offset = offset;

Note you're not needing to map the fd with an offset on the qemu side, it's something only needed on the remote.

Dave

Quoted 9 lines

Thanks!
--
Jag

Quoted 4 lines
Quoted 2 lines

Stefan

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK