From patchwork Thu Mar 7 07:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842283 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13F5C14DE for ; Thu, 7 Mar 2019 07:29:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE4982E032 for ; Thu, 7 Mar 2019 07:29:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E229B2E04D; Thu, 7 Mar 2019 07:29:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C4F3D2E032 for ; Thu, 7 Mar 2019 07:29:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:46657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nTD-0000Iy-2s for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:29:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLH-0001fL-ID for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLG-0004gf-HT for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:23 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47644) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLG-0004gD-7X for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:22 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JB4k037791; Thu, 7 Mar 2019 07:21:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=OGmQ2UVBTlAXucxgJQW/Vrs3bjeFn1zBPSEAl8FNA6E=; b=PBwUoxsKFxi/5Y8ELYT/5DdE58QjAaN70E9QQLyzp+4GkYnDnbc3RaXWum1ZlmnYffrC VKN74gFmuaLb5+DlAAhtIq4/AFyMdQ4sNlRhagr6wqzYOKgvxyrmhyg3+ZiJzTZug+j/ UWitKCinl94uK5UlJmp0JKV8zX/4hofgQ55gllA01Xecvu3aUAxwYal5GjNalOFLVVmJ rEK7nhZ110xqT9ET9lhIcG8fVaMu+UQ+0WmTecJxk+M+SsyxAVXzv4cCsCV1yY4pbycJ mO4+zN3JMhklO46bddbMv4loeLjc/TAMEruudzZqeHRNnI+dxKd/SJ7kp2ZeeWUun4C9 uA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug939-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:04 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277KwYv027065 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:20:58 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277Kvkq004889; Thu, 7 Mar 2019 07:20:57 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:20:57 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:20:41 -0800 Message-Id: <20190307072041.8098-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 01/37] multi-process: memory: alloc RAM from file at offset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process. This will be needed for the following patches. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- exec.c | 9 +++++---- include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 2 +- memory.c | 2 +- util/mmap-alloc.c | 5 +++-- util/oslib-posix.c | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/exec.c b/exec.c index 1d4f378..dcef041 100644 --- a/exec.c +++ b/exec.c @@ -1813,6 +1813,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { void *area; @@ -1863,7 +1864,7 @@ static void *file_ram_alloc(RAMBlock *block, } area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED); + block->flags & RAM_SHARED, offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2252,7 +2253,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; @@ -2297,7 +2298,7 @@ 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; @@ -2327,7 +2328,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 9ecd911..2ed4579 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -100,7 +100,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp); + off_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index ef04f0e..25c4b12 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -7,7 +7,7 @@ size_t qemu_fd_getpagesize(int fd); size_t qemu_mempath_getpagesize(const char *mem_path); -void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared); +void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, off_t start); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/memory.c b/memory.c index 61d66e4..ffa91d0 100644 --- a/memory.c +++ b/memory.c @@ -1619,7 +1619,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, 0, &err); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; if (err) { mr->size = int128_zero(); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 8565885..58cb4cc 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -75,7 +75,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return getpagesize(); } -void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) +void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, off_t start) { int flags; int guardfd; @@ -130,7 +130,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) flags |= shared ? MAP_SHARED : MAP_PRIVATE; offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; - ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, flags, fd, 0); + ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, flags, fd, + start); if (ptr == MAP_FAILED) { munmap(guardptr, total); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 37c5854..e4c6380 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -203,7 +203,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); + void *ptr = qemu_ram_mmap(-1, size, align, shared, 0); if (ptr == MAP_FAILED) { return NULL; From patchwork Thu Mar 7 07:20:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842261 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5670614DE for ; Thu, 7 Mar 2019 07:22:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 356EC2E7CE for ; Thu, 7 Mar 2019 07:22:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 262442E84F; Thu, 7 Mar 2019 07:22:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C717D2E7CE for ; Thu, 7 Mar 2019 07:22:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:46563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMP-0002eo-3P for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:22:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nKz-0001Y9-Lc for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nKy-0004Dl-Tf for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:05 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:54846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nKy-0004DJ-KQ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:04 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JWkv037984; Thu, 7 Mar 2019 07:21:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=a/u1HZ4JrC7CQ1VNDRlH0Nm6D1tRq2GuVmhJVTmBQas=; b=u1FeCRMIa3szBD6d6O2BLzE5RfyYb0KSFS9Fj9x3yPit5P0l5UyJA4Cs1fPcB/a6h0CB w55l/VdoMVGe25TaieA6p1G965VxYqFuTsYMNO2+PD8/T213YzSILgTTIc00JewXorUn j3TlZKm4IDsmO3bOFWf9YGaOd8OuB3FxDHTpnIg5t1OcxggRWDZc8XLgVfhYb1lv8rCD uQEWH3EgiScvmvMlRSUFzxni6tuSL2bZYx43X9OW9T7SqSz9j3dKpusZE61iYyV/sCwE NlALj9j7h3IbtyBkz21b8c/iekNP2UrKJZLP53zSkPPgXoSLwPcelhQ9a4LmxMUUol6b Kg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qyjfrr59y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:01 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277L0Lw003049 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:01 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277L0uU023771; Thu, 7 Mar 2019 07:21:00 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:00 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:20:57 -0800 Message-Id: <20190307072057.8150-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 02/37] multi-process: util: Add qemu_thread_cancel() to cancel running thread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: 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 Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- include/qemu/thread.h | 1 + util/qemu-thread-posix.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 55d83a9..78791be 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -156,6 +156,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); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 1bf5e65..7c89071 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -573,3 +573,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__); + } +} From patchwork Thu Mar 7 07:21:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28DDF14DE for ; Thu, 7 Mar 2019 07:22:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C4592E7CE for ; Thu, 7 Mar 2019 07:22:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1BA32E84F; Thu, 7 Mar 2019 07:22:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9F7A62E7CE for ; Thu, 7 Mar 2019 07:22:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:46565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMn-0002x6-W6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:22:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLI-0001fP-O2 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLH-0004hK-Ps for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:24 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49762) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLH-0004gr-GV for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:23 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277Jl7i034482; Thu, 7 Mar 2019 07:21:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=D+Oq1pCteF6mF/3QwuBEzy9SNUWVl12oLfG01nkfLhE=; b=T/t0yXA/Msd8JIO5vWO/s8x/XLk2vg8AQtTzr7elt3b1wjA8fY9eZ6SFjUsm6OtoILvD mkXk6utZ0a2mk/sBEUqQQ5UuimcvEuR2FnAtjwujAj3/GqXht/dSSLTd9Vopthb/3m4+ B08mhJo9lYvdAe5qQpEoH3F+Jj2qrqLX9KQd88ERHx4UNo4AJUnTr/qAuFrO48NN7uQk Jau2OL/QhZ3xKa8NCZlVN3kJtpr1wfbuGNZJY0klrG2izTlvKbQGIkg670rtKP7XN8hN cKMH2+BQ9geDtFVQbm1rtfvwcPt3GX0YhXkr/bABPUgjDkCsLgJV3KUIeMGpiN8dafo/ 4w== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2qyfbeggdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:05 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277L48h029867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:04 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277L3Ih004927; Thu, 7 Mar 2019 07:21:03 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:03 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:00 -0800 Message-Id: <20190307072100.8197-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 03/37] multi-process: add a command line option for debug file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, peter.maydell@linaro.org, richard.henderson@linaro.org, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Can be used with -d rdebug command options when starting qemu. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- include/qemu/log.h | 1 + util/log.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6c..ca6f490 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -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 diff --git a/util/log.c b/util/log.c index c0dbbd4..c746125 100644 --- a/util/log.c +++ b/util/log.c @@ -274,6 +274,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 }, }; From patchwork Thu Mar 7 07:21:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA32D14DE for ; Thu, 7 Mar 2019 07:25:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90CBF2E84F for ; Thu, 7 Mar 2019 07:25:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 844472E8C8; Thu, 7 Mar 2019 07:25:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CC7EE2E84F for ; Thu, 7 Mar 2019 07:25:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:46620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nPL-0005KQ-UP for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:25:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLB-0001eX-Qc for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLA-0004bM-HC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:17 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLA-0004Zi-7P for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:16 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277Jp5k034503; Thu, 7 Mar 2019 07:21:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=GikO3jjq3sr5rCmlW2yXy8j687o4J0v3XTUnLlnZmfk=; b=jfJIfqa6SrUV3M8xEHvFNpfbSkdTQrtdjfXjN6zZsY6n5EtEqGw78AVN5ngePqsh966B ETfVlCRXyU/t6fCrn4EtnooJiE9hTw9Xh1yyHH2td2AhPt4ITy+3jRofgUcuHT+FNJOF Oai5QtuBGegPDv8rqjOlxosIv8QQpkvevV5XVx/LIKEtJtVxzBZcf1ji8mwHnswBpktt kAtmMwrC171PquEzrcqdRJ2Q4g3n1ustI63A3wJX+BWLXXNLpSrz22ttj2Z1NKL05bbb 4qTH5ciZa3h6G/GPGfb/JHEXe2SgHl7hW9Itv5KBOS0PTcl6NDpWNS2gC2pTq/y44qC9 Vg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbegge2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:08 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277L7Dh027931 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:07 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277L6al003512; Thu, 7 Mar 2019 07:21:06 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:06 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:03 -0800 Message-Id: <20190307072103.8243-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 04/37] multi-process: Add stub functions to facilate build of multi-process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, pavel.dovgaluk@ispras.ru, kvm@vger.kernel.org, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, paul.durrant@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, anthony.perard@citrix.com, kanth.ghatraju@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add stub functions that are needed during compile time but not in runtime. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- accel/stubs/kvm-stub.c | 5 +++ accel/stubs/tcg-stub.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ stubs/machine-init-done.c | 4 +++ stubs/monitor.c | 25 ++++++++++++++ stubs/net-stub.c | 31 +++++++++++++++++ stubs/replay.c | 14 ++++++++ stubs/vl-stub.c | 75 +++++++++++++++++++++++++++++++++++++++++ stubs/vmstate.c | 20 +++++++++++ stubs/xen-mapcache.c | 22 ++++++++++++ 9 files changed, 281 insertions(+) create mode 100644 stubs/net-stub.c create mode 100644 stubs/vl-stub.c create mode 100644 stubs/xen-mapcache.c diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 02d5170..573b4da 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -32,6 +32,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) { @@ -59,6 +60,10 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu) { } +void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu) +{ +} + int kvm_cpu_exec(CPUState *cpu) { abort(); diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index 76ae461..52722c7 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -16,11 +16,96 @@ #include "tcg/tcg.h" #include "exec/cpu-common.h" #include "exec/exec-all.h" +#include "translate-all.h" +#include "exec/ram_addr.h" + +bool parallel_cpus; void tb_flush(CPUState *cpu) { } +void tb_check_watchpoint(CPUState *cpu) +{ +} + +void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end) +{ +} + +void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end, + int is_cpu_write_access) +{ +} + +void tb_invalidate_phys_page_fast(struct page_collection *pages, + tb_page_addr_t start, int len) +{ +} + +void tlb_init(CPUState *cpu) +{ +} + void tlb_set_dirty(CPUState *cpu, target_ulong vaddr) { } + +void tlb_flush(CPUState *cpu) +{ +} + +void tlb_flush_page(CPUState *cpu, target_ulong addr) +{ +} + +void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length) +{ +} + +void tcg_region_init(void) +{ +} + +void tcg_register_thread(void) +{ +} + +void tcg_flush_softmmu_tlb(CPUState *cs) +{ +} + +void cpu_loop_exit_noexc(CPUState *cpu) +{ + cpu->exception_index = -1; + cpu_loop_exit(cpu); +} + +void cpu_loop_exit(CPUState *cpu) +{ + cpu->can_do_io = 1; + siglongjmp(cpu->jmp_env, 1); +} + +void cpu_reloading_memory_map(void) +{ +} + +int cpu_exec(CPUState *cpu) +{ + return 0; +} + +void cpu_exec_step_atomic(CPUState *cpu) +{ +} + +struct page_collection * +page_collection_lock(tb_page_addr_t start, tb_page_addr_t end) +{ + return NULL; +} + +void page_collection_unlock(struct page_collection *set) +{ +} diff --git a/stubs/machine-init-done.c b/stubs/machine-init-done.c index 4121f17..5bff245 100644 --- a/stubs/machine-init-done.c +++ b/stubs/machine-init-done.c @@ -7,3 +7,7 @@ bool machine_init_done = true; void qemu_add_machine_init_done_notifier(Notifier *notify) { } + +void qemu_remove_machine_init_done_notifier(Notifier *notify) +{ +} diff --git a/stubs/monitor.c b/stubs/monitor.c index b57fe6c..1973a3b 100644 --- a/stubs/monitor.c +++ b/stubs/monitor.c @@ -3,6 +3,8 @@ #include "qapi/qapi-emit-events.h" #include "qemu-common.h" #include "monitor/monitor.h" +#include "qapi/qapi-types-misc.h" +#include "qapi/qapi-commands-misc.h" __thread Monitor *cur_mon; @@ -19,3 +21,26 @@ void monitor_init(Chardev *chr, int flags) void qapi_event_emit(QAPIEvent event, QDict *qdict) { } + +int monitor_get_cpu_index(void) +{ + return -ENOSYS; +} +void monitor_printf(Monitor *mon, const char *fmt, ...) +{ +} + +bool monitor_cur_is_qmp(void) +{ + return false; +} + +ObjectPropertyInfoList *qmp_device_list_properties(const char *typename, + Error **errp) +{ + return NULL; +} + +void monitor_vfprintf(FILE *stream, const char *fmt, va_list ap) +{ +} diff --git a/stubs/net-stub.c b/stubs/net-stub.c new file mode 100644 index 0000000..cb2274b --- /dev/null +++ b/stubs/net-stub.c @@ -0,0 +1,31 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "net/net.h" + +int qemu_find_net_clients_except(const char *id, NetClientState **ncs, + NetClientDriver type, int max) +{ + return -ENOSYS; +} + +NetClientState *net_hub_port_find(int hub_id) +{ + return NULL; +} + +int net_hub_id_for_client(NetClientState *nc, int *id) +{ + return -ENOSYS; +} + +int qemu_show_nic_models(const char *arg, const char *const *models) +{ + return -ENOSYS; +} + +int qemu_find_nic_model(NICInfo *nd, const char * const *models, + const char *default_model) +{ + return -ENOSYS; +} + diff --git a/stubs/replay.c b/stubs/replay.c index 4ac6078..38fd1d3 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -80,3 +80,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) +{ +} diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c new file mode 100644 index 0000000..bff6a94 --- /dev/null +++ b/stubs/vl-stub.c @@ -0,0 +1,75 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/uuid.h" +#include "sysemu/sysemu.h" +#include "exec/cpu-common.h" +#include "exec/gdbstub.h" +#include "sysemu/replay.h" +#include "disas/disas.h" + +bool tcg_allowed; +bool xen_allowed; +bool boot_strict; + +int mem_prealloc; +int smp_cpus; +int vga_interface_type = VGA_NONE; +int smp_cores = 1; +int smp_threads = 1; +int icount_align_option; +int boot_menu; + +unsigned int max_cpus; +const uint32_t arch_type; +const char *mem_path; +uint8_t qemu_extra_params_fw[2]; +uint8_t *boot_splash_filedata; +size_t boot_splash_filedata_size; +struct syminfo *syminfos; + +ram_addr_t ram_size; +MachineState *current_machine; +QemuUUID qemu_uuid; + +int runstate_is_running(void) +{ + return 0; +} + +void runstate_set(RunState new_state) +{ +} + +void vm_state_notify(int running, RunState state) +{ +} + +bool qemu_vmstop_requested(RunState *r) +{ + return false; +} + +void qemu_system_debug_request(void) +{ +} + +char *qemu_find_file(int type, const char *name) +{ + return NULL; +} + +void gdb_set_stop_cpu(CPUState *cpu) +{ +} + +void replay_enable_events(void) +{ +} + +void replay_disable_events(void) +{ +} + +void x86_cpu_list(FILE *f, fprintf_function cpu_fprintf) +{ +} diff --git a/stubs/vmstate.c b/stubs/vmstate.c index 6399474..a9a2bc2 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -1,9 +1,12 @@ #include "qemu/osdep.h" #include "qemu-common.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, @@ -24,3 +27,20 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { return true; } + +void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_register_ram_global(MemoryRegion *mr) +{ +} + +bool migration_is_idle(void) +{ + return true; +} diff --git a/stubs/xen-mapcache.c b/stubs/xen-mapcache.c new file mode 100644 index 0000000..af5c031 --- /dev/null +++ b/stubs/xen-mapcache.c @@ -0,0 +1,22 @@ +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "exec/cpu-common.h" +#include "sysemu/xen-mapcache.h" + +#ifdef CONFIG_XEN + +void xen_invalidate_map_cache_entry(uint8_t *buffer) +{ +} + +uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size, uint8_t lock, bool dma) +{ + return NULL; +} + +ram_addr_t xen_ram_addr_from_mapcache(void *ptr) +{ + return 0; +} + +#endif From patchwork Thu Mar 7 07:21:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4371214DE for ; Thu, 7 Mar 2019 07:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 264562E922 for ; Thu, 7 Mar 2019 07:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A9162E8D3; Thu, 7 Mar 2019 07:25:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B087E2E926 for ; Thu, 7 Mar 2019 07:25:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:46572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nOs-0003bv-Sl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:25:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLD-0001eq-Nq for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLC-0004fN-VB for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:19 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLC-0004fC-Lp for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:18 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JWvX034131; Thu, 7 Mar 2019 07:21:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=3v0fd3pWKcoruQTgSWz8qLTVAu1H68EqKe0gE2QYwsg=; b=IQY+zEKO7UtiiUCKuOHyCxbffFdyyDtb0ENOk8/zKtiTMXDew+VEwrLKkrBO/tVM3Yc5 VfeqkvOdlwdmJySWRGAH3ypFZuWdjCLTluan52QLWmhUttIhljjdx0a9fWIINHrLBz6G SYPeYjmRxZ65hd9qSfPk95ACMxl5pM53bV1aGjqvth3p/B3oaAV1ZRjJUgz5YHSQ/a3b P/n9PfbGaBl5LbIu7nU0v+M4WqJEIwRNwH1Y0xjQ+fDrQAivLB6zh9kCL+iAQaOZeYpM yhSMyxaGXrYLMXF7nlOw544gKaIYEN2817DatI2V4tY6lJXg/suODXvy9952m57htd+A Jw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbeggef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:14 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277L9Jx028093 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:09 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277L9X7003534; Thu, 7 Mar 2019 07:21:09 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:09 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:06 -0800 Message-Id: <20190307072106.8288-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 05/37] multi-process: Add config option for multi-process QEMU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, thuth@redhat.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, kraxel@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, philmd@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add a configuration option to separate multi-process code Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- configure | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure b/configure index cefeb8f..acdfc3c 100755 --- a/configure +++ b/configure @@ -488,6 +488,7 @@ docker="no" debug_mutex="no" libpmem="" libudev="no" +mpqemu="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc" @@ -1497,6 +1498,10 @@ for opt do ;; --disable-libpmem) libpmem=no ;; + --enable-mpqemu) mpqemu=yes + ;; + --disable-mpqemu) mpqemu=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1778,6 +1783,7 @@ disabled with --disable-FEATURE, default is enabled if available: capstone capstone disassembler support debug-mutex mutex debugging support libpmem libpmem support + mpqemu multi-process QEMU support NOTE: The object files are built at the place where configure is launched EOF @@ -6250,6 +6256,7 @@ echo "capstone $capstone" echo "docker $docker" echo "libpmem support $libpmem" echo "libudev $libudev" +echo "multiprocess QEMU $mpqemu" if test "$supported_cpu" = "no"; then echo @@ -7015,6 +7022,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 From patchwork Thu Mar 7 07:21:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DA321515 for ; Thu, 7 Mar 2019 07:26:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C7662E825 for ; Thu, 7 Mar 2019 07:26:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3EA7E2E885; Thu, 7 Mar 2019 07:26:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3AA702E825 for ; Thu, 7 Mar 2019 07:26:10 +0000 (UTC) Received: from localhost ([127.0.0.1]:46622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nPt-0005kl-ED for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:26:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLS-0001p5-HB for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLQ-0004ss-C2 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:34 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47778) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLQ-0004r8-2O for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:32 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JD86037798; Thu, 7 Mar 2019 07:21:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=wurhFTtXaISmwRBVUC8SfpkP4zZcdiMlQqHJzcjkL+U=; b=wg5OFW5fj9revdG5tA+o+fK4Rm75tYyWwpU1zfxirpgegW4rac1JpD6eUsqg0+BWBC1V fatyxnwGcIu1Y2hfF77Z5s2YTffVKCn8TrgxjtPdG4lWWzhC2VOsPEY8yS/pFUMB0Mn/ rbnjH+jRujUJZglY0i7Hz16mf5D7cCWwTFzPvftweVLpW29c6JfcZ7zQwF7XM4PQaqKf +wIlQ5AaUeAL/72USZddbtnZeLumJ8l8621qSQbUceuNVUlTwbtolHtWbs1XHhCpysnh 4AtzPQwmpi/8MFFEcWPHMy+ORaW4tra8VHf5ggjC4nuHpwz7M+YRbGFoMWdEkvZo/JGl +A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug93q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:15 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LEBS028450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:14 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LCKk011083; Thu, 7 Mar 2019 07:21:12 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:12 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:09 -0800 Message-Id: <20190307072109.8334-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 06/37] multi-process: build system for remote device process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, mst@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, fam@euphon.net, kwolf@redhat.com, quintela@redhat.com, afaerber@suse.de Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Modify Makefile to support the building of the remote device process. Implements main() function of remote device process. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- Makefile | 5 ++++- Makefile.objs | 22 ++++++++++++++++++++++ Makefile.target | 50 +++++++++++++++++++++++++++++++++++++++++++++++-- backends/Makefile.objs | 2 ++ block/Makefile.objs | 2 ++ hw/Makefile.objs | 7 +++++++ hw/block/Makefile.objs | 2 ++ hw/core/Makefile.objs | 14 ++++++++++++++ hw/nvram/Makefile.objs | 2 ++ hw/pci/Makefile.objs | 4 ++++ hw/scsi/Makefile.objs | 2 ++ migration/Makefile.objs | 2 ++ qom/Makefile.objs | 4 ++++ remote/Makefile.objs | 1 + remote/remote-main.c | 35 ++++++++++++++++++++++++++++++++++ 15 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 remote/Makefile.objs create mode 100644 remote/remote-main.c diff --git a/Makefile b/Makefile index 2208bde..e325297 100644 --- a/Makefile +++ b/Makefile @@ -378,6 +378,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 \ @@ -459,7 +461,8 @@ subdir-capstone: .git-submodule-status $(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE)) $(SUBDIR_RULES): libqemuutil.a $(common-obj-y) $(chardev-obj-y) $(slirp-obj-y) \ - $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) + $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) \ + $(remote-pci-obj-y) $(remote-lsi-obj-y) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags diff --git a/Makefile.objs b/Makefile.objs index 6e91ee5..702acc8 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -22,6 +22,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 diff --git a/Makefile.target b/Makefile.target index 3b79e70..81335c6 100644 --- a/Makefile.target +++ b/Makefile.target @@ -33,7 +33,12 @@ QEMU_PROG_BUILD = $(QEMU_PROG) endif endif -PROGS=$(QEMU_PROG) $(QEMU_PROGW) +ifdef CONFIG_MPQEMU +SCSI_DEV_PROG=qemu-scsi-dev +SCSI_DEV_BUILD = $(SCSI_DEV_PROG) +endif + +PROGS=$(QEMU_PROG) $(QEMU_PROGW) $(SCSI_DEV_PROG) STPFILES= # Makefile Tests @@ -115,6 +120,16 @@ obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/tcg-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o + ######################################################### # Linux user emulator target @@ -170,11 +185,22 @@ endif # CONFIG_SOFTMMU dummy := $(call unnest-vars,,obj-y) all-obj-y := $(obj-y) +dummy := $(call unnest-vars,..,remote-pci-tgt-obj-y) +all-remote-pci-obj-y := $(remote-pci-tgt-obj-y) + +all-remote-pci-obj-y += memory.o +all-remote-pci-obj-y += exec.o +all-remote-pci-obj-y += numa.o +all-remote-pci-obj-y += ioport.o +all-remote-pci-obj-y += cpus.o + target-obj-y := block-obj-y := common-obj-y := chardev-obj-y := slirp-obj-y := +remote-pci-obj-y := +remote-lsi-obj-y := include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,,target-obj-y) target-obj-y-save := $(target-obj-y) @@ -189,7 +215,9 @@ dummy := $(call unnest-vars,.., \ io-obj-y \ common-obj-y \ common-obj-m \ - slirp-obj-y) + slirp-obj-y \ + remote-pci-obj-y \ + remote-lsi-obj-y) target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) all-obj-y += $(target-obj-y) @@ -201,7 +229,18 @@ all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(slirp-obj-y) +all-remote-pci-obj-y += $(authz-obj-y) +all-remote-pci-obj-y += $(block-obj-y) +all-remote-pci-obj-y += $(crypto-obj-y) +all-remote-pci-obj-y += $(io-obj-y) +all-remote-pci-obj-y += $(chardev-obj-y) +all-remote-pci-obj-y += $(remote-pci-obj-y) + + +all-remote-lsi-obj-y += $(all-remote-pci-obj-y) $(remote-lsi-obj-y) + $(QEMU_PROG_BUILD): config-devices.mak +$(SCSI_DEV_BUILD): config-devices.mak COMMON_LDADDS = ../libqemuutil.a @@ -213,6 +252,13 @@ ifdef CONFIG_DARWIN $(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@") endif +$(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS) + $(call LINK, $(filter-out %.mak, $^)) +ifdef CONFIG_DARWIN + $(call quiet-command,Rez -append $(SRC_PATH)/pc-bios/qemu.rsrc -o $@,"REZ","$(TARGET_DIR)$@") + $(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@") +endif + gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh $(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"GEN","$(TARGET_DIR)$@") diff --git a/backends/Makefile.objs b/backends/Makefile.objs index ff619d3..47c4161 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -15,3 +15,5 @@ common-obj-$(CONFIG_VHOST_CRYPTO) += cryptodev-vhost-user.o endif common-obj-$(CONFIG_LINUX) += hostmem-memfd.o + +remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o diff --git a/block/Makefile.objs b/block/Makefile.objs index 7a81892..cfc7719 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -63,3 +63,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 diff --git a/hw/Makefile.objs b/hw/Makefile.objs index e2fcd6a..4cbfdff 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -39,3 +39,10 @@ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) + +remote-pci-obj-$(CONFIG_MPQEMU) += core/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += pci/ +remote-pci-obj-$(CONFIG_MPQEMU) += nvram/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/ diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs index e206b8e..d3bafab 100644 --- a/hw/block/Makefile.objs +++ b/hw/block/Makefile.objs @@ -14,3 +14,5 @@ obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o obj-$(CONFIG_VIRTIO_BLK) += dataplane/ obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o + +remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index a799c83..3e3afaa 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -22,3 +22,17 @@ common-obj-$(CONFIG_SOFTMMU) += split-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o common-obj-$(CONFIG_SOFTMMU) += generic-loader.o common-obj-$(CONFIG_SOFTMMU) += null-machine.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 diff --git a/hw/nvram/Makefile.objs b/hw/nvram/Makefile.objs index 26f7b4c..9802a31 100644 --- a/hw/nvram/Makefile.objs +++ b/hw/nvram/Makefile.objs @@ -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 diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs index 9f905e6..f62025c 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -7,3 +7,7 @@ common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o + +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o +remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs index 45167ba..3052650 100644 --- a/hw/scsi/Makefile.objs +++ b/hw/scsi/Makefile.objs @@ -13,3 +13,5 @@ obj-y += virtio-scsi.o virtio-scsi-dataplane.o obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o endif + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi-generic.o scsi-bus.o lsi53c895a.o scsi-disk.o emulation.o diff --git a/migration/Makefile.objs b/migration/Makefile.objs index a4f3baf..016b6ab 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -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 diff --git a/qom/Makefile.objs b/qom/Makefile.objs index 516349e..f0392c2 100644 --- a/qom/Makefile.objs +++ b/qom/Makefile.objs @@ -2,3 +2,7 @@ qom-obj-y = object.o container.o qom-qobject.o qom-obj-y += object_interfaces.o common-obj-y = cpu.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) += cpu.o diff --git a/remote/Makefile.objs b/remote/Makefile.objs new file mode 100644 index 0000000..a9b2256 --- /dev/null +++ b/remote/Makefile.objs @@ -0,0 +1 @@ +remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o diff --git a/remote/remote-main.c b/remote/remote-main.c new file mode 100644 index 0000000..53c2aa5 --- /dev/null +++ b/remote/remote-main.c @@ -0,0 +1,35 @@ +/* + * Remote device initialization + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 + +#include "qemu/osdep.h" +#include "qemu/module.h" + +int main(int argc, char *argv[]) +{ + module_call_init(MODULE_INIT_QOM); + + return 0; +} From patchwork Thu Mar 7 07:21:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 247A114DE for ; Thu, 7 Mar 2019 07:28:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 067032E825 for ; Thu, 7 Mar 2019 07:28:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED2072E885; Thu, 7 Mar 2019 07:28:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 011EC2E825 for ; Thu, 7 Mar 2019 07:28:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:46626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nRh-00069u-49 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:28:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLJ-0001gN-P1 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLE-0004fx-8e for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:25 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLD-0004fe-Vg for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:20 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277Kvhj039086; Thu, 7 Mar 2019 07:21:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=pkujM8ULjqFTYLXTIputrZQGBGSK9V5VowlSnhBxEH4=; b=NdX8dAwv1BZ+Sb0w+r0YsxXY+MwkgDbTHetOq6oLFpyerbLddPFETZXhFStPNamqGUOl ENkhoSKsa2vAO3KL3GyH8p16jIqhtc81Qw2uG1ydhnIMQ0aZmvQCs1Dy4KxIVMhfJ0pd I5bSl41fMdbReJgJf6Qxr5/0RX1QsQBKuU56itoZBHXwJTMsh5fwqPN4+FWKD5Hj0Jqu AlZvQMDjLDAQwOMHZeluIxDdW0zTL1xMgFbdUVOrLxkxPngMVae4TMgr2nenEPPX0ITa cIK/4UQZpb9O8MfFj6jQAcfMciYYkDrZf0O7jydjK3S8RGPnqj8s/4QSOMLVHw5Hes6Y Gg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug93s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:17 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LFDe028580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:16 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277LFsV005114; Thu, 7 Mar 2019 07:21:15 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:14 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:12 -0800 Message-Id: <20190307072112.8379-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 07/37] multi-process: define proxy-link object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Defines proxy-link object which forms the communication link between QEMU & emulation program. Adds functions to configure members of proxy-link object instance. Adds functions to send and receive messages over the communication channel. Adds GMainLoop to handle events received on the communication channel. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- include/glib-compat.h | 4 + include/io/proxy-link.h | 136 ++++++++++++++++++++++++ io/Makefile.objs | 2 + io/proxy-link.c | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 417 insertions(+) create mode 100644 include/io/proxy-link.h create mode 100644 io/proxy-link.c diff --git a/include/glib-compat.h b/include/glib-compat.h index 1291628..6189b9a 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -19,12 +19,16 @@ /* Ask for warnings for anything that was marked deprecated in * the defined version, or before. It is a candidate for rewrite. */ +#ifndef GLIB_VERSION_MIN_REQUIRED #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40 +#endif /* Ask for warnings if code tries to use function that did not * exist in the defined version. These risk breaking builds */ +#ifndef GLIB_VERSION_MAX_ALLOWED #define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_40 +#endif #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h new file mode 100644 index 0000000..ff602e4 --- /dev/null +++ b/include/io/proxy-link.h @@ -0,0 +1,136 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 PROXY_LINK_H +#define PROXY_LINK_H + +#include +#include +#include +#include + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "qemu/thread.h" + +typedef struct ProxyLinkState ProxyLinkState; + +#define TYPE_PROXY_LINK "proxy-link" +#define PROXY_LINK(obj) \ + OBJECT_CHECK(ProxyLinkState, (obj), TYPE_PROXY_LINK) + +#define REMOTE_MAX_FDS 8 + +#define PROC_HDR_SIZE offsetof(ProcMsg, data1.u64) + +/* + * proc_cmd_t enum type to specify the command to be executed on the remote + * device + * + * Following commands are supported: + * CONF_READ PCI config. space read + * CONF_WRITE PCI config. space write + * + */ +typedef enum { + INIT = 0, + CONF_READ, + CONF_WRITE, + MAX, +} proc_cmd_t; + +/* + * ProcMsg Format of the message sent to the remote device from QEMU + * + * 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 + * + */ +typedef struct { + proc_cmd_t cmd; + int bytestream; + size_t size; + + union { + uint64_t u64; + } data1; + + int fds[REMOTE_MAX_FDS]; + int num_fds; + + uint8_t *data2; +} ProcMsg; + +struct conf_data_msg { + uint32_t addr; + uint32_t val; + int l; +}; + +typedef void (*proxy_link_callback)(GIOCondition cond); + +typedef struct ProxySrc { + GSource gsrc; + GPollFD gpfd; +} ProxySrc; + +/* + * ProxyLinkState Instance info. of the communication + * link between QEMU and remote process + * + * ctx GMainContext to be used for communication + * loop Main loop that would be used to poll for incoming data + * src Source fds to poll on, and which events to poll on + * sock Unix socket used for the link + * lock Lock to synchronize access to the link + * + */ +struct ProxyLinkState { + Object obj; + + GMainContext *ctx; + GMainLoop *loop; + ProxySrc *src; + + int sock; + QemuMutex lock; + + proxy_link_callback callback; +}; + +ProxyLinkState *proxy_link_create(void); +void proxy_link_finalize(ProxyLinkState *s); + +void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg); +int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg); +void proxy_link_set_sock(ProxyLinkState *s, int fd); +void proxy_link_set_callback(ProxyLinkState *s, proxy_link_callback callback); +void start_handler(ProxyLinkState *s); + +#endif diff --git a/io/Makefile.objs b/io/Makefile.objs index 9a20fce..ff88b46 100644 --- a/io/Makefile.objs +++ b/io/Makefile.objs @@ -10,3 +10,5 @@ io-obj-y += channel-util.o io-obj-y += dns-resolver.o io-obj-y += net-listener.o io-obj-y += task.o + +io-obj-$(CONFIG_MPQEMU) += proxy-link.o diff --git a/io/proxy-link.c b/io/proxy-link.c new file mode 100644 index 0000000..9ea0ed7 --- /dev/null +++ b/io/proxy-link.c @@ -0,0 +1,275 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/module.h" +#include "io/proxy-link.h" +#include "qemu/log.h" + +static void proxy_link_inst_init(Object *obj) +{ + ProxyLinkState *s = PROXY_LINK(obj); + + qemu_mutex_init(&s->lock); + + s->sock = STDIN_FILENO; + s->ctx = g_main_context_new(); + s->loop = g_main_loop_new(s->ctx, FALSE); +} + +static const TypeInfo proxy_link_info = { + .name = TYPE_PROXY_LINK, + .parent = TYPE_OBJECT, + .instance_size = sizeof(ProxyLinkState), + .instance_init = proxy_link_inst_init, +}; + +static void proxy_link_register_types(void) +{ + type_register_static(&proxy_link_info); +} + +type_init(proxy_link_register_types) + +ProxyLinkState *proxy_link_create(void) +{ + return PROXY_LINK(object_new(TYPE_PROXY_LINK)); +} + +void proxy_link_finalize(ProxyLinkState *s) +{ + g_source_unref(&s->src->gsrc); + g_main_loop_unref(s->loop); + g_main_context_unref(s->ctx); + g_main_loop_quit(s->loop); + + close(s->sock); + + qemu_mutex_destroy(&s->lock); + + object_unref(OBJECT(s)); +} + +void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg) +{ + int rc; + uint8_t *data; + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))] = { }; + struct msghdr hdr; + struct cmsghdr *chdr; + + struct iovec iov = { + .iov_base = (char *) msg, + .iov_len = PROC_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(control, 0, sizeof(control)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + + if (msg->num_fds > REMOTE_MAX_FDS) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__); + return; + } + + if (msg->num_fds > 0) { + size_t fdsize = msg->num_fds * sizeof(int); + + hdr.msg_control = control; + hdr.msg_controllen = sizeof(control); + + chdr = CMSG_FIRSTHDR(&hdr); + chdr->cmsg_len = CMSG_LEN(fdsize); + chdr->cmsg_level = SOL_SOCKET; + chdr->cmsg_type = SCM_RIGHTS; + memcpy(CMSG_DATA(chdr), msg->fds, fdsize); + hdr.msg_controllen = chdr->cmsg_len; + } + + qemu_mutex_lock(&s->lock); + + do { + rc = sendmsg(s->sock, &hdr, 0); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + + if (rc < 0) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d," + " sock %d\n", __func__, rc, errno, s->sock); + qemu_mutex_unlock(&s->lock); + return; + } + + if (msg->bytestream) { + data = msg->data2; + } else { + data = (uint8_t *)msg + PROC_HDR_SIZE; + } + + do { + rc = write(s->sock, data, msg->size); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + + qemu_mutex_unlock(&s->lock); +} + + +int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg) +{ + int rc; + uint8_t *data; + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))] = { }; + struct msghdr hdr; + struct cmsghdr *chdr; + size_t fdsize; + + struct iovec iov = { + .iov_base = (char *) msg, + .iov_len = PROC_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(control, 0, sizeof(control)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = control; + hdr.msg_controllen = sizeof(control); + + qemu_mutex_lock(&s->lock); + + do { + rc = recvmsg(s->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, s->sock); + qemu_mutex_unlock(&s->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); + 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; + } + + if (msg->size) { + do { + rc = read(s->sock, data, msg->size); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + } + + qemu_mutex_unlock(&s->lock); + + return rc; +} + +static gboolean proxy_link_handler_prepare(GSource *gsrc, gint *timeout) +{ + g_assert(timeout); + + *timeout = -1; + + return FALSE; +} + +static gboolean proxy_link_handler_check(GSource *gsrc) +{ + ProxySrc *src = (ProxySrc *)gsrc; + + return src->gpfd.events & src->gpfd.revents; +} + +static gboolean proxy_link_handler_dispatch(GSource *gsrc, GSourceFunc func, + gpointer data) +{ + ProxySrc *src = (ProxySrc *)gsrc; + ProxyLinkState *s = (ProxyLinkState *)data; + + s->callback(src->gpfd.revents); + + if ((src->gpfd.revents & G_IO_HUP) || (src->gpfd.revents & G_IO_ERR)) { + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +void proxy_link_set_sock(ProxyLinkState *s, int fd) +{ + s->sock = fd; +} + +void proxy_link_set_callback(ProxyLinkState *s, proxy_link_callback callback) +{ + s->callback = callback; +} + +void start_handler(ProxyLinkState *s) +{ + GSourceFuncs gsrc_funcs = (GSourceFuncs){ + .prepare = proxy_link_handler_prepare, + .check = proxy_link_handler_check, + .dispatch = proxy_link_handler_dispatch, + .finalize = NULL, + }; + ProxySrc *src = (ProxySrc *)g_source_new(&gsrc_funcs, sizeof(ProxySrc)); + guint id; + + g_source_set_callback(&src->gsrc, NULL, (gpointer)s, NULL); + + src->gpfd.fd = s->sock; + src->gpfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; + g_source_add_poll(&src->gsrc, &src->gpfd); + id = g_source_attach(&src->gsrc, s->ctx); + g_assert(id); + s->src = src; + + g_main_loop_run(s->loop); +} From patchwork Thu Mar 7 07:21:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8E861515 for ; Thu, 7 Mar 2019 07:32:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92DB22E8D3 for ; Thu, 7 Mar 2019 07:32:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86C482E54A; Thu, 7 Mar 2019 07:32:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20C0C2E54A for ; Thu, 7 Mar 2019 07:32:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:46702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nWI-0001bc-90 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:32:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLH-0001fK-Hr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLG-0004gl-Og for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:23 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47654) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLG-0004gU-GP for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:22 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JXWp038021; Thu, 7 Mar 2019 07:21:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=APi4SUqNvnOfi0hO7oGrcqrFOHHEzDuV8v6wpwCdkh4=; b=WMTpZueI5caJeG493v4ktiFH0HG5LLNSJ+NWXqh6uibUtmHlJH/alR95QOvdEAQKB553 01wK7XifAlf0Q476oFtvlQeE/nmUgjNXTz4z1U90n5AQtE4vMw+qsrPkjen2wpN5Tuqo wvrkOnUmYoZaMlJp5xZPKHTdGHuFb4tiIUZLdty8NS3gW+gZsalmKf88lVK799Y4XAPt 9OmoSd+Kdo0Uyo7pgfUYI4Id/RZnnF/X0ZuaTksPRDUie1DqNAy/T8wiiumbI0X1cuwx puUoaSEMccgeqm9e+C5D1c3V97LdgSeEf5qxkm0pBJbwLK+UOTNA/GIb+jxRkGPzL3Yu 4w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug93t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:18 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LH8B028713 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:17 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LHRs003570; Thu, 7 Mar 2019 07:21:17 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:17 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:15 -0800 Message-Id: <20190307072115.8428-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 08/37] multi-process: add functions to synchronize proxy and remote endpoints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman In some cases, for example MMIO read, QEMU has to wait for the remote to complete a command before proceeding. An eventfd based mechanism is added to synchronize QEMU & remote process. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- include/io/proxy-link.h | 9 +++++++++ io/proxy-link.c | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index ff602e4..a12c565 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -28,7 +28,9 @@ #include #include #include +#include #include +#include #include "qemu/osdep.h" #include "qom/object.h" @@ -124,11 +126,18 @@ struct ProxyLinkState { proxy_link_callback callback; }; +#define GET_REMOTE_WAIT eventfd(0, 0) +#define PUT_REMOTE_WAIT(wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + ProxyLinkState *proxy_link_create(void); void proxy_link_finalize(ProxyLinkState *s); void proxy_proc_send(ProxyLinkState *s, ProcMsg *msg); int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg); +uint64_t wait_for_remote(int efd); +void notify_proxy(int fd, uint64_t val); + void proxy_link_set_sock(ProxyLinkState *s, int fd); void proxy_link_set_callback(ProxyLinkState *s, proxy_link_callback callback); void start_handler(ProxyLinkState *s); diff --git a/io/proxy-link.c b/io/proxy-link.c index 9ea0ed7..9f6ae77 100644 --- a/io/proxy-link.c +++ b/io/proxy-link.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "qemu/module.h" #include "io/proxy-link.h" @@ -210,6 +211,31 @@ int proxy_proc_recv(ProxyLinkState *s, ProcMsg *msg) return rc; } +uint64_t wait_for_remote(int efd) +{ + uint64_t val; + + 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 proxy_link_handler_prepare(GSource *gsrc, gint *timeout) { g_assert(timeout); From patchwork Thu Mar 7 07:21:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF6CB14E1 for ; Thu, 7 Mar 2019 07:36:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB4D72D84C for ; Thu, 7 Mar 2019 07:36:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEAE52DF23; Thu, 7 Mar 2019 07:36:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0823F2DF0C for ; Thu, 7 Mar 2019 07:36:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:46770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nZS-0005Nl-9k for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:36:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLR-0001o9-B4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLQ-0004sg-5R for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:33 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLP-0004r5-Rq for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:32 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JJL8033918; Thu, 7 Mar 2019 07:21:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=L01sM7r3u3023qhdAD4ym+sY4h6Tt5dDELYjPp5BObw=; b=PfRYKtL3+egyXbThFaI2CLOCXPEE7n2YWe3r6M8+5xyS63SOxNCYmjyRwacGptqY8Gsr s36DOZQKsFiFjTTmmJD1pMhcIfMtJH88oWLp1gV0kqWCLQdfyhcJP6HHeumaRn39zYAQ NpVEcPVuaOEl6GStPRTfOukhmdQGBq+8Xp6qWhlq6wnH1JzUPr/ClYulMqLY6Q9y5KDF MFuGmAefVOL++NT5ev9+b41TWBmdeg/yTWS8LxenQoZ0Brapo4p+cJjnQJyUWNNhVJY5 mwy2NoWatGYjopLPBp2HNi+Ymn8MkfAA8ACvftWPtv7KkiCS6zoaKz5xAiTjwKM+P/C2 Hw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbeggf6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:27 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LQcP029346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:27 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LQLN011250; Thu, 7 Mar 2019 07:21:26 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:25 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:17 -0800 Message-Id: <20190307072117.8474-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 09/37] multi-process: setup PCI host bridge for remote device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, mst@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman PCI host bridge is setup for the remote device process. It is implemented using remote-pcihost object. It is an extension of the PCI host bridge setup by QEMU. Remote-pcihost configures a PCI bus which could be used by the remote PCI device to latch on to. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hw/pci/Makefile.objs | 2 +- include/remote/pcihost.h | 58 +++++++++++++++++++++++++++++++++ remote/Makefile.objs | 1 + remote/pcihost.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 include/remote/pcihost.h create mode 100644 remote/pcihost.c diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs index f62025c..ad50634 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -8,6 +8,6 @@ common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o -remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o pci_host.o pcie_host.o remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o diff --git a/include/remote/pcihost.h b/include/remote/pcihost.h new file mode 100644 index 0000000..4a40f04 --- /dev/null +++ b/include/remote/pcihost.h @@ -0,0 +1,58 @@ +/* + * PCI Host for remote device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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_PCIHOST_H +#define REMOTE_PCIHOST_H + +#include +#include + +#include "exec/memory.h" +#include "hw/pci/pcie_host.h" + +#define TYPE_REMOTE_HOST_DEVICE "remote-pcihost" +#define REMOTE_HOST_DEVICE(obj) \ + OBJECT_CHECK(RemPCIHost, (obj), TYPE_REMOTE_HOST_DEVICE) + +typedef struct RemPCIHost { + /*< private >*/ + PCIExpressHost parent_obj; + /*< public >*/ + + /* Memory Controller Hub (MCH) may not be necessary for the emulation + * program. The two important reasons for implementing a PCI host in the + * emulation program are: + * - Provide a PCI bus for IO devices + * - Enable translation of guest PA to the PCI bar regions + * + * For both the above mentioned purposes, it doesn't look like we would + * need the MCH + */ + + MemoryRegion *mr_pci_mem; + MemoryRegion *mr_sys_mem; + MemoryRegion *mr_sys_io; +} RemPCIHost; + +#endif diff --git a/remote/Makefile.objs b/remote/Makefile.objs index a9b2256..2757f5a 100644 --- a/remote/Makefile.objs +++ b/remote/Makefile.objs @@ -1 +1,2 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o +remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o diff --git a/remote/pcihost.c b/remote/pcihost.c new file mode 100644 index 0000000..74b74b4 --- /dev/null +++ b/remote/pcihost.c @@ -0,0 +1,84 @@ +/* + * Remote PCI host device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" +#include "hw/pci/pcie_host.h" +#include "remote/pcihost.h" +#include "exec/memory.h" + +static const char *remote_host_root_bus_path(PCIHostState *host_bridge, + PCIBus *rootbus) +{ + return "0000:00"; +} + +static void remote_host_realize(DeviceState *dev, Error **errp) +{ + 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); +} + +static Property remote_host_props[] = { + DEFINE_PROP_END_OF_LIST(), +}; + +static void remote_host_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); + + hc->root_bus_path = remote_host_root_bus_path; + dc->realize = remote_host_realize; + dc->props = remote_host_props; + + dc->user_creatable = false; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + dc->fw_name = "pci"; +} + +static const TypeInfo remote_host_info = { + .name = TYPE_REMOTE_HOST_DEVICE, + .parent = TYPE_PCIE_HOST_BRIDGE, + .instance_size = sizeof(RemPCIHost), + .class_init = remote_host_class_init, +}; + +static void remote_machine_register(void) +{ + type_register_static(&remote_host_info); +} + +type_init(remote_machine_register) From patchwork Thu Mar 7 07:21:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A16EE1515 for ; Thu, 7 Mar 2019 07:23:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84BD72E7CE for ; Thu, 7 Mar 2019 07:23:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78EED2E87A; Thu, 7 Mar 2019 07:23:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B4B222E86E for ; Thu, 7 Mar 2019 07:23:08 +0000 (UTC) Received: from localhost ([127.0.0.1]:46568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMy-00039B-15 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:23:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLS-0001pG-Nq for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLR-0004tH-Cr for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:34 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLR-0004sw-2x for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:33 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JZqc038035; Thu, 7 Mar 2019 07:21:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=wYnnoSXU+1d/KhZOCgDJekyzwsFjEAIXu45BWuWA5ck=; b=04zuOyVyYw35OJOmqEzskLvf7tK/mAcCmULmxieTkO0plHhVdS2aXJqtok7p8AeQ2vBn rtJNjJZV1c9RqfVA6byrS/+XjBvqBzIwGJ9h6WoCJdMqJNn8ff7YgHi7bu2FUFYRQ87K CIIqA9tUz7PrQu4/EMphX9dDjr3q67EMvUSZhWiJDOIMAWJB1gQrMcsd/MCPRDe3WNwv AeXBMUM+tdv/ge/BIdAkYzTRoSQpJUCdpRiXYhBZFURl4SMs8xvK88Z/DW31a3DI0T8i ZQYeiDeXPVVgRmtt27yB7udl2lZ70LYd4WeADGRHGTFOAIeM2JArrJAHhyedIHDWemhO IQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug94g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:30 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LTHx029547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:29 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LTOd003796; Thu, 7 Mar 2019 07:21:29 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:28 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:26 -0800 Message-Id: <20190307072126.8520-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 10/37] multi-process: setup a machine object for remote device process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- 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 diff --git a/exec.c b/exec.c index dcef041..4b7b3bc 100644 --- a/exec.c +++ b/exec.c @@ -193,7 +193,6 @@ typedef struct subpage_t { #define PHYS_SECTION_WATCH 3 static void io_mem_init(void); -static void memory_map_init(void); static void tcg_commit(MemoryListener *listener); static MemoryRegion io_mem_watch; @@ -3090,7 +3089,7 @@ static void tcg_commit(MemoryListener *listener) tlb_flush(cpuas->cpu); } -static void memory_map_init(void) +void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); diff --git a/include/exec/address-spaces.h b/include/exec/address-spaces.h index db8bfa9..56a877b 100644 --- a/include/exec/address-spaces.h +++ b/include/exec/address-spaces.h @@ -33,6 +33,8 @@ MemoryRegion *get_system_memory(void); */ MemoryRegion *get_system_io(void); +void memory_map_init(void); + extern AddressSpace address_space_memory; extern AddressSpace address_space_io; diff --git a/include/remote/machine.h b/include/remote/machine.h new file mode 100644 index 0000000..fe1e11b --- /dev/null +++ b/include/remote/machine.h @@ -0,0 +1,46 @@ +/* + * Remote machine configuration + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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_MACHINE_H +#define REMOTE_MACHINE_H + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "hw/boards.h" +#include "remote/pcihost.h" +#include "qemu/notify.h" + +typedef struct RemMachineState { + MachineState parent_obj; + + RemPCIHost *host; +} RemMachineState; + +#define TYPE_REMOTE_MACHINE "remote-machine" +#define REMOTE_MACHINE(obj) \ + OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE) + +void qemu_run_machine_init_done_notifiers(void); + +#endif diff --git a/remote/Makefile.objs b/remote/Makefile.objs index 2757f5a..13d4c48 100644 --- a/remote/Makefile.objs +++ b/remote/Makefile.objs @@ -1,2 +1,3 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine.o diff --git a/remote/machine.c b/remote/machine.c new file mode 100644 index 0000000..7001789 --- /dev/null +++ b/remote/machine.c @@ -0,0 +1,118 @@ +/* + * Machine for remote device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 +#include + +#include "qemu/osdep.h" +#include "remote/pcihost.h" +#include "remote/machine.h" +#include "exec/address-spaces.h" +#include "exec/memory.h" +#include "exec/ioport.h" +#include "exec/ramlist.h" +#include "qemu/thread.h" +#include "qom/object.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/main-loop.h" +#include "qemu-common.h" +#include "sysemu/sysemu.h" +#include "qemu/notify.h" + +static 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); + } +} + +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); +} + +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); + + object_property_add_child(object_get_root(), "machine", obj, &error_abort); + if (error_abort) { + error_report_err(error_abort); + } + + memory_map_init(); + + system_memory = get_system_memory(); + system_io = get_system_io(); + + pci_memory = g_new(MemoryRegion, 1); + memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); + + rem_host = REMOTE_HOST_DEVICE(qdev_create(NULL, TYPE_REMOTE_HOST_DEVICE)); + + rem_host->mr_pci_mem = pci_memory; + rem_host->mr_sys_mem = system_memory; + rem_host->mr_sys_io = system_io; + + s->host = rem_host; + + qemu_mutex_lock_iothread(); + memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1); + qemu_mutex_unlock_iothread(); + + qdev_init_nofail(DEVICE(rem_host)); +} + +static const TypeInfo remote_machine = { + .name = TYPE_REMOTE_MACHINE, + .parent = TYPE_MACHINE, + .instance_size = sizeof(RemMachineState), + .instance_init = remote_machine_init, +}; + +static void remote_machine_register_types(void) +{ + type_register_static(&remote_machine); +} + +type_init(remote_machine_register_types); diff --git a/remote/remote-main.c b/remote/remote-main.c index 53c2aa5..d5304fb 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -26,10 +26,17 @@ #include "qemu/osdep.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; } From patchwork Thu Mar 7 07:21:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842285 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E61D139A for ; Thu, 7 Mar 2019 07:30:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84DEB2E14C for ; Thu, 7 Mar 2019 07:30:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 782C42E170; Thu, 7 Mar 2019 07:30:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C367A2E14C for ; Thu, 7 Mar 2019 07:30:54 +0000 (UTC) Received: from localhost ([127.0.0.1]:46693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nUU-0001QF-10 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:30:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLV-0001s7-SU for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLU-0004ux-ME for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:37 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLU-0004ug-ED for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:36 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JUug034126; Thu, 7 Mar 2019 07:21:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=txTw6l4miynysw0esvhOCPciTN6D148zs5oj3DULPiE=; b=iDSdyU9ieB3MUXnkZv0FqCGQjX4xJfnO1pI7l2pjv7bykIX7jlaARd5Ij3OL5dk/igJB BIBcHux/ZB7rwJweCVm7SD04dh7QlqpoGtQgg2LyYksmOtRsz8wbCoKJW7ar92kz5Kpv auof9GJl7UPd4zsmRrq64EfvzI1124x/PlS2oLjqHN8dTGbE/1ShsYAVKrIkXmWygeYl z/r1tEKJrrxu1rptwr5a+88zu0gF6NMvJjyetsCKmG08F9F/wCEyaAVenqDIZfsityfV kOJF1Ix9lxHv9QneKzQYHKc+2gqF+lAjqSjW/PWIWBzBrc5BmdXESoh4koy7UaDp1luX JQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2qyfbeggfc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:33 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LWuV031050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:32 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LW7V003809; Thu, 7 Mar 2019 07:21:32 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:31 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:29 -0800 Message-Id: <20190307072129.8567-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 11/37] multi-process: setup memory manager for remote device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman sync_sysmem_msg_t message format is defined. It is used to send file descriptors of the RAM regions to remote device. RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- Makefile.target | 2 + include/io/proxy-link.h | 11 ++++++ include/remote/memory.h | 34 +++++++++++++++++ remote/memory.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 include/remote/memory.h create mode 100644 remote/memory.c diff --git a/Makefile.target b/Makefile.target index 81335c6..fc0c579 100644 --- a/Makefile.target +++ b/Makefile.target @@ -130,6 +130,8 @@ 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) += remote/memory.o + ######################################################### # Linux user emulator target diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index a12c565..521df4f 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -35,6 +35,8 @@ #include "qemu/osdep.h" #include "qom/object.h" #include "qemu/thread.h" +#include "exec/cpu-common.h" +#include "exec/hwaddr.h" typedef struct ProxyLinkState ProxyLinkState; @@ -53,12 +55,14 @@ typedef struct ProxyLinkState ProxyLinkState; * Following commands are supported: * CONF_READ PCI config. space read * CONF_WRITE PCI config. space write + * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * */ typedef enum { INIT = 0, CONF_READ, CONF_WRITE, + SYNC_SYSMEM, MAX, } proc_cmd_t; @@ -75,12 +79,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 { proc_cmd_t cmd; int bytestream; size_t size; union { uint64_t u64; + sync_sysmem_msg_t sync_sysmem; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/memory.h b/include/remote/memory.h new file mode 100644 index 0000000..6a32669 --- /dev/null +++ b/include/remote/memory.h @@ -0,0 +1,34 @@ +/* + * Memory manager for remote device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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/proxy-link.h" + +void remote_sysmem_reconfig(ProcMsg *msg, Error **errp); + +#endif diff --git a/remote/memory.c b/remote/memory.c new file mode 100644 index 0000000..aa76199 --- /dev/null +++ b/remote/memory.c @@ -0,0 +1,98 @@ +/* + * Memory manager for remote device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 +#include + +#include "qemu/osdep.h" +#include "qemu/queue.h" +#include "qemu-common.h" +#include "remote/memory.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" +#include "cpu.h" +#include "exec/ram_addr.h" +#include "io/proxy-link.h" +#include "qemu/main-loop.h" +#include "qapi/error.h" + +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); + mr->ram = true; + mr->terminates = true; + mr->destructor = remote_ram_destructor; + 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); +} + +void remote_sysmem_reconfig(ProcMsg *msg, Error **errp) +{ + sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem; + MemoryRegion *sysmem, *subregion, *next; + Error *local_err = NULL; + int region; + + sysmem = get_system_memory(); + + qemu_mutex_lock_iothread(); + + memory_region_transaction_begin(); + + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) { + if (subregion->ram) { + memory_region_del_subregion(sysmem, subregion); + /* TODO: should subregion be finalized separately? */ + } + } + + for (region = 0; region < msg->num_fds; region++) { + subregion = g_new(MemoryRegion, 1); + remote_ram_init_from_fd(subregion, msg->fds[region], + sysmem_info->sizes[region], + sysmem_info->offsets[region], &local_err); + if (local_err) { + error_propagate(errp, local_err); + break; + } + + memory_region_add_subregion(sysmem, sysmem_info->gpas[region], + subregion); + } + + memory_region_transaction_commit(); + + qemu_mutex_unlock_iothread(); +} From patchwork Thu Mar 7 07:21:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09C7714DE for ; Thu, 7 Mar 2019 07:28:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCED528D98 for ; Thu, 7 Mar 2019 07:28:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA6F828C16; Thu, 7 Mar 2019 07:28:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F94926253 for ; Thu, 7 Mar 2019 07:28:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:46639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nSb-0006xS-GU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:28:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLb-0001x9-ME for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLa-0004wx-T4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:43 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55304) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLa-0004wh-KQ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:42 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JL0q037943; Thu, 7 Mar 2019 07:21:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=1H9635U3ZeUQish7hUVDvcDGuquGhkpFSgr83dGpylM=; b=j5bNAHaXCTpCJwi+wSOGyZN3TrcIyQ/qICB7Jv6hNoTynIY1jdhHtcNI3bVK6A5l81ff vv0XeUA9KR1130X+cqaITRnnPRcuCOnlsUDtXvySE6cykRVu80RJi8iOHS/bP7+BRJKV zVSSAFv1Y5mhgNvOzfmh0hapwr6cvcbFx4UbR9Y46+XoSzjFiM1wBfrSesDLCOTiqU3L eNVL7jA9BO8TqLEwC9906JIMPJK6tcC9S4FUiqT5F9gtsTs60xmUxSiNUhB4ieK58zsk VBNA64dIQtZAVCTCXboFCfwwZBwTUdum9lZ9pNa05HwBi4llIzO3H2Mtn24SYUss2+gx Nw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qyjfrr5bj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:35 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277LZJ0004412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:35 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LYSH011298; Thu, 7 Mar 2019 07:21:34 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:34 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:32 -0800 Message-Id: <20190307072132.8630-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 12/37] multi-process: remote process initialization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Adds the handler to process message from QEMU, Initialize remote process main loop, handles SYNC_SYSMEM message by updating its "system_memory" container using shared file descriptors received from QEMU. Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- remote/remote-main.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index d5304fb..b15e299 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -23,6 +23,8 @@ */ #include +#include +#include #include "qemu/osdep.h" #include "qemu/module.h" @@ -31,12 +33,108 @@ #include "hw/boards.h" #include "hw/qdev-core.h" #include "qemu/main-loop.h" +#include "remote/memory.h" +#include "io/proxy-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 ProxyLinkState *proxy_link; +PCIDevice *remote_pci_dev; + +static void process_msg(GIOCondition cond) +{ + ProcMsg *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(ProcMsg)); + + if (proxy_proc_recv(proxy_link, msg) < 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); + proxy_link_finalize(proxy_link); + proxy_link = NULL; +} + +static void *remote_main_loop(void *data) +{ + while (1) { + qemu_mutex_lock_iothread(); + main_loop_wait(false); + qemu_mutex_unlock_iothread(); + } + + return NULL; +} int main(int argc, char *argv[]) { + Error *err = NULL; + QemuThread main_loop_thread; + 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))); + proxy_link = proxy_link_create(); + if (!proxy_link) { + printf("Could not create proxy link\n"); + return -1; + } + + proxy_link_set_sock(proxy_link, STDIN_FILENO); + proxy_link_set_callback(proxy_link, process_msg); + + qemu_thread_create(&main_loop_thread, "remote-main-loop", remote_main_loop, + NULL, QEMU_THREAD_DETACHED); + + start_handler(proxy_link); + + qemu_thread_cancel(&main_loop_thread); + return 0; } From patchwork Thu Mar 7 07:21:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 333CD14E1 for ; Thu, 7 Mar 2019 07:39:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F5182DDFC for ; Thu, 7 Mar 2019 07:39:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10B772DE17; Thu, 7 Mar 2019 07:39:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AE6C2DDFC for ; Thu, 7 Mar 2019 07:39:11 +0000 (UTC) Received: from localhost ([127.0.0.1]:46794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ncU-0007uG-8w for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:39:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLg-00021C-A0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLe-0004xu-Qx for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:48 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50116) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLe-0004xd-Ij for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:46 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JDUS033900; Thu, 7 Mar 2019 07:21:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=JSNOQVGsnoizDY8VovABP0cHrJQqn7NiIdeOLH4wCq8=; b=Ne9RA6aZOmp208Di8e5h/VZsggeBNkommcgpe4PqPN4p1jtWhm2HZDvmSoqsEBLMtfHL ib6CvZBOi4QVzoQGon5e/uo1ow7Zs2TLzS6vzKxef7QJFw/J2RCGV/8naJXPUpS8lzhC yJos49puCUuFle5Q3SVHNpHc4S9TJm69NJE7lOFWFWrk57Azssoj65UkBkI7FrlDrqjr +0r8uwY8qsIDS5by4SDmt2R6cibM+7c9Ceju8u65i4DLuiFW+veMjGC37hRmawE6COKC 0+ydj0evHIKIr+DuinwcMnZyLX8r5cIjcqT3CdT3z9O/vlKotCB/TA4L2lCpIatbk9bB fw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2qyfbeggfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:38 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277LbZA014631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:37 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277LbQO003834; Thu, 7 Mar 2019 07:21:37 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:36 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:34 -0800 Message-Id: <20190307072134.8687-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 13/37] multi-process: introduce proxy object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Defines a PCI Device proxy object as a parent of TYPE_PCI_DEVICE. PCI Proxy Object is responsible for registering PCI BARs,i MemoryRegionOps to handle access to the BARs and forwarding those to the remote device. PCI Proxy object intercepts config space reads and writes. In case of pci config write it forwards it to the remote device using communication channel set by proxy-link object. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- hw/Makefile.objs | 2 + hw/proxy/Makefile.objs | 1 + hw/proxy/qemu-proxy.c | 203 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 68 ++++++++++++++ remote/remote-main.c | 28 ++++++ 5 files changed, 302 insertions(+) create mode 100644 hw/proxy/Makefile.objs create mode 100644 hw/proxy/qemu-proxy.c create mode 100644 include/hw/proxy/qemu-proxy.h diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 4cbfdff..7449c50 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -40,6 +40,8 @@ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) +common-obj-$(CONFIG_MPQEMU) += proxy/ + remote-pci-obj-$(CONFIG_MPQEMU) += core/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += pci/ diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs new file mode 100644 index 0000000..eb81624 --- /dev/null +++ b/hw/proxy/Makefile.objs @@ -0,0 +1 @@ +common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c new file mode 100644 index 0000000..91cc82b --- /dev/null +++ b/hw/proxy/qemu-proxy.c @@ -0,0 +1,203 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 +#include +#include +#include +#include +#include +#include +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "io/proxy-link.h" +#include "exec/memory.h" +#include "exec/cpu-common.h" +#include "exec/address-spaces.h" +#include "qemu/int128.h" +#include "qemu/range.h" +#include "hw/pci/pci.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" +#include "sysemu/sysemu.h" +#include "hw/proxy/qemu-proxy.h" + +static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); + +static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, + unsigned int op) +{ + ProcMsg msg; + struct conf_data_msg conf_data; + int wait; + + memset(&msg, 0, sizeof(ProcMsg)); + conf_data.addr = addr; + conf_data.val = (op == CONF_WRITE) ? *val : 0; + conf_data.l = l; + + msg.data2 = (uint8_t *)malloc(sizeof(conf_data)); + if (!msg.data2) { + printf("Failed to allocate memory for msg.data2."); + return -ENOMEM; + } + + memcpy(msg.data2, (const uint8_t *)&conf_data, sizeof(conf_data)); + msg.size = sizeof(conf_data); + msg.cmd = op; + msg.bytestream = 1; + + if (op == CONF_WRITE) { + msg.num_fds = 0; + } else { + wait = GET_REMOTE_WAIT; + msg.num_fds = 1; + msg.fds[0] = wait; + } + + proxy_proc_send(dev->proxy_link, &msg); + + if (op == CONF_READ) { + *val = (uint32_t)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } + + 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); + + config_op_send(PCI_PROXY_DEV(d), addr, &val, len, CONF_READ); + + return val; +} + +static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val, + int l) +{ + pci_default_write_config(d, addr, val, l); + + config_op_send(PCI_PROXY_DEV(d), addr, &val, l, CONF_WRITE); +} + +static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) +{ + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->realize = pci_proxy_dev_realize; + k->config_read = pci_proxy_read_config; + k->config_write = pci_proxy_write_config; +} + +static const TypeInfo pci_proxy_dev_type_info = { + .name = TYPE_PCI_PROXY_DEV, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(PCIProxyDev), + .abstract = true, + .class_size = sizeof(PCIProxyDevClass), + .class_init = pci_proxy_dev_class_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + +static void pci_proxy_dev_register_types(void) +{ + type_register_static(&pci_proxy_dev_type_info); +} + +type_init(pci_proxy_dev_register_types) + +static void init_emulation_process(PCIProxyDev *pdev, const char *command, Error **errp) +{ + char *args[2]; + pid_t rpid; + int fd[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + error_setg(errp, "Unable to create unix socket."); + return; + } + + /* TODO: Restrict the forked process' permissions and capabilities. */ + rpid = qemu_fork(errp); + + if (rpid == -1) { + error_setg(errp, "Unable to spawn emulation program."); + close(fd[0]); + close(fd[1]); + return; + } + + if (rpid == 0) { + if (dup2(fd[1], STDIN_FILENO) != STDIN_FILENO) { + perror("Failed to acquire socket."); + exit(1); + } + + close(fd[0]); + close(fd[1]); + + args[0] = g_strdup(command); + args[1] = NULL; + execvp(args[0], (char *const *)args); + exit(1); + } + + pdev->proxy_link = proxy_link_create(); + + if (!pdev->proxy_link) { + error_setg(errp, "Failed to create proxy link"); + close(fd[0]); + close(fd[1]); + return; + } + + proxy_link_set_sock(pdev->proxy_link, fd[0]); + + close(fd[1]); +} + +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; + + init_emulation_process(dev, k->command, errp); + + if (k->realize) { + k->realize(dev, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + } +} diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h new file mode 100644 index 0000000..0b0d94a --- /dev/null +++ b/include/hw/proxy/qemu-proxy.h @@ -0,0 +1,68 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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/proxy-link.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV(obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_CLASS(klass) \ + OBJECT_CLASS_CHECK(PCIProxyDevClass, (klass), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_GET_CLASS(obj) \ + OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { + PCIDevice parent_dev; + + int n_mr_sections; + MemoryRegionSection *mr_sections; + + ProxyLinkState *proxy_link; + + EventNotifier intr; + EventNotifier resample; + + pid_t remote_pid; + char *rid; + + QLIST_ENTRY(PCIProxyDev) next; + + void (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd); + void (*proxy_ready) (PCIDevice *dev); + +} PCIProxyDev; + +typedef struct PCIProxyDevClass { + PCIDeviceClass parent_class; + + void (*realize)(PCIProxyDev *dev, Error **errp); + + char *command; +} PCIProxyDevClass; + +#endif /* QEMU_PROXY_H */ diff --git a/remote/remote-main.c b/remote/remote-main.c index b15e299..f708be2 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -49,6 +49,32 @@ static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; +static void process_config_write(ProcMsg *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(ProcMsg *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) { ProcMsg *msg = NULL; @@ -70,8 +96,10 @@ static void process_msg(GIOCondition cond) 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"); From patchwork Thu Mar 7 07:21:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA48B1515 for ; Thu, 7 Mar 2019 07:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3AE82E2D3 for ; Thu, 7 Mar 2019 07:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7C752E3A6; Thu, 7 Mar 2019 07:32:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 303A62E2D3 for ; Thu, 7 Mar 2019 07:32:04 +0000 (UTC) Received: from localhost ([127.0.0.1]:46704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nVb-0002En-9b for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:32:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLm-00026R-AM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLl-000514-8q for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:54 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLk-000501-V6 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:21:53 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JUb0037979; Thu, 7 Mar 2019 07:21:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=zxtJcc2/d6aPj6fVKyjkBz213OIhe1WHAYYKyRh8pNw=; b=RmJLAOYzNKz+7jwOmse245UbYvyqExZBv5C3SpHB3uB/yTBrimazYNqemGhwtXD4kNir LW5ttRRoyn4+srOdgq3ni6u8Udm5rX9PPuBy6K9Cf4wDAG5Jl6zQboguMqdf9ETPLIkS fhl7h11lmxDmHCn1yQchULapFGbme+b7VRsJc1rry6GexxOalIWOsGhn4YVQAbtdaBjO fkJZL8AxbHOHfIF24/4ENwKpNY82VLaw00/CgtDiFfl5PaD7NtrF+lQligyUyYcYYVWF ZC87EacJAGpUJd1xvbcFMobEH6+D2s7iu5TlWjIMri9+EKDQ137i/AmUIOeLyYRRxTTO Ow== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qyjfrr5c7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:50 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LiOE031667 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:44 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277Li1j011360; Thu, 7 Mar 2019 07:21:44 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:44 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:37 -0800 Message-Id: <20190307072137.8735-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 14/37] multi-process: PCI BAR write handling for proxy & remote endpoints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Proxy device object implements handler for PCI BAR writes. The handler sends BAR_WRITE message to the remote process with the BAR address and value to be written The remote process implements handler for BAR_WRITE message. Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson --- hw/proxy/qemu-proxy.c | 28 ++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 3 +++ include/io/proxy-link.h | 10 ++++++++++ remote/remote-main.c | 24 ++++++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 91cc82b..49ed683 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -201,3 +201,31 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) } } } + +static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, + bool write, hwaddr addr, uint64_t *val, + unsigned size, bool memory) +{ + ProcMsg msg; + + memset(&msg, 0, sizeof(ProcMsg)); + + 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; + } + + proxy_proc_send(proxy_link, &msg); +} + +void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, + uint64_t val, unsigned size, bool memory) +{ + send_bar_access_msg(dev->proxy_link, mr, true, addr, &val, size, memory); +} diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 0b0d94a..567a7c6 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -65,4 +65,7 @@ typedef struct PCIProxyDevClass { char *command; } PCIProxyDevClass; +void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, + uint64_t val, unsigned size, bool memory); + #endif /* QEMU_PROXY_H */ diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 521df4f..2884852 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -56,6 +56,7 @@ typedef struct ProxyLinkState ProxyLinkState; * 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 * */ typedef enum { @@ -63,6 +64,7 @@ typedef enum { CONF_READ, CONF_WRITE, SYNC_SYSMEM, + BAR_WRITE, MAX, } proc_cmd_t; @@ -85,6 +87,13 @@ typedef struct { } sync_sysmem_msg_t; typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} bar_access_msg_t; + +typedef struct { proc_cmd_t cmd; int bytestream; size_t size; @@ -92,6 +101,7 @@ typedef struct { union { uint64_t u64; sync_sysmem_msg_t sync_sysmem; + bar_access_msg_t bar_access; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/remote/remote-main.c b/remote/remote-main.c index f708be2..cf7949c 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -45,6 +45,7 @@ #include "qemu/config-file.h" #include "sysemu/sysemu.h" #include "block/block.h" +#include "exec/memattrs.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -75,6 +76,23 @@ static void process_config_read(ProcMsg *msg) PUT_REMOTE_WAIT(wait); } +/* TODO: confirm memtx attrs. */ +static void process_bar_write(ProcMsg *msg, Error **errp) +{ + bar_access_msg_t *bar_access = &msg->data1.bar_access; + AddressSpace *as = + bar_access->memory ? &address_space_memory : &address_space_io; + MemTxResult res; + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)&bar_access->val, bar_access->size, true); + + if (res != MEMTX_OK) { + error_setg(errp, "Could not perform address space write operation," + " inaccessible address: %lx.", bar_access->addr); + } +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -101,6 +119,12 @@ static void process_msg(GIOCondition cond) case CONF_READ: process_config_read(msg); break; + case BAR_WRITE: + process_bar_write(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Mar 7 07:21:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAC0414DE for ; Thu, 7 Mar 2019 07:26:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDAA62E84F for ; Thu, 7 Mar 2019 07:26:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0C992E8C8; Thu, 7 Mar 2019 07:26:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8CC432E84F for ; Thu, 7 Mar 2019 07:26:43 +0000 (UTC) Received: from localhost ([127.0.0.1]:46618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nQQ-00053Y-Rt for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:26:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLv-0002CS-PE for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLu-0005Az-EX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:03 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLu-0005AZ-3W for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:02 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JWkx037984; Thu, 7 Mar 2019 07:21:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=XwAQPebA+bSKr2BmyQvSkU/sOgzAzvxrSDRdPezq6Jo=; b=ZKpnSlznwGCidUYM1JYWGkcdw8Caen77qyZF3NxgXmdlWlHH6WyrR/GcN1q9Y9AW52y6 iT8iM6sAiKvrPTZKUR5j9pb3YW/aWFyg0lQP31HfxhpMVXGufgUF9v6otol4xgH+CQmL refitY+OUQPTEQnvKHCNBS2i1hr4+7Qryg9r1XRcoHs57gqGJHmiR8N5owE/ALJZtXIg iGiHgwPn/vLmmxkvM81B/u+eZkje9ECVqzP3Kkhv9kJFyCFUOgfx3V22oT2CVBbbYwro eCfvo7DA+OLdx+bXN0GkajRi9zrROtCmsNNKx9pioVEcQKOqmNpfrg/Ur+X2DgD3Ya6l 7Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qyjfrr5ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:57 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277Lp4E004973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:51 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277LpPF024211; Thu, 7 Mar 2019 07:21:51 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:50 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:44 -0800 Message-Id: <20190307072144.8781-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 15/37] multi-process: PCI BAR read handling for proxy & remote endpoints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Proxy device object implements the read handler for PCI BAR accesses. The handler sends BAR_READ message to the remote process. The remote process implements handler for BAR_READ message. Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson --- hw/proxy/qemu-proxy.c | 22 +++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 3 +++ include/io/proxy-link.h | 2 ++ remote/remote-main.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 49ed683..08e549e 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -207,6 +207,7 @@ static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, unsigned size, bool memory) { ProcMsg msg; + int wait; memset(&msg, 0, sizeof(ProcMsg)); @@ -219,9 +220,20 @@ static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, 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; } proxy_proc_send(proxy_link, &msg); + + if (!write) { + *val = wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } } void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, @@ -229,3 +241,13 @@ void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, { send_bar_access_msg(dev->proxy_link, mr, true, addr, &val, size, memory); } + +uint64_t proxy_default_bar_read(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, + unsigned size, bool memory) +{ + uint64_t val; + + send_bar_access_msg(dev->proxy_link, mr, false, addr, &val, size, memory); + + return val; +} diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 567a7c6..e8d3a9c 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -68,4 +68,7 @@ typedef struct PCIProxyDevClass { void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, uint64_t val, unsigned size, bool memory); +uint64_t proxy_default_bar_read(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, + unsigned size, bool memory); + #endif /* QEMU_PROXY_H */ diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 2884852..dc3c074 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -57,6 +57,7 @@ typedef struct ProxyLinkState ProxyLinkState; * 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 * */ typedef enum { @@ -65,6 +66,7 @@ typedef enum { CONF_WRITE, SYNC_SYSMEM, BAR_WRITE, + BAR_READ, MAX, } proc_cmd_t; diff --git a/remote/remote-main.c b/remote/remote-main.c index cf7949c..f0390cc 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -93,6 +93,49 @@ static void process_bar_write(ProcMsg *msg, Error **errp) } } +static void process_bar_read(ProcMsg *msg, Error **errp) +{ + bar_access_msg_t *bar_access = &msg->data1.bar_access; + AddressSpace *as; + int wait = msg->fds[0]; + MemTxResult res; + uint64_t val = 0; + + as = bar_access->memory ? &address_space_memory : &address_space_io; + + assert(bar_access->size <= sizeof(uint64_t)); + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)&val, bar_access->size, false); + + if (res != MEMTX_OK) { + error_setg(errp, "Could not perform address space read operation," + " inaccessible address: %lx.", bar_access->addr); + val = (uint64_t)-1; + goto fail; + } + + switch (bar_access->size) { + case 4: + val = *((uint32_t *)&val); + break; + case 2: + val = *((uint16_t *)&val); + break; + case 1: + val = *((uint8_t *)&val); + break; + default: + error_setg(errp, "Invalid PCI BAR read size"); + return; + } + +fail: + notify_proxy(wait, val); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -125,6 +168,12 @@ static void process_msg(GIOCondition cond) goto finalize_loop; } break; + case BAR_READ: + process_bar_read(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Mar 7 07:21:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18E4A14E1 for ; Thu, 7 Mar 2019 07:42:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AAB2E8D3 for ; Thu, 7 Mar 2019 07:42:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 019FF2E99D; Thu, 7 Mar 2019 07:42:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 451652E8F0 for ; Thu, 7 Mar 2019 07:42:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:46848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nfK-00024K-Bg for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:42:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLv-0002AJ-6k for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLt-0005Am-RE for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:03 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48220) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLt-0005A8-HU for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:01 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JQ6o037995; Thu, 7 Mar 2019 07:21:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=4ILLhrJq3Tp8/p2ijA0GSBnATptAFdDZ7udOQIwagLc=; b=Z6XcwI7rClG9GO/2YeSZQTR6HZstISCjSvwgCunFNq8Y8vleCfcNealFJOxRi5MHn5NI VsB8TGMrtzJ97yK6nq7erFmtfAypt5xzfKUnEzS7hl9tZJSB8Lgh1nNAQHJ2nGdFi0Pd V9feoFMOD1bZaRtEgzjRNqcbqVr9FYpKXtdwetK4Dd29ES2LV/dw++/3soRGVRkw/khn 3RJI4HJ6KQn/Yn+630/76xN2R/rMfM7RGqsZi7v8nnVg759OQk0V69OPwPflNvo+BNqD 4eVJaHpaft4sqBNf3ubHYkmu1u2V1BGlk7OOwCp5Tx86Ue9i91aQH9eXp7p8naaaWPjr qA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug95u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:21:57 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277LtKu031365 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:21:56 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277Ltv4011458; Thu, 7 Mar 2019 07:21:55 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:55 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:50 -0800 Message-Id: <20190307072151.8830-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 16/37] multi-process: Add LSI device proxy object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: 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. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- hw/proxy/Makefile.objs | 1 + hw/proxy/proxy-lsi53c895a.c | 162 ++++++++++++++++++++++++++++++++++++ include/hw/proxy/proxy-lsi53c895a.h | 42 ++++++++++ 3 files changed, 205 insertions(+) create mode 100644 hw/proxy/proxy-lsi53c895a.c create mode 100644 include/hw/proxy/proxy-lsi53c895a.h diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs index eb81624..f562f5a 100644 --- a/hw/proxy/Makefile.objs +++ b/hw/proxy/Makefile.objs @@ -1 +1,2 @@ common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o +common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o diff --git a/hw/proxy/proxy-lsi53c895a.c b/hw/proxy/proxy-lsi53c895a.c new file mode 100644 index 0000000..9a9eb52 --- /dev/null +++ b/hw/proxy/proxy-lsi53c895a.c @@ -0,0 +1,162 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "qemu/bitops.h" +#include "hw/pci/pci.h" +#include "hw/proxy/qemu-proxy.h" +#include "hw/proxy/proxy-lsi53c895a.h" +#include "exec/memory.h" + +static uint64_t proxy_lsi_io_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyLSIState *s = opaque; + + return proxy_default_bar_read(PCI_PROXY_DEV(s), &s->io_io, addr, size, + false); +} + +static void proxy_lsi_io_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyLSIState *s = opaque; + + proxy_default_bar_write(PCI_PROXY_DEV(s), &s->io_io, addr, val, size, + false); +} + +static const MemoryRegionOps proxy_lsi_io_ops = { + .read = proxy_lsi_io_read, + .write = proxy_lsi_io_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, +}; + +static uint64_t proxy_lsi_ram_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyLSIState *s = opaque; + + return proxy_default_bar_read(PCI_PROXY_DEV(s), &s->ram_io, addr, size, + true); +} + +static void proxy_lsi_ram_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyLSIState *s = opaque; + + proxy_default_bar_write(PCI_PROXY_DEV(s), &s->ram_io, addr, val, size, + true); +} + +static const MemoryRegionOps proxy_lsi_ram_ops = { + .read = proxy_lsi_ram_read, + .write = proxy_lsi_ram_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static uint64_t proxy_lsi_mmio_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyLSIState *s = opaque; + + return proxy_default_bar_read(PCI_PROXY_DEV(s), &s->mmio_io, addr, size, + true); +} + +static void proxy_lsi_mmio_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyLSIState *s = opaque; + + proxy_default_bar_write(PCI_PROXY_DEV(s), &s->mmio_io, addr, val, size, + true); +} + +static const MemoryRegionOps proxy_lsi_mmio_ops = { + .read = proxy_lsi_mmio_read, + .write = proxy_lsi_mmio_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, +}; + +static void proxy_lsi_realize(PCIProxyDev *dev, Error **errp) +{ + ProxyLSIState *s = LSI_PROXY_DEV(dev); + PCIDevice *pci_dev = PCI_DEVICE(dev); + uint8_t *pci_conf = pci_dev->config; + + pci_conf[PCI_LATENCY_TIMER] = 0xff; + pci_conf[PCI_INTERRUPT_PIN] = 0x01; + + memory_region_init_io(&s->mmio_io, OBJECT(s), &proxy_lsi_mmio_ops, s, + "proxy-lsi-mmio", 0x400); + memory_region_init_io(&s->ram_io, OBJECT(s), &proxy_lsi_ram_ops, s, + "proxy-lsi-ram", 0x2000); + memory_region_init_io(&s->io_io, OBJECT(s), &proxy_lsi_io_ops, s, + "proxy-lsi-io", 256); + + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_io); + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio_io); + pci_register_bar(pci_dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io); +} + +static void proxy_lsi_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *pci_class = PCI_DEVICE_CLASS(klass); + PCIProxyDevClass *proxy_class = PCI_PROXY_DEV_CLASS(klass); + + proxy_class->realize = proxy_lsi_realize; + proxy_class->command = g_strdup("qemu-scsi-dev"); + + pci_class->vendor_id = PCI_VENDOR_ID_LSI_LOGIC; + pci_class->device_id = PCI_DEVICE_ID_LSI_53C895A; + pci_class->class_id = PCI_CLASS_STORAGE_SCSI; + pci_class->subsystem_id = 0x1000; + + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + + dc->desc = "LSI Proxy Device"; +} + +static const TypeInfo lsi_proxy_dev_type_info = { + .name = TYPE_PROXY_LSI53C895A, + .parent = TYPE_PCI_PROXY_DEV, + .instance_size = sizeof(ProxyLSIState), + .class_init = proxy_lsi_class_init, +}; + +static void lsi_proxy_dev_register_types(void) +{ + type_register_static(&lsi_proxy_dev_type_info); +} + +type_init(lsi_proxy_dev_register_types) diff --git a/include/hw/proxy/proxy-lsi53c895a.h b/include/hw/proxy/proxy-lsi53c895a.h new file mode 100644 index 0000000..6368a4e --- /dev/null +++ b/include/hw/proxy/proxy-lsi53c895a.h @@ -0,0 +1,42 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 LSI_PROXY_H +#define LSI_PROXY_H + +#include "hw/proxy/qemu-proxy.h" + +#define TYPE_PROXY_LSI53C895A "proxy-lsi53c895a" + +#define LSI_PROXY_DEV(obj) \ + OBJECT_CHECK(ProxyLSIState, (obj), TYPE_PROXY_LSI53C895A) + +typedef struct ProxyLSIState { + PCIProxyDev parent_dev; + + MemoryRegion mmio_io; + MemoryRegion ram_io; + MemoryRegion io_io; + +} ProxyLSIState; + +#endif From patchwork Thu Mar 7 07:21:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D642139A for ; Thu, 7 Mar 2019 07:34:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA0492E8F2 for ; Thu, 7 Mar 2019 07:34:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7B922E922; Thu, 7 Mar 2019 07:34:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E43ED2E8F2 for ; Thu, 7 Mar 2019 07:34:12 +0000 (UTC) Received: from localhost ([127.0.0.1]:46710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nXf-0002gx-Tm for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:34:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nLy-0002Ep-4h for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nLw-0005DB-C9 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:06 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nLw-0005BP-0a for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:04 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JsjX038110; Thu, 7 Mar 2019 07:22:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=QuSFAOk+Va5rfatVDGw3m2KNg1CurxZdC61w4rv1k6A=; b=kAM2SF2Z6uJLM8cMatTbSAsIdVRUU31/n/Y9iEFFX7LyXVXJNKHlaiy6Nh8X7Mt1C1q5 NRyojZDv7K3cr2tc2c5GrVglU3sIXYDL6MK1sSlD4aajoM2K97+Y8B2tBXmlf52l2dRb LGAaLytVxTQGvCcTOTfNiG6FFmTDRwytMu5p/1mHKLd5fpzwUdEju7auJ1T7YDVHLSFC ZvzoszKAPOdv+DiwZGH8sq2BJhPvEfxZ68uXLTnlH9hyhavsVc4n5xV+dmwxb8cjcWK8 rZqL+GuzqNDxA/ZfkmgxsU9oaz9u2F2bCwgOwquDvCKYM4mCVTLmByO/IBP/18K2gJR/ LQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qyjfrr5de-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:01 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277M08p032541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:00 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277M0AV024367; Thu, 7 Mar 2019 07:22:00 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:21:59 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:21:55 -0800 Message-Id: <20190307072155.8886-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 17/37] multi-process: Synchronize remote memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, armbru@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add memory-listener object which is used to keep the view of the RAM in sync between QEMU and remote process. A MemoryListener is registered for system-memory AddressSpace. The listener sends SYNC_SYSMEM message to the remote process when memory listener commits the changes to memory, the remote process receives the message and processes it in the handler for SYNC_SYSMEM message. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- Makefile.target | 1 + hw/proxy/memory-sync.c | 214 +++++++++++++++++++++++++++++++++++++++++ hw/proxy/qemu-proxy.c | 6 ++ include/hw/proxy/memory-sync.h | 51 ++++++++++ include/hw/proxy/qemu-proxy.h | 2 + remote/remote-main.c | 11 +++ 6 files changed, 285 insertions(+) create mode 100644 hw/proxy/memory-sync.c create mode 100644 include/hw/proxy/memory-sync.h diff --git a/Makefile.target b/Makefile.target index fc0c579..470c153 100644 --- a/Makefile.target +++ b/Makefile.target @@ -119,6 +119,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 remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/tcg-stub.o diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c new file mode 100644 index 0000000..2f5e229 --- /dev/null +++ b/hw/proxy/memory-sync.c @@ -0,0 +1,214 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 +#include +#include + +#include "qemu/osdep.h" +#include "qemu/compiler.h" +#include "qemu/int128.h" +#include "qemu/range.h" +#include "exec/memory.h" +#include "exec/cpu-common.h" +#include "cpu.h" +#include "exec/ram_addr.h" +#include "exec/address-spaces.h" +#include "io/proxy-link.h" +#include "hw/proxy/memory-sync.h" + +static const TypeInfo remote_mem_sync_type_info = { + .name = TYPE_MEMORY_LISTENER, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteMemSync), +}; + +static void remote_mem_sync_register_types(void) +{ + type_register_static(&remote_mem_sync_type_info); +} + +type_init(remote_mem_sync_register_types) + +static void proxy_ml_begin(MemoryListener *listener) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + int mrs; + + for (mrs = 0; mrs < sync->n_mr_sections; mrs++) { + memory_region_unref(sync->mr_sections[mrs].mr); + } + + g_free(sync->mr_sections); + sync->mr_sections = NULL; + sync->n_mr_sections = 0; +} + +static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size) +{ + bool merge; + ram_addr_t offset; + int fd1, fd2; + MemoryRegion *mr; + + mr = memory_region_from_host((void *)(uintptr_t)host, &offset); + fd1 = memory_region_get_fd(mr); + + mr = memory_region_from_host((void *)(uintptr_t)prev_host, &offset); + fd2 = memory_region_get_fd(mr); + + merge = (fd1 == fd2); + + merge &= ((prev_host + size) == host); + + return merge; +} + +static void proxy_ml_region_addnop(MemoryListener *listener, + MemoryRegionSection *section) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + bool need_add = true; + uint64_t mrs_size, mrs_gpa, mrs_page; + uintptr_t mrs_host; + RAMBlock *mrs_rb; + MemoryRegionSection *prev_sec; + + if (!(memory_region_is_ram(section->mr) && + !memory_region_is_rom(section->mr))) { + return; + } + + mrs_rb = section->mr->ram_block; + mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb); + mrs_size = int128_get64(section->size); + mrs_gpa = section->offset_within_address_space; + mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + + mrs_host = mrs_host & ~(mrs_page - 1); + mrs_gpa = mrs_gpa & ~(mrs_page - 1); + mrs_size = ROUND_UP(mrs_size, mrs_page); + + if (sync->n_mr_sections) { + prev_sec = sync->mr_sections + (sync->n_mr_sections - 1); + uint64_t prev_gpa_start = prev_sec->offset_within_address_space; + uint64_t prev_size = int128_get64(prev_sec->size); + uint64_t prev_gpa_end = range_get_last(prev_gpa_start, prev_size); + uint64_t prev_host_start = + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) + + prev_sec->offset_within_region; + uint64_t prev_host_end = range_get_last(prev_host_start, prev_size); + + if (mrs_gpa <= (prev_gpa_end + 1)) { + if (mrs_gpa < prev_gpa_start) { + assert(0); + } + + if ((section->mr == prev_sec->mr) && + proxy_mrs_can_merge(mrs_host, prev_host_start, + (mrs_gpa - prev_gpa_start))) { + uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size); + need_add = false; + prev_sec->offset_within_address_space = + MIN(prev_gpa_start, mrs_gpa); + prev_sec->offset_within_region = + MIN(prev_host_start, mrs_host) - + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr); + prev_sec->size = int128_make64(max_end - MIN(prev_host_start, + mrs_host)); + } + } + } + + if (need_add) { + ++sync->n_mr_sections; + sync->mr_sections = g_renew(MemoryRegionSection, sync->mr_sections, + sync->n_mr_sections); + sync->mr_sections[sync->n_mr_sections - 1] = *section; + sync->mr_sections[sync->n_mr_sections - 1].fv = NULL; + memory_region_ref(section->mr); + } +} + +static void proxy_ml_commit(MemoryListener *listener) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + ProcMsg msg; + ram_addr_t offset; + MemoryRegion *mr; + MemoryRegionSection section; + uintptr_t host_addr; + int region; + + memset(&msg, 0, sizeof(ProcMsg)); + + msg.cmd = SYNC_SYSMEM; + msg.bytestream = 0; + msg.num_fds = sync->n_mr_sections; + msg.size = sizeof(msg.data1); + assert(msg.num_fds <= REMOTE_MAX_FDS); + + for (region = 0; region < sync->n_mr_sections; region++) { + section = sync->mr_sections[region]; + msg.data1.sync_sysmem.gpas[region] = + section.offset_within_address_space; + msg.data1.sync_sysmem.sizes[region] = int128_get64(section.size); + host_addr = (uintptr_t)memory_region_get_ram_ptr(section.mr) + + section.offset_within_region; + mr = memory_region_from_host((void *)host_addr, &offset); + msg.fds[region] = memory_region_get_fd(mr); + msg.data1.sync_sysmem.offsets[region] = offset; + } + proxy_proc_send(sync->proxy_link, &msg); +} + +void deconfigure_memory_sync(RemoteMemSync *sync) +{ + memory_listener_unregister(&sync->listener); +} + +/* + * TODO: Memory Sync need not be instantianted once per every proxy device. + * All remote devices are going to get the exact same updates at the + * same time. It therefore makes sense to have a broadcast model. + * + * Broadcast model would involve running the MemorySync object in a + * thread. MemorySync would contain a list of proxy_link objects + * that need notification. proxy_ml_commit() could send the same + * message to all the links at the same time. + */ +void configure_memory_sync(RemoteMemSync *sync, ProxyLinkState *proxy_link) +{ + sync->n_mr_sections = 0; + sync->mr_sections = NULL; + + sync->proxy_link = proxy_link; + + sync->listener.begin = proxy_ml_begin; + sync->listener.commit = proxy_ml_commit; + sync->listener.region_add = proxy_ml_region_addnop; + sync->listener.region_nop = proxy_ml_region_addnop; + sync->listener.priority = 10; + + memory_listener_register(&sync->listener, &address_space_memory); +} diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 08e549e..d3a9001 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -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); @@ -200,6 +202,10 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) error_propagate(errp, local_err); } } + + dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); + + configure_memory_sync(dev->sync, dev->proxy_link); } static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h new file mode 100644 index 0000000..99ca35e --- /dev/null +++ b/include/hw/proxy/memory-sync.h @@ -0,0 +1,51 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 MEMORY_SYNC_H +#define MEMORY_SYNC_H + +#include + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "exec/memory.h" +#include "io/proxy-link.h" + +#define TYPE_MEMORY_LISTENER "memory-listener" +#define REMOTE_MEM_SYNC(obj) \ + OBJECT_CHECK(RemoteMemSync, (obj), TYPE_MEMORY_LISTENER) + +typedef struct RemoteMemSync { + Object obj; + + MemoryListener listener; + + int n_mr_sections; + MemoryRegionSection *mr_sections; + + ProxyLinkState *proxy_link; +} RemoteMemSync; + +void configure_memory_sync(RemoteMemSync *sync, ProxyLinkState *proxy_link); +void deconfigure_memory_sync(RemoteMemSync *sync); + +#endif diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index e8d3a9c..03be8f9 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -24,6 +24,7 @@ #define QEMU_PROXY_H #include "io/proxy-link.h" +#include "hw/proxy/memory-sync.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -44,6 +45,7 @@ typedef struct PCIProxyDev { ProxyLinkState *proxy_link; + RemoteMemSync *sync; EventNotifier intr; EventNotifier resample; diff --git a/remote/remote-main.c b/remote/remote-main.c index f0390cc..c67b957 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -46,6 +46,7 @@ #include "sysemu/sysemu.h" #include "block/block.h" #include "exec/memattrs.h" +#include "exec/address-spaces.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -174,6 +175,16 @@ static void process_msg(GIOCondition cond) 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; From patchwork Thu Mar 7 07:22:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E0AB1515 for ; Thu, 7 Mar 2019 07:36:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17B8B2D84C for ; Thu, 7 Mar 2019 07:36:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 090172DF86; Thu, 7 Mar 2019 07:36:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B20232D84C for ; Thu, 7 Mar 2019 07:36:37 +0000 (UTC) Received: from localhost ([127.0.0.1]:46772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1na0-0005qt-TR for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:36:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nM5-0002KZ-SO for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nM3-0005PV-U4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:13 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55722) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nM3-0005K1-ID for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:11 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JUb3037979; Thu, 7 Mar 2019 07:22:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=2hjLIbfN3hc/pGdp3vPR37TY6GizZWecq6uItoo1tmw=; b=BJRfQHbngTGyJ3fxt9CR+AUHzMoF8L15NSiOFMXO7JOsljqoJvkhs7zqRs76g+GTj5Cu f6LBNodszkDKqKJyOBRN/anZf2kBMqKwT1uSjxYzxZi9J/Sm7CdNmGTpKHrD4fdHJI9D pLahmp6TRqFdoG7XNiqEhMNM4ruxFL6qk1neDit0rVT7haV3BvAVg0xNlBZHUU7EDOXw FkbkRik89FVNAvn297DnyI5/jDU0aInswauZRLCJcPzfbftoCyc0G1PyFlRh18cUFZfT 4bpsuXHCDCRQJ5iEUUnyqjbN8ZBcuKKkfMON8HcCYwa/80RrR4kGZzkwhgjJ/1+byYHp cw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2qyjfrr5dx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:07 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277M5sr016373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:06 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277M5qP005452; Thu, 7 Mar 2019 07:22:05 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:04 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:00 -0800 Message-Id: <20190307072200.8943-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 18/37] multi-process: create IOHUB object to handle irq X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, mst@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD ioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- hw/proxy/qemu-proxy.c | 63 ++++++++++++++++- include/hw/pci/pci_ids.h | 3 + include/hw/proxy/qemu-proxy.h | 5 ++ include/io/proxy-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 ++ 10 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 include/remote/iohub.h create mode 100644 remote/iohub.c diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index d3a9001..d525344 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -27,6 +27,9 @@ #include #include #include +#include +#include + #include "qemu/osdep.h" #include "qapi/error.h" #include "io/proxy-link.h" @@ -44,6 +47,16 @@ #include "hw/proxy/qemu-proxy.h" #include "hw/proxy/memory-sync.h" #include "qom/object.h" +#include "qemu/event_notifier.h" +#include "sysemu/kvm.h" +#include "util/event_notifier-posix.c" + +/* + * TODO: kvm_vm_ioctl is only available for per-target objects (NEED_CPU_H). + * The invocation of kvm_vm_ioctl should be moved to a per-target object. Until + * the the following definition is necessary + */ +int kvm_vm_ioctl(KVMState *s, int type, ...); static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); @@ -138,7 +151,53 @@ static void pci_proxy_dev_register_types(void) type_init(pci_proxy_dev_register_types) -static void init_emulation_process(PCIProxyDev *pdev, const char *command, Error **errp) +static void proxy_intx_update(PCIDevice *pci_dev) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); + PCIINTxRoute route; + int pin = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + if (dev->irqfd.fd) { + dev->irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); + memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd)); + } + + route = pci_device_route_intx_to_irq(pci_dev, pin); + + dev->irqfd.fd = event_notifier_get_fd(&dev->intr); + dev->irqfd.resamplefd = event_notifier_get_fd(&dev->resample); + dev->irqfd.gsi = route.irq; + dev->irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); +} + +static void setup_irqfd(PCIProxyDev *dev) +{ + PCIDevice *pci_dev = PCI_DEVICE(dev); + ProcMsg msg; + + event_notifier_init(&dev->intr, 0); + event_notifier_init(&dev->resample, 0); + + memset(&msg, 0, sizeof(ProcMsg)); + msg.cmd = SET_IRQFD; + msg.num_fds = 2; + msg.fds[0] = event_notifier_get_fd(&dev->intr); + msg.fds[1] = event_notifier_get_fd(&dev->resample); + msg.data1.set_irqfd.intx = + pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + proxy_proc_send(dev->proxy_link, &msg); + + memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd)); + + proxy_intx_update(pci_dev); + + pci_device_set_intx_routing_notifier(pci_dev, proxy_intx_update); +} + +static void init_emulation_process(PCIProxyDev *pdev, char *command, Error **errp) { char *args[2]; pid_t rpid; @@ -206,6 +265,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); configure_memory_sync(dev->sync, dev->proxy_link); + + setup_irqfd(dev); } static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 0abe27a..9cc5e28 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -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 diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 03be8f9..55160b0 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -23,8 +23,11 @@ #ifndef QEMU_PROXY_H #define QEMU_PROXY_H +#include + #include "io/proxy-link.h" #include "hw/proxy/memory-sync.h" +#include "qemu/event_notifier.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -46,6 +49,8 @@ typedef struct PCIProxyDev { ProxyLinkState *proxy_link; RemoteMemSync *sync; + struct kvm_irqfd irqfd; + EventNotifier intr; EventNotifier resample; diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index dc3c074..175e2f1 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -58,6 +58,8 @@ typedef struct ProxyLinkState ProxyLinkState; * 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 * */ typedef enum { @@ -67,6 +69,7 @@ typedef enum { SYNC_SYSMEM, BAR_WRITE, BAR_READ, + SET_IRQFD, MAX, } proc_cmd_t; @@ -96,6 +99,10 @@ typedef struct { } bar_access_msg_t; typedef struct { + int intx; +} set_irqfd_msg_t; + +typedef struct { proc_cmd_t cmd; int bytestream; size_t size; @@ -104,6 +111,7 @@ typedef struct { uint64_t u64; sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; + set_irqfd_msg_t set_irqfd; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/iohub.h b/include/remote/iohub.h new file mode 100644 index 0000000..0a799d6 --- /dev/null +++ b/include/remote/iohub.h @@ -0,0 +1,63 @@ +/* + * IO Hub for remote device + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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_IOHUB_H +#define REMOTE_IOHUB_H + +#include + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "qemu/event_notifier.h" +#include "qemu/thread-posix.h" +#include "io/proxy-link.h" + +#define REMOTE_IOHUB_NB_PIRQS 8 + +#define REMOTE_IOHUB_DEV 31 +#define REMOTE_IOHUB_FUNC 0 + +#define TYPE_REMOTE_IOHUB_DEVICE "remote-iohub" +#define REMOTE_IOHUB_DEVICE(obj) \ + OBJECT_CHECK(RemoteIOHubState, (obj), TYPE_REMOTE_IOHUB_DEVICE) + +typedef struct RemoteIOHubState { + PCIDevice d; + uint8_t irq_num[PCI_SLOT_MAX][PCI_NUM_PINS]; + EventNotifier irqfds[REMOTE_IOHUB_NB_PIRQS]; + EventNotifier resamplefds[REMOTE_IOHUB_NB_PIRQS]; + unsigned int irq_level[REMOTE_IOHUB_NB_PIRQS]; + QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS]; +} RemoteIOHubState; + +typedef struct ResampleToken { + RemoteIOHubState *iohub; + int pirq; +} ResampleToken; + +int remote_iohub_map_irq(PCIDevice *pci_dev, int intx); +void remote_iohub_set_irq(void *opaque, int pirq, int level); +void process_set_irqfd_msg(PCIDevice *pci_dev, ProcMsg *msg); + +#endif diff --git a/include/remote/machine.h b/include/remote/machine.h index fe1e11b..c38700c 100644 --- a/include/remote/machine.h +++ b/include/remote/machine.h @@ -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" diff --git a/remote/Makefile.objs b/remote/Makefile.objs index 13d4c48..cbb3065 100644 --- a/remote/Makefile.objs +++ b/remote/Makefile.objs @@ -1,3 +1,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o +remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o diff --git a/remote/iohub.c b/remote/iohub.c new file mode 100644 index 0000000..3ae0620 --- /dev/null +++ b/remote/iohub.c @@ -0,0 +1,159 @@ +/* + * Remote IO Hub + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_ids.h" +#include "hw/pci/pci_bus.h" +#include "remote/iohub.h" +#include "qemu/thread.h" +#include "hw/boards.h" +#include "remote/machine.h" +#include "qemu/main-loop.h" + +static void remote_iohub_initfn(Object *obj) +{ + RemoteIOHubState *iohub = REMOTE_IOHUB_DEVICE(obj); + int slot, intx, pirq; + + memset(&iohub->irqfds, 0, sizeof(iohub->irqfds)); + memset(&iohub->resamplefds, 0, sizeof(iohub->resamplefds)); + + for (slot = 0; slot < PCI_SLOT_MAX; slot++ ) { + for (intx = 0; intx < PCI_NUM_PINS; intx++) { + iohub->irq_num[slot][intx] = (slot + intx) % 4 + 4; + } + } + + for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { + qemu_mutex_init(&iohub->irq_level_lock[pirq]); + iohub->irq_level[pirq] = 0; + } +} + +static void remote_iohub_class_init(ObjectClass *klass, void *data) +{ + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + k->vendor_id = PCI_VENDOR_ID_ORACLE; + k->device_id = PCI_DEVICE_ID_REMOTE_IOHUB; +} + +static const TypeInfo remote_iohub_info = { + .name = TYPE_REMOTE_IOHUB_DEVICE, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(RemoteIOHubState), + .instance_init = remote_iohub_initfn, + .class_init = remote_iohub_class_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { } + } +}; + +static void remote_iohub_register(void) +{ + type_register_static(&remote_iohub_info); +} + +type_init(remote_iohub_register); + +int remote_iohub_map_irq(PCIDevice *pci_dev, int intx) +{ + BusState *bus = qdev_get_parent_bus(&pci_dev->qdev); + PCIBus *pci_bus = PCI_BUS(bus); + PCIDevice *pci_iohub = + pci_bus->devices[PCI_DEVFN(REMOTE_IOHUB_DEV, REMOTE_IOHUB_FUNC)]; + RemoteIOHubState *iohub = REMOTE_IOHUB_DEVICE(pci_iohub); + + return iohub->irq_num[PCI_SLOT(pci_dev->devfn)][intx]; +} + +/* + * TODO: Using lock to set the interrupt level could become a + * performance bottleneck. Check if atomic arithmetic + * is possible. + */ +void remote_iohub_set_irq(void *opaque, int pirq, int level) +{ + RemoteIOHubState *iohub = opaque; + + assert(pirq >= 0); + assert(pirq < REMOTE_IOHUB_NB_PIRQS); + + qemu_mutex_lock(&iohub->irq_level_lock[pirq]); + + if (level) { + if (++iohub->irq_level[pirq] == 1) { + event_notifier_set(&iohub->irqfds[pirq]); + } + } else if (iohub->irq_level[pirq] > 0) { + iohub->irq_level[pirq]--; + } + + qemu_mutex_unlock(&iohub->irq_level_lock[pirq]); +} + +static void intr_resample_handler(void *opaque) +{ + ResampleToken *token = opaque; + RemoteIOHubState *iohub = token->iohub; + uint64_t val; + int pirq, s; + + pirq = token->pirq; + + s = read(event_notifier_get_fd(&iohub->resamplefds[pirq]), &val, + sizeof(uint64_t)); + + 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, ProcMsg *msg) +{ + 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]); + + token = g_malloc0(sizeof(ResampleToken)); + token->iohub = iohub; + token->pirq = pirq; + + qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL, token); +} diff --git a/remote/machine.c b/remote/machine.c index 7001789..c1c7b77 100644 --- a/remote/machine.c +++ b/remote/machine.c @@ -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 = { diff --git a/remote/remote-main.c b/remote/remote-main.c index c67b957..4683e7d 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -47,6 +47,7 @@ #include "block/block.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" +#include "remote/iohub.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -185,6 +186,9 @@ static void process_msg(GIOCondition cond) 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; From patchwork Thu Mar 7 07:22:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2585214E1 for ; Thu, 7 Mar 2019 07:39:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D5EB2E22D for ; Thu, 7 Mar 2019 07:39:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2BDA2E237; Thu, 7 Mar 2019 07:39:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8778E2E22D for ; Thu, 7 Mar 2019 07:39:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:46796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nd1-0008RK-IX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:39:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMH-0002Up-3A for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMF-0005ZP-H2 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:24 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55842) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMD-0005YX-UC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:22 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JMEl037951; Thu, 7 Mar 2019 07:22:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=vb4bE9v6nX+5DQelgEoIGN2MZCiTDOYJfOIW1+ZX7GY=; b=3cXumAvFmCxwpp/hapbZdh50uttq55iJfCqNnyEiv96fFHgV5CtdUpsd4SuYeK3MlhcV mEAo21IucMUwbuj2iqrZCkJlnGCA9qBd+44b4PbMSu8XdQpYtIZ+Ge3FC11O8O9+Qc7N elWH241zGYLKHJTBVldSugE90CVviOhoKh1QJIEYVbzk8oaDTWWEjgIQUe6ljJZKybxj e8dtwbM4etFiKnrDGjRctGYMyLFQLd7jC97N5v6S60b6QdjC6dSbt8ucKyrTnltEGVA1 tNoT7ZS8QSeQX/oit3ZeV9XKQvh4a16qhR/OGWGm8bJtNoQv1civvFRZV1p1NO7aYGxZ wg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2qyjfrr5ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:18 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MC2U016587 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:12 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MCIG004151; Thu, 7 Mar 2019 07:22:12 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:12 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:05 -0800 Message-Id: <20190307072205.8990-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 19/37] multi-process: store info about the remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, mst@redhat.com, ehabkost@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Store info about the remote process in a hash table, so that it could be used later for QMP/HMP commands. Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- hw/i386/pc.c | 1 + hw/proxy/qemu-proxy.c | 7 +++++++ include/hw/i386/pc.h | 3 +++ 3 files changed, 11 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4212818..9f569cf 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2643,6 +2643,7 @@ static void pc_machine_initfn(Object *obj) pcms->smbus_enabled = true; pcms->sata_enabled = true; pcms->pit_enabled = true; + pcms->remote_devs = g_hash_table_new(g_str_hash, g_str_equal); } static void pc_machine_reset(void) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index d525344..d1560d9 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -50,6 +50,8 @@ #include "qemu/event_notifier.h" #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +#include "hw/i386/pc.h" +#include "hw/boards.h" /* * TODO: kvm_vm_ioctl is only available for per-target objects (NEED_CPU_H). @@ -234,6 +236,7 @@ static void init_emulation_process(PCIProxyDev *pdev, char *command, Error **err } pdev->proxy_link = proxy_link_create(); + pdev->remote_pid = rpid; if (!pdev->proxy_link) { error_setg(errp, "Failed to create proxy link"); @@ -252,9 +255,13 @@ 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; + PCMachineState *pcms = PC_MACHINE(current_machine); + DeviceState *d = DEVICE(dev); init_emulation_process(dev, k->command, errp); + (void)g_hash_table_insert(pcms->remote_devs, (gpointer)d->id, (gpointer)dev); + if (k->realize) { k->realize(dev, &local_err); if (local_err) { diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 54222a2..ded7cf0 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -1,6 +1,8 @@ #ifndef HW_PC_H #define HW_PC_H +#include + #include "qemu-common.h" #include "exec/memory.h" #include "hw/boards.h" @@ -39,6 +41,7 @@ struct PCMachineState { PCIBus *bus; FWCfgState *fw_cfg; qemu_irq *gsi; + GHashTable *remote_devs; /* Configuration options: */ uint64_t max_ram_below_4g; From patchwork Thu Mar 7 07:22:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9D3814E1 for ; Thu, 7 Mar 2019 07:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 980692E8F0 for ; Thu, 7 Mar 2019 07:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87A922E925; Thu, 7 Mar 2019 07:44:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DCCEE2E907 for ; Thu, 7 Mar 2019 07:44:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:46873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ni2-0004Tf-Rl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:44:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMM-0002Zy-9p for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMI-0005af-DK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:27 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMH-0005ZH-4F for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:25 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277Jprl038098; Thu, 7 Mar 2019 07:22:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=zR+3bu699ObrmS6qkY38PRRH7G4x2C3EPITE645ODmQ=; b=o31/4UK87mQuAtQfm3xqMdBKBVY0EYlEBoRAwBCzYkCnO6XA1jrfSaaak3UO9LMeMOE6 h2gyx4wE+QagjAHK0seYXuxZ7dTGpJr4+kBrt3OJawDFPY2uLA2tiiMr2gcX/aXc1AJR GKh4zsHnfGiMGutqfFLhzP0v89E0DonR2SWhF6/RRFGPT4vsJj1I+VkHOrdv03ae9q3K Ht0q1ldkgXxN04zV3Ig1Xc5UkbuHEUy4ubpptw/O+bK1wq9T/I4PahPVl/s5FIVYcsIB VWrMrj/8jkoPN4AH/b0fk4YgBS3ey9bYrzA/vD7y4LY9rHYhCb0lCCYw69dmX1cccrBF Ag== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qyjfrr5en-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:21 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MFIV001098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:15 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MFs3011683; Thu, 7 Mar 2019 07:22:15 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:14 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:12 -0800 Message-Id: <20190307072212.9058-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 20/37] multi-process: Add QMP & HMP commands to list remote processes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, armbru@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add query-remote QMP command and remote-proc-list HMP command, to list the remote processes spawned by QEMU. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hmp-commands.hx | 16 +++++++++ hmp.h | 1 + hw/proxy/Makefile.objs | 1 + hw/proxy/monitor.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 29 ++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 hw/proxy/monitor.c diff --git a/hmp-commands.hx b/hmp-commands.hx index 9b40359..fb3c8ba 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -725,6 +725,22 @@ STEXI Add device. ETEXI +#if defined(CONFIG_MPQEMU) + { + .name = "remote_proc_list", + .args_type = "", + .params = "", + .help = "list remote devices and their linux process IDs", + .cmd = hmp_remote_proc_list, + }, + +STEXI +@item remote_proc_list +@findex remote_proc_list +List remote devices and their linux process IDs. +ETEXI +#endif + { .name = "device_del", .args_type = "id:s", diff --git a/hmp.h b/hmp.h index e0f32f0..0940634 100644 --- a/hmp.h +++ b/hmp.h @@ -149,5 +149,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs index f562f5a..e642060 100644 --- a/hw/proxy/Makefile.objs +++ b/hw/proxy/Makefile.objs @@ -1,2 +1,3 @@ common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o +common-obj-$(CONFIG_MPQEMU) += monitor.o diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c new file mode 100644 index 0000000..3005eec --- /dev/null +++ b/hw/proxy/monitor.c @@ -0,0 +1,89 @@ +/* + * QEMU monitor command handler for multi-process QEMU + * + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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 + +#include "qemu/osdep.h" +#include "qapi/qapi-types-block-core.h" +#include "qapi/qapi-commands-block-core.h" +#include "monitor/monitor.h" +#include "qemu/option.h" +#include "hmp.h" +#include "hw/boards.h" +#include "hw/i386/pc.h" +#include "hw/proxy/qemu-proxy.h" + +/* + * TODO: Is there a callback where the allocated memory for QMP could be free'd + */ +RemoteProcList *qmp_query_remote(Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + RemoteProcList *proclist, *proc; + GHashTableIter itr; + PCIProxyDev *pdev; + PCIProxyDevClass *k; + DeviceState *d; + char *id; + + proclist = NULL; + + g_hash_table_iter_init(&itr, pcms->remote_devs); + + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { + k = PCI_PROXY_DEV_GET_CLASS(pdev); + d = DEVICE(pdev); + + proc = g_malloc0(sizeof(RemoteProcList)); + proc->next = proclist; + proclist = proc; + proc->value = g_malloc0(sizeof(RemoteProc)); + proc->value->pid = pdev->remote_pid; + proc->value->id = g_strdup(d->id); + proc->value->proc = g_strdup(k->command); + } + + return proclist; +} + +void hmp_remote_proc_list(Monitor *mon, const QDict *qdict) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + GHashTableIter itr; + PCIProxyDev *pdev; + PCIProxyDevClass *k; + char *id; + + g_hash_table_iter_init(&itr, pcms->remote_devs); + + monitor_printf(mon, "%8.8s\t%16.16s\t%16.16s\t%16.16s\n\n", "PID", "RID", + "QEMU ID", "PROCESS NAME"); + + while (g_hash_table_iter_next(&itr, (gpointer *)&id, (gpointer *)&pdev)) { + k = PCI_PROXY_DEV_GET_CLASS(pdev); + + monitor_printf(mon, "%8.8d\t%16.16s\t%16.16s\t%16.16s\n", + pdev->remote_pid, pdev->rid, id, k->command); + } +} diff --git a/qapi/block-core.json b/qapi/block-core.json index 2b8afbb..05394c4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -647,6 +647,23 @@ '*dirty-bitmaps': ['BlockDirtyInfo'] } } ## +# @RemoteProc: +# +# Remote process information. +# +# @id: Device ID +# +# @pid: Linux Process ID +# +# @proc: Process name +# +# Since: 3.0.93 +## +{ 'struct': 'RemoteProc', + 'data': {'id': 'str', 'pid': 'int32', 'proc': 'str' }, + 'if': 'defined(CONFIG_MPQEMU)' } + +## # @BlockMeasureInfo: # # Image file size calculation information. This structure describes the size @@ -768,6 +785,18 @@ ## { 'command': 'query-block', 'returns': ['BlockInfo'] } +## +# @query-remote: +# +# Get a list of all the remote processes spawned by QEMU. +# +# Returns: a list of @RemoteProc describing each remote process. +# +# Since: 3.0.93 +# +## +{ 'command': 'query-remote', 'returns': ['RemoteProc'], + 'if': 'defined(CONFIG_MPQEMU)' } ## # @BlockDeviceTimedStats: From patchwork Thu Mar 7 07:22:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 331AE1515 for ; Thu, 7 Mar 2019 07:29:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1583E2E032 for ; Thu, 7 Mar 2019 07:29:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 060F82E04D; Thu, 7 Mar 2019 07:29:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BCD72E032 for ; Thu, 7 Mar 2019 07:29:31 +0000 (UTC) Received: from localhost ([127.0.0.1]:46645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nT8-0007PA-I1 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:29:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nML-0002Ys-46 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMH-0005a7-3Y for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:27 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50636) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMF-0005Yx-Gd for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:24 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277KeCa035126; Thu, 7 Mar 2019 07:22:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=yQdH/YAk04bgQPUxGIrfWjIwVGjKbEdBbaUr6uAfvuo=; b=1CQLtUswSuBHn5audj9nGcWmnvvIE44jQJ4ZlXpmt7hY+Yi13XWfRjEZwwN3XnAq3q0G 8L3hEMw61Ayp3XicGr0IZdjI0dd7n7pxo/KmfHDxshRUICJDmg7pcesikuXgV+HdelKG GK8n73+4S0utVf2Va731dClqkr0ebg3NOPDz7Q0DJjOFhZ0Hco0/r71pDczljsJhGRca zSz27EPhhbmh7+O8Pntp2CUrmfv8AUPy7rQSdNts2F5z7lEcUGEzoW3br/JRjYTC+IG1 FG4TmualoRaR2BF6Rf3RDlxKfCaZyt37SDHlgRRcJ84Q6SKmgNt/3zOeN9nPLEnplqlQ aQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2qyfbeggj2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:19 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MImp006591 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:18 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277MIbF005617; Thu, 7 Mar 2019 07:22:18 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:17 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:15 -0800 Message-Id: <20190307072215.9104-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 21/37] multi-process: QMP/HMP commands to add a device to the remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, armbru@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Adds rdevice_add QMP & HMP commands to hotplug device to a remote device. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hmp-commands.hx | 14 ++++++++ hmp.h | 1 + hw/proxy/monitor.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ include/io/proxy-link.h | 2 ++ include/monitor/qdev.h | 4 +++ monitor.c | 5 +++ qapi/misc.json | 22 ++++++++++++ remote/remote-main.c | 48 ++++++++++++++++++++++++++ 8 files changed, 188 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index fb3c8ba..7e8e8ab 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -727,6 +727,20 @@ ETEXI #if defined(CONFIG_MPQEMU) { + .name = "rdevice_add", + .args_type = "rdev_id:s,driver:s,id:s,drive:s,bus:s", + .params = "rdev_id driver id drive bus", + .help = "add device to remote proc, like -rdevice on the command line", + .cmd = hmp_rdevice_add, + }, + +STEXI +@item rdevice_add @var{config} +@findex rdevice_add +Add device to remote proc. +ETEXI + + { .name = "remote_proc_list", .args_type = "", .params = "", diff --git a/hmp.h b/hmp.h index 0940634..355a27e 100644 --- a/hmp.h +++ b/hmp.h @@ -150,5 +150,6 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); +void hmp_rdevice_add(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c index 3005eec..2e2cda0 100644 --- a/hw/proxy/monitor.c +++ b/hw/proxy/monitor.c @@ -23,6 +23,7 @@ */ #include +#include #include "qemu/osdep.h" #include "qapi/qapi-types-block-core.h" @@ -33,6 +34,13 @@ #include "hw/boards.h" #include "hw/i386/pc.h" #include "hw/proxy/qemu-proxy.h" +#include "qapi/qapi-commands-misc.h" +#include "monitor/qdev.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" +#include "qapi/error.h" +#include "io/proxy-link.h" /* * TODO: Is there a callback where the allocated memory for QMP could be free'd @@ -87,3 +95,87 @@ void hmp_remote_proc_list(Monitor *mon, const QDict *qdict) pdev->remote_pid, pdev->rid, id, k->command); } } + +static PCIProxyDev *get_proxy_device(QDict *qdict, Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + PCIProxyDev *pdev = NULL; + const char *rdev_id; + + if (!qdict_haskey(qdict, "rdev_id")) { + error_setg(errp, "Please specify a value for rdev_id"); + return NULL; + } + + rdev_id = qdict_get_str(qdict, "rdev_id"); + + pdev = (PCIProxyDev *)g_hash_table_lookup(pcms->remote_devs, rdev_id); + if (!pdev) { + error_setg(errp, + "No remote device by ID %s. Use query-remote command to get remote devices", + rdev_id); + } + + return pdev; +} + +static void rdevice_add_del(QDict *qdict, proc_cmd_t cmd, Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + ProcMsg msg = {0}; + PCIProxyDev *pdev = NULL; + const char *id; + QString *json; + int wait; + + pdev = get_proxy_device(qdict, errp); + if (*errp) { + return; + } + + qdict_del(qdict, "rdev_id"); + + id = qdict_get_str(qdict, "id"); + + json = qobject_to_json(QOBJECT(qdict)); + + wait = GET_REMOTE_WAIT; + + msg.cmd = cmd; + msg.bytestream = 1; + msg.size = strlen(qstring_get_str(json)); + msg.data2 = (uint8_t *)qstring_get_str(json); + msg.num_fds = 1; + msg.fds[0] = wait; + + proxy_proc_send(pdev->proxy_link, &msg); + (void)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + + qstring_destroy_obj(QOBJECT(json)); + + /* TODO: Only on success */ + if (cmd == DEVICE_ADD) { + (void)g_hash_table_insert(pcms->remote_devs, (gpointer)g_strdup(id), + (gpointer)pdev); + } +} + +void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp) +{ + rdevice_add_del(qdict, DEVICE_ADD, errp); +} + +void hmp_rdevice_add(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + + /* TODO: Is it OK to modify the QDict argument from HMP? */ + rdevice_add_del((QDict *)qdict, DEVICE_ADD, &err); + + if (err) { + monitor_printf(mon, "rdevice_add error: %s\n", + error_get_pretty(err)); + error_free(err); + } +} diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 175e2f1..8781508 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -60,6 +60,7 @@ typedef struct ProxyLinkState ProxyLinkState; * BAR_READ Reads from PCI BAR region * SET_IRQFD Sets the IRQFD to be used to raise interrupts directly * from remote device + * DEVICE_ADD QMP/HMP command to hotplug device * */ typedef enum { @@ -70,6 +71,7 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + DEVICE_ADD, MAX, } proc_cmd_t; diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 0ff3331..065701c 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -10,6 +10,10 @@ void hmp_info_qdm(Monitor *mon, const QDict *qdict); void hmp_info_qom_tree(Monitor *mon, const QDict *dict); void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); +#ifdef CONFIG_MPQEMU +void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp); +#endif + int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); void qdev_set_id(DeviceState *dev, const char *id); diff --git a/monitor.c b/monitor.c index defa129..0ad52e5 100644 --- a/monitor.c +++ b/monitor.c @@ -1155,6 +1155,11 @@ static void monitor_init_qmp_commands(void) qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, QCO_NO_OPTIONS); +#ifdef CONFIG_MPQEMU + qmp_register_command(&qmp_commands, "rdevice_add", qmp_rdevice_add, + QCO_NO_OPTIONS); +#endif + QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG); diff --git a/qapi/misc.json b/qapi/misc.json index 8b3ca4f..28d49ea 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1663,6 +1663,28 @@ 'gen': false } # so we can get the additional arguments ## +# @rdevice_add: +# +# @rdev_id: ID of the remote device root +# +# @driver: the name of the new device's driver +# +# @bus: the device's parent bus (device tree path) +# +# @id: the device's ID, must be unique +# +# Additional arguments depend on the type. +# +# Add a device. +# +# Since: 3.0 +## +{ 'command': 'rdevice_add', + 'data': {'rdev_id': 'str', 'driver': 'str', '*bus': 'str', '*id': 'str'}, + 'if': 'defined(CONFIG_MPQEMU)', + 'gen': false } # so we can get the additional arguments + +## # @device_del: # # Remove a device from a guest diff --git a/remote/remote-main.c b/remote/remote-main.c index 4683e7d..03c14de 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -48,6 +48,11 @@ #include "exec/memattrs.h" #include "exec/address-spaces.h" #include "remote/iohub.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qobject.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "monitor/qdev.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -138,6 +143,44 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_device_add_msg(ProcMsg *msg) +{ + Error *local_err = NULL; + const char *json = (const char *)msg->data2; + int wait = msg->fds[0]; + QObject *qobj = NULL; + QDict *qdict = NULL; + QemuOpts *opts = NULL; + + qobj = qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict = qobject_to(QDict, qobj); + assert(qdict); + + opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); + if (local_err) { + goto fail; + } + + (void)qdev_device_add(opts, &local_err); + if (local_err) { + goto fail; + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -189,6 +232,9 @@ static void process_msg(GIOCondition cond) case SET_IRQFD: process_set_irqfd_msg(remote_pci_dev, msg); break; + case DEVICE_ADD: + process_device_add_msg(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; @@ -225,6 +271,8 @@ int main(int argc, char *argv[]) bdrv_init_with_whitelist(); + qemu_add_opts(&qemu_device_opts); + if (qemu_init_main_loop(&err)) { error_report_err(err); return -EBUSY; From patchwork Thu Mar 7 07:22:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DA4F14E1 for ; Thu, 7 Mar 2019 07:37:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 667D32DB9C for ; Thu, 7 Mar 2019 07:37:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 578A42DF86; Thu, 7 Mar 2019 07:37:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E9F92DB9C for ; Thu, 7 Mar 2019 07:37:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:46774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nap-0006Un-OH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:37:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMM-0002a6-Bf for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMJ-0005b4-1K for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:29 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMI-0005Zc-5d for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:26 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JHbu037916; Thu, 7 Mar 2019 07:22:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=baxZp8FeIEW2K+c7IGRGGALkEBvFQIOCsUHzX8i6D8U=; b=TnsB4Dcl9BnUJVQVdUV0AhuRZtfViy0PDvlHVVNcpo6461UiSsuphs9Xq/YZiU1YkqrH aJW5691KOoEP3wmYjfwU5s77emVDp+TkcoIzvnAhL96bTi7kGSvbR7E3FECKhIrcqq3i 9YeTER66LUuklsQRfHHWlrBBBhuWEqeJSBKvW/Us3uAhjatYd7EifhD6NUWSM6nYZ/xZ 0xoQZySwofwo1gCaJzAuMnn8ufOfmge6GH+9JBBNOunFr6449wly3A01LQ3SphjgLX/A ft33Wd2Z3/2Mcw45AdxcIkQ1/olQbmf64/6DDit8QdpektbU35p7u5CGEtFIm5qLFszP Jg== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qyjfrr5ep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:21 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MKI0001199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:20 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277MKAY024546; Thu, 7 Mar 2019 07:22:20 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:20 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:18 -0800 Message-Id: <20190307072218.9153-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 22/37] multi-process: QMP/HMP commands to remove device from the remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, armbru@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add rdevice_del QMP & HMP commands to hot-unplug device from remote device. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hmp-commands.hx | 14 ++++++++++++++ hmp.h | 1 + hw/proxy/monitor.c | 22 ++++++++++++++++++++++ include/hw/qdev-core.h | 1 + include/io/proxy-link.h | 2 ++ include/monitor/qdev.h | 1 + monitor.c | 2 ++ qapi/misc.json | 27 +++++++++++++++++++++++++++ qdev-monitor.c | 2 +- remote/remote-main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 1 deletion(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 7e8e8ab..7f121b4 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -741,6 +741,20 @@ Add device to remote proc. ETEXI { + .name = "rdevice_del", + .args_type = "rdev_id:s,id:s", + .params = "rdev_id id", + .help = "remove device from remote proc", + .cmd = hmp_rdevice_del, + }, + +STEXI +@item rdevice_del @var{rdev_id} @var{id} +@findex rdevice_del +Remove device from remote proc. +ETEXI + + { .name = "remote_proc_list", .args_type = "", .params = "", diff --git a/hmp.h b/hmp.h index 355a27e..52b83c0 100644 --- a/hmp.h +++ b/hmp.h @@ -151,5 +151,6 @@ void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); void hmp_rdevice_add(Monitor *mon, const QDict *qdict); +void hmp_rdevice_del(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c index 2e2cda0..05c8f8b 100644 --- a/hw/proxy/monitor.c +++ b/hw/proxy/monitor.c @@ -158,6 +158,8 @@ static void rdevice_add_del(QDict *qdict, proc_cmd_t cmd, Error **errp) if (cmd == DEVICE_ADD) { (void)g_hash_table_insert(pcms->remote_devs, (gpointer)g_strdup(id), (gpointer)pdev); + } else { + (void)g_hash_table_remove(pcms->remote_devs, (gpointer)id); } } @@ -179,3 +181,23 @@ void hmp_rdevice_add(Monitor *mon, const QDict *qdict) error_free(err); } } + +void qmp_rdevice_del(QDict *qdict, QObject **ret_data, Error **errp) +{ + rdevice_add_del(qdict, DEVICE_DEL, errp); +} + +void hmp_rdevice_del(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + + /* TODO: Is it OK to modify the QDict argument from HMP? */ + rdevice_add_del((QDict *)qdict, DEVICE_DEL, &err); + + if (err) { + monitor_printf(mon, "rdevice_del error: %s\n", + error_get_pretty(err)); + error_free(err); + } +} + diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 17f09aa..bdaa3b9 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -358,6 +358,7 @@ BusState *qdev_get_parent_bus(DeviceState *dev); /*** BUS API. ***/ 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); diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 8781508..ce2fcc3 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -61,6 +61,7 @@ typedef struct ProxyLinkState ProxyLinkState; * SET_IRQFD Sets the IRQFD to be used to raise interrupts directly * from remote device * DEVICE_ADD QMP/HMP command to hotplug device + * DEVICE_DEL QMP/HMP command to hot-unplug device * */ typedef enum { @@ -72,6 +73,7 @@ typedef enum { BAR_READ, SET_IRQFD, DEVICE_ADD, + DEVICE_DEL, MAX, } proc_cmd_t; diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 065701c..0ca0833 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -12,6 +12,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); #ifdef CONFIG_MPQEMU void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp); +void qmp_rdevice_del(QDict *qdict, QObject **ret_data, Error **errp); #endif int qdev_device_help(QemuOpts *opts); diff --git a/monitor.c b/monitor.c index 0ad52e5..6686c80 100644 --- a/monitor.c +++ b/monitor.c @@ -1158,6 +1158,8 @@ static void monitor_init_qmp_commands(void) #ifdef CONFIG_MPQEMU qmp_register_command(&qmp_commands, "rdevice_add", qmp_rdevice_add, QCO_NO_OPTIONS); + qmp_register_command(&qmp_commands, "rdevice_del", qmp_rdevice_del, + QCO_NO_OPTIONS); #endif QTAILQ_INIT(&qmp_cap_negotiation_commands); diff --git a/qapi/misc.json b/qapi/misc.json index 28d49ea..bc1d2ec 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -1717,6 +1717,33 @@ { 'command': 'device_del', 'data': {'id': 'str'} } ## +# @rdevice_del: +# +# Remove a device from a guest +# +# @rdev_id: ID of the remote device root +# +# @id: the device's ID +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# +# Notes: When this command completes, the device may not be removed from the +# guest. Hot removal is an operation that requires guest cooperation. +# This command merely requests that the guest begin the hot removal +# process. Completion of the device removal process is signaled with a +# DEVICE_DELETED event. Guest reset will automatically complete removal +# for all devices. +# +# Since: 3.0 +# +## +{ 'command': 'rdevice_del', + 'data': {'rdev_id': 'str', 'id': 'str'}, + 'if': 'defined(CONFIG_MPQEMU)', + 'gen': false } + +## # @DEVICE_DELETED: # # Emitted whenever the device removal completion is acknowledged by the guest. diff --git a/qdev-monitor.c b/qdev-monitor.c index d432098..46d0ad0 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -828,7 +828,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) object_unref(OBJECT(dev)); } -static DeviceState *find_device_state(const char *id, Error **errp) +DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; diff --git a/remote/remote-main.c b/remote/remote-main.c index 03c14de..a9c12a9 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -53,6 +53,7 @@ #include "qemu/option.h" #include "qemu/config-file.h" #include "monitor/qdev.h" +#include "qapi/qmp/qdict.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -181,6 +182,47 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_device_del_msg(ProcMsg *msg) +{ + Error *local_err = NULL; + DeviceState *dev = NULL; + const char *json = (const char *)msg->data2; + int wait = msg->fds[0]; + QObject *qobj = NULL; + QDict *qdict = NULL; + const char *id; + + qobj = qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict = qobject_to(QDict, qobj); + assert(qdict); + + id = qdict_get_try_str(qdict, "id"); + assert(id); + + dev = find_device_state(id, &local_err); + if (local_err) { + goto fail; + } + + if (dev) { + qdev_unplug(dev, &local_err); + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -235,6 +277,9 @@ static void process_msg(GIOCondition cond) case DEVICE_ADD: process_device_add_msg(msg); break; + case DEVICE_DEL: + process_device_del_msg(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Mar 7 07:22:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D8C01515 for ; Thu, 7 Mar 2019 07:47:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE4D32E98A for ; Thu, 7 Mar 2019 07:47:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2B382E99C; Thu, 7 Mar 2019 07:47:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5BA472E98A for ; Thu, 7 Mar 2019 07:47:39 +0000 (UTC) Received: from localhost ([127.0.0.1]:46931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nkg-00077G-Ie for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:47:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMa-0002lw-CJ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMX-0005in-H7 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:42 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50788) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMU-0005fG-ND for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:39 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277K2cM034689; Thu, 7 Mar 2019 07:22:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=bMHXWCDOh88mVzH3CmtMetjAgAzXJRLxnpq9rpK1nqk=; b=yZP4atsqUiwUjknmzTbD8gmf5n1D4VGTp67MnS1yiJwC3nbXU5kr7bOdnjv9E6Hl6SIq NBhnZ36fX1Fac+xe+LQJTmaOYgHV4wVF8Nwju1AVysp9jH77CMVQzmzeMZ9QwXurgT+P EFCytEhR1RizQLaegidhRc8C6e55HIo2qiDCMbS6uEXsxFC9Qk8aZFWHe7B8HENgpfcV E6Hx0ZVfUz9A7gaMcFaHePRKLWtbOut9dizHbOXrSdMZxFK9pg448jCINEGQYePB8CR8 g82SvlPrzpY1A3fgI59A42zsFLaS0XT2EjheIo9WZJvxP265H9mGJrIG02WK9qOoRfBH sw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2qyfbeggje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MO7P006808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:24 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MOxF011783; Thu, 7 Mar 2019 07:22:24 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:23 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:20 -0800 Message-Id: <20190307072220.9207-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 23/37] multi-process: add command line options rdrive and rdevice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, armbru@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com, kwolf@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva These command option have the same notion as the drive and device, except these will be emulated in remote process. Added parameter rid identified the remote process group. As an example, this will create the device emulated by the remote process: /usr/local/bin/qemu-system-x86_64 -name vm -m 6G -drive file=/root/ol7.qcow2,format=raw -enable-kvm -machine q35,accel=kvm -rdevice lsi53c895a,rid=0,id=scsi0,command=qemu-scsi-dev -rdevice scsi-hd,rid=0,drive=drive0,bus=scsi0.0,scsi-id=0 -rdrive id=drive0,rid=0,file=/root/cirros-0.4.0-x86_64-disk.img,format=qcow3 -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=6G,share=on -numa node,memdev=mem -display none -vnc :0 -monitor stdio Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- blockdev.c | 12 ++++++++++++ include/sysemu/sysemu.h | 2 ++ qdev-monitor.c | 9 +++++++++ qemu-options.hx | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/blockdev.c b/blockdev.c index 7e6bf99..c03a09f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4580,3 +4580,15 @@ QemuOptsList qemu_drive_opts = { { /* end of list */ } }, }; + +QemuOptsList qemu_rdrive_opts = { + .name = "rdrive", + .head = QTAILQ_HEAD_INITIALIZER(qemu_rdrive_opts.head), + .desc = { + /* + * no elements => accept any params + * validation will happen later + */ + { /* end of list */ } + }, +}; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 89604a8..82622be 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -193,5 +193,7 @@ extern QemuOptsList qemu_nic_opts; extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; +extern QemuOptsList qemu_rdevice_opts; +extern QemuOptsList qemu_rdrive_opts; #endif diff --git a/qdev-monitor.c b/qdev-monitor.c index 46d0ad0..eb7e542 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -964,6 +964,15 @@ QemuOptsList qemu_global_opts = { }, }; +QemuOptsList qemu_rdevice_opts = { + .name = "rdevice", + .implied_opt_name = "driver", + .head = QTAILQ_HEAD_INITIALIZER(qemu_rdevice_opts.head), + .desc = { + { /* end of list */ } + }, +}; + int qemu_global_option(const char *str) { char driver[64], property[64]; diff --git a/qemu-options.hx b/qemu-options.hx index 1cf9aac..0b82013 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -535,6 +535,17 @@ Like the KCS interface, but defines a BT interface. The default port is ETEXI +DEF("rdevice", HAS_ARG, QEMU_OPTION_rdevice, + "-rdevice driver[,prop[=value][,...]]\n" + " add device (based on driver)\n" + " prop=value,... sets driver properties\n" + " use '-device help' to print all possible drivers\n" + " use '-device driver,help' to print all possible properties\n", + QEMU_ARCH_ALL) +STEXI +Remote device options. +ETEXI + DEF("name", HAS_ARG, QEMU_OPTION_name, "-name string1[,process=string2][,debug-threads=on|off]\n" " set the name of the guest\n" @@ -786,6 +797,21 @@ Please refer to the QAPI documentation of the @code{blockdev-add} QMP command. ETEXI +DEF("rdrive", HAS_ARG, QEMU_OPTION_rdrive, + "-rdrive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" + " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" + " [,snapshot=on|off][,rerror=ignore|stop|report]\n" + " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" + " [,readonly=on|off][,copy-on-read=on|off]\n" + " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" + " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]\n" + " [[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]\n" + " [[,bps_max=bm]|[[,bps_rd_max=rm][,bps_wr_max=wm]]]\n" + " [[,iops_max=im]|[[,iops_rd_max=irm][,iops_wr_max=iwm]]]\n" + " [[,iops_size=is]]\n" + " [[,group=g]]\n" + " use 'file' as a drive image\n", QEMU_ARCH_ALL) + DEF("drive", HAS_ARG, QEMU_OPTION_drive, "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" " [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n" From patchwork Thu Mar 7 07:22:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4AC61515 for ; Thu, 7 Mar 2019 07:32:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD0B22E84F for ; Thu, 7 Mar 2019 07:32:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C601B2E54A; Thu, 7 Mar 2019 07:32:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B0D62E3A2 for ; Thu, 7 Mar 2019 07:32:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:46712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nWG-0002j9-5n for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:32:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMb-0002nK-Ry for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMa-0005kY-GB for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:45 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMY-0005hl-Ea for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:42 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JBJX037785; Thu, 7 Mar 2019 07:22:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=gx6ZDudI6fLANm177u5jX7wxcGUptTWcbygJVWipo5g=; b=bhOm2m7aBT83xcIJsfUXLGVfkvBSGc4Y3PgV6/0iCWjPqRx05CMK/00D1+4vUHTOqD6B td9SSanQZLgBIQqwEpMgS2OoCWiue+H/VorPsheSeLOin/5/Rgm2cdJsi3J4wOHnGScB UdsTfe6U6Fowv+a0ZCz3nYaWXizn9pyb4h+xI+B083BGWx4JGPAguvSQvj7kWPS9NoIh /nk0d8mhElwfXj7RqvwYaxfO07lA3BKF/zk17zPlm9FbQjXiq1Ai5hV/iUtVmF+AUpPc Qbf0WtQnYD5chhPidF9LpCSZq0vjbBLJCKY28HtAV5l6kxb8eTWDrKFgdgBAJi8g6C1/ KQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2qyh8ug98n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:32 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MQrx006849 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:27 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277MQsF024678; Thu, 7 Mar 2019 07:22:26 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:26 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:24 -0800 Message-Id: <20190307072224.9316-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 24/37] multi-process: pass proxy link socket fd to remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson --- hw/proxy/qemu-proxy.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index d1560d9..f519beb 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -201,7 +201,7 @@ static void setup_irqfd(PCIProxyDev *dev) static void init_emulation_process(PCIProxyDev *pdev, char *command, Error **errp) { - char *args[2]; + char *args[3]; pid_t rpid; int fd[2]; @@ -221,16 +221,12 @@ static void init_emulation_process(PCIProxyDev *pdev, char *command, Error **err } if (rpid == 0) { - if (dup2(fd[1], STDIN_FILENO) != STDIN_FILENO) { - perror("Failed to acquire socket."); - exit(1); - } - close(fd[0]); - close(fd[1]); args[0] = g_strdup(command); - args[1] = NULL; + args[1] = g_strdup_printf("%d", fd[1]); + args[2] = NULL; + execvp(args[0], (char *const *)args); exit(1); } From patchwork Thu Mar 7 07:22:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D8671515 for ; Thu, 7 Mar 2019 07:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76CA82E22D for ; Thu, 7 Mar 2019 07:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 751E32E4A5; Thu, 7 Mar 2019 07:40:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED5BF2E48C for ; Thu, 7 Mar 2019 07:40:31 +0000 (UTC) Received: from localhost ([127.0.0.1]:46828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ndn-0000fN-3c for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:40:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMa-0002m7-JP for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMY-0005jh-JX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:44 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48722) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMW-0005gb-Lv for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:41 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JBgE037788; Thu, 7 Mar 2019 07:22:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=W/RxEEXxKWivQvni8rzZcFqi2Xe5ocfOrHDOr3/2Ies=; b=TYCIeEbzk/EltlAHtefTbvYeLQiNXMzWb2/H/kV+N/e63Tl4gdVDPkYlZBVHkg2zqcHR coU8bGMnD2p+fm6JD9ARAydlvmK5tjVdcTN7ZJ2JCKV5EvkxNgRkm59Q/JTByhOysOuh j6EMGAG7+K5wWKMxaMQUlS5b+Ba7v12CYwIwwHnkjNa1zGi9e/tgzjdyC2UAULBndt7w 5ZHeHNnxe2bSU56n48kLDmvHgHoqtWVwykn0ACKNczMKMhUJ0Bgg1g7IFfGpipFjSCfq KrvKY+draNNq2mV1/inpOriyoELqSyPUVLoZv5LhGDD/XUsJxI5i6LyTs0MebH5bTXxu iw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2qyh8ug98a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MTed001788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:29 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MT4Q011802; Thu, 7 Mar 2019 07:22:29 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:28 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:26 -0800 Message-Id: <20190307072226.9362-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 25/37] multi-process: configure remote side devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Add functions to configure remote devices. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/proxy/qemu-proxy.c | 41 +++++++++++++++++++++++++++++++++++++++-- include/hw/proxy/qemu-proxy.h | 2 ++ include/io/proxy-link.h | 2 ++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index f519beb..9d075ec 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -52,6 +52,7 @@ #include "util/event_notifier-posix.c" #include "hw/i386/pc.h" #include "hw/boards.h" +#include "include/qemu/log.h" /* * TODO: kvm_vm_ioctl is only available for per-target objects (NEED_CPU_H). @@ -61,6 +62,40 @@ int kvm_vm_ioctl(KVMState *s, int type, ...); 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; + ProcMsg msg; + const char *str; + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + qstr = qobject_to_json(QOBJECT(qdict)); + str = qstring_get_str(qstr); + qemu_log_mask(LOG_REMOTE_DEBUG, "remote qdict in proxy: %s.\n", str); + + memset(&msg, 0, sizeof(ProcMsg)); + + msg.data2 = (uint8_t *)str; + msg.cmd = cmd; + msg.bytestream = 1; + msg.size = qstring_get_length(qstr) + 1; + msg.num_fds = 0; + + proxy_proc_send(pdev->proxy_link, &msg); + + return; +} static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, unsigned int op) @@ -76,7 +111,8 @@ static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, msg.data2 = (uint8_t *)malloc(sizeof(conf_data)); if (!msg.data2) { - printf("Failed to allocate memory for msg.data2."); + qemu_log_mask(LOG_REMOTE_DEBUG, "Failed to allocate memory" + " for msg.data2.\n"); return -ENOMEM; } @@ -268,8 +304,9 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); configure_memory_sync(dev->sync, dev->proxy_link); + dev->set_remote_opts = set_remote_opts; + dev->proxy_ready = proxy_ready; - setup_irqfd(dev); } static void send_bar_access_msg(ProxyLinkState *proxy_link, MemoryRegion *mr, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 55160b0..6b61bb7 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -28,6 +28,8 @@ #include "io/proxy-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" diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index ce2fcc3..21d63cc 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -72,6 +72,8 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + DEV_OPTS, + DRIVE_OPTS, DEVICE_ADD, DEVICE_DEL, MAX, From patchwork Thu Mar 7 07:22:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1225D1515 for ; Thu, 7 Mar 2019 07:42:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3C422E4A5 for ; Thu, 7 Mar 2019 07:42:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E73B82E907; Thu, 7 Mar 2019 07:42:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 450072E4A5 for ; Thu, 7 Mar 2019 07:42:38 +0000 (UTC) Received: from localhost ([127.0.0.1]:46850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nfp-0002V5-Dm for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:42:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMY-0002kE-Du for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMU-0005hh-OR for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:40 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48702) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMT-0005fc-EK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:37 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277Kvhq039086; Thu, 7 Mar 2019 07:22:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=+55Hplqi5v1+igu7FaQBZn1nF5vkQKPdiG7glE51P/8=; b=V9g4U6+Kc1b8zciEn1RMhM7UMvxrzscaY7otlG3C6giXZZgBFC5EnDdWYX3DaidWTar/ iurxWS/KluXcYw8jBkHhyc0s6WX2hQcyCCIKaSNfTceycLkvbLfYZDnwI0OUN3K63qa/ Ikv2Hz2yzLPSGua8M5tX5KifDOuTV4fHlt7UBjlsbk5ENPXBDRk3wlJvjSWWMho3j/sA Zagce0Du4BxI3Y349DCn/ISHEqBNWLHP+zh8+HA1BpRTZ7zPzqiE/L0IvdZmRqin3jAK 5twuCpS0JhA81aHvZ1q5kpXRh6vsbtSFx7oVhdrMvyD0kUcTEwXgxdyTzI6/TxibGSGY lg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qyh8ug98k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:32 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MVeM017212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:31 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MVBt004386; Thu, 7 Mar 2019 07:22:31 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:31 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:29 -0800 Message-Id: <20190307072229.9409-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 26/37] multi-process: add qdev_proxy_add to create proxy devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, ehabkost@redhat.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, marcandre.lureau@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva This is handled while parsing the command line options. The parsed options are being sent to remote process as the messgaes containing JSON strings. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- include/hw/proxy/qemu-proxy.h | 7 ++ include/monitor/qdev.h | 4 ++ qdev-monitor.c | 159 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 6b61bb7..3639792 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -74,6 +74,13 @@ typedef struct PCIProxyDevClass { char *command; } PCIProxyDevClass; +typedef struct PCIProxyDevList { + QLIST_HEAD(, PCIProxyDev) devices; +} proxy_dev_list_t; + +extern QemuMutex proxy_list_lock; +extern proxy_dev_list_t proxy_dev_list; + void proxy_default_bar_write(PCIProxyDev *dev, MemoryRegion *mr, hwaddr addr, uint64_t val, unsigned size, bool memory); diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index 0ca0833..089429c 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -11,8 +11,12 @@ void hmp_info_qom_tree(Monitor *mon, const QDict *dict); void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); #ifdef CONFIG_MPQEMU +#include "hw/proxy/qemu-proxy.h" void qmp_rdevice_add(QDict *qdict, QObject **ret_data, Error **errp); void qmp_rdevice_del(QDict *qdict, QObject **ret_data, Error **errp); +DeviceState *qdev_proxy_add(const char *rid, const char *id, Error **errp); +DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp); +void qdev_proxy_fire(void); #endif int qdev_device_help(QemuOpts *opts); diff --git a/qdev-monitor.c b/qdev-monitor.c index eb7e542..e0e16d8 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -33,6 +33,16 @@ #include "qemu/option.h" #include "sysemu/block-backend.h" #include "migration/misc.h" +#include "hw/proxy/qemu-proxy.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" +#include "sysemu/sysemu.h" +#include "hw/proxy/proxy-lsi53c895a.h" +#include "include/qemu/cutils.h" +#include "include/qemu/log.h" +#include "qapi/qmp/qlist.h" +#include "hw/proxy/qemu-proxy.h" +#include "io/proxy-link.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -45,6 +55,8 @@ typedef struct QDevAlias uint32_t arch_mask; } QDevAlias; +proxy_dev_list_t proxy_dev_list; +QemuMutex proxy_list_lock; /* Please keep this table sorted by typename. */ static const QDevAlias qdev_alias_table[] = { { "e1000", "e1000-82540em" }, @@ -569,6 +581,153 @@ void qdev_set_id(DeviceState *dev, const char *id) } } +#if defined(CONFIG_MPQEMU) +PCIProxyDev *get_proxy_object(const char *rid); +PCIProxyDev *get_proxy_object(const char *rid) +{ + PCIProxyDev *entry; + + qemu_mutex_lock(&proxy_list_lock); + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (strncmp(entry->rid, rid, strlen(entry->rid)) == 0) { + qemu_mutex_unlock(&proxy_list_lock); + return entry; + } + } + qemu_mutex_unlock(&proxy_list_lock); + return NULL; + +} + +#define MAX_RID_LENGTH 10 +void qdev_proxy_fire(void) +{ + PCIProxyDev *entry; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (entry->proxy_ready) { + entry->proxy_ready(PCI_DEVICE(entry)); + } + } +} + +DeviceState *qdev_proxy_add(const char *rid, const char *id, Error **errp) +{ + DeviceState *ds; + PCIProxyDev *pdev; + QemuOpts *proxy_opts; + const char *proxy_type; + Error *local_err = NULL; + QDict *qdict; + const char *str; + + pdev = get_proxy_object(rid); + if (pdev) { + return DEVICE(pdev); + } + + if (strlen(rid) > MAX_RID_LENGTH) { + qemu_log_mask(LOG_REMOTE_DEBUG, "rid is too long.\n"); + error_setg(errp, "rid %s is too long", rid); + return NULL; + } + + proxy_opts = qemu_opts_create(&qemu_device_opts, NULL, 0, + errp); + + /* TODO: remove hardcoded type and add approptiate type identification. */ + proxy_type = TYPE_PROXY_LSI53C895A; + if (!proxy_type) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Driver is not supported in" + " multi-process qemu.\n"); + error_setg(errp, "Driver is not supported in multi-process qemu."); + return NULL; + } + + qemu_opts_set_id(proxy_opts, (char *)rid); + qemu_opt_set(proxy_opts, "driver", proxy_type, &local_err); + + qdict = qemu_opts_to_qdict(proxy_opts, NULL); + str = qstring_get_str(qobject_to_json(QOBJECT(qdict))); + + ds = qdev_device_add(proxy_opts, &local_err); + if (!ds) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Could not create proxy device" + " with opts %s.\n", str); + error_propagate(errp, local_err); + return NULL; + } + qdev_set_id(ds, qemu_opts_id(proxy_opts)); + + pdev = PCI_PROXY_DEV(ds); + if (!pdev) { + qemu_log_mask(LOG_REMOTE_DEBUG, "qdev_device_add failed.\n"); + qdev_unplug(ds, errp); + return NULL; + } + pdev->rid = g_strdup(rid); + + qemu_mutex_lock(&proxy_list_lock); + QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next); + qemu_mutex_unlock(&proxy_list_lock); + + return ds; +} + +DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp) +{ + PCIProxyDev *pdev = NULL; + DeviceState *dev; + const char *rid; + QDict *qdict_new; + + 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) { + qemu_log_mask(LOG_REMOTE_DEBUG, "rdevice option needs rid" + " specified.\n"); + error_setg(errp, "rdevice option needs rid specified."); + return NULL; + } + + dev = qdev_proxy_add(rid, qemu_opt_get(opts, "id"), errp); + if (!dev) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Failed to add proxy for %s\n", + device ? "device" : "driver"); + error_setg(errp, "qdev_proxy_add error."); + return NULL; + } + + qdict_new = qemu_opts_to_qdict(opts, NULL); + + if (!qdict_new) { + printf("Could not parse rdevice options."); + error_setg(errp, "Could not parse rdevice options."); + return NULL; + } + + pdev = PCI_PROXY_DEV(dev); + if (!pdev->set_remote_opts) { + printf("will not set remote opts\n"); + qemu_log_mask(LOG_REMOTE_DEBUG, "Device/driver opts are not" + " specified, probably no multi-process support" + " rid=%s\n", rid); + /* TODO: destroy proxy? */ + error_setg(errp, "set_remote_opts not set."); + return NULL; + } else { + pdev->set_remote_opts(PCI_DEVICE(pdev), qdict_new, + device ? DEV_OPTS : DRIVE_OPTS); + } + + return dev; +} +#endif /*defined(CONFIG_MPQEMU)*/ + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; From patchwork Thu Mar 7 07:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD3D414E1 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99B832E8F0 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C1FD2E925; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 095A32E8F0 for ; Thu, 7 Mar 2019 07:43:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:46854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ngX-00037M-7S for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:43:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMc-0002nM-Rm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMa-0005ke-Hm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:45 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMY-0005hc-I8 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:43 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JFbk037804; Thu, 7 Mar 2019 07:22:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=fd/GUhEGvfP5hsOnpn7HBT74UTo6vyuTOlwbtjMbBxc=; b=1SJWQ9+4g/k2s21X0/l9YeASPo0zcQlk7mrju0mZPAjmjHo5lozoW77LP3AcE88pVbII QfXr5cYAo2ATso9vF4zolwh2slrNEPVfts6WBGKwUkzlN6cGqZFNbh7cx5H92CfrEWRG JJcG45s9Uh5pl05Xyr+7pfAjrddHPPOhz82AZyoQm/TdqRBwZg2eVFkyqPvbceNfMn0y 9HcbLt7ZaRFHPuHpxmMOoX88ijGSlFuLWe3OlfPnMOPPeFzTJ1z661fZ7QrEqJoWOBoL lRxlrviWKfushtnY4NFdNbSEpVzBbpWbUAMyb/5SDNpVE4U6nxKzglywJl3Nk3Lc6Htf Rw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qyh8ug992-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:35 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MYPw017273 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:34 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MYRf004397; Thu, 7 Mar 2019 07:22:34 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:33 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:31 -0800 Message-Id: <20190307072231.9457-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 27/37] multi-process: remote: add setup_devices and setup_drive msg processing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Receive by remote side the configuration messages and build the device object from JSON device descriptions. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- remote/remote-main.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index a9c12a9..52da3c8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -54,6 +54,15 @@ #include "qemu/config-file.h" #include "monitor/qdev.h" #include "qapi/qmp/qdict.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" +#include "block/block.h" +#include "qapi/qmp/qstring.h" +#include "hw/qdev-properties.h" +#include "hw/scsi/scsi.h" +#include "block/qdict.h" +#include "qapi/qmp/qlist.h" +#include "qemu/log.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -223,6 +232,107 @@ fail: PUT_REMOTE_WAIT(wait); } +static int init_drive(QDict *rqdict, Error **errp) +{ + QemuOpts *opts; + Error *local_error = NULL; + + if (rqdict != NULL && qdict_size(rqdict) > 0) { + opts = qemu_opts_from_qdict(&qemu_drive_opts, + rqdict, &local_error); + if (!opts) { + error_propagate(errp, local_error); + return -EINVAL; + } + } else { + return -EINVAL; + } + if (drive_new(opts, IF_IDE, &local_error) == NULL) { + error_propagate(errp, local_error); + return -EINVAL; + } + + return 0; +} + +static int setup_drive(ProcMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + Error *local_error = NULL; + int rc = -EINVAL; + + if (!msg->data2) { + return rc; + } + + qstr = qstring_from_str((char *)msg->data2); + obj = qobject_from_json(qstring_get_str(qstr), errp); + if (!obj) { + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + qdict_del(qdict, "rid"); + if (init_drive(qdict, &local_error)) { + error_propagate(errp, local_error); + return rc; + } + + return 0; +} + +static int setup_device(ProcMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + QemuOpts *opts; + DeviceState *dev = NULL; + int rc = -EINVAL; + + if (!msg->data2) { + return rc; + } + + qstr = qstring_from_str((char *)msg->data2); + + obj = qobject_from_json(qstring_get_str(qstr), errp); + if (!obj) { + error_setg(errp, "Could not convert to json object."); + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + g_assert(qdict_size(qdict) > 1); + + qdict_del(qdict, "command"); + qdict_del(qdict, "rid"); + + opts = qemu_opts_from_qdict(&qemu_device_opts, qdict, errp); + + dev = qdev_device_add(opts, errp); + if (!dev) { + error_setg(errp, "Could not add device %s.", qstring_get_str(qstr)); + return rc; + } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_pci_dev = PCI_DEVICE(dev); + } + qemu_opts_del(opts); + + return 0; +} + static void process_msg(GIOCondition cond) { ProcMsg *msg = NULL; @@ -268,11 +378,27 @@ static void process_msg(GIOCondition cond) */ remote_sysmem_reconfig(msg, &err); if (err) { + error_report_err(err); goto finalize_loop; } break; case SET_IRQFD: process_set_irqfd_msg(remote_pci_dev, msg); + qdev_machine_creation_done(); + qemu_mutex_lock_iothread(); + qemu_run_machine_init_done_notifiers(); + qemu_mutex_unlock_iothread(); + + break; + case DRIVE_OPTS: + if (setup_drive(msg, &err)) { + error_report_err(err); + } + break; + case DEV_OPTS: + if (setup_device(msg, &err)) { + error_report_err(err); + } break; case DEVICE_ADD: process_device_add_msg(msg); From patchwork Thu Mar 7 07:22:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842305 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBD861515 for ; Thu, 7 Mar 2019 07:39:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4EFB2DDBB for ; Thu, 7 Mar 2019 07:39:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A248A2DE08; Thu, 7 Mar 2019 07:39:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4E1E92DDBB for ; Thu, 7 Mar 2019 07:39:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:46792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1ncO-0007mN-7M for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:39:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMj-0002t5-Nd for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMh-0005sZ-MN for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:53 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50980) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMg-0005mn-59 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:50 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JnR7034494; Thu, 7 Mar 2019 07:22:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=OJJxlAbzXwXwhBc30c/4bc0GpJrkjE4U05SN6gxcngk=; b=2mYMpz4Ve0+2S9e4BLuXawz9eWfj2ltEe6Ju0De/Pi3Hf/jphQTpS2B6YWztVx6qyUgy zTBq28BfqIjoyUPTMqttL5pO84sFGec37iNtIp/hdVQ9uuHZSxfxM98tt0Qy+1e9zeFR HAMmf1fULlwhtcHeQ4bsfnJ7ZHSz9nD4KoBE6LXxOhXCpLxh/LD7RpJZ8R6Q5pR9inIV ZMHfFt73e38GRKDB6UuT0hOZSfGNIvLeNEgrteJDapZNqcw6emSsi2vV9hCWrHd4btHp v155uLmbO1F+tX3dwsIRZ9f+Sn1Ktp3HbOOc+gbaEmSIHEPNQ32/g6VsaAz0mC8rXVTQ Bw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbeggk6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:42 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MbHJ002065 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:37 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277Ma1Y005755; Thu, 7 Mar 2019 07:22:36 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:36 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:34 -0800 Message-Id: <20190307072234.9503-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 28/37] multi-process: remote: use fd for socket from parent process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- remote/remote-main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/remote/remote-main.c b/remote/remote-main.c index 52da3c8..fa32f2a 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -63,6 +63,7 @@ #include "block/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/log.h" +#include "qemu/cutils.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -437,6 +438,7 @@ int main(int argc, char *argv[]) { Error *err = NULL; QemuThread main_loop_thread; + int fd = -1; module_call_init(MODULE_INIT_QOM); @@ -461,7 +463,13 @@ int main(int argc, char *argv[]) return -1; } - proxy_link_set_sock(proxy_link, STDIN_FILENO); + fd = qemu_parse_fd(argv[1]); + if (fd == -1) { + printf("Failed to parse fd for remote process.\n"); + return -EINVAL; + } + + proxy_link_set_sock(proxy_link, fd); proxy_link_set_callback(proxy_link, process_msg); qemu_thread_create(&main_loop_thread, "remote-main-loop", remote_main_loop, From patchwork Thu Mar 7 07:22:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCB5F14DE for ; Thu, 7 Mar 2019 07:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACAF32E9EE for ; Thu, 7 Mar 2019 07:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0E402EA29; Thu, 7 Mar 2019 07:51:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3BADC2EA3D for ; Thu, 7 Mar 2019 07:51:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:47028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1noZ-00020x-BY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:51:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMh-0002qx-Pt for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMg-0005nb-GX for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:51 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMf-0005mc-4A for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:49 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JFbn037804; Thu, 7 Mar 2019 07:22:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=w3SDCbl70c5SqdGsJly46WkBvCf7foYJ41mQ+6izp+4=; b=NrM6wlZBymQ/mTZJ8wGwLmbJBUbbWFRHkRCdYA9fQL4/KujnqVH+TCdEEHoPPVQb9R8d uKsLhZcS3AI0xirsbRXty0bcotm6oPQO13YCcdyRF8vBu4ADeRg0cb0fTE9ywD5JoPbX nteU5Uh9DEzshL0Nj1iY8ArmZHHgFbE9PhZbqSvY90RJ7FBRUllfe9S2bbUR4wQFhU/x RxupSeNKosJSAsLlkvCzXPvU1o5JLAw3PcyGo/VMsv+JvWtjejG5Y2lDuL0BbBDu1VVT a/RJxO/rXQXM91nvjUEMOA6Phc3iXKPXl/9UvcOQehObPF5tIUzKw33B0KlAKXJJx6Ce 7g== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2qyh8ug99m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:44 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MdRA007259 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:39 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277Mdds005773; Thu, 7 Mar 2019 07:22:39 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:38 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:36 -0800 Message-Id: <20190307072236.9548-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 29/37] multi-process: remote: add create_done condition X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Do not allow BAR,MMIO handlers and irq setup to run before the configuration of the devices completes. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- remote/remote-main.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/remote/remote-main.c b/remote/remote-main.c index fa32f2a..3fa6cbd 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -67,6 +67,7 @@ static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; +bool create_done; static void process_config_write(ProcMsg *msg) { @@ -355,21 +356,31 @@ static void process_msg(GIOCondition cond) 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: @@ -389,7 +400,7 @@ static void process_msg(GIOCondition cond) 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)) { From patchwork Thu Mar 7 07:22:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29F3E17E9 for ; Thu, 7 Mar 2019 07:49:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1671F2E473 for ; Thu, 7 Mar 2019 07:49:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AA872E48A; Thu, 7 Mar 2019 07:49:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 798222E473 for ; Thu, 7 Mar 2019 07:49:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:46975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nmq-0000pD-QQ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:49:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMd-0002nQ-W0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMa-0005lF-WF for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:46 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMa-0005kB-Ji for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:44 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JTTr038001; Thu, 7 Mar 2019 07:22:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=fwMQMc0+FUjjA205VdjmTrASYT470Vr4B0t+OXaWzN0=; b=e26h8PxmpX7/KEkiHx9FpTE/bDqwagZuj0s+tOmRv5zCtLz13Y3laAwW8AHgWclR2PSI McXBWpsYywCjgCOoVgWNDTnNWHjzF/q/YrcTArxAkJ+imBbQR3y7KoZOysepMLOS6Vht A/WO1FH3RP23G85jUjTWUW2v8qlGI64PkCTC32lr+ZSL8iBr6RFh1hNEJ9uts3ffdBl+ qJ8Ub9caws+VQ32tMBCkGAyNCbmj9LEliGHqXfwgQyghTierM/osAY3mX7S+8cvIAIJE cU27r9IuN0f2d1KiPu7orFkS7ok4dvA3ysXZIcZ3078OOdsuQF/0FMZtphqID/raOc2a kA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2qyh8ug99f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:42 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MfnT007326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:41 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MfWH011869; Thu, 7 Mar 2019 07:22:41 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:41 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:39 -0800 Message-Id: <20190307072239.9594-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 30/37] multi-process: add processing of rdrive and rdevice command line X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Add processing of command line options rdrive and rdevice. After remote devices are created along with their proxies, signal the proxies to finish the configuration steps. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Please enter the commit message for your changes. Lines starting --- vl.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/vl.c b/vl.c index 4c5cc0d..f6bd66e 100644 --- a/vl.c +++ b/vl.c @@ -30,6 +30,11 @@ #include "qemu/help_option.h" #include "qemu/uuid.h" #include "sysemu/seccomp.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) @@ -1165,6 +1170,21 @@ static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) return drive_new(opts, *block_default_type, errp) == NULL; } +#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) { + qemu_log_mask(LOG_REMOTE_DEBUG, "qdev_remote_add failed for drive.\n"); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) { if (qemu_opt_get(opts, "snapshot") == NULL) { @@ -2298,6 +2318,21 @@ static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; } +#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) { + qemu_log_mask(LOG_REMOTE_DEBUG, "qdev_remote_add failed for device.\n"); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; @@ -2984,6 +3019,7 @@ int main(int argc, char **argv, char **envp) Error *err = NULL; bool list_data_dirs = false; char *dir, **dirs; + typedef struct BlockdevOptions_queue { BlockdevOptions *bdo; Location loc; @@ -3036,6 +3072,11 @@ 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); +#if defined(CONFIG_MPQEMU) + qemu_add_opts(&qemu_rdrive_opts); + qemu_add_opts(&qemu_rdevice_opts); +#endif + module_call_init(MODULE_INIT_OPTS); runstate_init(); @@ -3633,6 +3674,22 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + +#if defined(CONFIG_MPQEMU) + case QEMU_OPTION_rdevice: + if (!qemu_opts_parse_noisily(qemu_find_opts("rdevice"), + optarg, true)) { + exit(1); + } + + break; + case QEMU_OPTION_rdrive: + if (!qemu_opts_parse_noisily(qemu_find_opts("rdrive"), + optarg, false)) { + exit(1); + } + break; +#endif case QEMU_OPTION_smp: if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"), optarg, true)) { @@ -4387,6 +4444,7 @@ int main(int argc, char **argv, char **envp) qapi_free_BlockdevOptions(bdo->bdo); g_free(bdo); } + if (snapshot || replay_mode != REPLAY_MODE_NONE) { qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, NULL); @@ -4478,6 +4536,21 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, &error_fatal); +#if defined(CONFIG_MPQEMU) + if (qemu_opts_foreach(qemu_find_opts("rdrive"), rdrive_init_func, + NULL, &err)) { + qemu_log_mask(LOG_REMOTE_DEBUG, + "Failed to execute rdrive_init_func\n."); + } + + if (qemu_opts_foreach(qemu_find_opts("rdevice"), + + rdevice_init_func, NULL, &err)) { + qemu_log_mask(LOG_REMOTE_DEBUG, + "Failed to execute rdevice_init_func\n."); + } +#endif + cpu_synchronize_all_post_init(); rom_reset_order_override(); @@ -4530,10 +4603,13 @@ 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(); if (rom_check_and_register_reset() != 0) { error_report("rom check and register reset failed"); exit(1); } +#endif replay_start(); From patchwork Thu Mar 7 07:22:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D50CC1515 for ; Thu, 7 Mar 2019 07:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF7B62D84C for ; Thu, 7 Mar 2019 07:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0C0E2DF23; Thu, 7 Mar 2019 07:35:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B5262D84C for ; Thu, 7 Mar 2019 07:35:57 +0000 (UTC) Received: from localhost ([127.0.0.1]:46726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nZM-000407-At for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:35:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMg-0002pc-G8 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMf-0005n3-A4 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:50 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:48880) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMe-0005lx-0W for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:48 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JB9x037782; Thu, 7 Mar 2019 07:22:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=JtDkWMM8BaMrpWEwLytI9uWU6MXjDVqhRJ4Q/oU5gkU=; b=r21aj8t5Mga4MSTAPZmxjATkKZmP1oYmMABJrfCZ03Qc/dv0MswpNbWn2sfD6o/7UK97 Km0N0fI+UAmd7ZTcRZ0TnifB8fNcqXqrka3y/zskVqPP4379hJOug/95occf4/nXM79m k2oKXjIRJo4QWvg0BZNvcd/zpnUlm/S7nVCQ0E5oGUiulAPrBY5MzFSeLEhvf5Bf27RA I5H7/d+ZEpxVPBtr7zfz+iDe4IIRsnC3GATzRRi7ybwOEjekA3mD/f/nudDPq8Uk6gnv DLHn4wZmrxlczZKUzZZbfOgAF5yojJL+dvaQ6INxjHAMHNkhW+LIEsWiy7CBcCcPireF Aw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2qyh8ug99j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:44 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MiXW007378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:44 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277Mhhx011885; Thu, 7 Mar 2019 07:22:43 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:43 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:41 -0800 Message-Id: <20190307072241.9639-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [multiprocess RFC PATCH 31/37] multi-process: add heartbeat timer and signal handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Add isignal handler for launched remote processes and set up the heartbit timer for remote processes. Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- hw/proxy/qemu-proxy.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ include/io/proxy-link.h | 1 + 2 files changed, 102 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 9d075ec..e055abe 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -61,14 +61,96 @@ */ int kvm_vm_ioctl(KVMState *s, int type, ...); +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(ProcMsg *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(ProcMsg *msg, bool need_reply) +{ + PCIProxyDev *entry; + unsigned int pid; + int wait; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (need_reply) { + wait = GET_REMOTE_WAIT; + msg->num_fds = 1; + msg->fds[0] = wait; + } + + proxy_proc_send(entry->proxy_link, msg); + if (need_reply) { + pid = (uint32_t)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + /* TODO: Add proper handling. */ + if (pid) { + need_reply = 0; + } + } + } +} + +#define NOP_INTERVAL 1000000 + +static void remote_ping(void *opaque) +{ + ProcMsg msg; + + memset(&msg, 0, sizeof(ProcMsg)); + + 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) @@ -165,6 +247,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; } @@ -309,6 +392,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) } +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(ProxyLinkState *proxy_link, MemoryRegion *mr, bool write, hwaddr addr, uint64_t *val, unsigned size, bool memory) diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 21d63cc..af451e8 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -76,6 +76,7 @@ typedef enum { DRIVE_OPTS, DEVICE_ADD, DEVICE_DEL, + PROXY_PING, MAX, } proc_cmd_t; From patchwork Thu Mar 7 07:22:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7E4F1515 for ; Thu, 7 Mar 2019 07:41:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6B0C2E99C for ; Thu, 7 Mar 2019 07:41:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B463B2E9A6; Thu, 7 Mar 2019 07:41:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 57BAB2E99E for ; Thu, 7 Mar 2019 07:41:58 +0000 (UTC) Received: from localhost ([127.0.0.1]:46844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nfB-0001vL-JI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:41:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMj-0002t0-KT for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMh-0005tF-Oc for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:52 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50992) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMg-0005nJ-Ft for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:51 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277K2cN034689; Thu, 7 Mar 2019 07:22:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=fYZhaZtlBBQ+adgNK8LcHCysKP16KGXE5PVCZ9igBvA=; b=Bg2ONY6FYjtSdS2JumZU+k3GCHFT8aZkJ4kahM+aAur+QhYMYuGmiMmYr0n+iwtLXDe/ 86Y2KZHmsPDUGghrCDzf0Ls4biwmFuXiMJVlqM626qAHCCpbA4o/4L08XAt23kI4Xad7 z/nrqlEtdu+2eHyQ0XuT6eoCy2utEU4hQSsOKsk60zGW7QwYp0IDogyl0SpvX5CSQXGO Jm/kcvDcrItOuoCpwZlCUojpUGSRomWnRssssFMfC+n4/jf+xIMN7IFTjWMfOWJ2u/9d YMb6Jq9nUoQAvMoR1/uK+R+AtRrwMcZQ5qcs+HNJOqyZ6S60/fFixSprzK8m0/kUER2g Ow== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbeggka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:46 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MjZ4002398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:46 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277Mj9s024743; Thu, 7 Mar 2019 07:22:45 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:45 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:43 -0800 Message-Id: <20190307072243.9685-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 32/37] multi-process: handle heartbit messages in remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva and reply back to proxy object. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- remote/remote-main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index 3fa6cbd..1e45105 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -339,6 +339,7 @@ static void process_msg(GIOCondition cond) { ProcMsg *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); @@ -418,6 +419,11 @@ static void process_msg(GIOCondition cond) 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; From patchwork Thu Mar 7 07:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80CAC1515 for ; Thu, 7 Mar 2019 07:44:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DECF2E8F0 for ; Thu, 7 Mar 2019 07:44:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E42D2E925; Thu, 7 Mar 2019 07:44:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B6F182E8F0 for ; Thu, 7 Mar 2019 07:44:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:46869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nhr-0004L3-Tk for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:44:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMk-0002u2-Ig for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMj-00061o-5g for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:54 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56290) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMi-0005qk-0D for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:22:52 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JOxP037964; Thu, 7 Mar 2019 07:22:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=q0HEiWHShs9AiUnBv917/zCCyudpi5ZGEYP8OTeI+MU=; b=MXjZotiKDx5dS4Sth6FOzuApq/kiQ33eBLbQyGgVIA/sx0828JB6BPc12ETHiBnRzDrA +37H5b53x4Utw3rFwFOPVJesFked/DSFtlrXMbn/E6cmmZ53YvH53oeU8LSZYFFYuMB4 XtfxwFHhyRDd1RSgdXio6sj9x2u8MgYW2h0gHJobBZO/VSwneID1xsQgWMsDJKvbuYoR Y5Jqwic5TyajHNuwOQBP+KGzJdoxpCAbW9PRF34JHR7LN+6Y4w0q3x4fYSFqWvzhrze+ geRZhP9r+xhHR7ymjx8sDwn5YLh3fbxX3XIQP7TMZ73vtGMhqZFc3+OyN/TJYX+AejoS iA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qyjfrr5gf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:49 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x277MmoV007547 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:48 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277Mm0B004447; Thu, 7 Mar 2019 07:22:48 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:47 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:46 -0800 Message-Id: <20190307072246.9733-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 33/37] multi-process: HMP command to add drive to the remote device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add rdrive_add HMP command to hot-plug drive to the remote device. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hmp-commands.hx | 16 ++++++++++++++++ hw/proxy/monitor.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/io/proxy-link.h | 2 ++ include/sysemu/sysemu.h | 1 + remote/machine.c | 8 ++++++++ remote/remote-main.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 7f121b4..3829203 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1401,6 +1401,22 @@ STEXI Add drive to PCI storage controller. ETEXI +#if defined(CONFIG_MPQEMU) + { + .name = "rdrive_add", + .args_type = "rdev_id:s,id:s,opts:s", + .params = "rdev_id opts", + .help = "add drive to remote PCI storage controller", + .cmd = hmp_rdrive_add, + }, + +STEXI +@item rdrive_add +@findex rdrive_add +Add drive to remote PCI storage controller. +ETEXI +#endif + { .name = "pcie_aer_inject_error", .args_type = "advisory_non_fatal:-a,correctable:-c," diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c index 05c8f8b..ead1e3d 100644 --- a/hw/proxy/monitor.c +++ b/hw/proxy/monitor.c @@ -41,6 +41,7 @@ #include "qapi/qmp/qstring.h" #include "qapi/error.h" #include "io/proxy-link.h" +#include "sysemu/sysemu.h" /* * TODO: Is there a callback where the allocated memory for QMP could be free'd @@ -201,3 +202,47 @@ void hmp_rdevice_del(Monitor *mon, const QDict *qdict) } } +void hmp_rdrive_add(Monitor *mon, const QDict *qdict) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + Error *local_err = NULL; + ProcMsg msg = {0}; + PCIProxyDev *pdev = NULL; + const char *id, *opts; + char *data; + int wait; + + pdev = get_proxy_device((QDict *)qdict, &local_err); + if (local_err) { + monitor_printf(mon, "rdrive_add error: %s\n", + error_get_pretty(local_err)); + error_free(local_err); + return; + } + + id = qdict_get_str(qdict, "id"); + + opts = qdict_get_str(qdict, "opts"); + + data = g_strdup_printf("%s,id=%s", opts, id); + + wait = GET_REMOTE_WAIT; + + msg.cmd = DRIVE_ADD; + msg.bytestream = 1; + msg.size = strlen(data); + msg.data2 = (uint8_t *)data; + msg.num_fds = 1; + msg.fds[0] = wait; + + proxy_proc_send(pdev->proxy_link, &msg); + (void)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + + /* TODO: Only on success */ + (void)g_hash_table_insert(pcms->remote_devs, (gpointer)g_strdup(id), + (gpointer)pdev); + + g_free(data); +} + diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index af451e8..3ef16f1 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -62,6 +62,7 @@ typedef struct ProxyLinkState ProxyLinkState; * from remote device * DEVICE_ADD QMP/HMP command to hotplug device * DEVICE_DEL QMP/HMP command to hot-unplug device + * DRIVE_ADD HMP command to hotplug drive * */ typedef enum { @@ -76,6 +77,7 @@ typedef enum { DRIVE_OPTS, DEVICE_ADD, DEVICE_DEL, + DRIVE_ADD, PROXY_PING, MAX, } proc_cmd_t; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 82622be..0c51fe0 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -138,6 +138,7 @@ extern unsigned int nb_prom_envs; /* generic hotplug */ void hmp_drive_add(Monitor *mon, const QDict *qdict); +void hmp_rdrive_add(Monitor *mon, const QDict *qdict); /* pcie aer error injection */ void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); diff --git a/remote/machine.c b/remote/machine.c index c1c7b77..c6801ca 100644 --- a/remote/machine.c +++ b/remote/machine.c @@ -74,6 +74,8 @@ static void remote_machine_init(Object *obj) MemoryRegion *system_memory, *system_io, *pci_memory; PCIHostState *pci_host; PCIDevice *pci_dev; + MachineState *ms; + MachineClass *mc; Error *error_abort = NULL; @@ -116,6 +118,12 @@ static void remote_machine_init(Object *obj) pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, s->iohub, REMOTE_IOHUB_NB_PIRQS); + + ms = MACHINE(s); + + mc = MACHINE_GET_CLASS(ms); + + mc->block_default_type = IF_IDE; } static const TypeInfo remote_machine = { diff --git a/remote/remote-main.c b/remote/remote-main.c index 1e45105..4c52d30 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -234,6 +234,29 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_drive_add_msg(ProcMsg *msg) +{ + Error *local_err = NULL; + const char *optstr = (const char *)msg->data2; + int wait = msg->fds[0]; + QemuOpts *opts; + MachineClass *mc; + + opts = drive_def(optstr); + assert(opts); + + mc = MACHINE_GET_CLASS(current_machine); + (void)drive_new(opts, mc->block_default_type, &local_err); + + if (local_err) { + error_report_err(local_err); + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + static int init_drive(QDict *rqdict, Error **errp) { QemuOpts *opts; @@ -419,6 +442,9 @@ static void process_msg(GIOCondition cond) case DEVICE_DEL: process_device_del_msg(msg); break; + case DRIVE_ADD: + process_drive_add_msg(msg); + break; case PROXY_PING: wait = msg->fds[0]; notify_proxy(wait, (uint32_t)getpid()); @@ -462,6 +488,11 @@ int main(int argc, char *argv[]) bdrv_init_with_whitelist(); 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); if (qemu_init_main_loop(&err)) { error_report_err(err); From patchwork Thu Mar 7 07:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842343 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AFC6217E4 for ; Thu, 7 Mar 2019 07:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D8592E9A0 for ; Thu, 7 Mar 2019 07:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9064E2E9EE; Thu, 7 Mar 2019 07:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AC582E9A0 for ; Thu, 7 Mar 2019 07:52:49 +0000 (UTC) Received: from localhost ([127.0.0.1]:47032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nph-0002LE-7R for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:52:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMs-000329-C6 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMr-0006Zl-01 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:02 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMq-0006Z4-JP for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:00 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JK9o037932; Thu, 7 Mar 2019 07:22:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=mGjpMEfyTgWJNDfl6nQF6Y/MKVNzmDs9+vygYsGtLy8=; b=S24TaDUuZZxmjjKjlqfJZWBDAEJm6TqxegtT100eUNjJ5uZU8ECRpk5F5RZADgL/SYfb HN2siRpejKnxQ+AgystT3cQm3Tfvg36FyDKWldZE8bS8WySh3x6k9IZPgJcYTL2Y+/d5 JmmyV5cPJC5k60T7U3zewSArQeNfIxpLc8brVigK0oYemNu1QxRPhhPf9VZIs1PShkPL oDNYo/qKC/rcCDCm9gZH7PE2/DtNuuZjxXhOL32Y79ZddE5fAFZx1B1CgNk8sPk86odf 1o1iVDFCwNFucZ4bFe++LlN+D4A6cyNrD6MSjs0bZKuxIA4K0aaa+3GhNXkq4gzdNjjN iQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qyjfrr5gp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:56 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MpUj002572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:51 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MoIa011964; Thu, 7 Mar 2019 07:22:50 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:50 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:48 -0800 Message-Id: <20190307072248.9778-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 34/37] multi-process: HMP command to delete drive from remote device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Add rdrive_del HMP command to hot-unplug drive from remote device. Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson --- hmp-commands.hx | 14 ++++++++++++++ hw/proxy/monitor.c | 37 +++++++++++++++++++++++++++++++++++++ include/io/proxy-link.h | 2 ++ include/sysemu/blockdev.h | 1 + remote/remote-main.c | 18 ++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 3829203..510fc24 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1415,6 +1415,20 @@ STEXI @findex rdrive_add Add drive to remote PCI storage controller. ETEXI + + { + .name = "rdrive_del", + .args_type = "rdev_id:s,id:s", + .params = "rdev_id id", + .help = "remove drive from remote PCI storage controller", + .cmd = hmp_rdrive_del, + }, + +STEXI +@item rdrive_del +@findex rdrive_del +Remove drive from remote PCI storage controller +ETEXI #endif { diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c index ead1e3d..aa09ea8 100644 --- a/hw/proxy/monitor.c +++ b/hw/proxy/monitor.c @@ -42,6 +42,7 @@ #include "qapi/error.h" #include "io/proxy-link.h" #include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" /* * TODO: Is there a callback where the allocated memory for QMP could be free'd @@ -246,3 +247,39 @@ void hmp_rdrive_add(Monitor *mon, const QDict *qdict) g_free(data); } +void hmp_rdrive_del(Monitor *mon, const QDict *qdict) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + Error *local_err = NULL; + ProcMsg msg = {0}; + PCIProxyDev *pdev = NULL; + const char *id; + int wait; + + pdev = get_proxy_device((QDict *)qdict, &local_err); + if (local_err) { + monitor_printf(mon, "rdrive_del error: %s\n", + error_get_pretty(local_err)); + error_free(local_err); + return; + } + + id = qdict_get_str(qdict, "id"); + + wait = GET_REMOTE_WAIT; + + msg.cmd = DRIVE_DEL; + msg.bytestream = 1; + msg.size = strlen(id); + msg.data2 = (uint8_t *)id; + msg.num_fds = 1; + msg.fds[0] = wait; + + proxy_proc_send(pdev->proxy_link, &msg); + (void)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + + /* TODO: Only on success */ + (void)g_hash_table_remove(pcms->remote_devs, (gpointer)id); +} + diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 3ef16f1..013a845 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -63,6 +63,7 @@ typedef struct ProxyLinkState ProxyLinkState; * DEVICE_ADD QMP/HMP command to hotplug device * DEVICE_DEL QMP/HMP command to hot-unplug device * DRIVE_ADD HMP command to hotplug drive + * DRIVE_DEL HMP command to hot-unplug drive * */ typedef enum { @@ -78,6 +79,7 @@ typedef enum { DEVICE_ADD, DEVICE_DEL, DRIVE_ADD, + DRIVE_DEL, PROXY_PING, MAX, } proc_cmd_t; diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h index d34c492..e6a9780 100644 --- a/include/sysemu/blockdev.h +++ b/include/sysemu/blockdev.h @@ -61,4 +61,5 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type, void hmp_commit(Monitor *mon, const QDict *qdict); void hmp_drive_del(Monitor *mon, const QDict *qdict); +void hmp_rdrive_del(Monitor *mon, const QDict *qdict); #endif diff --git a/remote/remote-main.c b/remote/remote-main.c index 4c52d30..08e3528 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -257,6 +257,21 @@ static void process_drive_add_msg(ProcMsg *msg) PUT_REMOTE_WAIT(wait); } +static void process_drive_del_msg(ProcMsg *msg) +{ + const char *idstr = (const char *)msg->data2; + int wait = msg->fds[0]; + QDict *qdict = qdict_new(); + + qdict_put_str(qdict, "id", idstr); + + hmp_drive_del(NULL, qdict); + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + static int init_drive(QDict *rqdict, Error **errp) { QemuOpts *opts; @@ -445,6 +460,9 @@ static void process_msg(GIOCondition cond) case DRIVE_ADD: process_drive_add_msg(msg); break; + case DRIVE_DEL: + process_drive_del_msg(msg); + break; case PROXY_PING: wait = msg->fds[0]; notify_proxy(wait, (uint32_t)getpid()); From patchwork Thu Mar 7 07:22:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F31E514DE for ; Thu, 7 Mar 2019 07:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFD9A2E8F0 for ; Thu, 7 Mar 2019 07:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D33E92E925; Thu, 7 Mar 2019 07:46:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC8C92E8F0 for ; Thu, 7 Mar 2019 07:46:08 +0000 (UTC) Received: from localhost ([127.0.0.1]:46909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1njE-0005mw-1J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:46:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMv-00036q-7K for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMs-0006aU-DK for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:05 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:51186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMr-0006ZJ-D3 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:02 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JSDs034097; Thu, 7 Mar 2019 07:22:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=xKJNpUiQYtxcNip19ElNf1k0CGpHFlXi/BKi9ArrLl4=; b=lchRqtzDz6BME68LhrPsKSTg4+X8hoxcXRAC+KQzFo6TqYVvfMcbzxZe1SU3Hnc+ihVi lTtjXPqgTjT2x8N9ySnIzDt0s+64ToDTyn5zr2StiBjZK1ARq7wNJL904o+mf6tvL2RV m9agPp53EmbMhUzEE1A9rSo6365eUsbWqkpF2eq9XlRox/NIFKTHnhPWiRgQTfeJqjtc E8FkTEbut8NLqNz2RaGJJpdeps/GlupUdKZVk7LEq9UMiPj42/bujMxemnSAm/M135I5 pnKU0K2z36c4QSZiMngmtDAy4HAwGj51O4zSuHGiTAZbMaAu4W1ql6ObhTKAYB07+8xw uA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2qyfbeggkf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:54 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MrpG002667 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:53 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x277MrSJ004495; Thu, 7 Mar 2019 07:22:53 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:53 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:51 -0800 Message-Id: <20190307072251.9823-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 35/37] multi-process: QMP/HMP commands to resize block device on remote process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, dgilbert@redhat.com, armbru@redhat.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jagannathan Raman Adds rblock_resize QMP/HMP commands to resize block devices on the remote process. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- hmp-commands.hx | 14 +++++++++++++ hmp.h | 1 + hw/proxy/monitor.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ include/io/proxy-link.h | 2 ++ qapi/block-core.json | 25 +++++++++++++++++++++++ remote/remote-main.c | 36 +++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 510fc24..844acd0 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1429,6 +1429,20 @@ STEXI @findex rdrive_del Remove drive from remote PCI storage controller ETEXI + + { + .name = "rblock_resize", + .args_type = "rdev_id:s,device:s,size:o", + .params = "rdev_id device size", + .help = "resize block device on the remote device", + .cmd = hmp_rblock_resize, + }, + +STEXI +@item rblock_resize +@findex rblock_resize +Resize block device on the remote device +ETEXI #endif { diff --git a/hmp.h b/hmp.h index 52b83c0..6a51bd3 100644 --- a/hmp.h +++ b/hmp.h @@ -152,5 +152,6 @@ void hmp_info_sev(Monitor *mon, const QDict *qdict); void hmp_remote_proc_list(Monitor *mon, const QDict *qdict); void hmp_rdevice_add(Monitor *mon, const QDict *qdict); void hmp_rdevice_del(Monitor *mon, const QDict *qdict); +void hmp_rblock_resize(Monitor *mon, const QDict *qdict); #endif diff --git a/hw/proxy/monitor.c b/hw/proxy/monitor.c index aa09ea8..bd5fc4f 100644 --- a/hw/proxy/monitor.c +++ b/hw/proxy/monitor.c @@ -283,3 +283,56 @@ void hmp_rdrive_del(Monitor *mon, const QDict *qdict) (void)g_hash_table_remove(pcms->remote_devs, (gpointer)id); } +void qmp_rblock_resize(const char *rdev_id, const char *device, int64_t size, + Error **errp) +{ + PCMachineState *pcms = PC_MACHINE(current_machine); + PCIProxyDev *pdev = NULL; + ProcMsg msg = {0}; + QString *json; + QDict *qdict; + int wait; + + pdev = (PCIProxyDev *)g_hash_table_lookup(pcms->remote_devs, rdev_id); + if (!pdev) { + error_setg(errp, "No remote device named %s", device); + return; + } + + qdict = qdict_new(); + qdict_put_str(qdict, "device", device); + qdict_put_int(qdict, "size", size); + + json = qobject_to_json(QOBJECT(qdict)); + + wait = GET_REMOTE_WAIT; + + msg.cmd = BLOCK_RESIZE; + msg.bytestream = 1; + msg.size = strlen(qstring_get_str(json)); + msg.data2 = (uint8_t *)qstring_get_str(json); + msg.num_fds = 1; + msg.fds[0] = wait; + + proxy_proc_send(pdev->proxy_link, &msg); + (void)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); +} + +void hmp_rblock_resize(Monitor *mon, const QDict *qdict) +{ + Error *local_err = NULL; + const char *rdev_id, *device; + int64_t size; + + rdev_id = qdict_get_str(qdict, "rdev_id"); + device = qdict_get_str(qdict, "device"); + size = qdict_get_int(qdict, "size"); + + qmp_rblock_resize(rdev_id, device, size, &local_err); + if (local_err) { + monitor_printf(mon, "rblock_resize error: %s\n", + error_get_pretty(local_err)); + error_free(local_err); + } +} diff --git a/include/io/proxy-link.h b/include/io/proxy-link.h index 013a845..8ed520c 100644 --- a/include/io/proxy-link.h +++ b/include/io/proxy-link.h @@ -64,6 +64,7 @@ typedef struct ProxyLinkState ProxyLinkState; * DEVICE_DEL QMP/HMP command to hot-unplug device * DRIVE_ADD HMP command to hotplug drive * DRIVE_DEL HMP command to hot-unplug drive + * BLOCK_RESIZE QMP/HMP command to resize block backend * */ typedef enum { @@ -81,6 +82,7 @@ typedef enum { DRIVE_ADD, DRIVE_DEL, PROXY_PING, + BLOCK_RESIZE, MAX, } proc_cmd_t; diff --git a/qapi/block-core.json b/qapi/block-core.json index 05394c4..4869ff7 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1260,6 +1260,31 @@ 'size': 'int' } } ## +# @rblock_resize: +# +# Resize a block image while a guest is running, on a remote device. +# +# @device: the name of the device to get the image resized +# +# @size: new image size in bytes +# +# Returns: nothing on success +# If @device is not a valid block device, DeviceNotFound +# +# Since: 3.0.93 +# +# Example: +# +# -> { "execute": "rblock_resize", +# "arguments": { "device": "scratch", "size": 1073741824 } } +# <- { "return": {} } +# +## +{ 'command': 'rblock_resize', + 'data': { 'rdev_id': 'str', 'device': 'str', 'size': 'int' }, + 'if': 'defined(CONFIG_MPQEMU)' } + +## # @NewImageMode: # # An enumeration that tells QEMU how to set the backing file path in diff --git a/remote/remote-main.c b/remote/remote-main.c index 08e3528..3316546 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -64,6 +64,7 @@ #include "qapi/qmp/qlist.h" #include "qemu/log.h" #include "qemu/cutils.h" +#include "qapi/qapi-commands-block-core.h" static ProxyLinkState *proxy_link; PCIDevice *remote_pci_dev; @@ -272,6 +273,38 @@ static void process_drive_del_msg(ProcMsg *msg) PUT_REMOTE_WAIT(wait); } +static void process_block_resize_msg(ProcMsg *msg) +{ + const char *json = (const char *)msg->data2; + Error *local_err = NULL; + int wait = msg->fds[0]; + const char *device; + int64_t size; + QObject *qobj = NULL; + QDict *qdict = NULL; + + qobj = qobject_from_json(json, &local_err); + if (local_err) { + error_report_err(local_err); + return; + } + + qdict = qobject_to(QDict, qobj); + assert(qdict); + + device = qdict_get_str(qdict, "device"); + size = qdict_get_int(qdict, "size"); + + qmp_block_resize(true, device, false, NULL, size, &local_err); + if (local_err) { + error_report_err(local_err); + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + static int init_drive(QDict *rqdict, Error **errp) { QemuOpts *opts; @@ -468,6 +501,9 @@ static void process_msg(GIOCondition cond) notify_proxy(wait, (uint32_t)getpid()); PUT_REMOTE_WAIT(wait); break; + case BLOCK_RESIZE: + process_block_resize_msg(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Mar 7 07:22:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14CF114DE for ; Thu, 7 Mar 2019 07:47:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE0B52E925 for ; Thu, 7 Mar 2019 07:47:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1D102E99A; Thu, 7 Mar 2019 07:47:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F42012E925 for ; Thu, 7 Mar 2019 07:47:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:46929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nkd-00074R-9l for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:47:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nN4-0003FJ-6z for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMx-0006lv-FM for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:13 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:56484) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMw-0006e3-1q for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:06 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JjwT038079; Thu, 7 Mar 2019 07:22:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=gXFDENtXUtHnhuo8QfWWueN2lEONvnkqvdp4/b02S1E=; b=oL1Kkgw9oDEYkbcQup88aWJ7glUfm/x2onWseZRMuu3mFiSh83WAvQoRbGt7zmfdruhq VfVdO+8xRVJ93zvwEpAqgGzhwDhNwAqoovvZx7YqhLagkHHn53Ck2hL5Gkp+ZlVsR462 RV/g0koLGJOXN5dV+KNj8k+Hs3JLL+2O04GxZOnSwc+lp+PnNFryJWwycrymY0SvwCTZ DXT4sgRcssB0P8kv6lyVeOhFGjqsfSt9sERnGizUhPA/qHA3a/Lv661alpc0TpI66sz0 2MZoLUw9B6W65J+BZW6e6sXKEQhwbxrOiwR67pBuYwlraKVLAquszTCPyBXCFFZNj+ju Jw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qyjfrr5gr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:22:57 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277MuEM002812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:22:56 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277MuA5005817; Thu, 7 Mar 2019 07:22:56 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:55 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:53 -0800 Message-Id: <20190307072253.9868-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [multiprocess RFC PATCH 36/37] multi-process: add the concept description to docs/devel/qemu-multiprocess X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva TODO: Make relevant changes to the doc. Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- docs/devel/qemu-multiprocess.txt | 1109 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1109 insertions(+) create mode 100644 docs/devel/qemu-multiprocess.txt diff --git a/docs/devel/qemu-multiprocess.txt b/docs/devel/qemu-multiprocess.txt new file mode 100644 index 0000000..e29c6c8 --- /dev/null +++ b/docs/devel/qemu-multiprocess.txt @@ -0,0 +1,1109 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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. + */ + +Disaggregating QEMU + +This document describes implementation details of multi-process +qemu. + +1. 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. + +1.1 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 control QEMU process would remain, but in disaggregated +mode, it would be a control point that exec()s the processes needed to +support the VM being created, but have no direct interface 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 QEMU control process. + + +2. 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. + +2.1 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 a device +named "foo" is included in the target VM (such as via the QEMU command +line as -device "foo".) + + The object model is hierarchical, so device emulation code can +name 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. + +2.2 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. + +2.2.1 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. + +2.2.1.1 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. + +2.2.1.2 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 return 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. + +2.2.1.3 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. + +2.2.1.4 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 mmap()d 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. + +2.2.1.5 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. + +2.2.2 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. + +2.3 New separation model based on proxy objects + + A different model based on proxy objects in the QEMU program +communicating with proxy objects the separated 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. + +2.3.1 command line specification + + 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. + +2.3.1.1 devices + + Devices that are to be emulated in a separate process will be +identified by using "-rdevice" on the QEMU command line in lieu of +"-device". The device's other options will also be included in the +command line, with the addition of a "command" option that specifies +the remote program to execute to emulate the device. e.g., an LSI +SCSI controller and disk can be specified as: + +-device lsi53c895a,id=scsi0 device +-device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + + If these devices are emulated with program "lsi-scsi," the +QEMU command line would be: + +-rdevice lsi53c895a,id=scsi0,command="lsi-scsi" +-rdevice scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + + Some devices are implicitly created by the machine object. +e.g., the "q35" machine object will create its PCI bus, and attach a +"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-command="ahci-ide" + + will use the "ahci-ide" program to emulate the IDE controller +and its disks. The disks themselves still need to be specified with +"-rdevice", e.g., + +-rdevice ide-hd,drive=drive0,bus=ide.0,unit=0 + + The "-rdevice" devices will be parsed into a separate +QemuOptsList from "-device" ones, but will still have "driver" +as the implied name of the initial option. + +2.3.1.2 backends + + The device's backend would similarly have a changed command +line specification. e.g., a qcow2 block backend specified as: + +-blockdev driver=file,node-name=file0,filename=disk-file0 +-blockdev driver=qcow2,node-name=drive0,file=file0 + +becomes + +-rblockdev driver=file,node-name=file0,filename=disk-file0 +-rblockdev driver=qcow2,node-name=drive0,file=file0 + + As is the case with devices, "-rblockdev" backends will +be parsed into their own BlockdevOptions_queue. + +2.3.2 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 "-rdevice" +devices will be instantiated in the same manner as "-device" 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 "scsi-hd" +proxy class will be "scsi-hd-proxy" + +2.3.2.1 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(). + +2.3.2.1.1 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. + +2.3.2.1.2 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. They also need to add a "json_device" string +property that contains the JSON representation of the command line +options used to create the object. + + This JSON representation is used to create the corresponding +object in an emulation process. e.g., for an LSI SCSI controller +invoked as: + + -rdevice lsi53c895a,id=scsi0,command="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 must be removed. The "command" option isn't +needed in the JSON description since it only applies to the proxy +object in the QEMU process. + + Other tasks will are device-specific. PCI device objects will +initialize the PCI config space in order to make a valid PCI device +tree within the QEMU process. Disk devices will probe their backend +object to get its JSON description, and publish this description as a +"json_backend" string property (see the backend discussion below.) + +2.3.2.2 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 via a proxy_proc_send() call. Any response will +be read via proxy_proc_recv(). + + Note that the callbacks are called with an address space lock, +so it would not be a appropriate to synchronously wait for any +response. Instead the QEMU code must be changed to check if the +thread needs to sleep after the address_space_rw() call (in +kvm_cpu_exec().) + +2.3.2.3 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 it's 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. + +2.3.2.3.1 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. + +2.3.2.4 interrupt receipt + + A proxy for a device that generates interrupts will receive +the interrupt indication via the read callback it provided to +proxy_ctx_alloc(). The 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(). + +2.3.3 device backends + + Each type of device has backends which perform IO operations +in the host system. For example, block backend objects emulate the +disk images configured into the VM. While block backends are +implemented as objects, not all backends are. For example, display +backends (e.g., vnc) are not objects, they register a set of virtual +functions that are called by QEMU's display emulation. + + These device backends also need run in the device emulation +processes, and the emulation process must be given access the the +corresponding host files or devices. + +2.3.3.1 block backends + + Block backends are objects that can implement file protocols +(such as a local file or an iSCSI volume), implement disk image +formats (such as qcow2), or serve as a request filter (such as IO +throttling). They are often stacked on each other (such as a qcow2 +format on a local file protocol.) They're are named by "node-name" +properties that are then matched to "drive" properties of the +corresponding disk devices. + + Block backend objects are not part of the QEMU object model +(i.e., they're not sub-classes of "object"). They are instantiated +when the bdrv_file_open() method is invoked with a Qdict dictionary +of the backend's command line options. + +2.3.3.1.1 initialization + + When a "-rblockdev" backend is initialized, it will not open +the underlying backend object, as is done for "-blockdev" backends. +Instead, it will create a BlockDriverState node that has a proxy name +and the original options Qdict. The proxy name will consist of the +backend's node-name with "-peer" appended to it (i.e., a "drive0" +node-name would have a "drive0-peer" peer.) + + A proxy backend object with then be opened, using an +initialization Qdict containing the "node-name" of the underlying +backend, so that disk device objects and QMP commands can find it. +The proxy's Qdict will also be given the proxy name as a "peer" +property so it can lookup its underlying backend object and its +associated Qdict. + +2.3.3.1.2 bdrv_probe_json + + This API returns the JSON description of the peer of a given +backend proxy. It will be used by disk device proxy objects to get +the JSON descriptions of the block backend (and any backends layered +below) needed to emulate the disk image. + +2.3.3.1.3 bdrv_get_json + + This is a new block backend object method that returns the +JSON description this object, and all of its underlying objects. It +will recursively descend any layered backend objects (e.g., a format +object will call its underlying protocol object) This method can be +invoked on an object that has not been opened. It will mainly be used +by bdrv_probe_json(). + +2.3.3.1.4 bdrv_assign_proxy_name + + The API creates the node with a proxy name, and enters it on a +list of peer nodes. This list can be searched by proxy backends to +find their associated peers. + +2.3.3.1.5 QMP commands + + Various QMP command operate on blockdevs. These will need +to work on rblockevs in separated processes as well. There are +several cases that need to be handled. + +2.3.3.1.5.1 adding rblockdevs + + QMP allows users to add blockdevs to a running QEMU instance. +This is done not just to hot-plug a disk device into a guest, but also +for advanced blockdev features such as changing quorum devices. +Likewise, QMP needs be able to add an rblockdev to the guest, so +similar operations can be performed on devices being emulated in a +separate process. + + This operation doesn't need to be performed differently from +adding an rblockdev from the command line. Blockdevs are added with a +qmp_blockdev_add() routine that can be called from either the command +line parser or from QMP. Note the name of the C routine called from +QMP is generated by a python script, so a "rblockdev-add" command must +be implemented by qmp_rblockdev_add(). + +2.3.3.1.5.2 targeted commands + + Many QMP commands operate on specified blockdevs. These +commands will find the proxy node when they lookup the targeted name, +which will then forward the request to the emulation process managing +the peer node. + +2.3.3.1.5.3 blockdev lists + + Several QMP query commands (such as query-block or +query-block-jobs) operate on all blockdevs. These will function +much like targeted commands, with the proxy nodes forwarding the +request to its peer emulation process. + +2.3.4 proxy APIs + + There will be a set of APIs provided by a process execution +service for proxy objects to use to manage the separate emulation +program. + +2.3.4.1 proxy_register + + A proxy device object must register itself with the +proxy_register() API. The registration call will include validation +and execution callbacks that will be invoked after the emulated +machine has been setup in QEMU. + +2.3.4.1.1 validation callback + + This callback will invoked after all devices in the emulated +system have been initialized. Its purpose is to validate the device +configuration by checking that its parent and child bus objects are +compatible with being proxied. For example, a disk controller can +check that all the devices on its bus are all proxy objects, or a disk +object can check that its backend object is a proxy. If any of the +validation callbacks return an error, QEMU will exit. If there are no +errors, the execution callbacks will be invoked. + +2.3.4.1.2 execution callback + + A device proxy object that manages an emulation process will +provide an execution callback in its proxy_register() call. This +callback will allocate an execution context with proxy_ctx_alloc(), +marshal the arguments needed for the emulation program, and invoke +proxy_execute() to execute it. + +2.3.4.2 proxy_ctx_alloc + + Before the emulation program can be executed, the proxy object +must call proxy_ctx_alloc() to create an execution context for the +process. The execution context will serve as a handle on which the +other proxy APIs operate. + +2.3.4.3 proxy_ctx_callbacks + + This API registers two callback functions: get_reply() and +get_request(), on the context. get_reply() is invoked to handle +replies to requests sent to the emulation process. get_request() is +invoked to handle requests from the emulation process. This API can +be called multiple times on the same context; a class field within an +incoming message indicates which callbacks will be invoked. + +2.3.4.4 proxy_execute + + This function executes an emulation program. It needs to be +provided with an execution context, the file to execute, and any +arguments needed by the program. Before executing the given program, +it will setup the communications channels for the new process. + +2.3.5 communication with emulation process + + The execution service will setup two communication channels +between the main QEMU process and the emulation process. The channels +will be created using socketpair() so that file descriptors can be +passed from QEMU to the process. + +2.3.5.1 requests to emulation process + + The stdin file descriptor of the emulation process will be +used for requests from QEMU to the emulation process. The execution +service provides APIs to send and receive messages from the emulation +process. + +2.3.5.1.1 proxy_proc_send + + This API is for the proxy object in QEMU to send messages to +the emulation process. Its arguments will include an execution +context in addition to the actual message. + +2.3.5.1.2 proxy_proc_recv + + This API receives replies from the emulation process. It +requires the execution context of the target process, and will usually +be called from the get_reply() callback specified in proxy_ctx_alloc. + +2.3.5.2 requests to QEMU process + + The stdout file descriptor to the emulation process will be +used for requests from the emulation process to QEMU. As with +requests to the emulation process, APIs will be provided to facilitate +communication. + +2.3.5.2.1 proxy_qemu_recv + + This API receives requests from the emulation process. It +requires the execution context of the target process, and will usually +be called from the get_request() callback specified in +proxy_ctx_alloc. + +2.3.5.2.2 proxy_qemu_send + + This API is for the proxy object in QEMU to send replies to +the emulation process. Its arguments will include an execution +context in addition to the actual reply. + +2.3.5.3 JSON descriptions + + The initial messages sent to the emulation process will +describe the devices its will be tasked to emulate. The will be +described as JSON arrays of backend and device objects that need to be +instantiated by the emulation process. + +2.3.5.3.1 backend JSON + + The device proxy object will aggregate the "json_backend" +properties from the disk devices on the bus it controls, and send +them as a JSON array of objects. e.g., this command line: + +-rblockdev driver=file,node-name=file0,filename=disk-file0 +-rblockdev driver=qcow2,node-name=drive0,file=file0 + +would generate + +[ + { "driver" : "file", "node-name" : "file0", "filename" : "disk-file0" }. + { "driver" : "qcow2", "node-name" : "drive0", "file" : "file0" } +] + +2.3.5.3.2 device JSON + + The device proxy object will aggregate a JSON description of +itself and devices on the bus it controls (via their "json_device" +properties), and send them to the emulation process as a JSON array of +objects. + +2.3.5.4 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. + +2.3.5.5 IOMMU operations + + When the emulated system includes an IOMMU, the proxy +execution service will need to handle IOMMU requests from the +emulation process using an address_space_get_iotlb_entry() call. In +order to handle IOMMU unmaps, the proxy execution service 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. + + This also will require a proxy_ctx_callbacks() call to +register an IOMMU handler for incoming IOMMU requests from the +emulation program. + +2.3.6 device emulation process + + The device emulation process will run the object hierarchy of +the device, hopefully unmodified. It will be based on the QEMU source +code, because for anything but the simplest device, it would not be a +tractable problem to re-implement both the object model and the many +device backends that QEMU has. + + 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. + +2.3.6.1 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 arrays sent by the +QEMU process will drive which objects need to be created. + +2.3.6.1.1 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). + +2.3.6.1.2 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(). + +2.3.6.1.3 PCI + + IO initialization will be driven by the JSON description 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. + +2.3.6.2 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 withing 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. + +2.3.6.3 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. + +2.3.6.3.1 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. + +2.3.6.3.2 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. + +2.3.6.4 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. + +2.3.6.5 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. + +2.3.6.5.1 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. + +2.3.6.5.2 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. + +2.4 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. + +2.4.1 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. + +2.4.1.1 data structures + +2.4.1.1.1 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 x86 +machine, 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 enumeration value to specify which of the device's +ranges is being referred to. + +2.4.1.1.2 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. + +2.4.1.1.3 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. + +2.4.1.1.4 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. + +2.4.1.1.5 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. + +2.4.1.2 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. + +2.4.1.2.1 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 ioctls() on its KVM file descriptor. They include: + +2.4.1.1.2.1 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. + +2.4.1.1.2.2 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 that +will 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. + +2.4.1.1.2.3 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. + +2.4.1.3 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. + +2.4.1.3.1 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. + +2.4.1.3.2 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. + +2.4.1.3.3 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. + +2.4.1.3.4 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. + +2.4.1.3.5 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. + +2.4.1.4 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_devce 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. + +2.4.1.4.1 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. + +2.4.1.4.2 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. + +2.4.2 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. + +2.4.2.1 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 it. + +2.4.2.1.1 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(). + +2.4.2.1.2 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()) + +2.4.2.2 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. + +2.4.2.2.1 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(). + +2.4.2.2.2 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. + + +3. 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. + + +4. 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. + +4.1 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. + +4.2 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. + +4.2.1 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. + +4.2.2 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. + From patchwork Thu Mar 7 07:22:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elena Ufimtseva X-Patchwork-Id: 10842325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CCA914DE for ; Thu, 7 Mar 2019 07:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A5B2E8F0 for ; Thu, 7 Mar 2019 07:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D8A62E925; Thu, 7 Mar 2019 07:45:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 77FC82E8F0 for ; Thu, 7 Mar 2019 07:45:24 +0000 (UTC) Received: from localhost ([127.0.0.1]:46864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1niV-0003jG-Oo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Mar 2019 02:45:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1nMx-00039F-Hl for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1nMw-0006lO-9U for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:07 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:51310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1nMv-0006at-6G for qemu-devel@nongnu.org; Thu, 07 Mar 2019 02:23:05 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x277JHcZ033911; Thu, 7 Mar 2019 07:23:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=Y9ZGZypfPiibPbuFNxFWllovtDXnMgtqxUCSlAf0dDA=; b=yarli5LgXNPtPUoD+nrFPWrPdlNIzfp7OgbGPKonHniu1Gl0CrKwt98T9yC5Hhs3GhIW EXq2tyA6Uc3PaiV0LMxE2FPaNtB7qLEZ2ujJPXu2fUtCYZKwqvUAuCR2zRGQhjJi13ZF JPvr4AuMhj0dXfOB1X2WQJyv/g9jJCVaIAylUpe+H5GVeZCa8lAT6V/znV29YXY2plVK ObjtiumKP4DADz51xNQG7PnB/0djYQJ7AfzxM/w4DmlVHZAE8s/1XE2wL+aYoBwEbTTL Qfzg1ORERS+WAxwLoCP4YUflGNW9IuuR6kq/6W1UBOW5+RDmZSJzJQ5qbaWy+r9USFX5 6A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qyfbeggmd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 07 Mar 2019 07:23:01 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x277N0xn003103 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Mar 2019 07:23:00 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x277MwZY005824; Thu, 7 Mar 2019 07:23:00 GMT Received: from heatpipe.hsd1.ca.comcast.net (/73.170.27.202) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Mar 2019 23:22:58 -0800 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2019 23:22:56 -0800 Message-Id: <20190307072256.9917-1-elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.17.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9187 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903070053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [multiprocess RFC PATCH 37/37] multi-process: add configure and usage information X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, john.g.johnson@oracle.com, sstabellini@kernel.org, jag.raman@oracle.com, konrad.wilk@oracle.com, ross.lagerwall@citrix.com, liran.alon@oracle.com, stefanha@redhat.com, kanth.ghatraju@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- docs/qemu-multiprocess.txt | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 docs/qemu-multiprocess.txt diff --git a/docs/qemu-multiprocess.txt b/docs/qemu-multiprocess.txt new file mode 100644 index 0000000..b0428da --- /dev/null +++ b/docs/qemu-multiprocess.txt @@ -0,0 +1,104 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. All rights reserved. + * + * 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. + */ + + +Multi-process QEMU + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +Configure + +To enable support for multi-process add --enable-mpqemu +to the list of options for configure. + +Usage + +Command line + +To start qemu with devices intended to run in the separate emulation +process, the following options are used: + + -rdevice, -rdrive: + this is similar to -device option, with only difference being + the "rid" option that identifies the remote process. + +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: + -rdevice lsi53c895a,id=scsi0,rid=0 + -rdevice scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0 + -rdrive id=drive0,file=data-disk.img,rid=0 + + +The memorybackend object has to be specified on the command line: +-object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + + +Example of running scsi drive in the guest in separate qemu +process: + +qemu-system-x86_64 -enable-kvm -machine q35 -smp 4 -m 4096M -vnc :0 \ +-net nic -net user,hostfwd=tcp::5022-:22 -hda os.qcow2 \ +-rdevice lsi53c895a,rid=0,id=scsi0 \ +-rdevice scsi-hd,rid=0,drive=drive0,bus=scsi0.0,scsi-id=0 \ +-rdrive id=drive0,rid=0,file=data-disk.img \ +-object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on -numa node,memdev=mem + +HMP commands + +For hotplugging in multi-process qemu the following commands +can be used: + +- rdevice_add; +- rdevice_del; +- rdrive_add; +- rdrive_del; +- remote_proc_list + +Example: + +qemu-system-x86_64 -enable-kvm -machine q35 -smp 4 -m 4096M -vnc :0 \ +-net nic -net user,hostfwd=tcp::5022-:22 \ +-drive file=/root/ol7.qcow2,format=raw \ +-rdevice lsi53c895a,rid=0,id=scsi0 \ +-object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on \ +-numa node,memdev=mem \ +-monitor stdio + +(qemu) rdrive_add 0 drive0 file=/root/cirros-0.4.0-x86_64-disk.img +(qemu) rdevice_add 0 scsi-hd drive1 drive0 scsi0.0 +(qemu) remote_proc_list + PID RID QEMU ID PROCESS NAME + +00011079 0 drive0 qemu-scsi-dev +00011079 0 drive1 qemu-scsi-dev +00011079 0 0 qemu-scsi-dev + +After running rescan_scsi_bus.sh -a, guest will be able to identify newly +added devices. + + +