Skip to contentSkip to conversation

Initial support for multi-process qemu

PATCH Superseded Jagannathan Raman 10 participants 117 messages Feb 24, 2020 – Mar 29, 2020 Page 1 of 2

Subsystems (4)

v5 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#6 lore raw

PATCH v5 3/50 multi-process: add a command line option for debug file

In reply to Jagannathan Raman

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 f4724f7..a039ddb 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 2da6cb3..1f90e70 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
1.8.3.1
#8 lore raw

PATCH v5 5/50 multi-process: Add config option for multi-process QEMU

In reply to Jagannathan Raman

Add a configuration option to separate multi-process code

---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)
configure +11 -0
index 48d6f89..ab1e344 100755
@@ -506,6 +506,7 @@ libpmem=""
 default_devices="yes"
 plugins="no"
 fuzzing="no"
+mpqemu="no"
 
 supported_cpu="no"
 supported_os="no"
@@ -1572,6 +1573,10 @@ for opt do
   ;;
   --disable-fuzzing) fuzzing=no
   ;;
+  --enable-mpqemu) mpqemu=yes
+  ;;
+  --disable-mpqemu) mpqemu=no
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1860,6 +1865,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
@@ -6690,6 +6696,7 @@ echo "libudev           $libudev"
 echo "default devices   $default_devices"
 echo "plugin support    $plugins"
 echo "fuzzing support   $fuzzing"
+echo "multiprocess QEMU $mpqemu"
 
 if test "$supported_cpu" = "no"; then
     echo
@@ -7501,6 +7508,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
1.8.3.1
#0 lore raw

v5 cover Initial support for multi-process qemu

Hello

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] and RFC v4 [6].

John & Elena presented the status of this project in KVM Forum 2019. We appreciate the in-person and email feedback we received to improve this patchset. We also received valuable feedback and direction on future improvements from the bi-weekly KVM community conference. We have incorporated all the feedback in the current version of the series, v5.

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 are planning on making the following improvements in the future to the experimental Qemu multi-process:
- Asynchronous communication channel;
- Performance improvements;
- Libvirt support;
- Enforcement of security policies and privileges control;

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

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

Elena Ufimtseva (23):
multi-process: add a command line option for debug file
multi-process: introduce proxy object
mutli-process: build remote command line args
multi-process: configure remote side devices
multi-process: add qdev_proxy_add to create proxy devices
multi-process: remote: add setup_devices msg processing
multi-process: remote: use fd for socket from parent process
multi-process: remote: add create_done condition
multi-process: add processing of remote device command line
multi-process: refractor vl.c code
multi-process: add remote option
multi-process: add remote options parser
multi-process: add parse_cmdline in remote process
multi-process: send heartbeat messages to remote
multi-process: handle heartbeat messages in remote process multi-process/mon: choose HMP commands based on target multi-process/mig: Load VMSD in the proxy object multi-process/mig: refactor runstate_check into common file multi-process/mig: Synchronize runstate of remote process multi-process/mig: Restore the VMSD in remote process
multi-process: Enable support for multiple devices in remote
multi-process: Validate incoming commands from Proxy
multi-process: add configure and usage information

Jagannathan Raman (26):
multi-process: memory: alloc RAM from file at offset
multi-process: Refactor machine_init and exit notifiers
multi-process: Add stub functions to facilate 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: 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
multi-process: Introduce build flags to separate remote process code
multi-process: Use separate MMIO communication channel
multi-process: perform device reset in the remote process 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: Refactor monitor/chardev functions out of vl.c multi-process/mon: Initialize QMP module for remote processes
multi-process: prevent duplicate memory initialization in remote multi-process/mig: build migration module in the remote process multi-process/mig: Enable VMSD save in the Proxy object multi-process/mig: Send VMSD of remote to the Proxy object

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

 Makefile                         |    2 +
 Makefile.objs                    |   45 ++
 Makefile.target                  |  105 +++-
 accel/Makefile.objs              |    2 +
 accel/stubs/kvm-stub.c           |    5 +
 accel/stubs/tcg-stub.c           |  107 ++++
 backends/Makefile.objs           |    2 +
 block/Makefile.objs              |    2 +
 chardev/char.c                   |   14 +
 configure                        |   15 +
 docs/devel/index.rst             |    1 +
 docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
 docs/qemu-multiprocess.txt       |   86 +++
 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           |  212 ++++++++
 hw/proxy/qemu-proxy.c            |  906 +++++++++++++++++++++++++++++++
 hw/scsi/Makefile.objs            |    2 +
 include/chardev/char.h           |    1 +
 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    |  107 ++++
 include/hw/qdev-core.h           |    2 +
 include/io/mpqemu-link.h         |  218 ++++++++
 include/monitor/monitor.h        |    2 +
 include/monitor/qdev.h           |   26 +
 include/qemu-common.h            |    8 +
 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/runstate.h        |    3 +
 include/sysemu/sysemu.h          |    2 +
 io/Makefile.objs                 |    2 +
 io/mpqemu-link.c                 |  410 ++++++++++++++
 memory.c                         |    2 +-
 migration/Makefile.objs          |   13 +
 migration/savevm.c               |   63 +++
 migration/savevm.h               |    3 +
 monitor/Makefile.objs            |    4 +
 monitor/misc.c                   |   84 +--
 monitor/monitor-internal.h       |   38 ++
 monitor/monitor.c                |   40 +-
 net/Makefile.objs                |    2 +
 qapi/Makefile.objs               |    2 +
 qdev-monitor.c                   |  259 ++++++++-
 qemu-options.hx                  |   21 +
 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-main.c             |  625 +++++++++++++++++++++
 remote/remote-opts.c             |  115 ++++
 remote/remote-opts.h             |   15 +
 rules.mak                        |    2 +-
 runstate.c                       |   41 ++
 scripts/hxtool                   |   44 +-
 softmmu/vl.c                     |  299 ++++-------
 stubs/audio.c                    |   12 +
 stubs/gdbstub.c                  |   23 +
 stubs/machine-init-done.c        |    4 +
 stubs/migration.c                |  211 ++++++++
 stubs/monitor.c                  |   72 +++
 stubs/net-stub.c                 |  121 +++++
 stubs/qapi-misc.c                |   43 ++
 stubs/qapi-target.c              |   55 ++
 stubs/replay.c                   |   26 +
 stubs/runstate-check.c           |    3 +
 stubs/ui-stub.c                  |  130 +++++
 stubs/vl-stub.c                  |  195 +++++++
 stubs/vmstate.c                  |   19 +
 stubs/xen-mapcache.c             |   22 +
 ui/Makefile.objs                 |    2 +
 util/Makefile.objs               |    2 +
 util/log.c                       |    2 +
 util/mmap-alloc.c                |    7 +-
 util/notify.c                    |   43 ++
 util/oslib-posix.c               |    2 +-
 vl-parse.c                       |  164 ++++++
 vl.h                             |   43 ++
 92 files changed, 6698 insertions(+), 245 deletions(-)
 create mode 100644 docs/devel/qemu-multiprocess.rst
 create mode 100644 docs/qemu-multiprocess.txt
 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/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 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-main.c
 create mode 100644 remote/remote-opts.c
 create mode 100644 remote/remote-opts.h
 create mode 100644 runstate.c
 mode change 100644 => 100755 scripts/hxtool
 create mode 100644 stubs/audio.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 vl-parse.c
 create mode 100644 vl.h
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH v5 9/50 multi-process: setup PCI host bridge for remote device

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.

---
v4 -> v5:
- Setting PCI bus name on the fly
- Unable to grab the PCI bus name from object hierarchy as RemPCIHost have access to it during instantiation

 hw/pci/Makefile.objs     |  2 +-
 include/remote/pcihost.h | 45 ++++++++++++++++++++++++++++++++++
 remote/Makefile.objs     |  1 +
 remote/pcihost.c         | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 include/remote/pcihost.h
 create mode 100644 remote/pcihost.c
hw/pci/Makefile.objs +1 -1
index 955be54..90693a7 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 a9b2256..2757f5a 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
1.8.3.1
#4 lore raw

PATCH v5 2/50 multi-process: Refactor machine_init and exit notifiers

In reply to Jagannathan Raman

Relocate machine_int and exit notifiers into common code

---
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 ------------------------------------------
 util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 42 deletions(-)
include/sysemu/sysemu.h +2 -0
index dec64fc..2f37e2b 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

util/notify.c +43 -0

52 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v5 8/50 multi-process: add functions to synchronize proxy and remote endpoints

In reply to Jagannathan Raman

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         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                               mpqemu_link_callback callback);
 void mpqemu_start_coms(MPQemuLinkState *s);
 
+#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 +41 -0

53 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v5 1/50 multi-process: memory: alloc RAM from file at offset

In reply to Jagannathan Raman

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.
This will be needed for the following patches.

---
 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 c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     Error *err = NULL;
@@ -1893,7 +1894,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");
@@ -2322,7 +2324,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;
@@ -2367,7 +2369,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;
@@ -2397,7 +2400,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 5e59a3d..1b9f489 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 e786266..4f57985 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 aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,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 27dcccd..a28f702 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 5a291cc..bd221dd 100644
@@ -205,7 +205,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
1.8.3.1
#9 lore raw

PATCH v5 6/50 multi-process: build system for remote device process

In reply to Jagannathan Raman

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

---
 Makefile                |  2 ++
 Makefile.objs           | 26 +++++++++++++++++++++
 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 ++++
 17 files changed, 162 insertions(+), 1 deletion(-)
 create mode 100644 remote/Makefile.objs
 create mode 100644 remote/remote-main.c
Makefile +2 -0
index 15f8e53..f91dcb9 100644
@@ -454,6 +454,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 +26 -0
index 8a1cbe8..c80e107 100644
@@ -21,6 +21,32 @@ 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-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 17e5ac6..e312dd4 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 28a847c..947cde3 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 3bcb35c..6398613 100644
@@ -71,3 +71,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 660e2b4..af9235b 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 4b4a2b3..0b4644f 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 6215e7c..e3e8084 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 f3ad921..4d2d809 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 c78f2fb..955be54 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 54b36ed..ef97770 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 d3623d5..e7cdc76 100644
@@ -14,3 +14,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 f9d7735..07e50e5 100644
@@ -2,3 +2,6 @@ qom-obj-y = object.o container.o qom-qobject.o
 qom-obj-y += object_interfaces.o
 
 common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o 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 0000000..a9b2256
@@ -0,0 +1 @@
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
remote/remote-main.c new file +23 -0
new file mode 100644
index 0000000..7c0764a
@@ -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 2e3feee..9b53c0c 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
1.8.3.1
#37 lore raw

PATCH v5 15/50 multi-process: PCI BAR read/write handling for proxy & remote endpoints

In reply to Jagannathan Raman

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         | 65 ++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
 include/io/mpqemu-link.h      | 12 +++++++
 remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
 }
+
+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->com);
+
+    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 +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
 #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;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
     PCIDevice parent_dev;
 
     MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                         bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
 typedef struct PCIProxyDevClass {
     PCIDeviceClass parent_class;
@@ -51,4 +64,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 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
  * 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.
@@ -47,6 +49,8 @@ typedef enum {
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
     SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
     MAX,
 } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
 } sync_sysmem_msg_t;
 
 typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -77,6 +88,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];
remote/remote-main.c +73 -0

91 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#26 lore raw

PATCH v5 14/50 mutli-process: build remote command line args

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

 hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
 include/hw/proxy/qemu-proxy.h |  2 +-
 2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +53 -15
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;
+
+    return argc;
+}
+
 static int remote_spawn(PCIProxyDev *pdev, const char *opts,
                         const char *exec_name, Error **errp)
 {
-    char *args[3];
     pid_t rpid;
     int fd[2] = {-1, -1};
     Error *local_error = NULL;
+    char *argv[64];
+    int argc = 0;
+    char *sfd;
+    char *exec_dir;
     int rc = -EINVAL;
 
     if (pdev->managed) {
         /* Child is forked by external program (such as libvirt). */
         error_setg(errp, "Remote processed is managed and launched by external program");
-        return -1;
+        return rc;
     }
 
     if (!exec_name) {
@@ -41,32 +72,38 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
 
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
         error_setg(errp, "Unable to create unix socket.");
-        return -1;
+        return rc;
     }
+    exec_dir = g_strdup_printf("%s/%s", qemu_get_exec_dir(), exec_name);
+    argc = add_argv(exec_dir, argv, argc);
+    sfd = g_strdup_printf("%d", fd[1]);
+    argc = add_argv(sfd, argv, argc);
+    argc = make_argv((char *)opts, argv, argc);
+
     /* TODO: Restrict the forked process' permissions and capabilities. */
     rpid = qemu_fork(&local_error);
 
     if (rpid == -1) {
         error_setg(errp, "Unable to spawn emulation program.");
         close(fd[0]);
-        close(fd[1]);
-        return -1;
+        goto fail;
     }
 
     if (rpid == 0) {
         close(fd[0]);
 
-        args[0] = g_strdup(exec_name);
-        args[1] = g_strdup_printf("%d", fd[1]);
-        args[2] = NULL;
-        execvp(args[0], (char *const *)args);
+        rc = execv(argv[0], (char *const *)argv);
         exit(1);
     }
     pdev->remote_pid = rpid;
+    pdev->socket = fd[0];
+
+    rc = 0;
 
+fail:
     close(fd[1]);
 
-    return 0;
+    return rc;
 }
 
 static int get_proxy_sock(PCIDevice *dev)
@@ -177,16 +214,17 @@ static void pci_proxy_dev_register_types(void)
 type_init(pci_proxy_dev_register_types)
 
 static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
-                       Error **errp)
+                       bool need_spawn, Error **errp)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
     Error *local_error = NULL;
 
     if (!pdev->managed) {
-        if (command) {
-            remote_spawn(pdev, command, exec_name, &local_error);
-        } else {
-            return;
+        if (need_spawn) {
+            if (remote_spawn(pdev, command, exec_name, &local_error)) {
+                error_propagate(errp, local_error);
+                return;
+            }
         }
     } else {
         pdev->remote_pid = atoi(pdev->rid);
include/hw/proxy/qemu-proxy.h +1 -1
index 28b0114..29fa2e9 100644
@@ -39,7 +39,7 @@ typedef struct PCIProxyDev {
 
     void (*proxy_ready) (PCIDevice *dev);
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
-                        Error **errp);
+                        bool need_spawn, Error **errp);
 
 } PCIProxyDev;
 
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH v5 11/50 multi-process: setup memory manager for remote device

In reply to Jagannathan Raman

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.

---
v4 -> v5:
- Refactored remote_ram_init_from_fd into common code

 Makefile.target          |  2 ++
 exec.c                   | 17 +++++++++++++
 include/exec/ram_addr.h  |  2 ++
 include/io/mpqemu-link.h | 11 +++++++++
 include/remote/memory.h  | 20 +++++++++++++++
 remote/memory.c          | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 115 insertions(+)
 create mode 100644 include/remote/memory.h
 create mode 100644 remote/memory.c
Makefile.target +2 -0
index 375fdaa..cfd36c1 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 b4c9cc6..8e77c4c 100644
@@ -2410,6 +2410,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 1b9f489..d9d7314 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 +11 -0
index ae04fca..78c0818 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) \
@@ -34,6 +36,7 @@
  * mpqemu_cmd_t:
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
+ * 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.
@@ -42,6 +45,7 @@ typedef enum {
     INIT = 0,
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
+    SYNC_SYSMEM,
     MAX,
 } mpqemu_cmd_t;
 
@@ -59,12 +63,19 @@ typedef enum {
  *
  */
 typedef struct {
+    hwaddr gpas[REMOTE_MAX_FDS];
+    uint64_t sizes[REMOTE_MAX_FDS];
+    ram_addr_t offsets[REMOTE_MAX_FDS];
+} sync_sysmem_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
 
     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 0000000..e2e479b
@@ -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
remote/memory.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#44 lore raw

PATCH v5 18/50 multi-process: configure remote side devices

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add functions to configure remote devices.

---
v4 -> v5:
- Fixed qstr leak issue

 hw/proxy/qemu-proxy.c         | 56 ++++++++++++++++++++++++++++++++++++++++++-
 include/hw/proxy/qemu-proxy.h |  3 +++
 include/io/mpqemu-link.h      |  9 +++++++
 3 files changed, 67 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +55 -1
index 0cf7dcc..3ba05d9 100644
@@ -21,8 +21,60 @@
 #include "qemu/event_notifier.h"
 #include "sysemu/kvm.h"
 #include "util/event_notifier-posix.c"
+#include "hw/boards.h"
+#include "include/qemu/log.h"
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static void setup_irqfd(PCIProxyDev *dev);
+
+static void proxy_ready(PCIDevice *dev)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+
+    setup_irqfd(pdev);
+}
+
+static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
+{
+    QString *qstr;
+    MPQemuMsg msg;
+    PCIProxyDev *pdev;
+    const char *str;
+    uint32_t reply = 0;
+    int rc = -EINVAL;
+    int wait;
+
+    pdev = PCI_PROXY_DEV(dev);
+
+    qstr = qobject_to_json(QOBJECT(qdict));
+    str = qstring_get_str(qstr);
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.data2 = (uint8_t *)(str);
+    msg.cmd = cmd;
+    msg.bytestream = 1;
+    msg.size = qstring_get_length(qstr) + 1;
+
+
+    wait = eventfd(0, EFD_NONBLOCK);
+    msg.num_fds = 1;
+    msg.fds[0] = wait;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    reply = (uint32_t)wait_for_remote(wait);
+    close(wait);
+
+    /* TODO: Add proper handling if remote did not set options. */
+    if (reply == REMOTE_OK) {
+        rc = 0;
+    }
+
+    qobject_unref(qstr);
+
+    return rc;
+}
 
 static int add_argv(char *opts_str, char **argv, int argc)
 {
@@ -297,7 +349,6 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
                         pdev->socket);
 
     configure_memory_sync(pdev->sync, pdev->mpqemu_link);
-    setup_irqfd(pdev);
 }
 
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
@@ -317,6 +368,9 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
     dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
+
+    dev->set_remote_opts = set_remote_opts;
+    dev->proxy_ready = proxy_ready;
 }
 
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/qemu-proxy.h +3 -0
index 56aec0e..cd8505a 100644
@@ -14,6 +14,8 @@
 #include "io/mpqemu-link.h"
 #include "hw/proxy/memory-sync.h"
 #include "qemu/event_notifier.h"
+#include "hw/pci/pci.h"
+#include "block/qdict.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -62,6 +64,7 @@ struct PCIProxyDev {
     void (*set_proxy_sock) (PCIDevice *dev, int socket);
     int (*get_proxy_sock) (PCIDevice *dev);
 
+    int (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd);
     void (*proxy_ready) (PCIDevice *dev);
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                         bool need_spawn, Error **errp);
include/io/mpqemu-link.h +9 -0
index 13c4b80..90a8437 100644
@@ -54,9 +54,18 @@ typedef enum {
     BAR_WRITE,
     BAR_READ,
     SET_IRQFD,
+    DEV_OPTS,
+    DRIVE_OPTS,
+    DEVICE_ADD,
+    DEVICE_DEL,
     MAX,
 } mpqemu_cmd_t;
 
+typedef enum {
+    REMOTE_OK = 0,
+    REMOTE_FAIL,
+} mpqemu_reply_t;
+
 /**
  * MPQemuMsg:
  * @cmd: The remote command
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v5 7/50 multi-process: define mpqemu-link object

In reply to Jagannathan Raman

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.

---
v4 -> v5:
- Cleaned up included header files

 include/io/mpqemu-link.h | 138 ++++++++++++++++++++++
 io/Makefile.objs         |   2 +
 io/mpqemu-link.c         | 294 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 434 insertions(+)
 create mode 100644 include/io/mpqemu-link.h
 create mode 100644 io/mpqemu-link.c
include/io/mpqemu-link.h new file +138 -0
new file mode 100644
index 0000000..2f2dd83
@@ -0,0 +1,138 @@
+/*
+ * Communication channel between QEMU and remote device process
+ *
+ * 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 MPQEMU_LINK_H
+#define MPQEMU_LINK_H
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "qom/object.h"
+#include "qemu/thread.h"
+
+#define TYPE_MPQEMU_LINK "mpqemu-link"
+#define MPQEMU_LINK(obj) \
+    OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK)
+
+#define REMOTE_MAX_FDS 8
+
+#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64)
+
+/*
+ * TODO: Dont use mpqemu link object since it is
+ * not needed to be created via -object.
+ */
+
+/**
+ * mpqemu_cmd_t:
+ * PCI_CONFIG_READ        PCI configuration space read
+ * PCI_CONFIG_WRITE       PCI configuration space write
+ *
+ * proc_cmd_t enum type to specify the command to be executed on the remote
+ * device.
+ */
+typedef enum {
+    INIT = 0,
+    PCI_CONFIG_READ,
+    PCI_CONFIG_WRITE,
+    MAX,
+} mpqemu_cmd_t;
+
+/**
+ * MPQemuMsg:
+ * @cmd: The remote command
+ * @bytestream: Indicates if the data to be shared is structured (data1)
+ *              or unstructured (data2)
+ * @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;
+    int bytestream;
+    size_t size;
+
+    union {
+        uint64_t u64;
+    } data1;
+
+    int fds[REMOTE_MAX_FDS];
+    int num_fds;
+
+    uint8_t *data2;
+} MPQemuMsg;
+
+struct conf_data_msg {
+    uint32_t addr;
+    uint32_t val;
+    int l;
+};
+
+/**
+ * MPQemuChannel:
+ * @gsrc: GSource object to be used by loop
+ * @gpfd: GPollFD object containing the socket & events to monitor
+ * @sock: Socket to send/receive communication, same as the one in gpfd
+ * @send_lock: Mutex to synchronize access to the send stream
+ * @recv_lock: Mutex to synchronize access to the recv stream
+ *
+ * Defines the channel that make up the communication link
+ * between QEMU and remote process
+ */
+
+typedef struct MPQemuChannel {
+    GSource gsrc;
+    GPollFD gpfd;
+    int sock;
+    QemuMutex send_lock;
+    QemuMutex recv_lock;
+} MPQemuChannel;
+
+typedef void (*mpqemu_link_callback)(GIOCondition cond, MPQemuChannel *chan);
+
+/*
+ * MPQemuLinkState Instance info. of the communication
+ * link between QEMU and remote process. The Link could
+ * be made up of multiple channels.
+ *
+ * ctx        GMainContext to be used for communication
+ * loop       Main loop that would be used to poll for incoming data
+ * com        Communication channel to transport control messages
+ *
+ */
+
+typedef struct MPQemuLinkState {
+    Object obj;
+
+    GMainContext *ctx;
+    GMainLoop *loop;
+
+    MPQemuChannel *com;
+
+    mpqemu_link_callback callback;
+} MPQemuLinkState;
+
+MPQemuLinkState *mpqemu_link_create(void);
+void mpqemu_link_finalize(MPQemuLinkState *s);
+
+void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan);
+int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan);
+
+void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd);
+void mpqemu_destroy_channel(MPQemuChannel *chan);
+void mpqemu_link_set_callback(MPQemuLinkState *s,
+                              mpqemu_link_callback callback);
+void mpqemu_start_coms(MPQemuLinkState *s);
+
+#endif
io/Makefile.objs +2 -0
index 9a20fce..5875ab0 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 +294 -0

294 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#21 lore raw

PATCH v5 12/50 multi-process: remote process initialization

In reply to Jagannathan Raman

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.

---
v4 -> v5:
- We checked if we could use functions already defined in util/main-loop.c instead of using g_main_loop_run. However, we couldn't find a suitable function that's generic enough to do this. All of them have emulator code embedded in them which is not used by the remote process. We are therefore not making any change to this patch

 remote/remote-main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
remote/remote-main.c +85 -0
index ecf30e0..56315cd 100644
@@ -12,6 +12,7 @@
 #include "qemu-common.h"
 
 #include <stdio.h>
+#include <unistd.h>
 
 #include "qemu/module.h"
 #include "remote/pcihost.h"
@@ -19,12 +20,96 @@
 #include "hw/boards.h"
 #include "hw/qdev-core.h"
 #include "qemu/main-loop.h"
+#include "remote/memory.h"
+#include "io/mpqemu-link.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "qemu-common.h"
+#include "hw/pci/pci.h"
+#include "qemu/thread.h"
+#include "qemu/main-loop.h"
+#include "qemu/config-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "exec/ramlist.h"
+
+static MPQemuLinkState *mpqemu_link;
+PCIDevice *remote_pci_dev;
+
+static void process_msg(GIOCondition cond, MPQemuChannel *chan)
+{
+    MPQemuMsg *msg = NULL;
+    Error *err = NULL;
+
+    if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
+        goto finalize_loop;
+    }
+
+    msg = g_malloc0(sizeof(MPQemuMsg));
+
+    if (mpqemu_msg_recv(msg, chan) < 0) {
+        error_setg(&err, "Failed to receive message");
+        goto finalize_loop;
+    }
+
+    switch (msg->cmd) {
+    case INIT:
+        break;
+    case PCI_CONFIG_WRITE:
+        break;
+    case PCI_CONFIG_READ:
+        break;
+    default:
+        error_setg(&err, "Unknown command");
+        goto finalize_loop;
+    }
+
+    g_free(msg->data2);
+    g_free(msg);
+
+    return;
+
+finalize_loop:
+    if (err) {
+        error_report_err(err);
+    }
+    g_free(msg);
+    mpqemu_link_finalize(mpqemu_link);
+    mpqemu_link = NULL;
+}
 
 int main(int argc, char *argv[])
 {
+    Error *err = NULL;
+
     module_call_init(MODULE_INIT_QOM);
 
+    bdrv_init_with_whitelist();
+
+    if (qemu_init_main_loop(&err)) {
+        error_report_err(err);
+        return -EBUSY;
+    }
+
+    qemu_init_cpu_loop();
+
+    page_size_init();
+
+    qemu_mutex_init(&ram_list.mutex);
+
     current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
 
+    mpqemu_link = mpqemu_link_create();
+    if (!mpqemu_link) {
+        printf("Could not create MPQemu link\n");
+        return -1;
+    }
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO);
+    mpqemu_link_set_callback(mpqemu_link, process_msg);
+
+    mpqemu_start_coms(mpqemu_link);
+
     return 0;
 }
Signature · 1 line
1.8.3.1
#43 lore raw

PATCH v5 17/50 multi-process: create IOHUB object to handle irq

In reply to Jagannathan Raman

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.

---
v4 -> v5:
- Using event_notifier_test_and_clear
- Using event_notifier_cleanup()
- The token is not malloced

 Makefile.target               |   1 +
 hw/Makefile.objs              |   2 -
 hw/proxy/Makefile.objs        |   1 -
 hw/proxy/qemu-proxy.c         |  51 +++++++++++++++
 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 +
 remote/Makefile.objs          |   1 +
 remote/iohub.c                | 148 ++++++++++++++++++++++++++++++++++++++++++
 remote/machine.c              |  15 +++++
 remote/remote-main.c          |   4 ++
 13 files changed, 291 insertions(+), 3 deletions(-)
 delete mode 100644 hw/proxy/Makefile.objs
 create mode 100644 include/remote/iohub.h
 create mode 100644 remote/iohub.c
Makefile.target +1 -0
index 271d883..c621d70 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 7b489b1..af9235b 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 eb81624..0000000
@@ -1 +0,0 @@
-common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c +51 -0

69 lines not on this page · raw message

include/hw/pci/pci_ids.h +3 -0
index 11f8ab7..bd0c17d 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 c93ffe3..56aec0e 100644
@@ -9,8 +9,11 @@
 #ifndef QEMU_PROXY_H
 #define QEMU_PROXY_H
 
+#include <linux/kvm.h>
+
 #include "io/mpqemu-link.h"
 #include "hw/proxy/memory-sync.h"
+#include "qemu/event_notifier.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -44,6 +47,11 @@ struct PCIProxyDev {
     MPQemuLinkState *mpqemu_link;
 
     RemoteMemSync *sync;
+    struct kvm_irqfd irqfd;
+
+    EventNotifier intr;
+    EventNotifier resample;
+
     pid_t remote_pid;
     int socket;
 
include/io/mpqemu-link.h +8 -0
index 1a7738e..13c4b80 100644
@@ -40,6 +40,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.
@@ -51,6 +53,7 @@ typedef enum {
     SYNC_SYSMEM,
     BAR_WRITE,
     BAR_READ,
+    SET_IRQFD,
     MAX,
 } mpqemu_cmd_t;
 
@@ -81,6 +84,10 @@ typedef struct {
 } bar_access_msg_t;
 
 typedef struct {
+    int intx;
+} set_irqfd_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -89,6 +96,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 7e9bdbe..300394a 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"
remote/Makefile.objs +1 -0
index 13d4c48..cbb3065 100644
@@ -1,3 +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) += iohub.o
remote/iohub.c new file +148 -0

148 lines not on this page · raw message

remote/machine.c +15 -0
index 97e4f19..d529f68 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 9512a3b..02d78a4 100644
@@ -35,6 +35,7 @@
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
 #include "exec/address-spaces.h"
+#include "remote/iohub.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -172,6 +173,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             goto finalize_loop;
         }
         break;
+    case SET_IRQFD:
+        process_set_irqfd_msg(remote_pci_dev, msg);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#48 lore raw

PATCH v5 22/50 multi-process: remote: use fd for socket from parent process

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 remote/remote-main.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
remote/remote-main.c +9 -1
index 3a67cb9..455cfb6 100644
@@ -51,6 +51,7 @@
 #include "block/qdict.h"
 #include "qapi/qmp/qlist.h"
 #include "qemu/log.h"
+#include "qemu/cutils.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -400,6 +401,7 @@ finalize_loop:
 int main(int argc, char *argv[])
 {
     Error *err = NULL;
+    int fd = -1;
 
     module_call_init(MODULE_INIT_QOM);
 
@@ -424,7 +426,13 @@ 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.\n");
+        return -EINVAL;
+    }
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
     mpqemu_start_coms(mpqemu_link);
Signature · 1 line
1.8.3.1
#19 lore raw

PATCH v5 10/50 multi-process: setup a machine object for remote device process

In reply to Jagannathan Raman

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

---
v4 -> v5:
- Refactor notifier code into a common file
- Moved global initialization out of object specific code
- Added a child property relationship between RemMachineState & RemPCIHost

 Makefile.objs                 |  1 +
 exec.c                        |  3 +-
 include/exec/address-spaces.h |  2 ++
 include/remote/machine.h      | 30 ++++++++++++++++
 remote/Makefile.objs          |  1 +
 remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++++++++++
 remote/remote-main.c          |  7 ++++
 util/Makefile.objs            |  2 ++
 8 files changed, 128 insertions(+), 2 deletions(-)
 create mode 100644 include/remote/machine.h
 create mode 100644 remote/machine.c
Makefile.objs +1 -0
index c80e107..aad33fc 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 e524185..b4c9cc6 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);
 
@@ -3002,7 +3001,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 db8bfa9..56a877b 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 0000000..7e9bdbe
@@ -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 +1 -0
index 2757f5a..13d4c48 100644
@@ -1,2 +1,3 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
remote/machine.c new file +84 -0

84 lines not on this page · raw message

remote/remote-main.c +7 -0
index 7c0764a..ecf30e0 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 6b38b67..80b2067 100644
@@ -60,3 +60,5 @@ util-obj-y += guest-random.o
 util-obj-$(CONFIG_GIO) += dbus.o
 dbus.o-cflags = $(GIO_CFLAGS)
 dbus.o-libs = $(GIO_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += notify.o
Signature · 1 line
1.8.3.1
#25 lore raw

PATCH v5 13/50 multi-process: introduce proxy object

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE. PCI Proxy Object is responsible for registering PCI BARs,i MemoryRegionOps to handle access to the BARs and forwarding those to the remote device.
PCI Proxy object intercepts config space reads and writes. In case of pci config write it forwards it to the remote device using communication channel set by proxy-link object.

---
v4 -> v5:
- Switched to execv

 hw/Makefile.objs              |   2 +
 hw/proxy/Makefile.objs        |   1 +
 hw/proxy/qemu-proxy.c         | 226 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |  54 ++++++++++
 include/io/mpqemu-link.h      |   1 +
 remote/remote-main.c          |  28 ++++++
 6 files changed, 312 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
hw/Makefile.objs +2 -0
index af9235b..7b489b1 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 0000000..eb81624
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +226 -0

226 lines not on this page · raw message

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

54 lines not on this page · raw message

include/io/mpqemu-link.h +1 -0
index 78c0818..5a2be48 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"
remote/remote-main.c +28 -0
index 56315cd..7b4cf2f 100644
@@ -37,6 +37,32 @@
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
 
+static void process_config_write(MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+
+    qemu_mutex_lock_iothread();
+    pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l);
+    qemu_mutex_unlock_iothread();
+}
+
+static void process_config_read(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(remote_pci_dev, conf->addr, conf->l);
+    qemu_mutex_unlock_iothread();
+
+    notify_proxy(wait, val);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -57,8 +83,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case INIT:
         break;
     case PCI_CONFIG_WRITE:
+        process_config_write(msg);
         break;
     case PCI_CONFIG_READ:
+        process_config_read(msg);
         break;
     default:
         error_setg(&err, "Unknown command");
Signature · 1 line
1.8.3.1
#47 lore raw

PATCH v5 21/50 multi-process: remote: add setup_devices msg processing

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Receive by remote side the configuration messages and build the device object from JSON device descriptions.

---
 include/hw/qdev-core.h |   2 +
 qdev-monitor.c         |   2 +-
 remote/remote-main.c   | 182 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 185 insertions(+), 1 deletion(-)
include/hw/qdev-core.h +2 -0
index 1405b8a..64a4d58 100644
@@ -392,6 +392,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);
 
 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
 
+DeviceState *find_device_state(const char *id, Error **errp);
+
 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
qdev-monitor.c +1 -1
index 60557ed..ccd2ce0 100644
@@ -1055,7 +1055,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
     object_unref(OBJECT(dev));
 }
 
-static DeviceState *find_device_state(const char *id, Error **errp)
+DeviceState *find_device_state(const char *id, Error **errp)
 {
     Object *obj;
 
remote/remote-main.c +182 -0

205 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#66 lore raw

PATCH v5 35/50 multi-process/mon: stub functions to enable QMP module for remote process

In reply to Jagannathan Raman

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

---
 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    |  55 +++++++++++++++++
 stubs/ui-stub.c        | 130 +++++++++++++++++++++++++++++++++++++++
 stubs/vl-stub.c        |  92 ++++++++++++++++++++++++++++
 11 files changed, 625 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
accel/stubs/tcg-stub.c +10 -0
index 9b55fb0..c2d72fe 100644
@@ -119,3 +119,13 @@ 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);
+}
configure +4 -0
index ab1e344..53a2a4b 100755
@@ -7512,6 +7512,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 082da59..09da824 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 2b7aee5..1e65b54 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 a34dc87..190445c 100644
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
@@ -10,6 +11,24 @@
 #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"
+
+#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
 
 __thread Monitor *cur_mon;
 
@@ -17,11 +36,13 @@ __thread Monitor *cur_mon;
 
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+    qemu_debug_assert(0);
     abort();
 }
 
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
+    qemu_debug_assert(0);
     error_setg(errp, "only QEMU supports file descriptor passing");
     return -1;
 }
@@ -32,29 +53,39 @@ void monitor_init_qmp(Chardev *chr, bool pretty)
 
 void monitor_init_hmp(Chardev *chr, bool use_readline)
 {
+    qemu_debug_assert(0);
 }
 
 void qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
+    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 +55 -0

55 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
1.8.3.1
#40 lore raw

PATCH v5 16/50 multi-process: Synchronize remote memory

In reply to Jagannathan Raman

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.

TODO: No need to create object for remote memory listener.

---
 Makefile.target                |   3 +
 hw/proxy/memory-sync.c         | 212 +++++++++++++++++++++++++++++++++++++++++
 hw/proxy/qemu-proxy.c          |   5 +
 include/hw/proxy/memory-sync.h |  37 +++++++
 include/hw/proxy/qemu-proxy.h  |   5 +
 remote/remote-main.c           |  11 +++
 6 files changed, 273 insertions(+)
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 include/hw/proxy/memory-sync.h
Makefile.target +3 -0
index cfd36c1..271d883 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 +212 -0

212 lines not on this page · raw message

hw/proxy/qemu-proxy.c +5 -0
index b17d9bb..d3a9d38 100644
@@ -16,6 +16,8 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qstring.h"
 #include "hw/proxy/qemu-proxy.h"
+#include "hw/proxy/memory-sync.h"
+#include "qom/object.h"
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
@@ -243,6 +245,8 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
 
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
+
+    configure_memory_sync(pdev->sync, pdev->mpqemu_link);
 }
 
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
@@ -261,6 +265,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->set_proxy_sock = set_proxy_sock;
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
+    dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
 }
 
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/memory-sync.h new file +37 -0
new file mode 100644
index 0000000..d8329c9
@@ -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 +5 -0
index 44e370e..c93ffe3 100644
@@ -10,6 +10,7 @@
 #define QEMU_PROXY_H
 
 #include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -37,8 +38,12 @@ extern const MemoryRegionOps proxy_default_ops;
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
     MPQemuLinkState *mpqemu_link;
 
+    RemoteMemSync *sync;
     pid_t remote_pid;
     int socket;
 
remote/remote-main.c +11 -0
index acd8daf..9512a3b 100644
@@ -34,6 +34,7 @@
 #include "block/block.h"
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
+#include "exec/address-spaces.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -161,6 +162,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             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");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#56 lore raw

PATCH v5 30/50 multi-process: send heartbeat messages to remote

In reply to Jagannathan Raman

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

---
v4 -> v5:
- Heart beat messages are sent asynchronously

 hw/proxy/qemu-proxy.c         | 115 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |   2 +
 include/io/mpqemu-link.h      |   1 +
 3 files changed, 118 insertions(+)
hw/proxy/qemu-proxy.c +115 -0
index c888677..bcb24f7 100644
@@ -24,11 +24,104 @@
 #include "hw/boards.h"
 #include "include/qemu/log.h"
 
+QEMUTimer *hb_timer;
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 static void setup_irqfd(PCIProxyDev *dev);
+static void pci_dev_exit(PCIDevice *dev);
+static void start_broadcast_timer(void);
+static void stop_broadcast_timer(void);
+static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx);
+static void broadcast_init(void);
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op);
 
+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 remote_ping_handler(void *opaque)
+{
+    PCIProxyDev *pdev = opaque;
+
+    if (!event_notifier_test_and_clear(&pdev->en_ping)) {
+        /*
+         * TODO: Is retry needed? Add the handling of the
+         * non-responsive process. How its done in case
+         * of managed process?
+         */
+        printf("No reply from remote process, pid %d\n", pdev->remote_pid);
+        event_notifier_cleanup(&pdev->en_ping);
+    }
+}
+
+static void broadcast_msg(void)
+{
+    MPQemuMsg msg;
+    PCIProxyDev *entry;
+
+    QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+        if (event_notifier_get_fd(&entry->en_ping) == -1) {
+            continue;
+        }
+
+        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(&entry->en_ping);
+
+        mpqemu_msg_send(&msg, entry->mpqemu_link->com);
+    }
+}
+
+static void broadcast_init(void)
+{
+    PCIProxyDev *entry;
+
+    QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+        event_notifier_init(&entry->en_ping, 0);
+        qemu_set_fd_handler(event_notifier_get_fd(&entry->en_ping),
+                            remote_ping_handler, NULL, entry);
+    }
+}
+
+#define NOP_INTERVAL 1000000
+
+static void remote_ping(void *opaque)
+{
+    broadcast_msg();
+    timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+}
+
+static void start_broadcast_timer(void)
+{
+    hb_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
+                                            remote_ping,
+                                            &proxy_dev_list);
+    timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL);
+
+}
+
+static void stop_broadcast_timer(void)
+{
+    timer_del(hb_timer);
+    timer_free(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 void probe_pci_info(PCIDevice *dev)
 {
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
@@ -111,6 +204,9 @@ static void proxy_ready(PCIDevice *dev)
 
     setup_irqfd(pdev);
     probe_pci_info(dev);
+    set_sigchld_handler();
+    broadcast_init();
+    start_broadcast_timer();
 }
 
 static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
@@ -325,6 +421,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_dev_exit;
     k->config_read = pci_proxy_read_config;
     k->config_write = pci_proxy_write_config;
 }
@@ -455,6 +552,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->proxy_ready = proxy_ready;
 }
 
+static void pci_dev_exit(PCIDevice *pdev)
+{
+    PCIProxyDev *entry, *sentry;
+    PCIProxyDev *dev = PCI_PROXY_DEV(pdev);
+
+    stop_broadcast_timer();
+
+    QLIST_FOREACH_SAFE(entry, &proxy_dev_list.devices, next, sentry) {
+        if (entry->remote_pid == dev->remote_pid) {
+            QLIST_REMOVE(entry, next);
+        }
+    }
+
+    if (!QLIST_EMPTY(&proxy_dev_list.devices)) {
+        start_broadcast_timer();
+    }
+}
+
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
                                 bool write, hwaddr addr, uint64_t *val,
                                 unsigned size, bool memory)
include/hw/proxy/qemu-proxy.h +2 -0
index 7c6bddd..f7666fb 100644
@@ -55,6 +55,8 @@ struct PCIProxyDev {
     EventNotifier resample;
 
     pid_t remote_pid;
+    EventNotifier en_ping;
+
     int socket;
 
     char *rid;
include/io/mpqemu-link.h +1 -0
index 2ca89c5..aaaf1a4 100644
@@ -60,6 +60,7 @@ typedef enum {
     DEVICE_DEL,
     GET_PCI_INFO,
     RET_PCI_INFO,
+    PROXY_PING,
     MAX,
 } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1
#52 lore raw

PATCH v5 26/50 multi-process: refractor vl.c code

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

To re-use for device initialization for remote emulated devices and parsing options for remote process.

---
 Makefile.objs        |   5 ++
 remote/Makefile.objs |   1 +
 softmmu/vl.c         | 109 +-----------------------------------------
 vl-parse.c           | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.h                 |  42 +++++++++++++++++
 5 files changed, 179 insertions(+), 108 deletions(-)
 create mode 100644 vl-parse.c
 create mode 100644 vl.h
Makefile.objs +5 -0
index aad33fc..689a722 100644
@@ -96,6 +96,11 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 
 common-obj-$(CONFIG_FDT) += device_tree.o
 
+common-obj-y += vl-parse.o
+
+#######################################################################
+# qapi
+
 common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
remote/Makefile.objs +1 -0
index cbb3065..c1349ad 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) += iohub.o
+remote-pci-obj-$(CONFIG_MPQEMU) +=../vl-parse.o
softmmu/vl.c +1 -108

139 lines not on this page · raw message

vl-parse.c new file +130 -0

130 lines not on this page · raw message

vl.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#49 lore raw

PATCH v5 23/50 multi-process: remote: add create_done condition

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Do not allow BAR,MMIO handlers and irq setup to run before the configuration of the devices completes.

---
 remote/remote-main.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
remote/remote-main.c +18 -9
index 455cfb6..ec1ce2c 100644
@@ -55,6 +55,7 @@
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
+bool create_done;
 
 static void process_config_write(MPQemuMsg *msg)
 {
@@ -332,21 +333,29 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         process_get_pci_info_msg(remote_pci_dev, msg);
         break;
     case PCI_CONFIG_WRITE:
-        process_config_write(msg);
+        if (create_done) {
+            process_config_write(msg);
+        }
         break;
     case PCI_CONFIG_READ:
-        process_config_read(msg);
+        if (create_done) {
+            process_config_read(msg);
+        }
         break;
     case BAR_WRITE:
-        process_bar_write(msg, &err);
-        if (err) {
-            goto finalize_loop;
+        if (create_done) {
+            process_bar_write(msg, &err);
+            if (err) {
+                error_report_err(err);
+            }
         }
         break;
     case BAR_READ:
-        process_bar_read(msg, &err);
-        if (err) {
-            goto finalize_loop;
+        if (create_done) {
+            process_bar_read(msg, &err);
+            if (err) {
+                error_report_err(err);
+            }
         }
         break;
     case SYNC_SYSMEM:
@@ -366,7 +375,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         qemu_mutex_lock_iothread();
         qemu_run_machine_init_done_notifiers();
         qemu_mutex_unlock_iothread();
-
+        create_done = true;
         break;
     case DEV_OPTS:
         if (setup_device(msg, &err)) {
Signature · 1 line
1.8.3.1
#58 lore raw

PATCH v5 32/50 multi-process: Use separate MMIO communication channel

In reply to Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

---
 hw/proxy/qemu-proxy.c         | 51 ++++++++++++++++++++++++++++---------------
 include/hw/proxy/qemu-proxy.h |  1 +
 include/io/mpqemu-link.h      |  7 ++++++
 io/mpqemu-link.c              |  2 ++
 qdev-monitor.c                |  1 +
 remote/remote-main.c          | 18 ++++++++++-----
 6 files changed, 58 insertions(+), 22 deletions(-)
hw/proxy/qemu-proxy.c +34 -17
index bcb24f7..68517aa 100644
@@ -283,13 +283,14 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
                         const char *exec_name, Error **errp)
 {
     pid_t rpid;
-    int fd[2] = {-1, -1};
+    int fd[2], mmio[2];
     Error *local_error = NULL;
     char *argv[64];
     int argc = 0;
     char *sfd;
     char *exec_dir;
     int rc = -EINVAL;
+    struct timeval timeout = {.tv_sec = 10, .tv_usec = 0};
 
     if (pdev->managed) {
         /* Child is forked by external program (such as libvirt). */
@@ -302,7 +303,8 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
         return rc;
     }
 
-    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) ||
+        socketpair(AF_UNIX, SOCK_STREAM, 0, mmio)) {
         error_setg(errp, "Unable to create unix socket.");
         return rc;
     }
@@ -310,6 +312,8 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
     argc = add_argv(exec_dir, argv, argc);
     sfd = g_strdup_printf("%d", fd[1]);
     argc = add_argv(sfd, argv, argc);
+    sfd = g_strdup_printf("%d", mmio[1]);
+    argc = add_argv(sfd, argv, argc);
     argc = make_argv((char *)opts, argv, argc);
 
     /* TODO: Restrict the forked process' permissions and capabilities. */
@@ -318,24 +322,35 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
     if (rpid == -1) {
         error_setg(errp, "Unable to spawn emulation program.");
         close(fd[0]);
-        goto fail;
+        close(fd[1]);
+        close(mmio[0]);
+        close(mmio[1]);
+        return rc;
     }
 
     if (rpid == 0) {
         close(fd[0]);
+        close(mmio[0]);
 
         rc = execv(argv[0], (char *const *)argv);
         exit(1);
     }
     pdev->remote_pid = rpid;
     pdev->socket = fd[0];
+    pdev->mmio_sock = mmio[0];
 
-    rc = 0;
+    rc = setsockopt(mmio[0], SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
+                   sizeof(timeout));
+    if (rc < 0) {
+        close(fd[0]);
+        close(mmio[0]);
 
-fail:
-    close(fd[1]);
+        error_setg(errp, "Unable to set timeout for socket");
 
-    return rc;
+        return rc;
+    }
+
+    return 0;
 }
 
 static int get_proxy_sock(PCIDevice *dev)
@@ -523,6 +538,9 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
 
+    mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio,
+                        pdev->mmio_sock);
+
     configure_memory_sync(pdev->sync, pdev->mpqemu_link);
 }
 
@@ -575,10 +593,10 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
                                 unsigned size, bool memory)
 {
     MPQemuLinkState *mpqemu_link = dev->mpqemu_link;
-    MPQemuMsg msg;
-    int wait;
+    MPQemuMsg msg, ret;
 
     memset(&msg, 0, sizeof(MPQemuMsg));
+    memset(&ret, 0, sizeof(MPQemuMsg));
 
     msg.bytestream = 0;
     msg.size = sizeof(msg.data1);
@@ -590,19 +608,18 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
         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->com);
+    mpqemu_msg_send(&msg, mpqemu_link->mmio);
 
-    if (!write) {
-        *val = wait_for_remote(wait);
-        PUT_REMOTE_WAIT(wait);
+    if (write) {
+        return;
     }
+
+    mpqemu_msg_recv(&ret, mpqemu_link->mmio);
+
+    *val = ret.data1.mmio_ret.val;
 }
 
 void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
include/hw/proxy/qemu-proxy.h +1 -0
index f7666fb..2a2c732 100644
@@ -58,6 +58,7 @@ struct PCIProxyDev {
     EventNotifier en_ping;
 
     int socket;
+    int mmio_sock;
 
     char *rid;
     char *dev_id;
include/io/mpqemu-link.h +7 -0
index aaaf1a4..3962630 100644
@@ -61,6 +61,7 @@ typedef enum {
     GET_PCI_INFO,
     RET_PCI_INFO,
     PROXY_PING,
+    MMIO_RETURN,
     MAX,
 } mpqemu_cmd_t;
 
@@ -107,6 +108,10 @@ typedef struct {
 } ret_pci_info_msg_t;
 
 typedef struct {
+    uint64_t val;
+} mmio_ret_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -117,6 +122,7 @@ typedef struct {
         bar_access_msg_t bar_access;
         set_irqfd_msg_t set_irqfd;
         ret_pci_info_msg_t ret_pci_info;
+        mmio_ret_msg_t mmio_ret;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
@@ -171,6 +177,7 @@ typedef struct MPQemuLinkState {
     GMainLoop *loop;
 
     MPQemuChannel *com;
+    MPQemuChannel *mmio;
 
     mpqemu_link_callback callback;
 } MPQemuLinkState;
io/mpqemu-link.c +2 -0
index 73b7032..07a9be9 100644
@@ -57,6 +57,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s)
     g_main_loop_quit(s->loop);
 
     mpqemu_destroy_channel(s->com);
+    mpqemu_destroy_channel(s->mmio);
 
     object_unref(OBJECT(s));
 }
@@ -330,6 +331,7 @@ void mpqemu_start_coms(MPQemuLinkState *s)
 {
 
     g_assert(g_source_attach(&s->com->gsrc, s->ctx));
+    g_assert(g_source_attach(&s->mmio->gsrc, s->ctx));
 
     g_main_loop_run(s->loop);
 }
qdev-monitor.c +1 -0
index ccd2ce0..27b2ddc 100644
@@ -730,6 +730,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
     pdev->rid = g_strdup(rid);
     if (old_pdev) {
         pdev->socket = old_pdev->socket;
+        pdev->mmio_sock = old_pdev->mmio_sock;
         pdev->remote_pid = old_pdev->remote_pid;
     } else {
         pdev->socket = managed ? socket : -1;
remote/remote-main.c +13 -5
index 2c05d20..6cfc446 100644
@@ -104,8 +104,8 @@ static void process_bar_write(MPQemuMsg *msg, Error **errp)
 static void process_bar_read(MPQemuMsg *msg, Error **errp)
 {
     bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    MPQemuMsg ret = { 0 };
     AddressSpace *as;
-    int wait = msg->fds[0];
     MemTxResult res;
     uint64_t val = 0;
 
@@ -139,9 +139,10 @@ static void process_bar_read(MPQemuMsg *msg, Error **errp)
     }
 
 fail:
-    notify_proxy(wait, val);
-
-    PUT_REMOTE_WAIT(wait);
+    ret.cmd = MMIO_RETURN;
+    ret.data1.mmio_ret.val = val;
+    ret.size = sizeof(ret.data1);
+    mpqemu_msg_send(&ret, mpqemu_link->mmio);
 }
 
 static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
@@ -456,7 +457,14 @@ int main(int argc, char *argv[])
 
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
 
-    parse_cmdline(argc - 2, argv + 2, NULL);
+    fd = qemu_parse_fd(argv[2]);
+    if (fd == -1) {
+        printf("Failed to parse fd for remote process.\n");
+        return -EINVAL;
+    }
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd);
+
+    parse_cmdline(argc - 3, argv + 3, NULL);
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
Signature · 1 line
1.8.3.1
#46 lore raw

PATCH v5 20/50 multi-process: add qdev_proxy_add to create proxy devices

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

This is handled while parsing the command line options. The parsed options are being sent to remote process as the messgaes containing JSON strings.

---
v4 -> v5:
- Removed support for DRIVE_OPTS as it's managed by remote process
- Addressed locking issues
- Squashed fix to a previous patch

 include/hw/proxy/qemu-proxy.h |  10 +-
 include/monitor/qdev.h        |  25 +++++
 qdev-monitor.c                | 245 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 279 insertions(+), 1 deletion(-)
include/hw/proxy/qemu-proxy.h +9 -1
index cd8505a..7c6bddd 100644
@@ -58,8 +58,9 @@ struct PCIProxyDev {
     int socket;
 
     char *rid;
-
+    char *dev_id;
     bool managed;
+    QLIST_ENTRY(PCIProxyDev) next;
 
     void (*set_proxy_sock) (PCIDevice *dev, int socket);
     int (*get_proxy_sock) (PCIDevice *dev);
@@ -80,6 +81,13 @@ typedef struct PCIProxyDevClass {
     char *command;
 } PCIProxyDevClass;
 
+typedef struct PCIProxyDevList {
+    QLIST_HEAD(, PCIProxyDev) devices;
+} proxy_dev_list_t;
+
+extern QemuMutex proxy_list_lock;
+extern proxy_dev_list_t proxy_dev_list;
+
 void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
                              unsigned size);
 
include/monitor/qdev.h +25 -0
index eaa947d..d47a544 100644
@@ -1,13 +1,38 @@
 #ifndef MONITOR_QDEV_H
 #define MONITOR_QDEV_H
 
+#include "hw/proxy/qemu-proxy.h"
+
 /*** monitor commands ***/
 
 void hmp_info_qtree(Monitor *mon, const QDict *qdict);
 void hmp_info_qdm(Monitor *mon, const QDict *qdict);
 void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
 
+DeviceState *qdev_remote_add(QemuOpts *opts, Error **errp);
+void qdev_proxy_fire(void);
+
 int qdev_device_help(QemuOpts *opts);
+DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
+                            char *command, char *exec_name, int socket,
+                            bool managed, Error **errp);
+
+struct remote_process {
+    int rid;
+    int remote_pid;
+    unsigned int type;
+    int socket;
+    char *command;
+    QemuOpts *opts;
+
+    QLIST_ENTRY(remote_process) next;
+};
+
+void remote_process_register(struct remote_process *p);
+
+struct remote_process *get_remote_process_type(unsigned int type);
+struct remote_process *get_remote_process_rid(unsigned int rid);
+
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
 void qdev_set_id(DeviceState *dev, const char *id);
 
qdev-monitor.c +245 -0

263 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#71 lore raw

PATCH v5 37/50 multi-process/mon: Refactor monitor/chardev functions out of vl.c

In reply to Jagannathan Raman

Some of the initialization helper functions w.r.t monitor & 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    |  1 +
 include/monitor/monitor.h |  2 ++
 monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c      |  1 +
 remote/remote-opts.c      |  1 +
 softmmu/vl.c              | 48 -----------------------------------------------
 7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
     qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
+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;
+}
+
 type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ 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
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 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);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
 #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
 /*
  * To prevent flooding clients, events can be throttled. The
  * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,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_opts(QemuOpts *opts, Error **errp)
 {
     Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
 #include "qemu/cutils.h"
 #include "remote-opts.h"
 #include "monitor/monitor.h"
+#include "chardev/char.h"
 #include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
 #include "block/block.h"
 #include "remote/remote-opts.h"
 #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
 #include "vl.h"
 /*
softmmu/vl.c +0 -48

60 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#45 lore raw

PATCH v5 19/50 multi-process: Retrieve PCI info from remote process

In reply to Jagannathan Raman

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

---
New Patch in v5. Removes per-device proxy and adds support for a generic proxy object

 hw/proxy/qemu-proxy.c    | 84 +++++++++++++++++++++++++++++++++++++++++++++++-
 include/io/mpqemu-link.h | 10 ++++++
 remote/remote-main.c     | 20 ++++++++++++
 3 files changed, 113 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +83 -1
index 3ba05d9..c888677 100644
@@ -26,12 +26,91 @@
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 static void setup_irqfd(PCIProxyDev *dev);
+static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
+                          unsigned int op);
+
+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->com);
+
+    mpqemu_msg_recv(&ret, mpqemu_link->com);
+
+    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);
+        }
+    }
+}
 
 static void proxy_ready(PCIDevice *dev)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
 
     setup_irqfd(pdev);
+    probe_pci_info(dev);
 }
 
 static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
@@ -254,7 +333,6 @@ static const TypeInfo pci_proxy_dev_type_info = {
     .name          = TYPE_PCI_PROXY_DEV,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIProxyDev),
-    .abstract      = true,
     .class_size    = sizeof(PCIProxyDevClass),
     .class_init    = pci_proxy_dev_class_init,
     .interfaces = (InterfaceInfo[]) {
@@ -355,8 +433,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) {
include/io/mpqemu-link.h +10 -0
index 90a8437..2ca89c5 100644
@@ -58,6 +58,8 @@ typedef enum {
     DRIVE_OPTS,
     DEVICE_ADD,
     DEVICE_DEL,
+    GET_PCI_INFO,
+    RET_PCI_INFO,
     MAX,
 } mpqemu_cmd_t;
 
@@ -96,6 +98,13 @@ typedef struct {
     int intx;
 } set_irqfd_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;
+
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
@@ -106,6 +115,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 +20 -0
index 02d78a4..0f830b8 100644
@@ -126,6 +126,23 @@ fail:
     PUT_REMOTE_WAIT(wait);
 }
 
+static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
+{
+    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, mpqemu_link->com);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -145,6 +162,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     switch (msg->cmd) {
     case INIT:
         break;
+    case GET_PCI_INFO:
+        process_get_pci_info_msg(remote_pci_dev, msg);
+        break;
     case PCI_CONFIG_WRITE:
         process_config_write(msg);
         break;
Signature · 1 line
1.8.3.1
#62 lore raw

PATCH v5 34/50 multi-process/mon: choose HMP commands based on target

In reply to Jagannathan Raman

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       | 44 ++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 72 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 scripts/hxtool
hmp-commands-info.hx +10 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
         .params     = "",
         .help       = "show the version of QEMU",
         .cmd        = hmp_info_version,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -48,6 +49,7 @@ ETEXI
         .params     = "",
         .help       = "show the character devices",
         .cmd        = hmp_info_chardev,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -64,6 +66,7 @@ ETEXI
         .help       = "show info of one block device or all block devices "
                       "(-n: show named nodes; -v: show details)",
         .cmd        = hmp_info_block,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -78,6 +81,7 @@ ETEXI
         .params     = "",
         .help       = "show block device statistics",
         .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -92,6 +96,7 @@ ETEXI
         .params     = "",
         .help       = "show progress of ongoing block device operations",
         .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -167,6 +172,7 @@ ETEXI
         .params     = "",
         .help       = "show the command line history",
         .cmd        = hmp_info_history,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -224,6 +230,7 @@ ETEXI
         .params     = "",
         .help       = "show PCI info",
         .cmd        = hmp_info_pci,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -630,6 +637,7 @@ ETEXI
         .params     = "",
         .help       = "show device tree",
         .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -644,6 +652,7 @@ ETEXI
         .params     = "",
         .help       = "show qdev device model list",
         .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -658,6 +667,7 @@ ETEXI
         .params     = "[path]",
         .help       = "show QOM composition tree",
         .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
         .params     = "",
         .help       = "quit the emulator",
         .cmd        = hmp_quit,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -82,6 +83,7 @@ ETEXI
         .params     = "device size",
         .help       = "resize a block image",
         .cmd        = hmp_block_resize,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -99,6 +101,7 @@ ETEXI
         .params     = "device [speed [base]]",
         .help       = "copy data from a backing file into a block device",
         .cmd        = hmp_block_stream,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -113,6 +116,7 @@ ETEXI
         .params     = "device speed",
         .help       = "set maximum speed for a background block operation",
         .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -129,6 +133,7 @@ ETEXI
                       "\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",
     },
 
 STEXI
@@ -143,6 +148,7 @@ ETEXI
         .params     = "device",
         .help       = "stop an active background block operation",
         .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -158,6 +164,7 @@ ETEXI
         .params     = "device",
         .help       = "pause an active background block operation",
         .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -172,6 +179,7 @@ ETEXI
         .params     = "device",
         .help       = "resume a paused background block operation",
         .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -186,6 +194,7 @@ ETEXI
         .params     = "[-f] device",
         .help       = "eject a removable medium (use -f to force it)",
         .cmd        = hmp_eject,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -200,6 +209,7 @@ ETEXI
         .params     = "device",
         .help       = "remove host block device",
         .cmd        = hmp_drive_del,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -219,6 +229,7 @@ ETEXI
         .params     = "device filename [format [read-only-mode]]",
         .help       = "change a removable medium, optional format",
         .cmd        = hmp_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -732,6 +743,7 @@ ETEXI
         .help       = "add device, like -device on the command line",
         .cmd        = hmp_device_add,
         .command_completion = device_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -747,6 +759,7 @@ ETEXI
         .help       = "remove device",
         .cmd        = hmp_device_del,
         .command_completion = device_del_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                       "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",
     },
 STEXI
 @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                       "[,readonly=on|off][,copy-on-read=on|off]",
         .help       = "add drive to PCI storage controller",
         .cmd        = hmp_drive_add,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1816,6 +1831,7 @@ ETEXI
         .help       = "add chardev",
         .cmd        = hmp_chardev_add,
         .command_completion = chardev_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1831,6 +1847,7 @@ ETEXI
         .params     = "id args",
         .help       = "change chardev",
         .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1848,6 +1865,7 @@ ETEXI
         .help       = "remove chardev",
         .cmd        = hmp_chardev_remove,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1864,6 +1882,7 @@ ETEXI
         .help       = "send a break on chardev",
         .cmd        = hmp_chardev_send_break,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1940,6 +1959,7 @@ ETEXI
         .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 +42 -2

65 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#95 lore raw

PATCH v5 46/50 multi-process/mig: Restore the VMSD in remote process

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

The remote process accepts the VMSD from Proxy object and restores it

---
 migration/savevm.c   | 36 ++++++++++++++++++++++++++++++++++++
 migration/savevm.h   |  1 +
 remote/remote-main.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
migration/savevm.c +36 -0
index 09af14d..e95ea4a 100644
@@ -2969,3 +2969,39 @@ int qemu_remote_savevm(QEMUFile *f)
 
     return 0;
 }
+
+int qemu_remote_loadvm(QEMUFile *f)
+{
+    uint8_t section_type;
+    int ret = 0;
+
+    qemu_mutex_lock_iothread();
+
+    while (true) {
+        section_type = qemu_get_byte(f);
+
+        if (qemu_file_get_error(f)) {
+            ret = qemu_file_get_error(f);
+            break;
+        }
+
+        switch (section_type) {
+        case QEMU_VM_SECTION_FULL:
+            ret = qemu_loadvm_section_start_full(f, NULL);
+            if (ret < 0) {
+                break;
+            }
+            break;
+        case QEMU_VM_EOF:
+            goto out;
+        default:
+            ret = -EINVAL;
+            goto out;
+        }
+    }
+
+out:
+    qemu_mutex_unlock_iothread();
+
+    return ret;
+}
migration/savevm.h +1 -0
index 0491d3a..8741c66 100644
@@ -66,5 +66,6 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
 int qemu_load_device_state(QEMUFile *f);
 
 int qemu_remote_savevm(QEMUFile *f);
+int qemu_remote_loadvm(QEMUFile *f);
 
 #endif
remote/remote-main.c +33 -0
index 0260c7c..ab4ad0b 100644
@@ -68,6 +68,7 @@
 #include "chardev/char.h"
 #include "sysemu/reset.h"
 #include "vl.h"
+#include "migration/misc.h"
 
 static MPQemuLinkState *mpqemu_link;
 
@@ -363,6 +364,30 @@ static void process_start_mig_out(MPQemuMsg *msg)
     qemu_fclose(f);
 }
 
+static int process_start_mig_in(MPQemuMsg *msg)
+{
+    Error *err = NULL;
+    QIOChannel *ioc;
+    QEMUFile *f;
+    int rc = -EINVAL;
+
+    ioc = qio_channel_new_fd(msg->fds[0], &err);
+    if (err) {
+        error_report_err(err);
+        return rc;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
+
+    f = qemu_fopen_channel_input(ioc);
+
+    rc = qemu_remote_loadvm(f);
+
+    qemu_fclose(f);
+
+    return rc;
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -455,6 +480,12 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case START_MIG_OUT:
         process_start_mig_out(msg);
         break;
+    case START_MIG_IN:
+        if (process_start_mig_in(msg)) {
+            error_setg(&err, "Incoming migration failed.");
+            goto finalize_loop;
+        }
+        break;
     case RUNSTATE_SET:
         remote_runstate_set(msg->data1.runstate.state);
         notify_proxy(msg->fds[0], 0);
@@ -532,6 +563,8 @@ int main(int argc, char *argv[])
     }
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd);
 
+    migration_object_init();
+
     parse_cmdline(argc - 3, argv + 3, NULL);
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
Signature · 1 line
1.8.3.1
#50 lore raw

PATCH v5 24/50 multi-process: add processing of remote device command line

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add processing of command line options for devices emulated in the remote process.
After remote devices are created along with their proxies, signal the proxies to finish the configuration steps.

---
 softmmu/vl.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
softmmu/vl.c +33 -0
index 94a7b93..79a286c 100644
@@ -35,6 +35,11 @@
 #include "sysemu/runstate.h"
 #include "sysemu/seccomp.h"
 #include "sysemu/tcg.h"
+#include "qapi/qmp/qdict.h"
+#include "block/qdict.h"
+#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qlist.h"
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
@@ -2065,10 +2070,35 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
     return qdev_device_help(opts);
 }
 
+#if defined(CONFIG_MPQEMU)
+static int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    DeviceState *dev;
+
+    dev = qdev_remote_add(opts, errp);
+    if (!dev) {
+        error_setg(errp, "qdev_remote_add failed for device.");
+        return -1;
+    }
+    object_unref(OBJECT(dev));
+    return 0;
+}
+#endif
+
 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     DeviceState *dev;
 
+#if defined(CONFIG_MPQEMU)
+    const char *remote;
+
+    remote = qemu_opt_get(opts, "remote");
+    if (remote) {
+        /* This will be a remote process */
+        return rdevice_init_func(opaque, opts, errp);
+    }
+#endif
+
     dev = qdev_device_add(opts, errp);
     if (!dev && *errp) {
         error_report_err(*errp);
@@ -4307,6 +4337,9 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
     qemu_run_machine_init_done_notifiers();
 
+#if defined(CONFIG_MPQEMU)
+    qdev_proxy_fire();
+#endif
     if (rom_check_and_register_reset() != 0) {
         error_report("rom check and register reset failed");
         exit(1);
Signature · 1 line
1.8.3.1
#91 lore raw

PATCH v5 43/50 multi-process/mig: Load VMSD in the proxy object

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

The Proxy object loads the VMSD of remote process in source and send it to the remote process in the destination

---
 hw/proxy/qemu-proxy.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 2 files changed, 51 insertions(+)
hw/proxy/qemu-proxy.c +50 -0
index 19f0dbb..1649f60 100644
@@ -581,12 +581,62 @@ static int proxy_post_save(void *opaque)
     return 0;
 }
 
+static int proxy_post_load(void *opaque, int version_id)
+{
+    MigrationIncomingState *mis = migration_incoming_get_current();
+    PCIProxyDev *pdev = opaque;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    uint8_t byte;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "proxy-migration-channel");
+
+    f_remote = qemu_fopen_channel_output(ioc);
+
+    msg.cmd = START_MIG_IN;
+    msg.bytestream = 0;
+    msg.num_fds = 1;
+    msg.fds[0] = fd[1];
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    size = pdev->migsize;
+
+    while (size) {
+        byte = qemu_get_byte(mis->from_src_file);
+        qemu_put_byte(f_remote, byte);
+        size--;
+    }
+
+    qemu_fflush(f_remote);
+    qemu_fclose(f_remote);
+
+    close(fd[1]);
+
+    return 0;
+}
+
 const VMStateDescription vmstate_pci_proxy_device = {
     .name = "PCIProxyDevice",
     .version_id = 2,
     .minimum_version_id = 1,
     .pre_save = proxy_pre_save,
     .post_save = proxy_post_save,
+    .post_load = proxy_post_load,
     .fields = (VMStateField[]) {
         VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
         VMSTATE_UINT64(migsize, PCIProxyDev),
include/io/mpqemu-link.h +1 -0
index b42c003..01371fc 100644
@@ -64,6 +64,7 @@ typedef enum {
     MMIO_RETURN,
     DEVICE_RESET,
     START_MIG_OUT,
+    START_MIG_IN,
     MAX,
 } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1
#51 lore raw

PATCH v5 25/50 multi-process: Introduce build flags to separate remote process code

In reply to Jagannathan Raman

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 c621d70..035c23b 100644
@@ -268,6 +268,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 e39b073..6c8560f 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
1.8.3.1
#84 lore raw

PATCH v5 41/50 multi-process/mig: Enable VMSD save in the Proxy object

In reply to Jagannathan Raman

Collect the VMSD from remote process on the source and save it to the channel leading to the destination

---
v4 -> v5:
- Using qemu_file_shutdown() instead of qemu_thread_cancel(). Removed patch which introduced qemu_thread_cancel()

 hw/proxy/qemu-proxy.c         | 135 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |   2 +
 include/io/mpqemu-link.h      |   1 +
 3 files changed, 138 insertions(+)
hw/proxy/qemu-proxy.c +135 -0
index b1b9282..19f0dbb 100644
@@ -23,6 +23,14 @@
 #include "util/event_notifier-posix.c"
 #include "hw/boards.h"
 #include "include/qemu/log.h"
+#include "io/channel.h"
+#include "migration/qemu-file-types.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+#include "migration/migration.h"
+#include "migration/vmstate.h"
 
 QEMUTimer *hb_timer;
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
@@ -35,6 +43,9 @@ static void broadcast_init(void);
 static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
                           unsigned int op);
 
+#define PAGE_SIZE qemu_real_host_page_size
+uint8_t *mig_data;
+
 static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx)
 {
     /* TODO: Add proper handler. */
@@ -460,6 +471,129 @@ static void pci_proxy_dev_inst_init(Object *obj)
     dev->mem_init = false;
 }
 
+typedef struct {
+    QEMUFile *rem;
+    PCIProxyDev *dev;
+} proxy_mig_data;
+
+static void *proxy_mig_out(void *opaque)
+{
+    proxy_mig_data *data = opaque;
+    PCIProxyDev *dev = data->dev;
+    uint8_t byte;
+    uint64_t data_size = PAGE_SIZE;
+
+    mig_data = g_malloc(data_size);
+
+    while (true) {
+        byte = qemu_get_byte(data->rem);
+
+        if (qemu_file_get_error(data->rem)) {
+            break;
+        }
+
+        mig_data[dev->migsize++] = byte;
+        if (dev->migsize == data_size) {
+            data_size += PAGE_SIZE;
+            mig_data = g_realloc(mig_data, data_size);
+        }
+    }
+
+    return NULL;
+}
+
+static int proxy_pre_save(void *opaque)
+{
+    PCIProxyDev *pdev = opaque;
+    proxy_mig_data *mig_data;
+    QEMUFile *f_remote;
+    MPQemuMsg msg = {0};
+    QemuThread thread;
+    Error *err = NULL;
+    QIOChannel *ioc;
+    uint64_t size;
+    int fd[2];
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        return -1;
+    }
+
+    ioc = qio_channel_new_fd(fd[0], &err);
+    if (err) {
+        error_report_err(err);
+        return -1;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig");
+
+    f_remote = qemu_fopen_channel_input(ioc);
+
+    pdev->migsize = 0;
+
+    mig_data = g_malloc0(sizeof(proxy_mig_data));
+    mig_data->rem = f_remote;
+    mig_data->dev = pdev;
+
+    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
+                       QEMU_THREAD_DETACHED);
+
+    msg.cmd = START_MIG_OUT;
+    msg.bytestream = 0;
+    msg.num_fds = 2;
+    msg.fds[0] = fd[1];
+    msg.fds[1] = GET_REMOTE_WAIT;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+    size = wait_for_remote(msg.fds[1]);
+    PUT_REMOTE_WAIT(msg.fds[1]);
+
+    assert(size != ULLONG_MAX);
+
+    /*
+     * migsize is being update by a separate thread. Using volatile to
+     * instruct the compiler to fetch the value of this variable from
+     * memory during every read
+     */
+    while (*((volatile uint64_t *)&pdev->migsize) < size) {
+    }
+
+    qemu_file_shutdown(f_remote);
+
+    qemu_fclose(f_remote);
+    close(fd[1]);
+
+    return 0;
+}
+
+static int proxy_post_save(void *opaque)
+{
+    MigrationState *ms = migrate_get_current();
+    PCIProxyDev *pdev = opaque;
+    uint64_t pos = 0;
+
+    while (pos < pdev->migsize) {
+        qemu_put_byte(ms->to_dst_file, mig_data[pos]);
+        pos++;
+    }
+
+    qemu_fflush(ms->to_dst_file);
+
+    return 0;
+}
+
+const VMStateDescription vmstate_pci_proxy_device = {
+    .name = "PCIProxyDevice",
+    .version_id = 2,
+    .minimum_version_id = 1,
+    .pre_save = proxy_pre_save,
+    .post_save = proxy_post_save,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev),
+        VMSTATE_UINT64(migsize, PCIProxyDev),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -471,6 +605,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
     k->config_write = pci_proxy_write_config;
 
     dc->reset = proxy_device_reset;
+    dc->vmsd = &vmstate_pci_proxy_device;
 }
 
 static const TypeInfo pci_proxy_dev_type_info = {
include/hw/proxy/qemu-proxy.h +2 -0
index 5de8129..537c227 100644
@@ -75,6 +75,8 @@ struct PCIProxyDev {
                         bool need_spawn, Error **errp);
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+    uint64_t migsize;
 };
 
 typedef struct PCIProxyDevClass {
include/io/mpqemu-link.h +1 -0
index d2234ca..b42c003 100644
@@ -63,6 +63,7 @@ typedef enum {
     PROXY_PING,
     MMIO_RETURN,
     DEVICE_RESET,
+    START_MIG_OUT,
     MAX,
 } mpqemu_cmd_t;
 
Signature · 1 line
1.8.3.1
#53 lore raw

PATCH v5 27/50 multi-process: add remote option

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 qemu-options.hx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
qemu-options.hx +21 -0
index ac315c1..2c5e97f 100644
@@ -27,6 +27,27 @@ STEXI
 Display version information and exit
 ETEXI
 
+DEF("remote", HAS_ARG, QEMU_OPTION_remote,
+    "-remote socket[,prop[=value][,...]]\n"
+    "                add remote process\n"
+    "                prop=value,... sets driver properties\n"
+    "                use '-remote help' to print all possible properties\n",
+    QEMU_ARCH_ALL)
+STEXI
+@table @option
+@item rid
+@findex -rid
+remote id
+@item socket
+@findex -socket
+Remote process socket
+@item command
+@findex -command
+Remote process command.
+
+@end table
+ETEXI
+
 DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "-machine [type=]name[,prop[=value][,...]]\n"
     "                selects emulated machine ('-machine help' for list)\n"
Signature · 1 line
1.8.3.1
#88 lore raw

PATCH v5 42/50 multi-process/mig: Send VMSD of remote to the Proxy object

In reply to Jagannathan Raman

The remote process sends the VMSD to the Proxy object, on the source side

---
 migration/savevm.c   | 27 +++++++++++++++++++++++++++
 migration/savevm.h   |  2 ++
 remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
migration/savevm.c +27 -0
index 1d4220e..09af14d 100644
@@ -2942,3 +2942,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
 
     return !(vmsd && vmsd->unmigratable);
 }
+
+int qemu_remote_savevm(QEMUFile *f)
+{
+    SaveStateEntry *se;
+    int ret;
+
+    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
+        if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) {
+            continue;
+        }
+
+        save_section_header(f, se, QEMU_VM_SECTION_FULL);
+
+        ret = vmstate_save(f, se, NULL);
+        if (ret) {
+            qemu_file_set_error(f, ret);
+            return ret;
+        }
+
+        save_section_footer(f, se);
+    }
+
+    qemu_put_byte(f, QEMU_VM_EOF);
+    qemu_fflush(f);
+
+    return 0;
+}
migration/savevm.h +2 -0
index ba64a7e..0491d3a 100644
@@ -65,4 +65,6 @@ void qemu_loadvm_state_cleanup(void);
 int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);
 int qemu_load_device_state(QEMUFile *f);
 
+int qemu_remote_savevm(QEMUFile *f);
+
 #endif
remote/remote-main.c +43 -0

61 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#54 lore raw

PATCH v5 28/50 multi-process: add remote options parser

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 include/monitor/qdev.h |   1 +
 softmmu/vl.c           | 105 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl-parse.c             |  31 +++++++++++++++
 vl.h                   |   1 +
 4 files changed, 138 insertions(+)
include/monitor/qdev.h +1 -0
index d47a544..f3a56fa 100644
@@ -23,6 +23,7 @@ struct remote_process {
     unsigned int type;
     int socket;
     char *command;
+    char *exec;
     QemuOpts *opts;
 
     QLIST_ENTRY(remote_process) next;
softmmu/vl.c +105 -0

135 lines not on this page · raw message

vl-parse.c +31 -0
index b76bc95..1f6a3f0 100644
@@ -85,6 +85,37 @@ const QEMUOption *lookup_opt(int argc, char **argv,
     return popt;
 }
 
+#if defined(CONFIG_MPQEMU)
+int device_remote_add(void *opaque, QemuOpts *opts, Error **errp)
+{
+    unsigned int rid = 0;
+    const char *opt_rid = NULL;
+    struct remote_process *p = NULL;
+
+    if (opaque) {
+        rid = *(unsigned int *)opaque;
+    }
+    opt_rid = qemu_opt_get(opts, "rid");
+    if (!opt_rid) {
+        return 0;
+    }
+
+    p = get_remote_process_rid(rid);
+    if (!p) {
+        error_setg(errp, "No process for rid %d", rid);
+        return -EINVAL;
+    }
+
+    if (atoi(opt_rid) == rid) {
+        qemu_opt_set(opts, "command", p->command, errp);
+        qemu_opt_set(opts, "exec", p->exec, errp);
+        rdevice_init_func(opaque, opts, errp);
+        qemu_opts_del(opts);
+    }
+    return 0;
+}
+#endif
+
 int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     BlockInterfaceType *block_default_type = opaque;
vl.h +1 -0
index a171fab..d84bf63 100644
@@ -36,6 +36,7 @@ int device_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
 #if defined(CONFIG_MPQEMU)
 int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp);
+int device_remote_add(void *opaque, QemuOpts *opts, Error **errp);
 #endif
 
 #endif /* VL_H */
Signature · 1 line
1.8.3.1
#67 lore raw

PATCH v5 36/50 multi-process/mon: enable QMP module support in the remote process

In reply to Jagannathan Raman

Build system changes to enable QMP module in the remote process

---
 Makefile.objs              |  9 +++++
 Makefile.target            | 35 +++++++++++++++++--
 hmp-commands.hx            |  5 +--
 hw/core/Makefile.objs      |  1 +
 monitor/Makefile.objs      |  4 +++
 monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++++
 qapi/Makefile.objs         |  2 ++
 qom/Makefile.objs          |  1 +
 ui/Makefile.objs           |  2 ++
 10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 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
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.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) += device-hotplug.o
 
 #######################################################################
 # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
 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 035c23b..4ead5c3 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
 
 #########################################################
@@ -203,6 +222,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)
@@ -288,10 +311,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
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
         .args_type  = "name:S?",
         .params     = "[cmd]",
         .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -618,7 +619,7 @@ ETEXI
         .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,
     },
 
 STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 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 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
 common-obj-y += monitor.o qmp.o hmp.o
 common-obj-y += qmp-cmds.o qmp-cmds-control.o
 common-obj-y += hmp-cmds.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 +46 -38

322 lines not on this page · raw message

monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 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
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
 obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
 obj-y += qapi-commands.o
 obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o 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
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 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
1.8.3.1
#61 lore raw

PATCH v5 33/50 multi-process: perform device reset in the remote process

In reply to Jagannathan Raman

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

---
V4 -> v5:
- Device reset wait for remote

 hw/proxy/qemu-proxy.c    | 25 +++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 remote/remote-main.c     | 14 ++++++++++++++
 3 files changed, 40 insertions(+)
hw/proxy/qemu-proxy.c +25 -0
index 68517aa..741f02a 100644
@@ -431,14 +431,39 @@ static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,
     config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE);
 }
 
+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 = eventfd(0, EFD_CLOEXEC);
+    msg.num_fds = 1;
+    msg.fds[0] = wait;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    wait_for_remote(wait);
+    close(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_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 3962630..d2234ca 100644
@@ -62,6 +62,7 @@ typedef enum {
     RET_PCI_INFO,
     PROXY_PING,
     MMIO_RETURN,
+    DEVICE_RESET,
     MAX,
 } mpqemu_cmd_t;
 
remote/remote-main.c +14 -0
index 6cfc446..5284ee9 100644
@@ -53,8 +53,11 @@
 #include "qemu/log.h"
 #include "qemu/cutils.h"
 #include "remote-opts.h"
+#include "monitor/monitor.h"
+#include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
+
 PCIDevice *remote_pci_dev;
 bool create_done;
 
@@ -241,6 +244,11 @@ fail:
     PUT_REMOTE_WAIT(wait);
 }
 
+static void process_device_reset_msg(MPQemuMsg *msg)
+{
+    qemu_devices_reset();
+}
+
 static int setup_device(MPQemuMsg *msg, Error **errp)
 {
     QObject *obj;
@@ -395,6 +403,12 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         wait = msg->fds[0];
         notify_proxy(wait, (uint32_t)getpid());
         break;
+    case DEVICE_RESET:
+        process_device_reset_msg(msg);
+        if (msg->num_fds == 1) {
+            notify_proxy(msg->fds[0], 0);
+        }
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#55 lore raw

PATCH v5 29/50 multi-process: add parse_cmdline in remote process

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 remote/Makefile.objs |  1 +
 remote/remote-main.c | 11 ++++++
 remote/remote-opts.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 remote/remote-opts.h | 15 ++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 remote/remote-opts.c
 create mode 100644 remote/remote-opts.h
remote/Makefile.objs +1 -0
index c1349ad..a677fce 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) += iohub.o
remote/remote-main.c +11 -0
index ec1ce2c..872ff7e 100644
@@ -52,6 +52,7 @@
 #include "qapi/qmp/qlist.h"
 #include "qemu/log.h"
 #include "qemu/cutils.h"
+#include "remote-opts.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -429,6 +430,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\n");
@@ -442,6 +450,9 @@ int main(int argc, char *argv[])
     }
 
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
+
+    parse_cmdline(argc - 2, argv + 2, NULL);
+
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
     mpqemu_start_coms(mpqemu_link);
remote/remote-opts.c new file +99 -0

99 lines not on this page · raw message

remote/remote-opts.h new file +15 -0
new file mode 100644
index 0000000..263d428
@@ -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
1.8.3.1
#94 lore raw

PATCH v5 45/50 multi-process/mig: Synchronize runstate of remote process

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Synchronize the runstate of the remote process with that of QEMU

---
 hw/proxy/qemu-proxy.c         | 26 ++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |  2 ++
 include/io/mpqemu-link.h      |  8 ++++++++
 include/sysemu/runstate.h     |  1 +
 qdev-monitor.c                | 11 ++++++++++-
 remote/remote-main.c          |  5 +++++
 remote/remote-opts.c          |  5 +++++
 runstate.c                    |  5 +++++
 8 files changed, 62 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +26 -0
index 1649f60..5876957 100644
@@ -15,6 +15,7 @@
 #include "hw/pci/pci.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qstring.h"
+#include "sysemu/runstate.h"
 #include "hw/proxy/qemu-proxy.h"
 #include "hw/proxy/memory-sync.h"
 #include "qom/object.h"
@@ -765,6 +766,27 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
     }
 }
 
+static void proxy_vm_state_change(void *opaque, int running, RunState state)
+{
+    PCIProxyDev *dev = opaque;
+    MPQemuMsg msg = { 0 };
+    int wait = -1;
+
+    msg.cmd = RUNSTATE_SET;
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.data1.runstate.state = state;
+
+    wait = eventfd(0, EFD_CLOEXEC);
+    msg.num_fds = 1;
+    msg.fds[0] = wait;
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->com);
+
+    wait_for_remote(wait);
+    close(wait);
+}
+
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
 {
     PCIProxyDev *dev = PCI_PROXY_DEV(device);
@@ -782,6 +804,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
         }
     }
 
+    dev->vmcse = qemu_add_vm_change_state_handler(proxy_vm_state_change, dev);
+
     dev->set_proxy_sock = set_proxy_sock;
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
@@ -807,6 +831,8 @@ static void pci_dev_exit(PCIDevice *pdev)
     if (!QLIST_EMPTY(&proxy_dev_list.devices)) {
         start_broadcast_timer();
     }
+
+    qemu_del_vm_change_state_handler(dev->vmcse);
 }
 
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/qemu-proxy.h +2 -0
index 537c227..6784298 100644
@@ -76,6 +76,8 @@ struct PCIProxyDev {
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
 
+    VMChangeStateEntry *vmcse;
+
     uint64_t migsize;
 };
 
include/io/mpqemu-link.h +8 -0
index 01371fc..beb8293 100644
@@ -20,6 +20,8 @@
 #include "exec/cpu-common.h"
 #include "exec/hwaddr.h"
 
+#include "qapi/qapi-types-run-state.h"
+
 #define TYPE_MPQEMU_LINK "mpqemu-link"
 #define MPQEMU_LINK(obj) \
     OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK)
@@ -65,6 +67,7 @@ typedef enum {
     DEVICE_RESET,
     START_MIG_OUT,
     START_MIG_IN,
+    RUNSTATE_SET,
     MAX,
 } mpqemu_cmd_t;
 
@@ -115,6 +118,10 @@ typedef struct {
 } mmio_ret_msg_t;
 
 typedef struct {
+    RunState state;
+} runstate_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -126,6 +133,7 @@ typedef struct {
         set_irqfd_msg_t set_irqfd;
         ret_pci_info_msg_t ret_pci_info;
         mmio_ret_msg_t mmio_ret;
+        runstate_msg_t runstate;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
include/sysemu/runstate.h +1 -0
index ece939f..8c5810f 100644
@@ -8,6 +8,7 @@ extern RunState current_run_state;
 
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
+void remote_runstate_set(RunState state);
 int runstate_is_running(void);
 bool runstate_needs_reset(void);
 bool runstate_store(char *str, size_t size);
qdev-monitor.c +10 -1
index f120509..8efa1a8 100644
@@ -35,6 +35,7 @@
 #include "qemu/option_int.h"
 #include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
 #include "migration/misc.h"
 #include "migration/migration.h"
 #include "qemu/cutils.h"
@@ -674,6 +675,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
     const char *str;
     bool need_spawn = false;
     bool remote_exists = false;
+    char *command = NULL;
 
     if (strlen(rid) > MAX_RID_LENGTH) {
         error_setg(errp, "rid %s is too long.", rid);
@@ -743,11 +745,18 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
         need_spawn = true;
     }
 
-    pdev->init_proxy(PCI_DEVICE(ds), cmd, exec_name, need_spawn, errp);
+    if (runstate_check(RUN_STATE_INMIGRATE)) {
+        command = g_strdup_printf("%s %s", cmd, "-incoming defer");
+    } else {
+        command = g_strdup(cmd);
+    }
+
+    pdev->init_proxy(PCI_DEVICE(ds), command, exec_name, need_spawn, errp);
 
     QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next);
 
     qemu_opts_del(proxy_opts);
+
     return ds;
 }
 
remote/remote-main.c +5 -0
index e97eb76..0260c7c 100644
@@ -31,6 +31,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
 #include "block/block.h"
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
@@ -454,6 +455,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case START_MIG_OUT:
         process_start_mig_out(msg);
         break;
+    case RUNSTATE_SET:
+        remote_runstate_set(msg->data1.runstate.state);
+        notify_proxy(msg->fds[0], 0);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
remote/remote-opts.c +5 -0
index e22ad5c..839baf1 100644
@@ -40,8 +40,10 @@
 #include "remote/remote-opts.h"
 #include "include/qemu-common.h"
 #include "monitor/monitor.h"
+#include "sysemu/runstate.h"
 
 #include "vl.h"
+
 /*
  * In remote process, we parse only subset of options. The code
  * taken from vl.c to re-use in remote command line parser.
@@ -85,6 +87,9 @@ void parse_cmdline(int argc, char **argv, char **envp)
             case QEMU_OPTION_qmp:
                 monitor_parse(optarg, "control", false);
                 break;
+            case QEMU_OPTION_incoming:
+                remote_runstate_set(RUN_STATE_INMIGRATE);
+                break;
             case QEMU_OPTION_monitor:
                 if (!strncmp(optarg, "stdio", 5)) {
                     warn_report("STDIO not supported in remote process");
runstate.c +5 -0
index 273345a..9c5c627 100644
@@ -34,3 +34,8 @@ bool runstate_check(RunState state)
 {
     return current_run_state == state;
 }
+
+void remote_runstate_set(RunState state)
+{
+    current_run_state = state;
+}
Signature · 1 line
1.8.3.1
#75 lore raw

PATCH v5 39/50 multi-process: prevent duplicate memory initialization in remote

In reply to Jagannathan Raman

When multiple controllers are configured in a remote process, it's better for the memory to be managed by only one of the proxy objects for that process, in order to conserve file descriptors. Added "mem_int" flag for this purpose.

---
 hw/proxy/qemu-proxy.c         | 13 ++++++++++++-
 include/hw/proxy/qemu-proxy.h |  1 +
 qdev-monitor.c                |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +12 -1
index 741f02a..b1b9282 100644
@@ -453,6 +453,13 @@ static void proxy_device_reset(DeviceState *dev)
     close(wait);
 }
 
+static void pci_proxy_dev_inst_init(Object *obj)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(obj);
+
+    dev->mem_init = false;
+}
+
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -470,6 +477,7 @@ static const TypeInfo pci_proxy_dev_type_info = {
     .name          = TYPE_PCI_PROXY_DEV,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIProxyDev),
+    .instance_init = pci_proxy_dev_inst_init,
     .class_size    = sizeof(PCIProxyDevClass),
     .class_init    = pci_proxy_dev_class_init,
     .interfaces = (InterfaceInfo[]) {
@@ -566,7 +574,10 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio,
                         pdev->mmio_sock);
 
-    configure_memory_sync(pdev->sync, pdev->mpqemu_link);
+    if (!pdev->mem_init) {
+        pdev->mem_init = true;
+        configure_memory_sync(pdev->sync, pdev->mpqemu_link);
+    }
 }
 
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
include/hw/proxy/qemu-proxy.h +1 -0
index 2a2c732..5de8129 100644
@@ -49,6 +49,7 @@ struct PCIProxyDev {
     MPQemuLinkState *mpqemu_link;
 
     RemoteMemSync *sync;
+    bool mem_init;
     struct kvm_irqfd irqfd;
 
     EventNotifier intr;
qdev-monitor.c +1 -1
index 27b2ddc..f120509 100644
@@ -732,9 +732,9 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
         pdev->socket = old_pdev->socket;
         pdev->mmio_sock = old_pdev->mmio_sock;
         pdev->remote_pid = old_pdev->remote_pid;
+        pdev->mem_init = true;
     } else {
         pdev->socket = managed ? socket : -1;
-
     }
     pdev->managed = managed;
 
Signature · 1 line
1.8.3.1
#57 lore raw

PATCH v5 31/50 multi-process: handle heartbeat messages in remote process

In reply to Jagannathan Raman

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 872ff7e..2c05d20 100644
@@ -315,6 +315,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
     Error *err = NULL;
+    int wait;
 
     if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
         goto finalize_loop;
@@ -389,6 +390,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case DEVICE_DEL:
         process_device_del_msg(msg);
         break;
+    case PROXY_PING:
+        wait = msg->fds[0];
+        notify_proxy(wait, (uint32_t)getpid());
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#100 lore raw

PATCH v5 48/50 multi-process: Validate incoming commands from Proxy

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Validate the incoming commands to confirm that they would not cause any errors in the remote process.

---
 hw/proxy/qemu-proxy.c    |  6 +++-
 include/io/mpqemu-link.h |  2 ++
 io/mpqemu-link.c         | 75 +++++++++++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c     |  4 +++
 4 files changed, 85 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +5 -1
index 4d4eff4..7330094 100644
@@ -868,7 +868,11 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
 
     mpqemu_msg_recv(&ret, mpqemu_link->mmio);
 
-    *val = ret.data1.mmio_ret.val;
+    if (!mpqemu_msg_valid(&ret)) {
+        *val = 0;
+    } else {
+        *val = ret.data1.mmio_ret.val;
+    }
 }
 
 void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
include/io/mpqemu-link.h +2 -0
index 722f08c..2f44f31 100644
@@ -213,4 +213,6 @@ void mpqemu_start_coms(MPQemuLinkState *s);
 uint64_t wait_for_remote(int efd);
 void notify_proxy(int fd, uint64_t val);
 
+bool mpqemu_msg_valid(MPQemuMsg *msg);
+
 #endif
io/mpqemu-link.c +74 -1

84 lines not on this page · raw message

remote/remote-main.c +4 -0
index 20d160e..c4aa3e0 100644
@@ -435,6 +435,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     if (msg->id > MAX_REMOTE_DEVICES) {
         error_setg(&err, "id of the device is larger than max number of "\
                          "devices per remote process.");
+    }
+
+    if (!mpqemu_msg_valid(msg)) {
+        error_setg(&err, "Message is not valid");
         goto finalize_loop;
     }
 
Signature · 1 line
1.8.3.1
#106 lore raw

PATCH v5 50/50 multi-process: add configure and usage information

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 docs/qemu-multiprocess.txt
docs/qemu-multiprocess.txt new file +86 -0
new file mode 100644
index 0000000..f156177
@@ -0,0 +1,86 @@
+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
+--------
+
+To start qemu with devices intended to run in a separate emulation
+process without libvirtd support, the following should be used on QEMU
+command line. As of now, we only support the emulation of lsi53c895a
+in a separate process
+
+* Since parts of the RAM are shared between QEMU & remote process, a
+  memory-backend-file is required to facilitate this, as follows:
+
+  -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on
+
+* The devices to be emulated in the separate process are defined as
+  before with addition of "rid" suboption that serves as a remote group
+  identificator.
+
+  -device <device options>,rid="remote process id"
+
+  For example, for non multi-process qemu:
+    -device lsi53c895a,id=scsi0 device
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
+    -drive id=drive0,file=data-disk.img
+
+  and for multi-process qemu and no libvirt
+  support (i.e. QEMU forks child processes):
+    -device lsi53c895a,id=scsi0,rid=0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0
+
+* The command-line options for the remote process are added to the "command"
+  suboption of the newly added "-remote" option. 
+
+   -remote [socket],rid=0,exec="...",command="..."
+
+  The drives to be emulated by the remote process are specified as part of
+  this command sub-option. The device to be used to connect to the monitor
+  is also specified as part of this suboption.
+
+  For example, the following option adds a drive and monitor to the remote
+  process:
+  -remote rid=0,exec="qemu-scsi-dev",command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait"
+
+  Note: There's an issue with this "command" sub-option which we are in the
+  process of fixing. To work around this issue, it requires additional
+  "comma" characters as illustrated above, and in the example below.
+
+* Example QEMU command-line to launch lsi53c895a in a remote process
+
+  #/bin/sh
+  qemu-system-x86_64 \
+  -name "OL7.4" \
+  -machine q35,accel=kvm \
+  -smp sockets=1,cores=1,threads=1 \
+  -cpu host \
+  -m 2048 \
+  -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \
+  -numa node,memdev=mem \
+  -device virtio-scsi-pci,id=virtio_scsi_pci0 \
+  -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \
+  -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \
+  -boot d \
+  -monitor stdio \
+  -vnc :0 \
+  -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \
+  -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\
+  -remote rid=8,exec="qemu-scsi-dev",command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait"
+
+  We could connect to the monitor using the following command:
+  socat /home/qmp-sock stdio
+
+  After hotplugging disks to the remote process, please execute the
+  following command in the guest to refresh the list of storage devices:
+  rescan_scsi_bus.sh -a
Signature · 1 line
1.8.3.1
#74 lore raw

PATCH v5 38/50 multi-process/mon: Initialize QMP module for remote processes

In reply to Jagannathan Raman
---
 remote/remote-main.c | 11 +++++++++++
 remote/remote-opts.c | 10 ++++++++++
 2 files changed, 21 insertions(+)
remote/remote-main.c +11 -0
index 23fc0df..58d9905 100644
@@ -56,6 +56,7 @@
 #include "monitor/monitor.h"
 #include "chardev/char.h"
 #include "sysemu/reset.h"
+#include "vl.h"
 
 static MPQemuLinkState *mpqemu_link;
 
@@ -436,6 +437,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)) {
@@ -453,6 +456,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);
@@ -483,6 +488,12 @@ int main(int argc, char *argv[])
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
+    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_start_coms(mpqemu_link);
 
     return 0;
remote/remote-opts.c +10 -0
index 565e641..e22ad5c 100644
@@ -82,6 +82,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
1.8.3.1
#76 lore raw

PATCH v5 40/50 multi-process/mig: build migration module in the remote process

In reply to Jagannathan Raman

Add Makefile support to enable migration in remote process

---
 Makefile.objs           |  4 +++-
 Makefile.target         |  1 +
 migration/Makefile.objs | 13 ++++++++++++-
 net/Makefile.objs       |  2 ++
 softmmu/vl.c            |  2 --
 stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 stubs/net-stub.c        | 21 +++++++++++++++++++++
 stubs/qapi-misc.c       |  2 ++
 stubs/replay.c          |  8 ++++++++
 stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
 vl-parse.c              |  3 +++
 11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
 
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
 common-obj-$(CONFIG_LINUX) += fsdev/
 
 common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
 
 #######################################################################
 # qapi
-
 common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
 remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
 remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
 remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
 all-remote-pci-obj-y += exec-vary.o
 all-remote-pci-obj-y += ioport.o
 all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
 endif
 
 remote-pci-obj-y :=
migration/Makefile.objs +12 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
 vde.o-libs = $(VDE_LIBS)
 
 common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
 bool enable_cpu_pm = false;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
 bool boot_strict;
 uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
 bool wakeup_suspend_enabled;
 
 int icount_align_option;
stubs/migration.c +49 -0

58 lines not on this page · raw message

stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
 #include "qapi/qapi-commands-net.h"
 #include "qapi/qapi-commands-rocker.h"
 
+#pragma weak qmp_announce_self
+
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                  NetClientDriver type, int max)
 {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
 {
     qemu_debug_assert(0);
 }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
 #include "./qapi/qapi-types-dump.h"
 #include "qapi/qapi-commands-dump.h"
 
+#pragma weak qmp_xen_load_devices_state
+
 void qmp_dump_guest_memory(bool paging, const char *file,
                            bool has_detach, bool detach,
                            bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "sysemu/replay.h"
 
 ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
 void replay_add_blocker(Error *reason)
 {
 }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
 #include "disas/disas.h"
 #include "audio/audio.h"
 
+#pragma weak qemu_add_exit_notifier
+
 bool tcg_allowed;
 bool xen_allowed;
 bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 
     return -1;
 }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
 
 #include "vl.h"
 
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
 /***********************************************************/
 /* QEMU Block devices */
 
Signature · 1 line
1.8.3.1
#97 lore raw

PATCH v5 47/50 multi-process: Enable support for multiple devices in remote

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add support to allow multiple devices to be configured in the remote process

---
 hw/proxy/qemu-proxy.c         |  4 ++-
 include/hw/proxy/qemu-proxy.h |  3 +++
 include/io/mpqemu-link.h      |  1 +
 qdev-monitor.c                |  2 ++
 remote/remote-main.c          | 62 +++++++++++++++++++++++++++++++++++--------
 5 files changed, 60 insertions(+), 12 deletions(-)
hw/proxy/qemu-proxy.c +3 -1
index 5876957..4d4eff4 100644
@@ -242,7 +242,7 @@ static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
     msg.cmd = cmd;
     msg.bytestream = 1;
     msg.size = qstring_get_length(qstr) + 1;
-
+    msg.id = pdev->id;
 
     wait = eventfd(0, EFD_NONBLOCK);
     msg.num_fds = 1;
@@ -404,6 +404,7 @@ static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
     msg.size = sizeof(conf_data);
     msg.cmd = op;
     msg.bytestream = 1;
+    msg.id = dev->id;
 
     if (op == PCI_CONFIG_WRITE) {
         msg.num_fds = 0;
@@ -710,6 +711,7 @@ static void setup_irqfd(PCIProxyDev *dev)
 
     memset(&msg, 0, sizeof(MPQemuMsg));
     msg.cmd = SET_IRQFD;
+    msg.id = dev->id;
     msg.num_fds = 2;
     msg.fds[0] = event_notifier_get_fd(&dev->intr);
     msg.fds[1] = event_notifier_get_fd(&dev->resample);
include/hw/proxy/qemu-proxy.h +3 -0
index 6784298..5ff3aec 100644
@@ -43,6 +43,9 @@ extern const MemoryRegionOps proxy_default_ops;
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    uint64_t id;
+    uint64_t nr_devices;
+
     int n_mr_sections;
     MemoryRegionSection *mr_sections;
 
include/io/mpqemu-link.h +1 -0
index beb8293..722f08c 100644
@@ -124,6 +124,7 @@ typedef struct {
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
+    uint64_t id;
     size_t size;
 
     union {
qdev-monitor.c +2 -0
index 8efa1a8..cda2545 100644
@@ -735,8 +735,10 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
         pdev->mmio_sock = old_pdev->mmio_sock;
         pdev->remote_pid = old_pdev->remote_pid;
         pdev->mem_init = true;
+        pdev->id = old_pdev->nr_devices++;
     } else {
         pdev->socket = managed ? socket : -1;
+        pdev->id =  pdev->nr_devices++;
     }
     pdev->managed = managed;
 
remote/remote-main.c +51 -11

111 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#93 lore raw

PATCH v5 44/50 multi-process/mig: refactor runstate_check into common file

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

runstate_check file is refactored into vl-parse.c

---
 Makefile.objs             |  2 ++
 include/sysemu/runstate.h |  2 ++
 runstate.c                | 36 ++++++++++++++++++++++++++++++++++++
 softmmu/vl.c              | 10 ----------
 stubs/runstate-check.c    |  3 +++
 5 files changed, 43 insertions(+), 10 deletions(-)
 create mode 100644 runstate.c
Makefile.objs +2 -0
index 65009da..cf2200d 100644
@@ -40,6 +40,7 @@ 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) += runstate.o
 
 ##############################################################
 # remote-lsi-obj-y is code used to implement remote LSI device
@@ -103,6 +104,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 common-obj-$(CONFIG_FDT) += device_tree.o
 
 common-obj-y += vl-parse.o
+common-obj-y += runstate.o
 
 #######################################################################
 # qapi
include/sysemu/runstate.h +2 -0
index f760094..ece939f 100644
@@ -4,6 +4,8 @@
 #include "qapi/qapi-types-run-state.h"
 #include "qemu/notify.h"
 
+extern RunState current_run_state;
+
 bool runstate_check(RunState state);
 void runstate_set(RunState new_state);
 int runstate_is_running(void);
runstate.c new file +36 -0
new file mode 100644
index 0000000..273345a
@@ -0,0 +1,36 @@
+/*
+ * 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-common.h"
+#include "sysemu/runstate.h"
+
+/***********************************************************/
+/* QEMU state */
+
+RunState current_run_state = RUN_STATE_PRECONFIG;
+
+bool runstate_check(RunState state)
+{
+    return current_run_state == state;
+}
softmmu/vl.c +0 -10
index 42d5682..d95ee2f 100644
@@ -620,11 +620,6 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
     return 0;
 }
 
-/***********************************************************/
-/* QEMU state */
-
-static RunState current_run_state = RUN_STATE_PRECONFIG;
-
 /* We use RUN_STATE__MAX but any invalid value will do */
 static RunState vmstop_requested = RUN_STATE__MAX;
 static QemuMutex vmstop_lock;
@@ -732,11 +727,6 @@ static const RunStateTransition runstate_transitions_def[] = {
 
 static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX];
 
-bool runstate_check(RunState state)
-{
-    return current_run_state == state;
-}
-
 bool runstate_store(char *str, size_t size)
 {
     const char *state = RunState_str(current_run_state);
stubs/runstate-check.c +3 -0
index 2ccda2b..3038bcb 100644
@@ -1,6 +1,9 @@
 #include "qemu/osdep.h"
 
 #include "sysemu/runstate.h"
+
+#pragma weak runstate_check
+
 bool runstate_check(RunState state)
 {
     return state == RUN_STATE_PRELAUNCH;
Signature · 1 line
1.8.3.1
#103 lore raw

PATCH v5 49/50 multi-process: add the concept description to docs/devel/qemu-multiprocess

In reply to Jagannathan Raman

From: John G Johnson <[email protected]>

---
 docs/devel/index.rst             |    1 +
 docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1103 insertions(+)
 create mode 100644 docs/devel/qemu-multiprocess.rst
docs/devel/index.rst +1 -0
index 4dc2ca8..1a95871 100644
@@ -25,3 +25,4 @@ Contents:
    tcg-plugins
    bitops
    reset
+   multi-process
docs/devel/qemu-multiprocess.rst new file +1102 -0

1,102 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v5 4/50 multi-process: Add stub functions to facilate build of multi-process

In reply to Jagannathan Raman

Add stub functions that are needed during compile time but not in runtime.

---
 accel/stubs/kvm-stub.c    |  5 +++
 accel/stubs/tcg-stub.c    | 97 +++++++++++++++++++++++++++++++++++++++++++++++
 stubs/audio.c             | 12 ++++++
 stubs/machine-init-done.c |  4 ++
 stubs/monitor.c           | 41 ++++++++++++++++++++
 stubs/net-stub.c          | 31 +++++++++++++++
 stubs/replay.c            | 14 +++++++
 stubs/vl-stub.c           | 79 ++++++++++++++++++++++++++++++++++++++
 stubs/vmstate.c           | 19 ++++++++++
 stubs/xen-mapcache.c      | 22 +++++++++++
 10 files changed, 324 insertions(+)
 create mode 100644 stubs/audio.c
 create mode 100644 stubs/net-stub.c
 create mode 100644 stubs/vl-stub.c
 create mode 100644 stubs/xen-mapcache.c
accel/stubs/kvm-stub.c +5 -0
index 82f118d..baa6b38 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 +97 -0

111 lines not on this page · raw message

stubs/audio.c new file +12 -0
new file mode 100644
index 0000000..8ae3b0f
@@ -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/machine-init-done.c +4 -0
index cd8e813..3deabc9 100644
@@ -6,3 +6,7 @@ bool machine_init_done = true;
 void qemu_add_machine_init_done_notifier(Notifier *notify)
 {
 }
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
stubs/monitor.c +41 -0

53 lines not on this page · raw message

stubs/net-stub.c new file +31 -0
new file mode 100644
index 0000000..cb2274b
@@ -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 5974ec1..2e3feee 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 cc4fe41..c7c015a 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 0000000..af5c031
@@ -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
1.8.3.1
#110 lore raw
In reply to Jagannathan Raman
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [PATCH v5 00/50] Initial support for multi-process qemu
Message-id: [email protected]
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
046649c multi-process: add configure and usage information
7c79419 multi-process: add the concept description to docs/devel/qemu-multiprocess b06e676 multi-process: Validate incoming commands from Proxy
cc1f6b4 multi-process: Enable support for multiple devices in remote 0060f81 multi-process/mig: Restore the VMSD in remote process
f163e9b multi-process/mig: Synchronize runstate of remote process 8bc3796 multi-process/mig: refactor runstate_check into common file 4ebbd74 multi-process/mig: Load VMSD in the proxy object
4b124b2 multi-process/mig: Send VMSD of remote to the Proxy object b8dbad8 multi-process/mig: Enable VMSD save in the Proxy object 3253157 multi-process/mig: build migration module in the remote process 96557d0 multi-process: prevent duplicate memory initialization in remote 9a85af0 multi-process/mon: Initialize QMP module for remote processes ca70d4a multi-process/mon: Refactor monitor/chardev functions out of vl.c dbe3a63 multi-process/mon: enable QMP module support in the remote process a12a802 multi-process/mon: stub functions to enable QMP module for remote process 1e6d3af multi-process/mon: choose HMP commands based on target 888e741 multi-process: perform device reset in the remote process 8f15bd8 multi-process: Use separate MMIO communication channel 64593f5 multi-process: handle heartbeat messages in remote process 93b0f96 multi-process: send heartbeat messages to remote
ad214e9 multi-process: add parse_cmdline in remote process
83bc352 multi-process: add remote options parser
7fcc704 multi-process: add remote option
24ca162 multi-process: refractor vl.c code
20c05d9 multi-process: Introduce build flags to separate remote process code 335f331 multi-process: add processing of remote device command line 413bf28 multi-process: remote: add create_done condition
d0e4f00 multi-process: remote: use fd for socket from parent process 045f8f8 multi-process: remote: add setup_devices msg processing a8ea8aa multi-process: add qdev_proxy_add to create proxy devices 59d0bff multi-process: Retrieve PCI info from remote process
898af59 multi-process: configure remote side devices
b49c9f3 multi-process: create IOHUB object to handle irq
06dc766 multi-process: Synchronize remote memory
a88dcbd multi-process: PCI BAR read/write handling for proxy & remote endpoints 5a3fbbb mutli-process: build remote command line args
c319ce7 multi-process: introduce proxy object
7cb950d multi-process: remote process initialization
e91592e multi-process: setup memory manager for remote device
4f14ba4 multi-process: setup a machine object for remote device process b1e58b1 multi-process: setup PCI host bridge for remote device 2785043 multi-process: add functions to synchronize proxy and remote endpoints f83d3f3 multi-process: define mpqemu-link object
252d736 multi-process: build system for remote device process
1482849 multi-process: Add config option for multi-process QEMU b78f0cc multi-process: Add stub functions to facilate build of multi-process 837f4a6 multi-process: add a command line option for debug file e58fa6d multi-process: Refactor machine_init and exit notifiers bf5b343 multi-process: memory: alloc RAM from file at offset

=== OUTPUT BEGIN ===
1/50 Checking commit bf5b3438f584 (multi-process: memory: alloc RAM from file at offset) 2/50 Checking commit e58fa6db276f (multi-process: Refactor machine_init and exit notifiers) 3/50 Checking commit 837f4a602862 (multi-process: add a command line option for debug file) 4/50 Checking commit b78f0cc3f072 (multi-process: Add stub functions to facilate build of multi-process)
ERROR: suspect code indent for conditional statements (4, 4)
#141: FILE: accel/stubs/tcg-stub.c:109:
+ while (1) {
+ }

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #155:
new file mode 100644

total: 1 errors, 1 warnings, 378 lines checked

Patch 4/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

5/50 Checking commit 1482849e9584 (multi-process: Add config option for multi-process QEMU) 6/50 Checking commit 252d7366e5c1 (multi-process: build system for remote device process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #311:
new file mode 100644

total: 0 errors, 1 warnings, 250 lines checked

Patch 6/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/50 Checking commit f83d3f37432f (multi-process: define mpqemu-link object)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #20:
new file mode 100644

total: 0 errors, 1 warnings, 437 lines checked

Patch 7/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/50 Checking commit 278504388c18 (multi-process: add functions to synchronize proxy and remote endpoints) 9/50 Checking commit b1e58b14c4d2 (multi-process: setup PCI host bridge for remote device)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#31:
new file mode 100644

total: 0 errors, 1 warnings, 118 lines checked

Patch 9/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
10/50 Checking commit 4f14ba434d5b (multi-process: setup a machine object for remote device process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#63:
new file mode 100644

total: 0 errors, 1 warnings, 169 lines checked

Patch 10/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/50 Checking commit e91592e1d3e5 (multi-process: setup memory manager for remote device)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #122:
new file mode 100644

total: 0 errors, 1 warnings, 163 lines checked

Patch 11/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/50 Checking commit 7cb950d0b414 (multi-process: remote process initialization) 13/50 Checking commit c319ce7e8e42 (multi-process: introduce proxy object)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #34:
new file mode 100644

WARNING: line over 80 characters
#78: FILE: hw/proxy/qemu-proxy.c:33:
+ error_setg(errp, "Remote processed is managed and launched by external program");

total: 0 errors, 2 warnings, 338 lines checked

Patch 13/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
14/50 Checking commit 5a3fbbb83e89 (mutli-process: build remote command line args)
15/50 Checking commit a88dcbd3b371 (multi-process: PCI BAR read/write handling for proxy & remote endpoints) 16/50 Checking commit 06dc7666cb21 (multi-process: Synchronize remote memory)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#36:
new file mode 100644

total: 0 errors, 1 warnings, 323 lines checked

Patch 16/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
17/50 Checking commit b49c9f3a3655 (multi-process: create IOHUB object to handle irq)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #43:
deleted file mode 100644

total: 0 errors, 1 warnings, 411 lines checked

Patch 17/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
18/50 Checking commit 898af59b01ef (multi-process: configure remote side devices)
19/50 Checking commit 59d0bff02614 (multi-process: Retrieve PCI info from remote process) 20/50 Checking commit a8ea8aa3417d (multi-process: add qdev_proxy_add to create proxy devices) 21/50 Checking commit 045f8f82de1c (multi-process: remote: add setup_devices msg processing) 22/50 Checking commit d0e4f00c3065 (multi-process: remote: use fd for socket from parent process) 23/50 Checking commit 413bf287c459 (multi-process: remote: add create_done condition) 24/50 Checking commit 335f331eed39 (multi-process: add processing of remote device command line) 25/50 Checking commit 20c05d9deccc (multi-process: Introduce build flags to separate remote process code) 26/50 Checking commit 24ca162587f0 (multi-process: refractor vl.c code)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#189:
new file mode 100644

total: 0 errors, 1 warnings, 326 lines checked

Patch 26/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
27/50 Checking commit 7fcc7047eaa0 (multi-process: add remote option) 28/50 Checking commit 83bc352512c7 (multi-process: add remote options parser) 29/50 Checking commit ad214e916e4d (multi-process: add parse_cmdline in remote process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #59:
new file mode 100644

ERROR: line over 90 characters
#135: FILE: remote/remote-opts.c:72:
+ error_report("Option not supported for this target, %x arch_mask, %x arch_type",

total: 1 errors, 1 warnings, 148 lines checked

Patch 29/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

30/50 Checking commit 93b0f96ec29b (multi-process: send heartbeat messages to remote)
31/50 Checking commit 64593f51a86c (multi-process: handle heartbeat messages in remote process) 32/50 Checking commit 8f15bd8412a3 (multi-process: Use separate MMIO communication channel) 33/50 Checking commit 888e741a19af (multi-process: perform device reset in the remote process) 34/50 Checking commit 1e6d3af047e6 (multi-process/mon: choose HMP commands based on target) 35/50 Checking commit a12a80202f4e (multi-process/mon: stub functions to enable QMP module for remote process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#110:
new file mode 100644

ERROR: line over 90 characters
#550: FILE: stubs/qapi-target.c:48:
+#if defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X) || defined(TARGET_MIPS)

total: 1 errors, 1 warnings, 730 lines checked

Patch 35/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

36/50 Checking commit dbe3a637fac7 (multi-process/mon: enable QMP module support in the remote process) 37/50 Checking commit ca70d4a7859d (multi-process/mon: Refactor monitor/chardev functions out of vl.c) 38/50 Checking commit 9a85af09cf01 (multi-process/mon: Initialize QMP module for remote processes) 39/50 Checking commit 96557d09787c (multi-process: prevent duplicate memory initialization in remote) 40/50 Checking commit 32531572e8c7 (multi-process/mig: build migration module in the remote process) 41/50 Checking commit b8dbad8073b6 (multi-process/mig: Enable VMSD save in the Proxy object)
ERROR: suspect code indent for conditional statements (4, 4)
#131: FILE: hw/proxy/qemu-proxy.c:557:
+ while (*((volatile uint64_t *)&pdev->migsize) < size) {
+ }

total: 1 errors, 0 warnings, 174 lines checked

Patch 41/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

42/50 Checking commit 4b124b25aded (multi-process/mig: Send VMSD of remote to the Proxy object) 43/50 Checking commit 4ebbd744f34b (multi-process/mig: Load VMSD in the proxy object) 44/50 Checking commit 8bc37967dcd8 (multi-process/mig: refactor runstate_check into common file)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#48:
new file mode 100644

total: 0 errors, 1 warnings, 89 lines checked

Patch 44/50 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
45/50 Checking commit f163e9b02e25 (multi-process/mig: Synchronize runstate of remote process) 46/50 Checking commit 0060f814e9c8 (multi-process/mig: Restore the VMSD in remote process) 47/50 Checking commit cc1f6b4970d4 (multi-process: Enable support for multiple devices in remote) 48/50 Checking commit b06e676c2119 (multi-process: Validate incoming commands from Proxy) 49/50 Checking commit 7c794195319d (multi-process: add the concept description to docs/devel/qemu-multiprocess)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#22:
new file mode 100644

total: 0 errors, 1 warnings, 1106 lines checked

Patch 49/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
50/50 Checking commit 046649c71c87 (multi-process: add configure and usage information)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644

total: 0 errors, 1 warnings, 86 lines checked

Patch 50/50 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#111 lore raw
In reply to Jagannathan Raman
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

CC stubs/sysbus.o
CC stubs/tpm.o

Warning, treated as error:
/tmp/qemu-test/src/docs/devel/index.rst:13:toctree contains reference to nonexisting document 'multi-process'

  CC      stubs/trace-control.o
  CC      stubs/uuid.o
  CC      stubs/vm-stop.o
make: *** [Makefile:1063: docs/devel/index.html] Error 2
make: *** Waiting for unfinished jobs....
In file included from /tmp/qemu-test/src/include/monitor/qdev.h:4,
                 from /tmp/qemu-test/src/stubs/monitor.c:14:
/tmp/qemu-test/src/include/hw/proxy/qemu-proxy.h:12:10: fatal error: linux/kvm.h: No such file or directory
 #include <linux/kvm.h>
          ^~~~~~~~~~~~~

compilation terminated.
make: *** [/tmp/qemu-test/src/rules.mak:69: stubs/monitor.o] Error 1 Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>

    sys.exit(main())

---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=4f8cf4b3c5d9425cb7ce2e50962601a2', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-gx6fxsj2/src/docker-src.2020-02-24-17.00.12.3070:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=4f8cf4b3c5d9425cb7ce2e50962601a2
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-gx6fxsj2/src'
make: *** [docker-run-test-mingw@fedora] Error 2

real 3m34.769s
user 0m4.558s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#112 lore raw
In reply to Jagannathan Raman
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

qemu-system-aarch64: falling back to tcg
TEST check-unit: tests/test-char
**
ERROR:/tmp/qemu-test/src/tests/test-char.c:230:char_mux_test: assertion failed (h1.last_event == 42): (3 == 42)
TEST iotest-qcow2: 004
qemu-system-aarch64: -accel kvm: invalid accelerator kvm
qemu-system-aarch64: falling back to tcg
ERROR - Bail out! ERROR:/tmp/qemu-test/src/tests/test-char.c:230:char_mux_test: assertion failed (h1.last_event == 42): (3 == 42)
make: *** [check-unit] Error 1
make: *** Waiting for unfinished jobs....
TEST check-qtest-x86_64: tests/qtest/fdc-test
TEST iotest-qcow2: 005
---
Not run: 259
Failures: 030 040 041 071 099 120 184 186 267
Failed 9 of 116 iotests
make: *** [check-tests/check-block.sh] Error 1
Traceback (most recent call last):
File "./tests/docker/docker.py", line 664, in <module>

    sys.exit(main())

---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=084f448bfb414d66a22a2ccf133f7163', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-0vhz47_c/src/docker-src.2020-02-24-17.09.16.1174:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=084f448bfb414d66a22a2ccf133f7163
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-0vhz47_c/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 14m39.906s
user 0m8.340s

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#107 lore raw

Re: [PATCH v5 50/50] multi-process: add configure and usage information

In reply to Jagannathan Raman
Quoted 31 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 docs/qemu-multiprocess.txt
docs/qemu-multiprocess.txt new file +15 -0
new file mode 100644
index 0000000..f156177
@@ -0,0 +1,86 @@
+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
+--------

docs/qemu-multiprocess.txt line 25

Quoted 10 lines
docs/qemu-multiprocess.txt new file +10 -0
+
+To start qemu with devices intended to run in a separate emulation
+process without libvirtd support, the following should be used on QEMU
+command line. As of now, we only support the emulation of lsi53c895a
+in a separate process
+
+* Since parts of the RAM are shared between QEMU & remote process, a
+  memory-backend-file is required to facilitate this, as follows:
+
+  -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on

memory-backend-memfd is more convenient. It doesn't require a mem-path and share=on is the default.

Quoted 6 lines
docs/qemu-multiprocess.txt new file +6 -0
+
+* The devices to be emulated in the separate process are defined as
+  before with addition of "rid" suboption that serves as a remote group
+  identificator.
+
+  -device <device options>,rid="remote process id"

docs/qemu-multiprocess.txt line 41

Quoted 10 lines
docs/qemu-multiprocess.txt new file +10 -0
+
+  For example, for non multi-process qemu:
+    -device lsi53c895a,id=scsi0 device
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
+    -drive id=drive0,file=data-disk.img
+
+  and for multi-process qemu and no libvirt
+  support (i.e. QEMU forks child processes):
+    -device lsi53c895a,id=scsi0,rid=0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0

This approach is invasive:
* lsi53c895a should not need to be modified with a new rid= option.
* QEMU should not know about the scsi-hd device or drive0. Only the device emulation process needs to know about scsi-hd.

In order to cleanly separate QEMU and the device emulation process syntax like this is needed:

-object remote-device,id=rid0,...
-device remote-pci-device,id=scsi0,remote-device=rid0

The "remote-device" object could be part of remote-pci-device, but keeping it separate may be useful in the future in order to support things like reconnection.

The generic "remote-pci-device" device handles any remote PCI device, not just the LSI SCSI controller.

Do you agree with this approach?

docs/qemu-multiprocess.txt line 46

Quoted 4 lines
docs/qemu-multiprocess.txt new file +4 -0
+* The command-line options for the remote process are added to the "command"
+  suboption of the newly added "-remote" option. 
+
+   -remote [socket],rid=0,exec="...",command="..."

QEMU has been using the -object TYPE syntax instead of adding new -TYPE command-line options. This gives you object_add hotplug for free, for example. I suggest using -object remote-device,id=,exec=,command=, instead of -remote.

docs/qemu-multiprocess.txt line 58

Quoted 12 lines
docs/qemu-multiprocess.txt new file +12 -0
+
+  The drives to be emulated by the remote process are specified as part of
+  this command sub-option. The device to be used to connect to the monitor
+  is also specified as part of this suboption.
+
+  For example, the following option adds a drive and monitor to the remote
+  process:
+  -remote rid=0,exec="qemu-scsi-dev",command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait"
+
+  Note: There's an issue with this "command" sub-option which we are in the
+  process of fixing. To work around this issue, it requires additional
+  "comma" characters as illustrated above, and in the example below.

command= (which could be called args= for clarity) will be difficult to use not just because of comma escaping but also because of double-quote escaping. How do you pass a command-line argument that contains spaces?

#104 lore raw

Re: [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess

In reply to Jagannathan Raman
Quoted 26 lines · Jagannathan Raman

From: John G Johnson <[email protected]>

---
 docs/devel/index.rst             |    1 +
 docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1103 insertions(+)
 create mode 100644 docs/devel/qemu-multiprocess.rst
docs/devel/index.rst +1 -0
index 4dc2ca8..1a95871 100644
@@ -25,3 +25,4 @@ Contents:
    tcg-plugins
    bitops
    reset
+   multi-process
docs/devel/qemu-multiprocess.rst new file +0 -0
new file mode 100644
index 0000000..477e246

docs/devel/qemu-multiprocess.rst line 1

Quoted 1 line
docs/devel/qemu-multiprocess.rst new file +1 -0
@@ -0,0 +1,1102 @@
+Disaggregating QEMU

Please revise this document and the patch series to use consistent terminology. At least "qemu-multiprocess.rst", "--enable-mpqemu", and "disaggregated QEMU" are used to describe this feature (there are probably more, I have only looked at 2 patches so far).

It's confusing for someone who stumbles across one of these terms and then has to figure out that we're talking about the same thing when encountering other terms later on.

Please use a single name and use it consistently.

docs/devel/qemu-multiprocess.rst line 11

Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10 -0
+===================
+
+QEMU is often used as the hypervisor for virtual machines running in the
+Oracle cloud. Since one of the advantages of cloud computing is the
+ability to run many VMs from different tenants in the same cloud
+infrastructure, a guest that compromised its hypervisor could
+potentially use the hypervisor's access privileges to access data it is
+not authorized for.
+
+QEMU can be susceptible to security attack because it is a large,

s/attack/attacks/

docs/devel/qemu-multiprocess.rst line 13

Quoted 2 lines
docs/devel/qemu-multiprocess.rst new file +2 -0
+monolithic program that provides many features to the VMs it services.
+Many of these feature can be configured out of QEMU, but even a reduced

s/feature/features/

#101 lore raw

Re: [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy

In reply to Jagannathan Raman
Quoted 8 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Validate the incoming commands to confirm that they would not cause any errors in the remote process.

Quoted 6 lines
---
 hw/proxy/qemu-proxy.c    |  6 +++-
 include/io/mpqemu-link.h |  2 ++
 io/mpqemu-link.c         | 75 +++++++++++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c     |  4 +++
 4 files changed, 85 insertions(+), 2 deletions(-)

Please squash this into the patch(es) that introduced the code.

Reviewers want to see a logical sequence of patches. Introducing unsafe code in an earlier patch and adding checks in a later patch makes it impossible to review the patches in sequence (reviewers would waste time pointing out bugs that end up getting fixed later).

remote/remote-main.c static void process_msg(GIOCondition cond, MPQemuChannel *chan) · line 438

Quoted 9 lines
remote/remote-main.c +1 -0
index 20d160e..c4aa3e0 100644
@@ -435,6 +435,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     if (msg->id > MAX_REMOTE_DEVICES) {
         error_setg(&err, "id of the device is larger than max number of "\
                          "devices per remote process.");
+    }

Was goto finalize_loop accidentally dropped?

#98 lore raw

Re: [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote

In reply to Jagannathan Raman
Quoted 4 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add support to allow multiple devices to be configured in the remote process

This patch allows multiple devices to be addressed over a single UNIX domain socket. This could be a scalability/performance bottleneck because an SMP guest can only talk to 1 device at a time.

This approach doesn't address the qemu-storage-daemon use case where one device emulation process provides devices to multiple guests. Multiple UNIX domain sockets are needed for that.

Is multiplexing multiple devices over a single connection is a desirable feature? The alternative of one UNIX domain socket per device instance seems more practical to me because it should perform better and solves the qemu-storage-daemon use case.

#102 lore raw

Re: [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy

In reply to Stefan Hajnoczi
Quoted 16 lines · Stefan Hajnoczi
Quoted 8 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Validate the incoming commands to confirm that they would not cause any errors in the remote process.

Quoted 6 lines
---
 hw/proxy/qemu-proxy.c    |  6 +++-
 include/io/mpqemu-link.h |  2 ++
 io/mpqemu-link.c         | 75 +++++++++++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c     |  4 +++
 4 files changed, 85 insertions(+), 2 deletions(-)
Quoted 7 lines

Please squash this into the patch(es) that introduced the code.

Reviewers want to see a logical sequence of patches. Introducing unsafe code in an earlier patch and adding checks in a later patch makes it impossible to review the patches in sequence (reviewers would waste time pointing out bugs that end up getting fixed later).

Thanks Stefan, will merge that with appropriate patches.

Quoted 11 lines

remote/remote-main.c static void process_msg(GIOCondition cond, MPQemuChannel *chan) · line 438

Quoted 9 lines
remote/remote-main.c +1 -0
index 20d160e..c4aa3e0 100644
@@ -435,6 +435,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     if (msg->id > MAX_REMOTE_DEVICES) {
         error_setg(&err, "id of the device is larger than max number of "\
                          "devices per remote process.");
+    }

Was goto finalize_loop accidentally dropped?

Yes, thank you.

Elena

#108 lore raw

Re: [PATCH v5 50/50] multi-process: add configure and usage information

In reply to Stefan Hajnoczi
Quoted 37 lines · Stefan Hajnoczi
Quoted 36 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 docs/qemu-multiprocess.txt
docs/qemu-multiprocess.txt new file +20 -0
new file mode 100644
index 0000000..f156177
@@ -0,0 +1,86 @@
+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
+--------
+
+To start qemu with devices intended to run in a separate emulation
+process without libvirtd support, the following should be used on QEMU
+command line. As of now, we only support the emulation of lsi53c895a
+in a separate process
Quoted 9 lines

docs/qemu-multiprocess.txt line 25

Quoted 5 lines
docs/qemu-multiprocess.txt new file +5 -0
+
+* Since parts of the RAM are shared between QEMU & remote process, a
+  memory-backend-file is required to facilitate this, as follows:
+
+  -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on

memory-backend-memfd is more convenient. It doesn't require a mem-path and share=on is the default.

Will change this.

Quoted 28 lines
Quoted 6 lines
docs/qemu-multiprocess.txt new file +6 -0
+
+* The devices to be emulated in the separate process are defined as
+  before with addition of "rid" suboption that serves as a remote group
+  identificator.
+
+  -device <device options>,rid="remote process id"

docs/qemu-multiprocess.txt line 41

Quoted 10 lines
docs/qemu-multiprocess.txt new file +10 -0
+
+  For example, for non multi-process qemu:
+    -device lsi53c895a,id=scsi0 device
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
+    -drive id=drive0,file=data-disk.img
+
+  and for multi-process qemu and no libvirt
+  support (i.e. QEMU forks child processes):
+    -device lsi53c895a,id=scsi0,rid=0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0

This approach is invasive:
* lsi53c895a should not need to be modified with a new rid= option.
* QEMU should not know about the scsi-hd device or drive0. Only the device emulation process needs to know about scsi-hd.

In order to cleanly separate QEMU and the device emulation process syntax like this is needed:

-object remote-device,id=rid0,...
-device remote-pci-device,id=scsi0,remote-device=rid0

Quoted 9 lines

The "remote-device" object could be part of remote-pci-device, but keeping it separate may be useful in the future in order to support things like reconnection.

The generic "remote-pci-device" device handles any remote PCI device, not just the LSI SCSI controller.

Do you agree with this approach?

We discussed these changes and they seem to be along the lines with the future work on vfio over socket approach we will be working on later.

Could we for this experimental version have the changes you propose here with one modification - instead of having generic remote-pci-device imply that that is LSI device? And while we work towards vfio over socket this will become any remote PCI device?

Quoted 10 lines

docs/qemu-multiprocess.txt line 46

Quoted 4 lines
docs/qemu-multiprocess.txt new file +4 -0
+* The command-line options for the remote process are added to the "command"
+  suboption of the newly added "-remote" option. 
+
+   -remote [socket],rid=0,exec="...",command="..."

QEMU has been using the -object TYPE syntax instead of adding new -TYPE command-line options. This gives you object_add hotplug for free, for example. I suggest using -object remote-device,id=,exec=,command=, instead of -remote.

We will add these changes.

Quoted 8 lines
Quoted 8 lines
docs/qemu-multiprocess.txt new file +8 -0
+
+  The drives to be emulated by the remote process are specified as part of
+  this command sub-option. The device to be used to connect to the monitor
+  is also specified as part of this suboption.
+
+  For example, the following option adds a drive and monitor to the remote
+  process:
+  -remote rid=0,exec="qemu-scsi-dev",command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait"
Quoted 8 lines

docs/qemu-multiprocess.txt line 58

Quoted 4 lines
docs/qemu-multiprocess.txt new file +4 -0
+
+  Note: There's an issue with this "command" sub-option which we are in the
+  process of fixing. To work around this issue, it requires additional
+  "comma" characters as illustrated above, and in the example below.

command= (which could be called args= for clarity) will be difficult to use not just because of comma escaping but also because of double-quote escaping. How do you pass a command-line argument that contains spaces?

Yes, this is not great. And spaces are the problem at the moment. I am looking if the -object has some properties that can allow for arbitrary strings. Maybe such as data for "secret" object would do?

Elena

#105 lore raw

Re: [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess

In reply to Stefan Hajnoczi
Quoted 34 lines · Stefan Hajnoczi
Quoted 26 lines · Jagannathan Raman

From: John G Johnson <[email protected]>

---
 docs/devel/index.rst             |    1 +
 docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1103 insertions(+)
 create mode 100644 docs/devel/qemu-multiprocess.rst
docs/devel/index.rst +1 -0
index 4dc2ca8..1a95871 100644
@@ -25,3 +25,4 @@ Contents:
    tcg-plugins
    bitops
    reset
+   multi-process
docs/devel/qemu-multiprocess.rst new file +0 -0
new file mode 100644
index 0000000..477e246

docs/devel/qemu-multiprocess.rst line 1

Quoted 1 line
docs/devel/qemu-multiprocess.rst new file +1 -0
@@ -0,0 +1,1102 @@
+Disaggregating QEMU

Please revise this document and the patch series to use consistent terminology. At least "qemu-multiprocess.rst", "--enable-mpqemu", and "disaggregated QEMU" are used to describe this feature (there are probably more, I have only looked at 2 patches so far).

Quoted 6 lines

It's confusing for someone who stumbles across one of these terms and then has to figure out that we're talking about the same thing when encountering other terms later on.

Please use a single name and use it consistently.

Thanks Stefan, will work on this.

Quoted 17 lines

docs/devel/qemu-multiprocess.rst line 11

Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10 -0
+===================
+
+QEMU is often used as the hypervisor for virtual machines running in the
+Oracle cloud. Since one of the advantages of cloud computing is the
+ability to run many VMs from different tenants in the same cloud
+infrastructure, a guest that compromised its hypervisor could
+potentially use the hypervisor's access privileges to access data it is
+not authorized for.
+
+QEMU can be susceptible to security attack because it is a large,

s/attack/attacks/

docs/devel/qemu-multiprocess.rst line 13

Quoted 2 lines
docs/devel/qemu-multiprocess.rst new file +2 -0
+monolithic program that provides many features to the VMs it services.
+Many of these feature can be configured out of QEMU, but even a reduced

s/feature/features/

#113 lore raw
In reply to Jagannathan Raman
Quoted 28 lines · Jagannathan Raman

Hello

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] and RFC v4 [6].

John & Elena presented the status of this project in KVM Forum 2019. We appreciate the in-person and email feedback we received to improve this patchset. We also received valuable feedback and direction on future improvements from the bi-weekly KVM community conference. We have incorporated all the feedback in the current version of the series, v5.

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.

Quoted 8 lines

We are planning on making the following improvements in the future to the experimental Qemu multi-process:
- Asynchronous communication channel;
- Performance improvements;
- Libvirt support;
- Enforcement of security policies and privileges control;

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

There seem to be quite a few CI failures with this series applied:

https://travis-ci.org/stsquad/qemu/builds/656432858
https://app.shippable.com/github/stsquad/qemu/runs/1275/summary/console
https://gitlab.com/stsquad/qemu/pipelines/122030403
https://cirrus-ci.com/build/4577637150490624

Signature · 1 line
Alex Bennée
author
#114 lore raw
Quoted 38 lines · Alex Bennée
Quoted 35 lines · Jagannathan Raman

Hello

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] and RFC v4 [6].

John & Elena presented the status of this project in KVM Forum 2019. We appreciate the in-person and email feedback we received to improve this patchset. We also received valuable feedback and direction on future improvements from the bi-weekly KVM community conference. We have incorporated all the feedback in the current version of the series, v5.

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 are planning on making the following improvements in the future to the experimental Qemu multi-process:
- Asynchronous communication channel;
- Performance improvements;
- Libvirt support;
- Enforcement of security policies and privileges control;

Quoted 8 lines
Quoted 1 line

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

There seem to be quite a few CI failures with this series applied:

   https://travis-ci.org/stsquad/qemu/builds/656432858
   https://app.shippable.com/github/stsquad/qemu/runs/1275/summary/console
   https://gitlab.com/stsquad/qemu/pipelines/122030403
   https://cirrus-ci.com/build/4577637150490624

Hi Alex,

Thanks for pointing it out.

"Patchew" also identified some errors which we are working on fixing for the next version. Patchew summarized the errors in the following page:
https://patchew.org/QEMU/[email protected]/

To confirm we're compliant with Patchew, we are running docker tests before sending the patches for review next time around.

We'll use the following wiki to trigger "travis-ci" tests before pushing the branch for review next time around:
https://wiki.qemu.org/Testing/CI/Travis#Testing_Changes_to_Travis

Are shippable, stsquad & cirrus-ci redundant if travis-ci & docker tests pass?

Thank you very much!
--
Jag

Quoted 1 line
#115 lore raw
Quoted 56 lines · Jag Raman
Quoted 37 lines · Alex Bennée
Quoted 35 lines · Jagannathan Raman

Hello
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] and RFC v4 [6].

John & Elena presented the status of this project in KVM Forum 2019. We appreciate the in-person and email feedback we received to improve this patchset. We also received valuable feedback and direction on future improvements from the bi-weekly KVM community conference. We have incorporated all the feedback in the current version of the series, v5.

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 are planning on making the following improvements in the future to the experimental Qemu multi-process:
- Asynchronous communication channel;
- Performance improvements;
- Libvirt support;
- Enforcement of security policies and privileges control;

Quoted 6 lines
Quoted 1 line

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

There seem to be quite a few CI failures with this series applied:

   https://travis-ci.org/stsquad/qemu/builds/656432858
   https://app.shippable.com/github/stsquad/qemu/runs/1275/summary/console
   https://gitlab.com/stsquad/qemu/pipelines/122030403
   https://cirrus-ci.com/build/4577637150490624

Hi Alex,

Thanks for pointing it out.

"Patchew" also identified some errors which we are working on fixing for the next version. Patchew summarized the errors in the following page:
https://patchew.org/QEMU/[email protected]/

To confirm we're compliant with Patchew, we are running docker tests before sending the patches for review next time around.

Quoted 6 lines

We'll use the following wiki to trigger "travis-ci" tests before pushing the branch for review next time around:
https://wiki.qemu.org/Testing/CI/Travis#Testing_Changes_to_Travis

Are shippable, stsquad & cirrus-ci redundant if travis-ci & docker tests

stsquad is just my user account, hopefully I'm not redundant ;-)

They all test slightly different things but you should be able to replicate the tests locally.

Travis basically tests a bunch of different configuration setups on mostly x86 hardware. Unless it's a weird library interaction issue this should replicate in your normal build environment.

Shippable are cross compile tests. They use the existing docker infrastructure to cross compile for various target architectures. See "make docker" and the notes in docs/devel/testing.rst.

CirrusCI tests MacOS and FreeBSD builds. You can build on the BSD's yourself, see "make vm-help". MacOSX is trickier unless you have a Mac yourself of course.

Quoted 3 lines

pass?

Thank you very much!

Signature · 1 line
Alex Bennée
author
#116 lore raw
Quoted 59 lines · Alex Bennée
Quoted 56 lines · Jag Raman
Quoted 37 lines · Alex Bennée
Quoted 35 lines · Jagannathan Raman

Hello
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] and RFC v4 [6].

John & Elena presented the status of this project in KVM Forum 2019. We appreciate the in-person and email feedback we received to improve this patchset. We also received valuable feedback and direction on future improvements from the bi-weekly KVM community conference. We have incorporated all the feedback in the current version of the series, v5.

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 are planning on making the following improvements in the future to the experimental Qemu multi-process:
- Asynchronous communication channel;
- Performance improvements;
- Libvirt support;
- Enforcement of security policies and privileges control;

Quoted 6 lines
Quoted 1 line

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

There seem to be quite a few CI failures with this series applied:

    https://travis-ci.org/stsquad/qemu/builds/656432858
    https://app.shippable.com/github/stsquad/qemu/runs/1275/summary/console
    https://gitlab.com/stsquad/qemu/pipelines/122030403
    https://cirrus-ci.com/build/4577637150490624

Hi Alex,

Thanks for pointing it out.

"Patchew" also identified some errors which we are working on fixing for the next version. Patchew summarized the errors in the following page:
https://patchew.org/QEMU/[email protected]/

To confirm we're compliant with Patchew, we are running docker tests before sending the patches for review next time around.

Quoted 8 lines
Quoted 6 lines

We'll use the following wiki to trigger "travis-ci" tests before pushing the branch for review next time around:
https://wiki.qemu.org/Testing/CI/Travis#Testing_Changes_to_Travis

Are shippable, stsquad & cirrus-ci redundant if travis-ci & docker tests

stsquad is just my user account, hopefully I'm not redundant ;-)

Sorry I didn't realize it's your account. :)

Quoted 7 lines

They all test slightly different things but you should be able to replicate the tests locally.

Travis basically tests a bunch of different configuration setups on mostly x86 hardware. Unless it's a weird library interaction issue this should replicate in your normal build environment.

We'll run Travis CI also before submitting patches next time. The qemu wiki page for TravisCI says it tests MacOS. So this test should be sufficient to cover MacOS build tests I suppose.

https://wiki.qemu.org/Testing/CI/Travis#Testing_Changes_to_Travis

Quoted 4 lines

Shippable are cross compile tests. They use the existing docker infrastructure to cross compile for various target architectures. See "make docker" and the notes in docs/devel/testing.rst.

We're running these docker tests locally.

Thank you very much!
--
Jag

Quoted 10 lines

CirrusCI tests MacOS and FreeBSD builds. You can build on the BSD's yourself, see "make vm-help". MacOSX is trickier unless you have a Mac yourself of course.

Quoted 3 lines

pass?

Thank you very much!

#27 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Jagannathan Raman

typo "multi" in patch subject.

Quoted 37 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +14 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
 
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+

hw/proxy/qemu-proxy.c line 45

Quoted 10 lines
hw/proxy/qemu-proxy.c +10 -0
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Quoted 109 lines
hw/proxy/qemu-proxy.c +29 -15
+
+    return argc;
+}
+
  static int remote_spawn(PCIProxyDev *pdev, const char *opts,
                          const char *exec_name, Error **errp)
  {
-    char *args[3];
      pid_t rpid;
      int fd[2] = {-1, -1};
      Error *local_error = NULL;
+    char *argv[64];
+    int argc = 0;
+    char *sfd;
+    char *exec_dir;
      int rc = -EINVAL;
 
      if (pdev->managed) {
          /* Child is forked by external program (such as libvirt). */
          error_setg(errp, "Remote processed is managed and launched by external program");
-        return -1;
+        return rc;
      }
 
      if (!exec_name) {
@@ -41,32 +72,38 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts,
 
      if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
          error_setg(errp, "Unable to create unix socket.");
-        return -1;
+        return rc;
      }
+    exec_dir = g_strdup_printf("%s/%s", qemu_get_exec_dir(), exec_name);
+    argc = add_argv(exec_dir, argv, argc);
+    sfd = g_strdup_printf("%d", fd[1]);
+    argc = add_argv(sfd, argv, argc);
+    argc = make_argv((char *)opts, argv, argc);
+
      /* TODO: Restrict the forked process' permissions and capabilities. */
      rpid = qemu_fork(&local_error);
 
      if (rpid == -1) {
          error_setg(errp, "Unable to spawn emulation program.");
          close(fd[0]);
-        close(fd[1]);
-        return -1;
+        goto fail;
      }
 
      if (rpid == 0) {
          close(fd[0]);
 
-        args[0] = g_strdup(exec_name);
-        args[1] = g_strdup_printf("%d", fd[1]);
-        args[2] = NULL;
-        execvp(args[0], (char *const *)args);
+        rc = execv(argv[0], (char *const *)argv);
          exit(1);
      }
      pdev->remote_pid = rpid;
+    pdev->socket = fd[0];
+
+    rc = 0;
 
+fail:
      close(fd[1]);
 
-    return 0;
+    return rc;
  }
 
  static int get_proxy_sock(PCIDevice *dev)
@@ -177,16 +214,17 @@ static void pci_proxy_dev_register_types(void)
  type_init(pci_proxy_dev_register_types)
 
  static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
-                       Error **errp)
+                       bool need_spawn, Error **errp)
  {
      PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
      Error *local_error = NULL;
 
      if (!pdev->managed) {
-        if (command) {
-            remote_spawn(pdev, command, exec_name, &local_error);
-        } else {
-            return;
+        if (need_spawn) {
+            if (remote_spawn(pdev, command, exec_name, &local_error)) {
+                error_propagate(errp, local_error);
+                return;
+            }
          }
      } else {
          pdev->remote_pid = atoi(pdev->rid);
include/hw/proxy/qemu-proxy.h +1 -1
index 28b0114..29fa2e9 100644
@@ -39,7 +39,7 @@ typedef struct PCIProxyDev {
 
      void (*proxy_ready) (PCIDevice *dev);
      void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
-                        Error **errp);
+                        bool need_spawn, Error **errp);
 
  } PCIProxyDev;
 
#28 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

Quoted 42 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Quoted 39 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 8 lines

hw/proxy/qemu-proxy.c line 45

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

g_shell_parse_argv() perhaps

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

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 :|
author
#99 lore raw

Re: [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote

In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi
Quoted 4 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add support to allow multiple devices to be configured in the remote process

This patch allows multiple devices to be addressed over a single UNIX domain socket. This could be a scalability/performance bottleneck because an SMP guest can only talk to 1 device at a time.

Quoted 8 lines

This approach doesn't address the qemu-storage-daemon use case where one device emulation process provides devices to multiple guests. Multiple UNIX domain sockets are needed for that.

Is multiplexing multiple devices over a single connection is a desirable feature? The alternative of one UNIX domain socket per device instance seems more practical to me because it should perform better and solves the qemu-storage-daemon use case.

Hi Stefan,

We will implement a separate communication channel for each device in the remote process, in the next series.

Thanks!
--
Jag

Quoted 1 line
#29 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Daniel P. Berrangé
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 45

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

Thanks!

Elena

Quoted 8 lines

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 :|
Reviewed-by on v5 1/50
#2 lore raw

Re: [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset

In reply to Jagannathan Raman
Quoted 8 lines · * Jagannathan Raman ([email protected]) wrote:

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.
This will be needed for the following patches.

This looks reasonable to me, so :

but can I suggest you take simple things like this and split them out into a separate little series; I think people would probably take them even though the current users have a 0 offset.

Dave

Quoted 147 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 c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     Error *err = NULL;
@@ -1893,7 +1894,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");
@@ -2322,7 +2324,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;
@@ -2367,7 +2369,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;
@@ -2397,7 +2400,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 5e59a3d..1b9f489 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 e786266..4f57985 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 aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,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 27dcccd..a28f702 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 5a291cc..bd221dd 100644
@@ -205,7 +205,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
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#15 lore raw

Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints

In reply to Jagannathan Raman
Quoted 47 lines · * Jagannathan Raman ([email protected]) wrote:

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         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                               mpqemu_link_callback callback);
 void mpqemu_start_coms(MPQemuLinkState *s);
 
+#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 +4 -0
index bac120b..73b7032 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"
@@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
     return rc;
 }
 
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };

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

Quoted 10 lines
io/mpqemu-link.c +10 -0
+    uint64_t val;
+    int ret;
+
+    ret = poll(&pfd, 1, 1000);
+
+    switch (ret) {
+    case 0:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+        /* TODO: Kick-off error recovery */
+        return ULLONG_MAX;

Shouldn't these be UINT64_MAX?

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

Quoted 13 lines
io/mpqemu-link.c +13 -0
+    case -1:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+                      strerror(errno));
+        return ULLONG_MAX;
+    default:
+        if (read(efd, &val, sizeof(val)) == -1) {
+            qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                          strerror(errno));
+            return ULLONG_MAX;
+        }
+    }
+
+    val = (val == ULLONG_MAX) ? val : (val - 1);

Can you explain what's going on there??

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

Quoted 8 lines
io/mpqemu-link.c +8 -0
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == ULLONG_MAX) ? val : (val + 1);
+
+    if (write(efd, &val, sizeof(val)) == -1) {

I'd actually check the write/read's are returning sizeof(val) - they can on a bad day return 0 or send only a few bytes; in theory?

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        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
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#36 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Jagannathan Raman
Quoted 26 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

 hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
 include/hw/proxy/qemu-proxy.h |  2 +-
 2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +3 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;

...

Quoted 4 lines
hw/proxy/qemu-proxy.c +4 -0
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;

.....

hw/proxy/qemu-proxy.c line 56

Quoted 9 lines
hw/proxy/qemu-proxy.c +2 -1
+
 static int remote_spawn(PCIProxyDev *pdev, const char *opts,
                         const char *exec_name, Error **errp)
 {
-    char *args[3];
     pid_t rpid;
     int fd[2] = {-1, -1};
     Error *local_error = NULL;
+    char *argv[64];

Magic '64' in a lot of places; that should be one constant somewhere (if it's actually needed).

Dave

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#22 lore raw

Re: [PATCH v5 12/50] multi-process: remote process initialization

In reply to Jagannathan Raman
Quoted 56 lines · * Jagannathan Raman ([email protected]) wrote:

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.

---
v4 -> v5:
- We checked if we could use functions already defined in util/main-loop.c instead of using g_main_loop_run. However, we couldn't find a suitable function that's generic enough to do this. All of them have emulator code embedded in them which is not used by the remote process. We are therefore not making any change to this patch

 remote/remote-main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
remote/remote-main.c +21 -0
index ecf30e0..56315cd 100644
@@ -12,6 +12,7 @@
 #include "qemu-common.h"
 
 #include <stdio.h>
+#include <unistd.h>
 
 #include "qemu/module.h"
 #include "remote/pcihost.h"
@@ -19,12 +20,96 @@
 #include "hw/boards.h"
 #include "hw/qdev-core.h"
 #include "qemu/main-loop.h"
+#include "remote/memory.h"
+#include "io/mpqemu-link.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "qemu-common.h"
+#include "hw/pci/pci.h"
+#include "qemu/thread.h"
+#include "qemu/main-loop.h"
+#include "qemu/config-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "exec/ramlist.h"
+
+static MPQemuLinkState *mpqemu_link;
+PCIDevice *remote_pci_dev;
+
+static void process_msg(GIOCondition cond, MPQemuChannel *chan)
+{
+    MPQemuMsg *msg = NULL;

remote/remote-main.c line 52

Quoted 10 lines
remote/remote-main.c +10 -0
+    Error *err = NULL;
+
+    if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
+        goto finalize_loop;
+    }
+
+    msg = g_malloc0(sizeof(MPQemuMsg));
+
+    if (mpqemu_msg_recv(msg, chan) < 0) {
+        error_setg(&err, "Failed to receive message");

Please give error messages more context, e.g. the device or process name or something like that so that; it helps when we get a user reporting a crash and they report 'Unknown command' in their log, but then we have to figure out where to point them.

Quoted 38 lines
remote/remote-main.c +33 -0
+        goto finalize_loop;
+    }
+
+    switch (msg->cmd) {
+    case INIT:
+        break;
+    case PCI_CONFIG_WRITE:
+        break;
+    case PCI_CONFIG_READ:
+        break;
+    default:
+        error_setg(&err, "Unknown command");
+        goto finalize_loop;
+    }
+
+    g_free(msg->data2);
+    g_free(msg);
+
+    return;
+
+finalize_loop:
+    if (err) {
+        error_report_err(err);
+    }
+    g_free(msg);
+    mpqemu_link_finalize(mpqemu_link);
+    mpqemu_link = NULL;
+}
 
 int main(int argc, char *argv[])
 {
+    Error *err = NULL;
+
     module_call_init(MODULE_INIT_QOM);
 
+    bdrv_init_with_whitelist();
+
+    if (qemu_init_main_loop(&err)) {

remote/remote-main.c line 100

Quoted 10 lines
remote/remote-main.c +10 -0
+        error_report_err(err);
+        return -EBUSY;
+    }
+
+    qemu_init_cpu_loop();
+
+    page_size_init();
+
+    qemu_mutex_init(&ram_list.mutex);
+

So these are some subset of the things from qemu_init; I guess we'll have to be careful when we add stuff to vl.c to think what should also be added here.

Dave

Quoted 18 lines
remote/remote-main.c +11 -0
     current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
 
+    mpqemu_link = mpqemu_link_create();
+    if (!mpqemu_link) {
+        printf("Could not create MPQemu link\n");
+        return -1;
+    }
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO);
+    mpqemu_link_set_callback(mpqemu_link, process_msg);
+
+    mpqemu_start_coms(mpqemu_link);
+
     return 0;
 }
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#38 lore raw

Re: [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints

In reply to Jagannathan Raman
Quoted 211 lines · * Jagannathan Raman ([email protected]) wrote:

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         | 65 ++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
 include/io/mpqemu-link.h      | 12 +++++++
 remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
 }
+
+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->com);
+
+    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 +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
 #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;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
     PCIDevice parent_dev;
 
     MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                         bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
 typedef struct PCIProxyDevClass {
     PCIDeviceClass parent_class;
@@ -51,4 +64,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 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
  * 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.
@@ -47,6 +49,8 @@ typedef enum {
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
     SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
     MAX,
 } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
 } sync_sysmem_msg_t;
 
 typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -77,6 +88,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];
remote/remote-main.c +19 -0
index 7b4cf2f..acd8daf 100644
@@ -33,6 +33,7 @@
 #include "sysemu/sysemu.h"
 #include "block/block.h"
 #include "exec/ramlist.h"
+#include "exec/memattrs.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -63,6 +64,66 @@ static void process_config_read(MPQemuMsg *msg)
     PUT_REMOTE_WAIT(wait);
 }
 
+/* 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;
+
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&bar_access->val, bar_access->size, true);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space write operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+    }
+}
+
+static void process_bar_read(MPQemuMsg *msg, Error **errp)

remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 94

Quoted 10 lines
remote/remote-main.c +10 -0
+{
+    bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    AddressSpace *as;
+    int wait = msg->fds[0];
+    MemTxResult res;
+    uint64_t val = 0;
+
+    as = bar_access->memory ? &address_space_memory : &address_space_io;
+
+    assert(bar_access->size <= sizeof(uint64_t));

Note you don't have that check on the write function above.
Do you actually want something like:
assert(is_power_of_2(bar_access->size) && bar_access->size <= sizeof(uint64_t));

remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 106

Quoted 11 lines
remote/remote-main.c +11 -0
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&val, bar_access->size, false);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space read operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+        val = (uint64_t)-1;
+        goto fail;
+    }
+
+    switch (bar_access->size) {

No case 8 ?

Dave

Quoted 45 lines
remote/remote-main.c +32 -0
+    case 4:
+        val = *((uint32_t *)&val);
+        break;
+    case 2:
+        val = *((uint16_t *)&val);
+        break;
+    case 1:
+        val = *((uint8_t *)&val);
+        break;
+    default:
+        error_setg(errp, "Invalid PCI BAR read size");
+        return;
+    }
+
+fail:
+    notify_proxy(wait, val);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -88,6 +149,18 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case PCI_CONFIG_READ:
         process_config_read(msg);
         break;
+    case BAR_WRITE:
+        process_bar_write(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
+    case BAR_READ:
+        process_bar_read(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#30 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Elena Ufimtseva
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 45

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

I understand this is probably more complex, because we're having to pass this across processes, via QemuOpts IIUC, but I still believe it is important to have this data kept in array format if at all practical.

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 :|
#41 lore raw

Re: [PATCH v5 16/50] multi-process: Synchronize remote memory

In reply to Jagannathan Raman
Quoted 90 lines · * Jagannathan Raman ([email protected]) wrote:

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.

TODO: No need to create object for remote memory listener.

---
 Makefile.target                |   3 +
 hw/proxy/memory-sync.c         | 212 +++++++++++++++++++++++++++++++++++++++++
 hw/proxy/qemu-proxy.c          |   5 +
 include/hw/proxy/memory-sync.h |  37 +++++++
 include/hw/proxy/qemu-proxy.h  |   5 +
 remote/remote-main.c           |  11 +++
 6 files changed, 273 insertions(+)
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 include/hw/proxy/memory-sync.h
Makefile.target +3 -0
index cfd36c1..271d883 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 +47 -0
new file mode 100644
index 0000000..3edbb19
@@ -0,0 +1,212 @@
+/*
+ * 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>
+
+#include "qemu/osdep.h"
+#include "qemu/compiler.h"
+#include "qemu/int128.h"
+#include "qemu/range.h"
+#include "exec/memory.h"
+#include "exec/cpu-common.h"
+#include "cpu.h"
+#include "exec/ram_addr.h"
+#include "exec/address-spaces.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
+
+static const TypeInfo remote_mem_sync_type_info = {
+    .name          = TYPE_MEMORY_LISTENER,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(RemoteMemSync),
+};
+
+static void remote_mem_sync_register_types(void)
+{
+    type_register_static(&remote_mem_sync_type_info);
+}
+
+type_init(remote_mem_sync_register_types)
+
+static void proxy_ml_begin(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    int mrs;
+
+    for (mrs = 0; mrs < sync->n_mr_sections; mrs++) {
+        memory_region_unref(sync->mr_sections[mrs].mr);
+    }
+
+    g_free(sync->mr_sections);

hw/proxy/memory-sync.c line 57

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    sync->mr_sections = NULL;
+    sync->n_mr_sections = 0;
+}
+
+static int get_fd_from_hostaddr(uint64_t host, ram_addr_t *offset)
+{
+    MemoryRegion *mr;
+    ram_addr_t off;
+
+    mr = memory_region_from_host((void *)(uintptr_t)host, &off);

Do you need to just check we found an 'mr' ?

Quoted 9 lines
hw/proxy/memory-sync.c new file +9 -0
+    if (offset) {
+        *offset = off;
+    }
+
+    return memory_region_get_fd(mr);
+}
+
+static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size)
+{

hw/proxy/memory-sync.c line 77

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    bool merge;
+    int fd1, fd2;
+
+    fd1 = get_fd_from_hostaddr(host, NULL);
+
+    fd2 = get_fd_from_hostaddr(prev_host, NULL);
+
+    merge = (fd1 == fd2);
+
+    merge &= ((prev_host + size) == host);

It's interesting; I think the vhost code checks that the two mr's are the same where you are checking for the same underlying fd - but I think that's OK.
(I wonder if we need to check offset's within the fd's match up when they're merged - since you added that offset feature in an earlier patch?
That would also need checking in vhost_region_add_section)

Quoted 22 lines
hw/proxy/memory-sync.c new file +22 -0
+    return merge;
+}
+
+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) &&
+          !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;

hw/proxy/memory-sync.c line 110

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) +
+               section->offset_within_region;
+
+    if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) {
+        return;
+    }
+
+    mrs_host = mrs_host & ~(mrs_page - 1);
+    mrs_gpa = mrs_gpa & ~(mrs_page - 1);
+    mrs_size = ROUND_UP(mrs_size, mrs_page);

OK, just note the more complex code in vhost_region_add_section for page aligning regions that are needed for postcopy; I think that would be the same if you wanted to do postcopy with remote processes.

Quoted 4 lines
hw/proxy/memory-sync.c new file +4 -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);

hw/proxy/memory-sync.c line 125

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+        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);
+
+        if (mrs_gpa <= (prev_gpa_end + 1)) {
+            if (mrs_gpa < prev_gpa_start) {
+                assert(0);
+            }

g_assert(mrs_gpa < prev_gpa_start);

Quoted 14 lines
hw/proxy/memory-sync.c new file +14 -0
+            if ((section->mr == prev_sec->mr) &&
+                proxy_mrs_can_merge(mrs_host, prev_host_start,
+                                    (mrs_gpa - prev_gpa_start))) {
+                uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size);
+                need_add = false;
+                prev_sec->offset_within_address_space =
+                    MIN(prev_gpa_start, mrs_gpa);
+                prev_sec->offset_within_region =
+                    MIN(prev_host_start, mrs_host) -
+                    (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr);
+                prev_sec->size = int128_make64(max_end - MIN(prev_host_start,
+                                                             mrs_host));
+            }
+        }

hw/proxy/memory-sync.c line 150

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    }
+
+    if (need_add) {
+        ++sync->n_mr_sections;
+        sync->mr_sections = g_renew(MemoryRegionSection, sync->mr_sections,
+                                    sync->n_mr_sections);
+        sync->mr_sections[sync->n_mr_sections - 1] = *section;
+        sync->mr_sections[sync->n_mr_sections - 1].fv = NULL;
+        memory_region_ref(section->mr);
+    }

I'd add some tracing in this function; it's a nightmare to debug when it does something unexpected.

Quoted 17 lines
hw/proxy/memory-sync.c new file +17 -0
+}
+
+static void proxy_ml_commit(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    MPQemuMsg msg;
+    MemoryRegionSection section;
+    ram_addr_t offset;
+    uintptr_t host_addr;
+    int region;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.cmd = SYNC_SYSMEM;
+    msg.bytestream = 0;
+    msg.num_fds = sync->n_mr_sections;
+    msg.size = sizeof(msg.data1);

hw/proxy/memory-sync.c line 177

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    assert(msg.num_fds <= REMOTE_MAX_FDS);
+
+    for (region = 0; region < sync->n_mr_sections; region++) {
+        section = sync->mr_sections[region];
+        msg.data1.sync_sysmem.gpas[region] =
+            section.offset_within_address_space;
+        msg.data1.sync_sysmem.sizes[region] = int128_get64(section.size);
+        host_addr = (uintptr_t)memory_region_get_ram_ptr(section.mr) +
+                    section.offset_within_region;
+        msg.fds[region] = get_fd_from_hostaddr(host_addr, &offset);

Since you already have section.mr you cna use memory_region_get_fd.

Quoted 146 lines
hw/proxy/memory-sync.c new file +35 -0
+        msg.data1.sync_sysmem.offsets[region] = offset;
+    }
+    mpqemu_msg_send(&msg, sync->mpqemu_link->com);
+}
+
+void deconfigure_memory_sync(RemoteMemSync *sync)
+{
+    memory_listener_unregister(&sync->listener);
+}
+
+/*
+ * TODO: Memory Sync need not be instantianted once per every proxy device.
+ *       All remote devices are going to get the exact same updates at the
+ *       same time. It therefore makes sense to have a broadcast model.
+ *
+ *       Broadcast model would involve running the MemorySync object in a
+ *       thread. MemorySync would contain a list of mpqemu-link objects
+ *       that need notification. proxy_ml_commit() could send the same
+ *       message to all the links at the same time.
+ */
+void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link)
+{
+    sync->n_mr_sections = 0;
+    sync->mr_sections = NULL;
+
+    sync->mpqemu_link = mpqemu_link;
+
+    sync->listener.begin = proxy_ml_begin;
+    sync->listener.commit = proxy_ml_commit;
+    sync->listener.region_add = proxy_ml_region_addnop;
+    sync->listener.region_nop = proxy_ml_region_addnop;
+    sync->listener.priority = 10;
+
+    memory_listener_register(&sync->listener, &address_space_memory);
+}
hw/proxy/qemu-proxy.c +5 -0
index b17d9bb..d3a9d38 100644
@@ -16,6 +16,8 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qstring.h"
 #include "hw/proxy/qemu-proxy.h"
+#include "hw/proxy/memory-sync.h"
+#include "qom/object.h"
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
@@ -243,6 +245,8 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
 
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
+
+    configure_memory_sync(pdev->sync, pdev->mpqemu_link);
 }
 
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
@@ -261,6 +265,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->set_proxy_sock = set_proxy_sock;
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
+    dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
 }
 
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/memory-sync.h new file +37 -0
new file mode 100644
index 0000000..d8329c9
@@ -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 +5 -0
index 44e370e..c93ffe3 100644
@@ -10,6 +10,7 @@
 #define QEMU_PROXY_H
 
 #include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -37,8 +38,12 @@ extern const MemoryRegionOps proxy_default_ops;
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
     MPQemuLinkState *mpqemu_link;
 
+    RemoteMemSync *sync;
     pid_t remote_pid;
     int socket;
 
remote/remote-main.c +1 -0
index acd8daf..9512a3b 100644
@@ -34,6 +34,7 @@
 #include "block/block.h"
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
+#include "exec/address-spaces.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;

remote/remote-main.c static void process_msg(GIOCondition cond, MPQemuChannel *chan) · line 168

Quoted 7 lines
remote/remote-main.c +4 -0
@@ -161,6 +162,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             goto finalize_loop;
         }
         break;
+    case SYNC_SYSMEM:
+        /*
+         * TODO: ensure no active DMA is happening when
+         * sysmem is being updated

In practice this turns out to be hard!

Dave

Quoted 12 lines
remote/remote-main.c +6 -0
+         */
+        remote_sysmem_reconfig(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#77 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

In reply to Jagannathan Raman
Quoted 68 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
 Makefile.objs           |  4 +++-
 Makefile.target         |  1 +
 migration/Makefile.objs | 13 ++++++++++++-
 net/Makefile.objs       |  2 ++
 softmmu/vl.c            |  2 --
 stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 stubs/net-stub.c        | 21 +++++++++++++++++++++
 stubs/qapi-misc.c       |  2 ++
 stubs/replay.c          |  8 ++++++++
 stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
 vl-parse.c              |  3 +++
 11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
 
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
 common-obj-$(CONFIG_LINUX) += fsdev/
 
 common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
 
 #######################################################################
 # qapi
-
 common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
 remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
 remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
 remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
 all-remote-pci-obj-y += exec-vary.o
 all-remote-pci-obj-y += ioport.o
 all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
 endif
 
 remote-pci-obj-y :=
migration/Makefile.objs +2 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 10 lines
migration/Makefile.objs +10 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Dave

Quoted 220 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
 vde.o-libs = $(VDE_LIBS)
 
 common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
 bool enable_cpu_pm = false;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
 bool boot_strict;
 uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
 bool wakeup_suspend_enabled;
 
 int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
 #include "qapi/qapi-types-migration.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
 
 MigrationInfo *qmp_query_migrate(Error **errp)
 {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
 
     return NULL;
 }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
 #include "qapi/qapi-commands-net.h"
 #include "qapi/qapi-commands-rocker.h"
 
+#pragma weak qmp_announce_self
+
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                  NetClientDriver type, int max)
 {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
 {
     qemu_debug_assert(0);
 }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
 #include "./qapi/qapi-types-dump.h"
 #include "qapi/qapi-commands-dump.h"
 
+#pragma weak qmp_xen_load_devices_state
+
 void qmp_dump_guest_memory(bool paging, const char *file,
                            bool has_detach, bool detach,
                            bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "sysemu/replay.h"
 
 ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
 void replay_add_blocker(Error *reason)
 {
 }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
 #include "disas/disas.h"
 #include "audio/audio.h"
 
+#pragma weak qemu_add_exit_notifier
+
 bool tcg_allowed;
 bool xen_allowed;
 bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 
     return -1;
 }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
 
 #include "vl.h"
 
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
 /***********************************************************/
 /* QEMU Block devices */
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#31 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Daniel P. Berrangé
Quoted 81 lines · Daniel P. Berrangé
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 45

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

Quoted 4 lines

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

Hi Daniel

Thank you for explanation.
At this point there is no intermediate stage as we grab the arguments as a raw string from the command line option -remote:

-remote rid=8,exec=qemu-scsi-dev,command="-drive id=drive_image2,,file=/root/remote-process-disk.img"

So the command="" string is being later parsed into the array and remote process gets spawned with the "char **argv".

Stefan expressed his concern that its not convenient to use due to the double escaping commas, spaces, quotes and we do agree with that. We were seeking an advice on what is the better approach.

Few things we discussed internally is to have the remote drive command line options passed over by messages or using QMP.

Thank you!
Elena

Quoted 11 lines

I understand this is probably more complex, because we're having to pass this across processes, via QemuOpts IIUC, but I still believe it is important to have this data kept in array format if at all practical.

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 :|
#32 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

Quoted 92 lines · Elena Ufimtseva
Quoted 81 lines · Daniel P. Berrangé
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 45

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

Quoted 4 lines

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

Hi Daniel

Thank you for explanation.
At this point there is no intermediate stage as we grab the arguments as a raw string from the command line option -remote:

Quoted 8 lines

-remote rid=8,exec=qemu-scsi-dev,command="-drive id=drive_image2,,file=/root/remote-process-disk.img"

So the command="" string is being later parsed into the array and remote process gets spawned with the "char **argv".

Stefan expressed his concern that its not convenient to use due to the double escaping commas, spaces, quotes and we do agree with that. We were seeking an advice on what is the better approach.

I've not looked closely enough to understand the range of different options we need to be able to pass to the remote QEMU ? Is it just "-drive" options, or can it be absolutely any QEMU option ?

If it is just -drive, then I could imagine a -remote-drive option such that we end up with with a set of args

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -remote-drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -remote-drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -remote-drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -remote-drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

And this gets turned into 2 execs:

   qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img
   
   qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

Or maybe instead of having a '-remote-drive' arg, we can make the '-drive' arg take an optional "rid" attribute to associate it with the remote process

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

When 'rid' is seen, instead of creating a local block backend, the args get used for the remote process.

This would have the nice user behaviour that you can take an existing QEMU command line, and turn it into a multi-process command line simply by adding the '-remote ...' arg, and adding 'rid=NN' to each -drive. Nothing else about your existing command line need change.

Quoted 2 lines

Few things we discussed internally is to have the remote drive command line options passed over by messages or using QMP.

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 :|
author
#3 lore raw

Re: [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset

In reply to Dr. David Alan Gilbert
Quoted 10 lines · Dr. David Alan Gilbert
Quoted 8 lines · * Jagannathan Raman ([email protected]) wrote:

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.
This will be needed for the following patches.

Quoted 7 lines

This looks reasonable to me, so :

but can I suggest you take simple things like this and split them out into a separate little series; I think people would probably take them even though the current users have a 0 offset.

Thanks Dave! We'll split these out of the series and integrate them first.

--
Jag

Quoted 154 lines

Dave

Quoted 147 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 c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                              ram_addr_t memory,
                              int fd,
                              bool truncate,
+                            off_t offset,
                              Error **errp)
  {
      Error *err = NULL;
@@ -1893,7 +1894,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");
@@ -2322,7 +2324,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;
@@ -2367,7 +2369,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;
@@ -2397,7 +2400,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 5e59a3d..1b9f489 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 e786266..4f57985 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 aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,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 27dcccd..a28f702 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 5a291cc..bd221dd 100644
@@ -205,7 +205,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
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#16 lore raw

Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints

In reply to Dr. David Alan Gilbert
Quoted 45 lines · Dr. David Alan Gilbert
Quoted 44 lines · * Jagannathan Raman ([email protected]) wrote:

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         | 41 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                                mpqemu_link_callback callback);
  void mpqemu_start_coms(MPQemuLinkState *s);
 
+#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 +1 -0
index bac120b..73b7032 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"
@@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
      return rc;
  }
 
Quoted 15 lines

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

Quoted 13 lines
io/mpqemu-link.c +13 -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);
+
+    switch (ret) {
+    case 0:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+        /* TODO: Kick-off error recovery */
+        return ULLONG_MAX;

Shouldn't these be UINT64_MAX?

Sure, we'll change these to UINT64_MAX.

Quoted 15 lines
Quoted 4 lines
io/mpqemu-link.c +3 -0
+    case -1:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+                      strerror(errno));

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

Quoted 10 lines
io/mpqemu-link.c +10 -0
+        return ULLONG_MAX;
+    default:
+        if (read(efd, &val, sizeof(val)) == -1) {
+            qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                          strerror(errno));
+            return ULLONG_MAX;
+        }
+    }
+
+    val = (val == ULLONG_MAX) ? val : (val - 1);
Quoted 1 line

Can you explain what's going on there??

This wait_for_remote() function serves two purposes. This first one is to synchronize QEMU and the remote process. Secondly, it allows the remote process to return a 64-bit value to QEMU. When the remote process has completed the task, it uses the notify_proxy() function to return to QEMU along with a return value.

We have implemented this synchronization mechanism using eventfd, as it's easy to setup. So 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.

--
Jag

Quoted 29 lines

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

Quoted 9 lines
io/mpqemu-link.c +8 -0
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == ULLONG_MAX) ? val : (val + 1);
+
+    if (write(efd, &val, sizeof(val)) == -1) {

I'd actually check the write/read's are returning sizeof(val) - they can on a bad day return 0 or send only a few bytes; in theory?

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        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
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#23 lore raw

Re: [PATCH v5 12/50] multi-process: remote process initialization

In reply to Dr. David Alan Gilbert
Quoted 64 lines · Dr. David Alan Gilbert
Quoted 63 lines · * Jagannathan Raman ([email protected]) wrote:

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.

---
v4 -> v5:
- We checked if we could use functions already defined in util/main-loop.c instead of using g_main_loop_run. However, we couldn't find a suitable function that's generic enough to do this. All of them have emulator code embedded in them which is not used by the remote process. We are therefore not making any change to this patch

  remote/remote-main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 85 insertions(+)
remote/remote-main.c +28 -0
index ecf30e0..56315cd 100644
@@ -12,6 +12,7 @@
  #include "qemu-common.h"
 
  #include <stdio.h>
+#include <unistd.h>
 
  #include "qemu/module.h"
  #include "remote/pcihost.h"
@@ -19,12 +20,96 @@
  #include "hw/boards.h"
  #include "hw/qdev-core.h"
  #include "qemu/main-loop.h"
+#include "remote/memory.h"
+#include "io/mpqemu-link.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "qemu-common.h"
+#include "hw/pci/pci.h"
+#include "qemu/thread.h"
+#include "qemu/main-loop.h"
+#include "qemu/config-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "exec/ramlist.h"
+
+static MPQemuLinkState *mpqemu_link;
+PCIDevice *remote_pci_dev;
+
+static void process_msg(GIOCondition cond, MPQemuChannel *chan)
+{
+    MPQemuMsg *msg = NULL;
+    Error *err = NULL;
+
+    if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
+        goto finalize_loop;
+    }
+
+    msg = g_malloc0(sizeof(MPQemuMsg));
Quoted 8 lines

remote/remote-main.c line 52

Quoted 3 lines
remote/remote-main.c +3 -0
+
+    if (mpqemu_msg_recv(msg, chan) < 0) {
+        error_setg(&err, "Failed to receive message");

Please give error messages more context, e.g. the device or process name or something like that so that; it helps when we get a user reporting a crash and they report 'Unknown command' in their log, but then we have to figure out where to point them.

Ah OK, we'll add the exec name & PID of the QEMU process that spawned this remote process in the error messages.

Thank you!
--
Jag

Quoted 77 lines
Quoted 39 lines
remote/remote-main.c +33 -0
+        goto finalize_loop;
+    }
+
+    switch (msg->cmd) {
+    case INIT:
+        break;
+    case PCI_CONFIG_WRITE:
+        break;
+    case PCI_CONFIG_READ:
+        break;
+    default:
+        error_setg(&err, "Unknown command");
+        goto finalize_loop;
+    }
+
+    g_free(msg->data2);
+    g_free(msg);
+
+    return;
+
+finalize_loop:
+    if (err) {
+        error_report_err(err);
+    }
+    g_free(msg);
+    mpqemu_link_finalize(mpqemu_link);
+    mpqemu_link = NULL;
+}
 
  int main(int argc, char *argv[])
  {
+    Error *err = NULL;
+
      module_call_init(MODULE_INIT_QOM);
 
+    bdrv_init_with_whitelist();
+
+    if (qemu_init_main_loop(&err)) {

remote/remote-main.c line 100

Quoted 10 lines
remote/remote-main.c +10 -0
+        error_report_err(err);
+        return -EBUSY;
+    }
+
+    qemu_init_cpu_loop();
+
+    page_size_init();
+
+    qemu_mutex_init(&ram_list.mutex);
+

So these are some subset of the things from qemu_init; I guess we'll have to be careful when we add stuff to vl.c to think what should also be added here.

Dave

Quoted 18 lines
remote/remote-main.c +11 -0
      current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
 
+    mpqemu_link = mpqemu_link_create();
+    if (!mpqemu_link) {
+        printf("Could not create MPQemu link\n");
+        return -1;
+    }
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO);
+    mpqemu_link_set_callback(mpqemu_link, process_msg);
+
+    mpqemu_start_coms(mpqemu_link);
+
      return 0;
  }
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#24 lore raw

Re: [PATCH v5 12/50] multi-process: remote process initialization

Quoted 74 lines · * Jag Raman ([email protected]) wrote:
Quoted 62 lines · Dr. David Alan Gilbert
Quoted 61 lines · * Jagannathan Raman ([email protected]) wrote:

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.

---
v4 -> v5:
- We checked if we could use functions already defined in util/main-loop.c instead of using g_main_loop_run. However, we couldn't find a suitable function that's generic enough to do this. All of them have emulator code embedded in them which is not used by the remote process. We are therefore not making any change to this patch

  remote/remote-main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 85 insertions(+)
remote/remote-main.c +28 -0
index ecf30e0..56315cd 100644
@@ -12,6 +12,7 @@
  #include "qemu-common.h"
  #include <stdio.h>
+#include <unistd.h>
  #include "qemu/module.h"
  #include "remote/pcihost.h"
@@ -19,12 +20,96 @@
  #include "hw/boards.h"
  #include "hw/qdev-core.h"
  #include "qemu/main-loop.h"
+#include "remote/memory.h"
+#include "io/mpqemu-link.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "qemu-common.h"
+#include "hw/pci/pci.h"
+#include "qemu/thread.h"
+#include "qemu/main-loop.h"
+#include "qemu/config-file.h"
+#include "sysemu/sysemu.h"
+#include "block/block.h"
+#include "exec/ramlist.h"
+
+static MPQemuLinkState *mpqemu_link;
+PCIDevice *remote_pci_dev;
+
+static void process_msg(GIOCondition cond, MPQemuChannel *chan)
+{
+    MPQemuMsg *msg = NULL;
+    Error *err = NULL;
+
+    if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) {
+        goto finalize_loop;
+    }
+
+    msg = g_malloc0(sizeof(MPQemuMsg));
Quoted 8 lines

remote/remote-main.c line 52

Quoted 3 lines
remote/remote-main.c +3 -0
+
+    if (mpqemu_msg_recv(msg, chan) < 0) {
+        error_setg(&err, "Failed to receive message");

Please give error messages more context, e.g. the device or process name or something like that so that; it helps when we get a user reporting a crash and they report 'Unknown command' in their log, but then we have to figure out where to point them.

Quoted 2 lines

Ah OK, we'll add the exec name & PID of the QEMU process that spawned this remote process in the error messages.

Great, if you can get something to say which process this particular one is it would be good; so if you've got multiple remote processes we know which one spat out the error.

Dave

Quoted 79 lines

Thank you!
--
Jag

Quoted 74 lines
Quoted 37 lines
remote/remote-main.c +33 -0
+        goto finalize_loop;
+    }
+
+    switch (msg->cmd) {
+    case INIT:
+        break;
+    case PCI_CONFIG_WRITE:
+        break;
+    case PCI_CONFIG_READ:
+        break;
+    default:
+        error_setg(&err, "Unknown command");
+        goto finalize_loop;
+    }
+
+    g_free(msg->data2);
+    g_free(msg);
+
+    return;
+
+finalize_loop:
+    if (err) {
+        error_report_err(err);
+    }
+    g_free(msg);
+    mpqemu_link_finalize(mpqemu_link);
+    mpqemu_link = NULL;
+}
  int main(int argc, char *argv[])
  {
+    Error *err = NULL;
+
      module_call_init(MODULE_INIT_QOM);
+    bdrv_init_with_whitelist();
+
+    if (qemu_init_main_loop(&err)) {

remote/remote-main.c line 100

Quoted 10 lines
remote/remote-main.c +10 -0
+        error_report_err(err);
+        return -EBUSY;
+    }
+
+    qemu_init_cpu_loop();
+
+    page_size_init();
+
+    qemu_mutex_init(&ram_list.mutex);
+

So these are some subset of the things from qemu_init; I guess we'll have to be careful when we add stuff to vl.c to think what should also be added here.

Dave

Quoted 17 lines
remote/remote-main.c +11 -0
      current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
+    mpqemu_link = mpqemu_link_create();
+    if (!mpqemu_link) {
+        printf("Could not create MPQemu link\n");
+        return -1;
+    }
+
+    mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO);
+    mpqemu_link_set_callback(mpqemu_link, process_msg);
+
+    mpqemu_start_coms(mpqemu_link);
+
      return 0;
  }
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#39 lore raw

Re: [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints

In reply to Dr. David Alan Gilbert
Quoted 225 lines · Dr. David Alan Gilbert
Quoted 211 lines · * Jagannathan Raman ([email protected]) wrote:

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         | 65 ++++++++++++++++++++++++++++++++++++++
  include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
  include/io/mpqemu-link.h      | 12 +++++++
  remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
  4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
      dev->get_proxy_sock = get_proxy_sock;
      dev->init_proxy = init_proxy;
  }
+
+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->com);
+
+    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 +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
  #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;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
      PCIDevice parent_dev;
 
      MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
      void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                          bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
  typedef struct PCIProxyDevClass {
      PCIDeviceClass parent_class;
@@ -51,4 +64,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 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
   * PCI_CONFIG_READ        PCI configuration space read
   * PCI_CONFIG_WRITE       PCI configuration space write
   * 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.
@@ -47,6 +49,8 @@ typedef enum {
      PCI_CONFIG_READ,
      PCI_CONFIG_WRITE,
      SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
      MAX,
  } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
  } sync_sysmem_msg_t;
 
  typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
      mpqemu_cmd_t cmd;
      int bytestream;
      size_t size;
@@ -77,6 +88,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];
remote/remote-main.c +19 -0
index 7b4cf2f..acd8daf 100644
@@ -33,6 +33,7 @@
  #include "sysemu/sysemu.h"
  #include "block/block.h"
  #include "exec/ramlist.h"
+#include "exec/memattrs.h"
 
  static MPQemuLinkState *mpqemu_link;
  PCIDevice *remote_pci_dev;
@@ -63,6 +64,66 @@ static void process_config_read(MPQemuMsg *msg)
      PUT_REMOTE_WAIT(wait);
  }
 
+/* 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;
+
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&bar_access->val, bar_access->size, true);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space write operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+    }
+}
+
+static void process_bar_read(MPQemuMsg *msg, Error **errp)

remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 94

Quoted 10 lines
remote/remote-main.c +10 -0
+{
+    bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    AddressSpace *as;
+    int wait = msg->fds[0];
+    MemTxResult res;
+    uint64_t val = 0;
+
+    as = bar_access->memory ? &address_space_memory : &address_space_io;
+
+    assert(bar_access->size <= sizeof(uint64_t));

Note you don't have that check on the write function above. Do you actually want something like:

Quoted 1 line
    assert(is_power_of_2(bar_access->size) && bar_access->size <= sizeof(uint64_t));

Thanks, Dave! I think we should add this check to the write function as well.

Quoted 14 lines

remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 106

Quoted 12 lines
remote/remote-main.c +11 -0
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&val, bar_access->size, false);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space read operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+        val = (uint64_t)-1;
+        goto fail;
+    }
+
+    switch (bar_access->size) {

No case 8 ?

You're correct; we need case 8 in this case.

We don't need to do an explicit typecast for case 8, as the variable "val" is already 8 bytes long. However, if we don't have case 8, then all 8-byte reads would get picked up as "default" and report an error.

We initially didn't have the "default" case. But checkpatch complained about switch-case without default, and this bug got introduced unwittingly.

Thank you!
--
Jag

Quoted 51 lines

Dave

Quoted 45 lines
remote/remote-main.c +32 -0
+    case 4:
+        val = *((uint32_t *)&val);
+        break;
+    case 2:
+        val = *((uint16_t *)&val);
+        break;
+    case 1:
+        val = *((uint8_t *)&val);
+        break;
+    default:
+        error_setg(errp, "Invalid PCI BAR read size");
+        return;
+    }
+
+fail:
+    notify_proxy(wait, val);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
  static void process_msg(GIOCondition cond, MPQemuChannel *chan)
  {
      MPQemuMsg *msg = NULL;
@@ -88,6 +149,18 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
      case PCI_CONFIG_READ:
          process_config_read(msg);
          break;
+    case BAR_WRITE:
+        process_bar_write(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
+    case BAR_READ:
+        process_bar_read(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
      default:
          error_setg(&err, "Unknown command");
          goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#42 lore raw

Re: [PATCH v5 16/50] multi-process: Synchronize remote memory

In reply to Dr. David Alan Gilbert
Quoted 95 lines · Dr. David Alan Gilbert
Quoted 94 lines · * Jagannathan Raman ([email protected]) wrote:

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.

TODO: No need to create object for remote memory listener.

---
  Makefile.target                |   3 +
  hw/proxy/memory-sync.c         | 212 +++++++++++++++++++++++++++++++++++++++++
  hw/proxy/qemu-proxy.c          |   5 +
  include/hw/proxy/memory-sync.h |  37 +++++++
  include/hw/proxy/qemu-proxy.h  |   5 +
  remote/remote-main.c           |  11 +++
  6 files changed, 273 insertions(+)

create mode 100644 hw/proxy/memory-sync.c create mode 100644 include/hw/proxy/memory-sync.h

Makefile.target +3 -0
index cfd36c1..271d883 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 +51 -0
new file mode 100644
index 0000000..3edbb19
@@ -0,0 +1,212 @@
+/*
+ * 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>
+
+#include "qemu/osdep.h"
+#include "qemu/compiler.h"
+#include "qemu/int128.h"
+#include "qemu/range.h"
+#include "exec/memory.h"
+#include "exec/cpu-common.h"
+#include "cpu.h"
+#include "exec/ram_addr.h"
+#include "exec/address-spaces.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
+
+static const TypeInfo remote_mem_sync_type_info = {
+    .name          = TYPE_MEMORY_LISTENER,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(RemoteMemSync),
+};
+
+static void remote_mem_sync_register_types(void)
+{
+    type_register_static(&remote_mem_sync_type_info);
+}
+
+type_init(remote_mem_sync_register_types)
+
+static void proxy_ml_begin(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    int mrs;
+
+    for (mrs = 0; mrs < sync->n_mr_sections; mrs++) {
+        memory_region_unref(sync->mr_sections[mrs].mr);
+    }
+
+    g_free(sync->mr_sections);
+    sync->mr_sections = NULL;
+    sync->n_mr_sections = 0;
+}
+
Quoted 8 lines

hw/proxy/memory-sync.c line 57

Quoted 6 lines
hw/proxy/memory-sync.c new file +6 -0
+static int get_fd_from_hostaddr(uint64_t host, ram_addr_t *offset)
+{
+    MemoryRegion *mr;
+    ram_addr_t off;
+
+    mr = memory_region_from_host((void *)(uintptr_t)host, &off);

Do you need to just check we found an 'mr' ?

OK, we'll add this check.

Quoted 21 lines
Quoted 10 lines
hw/proxy/memory-sync.c new file +9 -0
+    if (offset) {
+        *offset = off;
+    }
+
+    return memory_region_get_fd(mr);
+}
+
+static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size)
+{

hw/proxy/memory-sync.c line 77

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    bool merge;
+    int fd1, fd2;
+
+    fd1 = get_fd_from_hostaddr(host, NULL);
+
+    fd2 = get_fd_from_hostaddr(prev_host, NULL);
+
+    merge = (fd1 == fd2);
+
+    merge &= ((prev_host + size) == host);
Quoted 7 lines

It's interesting; I think the vhost code checks that the two mr's are the same where you are checking for the same underlying fd - but I think that's OK.
(I wonder if we need to check offset's within the fd's match up when they're merged - since you added that offset feature in an earlier patch?
That would also need checking in vhost_region_add_section)

If the fds are the same, and the subsequent check ((prev_host + size) == host) passes, then I believe the offsets would match as well.

Quoted 29 lines
Quoted 29 lines
hw/proxy/memory-sync.c new file +28 -0
+    return merge;
+}
+
+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) &&
+          !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;
+
+    if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) {
+        return;
+    }
Quoted 8 lines

hw/proxy/memory-sync.c line 110

Quoted 4 lines
hw/proxy/memory-sync.c new file +4 -0
+
+    mrs_host = mrs_host & ~(mrs_page - 1);
+    mrs_gpa = mrs_gpa & ~(mrs_page - 1);
+    mrs_size = ROUND_UP(mrs_size, mrs_page);

OK, just note the more complex code in vhost_region_add_section for page aligning regions that are needed for postcopy; I think that would be the same if you wanted to do postcopy with remote processes.

Since mmap requires the addresses to be aligned with a page boundry, we added these checks. We are essentially doing the same with alignage as compared with vhost user. So we should be compliant with postcopy I believe.

Quoted 16 lines
Quoted 5 lines
hw/proxy/memory-sync.c new file +4 -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);

hw/proxy/memory-sync.c line 125

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+        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);
+
+        if (mrs_gpa <= (prev_gpa_end + 1)) {
+            if (mrs_gpa < prev_gpa_start) {
+                assert(0);
+            }
Quoted 1 line

g_assert(mrs_gpa < prev_gpa_start);

Thank you, we'll update the above check with the version you proposed.

Quoted 27 lines
Quoted 16 lines
hw/proxy/memory-sync.c new file +14 -0
+            if ((section->mr == prev_sec->mr) &&
+                proxy_mrs_can_merge(mrs_host, prev_host_start,
+                                    (mrs_gpa - prev_gpa_start))) {
+                uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size);
+                need_add = false;
+                prev_sec->offset_within_address_space =
+                    MIN(prev_gpa_start, mrs_gpa);
+                prev_sec->offset_within_region =
+                    MIN(prev_host_start, mrs_host) -
+                    (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr);
+                prev_sec->size = int128_make64(max_end - MIN(prev_host_start,
+                                                             mrs_host));
+            }
+        }

hw/proxy/memory-sync.c line 150

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+    }
+
+    if (need_add) {
+        ++sync->n_mr_sections;
+        sync->mr_sections = g_renew(MemoryRegionSection, sync->mr_sections,
+                                    sync->n_mr_sections);
+        sync->mr_sections[sync->n_mr_sections - 1] = *section;
+        sync->mr_sections[sync->n_mr_sections - 1].fv = NULL;
+        memory_region_ref(section->mr);
+    }
Quoted 2 lines

I'd add some tracing in this function; it's a nightmare to debug when it does something unexpected.

Thank you, we'll add the tracing.

Quoted 22 lines
Quoted 22 lines
hw/proxy/memory-sync.c new file +21 -0
+}
+
+static void proxy_ml_commit(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    MPQemuMsg msg;
+    MemoryRegionSection section;
+    ram_addr_t offset;
+    uintptr_t host_addr;
+    int region;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.cmd = SYNC_SYSMEM;
+    msg.bytestream = 0;
+    msg.num_fds = sync->n_mr_sections;
+    msg.size = sizeof(msg.data1);
+    assert(msg.num_fds <= REMOTE_MAX_FDS);
+
+    for (region = 0; region < sync->n_mr_sections; region++) {
+        section = sync->mr_sections[region];
Quoted 8 lines

hw/proxy/memory-sync.c line 177

Quoted 6 lines
hw/proxy/memory-sync.c new file +6 -0
+        msg.data1.sync_sysmem.gpas[region] =
+            section.offset_within_address_space;
+        msg.data1.sync_sysmem.sizes[region] = int128_get64(section.size);
+        host_addr = (uintptr_t)memory_region_get_ram_ptr(section.mr) +
+                    section.offset_within_region;
+        msg.fds[region] = get_fd_from_hostaddr(host_addr, &offset);

Since you already have section.mr you cna use memory_region_get_fd.

OK.

Thank you!
--
Jag

Quoted 174 lines
Quoted 147 lines
hw/proxy/memory-sync.c new file +35 -0
+        msg.data1.sync_sysmem.offsets[region] = offset;
+    }
+    mpqemu_msg_send(&msg, sync->mpqemu_link->com);
+}
+
+void deconfigure_memory_sync(RemoteMemSync *sync)
+{
+    memory_listener_unregister(&sync->listener);
+}
+
+/*
+ * TODO: Memory Sync need not be instantianted once per every proxy device.
+ *       All remote devices are going to get the exact same updates at the
+ *       same time. It therefore makes sense to have a broadcast model.
+ *
+ *       Broadcast model would involve running the MemorySync object in a
+ *       thread. MemorySync would contain a list of mpqemu-link objects
+ *       that need notification. proxy_ml_commit() could send the same
+ *       message to all the links at the same time.
+ */
+void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link)
+{
+    sync->n_mr_sections = 0;
+    sync->mr_sections = NULL;
+
+    sync->mpqemu_link = mpqemu_link;
+
+    sync->listener.begin = proxy_ml_begin;
+    sync->listener.commit = proxy_ml_commit;
+    sync->listener.region_add = proxy_ml_region_addnop;
+    sync->listener.region_nop = proxy_ml_region_addnop;
+    sync->listener.priority = 10;
+
+    memory_listener_register(&sync->listener, &address_space_memory);
+}
hw/proxy/qemu-proxy.c +5 -0
index b17d9bb..d3a9d38 100644
@@ -16,6 +16,8 @@
  #include "qapi/qmp/qjson.h"
  #include "qapi/qmp/qstring.h"
  #include "hw/proxy/qemu-proxy.h"
+#include "hw/proxy/memory-sync.h"
+#include "qom/object.h"
 
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
@@ -243,6 +245,8 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
 
      mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                          pdev->socket);
+
+    configure_memory_sync(pdev->sync, pdev->mpqemu_link);
  }
 
  static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
@@ -261,6 +265,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
      dev->set_proxy_sock = set_proxy_sock;
      dev->get_proxy_sock = get_proxy_sock;
      dev->init_proxy = init_proxy;
+    dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
  }
 
  static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/memory-sync.h new file +37 -0
new file mode 100644
index 0000000..d8329c9
@@ -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 +5 -0
index 44e370e..c93ffe3 100644
@@ -10,6 +10,7 @@
  #define QEMU_PROXY_H
 
  #include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
 
  #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -37,8 +38,12 @@ extern const MemoryRegionOps proxy_default_ops;
  struct PCIProxyDev {
      PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
      MPQemuLinkState *mpqemu_link;
 
+    RemoteMemSync *sync;
      pid_t remote_pid;
      int socket;
 
remote/remote-main.c +1 -0
index acd8daf..9512a3b 100644
@@ -34,6 +34,7 @@
  #include "block/block.h"
  #include "exec/ramlist.h"
  #include "exec/memattrs.h"
+#include "exec/address-spaces.h"
 
  static MPQemuLinkState *mpqemu_link;
  PCIDevice *remote_pci_dev;

remote/remote-main.c static void process_msg(GIOCondition cond, MPQemuChannel *chan) · line 168

Quoted 7 lines
remote/remote-main.c +4 -0
@@ -161,6 +162,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
              goto finalize_loop;
          }
          break;
+    case SYNC_SYSMEM:
+        /*
+         * TODO: ensure no active DMA is happening when
+         * sysmem is being updated

In practice this turns out to be hard!

Dave

Quoted 12 lines
remote/remote-main.c +6 -0
+         */
+        remote_sysmem_reconfig(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
      default:
          error_setg(&err, "Unknown command");
          goto finalize_loop;
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#78 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

In reply to Dr. David Alan Gilbert
Quoted 75 lines · Dr. David Alan Gilbert
Quoted 74 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
  Makefile.objs           |  4 +++-
  Makefile.target         |  1 +
  migration/Makefile.objs | 13 ++++++++++++-
  net/Makefile.objs       |  2 ++
  softmmu/vl.c            |  2 --
  stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  stubs/net-stub.c        | 21 +++++++++++++++++++++
  stubs/qapi-misc.c       |  2 ++
  stubs/replay.c          |  8 ++++++++
  stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
  vl-parse.c              |  3 +++
  11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
  common-obj-$(CONFIG_WIN32) += os-win32.o
  common-obj-$(CONFIG_POSIX) += os-posix.o
 
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
  common-obj-$(CONFIG_LINUX) += fsdev/
 
  common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
 
  #######################################################################
  # qapi
-
  common-obj-y += qapi/
 
  endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
  remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
  remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
  remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
  all-remote-pci-obj-y += exec-vary.o
  all-remote-pci-obj-y += ioport.o
  all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
  endif
 
  remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

Thank you!
--
Jag

Quoted 226 lines

Dave

Quoted 220 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
  vde.o-libs = $(VDE_LIBS)
 
  common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
  ram_addr_t ram_size;
  const char *mem_path = NULL;
  int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
  bool enable_cpu_pm = false;
  int nb_nics;
  NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
  int boot_menu;
  bool boot_strict;
  uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
  bool wakeup_suspend_enabled;
 
  int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
  #include "qapi/qapi-types-migration.h"
  #include "qapi/qapi-commands-migration.h"
  #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
 
  MigrationInfo *qmp_query_migrate(Error **errp)
  {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
 
      return NULL;
  }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
  #include "qapi/qapi-commands-net.h"
  #include "qapi/qapi-commands-rocker.h"
 
+#pragma weak qmp_announce_self
+
  int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                   NetClientDriver type, int max)
  {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
  {
      qemu_debug_assert(0);
  }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
  #include "./qapi/qapi-types-dump.h"
  #include "qapi/qapi-commands-dump.h"
 
+#pragma weak qmp_xen_load_devices_state
+
  void qmp_dump_guest_memory(bool paging, const char *file,
                             bool has_detach, bool detach,
                             bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
  #include "qemu/osdep.h"
+#include "qemu-common.h"
  #include "sysemu/replay.h"
 
  ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
  void replay_add_blocker(Error *reason)
  {
  }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
  #include "disas/disas.h"
  #include "audio/audio.h"
 
+#pragma weak qemu_add_exit_notifier
+
  bool tcg_allowed;
  bool xen_allowed;
  bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 
      return -1;
  }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
 
  #include "vl.h"
 
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
  /***********************************************************/
  /* QEMU Block devices */
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#17 lore raw

Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints

In reply to Jag Raman
Quoted 85 lines · * Jag Raman ([email protected]) wrote:
Quoted 48 lines · Dr. David Alan Gilbert
Quoted 47 lines · * Jagannathan Raman ([email protected]) wrote:

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         | 41 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                                mpqemu_link_callback callback);
  void mpqemu_start_coms(MPQemuLinkState *s);
+#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 +8 -0
index bac120b..73b7032 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"
@@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
      return rc;
  }
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };
+    uint64_t val;
+    int ret;
+
+    ret = poll(&pfd, 1, 1000);
Quoted 8 lines

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

Quoted 6 lines
io/mpqemu-link.c +6 -0
+
+    switch (ret) {
+    case 0:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n");
+        /* TODO: Kick-off error recovery */
+        return ULLONG_MAX;

Shouldn't these be UINT64_MAX?

Sure, we'll change these to UINT64_MAX.

Quoted 15 lines
Quoted 4 lines
io/mpqemu-link.c +3 -0
+    case -1:
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n",
+                      strerror(errno));

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

Quoted 10 lines
io/mpqemu-link.c +10 -0
+        return ULLONG_MAX;
+    default:
+        if (read(efd, &val, sizeof(val)) == -1) {
+            qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n",
+                          strerror(errno));
+            return ULLONG_MAX;
+        }
+    }
+
+    val = (val == ULLONG_MAX) ? val : (val - 1);
Quoted 1 line

Can you explain what's going on there??

This wait_for_remote() function serves two purposes. This first one is to synchronize QEMU and the remote process. Secondly, it allows the remote process to return a 64-bit value to QEMU. When the remote process has completed the task, it uses the notify_proxy() function to return to QEMU along with a return value.

Quoted 6 lines

We have implemented this synchronization mechanism using eventfd, as it's easy to setup. So 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.

OK, that needs a big hairy comment to explain what's going on.

Dave

Quoted 33 lines

--
Jag

Quoted 29 lines

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

Quoted 9 lines
io/mpqemu-link.c +8 -0
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == ULLONG_MAX) ? val : (val + 1);
+
+    if (write(efd, &val, sizeof(val)) == -1) {

I'd actually check the write/read's are returning sizeof(val) - they can on a bad day return 0 or send only a few bytes; in theory?

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        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
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#79 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

In reply to Jag Raman
Quoted 79 lines · * Jag Raman ([email protected]) wrote:
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 66 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
  Makefile.objs           |  4 +++-
  Makefile.target         |  1 +
  migration/Makefile.objs | 13 ++++++++++++-
  net/Makefile.objs       |  2 ++
  softmmu/vl.c            |  2 --
  stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
  stubs/net-stub.c        | 21 +++++++++++++++++++++
  stubs/qapi-misc.c       |  2 ++
  stubs/replay.c          |  8 ++++++++
  stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
  vl-parse.c              |  3 +++
  11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
  common-obj-$(CONFIG_WIN32) += os-win32.o
  common-obj-$(CONFIG_POSIX) += os-posix.o
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
  common-obj-$(CONFIG_LINUX) += fsdev/
  common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
  #######################################################################
  # qapi
-
  common-obj-y += qapi/
  endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
  remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
  remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
  remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
  all-remote-pci-obj-y += exec-vary.o
  all-remote-pci-obj-y += ioport.o
  all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
  endif
  remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Quoted 4 lines

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

But are you even running a migration stream from the remote process? Aren't you just doing vmstate migration of devices; i.e. do you need anything relating to incremental RAM migration (e.g. xbzrle, rdma, postcopy).

Dave

Quoted 219 lines

Thank you!
--
Jag

Quoted 214 lines

Dave

Quoted 208 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
  vde.o-libs = $(VDE_LIBS)
  common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
  ram_addr_t ram_size;
  const char *mem_path = NULL;
  int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
  bool enable_cpu_pm = false;
  int nb_nics;
  NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
  int boot_menu;
  bool boot_strict;
  uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
  bool wakeup_suspend_enabled;
  int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
  #include "qapi/qapi-types-migration.h"
  #include "qapi/qapi-commands-migration.h"
  #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
  MigrationInfo *qmp_query_migrate(Error **errp)
  {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
      return NULL;
  }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
  #include "qapi/qapi-commands-net.h"
  #include "qapi/qapi-commands-rocker.h"
+#pragma weak qmp_announce_self
+
  int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                   NetClientDriver type, int max)
  {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
  {
      qemu_debug_assert(0);
  }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
  #include "./qapi/qapi-types-dump.h"
  #include "qapi/qapi-commands-dump.h"
+#pragma weak qmp_xen_load_devices_state
+
  void qmp_dump_guest_memory(bool paging, const char *file,
                             bool has_detach, bool detach,
                             bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
  #include "qemu/osdep.h"
+#include "qemu-common.h"
  #include "sysemu/replay.h"
  ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
  void replay_add_blocker(Error *reason)
  {
  }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
  #include "disas/disas.h"
  #include "audio/audio.h"
+#pragma weak qemu_add_exit_notifier
+
  bool tcg_allowed;
  bool xen_allowed;
  bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
      return -1;
  }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
  #include "vl.h"
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
  /***********************************************************/
  /* QEMU Block devices */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#80 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

Quoted 85 lines · Dr. David Alan Gilbert
Quoted 79 lines · * Jag Raman ([email protected]) wrote:
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 66 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
   Makefile.objs           |  4 +++-
   Makefile.target         |  1 +
   migration/Makefile.objs | 13 ++++++++++++-
   net/Makefile.objs       |  2 ++
   softmmu/vl.c            |  2 --
   stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   stubs/net-stub.c        | 21 +++++++++++++++++++++
   stubs/qapi-misc.c       |  2 ++
   stubs/replay.c          |  8 ++++++++
   stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
   vl-parse.c              |  3 +++
   11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
   common-obj-$(CONFIG_WIN32) += os-win32.o
   common-obj-$(CONFIG_POSIX) += os-posix.o
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
   common-obj-$(CONFIG_LINUX) += fsdev/
   common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
   #######################################################################
   # qapi
-
   common-obj-y += qapi/
   endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
   remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
   remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
   remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
   all-remote-pci-obj-y += exec-vary.o
   all-remote-pci-obj-y += ioport.o
   all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
   endif
   remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Quoted 4 lines

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

Quoted 4 lines

But are you even running a migration stream from the remote process? Aren't you just doing vmstate migration of devices; i.e. do you need anything relating to incremental RAM migration (e.g. xbzrle, rdma, postcopy).

We are running a migration stream from the remote process. We are only doing the vmstate migration of devices, and not anything incremental related to RAM.

We are using QEMU's existing migration infrastructure (vmstate_save / qemu_loadvm_section_start_full) to move the vmstate. Based on my limited experience with the migration code, I get that it comes as a suite. Without some refactoring, we would need to build all of the files within the migration folder.

The vmstate functions communicate over QEMUFile, which would be using fd, tcp, rdma, etc... at the backend. These functions also need other functions defined in migration.c, which require the building of xbzrle, postcopy, etc...

Thank you!
--
Jag

Quoted 225 lines

Dave

Quoted 219 lines

Thank you!
--
Jag

Quoted 214 lines

Dave

Quoted 208 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
   vde.o-libs = $(VDE_LIBS)
   common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
   ram_addr_t ram_size;
   const char *mem_path = NULL;
   int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
   bool enable_cpu_pm = false;
   int nb_nics;
   NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
   int boot_menu;
   bool boot_strict;
   uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
   bool wakeup_suspend_enabled;
   int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
   #include "qapi/qapi-types-migration.h"
   #include "qapi/qapi-commands-migration.h"
   #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
   MigrationInfo *qmp_query_migrate(Error **errp)
   {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
       return NULL;
   }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
   #include "qapi/qapi-commands-net.h"
   #include "qapi/qapi-commands-rocker.h"
+#pragma weak qmp_announce_self
+
   int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                    NetClientDriver type, int max)
   {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
   {
       qemu_debug_assert(0);
   }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
   #include "./qapi/qapi-types-dump.h"
   #include "qapi/qapi-commands-dump.h"
+#pragma weak qmp_xen_load_devices_state
+
   void qmp_dump_guest_memory(bool paging, const char *file,
                              bool has_detach, bool detach,
                              bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
   #include "qemu/osdep.h"
+#include "qemu-common.h"
   #include "sysemu/replay.h"
   ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
   void replay_add_blocker(Error *reason)
   {
   }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
   #include "disas/disas.h"
   #include "audio/audio.h"
+#pragma weak qemu_add_exit_notifier
+
   bool tcg_allowed;
   bool xen_allowed;
   bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
       return -1;
   }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
   #include "vl.h"
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
   /***********************************************************/
   /* QEMU Block devices */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#33 lore raw

Re: [PATCH v5 14/50] mutli-process: build remote command line args

In reply to Daniel P. Berrangé
Quoted 139 lines · Daniel P. Berrangé
Quoted 92 lines · Elena Ufimtseva
Quoted 81 lines · Daniel P. Berrangé
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 43

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

Quoted 4 lines

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

Hi Daniel

Thank you for explanation.
At this point there is no intermediate stage as we grab the arguments as a raw string from the command line option -remote:

Quoted 8 lines

-remote rid=8,exec=qemu-scsi-dev,command="-drive id=drive_image2,,file=/root/remote-process-disk.img"

So the command="" string is being later parsed into the array and remote process gets spawned with the "char **argv".

Stefan expressed his concern that its not convenient to use due to the double escaping commas, spaces, quotes and we do agree with that. We were seeking an advice on what is the better approach.

I've not looked closely enough to understand the range of different options we need to be able to pass to the remote QEMU ? Is it just "-drive" options, or can it be absolutely any QEMU option ?

If it is just -drive, then I could imagine a -remote-drive option such that we end up with with a set of args

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -remote-drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -remote-drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -remote-drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -remote-drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

And this gets turned into 2 execs:

   qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img
   
   qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

Or maybe instead of having a '-remote-drive' arg, we can make the '-drive' arg take an optional "rid" attribute to associate it with the remote process

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img
Quoted 8 lines

When 'rid' is seen, instead of creating a local block backend, the args get used for the remote process.

This would have the nice user behaviour that you can take an existing QEMU command line, and turn it into a multi-process command line simply by adding the '-remote ...' arg, and adding 'rid=NN' to each -drive. Nothing else about your existing command line need change.

This does look good, especially unmodified -drive.
And -monitor for the remote process could also be similarly added with only rid specified instead of plugging it into the raw string.

Stefan did mention in the another patch that he thinks that adding -remote option is too invasive and suggested using -object itself to further separate remote process devices.

So to compile both replies, the command line for the remote process will look something like this:

-object remote-device,id=rid0,exec=qemu-scsi-dev \
-device remote-pci-device,id=scsi0,remote-device=rid0 \
-device scsi-hd,drive=drive_image1,bus=scsi0.0,scsi-id=0,remote-device=rid0 \
-drive id=drive_image3,file=/root/remote-process-disk3.img,remote-device=rid0 \
-drive id=drive_image4,file=/root/remote-process-disk4.img,remote-device=rid0 \
-monitor unix:/home/qmp-sock,,server,,nowait,remote-device=rid0

And in experimental version we imply that remote-pci-device is the LSI controller. For vfio-over-socket it will represent any remote PCI device.

What your thoughts on this?

Thank you!
Elena

Stefan,

Quoted 11 lines
Quoted 3 lines

Few things we discussed internally is to have the remote drive command line options passed over by messages or using QMP.

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 v5 14/50] mutli-process: build remote command line args

Quoted 168 lines · Elena Ufimtseva
Quoted 139 lines · Daniel P. Berrangé
Quoted 92 lines · Elena Ufimtseva
Quoted 81 lines · Daniel P. Berrangé
Quoted 63 lines · Elena Ufimtseva
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Thank Philippe, will fix.

Quoted 40 lines
Quoted 40 lines · Jagannathan Raman
Quoted 39 lines

From: Elena Ufimtseva <[email protected]>

---
v4 -> v5:
- Added "exec" suboption to get the executable's name
- Addressed feedback about variable names
- Removed redundant check for spawning a process

  hw/proxy/qemu-proxy.c         | 68 +++++++++++++++++++++++++++++++++----------
  include/hw/proxy/qemu-proxy.h |  2 +-
  2 files changed, 54 insertions(+), 16 deletions(-)
hw/proxy/qemu-proxy.c +18 -0
index 828bbd7..d792e86 100644
@@ -19,19 +19,50 @@
  static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+static int add_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
+    if (argc < max_args - 1) {
+        argv[argc++] = opts_str;
+        argv[argc] = 0;
+    } else {
+        return 0;
+    }
+
+    return argc;
+}
+
+static int make_argv(char *opts_str, char **argv, int argc)
+{
+    int max_args = 64;
+
Quoted 9 lines
Quoted 8 lines

hw/proxy/qemu-proxy.c line 43

Quoted 6 lines
hw/proxy/qemu-proxy.c +6 -0
+    char *p2 = strtok(opts_str, " ");
+    while (p2 && argc < max_args - 1) {
+        argv[argc++] = p2;
+        p2 = strtok(0, " ");
+    }
+    argv[argc] = 0;

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

https://developer.gnome.org/glib/stable/glib-Shell-related-Utilities.html

Though my preference would be to avoid the need to do this at all, by not accepting a raw shell command line string in the first place.

Can you please clarify? Did you mean that it would be better if Qemu somehow verifies the options and then passes it to a remote process via a message?

I've not been able to trace the code paths back all the way, so I can't point to where I think needs fixing. I assuming that something, somewhere in this patch series should starts out with a binary name and a list of argv as an array of char *. ie a "char **argv". At some point this array gets mashed together into a single 'char *' string where all the argv are separated by a space. This patch now tries to parse this and turn it back into a "char **argv" array.

Quoted 4 lines

So my key point is that we should try hard to avoid this intermediate shell command line string stage entirely. Always keep the argv in an array form, and never mash them together such that they then need parsing again.

Hi Daniel

Thank you for explanation.
At this point there is no intermediate stage as we grab the arguments as a raw string from the command line option -remote:

Quoted 8 lines

-remote rid=8,exec=qemu-scsi-dev,command="-drive id=drive_image2,,file=/root/remote-process-disk.img"

So the command="" string is being later parsed into the array and remote process gets spawned with the "char **argv".

Stefan expressed his concern that its not convenient to use due to the double escaping commas, spaces, quotes and we do agree with that. We were seeking an advice on what is the better approach.

I've not looked closely enough to understand the range of different options we need to be able to pass to the remote QEMU ? Is it just "-drive" options, or can it be absolutely any QEMU option ?

If it is just -drive, then I could imagine a -remote-drive option such that we end up with with a set of args

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -remote-drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -remote-drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -remote-drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -remote-drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

And this gets turned into 2 execs:

   qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img
   
   qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img

Or maybe instead of having a '-remote-drive' arg, we can make the '-drive' arg take an optional "rid" attribute to associate it with the remote process

   $QEMU \
   -remote rid=8,exec=qemu-scsi-dev \
   -drive rid=8,id=drive_image1,file=/root/remote-process-disk1.img \
   -drive rid=8,id=drive_image2,file=/root/remote-process-disk2.img \
   -remote rid=9,exec=qemu-scsi-dev \
   -drive rid=9,id=drive_image3,file=/root/remote-process-disk3.img \
   -drive rid=9,id=drive_image4,file=/root/remote-process-disk4.img
Quoted 8 lines

When 'rid' is seen, instead of creating a local block backend, the args get used for the remote process.

This would have the nice user behaviour that you can take an existing QEMU command line, and turn it into a multi-process command line simply by adding the '-remote ...' arg, and adding 'rid=NN' to each -drive. Nothing else about your existing command line need change.

This does look good, especially unmodified -drive.
And -monitor for the remote process could also be similarly added with only rid specified instead of plugging it into the raw string.

Stefan did mention in the another patch that he thinks that adding -remote option is too invasive and suggested using -object itself to further separate remote process devices.

So to compile both replies, the command line for the remote process will look something like this:

(quoted diff) +0 -6
-object remote-device,id=rid0,exec=qemu-scsi-dev \
-device remote-pci-device,id=scsi0,remote-device=rid0 \
-device scsi-hd,drive=drive_image1,bus=scsi0.0,scsi-id=0,remote-device=rid0 \
-drive id=drive_image3,file=/root/remote-process-disk3.img,remote-device=rid0 \
-drive id=drive_image4,file=/root/remote-process-disk4.img,remote-device=rid0 \
-monitor unix:/home/qmp-sock,,server,,nowait,remote-device=rid0
Quoted 4 lines

And in experimental version we imply that remote-pci-device is the LSI controller. For vfio-over-socket it will represent any remote PCI device.

What your thoughts on this?

Looks like a reasonable idea to me. I guess I'm not sure how much the block maintainers will like having a -drive additional property. Probably depends how much it impacts the code paths processing it.

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 :|
#81 lore raw

Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process

In reply to Jag Raman
Quoted 103 lines · * Jag Raman ([email protected]) wrote:
Quoted 85 lines · Dr. David Alan Gilbert
Quoted 79 lines · * Jag Raman ([email protected]) wrote:
Quoted 67 lines · Dr. David Alan Gilbert
Quoted 66 lines · * Jagannathan Raman ([email protected]) wrote:

Add Makefile support to enable migration in remote process

---
   Makefile.objs           |  4 +++-
   Makefile.target         |  1 +
   migration/Makefile.objs | 13 ++++++++++++-
   net/Makefile.objs       |  2 ++
   softmmu/vl.c            |  2 --
   stubs/migration.c       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
   stubs/net-stub.c        | 21 +++++++++++++++++++++
   stubs/qapi-misc.c       |  2 ++
   stubs/replay.c          |  8 ++++++++
   stubs/vl-stub.c         | 24 ++++++++++++++++++++++++
   vl-parse.c              |  3 +++
   11 files changed, 125 insertions(+), 4 deletions(-)
Makefile.objs +3 -1
index 4b5db09..65009da 100644
@@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o
   common-obj-$(CONFIG_WIN32) += os-win32.o
   common-obj-$(CONFIG_POSIX) += os-posix.o
+remote-pci-obj-$(CONFIG_POSIX) += os-posix.o
+
   common-obj-$(CONFIG_LINUX) += fsdev/
   common-obj-y += accel/
@@ -104,11 +106,11 @@ common-obj-y += vl-parse.o
   #######################################################################
   # qapi
-
   common-obj-y += qapi/
   endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += net/
   remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
   remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
   remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
Makefile.target +1 -0
index 4ead5c3..4012ae5 100644
@@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o
   all-remote-pci-obj-y += exec-vary.o
   all-remote-pci-obj-y += ioport.o
   all-remote-pci-obj-y += cpus.o
+all-remote-pci-obj-y += migration/ram.o
   endif
   remote-pci-obj-y :=
migration/Makefile.objs +8 -1
index e7cdc76..21f9d8d 100644
@@ -15,4 +15,15 @@ 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
+remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o
+remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o
+remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o
+remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o
Quoted 8 lines

migration/Makefile.objs common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o · line 29

Quoted 4 lines
migration/Makefile.objs +4 -0
+remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o
+remote-pci-obj-$(CONFIG_RDMA) += rdma.o
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o
+remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o

Hmm, are you really going to want all this lot in your remote process? Assuming it's just devices, I can understand the first line or two, but it seems odd to have all of this.

Quoted 4 lines

Yeah, we ended up needing to compile these in to enable migration. We are only using "fd" to enable migration. Although we don't use tls, xbzrle, rdma, multifd, etc... for example, the migration code does support these protocols and, therefore, we had to compile them in.

Quoted 4 lines

But are you even running a migration stream from the remote process? Aren't you just doing vmstate migration of devices; i.e. do you need anything relating to incremental RAM migration (e.g. xbzrle, rdma, postcopy).

We are running a migration stream from the remote process. We are only doing the vmstate migration of devices, and not anything incremental related to RAM.

We are using QEMU's existing migration infrastructure (vmstate_save / qemu_loadvm_section_start_full) to move the vmstate. Based on my limited experience with the migration code, I get that it comes as a suite. Without some refactoring, we would need to build all of the files within the migration folder.

Quoted 4 lines

The vmstate functions communicate over QEMUFile, which would be using fd, tcp, rdma, etc... at the backend. These functions also need other functions defined in migration.c, which require the building of xbzrle, postcopy, etc...

OK, I bet we can refactor some of that to be modular fairly easily; some is harder than others. For example there are different QEMUFile subclasses for RDMA, so you should be able to have just the top level QEMUFile and the implementations you need.
Similarly the vmstate code shouldn't depend on the ram code; we can look at splitting it up some how.

Dave

Quoted 230 lines

Thank you!
--
Jag

Quoted 225 lines

Dave

Quoted 219 lines

Thank you!
--
Jag

Quoted 214 lines

Dave

Quoted 208 lines
net/Makefile.objs +2 -0
index c5d076d..a8ad986 100644
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o
   vde.o-libs = $(VDE_LIBS)
   common-obj-$(CONFIG_CAN_BUS) += can/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
softmmu/vl.c +0 -2
index 4a4f52c..42d5682 100644
@@ -128,7 +128,6 @@ const char* keyboard_layout = NULL;
   ram_addr_t ram_size;
   const char *mem_path = NULL;
   int mem_prealloc = 0; /* force preallocation of physical target memory */
-bool enable_mlock = false;
   bool enable_cpu_pm = false;
   int nb_nics;
   NICInfo nd_table[MAX_NICS];
@@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS];
   int boot_menu;
   bool boot_strict;
   uint8_t *boot_splash_filedata;
-int only_migratable; /* turn it off unless user states otherwise */
   bool wakeup_suspend_enabled;
   int icount_align_option;
stubs/migration.c +49 -0
index 28ccf80..dbd12db 100644
@@ -6,6 +6,35 @@
   #include "qapi/qapi-types-migration.h"
   #include "qapi/qapi-commands-migration.h"
   #include "qapi/qapi-types-net.h"
+#include "net/filter.h"
+#include "net/colo-compare.h"
+
+#pragma weak qmp_query_migrate_capabilities
+#pragma weak qmp_query_migrate_parameters
+#pragma weak migrate_announce_params
+#pragma weak qmp_query_migrate
+#pragma weak qmp_migrate_set_capabilities
+#pragma weak qmp_migrate_set_parameters
+#pragma weak qmp_migrate_incoming
+#pragma weak qmp_migrate_recover
+#pragma weak qmp_migrate_pause
+#pragma weak qmp_migrate
+#pragma weak qmp_migrate_cancel
+#pragma weak qmp_migrate_continue
+#pragma weak qmp_migrate_set_cache_size
+#pragma weak qmp_query_migrate_cache_size
+#pragma weak qmp_migrate_set_speed
+#pragma weak qmp_migrate_set_downtime
+#pragma weak qmp_migrate_start_postcopy
+#pragma weak migration_global_dump
+#pragma weak save_snapshot
+#pragma weak qmp_xen_save_devices_state
+#pragma weak load_snapshot
+#pragma weak qmp_xen_set_replication
+#pragma weak qmp_query_xen_replication_status
+#pragma weak qmp_xen_colo_do_checkpoint
+#pragma weak qmp_query_colo_status
+#pragma weak qmp_x_colo_lost_heartbeat
   MigrationInfo *qmp_query_migrate(Error **errp)
   {
@@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void)
       return NULL;
   }
+
+void colo_notify_filters_event(int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_notify_compares_event(void *opaque, int event, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_register_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
+
+void colo_compare_unregister_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
stubs/net-stub.c +21 -0
index 962827e..ddfd1e4 100644
@@ -5,6 +5,8 @@
   #include "qapi/qapi-commands-net.h"
   #include "qapi/qapi-commands-rocker.h"
+#pragma weak qmp_announce_self
+
   int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                    NetClientDriver type, int max)
   {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp)
   {
       qemu_debug_assert(0);
   }
+
+NetClientState *qemu_get_queue(NICState *nic)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
+{
+    qemu_debug_assert(0);
+}
stubs/qapi-misc.c +2 -0
index 3eeedd9..824eac1 100644
@@ -5,6 +5,8 @@
   #include "./qapi/qapi-types-dump.h"
   #include "qapi/qapi-commands-dump.h"
+#pragma weak qmp_xen_load_devices_state
+
   void qmp_dump_guest_memory(bool paging, const char *file,
                              bool has_detach, bool detach,
                              bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
index 9b53c0c..6fc7850 100644
@@ -1,4 +1,5 @@
   #include "qemu/osdep.h"
+#include "qemu-common.h"
   #include "sysemu/replay.h"
   ReplayMode replay_mode;
@@ -106,3 +107,10 @@ void replay_account_executed_instructions(void)
   void replay_add_blocker(Error *reason)
   {
   }
+
+bool replay_can_snapshot(void)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
stubs/vl-stub.c +24 -0
index 606f078..5f308c1 100644
@@ -14,6 +14,8 @@
   #include "disas/disas.h"
   #include "audio/audio.h"
+#pragma weak qemu_add_exit_notifier
+
   bool tcg_allowed;
   bool xen_allowed;
   bool boot_strict;
@@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
       return -1;
   }
+
+void qemu_system_killed(int signal, pid_t pid)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_store(char *str, size_t size)
+{
+    qemu_debug_assert(0);
+
+    return false;
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    qemu_debug_assert(0);
+}
vl-parse.c +3 -0
index 1f6a3f0..423f4a0 100644
@@ -27,6 +27,9 @@
   #include "vl.h"
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
   /***********************************************************/
   /* QEMU Block devices */
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#63 lore raw

Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target

In reply to Jagannathan Raman
Quoted 28 lines · * Jagannathan Raman ([email protected]) wrote:

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       | 44 ++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 72 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 scripts/hxtool
hmp-commands-info.hx +1 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
         .params     = "",
         .help       = "show the version of QEMU",
         .cmd        = hmp_info_version,
+        .targets    = "scsi",
         .flags      = "p",
     },
 

hmp-commands-info.hx ETEXI · line 52

Quoted 4 lines
hmp-commands-info.hx +1 -0
@@ -48,6 +49,7 @@ ETEXI
         .params     = "",
         .help       = "show the character devices",
         .cmd        = hmp_info_chardev,
+        .targets    = "scsi",

I'm a bit confused what this means; is this saying that the scsi-remote will respond to 'info chardev' ? Why would it be interested in info chardev?

Quoted 254 lines
hmp-commands-info.hx +8 -0
         .flags      = "p",
     },
 
@@ -64,6 +66,7 @@ ETEXI
         .help       = "show info of one block device or all block devices "
                       "(-n: show named nodes; -v: show details)",
         .cmd        = hmp_info_block,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -78,6 +81,7 @@ ETEXI
         .params     = "",
         .help       = "show block device statistics",
         .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -92,6 +96,7 @@ ETEXI
         .params     = "",
         .help       = "show progress of ongoing block device operations",
         .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -167,6 +172,7 @@ ETEXI
         .params     = "",
         .help       = "show the command line history",
         .cmd        = hmp_info_history,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -224,6 +230,7 @@ ETEXI
         .params     = "",
         .help       = "show PCI info",
         .cmd        = hmp_info_pci,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -630,6 +637,7 @@ ETEXI
         .params     = "",
         .help       = "show device tree",
         .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -644,6 +652,7 @@ ETEXI
         .params     = "",
         .help       = "show qdev device model list",
         .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -658,6 +667,7 @@ ETEXI
         .params     = "[path]",
         .help       = "show QOM composition tree",
         .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
         .params     = "",
         .help       = "quit the emulator",
         .cmd        = hmp_quit,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -82,6 +83,7 @@ ETEXI
         .params     = "device size",
         .help       = "resize a block image",
         .cmd        = hmp_block_resize,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -99,6 +101,7 @@ ETEXI
         .params     = "device [speed [base]]",
         .help       = "copy data from a backing file into a block device",
         .cmd        = hmp_block_stream,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -113,6 +116,7 @@ ETEXI
         .params     = "device speed",
         .help       = "set maximum speed for a background block operation",
         .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -129,6 +133,7 @@ ETEXI
                       "\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",
     },
 
 STEXI
@@ -143,6 +148,7 @@ ETEXI
         .params     = "device",
         .help       = "stop an active background block operation",
         .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -158,6 +164,7 @@ ETEXI
         .params     = "device",
         .help       = "pause an active background block operation",
         .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -172,6 +179,7 @@ ETEXI
         .params     = "device",
         .help       = "resume a paused background block operation",
         .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -186,6 +194,7 @@ ETEXI
         .params     = "[-f] device",
         .help       = "eject a removable medium (use -f to force it)",
         .cmd        = hmp_eject,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -200,6 +209,7 @@ ETEXI
         .params     = "device",
         .help       = "remove host block device",
         .cmd        = hmp_drive_del,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -219,6 +229,7 @@ ETEXI
         .params     = "device filename [format [read-only-mode]]",
         .help       = "change a removable medium, optional format",
         .cmd        = hmp_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -732,6 +743,7 @@ ETEXI
         .help       = "add device, like -device on the command line",
         .cmd        = hmp_device_add,
         .command_completion = device_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -747,6 +759,7 @@ ETEXI
         .help       = "remove device",
         .cmd        = hmp_device_del,
         .command_completion = device_del_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                       "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",
     },
 STEXI
 @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                       "[,readonly=on|off][,copy-on-read=on|off]",
         .help       = "add drive to PCI storage controller",
         .cmd        = hmp_drive_add,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1816,6 +1831,7 @@ ETEXI
         .help       = "add chardev",
         .cmd        = hmp_chardev_add,
         .command_completion = chardev_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1831,6 +1847,7 @@ ETEXI
         .params     = "id args",
         .help       = "change chardev",
         .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1848,6 +1865,7 @@ ETEXI
         .help       = "remove chardev",
         .cmd        = hmp_chardev_remove,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1864,6 +1882,7 @@ ETEXI
         .help       = "send a break on chardev",
         .cmd        = hmp_chardev_send_break,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1940,6 +1959,7 @@ ETEXI
         .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 +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
             STEXI*|ETEXI*|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

scripts/hxtool hxtotexi() · line 96

Quoted 7 lines
scripts/hxtool +3 -1
@@ -84,16 +91,49 @@ hxtotexi()
             print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
             ;;
             *)
-            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 '.targetss'

One extra 's' ?

Quoted 46 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
             ;;
         esac
         line=$((line+1))
     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*)
+            ;;
+            STEXI*|ETEXI*) 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
+}
+
 case "$1" in
 "-h") hxtoh ;;
 "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
 *) exit 1 ;;
 esac
 
Signature · 1 line
1.8.3.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK