Initial support for multi-process Qemu
Subsystems (2)
v9 cover Initial support for multi-process Qemu
From: Elena Ufimtseva <[email protected]>
Hello
This is the v9 of the patchset. Thank you very much for the detailed feedback for v8. We appreciate your time. We believe we have address all the comments for v8 in the current series. Special thanks to Stefan Hajnoczi.
The v9 has the following changes:
- Communication channel. Qemu side uses blocking call to send and receive the message from the remote and cannot progress further until the remote side replies. Enhanced the communication channel by dropping iothread lock before blocking on Qemu end. Use the co-routines on the remote end to avoid blocking QMP monitor;
- removed the heartbeat functionality, it will be added later in a full extent;
- fixed leaked errors and similar fixes;
- eliminated bytestream passing over the channel;
- The build system had to be changed in order to accomodate the latest changes in Qemu to use Kconfig/mason.
To touch upon the history of this project, we posted the Proof Of Concept patches before the BoF session in 2018. Subsequently, we posted 8 versions on the qemu-devel mailist. You can find them by following the links below ([1] - [8]).
Following people contributed to the design and
implementation of this project:
Jagannathan Raman <[email protected]>
Elena Ufimtseva <[email protected]>
John G Johnson <[email protected]>
Stefan Hajnoczi <[email protected]>
Konrad Wilk <[email protected]>
Kanth Ghatraju <[email protected]>
We would like to thank QEMU community for your feedback in the design and implementation of this project.
Qemu wiki page:
https://wiki.qemu.org/Features/MultiProcessQEMU
For the full concept writeup about QEMU multi-process, please refer to docs/devel/qemu-multiprocess.rst. Also see docs/qemu-multiprocess.txt for usage information.
We welcome all your ideas, concerns, and questions for this patchset.
[POC]: https://www.mail-archive.com/[email protected]/msg566538.html
[1]: https://www.mail-archive.com/[email protected]/msg602285.html
[2]: https://www.mail-archive.com/[email protected]/msg624877.html
[3]: https://www.mail-archive.com/[email protected]/msg642000.html
[4]: https://www.mail-archive.com/[email protected]/msg655118.html
[5]: https://www.mail-archive.com/[email protected]/msg682429.html
[6]: https://www.mail-archive.com/[email protected]/msg697484.html
[7]: https://patchew.org/QEMU/[email protected]/
[8]: https://www.mail-archive.com/[email protected]/msg727007.html
Elena Ufimtseva (8):
multi-process: add qio channel function to transmit
multi-process: define MPQemuMsg format and transmission functions
multi-process: define transmission functions in remote
multi-process: introduce proxy object
multi-process: add proxy communication functions
multi-process: Forward PCI config space acceses to the remote process
multi-process: perform device reset in the remote process
multi-process: add configure and usage information
Jagannathan Raman (11):
memory: alloc RAM from file at offset
multi-process: Add config option for multi-process QEMU
multi-process: setup PCI host bridge for remote device
multi-process: setup a machine object for remote device process
multi-process: Initialize message handler in remote device
multi-process: Associate fd of a PCIDevice with its object
multi-process: setup memory manager for remote device
multi-process: PCI BAR read/write handling for proxy & remote
endpoints
multi-process: Synchronize remote memory
multi-process: create IOHUB object to handle irq
multi-process: Retrieve PCI info from remote process
John G Johnson (1):
multi-process: add the concept description to
docs/devel/qemu-multiprocess
MAINTAINERS | 26 + backends/hostmem-memfd.c | 2 +- configure | 10 + docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 966 ++++++++++++++++++++++++++++++++ docs/multi-process.rst | 67 +++ exec.c | 11 +- hw/i386/meson.build | 5 + hw/i386/remote-iohub.c | 123 ++++ hw/i386/remote-memory.c | 58 ++ hw/i386/remote-msg.c | 263 +++++++++ hw/i386/remote-obj.c | 140 +++++ hw/i386/remote.c | 79 +++ hw/misc/ivshmem.c | 3 +- hw/pci-host/meson.build | 1 + hw/pci-host/remote.c | 75 +++ hw/pci/memory-sync.c | 210 +++++++ hw/pci/meson.build | 3 + hw/pci/proxy.c | 363 ++++++++++++ include/exec/memory.h | 2 + include/exec/ram_addr.h | 2 +- include/hw/i386/remote-iohub.h | 42 ++ include/hw/i386/remote-memory.h | 19 + include/hw/i386/remote-obj.h | 42 ++ include/hw/i386/remote.h | 35 ++ include/hw/pci-host/remote.h | 31 + include/hw/pci/memory-sync.h | 27 + include/hw/pci/pci_ids.h | 3 + include/hw/pci/proxy.h | 54 ++ include/io/channel.h | 24 + include/io/mpqemu-link.h | 110 ++++ include/qemu/mmap-alloc.h | 3 +- io/channel.c | 45 ++ io/meson.build | 2 + io/mpqemu-link.c | 347 ++++++++++++ meson.build | 1 + scripts/mpqemu-launcher.py | 49 ++ softmmu/memory.c | 3 +- util/mmap-alloc.c | 7 +- util/oslib-posix.c | 2 +- 40 files changed, 3243 insertions(+), 13 deletions(-) create mode 100644 docs/devel/multi-process.rst create mode 100644 docs/multi-process.rst create mode 100644 hw/i386/remote-iohub.c create mode 100644 hw/i386/remote-memory.c create mode 100644 hw/i386/remote-msg.c create mode 100644 hw/i386/remote-obj.c create mode 100644 hw/i386/remote.c create mode 100644 hw/pci-host/remote.c create mode 100644 hw/pci/memory-sync.c create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/i386/remote-iohub.h create mode 100644 include/hw/i386/remote-memory.h create mode 100644 include/hw/i386/remote-obj.h create mode 100644 include/hw/i386/remote.h create mode 100644 include/hw/pci-host/remote.h create mode 100644 include/hw/pci/memory-sync.h create mode 100644 include/hw/pci/proxy.h create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c create mode 100755 scripts/mpqemu-launcher.py
Signature · 1 line
2.25.GIT
PATCH v9 1/20 memory: alloc RAM from file at offset
From: Jagannathan Raman <[email protected]>
Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.
--- backends/hostmem-memfd.c | 2 +- exec.c | 11 +++++++---- hw/misc/ivshmem.c | 3 ++- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 3 ++- softmmu/memory.c | 3 ++- util/mmap-alloc.c | 7 ++++--- util/oslib-posix.c | 2 +- 9 files changed, 22 insertions(+), 13 deletions(-)
backends/hostmem-memfd.c +1 -1
@@ -56,7 +56,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) name =host_memory_backend_get_name (backend);memory_region_init_ram_from_fd (&backend->mr,OBJECT (backend), name, backend->size, - backend->share, fd, errp); + backend->share, fd,0 , errp);g_free (name); }
exec.c +7 -4
@@ -1832,6 +1832,7 @@ static void *file_ram_alloc(RAMBlock *block,ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { void *area;
@@ -1882,7 +1883,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" );
@@ -2314,7 +2316,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);
hw/misc/ivshmem.c +2 -1
@@ -492,7 +492,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)/* mmap the region and map into the BAR2 */ memory_region_init_ram_from_fd (&s->server_bar2,OBJECT (s), -"ivshmem.bar2" , size, true, fd, &local_err); +"ivshmem.bar2" , size, true, fd,0 , + &local_err);if (local_err) {error_propagate (errp, local_err);return ;
include/exec/memory.h +2 -0
@@ -908,6 +908,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,* @size: size of the region. * @share: %true if memory must be mmaped with the MAP_SHARED flag * @fd: the fd to mmap. +* @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. * * Note that this function does not do anything to cause the data in the
@@ -919,6 +920,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,uint64_t size, bool share, int fd, + ram_addr_t offset, Error **errp);#endif
include/exec/ram_addr.h +1 -1
@@ -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
@@ -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);
softmmu/memory.c +2 -1
@@ -1576,6 +1576,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,uint64_t size, bool share, int fd, + ram_addr_t offset, Error **errp) { Error *err = NULL;
@@ -1585,7 +1586,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, offset, &err); mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();
util/mmap-alloc.c +4 -3
@@ -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
@@ -227,7 +227,7 @@ void *qemu_memalign(size_t alignment, size_t size)void *qemu_anon_ram_alloc (size_t size,uint64_t *alignment,bool shared) {size_t align =QEMU_VMALLOC_ALIGN ; -void *ptr =qemu_ram_mmap (-1 , size, align, shared, false); +void *ptr =qemu_ram_mmap (-1 , size, align, shared, false,0 );if (ptr ==MAP_FAILED ) {return NULL ;
Signature · 1 line
2.25.GIT
PATCH v9 2/20 multi-process: Add config option for multi-process QEMU
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Add a configuration option to separate multi-process code
--- configure | 10 ++++++++++ meson.build | 1 + 2 files changed, 11 insertions(+)
configure +10 -0
@@ -570,6 +570,7 @@ libdaxctl="" meson="" skip_meson=no gettext="" +mpqemu="no" bogus_os="no" malloc_trim=""
@@ -1661,6 +1662,10 @@ for opt do ;; --disable-libdaxctl) libdaxctl=no ;; + --enable-mpqemu) mpqemu=yes + ;; + --disable-mpqemu) mpqemu=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1984,6 +1989,8 @@ disabled with --disable-FEATURE, default is enabled if available: xkbcommon xkbcommon support rng-none dummy RNG, avoid using /dev/(u)random and getrandom() libdaxctl libdaxctl support + mpqemu multi-process QEMU support + NOTE: The object files are built at the place where configure is launched EOF
@@ -7502,6 +7509,9 @@ fi if test "$have_mlockall" = "yes" ; then echo "HAVE_MLOCKALL=y" >> $config_host_mak fi +if test "$mpqemu" = "yes" ; then + echo "CONFIG_MPQEMU=y" >> $config_host_mak +fi if test "$fuzzing" = "yes" ; then QEMU_CFLAGS="$QEMU_CFLAGS -fsanitize=fuzzer-no-link" fi
meson.build +1 -0
@@ -1426,6 +1426,7 @@ endif summary_info += {'thread sanitizer': config_host.has_key('CONFIG_TSAN')} summary_info += {'rng-none': config_host.has_key('CONFIG_RNG_NONE')} summary_info += {'Linux keyring': config_host.has_key('CONFIG_SECRET_KEYRING')} +summary_info += {'Multi-Process QEMU': config_host.has_key('CONFIG_MPQEMU')} summary(summary_info, bool_yn: true) if not supported_cpus.contains(cpu)
Signature · 1 line
2.25.GIT
PATCH v9 3/20 multi-process: setup PCI host bridge for remote device
In reply to [email protected]From: Jagannathan Raman <[email protected]>
PCI host bridge is setup for the remote device process. It is implemented using remote-pcihost object. It is an extension of the PCI host bridge setup by QEMU.
Remote-pcihost configures a PCI bus which could be used by the remote PCI device to latch on to.
--- MAINTAINERS | 8 ++++ hw/pci-host/meson.build | 1 + hw/pci-host/remote.c | 75 ++++++++++++++++++++++++++++++++++++ include/hw/pci-host/remote.h | 30 +++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 hw/pci-host/remote.c create mode 100644 include/hw/pci-host/remote.h
MAINTAINERS +8 -0
@@ -3036,6 +3036,14 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ +Multi-process QEMU +M: Jagannathan Raman <[email protected]> +M: Elena Ufimtseva <[email protected]> +M: John G Johnson <[email protected]> +S: Maintained +F: hw/pci-host/remote.c +F: include/hw/pci-host/remote.h + Build and test automation ------------------------- Build and test automation
hw/pci-host/meson.build +1 -0
@@ -8,6 +8,7 @@ pci_ss.add(when: 'CONFIG_PCI_EXPRESS_XILINX', if_true: files('xilinx-pcie.c')) pci_ss.add(when: 'CONFIG_PCI_I440FX', if_true: files('i440fx.c')) pci_ss.add(when: 'CONFIG_PCI_SABRE', if_true: files('sabre.c')) pci_ss.add(when: 'CONFIG_XEN_IGD_PASSTHROUGH', if_true: files('xen_igd_pt.c')) +pci_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) # PPC devices pci_ss.add(when: 'CONFIG_PREP_PCI', if_true: files('prep.c'))
hw/pci-host/remote.c new file +75 -0
75 lines not on this page · raw message
include/hw/pci-host/remote.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* PCI Host for remote device +* +* Copyright © 2018, 2020 Oracle and/or its affiliates. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef REMOTE_PCIHOST_H +#define REMOTE_PCIHOST_H + +#include "exec/memory.h" +#include "hw/pci/pcie_host.h" + +#define TYPE_REMOTE_HOST_DEVICE "remote-pcihost" +#define REMOTE_HOST_DEVICE (obj) \ + OBJECT_CHECK(RemotePCIHost, (obj), TYPE_REMOTE_HOST_DEVICE) + +typedef struct RemotePCIHost { +/*< private >*/ +PCIExpressHost parent_obj; +/*< public >*/ + +MemoryRegion *mr_pci_mem; +MemoryRegion *mr_sys_io; +}RemotePCIHost ; + +#endif
Signature · 1 line
2.25.GIT
Re: [PATCH v9 03/20] multi-process: setup PCI host bridge for remote device
Quoted 11 lines · On Thu, Aug 27, 2020 at 11:12:14AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
PCI host bridge is setup for the remote device process. It is implemented using remote-pcihost object. It is an extension of the PCI host bridge setup by QEMU.
Remote-pcihost configures a PCI bus which could be used by the remote PCI device to latch on to.Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 8 ++++ hw/pci-host/meson.build | 1 + hw/pci-host/remote.c | 75 ++++++++++++++++++++++++++++++++++++ include/hw/pci-host/remote.h | 30 +++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 hw/pci-host/remote.c create mode 100644 include/hw/pci-host/remote.h
PATCH v9 4/20 multi-process: setup a machine object for remote device process
In reply to [email protected]From: Jagannathan Raman <[email protected]>
remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.
--- MAINTAINERS | 2 ++ hw/i386/meson.build | 1 + hw/i386/remote.c | 69 ++++++++++++++++++++++++++++++++++++ include/hw/i386/remote.h | 28 +++++++++++++++ include/hw/pci-host/remote.h | 1 + 5 files changed, 101 insertions(+) create mode 100644 hw/i386/remote.c create mode 100644 include/hw/i386/remote.h
MAINTAINERS +2 -0
@@ -3043,6 +3043,8 @@ M: John G Johnson <[email protected]> S: Maintained F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h +F: hw/i386/remote.c +F: include/hw/i386/remote.h Build and test automation -------------------------
hw/i386/meson.build +1 -0
@@ -23,6 +23,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( 'pc_sysfw.c', 'acpi-build.c', 'port92.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) subdir('kvm') subdir('xen')
hw/i386/remote.c new file +69 -0
69 lines not on this page · raw message
include/hw/i386/remote.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* 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 "qom/object.h" +#include "hw/boards.h" +#include "hw/pci-host/remote.h" + +typedef struct RemoteMachineState { +MachineState parent_obj; + +RemotePCIHost *host; +}RemoteMachineState ; + +#define TYPE_REMOTE_MACHINE "remote-machine" +#define REMOTE_MACHINE (obj) \ + OBJECT_CHECK(RemoteMachineState, (obj), TYPE_REMOTE_MACHINE) + +#endif
include/hw/pci-host/remote.h +1 -0
@@ -25,6 +25,7 @@ typedef struct RemotePCIHost {MemoryRegion *mr_pci_mem;MemoryRegion *mr_sys_io; + MemoryRegion *mr_sys_mem; } RemotePCIHost;#endif
Signature · 1 line
2.25.GIT
Re: [PATCH v9 04/20] multi-process: setup a machine object for remote device process
Quoted 9 lines · On Thu, Aug 27, 2020 at 11:12:15AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.
Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>
Quoted 9 lines
--- MAINTAINERS | 2 ++ hw/i386/meson.build | 1 + hw/i386/remote.c | 69 ++++++++++++++++++++++++++++++++++++ include/hw/i386/remote.h | 28 +++++++++++++++ include/hw/pci-host/remote.h | 1 + 5 files changed, 101 insertions(+) create mode 100644 hw/i386/remote.c create mode 100644 include/hw/i386/remote.h
PATCH v9 5/20 multi-process: add qio channel function to transmit
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
The entire array of the memory regions and file handlers. Will be used in the next patch.
--- include/io/channel.h | 24 +++++++++++++++++++++++ io/channel.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
include/io/channel.h +24 -0
@@ -779,5 +779,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, IOHandler *io_read, IOHandler *io_write, void *opaque); +/** +* qio_channel_writev_full_all: +* @ioc: the channel object +* @iov: the array of memory regions to write data from +* @niov: the length of the @iov array +* @fds: an array of file handles to send +* @nfds: number of file handles in @fds +* @errp: pointer to a NULL-initialized error object +* +* +* Behaves like qio_channel_writev_full but will attempt +* to send all data passed (file handles and memory regions). +* The function will wait for all requested data +* to be written, yielding from the current coroutine +* if required. +* +* Returns: 0 if all bytes were written, or -1 on error +*/ + +int qio_channel_writev_full_all (QIOChannel *ioc, +const struct iovec *iov, +size_t niov, +int *fds,size_t nfds, +Error **errp);#endif /* QIO_CHANNEL_H */
io/channel.c +45 -0
51 lines not on this page · raw message
Signature · 1 line
2.25.GIT
PATCH v9 6/20 multi-process: define MPQemuMsg format and transmission functions
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
Defines MPQemuMsg, which is the message that is sent to the remote process. This message is sent over QIOChannel and is used to command the remote process to perform various tasks.
Also defined the helper functions to send and receive messages over the QIOChannel
--- MAINTAINERS | 2 + include/io/mpqemu-link.h | 60 ++++++++++++++ io/meson.build | 2 + io/mpqemu-link.c | 173 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 237 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c
MAINTAINERS +2 -0
@@ -3045,6 +3045,8 @@ F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h F: hw/i386/remote.c F: include/hw/i386/remote.h +F: io/mpqemu-link.c +F: include/io/mpqemu-link.h Build and test automation -------------------------
include/io/mpqemu-link.h new file +60 -0
60 lines not on this page · raw message
io/meson.build +2 -0
@@ -15,6 +15,8 @@ io_ss.add(files( 'task.c', )) +io_ss.add(when: 'CONFIG_MPQEMU', if_true: files('mpqemu-link.c')) + io_ss = io_ss.apply(config_host, strict: false) libio = static_library('io', io_ss.sources() + genh, dependencies: [io_ss.dependencies()],
io/mpqemu-link.c new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.25.GIT
Re: [PATCH v9 06/20] multi-process: define MPQemuMsg format and transmission functions
include/io/mpqemu-link.h line 30
Quoted 9 lines · On Thu, Aug 27, 2020 at 11:12:17AM -0700, [email protected] wrote:
include/io/mpqemu-link.h new file +9
-0+/** +* MPQemuCmd: +* +* MPQemuCmd enum type to specify the command to be executed on the remote +* device. +*/ +typedef enum { + INIT = 0, + MAX = INT_MAX,
enum members are in a global namespace. INIT and MAX are likely to collide with other code using these names. Please use MPQEMU_CMD_INIT and MPQEMU_CMD_MAX.
Why is MAX = INT_MAX? I expected MAX to be related to the number of commands that have been defined (1 so far).
Quoted 5 lines
include/io/mpqemu-link.h new file +5
-0+} MPQemuCmd; + +/** +* MPQemuMsg: +* @cmd: The remote command
include/io/mpqemu-link.h line 45
Quoted 10 lines
include/io/mpqemu-link.h new file +10
-0+* @size: Size of the data to be shared +* @data: Structured data +* @fds: File descriptors to be shared with remote device +* +* MPQemuMsg Format of the message sent to the remote device from QEMU. +* +*/ +typedef struct { + int cmd; + size_t size;
I worry about the hole (compiler-inserted padding) between the cmd and size fields.
It is safer to use fixed-size types and use QEMU_PACKED for structs that are transferred over the network:
typedef struct {
int32_t cmd;
uint64_t size;
...
} QEMU_PACKED MPQemuMsg;This way the struct layout is independent of the compilation environment (32-/64-bit, ABI) and there is no risk of accidentally exposing memory (information leaks) through holes.
Quoted 69 lines
include/io/mpqemu-link.h new file +15
-0+ +union { +uint64_t u64; + } data; + +int fds[REMOTE_MAX_FDS ]; + int num_fds; +} MPQemuMsg; + +void mpqemu_msg_send (MPQemuMsg *msg,QIOChannel *ioc,Error **errp); +void mpqemu_msg_recv (MPQemuMsg *msg,QIOChannel *ioc,Error **errp); + +bool mpqemu_msg_valid (MPQemuMsg *msg); + +#endif io/meson.build +2
-0@@ -15,6 +15,8 @@ io_ss.add(files( 'task.c', )) +io_ss.add(when: 'CONFIG_MPQEMU', if_true: files('mpqemu-link.c')) + io_ss = io_ss.apply(config_host, strict: false) libio = static_library('io', io_ss.sources() + genh, dependencies: [io_ss.dependencies()],io/mpqemu-link.c new file +35
-0@@ -0,0 +1,173 @@ +/* +* Communication channel between QEMU and remote device process +* +* Copyright © 2018, 2020 Oracle and/or its affiliates. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/module.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/iov.h" +#include "qemu/error-report.h" +#include "qemu/main-loop.h" + +void mpqemu_msg_send (MPQemuMsg *msg,QIOChannel *ioc,Error **errp) +{ +bool iolock =qemu_mutex_iothread_locked (); +Error *local_err =NULL ; +struct iovec send[2 ]; +int *fds =NULL ; +size_t nfds =0 ; + + send[0 ].iov_base = msg; + send[0 ].iov_len =MPQEMU_MSG_HDR_SIZE ; + + send[1 ].iov_base = (void *)&msg->data; + send[1 ].iov_len = msg->size; + +if (msg->num_fds) {
io/mpqemu-link.c line 45
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+ nfds = msg->num_fds; + fds = msg->fds; + } + +if (iolock) { +qemu_mutex_unlock_iothread (); + } + + (void )qio_channel_writev_full_all (ioc, send,G_N_ELEMENTS (send), fds, nfds, + &local_err);
I tried to understand when it is safe to call this function:
Thread | Coroutine? | Comments
------------------------------------
Main loop | Yes | Okay Main loop | No | Do not use, blocks main loop vCPU | Yes | Careful, can move coroutine to main loop vCPU | No | Okay if no other ioc activity in main loop IOThread | Yes | Broken: we shouldn't touch the global mutex! IOThread | No | Do not use, blocks IOThread
The IOThreads case with coroutines can be fixed by skipping qemu_mutex_lock_iothread() when running in an IOThread. Please address this.
Cases that look usable to me are:
1. Main loop with coroutines
2. vCPU without coroutines
3. IOThread with coroutines (needs fix though)
All this is not obvious so a comment and assertions would be good. The following helpers are available for implementing assertions:
1. bool qemu_in_coroutine() -> true if running in a coroutine
2. qemu_get_current_aio_context() != qemu_get_aio_context() -> true in IOThread
Quoted 6 lines
io/mpqemu-link.c new file +6
-0+ +if (iolock) { +qemu_mutex_lock_iothread (); + } + +if (errp) {
io/mpqemu-link.c line 61
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+error_propagate (errp, local_err); + }else if (local_err) { +error_report_err (local_err); + } + +return ; +} + +static ssize_t mpqemu_read (QIOChannel *ioc,void *buf,size_t len,int **fds, +size_t *nfds,Error **errp)
The same constraints apply to this function.
PATCH v9 7/20 multi-process: define transmission functions in remote
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
remote process uses Qemu event loop and cannot block while communicating with the remote proxy object.
This patch defines the co-routines to receive and send messages to the proxy from remote process.
TODO: Avoid the aio_poll by entering the co-routines from the higher level to avoid aio_poll.
--- include/io/mpqemu-link.h | 12 +++++ io/mpqemu-link.c | 108 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+)
include/io/mpqemu-link.h +12 -0
@@ -52,6 +52,18 @@ typedef struct {int num_fds; } MPQemuMsg; +struct MPQemuRequest { +MPQemuMsg *msg; +QIOChannel *ioc; +bool finished; +int error; +}; + +typedef struct MPQemuRequest MPQemuRequest ; + +void mpqemu_msg_send_in_co (MPQemuRequest *req,QIOChannel *ioc,Error **errp); +void mpqemu_msg_recv_in_co (MPQemuRequest *req,QIOChannel *ioc,Error **errp); +void mpqemu_msg_send (MPQemuMsg *msg,QIOChannel *ioc,Error **errp);void mpqemu_msg_recv (MPQemuMsg *msg,QIOChannel *ioc,Error **errp);
io/mpqemu-link.c +108 -0
114 lines not on this page · raw message
Signature · 1 line
2.25.GIT
Re: [PATCH v9 07/20] multi-process: define transmission functions in remote
Quoted 2 lines · On Thu, Aug 27, 2020 at 11:12:18AM -0700, [email protected] wrote:
TODO: Avoid the
aio_pollby entering the co-routines from the higher level to avoidaio_poll.
The monitor is unresponsive during the aio_poll() loop. Is this a blocker for you?
Running all mpqemu communication in a coroutine as mentioned in this TODO is a cleaner solution. Then this patch will be unnecessary.
io/mpqemu-link.c fail: · line 164
Quoted 12 lines
io/mpqemu-link.c +12
-0+static void coroutine_fn mpqemu_msg_send_co(void *data) +{ +MPQemuRequest *req = (MPQemuRequest *)data; +Error *local_err =NULL ; + +mpqemu_msg_send (req->msg, req->ioc, &local_err); +if (local_err) { +error_report ("ERROR: failed to send command to remote %d, " , + req->msg->cmd); + req->finished = true; + req->error = -EINVAL ; +return ;
local_err is leaked.
Quoted 6 lines
io/mpqemu-link.c +6
-0+ } + + req->finished = true; +} + +void mpqemu_msg_send_in_co(MPQemuRequest *req, QIOChannel *ioc,
io/mpqemu-link.c fail: · line 180
Quoted 10 lines
io/mpqemu-link.c +10
-0+ Error **errp) +{ +Coroutine *co; + +if (!req->ioc) { +if (errp) { +error_setg (errp,"Channel is set to NULL" ); + }else { +error_report ("Channel is set to NULL" ); + }
The caller should provide an errp if they are interested in the error message. Duplicating error messages is messy.
io/mpqemu-link.c fail: · line 218
Quoted 12 lines
io/mpqemu-link.c +12
-0+static void coroutine_fn mpqemu_msg_recv_co(void *data) +{ +MPQemuRequest *req = (MPQemuRequest *)data; +Error *local_err =NULL ; + +mpqemu_msg_recv (req->msg, req->ioc, &local_err); +if (local_err) { +error_report ("ERROR: failed to send command to remote %d, " , + req->msg->cmd); + req->finished = true; + req->error = -EINVAL ; +return ;
local_err is leaked.
Re: [PATCH v9 07/20] multi-process: define transmission functions in remote
Quoted 7 lines · Stefan Hajnoczi
Quoted 2 lines · On Thu, Aug 27, 2020 at 11:12:18AM -0700, [email protected] wrote:
TODO: Avoid the
aio_pollby entering the co-routines from the higher level to avoidaio_poll.The monitor is unresponsive during the
aio_poll()loop. Is this a blocker for you?
Hi Stefan
No, not a blocker, had to leave out removal of aio_poll for the next round.
Quoted 3 lines
Running all mpqemu communication in a coroutine as mentioned in this TODO is a cleaner solution. Then this patch will be unnecessary.
Yes, thank you, it will go away in v10.
Quoted 35 lines
io/mpqemu-link.c fail: · line 164
Quoted 12 lines
io/mpqemu-link.c +12
-0+static void coroutine_fn mpqemu_msg_send_co(void *data) +{ +MPQemuRequest *req = (MPQemuRequest *)data; +Error *local_err =NULL ; + +mpqemu_msg_send (req->msg, req->ioc, &local_err); +if (local_err) { +error_report ("ERROR: failed to send command to remote %d, " , + req->msg->cmd); + req->finished = true; + req->error = -EINVAL ; +return ;
local_erris leaked.Quoted 6 lines
io/mpqemu-link.c +6
-0+ } + + req->finished = true; +} + +void mpqemu_msg_send_in_co(MPQemuRequest *req, QIOChannel *ioc,io/mpqemu-link.c fail: · line 180
Quoted 10 lines
io/mpqemu-link.c +10
-0+ Error **errp) +{ +Coroutine *co; + +if (!req->ioc) { +if (errp) { +error_setg (errp,"Channel is set to NULL" ); + }else { +error_report ("Channel is set to NULL" ); + }The caller should provide an errp if they are interested in the error message. Duplicating error messages is messy.
Quoted 14 lines
io/mpqemu-link.c fail: · line 218
Quoted 12 lines
io/mpqemu-link.c +12
-0+static void coroutine_fn mpqemu_msg_recv_co(void *data) +{ +MPQemuRequest *req = (MPQemuRequest *)data; +Error *local_err =NULL ; + +mpqemu_msg_recv (req->msg, req->ioc, &local_err); +if (local_err) { +error_report ("ERROR: failed to send command to remote %d, " , + req->msg->cmd); + req->finished = true; + req->error = -EINVAL ; +return ;
local_erris leaked.
Thank you for reviewing these, will fix If the code above will be re-used.
Elena
PATCH v9 8/20 multi-process: Initialize message handler in remote device
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Initializes the message handler function in the remote process. It is called whenever there's an event pending on QIOChannel that registers this function.
--- MAINTAINERS | 1 + hw/i386/meson.build | 1 + hw/i386/remote-msg.c | 66 ++++++++++++++++++++++++++++++++++++++++ include/hw/i386/remote.h | 4 +++ 4 files changed, 72 insertions(+) create mode 100644 hw/i386/remote-msg.c
MAINTAINERS +1 -0
@@ -3047,6 +3047,7 @@ F: hw/i386/remote.c F: include/hw/i386/remote.h F: io/mpqemu-link.c F: include/io/mpqemu-link.h +F: hw/i386/remote-msg.c Build and test automation -------------------------
hw/i386/meson.build +1 -0
@@ -24,6 +24,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( 'acpi-build.c', 'port92.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-msg.c')) subdir('kvm') subdir('xen')
hw/i386/remote-msg.c new file +66 -0
66 lines not on this page · raw message
include/hw/i386/remote.h +4 -0
@@ -14,6 +14,7 @@#include "qom/object.h" #include "hw/boards.h" #include "hw/pci-host/remote.h" +#include "io/channel.h" typedef struct RemoteMachineState { MachineState parent_obj;
@@ -25,4 +26,7 @@ typedef struct RemoteMachineState {#define REMOTE_MACHINE (obj) \ OBJECT_CHECK(RemoteMachineState, (obj), TYPE_REMOTE_MACHINE) +gboolean mpqemu_process_msg (QIOChannel *ioc,GIOCondition cond, +gpointer opaque); +#endif
Signature · 1 line
2.25.GIT
Re: [PATCH v9 08/20] multi-process: Initialize message handler in remote device
This is the function that can be converted from a callback to a coroutine like this:
void coroutine_fn mpqemu_loop(...)
{
for (;;) {
if (mpqemu_msg_read(...) < 0) {
/* Fatal connection error (disconnected, etc) */
break;
}
if (!mpqemu_msg_valid(&msg)) {
/* Protocol violation, terminate connection */
break;
}
switch (msg.cmd) {
/* Dispatch command */
}
}}
Re: [PATCH v9 08/20] multi-process: Initialize message handler in remote device
Quoted 20 lines · Stefan Hajnoczi
This is the function that can be converted from a callback to a coroutine like this:
void
coroutine_fnmpqemu_loop(...){ for (;;) { if (mpqemu_msg_read(...) < 0) { /* Fatal connection error (disconnected, etc) */ break; } if (!mpqemu_msg_valid(&msg)) { /* Protocol violation, terminate connection */ break; } switch (msg.cmd) { /* Dispatch command */ } }
Quoted 1 line
}
Ok, thank you! I have something similar.
Elena
PATCH v9 9/20 multi-process: Associate fd of a PCIDevice with its object
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Associate the file descriptor for a PCIDevice in remote process with DeviceState object.
--- MAINTAINERS | 2 + hw/i386/meson.build | 1 + hw/i386/remote-obj.c | 140 +++++++++++++++++++++++++++++++++++ include/hw/i386/remote-obj.h | 42 +++++++++++ 4 files changed, 185 insertions(+) create mode 100644 hw/i386/remote-obj.c create mode 100644 include/hw/i386/remote-obj.h
MAINTAINERS +2 -0
@@ -3048,6 +3048,8 @@ F: include/hw/i386/remote.h F: io/mpqemu-link.c F: include/io/mpqemu-link.h F: hw/i386/remote-msg.c +F: include/hw/i386/remote-obj.h +F: hw/i386/remote-obj.c Build and test automation -------------------------
hw/i386/meson.build +1 -0
@@ -25,6 +25,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( 'port92.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-msg.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-obj.c')) subdir('kvm') subdir('xen')
hw/i386/remote-obj.c new file +140 -0
140 lines not on this page · raw message
include/hw/i386/remote-obj.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.25.GIT
Re: [PATCH v9 09/20] multi-process: Associate fd of a PCIDevice with its object
Quoted 8 lines · On Thu, Aug 27, 2020 at 11:12:20AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
Associate the file descriptor for a PCIDevice in remote process with DeviceState object.
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 2 + hw/i386/meson.build | 1 + hw/i386/remote-obj.c | 140 +++++++++++++++++++++++++++++++++++ include/hw/i386/remote-obj.h | 42 +++++++++++ 4 files changed, 185 insertions(+) create mode 100644 hw/i386/remote-obj.c create mode 100644 include/hw/i386/remote-obj.h
PATCH v9 10/20 multi-process: setup memory manager for remote device
In reply to [email protected]From: Jagannathan Raman <[email protected]>
SyncSysMemMsg message format is defined. It is used to send file descriptors of the RAM regions to remote device.
RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM.
--- MAINTAINERS | 2 ++ hw/i386/meson.build | 1 + hw/i386/remote-memory.c | 58 +++++++++++++++++++++++++++++++++ include/hw/i386/remote-memory.h | 19 +++++++++++ include/io/mpqemu-link.h | 13 ++++++++ io/mpqemu-link.c | 11 +++++++ 6 files changed, 104 insertions(+) create mode 100644 hw/i386/remote-memory.c create mode 100644 include/hw/i386/remote-memory.h
MAINTAINERS +2 -0
@@ -3050,6 +3050,8 @@ F: include/io/mpqemu-link.h F: hw/i386/remote-msg.c F: include/hw/i386/remote-obj.h F: hw/i386/remote-obj.c +F: include/hw/i386/remote-memory.h +F: hw/i386/remote-memory.c Build and test automation -------------------------
hw/i386/meson.build +1 -0
@@ -26,6 +26,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-msg.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-obj.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-memory.c')) subdir('kvm') subdir('xen')
hw/i386/remote-memory.c new file +58 -0
58 lines not on this page · raw message
include/hw/i386/remote-memory.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* 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 "exec/hwaddr.h" +#include "io/mpqemu-link.h" + +void remote_sysmem_reconfig (MPQemuMsg *msg,Error **errp); + +#endif
include/io/mpqemu-link.h +13 -0
@@ -14,6 +14,7 @@#include "qom/object.h" #include "qemu/thread.h" #include "io/channel.h" +#include "exec/hwaddr.h" #define REMOTE_MAX_FDS 8
@@ -24,12 +25,22 @@* * MPQemuCmd enum type to specify the command to be executed on the remote * device. +* +* SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM */ typedef enum {INIT =0 , +SYNC_SYSMEM , +RET_MSG ,MAX =INT_MAX , }MPQemuCmd ; +typedef struct { +hwaddr gpas[REMOTE_MAX_FDS ]; +uint64_t sizes[REMOTE_MAX_FDS ]; +off_t offsets[REMOTE_MAX_FDS ]; +}SyncSysmemMsg ; +/** * MPQemuMsg: * @cmd: The remote command
@@ -40,12 +51,14 @@ typedef enum {* MPQemuMsg Format of the message sent to the remote device from QEMU. * */ + typedef struct { int cmd; size_t size; union { uint64_t u64; + SyncSysmemMsg sync_sysmem; } data; int fds[REMOTE_MAX_FDS];
io/mpqemu-link.c +11 -0
@@ -277,5 +277,16 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) } } +/* Verify message specific fields. */ +switch (msg->cmd) { +case SYNC_SYSMEM : +if (msg->num_fds ==0 || msg->size !=sizeof (SyncSysmemMsg)) { +return false; + } +break ; +default : +break ; + } +return true; }
Signature · 1 line
2.25.GIT
Re: [PATCH v9 10/20] multi-process: setup memory manager for remote device
Quoted 11 lines · On Thu, Aug 27, 2020 at 11:12:21AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
SyncSysMemMsg message format is defined. It is used to send file descriptors of the RAM regions to remote device.
RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM.Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>
Quoted 10 lines
--- MAINTAINERS | 2 ++ hw/i386/meson.build | 1 + hw/i386/remote-memory.c | 58 +++++++++++++++++++++++++++++++++ include/hw/i386/remote-memory.h | 19 +++++++++++ include/io/mpqemu-link.h | 13 ++++++++ io/mpqemu-link.c | 11 +++++++ 6 files changed, 104 insertions(+) create mode 100644 hw/i386/remote-memory.c create mode 100644 include/hw/i386/remote-memory.h
PATCH v9 11/20 multi-process: introduce proxy object
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
Defines a PCI Device proxy object as a child of TYPE_PCI_DEVICE.
--- MAINTAINERS | 2 + hw/pci/meson.build | 1 + hw/pci/proxy.c | 84 ++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 34 +++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/pci/proxy.h
MAINTAINERS +2 -0
@@ -3052,6 +3052,8 @@ F: include/hw/i386/remote-obj.h F: hw/i386/remote-obj.c F: include/hw/i386/remote-memory.h F: hw/i386/remote-memory.c +F: hw/pci/proxy.c +F: include/hw/pci/proxy.h Build and test automation -------------------------
hw/pci/meson.build +1 -0
@@ -12,6 +12,7 @@ pci_ss.add(files( # allow plugging PCIe devices into PCI buses, include them even if # CONFIG_PCI_EXPRESS=n. pci_ss.add(files('pcie.c', 'pcie_aer.c')) +pci_ss.add(when: 'CONFIG_MPQEMU', if_true: files('proxy.c')) softmmu_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c')) softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)
hw/pci/proxy.c new file +84 -0
84 lines not on this page · raw message
include/hw/pci/proxy.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* 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 PROXY_H +#define PROXY_H + +#include "hw/pci/pci.h" +#include "io/channel.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV (obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { +PCIDevice parent_dev; +char *fd; + +/* +* Mutex used to protect the QIOChannel fd from +* the concurrent access by the VCPUs since proxy +* blocks while awaiting for the replies from the +* process remote. +*/ +QemuMutex io_mutex; +QIOChannel *ioc; +}PCIProxyDev ; + +#endif /* PROXY_H */
Signature · 1 line
2.25.GIT
Re: [PATCH v9 11/20] multi-process: introduce proxy object
Quoted 7 lines · On Thu, Aug 27, 2020 at 11:12:22AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Defines a PCI Device proxy object as a child of
TYPE_PCI_DEVICE.Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>
Quoted 8 lines
--- MAINTAINERS | 2 + hw/pci/meson.build | 1 + hw/pci/proxy.c | 84 ++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 34 +++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/pci/proxy.h
Re: [PATCH v9 11/20] multi-process: introduce proxy object
In reply to [email protected]Quoted 7 lines · On Thu, Aug 27, 2020 at 11:12:22AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Defines a PCI Device proxy object as a child of
TYPE_PCI_DEVICE.Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>
Hmm I think this device needs to block migration. And maybe the pci host device needs to do it too?
Quoted 166 lines
--- MAINTAINERS | 2 + hw/pci/meson.build | 1 + hw/pci/proxy.c | 84 ++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 34 +++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/pci/proxy.hMAINTAINERS +2
-0@@ -3052,6 +3052,8 @@ F: include/hw/i386/remote-obj.h F: hw/i386/remote-obj.c F: include/hw/i386/remote-memory.h F: hw/i386/remote-memory.c +F: hw/pci/proxy.c +F: include/hw/pci/proxy.h Build and test automation -------------------------hw/pci/meson.build +1
-0@@ -12,6 +12,7 @@ pci_ss.add(files( # allow plugging PCIe devices into PCI buses, include them even if # CONFIG_PCI_EXPRESS=n. pci_ss.add(files('pcie.c', 'pcie_aer.c')) +pci_ss.add(when: 'CONFIG_MPQEMU', if_true: files('proxy.c')) softmmu_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c')) softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)hw/pci/proxy.c new file +84
-0@@ -0,0 +1,84 @@ +/* +* 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 "hw/pci/proxy.h" +#include "hw/pci/pci.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "hw/qdev-properties.h" +#include "monitor/monitor.h" + +static void proxy_set_socket (PCIProxyDev *pdev,int fd,Error **errp) +{ + pdev->ioc =qio_channel_new_fd (fd, errp); +} + +static Property proxy_properties[] = { +DEFINE_PROP_STRING ("fd" , PCIProxyDev, fd), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pci_proxy_dev_realize (PCIDevice *device,Error **errp) +{ +PCIProxyDev *dev =PCI_PROXY_DEV (device); +int fd; + +if (dev->fd) { + fd =monitor_fd_param (cur_mon, dev->fd, errp); +if (fd ==-1 ) { +error_prepend (errp,"proxy: unable to parse fd: " ); +return ; + } +proxy_set_socket (dev, fd, errp); + }else { +error_setg (errp,"fd parameter not specified for %s" , +DEVICE (device)->id); +return ; + } + +qemu_mutex_init (&dev->io_mutex); +qio_channel_set_blocking (dev->ioc, true,NULL ); +} + +static void pci_proxy_dev_exit (PCIDevice *pdev) +{ +PCIProxyDev *dev =PCI_PROXY_DEV (pdev); + +qio_channel_close (dev->ioc,NULL ); +} + +static void pci_proxy_dev_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->realize = pci_proxy_dev_realize; + k->exit = pci_proxy_dev_exit; +device_class_set_props (dc, proxy_properties); +} + +static const TypeInfo pci_proxy_dev_type_info = { + .name =TYPE_PCI_PROXY_DEV , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIProxyDev), + .class_init = pci_proxy_dev_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + +static void pci_proxy_dev_register_types (void ) +{ +type_register_static (&pci_proxy_dev_type_info); +} + +type_init (pci_proxy_dev_register_types)include/hw/pci/proxy.h new file +34
-0@@ -0,0 +1,34 @@ +/* +* 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 PROXY_H +#define PROXY_H + +#include "hw/pci/pci.h" +#include "io/channel.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV (obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { +PCIDevice parent_dev; +char *fd; + +/* +* Mutex used to protect the QIOChannel fd from +* the concurrent access by the VCPUs since proxy +* blocks while awaiting for the replies from the +* process remote. +*/ +QemuMutex io_mutex; +QIOChannel *ioc; +}PCIProxyDev ; + +#endif /* PROXY_H */ Signature · 1 line
2.25.GIT
Re: [PATCH v9 11/20] multi-process: introduce proxy object
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · On Thu, Aug 27, 2020 at 11:12:22AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Defines a PCI Device proxy object as a child of
TYPE_PCI_DEVICE.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>Hmm I think this device needs to block migration. And maybe the pci host device needs to do it too?
Thanks for the comment Michael. We will add a migration blocker from this device.
—
Jag
Quoted 168 lines
Quoted 167 lines
---
MAINTAINERS | 2 + hw/pci/meson.build | 1 + hw/pci/proxy.c | 84 ++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 34 +++++++++++++++++ 4 files changed, 121 insertions(+)create mode 100644
hw/pci/proxy.c
create mode 100644include/hw/pci/proxy.hMAINTAINERS +0
-0@@ -3052,6 +3052,8 @@ F: include/hw/i386/remote-obj.hF:
hw/i386/remote-obj.c
F:include/hw/i386/remote-memory.h
F:hw/i386/remote-memory.cMAINTAINERS +2
-0+F: hw/pci/proxy.c +F: include/hw/pci/proxy.hBuild and test automation
-------------------------hw/pci/meson.build +1
-0@@ -12,6 +12,7 @@ pci_ss.add(files( # allow plugging PCIe devices into PCI buses, include them even if # CONFIG_PCI_EXPRESS=n. pci_ss.add(files('pcie.c', 'pcie_aer.c')) +pci_ss.add(when: 'CONFIG_MPQEMU', if_true: files('proxy.c')) softmmu_ss.add(when: 'CONFIG_PCI_EXPRESS', if_true: files('pcie_port.c', 'pcie_host.c')) softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss)hw/pci/proxy.c new file +84
-0@@ -0,0 +1,84 @@ +/* +* 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 "hw/pci/proxy.h" +#include "hw/pci/pci.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "hw/qdev-properties.h" +#include "monitor/monitor.h" + +static void proxy_set_socket (PCIProxyDev *pdev,int fd,Error **errp) +{ + pdev->ioc =qio_channel_new_fd (fd, errp); +} + +static Property proxy_properties[] = { +DEFINE_PROP_STRING ("fd" , PCIProxyDev, fd), +DEFINE_PROP_END_OF_LIST (), +}; + +static void pci_proxy_dev_realize (PCIDevice *device,Error **errp) +{ +PCIProxyDev *dev =PCI_PROXY_DEV (device); +int fd; + +if (dev->fd) { + fd =monitor_fd_param (cur_mon, dev->fd, errp); +if (fd ==-1 ) { +error_prepend (errp,"proxy: unable to parse fd: " ); +return ; + } +proxy_set_socket (dev, fd, errp); + }else { +error_setg (errp,"fd parameter not specified for %s" , +DEVICE (device)->id); +return ; + } + +qemu_mutex_init (&dev->io_mutex); +qio_channel_set_blocking (dev->ioc, true,NULL ); +} + +static void pci_proxy_dev_exit (PCIDevice *pdev) +{ +PCIProxyDev *dev =PCI_PROXY_DEV (pdev); + +qio_channel_close (dev->ioc,NULL ); +} + +static void pci_proxy_dev_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); + + k->realize = pci_proxy_dev_realize; + k->exit = pci_proxy_dev_exit; +device_class_set_props (dc, proxy_properties); +} + +static const TypeInfo pci_proxy_dev_type_info = { + .name =TYPE_PCI_PROXY_DEV , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIProxyDev), + .class_init = pci_proxy_dev_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + +static void pci_proxy_dev_register_types (void ) +{ +type_register_static (&pci_proxy_dev_type_info); +} + +type_init (pci_proxy_dev_register_types)include/hw/pci/proxy.h new file +34
-0@@ -0,0 +1,34 @@ +/* +* 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 PROXY_H +#define PROXY_H + +#include "hw/pci/pci.h" +#include "io/channel.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV (obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { +PCIDevice parent_dev; +char *fd; + +/* +* Mutex used to protect the QIOChannel fd from +* the concurrent access by the VCPUs since proxy +* blocks while awaiting for the replies from the +* process remote. +*/ +QemuMutex io_mutex; +QIOChannel *ioc; +}PCIProxyDev ; + +#endif /* PROXY_H */ Signature · 1 line
2.25.GIT
PATCH v9 12/20 multi-process: add proxy communication functions
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
--- include/io/mpqemu-link.h | 4 ++++ io/mpqemu-link.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/io/mpqemu-link.h +4 -0
@@ -15,6 +15,8 @@#include "qemu/thread.h" #include "io/channel.h" #include "exec/hwaddr.h" +#include "io/channel-socket.h" +#include "hw/pci/proxy.h" #define REMOTE_MAX_FDS 8
@@ -77,6 +79,8 @@ typedef struct MPQemuRequest MPQemuRequest;void mpqemu_msg_send_in_co (MPQemuRequest *req,QIOChannel *ioc,Error **errp);void mpqemu_msg_recv_in_co (MPQemuRequest *req,QIOChannel *ioc,Error **errp); +uint64_t mpqemu_msg_send_and_await_reply (MPQemuMsg *msg,PCIProxyDev *pdev, +Error **errp);void mpqemu_msg_send (MPQemuMsg *msg,QIOChannel *ioc,Error **errp);void mpqemu_msg_recv (MPQemuMsg *msg,QIOChannel *ioc,Error **errp);
io/mpqemu-link.c +38 -0
@@ -17,6 +17,7 @@#include "qemu/iov.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" +#include "io/channel.h" void mpqemu_msg_send (MPQemuMsg *msg,QIOChannel *ioc,Error **errp) {
@@ -150,6 +151,43 @@ fail: } } +uint64_t mpqemu_msg_send_and_await_reply (MPQemuMsg *msg,PCIProxyDev *pdev, +Error **errp) +{ +MPQemuMsg msg_reply = {0 }; +uint64_t ret =UINT64_MAX ; +Error *local_err =NULL ; + +qemu_mutex_unlock_iothread (); +qemu_mutex_lock (&pdev->io_mutex); + +mpqemu_msg_send (msg, pdev->ioc, &local_err); +if (local_err) { +error_propagate (errp, local_err); + goto exit_send; + } + +mpqemu_msg_recv (&msg_reply, pdev->ioc, &local_err); +if (local_err) { +error_propagate (errp, local_err); + goto exit_send; + } + +if (!mpqemu_msg_valid (&msg_reply) || msg_reply.cmd !=RET_MSG ) { +error_setg (errp,"ERROR: Invalid reply received for command %d" , + msg->cmd); + goto exit_send; + }else { + ret = msg_reply.data.u64; + } + + exit_send: +qemu_mutex_unlock (&pdev->io_mutex); +qemu_mutex_lock_iothread (); + +return ret; +} + static void coroutine_fn mpqemu_msg_send_co(void *data) {MPQemuRequest *req = (MPQemuRequest *)data;
Signature · 1 line
2.25.GIT
Re: [PATCH v9 12/20] multi-process: add proxy communication functions
io/mpqemu-link.c fail: · line 155
Quoted 2 lines · On Thu, Aug 27, 2020 at 11:12:23AM -0700, [email protected] wrote:
io/mpqemu-link.c +2
-0+uint64_t mpqemu_msg_send_and_await_reply (MPQemuMsg *msg,PCIProxyDev *pdev, +Error **errp)
A doc comment that says "called from a vcpu thread in non-coroutine context" would help document the constraints.
PATCH v9 13/20 multi-process: Forward PCI config space acceses to the remote process
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
The Proxy Object sends the PCI config space accesses as messages to the remote process over the communication channel
TODO:
Investigate if the local PCI config writes can be dropped. Without the proxy local PCI config space writes for the device, the driver in the guest times out on the probing.
We have tried to only refer to the remote for the PCI config writes, but the driver timeout in the guest forced as to left this as it is (removing local PCI config only).
--- hw/i386/remote-msg.c | 70 ++++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 50 ++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 9 ++++++ io/mpqemu-link.c | 6 ++++ 4 files changed, 135 insertions(+)
hw/i386/remote-msg.c +70 -0
@@ -15,6 +15,12 @@#include "io/mpqemu-link.h" #include "qapi/error.h" #include "sysemu/runstate.h" +#include "hw/pci/pci.h" + +static void process_config_write (QIOChannel *ioc,PCIDevice *dev, +MPQemuMsg *msg); +static void process_config_read (QIOChannel *ioc,PCIDevice *dev, +MPQemuMsg *msg);gboolean mpqemu_process_msg (QIOChannel *ioc,GIOCondition cond,gpointer opaque)
@@ -50,6 +56,12 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, }switch (msg.cmd) { +case PCI_CONFIG_WRITE : +process_config_write (ioc, pci_dev, &msg); +break ; +case PCI_CONFIG_READ : +process_config_read (ioc, pci_dev, &msg); +break ;default : error_setg(&local_err, "Unknown command (%d) received for device %s (pid=%d)",
@@ -64,3 +76,61 @@ exit:return TRUE; } + +static void process_config_write (QIOChannel *ioc,PCIDevice *dev, +MPQemuMsg *msg) +{ +ConfDataMsg *conf = (ConfDataMsg *)&msg->data.conf_data; +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; +Error *local_err =NULL ; + +if ((conf->addr +sizeof (conf->val)) >pci_config_size (dev)) { +error_report ("Bad address received when writing PCI config, pid %d" , +getpid ()); + ret.data.u64 =UINT64_MAX ; + }else { +pci_default_write_config (dev, conf->addr, conf->val, conf->l); + } + + ret.cmd =RET_MSG ; + ret.size =sizeof (ret.data.u64); + + req.ioc = ioc; + req.msg = &ret; + +mpqemu_msg_send_in_co (&req, ioc, &local_err); +if (local_err) { +error_report ("Could not send message to proxy from pid %d" , +getpid ()); + } +} + +static void process_config_read (QIOChannel *ioc,PCIDevice *dev, +MPQemuMsg *msg) +{ +ConfDataMsg *conf = (ConfDataMsg *)&msg->data.conf_data; +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; +Error *local_err =NULL ; + +if ((conf->addr +sizeof (conf->val)) >pci_config_size (dev)) { +error_report ("Bad address received when reading PCI config, pid %d" , +getpid ()); + ret.data.u64 =UINT64_MAX ; + }else { + ret.data.u64 =pci_default_read_config (dev, conf->addr, conf->l); + } + + ret.cmd =RET_MSG ; + ret.size =sizeof (ret.data.u64); + + req.ioc = ioc; + req.msg = &ret; + +mpqemu_msg_send_in_co (&req, ioc, &local_err); +if (local_err) { +error_report ("Could not send message to proxy from pid %d" , +getpid ()); + } +}
hw/pci/proxy.c +50 -0
68 lines not on this page · raw message
include/io/mpqemu-link.h +9 -0
@@ -34,6 +34,8 @@ typedef enum {INIT =0 ,SYNC_SYSMEM ,RET_MSG , +PCI_CONFIG_WRITE , +PCI_CONFIG_READ ,MAX =INT_MAX , } MPQemuCmd;
@@ -43,6 +45,12 @@ typedef struct {off_t offsets[REMOTE_MAX_FDS ]; } SyncSysmemMsg; +typedef struct { +uint32_t addr; +uint32_t val; +int l; +}ConfDataMsg ; +/** * MPQemuMsg: * @cmd: The remote command
@@ -60,6 +68,7 @@ typedef struct {union {uint64_t u64; +ConfDataMsg conf_data;SyncSysmemMsg sync_sysmem; } data;
io/mpqemu-link.c +6 -0
@@ -322,6 +322,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)return false; }break ; +case PCI_CONFIG_WRITE : +case PCI_CONFIG_READ : +if (msg->size !=sizeof (ConfDataMsg)) { +return false; + } +break ;default :break ; }
Signature · 1 line
2.25.GIT
Re: [PATCH v9 13/20] multi-process: Forward PCI config space acceses to the remote process
Quoted 16 lines · On Thu, Aug 27, 2020 at 11:12:24AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
The Proxy Object sends the PCI config space accesses as messages to the remote process over the communication channel
TODO:
Investigate if the local PCI config writes can be dropped. Without the proxy local PCI config space writes for the device, the driver in the guest times out on the probing.
We have tried to only refer to the remote for the PCI config writes, but the driver timeout in the guest forced as to left this as it is (removing local PCI config only).Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>
Quoted 6 lines
--- hw/i386/remote-msg.c | 70 ++++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 50 ++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 9 ++++++ io/mpqemu-link.c | 6 ++++ 4 files changed, 135 insertions(+)
PATCH v9 14/20 multi-process: PCI BAR read/write handling for proxy & remote endpoints
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Proxy device object implements handler for PCI BAR writes and reads. The handler uses BAR_WRITE/BAR_READ message to communicate to the remote process with the BAR address and value to be written/read. The remote process implements handler for BAR_WRITE/BAR_READ message.
--- hw/i386/remote-msg.c | 94 ++++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 64 ++++++++++++++++++++++++++- include/hw/pci/proxy.h | 16 ++++++- include/io/mpqemu-link.h | 10 +++++ io/mpqemu-link.c | 6 +++ 5 files changed, 186 insertions(+), 4 deletions(-)
hw/i386/remote-msg.c +94 -0
@@ -16,11 +16,14 @@#include "qapi/error.h" #include "sysemu/runstate.h" #include "hw/pci/pci.h" +#include "exec/memattrs.h" static void process_config_write (QIOChannel *ioc,PCIDevice *dev,MPQemuMsg *msg);static void process_config_read (QIOChannel *ioc,PCIDevice *dev,MPQemuMsg *msg); +static void process_bar_write (QIOChannel *ioc,MPQemuMsg *msg,Error **errp); +static void process_bar_read (QIOChannel *ioc,MPQemuMsg *msg,Error **errp);gboolean mpqemu_process_msg (QIOChannel *ioc,GIOCondition cond,gpointer opaque)
@@ -62,6 +65,12 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond,case PCI_CONFIG_READ :process_config_read (ioc, pci_dev, &msg);break ; +case BAR_WRITE : +process_bar_write (ioc, &msg, &local_err); +break ; +case BAR_READ : +process_bar_read (ioc, &msg, &local_err); +break ;default : error_setg(&local_err, "Unknown command (%d) received for device %s (pid=%d)",
@@ -134,3 +143,88 @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, getpid()); } } + +static void process_bar_write (QIOChannel *ioc,MPQemuMsg *msg,Error **errp) +{ +BarAccessMsg *bar_access = &msg->data.bar_access; +AddressSpace *as = + bar_access->memory ? &address_space_memory : &address_space_io; +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; +MemTxResult res; +uint64_t val; +Error *local_err =NULL ; + +if (!is_power_of_2 (bar_access->size) || + (bar_access->size >sizeof (uint64_t ))) { + ret.data.u64 =UINT64_MAX ; + goto fail; + } + + val =cpu_to_le64 (bar_access->val); + + res =address_space_rw (as, bar_access->addr,MEMTXATTRS_UNSPECIFIED , + (void *)&val, bar_access->size, true); + +if (res !=MEMTX_OK ) { +error_setg (errp,"Could not perform address space write operation," +" inaccessible address: %lx in pid %d." , + bar_access->addr,getpid ()); + ret.data.u64 =-1 ; + } + +fail: + ret.cmd =RET_MSG ; + ret.size =sizeof (ret.data.u64); + + req.ioc = ioc; + req.msg = &ret; + +mpqemu_msg_send_in_co (&req, ioc, (errp && *errp) ?NULL : &local_err); +if (local_err) { +error_setg (errp,"Error while sending message to proxy " +"in remote process pid=%d" ,getpid ()); + } +} + +static void process_bar_read (QIOChannel *ioc,MPQemuMsg *msg,Error **errp) +{ +BarAccessMsg *bar_access = &msg->data.bar_access; +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; +AddressSpace *as; +MemTxResult res; +uint64_t val =0 ; +Error *local_err =NULL ; + + as = bar_access->memory ? &address_space_memory : &address_space_io; + +if (!is_power_of_2 (bar_access->size) || + (bar_access->size >sizeof (uint64_t ))) { + val =UINT64_MAX ; + goto fail; + } + + res =address_space_rw (as, bar_access->addr,MEMTXATTRS_UNSPECIFIED , + (void *)&val, bar_access->size, false); + +if (res !=MEMTX_OK ) { +error_setg (errp,"Could not perform address space read operation," +" inaccessible address: %lx in pid %d." , + bar_access->addr,getpid ()); + val =UINT64_MAX ; + } + +fail: + ret.cmd =RET_MSG ; + ret.data.u64 =le64_to_cpu (val); + ret.size =sizeof (ret.data.u64); + + req.ioc = ioc; + req.msg = &ret; +mpqemu_msg_send_in_co (&req, ioc, (errp && *errp) ?NULL : &local_err); +if (local_err) { +error_setg (errp,"Error while sending message to proxy " +"in remote process pid=%d" ,getpid ()); + } +}
hw/pci/proxy.c +62 -2
79 lines not on this page · raw message
include/hw/pci/proxy.h +14 -2
@@ -17,7 +17,17 @@#define PCI_PROXY_DEV (obj) \ OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) -typedef struct PCIProxyDev { +typedef struct PCIProxyDev PCIProxyDev ; + +typedef struct ProxyMemoryRegion { +PCIProxyDev *dev; +MemoryRegion mr; +bool memory; +bool present; +uint8_t type; +}ProxyMemoryRegion ; + +struct PCIProxyDev {PCIDevice parent_dev;char *fd;
@@ -29,6 +39,8 @@ typedef struct PCIProxyDev {*/ QemuMutex io_mutex;QIOChannel *ioc; -} PCIProxyDev; + + ProxyMemoryRegion region[PCI_NUM_REGIONS]; +};#endif /* PROXY_H */
include/io/mpqemu-link.h +10 -0
@@ -36,6 +36,8 @@ typedef enum {RET_MSG ,PCI_CONFIG_WRITE ,PCI_CONFIG_READ , +BAR_WRITE , +BAR_READ ,MAX =INT_MAX , } MPQemuCmd;
@@ -51,6 +53,13 @@ typedef struct {int l; } ConfDataMsg; +typedef struct { +hwaddr addr; +uint64_t val; +unsigned size; +bool memory; +}BarAccessMsg ; +/** * MPQemuMsg: * @cmd: The remote command
@@ -70,6 +79,7 @@ typedef struct {uint64_t u64;ConfDataMsg conf_data;SyncSysmemMsg sync_sysmem; +BarAccessMsg bar_access; } data;int fds[REMOTE_MAX_FDS ];
io/mpqemu-link.c +6 -0
@@ -328,6 +328,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)return false; }break ; +case BAR_WRITE : +case BAR_READ : +if ((msg->size !=sizeof (BarAccessMsg)) || (msg->num_fds !=0 )) { +return false; + } +break ;default :break ; }
Signature · 1 line
2.25.GIT
Re: [PATCH v9 14/20] multi-process: PCI BAR read/write handling for proxy & remote endpoints
hw/i386/remote-msg.c static void process_config_read(QIOChannel *ioc, PCIDevice *dev, · line 200
Quoted 11 lines · On Thu, Aug 27, 2020 at 11:12:25AM -0700, [email protected] wrote:
hw/i386/remote-msg.c +11
-0+static void process_bar_read (QIOChannel *ioc,MPQemuMsg *msg,Error **errp) +{ +BarAccessMsg *bar_access = &msg->data.bar_access; +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; +AddressSpace *as; +MemTxResult res; +uint64_t val =0 ; +Error *local_err =NULL ; + + as = bar_access->memory ? &address_space_memory : &address_space_io;
Doesn't need to be changed yet but eventually this should directly access BAR MemoryRegions instead of using global address_space_memory/address_space_io. Then bar_access->addr can be relative to the start of the BAR.
Isolating the device from global address spaces makes it possible to support multiple devices running in the same device emulation process.
Quoted 14 lines
hw/pci/proxy.c +1
-1@@ -61,7 +61,7 @@ static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, int l, unsigned int op) {MPQemuMsg msg = {0 }; -long ret = -EINVAL ; +uint64_t ret = -EINVAL ;Error *local_err =NULL ; msg.cmd = op;
hw/pci/proxy.c static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, · line 78
Quoted 8 lines
hw/pci/proxy.c +1
-1@@ -72,7 +72,7 @@ static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, ret =mpqemu_msg_send_and_await_reply (&msg, pdev, &local_err);if (local_err) { -error_report ("Failed to exchange PCI_CONFIG message with remote" ); +error_report_err (local_err); }if (op ==PCI_CONFIG_READ ) { *val = (uint32_t )ret;
Unrelated fixes. Please squash them into the PCI_CONFIG_READ patch.
PATCH v9 15/20 multi-process: Synchronize remote memory
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Add memory-listener object which is used to keep the view of the RAM in sync between QEMU and remote process.
A MemoryListener is registered for system-memory AddressSpace. The listener sends SYNC_SYSMEM message to the remote process when memory listener commits the changes to memory, the remote process receives the message and processes it in the handler for SYNC_SYSMEM message.
--- MAINTAINERS | 2 + hw/i386/remote-msg.c | 4 + hw/pci/memory-sync.c | 210 +++++++++++++++++++++++++++++++++++ hw/pci/meson.build | 2 + hw/pci/proxy.c | 6 + include/hw/pci/memory-sync.h | 27 +++++ include/hw/pci/proxy.h | 3 + 7 files changed, 254 insertions(+) create mode 100644 hw/pci/memory-sync.c create mode 100644 include/hw/pci/memory-sync.h
MAINTAINERS +2 -0
@@ -3054,6 +3054,8 @@ F: include/hw/i386/remote-memory.h F: hw/i386/remote-memory.c F: hw/pci/proxy.c F: include/hw/pci/proxy.h +F: hw/pci/memory-sync.c +F: include/hw/pci/memory-sync.h Build and test automation -------------------------
hw/i386/remote-msg.c +4 -0
@@ -17,6 +17,7 @@#include "sysemu/runstate.h" #include "hw/pci/pci.h" #include "exec/memattrs.h" +#include "hw/i386/remote-memory.h" static void process_config_write (QIOChannel *ioc,PCIDevice *dev,MPQemuMsg *msg);
@@ -71,6 +72,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond,case BAR_READ :process_bar_read (ioc, &msg, &local_err);break ; +case SYNC_SYSMEM : +remote_sysmem_reconfig (&msg, &local_err); +break ;default : error_setg(&local_err, "Unknown command (%d) received for device %s (pid=%d)",
hw/pci/memory-sync.c new file +210 -0
210 lines not on this page · raw message
hw/pci/meson.build +2 -0
@@ -18,3 +18,5 @@ softmmu_ss.add_all(when: 'CONFIG_PCI', if_true: pci_ss) softmmu_ss.add(when: 'CONFIG_PCI', if_false: files('pci-stub.c')) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('pci-stub.c')) + +specific_ss.add(when: 'CONFIG_MPQEMU', if_true: files('memory-sync.c'))
hw/pci/proxy.c +6 -0
@@ -17,6 +17,8 @@#include "monitor/monitor.h" #include "io/mpqemu-link.h" #include "qemu/error-report.h" +#include "hw/pci/memory-sync.h" +#include "qom/object.h" static void proxy_set_socket (PCIProxyDev *pdev,int fd,Error **errp) {
@@ -48,6 +50,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)qemu_mutex_init (&dev->io_mutex);qio_channel_set_blocking (dev->ioc, true,NULL ); + +configure_memory_sync (&dev->sync, dev->ioc); }static void pci_proxy_dev_exit (PCIDevice *pdev)
@@ -55,6 +59,8 @@ static void pci_proxy_dev_exit(PCIDevice *pdev)PCIProxyDev *dev =PCI_PROXY_DEV (pdev);qio_channel_close (dev->ioc,NULL ); + +deconfigure_memory_sync (&dev->sync); } static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val,
include/hw/pci/memory-sync.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* 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 "exec/memory.h" +#include "io/channel.h" + +typedef struct RemoteMemSync { +MemoryListener listener; + +int n_mr_sections; +MemoryRegionSection *mr_sections; + +QIOChannel *ioc; +}RemoteMemSync ; + +void configure_memory_sync (RemoteMemSync *sync,QIOChannel *ioc); +void deconfigure_memory_sync (RemoteMemSync *sync); + +#endif
include/hw/pci/proxy.h +3 -0
@@ -11,6 +11,7 @@#include "hw/pci/pci.h" #include "io/channel.h" +#include "hw/pci/memory-sync.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
@@ -40,6 +41,8 @@ struct PCIProxyDev {QemuMutex io_mutex;QIOChannel *ioc; +RemoteMemSync sync; +ProxyMemoryRegion region[PCI_NUM_REGIONS ]; };
Signature · 1 line
2.25.GIT
Re: [PATCH v9 15/20] multi-process: Synchronize remote memory
Quoted 12 lines · On Thu, Aug 27, 2020 at 11:12:26AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
Add memory-listener object which is used to keep the view of the RAM in sync between QEMU and remote process.
A MemoryListener is registered for system-memory AddressSpace. The listener sendsSYNC_SYSMEMmessage to the remote process when memory listener commits the changes to memory, the remote process receives the message and processes it in the handler forSYNC_SYSMEMmessage.Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>
Quoted 11 lines
--- MAINTAINERS | 2 + hw/i386/remote-msg.c | 4 + hw/pci/memory-sync.c | 210 +++++++++++++++++++++++++++++++++++ hw/pci/meson.build | 2 + hw/pci/proxy.c | 6 + include/hw/pci/memory-sync.h | 27 +++++ include/hw/pci/proxy.h | 3 + 7 files changed, 254 insertions(+) create mode 100644 hw/pci/memory-sync.c create mode 100644 include/hw/pci/memory-sync.h
PATCH v9 16/20 multi-process: create IOHUB object to handle irq
In reply to [email protected]From: Jagannathan Raman <[email protected]>
IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD ioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU.
--- MAINTAINERS | 2 + hw/i386/meson.build | 1 + hw/i386/remote-iohub.c | 123 +++++++++++++++++++++++++++++++++ hw/i386/remote-msg.c | 4 ++ hw/i386/remote.c | 10 +++ hw/pci/proxy.c | 58 ++++++++++++++++ include/hw/i386/remote-iohub.h | 42 +++++++++++ include/hw/i386/remote.h | 3 + include/hw/pci/pci_ids.h | 3 + include/hw/pci/proxy.h | 5 ++ include/io/mpqemu-link.h | 1 + io/mpqemu-link.c | 5 ++ 12 files changed, 257 insertions(+) create mode 100644 hw/i386/remote-iohub.c create mode 100644 include/hw/i386/remote-iohub.h
MAINTAINERS +2 -0
@@ -3056,6 +3056,8 @@ F: hw/pci/proxy.c F: include/hw/pci/proxy.h F: hw/pci/memory-sync.c F: include/hw/pci/memory-sync.h +F: hw/i386/remote-iohub.c +F: include/hw/i386/remote-iohub.h Build and test automation -------------------------
hw/i386/meson.build +1 -0
@@ -27,6 +27,7 @@ i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-msg.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-obj.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-memory.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-iohub.c')) subdir('kvm') subdir('xen')
hw/i386/remote-iohub.c new file +123 -0
123 lines not on this page · raw message
hw/i386/remote-msg.c +4 -0
@@ -18,6 +18,7 @@#include "hw/pci/pci.h" #include "exec/memattrs.h" #include "hw/i386/remote-memory.h" +#include "hw/i386/remote-iohub.h" static void process_config_write (QIOChannel *ioc,PCIDevice *dev,MPQemuMsg *msg);
@@ -75,6 +76,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond,case SYNC_SYSMEM :remote_sysmem_reconfig (&msg, &local_err);break ; +case SET_IRQFD : +process_set_irqfd_msg (pci_dev, &msg); +break ;default : error_setg(&local_err, "Unknown command (%d) received for device %s (pid=%d)",
hw/i386/remote.c +10 -0
@@ -20,12 +20,15 @@#include "exec/address-spaces.h" #include "exec/memory.h" #include "qapi/error.h" +#include "hw/pci/pci_host.h" +#include "hw/i386/remote-iohub.h" static void remote_machine_init (MachineState *machine) {MemoryRegion *system_memory, *system_io, *pci_memory;RemoteMachineState *s =REMOTE_MACHINE (machine);RemotePCIHost *rem_host; +PCIHostState *pci_host; system_memory =get_system_memory (); system_io =get_system_io ();
@@ -45,6 +48,13 @@ static void remote_machine_init(MachineState *machine)memory_region_add_subregion_overlap (system_memory,0x0 , pci_memory,-1 );qdev_realize (DEVICE (rem_host),sysbus_get_default (), &error_fatal); + + pci_host =PCI_HOST_BRIDGE (rem_host); + +remote_iohub_init (&s->iohub); + +pci_bus_irqs (pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub,REMOTE_IOHUB_NB_PIRQS ); }static void remote_machine_class_init (ObjectClass *oc,void *data)
hw/pci/proxy.c +58 -0
82 lines not on this page · raw message
include/hw/i386/remote-iohub.h new file +42 -0
42 lines not on this page · raw message
include/hw/i386/remote.h +3 -0
@@ -15,11 +15,14 @@#include "hw/boards.h" #include "hw/pci-host/remote.h" #include "io/channel.h" +#include "hw/i386/remote-iohub.h" typedef struct RemoteMachineState {MachineState parent_obj;RemotePCIHost *host; + +RemoteIOHubState iohub; }RemoteMachineState ;#define TYPE_REMOTE_MACHINE "remote-machine"
include/hw/pci/pci_ids.h +3 -0
@@ -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/pci/proxy.h +5 -0
@@ -12,6 +12,7 @@#include "hw/pci/pci.h" #include "io/channel.h" #include "hw/pci/memory-sync.h" +#include "qemu/event_notifier.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
@@ -43,6 +44,10 @@ struct PCIProxyDev {RemoteMemSync sync; +int virq; +EventNotifier intr; +EventNotifier resample; +ProxyMemoryRegion region[PCI_NUM_REGIONS ]; };
include/io/mpqemu-link.h +1 -0
@@ -38,6 +38,7 @@ typedef enum {PCI_CONFIG_READ ,BAR_WRITE ,BAR_READ , +SET_IRQFD ,MAX =INT_MAX , } MPQemuCmd;
io/mpqemu-link.c +5 -0
@@ -334,6 +334,11 @@ bool mpqemu_msg_valid(MPQemuMsg *msg)return false; }break ; +case SET_IRQFD : +if (msg->size || (msg->num_fds !=2 )) { +return false; + } +break ;default :break ; }
Signature · 1 line
2.25.GIT
Re: [PATCH v9 16/20] multi-process: create IOHUB object to handle irq
Quoted 10 lines · On Thu, Aug 27, 2020 at 11:12:27AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
IOHUB object is added to manage PCI IRQs. It uses
KVM_IRQFDioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>
Quoted 16 lines
--- MAINTAINERS | 2 + hw/i386/meson.build | 1 + hw/i386/remote-iohub.c | 123 +++++++++++++++++++++++++++++++++ hw/i386/remote-msg.c | 4 ++ hw/i386/remote.c | 10 +++ hw/pci/proxy.c | 58 ++++++++++++++++ include/hw/i386/remote-iohub.h | 42 +++++++++++ include/hw/i386/remote.h | 3 + include/hw/pci/pci_ids.h | 3 + include/hw/pci/proxy.h | 5 ++ include/io/mpqemu-link.h | 1 + io/mpqemu-link.c | 5 ++ 12 files changed, 257 insertions(+) create mode 100644 hw/i386/remote-iohub.c create mode 100644 include/hw/i386/remote-iohub.h
PATCH v9 17/20 multi-process: Retrieve PCI info from remote process
In reply to [email protected]From: Jagannathan Raman <[email protected]>
Retrieve PCI configuration info about the remote device and configure the Proxy PCI object based on the returned information
--- hw/pci/proxy.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
hw/pci/proxy.c +85 -0
@@ -23,6 +23,8 @@#include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +static void probe_pci_info (PCIDevice *dev,Error **errp); +static void proxy_set_socket (PCIProxyDev *pdev,int fd,Error **errp) { pdev->ioc =qio_channel_new_fd (fd, errp);
@@ -86,6 +88,7 @@ static void setup_irqfd(PCIProxyDev *dev)static void pci_proxy_dev_realize (PCIDevice *device,Error **errp) {PCIProxyDev *dev =PCI_PROXY_DEV (device); +uint8_t *pci_conf = device->config;int fd;if (dev->fd) {
@@ -104,9 +107,14 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)qemu_mutex_init (&dev->io_mutex);qio_channel_set_blocking (dev->ioc, true,NULL ); + pci_conf[PCI_LATENCY_TIMER ] =0xff ; + pci_conf[PCI_INTERRUPT_PIN ] =0x01 ; +configure_memory_sync (&dev->sync, dev->ioc);setup_irqfd (dev); + +probe_pci_info (PCI_DEVICE (dev), errp); }static void pci_proxy_dev_exit (PCIDevice *pdev)
@@ -256,3 +264,80 @@ const MemoryRegionOps proxy_mr_ops = { .max_access_size = 8, }, }; + +static void probe_pci_info (PCIDevice *dev,Error **errp) +{ +PCIDeviceClass *pc =PCI_DEVICE_GET_CLASS (dev); +uint32_t orig_val, new_val, base_class, val; +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); +DeviceClass *dc =DEVICE_CLASS (pc); +uint8_t type; +int i, size; +char *name; + +config_op_send (pdev,PCI_VENDOR_ID , &val,2 ,PCI_CONFIG_READ ); + pc->vendor_id = (uint16_t )val; + +config_op_send (pdev,PCI_DEVICE_ID , &val,2 ,PCI_CONFIG_READ ); + pc->device_id = (uint16_t )val; + +config_op_send (pdev,PCI_CLASS_DEVICE , &val,2 ,PCI_CONFIG_READ ); + pc->class_id = (uint16_t )val; + +config_op_send (pdev,PCI_SUBSYSTEM_ID , &val,2 ,PCI_CONFIG_READ ); + pc->subsystem_id = (uint16_t )val; + + base_class = pc->class_id >>4 ; +switch (base_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 <PCI_NUM_REGIONS ; i++) { +config_op_send (pdev,PCI_BASE_ADDRESS_0 + (4 * i), &orig_val,4 , +PCI_CONFIG_READ ); + new_val =0xffffffff ; +config_op_send (pdev,PCI_BASE_ADDRESS_0 + (4 * i), &new_val,4 , +PCI_CONFIG_WRITE ); +config_op_send (pdev,PCI_BASE_ADDRESS_0 + (4 * i), &new_val,4 , +PCI_CONFIG_READ ); + size = (~(new_val &0xFFFFFFF0 )) +1 ; +config_op_send (pdev,PCI_BASE_ADDRESS_0 + (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_mr_ops, &pdev->region[i], + name, size); +pci_register_bar (dev, i, type, &pdev->region[i].mr); +g_free (name); + } + } +}
Signature · 1 line
2.25.GIT
Re: [PATCH v9 17/20] multi-process: Retrieve PCI info from remote process
Quoted 11 lines · On Thu, Aug 27, 2020 at 11:12:28AM -0700, [email protected] wrote:
From: Jagannathan Raman <[email protected]>
Retrieve PCI configuration info about the remote device and configure the Proxy PCI object based on the returned information
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>--- hw/pci/proxy.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
PATCH v9 18/20 multi-process: perform device reset in the remote process
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
Perform device reset in the remote process when QEMU performs device reset. This is required to reset the internal state (like registers, etc...) of emulated devices
--- hw/i386/remote-msg.c | 25 +++++++++++++++++++++++++ hw/pci/proxy.c | 20 ++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 3 files changed, 46 insertions(+)
hw/i386/remote-msg.c +25 -0
@@ -19,6 +19,7 @@#include "exec/memattrs.h" #include "hw/i386/remote-memory.h" #include "hw/i386/remote-iohub.h" +#include "sysemu/reset.h" static void process_config_write (QIOChannel *ioc,PCIDevice *dev,MPQemuMsg *msg);
@@ -26,6 +27,8 @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg);static void process_bar_write (QIOChannel *ioc,MPQemuMsg *msg,Error **errp);static void process_bar_read (QIOChannel *ioc,MPQemuMsg *msg,Error **errp); +static void process_device_reset_msg (QIOChannel *ioc,PCIDevice *dev, +Error **errp);gboolean mpqemu_process_msg (QIOChannel *ioc,GIOCondition cond,gpointer opaque)
@@ -79,6 +82,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond,case SET_IRQFD :process_set_irqfd_msg (pci_dev, &msg);break ; +case DEVICE_RESET : +process_device_reset_msg (ioc, pci_dev, &local_err); +break ;default : error_setg(&local_err, "Unknown command (%d) received for device %s (pid=%d)",
@@ -236,3 +242,22 @@ fail: "in remote process pid=%d", getpid()); } } + +static void process_device_reset_msg (QIOChannel *ioc,PCIDevice *dev, +Error **errp) +{ +DeviceClass *dc =DEVICE_GET_CLASS (dev); +DeviceState *s =DEVICE (dev); +MPQemuMsg ret = {0 }; +MPQemuRequest req = {0 }; + +if (dc->reset) { + dc->reset (s); + } + + ret.cmd =RET_MSG ; + req.msg = &ret; + req.ioc = ioc; + +mpqemu_msg_send_in_co (&req, ioc, errp); +}
hw/pci/proxy.c +20 -0
@@ -24,6 +24,7 @@#include "util/event_notifier-posix.c" static void probe_pci_info (PCIDevice *dev,Error **errp); +static void proxy_device_reset (DeviceState *dev);static void proxy_set_socket (PCIProxyDev *pdev,int fd,Error **errp) {
@@ -184,6 +185,8 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; + dc->reset = proxy_device_reset; +device_class_set_props (dc, proxy_properties); }
@@ -341,3 +344,20 @@ static void probe_pci_info(PCIDevice *dev, Error **errp) } } } + +static void proxy_device_reset (DeviceState *dev) +{ +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); +MPQemuMsg msg = {0 }; +Error *local_err =NULL ; + + msg.cmd =DEVICE_RESET ; + msg.size =0 ; + + (void )mpqemu_msg_send_and_await_reply (&msg, pdev, &local_err); +if (local_err) { +error_report ("Failed to send DEVICE_RESET to the remote process" ); +error_free (local_err); + } + +}
include/io/mpqemu-link.h +1 -0
@@ -39,6 +39,7 @@ typedef enum {BAR_WRITE ,BAR_READ ,SET_IRQFD , +DEVICE_RESET ,MAX =INT_MAX , } MPQemuCmd;
Signature · 1 line
2.25.GIT
Re: [PATCH v9 18/20] multi-process: perform device reset in the remote process
Quoted 6 lines · On Thu, Aug 27, 2020 at 11:12:29AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Perform device reset in the remote process when QEMU performs device reset. This is required to reset the internal state (like registers, etc...) of emulated devices
Quoted 8 lines
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>--- hw/i386/remote-msg.c | 25 +++++++++++++++++++++++++ hw/pci/proxy.c | 20 ++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 3 files changed, 46 insertions(+)
PATCH v9 19/20 multi-process: add the concept description to docs/devel/qemu-multiprocess
In reply to [email protected]From: John G Johnson <[email protected]>
--- MAINTAINERS | 1 + docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 966 +++++++++++++++++++++++++++++++++++ 3 files changed, 968 insertions(+) create mode 100644 docs/devel/multi-process.rst
MAINTAINERS +1 -0
@@ -3058,6 +3058,7 @@ F: hw/pci/memory-sync.c F: include/hw/pci/memory-sync.h F: hw/i386/remote-iohub.c F: include/hw/i386/remote-iohub.h +F: docs/devel/multi-process.rst Build and test automation -------------------------
docs/devel/index.rst +1 -0
@@ -31,3 +31,4 @@ Contents: reset s390-dasd-ipl clocks + multi-process
docs/devel/multi-process.rst new file +966 -0
966 lines not on this page · raw message
Signature · 1 line
2.25.GIT
Re: [PATCH v9 19/20] multi-process: add the concept description to docs/devel/qemu-multiprocess
Quoted 11 lines · On Thu, Aug 27, 2020 at 11:12:30AM -0700, [email protected] wrote:
From: John G Johnson <[email protected]>
Signed-off-by John G Johnson <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>--- MAINTAINERS | 1 + docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 966 +++++++++++++++++++++++++++++++++++ 3 files changed, 968 insertions(+) create mode 100644 docs/devel/multi-process.rst
PATCH v9 20/20 multi-process: add configure and usage information
In reply to [email protected]From: Elena Ufimtseva <[email protected]>
--- MAINTAINERS | 2 ++ docs/multi-process.rst | 67 ++++++++++++++++++++++++++++++++++++++ scripts/mpqemu-launcher.py | 49 ++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 docs/multi-process.rst create mode 100755 scripts/mpqemu-launcher.py
MAINTAINERS +2 -0
@@ -3059,6 +3059,8 @@ F: include/hw/pci/memory-sync.h F: hw/i386/remote-iohub.c F: include/hw/i386/remote-iohub.h F: docs/devel/multi-process.rst +F: scripts/mpqemu-launcher.py +F: scripts/mpqemu-launcher-perf-mode.py Build and test automation -------------------------
docs/multi-process.rst new file +67 -0
67 lines not on this page · raw message
scripts/mpqemu-launcher.py new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.25.GIT
Re: [PATCH v9 20/20] multi-process: add configure and usage information
Quoted 5 lines · On Thu, Aug 27, 2020 at 11:12:31AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>
Quoted 7 lines
--- MAINTAINERS | 2 ++ docs/multi-process.rst | 67 ++++++++++++++++++++++++++++++++++++++ scripts/mpqemu-launcher.py | 49 ++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 docs/multi-process.rst create mode 100755 scripts/mpqemu-launcher.py
Quoted 8 lines · On Thu, Aug 27, 2020 at 11:12:11AM -0700, [email protected] wrote:
From: Elena Ufimtseva <[email protected]>
Hello
This is the v9 of the patchset. Thank you very much for the detailed feedback for v8. We appreciate your time. We believe we have address all the comments for v8 in the current series. Special thanks to Stefan Hajnoczi.
I think overall it's in a good shape.
IIUC migration isn't supported yet so needs to be blocked. But otherwise I don't see why we won't merge this and interate on features upstream.
Quoted 142 lines
The v9 has the following changes:
- Communication channel. Qemu side uses blocking call to send and receive the message from the remote and cannot progress further until the remote side replies. Enhanced the communication channel by dropping iothread lock before blocking on Qemu end. Use the co-routines on the remote end to avoid blocking QMP monitor;
- removed the heartbeat functionality, it will be added later in a full extent;
- fixed leaked errors and similar fixes;
- eliminated bytestream passing over the channel;
- The build system had to be changed in order to accomodate the latest changes in Qemu to use Kconfig/mason.To touch upon the history of this project, we posted the Proof Of Concept patches before the BoF session in 2018. Subsequently, we posted 8 versions on the qemu-devel mailist. You can find them by following the links below ([1] - [8]).
Following people contributed to the design and
implementation of this project:
Jagannathan Raman <[email protected]>
Elena Ufimtseva <[email protected]>
John G Johnson <[email protected]>
Stefan Hajnoczi <[email protected]>
Konrad Wilk <[email protected]>
Kanth Ghatraju <[email protected]>We would like to thank QEMU community for your feedback in the design and implementation of this project.
Qemu wiki page:
https://wiki.qemu.org/Features/MultiProcessQEMUFor the full concept writeup about QEMU multi-process, please refer to
docs/devel/qemu-multiprocess.rst. Also seedocs/qemu-multiprocess.txtfor usage information.We welcome all your ideas, concerns, and questions for this patchset.
[POC]: https://www.mail-archive.com/[email protected]/msg566538.html
[1]: https://www.mail-archive.com/[email protected]/msg602285.html
[2]: https://www.mail-archive.com/[email protected]/msg624877.html
[3]: https://www.mail-archive.com/[email protected]/msg642000.html
[4]: https://www.mail-archive.com/[email protected]/msg655118.html
[5]: https://www.mail-archive.com/[email protected]/msg682429.html
[6]: https://www.mail-archive.com/[email protected]/msg697484.html
[7]: https://patchew.org/QEMU/[email protected]/
[8]: https://www.mail-archive.com/[email protected]/msg727007.htmlElena Ufimtseva (8):
multi-process: add qio channel function to transmit
multi-process: define MPQemuMsg format and transmission functions
multi-process: define transmission functions in remote
multi-process: introduce proxy object
multi-process: add proxy communication functions
multi-process: Forward PCI config space acceses to the remote process
multi-process: perform device reset in the remote process
multi-process: add configure and usage informationJagannathan Raman (11):
memory: alloc RAM from file at offset
multi-process: Add config option for multi-process QEMU
multi-process: setup PCI host bridge for remote device
multi-process: setup a machine object for remote device process
multi-process: Initialize message handler in remote device
multi-process: Associate fd of a PCIDevice with its object
multi-process: setup memory manager for remote device
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 processJohn G Johnson (1):
multi-process: add the concept description to
docs/devel/qemu-multiprocessMAINTAINERS | 26 + backends/hostmem-memfd.c | 2 +- configure | 10 + docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 966 ++++++++++++++++++++++++++++++++ docs/multi-process.rst | 67 +++ exec.c | 11 +- hw/i386/meson.build | 5 + hw/i386/remote-iohub.c | 123 ++++ hw/i386/remote-memory.c | 58 ++ hw/i386/remote-msg.c | 263 +++++++++ hw/i386/remote-obj.c | 140 +++++ hw/i386/remote.c | 79 +++ hw/misc/ivshmem.c | 3 +- hw/pci-host/meson.build | 1 + hw/pci-host/remote.c | 75 +++ hw/pci/memory-sync.c | 210 +++++++ hw/pci/meson.build | 3 + hw/pci/proxy.c | 363 ++++++++++++ include/exec/memory.h | 2 + include/exec/ram_addr.h | 2 +- include/hw/i386/remote-iohub.h | 42 ++ include/hw/i386/remote-memory.h | 19 + include/hw/i386/remote-obj.h | 42 ++ include/hw/i386/remote.h | 35 ++ include/hw/pci-host/remote.h | 31 + include/hw/pci/memory-sync.h | 27 + include/hw/pci/pci_ids.h | 3 + include/hw/pci/proxy.h | 54 ++ include/io/channel.h | 24 + include/io/mpqemu-link.h | 110 ++++ include/qemu/mmap-alloc.h | 3 +- io/channel.c | 45 ++ io/meson.build | 2 + io/mpqemu-link.c | 347 ++++++++++++ meson.build | 1 + scripts/mpqemu-launcher.py | 49 ++ softmmu/memory.c | 3 +- util/mmap-alloc.c | 7 +- util/oslib-posix.c | 2 +- 40 files changed, 3243 insertions(+), 13 deletions(-) create mode 100644 docs/devel/multi-process.rst create mode 100644 docs/multi-process.rst create mode 100644 hw/i386/remote-iohub.c create mode 100644 hw/i386/remote-memory.c create mode 100644 hw/i386/remote-msg.c create mode 100644 hw/i386/remote-obj.c create mode 100644 hw/i386/remote.c create mode 100644 hw/pci-host/remote.c create mode 100644 hw/pci/memory-sync.c create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/i386/remote-iohub.h create mode 100644 include/hw/i386/remote-memory.h create mode 100644 include/hw/i386/remote-obj.h create mode 100644 include/hw/i386/remote.h create mode 100644 include/hw/pci-host/remote.h create mode 100644 include/hw/pci/memory-sync.h create mode 100644 include/hw/pci/proxy.h create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c create mode 100755 scripts/mpqemu-launcher.pySignature · 1 line
2.25.GIT
Quoted 5 lines · On Thu, Aug 27, 2020 at 11:12:11AM -0700, [email protected] wrote:
The v9 has the following changes:
- Communication channel. Qemu side uses blocking call to send and receive the message from the remote and cannot progress further until the remote side replies. Enhanced the communication channel by dropping iothread lock before blocking
Quoted 8 lines
on Qemu end. Use the co-routines on the remote end to avoid blocking QMP monitor;
- removed the heartbeat functionality, it will be added later in a full extent;
- fixed leaked errors and similar fixes;
- eliminated bytestream passing over the channel;
- The build system had to be changed in order to accomodate the latest changes in Qemu to use Kconfig/mason.
Thanks, I left comments but I'm happy with most patches now.
Stefan
Quoted 19 lines · Stefan Hajnoczi
Quoted 5 lines · On Thu, Aug 27, 2020 at 11:12:11AM -0700, [email protected] wrote:
The v9 has the following changes:
- Communication channel. Qemu side uses blocking call to send and receive the message from the remote and cannot progress further until the remote side replies. Enhanced the communication channel by dropping iothread lock before blockingQuoted 8 lines
on Qemu end. Use the co-routines on the remote end to avoid blocking QMP monitor;
- removed the heartbeat functionality, it will be added later in a full extent;
- fixed leaked errors and similar fixes;
- eliminated bytestream passing over the channel;
- The build system had to be changed in order to accomodate the latest changes in Qemu to use Kconfig/mason.
Quoted 1 line
Thanks, I left comments but I'm happy with most patches now.
Thank you for the comments, Stefan. We will address them in the next series.
—
Jag
Quoted 2 lines
Stefan