All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 00/50] Initial support for multi-process qemu
@ 2020-02-24 20:54 Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
                   ` (53 more replies)
  0 siblings, 54 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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 <john.g.johnson@oracle.com>
Jagannathan Raman <jag.raman@oracle.com>
Elena Ufimtseva <elena.ufimtseva@oracle.com>
Kanth Ghatraju <kanth.ghatraju@oracle.com>
Konrad Wilk <konrad.wilk@oracle.com>

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/qemu-devel@nongnu.org/msg566538.html
[3]: https://www.mail-archive.com/qemu-devel@nongnu.org/msg602285.html
[4]: https://www.mail-archive.com/qemu-devel@nongnu.org/msg624877.html
[5]: https://www.mail-archive.com/qemu-devel@nongnu.org/msg642000.html
[6]: https://www.mail-archive.com/qemu-devel@nongnu.org/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

-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 117+ messages in thread

* [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-03-03 19:51   ` Dr. David Alan Gilbert
  2020-02-24 20:54 ` [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers Jagannathan Raman
                   ` (52 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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(-)

diff --git a/exec.c b/exec.c
index c930040..e524185 100644
--- a/exec.c
+++ b/exec.c
@@ -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);
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 5e59a3d..1b9f489 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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);
diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
index e786266..4f57985 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -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);
 
diff --git a/memory.c b/memory.c
index aeaa8dc..131bc6c 100644
--- a/memory.c
+++ b/memory.c
@@ -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();
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 27dcccd..a28f702 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -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) {
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 5a291cc..bd221dd 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-03-29 16:45   ` Marc-André Lureau
  2020-02-24 20:54 ` [PATCH v5 03/50] multi-process: add a command line option for debug file Jagannathan Raman
                   ` (51 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Relocate machine_int and exit notifiers into common code

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 ------------------------------------------
 util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index dec64fc..2f37e2b 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -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;
 
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 92c7b3a..94a7b93 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -173,12 +173,6 @@ int icount_align_option;
 QemuUUID qemu_uuid;
 bool qemu_uuid_set;
 
-static NotifierList exit_notifiers =
-    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
-
-static NotifierList machine_init_done_notifiers =
-    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
-
 bool xen_allowed;
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
@@ -2324,21 +2318,6 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
     return mc;
 }
 
-void qemu_add_exit_notifier(Notifier *notify)
-{
-    notifier_list_add(&exit_notifiers, notify);
-}
-
-void qemu_remove_exit_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_exit_notifiers(void)
-{
-    notifier_list_notify(&exit_notifiers, NULL);
-}
-
 static const char *pid_file;
 static Notifier qemu_unlink_pidfile_notifier;
 
@@ -2349,27 +2328,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
     }
 }
 
-bool machine_init_done;
-
-void qemu_add_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_list_add(&machine_init_done_notifiers, notify);
-    if (machine_init_done) {
-        notify->notify(notify, NULL);
-    }
-}
-
-void qemu_remove_machine_init_done_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
-}
-
-static void qemu_run_machine_init_done_notifiers(void)
-{
-    machine_init_done = true;
-    notifier_list_notify(&machine_init_done_notifiers, NULL);
-}
-
 static const QEMUOption *lookup_opt(int argc, char **argv,
                                     const char **poptarg, int *poptind)
 {
diff --git a/util/notify.c b/util/notify.c
index 76bab21..0e7479b 100644
--- a/util/notify.c
+++ b/util/notify.c
@@ -15,6 +15,15 @@
 
 #include "qemu/osdep.h"
 #include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+
+bool machine_init_done;
+
+static NotifierList machine_init_done_notifiers =
+    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
+
+static NotifierList exit_notifiers =
+    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
 
 void notifier_list_init(NotifierList *list)
 {
@@ -74,3 +83,37 @@ int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
     }
     return ret;
 }
+
+void qemu_add_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_list_add(&machine_init_done_notifiers, notify);
+    if (machine_init_done) {
+        notify->notify(notify, NULL);
+    }
+}
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_machine_init_done_notifiers(void)
+{
+    machine_init_done = true;
+    notifier_list_notify(&machine_init_done_notifiers, NULL);
+}
+
+void qemu_add_exit_notifier(Notifier *notify)
+{
+    notifier_list_add(&exit_notifiers, notify);
+}
+
+void qemu_remove_exit_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
+
+void qemu_run_exit_notifiers(void)
+{
+    notifier_list_notify(&exit_notifiers, NULL);
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 03/50] multi-process: add a command line option for debug file
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 04/50] multi-process: Add stub functions to facilate build of multi-process Jagannathan Raman
                   ` (50 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/qemu/log.h | 1 +
 util/log.c         | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/qemu/log.h b/include/qemu/log.h
index f4724f7..a039ddb 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -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
diff --git a/util/log.c b/util/log.c
index 2da6cb3..1f90e70 100644
--- a/util/log.c
+++ b/util/log.c
@@ -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 },
 };
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 04/50] multi-process: Add stub functions to facilate build of multi-process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (2 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 03/50] multi-process: add a command line option for debug file Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU Jagannathan Raman
                   ` (49 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
index 82f118d..baa6b38 100644
--- a/accel/stubs/kvm-stub.c
+++ b/accel/stubs/kvm-stub.c
@@ -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();
diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c
index 677191a..9b55fb0 100644
--- a/accel/stubs/tcg-stub.c
+++ b/accel/stubs/tcg-stub.c
@@ -11,14 +11,111 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "cpu.h"
 #include "tcg/tcg.h"
 #include "exec/exec-all.h"
+#include "translate-all.h"
+#include "exec/ram_addr.h"
+
+bool parallel_cpus;
 
 void tb_flush(CPUState *cpu)
 {
 }
 
+void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr)
+{
+}
+
+void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end)
+{
+}
+
+void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end)
+{
+}
+
+void tb_invalidate_phys_page_fast(struct page_collection *pages,
+                                  tb_page_addr_t start, int len,
+                                  uintptr_t retaddr)
+{
+}
+
+void tlb_init(CPUState *cpu)
+{
+}
+
 void tlb_set_dirty(CPUState *cpu, target_ulong vaddr)
 {
 }
+
+void tlb_flush(CPUState *cpu)
+{
+}
+
+void tlb_flush_page(CPUState *cpu, target_ulong addr)
+{
+}
+
+void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length)
+{
+}
+
+void tcg_region_init(void)
+{
+}
+
+void tcg_register_thread(void)
+{
+}
+
+void tcg_flush_softmmu_tlb(CPUState *cs)
+{
+}
+
+void cpu_loop_exit_noexc(CPUState *cpu)
+{
+    cpu->exception_index = -1;
+    cpu_loop_exit(cpu);
+}
+
+void cpu_loop_exit(CPUState *cpu)
+{
+    cpu->can_do_io = 1;
+    siglongjmp(cpu->jmp_env, 1);
+}
+
+void cpu_reloading_memory_map(void)
+{
+}
+
+int cpu_exec(CPUState *cpu)
+{
+    return 0;
+}
+
+void cpu_exec_step_atomic(CPUState *cpu)
+{
+}
+
+bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit)
+{
+    return false;
+}
+
+void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
+{
+    while (1) {
+    }
+}
+
+struct page_collection *
+page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)
+{
+    return NULL;
+}
+
+void page_collection_unlock(struct page_collection *set)
+{
+}
diff --git a/stubs/audio.c b/stubs/audio.c
new file mode 100644
index 0000000..8ae3b0f
--- /dev/null
+++ b/stubs/audio.c
@@ -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;
+}
diff --git a/stubs/machine-init-done.c b/stubs/machine-init-done.c
index cd8e813..3deabc9 100644
--- a/stubs/machine-init-done.c
+++ b/stubs/machine-init-done.c
@@ -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)
+{
+}
diff --git a/stubs/monitor.c b/stubs/monitor.c
index c3e9a2e..a34dc87 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -2,9 +2,19 @@
 #include "qapi/error.h"
 #include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
+#include "qapi/qapi-types-misc.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/qapi-types-qom.h"
+#include "qapi/qapi-commands-qdev.h"
+#include "hw/qdev-core.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
+#include "monitor/hmp.h"
 
 __thread Monitor *cur_mon;
 
+#pragma weak hmp_handle_error
+
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
     abort();
@@ -27,3 +37,34 @@ void monitor_init_hmp(Chardev *chr, bool use_readline)
 void qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
 }
+
+int monitor_get_cpu_index(void)
+{
+    return -ENOSYS;
+}
+int monitor_printf(Monitor *mon, const char *fmt, ...)
+{
+    return -ENOSYS;
+}
+
+bool monitor_cur_is_qmp(void)
+{
+    return false;
+}
+
+ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
+                                                   Error **errp)
+{
+    return NULL;
+}
+
+VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
+                                                     VMChangeStateHandler *cb,
+                                                     void *opaque)
+{
+    return NULL;
+}
+
+void hmp_handle_error(Monitor *mon, Error *err)
+{
+}
diff --git a/stubs/net-stub.c b/stubs/net-stub.c
new file mode 100644
index 0000000..cb2274b
--- /dev/null
+++ b/stubs/net-stub.c
@@ -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;
+}
+
diff --git a/stubs/replay.c b/stubs/replay.c
index 5974ec1..2e3feee 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -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)
+{
+}
diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
new file mode 100644
index 0000000..fff72be
--- /dev/null
+++ b/stubs/vl-stub.c
@@ -0,0 +1,79 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/uuid.h"
+#include "sysemu/sysemu.h"
+#include "exec/cpu-common.h"
+#include "exec/gdbstub.h"
+#include "sysemu/replay.h"
+#include "disas/disas.h"
+#include "sysemu/runstate.h"
+
+bool tcg_allowed;
+bool xen_allowed;
+bool boot_strict;
+bool qemu_uuid_set;
+
+int mem_prealloc;
+int smp_cpus;
+int vga_interface_type = VGA_NONE;
+int smp_cores = 1;
+int smp_threads = 1;
+int icount_align_option;
+int boot_menu;
+
+unsigned int max_cpus;
+const uint32_t arch_type;
+const char *mem_path;
+uint8_t qemu_extra_params_fw[2];
+uint8_t *boot_splash_filedata;
+size_t boot_splash_filedata_size;
+struct syminfo *syminfos;
+
+ram_addr_t ram_size;
+MachineState *current_machine;
+QemuUUID qemu_uuid;
+
+int runstate_is_running(void)
+{
+    return 0;
+}
+
+void runstate_set(RunState new_state)
+{
+}
+
+void vm_state_notify(int running, RunState state)
+{
+}
+
+bool qemu_vmstop_requested(RunState *r)
+{
+    return false;
+}
+
+void qemu_system_debug_request(void)
+{
+}
+
+char *qemu_find_file(int type, const char *name)
+{
+    return NULL;
+}
+
+void gdb_set_stop_cpu(CPUState *cpu)
+{
+}
+
+void replay_enable_events(void)
+{
+}
+
+void replay_disable_events(void)
+{
+}
+
+#ifdef TARGET_I386
+void x86_cpu_list(void)
+{
+}
+#endif
diff --git a/stubs/vmstate.c b/stubs/vmstate.c
index cc4fe41..c7c015a 100644
--- a/stubs/vmstate.c
+++ b/stubs/vmstate.c
@@ -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;
+}
diff --git a/stubs/xen-mapcache.c b/stubs/xen-mapcache.c
new file mode 100644
index 0000000..af5c031
--- /dev/null
+++ b/stubs/xen-mapcache.c
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (3 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 04/50] multi-process: Add stub functions to facilate build of multi-process Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 06/50] multi-process: build system for remote device process Jagannathan Raman
                   ` (48 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Add a configuration option to separate multi-process code

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/configure b/configure
index 48d6f89..ab1e344 100755
--- a/configure
+++ b/configure
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 06/50] multi-process: build system for remote device process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (4 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-02-24 20:54 ` [PATCH v5 07/50] multi-process: define mpqemu-link object Jagannathan Raman
                   ` (47 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/Makefile b/Makefile
index 15f8e53..f91dcb9 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
 
diff --git a/Makefile.objs b/Makefile.objs
index 8a1cbe8..c80e107 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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/
diff --git a/Makefile.target b/Makefile.target
index 2d43dc5..375fdaa 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -36,7 +36,17 @@ QEMU_PROG_BUILD = $(QEMU_PROG)
 endif
 endif
 
+ifdef CONFIG_MPQEMU
+SCSI_DEV_PROG=qemu-scsi-dev
+SCSI_DEV_BUILD = $(SCSI_DEV_PROG)
+endif
+
 PROGS=$(QEMU_PROG) $(QEMU_PROGW)
+
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+PROGS += $(SCSI_DEV_PROG)
+endif
+
 STPFILES=
 
 config-target.h: config-target.h-timestamp
@@ -121,6 +131,20 @@ LIBS := $(libs_cpu) $(LIBS)
 
 obj-$(CONFIG_PLUGIN) += plugins/
 
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/tcg-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+endif
+
 #########################################################
 # Linux user emulator target
 
@@ -178,6 +202,20 @@ endif # CONFIG_SOFTMMU
 dummy := $(call unnest-vars,,obj-y)
 all-obj-y := $(obj-y)
 
+dummy := $(call unnest-vars,..,remote-pci-tgt-obj-y)
+all-remote-pci-obj-y := $(remote-pci-tgt-obj-y)
+
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+all-remote-pci-obj-y += memory.o
+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
+endif
+
+remote-pci-obj-y :=
+remote-lsi-obj-y :=
+
 include $(SRC_PATH)/Makefile.objs
 dummy := $(call unnest-vars,.., \
                authz-obj-y \
@@ -188,7 +226,10 @@ dummy := $(call unnest-vars,.., \
                qom-obj-y \
                io-obj-y \
                common-obj-y \
-               common-obj-m)
+               common-obj-m \
+               remote-pci-obj-y \
+               remote-lsi-obj-y)
+
 all-obj-y += $(common-obj-y)
 all-obj-y += $(qom-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
@@ -196,8 +237,19 @@ all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
 
+all-remote-pci-obj-y += $(authz-obj-y)
+all-remote-pci-obj-y += $(block-obj-y)
+all-remote-pci-obj-y += $(crypto-obj-y)
+all-remote-pci-obj-y += $(io-obj-y)
+all-remote-pci-obj-y += $(chardev-obj-y)
+all-remote-pci-obj-y += $(remote-pci-obj-y)
+
+
+all-remote-lsi-obj-y += $(all-remote-pci-obj-y) $(remote-lsi-obj-y)
+
 ifdef CONFIG_SOFTMMU
 $(QEMU_PROG_BUILD): config-devices.mak
+$(SCSI_DEV_BUILD): config-devices.mak
 endif
 
 COMMON_LDADDS = ../libqemuutil.a
@@ -210,6 +262,13 @@ ifdef CONFIG_DARWIN
 	$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
 endif
 
+$(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS)
+	$(call LINK, $(filter-out %.mak, $^))
+ifdef CONFIG_DARWIN
+	$(call quiet-command,Rez -append $(SRC_PATH)/pc-bios/qemu.rsrc -o $@,"REZ","$(TARGET_DIR)$@")
+	$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
+endif
+
 gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
 	$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"GEN","$(TARGET_DIR)$@")
 
diff --git a/accel/Makefile.objs b/accel/Makefile.objs
index 17e5ac6..e312dd4 100644
--- a/accel/Makefile.objs
+++ b/accel/Makefile.objs
@@ -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
diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 28a847c..947cde3 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -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
diff --git a/block/Makefile.objs b/block/Makefile.objs
index 3bcb35c..6398613 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -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
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 660e2b4..af9235b 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -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/
diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs
index 4b4a2b3..0b4644f 100644
--- a/hw/block/Makefile.objs
+++ b/hw/block/Makefile.objs
@@ -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
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 6215e7c..e3e8084 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -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
diff --git a/hw/nvram/Makefile.objs b/hw/nvram/Makefile.objs
index f3ad921..4d2d809 100644
--- a/hw/nvram/Makefile.objs
+++ b/hw/nvram/Makefile.objs
@@ -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
diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
index c78f2fb..955be54 100644
--- a/hw/pci/Makefile.objs
+++ b/hw/pci/Makefile.objs
@@ -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
diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs
index 54b36ed..ef97770 100644
--- a/hw/scsi/Makefile.objs
+++ b/hw/scsi/Makefile.objs
@@ -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
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index d3623d5..e7cdc76 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -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
diff --git a/qom/Makefile.objs b/qom/Makefile.objs
index f9d7735..07e50e5 100644
--- a/qom/Makefile.objs
+++ b/qom/Makefile.objs
@@ -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
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
new file mode 100644
index 0000000..a9b2256
--- /dev/null
+++ b/remote/Makefile.objs
@@ -0,0 +1 @@
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
diff --git a/remote/remote-main.c b/remote/remote-main.c
new file mode 100644
index 0000000..7c0764a
--- /dev/null
+++ b/remote/remote-main.c
@@ -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;
+}
diff --git a/stubs/replay.c b/stubs/replay.c
index 2e3feee..9b53c0c 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -102,3 +102,7 @@ int replay_get_instructions(void)
 void replay_account_executed_instructions(void)
 {
 }
+
+void replay_add_blocker(Error *reason)
+{
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 07/50] multi-process: define mpqemu-link object
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (5 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 06/50] multi-process: build system for remote device process Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-03-10 16:09   ` Stefan Hajnoczi
  2020-02-24 20:54 ` [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints Jagannathan Raman
                   ` (46 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
new file mode 100644
index 0000000..2f2dd83
--- /dev/null
+++ b/include/io/mpqemu-link.h
@@ -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
diff --git a/io/Makefile.objs b/io/Makefile.objs
index 9a20fce..5875ab0 100644
--- a/io/Makefile.objs
+++ b/io/Makefile.objs
@@ -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
diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
new file mode 100644
index 0000000..bac120b
--- /dev/null
+++ b/io/mpqemu-link.c
@@ -0,0 +1,294 @@
+/*
+ * 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.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "qemu/module.h"
+#include "io/mpqemu-link.h"
+#include "qemu/log.h"
+
+GSourceFuncs gsrc_funcs;
+
+/*
+ * TODO: make all communications asynchronous and run in the main
+ * loop or existing IOThread.
+ */
+
+static void mpqemu_link_inst_init(Object *obj)
+{
+    MPQemuLinkState *s = MPQEMU_LINK(obj);
+
+    s->ctx = g_main_context_default();
+    s->loop = g_main_loop_new(s->ctx, FALSE);
+}
+
+static const TypeInfo mpqemu_link_info = {
+    .name = TYPE_MPQEMU_LINK,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(MPQemuLinkState),
+    .instance_init = mpqemu_link_inst_init,
+};
+
+static void mpqemu_link_register_types(void)
+{
+    type_register_static(&mpqemu_link_info);
+}
+
+type_init(mpqemu_link_register_types)
+
+MPQemuLinkState *mpqemu_link_create(void)
+{
+    return MPQEMU_LINK(object_new(TYPE_MPQEMU_LINK));
+}
+
+void mpqemu_link_finalize(MPQemuLinkState *s)
+{
+    g_main_loop_unref(s->loop);
+    g_main_context_unref(s->ctx);
+    g_main_loop_quit(s->loop);
+
+    mpqemu_destroy_channel(s->com);
+
+    object_unref(OBJECT(s));
+}
+
+void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->send_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;
+    hdr.msg_iovlen = 1;
+
+    if (msg->num_fds > REMOTE_MAX_FDS) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
+        return;
+    }
+
+    if (msg->num_fds > 0) {
+        size_t fdsize = msg->num_fds * sizeof(int);
+
+        hdr.msg_control = &u;
+        hdr.msg_controllen = sizeof(u);
+
+        chdr = CMSG_FIRSTHDR(&hdr);
+        chdr->cmsg_len = CMSG_LEN(fdsize);
+        chdr->cmsg_level = SOL_SOCKET;
+        chdr->cmsg_type = SCM_RIGHTS;
+        memcpy(CMSG_DATA(chdr), msg->fds, fdsize);
+        hdr.msg_controllen = CMSG_SPACE(fdsize);
+    }
+
+    qemu_mutex_lock(lock);
+
+    do {
+        rc = sendmsg(sock, &hdr, 0);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    if (rc < 0) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d,"
+                      " sock %d\n", __func__, rc, errno, sock);
+        qemu_mutex_unlock(lock);
+        return;
+    }
+
+    if (msg->bytestream) {
+        data = msg->data2;
+    } else {
+        data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE;
+    }
+
+    do {
+        rc = write(sock, data, msg->size);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    qemu_mutex_unlock(lock);
+}
+
+
+int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
+{
+    int rc;
+    uint8_t *data;
+    union {
+        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
+        struct cmsghdr align;
+    } u;
+    struct msghdr hdr;
+    struct cmsghdr *chdr;
+    size_t fdsize;
+    int sock = chan->sock;
+    QemuMutex *lock = &chan->recv_lock;
+
+    struct iovec iov = {
+        .iov_base = (char *) msg,
+        .iov_len = MPQEMU_MSG_HDR_SIZE,
+    };
+
+    memset(&hdr, 0, sizeof(hdr));
+    memset(&u, 0, sizeof(u));
+
+    hdr.msg_iov = &iov;
+    hdr.msg_iovlen = 1;
+    hdr.msg_control = &u;
+    hdr.msg_controllen = sizeof(u);
+
+    qemu_mutex_lock(lock);
+
+    do {
+        rc = recvmsg(sock, &hdr, 0);
+    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+
+    if (rc < 0) {
+        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - recvmsg rc is %d, errno is %d,"
+                      " sock %d\n", __func__, rc, errno, sock);
+        qemu_mutex_unlock(lock);
+        return rc;
+    }
+
+    msg->num_fds = 0;
+    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
+         chdr = CMSG_NXTHDR(&hdr, chdr)) {
+        if ((chdr->cmsg_level == SOL_SOCKET) &&
+            (chdr->cmsg_type == SCM_RIGHTS)) {
+            fdsize = chdr->cmsg_len - CMSG_LEN(0);
+            msg->num_fds = fdsize / sizeof(int);
+            if (msg->num_fds > REMOTE_MAX_FDS) {
+                /*
+                 * TODO: Security issue detected. Sender never sends more
+                 * than REMOTE_MAX_FDS. This condition should be signaled to
+                 * the admin
+                 */
+                qemu_log_mask(LOG_REMOTE_DEBUG,
+                              "%s: Max FDs exceeded\n", __func__);
+                return -ERANGE;
+            }
+
+            memcpy(msg->fds, CMSG_DATA(chdr), fdsize);
+            break;
+        }
+    }
+
+    if (msg->bytestream) {
+        if (!msg->size) {
+            qemu_mutex_unlock(lock);
+            return -EINVAL;
+        }
+
+        msg->data2 = calloc(1, msg->size);
+        data = msg->data2;
+    } else {
+        data = (uint8_t *)&msg->data1;
+    }
+
+    if (msg->size) {
+        do {
+            rc = read(sock, data, msg->size);
+        } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
+    }
+
+    qemu_mutex_unlock(lock);
+
+    return rc;
+}
+
+static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
+{
+    g_assert(timeout);
+
+    *timeout = -1;
+
+    return FALSE;
+}
+
+static gboolean mpqemu_link_handler_check(GSource *gsrc)
+{
+    MPQemuChannel *chan = (MPQemuChannel *)gsrc;
+
+    return chan->gpfd.events & chan->gpfd.revents;
+}
+
+static gboolean mpqemu_link_handler_dispatch(GSource *gsrc, GSourceFunc func,
+                                             gpointer data)
+{
+    MPQemuLinkState *s = (MPQemuLinkState *)data;
+    MPQemuChannel *chan = (MPQemuChannel *)gsrc;
+
+    s->callback(chan->gpfd.revents, chan);
+
+    if ((chan->gpfd.revents & G_IO_HUP) || (chan->gpfd.revents & G_IO_ERR)) {
+        return G_SOURCE_REMOVE;
+    }
+
+    return G_SOURCE_CONTINUE;
+}
+
+void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback)
+{
+    s->callback = callback;
+}
+
+void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd)
+{
+    MPQemuChannel *src;
+
+    gsrc_funcs = (GSourceFuncs){
+        .prepare = mpqemu_link_handler_prepare,
+        .check = mpqemu_link_handler_check,
+        .dispatch = mpqemu_link_handler_dispatch,
+        .finalize = NULL,
+    };
+
+    src = (MPQemuChannel *)g_source_new(&gsrc_funcs, sizeof(MPQemuChannel));
+
+    src->sock = fd;
+    qemu_mutex_init(&src->send_lock);
+    qemu_mutex_init(&src->recv_lock);
+
+    g_source_set_callback(&src->gsrc, NULL, (gpointer)s, NULL);
+    src->gpfd.fd = fd;
+    src->gpfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+    g_source_add_poll(&src->gsrc, &src->gpfd);
+
+    *chan = src;
+}
+
+void mpqemu_destroy_channel(MPQemuChannel *chan)
+{
+    g_source_unref(&chan->gsrc);
+    close(chan->sock);
+    qemu_mutex_destroy(&chan->send_lock);
+    qemu_mutex_destroy(&chan->recv_lock);
+}
+
+void mpqemu_start_coms(MPQemuLinkState *s)
+{
+
+    g_assert(g_source_attach(&s->com->gsrc, s->ctx));
+
+    g_main_loop_run(s->loop);
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (6 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 07/50] multi-process: define mpqemu-link object Jagannathan Raman
@ 2020-02-24 20:54 ` Jagannathan Raman
  2020-03-03 19:56   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device Jagannathan Raman
                   ` (45 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 include/io/mpqemu-link.h |  7 +++++++
 io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 2f2dd83..ae04fca 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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
diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
index bac120b..73b7032 100644
--- a/io/mpqemu-link.c
+++ b/io/mpqemu-link.c
@@ -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);
+
+    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;
+    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);
+
+    return val;
+}
+
+void notify_proxy(int efd, uint64_t val)
+{
+    val = (val == ULLONG_MAX) ? val : (val + 1);
+
+    if (write(efd, &val, sizeof(val)) == -1) {
+        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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (7 preceding siblings ...)
  2020-02-24 20:54 ` [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 10/50] multi-process: setup a machine object for remote device process Jagannathan Raman
                   ` (44 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
index 955be54..90693a7 100644
--- a/hw/pci/Makefile.objs
+++ b/hw/pci/Makefile.objs
@@ -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
diff --git a/include/remote/pcihost.h b/include/remote/pcihost.h
new file mode 100644
index 0000000..7aca9cc
--- /dev/null
+++ b/include/remote/pcihost.h
@@ -0,0 +1,45 @@
+/*
+ * PCI Host for remote device
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_PCIHOST_H
+#define REMOTE_PCIHOST_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "exec/memory.h"
+#include "hw/pci/pcie_host.h"
+
+#define TYPE_REMOTE_HOST_DEVICE "remote-pcihost"
+#define REMOTE_HOST_DEVICE(obj) \
+    OBJECT_CHECK(RemPCIHost, (obj), TYPE_REMOTE_HOST_DEVICE)
+
+typedef struct RemPCIHost {
+    /*< private >*/
+    PCIExpressHost parent_obj;
+    /*< public >*/
+
+    /*
+     * Memory Controller Hub (MCH) may not be necessary for the emulation
+     * program. The two important reasons for implementing a PCI host in the
+     * emulation program are:
+     * - Provide a PCI bus for IO devices
+     * - Enable translation of guest PA to the PCI bar regions
+     *
+     * For both the above mentioned purposes, it doesn't look like we would
+     * need the MCH
+     */
+
+    MemoryRegion *mr_pci_mem;
+    MemoryRegion *mr_sys_mem;
+    MemoryRegion *mr_sys_io;
+} RemPCIHost;
+
+#endif
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index a9b2256..2757f5a 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -1 +1,2 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
diff --git a/remote/pcihost.c b/remote/pcihost.c
new file mode 100644
index 0000000..dbe0819
--- /dev/null
+++ b/remote/pcihost.c
@@ -0,0 +1,64 @@
+/*
+ * Remote PCI host 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.
+ *
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci/pcie_host.h"
+#include "hw/qdev-properties.h"
+#include "remote/pcihost.h"
+#include "exec/memory.h"
+
+static const char *remote_host_root_bus_path(PCIHostState *host_bridge,
+                                             PCIBus *rootbus)
+{
+    return "0000:00";
+}
+
+static void remote_host_realize(DeviceState *dev, Error **errp)
+{
+    char *busname = g_strdup_printf("remote-pci-%ld", (unsigned long)getpid());
+    PCIHostState *pci = PCI_HOST_BRIDGE(dev);
+    RemPCIHost *s = REMOTE_HOST_DEVICE(dev);
+
+    pci->bus = pci_root_bus_new(DEVICE(s), busname,
+                                s->mr_pci_mem, s->mr_sys_io,
+                                0, TYPE_PCIE_BUS);
+}
+
+static void remote_host_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
+
+    hc->root_bus_path = remote_host_root_bus_path;
+    dc->realize = remote_host_realize;
+
+    dc->user_creatable = false;
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+    dc->fw_name = "pci";
+}
+
+static const TypeInfo remote_host_info = {
+    .name = TYPE_REMOTE_HOST_DEVICE,
+    .parent = TYPE_PCIE_HOST_BRIDGE,
+    .instance_size = sizeof(RemPCIHost),
+    .class_init = remote_host_class_init,
+};
+
+static void remote_machine_register(void)
+{
+    type_register_static(&remote_host_info);
+}
+
+type_init(remote_machine_register)
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 10/50] multi-process: setup a machine object for remote device process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (8 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 11/50] multi-process: setup memory manager for remote device Jagannathan Raman
                   ` (43 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/Makefile.objs b/Makefile.objs
index c80e107..aad33fc 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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
diff --git a/exec.c b/exec.c
index e524185..b4c9cc6 100644
--- a/exec.c
+++ b/exec.c
@@ -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));
 
diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h
index db8bfa9..56a877b 100644
--- a/include/exec/address-spaces.h
+++ b/include/exec/address-spaces.h
@@ -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;
 
diff --git a/include/remote/machine.h b/include/remote/machine.h
new file mode 100644
index 0000000..7e9bdbe
--- /dev/null
+++ b/include/remote/machine.h
@@ -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
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index 2757f5a..13d4c48 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -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
diff --git a/remote/machine.c b/remote/machine.c
new file mode 100644
index 0000000..97e4f19
--- /dev/null
+++ b/remote/machine.c
@@ -0,0 +1,84 @@
+/*
+ * Machine 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.
+ *
+ */
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#include "exec/address-spaces.h"
+#include "exec/memory.h"
+#include "exec/ioport.h"
+#include "qemu/thread.h"
+#include "qom/object.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "qemu/main-loop.h"
+#include "qemu-common.h"
+#include "sysemu/sysemu.h"
+#include "qemu/notify.h"
+
+static void remote_machine_init(Object *obj)
+{
+    RemMachineState *s = REMOTE_MACHINE(obj);
+    RemPCIHost *rem_host;
+    MemoryRegion *system_memory, *system_io, *pci_memory;
+
+    Error *error_abort = NULL;
+
+    object_property_add_child(object_get_root(), "machine", obj, &error_abort);
+    if (error_abort) {
+        error_report_err(error_abort);
+    }
+
+    memory_map_init();
+
+    system_memory = get_system_memory();
+    system_io = get_system_io();
+
+    pci_memory = g_new(MemoryRegion, 1);
+    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+
+    rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE));
+
+    rem_host->mr_pci_mem = pci_memory;
+    rem_host->mr_sys_mem = system_memory;
+    rem_host->mr_sys_io = system_io;
+
+    s->host = rem_host;
+
+    object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host),
+                              &error_abort);
+    if (error_abort) {
+        error_report_err(error_abort);
+        return;
+    }
+
+    qemu_mutex_lock_iothread();
+    memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1);
+    qemu_mutex_unlock_iothread();
+
+    qdev_init_nofail(DEVICE(rem_host));
+}
+
+static const TypeInfo remote_machine = {
+    .name = TYPE_REMOTE_MACHINE,
+    .parent = TYPE_MACHINE,
+    .instance_size = sizeof(RemMachineState),
+    .instance_init = remote_machine_init,
+};
+
+static void remote_machine_register_types(void)
+{
+    type_register_static(&remote_machine);
+}
+
+type_init(remote_machine_register_types);
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 7c0764a..ecf30e0 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
 }
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 6b38b67..80b2067 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 11/50] multi-process: setup memory manager for remote device
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (9 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 10/50] multi-process: setup a machine object for remote device process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 12/50] multi-process: remote process initialization Jagannathan Raman
                   ` (42 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/Makefile.target b/Makefile.target
index 375fdaa..cfd36c1 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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
 
 #########################################################
diff --git a/exec.c b/exec.c
index b4c9cc6..8e77c4c 100644
--- a/exec.c
+++ b/exec.c
@@ -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
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 1b9f489..d9d7314 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -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);
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index ae04fca..78c0818 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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];
diff --git a/include/remote/memory.h b/include/remote/memory.h
new file mode 100644
index 0000000..e2e479b
--- /dev/null
+++ b/include/remote/memory.h
@@ -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
diff --git a/remote/memory.c b/remote/memory.c
new file mode 100644
index 0000000..2c8b7bb
--- /dev/null
+++ b/remote/memory.c
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ *
+ */
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "qemu/queue.h"
+#include "qemu-common.h"
+#include "remote/memory.h"
+#include "exec/memory.h"
+#include "exec/address-spaces.h"
+#include "cpu.h"
+#include "exec/ram_addr.h"
+#include "io/mpqemu-link.h"
+#include "qemu/main-loop.h"
+#include "qapi/error.h"
+
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
+{
+    sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem;
+    MemoryRegion *sysmem, *subregion, *next;
+    Error *local_err = NULL;
+    int region;
+
+    sysmem = get_system_memory();
+
+    qemu_mutex_lock_iothread();
+
+    memory_region_transaction_begin();
+
+    QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) {
+        if (subregion->ram) {
+            memory_region_del_subregion(sysmem, subregion);
+            qemu_ram_free(subregion->ram_block);
+        }
+    }
+
+    for (region = 0; region < msg->num_fds; region++) {
+        subregion = g_new(MemoryRegion, 1);
+        qemu_ram_init_from_fd(subregion, msg->fds[region],
+                              sysmem_info->sizes[region],
+                              sysmem_info->offsets[region], &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            break;
+        }
+
+        memory_region_add_subregion(sysmem, sysmem_info->gpas[region],
+                                    subregion);
+    }
+
+    memory_region_transaction_commit();
+
+    qemu_mutex_unlock_iothread();
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 12/50] multi-process: remote process initialization
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (10 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 11/50] multi-process: setup memory manager for remote device Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-04 10:29   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 13/50] multi-process: introduce proxy object Jagannathan Raman
                   ` (41 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(+)

diff --git a/remote/remote-main.c b/remote/remote-main.c
index ecf30e0..56315cd 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
 }
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 13/50] multi-process: introduce proxy object
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (11 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 12/50] multi-process: remote process initialization Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 14/50] mutli-process: build remote command line args Jagannathan Raman
                   ` (40 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index af9235b..7b489b1 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -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/
diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs
new file mode 100644
index 0000000..eb81624
--- /dev/null
+++ b/hw/proxy/Makefile.objs
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
new file mode 100644
index 0000000..828bbd7
--- /dev/null
+++ b/hw/proxy/qemu-proxy.c
@@ -0,0 +1,226 @@
+/*
+ * 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 "qapi/error.h"
+#include "io/mpqemu-link.h"
+#include "exec/memory.h"
+#include "exec/cpu-common.h"
+#include "exec/address-spaces.h"
+#include "hw/pci/pci.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qstring.h"
+#include "hw/proxy/qemu-proxy.h"
+
+static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
+
+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;
+    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;
+    }
+
+    if (!exec_name) {
+        error_setg(errp, "The remote exec name is NULL.");
+        return rc;
+    }
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
+        error_setg(errp, "Unable to create unix socket.");
+        return -1;
+    }
+    /* 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;
+    }
+
+    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);
+        exit(1);
+    }
+    pdev->remote_pid = rpid;
+
+    close(fd[1]);
+
+    return 0;
+}
+
+static int get_proxy_sock(PCIDevice *dev)
+{
+    PCIProxyDev *pdev;
+
+    pdev = PCI_PROXY_DEV(dev);
+
+    return pdev->socket;
+}
+
+static void set_proxy_sock(PCIDevice *dev, int socket)
+{
+    PCIProxyDev *pdev;
+
+    pdev = PCI_PROXY_DEV(dev);
+
+    pdev->socket = socket;
+    pdev->managed = true;
+}
+
+static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
+                          unsigned int op)
+{
+    MPQemuMsg msg;
+    struct conf_data_msg conf_data;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    conf_data.addr = addr;
+    conf_data.val = (op == PCI_CONFIG_WRITE) ? *val : 0;
+    conf_data.l = l;
+
+    msg.data2 = (uint8_t *)&conf_data;
+    if (!msg.data2) {
+        return -ENOMEM;
+    }
+
+    msg.size = sizeof(conf_data);
+    msg.cmd = op;
+    msg.bytestream = 1;
+
+    if (op == PCI_CONFIG_WRITE) {
+        msg.num_fds = 0;
+    } else {
+        /* TODO: Dont create fd each time for send. */
+        wait = GET_REMOTE_WAIT;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->com);
+
+    if (op == PCI_CONFIG_READ) {
+        *val = (uint32_t)wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+
+    return 0;
+}
+
+static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len)
+{
+    uint32_t val;
+
+    (void)pci_default_read_config(d, addr, len);
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, len, PCI_CONFIG_READ);
+
+    return val;
+}
+
+static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,
+                                   int l)
+{
+    pci_default_write_config(d, addr, val, l);
+
+    config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE);
+}
+
+static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->realize = pci_proxy_dev_realize;
+    k->config_read = pci_proxy_read_config;
+    k->config_write = pci_proxy_write_config;
+}
+
+static const TypeInfo pci_proxy_dev_type_info = {
+    .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[]) {
+        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { },
+    },
+};
+
+static void pci_proxy_dev_register_types(void)
+{
+    type_register_static(&pci_proxy_dev_type_info);
+}
+
+type_init(pci_proxy_dev_register_types)
+
+static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
+                       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;
+        }
+    } else {
+        pdev->remote_pid = atoi(pdev->rid);
+        if (pdev->remote_pid == -1) {
+            error_setg(errp, "Remote PID is -1");
+            return;
+        }
+    }
+
+    pdev->mpqemu_link = mpqemu_link_create();
+
+    if (!pdev->mpqemu_link) {
+        error_setg(errp, "Failed to create proxy link");
+        return;
+    }
+
+    mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
+                        pdev->socket);
+}
+
+static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(device);
+    PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    Error *local_err = NULL;
+
+    if (k->realize) {
+        k->realize(dev, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+        }
+    }
+
+    dev->set_proxy_sock = set_proxy_sock;
+    dev->get_proxy_sock = get_proxy_sock;
+    dev->init_proxy = init_proxy;
+}
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
new file mode 100644
index 0000000..28b0114
--- /dev/null
+++ b/include/hw/proxy/qemu-proxy.h
@@ -0,0 +1,54 @@
+/*
+ * 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 QEMU_PROXY_H
+#define QEMU_PROXY_H
+
+#include "io/mpqemu-link.h"
+
+#define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
+
+#define PCI_PROXY_DEV(obj) \
+            OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV)
+
+#define PCI_PROXY_DEV_CLASS(klass) \
+            OBJECT_CLASS_CHECK(PCIProxyDevClass, (klass), TYPE_PCI_PROXY_DEV)
+
+#define PCI_PROXY_DEV_GET_CLASS(obj) \
+            OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
+
+typedef struct PCIProxyDev {
+    PCIDevice parent_dev;
+
+    MPQemuLinkState *mpqemu_link;
+
+    pid_t remote_pid;
+    int socket;
+
+    char *rid;
+
+    bool managed;
+
+    void (*set_proxy_sock) (PCIDevice *dev, int socket);
+    int (*get_proxy_sock) (PCIDevice *dev);
+
+    void (*proxy_ready) (PCIDevice *dev);
+    void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
+                        Error **errp);
+
+} PCIProxyDev;
+
+typedef struct PCIProxyDevClass {
+    PCIDeviceClass parent_class;
+
+    void (*realize)(PCIProxyDev *dev, Error **errp);
+
+    char *command;
+} PCIProxyDevClass;
+
+#endif /* QEMU_PROXY_H */
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 78c0818..5a2be48 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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"
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 56315cd..7b4cf2f 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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");
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 14/50] mutli-process: build remote command line args
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (12 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 13/50] multi-process: introduce proxy object Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-02 17:36   ` Philippe Mathieu-Daudé
  2020-03-04 10:09   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
                   ` (39 subsequent siblings)
  53 siblings, 2 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 828bbd7..d792e86 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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);
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 28b0114..29fa2e9 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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;
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (13 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 14/50] mutli-process: build remote command line args Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-04 10:47   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 16/50] multi-process: Synchronize remote memory Jagannathan Raman
                   ` (38 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index d792e86..b17d9bb 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
+    },
+};
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 29fa2e9..44e370e 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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 */
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 5a2be48..1a7738e 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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];
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 7b4cf2f..acd8daf 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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)
+{
+    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));
+
+    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) {
+    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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 16/50] multi-process: Synchronize remote memory
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (14 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-04 11:53   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 17/50] multi-process: create IOHUB object to handle irq Jagannathan Raman
                   ` (37 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/Makefile.target b/Makefile.target
index cfd36c1..271d883 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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/
diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c
new file mode 100644
index 0000000..3edbb19
--- /dev/null
+++ b/hw/proxy/memory-sync.c
@@ -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;
+}
+
+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);
+
+    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)
+{
+    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);
+
+    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;
+    }
+
+    mrs_host = mrs_host & ~(mrs_page - 1);
+    mrs_gpa = mrs_gpa & ~(mrs_page - 1);
+    mrs_size = ROUND_UP(mrs_size, mrs_page);
+
+    if (sync->n_mr_sections) {
+        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
+        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
+        uint64_t prev_size = int128_get64(prev_sec->size);
+        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
+        uint64_t prev_host_start =
+            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
+            prev_sec->offset_within_region;
+        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);
+
+        if (mrs_gpa <= (prev_gpa_end + 1)) {
+            if (mrs_gpa < prev_gpa_start) {
+                assert(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));
+            }
+        }
+    }
+
+    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);
+    }
+}
+
+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];
+        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);
+        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);
+}
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index b17d9bb..d3a9d38 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h
new file mode 100644
index 0000000..d8329c9
--- /dev/null
+++ b/include/hw/proxy/memory-sync.h
@@ -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
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 44e370e..c93ffe3 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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;
 
diff --git a/remote/remote-main.c b/remote/remote-main.c
index acd8daf..9512a3b 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 17/50] multi-process: create IOHUB object to handle irq
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (15 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 16/50] multi-process: Synchronize remote memory Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 18/50] multi-process: configure remote side devices Jagannathan Raman
                   ` (36 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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

diff --git a/Makefile.target b/Makefile.target
index 271d883..c621d70 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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)
 
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 7b489b1..af9235b 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -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/
diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs
deleted file mode 100644
index eb81624..0000000
--- a/hw/proxy/Makefile.objs
+++ /dev/null
@@ -1 +0,0 @@
-common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index d3a9d38..0cf7dcc 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -18,6 +18,9 @@
 #include "hw/proxy/qemu-proxy.h"
 #include "hw/proxy/memory-sync.h"
 #include "qom/object.h"
+#include "qemu/event_notifier.h"
+#include "sysemu/kvm.h"
+#include "util/event_notifier-posix.c"
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
@@ -215,6 +218,53 @@ static void pci_proxy_dev_register_types(void)
 
 type_init(pci_proxy_dev_register_types)
 
+static void proxy_intx_update(PCIDevice *pci_dev)
+{
+    PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev);
+    PCIINTxRoute route;
+    int pin = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1;
+
+    if (dev->irqfd.fd) {
+        dev->irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN;
+        (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd);
+        memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd));
+    }
+
+    route = pci_device_route_intx_to_irq(pci_dev, pin);
+
+    dev->irqfd.fd = event_notifier_get_fd(&dev->intr);
+    dev->irqfd.resamplefd = event_notifier_get_fd(&dev->resample);
+    dev->irqfd.gsi = route.irq;
+    dev->irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE;
+    (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd);
+}
+
+static void setup_irqfd(PCIProxyDev *dev)
+{
+    PCIDevice *pci_dev = PCI_DEVICE(dev);
+    MPQemuMsg msg;
+
+    event_notifier_init(&dev->intr, 0);
+    event_notifier_init(&dev->resample, 0);
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    msg.cmd = SET_IRQFD;
+    msg.num_fds = 2;
+    msg.fds[0] = event_notifier_get_fd(&dev->intr);
+    msg.fds[1] = event_notifier_get_fd(&dev->resample);
+    msg.data1.set_irqfd.intx =
+        pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1;
+    msg.size = sizeof(msg.data1);
+
+    mpqemu_msg_send(&msg, dev->mpqemu_link->com);
+
+    memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd));
+
+    proxy_intx_update(pci_dev);
+
+    pci_device_set_intx_routing_notifier(pci_dev, proxy_intx_update);
+}
+
 static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
                        bool need_spawn, Error **errp)
 {
@@ -247,6 +297,7 @@ 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)
diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h
index 11f8ab7..bd0c17d 100644
--- a/include/hw/pci/pci_ids.h
+++ b/include/hw/pci/pci_ids.h
@@ -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
 
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index c93ffe3..56aec0e 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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;
 
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 1a7738e..13c4b80 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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];
diff --git a/include/remote/iohub.h b/include/remote/iohub.h
new file mode 100644
index 0000000..7a488a8
--- /dev/null
+++ b/include/remote/iohub.h
@@ -0,0 +1,50 @@
+/*
+ * IO Hub for remote device
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_IOHUB_H
+#define REMOTE_IOHUB_H
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "qemu/event_notifier.h"
+#include "qemu/thread-posix.h"
+#include "io/mpqemu-link.h"
+
+#define REMOTE_IOHUB_NB_PIRQS    8
+
+#define REMOTE_IOHUB_DEV         31
+#define REMOTE_IOHUB_FUNC        0
+
+#define TYPE_REMOTE_IOHUB_DEVICE "remote-iohub"
+#define REMOTE_IOHUB_DEVICE(obj) \
+    OBJECT_CHECK(RemoteIOHubState, (obj), TYPE_REMOTE_IOHUB_DEVICE)
+
+typedef struct ResampleToken {
+    void *iohub;
+    int pirq;
+} ResampleToken;
+
+typedef struct RemoteIOHubState {
+    PCIDevice d;
+    uint8_t irq_num[PCI_SLOT_MAX][PCI_NUM_PINS];
+    EventNotifier irqfds[REMOTE_IOHUB_NB_PIRQS];
+    EventNotifier resamplefds[REMOTE_IOHUB_NB_PIRQS];
+    unsigned int irq_level[REMOTE_IOHUB_NB_PIRQS];
+    ResampleToken token[REMOTE_IOHUB_NB_PIRQS];
+    QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS];
+} RemoteIOHubState;
+
+int remote_iohub_map_irq(PCIDevice *pci_dev, int intx);
+void remote_iohub_set_irq(void *opaque, int pirq, int level);
+void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg);
+
+#endif
diff --git a/include/remote/machine.h b/include/remote/machine.h
index 7e9bdbe..300394a 100644
--- a/include/remote/machine.h
+++ b/include/remote/machine.h
@@ -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"
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index 13d4c48..cbb3065 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -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
diff --git a/remote/iohub.c b/remote/iohub.c
new file mode 100644
index 0000000..a991a4e
--- /dev/null
+++ b/remote/iohub.c
@@ -0,0 +1,148 @@
+/*
+ * Remote IO Hub
+ *
+ * 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 "qemu/osdep.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_ids.h"
+#include "hw/pci/pci_bus.h"
+#include "remote/iohub.h"
+#include "qemu/thread.h"
+#include "hw/boards.h"
+#include "remote/machine.h"
+#include "qemu/main-loop.h"
+
+static void remote_iohub_initfn(Object *obj)
+{
+    RemoteIOHubState *iohub = REMOTE_IOHUB_DEVICE(obj);
+    int slot, intx, pirq;
+
+    memset(&iohub->irqfds, 0, sizeof(iohub->irqfds));
+    memset(&iohub->resamplefds, 0, sizeof(iohub->resamplefds));
+
+    for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
+        for (intx = 0; intx < PCI_NUM_PINS; intx++) {
+            iohub->irq_num[slot][intx] = (slot + intx) % 4 + 4;
+        }
+    }
+
+    for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) {
+        qemu_mutex_init(&iohub->irq_level_lock[pirq]);
+        iohub->irq_level[pirq] = 0;
+    }
+}
+
+static void remote_iohub_class_init(ObjectClass *klass, void *data)
+{
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    k->vendor_id = PCI_VENDOR_ID_ORACLE;
+    k->device_id = PCI_DEVICE_ID_REMOTE_IOHUB;
+}
+
+static const TypeInfo remote_iohub_info = {
+    .name       = TYPE_REMOTE_IOHUB_DEVICE,
+    .parent     = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(RemoteIOHubState),
+    .instance_init = remote_iohub_initfn,
+    .class_init  = remote_iohub_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { }
+    }
+};
+
+static void remote_iohub_register(void)
+{
+    type_register_static(&remote_iohub_info);
+}
+
+type_init(remote_iohub_register);
+
+int remote_iohub_map_irq(PCIDevice *pci_dev, int intx)
+{
+    BusState *bus = qdev_get_parent_bus(&pci_dev->qdev);
+    PCIBus *pci_bus = PCI_BUS(bus);
+    PCIDevice *pci_iohub =
+        pci_bus->devices[PCI_DEVFN(REMOTE_IOHUB_DEV, REMOTE_IOHUB_FUNC)];
+    RemoteIOHubState *iohub = REMOTE_IOHUB_DEVICE(pci_iohub);
+
+    return iohub->irq_num[PCI_SLOT(pci_dev->devfn)][intx];
+}
+
+/*
+ * TODO: Using lock to set the interrupt level could become a
+ *       performance bottleneck. Check if atomic arithmetic
+ *       is possible.
+ */
+void remote_iohub_set_irq(void *opaque, int pirq, int level)
+{
+    RemoteIOHubState *iohub = opaque;
+
+    assert(pirq >= 0);
+    assert(pirq < REMOTE_IOHUB_NB_PIRQS);
+
+    qemu_mutex_lock(&iohub->irq_level_lock[pirq]);
+
+    if (level) {
+        if (++iohub->irq_level[pirq] == 1) {
+            event_notifier_set(&iohub->irqfds[pirq]);
+        }
+    } else if (iohub->irq_level[pirq] > 0) {
+        iohub->irq_level[pirq]--;
+    }
+
+    qemu_mutex_unlock(&iohub->irq_level_lock[pirq]);
+}
+
+static void intr_resample_handler(void *opaque)
+{
+    ResampleToken *token = opaque;
+    RemoteIOHubState *iohub = token->iohub;
+    int pirq, s;
+
+    pirq = token->pirq;
+
+    s = event_notifier_test_and_clear(&iohub->resamplefds[pirq]);
+
+    assert(s >= 0);
+
+    qemu_mutex_lock(&iohub->irq_level_lock[pirq]);
+
+    if (iohub->irq_level[pirq]) {
+        event_notifier_set(&iohub->irqfds[pirq]);
+    }
+
+    qemu_mutex_unlock(&iohub->irq_level_lock[pirq]);
+}
+
+void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
+{
+    RemMachineState *machine = REMOTE_MACHINE(current_machine);
+    RemoteIOHubState *iohub = machine->iohub;
+    int pirq = remote_iohub_map_irq(pci_dev, msg->data1.set_irqfd.intx);
+
+    assert(msg->num_fds == 2);
+
+    if (event_notifier_get_fd(&iohub->irqfds[pirq]) != -1) {
+        event_notifier_cleanup(&iohub->irqfds[pirq]);
+        event_notifier_cleanup(&iohub->resamplefds[pirq]);
+        memset(&iohub->token[pirq], 0, sizeof(ResampleToken));
+    }
+
+    event_notifier_init_fd(&iohub->irqfds[pirq], msg->fds[0]);
+    event_notifier_init_fd(&iohub->resamplefds[pirq], msg->fds[1]);
+
+    iohub->token[pirq].iohub = iohub;
+    iohub->token[pirq].pirq = pirq;
+
+    qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL,
+                        &iohub->token[pirq]);
+}
diff --git a/remote/machine.c b/remote/machine.c
index 97e4f19..d529f68 100644
--- a/remote/machine.c
+++ b/remote/machine.c
@@ -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 = {
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 9512a3b..02d78a4 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 18/50] multi-process: configure remote side devices
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (16 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 17/50] multi-process: create IOHUB object to handle irq Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process Jagannathan Raman
                   ` (35 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Add functions to configure remote devices.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 0cf7dcc..3ba05d9 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 56aec0e..cd8505a 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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);
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 13c4b80..90a8437 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (17 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 18/50] multi-process: configure remote side devices Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices Jagannathan Raman
                   ` (34 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 3ba05d9..c888677 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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) {
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 90a8437..2ca89c5 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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];
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 02d78a4..0f830b8 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (18 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing Jagannathan Raman
                   ` (33 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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(-)

diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index cd8505a..7c6bddd 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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);
 
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index eaa947d..d47a544 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -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);
 
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 8ce71a2..60557ed 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -38,6 +38,15 @@
 #include "migration/misc.h"
 #include "migration/migration.h"
 #include "qemu/cutils.h"
+#include "hw/boards.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qstring.h"
+#include "sysemu/sysemu.h"
+#include "include/qemu/log.h"
+#include "qapi/qmp/qlist.h"
+#include "hw/proxy/qemu-proxy.h"
+#include "io/mpqemu-link.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -50,6 +59,8 @@ typedef struct QDevAlias
     uint32_t arch_mask;
 } QDevAlias;
 
+proxy_dev_list_t proxy_dev_list;
+
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
     { "e1000", "e1000-82540em" },
@@ -592,6 +603,240 @@ static bool should_hide_device(QemuOpts *opts)
     return true;
 }
 
+static QLIST_HEAD(, remote_process) remote_processes;
+
+void remote_process_register(struct remote_process *p)
+{
+    QLIST_INSERT_HEAD(&remote_processes, p, next);
+}
+
+struct remote_process *get_remote_process_rid(unsigned int rid)
+{
+    struct remote_process *p;
+
+    QLIST_FOREACH(p, &remote_processes, next) {
+        if (rid == p->rid) {
+            return p;
+        }
+    }
+    return NULL;
+}
+
+struct remote_process *get_remote_process_type(unsigned int type)
+{
+    struct remote_process *p;
+
+    QLIST_FOREACH(p, &remote_processes, next) {
+        if (type == p->type) {
+            return p;
+        }
+    }
+    return NULL;
+}
+
+#if defined(CONFIG_MPQEMU)
+
+static PCIProxyDev *get_proxy_object_rid(const char *rid)
+{
+    PCIProxyDev *entry;
+
+    QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+        if (strncmp(entry->rid, rid, strlen(entry->rid)) == 0) {
+            return entry;
+        }
+    }
+
+    return NULL;
+}
+
+#define MAX_RID_LENGTH 10
+void qdev_proxy_fire(void)
+{
+    PCIProxyDev *entry;
+
+    QLIST_FOREACH(entry, &proxy_dev_list.devices, next) {
+        if (entry->proxy_ready) {
+            entry->proxy_ready(PCI_DEVICE(entry));
+        }
+    }
+}
+
+DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,
+                            char *cmd, char *exec_name, int socket,
+                            bool managed, Error **errp)
+{
+    DeviceState *ds;
+    PCIProxyDev *pdev, *old_pdev;
+    QemuOpts *proxy_opts;
+    const char *proxy_type;
+    Error *local_err = NULL;
+    QDict *qdict;
+    const char *str;
+    bool need_spawn = false;
+    bool remote_exists = false;
+
+    if (strlen(rid) > MAX_RID_LENGTH) {
+        error_setg(errp, "rid %s is too long.", rid);
+        return NULL;
+    }
+
+    old_pdev = get_proxy_object_rid(rid);
+    if (old_pdev) {
+        remote_exists = true;
+        if (old_pdev->dev_id) {
+            if (id) {
+                if (strncmp(id, old_pdev->dev_id,
+                            strlen(old_pdev->dev_id)) == 0) {
+                    return DEVICE(old_pdev);
+                }
+            } else {
+            /* check if device belongs to this proxy, use bus */
+                if (bus) {
+                    if (strncmp(bus, old_pdev->dev_id,
+                                strlen(old_pdev->dev_id)) == 0) {
+                        return DEVICE(old_pdev);
+                    }
+                }
+            }
+        }
+    }
+
+    proxy_opts = qemu_opts_create(&qemu_device_opts, NULL, 0,
+                                  errp);
+
+    proxy_type = TYPE_PCI_PROXY_DEV;
+
+    qemu_opts_set_id(proxy_opts, (char *)rid);
+    qemu_opt_set(proxy_opts, "driver", proxy_type, &local_err);
+
+    qdict = qemu_opts_to_qdict(proxy_opts, NULL);
+    str = qstring_get_str(qobject_to_json(QOBJECT(qdict)));
+
+    ds = qdev_device_add(proxy_opts, &local_err);
+    if (!ds) {
+        error_setg(errp, "Could not create proxy device"
+                      " with opts %s.", str);
+        qemu_opts_del(proxy_opts);
+        return NULL;
+    }
+    qdev_set_id(ds, qemu_opts_id(proxy_opts));
+
+    pdev = PCI_PROXY_DEV(ds);
+    if (!pdev) {
+        error_setg(errp, "qdev_device_add failed.");
+        qemu_opts_del(proxy_opts);
+        return NULL;
+    }
+    pdev->rid = g_strdup(rid);
+    if (old_pdev) {
+        pdev->socket = old_pdev->socket;
+        pdev->remote_pid = old_pdev->remote_pid;
+    } else {
+        pdev->socket = managed ? socket : -1;
+
+    }
+    pdev->managed = managed;
+
+    /* With no libvirt, we will need to spawn. For now, every time. */
+    if (!remote_exists) {
+        need_spawn = true;
+    }
+
+    pdev->init_proxy(PCI_DEVICE(ds), cmd, exec_name, need_spawn, errp);
+
+    QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next);
+
+    qemu_opts_del(proxy_opts);
+    return ds;
+}
+
+DeviceState *qdev_remote_add(QemuOpts *opts, Error **errp)
+{
+    PCIProxyDev *pdev = NULL;
+    DeviceState *dev;
+    const char *rid, *socket = NULL, *command = NULL;
+    QDict *qdict_new;
+    const char *id = NULL;
+    const char *driver = NULL;
+    const char *bus = NULL;
+    const char *exec_name = NULL;
+
+    rid = qemu_opt_get(opts, "rid");
+    if (!rid) {
+        error_setg(errp, "rdevice option needs rid specified.");
+        return NULL;
+    }
+
+    driver = qemu_opt_get(opts, "driver");
+    /* TODO: properly identify the device class. */
+    if (strncmp(driver, "lsi", 3) == 0) {
+        id = qemu_opts_id(opts);
+        if (!id) {
+            error_setg(errp, "qdev_remote_add option needs id specified.");
+            return NULL;
+        }
+    }
+
+    socket = qemu_opt_get(opts, "socket");
+    if (socket) {
+        if (strlen(socket) > MAX_RID_LENGTH) {
+            error_setg(errp, "Socket number is incorrect.");
+            return NULL;
+        }
+    }
+    /*
+     * TODO: verify command with known commands and on remote end.
+     * How else can we verify the binary we launch without libvirtd support?
+     */
+    command = qemu_opt_get(opts, "command");
+    if (!socket && !command) {
+        error_setg(errp, "remote device needs socket or command specified.");
+        return NULL;
+    }
+
+    exec_name = qemu_opt_get(opts, "exec");
+    if (!exec_name && !socket) {
+        error_setg(errp, "exec name is not specified.");
+        return NULL;
+    }
+
+    bus = qemu_opt_get(opts, "bus");
+    dev = qdev_proxy_add(rid, id, (char *)bus, (char *)command,
+                         (char *)exec_name,
+                         socket ? atoi(socket) : -1,
+                         socket ? true : false, errp);
+    if (!dev) {
+        error_setg(errp, "qdev_proxy_add error.");
+        return NULL;
+    }
+
+    qdict_new = qemu_opts_to_qdict(opts, NULL);
+
+    if (!qdict_new) {
+        error_setg(errp, "Could not parse rdevice options.");
+        return NULL;
+    }
+
+    pdev = PCI_PROXY_DEV(dev);
+    if (!pdev->set_remote_opts) {
+        /* TODO: destroy proxy? */
+        error_setg(errp, "set_remote_opts failed.");
+        return NULL;
+    } else {
+        if (id && !pdev->dev_id) {
+            pdev->dev_id = g_strdup(id);
+        }
+        if (pdev->set_remote_opts(PCI_DEVICE(pdev), qdict_new,
+                                  DEV_OPTS)) {
+            error_setg(errp, "Remote process was unable to set options");
+            return NULL;
+        }
+    }
+
+    return dev;
+}
+#endif /*defined(CONFIG_MPQEMU)*/
+
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
 {
     DeviceClass *dc;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (19 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 22/50] multi-process: remote: use fd for socket from parent process Jagannathan Raman
                   ` (32 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 include/hw/qdev-core.h |   2 +
 qdev-monitor.c         |   2 +-
 remote/remote-main.c   | 182 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 185 insertions(+), 1 deletion(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 1405b8a..64a4d58 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 60557ed..ccd2ce0 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
 
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 0f830b8..3a67cb9 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -36,6 +36,21 @@
 #include "exec/memattrs.h"
 #include "exec/address-spaces.h"
 #include "remote/iohub.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qobject.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "monitor/qdev.h"
+#include "qapi/qmp/qdict.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/blockdev.h"
+#include "block/block.h"
+#include "qapi/qmp/qstring.h"
+#include "hw/qdev-properties.h"
+#include "hw/scsi/scsi.h"
+#include "block/qdict.h"
+#include "qapi/qmp/qlist.h"
+#include "qemu/log.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -143,6 +158,156 @@ static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
     mpqemu_msg_send(&ret, mpqemu_link->com);
 }
 
+static void process_device_add_msg(MPQemuMsg *msg)
+{
+    Error *local_err = NULL;
+    const char *json = (const char *)msg->data2;
+    int wait = msg->fds[0];
+    QObject *qobj = NULL;
+    QDict *qdict = NULL;
+    QemuOpts *opts = NULL;
+
+    qobj = qobject_from_json(json, &local_err);
+    if (local_err) {
+        goto fail;
+    }
+
+    qdict = qobject_to(QDict, qobj);
+    assert(qdict);
+
+    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
+    if (local_err) {
+        goto fail;
+    }
+
+    (void)qdev_device_add(opts, &local_err);
+    if (local_err) {
+        goto fail;
+    }
+
+fail:
+    if (local_err) {
+        error_report_err(local_err);
+        /* TODO: communicate the exact error message to proxy */
+    }
+
+    notify_proxy(wait, 1);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
+static void process_device_del_msg(MPQemuMsg *msg)
+{
+    Error *local_err = NULL;
+    DeviceState *dev = NULL;
+    const char *json = (const char *)msg->data2;
+    int wait = msg->fds[0];
+    QObject *qobj = NULL;
+    QDict *qdict = NULL;
+    const char *id;
+
+    qobj = qobject_from_json(json, &local_err);
+    if (local_err) {
+        goto fail;
+    }
+
+    qdict = qobject_to(QDict, qobj);
+    assert(qdict);
+
+    id = qdict_get_try_str(qdict, "id");
+    assert(id);
+
+    dev = find_device_state(id, &local_err);
+    if (local_err) {
+        goto fail;
+    }
+
+    if (dev) {
+        qdev_unplug(dev, &local_err);
+    }
+
+fail:
+    if (local_err) {
+        error_report_err(local_err);
+        /* TODO: communicate the exact error message to proxy */
+    }
+
+    notify_proxy(wait, 1);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
+static int setup_device(MPQemuMsg *msg, Error **errp)
+{
+    QObject *obj;
+    QDict *qdict;
+    QString *qstr;
+    QemuOpts *opts = NULL;
+    DeviceState *dev = NULL;
+    int wait = -1;
+    int rc = -EINVAL;
+    Error *local_error = NULL;
+
+    if (msg->num_fds == 1) {
+        wait = msg->fds[0];
+    } else {
+        error_setg(errp, "Numebr of FDs is incorrect");
+        return rc;
+    }
+
+    if (!msg->data2) {
+        return rc;
+    }
+
+    qstr = qstring_from_str((char *)msg->data2);
+    obj = qobject_from_json(qstring_get_str(qstr), &local_error);
+    if (!obj) {
+        error_setg(errp, "Could not get object!");
+        goto device_failed;
+    }
+
+    qdict = qobject_to(QDict, obj);
+    if (!qdict) {
+        error_setg(errp, "Could not get QDict");
+        goto device_failed;
+    }
+
+    g_assert(qdict_size(qdict) > 1);
+
+    opts = qemu_opts_from_qdict(&qemu_device_opts, qdict, &local_error);
+    qemu_opt_unset(opts, "rid");
+    qemu_opt_unset(opts, "socket");
+    qemu_opt_unset(opts, "remote");
+    qemu_opt_unset(opts, "command");
+    qemu_opt_unset(opts, "exec");
+    /*
+     * TODO: use the bus and addr from the device options. For now
+     * we use default value.
+     */
+    qemu_opt_unset(opts, "bus");
+    qemu_opt_unset(opts, "addr");
+
+    dev = qdev_device_add(opts, &local_error);
+    if (!dev) {
+        error_setg(errp, "Could not add device %s.",
+                   qstring_get_str(qobject_to_json(QOBJECT(qdict))));
+        goto device_failed;
+    }
+    if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+        remote_pci_dev = PCI_DEVICE(dev);
+    }
+
+    notify_proxy(wait, (uint32_t)REMOTE_OK);
+    qemu_opts_del(opts);
+    return 0;
+
+ device_failed:
+    notify_proxy(wait, (uint32_t)REMOTE_FAIL);
+    qemu_opts_del(opts);
+    return rc;
+
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -190,11 +355,28 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
          */
         remote_sysmem_reconfig(msg, &err);
         if (err) {
+            error_report_err(err);
             goto finalize_loop;
         }
         break;
     case SET_IRQFD:
         process_set_irqfd_msg(remote_pci_dev, msg);
+        qdev_machine_creation_done();
+        qemu_mutex_lock_iothread();
+        qemu_run_machine_init_done_notifiers();
+        qemu_mutex_unlock_iothread();
+
+        break;
+    case DEV_OPTS:
+        if (setup_device(msg, &err)) {
+            error_report_err(err);
+        }
+        break;
+    case DEVICE_ADD:
+        process_device_add_msg(msg);
+        break;
+    case DEVICE_DEL:
+        process_device_del_msg(msg);
         break;
     default:
         error_setg(&err, "Unknown command");
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 22/50] multi-process: remote: use fd for socket from parent process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (20 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 23/50] multi-process: remote: add create_done condition Jagannathan Raman
                   ` (31 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 remote/remote-main.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/remote/remote-main.c b/remote/remote-main.c
index 3a67cb9..455cfb6 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 23/50] multi-process: remote: add create_done condition
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (21 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 22/50] multi-process: remote: use fd for socket from parent process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 24/50] multi-process: add processing of remote device command line Jagannathan Raman
                   ` (30 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 remote/remote-main.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/remote/remote-main.c b/remote/remote-main.c
index 455cfb6..ec1ce2c 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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)) {
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 24/50] multi-process: add processing of remote device command line
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (22 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 23/50] multi-process: remote: add create_done condition Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code Jagannathan Raman
                   ` (29 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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.

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 softmmu/vl.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 94a7b93..79a286c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (23 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 24/50] multi-process: add processing of remote device command line Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 26/50] multi-process: refractor vl.c code Jagannathan Raman
                   ` (28 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 Makefile.target | 4 ++++
 rules.mak       | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Makefile.target b/Makefile.target
index c621d70..035c23b 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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
diff --git a/rules.mak b/rules.mak
index e39b073..6c8560f 100644
--- a/rules.mak
+++ b/rules.mak
@@ -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)$@")
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 26/50] multi-process: refractor vl.c code
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (24 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 27/50] multi-process: add remote option Jagannathan Raman
                   ` (27 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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

diff --git a/Makefile.objs b/Makefile.objs
index aad33fc..689a722 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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
diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index cbb3065..c1349ad 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -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
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 79a286c..b277de3 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -40,6 +40,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qlist.h"
+#include "vl.h"
 
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
@@ -975,20 +976,6 @@ static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
 /***********************************************************/
 /* QEMU Block devices */
 
-#define HD_OPTS "media=disk"
-#define CDROM_OPTS "media=cdrom"
-#define FD_OPTS ""
-#define PFLASH_OPTS ""
-#define MTD_OPTS ""
-#define SD_OPTS ""
-
-static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    BlockInterfaceType *block_default_type = opaque;
-
-    return drive_new(opts, *block_default_type, errp) == NULL;
-}
-
 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
 {
     if (qemu_opt_get(opts, "snapshot") == NULL) {
@@ -1694,21 +1681,6 @@ static void help(int exitcode)
     exit(exitcode);
 }
 
-#define HAS_ARG 0x0001
-
-typedef struct QEMUOption {
-    const char *name;
-    int flags;
-    int index;
-    uint32_t arch_mask;
-} QEMUOption;
-
-static const QEMUOption qemu_options[] = {
-    { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
-#define QEMU_OPTIONS_GENERATE_OPTIONS
-#include "qemu-options-wrapper.h"
-    { NULL },
-};
 
 typedef struct VGAInterfaceInfo {
     const char *opt_name;    /* option name */
@@ -2070,45 +2042,6 @@ 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);
-        return -1;
-    } else if (dev) {
-        object_unref(OBJECT(dev));
-    }
-    return 0;
-}
-
 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     Error *local_err = NULL;
@@ -2358,46 +2291,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
     }
 }
 
-static const QEMUOption *lookup_opt(int argc, char **argv,
-                                    const char **poptarg, int *poptind)
-{
-    const QEMUOption *popt;
-    int optind = *poptind;
-    char *r = argv[optind];
-    const char *optarg;
-
-    loc_set_cmdline(argv, optind, 1);
-    optind++;
-    /* Treat --foo the same as -foo.  */
-    if (r[1] == '-')
-        r++;
-    popt = qemu_options;
-    for(;;) {
-        if (!popt->name) {
-            error_report("invalid option");
-            exit(1);
-        }
-        if (!strcmp(popt->name, r + 1))
-            break;
-        popt++;
-    }
-    if (popt->flags & HAS_ARG) {
-        if (optind >= argc) {
-            error_report("requires an argument");
-            exit(1);
-        }
-        optarg = argv[optind++];
-        loc_set_cmdline(argv, optind - 2, 2);
-    } else {
-        optarg = NULL;
-    }
-
-    *poptarg = optarg;
-    *poptind = optind;
-
-    return popt;
-}
-
 static MachineClass *select_machine(void)
 {
     GSList *machines = object_class_get_list(TYPE_MACHINE, false);
diff --git a/vl-parse.c b/vl-parse.c
new file mode 100644
index 0000000..b76bc95
--- /dev/null
+++ b/vl-parse.c
@@ -0,0 +1,130 @@
+/*
+ * 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/units.h"
+#include "qapi/error.h"
+#include "qemu/cutils.h"
+#include "qemu/error-report.h"
+#include "monitor/qdev.h"
+#include "monitor/qdev.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/runstate.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "sysemu/blockdev.h"
+
+#include "chardev/char.h"
+#include "monitor/monitor.h"
+#include "qemu/config-file.h"
+
+#include "sysemu/arch_init.h"
+
+#include "vl.h"
+
+/***********************************************************/
+/* QEMU Block devices */
+
+static const QEMUOption qemu_options[] = {
+    { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
+#define QEMU_OPTIONS_GENERATE_OPTIONS
+#include "qemu-options-wrapper.h"
+    { NULL },
+};
+
+const QEMUOption *lookup_opt(int argc, char **argv,
+                                    const char **poptarg, int *poptind)
+{
+    const QEMUOption *popt;
+    int optind = *poptind;
+    char *r = argv[optind];
+    const char *optarg;
+
+    loc_set_cmdline(argv, optind, 1);
+    optind++;
+    /* Treat --foo the same as -foo.  */
+    if (r[1] == '-') {
+        r++;
+    }
+    popt = qemu_options;
+    if (!popt) {
+        error_report("Not valid qemu_options");
+    }
+    for (;;) {
+        if (!popt->name) {
+            error_report("invalid option*");
+            exit(1);
+            popt++;
+            continue;
+        }
+        if (!strcmp(popt->name, r + 1)) {
+            break;
+        }
+        popt++;
+    }
+    if (popt->flags & HAS_ARG) {
+        if (optind >= argc) {
+            error_report("optind %d, argc %d", optind, argc);
+            error_report("requires an argument");
+            exit(1);
+        }
+        optarg = argv[optind++];
+        loc_set_cmdline(argv, optind - 2, 2);
+    } else {
+        optarg = NULL;
+    }
+
+    *poptarg = optarg;
+    *poptind = optind;
+
+    return popt;
+}
+
+int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    BlockInterfaceType *block_default_type = opaque;
+
+    if (!drive_new(opts, *block_default_type, errp)) {
+        error_report_err(*errp);
+    }
+
+    return 0;
+}
+
+#if defined(CONFIG_MPQEMU)
+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;
+    }
+    return 0;
+}
+#endif
+
+int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    DeviceState *dev;
+
+#if defined(CONFIG_MPQEMU)
+    const char *remote = qemu_opt_get(opts, "rid");
+    if (remote) {
+        return 0;
+    }
+#endif
+
+    dev = qdev_device_add(opts, errp);
+    if (!dev) {
+        return -1;
+    }
+    object_unref(OBJECT(dev));
+    return 0;
+}
diff --git a/vl.h b/vl.h
new file mode 100644
index 0000000..a171fab
--- /dev/null
+++ b/vl.h
@@ -0,0 +1,42 @@
+/*
+ * 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 VL_H
+#define VL_H
+
+/***********************************************************/
+/* QEMU Block devices */
+
+#define HD_OPTS "media=disk"
+#define CDROM_OPTS "media=cdrom"
+#define FD_OPTS ""
+#define PFLASH_OPTS ""
+#define MTD_OPTS ""
+#define SD_OPTS ""
+
+
+#define HAS_ARG 0x0001
+typedef struct QEMUOption {
+    const char *name;
+    int flags;
+    int index;
+    uint32_t arch_mask;
+} QEMUOption;
+
+const QEMUOption *lookup_opt(int argc, char **argv,
+                                    const char **poptarg, int *poptind);
+
+int drive_init_func(void *opaque, QemuOpts *opts, Error **errp);
+int device_init_func(void *opaque, QemuOpts *opts, Error **errp);
+
+#if defined(CONFIG_MPQEMU)
+int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp);
+#endif
+
+#endif /* VL_H */
+
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 27/50] multi-process: add remote option
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (25 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 26/50] multi-process: refractor vl.c code Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 28/50] multi-process: add remote options parser Jagannathan Raman
                   ` (26 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 qemu-options.hx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/qemu-options.hx b/qemu-options.hx
index ac315c1..2c5e97f 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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"
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 28/50] multi-process: add remote options parser
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (26 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 27/50] multi-process: add remote option Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 29/50] multi-process: add parse_cmdline in remote process Jagannathan Raman
                   ` (25 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 include/monitor/qdev.h |   1 +
 softmmu/vl.c           | 105 +++++++++++++++++++++++++++++++++++++++++++++++++
 vl-parse.c             |  31 +++++++++++++++
 vl.h                   |   1 +
 4 files changed, 138 insertions(+)

diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index d47a544..f3a56fa 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -23,6 +23,7 @@ struct remote_process {
     unsigned int type;
     int socket;
     char *command;
+    char *exec;
     QemuOpts *opts;
 
     QLIST_ENTRY(remote_process) next;
diff --git a/softmmu/vl.c b/softmmu/vl.c
index b277de3..a8a6f35 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -253,6 +253,32 @@ static QemuOptsList qemu_option_rom_opts = {
     },
 };
 
+static QemuOptsList qemu_remote_opts = {
+    .name = "remote",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_remote_opts.head),
+    .desc = {
+        {
+            .name = "rid",
+            .type = QEMU_OPT_NUMBER,
+            .help = "id of the remote process"
+        },{
+            .name = "socket",
+            .type = QEMU_OPT_NUMBER,
+            .help = "Socket for remote",
+        },{
+            .name = "command",
+            .type = QEMU_OPT_STRING,
+            .help = "command to run",
+        },{
+            .name = "exec",
+            .type = QEMU_OPT_STRING,
+            .help = "exec name",
+        },
+        { /* end of list */ }
+    },
+};
+
+
 static QemuOptsList qemu_machine_opts = {
     .name = "machine",
     .implied_opt_name = "type",
@@ -314,6 +340,71 @@ static QemuOptsList qemu_boot_opts = {
     },
 };
 
+#if defined(CONFIG_MPQEMU)
+static int parse_remote(void *opaque, QemuOpts *opts, Error **errp)
+{
+    int rid;
+    int socket;
+    char  *c_sock = NULL;
+    char *command = NULL;
+    char *exec = NULL;
+    struct remote_process r_proc;
+
+    rid = atoi(qemu_opt_get(opts, "rid"));
+    if (rid < 0) {
+        error_setg(errp, "rid is required.");
+        return -1;
+    }
+    if (get_remote_process_rid(rid)) {
+        error_setg(errp, "There is already process with rid %d", rid);
+        goto cont_devices;
+    }
+
+    c_sock = (char *)qemu_opt_get(opts, "socket");
+    if (c_sock) {
+        socket = atoi(c_sock);
+    } else {
+        socket = -1;
+    }
+    if (socket <= STDERR_FILENO && socket != -1) {
+        socket = -1;
+    }
+
+    exec = (char *)qemu_opt_get(opts, "exec");
+
+    if (!exec && socket < 0) {
+        error_setg(errp, "No socket or exec defined for remote.");
+        return -1;
+    }
+    if (exec && (socket != -1)) {
+        error_setg(errp, "Both socket and exec are specified, " \
+                         "need only one of those.");
+        return -1;
+    }
+
+    command = (char *)qemu_opt_get(opts, "command");
+    if (!command && socket < 0) {
+        error_setg(errp, "Remote process command option is not specified.");
+        return -1;
+    }
+
+    r_proc.rid = rid;
+    r_proc.socket = socket;
+    r_proc.command = g_strdup(command);
+    r_proc.exec = g_strdup(exec);
+    remote_process_register(&r_proc);
+
+ cont_devices:
+    if (qemu_opts_foreach(qemu_find_opts("device"), device_remote_add,
+                          &rid, NULL)) {
+        error_setg(errp, "Could not process some of the remote devices.");
+        return -EINVAL;
+    }
+
+    return 0;
+}
+#endif
+
 static QemuOptsList qemu_add_fd_opts = {
     .name = "add-fd",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
@@ -2751,6 +2842,7 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_icount_opts);
     qemu_add_opts(&qemu_semihosting_config_opts);
     qemu_add_opts(&qemu_fw_cfg_opts);
+    qemu_add_opts(&qemu_remote_opts);
     module_call_init(MODULE_INIT_OPTS);
 
     runstate_init();
@@ -3575,6 +3667,14 @@ void qemu_init(int argc, char **argv, char **envp)
                 exit(1);
 #endif
                 break;
+            case QEMU_OPTION_remote:
+                opts = qemu_opts_parse_noisily(qemu_find_opts("remote"),
+                                               optarg, false);
+                if (!opts) {
+                    exit(1);
+                }
+                break;
+
             case QEMU_OPTION_object:
                 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
                                                optarg, true);
@@ -4170,6 +4270,11 @@ void qemu_init(int argc, char **argv, char **envp)
     qemu_opts_foreach(qemu_find_opts("device"),
                       device_init_func, NULL, &error_fatal);
 
+#ifdef CONFIG_MPQEMU
+    qemu_opts_foreach(qemu_find_opts("remote"),
+                      parse_remote, NULL, &error_fatal);
+#endif
+
     cpu_synchronize_all_post_init();
 
     rom_reset_order_override();
diff --git a/vl-parse.c b/vl-parse.c
index b76bc95..1f6a3f0 100644
--- a/vl-parse.c
+++ b/vl-parse.c
@@ -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;
diff --git a/vl.h b/vl.h
index a171fab..d84bf63 100644
--- a/vl.h
+++ b/vl.h
@@ -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 */
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 29/50] multi-process: add parse_cmdline in remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (27 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 28/50] multi-process: add remote options parser Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 30/50] multi-process: send heartbeat messages to remote Jagannathan Raman
                   ` (24 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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

diff --git a/remote/Makefile.objs b/remote/Makefile.objs
index c1349ad..a677fce 100644
--- a/remote/Makefile.objs
+++ b/remote/Makefile.objs
@@ -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
diff --git a/remote/remote-main.c b/remote/remote-main.c
index ec1ce2c..872ff7e 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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);
diff --git a/remote/remote-opts.c b/remote/remote-opts.c
new file mode 100644
index 0000000..7e12700
--- /dev/null
+++ b/remote/remote-opts.c
@@ -0,0 +1,99 @@
+/*
+ * 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 <unistd.h>
+
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu-common.h"
+
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#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-options.h"
+#include "sysemu/arch_init.h"
+
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qobject.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "monitor/qdev.h"
+#include "qapi/qmp/qdict.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/blockdev.h"
+#include "block/block.h"
+#include "remote/remote-opts.h"
+#include "include/qemu-common.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.
+ */
+void parse_cmdline(int argc, char **argv, char **envp)
+{
+    int optind;
+    const char *optarg;
+    MachineClass *mc;
+
+    /* from vl.c */
+    optind = 0;
+
+    /* second pass of option parsing */
+
+    for (;;) {
+        if (optind >= argc) {
+            break;
+        }
+        if (argv[optind][0] != '-') {
+            loc_set_cmdline(argv, optind, 1);
+            drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
+        } else {
+            const QEMUOption *popt;
+
+            popt = lookup_opt(argc, argv, &optarg, &optind);
+            #ifndef REMOTE_PROCESS
+            if (!(popt->arch_mask & arch_type)) {
+                error_report("Option not supported for this target, %x arch_mask, %x arch_type",
+                             popt->arch_mask, arch_type);
+                exit(1);
+            }
+            #endif
+            switch (popt->index) {
+            case QEMU_OPTION_drive:
+                if (drive_def(optarg) == NULL) {
+                    fprintf(stderr, "Could not init drive\n");
+                    exit(1);
+                }
+                break;
+            default:
+                break;
+            }
+        }
+    }
+    mc = MACHINE_GET_CLASS(current_machine);
+
+    mc->block_default_type = IF_IDE;
+    if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
+                          &mc->block_default_type, &error_fatal)) {
+        /* We printed help */
+        exit(0);
+    }
+
+    return;
+}
diff --git a/remote/remote-opts.h b/remote/remote-opts.h
new file mode 100644
index 0000000..263d428
--- /dev/null
+++ b/remote/remote-opts.h
@@ -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
+
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 30/50] multi-process: send heartbeat messages to remote
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (28 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 29/50] multi-process: add parse_cmdline in remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 31/50] multi-process: handle heartbeat messages in remote process Jagannathan Raman
                   ` (23 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 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(+)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index c888677..bcb24f7 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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)
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 7c6bddd..f7666fb 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -55,6 +55,8 @@ struct PCIProxyDev {
     EventNotifier resample;
 
     pid_t remote_pid;
+    EventNotifier en_ping;
+
     int socket;
 
     char *rid;
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 2ca89c5..aaaf1a4 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -60,6 +60,7 @@ typedef enum {
     DEVICE_DEL,
     GET_PCI_INFO,
     RET_PCI_INFO,
+    PROXY_PING,
     MAX,
 } mpqemu_cmd_t;
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 31/50] multi-process: handle heartbeat messages in remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (29 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 30/50] multi-process: send heartbeat messages to remote Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 32/50] multi-process: Use separate MMIO communication channel Jagannathan Raman
                   ` (22 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
---
 remote/remote-main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/remote/remote-main.c b/remote/remote-main.c
index 872ff7e..2c05d20 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 32/50] multi-process: Use separate MMIO communication channel
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (30 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 31/50] multi-process: handle heartbeat messages in remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-06 16:52   ` Stefan Hajnoczi
  2020-02-24 20:55 ` [PATCH v5 33/50] multi-process: perform device reset in the remote process Jagannathan Raman
                   ` (21 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Using a separate communication channel for MMIO helps
with improving Performance

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index bcb24f7..68517aa 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index f7666fb..2a2c732 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -58,6 +58,7 @@ struct PCIProxyDev {
     EventNotifier en_ping;
 
     int socket;
+    int mmio_sock;
 
     char *rid;
     char *dev_id;
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index aaaf1a4..3962630 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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;
diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
index 73b7032..07a9be9 100644
--- a/io/mpqemu-link.c
+++ b/io/mpqemu-link.c
@@ -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);
 }
diff --git a/qdev-monitor.c b/qdev-monitor.c
index ccd2ce0..27b2ddc 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 2c05d20..6cfc446 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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);
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 33/50] multi-process: perform device reset in the remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (31 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 32/50] multi-process: Use separate MMIO communication channel Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target Jagannathan Raman
                   ` (20 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(+)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 68517aa..741f02a 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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 = {
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 3962630..d2234ca 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -62,6 +62,7 @@ typedef enum {
     RET_PCI_INFO,
     PROXY_PING,
     MMIO_RETURN,
+    DEVICE_RESET,
     MAX,
 } mpqemu_cmd_t;
 
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 6cfc446..5284ee9 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (32 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 33/50] multi-process: perform device reset in the remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 10:39   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 35/50] multi-process/mon: stub functions to enable QMP module for remote process Jagannathan Raman
                   ` (19 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 257ee7d..631cc76 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -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",
     },
 
diff --git a/hmp-commands.hx b/hmp-commands.hx
index dc23185..ecc6169 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -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",
     },
diff --git a/scripts/hxtool b/scripts/hxtool
old mode 100644
new mode 100755
index 0003e7b..802cbd4
--- a/scripts/hxtool
+++ b/scripts/hxtool
@@ -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
@@ -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'
+            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
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 35/50] multi-process/mon: stub functions to enable QMP module for remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (33 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 36/50] multi-process/mon: enable QMP module support in the " Jagannathan Raman
                   ` (18 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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

diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c
index 9b55fb0..c2d72fe 100644
--- a/accel/stubs/tcg-stub.c
+++ b/accel/stubs/tcg-stub.c
@@ -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);
+}
diff --git a/configure b/configure
index ab1e344..53a2a4b 100755
--- a/configure
+++ b/configure
@@ -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
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 082da59..09da824 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -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
diff --git a/stubs/gdbstub.c b/stubs/gdbstub.c
index 2b7aee5..1e65b54 100644
--- a/stubs/gdbstub.c
+++ b/stubs/gdbstub.c
@@ -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
diff --git a/stubs/migration.c b/stubs/migration.c
new file mode 100644
index 0000000..28ccf80
--- /dev/null
+++ b/stubs/migration.c
@@ -0,0 +1,162 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "migration/misc.h"
+#include "migration/snapshot.h"
+#include "qapi/qapi-types-migration.h"
+#include "qapi/qapi-commands-migration.h"
+#include "qapi/qapi-types-net.h"
+
+MigrationInfo *qmp_query_migrate(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
+                                  Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+MigrationParameters *qmp_query_migrate_parameters(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_migrate_start_postcopy(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_cancel(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_continue(MigrationStatus state, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_set_downtime(double value, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_set_speed(int64_t value, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_set_cache_size(int64_t value, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+int64_t qmp_query_migrate_cache_size(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return 0;
+}
+
+void qmp_migrate(const char *uri, bool has_blk, bool blk,
+                 bool has_inc, bool inc, bool has_detach, bool detach,
+                 bool has_resume, bool resume, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_incoming(const char *uri, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_recover(const char *uri, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_migrate_pause(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_x_colo_lost_heartbeat(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live,
+                                Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_xen_set_replication(bool enable, bool primary,
+                             bool has_failover, bool failover,
+                             Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+ReplicationStatus *qmp_query_xen_replication_status(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_xen_colo_do_checkpoint(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+COLOStatus *qmp_query_colo_status(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void migration_global_dump(Monitor *mon)
+{
+    qemu_debug_assert(0);
+}
+
+int load_snapshot(const char *name, Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+int save_snapshot(const char *name, Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+AnnounceParameters *migrate_announce_params(void)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
diff --git a/stubs/monitor.c b/stubs/monitor.c
index a34dc87..190445c 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -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;
 }
 
diff --git a/stubs/net-stub.c b/stubs/net-stub.c
index cb2274b..962827e 100644
--- a/stubs/net-stub.c
+++ b/stubs/net-stub.c
@@ -2,6 +2,9 @@
 #include "qemu-common.h"
 #include "net/net.h"
 
+#include "qapi/qapi-commands-net.h"
+#include "qapi/qapi-commands-rocker.h"
+
 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
                                  NetClientDriver type, int max)
 {
@@ -29,3 +32,69 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
     return -ENOSYS;
 }
 
+void qmp_set_link(const char *name, bool up, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_netdev_del(const char *id, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
+                                      Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_announce_self(AnnounceParameters *params, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+RockerSwitch *qmp_query_rocker(const char *name, Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name,
+                                                   bool has_tbl_id,
+                                                   uint32_t tbl_id,
+                                                   Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name,
+                                                     bool has_type,
+                                                     uint8_t type,
+                                                     Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void netdev_add(QemuOpts *opts, Error **errp)
+{
+    qemu_debug_assert(0);
+}
diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
new file mode 100644
index 0000000..3eeedd9
--- /dev/null
+++ b/stubs/qapi-misc.c
@@ -0,0 +1,41 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "qapi/qapi-commands-misc.h"
+#include "./qapi/qapi-types-dump.h"
+#include "qapi/qapi-commands-dump.h"
+
+void qmp_dump_guest_memory(bool paging, const char *file,
+                           bool has_detach, bool detach,
+                           bool has_begin, int64_t begin, bool has_length,
+                           int64_t length, bool has_format,
+                           DumpGuestMemoryFormat format, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+DumpQueryResult *qmp_query_dump(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_xen_load_devices_state(const char *filename, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+bool dump_in_progress(void)
+{
+    qemu_debug_assert(0);
+
+    return FALSE;
+}
diff --git a/stubs/qapi-target.c b/stubs/qapi-target.c
new file mode 100644
index 0000000..5d224e4
--- /dev/null
+++ b/stubs/qapi-target.c
@@ -0,0 +1,55 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "qapi/qapi-types-misc-target.h"
+#include "qapi/qapi-commands-misc-target.h"
+#include "qapi/qapi-types-machine-target.h"
+#include "qapi/qapi-commands-machine-target.h"
+
+#if defined(TARGET_I386)
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+SevInfo *qmp_query_sev(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+SevCapability *qmp_query_sev_capabilities(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+#endif
+
+#if defined(TARGET_S390X) || defined(TARGET_I386) || defined(TARGET_ARM)
+CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
+                                                     CpuModelInfo *model,
+                                                     Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+#endif
+
+#if defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X) || defined(TARGET_MIPS)
+CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+#endif
diff --git a/stubs/ui-stub.c b/stubs/ui-stub.c
new file mode 100644
index 0000000..a5a63ea
--- /dev/null
+++ b/stubs/ui-stub.c
@@ -0,0 +1,130 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include "ui/console.h"
+#include "ui/input.h"
+#include "ui/qemu-spice.h"
+
+#include "qapi/qapi-types-ui.h"
+#include "qapi/qapi-commands-ui.h"
+
+void qmp_screendump(const char *filename, bool has_device, const char *device,
+                    bool has_head, int64_t head, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+VncInfo *qmp_query_vnc(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+VncInfo2List *qmp_query_vnc_servers(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+MouseInfoList *qmp_query_mice(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
+                  Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void qmp_input_send_event(bool has_device, const char *device,
+                          bool has_head, int64_t head,
+                          InputEventList *events, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void vnc_display_open(const char *id, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+void vnc_display_add_client(const char *id, int csock, bool skipauth)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_input_event_sync(void)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
+                               uint32_t button_old, uint32_t button_new)
+{
+    qemu_debug_assert(0);
+}
+
+#ifdef CONFIG_SPICE
+
+int using_spice;
+
+SpiceInfo *qmp_query_spice(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
+                            const char *subject)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+int qemu_spice_display_add_client(int csock, int skipauth, int tls)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+int qemu_spice_set_passwd(const char *passwd, bool fail_if_conn,
+                          bool disconnect_if_conn)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+int qemu_spice_set_pw_expire(time_t expires)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+#endif
+
+int index_from_key(const char *key, size_t key_length)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
index fff72be..606f078 100644
--- a/stubs/vl-stub.c
+++ b/stubs/vl-stub.c
@@ -8,6 +8,12 @@
 #include "disas/disas.h"
 #include "sysemu/runstate.h"
 
+#include "qapi/qapi-commands-ui.h"
+#include "qapi/qapi-commands-run-state.h"
+#include "sysemu/watchdog.h"
+#include "disas/disas.h"
+#include "audio/audio.h"
+
 bool tcg_allowed;
 bool xen_allowed;
 bool boot_strict;
@@ -21,6 +27,8 @@ int smp_threads = 1;
 int icount_align_option;
 int boot_menu;
 
+#pragma weak arch_type
+
 unsigned int max_cpus;
 const uint32_t arch_type;
 const char *mem_path;
@@ -33,6 +41,11 @@ ram_addr_t ram_size;
 MachineState *current_machine;
 QemuUUID qemu_uuid;
 
+int singlestep;
+const char *qemu_name;
+int no_shutdown;
+int autostart;
+
 int runstate_is_running(void)
 {
     return 0;
@@ -77,3 +90,82 @@ void x86_cpu_list(void)
 {
 }
 #endif
+
+void qemu_system_shutdown_request(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_reset_request(ShutdownCause reason)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_system_powerdown_request(void)
+{
+    qemu_debug_assert(0);
+}
+
+void qemu_exit_preconfig_request(void)
+{
+    qemu_debug_assert(0);
+}
+
+bool runstate_needs_reset(void)
+{
+    qemu_debug_assert(0);
+
+    return FALSE;
+}
+
+bool qemu_wakeup_suspend_enabled(void)
+{
+    qemu_debug_assert(0);
+
+    return FALSE;
+}
+
+void qemu_system_wakeup_request(WakeupReason reason, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+DisplayOptions *qmp_query_display_options(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+StatusInfo *qmp_query_status(Error **errp)
+{
+    qemu_debug_assert(0);
+
+    return NULL;
+}
+
+void qmp_watchdog_set_action(WatchdogAction action, Error **errp)
+{
+    qemu_debug_assert(0);
+}
+
+int select_watchdog_action(const char *p)
+{
+    qemu_debug_assert(0);
+
+    return -1;
+}
+
+void monitor_disas(Monitor *mon, CPUState *cpu,
+                   target_ulong pc, int nb_insn, int is_physical)
+{
+    qemu_debug_assert(0);
+}
+
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+                      int freq, int bits, int nchannels)
+{
+    qemu_debug_assert(0);
+
+    return -1;
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (34 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 35/50] multi-process/mon: stub functions to enable QMP module for remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 10:43   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c Jagannathan Raman
                   ` (17 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Build system changes to enable QMP module in the remote process

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/Makefile.objs b/Makefile.objs
index 689a722..4b5db09 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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
diff --git a/Makefile.target b/Makefile.target
index 035c23b..4ead5c3 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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
diff --git a/hmp-commands.hx b/hmp-commands.hx
index ecc6169..a1932c4 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -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
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index e3e8084..251b77b 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -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
diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs
index 9244d90..48d8017 100644
--- a/monitor/Makefile.objs
+++ b/monitor/Makefile.objs
@@ -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
diff --git a/monitor/misc.c b/monitor/misc.c
index 6c41293..f1f09bf 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
     return 0;
 }
 
-static void do_help_cmd(Monitor *mon, const QDict *qdict)
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
 {
     help_cmd(mon, qdict_get_try_str(qdict, "name"));
 }
 
-static void hmp_trace_event(Monitor *mon, const QDict *qdict)
+void hmp_trace_event(Monitor *mon, const QDict *qdict)
 {
     const char *tp_name = qdict_get_str(qdict, "name");
     bool new_state = qdict_get_bool(qdict, "option");
@@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static void hmp_info_help(Monitor *mon, const QDict *qdict)
+void hmp_info_help(Monitor *mon, const QDict *qdict)
 {
     help_cmd(mon, "info");
 }
@@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
     return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
 }
 
-static void hmp_info_registers(Monitor *mon, const QDict *qdict)
+void hmp_info_registers(Monitor *mon, const QDict *qdict)
 {
     bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
     CPUState *cs;
@@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
 }
 
 #ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
+void hmp_info_jit(Monitor *mon, const QDict *qdict)
 {
     if (!tcg_enabled()) {
         error_report("JIT information is only available with accel=tcg");
@@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
     dump_drift_info();
 }
 
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
+void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 {
     dump_opcount_info();
 }
 #endif
 
-static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 {
     int64_t max = qdict_get_try_int(qdict, "max", 10);
     bool mean = qdict_get_try_bool(qdict, "mean", false);
@@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
     qsp_report(max, sort_by, coalesce);
 }
 
-static void hmp_info_history(Monitor *mon, const QDict *qdict)
+void hmp_info_history(Monitor *mon, const QDict *qdict)
 {
     MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
     int i;
@@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
 {
     CPUState *cs = mon_get_cpu();
 
@@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
     cpu_dump_statistics(cs, 0);
 }
 
-static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
 {
     const char *name = qdict_get_try_str(qdict, "name");
     bool has_vcpu = qdict_haskey(qdict, "vcpu");
@@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
     error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
 }
 
-static void hmp_logfile(Monitor *mon, const QDict *qdict)
+void hmp_logfile(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
 
@@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_log(Monitor *mon, const QDict *qdict)
+void hmp_log(Monitor *mon, const QDict *qdict)
 {
     int mask;
     const char *items = qdict_get_str(qdict, "items");
@@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
     qemu_set_log(mask);
 }
 
-static void hmp_singlestep(Monitor *mon, const QDict *qdict)
+void hmp_singlestep(Monitor *mon, const QDict *qdict)
 {
     const char *option = qdict_get_try_str(qdict, "option");
     if (!option || !strcmp(option, "on")) {
@@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
+void hmp_gdbserver(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_try_str(qdict, "device");
     if (!device)
@@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
 {
     const char *action = qdict_get_str(qdict, "action");
     if (select_watchdog_action(action) == -1) {
@@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
     }
 }
 
-static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_memory_dump(Monitor *mon, const QDict *qdict)
 {
     int count = qdict_get_int(qdict, "count");
     int format = qdict_get_int(qdict, "format");
@@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
     memory_dump(mon, count, format, size, addr, 0);
 }
 
-static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
 {
     int count = qdict_get_int(qdict, "count");
     int format = qdict_get_int(qdict, "format");
@@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
     return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
 }
 
-static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
 {
     hwaddr addr = qdict_get_int(qdict, "addr");
     Error *local_err = NULL;
@@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
     memory_region_unref(mr);
 }
 
-static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
 {
     target_ulong addr = qdict_get_int(qdict, "addr");
     MemTxAttrs attrs;
@@ -768,7 +768,7 @@ out:
     return ret;
 }
 
-static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
 {
     hwaddr addr = qdict_get_int(qdict, "addr");
     Error *local_err = NULL;
@@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static void do_print(Monitor *mon, const QDict *qdict)
+void hmp_do_print(Monitor *mon, const QDict *qdict)
 {
     int format = qdict_get_int(qdict, "format");
     hwaddr val = qdict_get_int(qdict, "val");
@@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 }
 
-static void hmp_sum(Monitor *mon, const QDict *qdict)
+void hmp_sum(Monitor *mon, const QDict *qdict)
 {
     uint32_t addr;
     uint16_t sum;
@@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
 
 static int mouse_button_state;
 
-static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
+void hmp_mouse_move(Monitor *mon, const QDict *qdict)
 {
     int dx, dy, dz, button;
     const char *dx_str = qdict_get_str(qdict, "dx_str");
@@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
     qemu_input_event_sync();
 }
 
-static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
+void hmp_mouse_button(Monitor *mon, const QDict *qdict)
 {
     static uint32_t bmap[INPUT_BUTTON__MAX] = {
         [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
@@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
     mouse_button_state = button_state;
 }
 
-static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
+void hmp_ioport_read(Monitor *mon, const QDict *qdict)
 {
     int size = qdict_get_int(qdict, "size");
     int addr = qdict_get_int(qdict, "addr");
@@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
                    suffix, addr, size * 2, val);
 }
 
-static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
+void hmp_ioport_write(Monitor *mon, const QDict *qdict)
 {
     int size = qdict_get_int(qdict, "size");
     int addr = qdict_get_int(qdict, "addr");
@@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_boot_set(Monitor *mon, const QDict *qdict)
+void hmp_boot_set(Monitor *mon, const QDict *qdict)
 {
     Error *local_err = NULL;
     const char *bootdevice = qdict_get_str(qdict, "bootdevice");
@@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
+void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 {
     bool flatview = qdict_get_try_bool(qdict, "flatview", false);
     bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
@@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
 
 int64_t dev_time;
 
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     static int64_t last_cpu_exec_time;
     int64_t cpu_exec_time;
@@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
     dev_time = 0;
 }
 #else
-static void hmp_info_profile(Monitor *mon, const QDict *qdict)
+void hmp_info_profile(Monitor *mon, const QDict *qdict)
 {
     monitor_printf(mon, "Internal profiler not compiled\n");
 }
@@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
 /* Capture support */
 static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
 
-static void hmp_info_capture(Monitor *mon, const QDict *qdict)
+void hmp_info_capture(Monitor *mon, const QDict *qdict)
 {
     int i;
     CaptureState *s;
@@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
+void hmp_stopcapture(Monitor *mon, const QDict *qdict)
 {
     int i;
     int n = qdict_get_int(qdict, "n");
@@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
+void hmp_wavcapture(Monitor *mon, const QDict *qdict)
 {
     const char *path = qdict_get_str(qdict, "path");
     int freq = qdict_get_try_int(qdict, "freq", 44100);
@@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
     warn_acl = true;
 }
 
-static void hmp_acl_show(Monitor *mon, const QDict *qdict)
+void hmp_acl_show(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     QAuthZList *auth = find_auth(mon, aclname);
@@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
+void hmp_acl_reset(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     QAuthZList *auth = find_auth(mon, aclname);
@@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "acl: removed all rules\n");
 }
 
-static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
+void hmp_acl_policy(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *policy = qdict_get_str(qdict, "policy");
@@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
     }
 }
 
-static void hmp_acl_add(Monitor *mon, const QDict *qdict)
+void hmp_acl_add(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *match = qdict_get_str(qdict, "match");
@@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
+void hmp_acl_remove(Monitor *mon, const QDict *qdict)
 {
     const char *aclname = qdict_get_str(qdict, "aclname");
     const char *match = qdict_get_str(qdict, "match");
@@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
 
 /* Please update hmp-commands.hx when adding or changing commands */
 static HMPCommand hmp_info_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands-info.h"
+#else
 #include "hmp-commands-info.h"
+#endif
     { NULL, NULL, },
 };
 
 /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
 HMPCommand hmp_cmds[] = {
+#if defined(SCSI_PROCESS)
+#include "hmp-scsi-commands.h"
+#else
 #include "hmp-commands.h"
+#endif
     { NULL, NULL, },
 };
 
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index 3e6baba..26349cb 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -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
diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
index 20fcc37..a8a3925 100644
--- a/qapi/Makefile.objs
+++ b/qapi/Makefile.objs
@@ -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)
diff --git a/qom/Makefile.objs b/qom/Makefile.objs
index 07e50e5..16603d7 100644
--- a/qom/Makefile.objs
+++ b/qom/Makefile.objs
@@ -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
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index e6da6ff..c3ac572 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (35 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 36/50] multi-process/mon: enable QMP module support in the " Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 10:51   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 38/50] multi-process/mon: Initialize QMP module for remote processes Jagannathan Raman
                   ` (16 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/chardev/char.c b/chardev/char.c
index 8723756..1d03ea0 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -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);
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 00589a6..e370320 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -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
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index b7bdd2b..d92bf1c 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -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 */
diff --git a/monitor/monitor.c b/monitor/monitor.c
index c1a6c44..5759b84 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -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;
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 5284ee9..23fc0df 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
diff --git a/remote/remote-opts.c b/remote/remote-opts.c
index 7e12700..565e641 100644
--- a/remote/remote-opts.c
+++ b/remote/remote-opts.c
@@ -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"
 /*
diff --git a/softmmu/vl.c b/softmmu/vl.c
index a8a6f35..4a4f52c 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
     return qdev_device_help(opts);
 }
 
-static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    Error *local_err = NULL;
-
-    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
-        if (local_err) {
-            error_propagate(errp, local_err);
-            return -1;
-        }
-        exit(0);
-    }
-    return 0;
-}
 
 #ifdef CONFIG_VIRTFS
 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
 }
 #endif
 
-static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
-{
-    return monitor_init_opts(opts, errp);
-}
-
-static void monitor_parse(const char *optarg, const char *mode, bool pretty)
-{
-    static int monitor_device_index = 0;
-    QemuOpts *opts;
-    const char *p;
-    char label[32];
-
-    if (strstart(optarg, "chardev:", &p)) {
-        snprintf(label, sizeof(label), "%s", p);
-    } else {
-        snprintf(label, sizeof(label), "compat_monitor%d",
-                 monitor_device_index);
-        opts = qemu_chr_parse_compat(label, optarg, true);
-        if (!opts) {
-            error_report("parse error: %s", optarg);
-            exit(1);
-        }
-    }
-
-    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
-    qemu_opt_set(opts, "mode", mode, &error_abort);
-    qemu_opt_set(opts, "chardev", label, &error_abort);
-    if (!strcmp(mode, "control")) {
-        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
-    } else {
-        assert(pretty == false);
-    }
-    monitor_device_index++;
-}
-
 struct device_config {
     enum {
         DEV_USB,       /* -usbdevice     */
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 38/50] multi-process/mon: Initialize QMP module for remote processes
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (36 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 39/50] multi-process: prevent duplicate memory initialization in remote Jagannathan Raman
                   ` (15 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 remote/remote-main.c | 11 +++++++++++
 remote/remote-opts.c | 10 ++++++++++
 2 files changed, 21 insertions(+)

diff --git a/remote/remote-main.c b/remote/remote-main.c
index 23fc0df..58d9905 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
diff --git a/remote/remote-opts.c b/remote/remote-opts.c
index 565e641..e22ad5c 100644
--- a/remote/remote-opts.c
+++ b/remote/remote-opts.c
@@ -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;
             }
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 39/50] multi-process: prevent duplicate memory initialization in remote
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (37 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 38/50] multi-process/mon: Initialize QMP module for remote processes Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 40/50] multi-process/mig: build migration module in the remote process Jagannathan Raman
                   ` (14 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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.

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 hw/proxy/qemu-proxy.c         | 13 ++++++++++++-
 include/hw/proxy/qemu-proxy.h |  1 +
 qdev-monitor.c                |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 741f02a..b1b9282 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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)
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 2a2c732..5de8129 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -49,6 +49,7 @@ struct PCIProxyDev {
     MPQemuLinkState *mpqemu_link;
 
     RemoteMemSync *sync;
+    bool mem_init;
     struct kvm_irqfd irqfd;
 
     EventNotifier intr;
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 27b2ddc..f120509 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (38 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 39/50] multi-process: prevent duplicate memory initialization in remote Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-04 15:58   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object Jagannathan Raman
                   ` (13 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

Add Makefile support to enable migration in remote process

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/Makefile.objs b/Makefile.objs
index 4b5db09..65009da 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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
diff --git a/Makefile.target b/Makefile.target
index 4ead5c3..4012ae5 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -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 :=
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index e7cdc76..21f9d8d 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -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
diff --git a/net/Makefile.objs b/net/Makefile.objs
index c5d076d..a8ad986 100644
--- a/net/Makefile.objs
+++ b/net/Makefile.objs
@@ -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
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 4a4f52c..42d5682 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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;
diff --git a/stubs/migration.c b/stubs/migration.c
index 28ccf80..dbd12db 100644
--- a/stubs/migration.c
+++ b/stubs/migration.c
@@ -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);
+}
diff --git a/stubs/net-stub.c b/stubs/net-stub.c
index 962827e..ddfd1e4 100644
--- a/stubs/net-stub.c
+++ b/stubs/net-stub.c
@@ -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);
+}
diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
index 3eeedd9..824eac1 100644
--- a/stubs/qapi-misc.c
+++ b/stubs/qapi-misc.c
@@ -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,
diff --git a/stubs/replay.c b/stubs/replay.c
index 9b53c0c..6fc7850 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -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;
+}
diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
index 606f078..5f308c1 100644
--- a/stubs/vl-stub.c
+++ b/stubs/vl-stub.c
@@ -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);
+}
diff --git a/vl-parse.c b/vl-parse.c
index 1f6a3f0..423f4a0 100644
--- a/vl-parse.c
+++ b/vl-parse.c
@@ -27,6 +27,9 @@
 
 #include "vl.h"
 
+int only_migratable; /* turn it off unless user states otherwise */
+bool enable_mlock;
+
 /***********************************************************/
 /* QEMU Block devices */
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (39 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 40/50] multi-process/mig: build migration module in the remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 12:31   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to " Jagannathan Raman
                   ` (12 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(+)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index b1b9282..19f0dbb 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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 = {
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 5de8129..537c227 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -75,6 +75,8 @@ struct PCIProxyDev {
                         bool need_spawn, Error **errp);
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
+
+    uint64_t migsize;
 };
 
 typedef struct PCIProxyDevClass {
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index d2234ca..b42c003 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -63,6 +63,7 @@ typedef enum {
     PROXY_PING,
     MMIO_RETURN,
     DEVICE_RESET,
+    START_MIG_OUT,
     MAX,
 } mpqemu_cmd_t;
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (40 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 14:39   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object Jagannathan Raman
                   ` (11 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 migration/savevm.c   | 27 +++++++++++++++++++++++++++
 migration/savevm.h   |  2 ++
 remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/migration/savevm.c b/migration/savevm.c
index 1d4220e..09af14d 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -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;
+}
diff --git a/migration/savevm.h b/migration/savevm.h
index ba64a7e..0491d3a 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -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
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 58d9905..e97eb76 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -53,6 +53,16 @@
 #include "qemu/log.h"
 #include "qemu/cutils.h"
 #include "remote-opts.h"
+#include "qapi/error.h"
+#include "io/channel-util.h"
+
+#include "io/channel.h"
+#include "io/channel-socket.h"
+#include "migration/qemu-file-types.h"
+#include "migration/savevm.h"
+#include "migration/qemu-file-channel.h"
+#include "migration/qemu-file.h"
+
 #include "monitor/monitor.h"
 #include "chardev/char.h"
 #include "sysemu/reset.h"
@@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
 
 }
 
+static void process_start_mig_out(MPQemuMsg *msg)
+{
+    int wait = msg->fds[1];
+    Error *err = NULL;
+    QIOChannel *ioc;
+    QEMUFile *f;
+
+    ioc = qio_channel_new_fd(msg->fds[0], &err);
+    if (err) {
+        error_report_err(err);
+        return;
+    }
+
+    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
+
+    f = qemu_fopen_channel_output(ioc);
+
+    bdrv_drain_all();
+    (void)bdrv_flush_all();
+
+    (void)qemu_remote_savevm(f);
+
+    qemu_fflush(f);
+
+    notify_proxy(wait, (uint64_t)qemu_ftell(f));
+    PUT_REMOTE_WAIT(wait);
+
+    qemu_fclose(f);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             notify_proxy(msg->fds[0], 0);
         }
         break;
+    case START_MIG_OUT:
+        process_start_mig_out(msg);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (41 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to " Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 15:28   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 44/50] multi-process/mig: refactor runstate_check into common file Jagannathan Raman
                   ` (10 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 hw/proxy/qemu-proxy.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 2 files changed, 51 insertions(+)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 19f0dbb..1649f60 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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),
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index b42c003..01371fc 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -64,6 +64,7 @@ typedef enum {
     MMIO_RETURN,
     DEVICE_RESET,
     START_MIG_OUT,
+    START_MIG_IN,
     MAX,
 } mpqemu_cmd_t;
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 44/50] multi-process/mig: refactor runstate_check into common file
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (42 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 45/50] multi-process/mig: Synchronize runstate of remote process Jagannathan Raman
                   ` (9 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

runstate_check file is refactored into vl-parse.c

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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

diff --git a/Makefile.objs b/Makefile.objs
index 65009da..cf2200d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -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
diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index f760094..ece939f 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -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);
diff --git a/runstate.c b/runstate.c
new file mode 100644
index 0000000..273345a
--- /dev/null
+++ b/runstate.c
@@ -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;
+}
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 42d5682..d95ee2f 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -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);
diff --git a/stubs/runstate-check.c b/stubs/runstate-check.c
index 2ccda2b..3038bcb 100644
--- a/stubs/runstate-check.c
+++ b/stubs/runstate-check.c
@@ -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;
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 45/50] multi-process/mig: Synchronize runstate of remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (43 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 44/50] multi-process/mig: refactor runstate_check into common file Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-24 20:55 ` [PATCH v5 46/50] multi-process/mig: Restore the VMSD in " Jagannathan Raman
                   ` (8 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Synchronize the runstate of the remote process with that of QEMU

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 1649f60..5876957 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 537c227..6784298 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -76,6 +76,8 @@ struct PCIProxyDev {
 
     ProxyMemoryRegion region[PCI_NUM_REGIONS];
 
+    VMChangeStateEntry *vmcse;
+
     uint64_t migsize;
 };
 
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 01371fc..beb8293 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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];
diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
index ece939f..8c5810f 100644
--- a/include/sysemu/runstate.h
+++ b/include/sysemu/runstate.h
@@ -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);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index f120509..8efa1a8 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
 }
 
diff --git a/remote/remote-main.c b/remote/remote-main.c
index e97eb76..0260c7c 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
diff --git a/remote/remote-opts.c b/remote/remote-opts.c
index e22ad5c..839baf1 100644
--- a/remote/remote-opts.c
+++ b/remote/remote-opts.c
@@ -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");
diff --git a/runstate.c b/runstate.c
index 273345a..9c5c627 100644
--- a/runstate.c
+++ b/runstate.c
@@ -34,3 +34,8 @@ bool runstate_check(RunState state)
 {
     return current_run_state == state;
 }
+
+void remote_runstate_set(RunState state)
+{
+    current_run_state = state;
+}
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 46/50] multi-process/mig: Restore the VMSD in remote process
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (44 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 45/50] multi-process/mig: Synchronize runstate of remote process Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-03-05 16:05   ` Dr. David Alan Gilbert
  2020-02-24 20:55 ` [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote Jagannathan Raman
                   ` (7 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 migration/savevm.c   | 36 ++++++++++++++++++++++++++++++++++++
 migration/savevm.h   |  1 +
 remote/remote-main.c | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)

diff --git a/migration/savevm.c b/migration/savevm.c
index 09af14d..e95ea4a 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -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;
+}
diff --git a/migration/savevm.h b/migration/savevm.h
index 0491d3a..8741c66 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -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
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 0260c7c..ab4ad0b 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (45 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 46/50] multi-process/mig: Restore the VMSD in " Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-28 16:44   ` Stefan Hajnoczi
  2020-02-24 20:55 ` [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy Jagannathan Raman
                   ` (6 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 5876957..4d4eff4 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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);
diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
index 6784298..5ff3aec 100644
--- a/include/hw/proxy/qemu-proxy.h
+++ b/include/hw/proxy/qemu-proxy.h
@@ -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;
 
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index beb8293..722f08c 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -124,6 +124,7 @@ typedef struct {
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
+    uint64_t id;
     size_t size;
 
     union {
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 8efa1a8..cda2545 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -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;
 
diff --git a/remote/remote-main.c b/remote/remote-main.c
index ab4ad0b..20d160e 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -72,15 +72,23 @@
 
 static MPQemuLinkState *mpqemu_link;
 
-PCIDevice *remote_pci_dev;
+PCIDevice **remote_pci_devs;
+uint64_t nr_devices;
+#define MAX_REMOTE_DEVICES 256
+
 bool create_done;
 
 static void process_config_write(MPQemuMsg *msg)
 {
     struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
 
+    if (msg->id > nr_devices) {
+        return;
+    }
+
     qemu_mutex_lock_iothread();
-    pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l);
+    pci_default_write_config(remote_pci_devs[msg->id], conf->addr, conf->val,
+                             conf->l);
     qemu_mutex_unlock_iothread();
 }
 
@@ -92,8 +100,13 @@ static void process_config_read(MPQemuMsg *msg)
 
     wait = msg->fds[0];
 
+    if (msg->id > nr_devices) {
+        return;
+    }
+
     qemu_mutex_lock_iothread();
-    val = pci_default_read_config(remote_pci_dev, conf->addr, conf->l);
+    val = pci_default_read_config(remote_pci_devs[msg->id], conf->addr,
+                                  conf->l);
     qemu_mutex_unlock_iothread();
 
     notify_proxy(wait, val);
@@ -282,6 +295,13 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
     }
 
     if (!msg->data2) {
+        error_setg(errp, "Message data is empty");
+        return rc;
+    }
+
+    if (msg->id > MAX_REMOTE_DEVICES) {
+        error_setg(errp, "id of the device is larger than max number of "\
+                         "devices per remote process.");
         return rc;
     }
 
@@ -319,8 +339,15 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
                    qstring_get_str(qobject_to_json(QOBJECT(qdict))));
         goto device_failed;
     }
+
     if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
-        remote_pci_dev = PCI_DEVICE(dev);
+        if (nr_devices <= msg->id) {
+            nr_devices = msg->id + 1;
+            remote_pci_devs = g_realloc(remote_pci_devs,
+                                        nr_devices * sizeof(PCIDevice *));
+        }
+
+        remote_pci_devs[msg->id] = PCI_DEVICE(dev);
     }
 
     notify_proxy(wait, (uint32_t)REMOTE_OK);
@@ -405,11 +432,17 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         goto finalize_loop;
     }
 
+    if (msg->id > MAX_REMOTE_DEVICES) {
+        error_setg(&err, "id of the device is larger than max number of "\
+                         "devices per remote process.");
+        goto finalize_loop;
+    }
+
     switch (msg->cmd) {
     case INIT:
         break;
     case GET_PCI_INFO:
-        process_get_pci_info_msg(remote_pci_dev, msg);
+        process_get_pci_info_msg(remote_pci_devs[msg->id], msg);
         break;
     case PCI_CONFIG_WRITE:
         if (create_done) {
@@ -449,12 +482,19 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         }
         break;
     case SET_IRQFD:
-        process_set_irqfd_msg(remote_pci_dev, msg);
-        qdev_machine_creation_done();
-        qemu_mutex_lock_iothread();
-        qemu_run_machine_init_done_notifiers();
-        qemu_mutex_unlock_iothread();
-        create_done = true;
+        if (msg->id > nr_devices) {
+            error_setg(&err, "incorrect device id in the message");
+            goto finalize_loop;
+        }
+        process_set_irqfd_msg(remote_pci_devs[msg->id], msg);
+
+        if (!create_done) {
+            qdev_machine_creation_done();
+            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)) {
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (46 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-27 17:18   ` Stefan Hajnoczi
  2020-02-24 20:55 ` [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
                   ` (5 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

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

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 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(-)

diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
index 4d4eff4..7330094 100644
--- a/hw/proxy/qemu-proxy.c
+++ b/hw/proxy/qemu-proxy.c
@@ -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,
diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
index 722f08c..2f44f31 100644
--- a/include/io/mpqemu-link.h
+++ b/include/io/mpqemu-link.h
@@ -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
diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
index 07a9be9..298bb58 100644
--- a/io/mpqemu-link.c
+++ b/io/mpqemu-link.c
@@ -65,7 +65,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s)
 void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
 {
     int rc;
-    uint8_t *data;
+    uint8_t *data = NULL;
     union {
         char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
         struct cmsghdr align;
@@ -335,3 +335,76 @@ void mpqemu_start_coms(MPQemuLinkState *s)
 
     g_main_loop_run(s->loop);
 }
+
+bool mpqemu_msg_valid(MPQemuMsg *msg)
+{
+    if (msg->cmd >= MAX) {
+        return false;
+    }
+
+    if (msg->bytestream) {
+        if (!msg->data2) {
+            return false;
+        }
+    } else {
+        if (msg->data2) {
+            return false;
+        }
+    }
+
+    /* Verify FDs. */
+    if (msg->num_fds >= REMOTE_MAX_FDS) {
+        return false;
+    }
+    if (msg->num_fds > 0) {
+        for (int i = 0; i < msg->num_fds; i++) {
+            if (fcntl(msg->fds[i], F_GETFL) == -1) {
+                return false;
+            }
+        }
+    }
+
+    /* Verify ID size. */
+    if (msg->id >= UINT64_MAX) {
+        return false;
+    }
+
+    /* Verify message specific fields. */
+    switch (msg->cmd) {
+    case SYNC_SYSMEM:
+        if (msg->num_fds == 0 || msg->bytestream != 0) {
+            return false;
+        }
+        if (msg->size != sizeof(msg->data1)) {
+            return false;
+        }
+        break;
+    case PCI_CONFIG_WRITE:
+    case PCI_CONFIG_READ:
+        if (msg->size != sizeof(struct conf_data_msg)) {
+            return false;
+        }
+        break;
+    case BAR_WRITE:
+    case BAR_READ:
+    case SET_IRQFD:
+    case MMIO_RETURN:
+    case DEVICE_RESET:
+    case RUNSTATE_SET:
+        if (msg->size != sizeof(msg->data1)) {
+            return false;
+        }
+        break;
+    case PROXY_PING:
+    case START_MIG_OUT:
+    case START_MIG_IN:
+        if (msg->size != 0) {
+            return false;
+        }
+        break;
+    default:
+        break;
+    }
+
+    return true;
+}
diff --git a/remote/remote-main.c b/remote/remote-main.c
index 20d160e..c4aa3e0 100644
--- a/remote/remote-main.c
+++ b/remote/remote-main.c
@@ -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;
     }
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (47 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-27 17:11   ` Stefan Hajnoczi
  2020-02-24 20:55 ` [PATCH v5 50/50] multi-process: add configure and usage information Jagannathan Raman
                   ` (4 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: John G Johnson <john.g.johnson@oracle.com>

Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
---
 docs/devel/index.rst             |    1 +
 docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1103 insertions(+)
 create mode 100644 docs/devel/qemu-multiprocess.rst

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index 4dc2ca8..1a95871 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -25,3 +25,4 @@ Contents:
    tcg-plugins
    bitops
    reset
+   multi-process
diff --git a/docs/devel/qemu-multiprocess.rst b/docs/devel/qemu-multiprocess.rst
new file mode 100644
index 0000000..477e246
--- /dev/null
+++ b/docs/devel/qemu-multiprocess.rst
@@ -0,0 +1,1102 @@
+Disaggregating QEMU
+===================
+
+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,
+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
+configuration QEMU has a large amount of code a guest can potentially
+attack. Disaggregating QEMU reduces the attack surface by aiding to
+limit each component in the system to only access the resources that
+it needs to perform its job.
+
+QEMU services
+-------------
+
+QEMU can be broadly described as providing three main services. One is a
+VM control point, where VMs can be created, migrated, re-configured, and
+destroyed. A second is to emulate the CPU instructions within the VM,
+often accelerated by HW virtualization features such as Intel's VT
+extensions. Finally, it provides IO services to the VM by emulating HW
+IO devices, such as disk and network devices.
+
+A disaggregated QEMU
+~~~~~~~~~~~~~~~~~~~~
+
+A disaggregated QEMU involves separating QEMU services into separate
+host processes. Each of these processes can be given only the privileges
+it needs to provide its service, e.g., a disk service could be given
+access only the the disk images it provides, and not be allowed to
+access other files, or any network devices. An attacker who compromised
+this service would not be able to use this exploit to access files or
+devices beyond what the disk service was given access to.
+
+A QEMU control process would remain, but in disaggregated mode, but will
+have no direct interfaces to the VM. During VM execution, it would still
+provide the user interface to hot-plug devices or live migrate the VM.
+
+A first step in creating a disaggregated QEMU is to separate IO services
+from the main QEMU program, which would continue to provide CPU
+emulation. i.e., the control process would also be the CPU emulation
+process. In a later phase, CPU emulation could be separated from the
+control process.
+
+Disaggregating IO services
+--------------------------
+
+Disaggregating IO services is a good place to begin QEMU disaggregating
+for a couple of reasons. One is the sheer number of IO devices QEMU can
+emulate provides a large surface of interfaces which could potentially
+be exploited, and, indeed, have been a source of exploits in the past.
+Another is the modular nature of QEMU device emulation code provides
+interface points where the QEMU functions that perform device emulation
+can be separated from the QEMU functions that manage the emulation of
+guest CPU instructions.
+
+QEMU device emulation
+~~~~~~~~~~~~~~~~~~~~~
+
+QEMU uses a object oriented SW architecture for device emulation code.
+Configured objects are all compiled into the QEMU binary, then objects
+are instantiated by name when used by the guest VM. For example, the
+code to emulate a device named "foo" is always present in QEMU, but its
+instantiation code is only run when the device is included in the target
+VM. (e.g., via the QEMU command line as *-device foo*)
+
+The object model is hierarchical, so device emulation code names its
+parent object (such as "pci-device" for a PCI device) and QEMU will
+instantiate a parent object before calling the device's instantiation
+code.
+
+Current separation models
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In order to separate the device emulation code from the CPU emulation
+code, the device object code must run in a different process. There are
+a couple of existing QEMU features that can run emulation code
+separately from the main QEMU process. These are examined below.
+
+vhost user model
+^^^^^^^^^^^^^^^^
+
+Virtio guest device drivers can be connected to vhost user applications
+in order to perform their IO operations. This model uses special virtio
+device drivers in the guest and vhost user device objects in QEMU, but
+once the QEMU vhost user code has configured the vhost user application,
+mission-mode IO is performed by the application. The vhost user
+application is a daemon process that can be contacted via a known UNIX
+domain socket.
+
+vhost socket
+''''''''''''
+
+As mentioned above, one of the tasks of the vhost device object within
+QEMU is to contact the vhost application and send it configuration
+information about this device instance. As part of the configuration
+process, the application can also be sent other file descriptors over
+the socket, which then can be used by the vhost user application in
+various ways, some of which are described below.
+
+vhost MMIO store acceleration
+'''''''''''''''''''''''''''''
+
+VMs are often run using HW virtualization features via the KVM kernel
+driver. This driver allows QEMU to accelerate the emulation of guest CPU
+instructions by running the guest in a virtual HW mode. When the guest
+executes instructions that cannot be executed by virtual HW mode,
+execution returns to the KVM driver so it can inform QEMU to emulate the
+instructions in SW.
+
+One of the events that can cause a return to QEMU is when a guest device
+driver accesses an IO location. QEMU then dispatches the memory
+operation to the corresponding QEMU device object. In the case of a
+vhost user device, the memory operation would need to be sent over a
+socket to the vhost application. This path is accelerated by the QEMU
+virtio code by setting up an eventfd file descriptor that the vhost
+application can directly receive MMIO store notifications from the KVM
+driver, instead of needing them to be sent to the QEMU process first.
+
+vhost interrupt acceleration
+''''''''''''''''''''''''''''
+
+Another optimization used by the vhost application is the ability to
+directly inject interrupts into the VM via the KVM driver, again,
+bypassing the need to send the interrupt back to the QEMU process first.
+The QEMU virtio setup code configures the KVM driver with an eventfd
+that triggers the device interrupt in the guest when the eventfd is
+written. This irqfd file descriptor is then passed to the vhost user
+application program.
+
+vhost access to guest memory
+''''''''''''''''''''''''''''
+
+The vhost application is also allowed to directly access guest memory,
+instead of needing to send the data as messages to QEMU. This is also
+done with file descriptors sent to the vhost user application by QEMU.
+These descriptors can be passed to ``mmap()`` by the vhost application
+to map the guest address space into the vhost application.
+
+IOMMUs introduce another level of complexity, since the address given to
+the guest virtio device to DMA to or from is not a guest physical
+address. This case is handled by having vhost code within QEMU register
+as a listener for IOMMU mapping changes. The vhost application maintains
+a cache of IOMMMU translations: sending translation requests back to
+QEMU on cache misses, and in turn receiving flush requests from QEMU
+when mappings are purged.
+
+applicability to device separation
+''''''''''''''''''''''''''''''''''
+
+Much of the vhost model can be re-used by separated device emulation. In
+particular, the ideas of using a socket between QEMU and the device
+emulation application, using a file descriptor to inject interrupts into
+the VM via KVM, and allowing the application to ``mmap()`` the guest
+should be re used.
+
+There are, however, some notable differences between how a vhost
+application works and the needs of separated device emulation. The most
+basic is that vhost uses custom virtio device drivers which always
+trigger IO with MMIO stores. A separated device emulation model must
+work with existing IO device models and guest device drivers. MMIO loads
+break vhost store acceleration since they are synchronous - guest
+progress cannot continue until the load has been emulated. By contrast,
+stores are asynchronous, the guest can continue after the store event
+has been sent to the vhost application.
+
+Another difference is that in the vhost user model, a single daemon can
+support multiple QEMU instances. This is contrary to the security regime
+desired, in which the emulation application should only be allowed to
+access the files or devices the VM it's running on behalf of can access.
+#### qemu-io model
+
+Qemu-io is a test harness used to test changes to the QEMU block backend
+object code. (e.g., the code that implements disk images for disk driver
+emulation) Qemu-io is not a device emulation application per se, but it
+does compile the QEMU block objects into a separate binary from the main
+QEMU one. This could be useful for disk device emulation, since its
+emulation applications will need to include the QEMU block objects.
+
+New separation model based on proxy objects
+-------------------------------------------
+
+A different model based on proxy objects in the QEMU program
+communicating with remote emulation programs could provide separation
+while minimizing the changes needed to the device emulation code. The
+rest of this section is a discussion of how a proxy object model would
+work.
+
+Remote emulation processes
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The remote emulation process will run the QEMU object hierarchy without
+modification. The device emulation objects will be also be based on the
+QEMU code, because for anything but the simplest device, it would not be
+a tractable to re-implement both the object model and the many device
+backends that QEMU has.
+
+The processes will communicate with the QEMU process over UNIX domain
+sockets. The processes can be executed either as standalone processes,
+or be executed by QEMU. In both cases, the host backends the emulation
+processes will provide are specified on its command line, as they would
+be for QEMU. For example:
+
+::
+
+    disk-proc -blockdev driver=file,node-name=file0,filename=disk-file0  \
+    -blockdev driver=qcow2,node-name=drive0,file=file0
+
+would indicate process *disk-proc* uses a qcow2 emulated disk named
+*file0* as its backend.
+
+Emulation processes may emulate more than one guest controller. A common
+configuration might be to put all controllers of the same device class
+(e.g., disk, network, etc.) in a single process, so that all backends of
+the same type can be managed by a single QMP monitor.
+
+communication with QEMU
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Remote emulation processes will recognize a *-socket* argument that
+specifies the path of a UNIX domain socket used to communicate with the
+QEMU process. If no *-socket* argument is present, the process will use
+file descriptor 0 to communicate with QEMU. For example,
+
+::
+
+    disk-proc -socket /tmp/disk0-sock <backend list>
+
+will communicate with QEMU using the socket path */tmp/disk0-sock*.
+
+remote process QMP monitor
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Remote emulation processes can be monitored via QMP, similar to QEMU
+itself. The QMP monitor socket is specified the same as for a QEMU
+process:
+
+::
+
+    disk-proc -qmp unix:/tmp/disk-mon,server
+
+can be monitored over the UNIX socket path */tmp/disk-mon*.
+
+QEMU command line
+~~~~~~~~~~~~~~~~~
+
+The QEMU command line options will need to be modified to indicate which
+items are emulated by a separate program, and which remain emulated by
+QEMU itself.
+
+identifying remote emulation processes
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Remote emulation processes will be identified to QEMU using a *-remote*
+command line option. This option can either specify a command that QEMU
+will execute, or can specify a UNIX domain socket that QEMU can use to
+connect to an existing process. Both forms require a "id" option that
+identifies the process to later *-device* options. The process version
+is:
+
+::
+
+    -remote id=disk-proc,rid=0,exec="disc-proc",command="<backend list>"
+
+And the socket version is:
+
+::
+
+    -remote id=disk-proc,rid=0,socket="/tmp/disk0-sock"
+
+In the latter case, the remote process must be given the same socket on
+its command line when it is executed:
+
+::
+
+    disk-proc -socket /tmp/disk0-sock <backend list>
+
+identifying devices emulated remotely
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Devices that are to be emulated in a separate process will identify
+the remote process with a "rid" option on their *-device* command
+line specification. e.g., an LSI SCSI controller and disk can be
+specified as:
+
+::
+
+    -device lsi53c895a,id=scsi0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0
+
+If these devices are emulated by remote process "disk-proc," as
+described in the previous section, the QEMU command line would be:
+
+::
+
+    -device lsi53c895a,id=scsi0,rid=0
+    -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0
+
+Some devices are implicitly created by the machine object. e.g., the q35
+machine object will create its PCI bus, and attach an ich9-ahci IDE
+controller to it. In this case, options will need to be added to the
+*-machine* command line. e.g.,
+
+::
+
+    -machine pc-q35,ide-remote=disk-proc
+
+will use the remote process with an "id" of "disk-proc" to emulate the
+IDE controller and its disks.
+
+The disks themselves still need to be specified with *-remote* option,
+as in the example above. e.g.,
+
+::
+
+    -device ide-hd,drive=drive0,bus=ide.0,unit=0,remote=disk-proc
+
+QEMU management of remote processes
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Each *-remote* instance on the QEMU command line will create a remote
+process proxy instance in QEMU. They will be held on a *QList* that can
+be searched for by its "id" property. The remote process proxy will also
+establish a communication channel between QEMU and the remote process.
+This can be done in one of two methods: direction execution of the
+process by QEMU with ``fork()`` and ``exec()`` system calls, or by
+connecting to an existing process.
+
+direct execution
+^^^^^^^^^^^^^^^^
+
+When the remote process is directly executed, the remote process proxy
+will setup a communication channel between itself and the emulation
+process. This channel will be created using ``socketpair()`` and the
+remote process side of the pair will be given to the process as file
+descriptor 0.
+
+connecting to an existing process
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Some environments wish to deny QEMU the ability to execute ``fork()``
+and ``exec()`` In these case, emulation processes will be started before
+QEMU, and a UNIX domain socket will be given to each emulation process
+to communicate with QEMU over. After communication is established, the
+socket will be unlinked from the file system space by the QEMU process.
+
+communication with emulation process
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+primary socket
+''''''''''''''
+
+Whether the process was executed by QEMU or externally, there will be a
+primary socket for communication between QEMU and the remote process.
+This channel will handle configuration commands from QEMU to the
+process, either from the QEMU command line, or from QMP commands that
+affect the devices being emulated by the process. This channel will only
+allow one message to be pending at a time; if additional messages
+arrive, they must wait for previous ones to be acknowledged from the
+remote side.
+
+secondary sockets
+'''''''''''''''''
+
+The primary socket can pass the file descriptors of secondary sockets
+for operations that occur in parallel with commands on the primary
+channel. These include MMIO operations generated by the guest, interrupt
+notifications generated by the devices being emulated, or *vmstate* for
+live migration. These secondary sockets will be created at the behest of
+the device proxies that require them. A disk device proxy wouldn't need
+any secondary sockets, but a disk controller device proxy may need both
+an MMIO socket and an interrupt socket.
+
+emulation process attached via QMP command
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The command "device-add" QMP command facilitates device hot-plug that is
+tp. This command's arguments will be the same as the *-remote*
+command line when it's used to attach to a remote process. i.e., it will
+need an "id" argument so that hot-plugged devices can later find it, and
+a "socket" argument to identify the UNIX domain socket that will be used
+to communicate with QEMU.
+
+QEMU device proxy objects
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+QEMU has an object model based on sub-classes inherited from the
+"object" super-class. The sub-classes that are of interest here are the
+"device" and "bus" sub-classes whose child sub-classes make up the
+device tree of a QEMU emulated system.
+
+The proxy object model will use device proxy objects to replace the
+device emulation code within the QEMU process. These objects will live
+in the same place in the object and bus hierarchies as the objects they
+replace. i.e., the proxy object for an LSI SCSI controller will be a
+sub-class of the "pci-device" class, and will have the same PCI bus
+parent and the same SCSI bus child objects as the LSI controller object
+it replaces.
+
+After the QEMU command line has been parsed, the remote devices will be
+instantiated in the same manner as local devices are. (i.e.,
+``qdev_device_add()``). In order to distinguish them from regular
+*-device* device objects, their class name will be the name of the class
+it replaces, with "-proxy" appended. e.g., the "lsi53c895a" proxy class
+will be "lsi53c895a-proxy."
+
+device JSON description
+^^^^^^^^^^^^^^^^^^^^^^^
+
+The remote process needs a JSON representation of the command line
+options used to create the object. This JSON representation is used to
+create the corresponding object in the emulation process. e.g., for an
+LSI SCSI controller invoked as:
+
+::
+
+     -device lsi53c895a,id=scsi0,remote=lsi-scsi
+
+the proxy object would create a
+
+::
+
+    { "driver" : "lsi53c895a", "id" : "scsi0" }
+
+JSON description. The "driver" option is assigned to the device name
+when the command line is parsed, so the "-proxy" appended by the command
+line parsing code is removed. The "remote" option isn't needed in the
+JSON description since it only applies to the proxy object in the QEMU
+process.
+
+device object whitelist
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Some device objects may not need a proxy. These are devices with no
+direct guest interfaces. (e.g., no MMIO, PIO, or interrupts). There will
+be a whitelist of such devices, and any devices on this list will not be
+instantiated in QEMU. Their JSON representation will still be sent to
+the remote process, so the object can be created there.
+
+object initialization
+^^^^^^^^^^^^^^^^^^^^^
+
+QEMU object initialization occurs in two phases. The first
+initialization happens once per object class. (i.e., there can be many
+SCSI disks in an emulated system, but the "scsi-hd" class has its
+``class_init()`` function called only once) The second phase happens
+when each object's ``instance_init()`` function is called to initialize
+each instance of the object.
+
+All device objects are sub-classes of the "device" class, so they also
+have a ``realize()`` function that is called after ``instance_init()``
+is called and after the object's static properties have been
+initialized. Many device objects don't even provide an instance\_init()
+function, and do all their per-instance work in ``realize()``.
+
+class\_init
+'''''''''''
+
+The ``class_init()`` method of a proxy object will, in general behave
+similarly to the object it replaces, including setting any static
+properties and methods needed by the proxy.
+
+instance\_init / realize
+''''''''''''''''''''''''
+
+The ``instance_init()`` and ``realize()`` functions would only need to
+perform tasks related to being a proxy, such are registering its own
+MMIO handlers, or creating a child bus that other proxy devices can be
+attached to later.
+
+Other tasks will are device-specific. For example, PCI device objects
+will initialize the PCI config space in order to make a valid PCI device
+tree within the QEMU process.
+
+address space registration
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Most devices are driven by guest device driver accesses to IO addresses
+or ports. The QEMU device emulation code uses QEMU's memory region
+function calls (such as ``memory_region_init_io()``) to add callback
+functions that QEMU will invoke when the guest accesses the device's
+areas of the IO address space. When a guest driver does access the
+device, the VM will exit HW virtualization mode and return to QEMU,
+which will then lookup and execute the corresponding callback function.
+
+A proxy object would need to mirror the memory region calls the actual
+device emulator would perform in its initialization code, but with its
+own callbacks. When invoked by QEMU as a result of a guest IO operation,
+they will forward the operation to the device emulation process.
+
+PCI config space
+^^^^^^^^^^^^^^^^
+
+PCI devices also have a configuration space that can be accessed by the
+guest driver. Guest accesses to this space is not handled by the device
+emulation object, but by its PCI parent object. Much of this space is
+read-only, but certain registers (especially BAR and MSI-related ones)
+need to be propagated to the emulation process.
+
+PCI parent proxy
+''''''''''''''''
+
+One way to propagate guest PCI config accesses is to create a
+"pci-device-proxy" class that can serve as the parent of a PCI device
+proxy object. This class's parent would be "pci-device" and it would
+override the PCI parent's ``config_read()`` and ``config_write()``
+methods with ones that forward these operations to the emulation
+program.
+
+interrupt receipt
+^^^^^^^^^^^^^^^^^
+
+A proxy for a device that generates interrupts will need to create a
+socket to receive interrupt indications from the emulation process. An
+incoming interrupt indication would then be sent up to its bus parent to
+be injected into the guest. For example, a PCI device object may use
+``pci_set_irq()``.
+
+live migration
+^^^^^^^^^^^^^^
+
+The proxy will register to save and restore any *vmstate* it needs over
+a live migration event. The device proxy does not need to manage the
+remote device's *vmstate*; that will be handled by the remote process
+proxy (see below).
+
+QEMU remote device operation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Generic device operations, such as DMA, will be performed by the remote
+process proxy by sending messages to the remote process.
+
+DMA operations
+^^^^^^^^^^^^^^
+
+DMA operations would be handled much like vhost applications do. One of
+the initial messages sent to the emulation process is a guest memory
+table. Each entry in this table consists of a file descriptor and size
+that the emulation process can ``mmap()`` to directly access guest
+memory, similar to ``vhost_user_set_mem_table()``. Note guest memory
+must be backed by file descriptors, such as when QEMU is given the
+*-mem-path* command line option.
+
+IOMMU operations
+^^^^^^^^^^^^^^^^
+
+When the emulated system includes an IOMMU, the remote process proxy in
+QEMU will need to create a socket for IOMMU requests from the emulation
+process. It will handle those requests with an
+``address_space_get_iotlb_entry()`` call. In order to handle IOMMU
+unmaps, the remote process proxy will also register as a listener on the
+device's DMA address space. When an IOMMU memory region is created
+within the DMA address space, an IOMMU notifier for unmaps will be added
+to the memory region that will forward unmaps to the emulation process
+over the IOMMU socket.
+
+device hot-plug via QMP
+^^^^^^^^^^^^^^^^^^^^^^^
+
+An QMP "device\_add" command can add a device emulated by a remote
+process. It will also have "rid" option to the command, just as the
+*-device* command line option does. The remote process may either be one
+started at QEMU startup, or be one added by the "add-process" QMP
+command described above. In either case, the remote process proxy will
+forward the new device's JSON description to the corresponding emulation
+process.
+
+live migration
+^^^^^^^^^^^^^^
+
+The remote process proxy will also register for live migration
+notifications with ``vmstate_register()``. When called to save state,
+the proxy will send the remote process a secondary socket file
+descriptor to save the remote process's device *vmstate* over. The
+incoming byte stream length and data will be saved as the proxy's
+*vmstate*. When the proxy is resumed on its new host, this *vmstate*
+will be extracted, and a secondary socket file descriptor will be sent
+to the new remote process through which it receives the *vmstate* in
+order to restore the devices there.
+
+device emulation in remote process
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The parts of QEMU that the emulation program will need include the
+object model; the memory emulation objects; the device emulation objects
+of the targeted device, and any dependent devices; and, the device's
+backends. It will also need code to setup the machine environment,
+handle requests from the QEMU process, and route machine-level requests
+(such as interrupts or IOMMU mappings) back to the QEMU process.
+
+initialization
+''''''''''''''
+
+The process initialization sequence will follow the same sequence
+followed by QEMU. It will first initialize the backend objects, then
+device emulation objects. The JSON descriptions sent by the QEMU process
+will drive which objects need to be created.
+
+-  address spaces
+
+Before the device objects are created, the initial address spaces and
+memory regions must be configured with ``memory_map_init()``. This
+creates a RAM memory region object (*system\_memory*) and an IO memory
+region object (*system\_io*).
+
+-  RAM
+
+RAM memory region creation will follow how ``pc_memory_init()`` creates
+them, but must use ``memory_region_init_ram_from_fd()`` instead of
+``memory_region_allocate_system_memory()``. The file descriptors needed
+will be supplied by the guest memory table from above. Those RAM regions
+would then be added to the *system\_memory* memory region with
+``memory_region_add_subregion()``.
+
+-  PCI
+
+IO initialization will be driven by the JSON descriptions sent from the
+QEMU process. For a PCI device, a PCI bus will need to be created with
+``pci_root_bus_new()``, and a PCI memory region will need to be created
+and added to the *system\_memory* memory region with
+``memory_region_add_subregion_overlap()``. The overlap version is
+required for architectures where PCI memory overlaps with RAM memory.
+
+MMIO handling
+'''''''''''''
+
+The device emulation objects will use ``memory_region_init_io()`` to
+install their MMIO handlers, and ``pci_register_bar()`` to associate
+those handlers with a PCI BAR, as they do within QEMU currently.
+
+In order to use ``address_space_rw()`` in the emulation process to
+handle MMIO requests from QEMU, the PCI physical addresses must be the
+same in the QEMU process and the device emulation process. In order to
+accomplish that, guest BAR programming must also be forwarded from QEMU
+to the emulation process.
+
+interrupt injection
+'''''''''''''''''''
+
+When device emulation wants to inject an interrupt into the VM, the
+request climbs the device's bus object hierarchy until the point where a
+bus object knows how to signal the interrupt to the guest. The details
+depend on the type of interrupt being raised.
+
+-  PCI pin interrupts
+
+On x86 systems, there is an emulated IOAPIC object attached to the root
+PCI bus object, and the root PCI object forwards interrupt requests to
+it. The IOAPIC object, in turn, calls the KVM driver to inject the
+corresponding interrupt into the VM. The simplest way to handle this in
+an emulation process would be to setup the root PCI bus driver (via
+``pci_bus_irqs()``) to send a interrupt request back to the QEMU
+process, and have the device proxy object reflect it up the PCI tree
+there.
+
+-  PCI MSI/X interrupts
+
+PCI MSI/X interrupts are implemented in HW as DMA writes to a
+CPU-specific PCI address. In QEMU on x86, a KVM APIC object receives
+these DMA writes, then calls into the KVM driver to inject the interrupt
+into the VM. A simple emulation process implementation would be to send
+the MSI DMA address from QEMU as a message at initialization, then
+install an address space handler at that address which forwards the MSI
+message back to QEMU.
+
+DMA operations
+''''''''''''''
+
+When a emulation object wants to DMA into or out of guest memory, it
+first must use dma\_memory\_map() to convert the DMA address to a local
+virtual address. The emulation process memory region objects setup above
+will be used to translate the DMA address to a local virtual address the
+device emulation code can access.
+
+IOMMU
+'''''
+
+When an IOMMU is in use in QEMU, DMA translation uses IOMMU memory
+regions to translate the DMA address to a guest physical address before
+that physical address can be translated to a local virtual address. The
+emulation process will need similar functionality.
+
+-  IOTLB cache
+
+The emulation process will maintain a cache of recent IOMMU translations
+(the IOTLB). When the translate() callback of an IOMMU memory region is
+invoked, the IOTLB cache will be searched for an entry that will map the
+DMA address to a guest PA. On a cache miss, a message will be sent back
+to QEMU requesting the corresponding translation entry, which be both be
+used to return a guest address and be added to the cache.
+
+-  IOTLB purge
+
+The IOMMU emulation will also need to act on unmap requests from QEMU.
+These happen when the guest IOMMU driver purges an entry from the
+guest's translation table.
+
+live migration
+''''''''''''''
+
+When a remote process receives a live migration indication from QEMU, it
+will set up a channel using the received file descriptor with
+``qio_channel_socket_new_fd()``. This channel will be used to create a
+*QEMUfile* that can be passed to ``qemu_save_device_state()`` to send
+the process's device state back to QEMU. This method will be reversed on
+restore - the channel will be passed to ``qemu_loadvm_state()`` to
+restore the device state.
+
+Accelerating device emulation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The messages that are required to be sent between QEMU and the emulation
+process can add considerable latency to IO operations. The optimizations
+described below attempt to ameliorate this effect by allowing the
+emulation process to communicate directly with the kernel KVM driver.
+The KVM file descriptors created would be passed to the emulation process
+via initialization messages, much like the guest memory table is done.
+#### MMIO acceleration
+
+Vhost user applications can receive guest virtio driver stores directly
+from KVM. The issue with the eventfd mechanism used by vhost user is
+that it does not pass any data with the event indication, so it cannot
+handle guest loads or guest stores that carry store data. This concept
+could, however, be expanded to cover more cases.
+
+The expanded idea would require a new type of KVM device:
+*KVM\_DEV\_TYPE\_USER*. This device has two file descriptors: a master
+descriptor that QEMU can use for configuration, and a slave descriptor
+that the emulation process can use to receive MMIO notifications. QEMU
+would create both descriptors using the KVM driver, and pass the slave
+descriptor to the emulation process via an initialization message.
+
+data structures
+'''''''''''''''
+
+-  guest physical range
+
+The guest physical range structure describes the address range that a
+device will respond to. It includes the base and length of the range, as
+well as which bus the range resides on (e.g., on an x86machine, it can
+specify whether the range refers to memory or IO addresses).
+
+A device can have multiple physical address ranges it responds to (e.g.,
+a PCI device can have multiple BARs), so the structure will also include
+an enumerated identifier to specify which of the device's ranges is
+being referred to.
+
++--------+----------------------------+
+| Name   | Description                |
++========+============================+
+| addr   | range base address         |
++--------+----------------------------+
+| len    | range length               |
++--------+----------------------------+
+| bus    | addr type (memory or IO)   |
++--------+----------------------------+
+| id     | range ID (e.g., PCI BAR)   |
++--------+----------------------------+
+
+-  MMIO request structure
+
+This structure describes an MMIO operation. It includes which guest
+physical range the MMIO was within, the offset within that range, the
+MMIO type (e.g., load or store), and its length and data. It also
+includes a sequence number that can be used to reply to the MMIO, and
+the CPU that issued the MMIO.
+
++----------+------------------------+
+| Name     | Description            |
++==========+========================+
+| rid      | range MMIO is within   |
++----------+------------------------+
+| offset   | offset withing *rid*   |
++----------+------------------------+
+| type     | e.g., load or store    |
++----------+------------------------+
+| len      | MMIO length            |
++----------+------------------------+
+| data     | store data             |
++----------+------------------------+
+| seq      | sequence ID            |
++----------+------------------------+
+
+-  MMIO request queues
+
+MMIO request queues are FIFO arrays of MMIO request structures. There
+are two queues: pending queue is for MMIOs that haven't been read by the
+emulation program, and the sent queue is for MMIOs that haven't been
+acknowledged. The main use of the second queue is to validate MMIO
+replies from the emulation program.
+
+-  scoreboard
+
+Each CPU in the VM is emulated in QEMU by a separate thread, so multiple
+MMIOs may be waiting to be consumed by an emulation program and multiple
+threads may be waiting for MMIO replies. The scoreboard would contain a
+wait queue and sequence number for the per-CPU threads, allowing them to
+be individually woken when the MMIO reply is received from the emulation
+program. It also tracks the number of posted MMIO stores to the device
+that haven't been replied to, in order to satisfy the PCI constraint
+that a load to a device will not complete until all previous stores to
+that device have been completed.
+
+-  device shadow memory
+
+Some MMIO loads do not have device side-effects. These MMIOs can be
+completed without sending a MMIO request to the emulation program if the
+emulation program shares a shadow image of the device's memory image
+with the KVM driver.
+
+The emulation program will ask the KVM driver to allocate memory for the
+shadow image, and will then use ``mmap()`` to directly access it. The
+emulation program can control KVM access to the shadow image by sending
+KVM an access map telling it which areas of the image have no
+side-effects (and can be completed immediately), and which require a
+MMIO request to the emulation program. The access map can also inform
+the KVM drive which size accesses are allowed to the image.
+
+master descriptor
+'''''''''''''''''
+
+The master descriptor is used by QEMU to configure the new KVM device.
+The descriptor would be returned by the KVM driver when QEMU issues a
+*KVM\_CREATE\_DEVICE* ``ioctl()`` with a *KVM\_DEV\_TYPE\_USER* type.
+
+KVM\_DEV\_TYPE\_USER device ops
+
+
+The *KVM\_DEV\_TYPE\_USER* operations vector will be registered by a
+``kvm_register_device_ops()`` call when the KVM system in initialized by
+``kvm_init()``. These device ops are called by the KVM driver when QEMU
+executes certain ``ioctl()`` operations on its KVM file descriptor. They
+include:
+
+-  create
+
+This routine is called when QEMU issues a *KVM\_CREATE\_DEVICE*
+``ioctl()`` on its per-VM file descriptor. It will allocate and
+initialize a KVM user device specific data structure, and assign the
+*kvm\_device* private field to it.
+
+-  ioctl
+
+This routine is invoked when QEMU issues an ``ioctl()`` on the master
+descriptor. The ``ioctl()`` commands supported are defined by the KVM
+device type. *KVM\_DEV\_TYPE\_USER* ones will need several commands:
+
+*KVM\_DEV\_USER\_SLAVE\_FD* creates the slave file descriptor thatwill
+be passed to the device emulation program. Only one slave can be created
+by each master descriptor. The file operations performed by this
+descriptor are described below.
+
+The *KVM\_DEV\_USER\_PA\_RANGE* command configures a guest physical
+address range that the slave descriptor will receive MMIO notifications
+for. The range is specified by a guest physical range structure
+argument. For buses that assign addresses to devices dynamically, this
+command can be executed while the guest is running, such as the case
+when a guest changes a device's PCI BAR registers.
+
+*KVM\_DEV\_USER\_PA\_RANGE* will use ``kvm_io_bus_register_dev()`` to
+register *kvm\_io\_device\_ops* callbacks to be invoked when the guest
+performs a MMIO operation within the range. When a range is changed,
+``kvm_io_bus_unregister_dev()`` is used to remove the previous
+instantiation.
+
+*KVM\_DEV\_USER\_TIMEOUT* will configure a timeout value that specifies
+how long KVM will wait for the emulation process to respond to a MMIO
+indication.
+
+-  destroy
+
+This routine is called when the VM instance is destroyed. It will need
+to destroy the slave descriptor; and free any memory allocated by the
+driver, as well as the *kvm\_device* structure itself.
+
+slave descriptor
+''''''''''''''''
+
+The slave descriptor will have its own file operations vector, which
+responds to system calls on the descriptor performed by the device
+emulation program.
+
+-  read
+
+A read returns any pending MMIO requests from the KVM driver as MMIO
+request structures. Multiple structures can be returned if there are
+multiple MMIO operations pending. The MMIO requests are moved from the
+pending queue to the sent queue, and if there are threads waiting for
+space in the pending to add new MMIO operations, they will be woken
+here.
+
+-  write
+
+A write also consists of a set of MMIO requests. They are compared to
+the MMIO requests in the sent queue. Matches are removed from the sent
+queue, and any threads waiting for the reply are woken. If a store is
+removed, then the number of posted stores in the per-CPU scoreboard is
+decremented. When the number is zero, and a non side-effect load was
+waiting for posted stores to complete, the load is continued.
+
+-  ioctl
+
+There are several ioctl()s that can be performed on the slave
+descriptor.
+
+A *KVM\_DEV\_USER\_SHADOW\_SIZE* ``ioctl()`` causes the KVM driver to
+allocate memory for the shadow image. This memory can later be
+``mmap()``\ ed by the emulation process to share the emulation's view of
+device memory with the KVM driver.
+
+A *KVM\_DEV\_USER\_SHADOW\_CTRL* ``ioctl()`` controls access to the
+shadow image. It will send the KVM driver a shadow control map, which
+specifies which areas of the image can complete guest loads without
+sending the load request to the emulation program. It will also specify
+the size of load operations that are allowed.
+
+-  poll
+
+An emulation program will use the ``poll()`` call with a *POLLIN* flag
+to determine if there are MMIO requests waiting to be read. It will
+return if the pending MMIO request queue is not empty.
+
+-  mmap
+
+This call allows the emulation program to directly access the shadow
+image allocated by the KVM driver. As device emulation updates device
+memory, changes with no side-effects will be reflected in the shadow,
+and the KVM driver can satisfy guest loads from the shadow image without
+needing to wait for the emulation program.
+
+kvm\_io\_device ops
+'''''''''''''''''''
+
+Each KVM per-CPU thread can handle MMIO operation on behalf of the guest
+VM. KVM will use the MMIO's guest physical address to search for a
+matching *kvm\_io\_device* to see if the MMIO can be handled by the KVM
+driver instead of exiting back to QEMU. If a match is found, the
+corresponding callback will be invoked.
+
+-  read
+
+This callback is invoked when the guest performs a load to the device.
+Loads with side-effects must be handled synchronously, with the KVM
+driver putting the QEMU thread to sleep waiting for the emulation
+process reply before re-starting the guest. Loads that do not have
+side-effects may be optimized by satisfying them from the shadow image,
+if there are no outstanding stores to the device by this CPU. PCI memory
+ordering demands that a load cannot complete before all older stores to
+the same device have been completed.
+
+-  write
+
+Stores can be handled asynchronously unless the pending MMIO request
+queue is full. In this case, the QEMU thread must sleep waiting for
+space in the queue. Stores will increment the number of posted stores in
+the per-CPU scoreboard, in order to implement the PCI ordering
+constraint above.
+
+interrupt acceleration
+^^^^^^^^^^^^^^^^^^^^^^
+
+This performance optimization would work much like a vhost user
+application does, where the QEMU process sets up *eventfds* that cause
+the device's corresponding interrupt to be triggered by the KVM driver.
+These irq file descriptors are sent to the emulation process at
+initialization, and are used when the emulation code raises a device
+interrupt.
+
+intx acceleration
+'''''''''''''''''
+
+Traditional PCI pin interrupts are level based, so, in addition to an
+irq file descriptor, a re-sampling file descriptor needs to be sent to
+the emulation program. This second file descriptor allows multiple
+devices sharing an irq to be notified when the interrupt has been
+acknowledged by the guest, so they can re-trigger the interrupt if their
+device has not de-asserted its interrupt.
+
+intx irq descriptor
+
+
+The irq descriptors are created by the proxy object
+``using event_notifier_init()`` to create the irq and re-sampling
+*eventds*, and ``kvm_vm_ioctl(KVM_IRQFD)`` to bind them to an interrupt.
+The interrupt route can be found with
+``pci_device_route_intx_to_irq()``.
+
+intx routing changes
+
+
+Intx routing can be changed when the guest programs the APIC the device
+pin is connected to. The proxy object in QEMU will use
+``pci_device_set_intx_routing_notifier()`` to be informed of any guest
+changes to the route. This handler will broadly follow the VFIO
+interrupt logic to change the route: de-assigning the existing irq
+descriptor from its route, then assigning it the new route. (see
+``vfio_intx_update()``)
+
+MSI/X acceleration
+''''''''''''''''''
+
+MSI/X interrupts are sent as DMA transactions to the host. The interrupt
+data contains a vector that is programed by the guest, A device may have
+multiple MSI interrupts associated with it, so multiple irq descriptors
+may need to be sent to the emulation program.
+
+MSI/X irq descriptor
+
+
+This case will also follow the VFIO example. For each MSI/X interrupt,
+an *eventfd* is created, a virtual interrupt is allocated by
+``kvm_irqchip_add_msi_route()``, and the virtual interrupt is bound to
+the eventfd with ``kvm_irqchip_add_irqfd_notifier()``.
+
+MSI/X config space changes
+
+
+The guest may dynamically update several MSI-related tables in the
+device's PCI config space. These include per-MSI interrupt enables and
+vector data. Additionally, MSIX tables exist in device memory space, not
+config space. Much like the BAR case above, the proxy object must look
+at guest config space programming to keep the MSI interrupt state
+consistent between QEMU and the emulation program.
+
+--------------
+
+Disaggregated CPU emulation
+---------------------------
+
+After IO services have been disaggregated, a second phase would be to
+separate a process to handle CPU instruction emulation from the main
+QEMU control function. There are no object separation points for this
+code, so the first task would be to create one.
+
+Host access controls
+--------------------
+
+Separating QEMU relies on the host OS's access restriction mechanisms to
+enforce that the differing processes can only access the objects they
+are entitled to. There are a couple types of mechanisms usually provided
+by general purpose OSs.
+
+Discretionary access control
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Discretionary access control allows each user to control who can access
+their files. In Linux, this type of control is usually too coarse for
+QEMU separation, since it only provides three separate access controls:
+one for the same user ID, the second for users IDs with the same group
+ID, and the third for all other user IDs. Each device instance would
+need a separate user ID to provide access control, which is likely to be
+unwieldy for dynamically created VMs.
+
+Mandatory access control
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Mandatory access control allows the OS to add an additional set of
+controls on top of discretionary access for the OS to control. It also
+adds other attributes to processes and files such as types, roles, and
+categories, and can establish rules for how processes and files can
+interact.
+
+Type enforcement
+^^^^^^^^^^^^^^^^
+
+Type enforcement assigns a *type* attribute to processes and files, and
+allows rules to be written on what operations a process with a given
+type can perform on a file with a given type. QEMU separation could take
+advantage of type enforcement by running the emulation processes with
+different types, both from the main QEMU process, and from the emulation
+processes of different classes of devices.
+
+For example, guest disk images and disk emulation processes could have
+types separate from the main QEMU process and non-disk emulation
+processes, and the type rules could prevent processes other than disk
+emulation ones from accessing guest disk images. Similarly, network
+emulation processes can have a type separate from the main QEMU process
+and non-network emulation process, and only that type can access the
+host tun/tap device used to provide guest networking.
+
+Category enforcement
+^^^^^^^^^^^^^^^^^^^^
+
+Category enforcement assigns a set of numbers within a given range to
+the process or file. The process is granted access to the file if the
+process's set is a superset of the file's set. This enforcement can be
+used to separate multiple instances of devices in the same class.
+
+For example, if there are multiple disk devices provides to a guest,
+each device emulation process could be provisioned with a separate
+category. The different device emulation processes would not be able to
+access each other's backing disk images.
+
+Alternatively, categories could be used in lieu of the type enforcement
+scheme described above. In this scenario, different categories would be
+used to prevent device emulation processes in different classes from
+accessing resources assigned to other classes.
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* [PATCH v5 50/50] multi-process: add configure and usage information
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (48 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
@ 2020-02-24 20:55 ` Jagannathan Raman
  2020-02-27 16:58   ` Stefan Hajnoczi
  2020-02-24 21:59 ` [PATCH v5 00/50] Initial support for multi-process qemu no-reply
                   ` (3 subsequent siblings)
  53 siblings, 1 reply; 117+ messages in thread
From: Jagannathan Raman @ 2020-02-24 20:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

From: Elena Ufimtseva <elena.ufimtseva@oracle.com>

Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
---
 docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 docs/qemu-multiprocess.txt

diff --git a/docs/qemu-multiprocess.txt b/docs/qemu-multiprocess.txt
new file mode 100644
index 0000000..f156177
--- /dev/null
+++ b/docs/qemu-multiprocess.txt
@@ -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
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (49 preceding siblings ...)
  2020-02-24 20:55 ` [PATCH v5 50/50] multi-process: add configure and usage information Jagannathan Raman
@ 2020-02-24 21:59 ` no-reply
  2020-02-24 22:03 ` no-reply
                   ` (2 subsequent siblings)
  53 siblings, 0 replies; 117+ messages in thread
From: no-reply @ 2020-02-24 21:59 UTC (permalink / raw)
  To: jag.raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, thanos.makatos

Patchew URL: https://patchew.org/QEMU/cover.1582576372.git.jag.raman@oracle.com/



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: cover.1582576372.git.jag.raman@oracle.com
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/20200224205533.23798-1-philmd@redhat.com -> patchew/20200224205533.23798-1-philmd@redhat.com
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/cover.1582576372.git.jag.raman@oracle.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (50 preceding siblings ...)
  2020-02-24 21:59 ` [PATCH v5 00/50] Initial support for multi-process qemu no-reply
@ 2020-02-24 22:03 ` no-reply
  2020-02-24 22:23 ` no-reply
  2020-03-01 11:57 ` Alex Bennée
  53 siblings, 0 replies; 117+ messages in thread
From: no-reply @ 2020-02-24 22:03 UTC (permalink / raw)
  To: jag.raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, thanos.makatos

Patchew URL: https://patchew.org/QEMU/cover.1582576372.git.jag.raman@oracle.com/



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/cover.1582576372.git.jag.raman@oracle.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (51 preceding siblings ...)
  2020-02-24 22:03 ` no-reply
@ 2020-02-24 22:23 ` no-reply
  2020-03-01 11:57 ` Alex Bennée
  53 siblings, 0 replies; 117+ messages in thread
From: no-reply @ 2020-02-24 22:23 UTC (permalink / raw)
  To: jag.raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, jag.raman, quintela, mst, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, thanos.makatos

Patchew URL: https://patchew.org/QEMU/cover.1582576372.git.jag.raman@oracle.com/



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/cover.1582576372.git.jag.raman@oracle.com/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 50/50] multi-process: add configure and usage information
  2020-02-24 20:55 ` [PATCH v5 50/50] multi-process: add configure and usage information Jagannathan Raman
@ 2020-02-27 16:58   ` Stefan Hajnoczi
  2020-02-28 18:43     ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-02-27 16:58 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 4381 bytes --]

On Mon, Feb 24, 2020 at 03:55:41PM -0500, Jagannathan Raman wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>  docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 86 insertions(+)
>  create mode 100644 docs/qemu-multiprocess.txt
> 
> diff --git a/docs/qemu-multiprocess.txt b/docs/qemu-multiprocess.txt
> new file mode 100644
> index 0000000..f156177
> --- /dev/null
> +++ b/docs/qemu-multiprocess.txt
> @@ -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

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

> +
> +* 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

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?

> +* 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.

> +
> +  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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess
  2020-02-24 20:55 ` [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
@ 2020-02-27 17:11   ` Stefan Hajnoczi
  2020-02-28 18:44     ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-02-27 17:11 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 2217 bytes --]

On Mon, Feb 24, 2020 at 03:55:40PM -0500, Jagannathan Raman wrote:
> From: John G Johnson <john.g.johnson@oracle.com>
> 
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  docs/devel/index.rst             |    1 +
>  docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 1103 insertions(+)
>  create mode 100644 docs/devel/qemu-multiprocess.rst
> 
> diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> index 4dc2ca8..1a95871 100644
> --- a/docs/devel/index.rst
> +++ b/docs/devel/index.rst
> @@ -25,3 +25,4 @@ Contents:
>     tcg-plugins
>     bitops
>     reset
> +   multi-process
> diff --git a/docs/devel/qemu-multiprocess.rst b/docs/devel/qemu-multiprocess.rst
> new file mode 100644
> index 0000000..477e246
> --- /dev/null
> +++ b/docs/devel/qemu-multiprocess.rst
> @@ -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.

> +===================
> +
> +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/

> +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/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy
  2020-02-24 20:55 ` [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy Jagannathan Raman
@ 2020-02-27 17:18   ` Stefan Hajnoczi
  2020-02-28 17:53     ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-02-27 17:18 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]

On Mon, Feb 24, 2020 at 03:55:39PM -0500, Jagannathan Raman wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Validate the incoming commands to confirm that they would not cause any
> errors in the remote process.
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>  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).

> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index 20d160e..c4aa3e0 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote
  2020-02-24 20:55 ` [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote Jagannathan Raman
@ 2020-02-28 16:44   ` Stefan Hajnoczi
  2020-03-02 19:28     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-02-28 16:44 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 856 bytes --]

On Mon, Feb 24, 2020 at 03:55:38PM -0500, Jagannathan Raman wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> 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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy
  2020-02-27 17:18   ` Stefan Hajnoczi
@ 2020-02-28 17:53     ` Elena Ufimtseva
  0 siblings, 0 replies; 117+ messages in thread
From: Elena Ufimtseva @ 2020-02-28 17:53 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Thu, Feb 27, 2020 at 05:18:30PM +0000, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 03:55:39PM -0500, Jagannathan Raman wrote:
> > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > 
> > Validate the incoming commands to confirm that they would not cause any
> > errors in the remote process.
> > 
> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > ---
> >  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).
>

Thanks Stefan, will merge that with appropriate patches.
 
> > diff --git a/remote/remote-main.c b/remote/remote-main.c
> > index 20d160e..c4aa3e0 100644
> > --- a/remote/remote-main.c
> > +++ b/remote/remote-main.c
> > @@ -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




^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 50/50] multi-process: add configure and usage information
  2020-02-27 16:58   ` Stefan Hajnoczi
@ 2020-02-28 18:43     ` Elena Ufimtseva
  2020-03-06 16:42       ` Stefan Hajnoczi
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-02-28 18:43 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Thu, Feb 27, 2020 at 04:58:04PM +0000, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 03:55:41PM -0500, Jagannathan Raman wrote:
> > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > 
> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > ---
> >  docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 86 insertions(+)
> >  create mode 100644 docs/qemu-multiprocess.txt
> > 
> > diff --git a/docs/qemu-multiprocess.txt b/docs/qemu-multiprocess.txt
> > new file mode 100644
> > index 0000000..f156177
> > --- /dev/null
> > +++ b/docs/qemu-multiprocess.txt
> > @@ -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
> 
> memory-backend-memfd is more convenient.  It doesn't require a mem-path
> and share=on is the default.
>

Will change this. 
> > +
> > +* 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
> 
> 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?
> 

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?

> > +* 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.
> > +
> > +  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?

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


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess
  2020-02-27 17:11   ` Stefan Hajnoczi
@ 2020-02-28 18:44     ` Elena Ufimtseva
  0 siblings, 0 replies; 117+ messages in thread
From: Elena Ufimtseva @ 2020-02-28 18:44 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Thu, Feb 27, 2020 at 05:11:40PM +0000, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 03:55:40PM -0500, Jagannathan Raman wrote:
> > From: John G Johnson <john.g.johnson@oracle.com>
> > 
> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > ---
> >  docs/devel/index.rst             |    1 +
> >  docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 1103 insertions(+)
> >  create mode 100644 docs/devel/qemu-multiprocess.rst
> > 
> > diff --git a/docs/devel/index.rst b/docs/devel/index.rst
> > index 4dc2ca8..1a95871 100644
> > --- a/docs/devel/index.rst
> > +++ b/docs/devel/index.rst
> > @@ -25,3 +25,4 @@ Contents:
> >     tcg-plugins
> >     bitops
> >     reset
> > +   multi-process
> > diff --git a/docs/devel/qemu-multiprocess.rst b/docs/devel/qemu-multiprocess.rst
> > new file mode 100644
> > index 0000000..477e246
> > --- /dev/null
> > +++ b/docs/devel/qemu-multiprocess.rst
> > @@ -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.
>


Thanks Stefan, will work on this. 
> > +===================
> > +
> > +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/
> 
> > +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/




^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
                   ` (52 preceding siblings ...)
  2020-02-24 22:23 ` no-reply
@ 2020-03-01 11:57 ` Alex Bennée
  2020-03-02 15:28   ` Jag Raman
  53 siblings, 1 reply; 117+ messages in thread
From: Alex Bennée @ 2020-03-01 11:57 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha, pbonzini,
	rth, kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos


Jagannathan Raman <jag.raman@oracle.com> writes:

> 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 <john.g.johnson@oracle.com>
> Jagannathan Raman <jag.raman@oracle.com>
> Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Kanth Ghatraju <kanth.ghatraju@oracle.com>
> Konrad Wilk <konrad.wilk@oracle.com>
>
> 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.

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

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-03-01 11:57 ` Alex Bennée
@ 2020-03-02 15:28   ` Jag Raman
  2020-03-02 16:29     ` Alex Bennée
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-02 15:28 UTC (permalink / raw)
  To: Alex Bennée
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini



On 3/1/2020 6:57 AM, Alex Bennée wrote:
> 
> Jagannathan Raman <jag.raman@oracle.com> writes:
> 
>> 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 <john.g.johnson@oracle.com>
>> Jagannathan Raman <jag.raman@oracle.com>
>> Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Kanth Ghatraju <kanth.ghatraju@oracle.com>
>> Konrad Wilk <konrad.wilk@oracle.com>
>>
>> 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.
> 
> 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/cover.1582576372.git.jag.raman@oracle.com/

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

> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-03-02 15:28   ` Jag Raman
@ 2020-03-02 16:29     ` Alex Bennée
  2020-03-02 16:53       ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Alex Bennée @ 2020-03-02 16:29 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini


Jag Raman <jag.raman@oracle.com> writes:

> On 3/1/2020 6:57 AM, Alex Bennée wrote:
>> Jagannathan Raman <jag.raman@oracle.com> writes:
>> 
>>> 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 <john.g.johnson@oracle.com>
>>> Jagannathan Raman <jag.raman@oracle.com>
>>> Elena Ufimtseva <elena.ufimtseva@oracle.com>
>>> Kanth Ghatraju <kanth.ghatraju@oracle.com>
>>> Konrad Wilk <konrad.wilk@oracle.com>
>>>
>>> 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.
>> 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/cover.1582576372.git.jag.raman@oracle.com/
>
> 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

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.

> pass?
>
> Thank you very much!


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 00/50] Initial support for multi-process qemu
  2020-03-02 16:29     ` Alex Bennée
@ 2020-03-02 16:53       ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-02 16:53 UTC (permalink / raw)
  To: Alex Bennée
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini



On 3/2/2020 11:29 AM, Alex Bennée wrote:
> 
> Jag Raman <jag.raman@oracle.com> writes:
> 
>> On 3/1/2020 6:57 AM, Alex Bennée wrote:
>>> Jagannathan Raman <jag.raman@oracle.com> writes:
>>>
>>>> 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 <john.g.johnson@oracle.com>
>>>> Jagannathan Raman <jag.raman@oracle.com>
>>>> Elena Ufimtseva <elena.ufimtseva@oracle.com>
>>>> Kanth Ghatraju <kanth.ghatraju@oracle.com>
>>>> Konrad Wilk <konrad.wilk@oracle.com>
>>>>
>>>> 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.
>>> 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/cover.1582576372.git.jag.raman@oracle.com/
>>
>> 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
> 
> stsquad is just my user account, hopefully I'm not redundant ;-)

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

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

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

> 
> 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.
> 
>> pass?
>>
>> Thank you very much!
> 
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-02-24 20:55 ` [PATCH v5 14/50] mutli-process: build remote command line args Jagannathan Raman
@ 2020-03-02 17:36   ` Philippe Mathieu-Daudé
  2020-03-02 17:47     ` Daniel P. Berrangé
  2020-03-04 10:09   ` Dr. David Alan Gilbert
  1 sibling, 1 reply; 117+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-03-02 17:36 UTC (permalink / raw)
  To: Jagannathan Raman, qemu-devel, berrange
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, kraxel,
	quintela, mst, armbru, kanth.ghatraju, felipe, thuth, ehabkost,
	konrad.wilk, dgilbert, liran.alon, stefanha, pbonzini, rth,
	kwolf, mreitz, ross.lagerwall, marcandre.lureau, thanos.makatos

typo "multi" in patch subject.

On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>   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(-)
> 
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index 828bbd7..d792e86 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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;

Is there a GLib function to do that?

> +
> +    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);
> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
> index 28b0114..29fa2e9 100644
> --- a/include/hw/proxy/qemu-proxy.h
> +++ b/include/hw/proxy/qemu-proxy.h
> @@ -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;
>   
> 



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-02 17:36   ` Philippe Mathieu-Daudé
@ 2020-03-02 17:47     ` Daniel P. Berrangé
  2020-03-02 22:39       ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Daniel P. Berrangé @ 2020-03-02 17:47 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, Jagannathan Raman, quintela, mst, armbru, kanth.ghatraju,
	felipe, thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	stefanha, pbonzini, rth, kwolf, mreitz, ross.lagerwall,
	marcandre.lureau, thanos.makatos

On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> typo "multi" in patch subject.
> 
> On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > 
> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > ---
> >   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(-)
> > 
> > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > index 828bbd7..d792e86 100644
> > --- a/hw/proxy/qemu-proxy.c
> > +++ b/hw/proxy/qemu-proxy.c
> > @@ -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;
> 
> 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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote
  2020-02-28 16:44   ` Stefan Hajnoczi
@ 2020-03-02 19:28     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-02 19:28 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, pbonzini, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos



On 2/28/2020 11:44 AM, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 03:55:38PM -0500, Jagannathan Raman wrote:
>> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>>
>> 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.

Hi Stefan,

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

Thanks!
--
Jag

> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-02 17:47     ` Daniel P. Berrangé
@ 2020-03-02 22:39       ` Elena Ufimtseva
  2020-03-04 11:00         ` Daniel P. Berrangé
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-02 22:39 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos

On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > typo "multi" in patch subject.
> >
Thank Philippe, will fix.
 
> > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > 
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > ---
> > >   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(-)
> > > 
> > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > index 828bbd7..d792e86 100644
> > > --- a/hw/proxy/qemu-proxy.c
> > > +++ b/hw/proxy/qemu-proxy.c
> > > @@ -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;
> > 
> > Is there a GLib function to do that?
>

Hi Daniel

> g_shell_parse_argv() perhaps
>

Thanks for the suggestion.

>   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
> 
> Regards,
> Daniel
> -- 
> |: 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 :|
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset
  2020-02-24 20:54 ` [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
@ 2020-03-03 19:51   ` Dr. David Alan Gilbert
  2020-03-04 18:24     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-03 19:51 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) 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.
> 
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>

This looks reasonable to me, so :

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

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

> ---
>  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(-)
> 
> diff --git a/exec.c b/exec.c
> index c930040..e524185 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -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);
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 5e59a3d..1b9f489 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -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);
> diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
> index e786266..4f57985 100644
> --- a/include/qemu/mmap-alloc.h
> +++ b/include/qemu/mmap-alloc.h
> @@ -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);
>  
> diff --git a/memory.c b/memory.c
> index aeaa8dc..131bc6c 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -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();
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index 27dcccd..a28f702 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -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) {
> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
> index 5a291cc..bd221dd 100644
> --- a/util/oslib-posix.c
> +++ b/util/oslib-posix.c
> @@ -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;
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints
  2020-02-24 20:54 ` [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints Jagannathan Raman
@ 2020-03-03 19:56   ` Dr. David Alan Gilbert
  2020-03-04 18:42     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-03 19:56 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) 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.
> 
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> ---
>  include/io/mpqemu-link.h |  7 +++++++
>  io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+)
> 
> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> index 2f2dd83..ae04fca 100644
> --- a/include/io/mpqemu-link.h
> +++ b/include/io/mpqemu-link.h
> @@ -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
> diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
> index bac120b..73b7032 100644
> --- a/io/mpqemu-link.c
> +++ b/io/mpqemu-link.c
> @@ -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);
> +
> +    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?

> +    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??

> +    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

> +        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);
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-02-24 20:55 ` [PATCH v5 14/50] mutli-process: build remote command line args Jagannathan Raman
  2020-03-02 17:36   ` Philippe Mathieu-Daudé
@ 2020-03-04 10:09   ` Dr. David Alan Gilbert
  1 sibling, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 10:09 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>  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(-)
> 
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index 828bbd7..d792e86 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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;

...

> +
> +static int make_argv(char *opts_str, char **argv, int argc)
> +{
> +    int max_args = 64;

.....

> +
>  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 / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 12/50] multi-process: remote process initialization
  2020-02-24 20:55 ` [PATCH v5 12/50] multi-process: remote process initialization Jagannathan Raman
@ 2020-03-04 10:29   ` Dr. David Alan Gilbert
  2020-03-04 18:45     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 10:29 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) 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.
> 
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  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(+)
> 
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index ecf30e0..56315cd 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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");

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.

> +        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);
> +

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

>      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;
>  }
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints
  2020-02-24 20:55 ` [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
@ 2020-03-04 10:47   ` Dr. David Alan Gilbert
  2020-03-04 19:05     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 10:47 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) 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.
> 
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> ---
>  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(-)
> 
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index d792e86..b17d9bb 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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,
> +    },
> +};
> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
> index 29fa2e9..44e370e 100644
> --- a/include/hw/proxy/qemu-proxy.h
> +++ b/include/hw/proxy/qemu-proxy.h
> @@ -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 */
> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> index 5a2be48..1a7738e 100644
> --- a/include/io/mpqemu-link.h
> +++ b/include/io/mpqemu-link.h
> @@ -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];
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index 7b4cf2f..acd8daf 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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)
> +{
> +    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));

> +    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

> +    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;
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-02 22:39       ` Elena Ufimtseva
@ 2020-03-04 11:00         ` Daniel P. Berrangé
  2020-03-04 16:25           ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Daniel P. Berrangé @ 2020-03-04 11:00 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos

On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > typo "multi" in patch subject.
> > >
> Thank Philippe, will fix.
>  
> > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > 
> > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > ---
> > > >   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(-)
> > > > 
> > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > index 828bbd7..d792e86 100644
> > > > --- a/hw/proxy/qemu-proxy.c
> > > > +++ b/hw/proxy/qemu-proxy.c
> > > > @@ -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;
> > > 
> > > Is there a GLib function to do that?
> >
> 
> Hi Daniel
> 
> > g_shell_parse_argv() perhaps
> >
> 
> Thanks for the suggestion.
> 
> >   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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 16/50] multi-process: Synchronize remote memory
  2020-02-24 20:55 ` [PATCH v5 16/50] multi-process: Synchronize remote memory Jagannathan Raman
@ 2020-03-04 11:53   ` Dr. David Alan Gilbert
  2020-03-04 19:35     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 11:53 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) 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.
> 
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> ---
>  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
> 
> diff --git a/Makefile.target b/Makefile.target
> index cfd36c1..271d883 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -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/
> diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c
> new file mode 100644
> index 0000000..3edbb19
> --- /dev/null
> +++ b/hw/proxy/memory-sync.c
> @@ -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;
> +}
> +
> +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' ?

> +    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)
> +{
> +    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)

> +    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;
> +    }
> +
> +    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.

> +    if (sync->n_mr_sections) {
> +        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
> +        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
> +        uint64_t prev_size = int128_get64(prev_sec->size);
> +        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
> +        uint64_t prev_host_start =
> +            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
> +            prev_sec->offset_within_region;
> +        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);
> +
> +        if (mrs_gpa <= (prev_gpa_end + 1)) {
> +            if (mrs_gpa < prev_gpa_start) {
> +                assert(0);
> +            }

g_assert(mrs_gpa < prev_gpa_start);


> +            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));
> +            }
> +        }
> +    }
> +
> +    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.

> +}
> +
> +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];
> +        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.

> +        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);
> +}
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index b17d9bb..d3a9d38 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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,
> diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h
> new file mode 100644
> index 0000000..d8329c9
> --- /dev/null
> +++ b/include/hw/proxy/memory-sync.h
> @@ -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
> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
> index 44e370e..c93ffe3 100644
> --- a/include/hw/proxy/qemu-proxy.h
> +++ b/include/hw/proxy/qemu-proxy.h
> @@ -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;
>  
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index acd8daf..9512a3b 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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

In practice this turns out to be hard!

Dave

> +         */
> +        remote_sysmem_reconfig(msg, &err);
> +        if (err) {
> +            goto finalize_loop;
> +        }
> +        break;
>      default:
>          error_setg(&err, "Unknown command");
>          goto finalize_loop;
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-02-24 20:55 ` [PATCH v5 40/50] multi-process/mig: build migration module in the remote process Jagannathan Raman
@ 2020-03-04 15:58   ` Dr. David Alan Gilbert
  2020-03-04 19:45     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 15:58 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> Add Makefile support to enable migration in remote process
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  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(-)
> 
> diff --git a/Makefile.objs b/Makefile.objs
> index 4b5db09..65009da 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -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
> diff --git a/Makefile.target b/Makefile.target
> index 4ead5c3..4012ae5 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -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 :=
> diff --git a/migration/Makefile.objs b/migration/Makefile.objs
> index e7cdc76..21f9d8d 100644
> --- a/migration/Makefile.objs
> +++ b/migration/Makefile.objs
> @@ -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

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

> diff --git a/net/Makefile.objs b/net/Makefile.objs
> index c5d076d..a8ad986 100644
> --- a/net/Makefile.objs
> +++ b/net/Makefile.objs
> @@ -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
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 4a4f52c..42d5682 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -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;
> diff --git a/stubs/migration.c b/stubs/migration.c
> index 28ccf80..dbd12db 100644
> --- a/stubs/migration.c
> +++ b/stubs/migration.c
> @@ -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);
> +}
> diff --git a/stubs/net-stub.c b/stubs/net-stub.c
> index 962827e..ddfd1e4 100644
> --- a/stubs/net-stub.c
> +++ b/stubs/net-stub.c
> @@ -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);
> +}
> diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
> index 3eeedd9..824eac1 100644
> --- a/stubs/qapi-misc.c
> +++ b/stubs/qapi-misc.c
> @@ -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,
> diff --git a/stubs/replay.c b/stubs/replay.c
> index 9b53c0c..6fc7850 100644
> --- a/stubs/replay.c
> +++ b/stubs/replay.c
> @@ -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;
> +}
> diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
> index 606f078..5f308c1 100644
> --- a/stubs/vl-stub.c
> +++ b/stubs/vl-stub.c
> @@ -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);
> +}
> diff --git a/vl-parse.c b/vl-parse.c
> index 1f6a3f0..423f4a0 100644
> --- a/vl-parse.c
> +++ b/vl-parse.c
> @@ -27,6 +27,9 @@
>  
>  #include "vl.h"
>  
> +int only_migratable; /* turn it off unless user states otherwise */
> +bool enable_mlock;
> +
>  /***********************************************************/
>  /* QEMU Block devices */
>  
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-04 11:00         ` Daniel P. Berrangé
@ 2020-03-04 16:25           ` Elena Ufimtseva
  2020-03-04 16:33             ` Daniel P. Berrangé
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-04 16:25 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos

On Wed, Mar 04, 2020 at 11:00:32AM +0000, Daniel P. Berrangé wrote:
> On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> > On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > > typo "multi" in patch subject.
> > > >
> > Thank Philippe, will fix.
> >  
> > > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > 
> > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > ---
> > > > >   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(-)
> > > > > 
> > > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > > index 828bbd7..d792e86 100644
> > > > > --- a/hw/proxy/qemu-proxy.c
> > > > > +++ b/hw/proxy/qemu-proxy.c
> > > > > @@ -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;
> > > > 
> > > > Is there a GLib function to do that?
> > >
> > 
> > Hi Daniel
> > 
> > > g_shell_parse_argv() perhaps
> > >
> > 
> > Thanks for the suggestion.
> > 
> > >   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.
>
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


> 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
> -- 
> |: 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 :|
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-04 16:25           ` Elena Ufimtseva
@ 2020-03-04 16:33             ` Daniel P. Berrangé
  2020-03-04 22:37               ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Daniel P. Berrangé @ 2020-03-04 16:33 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Wed, Mar 04, 2020 at 08:25:34AM -0800, Elena Ufimtseva wrote:
> On Wed, Mar 04, 2020 at 11:00:32AM +0000, Daniel P. Berrangé wrote:
> > On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> > > On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > > > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > > > typo "multi" in patch subject.
> > > > >
> > > Thank Philippe, will fix.
> > >  
> > > > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > 
> > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > ---
> > > > > >   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(-)
> > > > > > 
> > > > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > > > index 828bbd7..d792e86 100644
> > > > > > --- a/hw/proxy/qemu-proxy.c
> > > > > > +++ b/hw/proxy/qemu-proxy.c
> > > > > > @@ -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;
> > > > > 
> > > > > Is there a GLib function to do that?
> > > >
> > > 
> > > Hi Daniel
> > > 
> > > > g_shell_parse_argv() perhaps
> > > >
> > > 
> > > Thanks for the suggestion.
> > > 
> > > >   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.
> >
> 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.

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.

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

Regards,
Daniel
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset
  2020-03-03 19:51   ` Dr. David Alan Gilbert
@ 2020-03-04 18:24     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-04 18:24 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, pbonzini, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos



On 3/3/2020 2:51 PM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) 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.
>>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> This looks reasonable to me, so :
> 
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 
> 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

> 
> Dave
> 
>> ---
>>   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(-)
>>
>> diff --git a/exec.c b/exec.c
>> index c930040..e524185 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -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);
>> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
>> index 5e59a3d..1b9f489 100644
>> --- a/include/exec/ram_addr.h
>> +++ b/include/exec/ram_addr.h
>> @@ -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);
>> diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
>> index e786266..4f57985 100644
>> --- a/include/qemu/mmap-alloc.h
>> +++ b/include/qemu/mmap-alloc.h
>> @@ -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);
>>   
>> diff --git a/memory.c b/memory.c
>> index aeaa8dc..131bc6c 100644
>> --- a/memory.c
>> +++ b/memory.c
>> @@ -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();
>> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
>> index 27dcccd..a28f702 100644
>> --- a/util/mmap-alloc.c
>> +++ b/util/mmap-alloc.c
>> @@ -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) {
>> diff --git a/util/oslib-posix.c b/util/oslib-posix.c
>> index 5a291cc..bd221dd 100644
>> --- a/util/oslib-posix.c
>> +++ b/util/oslib-posix.c
>> @@ -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;
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints
  2020-03-03 19:56   ` Dr. David Alan Gilbert
@ 2020-03-04 18:42     ` Jag Raman
  2020-03-04 19:46       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-04 18:42 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/3/2020 2:56 PM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) 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.
>>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> ---
>>   include/io/mpqemu-link.h |  7 +++++++
>>   io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
>>   2 files changed, 48 insertions(+)
>>
>> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
>> index 2f2dd83..ae04fca 100644
>> --- a/include/io/mpqemu-link.h
>> +++ b/include/io/mpqemu-link.h
>> @@ -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
>> diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
>> index bac120b..73b7032 100644
>> --- a/io/mpqemu-link.c
>> +++ b/io/mpqemu-link.c
>> @@ -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);
>> +
>> +    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.

> 
>> +    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??

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

> 
>> +    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
> 
>> +        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);
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 12/50] multi-process: remote process initialization
  2020-03-04 10:29   ` Dr. David Alan Gilbert
@ 2020-03-04 18:45     ` Jag Raman
  2020-03-04 19:00       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-04 18:45 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/4/2020 5:29 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) 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.
>>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> ---
>>   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(+)
>>
>> diff --git a/remote/remote-main.c b/remote/remote-main.c
>> index ecf30e0..56315cd 100644
>> --- a/remote/remote-main.c
>> +++ b/remote/remote-main.c
>> @@ -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");
> 
> 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

> 
>> +        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);
>> +
> 
> 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
> 
>>       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;
>>   }
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 12/50] multi-process: remote process initialization
  2020-03-04 18:45     ` Jag Raman
@ 2020-03-04 19:00       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 19:00 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/4/2020 5:29 AM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) 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.
> > > 
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > ---
> > >   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(+)
> > > 
> > > diff --git a/remote/remote-main.c b/remote/remote-main.c
> > > index ecf30e0..56315cd 100644
> > > --- a/remote/remote-main.c
> > > +++ b/remote/remote-main.c
> > > @@ -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");
> > 
> > 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.

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

> Thank you!
> --
> Jag
> 
> > 
> > > +        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);
> > > +
> > 
> > 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
> > 
> > >       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;
> > >   }
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints
  2020-03-04 10:47   ` Dr. David Alan Gilbert
@ 2020-03-04 19:05     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-04 19:05 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/4/2020 5:47 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) 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.
>>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> ---
>>   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(-)
>>
>> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
>> index d792e86..b17d9bb 100644
>> --- a/hw/proxy/qemu-proxy.c
>> +++ b/hw/proxy/qemu-proxy.c
>> @@ -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,
>> +    },
>> +};
>> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
>> index 29fa2e9..44e370e 100644
>> --- a/include/hw/proxy/qemu-proxy.h
>> +++ b/include/hw/proxy/qemu-proxy.h
>> @@ -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 */
>> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
>> index 5a2be48..1a7738e 100644
>> --- a/include/io/mpqemu-link.h
>> +++ b/include/io/mpqemu-link.h
>> @@ -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];
>> diff --git a/remote/remote-main.c b/remote/remote-main.c
>> index 7b4cf2f..acd8daf 100644
>> --- a/remote/remote-main.c
>> +++ b/remote/remote-main.c
>> @@ -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)
>> +{
>> +    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));

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

> 
>> +    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

> 
> Dave
> 
>> +    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;
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 16/50] multi-process: Synchronize remote memory
  2020-03-04 11:53   ` Dr. David Alan Gilbert
@ 2020-03-04 19:35     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-04 19:35 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/4/2020 6:53 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) 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.
>>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> ---
>>   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
>>
>> diff --git a/Makefile.target b/Makefile.target
>> index cfd36c1..271d883 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -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/
>> diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c
>> new file mode 100644
>> index 0000000..3edbb19
>> --- /dev/null
>> +++ b/hw/proxy/memory-sync.c
>> @@ -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;
>> +}
>> +
>> +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.

> 
>> +    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)
>> +{
>> +    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)

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

> 
>> +    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;
>> +    }
>> +
>> +    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.

> 
>> +    if (sync->n_mr_sections) {
>> +        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
>> +        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
>> +        uint64_t prev_size = int128_get64(prev_sec->size);
>> +        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
>> +        uint64_t prev_host_start =
>> +            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
>> +            prev_sec->offset_within_region;
>> +        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);
>> +
>> +        if (mrs_gpa <= (prev_gpa_end + 1)) {
>> +            if (mrs_gpa < prev_gpa_start) {
>> +                assert(0);
>> +            }
> 
> g_assert(mrs_gpa < prev_gpa_start);

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

> 
> 
>> +            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));
>> +            }
>> +        }
>> +    }
>> +
>> +    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.

Thank you, we'll add the tracing.

> 
>> +}
>> +
>> +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];
>> +        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

> 
>> +        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);
>> +}
>> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
>> index b17d9bb..d3a9d38 100644
>> --- a/hw/proxy/qemu-proxy.c
>> +++ b/hw/proxy/qemu-proxy.c
>> @@ -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,
>> diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h
>> new file mode 100644
>> index 0000000..d8329c9
>> --- /dev/null
>> +++ b/include/hw/proxy/memory-sync.h
>> @@ -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
>> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
>> index 44e370e..c93ffe3 100644
>> --- a/include/hw/proxy/qemu-proxy.h
>> +++ b/include/hw/proxy/qemu-proxy.h
>> @@ -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;
>>   
>> diff --git a/remote/remote-main.c b/remote/remote-main.c
>> index acd8daf..9512a3b 100644
>> --- a/remote/remote-main.c
>> +++ b/remote/remote-main.c
>> @@ -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
> 
> In practice this turns out to be hard!
> 
> Dave
> 
>> +         */
>> +        remote_sysmem_reconfig(msg, &err);
>> +        if (err) {
>> +            goto finalize_loop;
>> +        }
>> +        break;
>>       default:
>>           error_setg(&err, "Unknown command");
>>           goto finalize_loop;
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-04 15:58   ` Dr. David Alan Gilbert
@ 2020-03-04 19:45     ` Jag Raman
  2020-03-04 19:52       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-04 19:45 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>> Add Makefile support to enable migration in remote process
>>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> ---
>>   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(-)
>>
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 4b5db09..65009da 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -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
>> diff --git a/Makefile.target b/Makefile.target
>> index 4ead5c3..4012ae5 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -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 :=
>> diff --git a/migration/Makefile.objs b/migration/Makefile.objs
>> index e7cdc76..21f9d8d 100644
>> --- a/migration/Makefile.objs
>> +++ b/migration/Makefile.objs
>> @@ -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
> 
> 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

> 
> Dave
> 
>> diff --git a/net/Makefile.objs b/net/Makefile.objs
>> index c5d076d..a8ad986 100644
>> --- a/net/Makefile.objs
>> +++ b/net/Makefile.objs
>> @@ -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
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index 4a4f52c..42d5682 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -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;
>> diff --git a/stubs/migration.c b/stubs/migration.c
>> index 28ccf80..dbd12db 100644
>> --- a/stubs/migration.c
>> +++ b/stubs/migration.c
>> @@ -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);
>> +}
>> diff --git a/stubs/net-stub.c b/stubs/net-stub.c
>> index 962827e..ddfd1e4 100644
>> --- a/stubs/net-stub.c
>> +++ b/stubs/net-stub.c
>> @@ -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);
>> +}
>> diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
>> index 3eeedd9..824eac1 100644
>> --- a/stubs/qapi-misc.c
>> +++ b/stubs/qapi-misc.c
>> @@ -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,
>> diff --git a/stubs/replay.c b/stubs/replay.c
>> index 9b53c0c..6fc7850 100644
>> --- a/stubs/replay.c
>> +++ b/stubs/replay.c
>> @@ -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;
>> +}
>> diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
>> index 606f078..5f308c1 100644
>> --- a/stubs/vl-stub.c
>> +++ b/stubs/vl-stub.c
>> @@ -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);
>> +}
>> diff --git a/vl-parse.c b/vl-parse.c
>> index 1f6a3f0..423f4a0 100644
>> --- a/vl-parse.c
>> +++ b/vl-parse.c
>> @@ -27,6 +27,9 @@
>>   
>>   #include "vl.h"
>>   
>> +int only_migratable; /* turn it off unless user states otherwise */
>> +bool enable_mlock;
>> +
>>   /***********************************************************/
>>   /* QEMU Block devices */
>>   
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints
  2020-03-04 18:42     ` Jag Raman
@ 2020-03-04 19:46       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 19:46 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/3/2020 2:56 PM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) 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.
> > > 
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > ---
> > >   include/io/mpqemu-link.h |  7 +++++++
> > >   io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
> > >   2 files changed, 48 insertions(+)
> > > 
> > > diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> > > index 2f2dd83..ae04fca 100644
> > > --- a/include/io/mpqemu-link.h
> > > +++ b/include/io/mpqemu-link.h
> > > @@ -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
> > > diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c
> > > index bac120b..73b7032 100644
> > > --- a/io/mpqemu-link.c
> > > +++ b/io/mpqemu-link.c
> > > @@ -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);
> > > +
> > > +    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.
> 
> > 
> > > +    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??
> 
> 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.

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

Dave

> --
> Jag
> 
> > 
> > > +    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
> > 
> > > +        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);
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-04 19:45     ` Jag Raman
@ 2020-03-04 19:52       ` Dr. David Alan Gilbert
  2020-03-04 20:23         ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-04 19:52 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > Add Makefile support to enable migration in remote process
> > > 
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > ---
> > >   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(-)
> > > 
> > > diff --git a/Makefile.objs b/Makefile.objs
> > > index 4b5db09..65009da 100644
> > > --- a/Makefile.objs
> > > +++ b/Makefile.objs
> > > @@ -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
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 4ead5c3..4012ae5 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -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 :=
> > > diff --git a/migration/Makefile.objs b/migration/Makefile.objs
> > > index e7cdc76..21f9d8d 100644
> > > --- a/migration/Makefile.objs
> > > +++ b/migration/Makefile.objs
> > > @@ -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
> > 
> > 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.

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

> Thank you!
> --
> Jag
> 
> > 
> > Dave
> > 
> > > diff --git a/net/Makefile.objs b/net/Makefile.objs
> > > index c5d076d..a8ad986 100644
> > > --- a/net/Makefile.objs
> > > +++ b/net/Makefile.objs
> > > @@ -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
> > > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > > index 4a4f52c..42d5682 100644
> > > --- a/softmmu/vl.c
> > > +++ b/softmmu/vl.c
> > > @@ -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;
> > > diff --git a/stubs/migration.c b/stubs/migration.c
> > > index 28ccf80..dbd12db 100644
> > > --- a/stubs/migration.c
> > > +++ b/stubs/migration.c
> > > @@ -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);
> > > +}
> > > diff --git a/stubs/net-stub.c b/stubs/net-stub.c
> > > index 962827e..ddfd1e4 100644
> > > --- a/stubs/net-stub.c
> > > +++ b/stubs/net-stub.c
> > > @@ -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);
> > > +}
> > > diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
> > > index 3eeedd9..824eac1 100644
> > > --- a/stubs/qapi-misc.c
> > > +++ b/stubs/qapi-misc.c
> > > @@ -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,
> > > diff --git a/stubs/replay.c b/stubs/replay.c
> > > index 9b53c0c..6fc7850 100644
> > > --- a/stubs/replay.c
> > > +++ b/stubs/replay.c
> > > @@ -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;
> > > +}
> > > diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
> > > index 606f078..5f308c1 100644
> > > --- a/stubs/vl-stub.c
> > > +++ b/stubs/vl-stub.c
> > > @@ -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);
> > > +}
> > > diff --git a/vl-parse.c b/vl-parse.c
> > > index 1f6a3f0..423f4a0 100644
> > > --- a/vl-parse.c
> > > +++ b/vl-parse.c
> > > @@ -27,6 +27,9 @@
> > >   #include "vl.h"
> > > +int only_migratable; /* turn it off unless user states otherwise */
> > > +bool enable_mlock;
> > > +
> > >   /***********************************************************/
> > >   /* QEMU Block devices */
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-04 19:52       ` Dr. David Alan Gilbert
@ 2020-03-04 20:23         ` Jag Raman
  2020-03-05 10:10           ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-04 20:23 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/4/2020 2:52 PM, Dr. David Alan Gilbert wrote:
> * Jag Raman (jag.raman@oracle.com) wrote:
>>
>>
>> On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
>>> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>>>> Add Makefile support to enable migration in remote process
>>>>
>>>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>>>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>>>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>>>> ---
>>>>    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(-)
>>>>
>>>> diff --git a/Makefile.objs b/Makefile.objs
>>>> index 4b5db09..65009da 100644
>>>> --- a/Makefile.objs
>>>> +++ b/Makefile.objs
>>>> @@ -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
>>>> diff --git a/Makefile.target b/Makefile.target
>>>> index 4ead5c3..4012ae5 100644
>>>> --- a/Makefile.target
>>>> +++ b/Makefile.target
>>>> @@ -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 :=
>>>> diff --git a/migration/Makefile.objs b/migration/Makefile.objs
>>>> index e7cdc76..21f9d8d 100644
>>>> --- a/migration/Makefile.objs
>>>> +++ b/migration/Makefile.objs
>>>> @@ -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
>>>
>>> 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.
> 
> 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

> 
> Dave
> 
>> Thank you!
>> --
>> Jag
>>
>>>
>>> Dave
>>>
>>>> diff --git a/net/Makefile.objs b/net/Makefile.objs
>>>> index c5d076d..a8ad986 100644
>>>> --- a/net/Makefile.objs
>>>> +++ b/net/Makefile.objs
>>>> @@ -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
>>>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>>>> index 4a4f52c..42d5682 100644
>>>> --- a/softmmu/vl.c
>>>> +++ b/softmmu/vl.c
>>>> @@ -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;
>>>> diff --git a/stubs/migration.c b/stubs/migration.c
>>>> index 28ccf80..dbd12db 100644
>>>> --- a/stubs/migration.c
>>>> +++ b/stubs/migration.c
>>>> @@ -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);
>>>> +}
>>>> diff --git a/stubs/net-stub.c b/stubs/net-stub.c
>>>> index 962827e..ddfd1e4 100644
>>>> --- a/stubs/net-stub.c
>>>> +++ b/stubs/net-stub.c
>>>> @@ -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);
>>>> +}
>>>> diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
>>>> index 3eeedd9..824eac1 100644
>>>> --- a/stubs/qapi-misc.c
>>>> +++ b/stubs/qapi-misc.c
>>>> @@ -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,
>>>> diff --git a/stubs/replay.c b/stubs/replay.c
>>>> index 9b53c0c..6fc7850 100644
>>>> --- a/stubs/replay.c
>>>> +++ b/stubs/replay.c
>>>> @@ -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;
>>>> +}
>>>> diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
>>>> index 606f078..5f308c1 100644
>>>> --- a/stubs/vl-stub.c
>>>> +++ b/stubs/vl-stub.c
>>>> @@ -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);
>>>> +}
>>>> diff --git a/vl-parse.c b/vl-parse.c
>>>> index 1f6a3f0..423f4a0 100644
>>>> --- a/vl-parse.c
>>>> +++ b/vl-parse.c
>>>> @@ -27,6 +27,9 @@
>>>>    #include "vl.h"
>>>> +int only_migratable; /* turn it off unless user states otherwise */
>>>> +bool enable_mlock;
>>>> +
>>>>    /***********************************************************/
>>>>    /* QEMU Block devices */
>>>> -- 
>>>> 1.8.3.1
>>>>
>>> --
>>> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
>>>
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-04 16:33             ` Daniel P. Berrangé
@ 2020-03-04 22:37               ` Elena Ufimtseva
  2020-03-05  8:21                 ` Daniel P. Berrangé
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-04 22:37 UTC (permalink / raw)
  To: Daniel P. Berrangé, stefanha
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Wed, Mar 04, 2020 at 04:33:57PM +0000, Daniel P. Berrangé wrote:
> On Wed, Mar 04, 2020 at 08:25:34AM -0800, Elena Ufimtseva wrote:
> > On Wed, Mar 04, 2020 at 11:00:32AM +0000, Daniel P. Berrangé wrote:
> > > On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> > > > On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > > > > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > > > > typo "multi" in patch subject.
> > > > > >
> > > > Thank Philippe, will fix.
> > > >  
> > > > > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > 
> > > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > > ---
> > > > > > >   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(-)
> > > > > > > 
> > > > > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > > > > index 828bbd7..d792e86 100644
> > > > > > > --- a/hw/proxy/qemu-proxy.c
> > > > > > > +++ b/hw/proxy/qemu-proxy.c
> > > > > > > @@ -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;
> > > > > > 
> > > > > > Is there a GLib function to do that?
> > > > >
> > > > 
> > > > Hi Daniel
> > > > 
> > > > > g_shell_parse_argv() perhaps
> > > > >
> > > > 
> > > > Thanks for the suggestion.
> > > > 
> > > > >   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.
> > >
> > 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.
> 
> 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.

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, 
> 
> > Few things we discussed internally is to have the remote drive
> > command line options passed over by messages or using QMP.
> 
> Regards,
> Daniel
> -- 
> |: 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 :|
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-04 22:37               ` Elena Ufimtseva
@ 2020-03-05  8:21                 ` Daniel P. Berrangé
  2020-03-06 16:25                   ` Stefan Hajnoczi
  0 siblings, 1 reply; 117+ messages in thread
From: Daniel P. Berrangé @ 2020-03-05  8:21 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, stefanha,
	pbonzini, rth, kwolf, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos

On Wed, Mar 04, 2020 at 02:37:43PM -0800, Elena Ufimtseva wrote:
> On Wed, Mar 04, 2020 at 04:33:57PM +0000, Daniel P. Berrangé wrote:
> > On Wed, Mar 04, 2020 at 08:25:34AM -0800, Elena Ufimtseva wrote:
> > > On Wed, Mar 04, 2020 at 11:00:32AM +0000, Daniel P. Berrangé wrote:
> > > > On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> > > > > On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > > > > > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > > > > > typo "multi" in patch subject.
> > > > > > >
> > > > > Thank Philippe, will fix.
> > > > >  
> > > > > > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > > > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > > 
> > > > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > > > ---
> > > > > > > >   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(-)
> > > > > > > > 
> > > > > > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > > > > > index 828bbd7..d792e86 100644
> > > > > > > > --- a/hw/proxy/qemu-proxy.c
> > > > > > > > +++ b/hw/proxy/qemu-proxy.c
> > > > > > > > @@ -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;
> > > > > > > 
> > > > > > > Is there a GLib function to do that?
> > > > > >
> > > > > 
> > > > > Hi Daniel
> > > > > 
> > > > > > g_shell_parse_argv() perhaps
> > > > > >
> > > > > 
> > > > > Thanks for the suggestion.
> > > > > 
> > > > > >   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.
> > > >
> > > 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.
> > 
> > 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.
> 
> 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?

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
-- 
|: 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 :|



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-04 20:23         ` Jag Raman
@ 2020-03-05 10:10           ` Dr. David Alan Gilbert
  2020-03-05 17:07             ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 10:10 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/4/2020 2:52 PM, Dr. David Alan Gilbert wrote:
> > * Jag Raman (jag.raman@oracle.com) wrote:
> > > 
> > > 
> > > On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
> > > > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > > > Add Makefile support to enable migration in remote process
> > > > > 
> > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > ---
> > > > >    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(-)
> > > > > 
> > > > > diff --git a/Makefile.objs b/Makefile.objs
> > > > > index 4b5db09..65009da 100644
> > > > > --- a/Makefile.objs
> > > > > +++ b/Makefile.objs
> > > > > @@ -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
> > > > > diff --git a/Makefile.target b/Makefile.target
> > > > > index 4ead5c3..4012ae5 100644
> > > > > --- a/Makefile.target
> > > > > +++ b/Makefile.target
> > > > > @@ -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 :=
> > > > > diff --git a/migration/Makefile.objs b/migration/Makefile.objs
> > > > > index e7cdc76..21f9d8d 100644
> > > > > --- a/migration/Makefile.objs
> > > > > +++ b/migration/Makefile.objs
> > > > > @@ -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
> > > > 
> > > > 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.
> > 
> > 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...

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

> Thank you!
> --
> Jag
> 
> > 
> > Dave
> > 
> > > Thank you!
> > > --
> > > Jag
> > > 
> > > > 
> > > > Dave
> > > > 
> > > > > diff --git a/net/Makefile.objs b/net/Makefile.objs
> > > > > index c5d076d..a8ad986 100644
> > > > > --- a/net/Makefile.objs
> > > > > +++ b/net/Makefile.objs
> > > > > @@ -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
> > > > > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > > > > index 4a4f52c..42d5682 100644
> > > > > --- a/softmmu/vl.c
> > > > > +++ b/softmmu/vl.c
> > > > > @@ -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;
> > > > > diff --git a/stubs/migration.c b/stubs/migration.c
> > > > > index 28ccf80..dbd12db 100644
> > > > > --- a/stubs/migration.c
> > > > > +++ b/stubs/migration.c
> > > > > @@ -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);
> > > > > +}
> > > > > diff --git a/stubs/net-stub.c b/stubs/net-stub.c
> > > > > index 962827e..ddfd1e4 100644
> > > > > --- a/stubs/net-stub.c
> > > > > +++ b/stubs/net-stub.c
> > > > > @@ -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);
> > > > > +}
> > > > > diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
> > > > > index 3eeedd9..824eac1 100644
> > > > > --- a/stubs/qapi-misc.c
> > > > > +++ b/stubs/qapi-misc.c
> > > > > @@ -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,
> > > > > diff --git a/stubs/replay.c b/stubs/replay.c
> > > > > index 9b53c0c..6fc7850 100644
> > > > > --- a/stubs/replay.c
> > > > > +++ b/stubs/replay.c
> > > > > @@ -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;
> > > > > +}
> > > > > diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
> > > > > index 606f078..5f308c1 100644
> > > > > --- a/stubs/vl-stub.c
> > > > > +++ b/stubs/vl-stub.c
> > > > > @@ -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);
> > > > > +}
> > > > > diff --git a/vl-parse.c b/vl-parse.c
> > > > > index 1f6a3f0..423f4a0 100644
> > > > > --- a/vl-parse.c
> > > > > +++ b/vl-parse.c
> > > > > @@ -27,6 +27,9 @@
> > > > >    #include "vl.h"
> > > > > +int only_migratable; /* turn it off unless user states otherwise */
> > > > > +bool enable_mlock;
> > > > > +
> > > > >    /***********************************************************/
> > > > >    /* QEMU Block devices */
> > > > > -- 
> > > > > 1.8.3.1
> > > > > 
> > > > --
> > > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > > > 
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target
  2020-02-24 20:55 ` [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target Jagannathan Raman
@ 2020-03-05 10:39   ` Dr. David Alan Gilbert
  2020-03-05 15:38     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 10:39 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> Add "targets" field to HMP command definition to select the targets
> which would be supported by each command
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  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
> 
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 257ee7d..631cc76 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -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",

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?

>          .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",
>      },
>  
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index dc23185..ecc6169 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -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",
>      },
> diff --git a/scripts/hxtool b/scripts/hxtool
> old mode 100644
> new mode 100755
> index 0003e7b..802cbd4
> --- a/scripts/hxtool
> +++ b/scripts/hxtool
> @@ -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
> @@ -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' ?

> +            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
>  
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process
  2020-02-24 20:55 ` [PATCH v5 36/50] multi-process/mon: enable QMP module support in the " Jagannathan Raman
@ 2020-03-05 10:43   ` Dr. David Alan Gilbert
  2020-03-05 15:40     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 10:43 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> Build system changes to enable QMP module in the remote process
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>

It's odd that this is labelled as QMP changes yet a lot of the code is
actually HMP de-staticing.

Dave

> ---
>  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(-)
> 
> diff --git a/Makefile.objs b/Makefile.objs
> index 689a722..4b5db09 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -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
> diff --git a/Makefile.target b/Makefile.target
> index 035c23b..4ead5c3 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -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
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index ecc6169..a1932c4 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -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
> diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> index e3e8084..251b77b 100644
> --- a/hw/core/Makefile.objs
> +++ b/hw/core/Makefile.objs
> @@ -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
> diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs
> index 9244d90..48d8017 100644
> --- a/monitor/Makefile.objs
> +++ b/monitor/Makefile.objs
> @@ -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
> diff --git a/monitor/misc.c b/monitor/misc.c
> index 6c41293..f1f09bf 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
>      return 0;
>  }
>  
> -static void do_help_cmd(Monitor *mon, const QDict *qdict)
> +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
>  {
>      help_cmd(mon, qdict_get_try_str(qdict, "name"));
>  }
>  
> -static void hmp_trace_event(Monitor *mon, const QDict *qdict)
> +void hmp_trace_event(Monitor *mon, const QDict *qdict)
>  {
>      const char *tp_name = qdict_get_str(qdict, "name");
>      bool new_state = qdict_get_bool(qdict, "option");
> @@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
>  }
>  #endif
>  
> -static void hmp_info_help(Monitor *mon, const QDict *qdict)
> +void hmp_info_help(Monitor *mon, const QDict *qdict)
>  {
>      help_cmd(mon, "info");
>  }
> @@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
>      return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
>  }
>  
> -static void hmp_info_registers(Monitor *mon, const QDict *qdict)
> +void hmp_info_registers(Monitor *mon, const QDict *qdict)
>  {
>      bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
>      CPUState *cs;
> @@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
>  }
>  
>  #ifdef CONFIG_TCG
> -static void hmp_info_jit(Monitor *mon, const QDict *qdict)
> +void hmp_info_jit(Monitor *mon, const QDict *qdict)
>  {
>      if (!tcg_enabled()) {
>          error_report("JIT information is only available with accel=tcg");
> @@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
>      dump_drift_info();
>  }
>  
> -static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
> +void hmp_info_opcount(Monitor *mon, const QDict *qdict)
>  {
>      dump_opcount_info();
>  }
>  #endif
>  
> -static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
> +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
>  {
>      int64_t max = qdict_get_try_int(qdict, "max", 10);
>      bool mean = qdict_get_try_bool(qdict, "mean", false);
> @@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
>      qsp_report(max, sort_by, coalesce);
>  }
>  
> -static void hmp_info_history(Monitor *mon, const QDict *qdict)
> +void hmp_info_history(Monitor *mon, const QDict *qdict)
>  {
>      MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
>      int i;
> @@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
> +void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
>  {
>      CPUState *cs = mon_get_cpu();
>  
> @@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
>      cpu_dump_statistics(cs, 0);
>  }
>  
> -static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
> +void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>  {
>      const char *name = qdict_get_try_str(qdict, "name");
>      bool has_vcpu = qdict_haskey(qdict, "vcpu");
> @@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
>      error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
>  }
>  
> -static void hmp_logfile(Monitor *mon, const QDict *qdict)
> +void hmp_logfile(Monitor *mon, const QDict *qdict)
>  {
>      Error *err = NULL;
>  
> @@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_log(Monitor *mon, const QDict *qdict)
> +void hmp_log(Monitor *mon, const QDict *qdict)
>  {
>      int mask;
>      const char *items = qdict_get_str(qdict, "items");
> @@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
>      qemu_set_log(mask);
>  }
>  
> -static void hmp_singlestep(Monitor *mon, const QDict *qdict)
> +void hmp_singlestep(Monitor *mon, const QDict *qdict)
>  {
>      const char *option = qdict_get_try_str(qdict, "option");
>      if (!option || !strcmp(option, "on")) {
> @@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
> +void hmp_gdbserver(Monitor *mon, const QDict *qdict)
>  {
>      const char *device = qdict_get_try_str(qdict, "device");
>      if (!device)
> @@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
> +void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
>  {
>      const char *action = qdict_get_str(qdict, "action");
>      if (select_watchdog_action(action) == -1) {
> @@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
>      }
>  }
>  
> -static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
> +void hmp_memory_dump(Monitor *mon, const QDict *qdict)
>  {
>      int count = qdict_get_int(qdict, "count");
>      int format = qdict_get_int(qdict, "format");
> @@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
>      memory_dump(mon, count, format, size, addr, 0);
>  }
>  
> -static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
> +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
>  {
>      int count = qdict_get_int(qdict, "count");
>      int format = qdict_get_int(qdict, "format");
> @@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
>      return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
>  }
>  
> -static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
> +void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
>  {
>      hwaddr addr = qdict_get_int(qdict, "addr");
>      Error *local_err = NULL;
> @@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
>      memory_region_unref(mr);
>  }
>  
> -static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
> +void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
>  {
>      target_ulong addr = qdict_get_int(qdict, "addr");
>      MemTxAttrs attrs;
> @@ -768,7 +768,7 @@ out:
>      return ret;
>  }
>  
> -static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
> +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
>  {
>      hwaddr addr = qdict_get_int(qdict, "addr");
>      Error *local_err = NULL;
> @@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
>  }
>  #endif
>  
> -static void do_print(Monitor *mon, const QDict *qdict)
> +void hmp_do_print(Monitor *mon, const QDict *qdict)
>  {
>      int format = qdict_get_int(qdict, "format");
>      hwaddr val = qdict_get_int(qdict, "val");
> @@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
>      monitor_printf(mon, "\n");
>  }
>  
> -static void hmp_sum(Monitor *mon, const QDict *qdict)
> +void hmp_sum(Monitor *mon, const QDict *qdict)
>  {
>      uint32_t addr;
>      uint16_t sum;
> @@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
>  
>  static int mouse_button_state;
>  
> -static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
> +void hmp_mouse_move(Monitor *mon, const QDict *qdict)
>  {
>      int dx, dy, dz, button;
>      const char *dx_str = qdict_get_str(qdict, "dx_str");
> @@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
>      qemu_input_event_sync();
>  }
>  
> -static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
> +void hmp_mouse_button(Monitor *mon, const QDict *qdict)
>  {
>      static uint32_t bmap[INPUT_BUTTON__MAX] = {
>          [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
> @@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
>      mouse_button_state = button_state;
>  }
>  
> -static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
> +void hmp_ioport_read(Monitor *mon, const QDict *qdict)
>  {
>      int size = qdict_get_int(qdict, "size");
>      int addr = qdict_get_int(qdict, "addr");
> @@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
>                     suffix, addr, size * 2, val);
>  }
>  
> -static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
> +void hmp_ioport_write(Monitor *mon, const QDict *qdict)
>  {
>      int size = qdict_get_int(qdict, "size");
>      int addr = qdict_get_int(qdict, "addr");
> @@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_boot_set(Monitor *mon, const QDict *qdict)
> +void hmp_boot_set(Monitor *mon, const QDict *qdict)
>  {
>      Error *local_err = NULL;
>      const char *bootdevice = qdict_get_str(qdict, "bootdevice");
> @@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
> +void hmp_info_mtree(Monitor *mon, const QDict *qdict)
>  {
>      bool flatview = qdict_get_try_bool(qdict, "flatview", false);
>      bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
> @@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
>  
>  int64_t dev_time;
>  
> -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> +void hmp_info_profile(Monitor *mon, const QDict *qdict)
>  {
>      static int64_t last_cpu_exec_time;
>      int64_t cpu_exec_time;
> @@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>      dev_time = 0;
>  }
>  #else
> -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> +void hmp_info_profile(Monitor *mon, const QDict *qdict)
>  {
>      monitor_printf(mon, "Internal profiler not compiled\n");
>  }
> @@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>  /* Capture support */
>  static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
>  
> -static void hmp_info_capture(Monitor *mon, const QDict *qdict)
> +void hmp_info_capture(Monitor *mon, const QDict *qdict)
>  {
>      int i;
>      CaptureState *s;
> @@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
> +void hmp_stopcapture(Monitor *mon, const QDict *qdict)
>  {
>      int i;
>      int n = qdict_get_int(qdict, "n");
> @@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
> +void hmp_wavcapture(Monitor *mon, const QDict *qdict)
>  {
>      const char *path = qdict_get_str(qdict, "path");
>      int freq = qdict_get_try_int(qdict, "freq", 44100);
> @@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
>      warn_acl = true;
>  }
>  
> -static void hmp_acl_show(Monitor *mon, const QDict *qdict)
> +void hmp_acl_show(Monitor *mon, const QDict *qdict)
>  {
>      const char *aclname = qdict_get_str(qdict, "aclname");
>      QAuthZList *auth = find_auth(mon, aclname);
> @@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
> +void hmp_acl_reset(Monitor *mon, const QDict *qdict)
>  {
>      const char *aclname = qdict_get_str(qdict, "aclname");
>      QAuthZList *auth = find_auth(mon, aclname);
> @@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
>      monitor_printf(mon, "acl: removed all rules\n");
>  }
>  
> -static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
> +void hmp_acl_policy(Monitor *mon, const QDict *qdict)
>  {
>      const char *aclname = qdict_get_str(qdict, "aclname");
>      const char *policy = qdict_get_str(qdict, "policy");
> @@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
>      }
>  }
>  
> -static void hmp_acl_add(Monitor *mon, const QDict *qdict)
> +void hmp_acl_add(Monitor *mon, const QDict *qdict)
>  {
>      const char *aclname = qdict_get_str(qdict, "aclname");
>      const char *match = qdict_get_str(qdict, "match");
> @@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
>      }
>  }
>  
> -static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
> +void hmp_acl_remove(Monitor *mon, const QDict *qdict)
>  {
>      const char *aclname = qdict_get_str(qdict, "aclname");
>      const char *match = qdict_get_str(qdict, "match");
> @@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
>  
>  /* Please update hmp-commands.hx when adding or changing commands */
>  static HMPCommand hmp_info_cmds[] = {
> +#if defined(SCSI_PROCESS)
> +#include "hmp-scsi-commands-info.h"
> +#else
>  #include "hmp-commands-info.h"
> +#endif
>      { NULL, NULL, },
>  };
>  
>  /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
>  HMPCommand hmp_cmds[] = {
> +#if defined(SCSI_PROCESS)
> +#include "hmp-scsi-commands.h"
> +#else
>  #include "hmp-commands.h"
> +#endif
>      { NULL, NULL, },
>  };
>  
> diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
> index 3e6baba..26349cb 100644
> --- a/monitor/monitor-internal.h
> +++ b/monitor/monitor-internal.h
> @@ -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
> diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
> index 20fcc37..a8a3925 100644
> --- a/qapi/Makefile.objs
> +++ b/qapi/Makefile.objs
> @@ -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)
> diff --git a/qom/Makefile.objs b/qom/Makefile.objs
> index 07e50e5..16603d7 100644
> --- a/qom/Makefile.objs
> +++ b/qom/Makefile.objs
> @@ -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
> diff --git a/ui/Makefile.objs b/ui/Makefile.objs
> index e6da6ff..c3ac572 100644
> --- a/ui/Makefile.objs
> +++ b/ui/Makefile.objs
> @@ -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
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c
  2020-02-24 20:55 ` [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c Jagannathan Raman
@ 2020-03-05 10:51   ` Dr. David Alan Gilbert
  2020-03-05 15:41     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 10:51 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> 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.
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

This looks like another good candidate to go in a separate post that
doesn't need to wait for the rest of multi-process; you are probably
best splitting it into separate chardev and monitor chunks so they can
go via their respective maintainers.

Dave


> ---
>  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(-)
> 
> diff --git a/chardev/char.c b/chardev/char.c
> index 8723756..1d03ea0 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -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);
> diff --git a/include/chardev/char.h b/include/chardev/char.h
> index 00589a6..e370320 100644
> --- a/include/chardev/char.h
> +++ b/include/chardev/char.h
> @@ -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
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index b7bdd2b..d92bf1c 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -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 */
> diff --git a/monitor/monitor.c b/monitor/monitor.c
> index c1a6c44..5759b84 100644
> --- a/monitor/monitor.c
> +++ b/monitor/monitor.c
> @@ -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;
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index 5284ee9..23fc0df 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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;
> diff --git a/remote/remote-opts.c b/remote/remote-opts.c
> index 7e12700..565e641 100644
> --- a/remote/remote-opts.c
> +++ b/remote/remote-opts.c
> @@ -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"
>  /*
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index a8a6f35..4a4f52c 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
>      return qdev_device_help(opts);
>  }
>  
> -static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
> -{
> -    Error *local_err = NULL;
> -
> -    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
> -        if (local_err) {
> -            error_propagate(errp, local_err);
> -            return -1;
> -        }
> -        exit(0);
> -    }
> -    return 0;
> -}
>  
>  #ifdef CONFIG_VIRTFS
>  static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
> @@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
>  }
>  #endif
>  
> -static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
> -{
> -    return monitor_init_opts(opts, errp);
> -}
> -
> -static void monitor_parse(const char *optarg, const char *mode, bool pretty)
> -{
> -    static int monitor_device_index = 0;
> -    QemuOpts *opts;
> -    const char *p;
> -    char label[32];
> -
> -    if (strstart(optarg, "chardev:", &p)) {
> -        snprintf(label, sizeof(label), "%s", p);
> -    } else {
> -        snprintf(label, sizeof(label), "compat_monitor%d",
> -                 monitor_device_index);
> -        opts = qemu_chr_parse_compat(label, optarg, true);
> -        if (!opts) {
> -            error_report("parse error: %s", optarg);
> -            exit(1);
> -        }
> -    }
> -
> -    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
> -    qemu_opt_set(opts, "mode", mode, &error_abort);
> -    qemu_opt_set(opts, "chardev", label, &error_abort);
> -    if (!strcmp(mode, "control")) {
> -        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
> -    } else {
> -        assert(pretty == false);
> -    }
> -    monitor_device_index++;
> -}
> -
>  struct device_config {
>      enum {
>          DEV_USB,       /* -usbdevice     */
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object
  2020-02-24 20:55 ` [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object Jagannathan Raman
@ 2020-03-05 12:31   ` Dr. David Alan Gilbert
  2020-03-05 16:48     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 12:31 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> Collect the VMSD from remote process on the source and save
> it to the channel leading to the destination
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  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(+)
> 
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index b1b9282..19f0dbb 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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;

This feels way too complicated.   Since we know f_remote is always just
a simple fd we're getting we don't need to use qio or qemu_file here;
just use the fd - nice and simple.

Then the code to read it can just use read(2) with a sensible size chunk
rather than reading a byte at a time.

> +    mig_data->dev = pdev;
> +
> +    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
> +                       QEMU_THREAD_DETACHED);

I'm just checking why a thread is necessary; is this because you need to
be able to start reading before you block waiting for the remote to tell
you the size - worrying that if you don't start reading then the remote
might block waiting for us?

> +    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) {
> +    }

Hmm.  I suggest the following:

  a) You create a shared 'size' variable;  and initialize it to
    UINT64_MAX.
  b) The thread uses atomic_read(shared_size) to read that value.
  c) When you receive the size from the remote you do
     atomic_set(&shared_size, size);
  d) The thread does:
     while (received_size < atomic_read(&shared_size))

     so the thread will quit either on EOF or it hitting the size.

  e) We pthread_join here to wait for the thread
  f) We then check a received size to make sure it matches what we
expect.

That removes the tight loop.

> +    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;

I don't think you need that.

> +}
> +
> +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),

I think instead you should use a VMSTATE_VBUFFER here to save
the mig_data.
What we should do is the post_save should g_free the buffer.
(mig_data should be a field in proxy).

Dave


> +        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 = {
> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
> index 5de8129..537c227 100644
> --- a/include/hw/proxy/qemu-proxy.h
> +++ b/include/hw/proxy/qemu-proxy.h
> @@ -75,6 +75,8 @@ struct PCIProxyDev {
>                          bool need_spawn, Error **errp);
>  
>      ProxyMemoryRegion region[PCI_NUM_REGIONS];
> +
> +    uint64_t migsize;
>  };
>  
>  typedef struct PCIProxyDevClass {
> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> index d2234ca..b42c003 100644
> --- a/include/io/mpqemu-link.h
> +++ b/include/io/mpqemu-link.h
> @@ -63,6 +63,7 @@ typedef enum {
>      PROXY_PING,
>      MMIO_RETURN,
>      DEVICE_RESET,
> +    START_MIG_OUT,
>      MAX,
>  } mpqemu_cmd_t;
>  
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object
  2020-02-24 20:55 ` [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to " Jagannathan Raman
@ 2020-03-05 14:39   ` Dr. David Alan Gilbert
  2020-03-05 16:32     ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 14:39 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> The remote process sends the VMSD to the Proxy object, on the source
> side
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  migration/savevm.c   | 27 +++++++++++++++++++++++++++
>  migration/savevm.h   |  2 ++
>  remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 72 insertions(+)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 1d4220e..09af14d 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -2942,3 +2942,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
>  
>      return !(vmsd && vmsd->unmigratable);
>  }
> +

Can we add something here commenting, e.g.
/* Called by the remote process to serialise migration back to the qemu
 * */
> +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);

You have a qemu_fflush in process_start_mig_out  just after you call it
- so you don't need both; I suggest you remove this one.

> +    return 0;

And make this return qemu_file_get_error(f);  just like
qemu_save_device_state and then makybe some day we can merge them.

> +}


> diff --git a/migration/savevm.h b/migration/savevm.h
> index ba64a7e..0491d3a 100644
> --- a/migration/savevm.h
> +++ b/migration/savevm.h
> @@ -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
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index 58d9905..e97eb76 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -53,6 +53,16 @@
>  #include "qemu/log.h"
>  #include "qemu/cutils.h"
>  #include "remote-opts.h"
> +#include "qapi/error.h"
> +#include "io/channel-util.h"
> +
> +#include "io/channel.h"
> +#include "io/channel-socket.h"
> +#include "migration/qemu-file-types.h"
> +#include "migration/savevm.h"
> +#include "migration/qemu-file-channel.h"
> +#include "migration/qemu-file.h"
> +
>  #include "monitor/monitor.h"
>  #include "chardev/char.h"
>  #include "sysemu/reset.h"
> @@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
>  
>  }
>  
> +static void process_start_mig_out(MPQemuMsg *msg)
> +{
> +    int wait = msg->fds[1];
> +    Error *err = NULL;
> +    QIOChannel *ioc;
> +    QEMUFile *f;
> +
> +    ioc = qio_channel_new_fd(msg->fds[0], &err);
> +    if (err) {
> +        error_report_err(err);
> +        return;
> +    }
> +
> +    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
> +
> +    f = qemu_fopen_channel_output(ioc);
> +
> +    bdrv_drain_all();
> +    (void)bdrv_flush_all();

Do remote process always have block code? I mean can't we have a remote
process that's just say a NIC ?

> +    (void)qemu_remote_savevm(f);

It's probably bad to ignore errors here; what you could do is if there's
an error, you shoul dprint something and then send a poison value back
to the QEMU to let it know that you've failed.

> +    qemu_fflush(f);
> +
> +    notify_proxy(wait, (uint64_t)qemu_ftell(f));
> +    PUT_REMOTE_WAIT(wait);
> +
> +    qemu_fclose(f);
> +}
> +
>  static void process_msg(GIOCondition cond, MPQemuChannel *chan)
>  {
>      MPQemuMsg *msg = NULL;
> @@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
>              notify_proxy(msg->fds[0], 0);
>          }
>          break;
> +    case START_MIG_OUT:
> +        process_start_mig_out(msg);
> +        break;
>      default:
>          error_setg(&err, "Unknown command");
>          goto finalize_loop;
> -- 
> 1.8.3.1

--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object
  2020-02-24 20:55 ` [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object Jagannathan Raman
@ 2020-03-05 15:28   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 15:28 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> The Proxy object loads the VMSD of remote process in source
> and send it to the remote process in the destination
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  hw/proxy/qemu-proxy.c    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
>  include/io/mpqemu-link.h |  1 +
>  2 files changed, 51 insertions(+)
> 
> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> index 19f0dbb..1649f60 100644
> --- a/hw/proxy/qemu-proxy.c
> +++ b/hw/proxy/qemu-proxy.c
> @@ -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);

My suggestion on the previous patch about using the VMSTATE_BUFFERV
means you'd malloc on size, and do the put_byte's to the remote in the
post_load.

> +        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),
> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> index b42c003..01371fc 100644
> --- a/include/io/mpqemu-link.h
> +++ b/include/io/mpqemu-link.h
> @@ -64,6 +64,7 @@ typedef enum {
>      MMIO_RETURN,
>      DEVICE_RESET,
>      START_MIG_OUT,
> +    START_MIG_IN,
>      MAX,
>  } mpqemu_cmd_t;
>  
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target
  2020-03-05 10:39   ` Dr. David Alan Gilbert
@ 2020-03-05 15:38     ` Jag Raman
  2020-03-05 15:50       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-05 15:38 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/5/2020 5:39 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>>
>> Add "targets" field to HMP command definition to select the targets
>> which would be supported by each command
>>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> ---
>>   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
>>
>> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
>> index 257ee7d..631cc76 100644
>> --- a/hmp-commands-info.hx
>> +++ b/hmp-commands-info.hx
>> @@ -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",
> 
> 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?

We found that QMP/HMP monitor is initialized as a chardev in QEMU. So we
could use this to get info about the monitors attached to the remote
process.

> 
>>           .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",
>>       },
>>   
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index dc23185..ecc6169 100644
>> --- a/hmp-commands.hx
>> +++ b/hmp-commands.hx
>> @@ -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",
>>       },
>> diff --git a/scripts/hxtool b/scripts/hxtool
>> old mode 100644
>> new mode 100755
>> index 0003e7b..802cbd4
>> --- a/scripts/hxtool
>> +++ b/scripts/hxtool
>> @@ -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
>> @@ -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' ?

Thanks, we'll fix it.

--
Jag

> 
>> +            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
>>   
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process
  2020-03-05 10:43   ` Dr. David Alan Gilbert
@ 2020-03-05 15:40     ` Jag Raman
  2020-03-05 15:52       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-05 15:40 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/5/2020 5:43 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>> Build system changes to enable QMP module in the remote process
>>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> 
> It's odd that this is labelled as QMP changes yet a lot of the code is
> actually HMP de-staticing.

This patch builds the QMP related code into the remote process. In order
to facilitate the build, we need to de-staticize a bunch of HMP
functions.

May be we could update the patch title to reflect the destaticing as
well.

Thanks!
--
Jag

> 
> Dave
> 
>> ---
>>   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(-)
>>
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 689a722..4b5db09 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -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
>> diff --git a/Makefile.target b/Makefile.target
>> index 035c23b..4ead5c3 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -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
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index ecc6169..a1932c4 100644
>> --- a/hmp-commands.hx
>> +++ b/hmp-commands.hx
>> @@ -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
>> diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
>> index e3e8084..251b77b 100644
>> --- a/hw/core/Makefile.objs
>> +++ b/hw/core/Makefile.objs
>> @@ -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
>> diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs
>> index 9244d90..48d8017 100644
>> --- a/monitor/Makefile.objs
>> +++ b/monitor/Makefile.objs
>> @@ -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
>> diff --git a/monitor/misc.c b/monitor/misc.c
>> index 6c41293..f1f09bf 100644
>> --- a/monitor/misc.c
>> +++ b/monitor/misc.c
>> @@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
>>       return 0;
>>   }
>>   
>> -static void do_help_cmd(Monitor *mon, const QDict *qdict)
>> +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
>>   {
>>       help_cmd(mon, qdict_get_try_str(qdict, "name"));
>>   }
>>   
>> -static void hmp_trace_event(Monitor *mon, const QDict *qdict)
>> +void hmp_trace_event(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *tp_name = qdict_get_str(qdict, "name");
>>       bool new_state = qdict_get_bool(qdict, "option");
>> @@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
>>   }
>>   #endif
>>   
>> -static void hmp_info_help(Monitor *mon, const QDict *qdict)
>> +void hmp_info_help(Monitor *mon, const QDict *qdict)
>>   {
>>       help_cmd(mon, "info");
>>   }
>> @@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
>>       return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
>>   }
>>   
>> -static void hmp_info_registers(Monitor *mon, const QDict *qdict)
>> +void hmp_info_registers(Monitor *mon, const QDict *qdict)
>>   {
>>       bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
>>       CPUState *cs;
>> @@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
>>   }
>>   
>>   #ifdef CONFIG_TCG
>> -static void hmp_info_jit(Monitor *mon, const QDict *qdict)
>> +void hmp_info_jit(Monitor *mon, const QDict *qdict)
>>   {
>>       if (!tcg_enabled()) {
>>           error_report("JIT information is only available with accel=tcg");
>> @@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
>>       dump_drift_info();
>>   }
>>   
>> -static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
>> +void hmp_info_opcount(Monitor *mon, const QDict *qdict)
>>   {
>>       dump_opcount_info();
>>   }
>>   #endif
>>   
>> -static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
>> +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
>>   {
>>       int64_t max = qdict_get_try_int(qdict, "max", 10);
>>       bool mean = qdict_get_try_bool(qdict, "mean", false);
>> @@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
>>       qsp_report(max, sort_by, coalesce);
>>   }
>>   
>> -static void hmp_info_history(Monitor *mon, const QDict *qdict)
>> +void hmp_info_history(Monitor *mon, const QDict *qdict)
>>   {
>>       MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
>>       int i;
>> @@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
>> +void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
>>   {
>>       CPUState *cs = mon_get_cpu();
>>   
>> @@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
>>       cpu_dump_statistics(cs, 0);
>>   }
>>   
>> -static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>> +void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *name = qdict_get_try_str(qdict, "name");
>>       bool has_vcpu = qdict_haskey(qdict, "vcpu");
>> @@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
>>       error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
>>   }
>>   
>> -static void hmp_logfile(Monitor *mon, const QDict *qdict)
>> +void hmp_logfile(Monitor *mon, const QDict *qdict)
>>   {
>>       Error *err = NULL;
>>   
>> @@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_log(Monitor *mon, const QDict *qdict)
>> +void hmp_log(Monitor *mon, const QDict *qdict)
>>   {
>>       int mask;
>>       const char *items = qdict_get_str(qdict, "items");
>> @@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
>>       qemu_set_log(mask);
>>   }
>>   
>> -static void hmp_singlestep(Monitor *mon, const QDict *qdict)
>> +void hmp_singlestep(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *option = qdict_get_try_str(qdict, "option");
>>       if (!option || !strcmp(option, "on")) {
>> @@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
>> +void hmp_gdbserver(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *device = qdict_get_try_str(qdict, "device");
>>       if (!device)
>> @@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
>> +void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *action = qdict_get_str(qdict, "action");
>>       if (select_watchdog_action(action) == -1) {
>> @@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
>>       }
>>   }
>>   
>> -static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
>> +void hmp_memory_dump(Monitor *mon, const QDict *qdict)
>>   {
>>       int count = qdict_get_int(qdict, "count");
>>       int format = qdict_get_int(qdict, "format");
>> @@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
>>       memory_dump(mon, count, format, size, addr, 0);
>>   }
>>   
>> -static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
>> +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
>>   {
>>       int count = qdict_get_int(qdict, "count");
>>       int format = qdict_get_int(qdict, "format");
>> @@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
>>       return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
>>   }
>>   
>> -static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
>> +void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
>>   {
>>       hwaddr addr = qdict_get_int(qdict, "addr");
>>       Error *local_err = NULL;
>> @@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
>>       memory_region_unref(mr);
>>   }
>>   
>> -static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
>> +void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
>>   {
>>       target_ulong addr = qdict_get_int(qdict, "addr");
>>       MemTxAttrs attrs;
>> @@ -768,7 +768,7 @@ out:
>>       return ret;
>>   }
>>   
>> -static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
>> +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
>>   {
>>       hwaddr addr = qdict_get_int(qdict, "addr");
>>       Error *local_err = NULL;
>> @@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
>>   }
>>   #endif
>>   
>> -static void do_print(Monitor *mon, const QDict *qdict)
>> +void hmp_do_print(Monitor *mon, const QDict *qdict)
>>   {
>>       int format = qdict_get_int(qdict, "format");
>>       hwaddr val = qdict_get_int(qdict, "val");
>> @@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
>>       monitor_printf(mon, "\n");
>>   }
>>   
>> -static void hmp_sum(Monitor *mon, const QDict *qdict)
>> +void hmp_sum(Monitor *mon, const QDict *qdict)
>>   {
>>       uint32_t addr;
>>       uint16_t sum;
>> @@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
>>   
>>   static int mouse_button_state;
>>   
>> -static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
>> +void hmp_mouse_move(Monitor *mon, const QDict *qdict)
>>   {
>>       int dx, dy, dz, button;
>>       const char *dx_str = qdict_get_str(qdict, "dx_str");
>> @@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
>>       qemu_input_event_sync();
>>   }
>>   
>> -static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
>> +void hmp_mouse_button(Monitor *mon, const QDict *qdict)
>>   {
>>       static uint32_t bmap[INPUT_BUTTON__MAX] = {
>>           [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
>> @@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
>>       mouse_button_state = button_state;
>>   }
>>   
>> -static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
>> +void hmp_ioport_read(Monitor *mon, const QDict *qdict)
>>   {
>>       int size = qdict_get_int(qdict, "size");
>>       int addr = qdict_get_int(qdict, "addr");
>> @@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
>>                      suffix, addr, size * 2, val);
>>   }
>>   
>> -static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
>> +void hmp_ioport_write(Monitor *mon, const QDict *qdict)
>>   {
>>       int size = qdict_get_int(qdict, "size");
>>       int addr = qdict_get_int(qdict, "addr");
>> @@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_boot_set(Monitor *mon, const QDict *qdict)
>> +void hmp_boot_set(Monitor *mon, const QDict *qdict)
>>   {
>>       Error *local_err = NULL;
>>       const char *bootdevice = qdict_get_str(qdict, "bootdevice");
>> @@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
>> +void hmp_info_mtree(Monitor *mon, const QDict *qdict)
>>   {
>>       bool flatview = qdict_get_try_bool(qdict, "flatview", false);
>>       bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
>> @@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
>>   
>>   int64_t dev_time;
>>   
>> -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>> +void hmp_info_profile(Monitor *mon, const QDict *qdict)
>>   {
>>       static int64_t last_cpu_exec_time;
>>       int64_t cpu_exec_time;
>> @@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>>       dev_time = 0;
>>   }
>>   #else
>> -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>> +void hmp_info_profile(Monitor *mon, const QDict *qdict)
>>   {
>>       monitor_printf(mon, "Internal profiler not compiled\n");
>>   }
>> @@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
>>   /* Capture support */
>>   static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
>>   
>> -static void hmp_info_capture(Monitor *mon, const QDict *qdict)
>> +void hmp_info_capture(Monitor *mon, const QDict *qdict)
>>   {
>>       int i;
>>       CaptureState *s;
>> @@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
>> +void hmp_stopcapture(Monitor *mon, const QDict *qdict)
>>   {
>>       int i;
>>       int n = qdict_get_int(qdict, "n");
>> @@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
>> +void hmp_wavcapture(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *path = qdict_get_str(qdict, "path");
>>       int freq = qdict_get_try_int(qdict, "freq", 44100);
>> @@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
>>       warn_acl = true;
>>   }
>>   
>> -static void hmp_acl_show(Monitor *mon, const QDict *qdict)
>> +void hmp_acl_show(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *aclname = qdict_get_str(qdict, "aclname");
>>       QAuthZList *auth = find_auth(mon, aclname);
>> @@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
>> +void hmp_acl_reset(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *aclname = qdict_get_str(qdict, "aclname");
>>       QAuthZList *auth = find_auth(mon, aclname);
>> @@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
>>       monitor_printf(mon, "acl: removed all rules\n");
>>   }
>>   
>> -static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
>> +void hmp_acl_policy(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *aclname = qdict_get_str(qdict, "aclname");
>>       const char *policy = qdict_get_str(qdict, "policy");
>> @@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
>>       }
>>   }
>>   
>> -static void hmp_acl_add(Monitor *mon, const QDict *qdict)
>> +void hmp_acl_add(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *aclname = qdict_get_str(qdict, "aclname");
>>       const char *match = qdict_get_str(qdict, "match");
>> @@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
>>       }
>>   }
>>   
>> -static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
>> +void hmp_acl_remove(Monitor *mon, const QDict *qdict)
>>   {
>>       const char *aclname = qdict_get_str(qdict, "aclname");
>>       const char *match = qdict_get_str(qdict, "match");
>> @@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
>>   
>>   /* Please update hmp-commands.hx when adding or changing commands */
>>   static HMPCommand hmp_info_cmds[] = {
>> +#if defined(SCSI_PROCESS)
>> +#include "hmp-scsi-commands-info.h"
>> +#else
>>   #include "hmp-commands-info.h"
>> +#endif
>>       { NULL, NULL, },
>>   };
>>   
>>   /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
>>   HMPCommand hmp_cmds[] = {
>> +#if defined(SCSI_PROCESS)
>> +#include "hmp-scsi-commands.h"
>> +#else
>>   #include "hmp-commands.h"
>> +#endif
>>       { NULL, NULL, },
>>   };
>>   
>> diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
>> index 3e6baba..26349cb 100644
>> --- a/monitor/monitor-internal.h
>> +++ b/monitor/monitor-internal.h
>> @@ -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
>> diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
>> index 20fcc37..a8a3925 100644
>> --- a/qapi/Makefile.objs
>> +++ b/qapi/Makefile.objs
>> @@ -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)
>> diff --git a/qom/Makefile.objs b/qom/Makefile.objs
>> index 07e50e5..16603d7 100644
>> --- a/qom/Makefile.objs
>> +++ b/qom/Makefile.objs
>> @@ -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
>> diff --git a/ui/Makefile.objs b/ui/Makefile.objs
>> index e6da6ff..c3ac572 100644
>> --- a/ui/Makefile.objs
>> +++ b/ui/Makefile.objs
>> @@ -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
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c
  2020-03-05 10:51   ` Dr. David Alan Gilbert
@ 2020-03-05 15:41     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-05 15:41 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/5/2020 5:51 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>> 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.
>>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> 
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> 
> This looks like another good candidate to go in a separate post that
> doesn't need to wait for the rest of multi-process; you are probably
> best splitting it into separate chardev and monitor chunks so they can
> go via their respective maintainers.

Sure, thanks!

--
Jag

> 
> Dave
> 
> 
>> ---
>>   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(-)
>>
>> diff --git a/chardev/char.c b/chardev/char.c
>> index 8723756..1d03ea0 100644
>> --- a/chardev/char.c
>> +++ b/chardev/char.c
>> @@ -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);
>> diff --git a/include/chardev/char.h b/include/chardev/char.h
>> index 00589a6..e370320 100644
>> --- a/include/chardev/char.h
>> +++ b/include/chardev/char.h
>> @@ -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
>> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
>> index b7bdd2b..d92bf1c 100644
>> --- a/include/monitor/monitor.h
>> +++ b/include/monitor/monitor.h
>> @@ -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 */
>> diff --git a/monitor/monitor.c b/monitor/monitor.c
>> index c1a6c44..5759b84 100644
>> --- a/monitor/monitor.c
>> +++ b/monitor/monitor.c
>> @@ -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;
>> diff --git a/remote/remote-main.c b/remote/remote-main.c
>> index 5284ee9..23fc0df 100644
>> --- a/remote/remote-main.c
>> +++ b/remote/remote-main.c
>> @@ -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;
>> diff --git a/remote/remote-opts.c b/remote/remote-opts.c
>> index 7e12700..565e641 100644
>> --- a/remote/remote-opts.c
>> +++ b/remote/remote-opts.c
>> @@ -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"
>>   /*
>> diff --git a/softmmu/vl.c b/softmmu/vl.c
>> index a8a6f35..4a4f52c 100644
>> --- a/softmmu/vl.c
>> +++ b/softmmu/vl.c
>> @@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
>>       return qdev_device_help(opts);
>>   }
>>   
>> -static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
>> -{
>> -    Error *local_err = NULL;
>> -
>> -    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
>> -        if (local_err) {
>> -            error_propagate(errp, local_err);
>> -            return -1;
>> -        }
>> -        exit(0);
>> -    }
>> -    return 0;
>> -}
>>   
>>   #ifdef CONFIG_VIRTFS
>>   static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
>> @@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
>>   }
>>   #endif
>>   
>> -static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
>> -{
>> -    return monitor_init_opts(opts, errp);
>> -}
>> -
>> -static void monitor_parse(const char *optarg, const char *mode, bool pretty)
>> -{
>> -    static int monitor_device_index = 0;
>> -    QemuOpts *opts;
>> -    const char *p;
>> -    char label[32];
>> -
>> -    if (strstart(optarg, "chardev:", &p)) {
>> -        snprintf(label, sizeof(label), "%s", p);
>> -    } else {
>> -        snprintf(label, sizeof(label), "compat_monitor%d",
>> -                 monitor_device_index);
>> -        opts = qemu_chr_parse_compat(label, optarg, true);
>> -        if (!opts) {
>> -            error_report("parse error: %s", optarg);
>> -            exit(1);
>> -        }
>> -    }
>> -
>> -    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
>> -    qemu_opt_set(opts, "mode", mode, &error_abort);
>> -    qemu_opt_set(opts, "chardev", label, &error_abort);
>> -    if (!strcmp(mode, "control")) {
>> -        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
>> -    } else {
>> -        assert(pretty == false);
>> -    }
>> -    monitor_device_index++;
>> -}
>> -
>>   struct device_config {
>>       enum {
>>           DEV_USB,       /* -usbdevice     */
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target
  2020-03-05 15:38     ` Jag Raman
@ 2020-03-05 15:50       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 15:50 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/5/2020 5:39 AM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > 
> > > Add "targets" field to HMP command definition to select the targets
> > > which would be supported by each command
> > > 
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > ---
> > >   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
> > > 
> > > diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> > > index 257ee7d..631cc76 100644
> > > --- a/hmp-commands-info.hx
> > > +++ b/hmp-commands-info.hx
> > > @@ -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",
> > 
> > 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?
> 
> We found that QMP/HMP monitor is initialized as a chardev in QEMU. So we
> could use this to get info about the monitors attached to the remote
> process.

Ah OK.

> > 
> > >           .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",
> > >       },
> > > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > > index dc23185..ecc6169 100644
> > > --- a/hmp-commands.hx
> > > +++ b/hmp-commands.hx
> > > @@ -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",
> > >       },
> > > diff --git a/scripts/hxtool b/scripts/hxtool
> > > old mode 100644
> > > new mode 100755
> > > index 0003e7b..802cbd4
> > > --- a/scripts/hxtool
> > > +++ b/scripts/hxtool
> > > @@ -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
> > > @@ -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' ?
> 
> Thanks, we'll fix it.
> 
> --
> Jag
> 
> > 
> > > +            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
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process
  2020-03-05 15:40     ` Jag Raman
@ 2020-03-05 15:52       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 15:52 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/5/2020 5:43 AM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > Build system changes to enable QMP module in the remote process
> > > 
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > 
> > It's odd that this is labelled as QMP changes yet a lot of the code is
> > actually HMP de-staticing.
> 
> This patch builds the QMP related code into the remote process. In order
> to facilitate the build, we need to de-staticize a bunch of HMP
> functions.
> 
> May be we could update the patch title to reflect the destaticing as
> well.

Or split it into two.

Dave

> Thanks!
> --
> Jag
> 
> > 
> > Dave
> > 
> > > ---
> > >   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(-)
> > > 
> > > diff --git a/Makefile.objs b/Makefile.objs
> > > index 689a722..4b5db09 100644
> > > --- a/Makefile.objs
> > > +++ b/Makefile.objs
> > > @@ -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
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 035c23b..4ead5c3 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -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
> > > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > > index ecc6169..a1932c4 100644
> > > --- a/hmp-commands.hx
> > > +++ b/hmp-commands.hx
> > > @@ -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
> > > diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
> > > index e3e8084..251b77b 100644
> > > --- a/hw/core/Makefile.objs
> > > +++ b/hw/core/Makefile.objs
> > > @@ -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
> > > diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs
> > > index 9244d90..48d8017 100644
> > > --- a/monitor/Makefile.objs
> > > +++ b/monitor/Makefile.objs
> > > @@ -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
> > > diff --git a/monitor/misc.c b/monitor/misc.c
> > > index 6c41293..f1f09bf 100644
> > > --- a/monitor/misc.c
> > > +++ b/monitor/misc.c
> > > @@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list)
> > >       return 0;
> > >   }
> > > -static void do_help_cmd(Monitor *mon, const QDict *qdict)
> > > +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict)
> > >   {
> > >       help_cmd(mon, qdict_get_try_str(qdict, "name"));
> > >   }
> > > -static void hmp_trace_event(Monitor *mon, const QDict *qdict)
> > > +void hmp_trace_event(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *tp_name = qdict_get_str(qdict, "name");
> > >       bool new_state = qdict_get_bool(qdict, "option");
> > > @@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict)
> > >   }
> > >   #endif
> > > -static void hmp_info_help(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_help(Monitor *mon, const QDict *qdict)
> > >   {
> > >       help_cmd(mon, "info");
> > >   }
> > > @@ -314,7 +314,7 @@ int monitor_get_cpu_index(void)
> > >       return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
> > >   }
> > > -static void hmp_info_registers(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_registers(Monitor *mon, const QDict *qdict)
> > >   {
> > >       bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false);
> > >       CPUState *cs;
> > > @@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
> > >   }
> > >   #ifdef CONFIG_TCG
> > > -static void hmp_info_jit(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_jit(Monitor *mon, const QDict *qdict)
> > >   {
> > >       if (!tcg_enabled()) {
> > >           error_report("JIT information is only available with accel=tcg");
> > > @@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
> > >       dump_drift_info();
> > >   }
> > > -static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_opcount(Monitor *mon, const QDict *qdict)
> > >   {
> > >       dump_opcount_info();
> > >   }
> > >   #endif
> > > -static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int64_t max = qdict_get_try_int(qdict, "max", 10);
> > >       bool mean = qdict_get_try_bool(qdict, "mean", false);
> > > @@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
> > >       qsp_report(max, sort_by, coalesce);
> > >   }
> > > -static void hmp_info_history(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_history(Monitor *mon, const QDict *qdict)
> > >   {
> > >       MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
> > >       int i;
> > > @@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
> > >   {
> > >       CPUState *cs = mon_get_cpu();
> > > @@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict)
> > >       cpu_dump_statistics(cs, 0);
> > >   }
> > > -static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *name = qdict_get_try_str(qdict, "name");
> > >       bool has_vcpu = qdict_haskey(qdict, "vcpu");
> > > @@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,
> > >       error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice");
> > >   }
> > > -static void hmp_logfile(Monitor *mon, const QDict *qdict)
> > > +void hmp_logfile(Monitor *mon, const QDict *qdict)
> > >   {
> > >       Error *err = NULL;
> > > @@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_log(Monitor *mon, const QDict *qdict)
> > > +void hmp_log(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int mask;
> > >       const char *items = qdict_get_str(qdict, "items");
> > > @@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict)
> > >       qemu_set_log(mask);
> > >   }
> > > -static void hmp_singlestep(Monitor *mon, const QDict *qdict)
> > > +void hmp_singlestep(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *option = qdict_get_try_str(qdict, "option");
> > >       if (!option || !strcmp(option, "on")) {
> > > @@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
> > > +void hmp_gdbserver(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *device = qdict_get_try_str(qdict, "device");
> > >       if (!device)
> > > @@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
> > > +void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *action = qdict_get_str(qdict, "action");
> > >       if (select_watchdog_action(action) == -1) {
> > > @@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
> > >       }
> > >   }
> > > -static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
> > > +void hmp_memory_dump(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int count = qdict_get_int(qdict, "count");
> > >       int format = qdict_get_int(qdict, "format");
> > > @@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict)
> > >       memory_dump(mon, count, format, size, addr, 0);
> > >   }
> > > -static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
> > > +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int count = qdict_get_int(qdict, "count");
> > >       int format = qdict_get_int(qdict, "format");
> > > @@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp)
> > >       return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region);
> > >   }
> > > -static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
> > > +void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
> > >   {
> > >       hwaddr addr = qdict_get_int(qdict, "addr");
> > >       Error *local_err = NULL;
> > > @@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict)
> > >       memory_region_unref(mr);
> > >   }
> > > -static void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
> > > +void hmp_gva2gpa(Monitor *mon, const QDict *qdict)
> > >   {
> > >       target_ulong addr = qdict_get_int(qdict, "addr");
> > >       MemTxAttrs attrs;
> > > @@ -768,7 +768,7 @@ out:
> > >       return ret;
> > >   }
> > > -static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
> > > +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
> > >   {
> > >       hwaddr addr = qdict_get_int(qdict, "addr");
> > >       Error *local_err = NULL;
> > > @@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict)
> > >   }
> > >   #endif
> > > -static void do_print(Monitor *mon, const QDict *qdict)
> > > +void hmp_do_print(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int format = qdict_get_int(qdict, "format");
> > >       hwaddr val = qdict_get_int(qdict, "val");
> > > @@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict)
> > >       monitor_printf(mon, "\n");
> > >   }
> > > -static void hmp_sum(Monitor *mon, const QDict *qdict)
> > > +void hmp_sum(Monitor *mon, const QDict *qdict)
> > >   {
> > >       uint32_t addr;
> > >       uint16_t sum;
> > > @@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict)
> > >   static int mouse_button_state;
> > > -static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
> > > +void hmp_mouse_move(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int dx, dy, dz, button;
> > >       const char *dx_str = qdict_get_str(qdict, "dx_str");
> > > @@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict)
> > >       qemu_input_event_sync();
> > >   }
> > > -static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
> > > +void hmp_mouse_button(Monitor *mon, const QDict *qdict)
> > >   {
> > >       static uint32_t bmap[INPUT_BUTTON__MAX] = {
> > >           [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
> > > @@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict)
> > >       mouse_button_state = button_state;
> > >   }
> > > -static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
> > > +void hmp_ioport_read(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int size = qdict_get_int(qdict, "size");
> > >       int addr = qdict_get_int(qdict, "addr");
> > > @@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict)
> > >                      suffix, addr, size * 2, val);
> > >   }
> > > -static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
> > > +void hmp_ioport_write(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int size = qdict_get_int(qdict, "size");
> > >       int addr = qdict_get_int(qdict, "addr");
> > > @@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_boot_set(Monitor *mon, const QDict *qdict)
> > > +void hmp_boot_set(Monitor *mon, const QDict *qdict)
> > >   {
> > >       Error *local_err = NULL;
> > >       const char *bootdevice = qdict_get_str(qdict, "bootdevice");
> > > @@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_mtree(Monitor *mon, const QDict *qdict)
> > >   {
> > >       bool flatview = qdict_get_try_bool(qdict, "flatview", false);
> > >       bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false);
> > > @@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
> > >   int64_t dev_time;
> > > -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > >   {
> > >       static int64_t last_cpu_exec_time;
> > >       int64_t cpu_exec_time;
> > > @@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > >       dev_time = 0;
> > >   }
> > >   #else
> > > -static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > >   {
> > >       monitor_printf(mon, "Internal profiler not compiled\n");
> > >   }
> > > @@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict)
> > >   /* Capture support */
> > >   static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
> > > -static void hmp_info_capture(Monitor *mon, const QDict *qdict)
> > > +void hmp_info_capture(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int i;
> > >       CaptureState *s;
> > > @@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
> > > +void hmp_stopcapture(Monitor *mon, const QDict *qdict)
> > >   {
> > >       int i;
> > >       int n = qdict_get_int(qdict, "n");
> > > @@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
> > > +void hmp_wavcapture(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *path = qdict_get_str(qdict, "path");
> > >       int freq = qdict_get_try_int(qdict, "freq", 44100);
> > > @@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void)
> > >       warn_acl = true;
> > >   }
> > > -static void hmp_acl_show(Monitor *mon, const QDict *qdict)
> > > +void hmp_acl_show(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *aclname = qdict_get_str(qdict, "aclname");
> > >       QAuthZList *auth = find_auth(mon, aclname);
> > > @@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
> > > +void hmp_acl_reset(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *aclname = qdict_get_str(qdict, "aclname");
> > >       QAuthZList *auth = find_auth(mon, aclname);
> > > @@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict)
> > >       monitor_printf(mon, "acl: removed all rules\n");
> > >   }
> > > -static void hmp_acl_policy(Monitor *mon, const QDict *qdict)
> > > +void hmp_acl_policy(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *aclname = qdict_get_str(qdict, "aclname");
> > >       const char *policy = qdict_get_str(qdict, "policy");
> > > @@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match)
> > >       }
> > >   }
> > > -static void hmp_acl_add(Monitor *mon, const QDict *qdict)
> > > +void hmp_acl_add(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *aclname = qdict_get_str(qdict, "aclname");
> > >       const char *match = qdict_get_str(qdict, "match");
> > > @@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict)
> > >       }
> > >   }
> > > -static void hmp_acl_remove(Monitor *mon, const QDict *qdict)
> > > +void hmp_acl_remove(Monitor *mon, const QDict *qdict)
> > >   {
> > >       const char *aclname = qdict_get_str(qdict, "aclname");
> > >       const char *match = qdict_get_str(qdict, "match");
> > > @@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)
> > >   /* Please update hmp-commands.hx when adding or changing commands */
> > >   static HMPCommand hmp_info_cmds[] = {
> > > +#if defined(SCSI_PROCESS)
> > > +#include "hmp-scsi-commands-info.h"
> > > +#else
> > >   #include "hmp-commands-info.h"
> > > +#endif
> > >       { NULL, NULL, },
> > >   };
> > >   /* hmp_cmds and hmp_info_cmds would be sorted at runtime */
> > >   HMPCommand hmp_cmds[] = {
> > > +#if defined(SCSI_PROCESS)
> > > +#include "hmp-scsi-commands.h"
> > > +#else
> > >   #include "hmp-commands.h"
> > > +#endif
> > >       { NULL, NULL, },
> > >   };
> > > diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
> > > index 3e6baba..26349cb 100644
> > > --- a/monitor/monitor-internal.h
> > > +++ b/monitor/monitor-internal.h
> > > @@ -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
> > > diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs
> > > index 20fcc37..a8a3925 100644
> > > --- a/qapi/Makefile.objs
> > > +++ b/qapi/Makefile.objs
> > > @@ -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)
> > > diff --git a/qom/Makefile.objs b/qom/Makefile.objs
> > > index 07e50e5..16603d7 100644
> > > --- a/qom/Makefile.objs
> > > +++ b/qom/Makefile.objs
> > > @@ -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
> > > diff --git a/ui/Makefile.objs b/ui/Makefile.objs
> > > index e6da6ff..c3ac572 100644
> > > --- a/ui/Makefile.objs
> > > +++ b/ui/Makefile.objs
> > > @@ -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
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 46/50] multi-process/mig: Restore the VMSD in remote process
  2020-02-24 20:55 ` [PATCH v5 46/50] multi-process/mig: Restore the VMSD in " Jagannathan Raman
@ 2020-03-05 16:05   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 16:05 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jagannathan Raman (jag.raman@oracle.com) wrote:
> From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> 
> The remote process accepts the VMSD from Proxy object and
> restores it
> 
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  migration/savevm.c   | 36 ++++++++++++++++++++++++++++++++++++
>  migration/savevm.h   |  1 +
>  remote/remote-main.c | 33 +++++++++++++++++++++++++++++++++
>  3 files changed, 70 insertions(+)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 09af14d..e95ea4a 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -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;

It's good to print an error there - when it goes wrong we'll want to
know it.

> +            goto out;
> +        }
> +    }
> +
> +out:
> +    qemu_mutex_unlock_iothread();
> +
> +    return ret;
> +}
> diff --git a/migration/savevm.h b/migration/savevm.h
> index 0491d3a..8741c66 100644
> --- a/migration/savevm.h
> +++ b/migration/savevm.h
> @@ -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
> diff --git a/remote/remote-main.c b/remote/remote-main.c
> index 0260c7c..ab4ad0b 100644
> --- a/remote/remote-main.c
> +++ b/remote/remote-main.c
> @@ -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;

Do you have any sanity checks to make sure what happens if you were to
receive a MIG_IN while you were already running?

Dave

>      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);
> -- 
> 1.8.3.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object
  2020-03-05 14:39   ` Dr. David Alan Gilbert
@ 2020-03-05 16:32     ` Elena Ufimtseva
  0 siblings, 0 replies; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-05 16:32 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, liran.alon, stefanha,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Thu, Mar 05, 2020 at 02:39:49PM +0000, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > The remote process sends the VMSD to the Proxy object, on the source
> > side
> > 
> > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > ---
> >  migration/savevm.c   | 27 +++++++++++++++++++++++++++
> >  migration/savevm.h   |  2 ++
> >  remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 72 insertions(+)
> > 
> > diff --git a/migration/savevm.c b/migration/savevm.c
> > index 1d4220e..09af14d 100644
> > --- a/migration/savevm.c
> > +++ b/migration/savevm.c
> > @@ -2942,3 +2942,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)
> >  
> >      return !(vmsd && vmsd->unmigratable);
> >  }
> > +
> 
> Can we add something here commenting, e.g.
> /* Called by the remote process to serialise migration back to the qemu
>  * */

Will add this.
> > +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);
> 
> You have a qemu_fflush in process_start_mig_out  just after you call it
> - so you don't need both; I suggest you remove this one.
>
Ok. 
> > +    return 0;
> 
> And make this return qemu_file_get_error(f);  just like
> qemu_save_device_state and then makybe some day we can merge them.
>
Will do.
> > +}
> 
> 
> > diff --git a/migration/savevm.h b/migration/savevm.h
> > index ba64a7e..0491d3a 100644
> > --- a/migration/savevm.h
> > +++ b/migration/savevm.h
> > @@ -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
> > diff --git a/remote/remote-main.c b/remote/remote-main.c
> > index 58d9905..e97eb76 100644
> > --- a/remote/remote-main.c
> > +++ b/remote/remote-main.c
> > @@ -53,6 +53,16 @@
> >  #include "qemu/log.h"
> >  #include "qemu/cutils.h"
> >  #include "remote-opts.h"
> > +#include "qapi/error.h"
> > +#include "io/channel-util.h"
> > +
> > +#include "io/channel.h"
> > +#include "io/channel-socket.h"
> > +#include "migration/qemu-file-types.h"
> > +#include "migration/savevm.h"
> > +#include "migration/qemu-file-channel.h"
> > +#include "migration/qemu-file.h"
> > +
> >  #include "monitor/monitor.h"
> >  #include "chardev/char.h"
> >  #include "sysemu/reset.h"
> > @@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp)
> >  
> >  }
> >  
> > +static void process_start_mig_out(MPQemuMsg *msg)
> > +{
> > +    int wait = msg->fds[1];
> > +    Error *err = NULL;
> > +    QIOChannel *ioc;
> > +    QEMUFile *f;
> > +
> > +    ioc = qio_channel_new_fd(msg->fds[0], &err);
> > +    if (err) {
> > +        error_report_err(err);
> > +        return;
> > +    }
> > +
> > +    qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel");
> > +
> > +    f = qemu_fopen_channel_output(ioc);
> > +
> > +    bdrv_drain_all();
> > +    (void)bdrv_flush_all();
> 
> Do remote process always have block code? I mean can't we have a remote
> process that's just say a NIC ?

Not always (in the future), we will account for this.

> 
> > +    (void)qemu_remote_savevm(f);
> 
> It's probably bad to ignore errors here; what you could do is if there's
> an error, you shoul dprint something and then send a poison value back
> to the QEMU to let it know that you've failed.
> 

Yes, will add this.

> > +    qemu_fflush(f);
> > +
> > +    notify_proxy(wait, (uint64_t)qemu_ftell(f));
> > +    PUT_REMOTE_WAIT(wait);
> > +
> > +    qemu_fclose(f);
> > +}
> > +
> >  static void process_msg(GIOCondition cond, MPQemuChannel *chan)
> >  {
> >      MPQemuMsg *msg = NULL;
> > @@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
> >              notify_proxy(msg->fds[0], 0);
> >          }
> >          break;
> > +    case START_MIG_OUT:
> > +        process_start_mig_out(msg);
> > +        break;
> >      default:
> >          error_setg(&err, "Unknown command");
> >          goto finalize_loop;
> > -- 
> > 1.8.3.1
> 
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object
  2020-03-05 12:31   ` Dr. David Alan Gilbert
@ 2020-03-05 16:48     ` Jag Raman
  2020-03-05 17:04       ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Jag Raman @ 2020-03-05 16:48 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/5/2020 7:31 AM, Dr. David Alan Gilbert wrote:
> * Jagannathan Raman (jag.raman@oracle.com) wrote:
>> Collect the VMSD from remote process on the source and save
>> it to the channel leading to the destination
>>
>> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
>> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
>> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
>> ---
>>   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(+)
>>
>> diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
>> index b1b9282..19f0dbb 100644
>> --- a/hw/proxy/qemu-proxy.c
>> +++ b/hw/proxy/qemu-proxy.c
>> @@ -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;
> 
> This feels way too complicated.   Since we know f_remote is always just
> a simple fd we're getting we don't need to use qio or qemu_file here;
> just use the fd - nice and simple.
> 
> Then the code to read it can just use read(2) with a sensible size chunk
> rather than reading a byte at a time.

Hi Dave,

Upon closer inspection, we found that the migration code on the remote
(which uses QEMUFile) could sometimes set an error on the channel using
qemu_file_set_error(). We needed to use qemu_file_get_error() to catch
these errors and abort migration. So we had to stick with QEMUFile at
the receiving end as well.

> 
>> +    mig_data->dev = pdev;
>> +
>> +    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
>> +                       QEMU_THREAD_DETACHED);
> 
> I'm just checking why a thread is necessary; is this because you need to
> be able to start reading before you block waiting for the remote to tell
> you the size - worrying that if you don't start reading then the remote
> might block waiting for us?

Yes, Dave. That is correct.

> 
>> +    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) {
>> +    }
> 
> Hmm.  I suggest the following:
> 
>    a) You create a shared 'size' variable;  and initialize it to
>      UINT64_MAX.
>    b) The thread uses atomic_read(shared_size) to read that value.
>    c) When you receive the size from the remote you do
>       atomic_set(&shared_size, size);
>    d) The thread does:
>       while (received_size < atomic_read(&shared_size))
> 
>       so the thread will quit either on EOF or it hitting the size.
> 
>    e) We pthread_join here to wait for the thread
>    f) We then check a received size to make sure it matches what we
> expect.
> 
> That removes the tight loop.

Sure, will do.

> 
>> +    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;
> 
> I don't think you need that.
> 
>> +}
>> +
>> +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),
> 
> I think instead you should use a VMSTATE_VBUFFER here to save
> the mig_data.
> What we should do is the post_save should g_free the buffer.
> (mig_data should be a field in proxy).

We noticed that VMSTATE_BUFFER requires that the buffer be part of a
"struct" and that the buffer is an array. Since the buffer we're using
is neither an array nor part of a "struct", we decided to go with
writing the buffer directly to the migration stream in proxy_post_save()
instead of using VMSTATE_BUFFER.

I think we should nevertheless g_free this buffer in post_save like you
pointed out.

Thank you!
--
Jag

> 
> Dave
> 
> 
>> +        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 = {
>> diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
>> index 5de8129..537c227 100644
>> --- a/include/hw/proxy/qemu-proxy.h
>> +++ b/include/hw/proxy/qemu-proxy.h
>> @@ -75,6 +75,8 @@ struct PCIProxyDev {
>>                           bool need_spawn, Error **errp);
>>   
>>       ProxyMemoryRegion region[PCI_NUM_REGIONS];
>> +
>> +    uint64_t migsize;
>>   };
>>   
>>   typedef struct PCIProxyDevClass {
>> diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
>> index d2234ca..b42c003 100644
>> --- a/include/io/mpqemu-link.h
>> +++ b/include/io/mpqemu-link.h
>> @@ -63,6 +63,7 @@ typedef enum {
>>       PROXY_PING,
>>       MMIO_RETURN,
>>       DEVICE_RESET,
>> +    START_MIG_OUT,
>>       MAX,
>>   } mpqemu_cmd_t;
>>   
>> -- 
>> 1.8.3.1
>>
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object
  2020-03-05 16:48     ` Jag Raman
@ 2020-03-05 17:04       ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 17:04 UTC (permalink / raw)
  To: Jag Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Jag Raman (jag.raman@oracle.com) wrote:
> 
> 
> On 3/5/2020 7:31 AM, Dr. David Alan Gilbert wrote:
> > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > Collect the VMSD from remote process on the source and save
> > > it to the channel leading to the destination
> > > 
> > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > ---
> > >   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(+)
> > > 
> > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > index b1b9282..19f0dbb 100644
> > > --- a/hw/proxy/qemu-proxy.c
> > > +++ b/hw/proxy/qemu-proxy.c
> > > @@ -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;
> > 
> > This feels way too complicated.   Since we know f_remote is always just
> > a simple fd we're getting we don't need to use qio or qemu_file here;
> > just use the fd - nice and simple.
> > 
> > Then the code to read it can just use read(2) with a sensible size chunk
> > rather than reading a byte at a time.
> 
> Hi Dave,
> 
> Upon closer inspection, we found that the migration code on the remote
> (which uses QEMUFile) could sometimes set an error on the channel using
> qemu_file_set_error(). We needed to use qemu_file_get_error() to catch
> these errors and abort migration. So we had to stick with QEMUFile at
> the receiving end as well.

I realise you need to use a QEMUFile on the part that connects to the
Savevm code/vmstate code - but that doesn't mean you need it on the side
that just connects between your pipe and the qemu.

> > 
> > > +    mig_data->dev = pdev;
> > > +
> > > +    qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data,
> > > +                       QEMU_THREAD_DETACHED);
> > 
> > I'm just checking why a thread is necessary; is this because you need to
> > be able to start reading before you block waiting for the remote to tell
> > you the size - worrying that if you don't start reading then the remote
> > might block waiting for us?
> 
> Yes, Dave. That is correct.
> 
> > 
> > > +    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) {
> > > +    }
> > 
> > Hmm.  I suggest the following:
> > 
> >    a) You create a shared 'size' variable;  and initialize it to
> >      UINT64_MAX.
> >    b) The thread uses atomic_read(shared_size) to read that value.
> >    c) When you receive the size from the remote you do
> >       atomic_set(&shared_size, size);
> >    d) The thread does:
> >       while (received_size < atomic_read(&shared_size))
> > 
> >       so the thread will quit either on EOF or it hitting the size.
> > 
> >    e) We pthread_join here to wait for the thread
> >    f) We then check a received size to make sure it matches what we
> > expect.
> > 
> > That removes the tight loop.
> 
> Sure, will do.
> 
> > 
> > > +    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;
> > 
> > I don't think you need that.
> > 
> > > +}
> > > +
> > > +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),
> > 
> > I think instead you should use a VMSTATE_VBUFFER here to save
> > the mig_data.
> > What we should do is the post_save should g_free the buffer.
> > (mig_data should be a field in proxy).
> 
> We noticed that VMSTATE_BUFFER requires that the buffer be part of a
> "struct" and that the buffer is an array. Since the buffer we're using
> is neither an array nor part of a "struct", we decided to go with
> writing the buffer directly to the migration stream in proxy_post_save()
> instead of using VMSTATE_BUFFER.
> 
> I think we should nevertheless g_free this buffer in post_save like you
> pointed out.

Note I'm suggesting using VMSTATE_VBUFFER, not VMSTATE_BUFFER;
VBUFFER is expecting a unsigned char *; it does expect that to be in
your structure, so I'd expect your proxy to have a mig_data and uint32_t
mig_len fields.

Dave

> Thank you!
> --
> Jag
> 
> > 
> > Dave
> > 
> > 
> > > +        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 = {
> > > diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h
> > > index 5de8129..537c227 100644
> > > --- a/include/hw/proxy/qemu-proxy.h
> > > +++ b/include/hw/proxy/qemu-proxy.h
> > > @@ -75,6 +75,8 @@ struct PCIProxyDev {
> > >                           bool need_spawn, Error **errp);
> > >       ProxyMemoryRegion region[PCI_NUM_REGIONS];
> > > +
> > > +    uint64_t migsize;
> > >   };
> > >   typedef struct PCIProxyDevClass {
> > > diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h
> > > index d2234ca..b42c003 100644
> > > --- a/include/io/mpqemu-link.h
> > > +++ b/include/io/mpqemu-link.h
> > > @@ -63,6 +63,7 @@ typedef enum {
> > >       PROXY_PING,
> > >       MMIO_RETURN,
> > >       DEVICE_RESET,
> > > +    START_MIG_OUT,
> > >       MAX,
> > >   } mpqemu_cmd_t;
> > > -- 
> > > 1.8.3.1
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-05 10:10           ` Dr. David Alan Gilbert
@ 2020-03-05 17:07             ` Elena Ufimtseva
  2020-03-05 17:19               ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-05 17:07 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jag Raman, quintela, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

On Thu, Mar 05, 2020 at 10:10:59AM +0000, Dr. David Alan Gilbert wrote:
> * Jag Raman (jag.raman@oracle.com) wrote:
> > 
> > 
> > On 3/4/2020 2:52 PM, Dr. David Alan Gilbert wrote:
> > > * Jag Raman (jag.raman@oracle.com) wrote:
> > > > 
> > > > 
> > > > On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
> > > > > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > > > > Add Makefile support to enable migration in remote process
> > > > > > 
> > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > ---
> > > > > >    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(-)
> > > > > > 
> > > > > > diff --git a/Makefile.objs b/Makefile.objs
> > > > > > index 4b5db09..65009da 100644
> > > > > > --- a/Makefile.objs
> > > > > > +++ b/Makefile.objs
> > > > > > @@ -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
> > > > > > diff --git a/Makefile.target b/Makefile.target
> > > > > > index 4ead5c3..4012ae5 100644
> > > > > > --- a/Makefile.target
> > > > > > +++ b/Makefile.target
> > > > > > @@ -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 :=
> > > > > > diff --git a/migration/Makefile.objs b/migration/Makefile.objs
> > > > > > index e7cdc76..21f9d8d 100644
> > > > > > --- a/migration/Makefile.objs
> > > > > > +++ b/migration/Makefile.objs
> > > > > > @@ -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
> > > > > 
> > > > > 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.
> > > 
> > > 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...
> 
> 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.
>

Hi Dave

We did initially tried to split some of the vmstate code, and it was a lot of code to add to
already big patchset. So we could do this split later on as a separate series.
Would that be an option or you would rather see it in this set?

Thank you!

Elena 
> Dave
> 
> > Thank you!
> > --
> > Jag
> > 
> > > 
> > > Dave
> > > 
> > > > Thank you!
> > > > --
> > > > Jag
> > > > 
> > > > > 
> > > > > Dave
> > > > > 
> > > > > > diff --git a/net/Makefile.objs b/net/Makefile.objs
> > > > > > index c5d076d..a8ad986 100644
> > > > > > --- a/net/Makefile.objs
> > > > > > +++ b/net/Makefile.objs
> > > > > > @@ -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
> > > > > > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > > > > > index 4a4f52c..42d5682 100644
> > > > > > --- a/softmmu/vl.c
> > > > > > +++ b/softmmu/vl.c
> > > > > > @@ -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;
> > > > > > diff --git a/stubs/migration.c b/stubs/migration.c
> > > > > > index 28ccf80..dbd12db 100644
> > > > > > --- a/stubs/migration.c
> > > > > > +++ b/stubs/migration.c
> > > > > > @@ -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);
> > > > > > +}
> > > > > > diff --git a/stubs/net-stub.c b/stubs/net-stub.c
> > > > > > index 962827e..ddfd1e4 100644
> > > > > > --- a/stubs/net-stub.c
> > > > > > +++ b/stubs/net-stub.c
> > > > > > @@ -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);
> > > > > > +}
> > > > > > diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
> > > > > > index 3eeedd9..824eac1 100644
> > > > > > --- a/stubs/qapi-misc.c
> > > > > > +++ b/stubs/qapi-misc.c
> > > > > > @@ -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,
> > > > > > diff --git a/stubs/replay.c b/stubs/replay.c
> > > > > > index 9b53c0c..6fc7850 100644
> > > > > > --- a/stubs/replay.c
> > > > > > +++ b/stubs/replay.c
> > > > > > @@ -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;
> > > > > > +}
> > > > > > diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
> > > > > > index 606f078..5f308c1 100644
> > > > > > --- a/stubs/vl-stub.c
> > > > > > +++ b/stubs/vl-stub.c
> > > > > > @@ -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);
> > > > > > +}
> > > > > > diff --git a/vl-parse.c b/vl-parse.c
> > > > > > index 1f6a3f0..423f4a0 100644
> > > > > > --- a/vl-parse.c
> > > > > > +++ b/vl-parse.c
> > > > > > @@ -27,6 +27,9 @@
> > > > > >    #include "vl.h"
> > > > > > +int only_migratable; /* turn it off unless user states otherwise */
> > > > > > +bool enable_mlock;
> > > > > > +
> > > > > >    /***********************************************************/
> > > > > >    /* QEMU Block devices */
> > > > > > -- 
> > > > > > 1.8.3.1
> > > > > > 
> > > > > --
> > > > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > > > > 
> > > > 
> > > --
> > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > > 
> > 
> --
> Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> 


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process
  2020-03-05 17:07             ` Elena Ufimtseva
@ 2020-03-05 17:19               ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 117+ messages in thread
From: Dr. David Alan Gilbert @ 2020-03-05 17:19 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jag Raman, quintela, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, liran.alon, stefanha, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

* Elena Ufimtseva (elena.ufimtseva@oracle.com) wrote:
> On Thu, Mar 05, 2020 at 10:10:59AM +0000, Dr. David Alan Gilbert wrote:
> > * Jag Raman (jag.raman@oracle.com) wrote:
> > > 
> > > 
> > > On 3/4/2020 2:52 PM, Dr. David Alan Gilbert wrote:
> > > > * Jag Raman (jag.raman@oracle.com) wrote:
> > > > > 
> > > > > 
> > > > > On 3/4/2020 10:58 AM, Dr. David Alan Gilbert wrote:
> > > > > > * Jagannathan Raman (jag.raman@oracle.com) wrote:
> > > > > > > Add Makefile support to enable migration in remote process
> > > > > > > 
> > > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > > ---
> > > > > > >    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(-)
> > > > > > > 
> > > > > > > diff --git a/Makefile.objs b/Makefile.objs
> > > > > > > index 4b5db09..65009da 100644
> > > > > > > --- a/Makefile.objs
> > > > > > > +++ b/Makefile.objs
> > > > > > > @@ -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
> > > > > > > diff --git a/Makefile.target b/Makefile.target
> > > > > > > index 4ead5c3..4012ae5 100644
> > > > > > > --- a/Makefile.target
> > > > > > > +++ b/Makefile.target
> > > > > > > @@ -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 :=
> > > > > > > diff --git a/migration/Makefile.objs b/migration/Makefile.objs
> > > > > > > index e7cdc76..21f9d8d 100644
> > > > > > > --- a/migration/Makefile.objs
> > > > > > > +++ b/migration/Makefile.objs
> > > > > > > @@ -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
> > > > > > 
> > > > > > 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.
> > > > 
> > > > 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...
> > 
> > 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.
> >
> 
> Hi Dave
> 
> We did initially tried to split some of the vmstate code, and it was a lot of code to add to
> already big patchset. So we could do this split later on as a separate series.
> Would that be an option or you would rather see it in this set?

I'd say see if there are any easy things you can split; if there are
then lets take those as part of this series.

Dave

> Thank you!
> 
> Elena 
> > Dave
> > 
> > > Thank you!
> > > --
> > > Jag
> > > 
> > > > 
> > > > Dave
> > > > 
> > > > > Thank you!
> > > > > --
> > > > > Jag
> > > > > 
> > > > > > 
> > > > > > Dave
> > > > > > 
> > > > > > > diff --git a/net/Makefile.objs b/net/Makefile.objs
> > > > > > > index c5d076d..a8ad986 100644
> > > > > > > --- a/net/Makefile.objs
> > > > > > > +++ b/net/Makefile.objs
> > > > > > > @@ -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
> > > > > > > diff --git a/softmmu/vl.c b/softmmu/vl.c
> > > > > > > index 4a4f52c..42d5682 100644
> > > > > > > --- a/softmmu/vl.c
> > > > > > > +++ b/softmmu/vl.c
> > > > > > > @@ -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;
> > > > > > > diff --git a/stubs/migration.c b/stubs/migration.c
> > > > > > > index 28ccf80..dbd12db 100644
> > > > > > > --- a/stubs/migration.c
> > > > > > > +++ b/stubs/migration.c
> > > > > > > @@ -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);
> > > > > > > +}
> > > > > > > diff --git a/stubs/net-stub.c b/stubs/net-stub.c
> > > > > > > index 962827e..ddfd1e4 100644
> > > > > > > --- a/stubs/net-stub.c
> > > > > > > +++ b/stubs/net-stub.c
> > > > > > > @@ -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);
> > > > > > > +}
> > > > > > > diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c
> > > > > > > index 3eeedd9..824eac1 100644
> > > > > > > --- a/stubs/qapi-misc.c
> > > > > > > +++ b/stubs/qapi-misc.c
> > > > > > > @@ -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,
> > > > > > > diff --git a/stubs/replay.c b/stubs/replay.c
> > > > > > > index 9b53c0c..6fc7850 100644
> > > > > > > --- a/stubs/replay.c
> > > > > > > +++ b/stubs/replay.c
> > > > > > > @@ -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;
> > > > > > > +}
> > > > > > > diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c
> > > > > > > index 606f078..5f308c1 100644
> > > > > > > --- a/stubs/vl-stub.c
> > > > > > > +++ b/stubs/vl-stub.c
> > > > > > > @@ -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);
> > > > > > > +}
> > > > > > > diff --git a/vl-parse.c b/vl-parse.c
> > > > > > > index 1f6a3f0..423f4a0 100644
> > > > > > > --- a/vl-parse.c
> > > > > > > +++ b/vl-parse.c
> > > > > > > @@ -27,6 +27,9 @@
> > > > > > >    #include "vl.h"
> > > > > > > +int only_migratable; /* turn it off unless user states otherwise */
> > > > > > > +bool enable_mlock;
> > > > > > > +
> > > > > > >    /***********************************************************/
> > > > > > >    /* QEMU Block devices */
> > > > > > > -- 
> > > > > > > 1.8.3.1
> > > > > > > 
> > > > > > --
> > > > > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > > > > > 
> > > > > 
> > > > --
> > > > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > > > 
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 14/50] mutli-process: build remote command line args
  2020-03-05  8:21                 ` Daniel P. Berrangé
@ 2020-03-06 16:25                   ` Stefan Hajnoczi
  0 siblings, 0 replies; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-03-06 16:25 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: Elena Ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, Jagannathan Raman, quintela, mst, armbru, kanth.ghatraju,
	felipe, Philippe Mathieu-Daudé,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon, pbonzini,
	rth, kwolf, mreitz, ross.lagerwall, marcandre.lureau,
	thanos.makatos

[-- Attachment #1: Type: text/plain, Size: 9252 bytes --]

On Thu, Mar 05, 2020 at 08:21:14AM +0000, Daniel P. Berrangé wrote:
> On Wed, Mar 04, 2020 at 02:37:43PM -0800, Elena Ufimtseva wrote:
> > On Wed, Mar 04, 2020 at 04:33:57PM +0000, Daniel P. Berrangé wrote:
> > > On Wed, Mar 04, 2020 at 08:25:34AM -0800, Elena Ufimtseva wrote:
> > > > On Wed, Mar 04, 2020 at 11:00:32AM +0000, Daniel P. Berrangé wrote:
> > > > > On Mon, Mar 02, 2020 at 02:39:37PM -0800, Elena Ufimtseva wrote:
> > > > > > On Mon, Mar 02, 2020 at 05:47:45PM +0000, Daniel P. Berrangé wrote:
> > > > > > > On Mon, Mar 02, 2020 at 06:36:13PM +0100, Philippe Mathieu-Daudé wrote:
> > > > > > > > typo "multi" in patch subject.
> > > > > > > >
> > > > > > Thank Philippe, will fix.
> > > > > >  
> > > > > > > > On 2/24/20 9:55 PM, Jagannathan Raman wrote:
> > > > > > > > > From: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > > > 
> > > > > > > > > Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> > > > > > > > > Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> > > > > > > > > Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> > > > > > > > > ---
> > > > > > > > >   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(-)
> > > > > > > > > 
> > > > > > > > > diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c
> > > > > > > > > index 828bbd7..d792e86 100644
> > > > > > > > > --- a/hw/proxy/qemu-proxy.c
> > > > > > > > > +++ b/hw/proxy/qemu-proxy.c
> > > > > > > > > @@ -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;
> > > > > > > > 
> > > > > > > > Is there a GLib function to do that?
> > > > > > >
> > > > > > 
> > > > > > Hi Daniel
> > > > > > 
> > > > > > > g_shell_parse_argv() perhaps
> > > > > > >
> > > > > > 
> > > > > > Thanks for the suggestion.
> > > > > > 
> > > > > > >   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.
> > > > >
> > > > 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.
> > > 
> > > 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.
> > 
> > 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?
> 
> 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.

Not all of the remote program's command-line options may be known to
QEMU, so passing through just a few options like -drive does not fix the
problem.

I suggest just providing the arguments as a single string parameter like
this patch series already does, but make sure to consider the escaping
rules for commas and other special characters.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 50/50] multi-process: add configure and usage information
  2020-02-28 18:43     ` Elena Ufimtseva
@ 2020-03-06 16:42       ` Stefan Hajnoczi
  0 siblings, 0 replies; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-03-06 16:42 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

[-- Attachment #1: Type: text/plain, Size: 3594 bytes --]

On Fri, Feb 28, 2020 at 10:43:44AM -0800, Elena Ufimtseva wrote:
> On Thu, Feb 27, 2020 at 04:58:04PM +0000, Stefan Hajnoczi wrote:
> > On Mon, Feb 24, 2020 at 03:55:41PM -0500, Jagannathan Raman wrote:
> > > +* 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
> > 
> > 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?
> > 
> 
> 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?

Yes, that sounds good.

> > > +  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?
> 
> 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?

I'm not aware of a way to avoid the comma escaping.  The space escaping
is a question of how the remote process is spawned.  If the command-line
is processed by a shell like with system(3) then backslash can be used
to escape spaces.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel
  2020-02-24 20:55 ` [PATCH v5 32/50] multi-process: Use separate MMIO communication channel Jagannathan Raman
@ 2020-03-06 16:52   ` Stefan Hajnoczi
  2020-03-10 18:04     ` Jag Raman
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-03-06 16:52 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 2036 bytes --]

This went unanswered in the last revision:

On Thu, Nov 21, 2019 at 12:31:42PM +0000, Stefan Hajnoczi wrote:
> On Wed, Nov 13, 2019 at 11:14:50AM -0500, Jag Raman wrote:
> > On 11/11/2019 11:21 AM, Stefan Hajnoczi wrote:
> > > On Thu, Oct 24, 2019 at 05:09:13AM -0400, Jagannathan Raman wrote:
> > > > Using a separate communication channel for MMIO helps
> > > > with improving Performance
> > > 
> > > Why?
> > 
> > Typical initiation of IO operations involves multiple MMIO accesses per
> > IO operation. In some legacy devices like LSI, the completion of the IO
> > operations is also accomplished by polling on MMIO registers. Therefore,
> > MMIO traffic can be hefty in some cases and contribute to Performance.
> > 
> > Having a dedicated channel for MMIO ensures that it doesn't have to
> > compete with other messages to the remote process, especially when there
> > are multiple devices emulated by a single remote process.
> 
> A vCPU doing a polling read on an MMIO register will cause a BAR_READ
> message to be sent to the remote process.  The vCPU thread waits for the
> response to this message.
> 
> When there are multiple remote devices each has its own socket, so
> communication with different remote processes does not interfere.
> 
> The only scenarios I can think of are:
> 1. Interference within a single device between vCPUs and/or the QEMU
>    monitor.
> 2. A single process serving multiple devices that is implemented in a
>    way such that different devices interfere with each other.
> 
> It sounds like you are saying the problem is #2, but this is still
> unclear to me.  If the remote process can be implemented in a way such
> that there is no interference when each device has a special MMIO
> socket, then why can't it be implemented in a way such that there is no
> interference when each device's main socket is used (each device has
> it's own!).
> 
> Maybe I've missed the point.  It would be good if you could explain in
> more detail.
> 
> Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 07/50] multi-process: define mpqemu-link object
  2020-02-24 20:54 ` [PATCH v5 07/50] multi-process: define mpqemu-link object Jagannathan Raman
@ 2020-03-10 16:09   ` Stefan Hajnoczi
  2020-03-10 18:26     ` Elena Ufimtseva
  0 siblings, 1 reply; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-03-10 16:09 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini

[-- Attachment #1: Type: text/plain, Size: 3685 bytes --]

On Mon, Feb 24, 2020 at 03:54:58PM -0500, Jagannathan Raman wrote:
> +/*
> + * TODO: Dont use mpqemu link object since it is
> + * not needed to be created via -object.
> + */

Please investigate and resolve this TODO.

> +struct conf_data_msg {
> +    uint32_t addr;
> +    uint32_t val;
> +    int l;

Please use a self-explanatory field name.  I'm not sure what 'l' is.

conf_data_msg is not used in this patch.  Please introduce things when
they are needed to make the patch series easier to review in a linear
fashion.

> +/*
> + * TODO: make all communications asynchronous and run in the main
> + * loop or existing IOThread.
> + */

Please investigate and decide how to resolve this TODO.

> +void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
> +{
> +    int rc;
> +    uint8_t *data;
> +    union {
> +        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
> +        struct cmsghdr align;
> +    } u;
> +    struct msghdr hdr;
> +    struct cmsghdr *chdr;
> +    int sock = chan->sock;
> +    QemuMutex *lock = &chan->send_lock;
> +
> +    struct iovec iov = {
> +        .iov_base = (char *) msg,
> +        .iov_len = MPQEMU_MSG_HDR_SIZE,
> +    };
> +
> +    memset(&hdr, 0, sizeof(hdr));
> +    memset(&u, 0, sizeof(u));
> +
> +    hdr.msg_iov = &iov;
> +    hdr.msg_iovlen = 1;
> +
> +    if (msg->num_fds > REMOTE_MAX_FDS) {
> +        qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
> +        return;
> +    }
> +
> +    if (msg->num_fds > 0) {
> +        size_t fdsize = msg->num_fds * sizeof(int);
> +
> +        hdr.msg_control = &u;
> +        hdr.msg_controllen = sizeof(u);
> +
> +        chdr = CMSG_FIRSTHDR(&hdr);
> +        chdr->cmsg_len = CMSG_LEN(fdsize);
> +        chdr->cmsg_level = SOL_SOCKET;
> +        chdr->cmsg_type = SCM_RIGHTS;
> +        memcpy(CMSG_DATA(chdr), msg->fds, fdsize);
> +        hdr.msg_controllen = CMSG_SPACE(fdsize);
> +    }
> +
> +    qemu_mutex_lock(lock);
> +
> +    do {
> +        rc = sendmsg(sock, &hdr, 0);
> +    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> +
> +    if (rc < 0) {
> +        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d,"
> +                      " sock %d\n", __func__, rc, errno, sock);
> +        qemu_mutex_unlock(lock);
> +        return;
> +    }
> +
> +    if (msg->bytestream) {
> +        data = msg->data2;
> +    } else {
> +        data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE;
> +    }
> +
> +    do {
> +        rc = write(sock, data, msg->size);
> +    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> +
> +    qemu_mutex_unlock(lock);

Can this lock be avoided by using a single sendmsg(2) syscall instead of
sendmsg() + write()?  I feel deja vu here, like I maybe have raised this
in a previous revision of this patch series.

> +    msg->num_fds = 0;
> +    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
> +         chdr = CMSG_NXTHDR(&hdr, chdr)) {
> +        if ((chdr->cmsg_level == SOL_SOCKET) &&
> +            (chdr->cmsg_type == SCM_RIGHTS)) {
> +            fdsize = chdr->cmsg_len - CMSG_LEN(0);
> +            msg->num_fds = fdsize / sizeof(int);
> +            if (msg->num_fds > REMOTE_MAX_FDS) {
> +                /*
> +                 * TODO: Security issue detected. Sender never sends more
> +                 * than REMOTE_MAX_FDS. This condition should be signaled to
> +                 * the admin
> +                 */

This TODO doesn't seem actionable.  The error is already handled.

> +                qemu_log_mask(LOG_REMOTE_DEBUG,
> +                              "%s: Max FDs exceeded\n", __func__);
> +                return -ERANGE;

The mutex must be released.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel
  2020-03-06 16:52   ` Stefan Hajnoczi
@ 2020-03-10 18:04     ` Jag Raman
  0 siblings, 0 replies; 117+ messages in thread
From: Jag Raman @ 2020-03-10 18:04 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: elena.ufimtseva, fam, swapnil.ingle, john.g.johnson, qemu-devel,
	kraxel, quintela, mst, armbru, kanth.ghatraju, felipe, thuth,
	ehabkost, konrad.wilk, dgilbert, liran.alon, thanos.makatos, rth,
	kwolf, berrange, mreitz, ross.lagerwall, marcandre.lureau,
	pbonzini



On 3/6/2020 11:52 AM, Stefan Hajnoczi wrote:
> This went unanswered in the last revision:
> 
> On Thu, Nov 21, 2019 at 12:31:42PM +0000, Stefan Hajnoczi wrote:
>> On Wed, Nov 13, 2019 at 11:14:50AM -0500, Jag Raman wrote:
>>> On 11/11/2019 11:21 AM, Stefan Hajnoczi wrote:
>>>> On Thu, Oct 24, 2019 at 05:09:13AM -0400, Jagannathan Raman wrote:
>>>>> Using a separate communication channel for MMIO helps
>>>>> with improving Performance
>>>>
>>>> Why?
>>>
>>> Typical initiation of IO operations involves multiple MMIO accesses per
>>> IO operation. In some legacy devices like LSI, the completion of the IO
>>> operations is also accomplished by polling on MMIO registers. Therefore,
>>> MMIO traffic can be hefty in some cases and contribute to Performance.
>>>
>>> Having a dedicated channel for MMIO ensures that it doesn't have to
>>> compete with other messages to the remote process, especially when there
>>> are multiple devices emulated by a single remote process.
>>
>> A vCPU doing a polling read on an MMIO register will cause a BAR_READ
>> message to be sent to the remote process.  The vCPU thread waits for the
>> response to this message.
>>
>> When there are multiple remote devices each has its own socket, so
>> communication with different remote processes does not interfere.
>>
>> The only scenarios I can think of are:
>> 1. Interference within a single device between vCPUs and/or the QEMU
>>     monitor.
>> 2. A single process serving multiple devices that is implemented in a
>>     way such that different devices interfere with each other.
>>
>> It sounds like you are saying the problem is #2, but this is still
>> unclear to me.  If the remote process can be implemented in a way such
>> that there is no interference when each device has a special MMIO
>> socket, then why can't it be implemented in a way such that there is no
>> interference when each device's main socket is used (each device has
>> it's own!).
>>
>> Maybe I've missed the point.  It would be good if you could explain in
>> more detail.

Hi Stefan,

Sorry we missed this comment. We originally added this to enable
separate MMIO channels for each device in the remote process.

Given we are going to add a separate channel for each device in the
remote process based on the recent discussions, we could remove the
separate channel for MMIO.

Thank you very much!
--
Jag

>>
>> Stefan


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 07/50] multi-process: define mpqemu-link object
  2020-03-10 16:09   ` Stefan Hajnoczi
@ 2020-03-10 18:26     ` Elena Ufimtseva
  2020-03-16 11:26       ` Stefan Hajnoczi
  0 siblings, 1 reply; 117+ messages in thread
From: Elena Ufimtseva @ 2020-03-10 18:26 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	thanos.makatos, rth, kwolf, berrange, mreitz, ross.lagerwall,
	marcandre.lureau, pbonzini

On Tue, Mar 10, 2020 at 04:09:41PM +0000, Stefan Hajnoczi wrote:
> On Mon, Feb 24, 2020 at 03:54:58PM -0500, Jagannathan Raman wrote:
> > +/*
> > + * TODO: Dont use mpqemu link object since it is
> > + * not needed to be created via -object.
> > + */
> 
> Please investigate and resolve this TODO.
>
Thank you Stefan for reviewing more patches.
This particular TODO have to be removed and I am guessing
followed us from the earlier code.
 
> > +struct conf_data_msg {
> > +    uint32_t addr;
> > +    uint32_t val;
> > +    int l;
> 
> Please use a self-explanatory field name.  I'm not sure what 'l' is.
> 
> conf_data_msg is not used in this patch.  Please introduce things when
> they are needed to make the patch series easier to review in a linear
> fashion.

Will do.
> 
> > +/*
> > + * TODO: make all communications asynchronous and run in the main
> > + * loop or existing IOThread.
> > + */
> 
> Please investigate and decide how to resolve this TODO.
> 
> > +void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan)
> > +{
> > +    int rc;
> > +    uint8_t *data;
> > +    union {
> > +        char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))];
> > +        struct cmsghdr align;
> > +    } u;
> > +    struct msghdr hdr;
> > +    struct cmsghdr *chdr;
> > +    int sock = chan->sock;
> > +    QemuMutex *lock = &chan->send_lock;
> > +
> > +    struct iovec iov = {
> > +        .iov_base = (char *) msg,
> > +        .iov_len = MPQEMU_MSG_HDR_SIZE,
> > +    };
> > +
> > +    memset(&hdr, 0, sizeof(hdr));
> > +    memset(&u, 0, sizeof(u));
> > +
> > +    hdr.msg_iov = &iov;
> > +    hdr.msg_iovlen = 1;
> > +
> > +    if (msg->num_fds > REMOTE_MAX_FDS) {
> > +        qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
> > +        return;
> > +    }
> > +
> > +    if (msg->num_fds > 0) {
> > +        size_t fdsize = msg->num_fds * sizeof(int);
> > +
> > +        hdr.msg_control = &u;
> > +        hdr.msg_controllen = sizeof(u);
> > +
> > +        chdr = CMSG_FIRSTHDR(&hdr);
> > +        chdr->cmsg_len = CMSG_LEN(fdsize);
> > +        chdr->cmsg_level = SOL_SOCKET;
> > +        chdr->cmsg_type = SCM_RIGHTS;
> > +        memcpy(CMSG_DATA(chdr), msg->fds, fdsize);
> > +        hdr.msg_controllen = CMSG_SPACE(fdsize);
> > +    }
> > +
> > +    qemu_mutex_lock(lock);
> > +
> > +    do {
> > +        rc = sendmsg(sock, &hdr, 0);
> > +    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> > +
> > +    if (rc < 0) {
> > +        qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d,"
> > +                      " sock %d\n", __func__, rc, errno, sock);
> > +        qemu_mutex_unlock(lock);
> > +        return;
> > +    }
> > +
> > +    if (msg->bytestream) {
> > +        data = msg->data2;
> > +    } else {
> > +        data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE;
> > +    }
> > +
> > +    do {
> > +        rc = write(sock, data, msg->size);
> > +    } while (rc < 0 && (errno == EINTR || errno == EAGAIN));
> > +
> > +    qemu_mutex_unlock(lock);
> 
> Can this lock be avoided by using a single sendmsg(2) syscall instead of
> sendmsg() + write()?  I feel deja vu here, like I maybe have raised this
> in a previous revision of this patch series.
> 

Indeed, you did mention this. Sorry, it got forgotten.
It seems to be possible, we will investigate further and include in the
next version.

> > +    msg->num_fds = 0;
> > +    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
> > +         chdr = CMSG_NXTHDR(&hdr, chdr)) {
> > +        if ((chdr->cmsg_level == SOL_SOCKET) &&
> > +            (chdr->cmsg_type == SCM_RIGHTS)) {
> > +            fdsize = chdr->cmsg_len - CMSG_LEN(0);
> > +            msg->num_fds = fdsize / sizeof(int);
> > +            if (msg->num_fds > REMOTE_MAX_FDS) {
> > +                /*
> > +                 * TODO: Security issue detected. Sender never sends more
> > +                 * than REMOTE_MAX_FDS. This condition should be signaled to
> > +                 * the admin
> > +                 */
> 
> This TODO doesn't seem actionable.  The error is already handled.
> 
> > +                qemu_log_mask(LOG_REMOTE_DEBUG,
> > +                              "%s: Max FDs exceeded\n", __func__);
> > +                return -ERANGE;
> 
> The mutex must be released.

Thank you! Will fix this and above.


Elena


^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 07/50] multi-process: define mpqemu-link object
  2020-03-10 18:26     ` Elena Ufimtseva
@ 2020-03-16 11:26       ` Stefan Hajnoczi
  0 siblings, 0 replies; 117+ messages in thread
From: Stefan Hajnoczi @ 2020-03-16 11:26 UTC (permalink / raw)
  To: Elena Ufimtseva
  Cc: fam, john.g.johnson, swapnil.ingle, mst, qemu-devel, kraxel,
	Jagannathan Raman, quintela, armbru, kanth.ghatraju, felipe,
	thuth, ehabkost, konrad.wilk, dgilbert, liran.alon,
	Stefan Hajnoczi, pbonzini, rth, kwolf, berrange, mreitz,
	ross.lagerwall, marcandre.lureau, thanos.makatos

[-- Attachment #1: Type: text/plain, Size: 1554 bytes --]

On Tue, Mar 10, 2020 at 11:26:23AM -0700, Elena Ufimtseva wrote:
> On Tue, Mar 10, 2020 at 04:09:41PM +0000, Stefan Hajnoczi wrote:
> > On Mon, Feb 24, 2020 at 03:54:58PM -0500, Jagannathan Raman wrote:
> > > +    msg->num_fds = 0;
> > > +    for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL;
> > > +         chdr = CMSG_NXTHDR(&hdr, chdr)) {
> > > +        if ((chdr->cmsg_level == SOL_SOCKET) &&
> > > +            (chdr->cmsg_type == SCM_RIGHTS)) {
> > > +            fdsize = chdr->cmsg_len - CMSG_LEN(0);
> > > +            msg->num_fds = fdsize / sizeof(int);
> > > +            if (msg->num_fds > REMOTE_MAX_FDS) {
> > > +                /*
> > > +                 * TODO: Security issue detected. Sender never sends more
> > > +                 * than REMOTE_MAX_FDS. This condition should be signaled to
> > > +                 * the admin
> > > +                 */
> > 
> > This TODO doesn't seem actionable.  The error is already handled.
> > 
> > > +                qemu_log_mask(LOG_REMOTE_DEBUG,
> > > +                              "%s: Max FDs exceeded\n", __func__);
> > > +                return -ERANGE;
> > 
> > The mutex must be released.
> 
> Thank you! Will fix this and above.

I have posted a patch series that adds lock guards (automatic unlocking)
to prevent cases like this in the future:
https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg04628.html

You can use the QEMU_LOCK_GUARD() and/or WITH_QEMU_LOCK_GUARD() macros
to avoid the need for manual qemu_mutex_unlock() calls.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 117+ messages in thread

* Re: [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers
  2020-02-24 20:54 ` [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers Jagannathan Raman
@ 2020-03-29 16:45   ` Marc-André Lureau
  0 siblings, 0 replies; 117+ messages in thread
From: Marc-André Lureau @ 2020-03-29 16:45 UTC (permalink / raw)
  To: Jagannathan Raman
  Cc: Elena Ufimtseva, Fam Zheng, Swapnil Ingle, john.g.johnson, QEMU,
	Gerd Hoffmann, Juan Quintela, Michael S. Tsirkin,
	Markus Armbruster, kanth.ghatraju, Felipe Franciosi, Thomas Huth,
	Eduardo Habkost, Konrad Rzeszutek Wilk, Dr. David Alan Gilbert,
	liran.alon, Stefan Hajnoczi, Thanos Makatos, Richard Henderson,
	Kevin Wolf, Daniel P. Berrange, Max Reitz, Ross Lagerwall,
	Paolo Bonzini

Hi

On Mon, Feb 24, 2020 at 9:56 PM Jagannathan Raman <jag.raman@oracle.com> wrote:
>
> Relocate machine_int and exit notifiers into common code

utils/notify.c is not a good place to relocate those.

eventually, add a new softmmu/notifiers.c ?

And that patch broke make check test-char /char/mux, because it
overrides machine_init_done from stubs/machine-init-done.c..

>
> Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
> Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
> Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
> ---
>  include/sysemu/sysemu.h |  2 ++
>  softmmu/vl.c            | 42 ------------------------------------------
>  util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 45 insertions(+), 42 deletions(-)
>
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index dec64fc..2f37e2b 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -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;
>
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 92c7b3a..94a7b93 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -173,12 +173,6 @@ int icount_align_option;
>  QemuUUID qemu_uuid;
>  bool qemu_uuid_set;
>
> -static NotifierList exit_notifiers =
> -    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
> -
> -static NotifierList machine_init_done_notifiers =
> -    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
> -
>  bool xen_allowed;
>  uint32_t xen_domid;
>  enum xen_mode xen_mode = XEN_EMULATE;
> @@ -2324,21 +2318,6 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
>      return mc;
>  }
>
> -void qemu_add_exit_notifier(Notifier *notify)
> -{
> -    notifier_list_add(&exit_notifiers, notify);
> -}
> -
> -void qemu_remove_exit_notifier(Notifier *notify)
> -{
> -    notifier_remove(notify);
> -}
> -
> -static void qemu_run_exit_notifiers(void)
> -{
> -    notifier_list_notify(&exit_notifiers, NULL);
> -}
> -
>  static const char *pid_file;
>  static Notifier qemu_unlink_pidfile_notifier;
>
> @@ -2349,27 +2328,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data)
>      }
>  }
>
> -bool machine_init_done;
> -
> -void qemu_add_machine_init_done_notifier(Notifier *notify)
> -{
> -    notifier_list_add(&machine_init_done_notifiers, notify);
> -    if (machine_init_done) {
> -        notify->notify(notify, NULL);
> -    }
> -}
> -
> -void qemu_remove_machine_init_done_notifier(Notifier *notify)
> -{
> -    notifier_remove(notify);
> -}
> -
> -static void qemu_run_machine_init_done_notifiers(void)
> -{
> -    machine_init_done = true;
> -    notifier_list_notify(&machine_init_done_notifiers, NULL);
> -}
> -
>  static const QEMUOption *lookup_opt(int argc, char **argv,
>                                      const char **poptarg, int *poptind)
>  {
> diff --git a/util/notify.c b/util/notify.c
> index 76bab21..0e7479b 100644
> --- a/util/notify.c
> +++ b/util/notify.c
> @@ -15,6 +15,15 @@
>
>  #include "qemu/osdep.h"
>  #include "qemu/notify.h"
> +#include "sysemu/sysemu.h"
> +
> +bool machine_init_done;
> +
> +static NotifierList machine_init_done_notifiers =
> +    NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
> +
> +static NotifierList exit_notifiers =
> +    NOTIFIER_LIST_INITIALIZER(exit_notifiers);
>
>  void notifier_list_init(NotifierList *list)
>  {
> @@ -74,3 +83,37 @@ int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data)
>      }
>      return ret;
>  }
> +
> +void qemu_add_machine_init_done_notifier(Notifier *notify)
> +{
> +    notifier_list_add(&machine_init_done_notifiers, notify);
> +    if (machine_init_done) {
> +        notify->notify(notify, NULL);
> +    }
> +}
> +
> +void qemu_remove_machine_init_done_notifier(Notifier *notify)
> +{
> +    notifier_remove(notify);
> +}
> +
> +void qemu_run_machine_init_done_notifiers(void)
> +{
> +    machine_init_done = true;
> +    notifier_list_notify(&machine_init_done_notifiers, NULL);
> +}
> +
> +void qemu_add_exit_notifier(Notifier *notify)
> +{
> +    notifier_list_add(&exit_notifiers, notify);
> +}
> +
> +void qemu_remove_exit_notifier(Notifier *notify)
> +{
> +    notifier_remove(notify);
> +}
> +
> +void qemu_run_exit_notifiers(void)
> +{
> +    notifier_list_notify(&exit_notifiers, NULL);
> +}
> --
> 1.8.3.1
>


-- 
Marc-André Lureau


^ permalink raw reply	[flat|nested] 117+ messages in thread

end of thread, other threads:[~2020-03-29 16:47 UTC | newest]

Thread overview: 117+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 20:54 [PATCH v5 00/50] Initial support for multi-process qemu Jagannathan Raman
2020-02-24 20:54 ` [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Jagannathan Raman
2020-03-03 19:51   ` Dr. David Alan Gilbert
2020-03-04 18:24     ` Jag Raman
2020-02-24 20:54 ` [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers Jagannathan Raman
2020-03-29 16:45   ` Marc-André Lureau
2020-02-24 20:54 ` [PATCH v5 03/50] multi-process: add a command line option for debug file Jagannathan Raman
2020-02-24 20:54 ` [PATCH v5 04/50] multi-process: Add stub functions to facilate build of multi-process Jagannathan Raman
2020-02-24 20:54 ` [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU Jagannathan Raman
2020-02-24 20:54 ` [PATCH v5 06/50] multi-process: build system for remote device process Jagannathan Raman
2020-02-24 20:54 ` [PATCH v5 07/50] multi-process: define mpqemu-link object Jagannathan Raman
2020-03-10 16:09   ` Stefan Hajnoczi
2020-03-10 18:26     ` Elena Ufimtseva
2020-03-16 11:26       ` Stefan Hajnoczi
2020-02-24 20:54 ` [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints Jagannathan Raman
2020-03-03 19:56   ` Dr. David Alan Gilbert
2020-03-04 18:42     ` Jag Raman
2020-03-04 19:46       ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 10/50] multi-process: setup a machine object for remote device process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 11/50] multi-process: setup memory manager for remote device Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 12/50] multi-process: remote process initialization Jagannathan Raman
2020-03-04 10:29   ` Dr. David Alan Gilbert
2020-03-04 18:45     ` Jag Raman
2020-03-04 19:00       ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 13/50] multi-process: introduce proxy object Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 14/50] mutli-process: build remote command line args Jagannathan Raman
2020-03-02 17:36   ` Philippe Mathieu-Daudé
2020-03-02 17:47     ` Daniel P. Berrangé
2020-03-02 22:39       ` Elena Ufimtseva
2020-03-04 11:00         ` Daniel P. Berrangé
2020-03-04 16:25           ` Elena Ufimtseva
2020-03-04 16:33             ` Daniel P. Berrangé
2020-03-04 22:37               ` Elena Ufimtseva
2020-03-05  8:21                 ` Daniel P. Berrangé
2020-03-06 16:25                   ` Stefan Hajnoczi
2020-03-04 10:09   ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints Jagannathan Raman
2020-03-04 10:47   ` Dr. David Alan Gilbert
2020-03-04 19:05     ` Jag Raman
2020-02-24 20:55 ` [PATCH v5 16/50] multi-process: Synchronize remote memory Jagannathan Raman
2020-03-04 11:53   ` Dr. David Alan Gilbert
2020-03-04 19:35     ` Jag Raman
2020-02-24 20:55 ` [PATCH v5 17/50] multi-process: create IOHUB object to handle irq Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 18/50] multi-process: configure remote side devices Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 22/50] multi-process: remote: use fd for socket from parent process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 23/50] multi-process: remote: add create_done condition Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 24/50] multi-process: add processing of remote device command line Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 26/50] multi-process: refractor vl.c code Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 27/50] multi-process: add remote option Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 28/50] multi-process: add remote options parser Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 29/50] multi-process: add parse_cmdline in remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 30/50] multi-process: send heartbeat messages to remote Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 31/50] multi-process: handle heartbeat messages in remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 32/50] multi-process: Use separate MMIO communication channel Jagannathan Raman
2020-03-06 16:52   ` Stefan Hajnoczi
2020-03-10 18:04     ` Jag Raman
2020-02-24 20:55 ` [PATCH v5 33/50] multi-process: perform device reset in the remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target Jagannathan Raman
2020-03-05 10:39   ` Dr. David Alan Gilbert
2020-03-05 15:38     ` Jag Raman
2020-03-05 15:50       ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 35/50] multi-process/mon: stub functions to enable QMP module for remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 36/50] multi-process/mon: enable QMP module support in the " Jagannathan Raman
2020-03-05 10:43   ` Dr. David Alan Gilbert
2020-03-05 15:40     ` Jag Raman
2020-03-05 15:52       ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c Jagannathan Raman
2020-03-05 10:51   ` Dr. David Alan Gilbert
2020-03-05 15:41     ` Jag Raman
2020-02-24 20:55 ` [PATCH v5 38/50] multi-process/mon: Initialize QMP module for remote processes Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 39/50] multi-process: prevent duplicate memory initialization in remote Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 40/50] multi-process/mig: build migration module in the remote process Jagannathan Raman
2020-03-04 15:58   ` Dr. David Alan Gilbert
2020-03-04 19:45     ` Jag Raman
2020-03-04 19:52       ` Dr. David Alan Gilbert
2020-03-04 20:23         ` Jag Raman
2020-03-05 10:10           ` Dr. David Alan Gilbert
2020-03-05 17:07             ` Elena Ufimtseva
2020-03-05 17:19               ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object Jagannathan Raman
2020-03-05 12:31   ` Dr. David Alan Gilbert
2020-03-05 16:48     ` Jag Raman
2020-03-05 17:04       ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to " Jagannathan Raman
2020-03-05 14:39   ` Dr. David Alan Gilbert
2020-03-05 16:32     ` Elena Ufimtseva
2020-02-24 20:55 ` [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object Jagannathan Raman
2020-03-05 15:28   ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 44/50] multi-process/mig: refactor runstate_check into common file Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 45/50] multi-process/mig: Synchronize runstate of remote process Jagannathan Raman
2020-02-24 20:55 ` [PATCH v5 46/50] multi-process/mig: Restore the VMSD in " Jagannathan Raman
2020-03-05 16:05   ` Dr. David Alan Gilbert
2020-02-24 20:55 ` [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote Jagannathan Raman
2020-02-28 16:44   ` Stefan Hajnoczi
2020-03-02 19:28     ` Jag Raman
2020-02-24 20:55 ` [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy Jagannathan Raman
2020-02-27 17:18   ` Stefan Hajnoczi
2020-02-28 17:53     ` Elena Ufimtseva
2020-02-24 20:55 ` [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess Jagannathan Raman
2020-02-27 17:11   ` Stefan Hajnoczi
2020-02-28 18:44     ` Elena Ufimtseva
2020-02-24 20:55 ` [PATCH v5 50/50] multi-process: add configure and usage information Jagannathan Raman
2020-02-27 16:58   ` Stefan Hajnoczi
2020-02-28 18:43     ` Elena Ufimtseva
2020-03-06 16:42       ` Stefan Hajnoczi
2020-02-24 21:59 ` [PATCH v5 00/50] Initial support for multi-process qemu no-reply
2020-02-24 22:03 ` no-reply
2020-02-24 22:23 ` no-reply
2020-03-01 11:57 ` Alex Bennée
2020-03-02 15:28   ` Jag Raman
2020-03-02 16:29     ` Alex Bennée
2020-03-02 16:53       ` Jag Raman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.