Initial support of multi-process qemu
Subsystems (4)
v4 cover Initial support of multi-process qemu
Started with the presentation in October 2017 made by Marc-Andre (Red Hat) and Konrad Wilk (Oracle) [1], and continued by Jag's BoF at KVM Forum 2018, the multi-process project is now a prototype and presented in this patchset. John & Elena will present the status of this project in KVM Forum 2019.
This first series enables the emulation of lsi53c895a in a separate process.
We posted the Proof Of Concept patches [2] before the BoF session in 2018. Subsequently, we posted RFC v1 [3], RFC v2 [4] and RFC v3 [5] of this series.
We want to present version 4 of this series, which incorporates the feedback we received for v3 & adds support for live migrating the remote process.
Following people contributed to this patchset:
John G Johnson <[email protected]>
Jagannathan Raman <[email protected]>
Elena Ufimtseva <[email protected]>
Kanth Ghatraju <[email protected]>
For full concept writeup about QEMU disaggregation refer to docs/devel/qemu-multiprocess.rst. Please refer to docs/qemu-multiprocess.txt for usage information.
We are planning on making the following improvements in the future:
- Performance improvements
- Libvirt support
- Enforcement of security policies
- blockdev support
We welcome all your ideas, concerns, and questions for this patchset.
Thank you!
[1]: http://events17.linuxfoundation.org/sites/events/files/slides/KVM%20FORUM%20multi-process.pdf
[1]: https://www.youtube.com/watch?v=Kq1-coHh7lg
[2]: https://www.mail-archive.com/[email protected]/msg566538.html
[3]: https://www.mail-archive.com/[email protected]/msg602285.html
[4]: https://www.mail-archive.com/[email protected]/msg624877.html
[5]: https://www.mail-archive.com/[email protected]/msg642000.html
Elena Ufimtseva (22):
multi-process: add a command line option for debug file
multi-process: introduce proxy object
mutli-process: build remote command line args
multi-process: configure remote side devices
multi-process: add qdev_proxy_add to create proxy devices
multi-process: remote: add setup_devices and setup_drive msg
processing
multi-process: remote: use fd for socket from parent process
multi-process: remote: add create_done condition
multi-process: add processing of remote drive and device command line
multi-process: refractor vl.c code to re-use in remote
multi-process: add remote option
multi-process: add remote options parser
multi-process: add parse_cmdline in remote process
multi-process: send heartbeat messages to remote
multi-process: handle heartbeat messages in remote process multi-process/mon: choose HMP commands based on target multi-process/mig: Load VMSD in the proxy object multi-process/mig: refactor runstate_check into common file multi-process/mig: Synchronize runstate of remote process multi-process/mig: Restore the VMSD in remote process
multi-process: Enable support for multiple devices in remote
multi-process: add configure and usage information
Jagannathan Raman (26):
multi-process: memory: alloc RAM from file at offset
multi-process: util: Add qemu_thread_cancel() to cancel running thread
multi-process: Add stub functions to facilate build of multi-process
multi-process: Add config option for multi-process QEMU
multi-process: build system for remote device process
multi-process: define mpqemu-link object
multi-process: add functions to synchronize proxy and remote endpoints
multi-process: setup PCI host bridge for remote device
multi-process: setup a machine object for remote device process
multi-process: setup memory manager for remote device
multi-process: remote process initialization
multi-process: PCI BAR read/write handling for proxy & remote
endpoints
multi-process: Add LSI device proxy object
multi-process: Synchronize remote memory
multi-process: create IOHUB object to handle irq
multi-process: Introduce build flags to separate remote process code
multi-process: Use separate MMIO communication channel
multi-process: perform device reset in the remote process multi-process/mon: stub functions to enable QMP module for remote
process
multi-process/mon: enable QMP module support in the remote process multi-process/mon: Refactor monitor/chardev functions out of vl.c multi-process/mon: Initialize QMP module for remote processes
multi-process: prevent duplicate memory initialization in remote multi-process/mig: build migration module in the remote process multi-process/mig: Enable VMSD save in the Proxy object multi-process/mig: Send VMSD of remote to the Proxy object
John G Johnson (1):
multi-process: add the concept description to
docs/devel/qemu-multiprocess
Makefile | 2 + Makefile.objs | 39 ++ Makefile.target | 94 ++- accel/stubs/kvm-stub.c | 5 + accel/stubs/tcg-stub.c | 106 ++++ backends/Makefile.objs | 2 + block/Makefile.objs | 2 + chardev/char.c | 14 + configure | 15 + docs/devel/index.rst | 1 + docs/devel/qemu-multiprocess.rst | 1102 +++++++++++++++++++++++++++++++++++ docs/qemu-multiprocess.txt | 86 +++ exec.c | 14 +- hmp-commands-info.hx | 10 + hmp-commands.hx | 25 +- hw/Makefile.objs | 9 + hw/block/Makefile.objs | 2 + hw/core/Makefile.objs | 17 + hw/nvram/Makefile.objs | 2 + hw/pci/Makefile.objs | 4 + hw/proxy/Makefile.objs | 1 + hw/proxy/memory-sync.c | 226 +++++++ hw/proxy/proxy-lsi53c895a.c | 97 +++ hw/proxy/qemu-proxy.c | 807 +++++++++++++++++++++++++ hw/scsi/Makefile.objs | 2 + include/chardev/char.h | 1 + include/exec/address-spaces.h | 2 + include/exec/ram_addr.h | 2 +- include/hw/pci/pci_ids.h | 3 + include/hw/proxy/memory-sync.h | 51 ++ include/hw/proxy/proxy-lsi53c895a.h | 42 ++ include/hw/proxy/qemu-proxy.h | 125 ++++ include/hw/qdev-core.h | 2 + include/io/mpqemu-link.h | 214 +++++++ include/monitor/monitor.h | 2 + include/monitor/qdev.h | 25 + include/qemu-common.h | 8 + include/qemu/log.h | 1 + include/qemu/mmap-alloc.h | 3 +- include/qemu/thread.h | 1 + include/remote/iohub.h | 63 ++ include/remote/machine.h | 48 ++ include/remote/memory.h | 34 ++ include/remote/pcihost.h | 59 ++ include/sysemu/runstate.h | 3 + io/Makefile.objs | 2 + io/mpqemu-link.c | 351 +++++++++++ memory.c | 2 +- migration/Makefile.objs | 12 + migration/savevm.c | 63 ++ migration/savevm.h | 3 + monitor/Makefile.objs | 3 + monitor/misc.c | 84 +-- monitor/monitor-internal.h | 38 ++ monitor/monitor.c | 83 ++- net/Makefile.objs | 2 + qapi/Makefile.objs | 2 + qdev-monitor.c | 270 ++++++++- qemu-options.hx | 21 + qom/Makefile.objs | 4 + remote/Makefile.objs | 6 + remote/iohub.c | 159 +++++ remote/machine.c | 133 +++++ remote/memory.c | 99 ++++ remote/pcihost.c | 85 +++ remote/remote-main.c | 633 ++++++++++++++++++++ remote/remote-opts.c | 131 +++++ remote/remote-opts.h | 31 + replay/Makefile.objs | 2 +- rules.mak | 2 +- runstate.c | 41 ++ scripts/hxtool | 44 +- stubs/audio.c | 12 + stubs/gdbstub.c | 21 + stubs/machine-init-done.c | 4 + stubs/migration.c | 211 +++++++ stubs/monitor.c | 72 +++ stubs/net-stub.c | 121 ++++ stubs/qapi-misc.c | 43 ++ stubs/qapi-target.c | 49 ++ stubs/replay.c | 26 + stubs/runstate-check.c | 3 + stubs/ui-stub.c | 130 +++++ stubs/vl-stub.c | 193 ++++++ stubs/vmstate.c | 20 + stubs/xen-mapcache.c | 22 + ui/Makefile.objs | 2 + util/log.c | 2 + util/mmap-alloc.c | 7 +- util/oslib-posix.c | 2 +- util/qemu-thread-posix.c | 10 + vl-parse.c | 161 +++++ vl.c | 310 ++++------ vl.h | 54 ++ 94 files changed, 6908 insertions(+), 246 deletions(-) create mode 100644 docs/devel/qemu-multiprocess.rst create mode 100644 docs/qemu-multiprocess.txt create mode 100644 hw/proxy/Makefile.objs create mode 100644 hw/proxy/memory-sync.c create mode 100644 hw/proxy/proxy-lsi53c895a.c create mode 100644 hw/proxy/qemu-proxy.c create mode 100644 include/hw/proxy/memory-sync.h create mode 100644 include/hw/proxy/proxy-lsi53c895a.h create mode 100644 include/hw/proxy/qemu-proxy.h create mode 100644 include/io/mpqemu-link.h create mode 100644 include/remote/iohub.h create mode 100644 include/remote/machine.h create mode 100644 include/remote/memory.h create mode 100644 include/remote/pcihost.h create mode 100644 io/mpqemu-link.c create mode 100644 remote/Makefile.objs create mode 100644 remote/iohub.c create mode 100644 remote/machine.c create mode 100644 remote/memory.c create mode 100644 remote/pcihost.c create mode 100644 remote/remote-main.c create mode 100644 remote/remote-opts.c create mode 100644 remote/remote-opts.h create mode 100644 runstate.c mode change 100644 => 100755 scripts/hxtool create mode 100644 stubs/audio.c create mode 100644 stubs/migration.c create mode 100644 stubs/net-stub.c create mode 100644 stubs/qapi-misc.c create mode 100644 stubs/qapi-target.c create mode 100644 stubs/ui-stub.c create mode 100644 stubs/vl-stub.c create mode 100644 stubs/xen-mapcache.c create mode 100644 vl-parse.c create mode 100644 vl.h
Signature · 1 line
1.8.3.1
RFC PATCH v4 1/49 multi-process: memory: alloc RAM from file at offset
Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process.
This will be needed for the following patches.
--- exec.c | 11 +++++++---- include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 3 ++- memory.c | 2 +- util/mmap-alloc.c | 7 ++++--- util/oslib-posix.c | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-)
exec.c +7 -4
@@ -1871,6 +1871,7 @@ static void *file_ram_alloc(RAMBlock *block,ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { MachineState *ms = MACHINE(qdev_get_machine());
@@ -1922,7 +1923,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" );
@@ -2309,7 +2311,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 ;
@@ -2354,7 +2356,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 ;
@@ -2384,7 +2387,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,return NULL ; } - block =qemu_ram_alloc_from_fd (size, mr, ram_flags, fd, errp); + block =qemu_ram_alloc_from_fd (size, mr, ram_flags, fd,0 , errp);if (!block) {if (created) {unlink (mem_path);
include/exec/ram_addr.h +1 -1
@@ -159,7 +159,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);
memory.c +1 -1
@@ -1602,7 +1602,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc_from_fd (size, mr, share ?RAM_SHARED :0 , - fd, &err); + fd,0 , &err); mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();
util/mmap-alloc.c +4 -3
@@ -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
@@ -205,7 +205,7 @@ void *qemu_memalign(size_t alignment, size_t size)void *qemu_anon_ram_alloc (size_t size,uint64_t *alignment,bool shared) {size_t align =QEMU_VMALLOC_ALIGN ; -void *ptr =qemu_ram_mmap (-1 , size, align, shared, false); +void *ptr =qemu_ram_mmap (-1 , size, align, shared, false,0 );if (ptr ==MAP_FAILED ) {return NULL ;
Signature · 1 line
1.8.3.1
RFC PATCH v4 2/49 multi-process: util: Add qemu_thread_cancel() to cancel running thread
In reply to Jagannathan Ramanqemu_thread_cancel() added to destroy a given running thread. This will be needed in the following patches.
--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
include/qemu/thread.h +1 -0
@@ -175,6 +175,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,void *(*start_routine)(void *), void *arg, int mode);void *qemu_thread_join (QemuThread *thread); +void qemu_thread_cancel (QemuThread *thread);void qemu_thread_get_self (QemuThread *thread);bool qemu_thread_is_self (QemuThread *thread);void qemu_thread_exit (void *retval);
util/qemu-thread-posix.c +10 -0
@@ -590,3 +590,13 @@ void *qemu_thread_join(QemuThread *thread) }return ret; } + +void qemu_thread_cancel (QemuThread *thread) +{ +int err; + + err =pthread_cancel (thread->thread); +if (err) { +error_exit (err, __func__); + } +}
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread
Quoted 10 lines · Jagannathan Raman
qemu_thread_cancel()added to destroy a given running thread. This will be needed in the following patches.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
Is this still needed? I thought previous discussion concluded that thread cancellation is hard to get right and it's not actually used by this series?
Stefan
Re: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread
Quoted 12 lines · Stefan Hajnoczi
Quoted 10 lines · Jagannathan Raman
qemu_thread_cancel()added to destroy a given running thread. This will be needed in the following patches.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
Quoted 3 lines
Is this still needed? I thought previous discussion concluded that thread cancellation is hard to get right and it's not actually used by this series?
Hi Stefan,
This is used in PATCH 41/49.
Thank you very much!
--
Jag
Quoted 3 lines
Stefan
Re: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread
Quoted 15 lines · Jag Raman
Quoted 12 lines · Stefan Hajnoczi
Quoted 10 lines · Jagannathan Raman
qemu_thread_cancel()added to destroy a given running thread. This will be needed in the following patches.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
Quoted 7 lines
Quoted 3 lines
Is this still needed? I thought previous discussion concluded that thread cancellation is hard to get right and it's not actually used by this series?
Hi Stefan,
This is used in PATCH 41/49.
I don't believe the cancellation usage in that patch is safe :-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread
Quoted 20 lines · Daniel P. Berrangé
Quoted 19 lines · Jag Raman
Quoted 15 lines · Stefan Hajnoczi
Quoted 10 lines · Jagannathan Raman
qemu_thread_cancel()added to destroy a given running thread. This will be needed in the following patches.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)Is this still needed? I thought previous discussion concluded that thread cancellation is hard to get right and it's not actually used by this series?
Quoted 5 lines
Quoted 3 lines
Hi Stefan,
This is used in PATCH 41/49.
I don't believe the cancellation usage in that patch is safe :-)
Thanks for the feedback, we will address that.
May I please ask why it is not safe? Any clarification will help us to find a better alternative.
Thank you very much!
--
Jag
Quoted 4 lines
Regards,
Daniel
Re: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread
Quoted 25 lines · Jag Raman
Quoted 22 lines · Daniel P. Berrangé
Quoted 21 lines · Jag Raman
Quoted 12 lines · Stefan Hajnoczi
Quoted 10 lines · Jagannathan Raman
qemu_thread_cancel()added to destroy a given running thread. This will be needed in the following patches.Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by Elena Ufimtseva <[email protected]>--- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+)Quoted 3 lines
Is this still needed? I thought previous discussion concluded that thread cancellation is hard to get right and it's not actually used by this series?
Hi Stefan,
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This is used in PATCH 41/49.
I don't believe the cancellation usage in that patch is safe :-)
Thanks for the feedback, we will address that.
May I please ask why it is not safe? Any clarification will help us to find a better alternative.
I put some comments inline in the patch 41 explaining my thoughts.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
RFC PATCH v4 3/49 multi-process: add a command line option for debug file
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Can be used with -d rdebug command options when starting qemu.
--- include/qemu/log.h | 1 + util/log.c | 2 ++ 2 files changed, 3 insertions(+)
include/qemu/log.h +1 -0
@@ -45,6 +45,7 @@ static inline bool qemu_log_separate(void)/* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1 << 16)#define CPU_LOG_TB_FPU (1 << 17) +#define LOG_REMOTE_DEBUG (1 << 18)/* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
util/log.c +2 -0
@@ -273,6 +273,8 @@ const QEMULogItem qemu_log_items[] = { {CPU_LOG_TB_NOCHAIN ,"nochain" ,"do not chain compiled TBs so that \"exec\" and \"cpu\" show\n" "complete traces" }, + { LOG_REMOTE_DEBUG, "rdebug", + "log remote debug" }, { 0, NULL, NULL }, };
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 03/49] multi-process: add a command line option for debug file
Quoted 11 lines · Jagannathan Raman
From: Elena Ufimtseva <[email protected]>
Can be used with -d rdebug command options when starting qemu.
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>Signed-off-by John G Johnson <[email protected]>--- include/qemu/log.h | 1 + util/log.c | 2 ++ 2 files changed, 3 insertions(+)
RFC PATCH v4 4/49 multi-process: Add stub functions to facilate build of multi-process
In reply to Jagannathan RamanAdd stub functions that are needed during compile time but not in runtime.
--- accel/stubs/kvm-stub.c | 5 +++ accel/stubs/tcg-stub.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ stubs/audio.c | 12 ++++++ stubs/machine-init-done.c | 4 ++ stubs/monitor.c | 41 ++++++++++++++++++++ stubs/net-stub.c | 31 +++++++++++++++ stubs/replay.c | 14 +++++++ stubs/vl-stub.c | 79 ++++++++++++++++++++++++++++++++++++++ stubs/vmstate.c | 20 ++++++++++ stubs/xen-mapcache.c | 22 +++++++++++ 10 files changed, 324 insertions(+) create mode 100644 stubs/audio.c create mode 100644 stubs/net-stub.c create mode 100644 stubs/vl-stub.c create mode 100644 stubs/xen-mapcache.c
accel/stubs/kvm-stub.c +5 -0
@@ -31,6 +31,7 @@ bool kvm_allowed;bool kvm_readonly_mem_allowed;bool kvm_ioeventfd_any_length_allowed;bool kvm_msi_use_devid; +bool kvm_halt_in_kernel_allowed;int kvm_destroy_vcpu (CPUState *cpu) {
@@ -58,6 +59,10 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu) { } +void kvm_cpu_synchronize_pre_loadvm (CPUState *cpu) +{ +} +int kvm_cpu_exec (CPUState *cpu) {abort ();
accel/stubs/tcg-stub.c +96 -0
107 lines not on this page · raw message
stubs/audio.c new file +12 -0
@@ -0,0 +1,12 @@ +#include "qemu/osdep.h" +#include "audio/audio.h" + +AudioState *audio_state_by_name (const char *name) +{ +return NULL ; +} + +const char *audio_get_id (QEMUSoundCard *card) +{ +return NULL ; +}
stubs/machine-init-done.c +4 -0
@@ -6,3 +6,7 @@ bool machine_init_done = true;void qemu_add_machine_init_done_notifier (Notifier *notify) { } + +void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +}
stubs/monitor.c +41 -0
53 lines not on this page · raw message
stubs/net-stub.c new file +31 -0
@@ -0,0 +1,31 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "net/net.h" + +int qemu_find_net_clients_except (const char *id,NetClientState **ncs, +NetClientDriver type,int max) +{ +return -ENOSYS ; +} + +NetClientState *net_hub_port_find (int hub_id) +{ +return NULL ; +} + +int net_hub_id_for_client (NetClientState *nc,int *id) +{ +return -ENOSYS ; +} + +int qemu_show_nic_models (const char *arg,const char *const *models) +{ +return -ENOSYS ; +} + +int qemu_find_nic_model (NICInfo *nd,const char *const *models, +const char *default_model) +{ +return -ENOSYS ; +} +
stubs/replay.c +14 -0
@@ -79,3 +79,17 @@ void replay_mutex_lock(void)void replay_mutex_unlock (void ) { } + +bool replay_has_checkpoint (void ) +{ +return false; +} + +int replay_get_instructions (void ) +{ +return 0 ; +} + +void replay_account_executed_instructions (void ) +{ +}
stubs/vl-stub.c new file +79 -0
79 lines not on this page · raw message
stubs/vmstate.c +20 -0
@@ -1,8 +1,11 @@#include "qemu/osdep.h" #include "migration/vmstate.h" +#include "migration/misc.h" const VMStateDescription vmstate_dummy = {}; +const VMStateInfo vmstate_info_timer; + int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd,
@@ -23,3 +26,20 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd) {return true; } + +void vmstate_register_ram (MemoryRegion *mr,DeviceState *dev) +{ +} + +void vmstate_unregister_ram (MemoryRegion *mr,DeviceState *dev) +{ +} + +void vmstate_register_ram_global (MemoryRegion *mr) +{ +} + +bool migration_is_idle (void ) +{ +return true; +}
stubs/xen-mapcache.c new file +22 -0
@@ -0,0 +1,22 @@ +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "exec/cpu-common.h" +#include "sysemu/xen-mapcache.h" + +#ifdef CONFIG_XEN + +void xen_invalidate_map_cache_entry (uint8_t *buffer) +{ +} + +uint8_t *xen_map_cache (hwaddr phys_addr,hwaddr size,uint8_t lock,bool dma) +{ +return NULL ; +} + +ram_addr_t xen_ram_addr_from_mapcache (void *ptr) +{ +return 0 ; +} + +#endif
Signature · 1 line
1.8.3.1
RFC PATCH v4 5/49 multi-process: Add config option for multi-process QEMU
In reply to Jagannathan RamanAdd a configuration option to separate multi-process code
--- configure | 11 +++++++++++ 1 file changed, 11 insertions(+)
configure +11 -0
@@ -498,6 +498,7 @@ libxml2="" debug_mutex="no" libpmem="" default_devices="yes" +mpqemu="no" supported_cpu="no" supported_os="no"
@@ -1529,6 +1530,10 @@ for opt do ;; --disable-xkbcommon) xkbcommon=no ;; + --enable-mpqemu) mpqemu=yes + ;; + --disable-mpqemu) mpqemu=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1813,6 +1818,7 @@ disabled with --disable-FEATURE, default is enabled if available: debug-mutex mutex debugging support libpmem libpmem support xkbcommon xkbcommon support + mpqemu multi-process QEMU support NOTE: The object files are built at the place where configure is launched EOF
@@ -6439,6 +6445,7 @@ echo "capstone $capstone" echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" +echo "multiprocess QEMU $mpqemu" if test "$supported_cpu" = "no"; then echo
@@ -7241,6 +7248,10 @@ if test "$libpmem" = "yes" ; then echo "CONFIG_LIBPMEM=y" >> $config_host_mak fi +if test "$mpqemu" = "yes" ; then + echo "CONFIG_MPQEMU=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi
Signature · 1 line
1.8.3.1
RFC PATCH v4 6/49 multi-process: build system for remote device process
In reply to Jagannathan RamanModify Makefile to support the building of the remote device process. Implements main() function of remote device process.
--- Makefile | 2 ++ Makefile.objs | 22 ++++++++++++++++++++ Makefile.target | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- backends/Makefile.objs | 2 ++ block/Makefile.objs | 2 ++ hw/Makefile.objs | 7 +++++++ hw/block/Makefile.objs | 2 ++ hw/core/Makefile.objs | 16 +++++++++++++++ hw/nvram/Makefile.objs | 2 ++ hw/pci/Makefile.objs | 4 ++++ hw/scsi/Makefile.objs | 2 ++ migration/Makefile.objs | 2 ++ qom/Makefile.objs | 3 +++ remote/Makefile.objs | 1 + remote/remote-main.c | 37 ++++++++++++++++++++++++++++++++++ stubs/replay.c | 4 ++++ 16 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 remote/Makefile.objs create mode 100644 remote/remote-main.c
Makefile +2 -0
@@ -437,6 +437,8 @@ dummy := $(call unnest-vars,, \ qom-obj-y \ io-obj-y \ common-obj-y \ + remote-pci-obj-y \ + remote-lsi-obj-y \ common-obj-m \ ui-obj-y \ ui-obj-m \
Makefile.objs +22 -0
@@ -21,6 +21,28 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ +######################################################### +# remote-pci-obj-y is common code used by remote devices + +remote-pci-obj-$(CONFIG_MPQEMU) += hw/ +remote-pci-obj-$(CONFIG_MPQEMU) += qom/ +remote-pci-obj-$(CONFIG_MPQEMU) += backends/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += migration/ +remote-pci-obj-$(CONFIG_MPQEMU) += remote/ + +remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o +remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o +remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o +remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o + +############################################################## +# remote-lsi-obj-y is code used to implement remote LSI device + +remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ + ####################################################################### # crypto-obj-y is code used by both qemu system emulation and qemu-img
Makefile.target +51 -2
91 lines not on this page · raw message
backends/Makefile.objs +2 -0
@@ -17,3 +17,5 @@ endif common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO)) += vhost-user.o common-obj-$(CONFIG_LINUX) += hostmem-memfd.o + +remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o
block/Makefile.objs +2 -0
@@ -67,3 +67,5 @@ qcow.o-libs := -lz linux-aio.o-libs := -laio parallels.o-cflags := $(LIBXML2_CFLAGS) parallels.o-libs := $(LIBXML2_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += stream.o
hw/Makefile.objs +7 -0
@@ -43,3 +43,10 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) + +remote-pci-obj-$(CONFIG_MPQEMU) += core/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += pci/ +remote-pci-obj-$(CONFIG_MPQEMU) += nvram/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/
hw/block/Makefile.objs +2 -0
@@ -15,3 +15,5 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o obj-y += dataplane/ + +remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o
hw/core/Makefile.objs +16 -0
@@ -28,3 +28,19 @@ common-obj-$(CONFIG_SOFTMMU) += null-machine.o obj-$(CONFIG_SOFTMMU) += machine-qmp-cmds.o obj-$(CONFIG_SOFTMMU) += numa.o common-obj-$(CONFIG_SOFTMMU) += machine-hmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += bus.o +remote-pci-obj-$(CONFIG_MPQEMU) += irq.o +remote-pci-obj-$(CONFIG_MPQEMU) += hotplug.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine.o +remote-pci-obj-$(CONFIG_MPQEMU) += fw-path-provider.o +remote-pci-obj-$(CONFIG_MPQEMU) += reset.o +remote-pci-obj-$(CONFIG_MPQEMU) += sysbus.o +remote-pci-obj-$(CONFIG_MPQEMU) += loader.o +remote-pci-obj-$(CONFIG_MPQEMU) += nmi.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o +remote-pci-obj-$(CONFIG_MPQEMU) += numa.o +remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o
hw/nvram/Makefile.objs +2 -0
@@ -6,3 +6,5 @@ common-obj-y += chrp_nvram.o common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o obj-$(CONFIG_PSERIES) += spapr_nvram.o obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o + +remote-pci-obj-$(CONFIG_MPQEMU) += fw_cfg.o
hw/pci/Makefile.objs +4 -0
@@ -12,3 +12,7 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o + +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o +remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
hw/scsi/Makefile.objs +2 -0
@@ -13,3 +13,5 @@ obj-y += virtio-scsi.o virtio-scsi-dataplane.o obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o endif + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi-generic.o scsi-bus.o lsi53c895a.o scsi-disk.o emulation.o
migration/Makefile.objs +2 -0
@@ -13,3 +13,5 @@ common-obj-$(CONFIG_RDMA) += rdma.o common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o rdma.o-libs := $(RDMA_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o
qom/Makefile.objs +3 -0
@@ -2,3 +2,6 @@ qom-obj-y = object.o container.o qom-qobject.o qom-obj-y += object_interfaces.o common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o +remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o
remote/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o
remote/remote-main.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Remote device initialization +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <stdio.h> + +#include "qemu/module.h" + +int main (int argc,char *argv[]) +{ +module_call_init (MODULE_INIT_QOM ); + +return 0 ; +}
stubs/replay.c +4 -0
@@ -93,3 +93,7 @@ int replay_get_instructions(void)void replay_account_executed_instructions (void ) { } + +void replay_add_blocker (Error *reason) +{ +}
Signature · 1 line
1.8.3.1
RFC PATCH v4 7/49 multi-process: define mpqemu-link object
In reply to Jagannathan RamanDefines mpqemu-link object which forms the communication link between QEMU & emulation program.
Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel.
Adds GMainLoop to handle events received on the communication channel.
---
v1 -> v2:
- Use default context for main loop instead of a new context
v2 -> v3:
- Enabled multi-channel support in the communication link
v3 -> v4:
- Change the name of proxy-link to mpqemu-link
- Use separate locks for sending and receiving messages
include/io/mpqemu-link.h | 150 +++++++++++++++++++++++ io/Makefile.objs | 2 + io/mpqemu-link.c | 309 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 461 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c
include/io/mpqemu-link.h new file +150 -0
@@ -0,0 +1,150 @@ +/* +* Communication channel between QEMU and remote device process +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <stddef.h> +#include <stdint.h> +#include <pthread.h> + +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK (obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** +* mpqemu_cmd_t: +* CONF_READ PCI config. space read +* CONF_WRITE PCI config. space write +* +* proc_cmd_t enum type to specify the command to be executed on the remote +* device. +*/ +typedef enum { +INIT =0 , +CONF_READ , +CONF_WRITE , +MAX , +}mpqemu_cmd_t ; + +/** +* MPQemuMsg: +* @cmd: The remote command +* @bytestream: Indicates if the data to be shared is structured (data1) +* or unstructured (data2) +* @size: Size of the data to be shared +* @data1: Structured data +* @fds: File descriptors to be shared with remote device +* @data2: Unstructured data +* +* MPQemuMsg Format of the message sent to the remote device from QEMU. +* +*/ +typedef struct { +mpqemu_cmd_t cmd; +int bytestream; +size_t size; + +union { +uint64_t u64; + } data1; + +int fds[REMOTE_MAX_FDS ]; +int num_fds; + +uint8_t *data2; +}MPQemuMsg ; + +struct conf_data_msg { +uint32_t addr; +uint32_t val; +int l; +}; + +/** +* MPQemuChannel: +* @gsrc: GSource object to be used by loop +* @gpfd: GPollFD object containing the socket & events to monitor +* @sock: Socket to send/receive communication, same as the one in gpfd +* @send_lock: Mutex to synchronize access to the send stream +* @recv_lock: Mutex to synchronize access to the recv stream +* +* Defines the channel that make up the communication link +* between QEMU and remote process +*/ + +typedef struct MPQemuChannel { +GSource gsrc; +GPollFD gpfd; +int sock; +QemuMutex send_lock; +QemuMutex recv_lock; +}MPQemuChannel ; + +typedef void (*mpqemu_link_callback )(GIOCondition cond,MPQemuChannel *chan); + +/* +* MPQemuLinkState Instance info. of the communication +* link between QEMU and remote process. The Link could +* be made up of multiple channels. +* +* ctx GMainContext to be used for communication +* loop Main loop that would be used to poll for incoming data +* com Communication channel to transport control messages +* +*/ + +typedef struct MPQemuLinkState { +Object obj; + +GMainContext *ctx; +GMainLoop *loop; + +MPQemuChannel *com; + +mpqemu_link_callback callback; +}MPQemuLinkState ; + +MPQemuLinkState *mpqemu_link_create (void ); +void mpqemu_link_finalize (MPQemuLinkState *s); + +void mpqemu_msg_send (MPQemuLinkState *s,MPQemuMsg *msg,MPQemuChannel *chan); +int mpqemu_msg_recv (MPQemuLinkState *s,MPQemuMsg *msg,MPQemuChannel *chan); + +void mpqemu_init_channel (MPQemuLinkState *s,MPQemuChannel **chan,int fd); +void mpqemu_destroy_channel (MPQemuChannel *chan); +void mpqemu_link_set_callback (MPQemuLinkState *s,mpqemu_link_callback callback); +void mpqemu_start_coms (MPQemuLinkState *s); + +#endif
io/Makefile.objs +2 -0
@@ -10,3 +10,5 @@ io-obj-y += channel-util.o io-obj-y += dns-resolver.o io-obj-y += net-listener.o io-obj-y += task.o + +io-obj-$(CONFIG_MPQEMU) += mpqemu-link.o
io/mpqemu-link.c new file +309 -0
309 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object
Quoted 69 lines · Jagannathan Raman
io/mpqemu-link.c new file +69
-0+int mpqemu_msg_recv (MPQemuLinkState *s,MPQemuMsg *msg,MPQemuChannel *chan) +{ +int rc; +uint8_t *data; +union { +char control[CMSG_SPACE (REMOTE_MAX_FDS *sizeof (int ))]; +struct cmsghdr align; + } u; +struct msghdr hdr; +struct cmsghdr *chdr; +size_t fdsize; +int sock = chan->sock; +QemuMutex *lock = &chan->recv_lock; + +struct iovec iov = { + .iov_base = (char *) msg, + .iov_len =MPQEMU_MSG_HDR_SIZE , + }; + +memset (&hdr,0 ,sizeof (hdr)); +memset (&u,0 ,sizeof (u)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen =1 ; + hdr.msg_control = &u; + hdr.msg_controllen =sizeof (u); + +qemu_mutex_lock (lock); + +do { + rc =recvmsg (sock, &hdr,0 ); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); + +if (rc <0 ) { +qemu_log_mask (LOG_REMOTE_DEBUG ,"%s - recvmsg rc is %d, errno is %d," +" sock %d\n" , __func__, rc, errno, sock); +qemu_mutex_unlock (lock); +return rc; + } + + msg->num_fds =0 ; +for (chdr =CMSG_FIRSTHDR (&hdr); chdr !=NULL ; + chdr =CMSG_NXTHDR (&hdr, chdr)) { +if ((chdr->cmsg_level ==SOL_SOCKET ) && + (chdr->cmsg_type ==SCM_RIGHTS )) { + fdsize = chdr->cmsg_len -CMSG_LEN (0 ); + msg->num_fds = fdsize /sizeof (int ); +if (msg->num_fds >REMOTE_MAX_FDS ) { +/* +* TODO: Security issue detected. Sender never sends more +* than REMOTE_MAX_FDS. This condition should be signaled to +* the admin +*/ +qemu_log_mask (LOG_REMOTE_DEBUG ,"%s: Max FDs exceeded\n" , __func__); +return -ERANGE ; + } + +memcpy (msg->fds,CMSG_DATA (chdr), fdsize); +break ; + } + } + +if (msg->size && msg->bytestream) { + msg->data2 =calloc (1 , msg->size); + data = msg->data2; + }else { + data = (uint8_t *)&msg->data1; + } +
io/mpqemu-link.c line 232
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+if (msg->size) { +do { + rc =read (sock, data, msg->size); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); + } + +qemu_mutex_unlock (lock); + +return rc; +}
This code is still insecure. Until the communication between processes is made secure this series does not meet its goal of providing process isolation.
1. An attacker can overflow msg->data1 easily by setting msg->size but not msg->bytestream.
2. An attacker can allocate data2, all mpqemu_msg_recv() callers need to free it to prevent memory leaks.
3. mpqemu_msg_recv() callers generally do not validate untrusted msg fields. All the code needs to be audited.
Stefan
Re: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object
Quoted 85 lines · Stefan Hajnoczi
Quoted 69 lines · Jagannathan Raman
io/mpqemu-link.c new file +69
-0+int mpqemu_msg_recv (MPQemuLinkState *s,MPQemuMsg *msg,MPQemuChannel *chan) +{ +int rc; +uint8_t *data; +union { +char control[CMSG_SPACE (REMOTE_MAX_FDS *sizeof (int ))]; +struct cmsghdr align; + } u; +struct msghdr hdr; +struct cmsghdr *chdr; +size_t fdsize; +int sock = chan->sock; +QemuMutex *lock = &chan->recv_lock; + +struct iovec iov = { + .iov_base = (char *) msg, + .iov_len =MPQEMU_MSG_HDR_SIZE , + }; + +memset (&hdr,0 ,sizeof (hdr)); +memset (&u,0 ,sizeof (u)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen =1 ; + hdr.msg_control = &u; + hdr.msg_controllen =sizeof (u); + +qemu_mutex_lock (lock); + +do { + rc =recvmsg (sock, &hdr,0 ); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); + +if (rc <0 ) { +qemu_log_mask (LOG_REMOTE_DEBUG ,"%s - recvmsg rc is %d, errno is %d," +" sock %d\n" , __func__, rc, errno, sock); +qemu_mutex_unlock (lock); +return rc; + } + + msg->num_fds =0 ; +for (chdr =CMSG_FIRSTHDR (&hdr); chdr !=NULL ; + chdr =CMSG_NXTHDR (&hdr, chdr)) { +if ((chdr->cmsg_level ==SOL_SOCKET ) && + (chdr->cmsg_type ==SCM_RIGHTS )) { + fdsize = chdr->cmsg_len -CMSG_LEN (0 ); + msg->num_fds = fdsize /sizeof (int ); +if (msg->num_fds >REMOTE_MAX_FDS ) { +/* +* TODO: Security issue detected. Sender never sends more +* than REMOTE_MAX_FDS. This condition should be signaled to +* the admin +*/ +qemu_log_mask (LOG_REMOTE_DEBUG ,"%s: Max FDs exceeded\n" , __func__); +return -ERANGE ; + } + +memcpy (msg->fds,CMSG_DATA (chdr), fdsize); +break ; + } + } + +if (msg->size && msg->bytestream) { + msg->data2 =calloc (1 , msg->size); + data = msg->data2; + }else { + data = (uint8_t *)&msg->data1; + } +io/mpqemu-link.c line 232
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+if (msg->size) { +do { + rc =read (sock, data, msg->size); + }while (rc <0 && (errno ==EINTR || errno ==EAGAIN )); + } + +qemu_mutex_unlock (lock); + +return rc; +}This code is still insecure. Until the communication between processes is made secure this series does not meet its goal of providing process isolation.
Quoted 2 lines
1. An attacker can overflow
msg->data1easily by settingmsg->sizebutnot msg->bytestream.
We will add a check to ensure that msg->size is less than msg->data1 if msg->bytestream is not set.
Quoted 2 lines
2. An attacker can allocate data2, all
mpqemu_msg_recv()callers need to free it to prevent memory leaks.
We will address this memory leak.
Quoted 2 lines
3.
mpqemu_msg_recv()callers generally do not validate untrusted msg fields. All the code needs to be audited.
mpqemu_msg_recv() callers validate the num_fds field. But we will add more fields for validation by the callers.
Thanks!
--
Jag
Quoted 3 lines
Stefan
Re: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object
In reply to Jagannathan Ramaninclude/io/mpqemu-link.h line 32
Quoted 8 lines · Jagannathan Raman
include/io/mpqemu-link.h new file +8
-0+#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <stddef.h> +#include <stdint.h>
These are already included by "qemu/osdep.h".
Quoted 1 line
+#include <
pthread.h>
Is <pthread.h> needed?
Quoted 16 lines
include/io/mpqemu-link.h new file +16
-0+ +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK (obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** +* mpqemu_cmd_t: +* CONF_READ PCI config. space read +* CONF_WRITE PCI config. space write
include/io/mpqemu-link.h line 59
Quoted 10 lines
include/io/mpqemu-link.h new file +10
-0+* +* proc_cmd_t enum type to specify the command to be executed on the remote +* device. +*/ +typedef enum { +INIT =0 , +CONF_READ , +CONF_WRITE , +MAX , +}mpqemu_cmd_t ;
Please allow for future non-PCI devices by clearly naming PCI-specific commands and including a bus type in the initialization messages.
Quoted 34 lines
io/mpqemu-link.c new file +28
-0@@ -0,0 +1,309 @@ +/* +* Communication channel between QEMU and remote device process +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <assert.h>
io/mpqemu-link.c line 38
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <limits.h> +#include <poll.h>
Many of these are already included by "qemu/osdep.h". Some of them shouldn't be used directly because QEMU or glib have abstractions that hide the platform-specific differences (e.g. pthread, poll).
io/mpqemu-link.c line 71
Quoted 4 lines
io/mpqemu-link.c new file +4
-0+MPQemuLinkState *mpqemu_link_create (void ) +{ +return MPQEMU_LINK (object_new (TYPE_MPQEMU_LINK )); +}
I'm not sure what the purpose of this object is. mpqemu_link_create() suggests the objects will be created internally instead of via -object mpqemu-link,..., which is unusual.
mpqemu_msg_send() and mpqemu_msg_recv() seem to be the main functions but they do not even use their MPQemuLinkState *s argument.
io/mpqemu-link.c line 309
Quoted 7 lines
io/mpqemu-link.c new file +7
-0+void mpqemu_start_coms (MPQemuLinkState *s) +{ + +g_assert (g_source_attach (&s->com->gsrc, s->ctx)); + +g_main_loop_run (s->loop); +}
There is already IOThread if you need an event loop thread. But does this need to be its own thread? The communication should be asynchronous and therefore it can run in the main event loop or any existing IOThread.
Re: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object
Quoted 12 lines · Stefan Hajnoczi
include/io/mpqemu-link.h line 32
Quoted 8 lines · Jagannathan Raman
include/io/mpqemu-link.h new file +8
-0+#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <stddef.h> +#include <stdint.h> These are already included by "
qemu/osdep.h".
Quoted 3 lines
Quoted 1 line
+#include <
pthread.h>Is <
pthread.h> needed?
It's not needed. We'll remove it.
Quoted 22 lines
Quoted 22 lines
include/io/mpqemu-link.h new file +21
-0+ +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK (obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** +* mpqemu_cmd_t: +* CONF_READ PCI config. space read +* CONF_WRITE PCI config. space write +* +* proc_cmd_t enum type to specify the command to be executed on the remote +* device. +*/ +typedef enum {
Quoted 8 lines
include/io/mpqemu-link.h line 59
Quoted 5 lines
include/io/mpqemu-link.h new file +5
-0+INIT =0 , +CONF_READ , +CONF_WRITE , +MAX , +} mpqemu_cmd_t;Please allow for future non-PCI devices by clearly naming PCI-specific commands and including a bus type in the initialization messages.
OK, will do.
Quoted 59 lines
Quoted 35 lines
io/mpqemu-link.c new file +28
-0@@ -0,0 +1,309 @@ +/* +* Communication channel between QEMU and remote device process +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include <assert.h> io/mpqemu-link.c line 38
Quoted 10 lines
io/mpqemu-link.c new file +10
-0+#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> +#include <limits.h> +#include <poll.h> Many of these are already included by "
qemu/osdep.h". Some of them shouldn't be used directly because QEMU or glib have abstractions that hide the platform-specific differences (e.g. pthread, poll).io/mpqemu-link.c line 71
Quoted 4 lines
io/mpqemu-link.c new file +4
-0+MPQemuLinkState *mpqemu_link_create (void ) +{ +return MPQEMU_LINK (object_new (TYPE_MPQEMU_LINK )); +}I'm not sure what the purpose of this object is.
mpqemu_link_create()suggests the objects will be created internally instead of via -object mpqemu-link,..., which is unusual.
Quoted 2 lines
mpqemu_msg_send()andmpqemu_msg_recv()seem to be the main functions but they do not even use their MPQemuLinkState *s argument.
The LINK object is made up of multiple CHANNELS objects. For example, a link between QEMU & the remote process could be comprised of multiple channels.
You're correct, mpqemu_msg_send() & mpqemu_msg_recv() don't use the the argument "s". This was a consequence of adding the multi-channel support, before which this argument was used. We will fix this in the next review.
Thank you!
--
Jag
Quoted 14 lines
io/mpqemu-link.c line 309
Quoted 8 lines
io/mpqemu-link.c new file +7
-0+void mpqemu_start_coms (MPQemuLinkState *s) +{ + +g_assert (g_source_attach (&s->com->gsrc, s->ctx)); + +g_main_loop_run (s->loop); +}There is already IOThread if you need an event loop thread. But does this need to be its own thread? The communication should be asynchronous and therefore it can run in the main event loop or any existing IOThread.
RFC PATCH v4 8/49 multi-process: add functions to synchronize proxy and remote endpoints
In reply to Jagannathan RamanIn some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process.
---
v1 -> v2:
- Added timeout to synchronization functions
include/io/mpqemu-link.h | 9 +++++++++ io/mpqemu-link.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/io/mpqemu-link.h +9 -0
@@ -30,7 +30,9 @@#include <stddef.h> #include <stdint.h> +#include <unistd.h> #include <pthread.h> +#include <sys/eventfd.h> #include "qom/object.h" #include "qemu/thread.h"
@@ -147,4 +149,11 @@ void mpqemu_destroy_channel(MPQemuChannel *chan);void mpqemu_link_set_callback (MPQemuLinkState *s,mpqemu_link_callback callback);void mpqemu_start_coms (MPQemuLinkState *s); +#define GET_REMOTE_WAIT eventfd(0, 0) +#define PUT_REMOTE_WAIT (wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + +uint64_t wait_for_remote (int efd); +void notify_proxy (int fd,uint64_t val); +#endif
io/mpqemu-link.c +40 -0
@@ -231,6 +231,46 @@ int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan)return rc; } +uint64_t wait_for_remote (int efd) +{ +struct pollfd pfd = { .fd = efd, .events =POLLIN }; +uint64_t val; +int ret; + + ret =poll (&pfd,1 ,1000 ); + +switch (ret) { +case 0 : +qemu_log_mask (LOG_REMOTE_DEBUG ,"Error wait_for_remote: Timed out\n" ); +/* TODO: Kick-off error recovery */ +return ULLONG_MAX ; +case -1 : +qemu_log_mask (LOG_REMOTE_DEBUG ,"Poll error wait_for_remote: %s\n" , +strerror (errno)); +return ULLONG_MAX ; +default : +if (read (efd, &val,sizeof (val)) ==-1 ) { +qemu_log_mask (LOG_REMOTE_DEBUG ,"Error wait_for_remote: %s\n" , +strerror (errno)); +return ULLONG_MAX ; + } + } + + val = (val ==ULLONG_MAX ) ? val : (val -1 ); + +return val; +} + +void notify_proxy (int efd,uint64_t val) +{ + val = (val ==ULLONG_MAX ) ? val : (val +1 ); + +if (write (efd, &val,sizeof (val)) ==-1 ) { +qemu_log_mask (LOG_REMOTE_DEBUG ,"Error notify_proxy: %s\n" , +strerror (errno)); + } +} +static gboolean mpqemu_link_handler_prepare (GSource *gsrc,gint *timeout) {g_assert (timeout);
Signature · 1 line
1.8.3.1
RFC PATCH v4 9/49 multi-process: setup PCI host bridge for remote device
In reply to Jagannathan RamanPCI 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.
--- hw/pci/Makefile.objs | 2 +- include/remote/pcihost.h | 59 +++++++++++++++++++++++++++++++++ remote/Makefile.objs | 1 + remote/pcihost.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 include/remote/pcihost.h create mode 100644 remote/pcihost.c
hw/pci/Makefile.objs +1 -1
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o -remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o pci_host.o pcie_host.o remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o
include/remote/pcihost.h new file +59 -0
59 lines not on this page · raw message
remote/Makefile.objs +1 -0
@@ -1 +1,2 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o +remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o
remote/pcihost.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 09/49] multi-process: setup PCI host bridge for remote device
remote/pcihost.c line 52
Quoted 12 lines · Jagannathan Raman
remote/pcihost.c new file +12
-0+static void remote_host_realize (DeviceState *dev,Error **errp) +{ +PCIHostState *pci =PCI_HOST_BRIDGE (dev); +RemPCIHost *s =REMOTE_HOST_DEVICE (dev); + +/* +* TODO: the name of the bus would be provided by QEMU. Use +* "pcie.0" for now. +*/ + pci->bus =pci_root_bus_new (DEVICE (s),"pcie.0" , + s->mr_pci_mem, s->mr_sys_io, +0 ,TYPE_PCIE_BUS );
The PCI bus name could be a property and then whatever instantiates RemPCIHost could set it.
Machine types usually hardcode the name because they assume there is only one machine instance. In the case of mpqemu this is an okay starting point, but maybe multiple busses will become necessary if the device emulation process handles multiple device instances - especially if they are served to multiple guests like in a software-defined network switch use case.
Re: [RFC v4 PATCH 09/49] multi-process: setup PCI host bridge for remote device
Quoted 17 lines · Stefan Hajnoczi
remote/pcihost.c line 52
Quoted 12 lines · Jagannathan Raman
remote/pcihost.c new file +12
-0+static void remote_host_realize (DeviceState *dev,Error **errp) +{ +PCIHostState *pci =PCI_HOST_BRIDGE (dev); +RemPCIHost *s =REMOTE_HOST_DEVICE (dev); + +/* +* TODO: the name of the bus would be provided by QEMU. Use +* "pcie.0" for now. +*/ + pci->bus =pci_root_bus_new (DEVICE (s),"pcie.0" , + s->mr_pci_mem, s->mr_sys_io, +0 ,TYPE_PCIE_BUS );The PCI bus name could be a property and then whatever instantiates RemPCIHost could set it.
Quoted 6 lines
Machine types usually hardcode the name because they assume there is only one machine instance. In the case of mpqemu this is an okay starting point, but maybe multiple busses will become necessary if the device emulation process handles multiple device instances - especially if they are served to multiple guests like in a software-defined network switch use case.
Are you referring to a case where a single remote process will emulate devices from multiple guests?
We haven't thought about that application. But we will certainly add the ability to specify the name of the bus as a parameter.
Thank you very much!
--
Jag
Quoted 1 line
Re: [RFC v4 PATCH 09/49] multi-process: setup PCI host bridge for remote device
Quoted 25 lines · Jag Raman
Quoted 17 lines · Stefan Hajnoczi
remote/pcihost.c line 52
Quoted 12 lines · Jagannathan Raman
remote/pcihost.c new file +12
-0+static void remote_host_realize (DeviceState *dev,Error **errp) +{ +PCIHostState *pci =PCI_HOST_BRIDGE (dev); +RemPCIHost *s =REMOTE_HOST_DEVICE (dev); + +/* +* TODO: the name of the bus would be provided by QEMU. Use +* "pcie.0" for now. +*/ + pci->bus =pci_root_bus_new (DEVICE (s),"pcie.0" , + s->mr_pci_mem, s->mr_sys_io, +0 ,TYPE_PCIE_BUS );The PCI bus name could be a property and then whatever instantiates RemPCIHost could set it.
Quoted 6 lines
Machine types usually hardcode the name because they assume there is only one machine instance. In the case of mpqemu this is an okay starting point, but maybe multiple busses will become necessary if the device emulation process handles multiple device instances - especially if they are served to multiple guests like in a software-defined network switch use case.
Quoted 5 lines
Are you referring to a case where a single remote process will emulate devices from multiple guests?
We haven't thought about that application. But we will certainly add the ability to specify the name of the bus as a parameter.
Sooner or later someone will want to run multiple devices in one device emulation process, but it's not critical to support it in this patch series. I think it can be implemented later without breaking any stable interfaces.
Stefan
RFC PATCH v4 10/49 multi-process: setup a machine object for remote device process
In reply to Jagannathan Ramanremote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions.
--- exec.c | 3 +- include/exec/address-spaces.h | 2 + include/remote/machine.h | 46 ++++++++++++++++ remote/Makefile.objs | 1 + remote/machine.c | 118 ++++++++++++++++++++++++++++++++++++++++++ remote/remote-main.c | 7 +++ 6 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 include/remote/machine.h create mode 100644 remote/machine.c
exec.c +1 -2
@@ -192,7 +192,6 @@ typedef struct subpage_t {#define PHYS_SECTION_UNASSIGNED 0static void io_mem_init (void ); -static void memory_map_init (void );static void tcg_log_global_after_sync (MemoryListener *listener);static void tcg_commit (MemoryListener *listener);
@@ -2989,7 +2988,7 @@ static void tcg_commit(MemoryListener *listener)tlb_flush (cpuas->cpu); } -static void memory_map_init (void ) +void memory_map_init (void ) { system_memory =g_malloc (sizeof (*system_memory));
include/exec/address-spaces.h +2 -0
@@ -33,6 +33,8 @@ MemoryRegion *get_system_memory(void);*/ MemoryRegion *get_system_io (void ); +void memory_map_init (void ); +extern AddressSpace address_space_memory;extern AddressSpace address_space_io;
include/remote/machine.h new file +46 -0
46 lines not on this page · raw message
remote/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine.o
remote/machine.c new file +118 -0
118 lines not on this page · raw message
remote/remote-main.c +7 -0
@@ -28,10 +28,17 @@#include <stdio.h> #include "qemu/module.h" +#include "remote/pcihost.h" +#include "remote/machine.h" +#include "hw/boards.h" +#include "hw/qdev-core.h" +#include "qemu/main-loop.h" int main (int argc,char *argv[]) {module_call_init (MODULE_INIT_QOM ); + current_machine =MACHINE (REMOTE_MACHINE (object_new (TYPE_REMOTE_MACHINE ))); +return 0 ; }
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 10/49] multi-process: setup a machine object for remote device process
Quoted 13 lines · Jagannathan Raman
remote/machine.c new file +13
-0+static NotifierList machine_init_done_notifiers = +NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); + +bool machine_init_done; + +void qemu_add_machine_init_done_notifier (Notifier *notify) +{ +notifier_list_add (&machine_init_done_notifiers, notify); +if (machine_init_done) { + notify->notify (notify,NULL ); + } +} +
remote/machine.c line 66
Quoted 10 lines
remote/machine.c new file +10
-0+void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} + +void qemu_run_machine_init_done_notifiers (void ) +{ + machine_init_done = true; +notifier_list_notify (&machine_init_done_notifiers,NULL ); +}
qemu_add_machine_init_done_notifier() is already defined in vl.c. Please share the implementation instead of duplicating it into the remote program.
remote/machine.c line 76
Quoted 10 lines
remote/machine.c new file +10
-0+ +static void remote_machine_init (Object *obj) +{ +RemMachineState *s =REMOTE_MACHINE (obj); +RemPCIHost *rem_host; +MemoryRegion *system_memory, *system_io, *pci_memory; + +Error *error_abort =NULL ; + +qemu_mutex_init (&ram_list.mutex);
Please keep global initialization separate from RemMachineState (e.g. do it in main() or a function called by main()). This function should only initialize RemMachineState.
remote/machine.c line 83
Quoted 7 lines
remote/machine.c new file +7
-0+ +object_property_add_child (object_get_root (),"machine" , obj, &error_abort); +if (error_abort) { +error_report_err (error_abort); + } + +memory_map_init ();
This is global init, please move it elsewhere.
Quoted 4 lines
remote/machine.c new file +4
-0+ + system_memory =get_system_memory (); + system_io =get_system_io (); +
remote/machine.c line 97
Quoted 10 lines
remote/machine.c new file +10
-0+ pci_memory =g_new (MemoryRegion,1 ); +memory_region_init (pci_memory,NULL ,"pci" ,UINT64_MAX ); + + rem_host =REMOTE_HOST_DEVICE (qdev_create (NULL ,TYPE_REMOTE_HOST_DEVICE )); + + rem_host->mr_pci_mem = pci_memory; + rem_host->mr_sys_mem = system_memory; + rem_host->mr_sys_io = system_io; + + s->host = rem_host;
Both s and rem_host are QOM objects. There should be a child property relationship between them here. It will ensure that rem_host is cleaned up when s is cleaned up. Please use that instead of a regular C pointer.
Re: [RFC v4 PATCH 10/49] multi-process: setup a machine object for remote device process
Quoted 29 lines · Stefan Hajnoczi
Quoted 13 lines · Jagannathan Raman
remote/machine.c new file +13
-0+static NotifierList machine_init_done_notifiers = +NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); + +bool machine_init_done; + +void qemu_add_machine_init_done_notifier (Notifier *notify) +{ +notifier_list_add (&machine_init_done_notifiers, notify); +if (machine_init_done) { + notify->notify (notify,NULL ); + } +} +remote/machine.c line 66
Quoted 10 lines
remote/machine.c new file +10
-0+void qemu_remove_machine_init_done_notifier (Notifier *notify) +{ +notifier_remove (notify); +} + +void qemu_run_machine_init_done_notifiers (void ) +{ + machine_init_done = true; +notifier_list_notify (&machine_init_done_notifiers,NULL ); +}
qemu_add_machine_init_done_notifier()is already defined invl.c. Please share the implementation instead of duplicating it into the remote program.
Quoted 14 lines
remote/machine.c line 76
Quoted 10 lines
remote/machine.c new file +10
-0+ +static void remote_machine_init (Object *obj) +{ +RemMachineState *s =REMOTE_MACHINE (obj); +RemPCIHost *rem_host; +MemoryRegion *system_memory, *system_io, *pci_memory; + +Error *error_abort =NULL ; + +qemu_mutex_init (&ram_list.mutex);Please keep global initialization separate from RemMachineState (e.g. do it in
main()or a function called bymain()). This function should only initialize RemMachineState.
OK, will do!
Quoted 10 lines
remote/machine.c line 83
Quoted 8 lines
remote/machine.c new file +7
-0+ +object_property_add_child (object_get_root (),"machine" , obj, &error_abort); +if (error_abort) { +error_report_err (error_abort); + } + +memory_map_init ();This is global init, please move it elsewhere.
Got it, thank you!
Quoted 12 lines
Quoted 12 lines
remote/machine.c new file +11
-0+ + system_memory =get_system_memory (); + system_io =get_system_io (); + + pci_memory =g_new (MemoryRegion,1 ); +memory_region_init (pci_memory,NULL ,"pci" ,UINT64_MAX ); + + rem_host =REMOTE_HOST_DEVICE (qdev_create (NULL ,TYPE_REMOTE_HOST_DEVICE )); + + rem_host->mr_pci_mem = pci_memory; + rem_host->mr_sys_mem = system_memory;
Quoted 8 lines
remote/machine.c line 97
Quoted 3 lines
remote/machine.c new file +3
-0+ rem_host->mr_sys_io = system_io; + + s->host = rem_host;Both s and
rem_hostare QOM objects. There should be a child property relationship between them here. It will ensure thatrem_hostis cleaned up when s is cleaned up. Please use that instead of a regular C pointer.
OK, will add a property linking these two as parent-child.
Thank you!
--
Jag
Quoted 1 line
RFC PATCH v4 11/49 multi-process: setup memory manager for remote device
In reply to Jagannathan Ramansync_sysmem_msg_t message format is defined. It is used to send file descriptors of the RAM regions to remote device.
RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM.
--- Makefile.target | 2 + include/io/mpqemu-link.h | 11 ++++++ include/remote/memory.h | 34 +++++++++++++++++ remote/memory.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 include/remote/memory.h create mode 100644 remote/memory.c
Makefile.target +2 -0
@@ -136,6 +136,8 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o + ######################################################### # Linux user emulator target
include/io/mpqemu-link.h +11 -0
@@ -36,6 +36,8 @@#include "qom/object.h" #include "qemu/thread.h" +#include "exec/cpu-common.h" +#include "exec/hwaddr.h" #define TYPE_MPQEMU_LINK "mpqemu-link"#define MPQEMU_LINK (obj) \
@@ -49,6 +51,7 @@* mpqemu_cmd_t: * CONF_READ PCI config. space read * CONF_WRITE PCI config. space write +* SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * * proc_cmd_t enum type to specify the command to be executed on the remote * device.
@@ -57,6 +60,7 @@ typedef enum {INIT =0 ,CONF_READ ,CONF_WRITE , +SYNC_SYSMEM ,MAX , } mpqemu_cmd_t;
@@ -74,12 +78,19 @@ typedef enum {* */ typedef struct { +hwaddr gpas[REMOTE_MAX_FDS ]; +uint64_t sizes[REMOTE_MAX_FDS ]; +ram_addr_t offsets[REMOTE_MAX_FDS ]; +}sync_sysmem_msg_t ; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; union { uint64_t u64; + sync_sysmem_msg_t sync_sysmem; } data1; int fds[REMOTE_MAX_FDS];
include/remote/memory.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Memory manager for remote device +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef REMOTE_MEMORY_H +#define REMOTE_MEMORY_H + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "io/mpqemu-link.h" + +void remote_sysmem_reconfig (MPQemuMsg *msg,Error **errp); + +#endif
remote/memory.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 11/49] multi-process: setup memory manager for remote device
Quoted 11 lines · Jagannathan Raman
remote/memory.c new file +11
-0+static void remote_ram_destructor (MemoryRegion *mr) +{ +qemu_ram_free (mr->ram_block); +} + +static void remote_ram_init_from_fd (MemoryRegion *mr,int fd,uint64_t size, +ram_addr_t offset,Error **errp) +{ +char *name =g_strdup_printf ("%d" , fd); + +memory_region_init (mr,NULL , name, size);
remote/memory.c line 60
Quoted 10 lines
remote/memory.c new file +10
-0+ mr->ram = true; + mr->terminates = true; + mr->destructor =NULL ; + mr->align =0 ; + mr->ram_block =qemu_ram_alloc_from_fd (size, mr,RAM_SHARED , fd, offset, + errp); + mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; + +g_free (name); +}
This is not specific to remote/memory.c and could be shared in case something else in QEMU wants to initialize from an fd.
remote/memory.c line 64
Quoted 4 lines
remote/memory.c new file +4
-0+ +void remote_sysmem_reconfig (MPQemuMsg *msg,Error **errp) +{ +sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem;
A possible security issue with MPQemuMsg: was the message size validatedb before we access msg->data1.sync_sysmem?
If not, then we might access uninitialized data. I didn't see if there is a single place in the code that always zeroes msg, but I think the answer is no. Accessing uninitialized data could expose the old contents of the stack/heap to the other process. Information leaks like this can be used to defeat address-space randomization because the other process may learn about our memory layout if there are memory addresses in the uninitialized data.
Re: [RFC v4 PATCH 11/49] multi-process: setup memory manager for remote device
Quoted 34 lines · Stefan Hajnoczi
Quoted 11 lines · Jagannathan Raman
remote/memory.c new file +11
-0+static void remote_ram_destructor (MemoryRegion *mr) +{ +qemu_ram_free (mr->ram_block); +} + +static void remote_ram_init_from_fd (MemoryRegion *mr,int fd,uint64_t size, +ram_addr_t offset,Error **errp) +{ +char *name =g_strdup_printf ("%d" , fd); + +memory_region_init (mr,NULL , name, size);remote/memory.c line 60
Quoted 10 lines
remote/memory.c new file +10
-0+ mr->ram = true; + mr->terminates = true; + mr->destructor =NULL ; + mr->align =0 ; + mr->ram_block =qemu_ram_alloc_from_fd (size, mr,RAM_SHARED , fd, offset, + errp); + mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; + +g_free (name); +}This is not specific to
remote/memory.cand could be shared in case something else in QEMU wants to initialize from an fd.remote/memory.c line 64
Quoted 4 lines
remote/memory.c new file +4
-0+ +void remote_sysmem_reconfig (MPQemuMsg *msg,Error **errp) +{ +sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem;A possible security issue with MPQemuMsg: was the message size validatedb before we access
msg->data1.sync_sysmem?
Quoted 7 lines
If not, then we might access uninitialized data. I didn't see if there is a single place in the code that always zeroes msg, but I think the answer is no. Accessing uninitialized data could expose the old contents of the stack/heap to the other process. Information leaks like this can be used to defeat address-space randomization because the other process may learn about our memory layout if there are memory addresses in the uninitialized data.
Thanks for the feedback. Will do.
--
Jag
Quoted 1 line
RFC PATCH v4 12/49 multi-process: remote process initialization
In reply to Jagannathan RamanAdds the handler to process message from QEMU, Initialize remote process main loop, handles SYNC_SYSMEM message by updating its "system_memory" container using shared file descriptors received from QEMU.
---
v1 -> v2:
- Separate thread for message processing is removed
v2 -> v3:
- Added multi-channel support in the remote end
remote/remote-main.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
remote/remote-main.c +80 -0
@@ -26,6 +26,7 @@#include "qemu-common.h" #include <stdio.h> +#include <unistd.h> #include "qemu/module.h" #include "remote/pcihost.h"
@@ -33,12 +34,91 @@#include "hw/boards.h" #include "hw/qdev-core.h" #include "qemu/main-loop.h" +#include "remote/memory.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/main-loop.h" +#include "sysemu/cpus.h" +#include "qemu-common.h" +#include "hw/pci/pci.h" +#include "qemu/thread.h" +#include "qemu/main-loop.h" +#include "qemu/config-file.h" +#include "sysemu/sysemu.h" +#include "block/block.h" + +static MPQemuLinkState *mpqemu_link; +PCIDevice *remote_pci_dev; + +static void process_msg (GIOCondition cond,MPQemuChannel *chan) +{ +MPQemuMsg *msg =NULL ; +Error *err =NULL ; + +if ((cond &G_IO_HUP ) || (cond &G_IO_ERR )) { +error_setg (&err,"socket closed, cond is %d" , cond); + goto finalize_loop; + } + + msg =g_malloc0 (sizeof (MPQemuMsg)); + +if (mpqemu_msg_recv (mpqemu_link, msg, chan) <0 ) { +error_setg (&err,"Failed to receive message" ); + goto finalize_loop; + } + +switch (msg->cmd) { +case INIT : +break ; +case CONF_WRITE : +break ; +case CONF_READ : +break ; +default : +error_setg (&err,"Unknown command" ); + goto finalize_loop; + } + +g_free (msg); + +return ; + +finalize_loop: +error_report_err (err); +g_free (msg); +mpqemu_link_finalize (mpqemu_link); + mpqemu_link =NULL ; +}int main (int argc,char *argv[]) { +Error *err =NULL ; +module_call_init (MODULE_INIT_QOM ); +bdrv_init_with_whitelist (); + +if (qemu_init_main_loop (&err)) { +error_report_err (err); +return -EBUSY ; + } + +qemu_init_cpu_loop (); + +page_size_init (); + current_machine =MACHINE (REMOTE_MACHINE (object_new (TYPE_REMOTE_MACHINE ))); + mpqemu_link =mpqemu_link_create (); +if (!mpqemu_link) { +printf ("Could not create MPQemu link\n" ); +return -1 ; + } + +mpqemu_init_channel (mpqemu_link, &mpqemu_link->com,STDIN_FILENO ); +mpqemu_link_set_callback (mpqemu_link, process_msg); + +mpqemu_start_coms (mpqemu_link); +return 0 ; }
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 12/49] multi-process: remote process initialization
Quoted 19 lines · Jagannathan Raman
int
main(int argc, char *argv[])
{remote/remote-main.c +13
-0+Error *err =NULL ; +module_call_init (MODULE_INIT_QOM ); +bdrv_init_with_whitelist (); + +if (qemu_init_main_loop (&err)) { +error_report_err (err); +return -EBUSY ; + } + +qemu_init_cpu_loop (); + +page_size_init (); + current_machine =MACHINE (REMOTE_MACHINE (object_new (TYPE_REMOTE_MACHINE )));
remote/remote-main.c line 121
Quoted 10 lines
remote/remote-main.c +10
-0+ mpqemu_link =mpqemu_link_create (); +if (!mpqemu_link) { +printf ("Could not create MPQemu link\n" ); +return -1 ; + } + +mpqemu_init_channel (mpqemu_link, &mpqemu_link->com,STDIN_FILENO ); +mpqemu_link_set_callback (mpqemu_link, process_msg); + +mpqemu_start_coms (mpqemu_link);
Can you use util/main-loop.c instead of an mpqemu-specific event loop? I think that file is needed anyway because lots of QEMU code depends on it.
RFC PATCH v4 13/49 multi-process: introduce proxy object
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE. PCI Proxy Object is responsible for registering PCI BARs,i MemoryRegionOps to handle access to the BARs and forwarding those to the remote device.
PCI Proxy object intercepts config space reads and writes. In case of pci config write it forwards it to the remote device using communication channel set by proxy-link object.
--- hw/Makefile.objs | 2 + hw/proxy/Makefile.objs | 1 + hw/proxy/qemu-proxy.c | 247 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 81 ++++++++++++++ remote/remote-main.c | 28 +++++ 5 files changed, 359 insertions(+) create mode 100644 hw/proxy/Makefile.objs create mode 100644 hw/proxy/qemu-proxy.c create mode 100644 include/hw/proxy/qemu-proxy.h
hw/Makefile.objs +2 -0
@@ -44,6 +44,8 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) +common-obj-$(CONFIG_MPQEMU) += proxy/ + remote-pci-obj-$(CONFIG_MPQEMU) += core/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += pci/
hw/proxy/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o
hw/proxy/qemu-proxy.c new file +247 -0
247 lines not on this page · raw message
include/hw/proxy/qemu-proxy.h new file +81 -0
81 lines not on this page · raw message
remote/remote-main.c +28 -0
@@ -50,6 +50,32 @@static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev; +static void process_config_write (MPQemuMsg *msg) +{ +struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + +qemu_mutex_lock_iothread (); +pci_default_write_config (remote_pci_dev, conf->addr, conf->val, conf->l); +qemu_mutex_unlock_iothread (); +} + +static void process_config_read (MPQemuMsg *msg) +{ +struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; +uint32_t val; +int wait; + + wait = msg->fds[0 ]; + +qemu_mutex_lock_iothread (); + val =pci_default_read_config (remote_pci_dev, conf->addr, conf->l); +qemu_mutex_unlock_iothread (); + +notify_proxy (wait, val); + +PUT_REMOTE_WAIT (wait); +} +static void process_msg (GIOCondition cond,MPQemuChannel *chan) {MPQemuMsg *msg =NULL ;
@@ -71,8 +97,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)case INIT :break ;case CONF_WRITE : +process_config_write (msg);break ;case CONF_READ : +process_config_read (msg);break ;default :error_setg (&err,"Unknown command" );
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 13/49] multi-process: introduce proxy object
Quoted 26 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c new file +20
-0@@ -0,0 +1,247 @@ +/* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE.
hw/proxy/qemu-proxy.c line 30
Quoted 10 lines
hw/proxy/qemu-proxy.c new file +10
-0+*/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <unistd.h> +#include <assert.h> +#include <string.h> +#include "qemu/osdep.h"
Most of these includes are not necessary. Please see "Include directives" in CODING_STYLE.rst. "qemu/osdep.h" is always first (even before system headers) and it already includes the common system headers.
Quoted 23 lines
hw/proxy/qemu-proxy.c new file +23
-0+int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp) +{ +char *args[3 ]; +pid_t rpid; +int fd[2 ] = {-1 ,-1 }; +Error *local_error =NULL ; + +if (pdev->managed) { +/* Child is forked by external program (such as libvirt). */ +return -1 ; + } + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +error_setg (errp,"Unable to create unix socket." ); +return -1 ; + } +/* TODO: Restrict the forked process' permissions and capabilities. */ + rpid =qemu_fork (&local_error); + +if (rpid ==-1 ) { +error_setg (errp,"Unable to spawn emulation program." ); +close (fd[0 ]); +close (fd[1 ]);
hw/proxy/qemu-proxy.c line 80
Quoted 10 lines
hw/proxy/qemu-proxy.c new file +10
-0+return -1 ; + } + +if (rpid ==0 ) { +close (fd[0 ]); + + args[0 ] =g_strdup (command); + args[1 ] =g_strdup_printf ("%d" , fd[1 ]); + args[2 ] =NULL ; +execvp (args[0 ], (char *const *)args);
execv(3) is safer because it doesn't search PATH. Unless searching PATH is really needed I would use that instead just in case this is ever deployed in an environment where an attacker controls a directory in PATH or is able to set PATH.
Quoted 9 lines
hw/proxy/qemu-proxy.c new file +9
-0+static int config_op_send (PCIProxyDev *dev,uint32_t addr,uint32_t *val,int l, +unsigned int op) +{ +MPQemuMsg msg; +struct conf_data_msg conf_data; +int wait; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + conf_data.addr = addr;
hw/proxy/qemu-proxy.c line 129
Quoted 10 lines
hw/proxy/qemu-proxy.c new file +10
-0+ conf_data.val = (op ==CONF_WRITE ) ? *val :0 ; + conf_data.l = l; + + msg.data2 = (uint8_t *)malloc (sizeof (conf_data)); +if (!msg.data2) { +return -ENOMEM ; + } + +memcpy (msg.data2, (const uint8_t *)&conf_data,sizeof (conf_data)); + msg.size =sizeof (conf_data);
Why malloc msg.data2 instead of simply pointing it at conf_data?
hw/proxy/qemu-proxy.c line 136
Quoted 7 lines
hw/proxy/qemu-proxy.c new file +7
-0+ msg.cmd = op; + msg.bytestream =1 ; + +if (op ==CONF_WRITE ) { + msg.num_fds =0 ; + }else { + wait =GET_REMOTE_WAIT ;
It seems slow to create an fd and pass it for each 32-bit PCI Configuration Space read operation. This doesn't need to be changed right now, but eventually the protocol should handle this more efficiently.
hw/proxy/qemu-proxy.c line 146
Quoted 10 lines
hw/proxy/qemu-proxy.c new file +10
-0+ msg.num_fds =1 ; + msg.fds[0 ] = wait; + } + +mpqemu_msg_send (dev->mpqemu_link, &msg, dev->mpqemu_link->com); + +if (op ==CONF_READ ) { + *val = (uint32_t )wait_for_remote (wait); +PUT_REMOTE_WAIT (wait); + }
Waiting for the eventfd blocks the event loop. This means timers and other fds won't be serviced when the remote is slow to respond. Please avoid blocking operations in event loop threads.
hw/proxy/qemu-proxy.c line 157
Quoted 11 lines
hw/proxy/qemu-proxy.c new file +11
-0+ +free (msg.data2); + +return 0 ; +} + +static uint32_t pci_proxy_read_config (PCIDevice *d,uint32_t addr,int len) +{ +uint32_t val; + + (void )pci_default_read_config (d, addr, len);
What is the purpose of this call?
hw/proxy/qemu-proxy.c line 192
Quoted 12 lines
hw/proxy/qemu-proxy.c new file +12
-0+static const TypeInfo pci_proxy_dev_type_info = { + .name =TYPE_PCI_PROXY_DEV , + .parent =TYPE_PCI_DEVICE , + .instance_size =sizeof (PCIProxyDev), + .abstract = true, + .class_size =sizeof (PCIProxyDevClass), + .class_init = pci_proxy_dev_class_init, + .interfaces = (InterfaceInfo []) { + {INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +};
It would be nice for -device pci-proxy-dev to work as a placeholder for *any* PCI bus device without the need to define concrete subclasses. Could the protocol exchange the PCI device configuration (similar to VFIO and muser ioctls) so that this single object can act as any remote PCI device?
Quoted 39 lines
include/hw/proxy/qemu-proxy.h new file +33
-0@@ -0,0 +1,81 @@ +/* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef QEMU_PROXY_H +#define QEMU_PROXY_H + +#include "io/mpqemu-link.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV (obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_CLASS (klass) \
include/hw/proxy/qemu-proxy.h line 43
Quoted 10 lines
include/hw/proxy/qemu-proxy.h new file +10
-0+ OBJECT_CLASS_CHECK(PCIProxyDevClass, (klass), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { + PCIDevice parent_dev; + + int n_mr_sections; + MemoryRegionSection *mr_sections;
Unused.
include/hw/proxy/qemu-proxy.h line 48
Quoted 5 lines
include/hw/proxy/qemu-proxy.h new file +5
-0+ +MPQemuLinkState *mpqemu_link; + +EventNotifier intr; +EventNotifier resample;
Unused.
include/hw/proxy/qemu-proxy.h line 52
Quoted 4 lines
include/hw/proxy/qemu-proxy.h new file +4
-0+ +pid_t remote_pid; +int rsocket; +int socket;
What is the difference between rsocket and socket? Why is socket only read in this patch and never written?
include/hw/proxy/qemu-proxy.h line 54
Quoted 2 lines
include/hw/proxy/qemu-proxy.h new file +2
-0+ +char *rid;
Can remote_pid and rid be unified. They store the same value in different representations.
include/hw/proxy/qemu-proxy.h line 57
Quoted 3 lines
include/hw/proxy/qemu-proxy.h new file +3
-0+ +bool managed; +char *dev_id;
dev_id is unused.
include/hw/proxy/qemu-proxy.h line 59
Quoted 2 lines
include/hw/proxy/qemu-proxy.h new file +2
-0+ +QLIST_ENTRY (PCIProxyDev) next;
Unused.
include/hw/proxy/qemu-proxy.h line 65
Quoted 6 lines
include/hw/proxy/qemu-proxy.h new file +6
-0+ +void (*set_proxy_sock) (PCIDevice *dev,int socket); +int (*get_proxy_sock) (PCIDevice *dev); + +void (*set_remote_opts) (PCIDevice *dev,QDict *qdict,unsigned int cmd); +void (*proxy_ready) (PCIDevice *dev);
Unused.
include/hw/proxy/qemu-proxy.h line 66
Quoted 1 line
include/hw/proxy/qemu-proxy.h new file +1
-0+void (*init_proxy) (PCIDevice *pdev,char *command,Error **errp);
Why are these function pointers not in PCIProxyDevClass?
include/hw/proxy/qemu-proxy.h line 78
Quoted 12 lines
include/hw/proxy/qemu-proxy.h new file +12
-0+ +} PCIProxyDev; + +typedef struct PCIProxyDevClass { +PCIDeviceClass parent_class; + +void (*realize)(PCIProxyDev *dev,Error **errp); + +char *command; +}PCIProxyDevClass ; + +int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp);
Does this function need to be publicly visible?
Quoted 23 lines
remote/remote-main.c +15
-0@@ -50,6 +50,32 @@static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev; +static void process_config_write (MPQemuMsg *msg) +{ +struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + +qemu_mutex_lock_iothread (); +pci_default_write_config (remote_pci_dev, conf->addr, conf->val, conf->l); +qemu_mutex_unlock_iothread (); +} + +static void process_config_read (MPQemuMsg *msg) +{ +struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; +uint32_t val; +int wait; +
remote/remote-main.c line 77
Quoted 10 lines
remote/remote-main.c +10
-0+ wait = msg->fds[0 ]; + +qemu_mutex_lock_iothread (); + val =pci_default_read_config (remote_pci_dev, conf->addr, conf->l); +qemu_mutex_unlock_iothread (); + +notify_proxy (wait, val); + +PUT_REMOTE_WAIT (wait); +}
Input validation is missing in these message handler functions. I won't look out for this in patches that follow anymore. All message handler functions need to be audited. They must check the message size before accessing fields, that fds[0] was indeed passed, etc.
RFC PATCH v4 14/49 mutli-process: build remote command line args
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
---
New patch in v3
hw/proxy/qemu-proxy.c | 80 +++++++++++++++++++++++++++++++++---------- include/hw/proxy/qemu-proxy.h | 2 +- 2 files changed, 62 insertions(+), 20 deletions(-)
hw/proxy/qemu-proxy.c +61 -19
@@ -45,47 +45,89 @@static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp); +static int add_argv (char *command_str,char **argv,int argc) +{ +int max_args =64 ; + +if (argc < max_args -1 ) { + argv[argc++] = command_str; + argv[argc] =0 ; + }else { +return 0 ; + } + +return argc; +} + +static int make_argv (char *command_str,char **argv,int argc) +{ +int max_args =64 ; + +char *p2 =strtok (command_str," " ); +while (p2 && argc < max_args -1 ) { + argv[argc++] = p2; + p2 =strtok (0 ," " ); + } + argv[argc] =0 ; + +return argc; +} +int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp) { -char *args[3 ];pid_t rpid;int fd[2 ] = {-1 ,-1 };Error *local_error =NULL ; +char *argv[64 ]; +int argc =0 , _argc; +char *sfd; +char *exec_dir; +int rc = -EINVAL ;if (pdev->managed) {/* Child is forked by external program (such as libvirt). */ -return -1 ; +return rc; }if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) {error_setg (errp,"Unable to create unix socket." ); -return -1 ; +return rc; } + exec_dir =g_strdup_printf ("%s/%s" ,qemu_get_exec_dir (),"qemu-scsi-dev" ); + argc =add_argv (exec_dir, argv, argc); + sfd =g_strdup_printf ("%d" , fd[1 ]); + argc =add_argv (sfd, argv, argc); + _argc = argc; + argc =make_argv ((char *)command, argv, argc); +/* TODO: Restrict the forked process' permissions and capabilities. */ rpid =qemu_fork (&local_error);if (rpid ==-1 ) {error_setg (errp,"Unable to spawn emulation program." );close (fd[0 ]); -close (fd[1 ]); -return -1 ; + goto fail; }if (rpid ==0 ) {close (fd[0 ]); - - args[0 ] =g_strdup (command); - args[1 ] =g_strdup_printf ("%d" , fd[1 ]); - args[2 ] =NULL ; -execvp (args[0 ], (char *const *)args); +execvp (argv[0 ], (char *const *)argv);exit (1 ); } pdev->remote_pid = rpid; - pdev->rsocket = fd[0 ]; + pdev->rsocket = fd[1 ]; + pdev->socket = fd[0 ]; + rc =0 ; + +fail:close (fd[1 ]); -return 0 ; +for (int i =0 ; i < _argc; i++) { +g_free (argv[i]); + } + +return rc; }static int get_proxy_sock (PCIDevice *dev)
@@ -94,7 +136,7 @@ static int get_proxy_sock(PCIDevice *dev) pdev =PCI_PROXY_DEV (dev); -return pdev->rsocket; +return pdev->socket; }static void set_proxy_sock (PCIDevice *dev,int socket)
@@ -103,7 +145,7 @@ static void set_proxy_sock(PCIDevice *dev, int socket) pdev =PCI_PROXY_DEV (dev); - pdev->rsocket = socket; + pdev->socket = socket; pdev->managed = true; }
@@ -198,16 +240,16 @@ static void pci_proxy_dev_register_types(void)type_init (pci_proxy_dev_register_types) -static void init_proxy(PCIDevice *dev, char *command, Error **errp) +static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp) {PCIProxyDev *pdev =PCI_PROXY_DEV (dev);Error *local_error =NULL ;if (!pdev->managed) { -if (command) { -remote_spawn (pdev, command, &local_error); - }else { -return ; +if (need_spawn) { +if (!remote_spawn (pdev, command, &local_error)) { +return ; + } } }else { pdev->remote_pid =atoi (pdev->rid);
include/hw/proxy/qemu-proxy.h +1 -1
@@ -63,7 +63,7 @@ typedef struct PCIProxyDev {void (*set_remote_opts) (PCIDevice *dev,QDict *qdict,unsigned int cmd);void (*proxy_ready) (PCIDevice *dev); -void (*init_proxy) (PCIDevice *pdev,char *command,Error **errp); +void (*init_proxy) (PCIDevice *dev,char *command,bool need_spawn,Error **errp); } PCIProxyDev;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 14/49] mutli-process: build remote command line args
Quoted 37 lines · Jagannathan Raman
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]>---
New patch in v3hw/proxy/qemu-proxy.c | 80 +++++++++++++++++++++++++++++++++---------- include/hw/proxy/qemu-proxy.h | 2 +- 2 files changed, 62 insertions(+), 20 deletions(-)hw/proxy/qemu-proxy.c +17
-0@@ -45,47 +45,89 @@static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp); +static int add_argv (char *command_str,char **argv,int argc) +{ +int max_args =64 ; + +if (argc < max_args -1 ) { + argv[argc++] = command_str; + argv[argc] =0 ; + }else { +return 0 ; + } + +return argc; +} + +static int make_argv (char *command_str,char **argv,int argc) +{ +int max_args =64 ;
hw/proxy/qemu-proxy.c line 74
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +char *p2 =strtok (command_str," " ); +while (p2 && argc < max_args -1 ) { + argv[argc++] = p2; + p2 =strtok (0 ," " ); + } + argv[argc] =0 ; + +return argc; +}
So "command" isn't really the command-line, it's a string of options to append to the hardcoded qemu-scsi-dev command?
This needs to command-line string construction needs to be cleaned up and the hardcoded qemu-scsi-dev needs to be replaced with an argument.
hw/proxy/qemu-proxy.c line 76
Quoted 2 lines
hw/proxy/qemu-proxy.c +1
-0+int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp)
Error handling code is currently inconsistent because there is an int -errno return value and an errp argument. For example, errp isn't set when pdev->managed == true.
The int -errno return value isn't needed. It can be just be bool and errp should be set in every single error code path.
Quoted 44 lines
hw/proxy/qemu-proxy.c +15
-7{ -char *args[3 ];pid_t rpid;int fd[2 ] = {-1 ,-1 };Error *local_error =NULL ; +char *argv[64 ]; +int argc =0 , _argc; +char *sfd; +char *exec_dir; +int rc = -EINVAL ;if (pdev->managed) {/* Child is forked by external program (such as libvirt). */ -return -1 ; +return rc; }if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) {error_setg (errp,"Unable to create unix socket." ); -return -1 ; +return rc; } + exec_dir =g_strdup_printf ("%s/%s" ,qemu_get_exec_dir (),"qemu-scsi-dev" ); + argc =add_argv (exec_dir, argv, argc); + sfd =g_strdup_printf ("%d" , fd[1 ]); + argc =add_argv (sfd, argv, argc); + _argc = argc; + argc =make_argv ((char *)command, argv, argc); +/* TODO: Restrict the forked process' permissions and capabilities. */ rpid =qemu_fork (&local_error);if (rpid ==-1 ) {error_setg (errp,"Unable to spawn emulation program." );close (fd[0 ]); -close (fd[1 ]); -return -1 ; + goto fail; }if (rpid ==0 ) {close (fd[0 ]); - - args[0 ] =g_strdup (command);
hw/proxy/qemu-proxy.c line 119
Quoted 10 lines
hw/proxy/qemu-proxy.c +3
-4- args[1 ] =g_strdup_printf ("%d" , fd[1 ]); - args[2 ] =NULL ; -execvp (args[0 ], (char *const *)args); +execvp (argv[0 ], (char *const *)argv);exit (1 ); } pdev->remote_pid = rpid; - pdev->rsocket = fd[0 ]; + pdev->rsocket = fd[1 ]; + pdev->socket = fd[0 ];
Please choose meaningful names for these fields. I'm not sure why both need to be kept around though...
Quoted 39 lines
hw/proxy/qemu-proxy.c +11
-4+ rc =0 ; + +fail:close (fd[1 ]); -return 0 ; +for (int i =0 ; i < _argc; i++) { +g_free (argv[i]); + } + +return rc; }static int get_proxy_sock (PCIDevice *dev)@@ -94,7 +136,7 @@ static int get_proxy_sock(PCIDevice *dev) pdev =PCI_PROXY_DEV (dev); -return pdev->rsocket; +return pdev->socket; }static void set_proxy_sock (PCIDevice *dev,int socket)@@ -103,7 +145,7 @@ static void set_proxy_sock(PCIDevice *dev, int socket) pdev =PCI_PROXY_DEV (dev); - pdev->rsocket = socket; + pdev->socket = socket; pdev->managed = true; }@@ -198,16 +240,16 @@ static void pci_proxy_dev_register_types(void)type_init (pci_proxy_dev_register_types) -static void init_proxy(PCIDevice *dev, char *command, Error **errp) +static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp)
hw/proxy/qemu-proxy.c static void pci_proxy_dev_register_types(void) · line 249
Quoted 10 lines
hw/proxy/qemu-proxy.c +1
-4{PCIProxyDev *pdev =PCI_PROXY_DEV (dev);Error *local_error =NULL ;if (!pdev->managed) { -if (command) { -remote_spawn (pdev, command, &local_error); - }else { -return ; +if (need_spawn) {
pdev->managed, command == NULL, need_spawn are all ways of checking whether the remote process needs to be spawned. Why are all of them necessary and can they be simplified?
hw/proxy/qemu-proxy.c static void pci_proxy_dev_register_types(void) · line 251
Quoted 2 lines
hw/proxy/qemu-proxy.c +2
-0+if (!remote_spawn (pdev, command, &local_error)) { +return ;
local_error needs to be propagated.
RFC PATCH v4 15/49 multi-process: PCI BAR read/write handling for proxy & remote endpoints
In reply to Jagannathan RamanProxy device object implements handler for PCI BAR writes and reads. The handler uses BAR_WRITE/BAR_READ message to communicate to the remote process with the BAR address and value to be written/read.
The remote process implements handler for BAR_WRITE/BAR_READ message.
--- hw/proxy/qemu-proxy.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 21 ++++++++++-- include/io/mpqemu-link.h | 12 +++++++ remote/remote-main.c | 73 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +77 -0
@@ -275,6 +275,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp)PCIProxyDev *dev =PCI_PROXY_DEV (device);PCIProxyDevClass *k =PCI_PROXY_DEV_GET_CLASS (dev);Error *local_err =NULL ; +int r;if (k->realize) { k->realize (dev, &local_err);
@@ -283,7 +284,83 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) } } +for (r =0 ; r <PCI_NUM_REGIONS ; r++) { +if (!dev->region[r].present) { +continue ; + } + + dev->region[r].dev = dev; + +pci_register_bar (PCI_DEVICE (dev), r, dev->region[r].type, + &dev->region[r].mr); + } + dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; } + +static void send_bar_access_msg (PCIProxyDev *dev,MemoryRegion *mr, +bool write,hwaddr addr,uint64_t *val, +unsigned size,bool memory) +{ +MPQemuLinkState *mpqemu_link = dev->mpqemu_link; +MPQemuMsg msg; +int wait; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.data1.bar_access.addr = mr->addr + addr; + msg.data1.bar_access.size = size; + msg.data1.bar_access.memory = memory; + +if (write) { + msg.cmd =BAR_WRITE ; + msg.data1.bar_access.val = *val; + }else { + wait =GET_REMOTE_WAIT ; + + msg.cmd =BAR_READ ; + msg.num_fds =1 ; + msg.fds[0 ] = wait; + } + +mpqemu_msg_send (mpqemu_link, &msg, mpqemu_link->com); + +if (!write) { + *val =wait_for_remote (wait); +PUT_REMOTE_WAIT (wait); + } +} + +void proxy_default_bar_write (void *opaque,hwaddr addr,uint64_t val, +unsigned size) +{ +ProxyMemoryRegion *pmr = opaque; + +send_bar_access_msg (pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +uint64_t proxy_default_bar_read (void *opaque,hwaddr addr,unsigned size) +{ +ProxyMemoryRegion *pmr = opaque; +uint64_t val; + +send_bar_access_msg (pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + +return val; +} + +const MemoryRegionOps proxy_default_ops = { + .read = proxy_default_bar_read, + .write = proxy_default_bar_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = { + .min_access_size =1 , + .max_access_size =1 , + }, +};
include/hw/proxy/qemu-proxy.h +19 -2
@@ -36,7 +36,19 @@#define PCI_PROXY_DEV_GET_CLASS (obj) \ OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) -typedef struct PCIProxyDev { +typedef struct PCIProxyDev PCIProxyDev ; + +typedef struct ProxyMemoryRegion { +PCIProxyDev *dev; +MemoryRegion mr; +bool memory; +bool present; +uint8_t type; +}ProxyMemoryRegion ; + +extern const MemoryRegionOps proxy_default_ops; + +struct PCIProxyDev {PCIDevice parent_dev;int n_mr_sections;
@@ -65,7 +77,8 @@ typedef struct PCIProxyDev {void (*proxy_ready) (PCIDevice *dev);void (*init_proxy) (PCIDevice *dev,char *command,bool need_spawn,Error **errp); -} PCIProxyDev; +ProxyMemoryRegion region[PCI_NUM_REGIONS ]; +}; typedef struct PCIProxyDevClass { PCIDeviceClass parent_class;
@@ -77,5 +90,9 @@ typedef struct PCIProxyDevClass {int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp); +void proxy_default_bar_write (void *opaque,hwaddr addr,uint64_t val, +unsigned size); + +uint64_t proxy_default_bar_read (void *opaque,hwaddr addr,unsigned size);#endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +12 -0
@@ -52,6 +52,8 @@* CONF_READ PCI config. space read * CONF_WRITE PCI config. space write * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM +* BAR_WRITE Writes to PCI BAR region +* BAR_READ Reads from PCI BAR region * * proc_cmd_t enum type to specify the command to be executed on the remote * device.
@@ -61,6 +63,8 @@ typedef enum {CONF_READ ,CONF_WRITE ,SYNC_SYSMEM , +BAR_WRITE , +BAR_READ ,MAX , } mpqemu_cmd_t;
@@ -84,6 +88,13 @@ typedef struct { } sync_sysmem_msg_t;typedef struct { +hwaddr addr; +uint64_t val; +unsigned size; +bool memory; +}bar_access_msg_t ; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size;
@@ -91,6 +102,7 @@ typedef struct {union {uint64_t u64;sync_sysmem_msg_t sync_sysmem; +bar_access_msg_t bar_access; } data1;int fds[REMOTE_MAX_FDS ];
remote/remote-main.c +73 -0
91 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 15/49] multi-process: PCI BAR read/write handling for proxy & remote endpoints
Quoted 1 line · Jagannathan Raman
+const MemoryRegionOps
proxy_default_ops= {
Unused. Please structure patch series so that each patch is a self-contained logical change. It should be possible to review the series in order from start to finish.
If there is no user yet and this is a public API then there need to be doc comments describing the API.
include/io/mpqemu-link.h line 56
Quoted 10 lines
include/io/mpqemu-link.h +2
-0@@ -52,6 +52,8 @@* CONF_READ PCI config. space read * CONF_WRITE PCI config. space write * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM +* BAR_WRITE Writes to PCI BAR region +* BAR_READ Reads from PCI BAR region
Is it possible to generalize this to memory regions instead of PCI BARs? That way non-PCI devices will be able to use the same protocol messages and code. VFIO describes BARs generically too for the same reason, see <linux/vfio.h> struct vfio_region_info.
Quoted 13 lines
include/io/mpqemu-link.h +2
-0* * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -61,6 +63,8 @@ typedef enum {CONF_READ ,CONF_WRITE ,SYNC_SYSMEM , +BAR_WRITE , +BAR_READ ,MAX , } mpqemu_cmd_t;
include/io/mpqemu-link.h typedef struct { · line 94
Quoted 7 lines
include/io/mpqemu-link.h +4
-0@@ -84,6 +88,13 @@ typedef struct { } sync_sysmem_msg_t; typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory;
Why is this field necessary? Whether this is a memory access or not should be implicit from the address/BAR we are accessing.
RFC PATCH v4 16/49 multi-process: Add LSI device proxy object
In reply to Jagannathan RamanAdds proxy-lsi53c895a object, as a derivative of the pci-proxy-dev object. This object is the proxy for the lsi53c895a object instantiated by the remote process.
--- hw/proxy/Makefile.objs | 1 + hw/proxy/proxy-lsi53c895a.c | 91 +++++++++++++++++++++++++++++++++++++ include/hw/proxy/proxy-lsi53c895a.h | 42 +++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 hw/proxy/proxy-lsi53c895a.c create mode 100644 include/hw/proxy/proxy-lsi53c895a.h
hw/proxy/Makefile.objs +1 -0
@@ -1 +1,2 @@ common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o +common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o
hw/proxy/proxy-lsi53c895a.c new file +91 -0
91 lines not on this page · raw message
include/hw/proxy/proxy-lsi53c895a.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 16/49] multi-process: Add LSI device proxy object
Quoted 3 lines · Jagannathan Raman
Adds proxy-lsi53c895a object, as a derivative of the pci-proxy-dev object. This object is the proxy for the lsi53c895a object instantiated by the remote process.
The same information could be fetched from the remote process. That would eliminate the need for per-device proxy objects.
Stefan
RFC PATCH v4 17/49 multi-process: Synchronize remote memory
In reply to Jagannathan RamanAdd 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.
---
v2 -> v3:
- Refactored code to obtain fd from host address, added
get_fd_from_hostaddr().
- Discovered a bug which results in invalid FDs (-1) being sent over to the remote process. Fixed this by checking if the FD value is valid before sending over to remote.
Makefile.target | 1 + hw/proxy/memory-sync.c | 226 +++++++++++++++++++++++++++++++++++++++++ hw/proxy/qemu-proxy.c | 5 + include/hw/proxy/memory-sync.h | 51 ++++++++++ include/hw/proxy/qemu-proxy.h | 2 + remote/remote-main.c | 11 ++ 6 files changed, 296 insertions(+) create mode 100644 hw/proxy/memory-sync.c create mode 100644 include/hw/proxy/memory-sync.h
Makefile.target +1 -0
@@ -122,6 +122,7 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o +obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o LIBS := $(libs_cpu) $(LIBS) remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o
hw/proxy/memory-sync.c new file +226 -0
226 lines not on this page · raw message
hw/proxy/qemu-proxy.c +5 -0
@@ -42,6 +42,8 @@#include "qapi/qmp/qstring.h" #include "sysemu/sysemu.h" #include "hw/proxy/qemu-proxy.h" +#include "hw/proxy/memory-sync.h" +#include "qom/object.h" static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);
@@ -268,6 +270,8 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **empqemu_init_channel (pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); + +configure_memory_sync (pdev->sync, pdev->mpqemu_link); }static void pci_proxy_dev_realize (PCIDevice *device,Error **errp)
@@ -298,6 +302,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; + dev->sync =REMOTE_MEM_SYNC (object_new (TYPE_MEMORY_LISTENER )); } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/memory-sync.h new file +51 -0
51 lines not on this page · raw message
include/hw/proxy/qemu-proxy.h +2 -0
@@ -24,6 +24,7 @@#define QEMU_PROXY_H #include "io/mpqemu-link.h" +#include "hw/proxy/memory-sync.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
@@ -56,6 +57,7 @@ struct PCIProxyDev {MPQemuLinkState *mpqemu_link; +RemoteMemSync *sync;EventNotifier intr;EventNotifier resample;
remote/remote-main.c +11 -0
@@ -47,6 +47,7 @@#include "sysemu/sysemu.h" #include "block/block.h" #include "exec/memattrs.h" +#include "exec/address-spaces.h" static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev;
@@ -175,6 +176,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; }break ; +case SYNC_SYSMEM : +/* +* TODO: ensure no active DMA is happening when +* sysmem is being updated +*/ +remote_sysmem_reconfig (msg, &err); +if (err) { + goto finalize_loop; + } +break ;default :error_setg (&err,"Unknown command" ); goto finalize_loop;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 17/49] multi-process: Synchronize remote memory
hw/proxy/memory-sync.c line 50
Quoted 12 lines · Jagannathan Raman
hw/proxy/memory-sync.c new file +12
-0+static const TypeInfo remote_mem_sync_type_info = { + .name =TYPE_MEMORY_LISTENER , + .parent =TYPE_OBJECT , + .instance_size =sizeof (RemoteMemSync), +}; + +static void remote_mem_sync_register_types (void ) +{ +type_register_static (&remote_mem_sync_type_info); +} + +type_init (remote_mem_sync_register_types)
Why is a QEMU Object necessary for the memory listener? QEMU Objects are used for the device model and -object. The memory listener is an internal concept that doesn't need to be exposed as a QEMU Object. It's fine to use plain C structs and functions, not everything needs to be a QEMU Object.
Quoted 9 lines
+/*
+ * TODO: Memory Sync need not be instantianted once per every proxy device.
+ * All remote devices are going to get the exact same updates at the
+ * same time. It therefore makes sense to have a broadcast model.
+ *+ * Broadcast model would involve running the MemorySync object in a + * thread. MemorySync would contain a list of mpqemu-link objects + * that need notification. proxy_ml_commit() could send the same + * message to all the links at the same time.
Once mpqemu-link is made event-loop friendly (asynchronous) it won't be necessary to create more threads.
RFC PATCH v4 18/49 multi-process: create IOHUB object to handle irq
In reply to Jagannathan RamanIOHUB 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.
--- Makefile.target | 1 + hw/proxy/Makefile.objs | 1 - hw/proxy/qemu-proxy.c | 54 ++++++++++++++ include/hw/pci/pci_ids.h | 3 + include/hw/proxy/qemu-proxy.h | 5 ++ include/io/mpqemu-link.h | 8 +++ include/remote/iohub.h | 63 +++++++++++++++++ include/remote/machine.h | 2 + remote/Makefile.objs | 1 + remote/iohub.c | 159 ++++++++++++++++++++++++++++++++++++++++++ remote/machine.c | 15 ++++ remote/remote-main.c | 4 ++ 12 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 include/remote/iohub.h create mode 100644 remote/iohub.c
Makefile.target +1 -0
@@ -123,6 +123,7 @@ obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o +obj-$(CONFIG_MPQEMU) += hw/proxy/qemu-proxy.o LIBS := $(libs_cpu) $(LIBS) remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o
hw/proxy/Makefile.objs +0 -1
@@ -1,2 +1 @@ -common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o
hw/proxy/qemu-proxy.c +54 -0
78 lines not on this page · raw message
include/hw/pci/pci_ids.h +3 -0
@@ -191,6 +191,9 @@#define PCI_DEVICE_ID_SUN_SIMBA 0x5000#define PCI_DEVICE_ID_SUN_SABRE 0xa000 +#define PCI_VENDOR_ID_ORACLE 0x108e +#define PCI_DEVICE_ID_REMOTE_IOHUB 0xb000 +#define PCI_VENDOR_ID_CMD 0x1095#define PCI_DEVICE_ID_CMD_646 0x0646
include/hw/proxy/qemu-proxy.h +5 -0
@@ -23,8 +23,11 @@#ifndef QEMU_PROXY_H #define QEMU_PROXY_H +#include <linux/kvm.h> +#include "io/mpqemu-link.h" #include "hw/proxy/memory-sync.h" +#include "qemu/event_notifier.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
@@ -58,6 +61,8 @@ struct PCIProxyDev {MPQemuLinkState *mpqemu_link;RemoteMemSync *sync; +struct kvm_irqfd irqfd; +EventNotifier intr;EventNotifier resample;
include/io/mpqemu-link.h +8 -0
@@ -54,6 +54,8 @@* SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * BAR_WRITE Writes to PCI BAR region * BAR_READ Reads from PCI BAR region +* SET_IRQFD Sets the IRQFD to be used to raise interrupts directly +* from remote device * * proc_cmd_t enum type to specify the command to be executed on the remote * device.
@@ -65,6 +67,7 @@ typedef enum {SYNC_SYSMEM ,BAR_WRITE ,BAR_READ , +SET_IRQFD ,MAX , } mpqemu_cmd_t;
@@ -95,6 +98,10 @@ typedef struct { } bar_access_msg_t;typedef struct { +int intx; +}set_irqfd_msg_t ; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size;
@@ -103,6 +110,7 @@ typedef struct {uint64_t u64;sync_sysmem_msg_t sync_sysmem;bar_access_msg_t bar_access; +set_irqfd_msg_t set_irqfd; } data1;int fds[REMOTE_MAX_FDS ];
include/remote/iohub.h new file +63 -0
63 lines not on this page · raw message
include/remote/machine.h +2 -0
@@ -30,11 +30,13 @@#include "hw/boards.h" #include "remote/pcihost.h" #include "qemu/notify.h" +#include "remote/iohub.h" typedef struct RemMachineState {MachineState parent_obj;RemPCIHost *host; +RemoteIOHubState *iohub; }RemMachineState ;#define TYPE_REMOTE_MACHINE "remote-machine"
remote/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o +remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o
remote/iohub.c new file +159 -0
159 lines not on this page · raw message
remote/machine.c +15 -0
@@ -40,6 +40,8 @@#include "qemu-common.h" #include "sysemu/sysemu.h" #include "qemu/notify.h" +#include "hw/pci/pci_host.h" +#include "remote/iohub.h" static NotifierList machine_init_done_notifiers =NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers);
@@ -70,6 +72,8 @@ static void remote_machine_init(Object *obj)RemMachineState *s =REMOTE_MACHINE (obj);RemPCIHost *rem_host;MemoryRegion *system_memory, *system_io, *pci_memory; +PCIHostState *pci_host; +PCIDevice *pci_dev;Error *error_abort =NULL ;
@@ -101,6 +105,17 @@ static void remote_machine_init(Object *obj)qemu_mutex_unlock_iothread ();qdev_init_nofail (DEVICE (rem_host)); + + pci_host =PCI_HOST_BRIDGE (rem_host); + pci_dev =pci_create_simple_multifunction (pci_host->bus, +PCI_DEVFN (REMOTE_IOHUB_DEV , +REMOTE_IOHUB_FUNC ), + true,TYPE_REMOTE_IOHUB_DEVICE ); + + s->iohub =REMOTE_IOHUB_DEVICE (pci_dev); + +pci_bus_irqs (pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + s->iohub,REMOTE_IOHUB_NB_PIRQS ); }static const TypeInfo remote_machine = {
remote/remote-main.c +4 -0
@@ -48,6 +48,7 @@#include "block/block.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" +#include "remote/iohub.h" static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev;
@@ -186,6 +187,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; }break ; +case SET_IRQFD : +process_set_irqfd_msg (remote_pci_dev, msg); +break ;default :error_setg (&err,"Unknown command" ); goto finalize_loop;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 18/49] multi-process: create IOHUB object to handle irq
On Thu, Oct 24, 2019 at 05:08:59AM -0400, Jagannathan Raman wrote:
I don't know the interrupt code well enough to decide whether it's necessary to do so much work and tie the protocol to the KVM API. The main QEMU process already has the KVM API code and the ability to deal with these things. I was expecting something much simpler, like protocol messages that pass a single eventfd for raising an interrupt and no state tracking interrupt levels.
remote/iohub.c line 129
Quoted 11 lines
remote/iohub.c new file +11
-0+static void intr_resample_handler (void *opaque) +{ +ResampleToken *token = opaque; +RemoteIOHubState *iohub = token->iohub; +uint64_t val; +int pirq, s; + + pirq = token->pirq; + + s =read (event_notifier_get_fd (&iohub->resamplefds[pirq]), &val, +sizeof (uint64_t ));
Please use event_notifier_test_and_clear().
remote/iohub.c line 142
Quoted 13 lines
remote/iohub.c new file +13
-0+ +assert (s >=0 ); + +qemu_mutex_lock (&iohub->irq_level_lock[pirq]); + +if (iohub->irq_level[pirq]) { +event_notifier_set (&iohub->irqfds[pirq]); + } + +qemu_mutex_unlock (&iohub->irq_level_lock[pirq]); +} + +void process_set_irqfd_msg (PCIDevice *pci_dev,MPQemuMsg *msg)
This function doesn't handle the case where SET_IRQFD is sent multiple times for the same interrupt gracefully.
remote/iohub.c line 152
Quoted 10 lines
remote/iohub.c new file +10
-0+{ +RemMachineState *machine =REMOTE_MACHINE (current_machine); +RemoteIOHubState *iohub = machine->iohub; +ResampleToken *token; +int pirq =remote_iohub_map_irq (pci_dev, msg->data1.set_irqfd.intx); + +assert (msg->num_fds ==2 ); + +event_notifier_init_fd (&iohub->irqfds[pirq], msg->fds[0 ]); +event_notifier_init_fd (&iohub->resamplefds[pirq], msg->fds[1 ]);
event_notifier_cleanup() is missing.
remote/iohub.c line 154
Quoted 2 lines
remote/iohub.c new file +2
-0+ + token =g_malloc0 (sizeof (ResampleToken));
I couldn't find a g_free() and wonder if this needs to be malloced at all.
RFC PATCH v4 19/49 multi-process: configure remote side devices
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Add functions to configure remote devices.
--- hw/proxy/qemu-proxy.c | 39 ++++++++++++++++++++++++++++++++++++++- include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 4 ++++ 3 files changed, 44 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +38 -1
@@ -50,8 +50,43 @@#include "qemu/event_notifier.h" #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +#include "hw/boards.h" +#include "include/qemu/log.h" static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp); +static void setup_irqfd (PCIProxyDev *dev); + +static void proxy_ready (PCIDevice *dev) +{ +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); + +setup_irqfd (pdev); +} + +static void set_remote_opts (PCIDevice *dev,QDict *qdict,unsigned int cmd) +{ +QString *qstr; +MPQemuMsg msg; +const char *str; +PCIProxyDev *pdev; + + pdev =PCI_PROXY_DEV (dev); + + qstr =qobject_to_json (QOBJECT (qdict)); + str =qstring_get_str (qstr); + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.data2 = (uint8_t *)str; + msg.cmd = cmd; + msg.bytestream =1 ; + msg.size =qstring_get_length (qstr) +1 ; + msg.num_fds =0 ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + +return ; +}static int add_argv (char *command_str,char **argv,int argc) {
@@ -325,7 +360,6 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e pdev->socket);configure_memory_sync (pdev->sync, pdev->mpqemu_link); -setup_irqfd (pdev); }static void pci_proxy_dev_realize (PCIDevice *device,Error **errp)
@@ -357,6 +391,9 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; dev->sync =REMOTE_MEM_SYNC (object_new (TYPE_MEMORY_LISTENER )); + + dev->set_remote_opts = set_remote_opts; + dev->proxy_ready = proxy_ready; } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/qemu-proxy.h +2 -0
@@ -28,6 +28,8 @@#include "io/mpqemu-link.h" #include "hw/proxy/memory-sync.h" #include "qemu/event_notifier.h" +#include "hw/pci/pci.h" +#include "block/qdict.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev"
include/io/mpqemu-link.h +4 -0
@@ -68,6 +68,10 @@ typedef enum {BAR_WRITE ,BAR_READ ,SET_IRQFD , +DEV_OPTS , +DRIVE_OPTS , +DEVICE_ADD , +DEVICE_DEL ,MAX , } mpqemu_cmd_t;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 19/49] multi-process: configure remote side devices
hw/proxy/qemu-proxy.c line 75
Quoted 10 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +10
-0+static void set_remote_opts (PCIDevice *dev,QDict *qdict,unsigned int cmd) +{ +QString *qstr; +MPQemuMsg msg; +const char *str; +PCIProxyDev *pdev; + + pdev =PCI_PROXY_DEV (dev); + + qstr =qobject_to_json (QOBJECT (qdict));
qstr is leaked.
Quoted 14 lines
hw/proxy/qemu-proxy.c +14
-0+ str =qstring_get_str (qstr); + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.data2 = (uint8_t *)str; + msg.cmd = cmd; + msg.bytestream =1 ; + msg.size =qstring_get_length (qstr) +1 ; + msg.num_fds =0 ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + +return ; +}
RFC PATCH v4 20/49 multi-process: add qdev_proxy_add to create proxy devices
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
This is handled while parsing the command line options. The parsed options are being sent to remote process as the messgaes containing JSON strings.
---
v1 -> v2:
- parse socket and command suboptions of drive/device commands
hw/proxy/qemu-proxy.c | 3 +- include/hw/proxy/qemu-proxy.h | 7 ++ include/monitor/qdev.h | 25 +++++ qdev-monitor.c | 254 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +2 -1
@@ -337,7 +337,8 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **eif (!pdev->managed) {if (need_spawn) { -if (!remote_spawn (pdev, command, &local_error)) { +if (remote_spawn (pdev, command, &local_error)) { +fprintf (stderr,"remote spawn failed\n" );return ; } }
include/hw/proxy/qemu-proxy.h +7 -0
@@ -99,6 +99,13 @@ typedef struct PCIProxyDevClass {int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp); +typedef struct PCIProxyDevList { + QLIST_HEAD(, PCIProxyDev) devices; +}proxy_dev_list_t ; + +extern QemuMutex proxy_list_lock; +extern proxy_dev_list_t proxy_dev_list; +void proxy_default_bar_write (void *opaque,hwaddr addr,uint64_t val,unsigned size);
include/monitor/qdev.h +25 -0
@@ -1,13 +1,38 @@#ifndef MONITOR_QDEV_H #define MONITOR_QDEV_H +#include "hw/proxy/qemu-proxy.h" +/*** monitor commands ***/ void hmp_info_qtree (Monitor *mon,const QDict *qdict);void hmp_info_qdm (Monitor *mon,const QDict *qdict);void qmp_device_add (QDict *qdict,QObject **ret_data,Error **errp); +DeviceState *qdev_remote_add (QemuOpts *opts,bool device,Error **errp); +void qdev_proxy_fire (void ); +int qdev_device_help (QemuOpts *opts); +DeviceState *qdev_proxy_add (const char *rid,const char *id,char *bus, +char *command,int rsocket,bool managed, +Error **errp); + +struct remote_process { +int rid; +int remote_pid; +unsigned int type; +int socket; +char *command; +QemuOpts *opts; + +QLIST_ENTRY (remote_process) next; +}; + +void remote_process_register (struct remote_process *p); + +struct remote_process *get_remote_process_type (unsigned int type); +struct remote_process *get_remote_process_rid (unsigned int rid); +DeviceState *qdev_device_add (QemuOpts *opts,Error **errp);void qdev_set_id (DeviceState *dev,const char *id);
qdev-monitor.c +254 -0
272 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 20/49] multi-process: add qdev_proxy_add to create proxy devices
Quoted 5 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +0
-0
hw/proxy/qemu-proxy.c static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e · line 344
Quoted 9 lines
hw/proxy/qemu-proxy.c +2
-1@@ -337,7 +337,8 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **eif (!pdev->managed) {if (need_spawn) { -if (!remote_spawn (pdev, command, &local_error)) { +if (remote_spawn (pdev, command, &local_error)) { +fprintf (stderr,"remote spawn failed\n" );return ; } }
Looks like a fix for a bug in a previous patch. Please squash it. Also, please propagate local_err and do not use fprintf in a function that has an errp argument for reporting errors.
Quoted 1 line
+#if
defined(CONFIG_MPQEMU)
Maybe these functions should be in a separate file that the makefile includes when CONFIG_MPQEMU is defined.
hw/proxy/qemu-proxy.c
Quoted 8 lines
hw/proxy/qemu-proxy.c +8
-0+ +static PCIProxyDev *get_proxy_object_rid (const char *rid) +{ +PCIProxyDev *entry; +if (!proxy_list_lock.initialized) { +QLIST_INIT (&proxy_dev_list.devices); +qemu_mutex_init (&proxy_list_lock); + }
This locking approach is broken since exactly-once initialization semantics are required to avoid races during initialization. Is the lock needed at all?
Quoted 66 lines
hw/proxy/qemu-proxy.c +66
-0+DeviceState *qdev_remote_add (QemuOpts *opts,bool device,Error **errp) +{ +PCIProxyDev *pdev =NULL ; +DeviceState *dev; +const char *rid, *rsocket =NULL , *command =NULL ; +QDict *qdict_new; +const char *id =NULL ; +const char *driver =NULL ; +const char *bus =NULL ; + +if (!proxy_list_lock.initialized) { +QLIST_INIT (&proxy_dev_list.devices); +qemu_mutex_init (&proxy_list_lock); + } + + rid =qemu_opt_get (opts,"rid" ); +if (!rid) { +error_setg (errp,"rdevice option needs rid specified." ); +return NULL ; + } +if (device) { + driver =qemu_opt_get (opts,"driver" ); +/* TODO: properly identify the device class. */ +if (strncmp (driver,"lsi" ,3 ) ==0 ) { + id =qemu_opts_id (opts); +if (!id) { +error_setg (errp,"qdev_remote_add option needs id specified." ); +return NULL ; + } + } + } + + rsocket =qemu_opt_get (opts,"socket" ); +if (rsocket) { +if (strlen (rsocket) >MAX_RID_LENGTH ) { +error_setg (errp,"Socket number is incorrect." ); +return NULL ; + } + } +/* +* TODO: verify command with known commands and on remote end. +* How else can we verify the binary we launch without libvirtd support? +*/ + command =qemu_opt_get (opts,"command" ); +if (!rsocket && !command) { +error_setg (errp,"rdevice option needs socket or command specified." ); +return NULL ; + } + + bus =qemu_opt_get (opts,"bus" ); + dev =qdev_proxy_add (rid, id, (char *)bus, (char *)command, + rsocket ?atoi (rsocket) :-1 , + rsocket ? true : false, errp); +if (!dev) { +error_setg (errp,"qdev_proxy_add error." ); +return NULL ; + } + + qdict_new =qemu_opts_to_qdict (opts,NULL ); + +if (!qdict_new) { +error_setg (errp,"Could not parse rdevice options." ); +return NULL ; + } + + pdev =PCI_PROXY_DEV (dev);
hw/proxy/qemu-proxy.c
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+if (!pdev->set_remote_opts) { +/* TODO: destroy proxy? */ +error_setg (errp,"set_remote_opts failed." ); +return NULL ; + }else { +if (id && !pdev->dev_id) { + pdev->dev_id =g_strdup (id); + } + pdev->set_remote_opts (PCI_DEVICE (pdev), qdict_new, + device ?DEV_OPTS :DRIVE_OPTS );
This function needs to be able to return an error if setting the options failed. A response message needs to be defined in the protocol to support this.
Is DRIVE_OPTS still needed? I thought the drives would be configured in the remote process and no proxy objects were needed on the QEMU side?
RFC PATCH v4 21/49 multi-process: remote: add setup_devices and setup_drive msg processing
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Receive by remote side the configuration messages and build the device object from JSON device descriptions.
---
v1 -> v2:
- for new command line suboptions with libvirtd support, clean the options before creating drives/devices
- use default pci bus/address for now
include/hw/qdev-core.h | 2 + qdev-monitor.c | 2 +- remote/remote-main.c | 231 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 1 deletion(-)
include/hw/qdev-core.h +2 -0
@@ -357,6 +357,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);DeviceState *qdev_find_recursive (BusState *bus,const char *id); +DeviceState *find_device_state (const char *id,Error **errp); +/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn )(BusState *bus,void *opaque);typedef int (qdev_walkerfn )(DeviceState *dev,void *opaque);
qdev-monitor.c +1 -1
@@ -1025,7 +1025,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)object_unref (OBJECT (dev)); } -static DeviceState *find_device_state (const char *id,Error **errp) +DeviceState *find_device_state (const char *id,Error **errp) {Object *obj;
remote/remote-main.c +231 -0
254 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 22/49 multi-process: remote: use fd for socket from parent process
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
--- remote/remote-main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
remote/remote-main.c +9 -1
@@ -64,6 +64,7 @@#include "block/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/log.h" +#include "qemu/cutils.h" static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev;
@@ -440,6 +441,7 @@ finalize_loop:int main (int argc,char *argv[]) {Error *err =NULL ; +int fd =-1 ;module_call_init (MODULE_INIT_QOM );
@@ -462,7 +464,13 @@ int main(int argc, char *argv[])return -1 ; } -mpqemu_init_channel (mpqemu_link, &mpqemu_link->com,STDIN_FILENO ); + fd =qemu_parse_fd (argv[1 ]); +if (fd ==-1 ) { +printf ("Failed to parse fd for remote process.\n" ); +return -EINVAL ; + } + +mpqemu_init_channel (mpqemu_link, &mpqemu_link->com, fd);mpqemu_link_set_callback (mpqemu_link, process_msg);mpqemu_start_coms (mpqemu_link);
Signature · 1 line
1.8.3.1
RFC PATCH v4 23/49 multi-process: remote: add create_done condition
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Do not allow BAR,MMIO handlers and irq setup to run before the configuration of the devices completes.
--- remote/remote-main.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
remote/remote-main.c +20 -9
@@ -68,6 +68,7 @@static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev; +bool create_done;static void process_config_write (MPQemuMsg *msg) {
@@ -370,21 +371,31 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)case INIT :break ;case CONF_WRITE : -process_config_write (msg); +if (create_done) { +process_config_write (msg); + } +break ;case CONF_READ : -process_config_read (msg); +if (create_done) { +process_config_read (msg); + } +break ;case BAR_WRITE : -process_bar_write (msg, &err); -if (err) { - goto finalize_loop; +if (create_done) { +process_bar_write (msg, &err); +if (err) { +error_report_err (err); + } }break ;case BAR_READ : -process_bar_read (msg, &err); -if (err) { - goto finalize_loop; +if (create_done) { +process_bar_read (msg, &err); +if (err) { +error_report_err (err); + } }break ;case SYNC_SYSMEM :
@@ -404,7 +415,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)qemu_mutex_lock_iothread ();qemu_run_machine_init_done_notifiers ();qemu_mutex_unlock_iothread (); - + create_done = true;break ;case DRIVE_OPTS :if (setup_drive (msg, &err)) {
Signature · 1 line
1.8.3.1
RFC PATCH v4 24/49 multi-process: add processing of remote drive and device command line
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Add processing of command line options drive and device. After remote devices are created along with their proxies, signal the proxies to finish the configuration steps.
---
v1 -> v2:
- change command line option for remote process drive/device to use existing -drive/-device options
- process drive and device options only after non-remote devices and drives are added
vl.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+)
vl.c +78 -0
@@ -35,6 +35,11 @@#include "sysemu/runstate.h" #include "sysemu/seccomp.h" #include "sysemu/tcg.h" +#include "qapi/qmp/qdict.h" +#include "block/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qlist.h" #ifdef CONFIG_SDL #if defined(__APPLE__) || defined(main)
@@ -1136,11 +1141,45 @@ static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)#define MTD_OPTS ""#define SD_OPTS "" +#if defined(CONFIG_MPQEMU ) +static int rdrive_init_func (void *opaque,QemuOpts *opts,Error **errp) +{ +DeviceState *dev; + + dev =qdev_remote_add (opts, false/* this is drive */ , errp); +if (!dev) { +error_setg (errp,"qdev_remote_add failed for drive." ); +return -1 ; + } +object_unref (OBJECT (dev)); +return 0 ; +} +#endif + +#if defined(CONFIG_MPQEMU ) +static int pass; +#endif +static int drive_init_func (void *opaque,QemuOpts *opts,Error **errp) {BlockInterfaceType *block_default_type = opaque; +#if defined(CONFIG_MPQEMU ) +const char *remote; + + remote =qemu_opt_get (opts,"remote" ); +if (pass && remote) { +return rdrive_init_func (opaque, opts, errp); + }else { +if (!remote && !pass) { +drive_new (opts, *block_default_type, errp); + } + } + +return 0 ; +#else return drive_new (opts, *block_default_type, errp) ==NULL ; +#endif }static int drive_enable_snapshot (void *opaque,QemuOpts *opts,Error **errp)
@@ -2199,10 +2238,35 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)return qdev_device_help (opts); } +#if defined(CONFIG_MPQEMU ) +static int rdevice_init_func (void *opaque,QemuOpts *opts,Error **errp) +{ +DeviceState *dev; + + dev =qdev_remote_add (opts, true/* this is device */ , errp); +if (!dev) { +error_setg (errp,"qdev_remote_add failed for device." ); +return -1 ; + } +object_unref (OBJECT (dev)); +return 0 ; +} +#endif +static int device_init_func (void *opaque,QemuOpts *opts,Error **errp) {DeviceState *dev; +#if defined(CONFIG_MPQEMU ) +const char *remote; + + remote =qemu_opt_get (opts,"remote" ); +if (remote) { +/* This will be a remote process */ +return rdevice_init_func (opaque, opts, errp); + } +#endif + dev =qdev_device_add (opts, errp);if (!dev) {return -1 ;
@@ -4348,6 +4412,17 @@ int main(int argc, char **argv, char **envp)/* Check if IGD GFX passthrough. */ igd_gfx_passthru (); +#if defined(CONFIG_MPQEMU ) +/* +* Parse the list for remote drives here as we launch PCIProxyDev here and +* need PCI host initialized. As a TODO: could defer init of PCIProxyDev instead. +*/ +if (qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, + &machine_class->block_default_type, &error_fatal)) { +exit (0 ); + } +#endif +/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); qemu_opts_foreach(qemu_find_opts("device"),
@@ -4405,6 +4480,9 @@ int main(int argc, char **argv, char **envp)qemu_register_reset (qbus_reset_all_fn,sysbus_get_default ());qemu_run_machine_init_done_notifiers (); +#if defined(CONFIG_MPQEMU ) +qdev_proxy_fire (); +#endif if (rom_check_and_register_reset () !=0 ) {error_report ("rom check and register reset failed" );exit (1 );
Signature · 1 line
1.8.3.1
RFC PATCH v4 25/49 multi-process: Introduce build flags to separate remote process code
In reply to Jagannathan RamanIntroduce SCSI_PROCESS & REMOTE_PROCESS build flags to separate code that applies only to remote processes.
---
New patch in v3
Makefile.target | 4 ++++ rules.mak | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
Makefile.target +4 -0
@@ -255,6 +255,10 @@ ifdef CONFIG_DARWIN $(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@") endif +ifdef CONFIG_MPQEMU +$(SCSI_DEV_BUILD): REMOTE_FLAGS = -DREMOTE_PROCESS -DSCSI_PROCESS +endif + $(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS) $(call LINK, $(filter-out %.mak, $^)) ifdef CONFIG_DARWIN
rules.mak +1 -1
@@ -67,7 +67,7 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \ %.o: %.c $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ - $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ + $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) $(REMOTE_FLAGS) \ -c -o $@ $<,"CC","$(TARGET_DIR)$@") %.o: %.rc $(call quiet-command,$(WINDRES) -I. -o $@ $<,"RC","$(TARGET_DIR)$@")
Signature · 1 line
1.8.3.1
RFC PATCH v4 26/49 multi-process: refractor vl.c code to re-use in remote
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
---
New patch in v3
Makefile.objs | 2 + remote/Makefile.objs | 1 + vl-parse.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 152 +------------------------------------------------ vl.h | 54 ++++++++++++++++++ 5 files changed, 216 insertions(+), 151 deletions(-) create mode 100644 vl-parse.c create mode 100644 vl.h
Makefile.objs +2 -0
@@ -104,6 +104,8 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS) common-obj-$(CONFIG_FDT) += device_tree.o +common-obj-y += vl-parse.o + ###################################################################### # qapi
remote/Makefile.objs +1 -0
@@ -2,3 +2,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o +remote-pci-obj-$(CONFIG_MPQEMU) +=../vl-parse.o
vl-parse.c new file +158 -0
158 lines not on this page · raw message
vl.c +1 -151
188 lines not on this page · raw message
vl.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 27/49 multi-process: add remote option
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
---
New patch in v3
qemu-options.hx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
qemu-options.hx +21 -0
@@ -27,6 +27,27 @@ STEXI Display version information and exit ETEXI +DEF("remote", HAS_ARG, QEMU_OPTION_remote, + "-remote socket[,prop[=value][,...]]\n" + " add remote process\n" + " prop=value,... sets driver properties\n" + " use '-remote help' to print all possible properties\n", + QEMU_ARCH_ALL) +STEXI +@table @option +@item rid +@findex -rid +remote id +@item socket +@findex -socket +Remote process socket +@item command +@findex -command +Remote process command. + +@end table +ETEXI + DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ "-machine [type=]name[,prop[=value][,...]]\n" " selects emulated machine ('-machine help' for list)\n"
Signature · 1 line
1.8.3.1
RFC PATCH v4 28/49 multi-process: add remote options parser
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
---
New patch in v3
vl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+)
vl.c +117 -0
@@ -280,6 +280,28 @@ static QemuOptsList qemu_option_rom_opts = { }, }; +static QemuOptsList qemu_remote_opts = { + .name ="remote" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_remote_opts.head), + .desc = { + { + .name ="rid" , + .type =QEMU_OPT_NUMBER , + .help ="id of the remote process" + },{ + .name ="socket" , + .type =QEMU_OPT_NUMBER , + .help ="Socket for remote" , + },{ + .name ="command" , + .type =QEMU_OPT_STRING , + .help ="command to run" , + }, + {/* end of list */ } + }, +}; + +static QemuOptsList qemu_machine_opts = { .name ="machine" , .implied_opt_name ="type" ,
@@ -347,6 +369,87 @@ static QemuOptsList qemu_boot_opts = { }, }; +#if defined(CONFIG_MPQEMU ) +static int device_remote_add (void *opaque,QemuOpts *opts,Error **errp) +{ +unsigned int rid = *(unsigned int *)opaque; +const char *opt_rid =NULL ; +struct remote_process *p =NULL ;; + + opt_rid =qemu_opt_get (opts,"rid" ); +if (!opt_rid) { +return 0 ; + } + + p =get_remote_process_rid (rid); +if (!p) { +return -EINVAL ; + } + +if (atoi (opt_rid) == rid) { +qemu_opt_set (opts,"command" , p->command, errp); +rdevice_init_func (opaque, opts, errp); +qemu_opts_del (opts); + } +return 0 ; +} + +static int parse_remote (void *opaque,QemuOpts *opts,Error **errp) +{ +int rid; +int socket; +char *c_sock; +const char *command =NULL ; +struct remote_process r_proc; + + rid =atoi (qemu_opt_get (opts,"rid" )); +if (rid <0 ) { +error_setg (errp,"rid is required." ); +return -1 ; + } +if (get_remote_process_rid (rid)) { +error_setg (errp,"There is already process with rid %d" , rid); + goto cont_devices; + } + + c_sock = (char *)qemu_opt_get (opts,"socket" ); +if (c_sock) { + socket =atoi (c_sock); + }else { + socket =-1 ; + } + + command =qemu_opt_get (opts,"command" ); + +if (socket <=STDERR_FILENO && socket !=-1 ) { + socket =-1 ; + } + +if (!command && socket <0 ) { +error_setg (errp,"No correct socket or command defined for remote." ); +return -1 ; + } + +if (rid <0 ) { +error_setg (errp,"id option is required and must be non-negative" ); +return -1 ; + } + r_proc.rid = rid; + r_proc.socket = socket; + r_proc.command =g_strdup (command); +remote_process_register (&r_proc); + + cont_devices: +if (qemu_opts_foreach (qemu_find_opts ("device" ), device_remote_add, + &rid,NULL )) { +error_setg (errp,"Could not process some of the remote devices." ); + } + +return 0 ; +} + +#endif +static QemuOptsList qemu_add_fd_opts = { .name ="add-fd" , .head =QTAILQ_HEAD_INITIALIZER (qemu_add_fd_opts.head),
@@ -2826,6 +2929,7 @@ int main(int argc, char **argv, char **envp)qemu_add_opts (&qemu_icount_opts);qemu_add_opts (&qemu_semihosting_config_opts);qemu_add_opts (&qemu_fw_cfg_opts); +qemu_add_opts (&qemu_remote_opts);module_call_init (MODULE_INIT_OPTS );runstate_init ();
@@ -3678,6 +3782,14 @@ int main(int argc, char **argv, char **envp)exit (1 );#endif break ; +case QEMU_OPTION_remote: + opts =qemu_opts_parse_noisily (qemu_find_opts ("remote" ), + optarg, false); +if (!opts) { +exit (1 ); + } +break ; +case QEMU_OPTION_object: opts =qemu_opts_parse_noisily (qemu_find_opts ("object" ), optarg, true);
@@ -4278,6 +4390,11 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func,NULL , &error_fatal); +#ifdef CONFIG_MPQEMU +qemu_opts_foreach (qemu_find_opts ("remote" ), + parse_remote,NULL , &error_fatal); +#endif +cpu_synchronize_all_post_init ();rom_reset_order_override ();
Signature · 1 line
1.8.3.1
RFC PATCH v4 29/49 multi-process: add parse_cmdline in remote process
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
---
New patch in v3
remote/Makefile.objs | 1 + remote/remote-main.c | 11 +++++ remote/remote-opts.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ remote/remote-opts.h | 31 ++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 remote/remote-opts.c create mode 100644 remote/remote-opts.h
remote/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o +remote-pci-obj-$(CONFIG_MPQEMU) += remote-opts.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o
remote/remote-main.c +11 -0
@@ -65,6 +65,7 @@#include "qapi/qmp/qlist.h" #include "qemu/log.h" #include "qemu/cutils.h" +#include "remote-opts.h" static MPQemuLinkState *mpqemu_link;PCIDevice *remote_pci_dev;
@@ -469,6 +470,13 @@ int main(int argc, char *argv[]) current_machine =MACHINE (REMOTE_MACHINE (object_new (TYPE_REMOTE_MACHINE ))); +qemu_add_opts (&qemu_device_opts); +qemu_add_opts (&qemu_drive_opts); +qemu_add_drive_opts (&qemu_legacy_drive_opts); +qemu_add_drive_opts (&qemu_common_drive_opts); +qemu_add_drive_opts (&qemu_drive_opts); +qemu_add_drive_opts (&bdrv_runtime_opts); + mpqemu_link =mpqemu_link_create ();if (!mpqemu_link) {printf ("Could not create MPQemu link\n" );
@@ -482,6 +490,9 @@ int main(int argc, char *argv[]) }mpqemu_init_channel (mpqemu_link, &mpqemu_link->com, fd); + +parse_cmdline (argc -2 , argv +2 ,NULL ); +mpqemu_link_set_callback (mpqemu_link, process_msg);mpqemu_start_coms (mpqemu_link);
remote/remote-opts.c new file +115 -0
115 lines not on this page · raw message
remote/remote-opts.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Remote device initialization +* +* Copyright 2019, Oracle and/or its affiliates. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef REMOTE_OPTS_H +#define REMOTE_OPTS_H + +void parse_cmdline (int argc,char **argv,char **envp); + +#endif +
Signature · 1 line
1.8.3.1
RFC PATCH v4 30/49 multi-process: send heartbeat messages to remote
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
In order to detect remote processes which are hung, the proxy periodically sends heartbeat messages to confirm if the remote process is alive
--- hw/proxy/qemu-proxy.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 2 files changed, 102 insertions(+)
hw/proxy/qemu-proxy.c +101 -0
@@ -53,14 +53,96 @@#include "hw/boards.h" #include "include/qemu/log.h" +QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);static void setup_irqfd (PCIProxyDev *dev); +static void pci_dev_exit (PCIDevice *dev); +static void start_heartbeat_timer (void ); +static void stop_heartbeat_timer (void ); +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx); +static void broadcast_msg (MPQemuMsg *msg,bool need_reply); + +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) +{ +/* TODO: Add proper handler. */ +printf ("Child (pid %d) is dead? Signal is %d, Exit code is %d.\n" , + siginfo->si_pid, siginfo->si_signo, siginfo->si_code); +} + +static void broadcast_msg (MPQemuMsg *msg,bool need_reply) +{ +PCIProxyDev *entry; +unsigned int pid; +int wait; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { +if (need_reply) { + wait =eventfd (0 ,EFD_NONBLOCK ); + msg->num_fds =1 ; + msg->fds[0 ] = wait; + } + +mpqemu_msg_send (entry->mpqemu_link, msg, entry->mpqemu_link->com); +if (need_reply) { + pid = (uint32_t )wait_for_remote (wait); +close (wait); +/* TODO: Add proper handling. */ +if (pid) { + need_reply =0 ; + } + } + } +} + +#define NOP_INTERVAL 1000000 + +static void remote_ping (void *opaque) +{ +MPQemuMsg msg; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.num_fds =0 ; + msg.cmd =PROXY_PING ; + msg.bytestream =0 ; + msg.size =0 ; + +broadcast_msg (&msg, true); +timer_mod (hb_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +NOP_INTERVAL ); + +} + +void start_heartbeat_timer (void ) +{ + hb_timer =timer_new_ms (QEMU_CLOCK_VIRTUAL , + remote_ping, + &proxy_dev_list); +timer_mod (hb_timer,qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ) +NOP_INTERVAL ); + +} + +static void stop_heartbeat_timer (void ) +{ +timer_del (hb_timer); +timer_free (hb_timer); +} + +static void set_sigchld_handler (void ) +{ +struct sigaction sa_sigterm; +memset (&sa_sigterm,0 ,sizeof (sa_sigterm)); + sa_sigterm.sa_sigaction = childsig_handler; + sa_sigterm.sa_flags =SA_SIGINFO |SA_NOCLDWAIT |SA_NOCLDSTOP ; +sigaction (SIGCHLD , &sa_sigterm,NULL ); +}static void proxy_ready (PCIDevice *dev) {PCIProxyDev *pdev =PCI_PROXY_DEV (dev);setup_irqfd (pdev); +set_sigchld_handler (); +start_heartbeat_timer (); }static void set_remote_opts (PCIDevice *dev,QDict *qdict,unsigned int cmd)
@@ -259,6 +341,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data)PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); k->realize = pci_proxy_dev_realize; + k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; }
@@ -397,6 +480,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->proxy_ready = proxy_ready; } +static void pci_dev_exit (PCIDevice *pdev) +{ +PCIProxyDev *entry, *sentry; +PCIProxyDev *dev =PCI_PROXY_DEV (pdev); + +stop_heartbeat_timer (); + + QLIST_FOREACH_SAFE(entry, &proxy_dev_list.devices, next, sentry) { +if (entry->remote_pid == dev->remote_pid) { +QLIST_REMOVE (entry, next); + } + } + +if (!QLIST_EMPTY (&proxy_dev_list.devices)) { +start_heartbeat_timer (); + } +} +static void send_bar_access_msg (PCIProxyDev *dev,MemoryRegion *mr,bool write,hwaddr addr,uint64_t *val,unsigned size,bool memory)
include/io/mpqemu-link.h +1 -0
@@ -72,6 +72,7 @@ typedef enum {DRIVE_OPTS ,DEVICE_ADD ,DEVICE_DEL , +PROXY_PING ,MAX , } mpqemu_cmd_t;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote
Quoted 6 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +6
-0+static void broadcast_msg (MPQemuMsg *msg,bool need_reply) +{ +PCIProxyDev *entry; +unsigned int pid; +int wait; +
hw/proxy/qemu-proxy.c line 87
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { +if (need_reply) { + wait =eventfd (0 ,EFD_NONBLOCK ); + msg->num_fds =1 ; + msg->fds[0 ] = wait; + } + +mpqemu_msg_send (entry->mpqemu_link, msg, entry->mpqemu_link->com); +if (need_reply) { + pid = (uint32_t )wait_for_remote (wait);
Sometimes QEMU really needs to wait for the remote process before it can make progress. I think this is not one of those cases though.
Since QEMU is event-driven it's problematic to invoke blocking system calls. The remote process might not respond for a significant amount of time. Other QEMU threads will be held up waiting for the QEMU global mutex in the meantime (because we hold it!).
Please implement heartbeat/ping asynchronously. The wait eventfd should be read by an event loop fd handler instead. That way QEMU can continue with running the VM while waiting for the remote process.
This will also improve guest performance because there will be less jitter (random latency because the event loop is held up waiting for remote processes for short periods of time).
Re: [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote
Quoted 21 lines · Stefan Hajnoczi
Quoted 6 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +6
-0+static void broadcast_msg (MPQemuMsg *msg,bool need_reply) +{ +PCIProxyDev *entry; +unsigned int pid; +int wait; +hw/proxy/qemu-proxy.c line 87
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { +if (need_reply) { + wait =eventfd (0 ,EFD_NONBLOCK ); + msg->num_fds =1 ; + msg->fds[0 ] = wait; + } + +mpqemu_msg_send (entry->mpqemu_link, msg, entry->mpqemu_link->com); +if (need_reply) { + pid = (uint32_t )wait_for_remote (wait);Sometimes QEMU really needs to wait for the remote process before it can make progress. I think this is not one of those cases though.
Quoted 4 lines
Since QEMU is event-driven it's problematic to invoke blocking system calls. The remote process might not respond for a significant amount of time. Other QEMU threads will be held up waiting for the QEMU global mutex in the meantime (because we hold it!).
There are places where we wait synchronously for the remote process. However, these synchronous waits carry a timeout to prevent the hang situation you described above.
We will add an error recovery in the future. That is, we will respawn the remote process if the QEMU times out waiting for it.
Quoted 4 lines
Please implement heartbeat/ping asynchronously. The wait eventfd should be read by an event loop fd handler instead. That way QEMU can continue with running the VM while waiting for the remote process.
In the current implementation, the heartbeat/ping is asynchronous. start_heartbeat_timer() sets up a timer to perform the ping.
Thanks!
--
Jag
Quoted 5 lines
This will also improve guest performance because there will be less jitter (random latency because the event loop is held up waiting for remote processes for short periods of time).
Re: [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote
Quoted 29 lines · Jag Raman
Quoted 21 lines · Stefan Hajnoczi
Quoted 6 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +6
-0+static void broadcast_msg (MPQemuMsg *msg,bool need_reply) +{ +PCIProxyDev *entry; +unsigned int pid; +int wait; +hw/proxy/qemu-proxy.c line 87
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { +if (need_reply) { + wait =eventfd (0 ,EFD_NONBLOCK ); + msg->num_fds =1 ; + msg->fds[0 ] = wait; + } + +mpqemu_msg_send (entry->mpqemu_link, msg, entry->mpqemu_link->com); +if (need_reply) { + pid = (uint32_t )wait_for_remote (wait);Sometimes QEMU really needs to wait for the remote process before it can make progress. I think this is not one of those cases though.
Quoted 4 lines
Since QEMU is event-driven it's problematic to invoke blocking system calls. The remote process might not respond for a significant amount of time. Other QEMU threads will be held up waiting for the QEMU global mutex in the meantime (because we hold it!).
Quoted 6 lines
There are places where we wait synchronously for the remote process. However, these synchronous waits carry a timeout to prevent the hang situation you described above.
We will add an error recovery in the future. That is, we will respawn the remote process if the QEMU times out waiting for it.
Even with a timeout, in the meantime the event loop is blocked. That means timers will be delayed by a large amount, the monitor will be unresponsive, etc.
Quoted 7 lines
Quoted 4 lines
Please implement heartbeat/ping asynchronously. The wait eventfd should be read by an event loop fd handler instead. That way QEMU can continue with running the VM while waiting for the remote process.
In the current implementation, the heartbeat/ping is asynchronous.
start_heartbeat_timer()sets up a timer to perform the ping.
The heartbeat/ping is synchronous because broadcast_msg() blocks.
Stefan
RFC PATCH v4 31/49 multi-process: handle heartbeat messages in remote process
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
If the remote process is alive, it responds to proxy's heartbeat messages
--- remote/remote-main.c | 6 ++++++ 1 file changed, 6 insertions(+)
remote/remote-main.c +6 -0
@@ -355,6 +355,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) {MPQemuMsg *msg =NULL ;Error *err =NULL ; +int wait;if ((cond &G_IO_HUP ) || (cond &G_IO_ERR )) {error_setg (&err,"socket closed, cond is %d" , cond);
@@ -434,6 +435,11 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)case DEVICE_DEL :process_device_del_msg (msg);break ; +case PROXY_PING : + wait = msg->fds[0 ]; +notify_proxy (wait, (uint32_t )getpid ()); +PUT_REMOTE_WAIT (wait); +break ;default :error_setg (&err,"Unknown command" ); goto finalize_loop;
Signature · 1 line
1.8.3.1
RFC PATCH v4 32/49 multi-process: Use separate MMIO communication channel
In reply to Jagannathan RamanUsing a separate communication channel for MMIO helps with improving Performance
---
New patch in v3
hw/proxy/qemu-proxy.c | 39 +++++++++++++++++++++++++++------------ include/hw/proxy/qemu-proxy.h | 1 + include/io/mpqemu-link.h | 7 +++++++ io/mpqemu-link.c | 2 ++ qdev-monitor.c | 1 + remote/remote-main.c | 18 +++++++++++++----- 6 files changed, 51 insertions(+), 17 deletions(-)
hw/proxy/qemu-proxy.c +27 -12
@@ -201,20 +201,22 @@ static int make_argv(char *command_str, char **argv, int argc)int remote_spawn (PCIProxyDev *pdev,const char *command,Error **errp) {pid_t rpid; -int fd[2 ] = {-1 ,-1 }; +int fd[2 ], mmio[2 ];Error *local_error =NULL ;char *argv[64 ];int argc =0 , _argc;char *sfd;char *exec_dir;int rc = -EINVAL ; +struct timeval timeout = {.tv_sec =10 , .tv_usec =0 };if (pdev->managed) {/* Child is forked by external program (such as libvirt). */ return rc; } -if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd) || +socketpair (AF_UNIX ,SOCK_STREAM ,0 , mmio)) {error_setg (errp,"Unable to create unix socket." );return rc; }
@@ -222,6 +224,8 @@ int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) argc =add_argv (exec_dir, argv, argc); sfd =g_strdup_printf ("%d" , fd[1 ]); argc =add_argv (sfd, argv, argc); + sfd =g_strdup_printf ("%d" , mmio[1 ]); + argc =add_argv (sfd, argv, argc); _argc = argc; argc =make_argv ((char *)command, argv, argc);
@@ -231,22 +235,32 @@ int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp)if (rpid ==-1 ) {error_setg (errp,"Unable to spawn emulation program." );close (fd[0 ]); +close (mmio[0 ]); goto fail; }if (rpid ==0 ) {close (fd[0 ]); +close (mmio[0 ]);execvp (argv[0 ], (char *const *)argv);exit (1 ); } pdev->remote_pid = rpid; pdev->rsocket = fd[1 ]; pdev->socket = fd[0 ]; + pdev->mmio_sock = mmio[0 ]; + +if (setsockopt (mmio[0 ],SOL_SOCKET ,SO_RCVTIMEO , (char *)&timeout, +sizeof (timeout)) <0 ) { +error_setg (errp,"Unable to set timeout for socket" ); + goto fail; + } rc =0 ; fail:close (fd[1 ]); +close (mmio[1 ]);for (int i =0 ; i < _argc; i++) {g_free (argv[i]);
@@ -443,6 +457,9 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **empqemu_init_channel (pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); +mpqemu_init_channel (pdev->mpqemu_link, &pdev->mpqemu_link->mmio, + pdev->mmio_sock); +configure_memory_sync (pdev->sync, pdev->mpqemu_link); }
@@ -503,8 +520,7 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, unsigned size, bool memory) {MPQemuLinkState *mpqemu_link = dev->mpqemu_link; -MPQemuMsg msg; -int wait; +MPQemuMsg msg, ret;memset (&msg,0 ,sizeof (MPQemuMsg));
@@ -518,19 +534,18 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, msg.cmd =BAR_WRITE ; msg.data1.bar_access.val = *val; }else { - wait =GET_REMOTE_WAIT ; - msg.cmd =BAR_READ ; - msg.num_fds =1 ; - msg.fds[0 ] = wait; } -mpqemu_msg_send (mpqemu_link, &msg, mpqemu_link->com); +mpqemu_msg_send (mpqemu_link, &msg, mpqemu_link->mmio); -if (!write) { - *val =wait_for_remote (wait); -PUT_REMOTE_WAIT (wait); +if (write) { +return ; } + +mpqemu_msg_recv (mpqemu_link, &ret, mpqemu_link->mmio); + + *val = ret.data1.mmio_ret.val; } void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,
include/hw/proxy/qemu-proxy.h +1 -0
@@ -71,6 +71,7 @@ struct PCIProxyDev {pid_t remote_pid;int rsocket;int socket; +int mmio_sock;char *rid;
include/io/mpqemu-link.h +7 -0
@@ -73,6 +73,7 @@ typedef enum {DEVICE_ADD ,DEVICE_DEL ,PROXY_PING , +MMIO_RETURN ,MAX , } mpqemu_cmd_t;
@@ -107,6 +108,10 @@ typedef struct { } set_irqfd_msg_t;typedef struct { +uint64_t val; +}mmio_ret_msg_t ; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size;
@@ -116,6 +121,7 @@ typedef struct {sync_sysmem_msg_t sync_sysmem;bar_access_msg_t bar_access;set_irqfd_msg_t set_irqfd; +mmio_ret_msg_t mmio_ret; } data1;int fds[REMOTE_MAX_FDS ];
@@ -170,6 +176,7 @@ typedef struct MPQemuLinkState {GMainLoop *loop;MPQemuChannel *com; +MPQemuChannel *mmio;mpqemu_link_callback callback; } MPQemuLinkState;
io/mpqemu-link.c +2 -0
@@ -77,6 +77,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s)g_main_loop_quit (s->loop);mpqemu_destroy_channel (s->com); +mpqemu_destroy_channel (s->mmio);object_unref (OBJECT (s)); }
@@ -344,6 +345,7 @@ void mpqemu_start_coms(MPQemuLinkState *s) {g_assert (g_source_attach (&s->com->gsrc, s->ctx)); +g_assert (g_source_attach (&s->mmio->gsrc, s->ctx));g_main_loop_run (s->loop); }
qdev-monitor.c +1 -0
@@ -711,6 +711,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,if (old_pdev) { pdev->rsocket = old_pdev->rsocket; pdev->socket = old_pdev->socket; + pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; }else { pdev->rsocket = managed ? rsocket :-1 ;
remote/remote-main.c +13 -5
@@ -117,8 +117,8 @@ static void process_bar_write(MPQemuMsg *msg, Error **errp)static void process_bar_read (MPQemuMsg *msg,Error **errp) {bar_access_msg_t *bar_access = &msg->data1.bar_access; +MPQemuMsg ret = {0 };AddressSpace *as; -int wait = msg->fds[0 ];MemTxResult res;uint64_t val =0 ;
@@ -152,9 +152,10 @@ static void process_bar_read(MPQemuMsg *msg, Error **errp) } fail: -notify_proxy (wait, val); - -PUT_REMOTE_WAIT (wait); + ret.cmd =MMIO_RETURN ; + ret.data1.mmio_ret.val = val; + ret.size =sizeof (ret.data1); +mpqemu_msg_send (mpqemu_link, &ret, mpqemu_link->mmio); }static void process_device_add_msg (MPQemuMsg *msg)
@@ -497,7 +498,14 @@ int main(int argc, char *argv[])mpqemu_init_channel (mpqemu_link, &mpqemu_link->com, fd); -parse_cmdline (argc -2 , argv +2 ,NULL ); + fd =qemu_parse_fd (argv[2 ]); +if (fd ==-1 ) { +printf ("Failed to parse fd for remote process.\n" ); +return -EINVAL ; + } +mpqemu_init_channel (mpqemu_link, &mpqemu_link->mmio, fd); + +parse_cmdline (argc -3 , argv +3 ,NULL );mpqemu_link_set_callback (mpqemu_link, process_msg);
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel
Quoted 2 lines · Jagannathan Raman
Using a separate communication channel for MMIO helps with improving Performance
Why?
Re: [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman
Using a separate communication channel for MMIO helps with improving Performance
Why?
Typical initiation of IO operations involves multiple MMIO accesses per IO operation. In some legacy devices like LSI, the completion of the IO operations is also accomplished by polling on MMIO registers. Therefore, MMIO traffic can be hefty in some cases and contribute to Performance.
Having a dedicated channel for MMIO ensures that it doesn't have to compete with other messages to the remote process, especially when there are multiple devices emulated by a single remote process.
Thanks!
--
Jag
Quoted 1 line
Re: [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel
Quoted 7 lines · Jag Raman
Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines · Jagannathan Raman
Using a separate communication channel for MMIO helps with improving Performance
Why?
Quoted 8 lines
Typical initiation of IO operations involves multiple MMIO accesses per IO operation. In some legacy devices like LSI, the completion of the IO operations is also accomplished by polling on MMIO registers. Therefore, MMIO traffic can be hefty in some cases and contribute to Performance.
Having a dedicated channel for MMIO ensures that it doesn't have to compete with other messages to the remote process, especially when there are multiple devices emulated by a single remote process.
A vCPU doing a polling read on an MMIO register will cause a BAR_READ message to be sent to the remote process. The vCPU thread waits for the response to this message.
When there are multiple remote devices each has its own socket, so communication with different remote processes does not interfere.
The only scenarios I can think of are:
1. Interference within a single device between vCPUs and/or the QEMU monitor.
2. A single process serving multiple devices that is implemented in a way such that different devices interfere with each other.
It sounds like you are saying the problem is #2, but this is still unclear to me. If the remote process can be implemented in a way such that there is no interference when each device has a special MMIO socket, then why can't it be implemented in a way such that there is no interference when each device's main socket is used (each device has it's own!).
Maybe I've missed the point. It would be good if you could explain in more detail.
Stefan
RFC PATCH v4 33/49 multi-process: perform device reset in the remote process
In reply to Jagannathan RamanPerform 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
---
New patch in v3
hw/proxy/proxy-lsi53c895a.c | 6 ++++++ hw/proxy/qemu-proxy.c | 14 ++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 1 + remote/remote-main.c | 11 +++++++++++ 5 files changed, 34 insertions(+)
hw/proxy/proxy-lsi53c895a.c +6 -0
@@ -57,6 +57,11 @@ static void proxy_lsi_realize(PCIProxyDev *dev, Error **errp) &dev->region[2], "proxy-lsi-ram", 0x2000); } +static void proxy_lsi_reset (DeviceState *dev) +{ +proxy_device_reset (dev); +} +static void proxy_lsi_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -74,6 +79,7 @@ static void proxy_lsi_class_init(ObjectClass *klass, void *data)set_bit (DEVICE_CATEGORY_STORAGE , dc->categories); dc->desc ="LSI Proxy Device" ; + dc->reset = proxy_lsi_reset; }static const TypeInfo lsi_proxy_dev_type_info = {
hw/proxy/qemu-proxy.c +14 -0
@@ -577,3 +577,17 @@ const MemoryRegionOps proxy_default_ops = { .max_access_size = 1, }, }; + +void proxy_device_reset (DeviceState *dev) +{ +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); +MPQemuMsg msg; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.cmd =DEVICE_RESET ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); +}
include/hw/proxy/qemu-proxy.h +2 -0
@@ -112,4 +112,6 @@ void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val,uint64_t proxy_default_bar_read (void *opaque,hwaddr addr,unsigned size); +void proxy_device_reset (DeviceState *dev); +#endif /* QEMU_PROXY_H */
include/io/mpqemu-link.h +1 -0
@@ -74,6 +74,7 @@ typedef enum {DEVICE_DEL ,PROXY_PING ,MMIO_RETURN , +DEVICE_RESET ,MAX , } mpqemu_cmd_t;
remote/remote-main.c +11 -0
@@ -66,8 +66,11 @@#include "qemu/log.h" #include "qemu/cutils.h" #include "remote-opts.h" +#include "monitor/monitor.h" +#include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link; +PCIDevice *remote_pci_dev;bool create_done;
@@ -237,6 +240,11 @@ fail:PUT_REMOTE_WAIT (wait); } +static void process_device_reset_msg (MPQemuMsg *msg) +{ +qemu_devices_reset (); +} +static int init_drive (QDict *rqdict,Error **errp) {QemuOpts *opts;
@@ -441,6 +449,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)notify_proxy (wait, (uint32_t )getpid ());PUT_REMOTE_WAIT (wait);break ; +case DEVICE_RESET : +process_device_reset_msg (msg); +break ;default :error_setg (&err,"Unknown command" ); goto finalize_loop;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 33/49] multi-process: perform device reset in the remote process
hw/proxy/qemu-proxy.c const MemoryRegionOps proxy_default_ops = { · line 593
Quoted 13 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +13
-0+void proxy_device_reset (DeviceState *dev) +{ +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); +MPQemuMsg msg; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.cmd =DEVICE_RESET ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); +}
Device reset must wait for the remote process to finish reset, otherwise the remote device could still be running after proxy_device_reset() returns from sending the message.
Stefan
Re: [RFC v4 PATCH 33/49] multi-process: perform device reset in the remote process
Quoted 10 lines · Stefan Hajnoczi
Quoted 9 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +9
-0+void proxy_device_reset (DeviceState *dev) +{ +PCIProxyDev *pdev =PCI_PROXY_DEV (dev); +MPQemuMsg msg; + +memset (&msg,0 ,sizeof (MPQemuMsg)); + + msg.bytestream =0 ; + msg.size =sizeof (msg.data1);
Quoted 8 lines
hw/proxy/qemu-proxy.c const MemoryRegionOps proxy_default_ops = { · line 593
Quoted 4 lines
hw/proxy/qemu-proxy.c +4
-0+ msg.cmd =DEVICE_RESET ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); +}Device reset must wait for the remote process to finish reset, otherwise the remote device could still be running after
proxy_device_reset()returns from sending the message.
Thanks for feedback. We will wait for the reset to complete.
--
Jag
Quoted 3 lines
Stefan
RFC PATCH v4 34/49 multi-process/mon: choose HMP commands based on target
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Add "targets" field to HMP command definition to select the targets which would be supported by each command
---
New patch in v4
hmp-commands-info.hx | 10 ++++++++++ hmp-commands.hx | 20 ++++++++++++++++++++ scripts/hxtool | 44 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/hxtool
hmp-commands-info.hx +10 -0
@@ -19,6 +19,7 @@ ETEXI .params = "", .help = "show the version of QEMU", .cmd = hmp_info_version, + .targets = "scsi", .flags = "p", },
@@ -48,6 +49,7 @@ ETEXI .params = "", .help = "show the character devices", .cmd = hmp_info_chardev, + .targets = "scsi", .flags = "p", },
@@ -64,6 +66,7 @@ ETEXI .help = "show info of one block device or all block devices " "(-n: show named nodes; -v: show details)", .cmd = hmp_info_block, + .targets = "scsi", }, STEXI
@@ -78,6 +81,7 @@ ETEXI .params = "", .help = "show block device statistics", .cmd = hmp_info_blockstats, + .targets = "scsi", }, STEXI
@@ -92,6 +96,7 @@ ETEXI .params = "", .help = "show progress of ongoing block device operations", .cmd = hmp_info_block_jobs, + .targets = "scsi", }, STEXI
@@ -167,6 +172,7 @@ ETEXI .params = "", .help = "show the command line history", .cmd = hmp_info_history, + .targets = "scsi", .flags = "p", },
@@ -224,6 +230,7 @@ ETEXI .params = "", .help = "show PCI info", .cmd = hmp_info_pci, + .targets = "scsi", }, STEXI
@@ -630,6 +637,7 @@ ETEXI .params = "", .help = "show device tree", .cmd = hmp_info_qtree, + .targets = "scsi", }, STEXI
@@ -644,6 +652,7 @@ ETEXI .params = "", .help = "show qdev device model list", .cmd = hmp_info_qdm, + .targets = "scsi", }, STEXI
@@ -658,6 +667,7 @@ ETEXI .params = "[path]", .help = "show QOM composition tree", .cmd = hmp_info_qom_tree, + .targets = "scsi", .flags = "p", },
hmp-commands.hx +20 -0
@@ -49,6 +49,7 @@ ETEXI .params = "", .help = "quit the emulator", .cmd = hmp_quit, + .targets = "scsi", }, STEXI
@@ -82,6 +83,7 @@ ETEXI .params = "device size", .help = "resize a block image", .cmd = hmp_block_resize, + .targets = "scsi", }, STEXI
@@ -99,6 +101,7 @@ ETEXI .params = "device [speed [base]]", .help = "copy data from a backing file into a block device", .cmd = hmp_block_stream, + .targets = "scsi", }, STEXI
@@ -113,6 +116,7 @@ ETEXI .params = "device speed", .help = "set maximum speed for a background block operation", .cmd = hmp_block_job_set_speed, + .targets = "scsi", }, STEXI
@@ -129,6 +133,7 @@ ETEXI "\n\t\t\t if you want to abort the operation immediately" "\n\t\t\t instead of keep running until data is in sync)", .cmd = hmp_block_job_cancel, + .targets = "scsi", }, STEXI
@@ -143,6 +148,7 @@ ETEXI .params = "device", .help = "stop an active background block operation", .cmd = hmp_block_job_complete, + .targets = "scsi", }, STEXI
@@ -158,6 +164,7 @@ ETEXI .params = "device", .help = "pause an active background block operation", .cmd = hmp_block_job_pause, + .targets = "scsi", }, STEXI
@@ -172,6 +179,7 @@ ETEXI .params = "device", .help = "resume a paused background block operation", .cmd = hmp_block_job_resume, + .targets = "scsi", }, STEXI
@@ -186,6 +194,7 @@ ETEXI .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", .cmd = hmp_eject, + .targets = "scsi", }, STEXI
@@ -200,6 +209,7 @@ ETEXI .params = "device", .help = "remove host block device", .cmd = hmp_drive_del, + .targets = "scsi", }, STEXI
@@ -219,6 +229,7 @@ ETEXI .params = "device filename [format [read-only-mode]]", .help = "change a removable medium, optional format", .cmd = hmp_change, + .targets = "scsi", }, STEXI
@@ -732,6 +743,7 @@ ETEXI .help = "add device, like -device on the command line", .cmd = hmp_device_add, .command_completion = device_add_completion, + .targets = "scsi", }, STEXI
@@ -747,6 +759,7 @@ ETEXI .help = "remove device", .cmd = hmp_device_del, .command_completion = device_del_completion, + .targets = "scsi", }, STEXI
@@ -1351,6 +1364,7 @@ ETEXI "The -c flag requests QEMU to compress backup data\n\t\t\t" "(if the target format supports it).\n\t\t\t", .cmd = hmp_drive_backup, + .targets = "scsi", }, STEXI @item drive_backup
@@ -1368,6 +1382,7 @@ ETEXI "[,readonly=on|off][,copy-on-read=on|off]", .help = "add drive to PCI storage controller", .cmd = hmp_drive_add, + .targets = "scsi", }, STEXI
@@ -1816,6 +1831,7 @@ ETEXI .help = "add chardev", .cmd = hmp_chardev_add, .command_completion = chardev_add_completion, + .targets = "scsi", }, STEXI
@@ -1831,6 +1847,7 @@ ETEXI .params = "id args", .help = "change chardev", .cmd = hmp_chardev_change, + .targets = "scsi", }, STEXI
@@ -1848,6 +1865,7 @@ ETEXI .help = "remove chardev", .cmd = hmp_chardev_remove, .command_completion = chardev_remove_completion, + .targets = "scsi", }, STEXI
@@ -1864,6 +1882,7 @@ ETEXI .help = "send a break on chardev", .cmd = hmp_chardev_send_break, .command_completion = chardev_remove_completion, + .targets = "scsi", }, STEXI
@@ -1938,6 +1957,7 @@ ETEXI .params = "[subcommand]", .help = "show various information about the system state", .cmd = hmp_info_help, + .targets = "scsi", .sub_table = hmp_info_cmds, .flags = "p", },
scripts/hxtool +42 -2
65 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 35/49 multi-process/mon: stub functions to enable QMP module for remote process
In reply to Jagannathan RamanQMP module doesn't need some functions to run independently on the remote processes. However, these functions are necessary for compilation. Therefore, these functions are stub'ed out. The stub functions raise an assert if QEMU is built in debug mode (--enable-debug).
---
New patch in v3
accel/stubs/tcg-stub.c | 10 +++ configure | 4 ++ include/qemu-common.h | 8 +++ stubs/gdbstub.c | 21 +++++++ stubs/migration.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/monitor.c | 31 ++++++++++ stubs/net-stub.c | 69 +++++++++++++++++++++ stubs/qapi-misc.c | 41 +++++++++++++ stubs/qapi-target.c | 49 +++++++++++++++ stubs/ui-stub.c | 130 +++++++++++++++++++++++++++++++++++++++ stubs/vl-stub.c | 92 ++++++++++++++++++++++++++++ 11 files changed, 617 insertions(+) create mode 100644 stubs/migration.c create mode 100644 stubs/qapi-misc.c create mode 100644 stubs/qapi-target.c create mode 100644 stubs/ui-stub.c
accel/stubs/tcg-stub.c +10 -0
@@ -119,3 +119,13 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end)void page_collection_unlock (struct page_collection *set) { } + +void dump_exec_info (void ) +{ +qemu_debug_assert (0 ); +} + +void dump_opcount_info (void ) +{ +qemu_debug_assert (0 ); +}
configure +4 -0
@@ -7252,6 +7252,10 @@ if test "$mpqemu" = "yes" ; then echo "CONFIG_MPQEMU=y" >> $config_host_mak fi +if test "$debug" = "yes" ; then + echo "CONFIG_DEBUG=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi
include/qemu-common.h +8 -0
@@ -10,6 +10,8 @@#ifndef QEMU_COMMON_H #define QEMU_COMMON_H +#include <assert.h> +#define TFR (expr) do { if ((expr) != -1) break; } while (errno == EINTR)/* Copyright string for -version arguments, About dialogs, etc */
@@ -129,4 +131,10 @@ void page_size_init(void);* returned. */ bool dump_in_progress (void ); +#ifdef CONFIG_DEBUG +#define qemu_debug_assert (x) assert(x) +#else +#define qemu_debug_assert (x) +#endif +#endif
stubs/gdbstub.c +21 -0
@@ -1,6 +1,27 @@#include "qemu/osdep.h" +#include "qemu-common.h" #include "exec/gdbstub.h" /* xml_builtin */ const char *const xml_builtin[][2 ] = { {NULL ,NULL } }; + +#ifdef CONFIG_USER_ONLY + +int gdbserver_start (int port) +{ +qemu_debug_assert (0 ); + +return -ENOSYS ; +} + +#else + +int gdbserver_start (const char *device) +{ +qemu_debug_assert (0 ); + +return -ENOSYS ; +} + +#endif
stubs/migration.c new file +162 -0
162 lines not on this page · raw message
stubs/monitor.c +31 -0
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu-common.h" #include "qapi/error.h" #include "qapi/qapi-emit-events.h" #include "monitor/monitor.h"
@@ -10,6 +11,24 @@#include "sysemu/sysemu.h" #include "sysemu/runstate.h" #include "monitor/hmp.h" +#include "monitor/qdev.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" + +#include "qapi/qapi-types-block-core.h" +#include "qapi/qapi-commands-block-core.h" + +#pragma weak cur_mon +#pragma weak monitor_vprintf +#pragma weak monitor_get_fd +#pragma weak monitor_init +#pragma weak qapi_event_emit +#pragma weak monitor_get_cpu_index +#pragma weak monitor_printf +#pragma weak monitor_cur_is_qmp +#pragma weak qmp_device_list_properties +#pragma weak monitor_init_qmp +#pragma weak monitor_init_hmp __threadMonitor *cur_mon;
@@ -17,11 +36,13 @@ __thread Monitor *cur_mon;int monitor_vprintf (Monitor *mon,const char *fmt,va_list ap) { +qemu_debug_assert (0 );abort (); }int monitor_get_fd (Monitor *mon,const char *name,Error **errp) { +qemu_debug_assert (0 );error_setg (errp,"only QEMU supports file descriptor passing" );return -1 ; }
@@ -32,29 +53,39 @@ void monitor_init_qmp(Chardev *chr, bool pretty)void monitor_init_hmp (Chardev *chr,bool use_readline) { +qemu_debug_assert (0 ); }void qapi_event_emit (QAPIEvent event,QDict *qdict) { +qemu_debug_assert (0 ); }int monitor_get_cpu_index (void ) { +qemu_debug_assert (0 ); +return -ENOSYS ; }int monitor_printf (Monitor *mon,const char *fmt, ...) { +qemu_debug_assert (0 ); +return -ENOSYS ; }bool monitor_cur_is_qmp (void ) { +qemu_debug_assert (0 ); +return false; }ObjectPropertyInfoList *qmp_device_list_properties (const char *typename,Error **errp) { +qemu_debug_assert (0 ); +return NULL ; }
stubs/net-stub.c +69 -0
78 lines not on this page · raw message
stubs/qapi-misc.c new file +41 -0
41 lines not on this page · raw message
stubs/qapi-target.c new file +49 -0
49 lines not on this page · raw message
stubs/ui-stub.c new file +130 -0
130 lines not on this page · raw message
stubs/vl-stub.c +92 -0
113 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 36/49 multi-process/mon: enable QMP module support in the remote process
In reply to Jagannathan RamanBuild system changes to enable QMP module in the remote process
---
New patch in v3
Makefile.objs | 9 +++++ Makefile.target | 34 +++++++++++++++++-- hmp-commands.hx | 5 +-- hw/core/Makefile.objs | 1 + monitor/Makefile.objs | 3 ++ monitor/misc.c | 84 +++++++++++++++++++++++++--------------------- monitor/monitor-internal.h | 38 +++++++++++++++++++++ qapi/Makefile.objs | 2 ++ qom/Makefile.objs | 1 + ui/Makefile.objs | 2 ++ 10 files changed, 137 insertions(+), 42 deletions(-)
Makefile.objs +9 -0
@@ -30,6 +30,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += backends/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += migration/ remote-pci-obj-$(CONFIG_MPQEMU) += remote/ +remote-pci-obj-$(CONFIG_MPQEMU) += monitor/ remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o
@@ -42,6 +43,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o # remote-lsi-obj-y is code used to implement remote LSI device remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ +remote-lsi-obj-$(CONFIG_MPQEMU) += ui/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o ####################################################################### # crypto-obj-y is code used by both qemu system emulation and qemu-img
@@ -112,6 +116,11 @@ common-obj-y += vl-parse.o common-obj-y += qapi/ endif +remote-pci-obj-$(CONFIG_MPQEMU) += qapi/ +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o +remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o + ####################################################################### # Target-independent parts used in system and user emulation common-obj-y += cpus-common.o
Makefile.target +32 -2
@@ -132,13 +132,31 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o -remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o + +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o ######################################################### # Linux user emulator target
@@ -191,6 +209,10 @@ endif generated-files-y += hmp-commands.h hmp-commands-info.h generated-files-y += config-devices.h +ifdef CONFIG_MPQEMU +generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h +endif + endif # CONFIG_SOFTMMU dummy := $(call unnest-vars,,obj-y)
@@ -275,10 +297,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@") +ifdef CONFIG_MPQEMU +hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) + +hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) +endif + clean: clean-target rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') - rm -f hmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp
hmp-commands.hx +3 -2
@@ -14,7 +14,8 @@ ETEXI .args_type = "name:S?", .params = "[cmd]", .help = "show the help", - .cmd = do_help_cmd, + .cmd = hmp_do_help_cmd, + .targets = "scsi", .flags = "p", },
@@ -618,7 +619,7 @@ ETEXI .args_type = "fmt:/,val:l", .params = "/fmt expr", .help = "print expression value (use $reg for CPU register access)", - .cmd = do_print, + .cmd = hmp_do_print, }, STEXI
hw/core/Makefile.objs +1 -0
@@ -44,3 +44,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o remote-pci-obj-$(CONFIG_MPQEMU) += numa.o remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o
monitor/Makefile.objs +3 -0
@@ -1,3 +1,6 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o common-obj-y += qmp-cmds.o hmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o hmp-cmds.o
monitor/misc.c +46 -38
322 lines not on this page · raw message
monitor/monitor-internal.h +38 -0
@@ -179,4 +179,42 @@ void help_cmd(Monitor *mon, const char *name);void handle_hmp_command (MonitorHMP *mon,const char *cmdline);int hmp_compare_cmd (const char *name,const char *list); +void hmp_do_help_cmd (Monitor *mon,const QDict *qdict); +void hmp_trace_event (Monitor *mon,const QDict *qdict); +void hmp_info_help (Monitor *mon,const QDict *qdict); +void hmp_info_registers (Monitor *mon,const QDict *qdict); +void hmp_info_jit (Monitor *mon,const QDict *qdict); +void hmp_info_opcount (Monitor *mon,const QDict *qdict); +void hmp_info_sync_profile (Monitor *mon,const QDict *qdict); +void hmp_info_history (Monitor *mon,const QDict *qdict); +void hmp_info_cpustats (Monitor *mon,const QDict *qdict); +void hmp_info_trace_events (Monitor *mon,const QDict *qdict); +void hmp_logfile (Monitor *mon,const QDict *qdict); +void hmp_log (Monitor *mon,const QDict *qdict); +void hmp_singlestep (Monitor *mon,const QDict *qdict); +void hmp_gdbserver (Monitor *mon,const QDict *qdict); +void hmp_watchdog_action (Monitor *mon,const QDict *qdict); +void hmp_memory_dump (Monitor *mon,const QDict *qdict); +void hmp_physical_memory_dump (Monitor *mon,const QDict *qdict); +void hmp_gpa2hva (Monitor *mon,const QDict *qdict); +void hmp_gva2gpa (Monitor *mon,const QDict *qdict); +void hmp_gpa2hpa (Monitor *mon,const QDict *qdict); +void hmp_do_print (Monitor *mon,const QDict *qdict); +void hmp_sum (Monitor *mon,const QDict *qdict); +void hmp_mouse_move (Monitor *mon,const QDict *qdict); +void hmp_mouse_button (Monitor *mon,const QDict *qdict); +void hmp_ioport_read (Monitor *mon,const QDict *qdict); +void hmp_ioport_write (Monitor *mon,const QDict *qdict); +void hmp_boot_set (Monitor *mon,const QDict *qdict); +void hmp_info_mtree (Monitor *mon,const QDict *qdict); +void hmp_info_profile (Monitor *mon,const QDict *qdict); +void hmp_info_capture (Monitor *mon,const QDict *qdict); +void hmp_stopcapture (Monitor *mon,const QDict *qdict); +void hmp_wavcapture (Monitor *mon,const QDict *qdict); +void hmp_acl_show (Monitor *mon,const QDict *qdict); +void hmp_acl_reset (Monitor *mon,const QDict *qdict); +void hmp_acl_policy (Monitor *mon,const QDict *qdict); +void hmp_acl_add (Monitor *mon,const QDict *qdict); +void hmp_acl_remove (Monitor *mon,const QDict *qdict); +#endif
qapi/Makefile.objs +2 -0
@@ -30,3 +30,5 @@ obj-y += $(QAPI_TARGET_MODULES:%=qapi-events-%.o) obj-y += qapi-events.o obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o) obj-y += qapi-commands.o + +remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o)
qom/Makefile.objs +1 -0
@@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o +remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o
ui/Makefile.objs +2 -0
@@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS) egl-helpers.o-libs += $(OPENGL_LIBS) egl-context.o-libs += $(OPENGL_LIBS) egl-headless.o-libs += $(OPENGL_LIBS) + +remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o
Signature · 1 line
1.8.3.1
RFC PATCH v4 37/49 multi-process/mon: Refactor monitor/chardev functions out of vl.c
In reply to Jagannathan RamanSome of the initialization helper functions w.r.t monitor & chardev in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use.
---
New patch in v3
v3 -> v4
- Moved monitor related functions to monitor.c and chardev functions to char.c
chardev/char.c | 14 ++++++++ include/chardev/char.h | 1 + include/monitor/monitor.h | 2 ++ monitor/monitor.c | 83 +++++++++++++++++++++++++++++++++++++++++- remote/remote-main.c | 1 + remote/remote-opts.c | 1 + vl-parse.c | 35 +++++++++--------- vl.c | 91 ----------------------------------------------- 8 files changed, 119 insertions(+), 109 deletions(-)
chardev/char.c +14 -0
@@ -1168,4 +1168,18 @@ static void register_types(void)qemu_add_machine_init_done_notifier (&chardev_machine_done_notify); } +int chardev_init_func (void *opaque,QemuOpts *opts,Error **errp) +{ +Error *local_err =NULL ; + +if (!qemu_chr_new_from_opts (opts,NULL , &local_err)) { +if (local_err) { +error_propagate (errp, local_err); +return -1 ; + } +exit (0 ); + } +return 0 ; +} +type_init (register_types);
include/chardev/char.h +1 -0
@@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,/* console.c */ void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp); +int chardev_init_func (void *opaque,QemuOpts *opts,Error **errp);#endif
include/monitor/monitor.h +2 -0
@@ -42,5 +42,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags);int monitor_fdset_dup_fd_add (int64_t fdset_id,int dup_fd);void monitor_fdset_dup_fd_remove (int dup_fd);int64_t monitor_fdset_dup_fd_find (int dup_fd); +void monitor_parse (const char *optarg,const char *mode,bool pretty); +int mon_init_func (void *opaque,QemuOpts *opts,Error **errp);#endif /* MONITOR_H */
monitor/monitor.c +82 -1
95 lines not on this page · raw message
remote/remote-main.c +1 -0
@@ -67,6 +67,7 @@#include "qemu/cutils.h" #include "remote-opts.h" #include "monitor/monitor.h" +#include "chardev/char.h" #include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link;
remote/remote-opts.c +1 -0
@@ -55,6 +55,7 @@#include "block/block.h" #include "remote/remote-opts.h" #include "include/qemu-common.h" +#include "monitor/monitor.h" #include "vl.h" /*
vl-parse.c +18 -17
@@ -110,49 +110,50 @@ int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -#if defined(CONFIG_MPQEMU ) -int rdrive_init_func (void *opaque,QemuOpts *opts,Error **errp) +int device_init_func (void *opaque,QemuOpts *opts,Error **errp) {DeviceState *dev; +const char *remote =NULL ; - dev =qdev_remote_add (opts, false/* this is drive */ , errp); + remote =qemu_opt_get (opts,"rid" ); +if (remote) { +return 0 ; + } + + dev =qdev_device_add (opts, errp);if (!dev) { -error_setg (errp,"qdev_remote_add failed for drive." );return -1 ; }object_unref (OBJECT (dev));return 0 ; } -#endif #if defined(CONFIG_MPQEMU ) -int rdevice_init_func (void *opaque,QemuOpts *opts,Error **errp) +int rdrive_init_func (void *opaque,QemuOpts *opts,Error **errp) {DeviceState *dev; - dev =qdev_remote_add (opts, true/* this is device */ , errp); + dev =qdev_remote_add (opts, false/* this is drive */ , errp);if (!dev) { -error_setg (errp,"qdev_remote_add failed for device." ); +error_setg (errp,"qdev_remote_add failed for drive." );return -1 ; } +object_unref (OBJECT (dev));return 0 ; }#endif -int device_init_func (void *opaque,QemuOpts *opts,Error **errp) +#if defined(CONFIG_MPQEMU ) +int rdevice_init_func (void *opaque,QemuOpts *opts,Error **errp) {DeviceState *dev; -const char *remote =NULL ; - remote =qemu_opt_get (opts,"rid" ); -if (remote) { -return 0 ; - } - - dev =qdev_device_add (opts, errp); + dev =qdev_remote_add (opts, true/* this is device */ , errp);if (!dev) { +error_setg (errp,"qdev_remote_add failed for device." );return -1 ; } -object_unref (OBJECT (dev));return 0 ; } +#endif +
vl.c +0 -91
103 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 38/49 multi-process/mon: Initialize QMP module for remote processes
In reply to Jagannathan Raman---
New patch in v3
remote/remote-main.c | 11 +++++++++++ remote/remote-opts.c | 10 ++++++++++ 2 files changed, 21 insertions(+)
remote/remote-main.c +11 -0
@@ -69,6 +69,7 @@#include "monitor/monitor.h" #include "chardev/char.h" #include "sysemu/reset.h" +#include "vl.h" static MPQemuLinkState *mpqemu_link;
@@ -476,6 +477,8 @@ int main(int argc, char *argv[])module_call_init (MODULE_INIT_QOM ); +monitor_init_globals (); +bdrv_init_with_whitelist ();if (qemu_init_main_loop (&err)) {
@@ -491,6 +494,8 @@ int main(int argc, char *argv[])qemu_add_opts (&qemu_device_opts);qemu_add_opts (&qemu_drive_opts); +qemu_add_opts (&qemu_chardev_opts); +qemu_add_opts (&qemu_mon_opts);qemu_add_drive_opts (&qemu_legacy_drive_opts);qemu_add_drive_opts (&qemu_common_drive_opts);qemu_add_drive_opts (&qemu_drive_opts);
@@ -521,6 +526,12 @@ int main(int argc, char *argv[])mpqemu_link_set_callback (mpqemu_link, process_msg); +qemu_opts_foreach (qemu_find_opts ("chardev" ), + chardev_init_func,NULL , &error_fatal); + +qemu_opts_foreach (qemu_find_opts ("mon" ), + mon_init_func,NULL , &error_fatal); +mpqemu_start_coms (mpqemu_link);return 0 ;
remote/remote-opts.c +10 -0
@@ -98,6 +98,16 @@ void parse_cmdline(int argc, char **argv, char **envp)exit (1 ); }break ; +case QEMU_OPTION_qmp: +monitor_parse (optarg,"control" , false); +break ; +case QEMU_OPTION_monitor: +if (!strncmp (optarg,"stdio" ,5 )) { +warn_report ("STDIO not supported in remote process" ); + }else if (strncmp (optarg,"none" ,4 )) { +monitor_parse (optarg,"readline" , false); + } +break ;default :break ; }
Signature · 1 line
1.8.3.1
RFC PATCH v4 39/49 multi-process: prevent duplicate memory initialization in remote
In reply to Jagannathan RamanWhen multiple controllers are configured in a remote process, it's better for the memory to be managed by only one of the proxy objects for that process, in order to conserve file descriptors. Added "mem_int" flag for this purpose.
---
New patch in v3
hw/proxy/qemu-proxy.c | 13 ++++++++++++- include/hw/proxy/qemu-proxy.h | 1 + qdev-monitor.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-)
hw/proxy/qemu-proxy.c +12 -1
@@ -350,6 +350,13 @@ static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val,config_op_send (PCI_PROXY_DEV (d), addr, &val, l,CONF_WRITE ); } +static void pci_proxy_dev_inst_init (Object *obj) +{ +PCIProxyDev *dev =PCI_PROXY_DEV (obj); + + dev->mem_init = false; +} +static void pci_proxy_dev_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass);
@@ -364,6 +371,7 @@ static const TypeInfo pci_proxy_dev_type_info = { .name = TYPE_PCI_PROXY_DEV, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIProxyDev), + .instance_init = pci_proxy_dev_inst_init, .abstract = true, .class_size = sizeof(PCIProxyDevClass), .class_init = pci_proxy_dev_class_init,
@@ -460,7 +468,10 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **empqemu_init_channel (pdev->mpqemu_link, &pdev->mpqemu_link->mmio, pdev->mmio_sock); -configure_memory_sync (pdev->sync, pdev->mpqemu_link); +if (!pdev->mem_init) { + pdev->mem_init = true; +configure_memory_sync (pdev->sync, pdev->mpqemu_link); + } }static void pci_proxy_dev_realize (PCIDevice *device,Error **errp)
include/hw/proxy/qemu-proxy.h +1 -0
@@ -63,6 +63,7 @@ struct PCIProxyDev {MPQemuLinkState *mpqemu_link;RemoteMemSync *sync; +bool mem_init;struct kvm_irqfd irqfd;EventNotifier intr;
qdev-monitor.c +1 -1
@@ -713,10 +713,10 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->socket = old_pdev->socket; pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; + pdev->mem_init = true; }else { pdev->rsocket = managed ? rsocket :-1 ; pdev->socket = managed ? rsocket :-1 ; - } pdev->managed = managed;
Signature · 1 line
1.8.3.1
RFC PATCH v4 40/49 multi-process/mig: build migration module in the remote process
In reply to Jagannathan RamanAdd Makefile support to enable migration in remote process
---
New patch in v4
Makefile.objs | 4 ++++ Makefile.target | 1 + migration/Makefile.objs | 12 +++++++++++- net/Makefile.objs | 2 ++ replay/Makefile.objs | 2 +- stubs/migration.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/net-stub.c | 21 +++++++++++++++++++++ stubs/qapi-misc.c | 2 ++ stubs/replay.c | 8 ++++++++ stubs/vl-stub.c | 22 ++++++++++++++++++++++ vl-parse.c | 3 +++ vl.c | 2 -- 12 files changed, 124 insertions(+), 4 deletions(-)
Makefile.objs +4 -0
@@ -79,6 +79,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o common-obj-$(CONFIG_WIN32) += os-win32.o common-obj-$(CONFIG_POSIX) += os-posix.o +remote-pci-obj-$(CONFIG_POSIX) += os-posix.o + common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration/
@@ -110,6 +112,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o common-obj-y += vl-parse.o +remote-pci-obj-$(CONFIG_MPQEMU) += net/ + ###################################################################### # qapi
Makefile.target +1 -0
@@ -225,6 +225,7 @@ all-remote-pci-obj-y += memory.o all-remote-pci-obj-y += exec.o all-remote-pci-obj-y += ioport.o all-remote-pci-obj-y += cpus.o +all-remote-pci-obj-y += migration/ram.o remote-pci-obj-y := remote-lsi-obj-y :=
migration/Makefile.objs +11 -1
@@ -14,4 +14,14 @@ common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o rdma.o-libs := $(RDMA_LIBS) -remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o +remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o +remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o +remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o +remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o +remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o +remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o +remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o +remote-pci-obj-$(CONFIG_RDMA) += rdma.o +remote-pci-obj-$(CONFIG_MPQEMU) += block.o
net/Makefile.objs +2 -0
@@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/ + +remote-pci-obj-$(CONFIG_MPQEMU) += announce.o
replay/Makefile.objs +1 -1
@@ -6,4 +6,4 @@ common-obj-y += replay-input.o common-obj-y += replay-char.o common-obj-y += replay-snapshot.o common-obj-y += replay-net.o -common-obj-y += replay-audio.o +common-obj-y += replay-audio.o
stubs/migration.c +49 -0
58 lines not on this page · raw message
stubs/net-stub.c +21 -0
@@ -5,6 +5,8 @@#include "qapi/qapi-commands-net.h" #include "qapi/qapi-commands-rocker.h" +#pragma weak qmp_announce_self +int qemu_find_net_clients_except (const char *id,NetClientState **ncs,NetClientDriver type,int max) {
@@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp) {qemu_debug_assert (0 ); } + +NetClientState *qemu_get_queue (NICState *nic) +{ +qemu_debug_assert (0 ); + +return NULL ; +} + +ssize_t qemu_send_packet_raw (NetClientState *nc,const uint8_t *buf,int size) +{ +qemu_debug_assert (0 ); + +return 0 ; +} + +void qemu_foreach_nic (qemu_nic_foreach func,void *opaque) +{ +qemu_debug_assert (0 ); +}
stubs/qapi-misc.c +2 -0
@@ -5,6 +5,8 @@#include "./qapi/qapi-types-dump.h" #include "qapi/qapi-commands-dump.h" +#pragma weak qmp_xen_load_devices_state + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length,
stubs/replay.c +8 -0
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu-common.h" #include "sysemu/replay.h" ReplayMode replay_mode;
@@ -97,3 +98,10 @@ void replay_account_executed_instructions(void)void replay_add_blocker (Error *reason) { } + +bool replay_can_snapshot (void ) +{ +qemu_debug_assert (0 ); + +return false; +}
stubs/vl-stub.c +22 -0
@@ -169,3 +169,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,return -1 ; } + +void qemu_system_killed (int signal,pid_t pid) +{ +qemu_debug_assert (0 ); +} + +void qemu_system_reset (ShutdownCause reason) +{ +qemu_debug_assert (0 ); +} + +bool runstate_store (char *str,size_t size) +{ +qemu_debug_assert (0 ); + +return false; +} + +void qemu_add_exit_notifier (Notifier *notify) +{ +qemu_debug_assert (0 ); +}
vl-parse.c +3 -0
@@ -41,6 +41,9 @@#include "vl.h" +int only_migratable;/* turn it off unless user states otherwise */ +bool enable_mlock; +/***********************************************************/ /* QEMU Block devices */
vl.c +0 -2
@@ -148,7 +148,6 @@ const char* keyboard_layout = NULL;ram_addr_t ram_size;const char *mem_path =NULL ;int mem_prealloc =0 ;/* force preallocation of physical target memory */ -bool enable_mlock = false;bool enable_cpu_pm = false;int nb_nics;NICInfo nd_table[MAX_NICS ];
@@ -189,7 +188,6 @@ const char *prom_envs[MAX_PROM_ENVS];int boot_menu;bool boot_strict;uint8_t *boot_splash_filedata; -int only_migratable;/* turn it off unless user states otherwise */ bool wakeup_suspend_enabled;int icount_align_option;
Signature · 1 line
1.8.3.1
RFC PATCH v4 41/49 multi-process/mig: Enable VMSD save in the Proxy object
In reply to Jagannathan RamanCollect the VMSD from remote process on the source and save it to the channel leading to the destination
---
New patch in v4
hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)
hw/proxy/qemu-proxy.c +132 -0
@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);
@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */
@@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque) +{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem); + mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX ); + +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread); + +qemu_fclose (f_remote); +close (fd[1 ]); + +return 0 ; +} + +static int proxy_post_save (void *opaque) +{ +MigrationState *ms =migrate_get_current (); +PCIProxyDev *pdev = opaque; +uint64_t pos =0 ; + +while (pos < pdev->migsize) { +qemu_put_byte (ms->to_dst_file, mig_data[pos]); + pos++; + } + +qemu_fflush (ms->to_dst_file); + +return 0 ; +} + +const VMStateDescription vmstate_pci_proxy_device = { + .name ="PCIProxyDevice" , + .version_id =2 , + .minimum_version_id =1 , + .pre_save = proxy_pre_save, + .post_save = proxy_post_save, + .fields = (VMStateField []) { +VMSTATE_PCI_DEVICE (parent_dev, PCIProxyDev), +VMSTATE_UINT64 (migsize, PCIProxyDev), +VMSTATE_END_OF_LIST () + } +}; +static void pci_proxy_dev_class_init (ObjectClass *klass,void *data) {PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); k->realize = pci_proxy_dev_realize; k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; + + dc->vmsd = &vmstate_pci_proxy_device; }static const TypeInfo pci_proxy_dev_type_info = {
include/hw/proxy/qemu-proxy.h +2 -0
@@ -89,6 +89,8 @@ struct PCIProxyDev {void (*init_proxy) (PCIDevice *dev,char *command,bool need_spawn,Error **errp);ProxyMemoryRegion region[PCI_NUM_REGIONS ]; + +uint64_t migsize; }; typedef struct PCIProxyDevClass {
include/io/mpqemu-link.h +1 -0
@@ -75,6 +75,7 @@ typedef enum {PROXY_PING ,MMIO_RETURN ,DEVICE_RESET , +START_MIG_OUT ,MAX , } mpqemu_cmd_t;
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object
Quoted 53 lines · Jagannathan Raman
Collect the VMSD from remote process on the source and save it to the channel leading to the destination
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>---
New patch in v4hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)hw/proxy/qemu-proxy.c +17
-0@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque)
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 386
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem);
There is a pretty large set of APIs hiding behind the qemu_get_byte call, which does not give me confidence that...
Quoted 56 lines
hw/proxy/qemu-proxy.c +56
-0+ mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX );
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 452
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread);
....this is a safe way to stop the thread executing without resulting in memory being leaked.
In addition thread cancellation is asynchronous, so the thread may still be using the QEMUFile object while....
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 454
Quoted 1 line
hw/proxy/qemu-proxy.c +1
-0+qemu_fclose (f_remote);
..this is closing it. This feels like it is a crash danger.
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 458
Quoted 4 lines
hw/proxy/qemu-proxy.c +4
-0+close (fd[1 ]); + +return 0 ; +}
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object
Quoted 138 lines · Daniel P. Berrangé
Quoted 53 lines · Jagannathan Raman
Collect the VMSD from remote process on the source and save it to the channel leading to the destination
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>---
New patch in v4hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)hw/proxy/qemu-proxy.c +17
-0@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque)hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 386
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem);There is a pretty large set of APIs hiding behind the
qemu_get_bytecall, which does not give me confidence that...Quoted 56 lines
hw/proxy/qemu-proxy.c +56
-0+ mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX );hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 452
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread);....this is a safe way to stop the thread executing without resulting in memory being leaked.
Quoted 4 lines
In addition thread cancellation is asynchronous, so the thread may still be using the QEMUFile object while....
Quoted 1 line
hw/proxy/qemu-proxy.c +1
-0+qemu_fclose (f_remote);
The above "wait_for_remote()" call waits for the remote process to finish with Migration, and return the size of the VMSD.
It should be safe to cancel the thread and close the file, once the remote process is done sending the VMSD and we have read "size" bytes from it, is it not?
Thank you very much!
--
Jag
Quoted 12 lines
..this is closing it. This feels like it is a crash danger.
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 458
Quoted 4 lines
hw/proxy/qemu-proxy.c +4
-0+close (fd[1 ]); + +return 0 ; +}Regards,
Daniel
Re: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object
Quoted 141 lines · Jag Raman
Quoted 138 lines · Daniel P. Berrangé
Quoted 50 lines · Jagannathan Raman
Collect the VMSD from remote process on the source and save it to the channel leading to the destination
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>---
New patch in v4hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)hw/proxy/qemu-proxy.c +17
-0@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque)hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 385
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem);There is a pretty large set of APIs hiding behind the
qemu_get_bytecall, which does not give me confidence that...Quoted 56 lines
hw/proxy/qemu-proxy.c +56
-0+ mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX );hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 452
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread);....this is a safe way to stop the thread executing without resulting in memory being leaked.
In addition thread cancellation is asynchronous, so the thread may still be using the QEMUFile object while....
Quoted 8 lines
Quoted 1 line
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 454
Quoted 1 line
hw/proxy/qemu-proxy.c +1
-0+qemu_fclose (f_remote);The above "
wait_for_remote()" call waits for the remote process to finish with Migration, and return the size of the VMSD.It should be safe to cancel the thread and close the file, once the remote process is done sending the VMSD and we have read "size" bytes from it, is it not?
Ok, so the thread is doing
while (true) {
byte = qemu_get_byte(data->rem);
...do something with byte...
}so when the thread is cancelled it is almost certainly in the qemu_get_byte() call. Since you say wait_for_remote() syncs with the end of migration, I'll presume there's no more data to be read but the file is still open.
If we're using a blocking FD here we'll probably be stuck in read() when we're cancelled, and cancellation would probably be ok from looking at the current impl of QEMUFile / QIOChannel. If we're handling any error scenario though there could be a "Error *local_err" that needs freeing before cancellation.
If the fclose is processed before cancellation takes affect on the target thread though we could have a race.
1. proxy_mig_out blocked in read from qemu_fill_buffer
2. main thread request async cancel
3. main thread calls qemu_fclose which closes the FD and free's the QEMUFile object
4. proxy_mig_out thread returns from read() with
ret == 0 (EOF)
5. proxy_mig_out thread calls qemu_file_set_error_obj on a QEMUFole object free'd in (3). use after free. opps
6. ..async cancel request gets delivered....
admittedly it is fairly unlikely for the async cancel to be delayed for so long that this sequence happens, but unexpected things can happen when we really don't want them.
IMHO the safe way to deal with this would be a lock-step sequence between the threads
1. proxy_mig_out blocked in read from qemu_fill_buffer
2. main thread closes the FD with qemu_file_shutdown() closing both directions
3. proxy_mig_out returns from read with ret == 0 (EOF)
4. proxy_mig_out thread breaks out of its inifinite loop due to EOF and exits
5. main thread calls pthread_join on proxy_mig_out
6. main thread calls qemu_fclose()
this is easier to reason about the safety of than the cancel based approach IMHO.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object
Quoted 174 lines · Daniel P. Berrangé
Quoted 141 lines · Jag Raman
Quoted 138 lines · Daniel P. Berrangé
Quoted 50 lines · Jagannathan Raman
Collect the VMSD from remote process on the source and save it to the channel leading to the destination
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>---
New patch in v4hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)hw/proxy/qemu-proxy.c +17
-0@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque)hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 385
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem);There is a pretty large set of APIs hiding behind the
qemu_get_bytecall, which does not give me confidence that...Quoted 56 lines
hw/proxy/qemu-proxy.c +56
-0+ mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX );hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 452
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread);....this is a safe way to stop the thread executing without resulting in memory being leaked.
In addition thread cancellation is asynchronous, so the thread may still be using the QEMUFile object while....
Quoted 8 lines
Quoted 1 line
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 454
Quoted 1 line
hw/proxy/qemu-proxy.c +1
-0+qemu_fclose (f_remote);The above "
wait_for_remote()" call waits for the remote process to finish with Migration, and return the size of the VMSD.It should be safe to cancel the thread and close the file, once the remote process is done sending the VMSD and we have read "size" bytes from it, is it not?
Ok, so the thread is doing
while (true) { byte = qemu_get_byte(data->rem); ...do something with byte... }so when the thread is cancelled it is almost certainly in the
qemu_get_byte()call. Since you saywait_for_remote()syncs with the end of migration, I'll presume there's no more data to be read but the file is still open.If we're using a blocking FD here we'll probably be stuck in
read()when we're cancelled, and cancellation would probably be ok from looking at the current impl of QEMUFile / QIOChannel. If we're handling any error scenario though there could be a "Error*local_err" that needs freeing before cancellation.If the fclose is processed before cancellation takes affect on the target thread though we could have a race.
1.
proxy_mig_outblocked in read fromqemu_fill_buffer
Quoted 7 lines
2. main thread request async cancel
3. main thread calls
qemu_fclosewhich closes the FD and free's the QEMUFile object4.
proxy_mig_outthread returns fromread()withret == 0 (EOF)
This wasn't happening. It would be convenient if it did.
When the file was closed by the main thread, the async thread was still hung at qemu_fill_buffer(), instead of returning 0 (EOF). That's reason why we took the thread-cancellation route. We'd be glad to remove qemu_thread_cancel().
Quoted 9 lines
5.
proxy_mig_outthread callsqemu_file_set_error_objon a QEMUFole object free'd in (3). use after free. opps6. ..async cancel request gets delivered....
admittedly it is fairly unlikely for the async cancel to be delayed for so long that this sequence happens, but unexpected things can happen when we really don't want them.
Absolutely, we don't want to leave anything to chance.
Quoted 8 lines
IMHO the safe way to deal with this would be a lock-step sequence between the threads
1.
proxy_mig_outblocked in read fromqemu_fill_buffer2. main thread closes the FD with
qemu_file_shutdown()closing both directions
Will give qemu_file_shutdown() a try.
Thank you!
--
Jag
Quoted 16 lines
3.
proxy_mig_outreturns from read with ret == 0 (EOF)4.
proxy_mig_outthread breaks out of its inifinite loop due to EOF and exits5. main thread calls
pthread_joinonproxy_mig_out6. main thread calls
qemu_fclose()this is easier to reason about the safety of than the cancel based approach IMHO.
Regards,
Daniel
Re: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object
Quoted 205 lines · * Jag Raman ([email protected]) wrote:
Quoted 174 lines · Daniel P. Berrangé
Quoted 141 lines · Jag Raman
Quoted 138 lines · Daniel P. Berrangé
Quoted 50 lines · Jagannathan Raman
Collect the VMSD from remote process on the source and save it to the channel leading to the destination
Signed-off-by Elena Ufimtseva <[email protected]>Signed-off-by John G Johnson <[email protected]>Signed-off-by Jagannathan Raman <[email protected]>---
New patch in v4hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+)hw/proxy/qemu-proxy.c +17
-0@@ -52,6 +52,14 @@#include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer;static void pci_proxy_dev_realize (PCIDevice *dev,Error **errp);@@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void);static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx);static void broadcast_msg (MPQemuMsg *msg,bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; +static void childsig_handler (int sig,siginfo_t *siginfo,void *ctx) {/* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { +QEMUFile *rem; +PCIProxyDev *dev; +}proxy_mig_data ; + +static void *proxy_mig_out (void *opaque)hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 385
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+{ +proxy_mig_data *data = opaque; +PCIProxyDev *dev = data->dev; +uint8_t byte; +uint64_t data_size =PAGE_SIZE ; + + mig_data =g_malloc (data_size); + +while (true) { + byte =qemu_get_byte (data->rem);There is a pretty large set of APIs hiding behind the
qemu_get_bytecall, which does not give me confidence that...Quoted 56 lines
hw/proxy/qemu-proxy.c +56
-0+ mig_data[dev->migsize++] = byte; +if (dev->migsize == data_size) { + data_size +=PAGE_SIZE ; + mig_data =g_realloc (mig_data, data_size); + } + } + +return NULL ; +} + +static int proxy_pre_save (void *opaque) +{ +PCIProxyDev *pdev = opaque; +proxy_mig_data *mig_data; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +QemuThread thread; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"PCIProxyDevice-mig" ); + + f_remote =qemu_fopen_channel_input (ioc); + + pdev->migsize =0 ; + + mig_data =g_malloc0 (sizeof (proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + +qemu_thread_create (&thread,"Proxy MIG_OUT" , proxy_mig_out, mig_data, +QEMU_THREAD_DETACHED ); + + msg.cmd =START_MIG_OUT ; + msg.bytestream =0 ; + msg.num_fds =2 ; + msg.fds[0 ] = fd[1 ]; + msg.fds[1 ] =GET_REMOTE_WAIT ; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size =wait_for_remote (msg.fds[1 ]); +PUT_REMOTE_WAIT (msg.fds[1 ]); + +assert (size !=ULLONG_MAX );hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 452
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+ +/* +* migsize is being update by a separate thread. Using volatile to +* instruct the compiler to fetch the value of this variable from +* memory during every read +*/ +while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + +qemu_thread_cancel (&thread);....this is a safe way to stop the thread executing without resulting in memory being leaked.
In addition thread cancellation is asynchronous, so the thread may still be using the QEMUFile object while....
Quoted 8 lines
Quoted 1 line
hw/proxy/qemu-proxy.c static void pci_proxy_dev_inst_init(Object *obj) · line 454
Quoted 1 line
hw/proxy/qemu-proxy.c +1
-0+qemu_fclose (f_remote);The above "
wait_for_remote()" call waits for the remote process to finish with Migration, and return the size of the VMSD.It should be safe to cancel the thread and close the file, once the remote process is done sending the VMSD and we have read "size" bytes from it, is it not?
Ok, so the thread is doing
while (true) { byte = qemu_get_byte(data->rem); ...do something with byte... }so when the thread is cancelled it is almost certainly in the
qemu_get_byte()call. Since you saywait_for_remote()syncs with the end of migration, I'll presume there's no more data to be read but the file is still open.If we're using a blocking FD here we'll probably be stuck in
read()when we're cancelled, and cancellation would probably be ok from looking at the current impl of QEMUFile / QIOChannel. If we're handling any error scenario though there could be a "Error*local_err" that needs freeing before cancellation.If the fclose is processed before cancellation takes affect on the target thread though we could have a race.
1.
proxy_mig_outblocked in read fromqemu_fill_bufferQuoted 7 lines
2. main thread request async cancel
3. main thread calls
qemu_fclosewhich closes the FD and free's the QEMUFile object4.
proxy_mig_outthread returns fromread()withret == 0 (EOF)This wasn't happening. It would be convenient if it did.
When the file was closed by the main thread, the async thread was still hung at
qemu_fill_buffer(), instead of returning 0 (EOF). That's reason why we took the thread-cancellation route. We'd be glad to removeqemu_thread_cancel().Quoted 9 lines
5.
proxy_mig_outthread callsqemu_file_set_error_objon a QEMUFole object free'd in (3). use after free. opps6. ..async cancel request gets delivered....
admittedly it is fairly unlikely for the async cancel to be delayed for so long that this sequence happens, but unexpected things can happen when we really don't want them.
Absolutely, we don't want to leave anything to chance.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
IMHO the safe way to deal with this would be a lock-step sequence between the threads
1.
proxy_mig_outblocked in read fromqemu_fill_buffer
2. main thread closes the FD withqemu_file_shutdown()closing both directionsWill give
qemu_file_shutdown()a try.
Yes, shutdown() is quite nice - but note it does need to be a socket.
Dave
Quoted 21 lines
Thank you!
--
JagQuoted 16 lines
3.
proxy_mig_outreturns from read with ret == 0 (EOF)4.
proxy_mig_outthread breaks out of its inifinite loop due to EOF and exits5. main thread calls
pthread_joinonproxy_mig_out6. main thread calls
qemu_fclose()this is easier to reason about the safety of than the cancel based approach IMHO.
Regards,
Daniel
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC PATCH v4 42/49 multi-process/mig: Send VMSD of remote to the Proxy object
In reply to Jagannathan RamanThe remote process sends the VMSD to the Proxy object, on the source side
---
New patch in v4
migration/savevm.c | 27 +++++++++++++++++++++++++++ migration/savevm.h | 2 ++ remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+)
migration/savevm.c +27 -0
@@ -2903,3 +2903,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd)return !(vmsd && vmsd->unmigratable); } + +int qemu_remote_savevm (QEMUFile *f) +{ +SaveStateEntry *se; +int ret; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->vmsd || !vmstate_save_needed (se->vmsd, se->opaque)) { +continue ; + } + +save_section_header (f, se,QEMU_VM_SECTION_FULL ); + + ret =vmstate_save (f, se,NULL ); +if (ret) { +qemu_file_set_error (f, ret); +return ret; + } + +save_section_footer (f, se); + } + +qemu_put_byte (f,QEMU_VM_EOF ); +qemu_fflush (f); + +return 0 ; +}
migration/savevm.h +2 -0
@@ -64,4 +64,6 @@ void qemu_loadvm_state_cleanup(void);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f); +int qemu_remote_savevm (QEMUFile *f); +#endif
remote/remote-main.c +43 -0
61 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v4 43/49 multi-process/mig: Load VMSD in the proxy object
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
The Proxy object loads the VMSD of remote process in source and send it to the remote process in the destination
---
New patch in v4
hw/proxy/qemu-proxy.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 2 files changed, 51 insertions(+)
hw/proxy/qemu-proxy.c +50 -0
@@ -473,12 +473,62 @@ static int proxy_post_save(void *opaque)return 0 ; } +static int proxy_post_load (void *opaque,int version_id) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); +PCIProxyDev *pdev = opaque; +QEMUFile *f_remote; +MPQemuMsg msg = {0 }; +Error *err =NULL ; +QIOChannel *ioc; +uint64_t size; +uint8_t byte; +int fd[2 ]; + +if (socketpair (AF_UNIX ,SOCK_STREAM ,0 , fd)) { +return -1 ; + } + + ioc =qio_channel_new_fd (fd[0 ], &err); +if (err) { +error_report_err (err); +return -1 ; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"proxy-migration-channel" ); + + f_remote =qemu_fopen_channel_output (ioc); + + msg.cmd =START_MIG_IN ; + msg.bytestream =0 ; + msg.num_fds =1 ; + msg.fds[0 ] = fd[1 ]; + +mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + + size = pdev->migsize; + +while (size) { + byte =qemu_get_byte (mis->from_src_file); +qemu_put_byte (f_remote, byte); + size--; + } + +qemu_fflush (f_remote); +qemu_fclose (f_remote); + +close (fd[1 ]); + +return 0 ; +} +const VMStateDescription vmstate_pci_proxy_device = { .name ="PCIProxyDevice" , .version_id =2 , .minimum_version_id =1 , .pre_save = proxy_pre_save, .post_save = proxy_post_save, + .post_load = proxy_post_load, .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_dev, PCIProxyDev),VMSTATE_UINT64 (migsize, PCIProxyDev),
include/io/mpqemu-link.h +1 -0
@@ -76,6 +76,7 @@ typedef enum {MMIO_RETURN ,DEVICE_RESET ,START_MIG_OUT , +START_MIG_IN ,MAX , } mpqemu_cmd_t;
Signature · 1 line
1.8.3.1
RFC PATCH v4 44/49 multi-process/mig: refactor runstate_check into common file
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
runstate_check file is refactored into vl-parse.c
---
New patch in v4
Makefile.objs | 2 ++ include/sysemu/runstate.h | 2 ++ runstate.c | 36 ++++++++++++++++++++++++++++++++++++ stubs/runstate-check.c | 3 +++ vl-parse.c | 1 - vl.c | 10 ---------- 6 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 runstate.c
Makefile.objs +2 -0
@@ -38,6 +38,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o +remote-pci-obj-$(CONFIG_MPQEMU) += runstate.o ############################################################## # remote-lsi-obj-y is code used to implement remote LSI device
@@ -111,6 +112,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS) common-obj-$(CONFIG_FDT) += device_tree.o common-obj-y += vl-parse.o +common-obj-y += runstate.o remote-pci-obj-$(CONFIG_MPQEMU) += net/
include/sysemu/runstate.h +2 -0
@@ -4,6 +4,8 @@#include "qapi/qapi-types-run-state.h" #include "qemu/notify.h" +extern RunState current_run_state; +bool runstate_check (RunState state);void runstate_set (RunState new_state);int runstate_is_running (void );
runstate.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (c) 2003-2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/runstate.h" + +/***********************************************************/ +/* QEMU state */ + +RunState current_run_state =RUN_STATE_PRECONFIG ; + +bool runstate_check (RunState state) +{ +return current_run_state == state; +}
stubs/runstate-check.c +3 -0
@@ -1,6 +1,9 @@#include "qemu/osdep.h" #include "sysemu/runstate.h" + +#pragma weak runstate_check +bool runstate_check (RunState state) {return state ==RUN_STATE_PRELAUNCH ;
vl-parse.c +0 -1
@@ -159,4 +159,3 @@ int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; }#endif -
vl.c +0 -10
@@ -665,11 +665,6 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } -/***********************************************************/ -/* QEMU state */ - -static RunState current_run_state =RUN_STATE_PRECONFIG ; -/* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested =RUN_STATE__MAX ;static QemuMutex vmstop_lock;
@@ -777,11 +772,6 @@ static const RunStateTransition runstate_transitions_def[] = {static bool runstate_valid_transitions[RUN_STATE__MAX ][RUN_STATE__MAX ]; -bool runstate_check (RunState state) -{ -return current_run_state == state; -} -bool runstate_store (char *str,size_t size) {const char *state =RunState_str (current_run_state);
Signature · 1 line
1.8.3.1
RFC PATCH v4 45/49 multi-process/mig: Synchronize runstate of remote process
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Synchronize the runstate of the remote process with that of QEMU
---
New patch in v4
hw/proxy/qemu-proxy.c | 18 ++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 8 ++++++++ include/sysemu/runstate.h | 1 + qdev-monitor.c | 13 ++++++++++++- remote/remote-main.c | 4 ++++ remote/remote-opts.c | 5 +++++ runstate.c | 5 +++++ 8 files changed, 55 insertions(+), 1 deletion(-)
hw/proxy/qemu-proxy.c +18 -0
@@ -44,6 +44,7 @@#include "qapi/qmp/qjson.h" #include "qapi/qmp/qstring.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "hw/proxy/qemu-proxy.h" #include "hw/proxy/memory-sync.h" #include "qom/object.h"
@@ -656,6 +657,19 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e } } +static void proxy_vm_state_change (void *opaque,int running,RunState state) +{ +PCIProxyDev *dev = opaque; +MPQemuMsg msg = {0 }; + + msg.cmd =RUNSTATE_SET ; + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.data1.runstate.state = state; + +mpqemu_msg_send (dev->mpqemu_link, &msg, dev->mpqemu_link->com); +} +static void pci_proxy_dev_realize (PCIDevice *device,Error **errp) {PCIProxyDev *dev =PCI_PROXY_DEV (device);
@@ -681,6 +695,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) &dev->region[r].mr); } + dev->vmcse =qemu_add_vm_change_state_handler (proxy_vm_state_change, dev); + dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy;
@@ -706,6 +722,8 @@ static void pci_dev_exit(PCIDevice *pdev)if (!QLIST_EMPTY (&proxy_dev_list.devices)) {start_heartbeat_timer (); } + +qemu_del_vm_change_state_handler (dev->vmcse); } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr,
include/hw/proxy/qemu-proxy.h +2 -0
@@ -90,6 +90,8 @@ struct PCIProxyDev {ProxyMemoryRegion region[PCI_NUM_REGIONS ]; +VMChangeStateEntry *vmcse; +uint64_t migsize; };
include/io/mpqemu-link.h +8 -0
@@ -39,6 +39,8 @@#include "exec/cpu-common.h" #include "exec/hwaddr.h" +#include "qapi/qapi-types-run-state.h" +#define TYPE_MPQEMU_LINK "mpqemu-link"#define MPQEMU_LINK (obj) \ OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK)
@@ -77,6 +79,7 @@ typedef enum {DEVICE_RESET ,START_MIG_OUT ,START_MIG_IN , +RUNSTATE_SET ,MAX , } mpqemu_cmd_t;
@@ -115,6 +118,10 @@ typedef struct { } mmio_ret_msg_t;typedef struct { +RunState state; +}runstate_msg_t ; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size;
@@ -125,6 +132,7 @@ typedef struct {bar_access_msg_t bar_access;set_irqfd_msg_t set_irqfd;mmio_ret_msg_t mmio_ret; +runstate_msg_t runstate; } data1;int fds[REMOTE_MAX_FDS ];
include/sysemu/runstate.h +1 -0
@@ -8,6 +8,7 @@ extern RunState current_run_state;bool runstate_check (RunState state);void runstate_set (RunState new_state); +void remote_runstate_set (RunState state);int runstate_is_running (void );bool runstate_needs_reset (void );bool runstate_store (char *str,size_t size);
qdev-monitor.c +12 -1
@@ -34,6 +34,7 @@#include "qemu/qemu-print.h" #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "migration/misc.h" #include "hw/boards.h" #include "hw/proxy/qemu-proxy.h"
@@ -641,7 +642,7 @@ void qdev_proxy_fire(void) }DeviceState *qdev_proxy_add (const char *rid,const char *id,char *bus, -char *command,int rsocket,bool managed, +char *cmd,int rsocket,bool managed,Error **errp) {DeviceState *ds;
@@ -653,6 +654,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,const char *str;bool need_spawn = false;bool remote_exists = false; +char *command;if (strlen (rid) >MAX_RID_LENGTH ) {error_setg (errp,"rid %s is too long." , rid);
@@ -725,6 +727,12 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, need_spawn = true; } +if (runstate_check (RUN_STATE_INMIGRATE )) { + command =g_strdup_printf ("%s %s" , cmd,"-incoming defer" ); + }else { + command =g_strdup (cmd); + } + pdev->init_proxy (PCI_DEVICE (ds), command, need_spawn, errp);qemu_mutex_lock (&proxy_list_lock);
@@ -732,6 +740,9 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus,qemu_mutex_unlock (&proxy_list_lock);qemu_opts_del (proxy_opts); + +g_free (command); +return ds; }
remote/remote-main.c +4 -0
@@ -45,6 +45,7 @@#include "qemu/main-loop.h" #include "qemu/config-file.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "block/block.h" #include "exec/memattrs.h" #include "exec/address-spaces.h"
@@ -497,6 +498,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)case START_MIG_OUT :process_start_mig_out (msg);break ; +case RUNSTATE_SET : +remote_runstate_set (msg->data1.runstate.state); +break ;default :error_setg (&err,"Unknown command" ); goto finalize_loop;
remote/remote-opts.c +5 -0
@@ -56,8 +56,10 @@#include "remote/remote-opts.h" #include "include/qemu-common.h" #include "monitor/monitor.h" +#include "sysemu/runstate.h" #include "vl.h" +/* * In remote process, we parse only subset of options. The code * taken from vl.c to re-use in remote command line parser.
@@ -101,6 +103,9 @@ void parse_cmdline(int argc, char **argv, char **envp)case QEMU_OPTION_qmp:monitor_parse (optarg,"control" , false);break ; +case QEMU_OPTION_incoming: +remote_runstate_set (RUN_STATE_INMIGRATE ); +break ;case QEMU_OPTION_monitor:if (!strncmp (optarg,"stdio" ,5 )) {warn_report ("STDIO not supported in remote process" );
runstate.c +5 -0
@@ -34,3 +34,8 @@ bool runstate_check(RunState state) {return current_run_state == state; } + +void remote_runstate_set (RunState state) +{ + current_run_state = state; +}
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 45/49] multi-process/mig: Synchronize runstate of remote process
Quoted 6 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +2
-0@@ -656,6 +657,19 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e } } +static void proxy_vm_state_change (void *opaque,int running,RunState state) +{
hw/proxy/qemu-proxy.c static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e · line 671
Quoted 10 lines
hw/proxy/qemu-proxy.c +10
-0+PCIProxyDev *dev = opaque; +MPQemuMsg msg = {0 }; + + msg.cmd =RUNSTATE_SET ; + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.data1.runstate.state = state; + +mpqemu_msg_send (dev->mpqemu_link, &msg, dev->mpqemu_link->com); +}
Changing vm state is a barrier operation - devices must not dirty memory afterwards. This function doesn't have barrier semantics, it sends off the message without waiting for the remote process to finish processing it. This means there is a race condition where QEMU has changes the vm state but devices could still dirty memory. Please wait for a reply to prevent this.
Stefan
Re: [RFC v4 PATCH 45/49] multi-process/mig: Synchronize runstate of remote process
Quoted 16 lines · Stefan Hajnoczi
Quoted 15 lines · Jagannathan Raman
hw/proxy/qemu-proxy.c +11
-0@@ -656,6 +657,19 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e } } +static void proxy_vm_state_change (void *opaque,int running,RunState state) +{ +PCIProxyDev *dev = opaque; +MPQemuMsg msg = {0 }; + + msg.cmd =RUNSTATE_SET ; + msg.bytestream =0 ; + msg.size =sizeof (msg.data1); + msg.data1.runstate.state = state; + +mpqemu_msg_send (dev->mpqemu_link, &msg, dev->mpqemu_link->com);
Quoted 8 lines
Review static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e · line 671
Quoted 1 line
(quoted diff) +1
-0+}Changing vm state is a barrier operation - devices must not dirty memory afterwards. This function doesn't have barrier semantics, it sends off the message without waiting for the remote process to finish processing it. This means there is a race condition where QEMU has changes the vm state but devices could still dirty memory. Please wait for a reply to prevent this.
Got it, thanks! Will do.
--
Jag
Quoted 3 lines
Stefan
RFC PATCH v4 46/49 multi-process/mig: Restore the VMSD in remote process
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
The remote process accepts the VMSD from Proxy object and restores it
---
New patch in v4
migration/savevm.c | 36 ++++++++++++++++++++++++++++++++++++ migration/savevm.h | 1 + remote/remote-main.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
migration/savevm.c +36 -0
@@ -2930,3 +2930,39 @@ int qemu_remote_savevm(QEMUFile *f)return 0 ; } + +int qemu_remote_loadvm (QEMUFile *f) +{ +uint8_t section_type; +int ret =0 ; + +qemu_mutex_lock_iothread (); + +while (true) { + section_type =qemu_get_byte (f); + +if (qemu_file_get_error (f)) { + ret =qemu_file_get_error (f); +break ; + } + +switch (section_type) { +case QEMU_VM_SECTION_FULL : + ret =qemu_loadvm_section_start_full (f,NULL ); +if (ret <0 ) { +break ; + } +break ; +case QEMU_VM_EOF : + goto out; +default : + ret = -EINVAL ; + goto out; + } + } + +out: +qemu_mutex_unlock_iothread (); + +return ret; +}
migration/savevm.h +1 -0
@@ -65,5 +65,6 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f);int qemu_remote_savevm (QEMUFile *f); +int qemu_remote_loadvm (QEMUFile *f);#endif
remote/remote-main.c +34 -0
@@ -81,6 +81,7 @@#include "chardev/char.h" #include "sysemu/reset.h" #include "vl.h" +#include "migration/misc.h" static MPQemuLinkState *mpqemu_link;
@@ -403,6 +404,30 @@ static void process_start_mig_out(MPQemuMsg *msg)qemu_fclose (f); } +static int process_start_mig_in (MPQemuMsg *msg) +{ +Error *err =NULL ; +QIOChannel *ioc; +QEMUFile *f; +int rc = -EINVAL ; + + ioc =qio_channel_new_fd (msg->fds[0 ], &err); +if (err) { +error_report_err (err); +return rc; + } + +qio_channel_set_name (QIO_CHANNEL (ioc),"remote-migration-channel" ); + + f =qemu_fopen_channel_input (ioc); + + rc =qemu_remote_loadvm (f); + +qemu_fclose (f); + +return rc; +} +static void process_msg (GIOCondition cond,MPQemuChannel *chan) {MPQemuMsg *msg =NULL ;
@@ -498,6 +523,13 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan)case START_MIG_OUT :process_start_mig_out (msg);break ; +case START_MIG_IN : +if (process_start_mig_in (msg)) + { +error_setg (&err,"Incoming migration failed." ); + goto finalize_loop; + } +break ;case RUNSTATE_SET :remote_runstate_set (msg->data1.runstate.state);break ;
@@ -569,6 +601,8 @@ int main(int argc, char *argv[]) }mpqemu_init_channel (mpqemu_link, &mpqemu_link->mmio, fd); +migration_object_init (); +parse_cmdline (argc -3 , argv +3 ,NULL );mpqemu_link_set_callback (mpqemu_link, process_msg);
Signature · 1 line
1.8.3.1
RFC PATCH v4 47/49 multi-process: Enable support for multiple devices in remote
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
Add support to allow multiple devices to be configured in the remote process
---
New patch in v4
hw/proxy/qemu-proxy.c | 3 +++ include/hw/proxy/qemu-proxy.h | 3 +++ include/io/mpqemu-link.h | 1 + qdev-monitor.c | 2 ++ remote/remote-main.c | 34 ++++++++++++++++++++++++---------- 5 files changed, 33 insertions(+), 10 deletions(-)
hw/proxy/qemu-proxy.c +3 -0
@@ -176,6 +176,7 @@ static void set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) msg.bytestream =1 ; msg.size =qstring_get_length (qstr) +1 ; msg.num_fds =0 ; + msg.id = pdev->id;mpqemu_msg_send (pdev->mpqemu_link, &msg, pdev->mpqemu_link->com);
@@ -322,6 +323,7 @@ static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, msg.size =sizeof (conf_data); msg.cmd = op; msg.bytestream =1 ; + msg.id = dev->id;if (op ==CONF_WRITE ) { msg.num_fds =0 ;
@@ -602,6 +604,7 @@ static void setup_irqfd(PCIProxyDev *dev)memset (&msg,0 ,sizeof (MPQemuMsg)); msg.cmd =SET_IRQFD ; + msg.id = dev->id; msg.num_fds =2 ; msg.fds[0 ] =event_notifier_get_fd (&dev->intr); msg.fds[1 ] =event_notifier_get_fd (&dev->resample);
include/hw/proxy/qemu-proxy.h +3 -0
@@ -57,6 +57,9 @@ extern const MemoryRegionOps proxy_default_ops;struct PCIProxyDev {PCIDevice parent_dev; +uint64_t id; +uint64_t nr_devices; +int n_mr_sections;MemoryRegionSection *mr_sections;
include/io/mpqemu-link.h +1 -0
@@ -124,6 +124,7 @@ typedef struct { typedef struct { mpqemu_cmd_t cmd; int bytestream; + uint64_t id; size_t size; union {
qdev-monitor.c +2 -0
@@ -716,9 +716,11 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; pdev->mem_init = true; + pdev->id = old_pdev->nr_devices++; }else { pdev->rsocket = managed ? rsocket :-1 ; pdev->socket = managed ? rsocket :-1 ; + pdev->id = pdev->nr_devices++; } pdev->managed = managed;
remote/remote-main.c +24 -10
@@ -85,7 +85,8 @@static MPQemuLinkState *mpqemu_link; -PCIDevice *remote_pci_dev; +PCIDevice **remote_pci_devs; +uint64_t nr_devices;bool create_done;static void process_config_write (MPQemuMsg *msg)
@@ -93,7 +94,8 @@ static void process_config_write(MPQemuMsg *msg)struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;qemu_mutex_lock_iothread (); -pci_default_write_config (remote_pci_dev, conf->addr, conf->val, conf->l); +pci_default_write_config (remote_pci_devs[msg->id], conf->addr, conf->val, + conf->l);qemu_mutex_unlock_iothread (); }
@@ -106,7 +108,8 @@ static void process_config_read(MPQemuMsg *msg) wait = msg->fds[0 ];qemu_mutex_lock_iothread (); - val =pci_default_read_config (remote_pci_dev, conf->addr, conf->l); + val =pci_default_read_config (remote_pci_devs[msg->id], conf->addr, + conf->l);qemu_mutex_unlock_iothread ();notify_proxy (wait, val);
@@ -366,9 +369,17 @@ static int setup_device(MPQemuMsg *msg, Error **errp) qstring_get_str(qobject_to_json(QOBJECT(qdict))));return rc; } +if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) { - remote_pci_dev =PCI_DEVICE (dev); +if (nr_devices <= msg->id) { + nr_devices = msg->id +1 ; + remote_pci_devs =g_realloc (remote_pci_devs, + nr_devices *sizeof (PCIDevice *)); + } + + remote_pci_devs[msg->id] =PCI_DEVICE (dev); } +qemu_opts_del (opts);return 0 ;
@@ -489,12 +500,15 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) }break ;case SET_IRQFD : -process_set_irqfd_msg (remote_pci_dev, msg); -qdev_machine_creation_done (); -qemu_mutex_lock_iothread (); -qemu_run_machine_init_done_notifiers (); -qemu_mutex_unlock_iothread (); - create_done = true; +process_set_irqfd_msg (remote_pci_devs[msg->id], msg); + +if (!create_done) { +qdev_machine_creation_done (); +qemu_mutex_lock_iothread (); +qemu_run_machine_init_done_notifiers (); +qemu_mutex_unlock_iothread (); + create_done = true; + }break ;case DRIVE_OPTS :if (setup_drive (msg, &err)) {
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 47/49] multi-process: Enable support for multiple devices in remote
Quoted 11 lines · Jagannathan Raman
remote/remote-main.c +2
-1@@ -93,7 +94,8 @@ static void process_config_write(MPQemuMsg *msg)struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;qemu_mutex_lock_iothread (); -pci_default_write_config (remote_pci_dev, conf->addr, conf->val, conf->l); +pci_default_write_config (remote_pci_devs[msg->id], conf->addr, conf->val, + conf->l);qemu_mutex_unlock_iothread (); }
remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 115
Quoted 9 lines
remote/remote-main.c +2
-1@@ -106,7 +108,8 @@ static void process_config_read(MPQemuMsg *msg) wait = msg->fds[0 ];qemu_mutex_lock_iothread (); - val =pci_default_read_config (remote_pci_dev, conf->addr, conf->l); + val =pci_default_read_config (remote_pci_devs[msg->id], conf->addr, + conf->l);qemu_mutex_unlock_iothread ();notify_proxy (wait, val);
msg->id was read from a socket and hasn't been validated before indexing into remote_pci_devs[].
Re: [RFC v4 PATCH 47/49] multi-process: Enable support for multiple devices in remote
Quoted 20 lines · Stefan Hajnoczi
Quoted 19 lines · Jagannathan Raman
remote/remote-main.c +4
-2@@ -93,7 +94,8 @@ static void process_config_write(MPQemuMsg *msg)struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2;qemu_mutex_lock_iothread (); -pci_default_write_config (remote_pci_dev, conf->addr, conf->val, conf->l); +pci_default_write_config (remote_pci_devs[msg->id], conf->addr, conf->val, + conf->l);qemu_mutex_unlock_iothread (); }@@ -106,7 +108,8 @@ static void process_config_read(MPQemuMsg *msg) wait = msg->fds[0 ];qemu_mutex_lock_iothread (); - val =pci_default_read_config (remote_pci_dev, conf->addr, conf->l); + val =pci_default_read_config (remote_pci_devs[msg->id], conf->addr, + conf->l);qemu_mutex_unlock_iothread ();
Quoted 4 lines
remote/remote-main.c static void process_config_read(MPQemuMsg *msg) · line 115
Quoted 1 line
remote/remote-main.c +0
-0notify_proxy (wait, val);
msg->idwas read from a socket and hasn't been validated before indexing into remote_pci_devs[].
We see the common thread, w.r.t your concerns about security. Thanks for pointing them out.
We will fix this and other similar issues in the future.
Thank you very much!
--
Jag
Quoted 1 line
RFC PATCH v4 48/49 multi-process: add the concept description to docs/devel/qemu-multiprocess
In reply to Jagannathan RamanFrom: John G Johnson <[email protected]>
---
v2 -> v3:
- Updated with latest design of this project
v3 -> v4:
- Updated document to RST format
docs/devel/index.rst | 1 + docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 1103 insertions(+) create mode 100644 docs/devel/qemu-multiprocess.rst
docs/devel/index.rst +1 -0
@@ -22,3 +22,4 @@ Contents: decodetree secure-coding-practices tcg + multi-process
docs/devel/qemu-multiprocess.rst new file +1102 -0
1,102 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 48/49] multi-process: add the concept description to docs/devel/qemu-multiprocess
Quoted 5 lines · Jagannathan Raman
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]>
Quoted 7 lines
---
v2 -> v3:
- Updated with latest design of this projectv3 -> v4:
- Updated document to RST format
Hi,
The warning was reported in regards to this patch because the index for the multi-process document is incorrect as pointed by the automated tests.
"/tmp/qemu-test/src/docs/devel/index.rst:13:toctree contains reference to nonexisting document 'multi-process'".
The correct version of this patch is available. Should that be sent in the next series or can be correct version attached here?
Thank you!
Elena, Jag and JJ.
Quoted 1,125 lines
docs/devel/index.rst | 1 + docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 1103 insertions(+) create mode 100644 docs/devel/qemu-multiprocess.rstdocs/devel/index.rst +1
-0@@ -22,3 +22,4 @@ Contents: decodetree secure-coding-practices tcg + multi-processdocs/devel/qemu-multiprocess.rst new file +1102
-0@@ -0,0 +1,1102 @@ +Disaggregating QEMU +=================== + +QEMU is often used as the hypervisor for virtual machines running in the +Oracle cloud. Since one of the advantages of cloud computing is the +ability to run many VMs from different tenants in the same cloud +infrastructure, a guest that compromised its hypervisor could +potentially use the hypervisor's access privileges to access data it is +not authorized for. + +QEMU can be susceptible to security attack because it is a large, +monolithic program that provides many features to the VMs it services. +Many of these feature can be configured out of QEMU, but even a reduced +configuration QEMU has a large amount of code a guest can potentially +attack in order to gain additional privileges. + +QEMU services +------------- + +QEMU can be broadly described as providing three main services. One is a +VM control point, where VMs can be created, migrated, re-configured, and +destroyed. A second is to emulate the CPU instructions within the VM, +often accelerated by HW virtualization features such as Intel's VT +extensions. Finally, it provides IO services to the VM by emulating HW +IO devices, such as disk and network devices. + +A disaggregated QEMU +~~~~~~~~~~~~~~~~~~~~ + +A disaggregated QEMU involves separating QEMU services into separate +host processes. Each of these processes can be given only the privileges +it needs to provide its service, e.g., a disk service could be given +access only the the disk images it provides, and not be allowed to +access other files, or any network devices. An attacker who compromised +this service would not be able to use this exploit to access files or +devices beyond what the disk service was given access to. + +A QEMU control process would remain, but in disaggregated mode, it would +be a control point that executes the processes needed to support the VM +being created, but have no direct interfaces to the VM. During VM +execution, it would still provide the user interface to hot-plug devices +or live migrate the VM. + +A first step in creating a disaggregated QEMU is to separate IO services +from the main QEMU program, which would continue to provide CPU +emulation. i.e., the control process would also be the CPU emulation +process. In a later phase, CPU emulation could be separated from the +control process. + +Disaggregating IO services +-------------------------- + +Disaggregating IO services is a good place to begin QEMU disaggregating +for a couple of reasons. One is the sheer number of IO devices QEMU can +emulate provides a large surface of interfaces which could potentially +be exploited, and, indeed, have been a source of exploits in the past. +Another is the modular nature of QEMU device emulation code provides +interface points where the QEMU functions that perform device emulation +can be separated from the QEMU functions that manage the emulation of +guest CPU instructions. + +QEMU device emulation +~~~~~~~~~~~~~~~~~~~~~ + +QEMU uses a object oriented SW architecture for device emulation code. +Configured objects are all compiled into the QEMU binary, then objects +are instantiated by name when used by the guest VM. For example, the +code to emulate a device named "foo" is always present in QEMU, but its +instantiation code is only run when the device is included in the target +VM. (e.g., via the QEMU command line as *-device foo*) + +The object model is hierarchical, so device emulation code names its +parent object (such as "pci-device" for a PCI device) and QEMU will +instantiate a parent object before calling the device's instantiation +code. + +Current separation models +~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to separate the device emulation code from the CPU emulation +code, the device object code must run in a different process. There are +a couple of existing QEMU features that can run emulation code +separately from the main QEMU process. These are examined below. + +vhost user model +^^^^^^^^^^^^^^^^ + +Virtio guest device drivers can be connected to vhost user applications +in order to perform their IO operations. This model uses special virtio +device drivers in the guest and vhost user device objects in QEMU, but +once the QEMU vhost user code has configured the vhost user application, +mission-mode IO is performed by the application. The vhost user +application is a daemon process that can be contacted via a known UNIX +domain socket. + +vhost socket +'''''''''''' + +As mentioned above, one of the tasks of the vhost device object within +QEMU is to contact the vhost application and send it configuration +information about this device instance. As part of the configuration +process, the application can also be sent other file descriptors over +the socket, which then can be used by the vhost user application in +various ways, some of which are described below. + +vhost MMIO store acceleration +''''''''''''''''''''''''''''' + +VMs are often run using HW virtualization features via the KVM kernel +driver. This driver allows QEMU to accelerate the emulation of guest CPU +instructions by running the guest in a virtual HW mode. When the guest +executes instructions that cannot be executed by virtual HW mode, +execution returns to the KVM driver so it can inform QEMU to emulate the +instructions in SW. + +One of the events that can cause a return to QEMU is when a guest device +driver accesses an IO location. QEMU then dispatches the memory +operation to the corresponding QEMU device object. In the case of a +vhost user device, the memory operation would need to be sent over a +socket to the vhost application. This path is accelerated by the QEMU +virtio code by setting up an eventfd file descriptor that the vhost +application can directly receive MMIO store notifications from the KVM +driver, instead of needing them to be sent to the QEMU process first. + +vhost interrupt acceleration +'''''''''''''''''''''''''''' + +Another optimization used by the vhost application is the ability to +directly inject interrupts into the VM via the KVM driver, again, +bypassing the need to send the interrupt back to the QEMU process first. +The QEMU virtio setup code configures the KVM driver with an eventfd +that triggers the device interrupt in the guest when the eventfd is +written. This irqfd file descriptor is then passed to the vhost user +application program. + +vhost access to guest memory +'''''''''''''''''''''''''''' + +The vhost application is also allowed to directly access guest memory, +instead of needing to send the data as messages to QEMU. This is also +done with file descriptors sent to the vhost user application by QEMU. +These descriptors can be passed to ``mmap()`` by the vhost application +to map the guest address space into the vhost application. + +IOMMUs introduce another level of complexity, since the address given to +the guest virtio device to DMA to or from is not a guest physical +address. This case is handled by having vhost code within QEMU register +as a listener for IOMMU mapping changes. The vhost application maintains +a cache of IOMMMU translations: sending translation requests back to +QEMU on cache misses, and in turn receiving flush requests from QEMU +when mappings are purged. + +applicability to device separation +'''''''''''''''''''''''''''''''''' + +Much of the vhost model can be re-used by separated device emulation. In +particular, the ideas of using a socket between QEMU and the device +emulation application, using a file descriptor to inject interrupts into +the VM via KVM, and allowing the application to ``mmap()`` the guest +should be re used. + +There are, however, some notable differences between how a vhost +application works and the needs of separated device emulation. The most +basic is that vhost uses custom virtio device drivers which always +trigger IO with MMIO stores. A separated device emulation model must +work with existing IO device models and guest device drivers. MMIO loads +break vhost store acceleration since they are synchronous - guest +progress cannot continue until the load has been emulated. By contrast, +stores are asynchronous, the guest can continue after the store event +has been sent to the vhost application. + +Another difference is that in the vhost user model, a single daemon can +support multiple QEMU instances. This is contrary to the security regime +desired, in which the emulation application should only be allowed to +access the files or devices the VM it's running on behalf of can access. +#### qemu-io model + +Qemu-io is a test harness used to test changes to the QEMU block backend +object code. (e.g., the code that implements disk images for disk driver +emulation) Qemu-io is not a device emulation application per se, but it +does compile the QEMU block objects into a separate binary from the main +QEMU one. This could be useful for disk device emulation, since its +emulation applications will need to include the QEMU block objects. + +New separation model based on proxy objects +------------------------------------------- + +A different model based on proxy objects in the QEMU program +communicating with remote emulation programs could provide separation +while minimizing the changes needed to the device emulation code. The +rest of this section is a discussion of how a proxy object model would +work. + +Remote emulation processes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The remote emulation process will run the QEMU object hierarchy without +modification. The device emulation objects will be also be based on the +QEMU code, because for anything but the simplest device, it would not be +a tractable to re-implement both the object model and the many device +backends that QEMU has. + +The processes will communicate with the QEMU process over UNIX domain +sockets. The processes can be executed either as standalone processes, +or be executed by QEMU. In both cases, the host backends the emulation +processes will provide are specified on its command line, as they would +be for QEMU. For example: + +:: + + disk-proc -blockdev driver=file,node-name=file0,filename=disk-file0 \ + -blockdev driver=qcow2,node-name=drive0,file=file0 + +would indicate process *disk-proc* uses a qcow2 emulated disk named +*file0* as its backend. + +Emulation processes may emulate more than one guest controller. A common +configuration might be to put all controllers of the same device class +(e.g., disk, network, etc.) in a single process, so that all backends of +the same type can be managed by a single QMP monitor. + +communication with QEMU +^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes will recognize a *-socket* argument that +specifies the path of a UNIX domain socket used to communicate with the +QEMU process. If no *-socket* argument is present, the process will use +file descriptor 0 to communicate with QEMU. For example, + +:: + + disk-proc -socket /tmp/disk0-sock <backend list> + +will communicate with QEMU using the socket path */tmp/dik0-sock*. + +remote process QMP monitor +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes can be monitored via QMP, similar to QEMU +itself. The QMP monitor socket is specified the same as for a QEMU +process: + +:: + + disk-proc -qmp unix:/tmp/disk-mon,server + +can be monitored over the UNIX socket path */tmp/disk-mon*. + +QEMU command line +~~~~~~~~~~~~~~~~~ + +The QEMU command line options will need to be modified to indicate which +items are emulated by a separate program, and which remain emulated by +QEMU itself. + +identifying remote emulation processes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes will be identified to QEMU using a *-remote* +command line option. This option can either specify a command that QEMU +will execute, or can specify a UNIX domain socket that QEMU can use to +connect to an existing process. Both forms require a "id" option that +identifies the process to later *-device* options. The process version +is: + +:: + + -remote id=disk-proc,command="disk-proc <backend list>" + +And the socket version is: + +:: + + -remote id=disk-proc,socket="/tmp/disk0-sock" + +In the latter case, the remote process must be given the same socket on +its command line when it is executed: + +:: + + disk-proc -socket /tmp/disk0-sock <backend list> + +identifying devices emulated remotely +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Devices that are to be emulated in a separate process will be identify +the remote process with a "remote" option on their *-device* command +line specification. e.g., an LSI SCSI controller and disk can be +specified as: + +:: + + -device lsi53c895a,id=scsi0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + +If these devices are emulated by remote process "disk-proc," as +described in the previous section, the QEMU command line would be: + +:: + + -device lsi53c895a,id=scsi0,remote=disk-proc + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,remote=disk-proc + +Some devices are implicitly created by the machine object. e.g., the q35 +machine object will create its PCI bus, and attach an ich9-ahci IDE +controller to it. In this case, options will need to be added to the +*-machine* command line. e.g., + +:: + + -machine pc-q35,ide-remote=disk-proc + +will use the remote process with an "id" of "disk-proc" to emulate the +IDE controller and its disks. + +The disks themselves still need to be specified with *-remote* option, +as in the example above. e.g., + +:: + + -device ide-hd,drive=drive0,bus=ide.0,unit=0,remote=disk-proc + +QEMU management of remote processes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Each *-remote* instance on the QEMU command line will create a remote +process proxy instance in QEMU. They will be held on a *QList* that can +be searched for by its "id" property. The remote process proxy will also +establish a communication channel between QEMU and the remote process. +This can be done in one of two methods: direction execution of the +process by QEMU with ``fork()`` and ``exec()`` system calls, or by +connecting to an existing process. + +direct execution +^^^^^^^^^^^^^^^^ + +When the remote process is directly executed, the remote process proxy +will setup a communication channel between itself and the emulation +process. This channel will be created using ``socketpair()`` and the +remote process side of the pair will be given to the process as file +descriptor 0. + +connecting to an existing process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Some environments wish to deny QEMU the ability to execute ``fork()`` +and ``exec()`` In these case, emulation processes will be started before +QEMU, and a UNIX domain socket will be given to each emulation process +to communicate with QEMU over. After communication is established, the +socket will be unlinked from the file system space by the QEMU process. + +communication with emulation process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +primary socket +'''''''''''''' + +Whether the process was executed by QEMU or externally, there will be a +primary socket for communication between QEMU and the remote process. +This channel will handle configuration commands from QEMU to the +process, either from the QEMU command line, or from QMP commands that +affect the devices being emulated by the process. This channel will only +allow one message to be pending at a time; if additional messages +arrive, they must wait for previous ones to be acknowledged from the +remote side. + +secondary sockets +''''''''''''''''' + +The primary socket can pass the file descriptors of secondary sockets +for operations that occur in parallel with commands on the primary +channel. These include MMIO operations generated by the guest, interrupt +notifications generated by the devices being emulated, or *vmstate* for +live migration. These secondary sockets will be created at the behest of +the device proxies that require them. A disk device proxy wouldn't need +any secondary sockets, but a disk controller device proxy may need both +an MMIO socket and an interrupt socket. + +emulation process attached via QMP command +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There will be a new "attach-process" QMP command to facilitate device +hot-plug. This command's arguments will be the same as the *-remote* +command line when it's used to attach to a remote process. i.e., it will +need an "id" argument so that hot-plugged devices can later find it, and +a "socket" argument to identify the UNIX domain socket that will be used +to communicate with QEMU. + +QEMU device proxy objects +~~~~~~~~~~~~~~~~~~~~~~~~~ + +QEMU has an object model based on sub-classes inherited from the +"object" super-class. The sub-classes that are of interest here are the +"device" and "bus" sub-classes whose child sub-classes make up the +device tree of a QEMU emulated system. + +The proxy object model will use device proxy objects to replace the +device emulation code within the QEMU process. These objects will live +in the same place in the object and bus hierarchies as the objects they +replace. i.e., the proxy object for an LSI SCSI controller will be a +sub-class of the "pci-device" class, and will have the same PCI bus +parent and the same SCSI bus child objects as the LSI controller object +it replaces. + +After the QEMU command line has been parsed, the remote devices will be +instantiated in the same manner as local devices are. (i.e., +``qdev_device_add()``). In order to distinguish them from regular +*-device* device objects, their class name will be the name of the class +it replaces, with "-proxy" appended. e.g., the "lsi53c895a" proxy class +will be "lsi53c895a-proxy." + +device JSON description +^^^^^^^^^^^^^^^^^^^^^^^ + +The remote process needs a JSON representation of the command line +options used to create the object. This JSON representation is used to +create the corresponding object in the emulation process. e.g., for an +LSI SCSI controller invoked as: + +:: + + -device lsi53c895a,id=scsi0,remote=lsi-scsi + +the proxy object would create a + +:: + + { "driver" : "lsi53c895a", "id" : "scsi0" } + +JSON description. The "driver" option is assigned to the device name +when the command line is parsed, so the "-proxy" appended by the command +line parsing code is removed. The "remote" option isn't needed in the +JSON description since it only applies to the proxy object in the QEMU +process. + +device object whitelist +^^^^^^^^^^^^^^^^^^^^^^^ + +Some device objects may not need a proxy. These are devices with no +direct guest interfaces. (e.g., no MMIO, PIO, or interrupts). There will +be a whitelist of such devices, and any devices on this list will not be +instantiated in QEMU. Their JSON representation will still be sent to +the remote process, so the object can be created there. + +object initialization +^^^^^^^^^^^^^^^^^^^^^ + +QEMU object initialization occurs in two phases. The first +initialization happens once per object class. (i.e., there can be many +SCSI disks in an emulated system, but the "scsi-hd" class has its +``class_init()`` function called only once) The second phase happens +when each object's ``instance_init()`` function is called to initialize +each instance of the object. + +All device objects are sub-classes of the "device" class, so they also +have a ``realize()`` function that is called after ``instance_init()`` +is called and after the object's static properties have been +initialized. Many device objects don't even provide an instance\_init() +function, and do all their per-instance work in ``realize()``. + +class\_init +''''''''''' + +The ``class_init()`` method of a proxy object will, in general behave +similarly to the object it replaces, including setting any static +properties and methods needed by the proxy. + +instance\_init / realize +'''''''''''''''''''''''' + +The ``instance_init()`` and ``realize()`` functions would only need to +perform tasks related to being a proxy, such are registering its own +MMIO handlers, or creating a child bus that other proxy devices can be +attached to later. + +Other tasks will are device-specific. For example, PCI device objects +will initialize the PCI config space in order to make a valid PCI device +tree within the QEMU process. + +address space registration +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Most devices are driven by guest device driver accesses to IO addresses +or ports. The QEMU device emulation code uses QEMU's memory region +function calls (such as ``memory_region_init_io()``) to add callback +functions that QEMU will invoke when the guest accesses the device's +areas of the IO address space. When a guest driver does access the +device, the VM will exit HW virtualization mode and return to QEMU, +which will then lookup and execute the corresponding callback function. + +A proxy object would need to mirror the memory region calls the actual +device emulator would perform in its initialization code, but with its +own callbacks. When invoked by QEMU as a result of a guest IO operation, +they will forward the operation to the device emulation process. + +PCI config space +^^^^^^^^^^^^^^^^ + +PCI devices also have a configuration space that can be accessed by the +guest driver. Guest accesses to this space is not handled by the device +emulation object, but by its PCI parent object. Much of this space is +read-only, but certain registers (especially BAR and MSI-related ones) +need to be propagated to the emulation process. + +PCI parent proxy +'''''''''''''''' + +One way to propagate guest PCI config accesses is to create a +"pci-device-proxy" class that can serve as the parent of a PCI device +proxy object. This class's parent would be "pci-device" and it would +override the PCI parent's ``config_read()`` and ``config_write()`` +methods with ones that forward these operations to the emulation +program. + +interrupt receipt +^^^^^^^^^^^^^^^^^ + +A proxy for a device that generates interrupts will need to create a +socket to receive interrupt indications from the emulation process. An +incoming interrupt indication would then be sent up to its bus parent to +be injected into the guest. For example, a PCI device object may use +``pci_set_irq()``. + +live migration +^^^^^^^^^^^^^^ + +The proxy will register to save and restore any *vmstate* it needs over +a live migration event. The device proxy does not need to manage the +remote device's *vmstate*; that will be handled by the remote process +proxy (see below). + +QEMU remote device operation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Generic device operations, such as DMA, will be performs by the remote +process proxy by sending messages to the remote process. + +DMA operations +^^^^^^^^^^^^^^ + +DMA operations would be handled much like vhost applications do. One of +the initial messages sent to the emulation process is a guest memory +table. Each entry in this table consists of a file descriptor and size +that the emulation process can ``mmap()`` to directly access guest +memory, similar to ``vhost_user_set_mem_table()``. Note guest memory +must be backed by file descriptors, such as when QEMU is given the +*-mem-path* command line option. + +IOMMU operations +^^^^^^^^^^^^^^^^ + +When the emulated system includes an IOMMU, the remote process proxy in +QEMU will need to create a socket for IOMMU requests from the emulation +process. It will handle those requests with an +``address_space_get_iotlb_entry()`` call. In order to handle IOMMU +unmaps, the remote process proxy will also register as a listener on the +device's DMA address space. When an IOMMU memory region is created +within the DMA address space, an IOMMU notifier for unmaps will be added +to the memory region that will forward unmaps to the emulation process +over the IOMMU socket. + +device hot-plug via QMP +^^^^^^^^^^^^^^^^^^^^^^^ + +An QMP "device\_add" command can add a device emulated by a remote +process. It needs to add a "remote" option to the command, just as the +*-device* command line option does. The remote process may either be one +started at QEMU startup, or be one added by the "add-process" QMP +command described above. In either case, the remote process proxy will +forward the new device's JSON description to the corresponding emulation +process. + +live migration +^^^^^^^^^^^^^^ + +The remote process proxy will also register for live migration +notifications with ``vmstate_register()``. When called to save state, +the proxy will send the remote process a secondary socket file +descriptor to save the remote process's device *vmstate* over. The +incoming byte stream length and data will be saved as the proxy's +*vmstate*. When the proxy is resumed on its new host, this *vmstate* +will be extracted, and a secondary socket file descriptor will be sent +to the new remote process through which it receives the *vmstate* in +order to restore the devices there. + +device emulation in remote process +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The parts of QEMU that the emulation program will need include the +object model; the memory emulation objects; the device emulation objects +of the targeted device, and any dependent devices; and, the device's +backends. It will also need code to setup the machine environment, +handle requests from the QEMU process, and route machine-level requests +(such as interrupts or IOMMU mappings) back to the QEMU process. + +initialization +'''''''''''''' + +The process initialization sequence will follow the same sequence +followed by QEMU. It will first initialize the backend objects, then +device emulation objects. The JSON descriptions sent by the QEMU process +will drive which objects need to be created. + +- address spaces + +Before the device objects are created, the initial address spaces and +memory regions must be configured with ``memory_map_init()``. This +creates a RAM memory region object (*system\_memory*) and an IO memory +region object (*system\_io*). + +- RAM + +RAM memory region creation will follow how ``pc_memory_init()`` creates +them, but must use ``memory_region_init_ram_from_fd()`` instead of +``memory_region_allocate_system_memory()``. The file descriptors needed +will be supplied by the guest memory table from above. Those RAM regions +would then be added to the *system\_memory* memory region with +``memory_region_add_subregion()``. + +- PCI + +IO initialization will be driven by the JSON descriptions sent from the +QEMU process. For a PCI device, a PCI bus will need to be created with +``pci_root_bus_new()``, and a PCI memory region will need to be created +and added to the *system\_memory* memory region with +``memory_region_add_subregion_overlap()``. The overlap version is +required for architectures where PCI memory overlaps with RAM memory. + +MMIO handling +''''''''''''' + +The device emulation objects will use ``memory_region_init_io()`` to +install their MMIO handlers, and ``pci_register_bar()`` to associate +those handlers with a PCI BAR, as they do within QEMU currently. + +In order to use ``address_space_rw()`` in the emulation process to +handle MMIO requests from QEMU, the PCI physical addresses must be the +same in the QEMU process and the device emulation process. In order to +accomplish that, guest BAR programming must also be forwarded from QEMU +to the emulation process. + +interrupt injection +''''''''''''''''''' + +When device emulation wants to inject an interrupt into the VM, the +request climbs the device's bus object hierarchy until the point where a +bus object knows how to signal the interrupt to the guest. The details +depend on the type of interrupt being raised. + +- PCI pin interrupts + +On x86 systems, there is an emulated IOAPIC object attached to the root +PCI bus object, and the root PCI object forwards interrupt requests to +it. The IOAPIC object, in turn, calls the KVM driver to inject the +corresponding interrupt into the VM. The simplest way to handle this in +an emulation process would be to setup the root PCI bus driver (via +``pci_bus_irqs()``) to send a interrupt request back to the QEMU +process, and have the device proxy object reflect it up the PCI tree +there. + +- PCI MSI/X interrupts + +PCI MSI/X interrupts are implemented in HW as DMA writes to a +CPU-specific PCI address. In QEMU on x86, a KVM APIC object receives +these DMA writes, then calls into the KVM driver to inject the interrupt +into the VM. A simple emulation process implementation would be to send +the MSI DMA address from QEMU as a message at initialization, then +install an address space handler at that address which forwards the MSI +message back to QEMU. + +DMA operations +'''''''''''''' + +When a emulation object wants to DMA into or out of guest memory, it +first must use dma\_memory\_map() to convert the DMA address to a local +virtual address. The emulation process memory region objects setup above +will be used to translate the DMA address to a local virtual address the +device emulation code can access. + +IOMMU +''''' + +When an IOMMU is in use in QEMU, DMA translation uses IOMMU memory +regions to translate the DMA address to a guest physical address before +that physical address can be translated to a local virtual address. The +emulation process will need similar functionality. + +- IOTLB cache + +The emulation process will maintain a cache of recent IOMMU translations +(the IOTLB). When the translate() callback of an IOMMU memory region is +invoked, the IOTLB cache will be searched for an entry that will map the +DMA address to a guest PA. On a cache miss, a message will be sent back +to QEMU requesting the corresponding translation entry, which be both be +used to return a guest address and be added to the cache. + +- IOTLB purge + +The IOMMU emulation will also need to act on unmap requests from QEMU. +These happen when the guest IOMMU driver purges an entry from the +guest's translation table. + +live migration +'''''''''''''' + +When a remote process receives a live migration indication from QEMU, it +will set up a channel using the received file descriptor with +``qio_channel_socket_new_fd()``. This channel will be used to create a +*QEMUfile* that can be passed to ``qemu_save_device_state()`` to send +the process's device state back to QEMU. This method will be reversed on +restore - the channel will be passed to ``qemu_loadvm_state()`` to +restore the device state. + +Accelerating device emulation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The messages that are required to be sent between QEMU and the emulation +process can add considerable latency to IO operations. The optimizations +described below attempt to ameliorate this effect by allowing the +emulation process to communicate directly with the kernel KVM driver. +The KVM file descriptors created wold be passed to the emulation process +via initialization messages, much like the guest memory table is done. +#### MMIO acceleration + +Vhost user applications can receive guest virtio driver stores directly +from KVM. The issue with the eventfd mechanism used by vhost user is +that it does not pass any data with the event indication, so it cannot +handle guest loads or guest stores that carry store data. This concept +could, however, be expanded to cover more cases. + +The expanded idea would require a new type of KVM device: +*KVM\_DEV\_TYPE\_USER*. This device has two file descriptors: a master +descriptor that QEMU can use for configuration, and a slave descriptor +that the emulation process can use to receive MMIO notifications. QEMU +would create both descriptors using the KVM driver, and pass the slave +descriptor to the emulation process via an initialization message. + +data structures +''''''''''''''' + +- guest physical range + +The guest physical range structure describes the address range that a +device will respond to. It includes the base and length of the range, as +well as which bus the range resides on (e.g., on an x86machine, it can +specify whether the range refers to memory or IO addresses). + +A device can have multiple physical address ranges it responds to (e.g., +a PCI device can have multiple BARs), so the structure will also include +an enumerated identifier to specify which of the device's ranges is +being referred to. + ++--------+----------------------------+ +| Name | Description | ++========+============================+ +| addr | range base address | ++--------+----------------------------+ +| len | range length | ++--------+----------------------------+ +| bus | addr type (memory or IO) | ++--------+----------------------------+ +| id | range ID (e.g., PCI BAR) | ++--------+----------------------------+ + +- MMIO request structure + +This structure describes an MMIO operation. It includes which guest +physical range the MMIO was within, the offset within that range, the +MMIO type (e.g., load or store), and its length and data. It also +includes a sequence number that can be used to reply to the MMIO, and +the CPU that issued the MMIO. + ++----------+------------------------+ +| Name | Description | ++==========+========================+ +| rid | range MMIO is within | ++----------+------------------------+ +| offset | offset withing *rid* | ++----------+------------------------+ +| type | e.g., load or store | ++----------+------------------------+ +| len | MMIO length | ++----------+------------------------+ +| data | store data | ++----------+------------------------+ +| seq | sequence ID | ++----------+------------------------+ + +- MMIO request queues + +MMIO request queues are FIFO arrays of MMIO request structures. There +are two queues: pending queue is for MMIOs that haven't been read by the +emulation program, and the sent queue is for MMIOs that haven't been +acknowledged. The main use of the second queue is to validate MMIO +replies from the emulation program. + +- scoreboard + +Each CPU in the VM is emulated in QEMU by a separate thread, so multiple +MMIOs may be waiting to be consumed by an emulation program and multiple +threads may be waiting for MMIO replies. The scoreboard would contain a +wait queue and sequence number for the per-CPU threads, allowing them to +be individually woken when the MMIO reply is received from the emulation +program. It also tracks the number of posted MMIO stores to the device +that haven't been replied to, in order to satisfy the PCI constraint +that a load to a device will not complete until all previous stores to +that device have been completed. + +- device shadow memory + +Some MMIO loads do not have device side-effects. These MMIOs can be +completed without sending a MMIO request to the emulation program if the +emulation program shares a shadow image of the device's memory image +with the KVM driver. + +The emulation program will ask the KVM driver to allocate memory for the +shadow image, and will then use ``mmap()`` to directly access it. The +emulation program can control KVM access to the shadow image by sending +KVM an access map telling it which areas of the image have no +side-effects (and can be completed immediately), and which require a +MMIO request to the emulation program. The access map can also inform +the KVM drive which size accesses are allowed to the image. + +master descriptor +''''''''''''''''' + +The master descriptor is used by QEMU to configure the new KVM device. +The descriptor would be returned by the KVM driver when QEMU issues a +*KVM\_CREATE\_DEVICE* ``ioctl()`` with a *KVM\_DEV\_TYPE\_USER* type. + +KVM\_DEV\_TYPE\_USER device ops + + +The *KVM\_DEV\_TYPE\_USER* operations vector will be registered by a +``kvm_register_device_ops()`` call when the KVM system in initialized by +``kvm_init()``. These device ops are called by the KVM driver when QEMU +executes certain ``ioctl()`` operations on its KVM file descriptor. They +include: + +- create + +This routine is called when QEMU issues a *KVM\_CREATE\_DEVICE* +``ioctl()`` on its per-VM file descriptor. It will allocate and +initialize a KVM user device specific data structure, and assign the +*kvm\_device* private field to it. + +- ioctl + +This routine is invoked when QEMU issues an ``ioctl()`` on the master +descriptor. The ``ioctl()`` commands supported are defined by the KVM +device type. *KVM\_DEV\_TYPE\_USER* ones will need several commands: + +*KVM\_DEV\_USER\_SLAVE\_FD* creates the slave file descriptor thatwill +be passed to the device emulation program. Only one slave can be created +by each master descriptor. The file operations performed by this +descriptor are described below. + +The *KVM\_DEV\_USER\_PA\_RANGE* command configures a guest physical +address range that the slave descriptor will receive MMIO notifications +for. The range is specified by a guest physical range structure +argument. For buses that assign addresses to devices dynamically, this +command can be executed while the guest is running, such as the case +when a guest changes a device's PCI BAR registers. + +*KVM\_DEV\_USER\_PA\_RANGE* will use ``kvm_io_bus_register_dev()`` to +register *kvm\_io\_device\_ops* callbacks to be invoked when the guest +performs a MMIO operation within the range. When a range is changed, +``kvm_io_bus_unregister_dev()`` is used to remove the previous +instantiation. + +*KVM\_DEV\_USER\_TIMEOUT* will configure a timeout value that specifies +how long KVM will wait for the emulation process to respond to a MMIO +indication. + +- destroy + +This routine is called when the VM instance is destroyed. It will need +to destroy the slave descriptor; and free any memory allocated by the +driver, as well as the *kvm\_device* structure itself. + +slave descriptor +'''''''''''''''' + +The slave descriptor will have its own file operations vector, which +responds to system calls on the descriptor performed by the device +emulation program. + +- read + +A read returns any pending MMIO requests from the KVM driver as MMIO +request structures. Multiple structures can be returned if there are +multiple MMIO operations pending. The MMIO requests are moved from the +pending queue to the sent queue, and if there are threads waiting for +space in the pending to add new MMIO operations, they will be woken +here. + +- write + +A write also consists of a set of MMIO requests. They are compared to +the MMIO requests in the sent queue. Matches are removed from the sent +queue, and any threads waiting for the reply are woken. If a store is +removed, then the number of posted stores in the per-CPU scoreboard is +decremented. When the number is zero, and a non side-effect load was +waiting for posted stores to complete, the load is continued. + +- ioctl + +There are several ioctl()s that can be performed on the slave +descriptor. + +A *KVM\_DEV\_USER\_SHADOW\_SIZE* ``ioctl()`` causes the KVM driver to +allocate memory for the shadow image. This memory can later be +``mmap()``\ ed by the emulation process to share the emulation's view of +device memory with the KVM driver. + +A *KVM\_DEV\_USER\_SHADOW\_CTRL* ``ioctl()`` controls access to the +shadow image. It will send the KVM driver a shadow control map, which +specifies which areas of the image can complete guest loads without +sending the load request to the emulation program. It will also specify +the size of load operations that are allowed. + +- poll + +An emulation program will use the ``poll()`` call with a *POLLIN* flag +to determine if there are MMIO requests waiting to be read. It will +return if the pending MMIO request queue is not empty. + +- mmap + +This call allows the emulation program to directly access the shadow +image allocated by the KVM driver. As device emulation updates device +memory, changes with no side-effects will be reflected in the shadow, +and the KVM driver can satisfy guest loads from the shadow image without +needing to wait for the emulation program. + +kvm\_io\_device ops +''''''''''''''''''' + +Each KVM per-CPU thread can handle MMIO operation on behalf of the guest +VM. KVM will use the MMIO's guest physical address to search for a +matching *kvm\_io\_device* to see if the MMIO can be handled by the KVM +driver instead of exiting back to QEMU. If a match is found, the +corresponding callback will be invoked. + +- read + +This callback is invoked when the guest performs a load to the device. +Loads with side-effects must be handled synchronously, with the KVM +driver putting the QEMU thread to sleep waiting for the emulation +process reply before re-starting the guest. Loads that do not have +side-effects may be optimized by satisfying them from the shadow image, +if there are no outstanding stores to the device by this CPU. PCI memory +ordering demands that a load cannot complete before all older stores to +the same device have been completed. + +- write + +Stores can be handled asynchronously unless the pending MMIO request +queue is full. In this case, the QEMU thread must sleep waiting for +space in the queue. Stores will increment the number of posted stores in +the per-CPU scoreboard, in order to implement the PCI ordering +constraint above. + +interrupt acceleration +^^^^^^^^^^^^^^^^^^^^^^ + +This performance optimization would work much like a vhost user +application does, where the QEMU process sets up *eventfds* that cause +the device's corresponding interrupt to be triggered by the KVM driver. +These irq file descriptors are sent to the emulation process at +initialization, and are used when the emulation code raises a device +interrupt. + +intx acceleration +''''''''''''''''' + +Traditional PCI pin interrupts are level based, so, in addition to an +irq file descriptor, a re-sampling file descriptor needs to be sent to +the emulation program. This second file descriptor allows multiple +devices sharing an irq to be notified when the interrupt has been +acknowledged by the guest, so they can re-trigger the interrupt if their +device has not de-asserted its interrupt. + +intx irq descriptor + + +The irq descriptors are created by the proxy object +``using event_notifier_init()`` to create the irq and re-sampling +*eventds*, and ``kvm_vm_ioctl(KVM_IRQFD)`` to bind them to an interrupt. +The interrupt route can be found with +``pci_device_route_intx_to_irq()``. + +intx routing changes + + +Intx routing can be changed when the guest programs the APIC the device +pin is connected to. The proxy object in QEMU will use +``pci_device_set_intx_routing_notifier()`` to be informed of any guest +changes to the route. This handler will broadly follow the VFIO +interrupt logic to change the route: de-assigning the existing irq +descriptor from its route, then assigning it the new route. (see +``vfio_intx_update()``) + +MSI/X acceleration +'''''''''''''''''' + +MSI/X interrupts are sent as DMA transactions to the host. The interrupt +data contains a vector that is programed by the guest, A device may have +multiple MSI interrupts associated with it, so multiple irq descriptors +may need to be sent to the emulation program. + +MSI/X irq descriptor + + +This case will also follow the VFIO example. For each MSI/X interrupt, +an *eventfd* is created, a virtual interrupt is allocated by +``kvm_irqchip_add_msi_route()``, and the virtual interrupt is bound to +the eventfd with ``kvm_irqchip_add_irqfd_notifier()``. + +MSI/X config space changes + + +The guest may dynamically update several MSI-related tables in the +device's PCI config space. These include per-MSI interrupt enables and +vector data. Additionally, MSIX tables exist in device memory space, not +config space. Much like the BAR case above, the proxy object must look +at guest config space programming to keep the MSI interrupt state +consistent between QEMU and the emulation program. + +-------------- + +Disaggregated CPU emulation +--------------------------- + +After IO services have been disaggregated, a second phase would be to +separate a process to handle CPU instruction emulation from the main +QEMU control function. There are no object separation points for this +code, so the first task would be to create one. + +Host access controls +-------------------- + +Separating QEMU relies on the host OS's access restriction mechanisms to +enforce that the differing processes can only access the objects they +are entitled to. There are a couple types of mechanisms usually provided +by general purpose OSs. + +Discretionary access control +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Discretionary access control allows each user to control who can access +their files. In Linux, this type of control is usually too coarse for +QEMU separation, since it only provides three separate access controls: +one for the same user ID, the second for users IDs with the same group +ID, and the third for all other user IDs. Each device instance would +need a separate user ID to provide access control, which is likely to be +unwieldy for dynamically created VMs. + +Mandatory access control +~~~~~~~~~~~~~~~~~~~~~~~~ + +Mandatory access control allows the OS to add an additional set of +controls on top of discretionary access for the OS to control. It also +adds other attributes to processes and files such as types, roles, and +categories, and can establish rules for how processes and files can +interact. + +Type enforcement +^^^^^^^^^^^^^^^^ + +Type enforcement assigns a *type* attribute to processes and files, and +allows rules to be written on what operations a process with a given +type can perform on a file with a given type. QEMU separation could take +advantage of type enforcement by running the emulation processes with +different types, both from the main QEMU process, and from the emulation +processes of different classes of devices. + +For example, guest disk images and disk emulation processes could have +types separate from the main QEMU process and non-disk emulation +processes, and the type rules could prevent processes other than disk +emulation ones from accessing guest disk images. Similarly, network +emulation processes can have a type separate from the main QEMU process +and non-network emulation process, and only that type can access the +host tun/tap device used to provide guest networking. + +Category enforcement +^^^^^^^^^^^^^^^^^^^^ + +Category enforcement assigns a set of numbers within a given range to +the process or file. The process is granted access to the file if the +process's set is a superset of the file's set. This enforcement can be +used to separate multiple instances of devices in the same class. + +For example, if there are multiple disk devices provides to a guest, +each device emulation process could be provisioned with a separate +category. The different device emulation processes would not be able to +access each other's backing disk images. + +Alternatively, categories could be used in lieu of the type enforcement +scheme described above. In this scenario, different categories would be +used to prevent device emulation processes in different classes from +accessing resources assigned to other classes.Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 48/49] multi-process: add the concept description to docs/devel/qemu-multiprocess
In reply to Jagannathan RamanQuoted 11 lines · Jagannathan Raman
docs/devel/qemu-multiprocess.rst new file +5
-0@@ -0,0 +1,1102 @@ +Disaggregating QEMU +=================== + +QEMU is often used as the hypervisor for virtual machines running in the +Oracle cloud. Since one of the advantages of cloud computing is the
docs/devel/qemu-multiprocess.rst line 15
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+ability to run many VMs from different tenants in the same cloud +infrastructure, a guest that compromised its hypervisor could +potentially use the hypervisor's access privileges to access data it is +not authorized for. + +QEMU can be susceptible to security attack because it is a large, +monolithic program that provides many features to the VMs it services. +Many of these feature can be configured out of QEMU, but even a reduced +configuration QEMU has a large amount of code a guest can potentially +attack in order to gain additional privileges.
The "additional privileges" are only host userspace code execution (i.e. syscalls) within an unprivileged process that is sandboxed using seccomp and SELinux on a properly configured system. If QEMU has access to resources that do not belong to the guest then you have not configured QEMU correctly (libvirt handles a lot of this setup for you).
I think it's more accurate to describe the motivation for multi-process QEMU in terms of the principle of least privilege: each component in the system should only have access to the resources that it needs to perform its job. That way people don't get the impression that QEMU is a trusted component with access to resources that must be kept from the guest.
Quoted 16 lines
docs/devel/qemu-multiprocess.rst new file +16
-0+QEMU services +------------- + +QEMU can be broadly described as providing three main services. One is a +VM control point, where VMs can be created, migrated, re-configured, and +destroyed. A second is to emulate the CPU instructions within the VM, +often accelerated by HW virtualization features such as Intel's VT +extensions. Finally, it provides IO services to the VM by emulating HW +IO devices, such as disk and network devices. + +A disaggregated QEMU +~~~~~~~~~~~~~~~~~~~~ + +A disaggregated QEMU involves separating QEMU services into separate +host processes. Each of these processes can be given only the privileges +it needs to provide its service, e.g., a disk service could be given
docs/devel/qemu-multiprocess.rst line 42
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+access only the the disk images it provides, and not be allowed to +access other files, or any network devices. An attacker who compromised +this service would not be able to use this exploit to access files or +devices beyond what the disk service was given access to. + +A QEMU control process would remain, but in disaggregated mode, it would +be a control point that executes the processes needed to support the VM +being created, but have no direct interfaces to the VM. During VM +execution, it would still provide the user interface to hot-plug devices +or live migrate the VM.
"it would be a control point that executes the processes needed to support the VM being created"
libvirt does the sandboxing setup. I think the responsibility of executing and sandboxing device processes would also be left to libvirt, not to QEMU.
Perhaps it's best to leave this sentence out and enable both approaches (1. QEMU executes device processes, 2. management tool executes device processes).
Quoted 181 lines
docs/devel/qemu-multiprocess.rst new file +181
-0+A first step in creating a disaggregated QEMU is to separate IO services +from the main QEMU program, which would continue to provide CPU +emulation. i.e., the control process would also be the CPU emulation +process. In a later phase, CPU emulation could be separated from the +control process. + +Disaggregating IO services +-------------------------- + +Disaggregating IO services is a good place to begin QEMU disaggregating +for a couple of reasons. One is the sheer number of IO devices QEMU can +emulate provides a large surface of interfaces which could potentially +be exploited, and, indeed, have been a source of exploits in the past. +Another is the modular nature of QEMU device emulation code provides +interface points where the QEMU functions that perform device emulation +can be separated from the QEMU functions that manage the emulation of +guest CPU instructions. + +QEMU device emulation +~~~~~~~~~~~~~~~~~~~~~ + +QEMU uses a object oriented SW architecture for device emulation code. +Configured objects are all compiled into the QEMU binary, then objects +are instantiated by name when used by the guest VM. For example, the +code to emulate a device named "foo" is always present in QEMU, but its +instantiation code is only run when the device is included in the target +VM. (e.g., via the QEMU command line as *-device foo*) + +The object model is hierarchical, so device emulation code names its +parent object (such as "pci-device" for a PCI device) and QEMU will +instantiate a parent object before calling the device's instantiation +code. + +Current separation models +~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to separate the device emulation code from the CPU emulation +code, the device object code must run in a different process. There are +a couple of existing QEMU features that can run emulation code +separately from the main QEMU process. These are examined below. + +vhost user model +^^^^^^^^^^^^^^^^ + +Virtio guest device drivers can be connected to vhost user applications +in order to perform their IO operations. This model uses special virtio +device drivers in the guest and vhost user device objects in QEMU, but +once the QEMU vhost user code has configured the vhost user application, +mission-mode IO is performed by the application. The vhost user +application is a daemon process that can be contacted via a known UNIX +domain socket. + +vhost socket +'''''''''''' + +As mentioned above, one of the tasks of the vhost device object within +QEMU is to contact the vhost application and send it configuration +information about this device instance. As part of the configuration +process, the application can also be sent other file descriptors over +the socket, which then can be used by the vhost user application in +various ways, some of which are described below. + +vhost MMIO store acceleration +''''''''''''''''''''''''''''' + +VMs are often run using HW virtualization features via the KVM kernel +driver. This driver allows QEMU to accelerate the emulation of guest CPU +instructions by running the guest in a virtual HW mode. When the guest +executes instructions that cannot be executed by virtual HW mode, +execution returns to the KVM driver so it can inform QEMU to emulate the +instructions in SW. + +One of the events that can cause a return to QEMU is when a guest device +driver accesses an IO location. QEMU then dispatches the memory +operation to the corresponding QEMU device object. In the case of a +vhost user device, the memory operation would need to be sent over a +socket to the vhost application. This path is accelerated by the QEMU +virtio code by setting up an eventfd file descriptor that the vhost +application can directly receive MMIO store notifications from the KVM +driver, instead of needing them to be sent to the QEMU process first. + +vhost interrupt acceleration +'''''''''''''''''''''''''''' + +Another optimization used by the vhost application is the ability to +directly inject interrupts into the VM via the KVM driver, again, +bypassing the need to send the interrupt back to the QEMU process first. +The QEMU virtio setup code configures the KVM driver with an eventfd +that triggers the device interrupt in the guest when the eventfd is +written. This irqfd file descriptor is then passed to the vhost user +application program. + +vhost access to guest memory +'''''''''''''''''''''''''''' + +The vhost application is also allowed to directly access guest memory, +instead of needing to send the data as messages to QEMU. This is also +done with file descriptors sent to the vhost user application by QEMU. +These descriptors can be passed to ``mmap()`` by the vhost application +to map the guest address space into the vhost application. + +IOMMUs introduce another level of complexity, since the address given to +the guest virtio device to DMA to or from is not a guest physical +address. This case is handled by having vhost code within QEMU register +as a listener for IOMMU mapping changes. The vhost application maintains +a cache of IOMMMU translations: sending translation requests back to +QEMU on cache misses, and in turn receiving flush requests from QEMU +when mappings are purged. + +applicability to device separation +'''''''''''''''''''''''''''''''''' + +Much of the vhost model can be re-used by separated device emulation. In +particular, the ideas of using a socket between QEMU and the device +emulation application, using a file descriptor to inject interrupts into +the VM via KVM, and allowing the application to ``mmap()`` the guest +should be re used. + +There are, however, some notable differences between how a vhost +application works and the needs of separated device emulation. The most +basic is that vhost uses custom virtio device drivers which always +trigger IO with MMIO stores. A separated device emulation model must +work with existing IO device models and guest device drivers. MMIO loads +break vhost store acceleration since they are synchronous - guest +progress cannot continue until the load has been emulated. By contrast, +stores are asynchronous, the guest can continue after the store event +has been sent to the vhost application. + +Another difference is that in the vhost user model, a single daemon can +support multiple QEMU instances. This is contrary to the security regime +desired, in which the emulation application should only be allowed to +access the files or devices the VM it's running on behalf of can access. +#### qemu-io model + +Qemu-io is a test harness used to test changes to the QEMU block backend +object code. (e.g., the code that implements disk images for disk driver +emulation) Qemu-io is not a device emulation application per se, but it +does compile the QEMU block objects into a separate binary from the main +QEMU one. This could be useful for disk device emulation, since its +emulation applications will need to include the QEMU block objects. + +New separation model based on proxy objects +------------------------------------------- + +A different model based on proxy objects in the QEMU program +communicating with remote emulation programs could provide separation +while minimizing the changes needed to the device emulation code. The +rest of this section is a discussion of how a proxy object model would +work. + +Remote emulation processes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The remote emulation process will run the QEMU object hierarchy without +modification. The device emulation objects will be also be based on the +QEMU code, because for anything but the simplest device, it would not be +a tractable to re-implement both the object model and the many device +backends that QEMU has. + +The processes will communicate with the QEMU process over UNIX domain +sockets. The processes can be executed either as standalone processes, +or be executed by QEMU. In both cases, the host backends the emulation +processes will provide are specified on its command line, as they would +be for QEMU. For example: + +:: + + disk-proc -blockdev driver=file,node-name=file0,filename=disk-file0 \ + -blockdev driver=qcow2,node-name=drive0,file=file0 + +would indicate process *disk-proc* uses a qcow2 emulated disk named +*file0* as its backend. + +Emulation processes may emulate more than one guest controller. A common +configuration might be to put all controllers of the same device class +(e.g., disk, network, etc.) in a single process, so that all backends of +the same type can be managed by a single QMP monitor. + +communication with QEMU +^^^^^^^^^^^^^^^^^^^^^^^ +
docs/devel/qemu-multiprocess.rst line 234
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+Remote emulation processes will recognize a *-socket* argument that +specifies the path of a UNIX domain socket used to communicate with the +QEMU process. If no *-socket* argument is present, the process will use +file descriptor 0 to communicate with QEMU. For example, + +:: + + disk-proc -socket /tmp/disk0-sock <backend list> + +will communicate with QEMU using the socket path */tmp/dik0-sock*.
s/dik/disk/
Quoted 42 lines
docs/devel/qemu-multiprocess.rst new file +42
-0+ +remote process QMP monitor +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes can be monitored via QMP, similar to QEMU +itself. The QMP monitor socket is specified the same as for a QEMU +process: + +:: + + disk-proc -qmp unix:/tmp/disk-mon,server + +can be monitored over the UNIX socket path */tmp/disk-mon*. + +QEMU command line +~~~~~~~~~~~~~~~~~ + +The QEMU command line options will need to be modified to indicate which +items are emulated by a separate program, and which remain emulated by +QEMU itself. + +identifying remote emulation processes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes will be identified to QEMU using a *-remote* +command line option. This option can either specify a command that QEMU +will execute, or can specify a UNIX domain socket that QEMU can use to +connect to an existing process. Both forms require a "id" option that +identifies the process to later *-device* options. The process version +is: + +:: + + -remote id=disk-proc,command="disk-proc <backend list>" + +And the socket version is: + +:: + + -remote id=disk-proc,socket="/tmp/disk0-sock" + +In the latter case, the remote process must be given the same socket on
docs/devel/qemu-multiprocess.rst line 286
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+its command line when it is executed: + +:: + + disk-proc -socket /tmp/disk0-sock <backend list> + +identifying devices emulated remotely +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Devices that are to be emulated in a separate process will be identify
s/be//
Quoted 6 lines
docs/devel/qemu-multiprocess.rst new file +6
-0+the remote process with a "remote" option on their *-device* command +line specification. e.g., an LSI SCSI controller and disk can be +specified as: + +:: +
docs/devel/qemu-multiprocess.rst line 302
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+ -device lsi53c895a,id=scsi0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + +If these devices are emulated by remote process "disk-proc," as +described in the previous section, the QEMU command line would be: + +:: + + -device lsi53c895a,id=scsi0,remote=disk-proc + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,remote=disk-proc
The next patch documents rid=. This seems to be the same as remote=? Please use remote= everywhere.
docs/devel/qemu-multiprocess.rst line 314
Quoted 12 lines
docs/devel/qemu-multiprocess.rst new file +12
-0+ +Some devices are implicitly created by the machine object. e.g., the q35 +machine object will create its PCI bus, and attach an ich9-ahci IDE +controller to it. In this case, options will need to be added to the +*-machine* command line. e.g., + +:: + + -machine pc-q35,ide-remote=disk-proc + +will use the remote process with an "id" of "disk-proc" to emulate the +IDE controller and its disks.
It might be possible to avoid introducing special-purpose *-remote= parameters using the -set command-line option. If you know the id of the on-board device then you can set the remote= property on it:
-set piix4-ide.ide0.remote=disk-proc
I haven't tried this but if it works then no code changes are required.
Quoted 57 lines
docs/devel/qemu-multiprocess.rst new file +57
-0+The disks themselves still need to be specified with *-remote* option, +as in the example above. e.g., + +:: + + -device ide-hd,drive=drive0,bus=ide.0,unit=0,remote=disk-proc + +QEMU management of remote processes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Each *-remote* instance on the QEMU command line will create a remote +process proxy instance in QEMU. They will be held on a *QList* that can +be searched for by its "id" property. The remote process proxy will also +establish a communication channel between QEMU and the remote process. +This can be done in one of two methods: direction execution of the +process by QEMU with ``fork()`` and ``exec()`` system calls, or by +connecting to an existing process. + +direct execution +^^^^^^^^^^^^^^^^ + +When the remote process is directly executed, the remote process proxy +will setup a communication channel between itself and the emulation +process. This channel will be created using ``socketpair()`` and the +remote process side of the pair will be given to the process as file +descriptor 0. + +connecting to an existing process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Some environments wish to deny QEMU the ability to execute ``fork()`` +and ``exec()`` In these case, emulation processes will be started before +QEMU, and a UNIX domain socket will be given to each emulation process +to communicate with QEMU over. After communication is established, the +socket will be unlinked from the file system space by the QEMU process. + +communication with emulation process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +primary socket +'''''''''''''' + +Whether the process was executed by QEMU or externally, there will be a +primary socket for communication between QEMU and the remote process. +This channel will handle configuration commands from QEMU to the +process, either from the QEMU command line, or from QMP commands that +affect the devices being emulated by the process. This channel will only +allow one message to be pending at a time; if additional messages +arrive, they must wait for previous ones to be acknowledged from the +remote side. + +secondary sockets +''''''''''''''''' + +The primary socket can pass the file descriptors of secondary sockets +for operations that occur in parallel with commands on the primary +channel. These include MMIO operations generated by the guest, interrupt
docs/devel/qemu-multiprocess.rst line 382
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+notifications generated by the devices being emulated, or *vmstate* for +live migration. These secondary sockets will be created at the behest of +the device proxies that require them. A disk device proxy wouldn't need +any secondary sockets, but a disk controller device proxy may need both +an MMIO socket and an interrupt socket. + +emulation process attached via QMP command +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There will be a new "attach-process" QMP command to facilitate device
The QMP command name "remote-add" would be consistent with object-add. (There is also netdev_add and device_add but their names use underscores for legacy reasons.)
Quoted 18 lines
docs/devel/qemu-multiprocess.rst new file +18
-0+hot-plug. This command's arguments will be the same as the *-remote* +command line when it's used to attach to a remote process. i.e., it will +need an "id" argument so that hot-plugged devices can later find it, and +a "socket" argument to identify the UNIX domain socket that will be used +to communicate with QEMU. + +QEMU device proxy objects +~~~~~~~~~~~~~~~~~~~~~~~~~ + +QEMU has an object model based on sub-classes inherited from the +"object" super-class. The sub-classes that are of interest here are the +"device" and "bus" sub-classes whose child sub-classes make up the +device tree of a QEMU emulated system. + +The proxy object model will use device proxy objects to replace the +device emulation code within the QEMU process. These objects will live +in the same place in the object and bus hierarchies as the objects they +replace. i.e., the proxy object for an LSI SCSI controller will be a
docs/devel/qemu-multiprocess.rst line 410
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+sub-class of the "pci-device" class, and will have the same PCI bus +parent and the same SCSI bus child objects as the LSI controller object +it replaces. + +After the QEMU command line has been parsed, the remote devices will be +instantiated in the same manner as local devices are. (i.e., +``qdev_device_add()``). In order to distinguish them from regular +*-device* device objects, their class name will be the name of the class +it replaces, with "-proxy" appended. e.g., the "lsi53c895a" proxy class +will be "lsi53c895a-proxy."
Did you consider defining just -device pci-device-proxy,remote=ID and then transferring the device-specific details (e.g. PCI Configuration Space, BARs, and interrupt configuration) over the socket during initialization?
That way it's not necessary to write proxy devices. There is just one PCI proxy device that automatically reflects the information from the device emulation process.
Quoted 115 lines
docs/devel/qemu-multiprocess.rst new file +115
-0+ +device JSON description +^^^^^^^^^^^^^^^^^^^^^^^ + +The remote process needs a JSON representation of the command line +options used to create the object. This JSON representation is used to +create the corresponding object in the emulation process. e.g., for an +LSI SCSI controller invoked as: + +:: + + -device lsi53c895a,id=scsi0,remote=lsi-scsi + +the proxy object would create a + +:: + + { "driver" : "lsi53c895a", "id" : "scsi0" } + +JSON description. The "driver" option is assigned to the device name +when the command line is parsed, so the "-proxy" appended by the command +line parsing code is removed. The "remote" option isn't needed in the +JSON description since it only applies to the proxy object in the QEMU +process. + +device object whitelist +^^^^^^^^^^^^^^^^^^^^^^^ + +Some device objects may not need a proxy. These are devices with no +direct guest interfaces. (e.g., no MMIO, PIO, or interrupts). There will +be a whitelist of such devices, and any devices on this list will not be +instantiated in QEMU. Their JSON representation will still be sent to +the remote process, so the object can be created there. + +object initialization +^^^^^^^^^^^^^^^^^^^^^ + +QEMU object initialization occurs in two phases. The first +initialization happens once per object class. (i.e., there can be many +SCSI disks in an emulated system, but the "scsi-hd" class has its +``class_init()`` function called only once) The second phase happens +when each object's ``instance_init()`` function is called to initialize +each instance of the object. + +All device objects are sub-classes of the "device" class, so they also +have a ``realize()`` function that is called after ``instance_init()`` +is called and after the object's static properties have been +initialized. Many device objects don't even provide an instance\_init() +function, and do all their per-instance work in ``realize()``. + +class\_init +''''''''''' + +The ``class_init()`` method of a proxy object will, in general behave +similarly to the object it replaces, including setting any static +properties and methods needed by the proxy. + +instance\_init / realize +'''''''''''''''''''''''' + +The ``instance_init()`` and ``realize()`` functions would only need to +perform tasks related to being a proxy, such are registering its own +MMIO handlers, or creating a child bus that other proxy devices can be +attached to later. + +Other tasks will are device-specific. For example, PCI device objects +will initialize the PCI config space in order to make a valid PCI device +tree within the QEMU process. + +address space registration +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Most devices are driven by guest device driver accesses to IO addresses +or ports. The QEMU device emulation code uses QEMU's memory region +function calls (such as ``memory_region_init_io()``) to add callback +functions that QEMU will invoke when the guest accesses the device's +areas of the IO address space. When a guest driver does access the +device, the VM will exit HW virtualization mode and return to QEMU, +which will then lookup and execute the corresponding callback function. + +A proxy object would need to mirror the memory region calls the actual +device emulator would perform in its initialization code, but with its +own callbacks. When invoked by QEMU as a result of a guest IO operation, +they will forward the operation to the device emulation process. + +PCI config space +^^^^^^^^^^^^^^^^ + +PCI devices also have a configuration space that can be accessed by the +guest driver. Guest accesses to this space is not handled by the device +emulation object, but by its PCI parent object. Much of this space is +read-only, but certain registers (especially BAR and MSI-related ones) +need to be propagated to the emulation process. + +PCI parent proxy +'''''''''''''''' + +One way to propagate guest PCI config accesses is to create a +"pci-device-proxy" class that can serve as the parent of a PCI device +proxy object. This class's parent would be "pci-device" and it would +override the PCI parent's ``config_read()`` and ``config_write()`` +methods with ones that forward these operations to the emulation +program. + +interrupt receipt +^^^^^^^^^^^^^^^^^ + +A proxy for a device that generates interrupts will need to create a +socket to receive interrupt indications from the emulation process. An +incoming interrupt indication would then be sent up to its bus parent to +be injected into the guest. For example, a PCI device object may use +``pci_set_irq()``. + +live migration +^^^^^^^^^^^^^^
docs/devel/qemu-multiprocess.rst line 535
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+ +The proxy will register to save and restore any *vmstate* it needs over +a live migration event. The device proxy does not need to manage the +remote device's *vmstate*; that will be handled by the remote process +proxy (see below). + +QEMU remote device operation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Generic device operations, such as DMA, will be performs by the remote
s/performs/performed/
Quoted 22 lines
docs/devel/qemu-multiprocess.rst new file +22
-0+process proxy by sending messages to the remote process. + +DMA operations +^^^^^^^^^^^^^^ + +DMA operations would be handled much like vhost applications do. One of +the initial messages sent to the emulation process is a guest memory +table. Each entry in this table consists of a file descriptor and size +that the emulation process can ``mmap()`` to directly access guest +memory, similar to ``vhost_user_set_mem_table()``. Note guest memory +must be backed by file descriptors, such as when QEMU is given the +*-mem-path* command line option. + +IOMMU operations +^^^^^^^^^^^^^^^^ + +When the emulated system includes an IOMMU, the remote process proxy in +QEMU will need to create a socket for IOMMU requests from the emulation +process. It will handle those requests with an +``address_space_get_iotlb_entry()`` call. In order to handle IOMMU +unmaps, the remote process proxy will also register as a listener on the +device's DMA address space. When an IOMMU memory region is created
docs/devel/qemu-multiprocess.rst line 567
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+within the DMA address space, an IOMMU notifier for unmaps will be added +to the memory region that will forward unmaps to the emulation process +over the IOMMU socket. + +device hot-plug via QMP +^^^^^^^^^^^^^^^^^^^^^^^ + +An QMP "device\_add" command can add a device emulated by a remote +process. It needs to add a "remote" option to the command, just as the +*-device* command line option does. The remote process may either be one
device_add parameters are parsed by the same code as -device. It shouldn't be necessary to add a "remote" option to device_add.
Quoted 136 lines
docs/devel/qemu-multiprocess.rst new file +136
-0+started at QEMU startup, or be one added by the "add-process" QMP +command described above. In either case, the remote process proxy will +forward the new device's JSON description to the corresponding emulation +process. + +live migration +^^^^^^^^^^^^^^ + +The remote process proxy will also register for live migration +notifications with ``vmstate_register()``. When called to save state, +the proxy will send the remote process a secondary socket file +descriptor to save the remote process's device *vmstate* over. The +incoming byte stream length and data will be saved as the proxy's +*vmstate*. When the proxy is resumed on its new host, this *vmstate* +will be extracted, and a secondary socket file descriptor will be sent +to the new remote process through which it receives the *vmstate* in +order to restore the devices there. + +device emulation in remote process +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The parts of QEMU that the emulation program will need include the +object model; the memory emulation objects; the device emulation objects +of the targeted device, and any dependent devices; and, the device's +backends. It will also need code to setup the machine environment, +handle requests from the QEMU process, and route machine-level requests +(such as interrupts or IOMMU mappings) back to the QEMU process. + +initialization +'''''''''''''' + +The process initialization sequence will follow the same sequence +followed by QEMU. It will first initialize the backend objects, then +device emulation objects. The JSON descriptions sent by the QEMU process +will drive which objects need to be created. + +- address spaces + +Before the device objects are created, the initial address spaces and +memory regions must be configured with ``memory_map_init()``. This +creates a RAM memory region object (*system\_memory*) and an IO memory +region object (*system\_io*). + +- RAM + +RAM memory region creation will follow how ``pc_memory_init()`` creates +them, but must use ``memory_region_init_ram_from_fd()`` instead of +``memory_region_allocate_system_memory()``. The file descriptors needed +will be supplied by the guest memory table from above. Those RAM regions +would then be added to the *system\_memory* memory region with +``memory_region_add_subregion()``. + +- PCI + +IO initialization will be driven by the JSON descriptions sent from the +QEMU process. For a PCI device, a PCI bus will need to be created with +``pci_root_bus_new()``, and a PCI memory region will need to be created +and added to the *system\_memory* memory region with +``memory_region_add_subregion_overlap()``. The overlap version is +required for architectures where PCI memory overlaps with RAM memory. + +MMIO handling +''''''''''''' + +The device emulation objects will use ``memory_region_init_io()`` to +install their MMIO handlers, and ``pci_register_bar()`` to associate +those handlers with a PCI BAR, as they do within QEMU currently. + +In order to use ``address_space_rw()`` in the emulation process to +handle MMIO requests from QEMU, the PCI physical addresses must be the +same in the QEMU process and the device emulation process. In order to +accomplish that, guest BAR programming must also be forwarded from QEMU +to the emulation process. + +interrupt injection +''''''''''''''''''' + +When device emulation wants to inject an interrupt into the VM, the +request climbs the device's bus object hierarchy until the point where a +bus object knows how to signal the interrupt to the guest. The details +depend on the type of interrupt being raised. + +- PCI pin interrupts + +On x86 systems, there is an emulated IOAPIC object attached to the root +PCI bus object, and the root PCI object forwards interrupt requests to +it. The IOAPIC object, in turn, calls the KVM driver to inject the +corresponding interrupt into the VM. The simplest way to handle this in +an emulation process would be to setup the root PCI bus driver (via +``pci_bus_irqs()``) to send a interrupt request back to the QEMU +process, and have the device proxy object reflect it up the PCI tree +there. + +- PCI MSI/X interrupts + +PCI MSI/X interrupts are implemented in HW as DMA writes to a +CPU-specific PCI address. In QEMU on x86, a KVM APIC object receives +these DMA writes, then calls into the KVM driver to inject the interrupt +into the VM. A simple emulation process implementation would be to send +the MSI DMA address from QEMU as a message at initialization, then +install an address space handler at that address which forwards the MSI +message back to QEMU. + +DMA operations +'''''''''''''' + +When a emulation object wants to DMA into or out of guest memory, it +first must use dma\_memory\_map() to convert the DMA address to a local +virtual address. The emulation process memory region objects setup above +will be used to translate the DMA address to a local virtual address the +device emulation code can access. + +IOMMU +''''' + +When an IOMMU is in use in QEMU, DMA translation uses IOMMU memory +regions to translate the DMA address to a guest physical address before +that physical address can be translated to a local virtual address. The +emulation process will need similar functionality. + +- IOTLB cache + +The emulation process will maintain a cache of recent IOMMU translations +(the IOTLB). When the translate() callback of an IOMMU memory region is +invoked, the IOTLB cache will be searched for an entry that will map the +DMA address to a guest PA. On a cache miss, a message will be sent back +to QEMU requesting the corresponding translation entry, which be both be +used to return a guest address and be added to the cache. + +- IOTLB purge + +The IOMMU emulation will also need to act on unmap requests from QEMU. +These happen when the guest IOMMU driver purges an entry from the +guest's translation table. + +live migration
docs/devel/qemu-multiprocess.rst line 713
Quoted 10 lines
docs/devel/qemu-multiprocess.rst new file +10
-0+'''''''''''''' + +When a remote process receives a live migration indication from QEMU, it +will set up a channel using the received file descriptor with +``qio_channel_socket_new_fd()``. This channel will be used to create a +*QEMUfile* that can be passed to ``qemu_save_device_state()`` to send +the process's device state back to QEMU. This method will be reversed on +restore - the channel will be passed to ``qemu_loadvm_state()`` to +restore the device state. +
I have reviewed up to here... :)
Re: [RFC v4 PATCH 48/49] multi-process: add the concept description to docs/devel/qemu-multiprocess
In reply to Jagannathan Ramandocs/devel/qemu-multiprocess.rst line 721
Quoted 8 lines · Jagannathan Raman
docs/devel/qemu-multiprocess.rst new file +8
-0+Accelerating device emulation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The messages that are required to be sent between QEMU and the emulation +process can add considerable latency to IO operations. The optimizations +described below attempt to ameliorate this effect by allowing the +emulation process to communicate directly with the kernel KVM driver. +The KVM file descriptors created wold be passed to the emulation process
s/wold/would/
I skipped the acceleration section for now because they require kvm.ko changes. I'll focus the remainder of the review on the patches as they are now.
RFC PATCH v4 49/49 multi-process: add configure and usage information
In reply to Jagannathan RamanFrom: Elena Ufimtseva <[email protected]>
--- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/qemu-multiprocess.txt
docs/qemu-multiprocess.txt new file +86 -0
@@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows: + + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device <device options>,rid="remote process id" + + For exmaple, for non multi-process qemu: + -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command" + suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in the + process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \ + -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdio + + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -a
Signature · 1 line
1.8.3.1
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 39 lines · Jagannathan Raman
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]>--- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/qemu-multiprocess.txtdocs/qemu-multiprocess.txt new file +23
-0@@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows:
docs/qemu-multiprocess.txt line 33
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device <device options>,rid="remote process id" + + For exmaple, for non multi-process qemu:
s/exmaple/example/
docs/qemu-multiprocess.txt line 43
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command"
s/is added/are added/
docs/qemu-multiprocess.txt line 56
Quoted 13 lines
docs/qemu-multiprocess.txt new file +13
-0+ suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in the
s/subtion/sub-option/
Quoted 20 lines
docs/qemu-multiprocess.txt new file +20
-0+ process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \
docs/qemu-multiprocess.txt line 86
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdio + + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -a
This documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Remote processes require accesses to resources that the main QEMU process does not need access to, so I'm wondering how this process model ensures that each process has only the privileges it needs.
Stefan
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 7 lines · Stefan Hajnoczi
This documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Remote processes require accesses to resources that the main QEMU process does not need access to, so I'm wondering how this process model ensures that each process has only the privileges it needs.
I guess you have something like capabilities in mind?
When using something like selinux, priviledges are per binary so the order of startup doesn't matter.
Signature · 1 line
MST
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Stefan Hajnoczi
This documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Remote processes require accesses to resources that the main QEMU process does not need access to, so I'm wondering how this process model ensures that each process has only the privileges it needs.
I guess you have something like capabilities in mind?
Or namespaces (unshare(2)).
Quoted 2 lines
When using something like selinux, priviledges are per binary so the order of startup doesn't matter.
For static SELinux policies that make sense, thanks for explaining.
Does libvirt also perform dynamic (i.e. per-instance) SELinux configuration? I guess that cannot be associated with a specific binary because multiple QEMU instances launch the same binary yet need to be differentiated.
Stefan
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 17 lines · Stefan Hajnoczi
Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Stefan Hajnoczi
This documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Remote processes require accesses to resources that the main QEMU process does not need access to, so I'm wondering how this process model ensures that each process has only the privileges it needs.
I guess you have something like capabilities in mind?
Or namespaces (unshare(2)).
Quoted 2 lines
When using something like selinux, priviledges are per binary so the order of startup doesn't matter.
Quoted 6 lines
For static SELinux policies that make sense, thanks for explaining.
Does libvirt also perform dynamic (i.e. per-instance) SELinux configuration? I guess that cannot be associated with a specific binary because multiple QEMU instances launch the same binary yet need to be differentiated.
In a traditional SELinux approach, the SELinux context used for any process is determined by a combination of the label on the binary and a transition rule.
eg if the qemu-system-x86_64 file is labelled qemu_exec_t, and there's a context qemu_t for the QEMU process, a transition rule is defined "virtd_t + qemu_exec_t -> qemu_t". This says that when a process with context "vird_t" execs a binary labelled qemu_exec_t, the new process gets qemu_t.
We sVirt, however, we can't rely on automatic transitions, because we need to assign a unique MCS tag for each VM. Thus libvird will explicitly tell SELinux what label to apply.
In the case of multiprocess QEMU, if using sVirt from libvirt, then we'll need to continue setting the explicit labels as we'll still need the MCS tags for each helper process.
If not using libvirt and sVirt, and wanting automatic SELinux transitions for QEMU helper processes, then each helper would need to be a separate binary on disk so that each helper can be given a distinct file label, which in turns lets you define a set of transitions for each helper according to its expected access needs.
Having said all that I don't think its worth worrying about this. Anyone who cares about SELinux with QEMU will want to be using sVirt or an equivalent approach to assign unique MCS per VM. And thus automatic transitions are not possible even if we had distinct binaries for each helper.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
In reply to Stefan HajnocziQuoted 108 lines · Stefan Hajnoczi
Quoted 39 lines · Jagannathan Raman
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]>--- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/qemu-multiprocess.txtdocs/qemu-multiprocess.txt new file +23
-0@@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows:docs/qemu-multiprocess.txt line 33
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device <device options>,rid="remote process id" + + For exmaple, for non multi-process qemu:s/exmaple/example/
docs/qemu-multiprocess.txt line 43
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command"s/is added/are added/
docs/qemu-multiprocess.txt line 56
Quoted 13 lines
docs/qemu-multiprocess.txt new file +13
-0+ suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in thes/subtion/sub-option/
Quoted 26 lines
docs/qemu-multiprocess.txt new file +26
-0+ process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \ + -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdio
Quoted 8 lines
docs/qemu-multiprocess.txt line 86
Quoted 4 lines
docs/qemu-multiprocess.txt new file +4
-0+ + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -aThis documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
This syntax is for the simple case without privilege separation. If differing privilege levels are needed, then whatever spawns QEMU should spawn the remote helper process ahead of time, and then just pass the UNIX socket path to the -remote arg, instead of using the 'command' parameter.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 118 lines · Daniel P. Berrangé
Quoted 108 lines · Stefan Hajnoczi
Quoted 39 lines · Jagannathan Raman
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]>--- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)create mode 100644
docs/qemu-multiprocess.txtdocs/qemu-multiprocess.txt new file +23
-0@@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows:docs/qemu-multiprocess.txt line 33
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device <device options>,rid="remote process id" + + For exmaple, for non multi-process qemu:s/exmaple/example/
docs/qemu-multiprocess.txt line 43
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command"s/is added/are added/
docs/qemu-multiprocess.txt line 56
Quoted 13 lines
docs/qemu-multiprocess.txt new file +13
-0+ suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in thes/subtion/sub-option/
Quoted 26 lines
docs/qemu-multiprocess.txt new file +26
-0+ process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \ + -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdioQuoted 8 lines
docs/qemu-multiprocess.txt line 86
Quoted 4 lines
docs/qemu-multiprocess.txt new file +4
-0+ + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -aThis documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Quoted 8 lines
This syntax is for the simple case without privilege separation. If differing privilege levels are needed, then whatever spawns QEMU should spawn the remote helper process ahead of time, and then just pass the UNIX socket path to the -remote arg, instead of using the 'command' parameter.
Regards,
Daniel
Thank You, Stefan, Michael & Daniel, for your comments. I had a chance to sit down with my teammates to understand the feedback you gave at the KVM Forum. Thank you for that, as well.
We currently support two ways of launching the remote process - one is self-launch through QEMU, as outlined in this patch series. The other approach is using an Orchestrator like libvirt (we haven't had the chance to submit those patches for review yet).
In the case where libvirt is involved, it would assume the responsibility of spawning the remote process first and pass in the info required to connect to the remote process via command-line arguments to QEMU. This support in QEMU is available in the current series. We haven't sent the libvirt side of patches out for review yet. It would be easier to upstream libvirt once the QEMU side of things is firmed up.
In the case of self-launch, our understanding is that QEMU has the privilege to fork() the remote process until the "-sandbox" argument is processed. However, if an Orchestrator prohibits QEMU from spawning other processes from the get-go, then the Orchestrator would assume the responsibility of spawning the remote process as well - like Daniel just pointed out.
In both cases, we intend to apply the security policies required to confine the remote process externally - probably through SELinux. We haven't had the chance to upstream the SELinux policies yet, but we previously sent a sample of the policies for your comments. Like Michael pointed out earlier, the SELinux policies are per binary.
Thank you very much!
--
Jag
Quoted 1 line
Re: [RFC v4 PATCH 49/49] multi-process: add configure and usage information
Quoted 153 lines · Jag Raman
Quoted 118 lines · Daniel P. Berrangé
Quoted 108 lines · Stefan Hajnoczi
Quoted 39 lines · Jagannathan Raman
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]>--- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)create mode 100644
docs/qemu-multiprocess.txtdocs/qemu-multiprocess.txt new file +23
-0@@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows:docs/qemu-multiprocess.txt line 33
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device <device options>,rid="remote process id" + + For exmaple, for non multi-process qemu:s/exmaple/example/
docs/qemu-multiprocess.txt line 43
Quoted 10 lines
docs/qemu-multiprocess.txt new file +10
-0+ -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command"s/is added/are added/
docs/qemu-multiprocess.txt line 56
Quoted 13 lines
docs/qemu-multiprocess.txt new file +13
-0+ suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in thes/subtion/sub-option/
Quoted 26 lines
docs/qemu-multiprocess.txt new file +26
-0+ process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \ + -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdioQuoted 8 lines
docs/qemu-multiprocess.txt line 86
Quoted 4 lines
docs/qemu-multiprocess.txt new file +4
-0+ + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -aThis documentation suggests that QEMU spawns the remote processes. How do this work with unprivileged QEMU? Is there an additional step where QEMU drops privileges after having spawned remote processes?
Quoted 8 lines
This syntax is for the simple case without privilege separation. If differing privilege levels are needed, then whatever spawns QEMU should spawn the remote helper process ahead of time, and then just pass the UNIX socket path to the -remote arg, instead of using the 'command' parameter.
Regards,
DanielThank You, Stefan, Michael & Daniel, for your comments. I had a chance to sit down with my teammates to understand the feedback you gave at the KVM Forum. Thank you for that, as well.
We currently support two ways of launching the remote process - one is self-launch through QEMU, as outlined in this patch series. The other approach is using an Orchestrator like libvirt (we haven't had the chance to submit those patches for review yet).
In the case where libvirt is involved, it would assume the responsibility of spawning the remote process first and pass in the info required to connect to the remote process via command-line arguments to QEMU. This support in QEMU is available in the current series. We haven't sent the libvirt side of patches out for review yet. It would be easier to upstream libvirt once the QEMU side of things is firmed up.
In the case of self-launch, our understanding is that QEMU has the privilege to
fork()the remote process until the "-sandbox" argument is processed. However, if an Orchestrator prohibits QEMU from spawning other processes from the get-go, then the Orchestrator would assume the responsibility of spawning the remote process as well - like Daniel just pointed out.
Quoted 5 lines
In both cases, we intend to apply the security policies required to confine the remote process externally - probably through SELinux. We haven't had the chance to upstream the SELinux policies yet, but we previously sent a sample of the policies for your comments. Like Michael pointed out earlier, the SELinux policies are per binary.
Sounds good, please document -remote socket= as an alternative to -remote command= so it's clear that both approaches are supported.
Stefan
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
TEST iotest-qcow2: 268
Failures: 071 099 120 184 186
Failed 5 of 109 iotests
make: *** [check-tests/check-block.sh] Error 1
make: *** Waiting for unfinished jobs....
TEST check-qtest-aarch64: tests/qos-test
Traceback (most recent call last):
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=7fcd537d324f4e2997dd5a6e772bce59', '-u', '1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-k9w5q7fm/src/docker-src.2019-10-24-21.54.49.17993:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=7fcd537d324f4e2997dd5a6e772bce59
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-k9w5q7fm/src'
make: *** [docker-run-test-quick@centos7] Error 2
real 13m26.478s
user 0m8.947s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===
CC util/aio-wait.o
CC util/thread-pool.o
Warning, treated as error:
/tmp/qemu-test/src/docs/devel/index.rst:13:toctree contains reference to nonexisting document 'multi-process'
CC util/qemu-timer.o
CC util/main-loop.o
make: *** [Makefile:1003: docs/devel/index.html] Error 2
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 662, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=f573792346ea4c8cb0e6066fdd1f1ddf', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-pe_jt46w/src/docker-src.2019-10-24-22.05.58.3272:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=f573792346ea4c8cb0e6066fdd1f1ddf
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-pe_jt46w/src'
make: *** [docker-run-test-mingw@fedora] Error 2
real 2m19.037s
user 0m7.875s
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Subject: [RFC v4 PATCH 00/49] Initial support of multi-process qemu
Type: series
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
75d605b multi-process: add configure and usage information
1724569 multi-process: add the concept description to docs/devel/qemu-multiprocess 15328b7 multi-process: Enable support for multiple devices in remote 5cf79267 multi-process/mig: Restore the VMSD in remote process 97c15c9 multi-process/mig: Synchronize runstate of remote process 1b67b17 multi-process/mig: refactor runstate_check into common file 55e4b53 multi-process/mig: Load VMSD in the proxy object
7e1b819 multi-process/mig: Send VMSD of remote to the Proxy object 399f9bf multi-process/mig: Enable VMSD save in the Proxy object 645fc27 multi-process/mig: build migration module in the remote process f0265a7 multi-process: prevent duplicate memory initialization in remote a0faf9e multi-process/mon: Initialize QMP module for remote processes 58310d9 multi-process/mon: Refactor monitor/chardev functions out of vl.c ae4fd02 multi-process/mon: enable QMP module support in the remote process d7e2191 multi-process/mon: stub functions to enable QMP module for remote process 2c67c85 multi-process/mon: choose HMP commands based on target cb5ab3e multi-process: perform device reset in the remote process 3214409 multi-process: Use separate MMIO communication channel c34c47f multi-process: handle heartbeat messages in remote process ccd9230 multi-process: send heartbeat messages to remote
f4991d6 multi-process: add parse_cmdline in remote process
a90d6c6 multi-process: add remote options parser
d616c9d multi-process: add remote option
45c18dd multi-process: refractor vl.c code to re-use in remote 57b6105 multi-process: Introduce build flags to separate remote process code 1295409 multi-process: add processing of remote drive and device command line e876f72 multi-process: remote: add create_done condition
effa3f0 multi-process: remote: use fd for socket from parent process de69c89 multi-process: remote: add setup_devices and setup_drive msg processing afc658d multi-process: add qdev_proxy_add to create proxy devices 70e0f47 multi-process: configure remote side devices
701a141 multi-process: create IOHUB object to handle irq
613c372 multi-process: Synchronize remote memory
f5183a9 multi-process: Add LSI device proxy object
7778ec0 multi-process: PCI BAR read/write handling for proxy & remote endpoints 736d74d mutli-process: build remote command line args
650f3d1 multi-process: introduce proxy object
9374d1a multi-process: remote process initialization
1965b18 multi-process: setup memory manager for remote device
719f823 multi-process: setup a machine object for remote device process 59bdda6 multi-process: setup PCI host bridge for remote device 139cdee multi-process: add functions to synchronize proxy and remote endpoints 1b3c1f0 multi-process: define mpqemu-link object
ac130ca multi-process: build system for remote device process
93774c4 multi-process: Add config option for multi-process QEMU 7e5f9b2 multi-process: Add stub functions to facilate build of multi-process 73740e6 multi-process: add a command line option for debug file 59f2f7d multi-process: util: Add qemu_thread_cancel() to cancel running thread 18b29a1 multi-process: memory: alloc RAM from file at offset
=== OUTPUT BEGIN ===
1/49 Checking commit 18b29a1306b2 (multi-process: memory: alloc RAM from file at offset) 2/49 Checking commit 59f2f7d24d20 (multi-process: util: Add qemu_thread_cancel() to cancel running thread) 3/49 Checking commit 73740e6eff21 (multi-process: add a command line option for debug file) 4/49 Checking commit 7e5f9b26d48c (multi-process: Add stub functions to facilate build of multi-process)
ERROR: suspect code indent for conditional statements (4, 4)
#137: FILE: accel/stubs/tcg-stub.c:109:
+ while (1) {
+ }
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #151:
new file mode 100644
total: 1 errors, 1 warnings, 376 lines checked
Patch 4/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/49 Checking commit 93774c4a2c28 (multi-process: Add config option for multi-process QEMU) 6/49 Checking commit ac130ca326fe (multi-process: build system for remote device process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #286:
new file mode 100644
total: 0 errors, 1 warnings, 244 lines checked
Patch 6/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/49 Checking commit 1b3c1f0e0495 (multi-process: define mpqemu-link object)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #20:
new file mode 100644
WARNING: line over 80 characters
#171: FILE: include/io/mpqemu-link.h:147:
+void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback);
WARNING: line over 80 characters
#397: FILE: io/mpqemu-link.c:207:
+ qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__);
total: 0 errors, 3 warnings, 464 lines checked
Patch 7/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/49 Checking commit 139cdee6cbf6 (multi-process: add functions to synchronize proxy and remote endpoints) 9/49 Checking commit 59bdda61a183 (multi-process: setup PCI host bridge for remote device)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#31:
new file mode 100644
total: 0 errors, 1 warnings, 153 lines checked
Patch 9/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
10/49 Checking commit 719f82346cb6 (multi-process: setup a machine object for remote device process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#51:
new file mode 100644
total: 0 errors, 1 warnings, 207 lines checked
Patch 10/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/49 Checking commit 1965b18cc69e (multi-process: setup memory manager for remote device)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #81:
new file mode 100644
total: 0 errors, 1 warnings, 182 lines checked
Patch 11/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/49 Checking commit 9374d1ad3f30 (multi-process: remote process initialization) 13/49 Checking commit 650f3d106d82 (multi-process: introduce proxy object)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #34:
new file mode 100644
total: 0 errors, 1 warnings, 379 lines checked
Patch 13/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
14/49 Checking commit 736d74d6623b (mutli-process: build remote command line args)
WARNING: line over 80 characters
#141: FILE: hw/proxy/qemu-proxy.c:243:
+static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp)
WARNING: line over 80 characters
#167: FILE: include/hw/proxy/qemu-proxy.h:66:
+ void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error **errp);
total: 0 errors, 2 warnings, 146 lines checked
Patch 14/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
15/49 Checking commit 7778ec04e0e6 (multi-process: PCI BAR read/write handling for proxy & remote endpoints) 16/49 Checking commit f5183a9f01b5 (multi-process: Add LSI device proxy object)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#24:
new file mode 100644
total: 0 errors, 1 warnings, 135 lines checked
Patch 16/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
17/49 Checking commit 613c372a8221 (multi-process: Synchronize remote memory)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #32:
new file mode 100644
total: 0 errors, 1 warnings, 344 lines checked
Patch 17/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
18/49 Checking commit 701a141ec1a3 (multi-process: create IOHUB object to handle irq)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #202:
new file mode 100644
total: 0 errors, 1 warnings, 435 lines checked
Patch 18/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
19/49 Checking commit 70e0f47f0652 (multi-process: configure remote side devices)
20/49 Checking commit afc658d34c34 (multi-process: add qdev_proxy_add to create proxy devices) 21/49 Checking commit de69c899ae12 (multi-process: remote: add setup_devices and setup_drive msg processing) 22/49 Checking commit effa3f06a627 (multi-process: remote: use fd for socket from parent process) 23/49 Checking commit e876f72db9ae (multi-process: remote: add create_done condition) 24/49 Checking commit 129540993d75 (multi-process: add processing of remote drive and device command line)
WARNING: Block comments use a leading /* on a separate line
#41: FILE: vl.c:1149:
+ dev = qdev_remote_add(opts, false /* this is drive */, errp);
WARNING: Block comments use a leading /* on a separate line #87: FILE: vl.c:2246:
+ dev = qdev_remote_add(opts, true /* this is device */, errp);
WARNING: line over 80 characters
#121: FILE: vl.c:4418:
+ * need PCI host initialized. As a TODO: could defer init of PCIProxyDev instead.
total: 0 errors, 3 warnings, 117 lines checked
Patch 24/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
25/49 Checking commit 57b61051819d (multi-process: Introduce build flags to separate remote process code) 26/49 Checking commit 45c18ddb523b (multi-process: refractor vl.c code to re-use in remote)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#35:
new file mode 100644
WARNING: Block comments use a leading /* on a separate line #157: FILE: vl-parse.c:118:
+ dev = qdev_remote_add(opts, false /* this is drive */, errp);
WARNING: Block comments use a leading /* on a separate line #172: FILE: vl-parse.c:133:
+ dev = qdev_remote_add(opts, true /* this is device */, errp);
total: 0 errors, 3 warnings, 412 lines checked
Patch 26/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
27/49 Checking commit d616c9d52b3e (multi-process: add remote option) 28/49 Checking commit a90d6c6eebff (multi-process: add remote options parser)
WARNING: Block comments use a leading /* on a separate line
#37: FILE: vl.c:300:
+ { /* end of list */ }
total: 0 errors, 1 warnings, 147 lines checked
Patch 28/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
29/49 Checking commit f4991d61c243 (multi-process: add parse_cmdline in remote process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #59:
new file mode 100644
ERROR: line over 90 characters
#151: FILE: remote/remote-opts.c:88:
+ error_report("Option not supported for this target, %x arch_mask, %x arch_type",
total: 1 errors, 1 warnings, 180 lines checked
Patch 29/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
30/49 Checking commit ccd92304b77d (multi-process: send heartbeat messages to remote)
31/49 Checking commit c34c47ff9925 (multi-process: handle heartbeat messages in remote process) 32/49 Checking commit 32144092e7eb (multi-process: Use separate MMIO communication channel) 33/49 Checking commit cb5ab3eb7d63 (multi-process: perform device reset in the remote process) 34/49 Checking commit 2c67c85818aa (multi-process/mon: choose HMP commands based on target) 35/49 Checking commit d7e21910a6c4 (multi-process/mon: stub functions to enable QMP module for remote process)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#108:
new file mode 100644
total: 0 errors, 1 warnings, 722 lines checked
Patch 35/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
36/49 Checking commit ae4fd022fa7e (multi-process/mon: enable QMP module support in the remote process) 37/49 Checking commit 58310d9c635b (multi-process/mon: Refactor monitor/chardev functions out of vl.c) 38/49 Checking commit a0faf9ea04b0 (multi-process/mon: Initialize QMP module for remote processes) 39/49 Checking commit f0265a76742b (multi-process: prevent duplicate memory initialization in remote) 40/49 Checking commit 645fc2738aec (multi-process/mig: build migration module in the remote process) 41/49 Checking commit 399f9bf4ba56 (multi-process/mig: Enable VMSD save in the Proxy object)
ERROR: suspect code indent for conditional statements (4, 4)
#126: FILE: hw/proxy/qemu-proxy.c:449:
+ while (*((volatile uint64_t *)&pdev->migsize) < size) {
+ }
total: 1 errors, 0 warnings, 173 lines checked
Patch 41/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
42/49 Checking commit 7e1b8192f562 (multi-process/mig: Send VMSD of remote to the Proxy object) 43/49 Checking commit 55e4b53ec008 (multi-process/mig: Load VMSD in the proxy object) 44/49 Checking commit 1b67b1722798 (multi-process/mig: refactor runstate_check into common file)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#48:
new file mode 100644
total: 0 errors, 1 warnings, 92 lines checked
Patch 44/49 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
45/49 Checking commit 97c15c99f41f (multi-process/mig: Synchronize runstate of remote process) 46/49 Checking commit 5cf792672396 (multi-process/mig: Restore the VMSD in remote process)
ERROR: that open brace { should be on the previous line
#118: FILE: remote/remote-main.c:527:
+ if (process_start_mig_in(msg))
+ {
total: 1 errors, 0 warnings, 103 lines checked
Patch 46/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
47/49 Checking commit 15328b7aae2d (multi-process: Enable support for multiple devices in remote) 48/49 Checking commit 1724569b4d71 (multi-process: add the concept description to docs/devel/qemu-multiprocess)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#22:
new file mode 100644
total: 0 errors, 1 warnings, 1106 lines checked
Patch 48/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
49/49 Checking commit 75d605b31739 (multi-process: add configure and usage information)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #13:
new file mode 100644
total: 0 errors, 1 warnings, 86 lines checked
Patch 49/49 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 30 lines · Jagannathan Raman
Started with the presentation in October 2017 made by Marc-Andre (Red Hat) and Konrad Wilk (Oracle) [1], and continued by Jag's BoF at KVM Forum 2018, the multi-process project is now a prototype and presented in this patchset. John & Elena will present the status of this project in KVM Forum 2019.
This first series enables the emulation of lsi53c895a in a separate process.
We posted the Proof Of Concept patches [2] before the BoF session in 2018. Subsequently, we posted RFC v1 [3], RFC v2 [4] and RFC v3 [5] of this series.
We want to present version 4 of this series, which incorporates the feedback we received for v3 & adds support for live migrating the remote process.
Following people contributed to this patchset:
John G Johnson <[email protected]>
Jagannathan Raman <[email protected]>
Elena Ufimtseva <[email protected]>
Kanth Ghatraju <[email protected]>For full concept writeup about QEMU disaggregation refer to
docs/devel/qemu-multiprocess.rst. Please refer todocs/qemu-multiprocess.txtfor usage information.We are planning on making the following improvements in the future:
- Performance improvements
- Libvirt support
- Enforcement of security policies
- blockdev support
Quoted 3 lines
We welcome all your ideas, concerns, and questions for this patchset.
Thank you!
I've wrapped up for v4. There is more to review in detail but I've posted enough comments so that I'd like to see the next revision before investing more time.
The main topics:
1. It's possible to have just one proxy device per bus type (PCI, USB, etc). The proxy device instance can be initialized by communicating with the remote process to inquire about its memory regions, interrupts, etc. This removes the need to hardcode that information into per-device proxy objects, which is tedious and can get out-of-sync with the real device emulation code.
This is becoming similar to doing VFIO or muser over a socket...
2. Security and code quality. Missing input validation and resource leaks don't inspire confidence :(.
Please run scripts/checkpatch.pl on the code.
Stefan