Skip to contentSkip to conversation

Initial support for multi-process qemu

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

Subsystems (4)

v5 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

v5 cover Initial support for multi-process qemu

Hello

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

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

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

Following people contributed to this patchset:

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

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

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

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

Thank you!

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

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

Jagannathan Raman (26):
multi-process: memory: alloc RAM from file at offset
multi-process: Refactor machine_init and exit notifiers
multi-process: Add stub functions to facilate build of multi-process
multi-process: Add config option for multi-process QEMU
multi-process: build system for remote device process
multi-process: define mpqemu-link object
multi-process: add functions to synchronize proxy and remote endpoints
multi-process: setup PCI host bridge for remote device
multi-process: setup a machine object for remote device process
multi-process: setup memory manager for remote device
multi-process: remote process initialization
multi-process: PCI BAR read/write handling for proxy & remote
endpoints
multi-process: Synchronize remote memory
multi-process: create IOHUB object to handle irq
multi-process: Retrieve PCI info from remote process
multi-process: Introduce build flags to separate remote process code
multi-process: Use separate MMIO communication channel
multi-process: perform device reset in the remote process multi-process/mon: stub functions to enable QMP module for remote
process
multi-process/mon: enable QMP module support in the remote process multi-process/mon: Refactor monitor/chardev functions out of vl.c multi-process/mon: Initialize QMP module for remote processes
multi-process: prevent duplicate memory initialization in remote multi-process/mig: build migration module in the remote process multi-process/mig: Enable VMSD save in the Proxy object multi-process/mig: Send VMSD of remote to the Proxy object

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

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

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

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

---
 exec.c                    | 11 +++++++----
 include/exec/ram_addr.h   |  2 +-
 include/qemu/mmap-alloc.h |  3 ++-
 memory.c                  |  2 +-
 util/mmap-alloc.c         |  7 ++++---
 util/oslib-posix.c        |  2 +-
 6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     Error *err = NULL;
@@ -1893,7 +1894,8 @@ static void *file_ram_alloc(RAMBlock *block,
     }
 
     area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
     if (area == MAP_FAILED) {
         error_setg_errno(errp, errno,
                          "unable to map backing store for guest RAM");
@@ -2322,7 +2324,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 #ifdef CONFIG_POSIX
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
@@ -2367,7 +2369,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
     new_block->used_length = size;
     new_block->max_length = size;
     new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
     if (!new_block->host) {
         g_free(new_block);
         return NULL;
@@ -2397,7 +2400,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
     if (!block) {
         if (created) {
             unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d..1b9f489 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                    Error **errp);
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266..4f57985 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
     mr->destructor = memory_region_destructor_ram;
     mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                            share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
     if (err) {
         mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd..a28f702 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
 {
     int flags;
     int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
     offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
     ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
     if (ptr == MAP_FAILED && map_sync_flags) {
         if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
          * we will remove these flags to handle compatibility.
          */
         ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
     }
 
     if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 5a291cc..bd221dd 100644
@@ -205,7 +205,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
 {
     size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
     if (ptr == MAP_FAILED) {
         return NULL;
Signature · 1 line
1.8.3.1
Reviewed-by on v5 1/50
#2 lore raw

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

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

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

This looks reasonable to me, so :

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

Dave

Quoted 147 lines
---
 exec.c                    | 11 +++++++----
 include/exec/ram_addr.h   |  2 +-
 include/qemu/mmap-alloc.h |  3 ++-
 memory.c                  |  2 +-
 util/mmap-alloc.c         |  7 ++++---
 util/oslib-posix.c        |  2 +-
 6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             ram_addr_t memory,
                             int fd,
                             bool truncate,
+                            off_t offset,
                             Error **errp)
 {
     Error *err = NULL;
@@ -1893,7 +1894,8 @@ static void *file_ram_alloc(RAMBlock *block,
     }
 
     area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
     if (area == MAP_FAILED) {
         error_setg_errno(errp, errno,
                          "unable to map backing store for guest RAM");
@@ -2322,7 +2324,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 #ifdef CONFIG_POSIX
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
@@ -2367,7 +2369,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
     new_block->used_length = size;
     new_block->max_length = size;
     new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
     if (!new_block->host) {
         g_free(new_block);
         return NULL;
@@ -2397,7 +2400,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
     if (!block) {
         if (created) {
             unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d..1b9f489 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                    Error **errp);
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266..4f57985 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
 void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
     mr->destructor = memory_region_destructor_ram;
     mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                            share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
     mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
     if (err) {
         mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd..a28f702 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                     size_t size,
                     size_t align,
                     bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
 {
     int flags;
     int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
     offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
     ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
     if (ptr == MAP_FAILED && map_sync_flags) {
         if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
          * we will remove these flags to handle compatibility.
          */
         ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
     }
 
     if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 5a291cc..bd221dd 100644
@@ -205,7 +205,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
 {
     size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
     if (ptr == MAP_FAILED) {
         return NULL;
Signature · 1 line
1.8.3.1

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

author
#3 lore raw

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

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

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

Quoted 7 lines

This looks reasonable to me, so :

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

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

--
Jag

Quoted 154 lines

Dave

Quoted 147 lines
---
  exec.c                    | 11 +++++++----
  include/exec/ram_addr.h   |  2 +-
  include/qemu/mmap-alloc.h |  3 ++-
  memory.c                  |  2 +-
  util/mmap-alloc.c         |  7 ++++---
  util/oslib-posix.c        |  2 +-
  6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
index c930040..e524185 100644
@@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block,
                              ram_addr_t memory,
                              int fd,
                              bool truncate,
+                            off_t offset,
                              Error **errp)
  {
      Error *err = NULL;
@@ -1893,7 +1894,8 @@ static void *file_ram_alloc(RAMBlock *block,
      }
 
      area = qemu_ram_mmap(fd, memory, block->mr->align,
-                         block->flags & RAM_SHARED, block->flags & RAM_PMEM);
+                         block->flags & RAM_SHARED, block->flags & RAM_PMEM,
+                         offset);
      if (area == MAP_FAILED) {
          error_setg_errno(errp, errno,
                           "unable to map backing store for guest RAM");
@@ -2322,7 +2324,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
  #ifdef CONFIG_POSIX
  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                   uint32_t ram_flags, int fd,
-                                 Error **errp)
+                                 off_t offset, Error **errp)
  {
      RAMBlock *new_block;
      Error *local_err = NULL;
@@ -2367,7 +2369,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
      new_block->used_length = size;
      new_block->max_length = size;
      new_block->flags = ram_flags;
-    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
+    new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
+                                     errp);
      if (!new_block->host) {
          g_free(new_block);
          return NULL;
@@ -2397,7 +2400,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
          return NULL;
      }
 
-    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
+    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp);
      if (!block) {
          if (created) {
              unlink(mem_path);
include/exec/ram_addr.h +1 -1
index 5e59a3d..1b9f489 100644
@@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
                                     Error **errp);
  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                   uint32_t ram_flags, int fd,
-                                 Error **errp);
+                                 off_t offset, Error **errp);
 
  RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                    MemoryRegion *mr, Error **errp);
include/qemu/mmap-alloc.h +2 -1
index e786266..4f57985 100644
@@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd,
                      size_t size,
                      size_t align,
                      bool shared,
-                    bool is_pmem);
+                    bool is_pmem,
+                    off_t start);
 
  void qemu_ram_munmap(int fd, void *ptr, size_t size);
 
memory.c +1 -1
index aeaa8dc..131bc6c 100644
@@ -1595,7 +1595,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
      mr->destructor = memory_region_destructor_ram;
      mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
                                             share ? RAM_SHARED : 0,
-                                           fd, &err);
+                                           fd, 0, &err);
      mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
      if (err) {
          mr->size = int128_zero();
util/mmap-alloc.c +4 -3
index 27dcccd..a28f702 100644
@@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd,
                      size_t size,
                      size_t align,
                      bool shared,
-                    bool is_pmem)
+                    bool is_pmem,
+                    off_t start)
  {
      int flags;
      int map_sync_flags = 0;
@@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd,
      offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
      ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-               flags | map_sync_flags, fd, 0);
+               flags | map_sync_flags, fd, start);
 
      if (ptr == MAP_FAILED && map_sync_flags) {
          if (errno == ENOTSUP) {
@@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd,
           * we will remove these flags to handle compatibility.
           */
          ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
-                   flags, fd, 0);
+                   flags, fd, start);
      }
 
      if (ptr == MAP_FAILED) {
util/oslib-posix.c +1 -1
index 5a291cc..bd221dd 100644
@@ -205,7 +205,7 @@ void *qemu_memalign(size_t alignment, size_t size)
  void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared)
  {
      size_t align = QEMU_VMALLOC_ALIGN;
-    void *ptr = qemu_ram_mmap(-1, size, align, shared, false);
+    void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0);
 
      if (ptr == MAP_FAILED) {
          return NULL;
Signature · 1 line
1.8.3.1

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

#4 lore raw

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

In reply to Jagannathan Raman

Relocate machine_int and exit notifiers into common code

---
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 ------------------------------------------
 util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 42 deletions(-)
include/sysemu/sysemu.h +2 -0
index dec64fc..2f37e2b 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
 extern bool machine_init_done;
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
 extern int autostart;
 
softmmu/vl.c +0 -42

60 lines not on this page · raw message

util/notify.c +43 -0

52 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

Re: [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers

Hi

Quoted 2 lines · Jagannathan Raman

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

Quoted 156 lines
---
 include/sysemu/sysemu.h |  2 ++
 softmmu/vl.c            | 42 ------------------------------------------
 util/notify.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 42 deletions(-)
include/sysemu/sysemu.h +2 -0
index dec64fc..2f37e2b 100644
@@ -17,11 +17,13 @@ extern bool qemu_uuid_set;
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
+void qemu_run_exit_notifiers(void);
 
 extern bool machine_init_done;
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 void qemu_remove_machine_init_done_notifier(Notifier *notify);
+void qemu_run_machine_init_done_notifiers(void);
 
 extern int autostart;
 
softmmu/vl.c +0 -42
index 92c7b3a..94a7b93 100644
@@ -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)
 {
util/notify.c +43 -1
index 76bab21..0e7479b 100644
@@ -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

Signature · 1 line
Marc-André Lureau
#6 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

In reply to Jagannathan Raman

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

---
 accel/stubs/kvm-stub.c    |  5 +++
 accel/stubs/tcg-stub.c    | 97 +++++++++++++++++++++++++++++++++++++++++++++++
 stubs/audio.c             | 12 ++++++
 stubs/machine-init-done.c |  4 ++
 stubs/monitor.c           | 41 ++++++++++++++++++++
 stubs/net-stub.c          | 31 +++++++++++++++
 stubs/replay.c            | 14 +++++++
 stubs/vl-stub.c           | 79 ++++++++++++++++++++++++++++++++++++++
 stubs/vmstate.c           | 19 ++++++++++
 stubs/xen-mapcache.c      | 22 +++++++++++
 10 files changed, 324 insertions(+)
 create mode 100644 stubs/audio.c
 create mode 100644 stubs/net-stub.c
 create mode 100644 stubs/vl-stub.c
 create mode 100644 stubs/xen-mapcache.c
accel/stubs/kvm-stub.c +5 -0
index 82f118d..baa6b38 100644
@@ -31,6 +31,7 @@ bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 bool kvm_ioeventfd_any_length_allowed;
 bool kvm_msi_use_devid;
+bool kvm_halt_in_kernel_allowed;
 
 int kvm_destroy_vcpu(CPUState *cpu)
 {
@@ -58,6 +59,10 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
 }
 
+void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu)
+{
+}
+
 int kvm_cpu_exec(CPUState *cpu)
 {
     abort();
accel/stubs/tcg-stub.c +97 -0

111 lines not on this page · raw message

stubs/audio.c new file +12 -0
new file mode 100644
index 0000000..8ae3b0f
@@ -0,0 +1,12 @@
+#include "qemu/osdep.h"
+#include "audio/audio.h"
+
+AudioState *audio_state_by_name(const char *name)
+{
+    return NULL;
+}
+
+const char *audio_get_id(QEMUSoundCard *card)
+{
+    return NULL;
+}
stubs/machine-init-done.c +4 -0
index cd8e813..3deabc9 100644
@@ -6,3 +6,7 @@ bool machine_init_done = true;
 void qemu_add_machine_init_done_notifier(Notifier *notify)
 {
 }
+
+void qemu_remove_machine_init_done_notifier(Notifier *notify)
+{
+}
stubs/monitor.c +41 -0

53 lines not on this page · raw message

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

79 lines not on this page · raw message

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

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

In reply to Jagannathan Raman

Add a configuration option to separate multi-process code

---
 configure | 11 +++++++++++
 1 file changed, 11 insertions(+)
configure +11 -0
index 48d6f89..ab1e344 100755
@@ -506,6 +506,7 @@ libpmem=""
 default_devices="yes"
 plugins="no"
 fuzzing="no"
+mpqemu="no"
 
 supported_cpu="no"
 supported_os="no"
@@ -1572,6 +1573,10 @@ for opt do
   ;;
   --disable-fuzzing) fuzzing=no
   ;;
+  --enable-mpqemu) mpqemu=yes
+  ;;
+  --disable-mpqemu) mpqemu=no
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1860,6 +1865,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   debug-mutex     mutex debugging support
   libpmem         libpmem support
   xkbcommon       xkbcommon support
+  mpqemu          multi-process QEMU support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -6690,6 +6696,7 @@ echo "libudev           $libudev"
 echo "default devices   $default_devices"
 echo "plugin support    $plugins"
 echo "fuzzing support   $fuzzing"
+echo "multiprocess QEMU $mpqemu"
 
 if test "$supported_cpu" = "no"; then
     echo
@@ -7501,6 +7508,10 @@ if test "$libpmem" = "yes" ; then
   echo "CONFIG_LIBPMEM=y" >> $config_host_mak
 fi
 
+if test "$mpqemu" = "yes" ; then
+  echo "CONFIG_MPQEMU=y" >> $config_host_mak
+fi
+
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
Signature · 1 line
1.8.3.1
#9 lore raw

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

In reply to Jagannathan Raman

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

---
 Makefile                |  2 ++
 Makefile.objs           | 26 +++++++++++++++++++++
 Makefile.target         | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
 accel/Makefile.objs     |  2 ++
 backends/Makefile.objs  |  2 ++
 block/Makefile.objs     |  2 ++
 hw/Makefile.objs        |  7 ++++++
 hw/block/Makefile.objs  |  2 ++
 hw/core/Makefile.objs   | 18 +++++++++++++++
 hw/nvram/Makefile.objs  |  2 ++
 hw/pci/Makefile.objs    |  4 ++++
 hw/scsi/Makefile.objs   |  2 ++
 migration/Makefile.objs |  2 ++
 qom/Makefile.objs       |  3 +++
 remote/Makefile.objs    |  1 +
 remote/remote-main.c    | 23 +++++++++++++++++++
 stubs/replay.c          |  4 ++++
 17 files changed, 162 insertions(+), 1 deletion(-)
 create mode 100644 remote/Makefile.objs
 create mode 100644 remote/remote-main.c
Makefile +2 -0
index 15f8e53..f91dcb9 100644
@@ -454,6 +454,8 @@ dummy := $(call unnest-vars,, \
                 qom-obj-y \
                 io-obj-y \
                 common-obj-y \
+                remote-pci-obj-y \
+                remote-lsi-obj-y \
                 common-obj-m \
                 trace-obj-y)
 
Makefile.objs +26 -0
index 8a1cbe8..c80e107 100644
@@ -21,6 +21,32 @@ block-obj-$(CONFIG_REPLICATION) += replication.o
 
 block-obj-m = block/
 
+#########################################################
+# remote-pci-obj-y is common code used by remote devices
+
+remote-pci-obj-$(CONFIG_MPQEMU) += hw/
+remote-pci-obj-$(CONFIG_MPQEMU) += qom/
+remote-pci-obj-$(CONFIG_MPQEMU) += backends/
+remote-pci-obj-$(CONFIG_MPQEMU) += block/
+remote-pci-obj-$(CONFIG_MPQEMU) += migration/
+remote-pci-obj-$(CONFIG_MPQEMU) += remote/
+remote-pci-obj-$(CONFIG_MPQEMU) += accel/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
+remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o
+remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o
+remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
+
+##############################################################
+# remote-lsi-obj-y is code used to implement remote LSI device
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+
+#######################################################################
+# crypto-obj-y is code used by both qemu system emulation and qemu-img
+
 crypto-obj-y = crypto/
 
 io-obj-y = io/
Makefile.target +60 -1

100 lines not on this page · raw message

accel/Makefile.objs +2 -0
index 17e5ac6..e312dd4 100644
@@ -3,3 +3,5 @@ obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o
 obj-$(CONFIG_KVM) += kvm/
 obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += accel.o
backends/Makefile.objs +2 -0
index 28a847c..947cde3 100644
@@ -21,3 +21,5 @@ common-obj-$(CONFIG_LINUX) += hostmem-memfd.o
 common-obj-$(CONFIG_GIO) += dbus-vmstate.o
 dbus-vmstate.o-cflags = $(GIO_CFLAGS)
 dbus-vmstate.o-libs = $(GIO_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o
block/Makefile.objs +2 -0
index 3bcb35c..6398613 100644
@@ -71,3 +71,5 @@ io_uring.o-cflags  := $(LINUX_IO_URING_CFLAGS)
 io_uring.o-libs    := $(LINUX_IO_URING_LIBS)
 parallels.o-cflags := $(LIBXML2_CFLAGS)
 parallels.o-libs   := $(LIBXML2_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += stream.o
hw/Makefile.objs +7 -0
index 660e2b4..af9235b 100644
@@ -44,3 +44,10 @@ endif
 
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += core/
+remote-pci-obj-$(CONFIG_MPQEMU) += block/
+remote-pci-obj-$(CONFIG_MPQEMU) += pci/
+remote-pci-obj-$(CONFIG_MPQEMU) += nvram/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/
hw/block/Makefile.objs +2 -0
index 4b4a2b3..0b4644f 100644
@@ -16,3 +16,5 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
 
 obj-y += dataplane/
+
+remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o
hw/core/Makefile.objs +18 -0
index 6215e7c..e3e8084 100644
@@ -31,3 +31,21 @@ common-obj-$(CONFIG_OR_IRQ) += or-irq.o
 common-obj-$(CONFIG_SPLIT_IRQ) += split-irq.o
 common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
 common-obj-$(CONFIG_GENERIC_LOADER) += generic-loader.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev.o
+remote-pci-obj-$(CONFIG_MPQEMU) += bus.o
+remote-pci-obj-$(CONFIG_MPQEMU) += irq.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hotplug.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
+remote-pci-obj-$(CONFIG_MPQEMU) += fw-path-provider.o
+remote-pci-obj-$(CONFIG_MPQEMU) += reset.o
+remote-pci-obj-$(CONFIG_MPQEMU) += sysbus.o
+remote-pci-obj-$(CONFIG_MPQEMU) += loader.o
+remote-pci-obj-$(CONFIG_MPQEMU) += nmi.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o
+remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
+remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
+remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
+remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
hw/nvram/Makefile.objs +2 -0
index f3ad921..4d2d809 100644
@@ -6,3 +6,5 @@ common-obj-$(CONFIG_CHRP_NVRAM) += chrp_nvram.o
 common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
 common-obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o
 obj-$(CONFIG_PSERIES) += spapr_nvram.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += fw_cfg.o
hw/pci/Makefile.objs +4 -0
index c78f2fb..955be54 100644
@@ -12,3 +12,7 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o
 
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o
+remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
hw/scsi/Makefile.objs +2 -0
index 54b36ed..ef97770 100644
@@ -13,3 +13,5 @@ obj-y += virtio-scsi.o virtio-scsi-dataplane.o
 obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o
 obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o
 endif
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += scsi-generic.o scsi-bus.o lsi53c895a.o scsi-disk.o emulation.o
migration/Makefile.objs +2 -0
index d3623d5..e7cdc76 100644
@@ -14,3 +14,5 @@ common-obj-$(CONFIG_RDMA) += rdma.o
 common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o
 
 rdma.o-libs := $(RDMA_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o
qom/Makefile.objs +3 -0
index f9d7735..07e50e5 100644
@@ -2,3 +2,6 @@ qom-obj-y = object.o container.o qom-qobject.o
 qom-obj-y += object_interfaces.o
 
 common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
+remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
remote/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..a9b2256
@@ -0,0 +1 @@
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
remote/remote-main.c new file +23 -0
new file mode 100644
index 0000000..7c0764a
@@ -0,0 +1,23 @@
+/*
+ * Remote device initialization
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+
+#include <stdio.h>
+
+#include "qemu/module.h"
+
+int main(int argc, char *argv[])
+{
+    module_call_init(MODULE_INIT_QOM);
+
+    return 0;
+}
stubs/replay.c +4 -0
index 2e3feee..9b53c0c 100644
@@ -102,3 +102,7 @@ int replay_get_instructions(void)
 void replay_account_executed_instructions(void)
 {
 }
+
+void replay_add_blocker(Error *reason)
+{
+}
Signature · 1 line
1.8.3.1
#10 lore raw

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

In reply to Jagannathan Raman

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

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

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

294 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#11 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

Quoted 4 lines · Jagannathan Raman

+/*
+ * TODO: Dont use mpqemu link object since it is
+ * not needed to be created via -object.
+ */

Please investigate and resolve this TODO.

include/io/mpqemu-link.h line 79

Quoted 4 lines
include/io/mpqemu-link.h new file +4 -0
+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.

Quoted 4 lines

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

Please investigate and decide how to resolve this TODO.

Quoted 57 lines
io/mpqemu-link.c new file +57 -0
+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) {

io/mpqemu-link.c line 129

Quoted 10 lines
io/mpqemu-link.c new file +10 -0
+        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.

io/mpqemu-link.c line 185

Quoted 13 lines
io/mpqemu-link.c new file +13 -0
+    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.

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                qemu_log_mask(LOG_REMOTE_DEBUG,
+                              "%s: Max FDs exceeded\n", __func__);
+                return -ERANGE;

The mutex must be released.

#12 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

Quoted 8 lines · Stefan Hajnoczi
Quoted 4 lines · Jagannathan Raman

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

Quoted 10 lines

include/io/mpqemu-link.h line 79

Quoted 4 lines
include/io/mpqemu-link.h new file +4 -0
+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.

Quoted 71 lines
Quoted 5 lines

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

Please investigate and decide how to resolve this TODO.

Quoted 63 lines
io/mpqemu-link.c new file +63 -0
+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 {
Quoted 9 lines

io/mpqemu-link.c line 129

Quoted 4 lines
io/mpqemu-link.c new file +4 -0
+        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.

Quoted 14 lines

io/mpqemu-link.c line 185

Quoted 13 lines
io/mpqemu-link.c new file +13 -0
+    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
+                 */
Quoted 7 lines

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

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                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

#13 lore raw

Re: [PATCH v5 07/50] multi-process: define mpqemu-link object

Quoted 18 lines · Elena Ufimtseva
Quoted 17 lines · Stefan Hajnoczi

io/mpqemu-link.c line 185

Quoted 13 lines · Jagannathan Raman
io/mpqemu-link.c new file +13 -0
+    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.

Quoted 7 lines
Quoted 5 lines

io/mpqemu-link.c line 188

Quoted 3 lines
io/mpqemu-link.c new file +3 -0
+                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

#14 lore raw

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

In reply to Jagannathan Raman

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

---
 include/io/mpqemu-link.h |  7 +++++++
 io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                               mpqemu_link_callback callback);
 void mpqemu_start_coms(MPQemuLinkState *s);
 
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 #endif
io/mpqemu-link.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#15 lore raw

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

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

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

---
 include/io/mpqemu-link.h |  7 +++++++
 io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                               mpqemu_link_callback callback);
 void mpqemu_start_coms(MPQemuLinkState *s);
 
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
 #endif
io/mpqemu-link.c +4 -0
index bac120b..73b7032 100644
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include <poll.h>
 
 #include "qemu/module.h"
 #include "io/mpqemu-link.h"
@@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
     return rc;
 }
 
+uint64_t wait_for_remote(int efd)
+{
+    struct pollfd pfd = { .fd = efd, .events = POLLIN };

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

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

Shouldn't these be UINT64_MAX?

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

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

Can you explain what's going on there??

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

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

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

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
 static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
 {
     g_assert(timeout);
Signature · 1 line
1.8.3.1

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

author
#16 lore raw

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

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

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

---
  include/io/mpqemu-link.h |  7 +++++++
  io/mpqemu-link.c         | 41 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 48 insertions(+)
include/io/mpqemu-link.h +7 -0
index 2f2dd83..ae04fca 100644
@@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s,
                                mpqemu_link_callback callback);
  void mpqemu_start_coms(MPQemuLinkState *s);
 
+#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC)
+#define PUT_REMOTE_WAIT(wait) close(wait)
+#define PROXY_LINK_WAIT_DONE 1
+
+uint64_t wait_for_remote(int efd);
+void notify_proxy(int fd, uint64_t val);
+
  #endif
io/mpqemu-link.c +1 -0
index bac120b..73b7032 100644
@@ -10,6 +10,7 @@
 
  #include "qemu/osdep.h"
  #include "qemu-common.h"
+#include <poll.h>
 
  #include "qemu/module.h"
  #include "io/mpqemu-link.h"
@@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan)
      return rc;
  }
 
Quoted 15 lines

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

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

Shouldn't these be UINT64_MAX?

Sure, we'll change these to UINT64_MAX.

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

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

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

Can you explain what's going on there??

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

We have implemented this synchronization mechanism using eventfd, as it's easy to setup. So the remote process could write a non-zero value to the eventfd to wake QEMU up. However, the drawback of using eventfd for this purpose is that a return value of zero wouldn't wake QEMU up. Therefore, we offset the return value by one at the remote process and correct it in the QEMU end.

--
Jag

Quoted 29 lines

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

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

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

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
  static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
  {
      g_assert(timeout);
Signature · 1 line
1.8.3.1

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

#17 lore raw

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

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

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

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

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

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

Shouldn't these be UINT64_MAX?

Sure, we'll change these to UINT64_MAX.

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

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

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

Can you explain what's going on there??

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

Quoted 6 lines

We have implemented this synchronization mechanism using eventfd, as it's easy to setup. So the remote process could write a non-zero value to the eventfd to wake QEMU up. However, the drawback of using eventfd for this purpose is that a return value of zero wouldn't wake QEMU up. Therefore, we offset the return value by one at the remote process and correct it in the QEMU end.

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

Dave

Quoted 33 lines

--
Jag

Quoted 29 lines

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

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

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

Dave

Quoted 11 lines
io/mpqemu-link.c +5 -0
+        qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n",
+                      strerror(errno));
+    }
+}
+
  static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout)
  {
      g_assert(timeout);
Signature · 1 line
1.8.3.1

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

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

#18 lore raw

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

In reply to Jagannathan Raman

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

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

 hw/pci/Makefile.objs     |  2 +-
 include/remote/pcihost.h | 45 ++++++++++++++++++++++++++++++++++
 remote/Makefile.objs     |  1 +
 remote/pcihost.c         | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 include/remote/pcihost.h
 create mode 100644 remote/pcihost.c
hw/pci/Makefile.objs +1 -1
index 955be54..90693a7 100644
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
 
-remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o
+remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o pci_host.o pcie_host.o
 remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
include/remote/pcihost.h new file +45 -0

45 lines not on this page · raw message

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

64 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#19 lore raw

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

In reply to Jagannathan Raman

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

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

 Makefile.objs                 |  1 +
 exec.c                        |  3 +-
 include/exec/address-spaces.h |  2 ++
 include/remote/machine.h      | 30 ++++++++++++++++
 remote/Makefile.objs          |  1 +
 remote/machine.c              | 84 +++++++++++++++++++++++++++++++++++++++++++
 remote/remote-main.c          |  7 ++++
 util/Makefile.objs            |  2 ++
 8 files changed, 128 insertions(+), 2 deletions(-)
 create mode 100644 include/remote/machine.h
 create mode 100644 remote/machine.c
Makefile.objs +1 -0
index c80e107..aad33fc 100644
@@ -31,6 +31,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
+remote-pci-obj-$(CONFIG_MPQEMU) += util/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
exec.c +1 -2
index e524185..b4c9cc6 100644
@@ -161,7 +161,6 @@ typedef struct subpage_t {
 #define PHYS_SECTION_UNASSIGNED 0
 
 static void io_mem_init(void);
-static void memory_map_init(void);
 static void tcg_log_global_after_sync(MemoryListener *listener);
 static void tcg_commit(MemoryListener *listener);
 
@@ -3002,7 +3001,7 @@ static void tcg_commit(MemoryListener *listener)
     tlb_flush(cpuas->cpu);
 }
 
-static void memory_map_init(void)
+void memory_map_init(void)
 {
     system_memory = g_malloc(sizeof(*system_memory));
 
include/exec/address-spaces.h +2 -0
index db8bfa9..56a877b 100644
@@ -33,6 +33,8 @@ MemoryRegion *get_system_memory(void);
  */
 MemoryRegion *get_system_io(void);
 
+void memory_map_init(void);
+
 extern AddressSpace address_space_memory;
 extern AddressSpace address_space_io;
 
include/remote/machine.h new file +30 -0
new file mode 100644
index 0000000..7e9bdbe
@@ -0,0 +1,30 @@
+/*
+ * Remote machine configuration
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_MACHINE_H
+#define REMOTE_MACHINE_H
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "hw/boards.h"
+#include "remote/pcihost.h"
+#include "qemu/notify.h"
+
+typedef struct RemMachineState {
+    MachineState parent_obj;
+
+    RemPCIHost *host;
+} RemMachineState;
+
+#define TYPE_REMOTE_MACHINE "remote-machine"
+#define REMOTE_MACHINE(obj) \
+    OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE)
+
+#endif
remote/Makefile.objs +1 -0
index 2757f5a..13d4c48 100644
@@ -1,2 +1,3 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
remote/machine.c new file +84 -0

84 lines not on this page · raw message

remote/remote-main.c +7 -0
index 7c0764a..ecf30e0 100644
@@ -14,10 +14,17 @@
 #include <stdio.h>
 
 #include "qemu/module.h"
+#include "remote/pcihost.h"
+#include "remote/machine.h"
+#include "hw/boards.h"
+#include "hw/qdev-core.h"
+#include "qemu/main-loop.h"
 
 int main(int argc, char *argv[])
 {
     module_call_init(MODULE_INIT_QOM);
 
+    current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
+
     return 0;
 }
util/Makefile.objs +2 -0
index 6b38b67..80b2067 100644
@@ -60,3 +60,5 @@ util-obj-y += guest-random.o
 util-obj-$(CONFIG_GIO) += dbus.o
 dbus.o-cflags = $(GIO_CFLAGS)
 dbus.o-libs = $(GIO_LIBS)
+
+remote-pci-obj-$(CONFIG_MPQEMU) += notify.o
Signature · 1 line
1.8.3.1
#20 lore raw

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

In reply to Jagannathan Raman

sync_sysmem_msg_t message format is defined. It is used to send file descriptors of the RAM regions to remote device.
RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM.

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

 Makefile.target          |  2 ++
 exec.c                   | 17 +++++++++++++
 include/exec/ram_addr.h  |  2 ++
 include/io/mpqemu-link.h | 11 +++++++++
 include/remote/memory.h  | 20 +++++++++++++++
 remote/memory.c          | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 115 insertions(+)
 create mode 100644 include/remote/memory.h
 create mode 100644 remote/memory.c
Makefile.target +2 -0
index 375fdaa..cfd36c1 100644
@@ -143,6 +143,8 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
 endif
 
 #########################################################
exec.c +17 -0
index b4c9cc6..8e77c4c 100644
@@ -2410,6 +2410,23 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
 
     return block;
 }
+
+void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size,
+                           ram_addr_t offset, Error **errp)
+{
+    char *name = g_strdup_printf("%d", fd);
+
+    memory_region_init(mr, NULL, name, size);
+    mr->ram = true;
+    mr->terminates = true;
+    mr->destructor = NULL;
+    mr->align = 0;
+    mr->ram_block = qemu_ram_alloc_from_fd(size, mr, RAM_SHARED, fd, offset,
+                                           errp);
+    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
+
+    g_free(name);
+}
 #endif
 
 static
include/exec/ram_addr.h +2 -0
index 1b9f489..d9d7314 100644
@@ -122,6 +122,8 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
 RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
                                  off_t offset, Error **errp);
+void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size,
+                           ram_addr_t offset, Error **errp);
 
 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
                                   MemoryRegion *mr, Error **errp);
include/io/mpqemu-link.h +11 -0
index ae04fca..78c0818 100644
@@ -16,6 +16,8 @@
 
 #include "qom/object.h"
 #include "qemu/thread.h"
+#include "exec/cpu-common.h"
+#include "exec/hwaddr.h"
 
 #define TYPE_MPQEMU_LINK "mpqemu-link"
 #define MPQEMU_LINK(obj) \
@@ -34,6 +36,7 @@
  * mpqemu_cmd_t:
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
+ * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -42,6 +45,7 @@ typedef enum {
     INIT = 0,
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
+    SYNC_SYSMEM,
     MAX,
 } mpqemu_cmd_t;
 
@@ -59,12 +63,19 @@ typedef enum {
  *
  */
 typedef struct {
+    hwaddr gpas[REMOTE_MAX_FDS];
+    uint64_t sizes[REMOTE_MAX_FDS];
+    ram_addr_t offsets[REMOTE_MAX_FDS];
+} sync_sysmem_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
 
     union {
         uint64_t u64;
+        sync_sysmem_msg_t sync_sysmem;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
include/remote/memory.h new file +20 -0
new file mode 100644
index 0000000..e2e479b
@@ -0,0 +1,20 @@
+/*
+ * Memory manager for remote device
+ *
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_MEMORY_H
+#define REMOTE_MEMORY_H
+
+#include "qemu/osdep.h"
+#include "exec/hwaddr.h"
+#include "io/mpqemu-link.h"
+
+void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp);
+
+#endif
remote/memory.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#21 lore raw

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

In reply to Jagannathan Raman

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

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

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

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

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

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

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

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

remote/remote-main.c line 52

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

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

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

remote/remote-main.c line 100

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

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

Dave

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

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

author
#23 lore raw

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

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

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

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

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

remote/remote-main.c line 52

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

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

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

Thank you!
--
Jag

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

remote/remote-main.c line 100

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

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

Dave

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

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

#24 lore raw

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

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

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

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

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

remote/remote-main.c line 52

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

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

Quoted 2 lines

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

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

Dave

Quoted 79 lines

Thank you!
--
Jag

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

remote/remote-main.c line 100

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

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

Dave

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

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

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

#25 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

 hw/Makefile.objs              |   2 +
 hw/proxy/Makefile.objs        |   1 +
 hw/proxy/qemu-proxy.c         | 226 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h |  54 ++++++++++
 include/io/mpqemu-link.h      |   1 +
 remote/remote-main.c          |  28 ++++++
 6 files changed, 312 insertions(+)
 create mode 100644 hw/proxy/Makefile.objs
 create mode 100644 hw/proxy/qemu-proxy.c
 create mode 100644 include/hw/proxy/qemu-proxy.h
hw/Makefile.objs +2 -0
index af9235b..7b489b1 100644
@@ -45,6 +45,8 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
+common-obj-$(CONFIG_MPQEMU) += proxy/
+
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..eb81624
@@ -0,0 +1 @@
+common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +226 -0

226 lines not on this page · raw message

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

54 lines not on this page · raw message

include/io/mpqemu-link.h +1 -0
index 78c0818..5a2be48 100644
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
+#include "sys/eventfd.h"
 #include "qom/object.h"
 #include "qemu/thread.h"
 #include "exec/cpu-common.h"
remote/remote-main.c +28 -0
index 56315cd..7b4cf2f 100644
@@ -37,6 +37,32 @@
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
 
+static void process_config_write(MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+
+    qemu_mutex_lock_iothread();
+    pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l);
+    qemu_mutex_unlock_iothread();
+}
+
+static void process_config_read(MPQemuMsg *msg)
+{
+    struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;
+    uint32_t val;
+    int wait;
+
+    wait = msg->fds[0];
+
+    qemu_mutex_lock_iothread();
+    val = pci_default_read_config(remote_pci_dev, conf->addr, conf->l);
+    qemu_mutex_unlock_iothread();
+
+    notify_proxy(wait, val);
+
+    PUT_REMOTE_WAIT(wait);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -57,8 +83,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     case INIT:
         break;
     case PCI_CONFIG_WRITE:
+        process_config_write(msg);
         break;
     case PCI_CONFIG_READ:
+        process_config_read(msg);
         break;
     default:
         error_setg(&err, "Unknown command");
Signature · 1 line
1.8.3.1
#26 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

typo "multi" in patch subject.

Quoted 37 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

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

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

Quoted 42 lines · Philippe Mathieu-Daudé

typo "multi" in patch subject.

Quoted 39 lines · Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

g_shell_parse_argv() perhaps

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

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 6 lines

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

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

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

Thanks!

Elena

Quoted 8 lines

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

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

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

Quoted 4 lines

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

Hi Daniel

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

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

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

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

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

Thank you!
Elena

Quoted 11 lines

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 45

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

Quoted 4 lines

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

Hi Daniel

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

Quoted 8 lines

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

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

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

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

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

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

And this gets turned into 2 execs:

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

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

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

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

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

Quoted 2 lines

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 43

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

Quoted 4 lines

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

Hi Daniel

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

Quoted 8 lines

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

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

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

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

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

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

And this gets turned into 2 execs:

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

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

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

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

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

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

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

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

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

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

What your thoughts on this?

Thank you!
Elena

Stefan,

Quoted 11 lines
Quoted 3 lines

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 43

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

Quoted 4 lines

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

Hi Daniel

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

Quoted 8 lines

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

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

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

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

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

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

And this gets turned into 2 execs:

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

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

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

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

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

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

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

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

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

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

What your thoughts on this?

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

Regards,
Daniel

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

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

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

typo "multi" in patch subject.

Thank Philippe, will fix.

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

From: Elena Ufimtseva <[email protected]>

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

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

hw/proxy/qemu-proxy.c line 43

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

Is there a GLib function to do that?

Hi Daniel

Quoted 2 lines

g_shell_parse_argv() perhaps

Thanks for the suggestion.

Quoted 8 lines
Quoted 6 lines

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

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

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

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

Quoted 4 lines

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

Hi Daniel

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

Quoted 8 lines

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

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

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

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

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

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

And this gets turned into 2 execs:

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

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

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

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

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

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

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

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

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

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

What your thoughts on this?

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

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

#36 lore raw

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

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

From: Elena Ufimtseva <[email protected]>

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

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

...

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

.....

hw/proxy/qemu-proxy.c line 56

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

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

Dave

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

#37 lore raw

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

In reply to Jagannathan Raman

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

---
 hw/proxy/qemu-proxy.c         | 65 ++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
 include/io/mpqemu-link.h      | 12 +++++++
 remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
 }
+
+static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
+                                bool write, hwaddr addr, uint64_t *val,
+                                unsigned size, bool memory)
+{
+    MPQemuLinkState *mpqemu_link = dev->mpqemu_link;
+    MPQemuMsg msg;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.data1.bar_access.addr = mr->addr + addr;
+    msg.data1.bar_access.size = size;
+    msg.data1.bar_access.memory = memory;
+
+    if (write) {
+        msg.cmd = BAR_WRITE;
+        msg.data1.bar_access.val = *val;
+    } else {
+        wait = GET_REMOTE_WAIT;
+
+        msg.cmd = BAR_READ;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, mpqemu_link->com);
+
+    if (!write) {
+        *val = wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+}
+
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size,
+                        pmr->memory);
+}
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+    uint64_t val;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size,
+                        pmr->memory);
+
+     return val;
+}
+
+const MemoryRegionOps proxy_default_ops = {
+    .read = proxy_default_bar_read,
+    .write = proxy_default_bar_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
include/hw/proxy/qemu-proxy.h +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
 #define PCI_PROXY_DEV_GET_CLASS(obj) \
             OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
 
-typedef struct PCIProxyDev {
+typedef struct PCIProxyDev PCIProxyDev;
+
+typedef struct ProxyMemoryRegion {
+    PCIProxyDev *dev;
+    MemoryRegion mr;
+    bool memory;
+    bool present;
+    uint8_t type;
+} ProxyMemoryRegion;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
     PCIDevice parent_dev;
 
     MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                         bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
 typedef struct PCIProxyDevClass {
     PCIDeviceClass parent_class;
@@ -51,4 +64,9 @@ typedef struct PCIProxyDevClass {
     char *command;
 } PCIProxyDevClass;
 
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size);
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size);
+
 #endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +12 -0
index 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
  * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
+ * BAR_WRITE        Writes to PCI BAR region
+ * BAR_READ         Reads from PCI BAR region
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -47,6 +49,8 @@ typedef enum {
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
     SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
     MAX,
 } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
 } sync_sysmem_msg_t;
 
 typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -77,6 +88,7 @@ typedef struct {
     union {
         uint64_t u64;
         sync_sysmem_msg_t sync_sysmem;
+        bar_access_msg_t bar_access;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
remote/remote-main.c +73 -0

91 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#38 lore raw

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

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

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

---
 hw/proxy/qemu-proxy.c         | 65 ++++++++++++++++++++++++++++++++++++++
 include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
 include/io/mpqemu-link.h      | 12 +++++++
 remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
 }
+
+static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
+                                bool write, hwaddr addr, uint64_t *val,
+                                unsigned size, bool memory)
+{
+    MPQemuLinkState *mpqemu_link = dev->mpqemu_link;
+    MPQemuMsg msg;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.data1.bar_access.addr = mr->addr + addr;
+    msg.data1.bar_access.size = size;
+    msg.data1.bar_access.memory = memory;
+
+    if (write) {
+        msg.cmd = BAR_WRITE;
+        msg.data1.bar_access.val = *val;
+    } else {
+        wait = GET_REMOTE_WAIT;
+
+        msg.cmd = BAR_READ;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, mpqemu_link->com);
+
+    if (!write) {
+        *val = wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+}
+
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size,
+                        pmr->memory);
+}
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+    uint64_t val;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size,
+                        pmr->memory);
+
+     return val;
+}
+
+const MemoryRegionOps proxy_default_ops = {
+    .read = proxy_default_bar_read,
+    .write = proxy_default_bar_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
include/hw/proxy/qemu-proxy.h +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
 #define PCI_PROXY_DEV_GET_CLASS(obj) \
             OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
 
-typedef struct PCIProxyDev {
+typedef struct PCIProxyDev PCIProxyDev;
+
+typedef struct ProxyMemoryRegion {
+    PCIProxyDev *dev;
+    MemoryRegion mr;
+    bool memory;
+    bool present;
+    uint8_t type;
+} ProxyMemoryRegion;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
     PCIDevice parent_dev;
 
     MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
     void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                         bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
 typedef struct PCIProxyDevClass {
     PCIDeviceClass parent_class;
@@ -51,4 +64,9 @@ typedef struct PCIProxyDevClass {
     char *command;
 } PCIProxyDevClass;
 
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size);
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size);
+
 #endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +12 -0
index 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
  * PCI_CONFIG_READ        PCI configuration space read
  * PCI_CONFIG_WRITE       PCI configuration space write
  * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
+ * BAR_WRITE        Writes to PCI BAR region
+ * BAR_READ         Reads from PCI BAR region
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -47,6 +49,8 @@ typedef enum {
     PCI_CONFIG_READ,
     PCI_CONFIG_WRITE,
     SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
     MAX,
 } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
 } sync_sysmem_msg_t;
 
 typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -77,6 +88,7 @@ typedef struct {
     union {
         uint64_t u64;
         sync_sysmem_msg_t sync_sysmem;
+        bar_access_msg_t bar_access;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
remote/remote-main.c +19 -0
index 7b4cf2f..acd8daf 100644
@@ -33,6 +33,7 @@
 #include "sysemu/sysemu.h"
 #include "block/block.h"
 #include "exec/ramlist.h"
+#include "exec/memattrs.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -63,6 +64,66 @@ static void process_config_read(MPQemuMsg *msg)
     PUT_REMOTE_WAIT(wait);
 }
 
+/* TODO: confirm memtx attrs. */
+static void process_bar_write(MPQemuMsg *msg, Error **errp)
+{
+    bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    AddressSpace *as =
+        bar_access->memory ? &address_space_memory : &address_space_io;
+    MemTxResult res;
+
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&bar_access->val, bar_access->size, true);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space write operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+    }
+}
+
+static void process_bar_read(MPQemuMsg *msg, Error **errp)

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

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

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

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

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

No case 8 ?

Dave

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

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

author
#39 lore raw

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

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

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

---
  hw/proxy/qemu-proxy.c         | 65 ++++++++++++++++++++++++++++++++++++++
  include/hw/proxy/qemu-proxy.h | 22 +++++++++++--
  include/io/mpqemu-link.h      | 12 +++++++
  remote/remote-main.c          | 73 +++++++++++++++++++++++++++++++++++++++++++
  4 files changed, 170 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +65 -0
index d792e86..b17d9bb 100644
@@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
      dev->get_proxy_sock = get_proxy_sock;
      dev->init_proxy = init_proxy;
  }
+
+static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
+                                bool write, hwaddr addr, uint64_t *val,
+                                unsigned size, bool memory)
+{
+    MPQemuLinkState *mpqemu_link = dev->mpqemu_link;
+    MPQemuMsg msg;
+    int wait;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.data1.bar_access.addr = mr->addr + addr;
+    msg.data1.bar_access.size = size;
+    msg.data1.bar_access.memory = memory;
+
+    if (write) {
+        msg.cmd = BAR_WRITE;
+        msg.data1.bar_access.val = *val;
+    } else {
+        wait = GET_REMOTE_WAIT;
+
+        msg.cmd = BAR_READ;
+        msg.num_fds = 1;
+        msg.fds[0] = wait;
+    }
+
+    mpqemu_msg_send(&msg, mpqemu_link->com);
+
+    if (!write) {
+        *val = wait_for_remote(wait);
+        PUT_REMOTE_WAIT(wait);
+    }
+}
+
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size,
+                        pmr->memory);
+}
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ProxyMemoryRegion *pmr = opaque;
+    uint64_t val;
+
+    send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size,
+                        pmr->memory);
+
+     return val;
+}
+
+const MemoryRegionOps proxy_default_ops = {
+    .read = proxy_default_bar_read,
+    .write = proxy_default_bar_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
include/hw/proxy/qemu-proxy.h +20 -2
index 29fa2e9..44e370e 100644
@@ -22,7 +22,19 @@
  #define PCI_PROXY_DEV_GET_CLASS(obj) \
              OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV)
 
-typedef struct PCIProxyDev {
+typedef struct PCIProxyDev PCIProxyDev;
+
+typedef struct ProxyMemoryRegion {
+    PCIProxyDev *dev;
+    MemoryRegion mr;
+    bool memory;
+    bool present;
+    uint8_t type;
+} ProxyMemoryRegion;
+
+extern const MemoryRegionOps proxy_default_ops;
+
+struct PCIProxyDev {
      PCIDevice parent_dev;
 
      MPQemuLinkState *mpqemu_link;
@@ -41,7 +53,8 @@ typedef struct PCIProxyDev {
      void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name,
                          bool need_spawn, Error **errp);
 
-} PCIProxyDev;
+    ProxyMemoryRegion region[PCI_NUM_REGIONS];
+};
 
  typedef struct PCIProxyDevClass {
      PCIDeviceClass parent_class;
@@ -51,4 +64,9 @@ typedef struct PCIProxyDevClass {
      char *command;
  } PCIProxyDevClass;
 
+void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size);
+
+uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size);
+
  #endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +12 -0
index 5a2be48..1a7738e 100644
@@ -38,6 +38,8 @@
   * PCI_CONFIG_READ        PCI configuration space read
   * PCI_CONFIG_WRITE       PCI configuration space write
   * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
+ * BAR_WRITE        Writes to PCI BAR region
+ * BAR_READ         Reads from PCI BAR region
   *
   * proc_cmd_t enum type to specify the command to be executed on the remote
   * device.
@@ -47,6 +49,8 @@ typedef enum {
      PCI_CONFIG_READ,
      PCI_CONFIG_WRITE,
      SYNC_SYSMEM,
+    BAR_WRITE,
+    BAR_READ,
      MAX,
  } mpqemu_cmd_t;
 
@@ -70,6 +74,13 @@ typedef struct {
  } sync_sysmem_msg_t;
 
  typedef struct {
+    hwaddr addr;
+    uint64_t val;
+    unsigned size;
+    bool memory;
+} bar_access_msg_t;
+
+typedef struct {
      mpqemu_cmd_t cmd;
      int bytestream;
      size_t size;
@@ -77,6 +88,7 @@ typedef struct {
      union {
          uint64_t u64;
          sync_sysmem_msg_t sync_sysmem;
+        bar_access_msg_t bar_access;
      } data1;
 
      int fds[REMOTE_MAX_FDS];
remote/remote-main.c +19 -0
index 7b4cf2f..acd8daf 100644
@@ -33,6 +33,7 @@
  #include "sysemu/sysemu.h"
  #include "block/block.h"
  #include "exec/ramlist.h"
+#include "exec/memattrs.h"
 
  static MPQemuLinkState *mpqemu_link;
  PCIDevice *remote_pci_dev;
@@ -63,6 +64,66 @@ static void process_config_read(MPQemuMsg *msg)
      PUT_REMOTE_WAIT(wait);
  }
 
+/* TODO: confirm memtx attrs. */
+static void process_bar_write(MPQemuMsg *msg, Error **errp)
+{
+    bar_access_msg_t *bar_access = &msg->data1.bar_access;
+    AddressSpace *as =
+        bar_access->memory ? &address_space_memory : &address_space_io;
+    MemTxResult res;
+
+    res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED,
+                           (uint8_t *)&bar_access->val, bar_access->size, true);
+
+    if (res != MEMTX_OK) {
+        error_setg(errp, "Could not perform address space write operation,"
+                   " inaccessible address: %lx.", bar_access->addr);
+    }
+}
+
+static void process_bar_read(MPQemuMsg *msg, Error **errp)

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

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

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

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

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

Quoted 14 lines

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

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

No case 8 ?

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

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

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

Thank you!
--
Jag

Quoted 51 lines

Dave

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

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

#40 lore raw

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

In reply to Jagannathan Raman

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

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

---
 Makefile.target                |   3 +
 hw/proxy/memory-sync.c         | 212 +++++++++++++++++++++++++++++++++++++++++
 hw/proxy/qemu-proxy.c          |   5 +
 include/hw/proxy/memory-sync.h |  37 +++++++
 include/hw/proxy/qemu-proxy.h  |   5 +
 remote/remote-main.c           |  11 +++
 6 files changed, 273 insertions(+)
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 include/hw/proxy/memory-sync.h
Makefile.target +3 -0
index cfd36c1..271d883 100644
@@ -127,6 +127,9 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o
 obj-y += target/$(TARGET_BASE_ARCH)/
 obj-y += disas.o
 obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+endif
 LIBS := $(libs_cpu) $(LIBS)
 
 obj-$(CONFIG_PLUGIN) += plugins/
hw/proxy/memory-sync.c new file +212 -0

212 lines not on this page · raw message

hw/proxy/qemu-proxy.c +5 -0
index b17d9bb..d3a9d38 100644
@@ -16,6 +16,8 @@
 #include "qapi/qmp/qjson.h"
 #include "qapi/qmp/qstring.h"
 #include "hw/proxy/qemu-proxy.h"
+#include "hw/proxy/memory-sync.h"
+#include "qom/object.h"
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 
@@ -243,6 +245,8 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name,
 
     mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com,
                         pdev->socket);
+
+    configure_memory_sync(pdev->sync, pdev->mpqemu_link);
 }
 
 static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
@@ -261,6 +265,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
     dev->set_proxy_sock = set_proxy_sock;
     dev->get_proxy_sock = get_proxy_sock;
     dev->init_proxy = init_proxy;
+    dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER));
 }
 
 static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/memory-sync.h new file +37 -0
new file mode 100644
index 0000000..d8329c9
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef MEMORY_SYNC_H
+#define MEMORY_SYNC_H
+
+#include <sys/types.h>
+
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "exec/memory.h"
+#include "io/mpqemu-link.h"
+
+#define TYPE_MEMORY_LISTENER "memory-listener"
+#define REMOTE_MEM_SYNC(obj) \
+            OBJECT_CHECK(RemoteMemSync, (obj), TYPE_MEMORY_LISTENER)
+
+typedef struct RemoteMemSync {
+    Object obj;
+
+    MemoryListener listener;
+
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
+    MPQemuLinkState *mpqemu_link;
+} RemoteMemSync;
+
+void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link);
+void deconfigure_memory_sync(RemoteMemSync *sync);
+
+#endif
include/hw/proxy/qemu-proxy.h +5 -0
index 44e370e..c93ffe3 100644
@@ -10,6 +10,7 @@
 #define QEMU_PROXY_H
 
 #include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -37,8 +38,12 @@ extern const MemoryRegionOps proxy_default_ops;
 struct PCIProxyDev {
     PCIDevice parent_dev;
 
+    int n_mr_sections;
+    MemoryRegionSection *mr_sections;
+
     MPQemuLinkState *mpqemu_link;
 
+    RemoteMemSync *sync;
     pid_t remote_pid;
     int socket;
 
remote/remote-main.c +11 -0
index acd8daf..9512a3b 100644
@@ -34,6 +34,7 @@
 #include "block/block.h"
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
+#include "exec/address-spaces.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -161,6 +162,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             goto finalize_loop;
         }
         break;
+    case SYNC_SYSMEM:
+        /*
+         * TODO: ensure no active DMA is happening when
+         * sysmem is being updated
+         */
+        remote_sysmem_reconfig(msg, &err);
+        if (err) {
+            goto finalize_loop;
+        }
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#41 lore raw

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

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

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

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

---
 Makefile.target                |   3 +
 hw/proxy/memory-sync.c         | 212 +++++++++++++++++++++++++++++++++++++++++
 hw/proxy/qemu-proxy.c          |   5 +
 include/hw/proxy/memory-sync.h |  37 +++++++
 include/hw/proxy/qemu-proxy.h  |   5 +
 remote/remote-main.c           |  11 +++
 6 files changed, 273 insertions(+)
 create mode 100644 hw/proxy/memory-sync.c
 create mode 100644 include/hw/proxy/memory-sync.h
Makefile.target +3 -0
index cfd36c1..271d883 100644
@@ -127,6 +127,9 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o
 obj-y += target/$(TARGET_BASE_ARCH)/
 obj-y += disas.o
 obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+endif
 LIBS := $(libs_cpu) $(LIBS)
 
 obj-$(CONFIG_PLUGIN) += plugins/
hw/proxy/memory-sync.c new file +47 -0
new file mode 100644
index 0000000..3edbb19
@@ -0,0 +1,212 @@
+/*
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "qemu/osdep.h"
+#include "qemu/compiler.h"
+#include "qemu/int128.h"
+#include "qemu/range.h"
+#include "exec/memory.h"
+#include "exec/cpu-common.h"
+#include "cpu.h"
+#include "exec/ram_addr.h"
+#include "exec/address-spaces.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
+
+static const TypeInfo remote_mem_sync_type_info = {
+    .name          = TYPE_MEMORY_LISTENER,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(RemoteMemSync),
+};
+
+static void remote_mem_sync_register_types(void)
+{
+    type_register_static(&remote_mem_sync_type_info);
+}
+
+type_init(remote_mem_sync_register_types)
+
+static void proxy_ml_begin(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    int mrs;
+
+    for (mrs = 0; mrs < sync->n_mr_sections; mrs++) {
+        memory_region_unref(sync->mr_sections[mrs].mr);
+    }
+
+    g_free(sync->mr_sections);

hw/proxy/memory-sync.c line 57

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

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

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

hw/proxy/memory-sync.c line 77

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

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

Quoted 22 lines
hw/proxy/memory-sync.c new file +22 -0
+    return merge;
+}
+
+static void proxy_ml_region_addnop(MemoryListener *listener,
+                                   MemoryRegionSection *section)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    bool need_add = true;
+    uint64_t mrs_size, mrs_gpa, mrs_page;
+    uintptr_t mrs_host;
+    RAMBlock *mrs_rb;
+    MemoryRegionSection *prev_sec;
+
+    if (!(memory_region_is_ram(section->mr) &&
+          !memory_region_is_rom(section->mr))) {
+        return;
+    }
+
+    mrs_rb = section->mr->ram_block;
+    mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb);
+    mrs_size = int128_get64(section->size);
+    mrs_gpa = section->offset_within_address_space;

hw/proxy/memory-sync.c line 110

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

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

Quoted 4 lines
hw/proxy/memory-sync.c new file +4 -0
+    if (sync->n_mr_sections) {
+        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
+        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
+        uint64_t prev_size = int128_get64(prev_sec->size);

hw/proxy/memory-sync.c line 125

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
+        uint64_t prev_host_start =
+            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
+            prev_sec->offset_within_region;
+        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);
+
+        if (mrs_gpa <= (prev_gpa_end + 1)) {
+            if (mrs_gpa < prev_gpa_start) {
+                assert(0);
+            }

g_assert(mrs_gpa < prev_gpa_start);

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

hw/proxy/memory-sync.c line 150

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

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

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

hw/proxy/memory-sync.c line 177

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

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

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

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

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

In practice this turns out to be hard!

Dave

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

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

author
#42 lore raw

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

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

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

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

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

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

Makefile.target +3 -0
index cfd36c1..271d883 100644
@@ -127,6 +127,9 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o
  obj-y += target/$(TARGET_BASE_ARCH)/
  obj-y += disas.o
  obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
+ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
+obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+endif
  LIBS := $(libs_cpu) $(LIBS)
 
  obj-$(CONFIG_PLUGIN) += plugins/
hw/proxy/memory-sync.c new file +51 -0
new file mode 100644
index 0000000..3edbb19
@@ -0,0 +1,212 @@
+/*
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "qemu/osdep.h"
+#include "qemu/compiler.h"
+#include "qemu/int128.h"
+#include "qemu/range.h"
+#include "exec/memory.h"
+#include "exec/cpu-common.h"
+#include "cpu.h"
+#include "exec/ram_addr.h"
+#include "exec/address-spaces.h"
+#include "io/mpqemu-link.h"
+#include "hw/proxy/memory-sync.h"
+
+static const TypeInfo remote_mem_sync_type_info = {
+    .name          = TYPE_MEMORY_LISTENER,
+    .parent        = TYPE_OBJECT,
+    .instance_size = sizeof(RemoteMemSync),
+};
+
+static void remote_mem_sync_register_types(void)
+{
+    type_register_static(&remote_mem_sync_type_info);
+}
+
+type_init(remote_mem_sync_register_types)
+
+static void proxy_ml_begin(MemoryListener *listener)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    int mrs;
+
+    for (mrs = 0; mrs < sync->n_mr_sections; mrs++) {
+        memory_region_unref(sync->mr_sections[mrs].mr);
+    }
+
+    g_free(sync->mr_sections);
+    sync->mr_sections = NULL;
+    sync->n_mr_sections = 0;
+}
+
Quoted 8 lines

hw/proxy/memory-sync.c line 57

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

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

OK, we'll add this check.

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

hw/proxy/memory-sync.c line 77

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

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

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

Quoted 29 lines
Quoted 29 lines
hw/proxy/memory-sync.c new file +28 -0
+    return merge;
+}
+
+static void proxy_ml_region_addnop(MemoryListener *listener,
+                                   MemoryRegionSection *section)
+{
+    RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener);
+    bool need_add = true;
+    uint64_t mrs_size, mrs_gpa, mrs_page;
+    uintptr_t mrs_host;
+    RAMBlock *mrs_rb;
+    MemoryRegionSection *prev_sec;
+
+    if (!(memory_region_is_ram(section->mr) &&
+          !memory_region_is_rom(section->mr))) {
+        return;
+    }
+
+    mrs_rb = section->mr->ram_block;
+    mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb);
+    mrs_size = int128_get64(section->size);
+    mrs_gpa = section->offset_within_address_space;
+    mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) +
+               section->offset_within_region;
+
+    if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) {
+        return;
+    }
Quoted 8 lines

hw/proxy/memory-sync.c line 110

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

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

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

Quoted 16 lines
Quoted 5 lines
hw/proxy/memory-sync.c new file +4 -0
+    if (sync->n_mr_sections) {
+        prev_sec = sync->mr_sections + (sync->n_mr_sections - 1);
+        uint64_t prev_gpa_start = prev_sec->offset_within_address_space;
+        uint64_t prev_size = int128_get64(prev_sec->size);

hw/proxy/memory-sync.c line 125

Quoted 10 lines
hw/proxy/memory-sync.c new file +10 -0
+        uint64_t prev_gpa_end   = range_get_last(prev_gpa_start, prev_size);
+        uint64_t prev_host_start =
+            (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) +
+            prev_sec->offset_within_region;
+        uint64_t prev_host_end = range_get_last(prev_host_start, prev_size);
+
+        if (mrs_gpa <= (prev_gpa_end + 1)) {
+            if (mrs_gpa < prev_gpa_start) {
+                assert(0);
+            }
Quoted 1 line

g_assert(mrs_gpa < prev_gpa_start);

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

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

hw/proxy/memory-sync.c line 150

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

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

Thank you, we'll add the tracing.

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

hw/proxy/memory-sync.c line 177

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

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

OK.

Thank you!
--
Jag

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

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

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

In practice this turns out to be hard!

Dave

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

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

#43 lore raw

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

In reply to Jagannathan Raman

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

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

 Makefile.target               |   1 +
 hw/Makefile.objs              |   2 -
 hw/proxy/Makefile.objs        |   1 -
 hw/proxy/qemu-proxy.c         |  51 +++++++++++++++
 include/hw/pci/pci_ids.h      |   3 +
 include/hw/proxy/qemu-proxy.h |   8 +++
 include/io/mpqemu-link.h      |   8 +++
 include/remote/iohub.h        |  50 ++++++++++++++
 include/remote/machine.h      |   2 +
 remote/Makefile.objs          |   1 +
 remote/iohub.c                | 148 ++++++++++++++++++++++++++++++++++++++++++
 remote/machine.c              |  15 +++++
 remote/remote-main.c          |   4 ++
 13 files changed, 291 insertions(+), 3 deletions(-)
 delete mode 100644 hw/proxy/Makefile.objs
 create mode 100644 include/remote/iohub.h
 create mode 100644 remote/iohub.c
Makefile.target +1 -0
index 271d883..c621d70 100644
@@ -129,6 +129,7 @@ obj-y += disas.o
 obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
 ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-)
 obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o
+obj-$(CONFIG_MPQEMU) += hw/proxy/qemu-proxy.o
 endif
 LIBS := $(libs_cpu) $(LIBS)
 
hw/Makefile.objs +0 -2
index 7b489b1..af9235b 100644
@@ -45,8 +45,6 @@ endif
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
 
-common-obj-$(CONFIG_MPQEMU) += proxy/
-
 remote-pci-obj-$(CONFIG_MPQEMU) += core/
 remote-pci-obj-$(CONFIG_MPQEMU) += block/
 remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs deleted +0 -1
deleted file mode 100644
index eb81624..0000000
@@ -1 +0,0 @@
-common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c +51 -0

69 lines not on this page · raw message

include/hw/pci/pci_ids.h +3 -0
index 11f8ab7..bd0c17d 100644
@@ -192,6 +192,9 @@
 #define PCI_DEVICE_ID_SUN_SIMBA          0x5000
 #define PCI_DEVICE_ID_SUN_SABRE          0xa000
 
+#define PCI_VENDOR_ID_ORACLE             0x108e
+#define PCI_DEVICE_ID_REMOTE_IOHUB       0xb000
+
 #define PCI_VENDOR_ID_CMD                0x1095
 #define PCI_DEVICE_ID_CMD_646            0x0646
 
include/hw/proxy/qemu-proxy.h +8 -0
index c93ffe3..56aec0e 100644
@@ -9,8 +9,11 @@
 #ifndef QEMU_PROXY_H
 #define QEMU_PROXY_H
 
+#include <linux/kvm.h>
+
 #include "io/mpqemu-link.h"
 #include "hw/proxy/memory-sync.h"
+#include "qemu/event_notifier.h"
 
 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
 
@@ -44,6 +47,11 @@ struct PCIProxyDev {
     MPQemuLinkState *mpqemu_link;
 
     RemoteMemSync *sync;
+    struct kvm_irqfd irqfd;
+
+    EventNotifier intr;
+    EventNotifier resample;
+
     pid_t remote_pid;
     int socket;
 
include/io/mpqemu-link.h +8 -0
index 1a7738e..13c4b80 100644
@@ -40,6 +40,8 @@
  * SYNC_SYSMEM      Shares QEMU's RAM with remote device's RAM
  * BAR_WRITE        Writes to PCI BAR region
  * BAR_READ         Reads from PCI BAR region
+ * SET_IRQFD        Sets the IRQFD to be used to raise interrupts directly
+ *                  from remote device
  *
  * proc_cmd_t enum type to specify the command to be executed on the remote
  * device.
@@ -51,6 +53,7 @@ typedef enum {
     SYNC_SYSMEM,
     BAR_WRITE,
     BAR_READ,
+    SET_IRQFD,
     MAX,
 } mpqemu_cmd_t;
 
@@ -81,6 +84,10 @@ typedef struct {
 } bar_access_msg_t;
 
 typedef struct {
+    int intx;
+} set_irqfd_msg_t;
+
+typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
     size_t size;
@@ -89,6 +96,7 @@ typedef struct {
         uint64_t u64;
         sync_sysmem_msg_t sync_sysmem;
         bar_access_msg_t bar_access;
+        set_irqfd_msg_t set_irqfd;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
include/remote/iohub.h new file +50 -0

50 lines not on this page · raw message

include/remote/machine.h +2 -0
index 7e9bdbe..300394a 100644
@@ -16,11 +16,13 @@
 #include "hw/boards.h"
 #include "remote/pcihost.h"
 #include "qemu/notify.h"
+#include "remote/iohub.h"
 
 typedef struct RemMachineState {
     MachineState parent_obj;
 
     RemPCIHost *host;
+    RemoteIOHubState *iohub;
 } RemMachineState;
 
 #define TYPE_REMOTE_MACHINE "remote-machine"
remote/Makefile.objs +1 -0
index 13d4c48..cbb3065 100644
@@ -1,3 +1,4 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
 remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
+remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o
remote/iohub.c new file +148 -0

148 lines not on this page · raw message

remote/machine.c +15 -0
index 97e4f19..d529f68 100644
@@ -25,12 +25,16 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 #include "qemu/notify.h"
+#include "hw/pci/pci_host.h"
+#include "remote/iohub.h"
 
 static void remote_machine_init(Object *obj)
 {
     RemMachineState *s = REMOTE_MACHINE(obj);
     RemPCIHost *rem_host;
     MemoryRegion *system_memory, *system_io, *pci_memory;
+    PCIHostState *pci_host;
+    PCIDevice *pci_dev;
 
     Error *error_abort = NULL;
 
@@ -67,6 +71,17 @@ static void remote_machine_init(Object *obj)
     qemu_mutex_unlock_iothread();
 
     qdev_init_nofail(DEVICE(rem_host));
+
+    pci_host = PCI_HOST_BRIDGE(rem_host);
+    pci_dev = pci_create_simple_multifunction(pci_host->bus,
+                                              PCI_DEVFN(REMOTE_IOHUB_DEV,
+                                                        REMOTE_IOHUB_FUNC),
+                                              true, TYPE_REMOTE_IOHUB_DEVICE);
+
+    s->iohub = REMOTE_IOHUB_DEVICE(pci_dev);
+
+    pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq,
+                 s->iohub, REMOTE_IOHUB_NB_PIRQS);
 }
 
 static const TypeInfo remote_machine = {
remote/remote-main.c +4 -0
index 9512a3b..02d78a4 100644
@@ -35,6 +35,7 @@
 #include "exec/ramlist.h"
 #include "exec/memattrs.h"
 #include "exec/address-spaces.h"
+#include "remote/iohub.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -172,6 +173,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
             goto finalize_loop;
         }
         break;
+    case SET_IRQFD:
+        process_set_irqfd_msg(remote_pci_dev, msg);
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#44 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

Add functions to configure remote devices.

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

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

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

In reply to Jagannathan Raman

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

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

 hw/proxy/qemu-proxy.c    | 84 +++++++++++++++++++++++++++++++++++++++++++++++-
 include/io/mpqemu-link.h | 10 ++++++
 remote/remote-main.c     | 20 ++++++++++++
 3 files changed, 113 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +83 -1
index 3ba05d9..c888677 100644
@@ -26,12 +26,91 @@
 
 static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp);
 static void setup_irqfd(PCIProxyDev *dev);
+static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l,
+                          unsigned int op);
+
+static void probe_pci_info(PCIDevice *dev)
+{
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
+    DeviceClass *dc = DEVICE_CLASS(pc);
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+    MPQemuLinkState *mpqemu_link = pdev->mpqemu_link;
+    MPQemuMsg msg, ret;
+    uint32_t orig_val, new_val, class;
+    uint8_t type;
+    int i, size;
+    char *name;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+    msg.bytestream = 0;
+    msg.size = 0;
+    msg.cmd = GET_PCI_INFO;
+    mpqemu_msg_send(&msg, mpqemu_link->com);
+
+    mpqemu_msg_recv(&ret, mpqemu_link->com);
+
+    pc->vendor_id = ret.data1.ret_pci_info.vendor_id;
+    pc->device_id = ret.data1.ret_pci_info.device_id;
+    pc->class_id = ret.data1.ret_pci_info.class_id;
+    pc->subsystem_id = ret.data1.ret_pci_info.subsystem_id;
+
+    config_op_send(pdev, 11, &class, 1, PCI_CONFIG_READ);
+    switch (class) {
+    case PCI_BASE_CLASS_BRIDGE:
+        set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
+        break;
+    case PCI_BASE_CLASS_STORAGE:
+        set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+        break;
+    case PCI_BASE_CLASS_NETWORK:
+        set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
+        break;
+    case PCI_BASE_CLASS_INPUT:
+        set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+        break;
+    case PCI_BASE_CLASS_DISPLAY:
+        set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
+        break;
+    case PCI_BASE_CLASS_PROCESSOR:
+        set_bit(DEVICE_CATEGORY_CPU, dc->categories);
+        break;
+    default:
+        set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+        break;
+    }
+
+    for (i = 0; i < 6; i++) {
+        config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_READ);
+        new_val = 0xffffffff;
+        config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_WRITE);
+        config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_READ);
+        size = (~(new_val & 0xFFFFFFF0)) + 1;
+        config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_WRITE);
+        type = (new_val & 0x1) ?
+                   PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY;
+
+        if (size) {
+            pdev->region[i].dev = pdev;
+            pdev->region[i].present = true;
+            if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) {
+                pdev->region[i].memory = true;
+            }
+            name = g_strdup_printf("bar-region-%d", i);
+            memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev),
+                                  &proxy_default_ops, &pdev->region[i],
+                                  name, size);
+            pci_register_bar(dev, i, type, &pdev->region[i].mr);
+            g_free(name);
+        }
+    }
+}
 
 static void proxy_ready(PCIDevice *dev)
 {
     PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
 
     setup_irqfd(pdev);
+    probe_pci_info(dev);
 }
 
 static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd)
@@ -254,7 +333,6 @@ static const TypeInfo pci_proxy_dev_type_info = {
     .name          = TYPE_PCI_PROXY_DEV,
     .parent        = TYPE_PCI_DEVICE,
     .instance_size = sizeof(PCIProxyDev),
-    .abstract      = true,
     .class_size    = sizeof(PCIProxyDevClass),
     .class_init    = pci_proxy_dev_class_init,
     .interfaces = (InterfaceInfo[]) {
@@ -355,8 +433,12 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)
 {
     PCIProxyDev *dev = PCI_PROXY_DEV(device);
     PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev);
+    uint8_t *pci_conf = device->config;
     Error *local_err = NULL;
 
+    pci_conf[PCI_LATENCY_TIMER] = 0xff;
+    pci_conf[PCI_INTERRUPT_PIN] = 0x01;
+
     if (k->realize) {
         k->realize(dev, &local_err);
         if (local_err) {
include/io/mpqemu-link.h +10 -0
index 90a8437..2ca89c5 100644
@@ -58,6 +58,8 @@ typedef enum {
     DRIVE_OPTS,
     DEVICE_ADD,
     DEVICE_DEL,
+    GET_PCI_INFO,
+    RET_PCI_INFO,
     MAX,
 } mpqemu_cmd_t;
 
@@ -96,6 +98,13 @@ typedef struct {
     int intx;
 } set_irqfd_msg_t;
 
+ typedef struct {
+    uint16_t vendor_id;
+    uint16_t device_id;
+    uint16_t class_id;
+    uint16_t subsystem_id;
+} ret_pci_info_msg_t;
+
 typedef struct {
     mpqemu_cmd_t cmd;
     int bytestream;
@@ -106,6 +115,7 @@ typedef struct {
         sync_sysmem_msg_t sync_sysmem;
         bar_access_msg_t bar_access;
         set_irqfd_msg_t set_irqfd;
+        ret_pci_info_msg_t ret_pci_info;
     } data1;
 
     int fds[REMOTE_MAX_FDS];
remote/remote-main.c +20 -0
index 02d78a4..0f830b8 100644
@@ -126,6 +126,23 @@ fail:
     PUT_REMOTE_WAIT(wait);
 }
 
+static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg)
+{
+    PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
+    MPQemuMsg ret = { 0 };
+
+    ret.cmd = RET_PCI_INFO;
+
+    ret.data1.ret_pci_info.vendor_id = pc->vendor_id;
+    ret.data1.ret_pci_info.device_id = pc->device_id;
+    ret.data1.ret_pci_info.class_id = pc->class_id;
+    ret.data1.ret_pci_info.subsystem_id = pc->subsystem_id;
+
+    ret.size = sizeof(ret.data1);
+
+    mpqemu_msg_send(&ret, mpqemu_link->com);
+}
+
 static void process_msg(GIOCondition cond, MPQemuChannel *chan)
 {
     MPQemuMsg *msg = NULL;
@@ -145,6 +162,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
     switch (msg->cmd) {
     case INIT:
         break;
+    case GET_PCI_INFO:
+        process_get_pci_info_msg(remote_pci_dev, msg);
+        break;
     case PCI_CONFIG_WRITE:
         process_config_write(msg);
         break;
Signature · 1 line
1.8.3.1
#46 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

263 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#47 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

205 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#48 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

In reply to Jagannathan Raman

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

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

139 lines not on this page · raw message

vl-parse.c new file +130 -0

130 lines not on this page · raw message

vl.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#53 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

135 lines not on this page · raw message

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

---
 remote/Makefile.objs |  1 +
 remote/remote-main.c | 11 ++++++
 remote/remote-opts.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 remote/remote-opts.h | 15 ++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 remote/remote-opts.c
 create mode 100644 remote/remote-opts.h
remote/Makefile.objs +1 -0
index c1349ad..a677fce 100644
@@ -1,4 +1,5 @@
 remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
+remote-pci-obj-$(CONFIG_MPQEMU) += remote-opts.o
 remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
 remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
 remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o
remote/remote-main.c +11 -0
index ec1ce2c..872ff7e 100644
@@ -52,6 +52,7 @@
 #include "qapi/qmp/qlist.h"
 #include "qemu/log.h"
 #include "qemu/cutils.h"
+#include "remote-opts.h"
 
 static MPQemuLinkState *mpqemu_link;
 PCIDevice *remote_pci_dev;
@@ -429,6 +430,13 @@ int main(int argc, char *argv[])
 
     current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE)));
 
+    qemu_add_opts(&qemu_device_opts);
+    qemu_add_opts(&qemu_drive_opts);
+    qemu_add_drive_opts(&qemu_legacy_drive_opts);
+    qemu_add_drive_opts(&qemu_common_drive_opts);
+    qemu_add_drive_opts(&qemu_drive_opts);
+    qemu_add_drive_opts(&bdrv_runtime_opts);
+
     mpqemu_link = mpqemu_link_create();
     if (!mpqemu_link) {
         printf("Could not create MPQemu link\n");
@@ -442,6 +450,9 @@ int main(int argc, char *argv[])
     }
 
     mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd);
+
+    parse_cmdline(argc - 2, argv + 2, NULL);
+
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
     mpqemu_start_coms(mpqemu_link);
remote/remote-opts.c new file +99 -0

99 lines not on this page · raw message

remote/remote-opts.h new file +15 -0
new file mode 100644
index 0000000..263d428
@@ -0,0 +1,15 @@
+/*
+ * Copyright © 2018, 2020 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef REMOTE_OPTS_H
+#define REMOTE_OPTS_H
+
+void parse_cmdline(int argc, char **argv, char **envp);
+
+#endif
+
Signature · 1 line
1.8.3.1
#56 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

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

In reply to Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

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

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

This went unanswered in the last revision:

Quoted 41 lines · Stefan Hajnoczi
Quoted 7 lines · Jag Raman
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

Why?

Quoted 8 lines

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

author
#60 lore raw

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

Quoted 42 lines · Stefan Hajnoczi

This went unanswered in the last revision:

Quoted 39 lines · Stefan Hajnoczi
Quoted 7 lines · Jag Raman
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman

Using a separate communication channel for MMIO helps with improving Performance

Why?

Quoted 8 lines

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

Quoted 2 lines
Quoted 2 lines

Stefan

#61 lore raw

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

In reply to Jagannathan Raman

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

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

 hw/proxy/qemu-proxy.c    | 25 +++++++++++++++++++++++++
 include/io/mpqemu-link.h |  1 +
 remote/remote-main.c     | 14 ++++++++++++++
 3 files changed, 40 insertions(+)
hw/proxy/qemu-proxy.c +25 -0
index 68517aa..741f02a 100644
@@ -431,14 +431,39 @@ static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,
     config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE);
 }
 
+static void proxy_device_reset(DeviceState *dev)
+{
+    PCIProxyDev *pdev = PCI_PROXY_DEV(dev);
+    MPQemuMsg msg;
+    int wait = -1;
+
+    memset(&msg, 0, sizeof(MPQemuMsg));
+
+    msg.bytestream = 0;
+    msg.size = sizeof(msg.data1);
+    msg.cmd = DEVICE_RESET;
+
+    wait = eventfd(0, EFD_CLOEXEC);
+    msg.num_fds = 1;
+    msg.fds[0] = wait;
+
+    mpqemu_msg_send(&msg, pdev->mpqemu_link->com);
+
+    wait_for_remote(wait);
+    close(wait);
+}
+
 static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)
 {
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
 
     k->realize = pci_proxy_dev_realize;
     k->exit = pci_dev_exit;
     k->config_read = pci_proxy_read_config;
     k->config_write = pci_proxy_write_config;
+
+    dc->reset = proxy_device_reset;
 }
 
 static const TypeInfo pci_proxy_dev_type_info = {
include/io/mpqemu-link.h +1 -0
index 3962630..d2234ca 100644
@@ -62,6 +62,7 @@ typedef enum {
     RET_PCI_INFO,
     PROXY_PING,
     MMIO_RETURN,
+    DEVICE_RESET,
     MAX,
 } mpqemu_cmd_t;
 
remote/remote-main.c +14 -0
index 6cfc446..5284ee9 100644
@@ -53,8 +53,11 @@
 #include "qemu/log.h"
 #include "qemu/cutils.h"
 #include "remote-opts.h"
+#include "monitor/monitor.h"
+#include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
+
 PCIDevice *remote_pci_dev;
 bool create_done;
 
@@ -241,6 +244,11 @@ fail:
     PUT_REMOTE_WAIT(wait);
 }
 
+static void process_device_reset_msg(MPQemuMsg *msg)
+{
+    qemu_devices_reset();
+}
+
 static int setup_device(MPQemuMsg *msg, Error **errp)
 {
     QObject *obj;
@@ -395,6 +403,12 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)
         wait = msg->fds[0];
         notify_proxy(wait, (uint32_t)getpid());
         break;
+    case DEVICE_RESET:
+        process_device_reset_msg(msg);
+        if (msg->num_fds == 1) {
+            notify_proxy(msg->fds[0], 0);
+        }
+        break;
     default:
         error_setg(&err, "Unknown command");
         goto finalize_loop;
Signature · 1 line
1.8.3.1
#62 lore raw

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

In reply to Jagannathan Raman

From: Elena Ufimtseva <[email protected]>

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

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

65 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#63 lore raw

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

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

From: Elena Ufimtseva <[email protected]>

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

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

hmp-commands-info.hx ETEXI · line 52

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

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

Quoted 254 lines
hmp-commands-info.hx +8 -0
         .flags      = "p",
     },
 
@@ -64,6 +66,7 @@ ETEXI
         .help       = "show info of one block device or all block devices "
                       "(-n: show named nodes; -v: show details)",
         .cmd        = hmp_info_block,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -78,6 +81,7 @@ ETEXI
         .params     = "",
         .help       = "show block device statistics",
         .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -92,6 +96,7 @@ ETEXI
         .params     = "",
         .help       = "show progress of ongoing block device operations",
         .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -167,6 +172,7 @@ ETEXI
         .params     = "",
         .help       = "show the command line history",
         .cmd        = hmp_info_history,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -224,6 +230,7 @@ ETEXI
         .params     = "",
         .help       = "show PCI info",
         .cmd        = hmp_info_pci,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -630,6 +637,7 @@ ETEXI
         .params     = "",
         .help       = "show device tree",
         .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -644,6 +652,7 @@ ETEXI
         .params     = "",
         .help       = "show qdev device model list",
         .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -658,6 +667,7 @@ ETEXI
         .params     = "[path]",
         .help       = "show QOM composition tree",
         .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
         .params     = "",
         .help       = "quit the emulator",
         .cmd        = hmp_quit,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -82,6 +83,7 @@ ETEXI
         .params     = "device size",
         .help       = "resize a block image",
         .cmd        = hmp_block_resize,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -99,6 +101,7 @@ ETEXI
         .params     = "device [speed [base]]",
         .help       = "copy data from a backing file into a block device",
         .cmd        = hmp_block_stream,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -113,6 +116,7 @@ ETEXI
         .params     = "device speed",
         .help       = "set maximum speed for a background block operation",
         .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -129,6 +133,7 @@ ETEXI
                       "\n\t\t\t if you want to abort the operation immediately"
                       "\n\t\t\t instead of keep running until data is in sync)",
         .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -143,6 +148,7 @@ ETEXI
         .params     = "device",
         .help       = "stop an active background block operation",
         .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -158,6 +164,7 @@ ETEXI
         .params     = "device",
         .help       = "pause an active background block operation",
         .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -172,6 +179,7 @@ ETEXI
         .params     = "device",
         .help       = "resume a paused background block operation",
         .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -186,6 +194,7 @@ ETEXI
         .params     = "[-f] device",
         .help       = "eject a removable medium (use -f to force it)",
         .cmd        = hmp_eject,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -200,6 +209,7 @@ ETEXI
         .params     = "device",
         .help       = "remove host block device",
         .cmd        = hmp_drive_del,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -219,6 +229,7 @@ ETEXI
         .params     = "device filename [format [read-only-mode]]",
         .help       = "change a removable medium, optional format",
         .cmd        = hmp_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -732,6 +743,7 @@ ETEXI
         .help       = "add device, like -device on the command line",
         .cmd        = hmp_device_add,
         .command_completion = device_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -747,6 +759,7 @@ ETEXI
         .help       = "remove device",
         .cmd        = hmp_device_del,
         .command_completion = device_del_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                       "The -c flag requests QEMU to compress backup data\n\t\t\t"
                       "(if the target format supports it).\n\t\t\t",
         .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
     },
 STEXI
 @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                       "[,readonly=on|off][,copy-on-read=on|off]",
         .help       = "add drive to PCI storage controller",
         .cmd        = hmp_drive_add,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1816,6 +1831,7 @@ ETEXI
         .help       = "add chardev",
         .cmd        = hmp_chardev_add,
         .command_completion = chardev_add_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1831,6 +1847,7 @@ ETEXI
         .params     = "id args",
         .help       = "change chardev",
         .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1848,6 +1865,7 @@ ETEXI
         .help       = "remove chardev",
         .cmd        = hmp_chardev_remove,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1864,6 +1882,7 @@ ETEXI
         .help       = "send a break on chardev",
         .cmd        = hmp_chardev_send_break,
         .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
     },
 
 STEXI
@@ -1940,6 +1959,7 @@ ETEXI
         .params     = "[subcommand]",
         .help       = "show various information about the system state",
         .cmd        = hmp_info_help,
+        .targets    = "scsi",
         .sub_table  = hmp_info_cmds,
         .flags      = "p",
     },
scripts/hxtool +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
             STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
             ;;
             *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
             ;;
         esac
     done

scripts/hxtool hxtotexi() · line 96

Quoted 7 lines
scripts/hxtool +3 -1
@@ -84,16 +91,49 @@ hxtotexi()
             print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
             ;;
             *)
-            test $flag -eq 1 && printf '%s\n' "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targetss'

One extra 's' ?

Quoted 46 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
             ;;
         esac
         line=$((line+1))
     done
 }
 
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
+            ;;
+        esac
+    done
+}
+
 case "$1" in
 "-h") hxtoh ;;
 "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
 *) exit 1 ;;
 esac
 
Signature · 1 line
1.8.3.1

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

author
#64 lore raw

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

Quoted 28 lines · Dr. David Alan Gilbert
Quoted 27 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

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

---
  hmp-commands-info.hx | 10 ++++++++++
  hmp-commands.hx      | 20 ++++++++++++++++++++
  scripts/hxtool       | 44 ++++++++++++++++++++++++++++++++++++++++++--
  3 files changed, 72 insertions(+), 2 deletions(-)

mode change 100644 => 100755 scripts/hxtool

hmp-commands-info.hx +1 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
          .params     = "",
          .help       = "show the version of QEMU",
          .cmd        = hmp_info_version,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
Quoted 9 lines

hmp-commands-info.hx ETEXI · line 52

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

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

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.

Quoted 256 lines
Quoted 256 lines
hmp-commands-info.hx +8 -0
          .flags      = "p",
      },
 
@@ -64,6 +66,7 @@ ETEXI
          .help       = "show info of one block device or all block devices "
                        "(-n: show named nodes; -v: show details)",
          .cmd        = hmp_info_block,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -78,6 +81,7 @@ ETEXI
          .params     = "",
          .help       = "show block device statistics",
          .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -92,6 +96,7 @@ ETEXI
          .params     = "",
          .help       = "show progress of ongoing block device operations",
          .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -167,6 +172,7 @@ ETEXI
          .params     = "",
          .help       = "show the command line history",
          .cmd        = hmp_info_history,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
@@ -224,6 +230,7 @@ ETEXI
          .params     = "",
          .help       = "show PCI info",
          .cmd        = hmp_info_pci,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -630,6 +637,7 @@ ETEXI
          .params     = "",
          .help       = "show device tree",
          .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -644,6 +652,7 @@ ETEXI
          .params     = "",
          .help       = "show qdev device model list",
          .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -658,6 +667,7 @@ ETEXI
          .params     = "[path]",
          .help       = "show QOM composition tree",
          .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
          .params     = "",
          .help       = "quit the emulator",
          .cmd        = hmp_quit,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -82,6 +83,7 @@ ETEXI
          .params     = "device size",
          .help       = "resize a block image",
          .cmd        = hmp_block_resize,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -99,6 +101,7 @@ ETEXI
          .params     = "device [speed [base]]",
          .help       = "copy data from a backing file into a block device",
          .cmd        = hmp_block_stream,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -113,6 +116,7 @@ ETEXI
          .params     = "device speed",
          .help       = "set maximum speed for a background block operation",
          .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -129,6 +133,7 @@ ETEXI
                        "\n\t\t\t if you want to abort the operation immediately"
                        "\n\t\t\t instead of keep running until data is in sync)",
          .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -143,6 +148,7 @@ ETEXI
          .params     = "device",
          .help       = "stop an active background block operation",
          .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -158,6 +164,7 @@ ETEXI
          .params     = "device",
          .help       = "pause an active background block operation",
          .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -172,6 +179,7 @@ ETEXI
          .params     = "device",
          .help       = "resume a paused background block operation",
          .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -186,6 +194,7 @@ ETEXI
          .params     = "[-f] device",
          .help       = "eject a removable medium (use -f to force it)",
          .cmd        = hmp_eject,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -200,6 +209,7 @@ ETEXI
          .params     = "device",
          .help       = "remove host block device",
          .cmd        = hmp_drive_del,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -219,6 +229,7 @@ ETEXI
          .params     = "device filename [format [read-only-mode]]",
          .help       = "change a removable medium, optional format",
          .cmd        = hmp_change,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -732,6 +743,7 @@ ETEXI
          .help       = "add device, like -device on the command line",
          .cmd        = hmp_device_add,
          .command_completion = device_add_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -747,6 +759,7 @@ ETEXI
          .help       = "remove device",
          .cmd        = hmp_device_del,
          .command_completion = device_del_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                        "The -c flag requests QEMU to compress backup data\n\t\t\t"
                        "(if the target format supports it).\n\t\t\t",
          .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
      },
  STEXI
  @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                        "[,readonly=on|off][,copy-on-read=on|off]",
          .help       = "add drive to PCI storage controller",
          .cmd        = hmp_drive_add,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1816,6 +1831,7 @@ ETEXI
          .help       = "add chardev",
          .cmd        = hmp_chardev_add,
          .command_completion = chardev_add_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1831,6 +1847,7 @@ ETEXI
          .params     = "id args",
          .help       = "change chardev",
          .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1848,6 +1865,7 @@ ETEXI
          .help       = "remove chardev",
          .cmd        = hmp_chardev_remove,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1864,6 +1882,7 @@ ETEXI
          .help       = "send a break on chardev",
          .cmd        = hmp_chardev_send_break,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
 
  STEXI
@@ -1940,6 +1959,7 @@ ETEXI
          .params     = "[subcommand]",
          .help       = "show various information about the system state",
          .cmd        = hmp_info_help,
+        .targets    = "scsi",
          .sub_table  = hmp_info_cmds,
          .flags      = "p",
      },
scripts/hxtool +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
              STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
              ;;
              *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
              ;;
          esac
      done
@@ -84,16 +91,49 @@ hxtotexi()
              print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
Quoted 8 lines

scripts/hxtool hxtotexi() · line 96

Quoted 6 lines
scripts/hxtool +3 -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 '.targetss'

One extra 's' ?

Thanks, we'll fix it.

--
Jag

Quoted 50 lines
Quoted 47 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
              ;;
          esac
          line=$((line+1))
      done
  }
 
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
+            ;;
+        esac
+    done
+}
+
  case "$1" in
  "-h") hxtoh ;;
  "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
  *) exit 1 ;;
  esac
 
Signature · 1 line
1.8.3.1

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

#65 lore raw

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

Quoted 40 lines · * Jag Raman ([email protected]) wrote:
Quoted 28 lines · Dr. David Alan Gilbert
Quoted 27 lines · * Jagannathan Raman ([email protected]) wrote:

From: Elena Ufimtseva <[email protected]>

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

---
  hmp-commands-info.hx | 10 ++++++++++
  hmp-commands.hx      | 20 ++++++++++++++++++++
  scripts/hxtool       | 44 ++++++++++++++++++++++++++++++++++++++++++--
  3 files changed, 72 insertions(+), 2 deletions(-)

mode change 100644 => 100755 scripts/hxtool

hmp-commands-info.hx +1 -0
index 257ee7d..631cc76 100644
@@ -19,6 +19,7 @@ ETEXI
          .params     = "",
          .help       = "show the version of QEMU",
          .cmd        = hmp_info_version,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -48,6 +49,7 @@ ETEXI
Quoted 8 lines

hmp-commands-info.hx ETEXI · line 52

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

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

Quoted 3 lines

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.

Quoted 238 lines
Quoted 229 lines
Quoted 229 lines
hmp-commands-info.hx +8 -0
          .flags      = "p",
      },
@@ -64,6 +66,7 @@ ETEXI
          .help       = "show info of one block device or all block devices "
                        "(-n: show named nodes; -v: show details)",
          .cmd        = hmp_info_block,
+        .targets    = "scsi",
      },
  STEXI
@@ -78,6 +81,7 @@ ETEXI
          .params     = "",
          .help       = "show block device statistics",
          .cmd        = hmp_info_blockstats,
+        .targets    = "scsi",
      },
  STEXI
@@ -92,6 +96,7 @@ ETEXI
          .params     = "",
          .help       = "show progress of ongoing block device operations",
          .cmd        = hmp_info_block_jobs,
+        .targets    = "scsi",
      },
  STEXI
@@ -167,6 +172,7 @@ ETEXI
          .params     = "",
          .help       = "show the command line history",
          .cmd        = hmp_info_history,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -224,6 +230,7 @@ ETEXI
          .params     = "",
          .help       = "show PCI info",
          .cmd        = hmp_info_pci,
+        .targets    = "scsi",
      },
  STEXI
@@ -630,6 +637,7 @@ ETEXI
          .params     = "",
          .help       = "show device tree",
          .cmd        = hmp_info_qtree,
+        .targets    = "scsi",
      },
  STEXI
@@ -644,6 +652,7 @@ ETEXI
          .params     = "",
          .help       = "show qdev device model list",
          .cmd        = hmp_info_qdm,
+        .targets    = "scsi",
      },
  STEXI
@@ -658,6 +667,7 @@ ETEXI
          .params     = "[path]",
          .help       = "show QOM composition tree",
          .cmd        = hmp_info_qom_tree,
+        .targets    = "scsi",
          .flags      = "p",
      },
hmp-commands.hx +20 -0
index dc23185..ecc6169 100644
@@ -49,6 +49,7 @@ ETEXI
          .params     = "",
          .help       = "quit the emulator",
          .cmd        = hmp_quit,
+        .targets    = "scsi",
      },
  STEXI
@@ -82,6 +83,7 @@ ETEXI
          .params     = "device size",
          .help       = "resize a block image",
          .cmd        = hmp_block_resize,
+        .targets    = "scsi",
      },
  STEXI
@@ -99,6 +101,7 @@ ETEXI
          .params     = "device [speed [base]]",
          .help       = "copy data from a backing file into a block device",
          .cmd        = hmp_block_stream,
+        .targets    = "scsi",
      },
  STEXI
@@ -113,6 +116,7 @@ ETEXI
          .params     = "device speed",
          .help       = "set maximum speed for a background block operation",
          .cmd        = hmp_block_job_set_speed,
+        .targets    = "scsi",
      },
  STEXI
@@ -129,6 +133,7 @@ ETEXI
                        "\n\t\t\t if you want to abort the operation immediately"
                        "\n\t\t\t instead of keep running until data is in sync)",
          .cmd        = hmp_block_job_cancel,
+        .targets    = "scsi",
      },
  STEXI
@@ -143,6 +148,7 @@ ETEXI
          .params     = "device",
          .help       = "stop an active background block operation",
          .cmd        = hmp_block_job_complete,
+        .targets    = "scsi",
      },
  STEXI
@@ -158,6 +164,7 @@ ETEXI
          .params     = "device",
          .help       = "pause an active background block operation",
          .cmd        = hmp_block_job_pause,
+        .targets    = "scsi",
      },
  STEXI
@@ -172,6 +179,7 @@ ETEXI
          .params     = "device",
          .help       = "resume a paused background block operation",
          .cmd        = hmp_block_job_resume,
+        .targets    = "scsi",
      },
  STEXI
@@ -186,6 +194,7 @@ ETEXI
          .params     = "[-f] device",
          .help       = "eject a removable medium (use -f to force it)",
          .cmd        = hmp_eject,
+        .targets    = "scsi",
      },
  STEXI
@@ -200,6 +209,7 @@ ETEXI
          .params     = "device",
          .help       = "remove host block device",
          .cmd        = hmp_drive_del,
+        .targets    = "scsi",
      },
  STEXI
@@ -219,6 +229,7 @@ ETEXI
          .params     = "device filename [format [read-only-mode]]",
          .help       = "change a removable medium, optional format",
          .cmd        = hmp_change,
+        .targets    = "scsi",
      },
  STEXI
@@ -732,6 +743,7 @@ ETEXI
          .help       = "add device, like -device on the command line",
          .cmd        = hmp_device_add,
          .command_completion = device_add_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -747,6 +759,7 @@ ETEXI
          .help       = "remove device",
          .cmd        = hmp_device_del,
          .command_completion = device_del_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1351,6 +1364,7 @@ ETEXI
                        "The -c flag requests QEMU to compress backup data\n\t\t\t"
                        "(if the target format supports it).\n\t\t\t",
          .cmd        = hmp_drive_backup,
+        .targets    = "scsi",
      },
  STEXI
  @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI
                        "[,readonly=on|off][,copy-on-read=on|off]",
          .help       = "add drive to PCI storage controller",
          .cmd        = hmp_drive_add,
+        .targets    = "scsi",
      },
  STEXI
@@ -1816,6 +1831,7 @@ ETEXI
          .help       = "add chardev",
          .cmd        = hmp_chardev_add,
          .command_completion = chardev_add_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1831,6 +1847,7 @@ ETEXI
          .params     = "id args",
          .help       = "change chardev",
          .cmd        = hmp_chardev_change,
+        .targets    = "scsi",
      },
  STEXI
@@ -1848,6 +1865,7 @@ ETEXI
          .help       = "remove chardev",
          .cmd        = hmp_chardev_remove,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1864,6 +1882,7 @@ ETEXI
          .help       = "send a break on chardev",
          .cmd        = hmp_chardev_send_break,
          .command_completion = chardev_remove_completion,
+        .targets    = "scsi",
      },
  STEXI
@@ -1940,6 +1959,7 @@ ETEXI
          .params     = "[subcommand]",
          .help       = "show various information about the system state",
          .cmd        = hmp_info_help,
+        .targets    = "scsi",
          .sub_table  = hmp_info_cmds,
          .flags      = "p",
      },
scripts/hxtool +8 -1
old mode 100644
new mode 100755
index 0003e7b..802cbd4
@@ -10,7 +10,14 @@ hxtoh()
              STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1))
              ;;
              *)
-            test $flag -eq 1 && printf "%s\n" "$str"
+            # Skip line that has ".targets" as it is for multi-process targets based hmp
+            # commands generation.
+            echo $str | grep -q '.targets'
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf "%s\n" "$str"
+            fi
              ;;
          esac
      done
@@ -84,16 +91,49 @@ hxtotexi()
              print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")"
Quoted 8 lines

scripts/hxtool hxtotexi() · line 96

Quoted 6 lines
scripts/hxtool +3 -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 '.targetss'

One extra 's' ?

Quoted 54 lines

Thanks, we'll fix it.

--
Jag

Quoted 48 lines
Quoted 45 lines
scripts/hxtool +31 -0
+            if [ $? -eq 0 ]; then
+                continue
+            else
+                test $flag -eq 1 && printf '%s\n' "$str"
+            fi
              ;;
          esac
          line=$((line+1))
      done
  }
+hxtoh_tgt()
+{
+    section=""
+    flag=1
+    use_section=0
+    while read -r str; do
+        # Print section if it has ".targets" and the second argument passed to the
+        # script, such as "scsi".
+        echo "$str" | grep -q -E ".targets.*$1"
+        if [ $? -eq 0 ]; then
+            use_section=1
+            continue
+        fi
+        case $str in
+            HXCOMM*)
+            ;;
+            STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0
+            ;;
+            *)
+            test $flag -eq 1 && section="${section} ${str} ${IFS}"
+            ;;
+        esac
+    done
+}
+
  case "$1" in
  "-h") hxtoh ;;
  "-t") hxtotexi ;;
+"-tgt") hxtoh_tgt $2 ;;
  *) exit 1 ;;
  esac
Signature · 1 line
1.8.3.1

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

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

#66 lore raw

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

In reply to Jagannathan Raman

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

---
 accel/stubs/tcg-stub.c |  10 +++
 configure              |   4 ++
 include/qemu-common.h  |   8 +++
 stubs/gdbstub.c        |  23 +++++++
 stubs/migration.c      | 162 +++++++++++++++++++++++++++++++++++++++++++++++++
 stubs/monitor.c        |  31 ++++++++++
 stubs/net-stub.c       |  69 +++++++++++++++++++++
 stubs/qapi-misc.c      |  41 +++++++++++++
 stubs/qapi-target.c    |  55 +++++++++++++++++
 stubs/ui-stub.c        | 130 +++++++++++++++++++++++++++++++++++++++
 stubs/vl-stub.c        |  92 ++++++++++++++++++++++++++++
 11 files changed, 625 insertions(+)
 create mode 100644 stubs/migration.c
 create mode 100644 stubs/qapi-misc.c
 create mode 100644 stubs/qapi-target.c
 create mode 100644 stubs/ui-stub.c
accel/stubs/tcg-stub.c +10 -0
index 9b55fb0..c2d72fe 100644
@@ -119,3 +119,13 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)
 void page_collection_unlock(struct page_collection *set)
 {
 }
+
+void dump_exec_info(void)
+{
+    qemu_debug_assert(0);
+}
+
+void dump_opcount_info(void)
+{
+    qemu_debug_assert(0);
+}
configure +4 -0
index ab1e344..53a2a4b 100755
@@ -7512,6 +7512,10 @@ if test "$mpqemu" = "yes" ; then
   echo "CONFIG_MPQEMU=y" >> $config_host_mak
 fi
 
+if test "$debug" = "yes" ; then
+  echo "CONFIG_DEBUG=y" >> $config_host_mak
+fi
+
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
include/qemu-common.h +8 -0
index 082da59..09da824 100644
@@ -10,6 +10,8 @@
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
 
+#include <assert.h>
+
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /* Copyright string for -version arguments, About dialogs, etc */
@@ -135,4 +137,10 @@ void page_size_init(void);
  * returned. */
 bool dump_in_progress(void);
 
+#ifdef CONFIG_DEBUG
+#define qemu_debug_assert(x) assert(x)
+#else
+#define qemu_debug_assert(x)
+#endif
+
 #endif
stubs/gdbstub.c +23 -0
index 2b7aee5..1e65b54 100644
@@ -1,6 +1,29 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "exec/gdbstub.h"       /* xml_builtin */
 
+#pragma weak gdbserver_start
+
 const char *const xml_builtin[][2] = {
   { NULL, NULL }
 };
+
+#ifdef CONFIG_USER_ONLY
+
+int gdbserver_start(int port)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+#else
+
+int gdbserver_start(const char *device)
+{
+    qemu_debug_assert(0);
+
+    return -ENOSYS;
+}
+
+#endif
stubs/migration.c new file +162 -0

162 lines not on this page · raw message

stubs/monitor.c +31 -0
index a34dc87..190445c 100644
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu-common.h"
 #include "qapi/error.h"
 #include "qapi/qapi-emit-events.h"
 #include "monitor/monitor.h"
@@ -10,6 +11,24 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/runstate.h"
 #include "monitor/hmp.h"
+#include "monitor/qdev.h"
+#include "sysemu/blockdev.h"
+#include "sysemu/sysemu.h"
+
+#include "qapi/qapi-types-block-core.h"
+#include "qapi/qapi-commands-block-core.h"
+
+#pragma weak cur_mon
+#pragma weak monitor_vprintf
+#pragma weak monitor_get_fd
+#pragma weak monitor_init
+#pragma weak qapi_event_emit
+#pragma weak monitor_get_cpu_index
+#pragma weak monitor_printf
+#pragma weak monitor_cur_is_qmp
+#pragma weak qmp_device_list_properties
+#pragma weak monitor_init_qmp
+#pragma weak monitor_init_hmp
 
 __thread Monitor *cur_mon;
 
@@ -17,11 +36,13 @@ __thread Monitor *cur_mon;
 
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+    qemu_debug_assert(0);
     abort();
 }
 
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
+    qemu_debug_assert(0);
     error_setg(errp, "only QEMU supports file descriptor passing");
     return -1;
 }
@@ -32,29 +53,39 @@ void monitor_init_qmp(Chardev *chr, bool pretty)
 
 void monitor_init_hmp(Chardev *chr, bool use_readline)
 {
+    qemu_debug_assert(0);
 }
 
 void qapi_event_emit(QAPIEvent event, QDict *qdict)
 {
+    qemu_debug_assert(0);
 }
 
 int monitor_get_cpu_index(void)
 {
+    qemu_debug_assert(0);
+
     return -ENOSYS;
 }
 int monitor_printf(Monitor *mon, const char *fmt, ...)
 {
+    qemu_debug_assert(0);
+
     return -ENOSYS;
 }
 
 bool monitor_cur_is_qmp(void)
 {
+    qemu_debug_assert(0);
+
     return false;
 }
 
 ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
                                                    Error **errp)
 {
+    qemu_debug_assert(0);
+
     return NULL;
 }
 
stubs/net-stub.c +69 -0

78 lines not on this page · raw message

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

41 lines not on this page · raw message

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

55 lines not on this page · raw message

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

130 lines not on this page · raw message

stubs/vl-stub.c +92 -0

113 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#67 lore raw

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

In reply to Jagannathan Raman

Build system changes to enable QMP module in the remote process

---
 Makefile.objs              |  9 +++++
 Makefile.target            | 35 +++++++++++++++++--
 hmp-commands.hx            |  5 +--
 hw/core/Makefile.objs      |  1 +
 monitor/Makefile.objs      |  4 +++
 monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++++
 qapi/Makefile.objs         |  2 ++
 qom/Makefile.objs          |  1 +
 ui/Makefile.objs           |  2 ++
 10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
 remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
 # remote-lsi-obj-y is code used to implement remote LSI device
 
 remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
 #######################################################################
 # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
 #######################################################################
 # Target-independent parts used in system and user emulation
 common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
 endif
 
 #########################################################
@@ -203,6 +222,10 @@ endif
 generated-files-y += hmp-commands.h hmp-commands-info.h
 generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
 endif # CONFIG_SOFTMMU
 
 dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
 hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
 clean: clean-target
 	rm -f *.a *~ $(PROGS)
 	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
 	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 ifdef CONFIG_TRACE_SYSTEMTAP
 	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
         .args_type  = "name:S?",
         .params     = "[cmd]",
         .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -618,7 +619,7 @@ ETEXI
         .args_type  = "fmt:/,val:l",
         .params     = "/fmt expr",
         .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
     },
 
 STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
 remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
 remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
 remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
 common-obj-y += monitor.o qmp.o hmp.o
 common-obj-y += qmp-cmds.o qmp-cmds-control.o
 common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38

322 lines not on this page · raw message

monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
 void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                  Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
 #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
 obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
 obj-y += qapi-commands.o
 obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 
 remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
 remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
 egl-helpers.o-libs += $(OPENGL_LIBS)
 egl-context.o-libs += $(OPENGL_LIBS)
 egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1
#68 lore raw

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

Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

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

Dave

Quoted 602 lines
---
 Makefile.objs              |  9 +++++
 Makefile.target            | 35 +++++++++++++++++--
 hmp-commands.hx            |  5 +--
 hw/core/Makefile.objs      |  1 +
 monitor/Makefile.objs      |  4 +++
 monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
 monitor/monitor-internal.h | 38 +++++++++++++++++++++
 qapi/Makefile.objs         |  2 ++
 qom/Makefile.objs          |  1 +
 ui/Makefile.objs           |  2 ++
 10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
 remote-pci-obj-$(CONFIG_MPQEMU) += remote/
 remote-pci-obj-$(CONFIG_MPQEMU) += accel/
 remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
 remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
 remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
 # remote-lsi-obj-y is code used to implement remote LSI device
 
 remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
 #######################################################################
 # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
 endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
 #######################################################################
 # Target-independent parts used in system and user emulation
 common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
 endif
 
 #########################################################
@@ -203,6 +222,10 @@ endif
 generated-files-y += hmp-commands.h hmp-commands-info.h
 generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
 endif # CONFIG_SOFTMMU
 
 dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
 hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
 clean: clean-target
 	rm -f *.a *~ $(PROGS)
 	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
 	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 ifdef CONFIG_TRACE_SYSTEMTAP
 	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
         .args_type  = "name:S?",
         .params     = "[cmd]",
         .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
         .flags      = "p",
     },
 
@@ -618,7 +619,7 @@ ETEXI
         .args_type  = "fmt:/,val:l",
         .params     = "/fmt expr",
         .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
     },
 
 STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
 remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
 remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
 remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
 common-obj-y += monitor.o qmp.o hmp.o
 common-obj-y += qmp-cmds.o qmp-cmds-control.o
 common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -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, },
 };
 
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
 void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                  Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
 #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
 obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
 obj-y += qapi-commands.o
 obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 
 remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
 remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
 egl-helpers.o-libs += $(OPENGL_LIBS)
 egl-context.o-libs += $(OPENGL_LIBS)
 egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

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

author
#69 lore raw

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

Quoted 9 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

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

Quoted 608 lines

Dave

Quoted 602 lines
---
  Makefile.objs              |  9 +++++
  Makefile.target            | 35 +++++++++++++++++--
  hmp-commands.hx            |  5 +--
  hw/core/Makefile.objs      |  1 +
  monitor/Makefile.objs      |  4 +++
  monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++++
  qapi/Makefile.objs         |  2 ++
  qom/Makefile.objs          |  1 +
  ui/Makefile.objs           |  2 ++
  10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
  remote-pci-obj-$(CONFIG_MPQEMU) += remote/
  remote-pci-obj-$(CONFIG_MPQEMU) += accel/
  remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
 
  remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
  remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
  # remote-lsi-obj-y is code used to implement remote LSI device
 
  remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
 
  #######################################################################
  # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
 
  endif # CONFIG_SOFTMMU
 
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
  #######################################################################
  # Target-independent parts used in system and user emulation
  common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
 
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
  endif
 
  #########################################################
@@ -203,6 +222,10 @@ endif
  generated-files-y += hmp-commands.h hmp-commands-info.h
  generated-files-y += config-devices.h
 
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
  endif # CONFIG_SOFTMMU
 
  dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
  hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
  	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
  clean: clean-target
  	rm -f *.a *~ $(PROGS)
  	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
  	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
  ifdef CONFIG_TRACE_SYSTEMTAP
  	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
          .args_type  = "name:S?",
          .params     = "[cmd]",
          .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
          .flags      = "p",
      },
 
@@ -618,7 +619,7 @@ ETEXI
          .args_type  = "fmt:/,val:l",
          .params     = "/fmt expr",
          .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
      },
 
  STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
  remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
  remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
  remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
  common-obj-y += monitor.o qmp.o hmp.o
  common-obj-y += qmp-cmds.o qmp-cmds-control.o
  common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -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, },
  };
 
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
  void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                   Error **errp);
 
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
  #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
  obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
  obj-y += qapi-commands.o
  obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
 
  remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
  egl-helpers.o-libs += $(OPENGL_LIBS)
  egl-context.o-libs += $(OPENGL_LIBS)
  egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

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

#70 lore raw

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

Quoted 13 lines · * Jag Raman ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Jagannathan Raman ([email protected]) wrote:

Build system changes to enable QMP module in the remote process

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

Quoted 6 lines

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

Quoted 555 lines

Thanks!
--
Jag

Quoted 550 lines

Dave

Quoted 544 lines
---
  Makefile.objs              |  9 +++++
  Makefile.target            | 35 +++++++++++++++++--
  hmp-commands.hx            |  5 +--
  hw/core/Makefile.objs      |  1 +
  monitor/Makefile.objs      |  4 +++
  monitor/misc.c             | 84 +++++++++++++++++++++++++---------------------
  monitor/monitor-internal.h | 38 +++++++++++++++++++++
  qapi/Makefile.objs         |  2 ++
  qom/Makefile.objs          |  1 +
  ui/Makefile.objs           |  2 ++
  10 files changed, 139 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
index 689a722..4b5db09 100644
@@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/
  remote-pci-obj-$(CONFIG_MPQEMU) += remote/
  remote-pci-obj-$(CONFIG_MPQEMU) += accel/
  remote-pci-obj-$(CONFIG_MPQEMU) += util/
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor/
  remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o
  remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o
  # remote-lsi-obj-y is code used to implement remote LSI device
  remote-lsi-obj-$(CONFIG_MPQEMU) += hw/
+remote-lsi-obj-$(CONFIG_MPQEMU) += ui/
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o
  #######################################################################
  # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -105,6 +109,11 @@ common-obj-y += qapi/
  endif # CONFIG_SOFTMMU
+remote-pci-obj-$(CONFIG_MPQEMU) += qapi/
+remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o
+remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o
+
  #######################################################################
  # Target-independent parts used in system and user emulation
  common-obj-y += cpus-common.o
Makefile.target +33 -2
index 035c23b..4ead5c3 100644
@@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o
-remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o
  remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o
+
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o
+remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o
  endif
  #########################################################
@@ -203,6 +222,10 @@ endif
  generated-files-y += hmp-commands.h hmp-commands-info.h
  generated-files-y += config-devices.h
+ifdef CONFIG_MPQEMU
+generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h
+endif
+
  endif # CONFIG_SOFTMMU
  dummy := $(call unnest-vars,,obj-y)
@@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
  hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
  	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
+ifdef CONFIG_MPQEMU
+hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+
+hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
+	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@)
+endif
+
  clean: clean-target
  	rm -f *.a *~ $(PROGS)
  	rm -f $(shell find . -name '*.[od]')
-	rm -f hmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h
  	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
  ifdef CONFIG_TRACE_SYSTEMTAP
  	rm -f *.stp
hmp-commands.hx +3 -2
index ecc6169..a1932c4 100644
@@ -14,7 +14,8 @@ ETEXI
          .args_type  = "name:S?",
          .params     = "[cmd]",
          .help       = "show the help",
-        .cmd        = do_help_cmd,
+        .cmd        = hmp_do_help_cmd,
+        .targets    = "scsi",
          .flags      = "p",
      },
@@ -618,7 +619,7 @@ ETEXI
          .args_type  = "fmt:/,val:l",
          .params     = "/fmt expr",
          .help       = "print expression value (use $reg for CPU register access)",
-        .cmd        = do_print,
+        .cmd        = hmp_do_print,
      },
  STEXI
hw/core/Makefile.objs +1 -0
index e3e8084..251b77b 100644
@@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o
  remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
  remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o
  remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o
+remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +4 -0
index 9244d90..48d8017 100644
@@ -2,3 +2,7 @@ obj-y += misc.o
  common-obj-y += monitor.o qmp.o hmp.o
  common-obj-y += qmp-cmds.o qmp-cmds-control.o
  common-obj-y += hmp-cmds.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o
+remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o
monitor/misc.c +46 -38
index 6c41293..f1f09bf 100644
@@ -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, },
  };
monitor/monitor-internal.h +38 -0
index 3e6baba..26349cb 100644
@@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list);
  void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data,
                                   Error **errp);
+void hmp_do_help_cmd(Monitor *mon, const QDict *qdict);
+void hmp_trace_event(Monitor *mon, const QDict *qdict);
+void hmp_info_help(Monitor *mon, const QDict *qdict);
+void hmp_info_registers(Monitor *mon, const QDict *qdict);
+void hmp_info_jit(Monitor *mon, const QDict *qdict);
+void hmp_info_opcount(Monitor *mon, const QDict *qdict);
+void hmp_info_sync_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_history(Monitor *mon, const QDict *qdict);
+void hmp_info_cpustats(Monitor *mon, const QDict *qdict);
+void hmp_info_trace_events(Monitor *mon, const QDict *qdict);
+void hmp_logfile(Monitor *mon, const QDict *qdict);
+void hmp_log(Monitor *mon, const QDict *qdict);
+void hmp_singlestep(Monitor *mon, const QDict *qdict);
+void hmp_gdbserver(Monitor *mon, const QDict *qdict);
+void hmp_watchdog_action(Monitor *mon, const QDict *qdict);
+void hmp_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hva(Monitor *mon, const QDict *qdict);
+void hmp_gva2gpa(Monitor *mon, const QDict *qdict);
+void hmp_gpa2hpa(Monitor *mon, const QDict *qdict);
+void hmp_do_print(Monitor *mon, const QDict *qdict);
+void hmp_sum(Monitor *mon, const QDict *qdict);
+void hmp_mouse_move(Monitor *mon, const QDict *qdict);
+void hmp_mouse_button(Monitor *mon, const QDict *qdict);
+void hmp_ioport_read(Monitor *mon, const QDict *qdict);
+void hmp_ioport_write(Monitor *mon, const QDict *qdict);
+void hmp_boot_set(Monitor *mon, const QDict *qdict);
+void hmp_info_mtree(Monitor *mon, const QDict *qdict);
+void hmp_info_profile(Monitor *mon, const QDict *qdict);
+void hmp_info_capture(Monitor *mon, const QDict *qdict);
+void hmp_stopcapture(Monitor *mon, const QDict *qdict);
+void hmp_wavcapture(Monitor *mon, const QDict *qdict);
+void hmp_acl_show(Monitor *mon, const QDict *qdict);
+void hmp_acl_reset(Monitor *mon, const QDict *qdict);
+void hmp_acl_policy(Monitor *mon, const QDict *qdict);
+void hmp_acl_add(Monitor *mon, const QDict *qdict);
+void hmp_acl_remove(Monitor *mon, const QDict *qdict);
+
  #endif
qapi/Makefile.objs +2 -0
index 20fcc37..a8a3925 100644
@@ -31,3 +31,5 @@ obj-y += qapi-events.o
  obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o)
  obj-y += qapi-commands.o
  obj-y += qapi-init-commands.o
+
+remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
index 07e50e5..16603d7 100644
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o
  remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
+remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
index e6da6ff..c3ac572 100644
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS)
  egl-helpers.o-libs += $(OPENGL_LIBS)
  egl-context.o-libs += $(OPENGL_LIBS)
  egl-headless.o-libs += $(OPENGL_LIBS)
+
+remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1

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

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

#71 lore raw

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

In reply to Jagannathan Raman

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

---
 chardev/char.c            | 14 ++++++++++++++
 include/chardev/char.h    |  1 +
 include/monitor/monitor.h |  2 ++
 monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c      |  1 +
 remote/remote-opts.c      |  1 +
 softmmu/vl.c              | 48 -----------------------------------------------
 7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
     qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
 type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
 /* console.c */
 void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
 #endif
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
 #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
 /*
  * To prevent flooding clients, events can be throttled. The
  * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init_opts(QemuOpts *opts, Error **errp)
 {
     Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
 #include "qemu/cutils.h"
 #include "remote-opts.h"
 #include "monitor/monitor.h"
+#include "chardev/char.h"
 #include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
 #include "block/block.h"
 #include "remote/remote-opts.h"
 #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
 #include "vl.h"
 /*
softmmu/vl.c +0 -48

60 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by on v5 37/50
#72 lore raw

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

Quoted 8 lines · * Jagannathan Raman ([email protected]) 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.

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

Quoted 206 lines
---
 chardev/char.c            | 14 ++++++++++++++
 include/chardev/char.h    |  1 +
 include/monitor/monitor.h |  2 ++
 monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
 remote/remote-main.c      |  1 +
 remote/remote-opts.c      |  1 +
 softmmu/vl.c              | 48 -----------------------------------------------
 7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
     qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
 }
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
 type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
 /* console.c */
 void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
 #endif
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
 int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
 #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
 #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
 /*
  * To prevent flooding clients, events can be throttled. The
  * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                    NULL);
 }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
 int monitor_init_opts(QemuOpts *opts, Error **errp)
 {
     Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
 #include "qemu/cutils.h"
 #include "remote-opts.h"
 #include "monitor/monitor.h"
+#include "chardev/char.h"
 #include "sysemu/reset.h"
 
 static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
 #include "block/block.h"
 #include "remote/remote-opts.h"
 #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
 #include "vl.h"
 /*
softmmu/vl.c +0 -48
index a8a6f35..4a4f52c 100644
@@ -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     */
Signature · 1 line
1.8.3.1

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

author
#73 lore raw

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

Quoted 10 lines · Dr. David Alan Gilbert
Quoted 8 lines · * Jagannathan Raman ([email protected]) 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.

Quoted 6 lines

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

Quoted 213 lines

Dave

Quoted 206 lines
---
  chardev/char.c            | 14 ++++++++++++++
  include/chardev/char.h    |  1 +
  include/monitor/monitor.h |  2 ++
  monitor/monitor.c         | 40 ++++++++++++++++++++++++++++++++++++++-
  remote/remote-main.c      |  1 +
  remote/remote-opts.c      |  1 +
  softmmu/vl.c              | 48 -----------------------------------------------
  7 files changed, 58 insertions(+), 49 deletions(-)
chardev/char.c +14 -0
index 8723756..1d03ea0 100644
@@ -1189,4 +1189,18 @@ static void register_types(void)
      qemu_add_machine_init_done_notifier(&chardev_machine_done_notify);
  }
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    Error *local_err = NULL;
+
+    if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return -1;
+        }
+        exit(0);
+    }
+    return 0;
+}
+
  type_init(register_types);
include/chardev/char.h +1 -0
index 00589a6..e370320 100644
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
  /* console.c */
  void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp);
 
+int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp);
  #endif
include/monitor/monitor.h +2 -0
index b7bdd2b..d92bf1c 100644
@@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);
  int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
  void monitor_fdset_dup_fd_remove(int dup_fd);
  int64_t monitor_fdset_dup_fd_find(int dup_fd);
+void monitor_parse(const char *optarg, const char *mode, bool pretty);
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp);
 
  #endif /* MONITOR_H */
monitor/monitor.c +39 -1
index c1a6c44..5759b84 100644
@@ -33,7 +33,10 @@
  #include "sysemu/qtest.h"
  #include "sysemu/sysemu.h"
  #include "trace.h"
-
+#include "qemu/cutils.h"
+#include "qemu/option.h"
+#include "qemu-options.h"
+#include "qemu/config-file.h"
  /*
   * To prevent flooding clients, events can be throttled. The
   * throttling is calculated globally, rather than per-Monitor
@@ -609,6 +612,41 @@ void monitor_init_globals_core(void)
                                     NULL);
  }
 
+int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
+{
+    return monitor_init_opts(opts, errp);
+}
+
+void monitor_parse(const char *optarg, const char *mode, bool pretty)
+{
+    static int monitor_device_index;
+    QemuOpts *opts;
+    const char *p;
+    char label[32];
+
+    if (strstart(optarg, "chardev:", &p)) {
+        snprintf(label, sizeof(label), "%s", p);
+    } else {
+        snprintf(label, sizeof(label), "compat_monitor%d",
+                 monitor_device_index);
+        opts = qemu_chr_parse_compat(label, optarg, true);
+        if (!opts) {
+            error_report("parse error: %s", optarg);
+            exit(1);
+        }
+    }
+
+    opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
+    qemu_opt_set(opts, "mode", mode, &error_abort);
+    qemu_opt_set(opts, "chardev", label, &error_abort);
+    if (!strcmp(mode, "control")) {
+        qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
+    } else {
+        assert(pretty == false);
+    }
+    monitor_device_index++;
+}
+
  int monitor_init_opts(QemuOpts *opts, Error **errp)
  {
      Chardev *chr;
remote/remote-main.c +1 -0
index 5284ee9..23fc0df 100644
@@ -54,6 +54,7 @@
  #include "qemu/cutils.h"
  #include "remote-opts.h"
  #include "monitor/monitor.h"
+#include "chardev/char.h"
  #include "sysemu/reset.h"
 
  static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
index 7e12700..565e641 100644
@@ -39,6 +39,7 @@
  #include "block/block.h"
  #include "remote/remote-opts.h"
  #include "include/qemu-common.h"
+#include "monitor/monitor.h"
 
  #include "vl.h"
  /*
softmmu/vl.c +0 -48
index a8a6f35..4a4f52c 100644
@@ -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     */
Signature · 1 line
1.8.3.1

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

#74 lore raw

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

In reply to Jagannathan Raman
---
 remote/remote-main.c | 11 +++++++++++
 remote/remote-opts.c | 10 ++++++++++
 2 files changed, 21 insertions(+)
remote/remote-main.c +11 -0
index 23fc0df..58d9905 100644
@@ -56,6 +56,7 @@
 #include "monitor/monitor.h"
 #include "chardev/char.h"
 #include "sysemu/reset.h"
+#include "vl.h"
 
 static MPQemuLinkState *mpqemu_link;
 
@@ -436,6 +437,8 @@ int main(int argc, char *argv[])
 
     module_call_init(MODULE_INIT_QOM);
 
+    monitor_init_globals();
+
     bdrv_init_with_whitelist();
 
     if (qemu_init_main_loop(&err)) {
@@ -453,6 +456,8 @@ int main(int argc, char *argv[])
 
     qemu_add_opts(&qemu_device_opts);
     qemu_add_opts(&qemu_drive_opts);
+    qemu_add_opts(&qemu_chardev_opts);
+    qemu_add_opts(&qemu_mon_opts);
     qemu_add_drive_opts(&qemu_legacy_drive_opts);
     qemu_add_drive_opts(&qemu_common_drive_opts);
     qemu_add_drive_opts(&qemu_drive_opts);
@@ -483,6 +488,12 @@ int main(int argc, char *argv[])
 
     mpqemu_link_set_callback(mpqemu_link, process_msg);
 
+    qemu_opts_foreach(qemu_find_opts("chardev"),
+                      chardev_init_func, NULL, &error_fatal);
+
+    qemu_opts_foreach(qemu_find_opts("mon"),
+                      mon_init_func, NULL, &error_fatal);
+
     mpqemu_start_coms(mpqemu_link);
 
     return 0;
remote/remote-opts.c +10 -0
index 565e641..e22ad5c 100644
@@ -82,6 +82,16 @@ void parse_cmdline(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_qmp:
+                monitor_parse(optarg, "control", false);
+                break;
+            case QEMU_OPTION_monitor:
+                if (!strncmp(optarg, "stdio", 5)) {
+                    warn_report("STDIO not supported in remote process");
+                } else if (strncmp(optarg, "none", 4)) {
+                    monitor_parse(optarg, "readline", false);
+                }
+                break;
             default:
                 break;
             }
Signature · 1 line
1.8.3.1
#75 lore raw

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

In reply to Jagannathan Raman

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

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

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

In reply to Jagannathan Raman

Add Makefile support to enable migration in remote process

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

58 lines not on this page · raw message

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

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

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

Add Makefile support to enable migration in remote process

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

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

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

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

Dave

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

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

author
#78 lore raw

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

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

Add Makefile support to enable migration in remote process

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

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

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

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

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

Thank you!
--
Jag

Quoted 226 lines

Dave

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

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