From patchwork Thu Oct 24 09:08:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0717F1864 for ; Thu, 24 Oct 2019 09:11:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D0D7A20856 for ; Thu, 24 Oct 2019 09:11:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fQkRH8gM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0D7A20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9H-0007ZR-Ir for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:11:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43495) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ83-0004jS-1o for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ81-0003gR-Gv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:09:58 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ81-0003f7-8T for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:09:57 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94SPd099631; Thu, 24 Oct 2019 09:09:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=dQQbkkMIGKqJhdKyO0Hp9yWGPxltAF46CncL/MUwgNA=; b=fQkRH8gMvp6OFXC7Qo6/Bf9oLCXmvkxmaOQdzpqcZGDIRwR9ceWBv+jHtK0C8tOuP/SV OBRSUO6zaZvrSQIApzABEozMiZHiTaqREImPR8f6SFQGrjcgNGRHA14N6QQJMRKpbIC1 TrCqf22dDJkV82KgWPAVQRlb3QGGIYI8wz7YWjXlBHT5PWG1fQUHfVoE/QE1hVGwyt5p IxoTaGez6LFfISnQvJN8jnAOW4Wut9iYyE5SoZKxQhdwFWPl8vMqwUXtltDX5mWmFG0J pV/A4ViXD72DvOL4VcNKAff81hiLpr/N5dDnhgTpFsUTuj4wAoyCoDEZj1v0wexZjKti nQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2vqteq2abk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:47 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98mqc076119; Thu, 24 Oct 2019 09:09:46 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vtjkj2vg0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:46 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O99iwO022777; Thu, 24 Oct 2019 09:09:44 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:44 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 01/49] multi-process: memory: alloc RAM from file at offset Date: Thu, 24 Oct 2019 05:08:42 -0400 Message-Id: <3a9508f6dd5a89d731cb105a36fd3624d4b97b48.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 11 +++++++---- include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 3 ++- memory.c | 2 +- util/mmap-alloc.c | 7 ++++--- util/oslib-posix.c | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/exec.c b/exec.c index fb0943c..08c4181 100644 --- a/exec.c +++ b/exec.c @@ -1871,6 +1871,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { MachineState *ms = MACHINE(qdev_get_machine()); @@ -1922,7 +1923,8 @@ static void *file_ram_alloc(RAMBlock *block, } area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED, block->flags & RAM_PMEM); + block->flags & RAM_SHARED, block->flags & RAM_PMEM, + offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2309,7 +2311,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) #ifdef CONFIG_POSIX RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp) + off_t offset, Error **errp) { RAMBlock *new_block; Error *local_err = NULL; @@ -2354,7 +2356,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, new_block->used_length = size; new_block->max_length = size; new_block->flags = ram_flags; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, + errp); if (!new_block->host) { g_free(new_block); return NULL; @@ -2384,7 +2387,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index ad158bb..92134c0 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -159,7 +159,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp); + off_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index e786266..4f57985 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -25,7 +25,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, - bool is_pmem); + bool is_pmem, + off_t start); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/memory.c b/memory.c index c952eab..c25c74f 100644 --- a/memory.c +++ b/memory.c @@ -1602,7 +1602,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, 0, &err); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; if (err) { mr->size = int128_zero(); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index f7f177d..4b727bd 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -86,7 +86,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, - bool is_pmem) + bool is_pmem, + off_t start) { int flags; int map_sync_flags = 0; @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags | map_sync_flags, fd, 0); + flags | map_sync_flags, fd, start); if (ptr == MAP_FAILED && map_sync_flags) { if (errno == ENOTSUP) { @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, * we will remove these flags to handle compatibility. */ ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags, fd, 0); + flags, fd, start); } if (ptr == MAP_FAILED) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index f869338..bdfcdcf 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -205,7 +205,7 @@ void *qemu_memalign(size_t alignment, size_t size) void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); if (ptr == MAP_FAILED) { return NULL; From patchwork Thu Oct 24 09:08:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02CC814ED for ; Thu, 24 Oct 2019 09:15:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD3922166E for ; Thu, 24 Oct 2019 09:15:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pK+ITB7e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD3922166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZD0-0001rY-GF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43527) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ85-0004mf-8B for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ83-0003hw-2f for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ82-0003hA-RE for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:09:59 -0400 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 x9O94MJ0094923; Thu, 24 Oct 2019 09:09:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=MYE2nymoKiYp0sfsojEY79ZLbOlWj9NB3Uyfu9k9dmo=; b=pK+ITB7eGsWu9p+XkGy6Cm5tuxfXN+E4m7yuyIv5H58DNHifbqeZvjrXz3JT6EYC7h7l SgEms5ONW7yD14gamtFsSvASPo46+aRvropatkAEidUuLlUC0FuwQXzwbW96Xz4tqcpU ld7CqGhWKKStiytgxVvjZmettrKjoVd6vBUqOP/jflgGWsrJvnT6F5ZfiWqCCZCs/+L7 c60KDnO6PdjzwwmeVKNDZD9rNdfZSPjL+de9NdAOS12RP5iCGGJjgBEw0P338TbmJRZ0 WVrUpgCYdKgeI0q3UeGapGdM1OjaFV4cxtxk0Xs2OSnM5x5lF4RuNv6Aq4SWRzxJtuly fQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r24jt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:51 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Mf3047167; Thu, 24 Oct 2019 09:09:50 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2vu0fnu5xg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:50 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O99lZp008747; Thu, 24 Oct 2019 09:09:47 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:47 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 02/49] multi-process: util: Add qemu_thread_cancel() to cancel running thread Date: Thu, 24 Oct 2019 05:08:43 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 047db03..fe7fa5a 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -175,6 +175,7 @@ void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), void *arg, int mode); void *qemu_thread_join(QemuThread *thread); +void qemu_thread_cancel(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); bool qemu_thread_is_self(QemuThread *thread); void qemu_thread_exit(void *retval); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 838980a..2fd85ed 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -590,3 +590,13 @@ void *qemu_thread_join(QemuThread *thread) } return ret; } + +void qemu_thread_cancel(QemuThread *thread) +{ + int err; + + err = pthread_cancel(thread->thread); + if (err) { + error_exit(err, __func__); + } +} From patchwork Thu Oct 24 09:08:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1A85E14ED for ; Thu, 24 Oct 2019 09:11:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E4A9F20856 for ; Thu, 24 Oct 2019 09:11:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="FonJNxvz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4A9F20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9K-0007em-DB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:11:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43499) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ83-0004ja-1s for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ81-0003gs-SR for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:09:58 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:44682) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ81-0003g0-Kv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:09:57 -0400 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 x9O94MlK116305; Thu, 24 Oct 2019 09:09:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=T3mfHAj9+HL3xKXNgTXtFXhOJtn0MsOFyDfMHjSkdBA=; b=FonJNxvzL2C/NAPOsAjsxjW+2KPo/VFnT2q07FFh9oGH13ByetO9ZBUPN/PYZuMSBuM3 ncx9ln83vn39UrGqLgRloE155h7j4TF8bLVkXnxRn/cGLAf5kT+kgSouuxLcSzkckgOh 7takQHlbUI8WJ6J18TzAI7sLE4gFslgiPQiws6eVsMq/xHwUXjrYa+FLSZCGwTpTXHhU LZoUcJEtL1JT05SZx1yy+aI8V+JHrQspkPTQDkU83e2Ej4HHkP0NAbzHfKeajeGQPTce avnqqCBPBVCJPfDGNuBZy2jAy2Ro+RmUV4yhNxVHH3One7IXruCTs4OJvyhREnhqwma2 OA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vqswttdvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:52 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jao170543; Thu, 24 Oct 2019 09:09:51 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2vtsk484gc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:51 +0000 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 x9O99oFj001641; Thu, 24 Oct 2019 09:09:50 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:50 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 03/49] multi-process: add a command line option for debug file Date: Thu, 24 Oct 2019 05:08:44 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Stefan Hajnoczi --- 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 1d1b33f..78e3e82 100644 --- a/util/log.c +++ b/util/log.c @@ -273,6 +273,8 @@ const QEMULogItem qemu_log_items[] = { { CPU_LOG_TB_NOCHAIN, "nochain", "do not chain compiled TBs so that \"exec\" and \"cpu\" show\n" "complete traces" }, + { LOG_REMOTE_DEBUG, "rdebug", + "log remote debug" }, { 0, NULL, NULL }, }; From patchwork Thu Oct 24 09:08:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E139C14ED for ; Thu, 24 Oct 2019 09:14:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A73C920856 for ; Thu, 24 Oct 2019 09:14:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="M3/0OtyP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A73C920856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZCj-00018B-Av for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43564) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ88-0004v2-Nv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ86-0003kP-SX for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:04 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ86-0003jg-MU for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:02 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94ooY100039; Thu, 24 Oct 2019 09:09:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=WvBi4mcTucarrJC3mEUiNqJBXEVPDzCZQ0Lwyocd0PQ=; b=M3/0OtyPr/wKwVb30/EVXB9usKlZK1asaSi0mQ7P4Ti6CAHLJRmwKFpMNAqaqFIWafFA b8TXMPiyr2Grk7hEORJQ6lscmAkcmcTi+TaSsWcHLmXd6mJq/k7uQ8nE9Aeqx6dhxiBx OfRxZVGziFaaCJcT+uhWnzmj4HzSED9QwKfwgxw5YwLm9N4pCfuOJ30XDkmKTwFuTaK3 1oHbnLfG83CeEaJwS2wc7yniLbqRNaAuFf4BX7H9+y6LfFnEpz5Phx2hcmAav9PtlGdd Feh0eTC4SNurtK9rFtn0I6CjCUqPKRuD5DM+694l4jWuuCAooohHW6YVbVDYbqio5hQP 9g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2vqteq2ac9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:57 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98nq0076212; Thu, 24 Oct 2019 09:09:56 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2vtjkj2vrd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:56 +0000 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 x9O99sgN011422; Thu, 24 Oct 2019 09:09:54 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:53 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 04/49] multi-process: Add stub functions to facilate build of multi-process Date: Thu, 24 Oct 2019 05:08:45 -0400 Message-Id: <47d48853e305377e04143c4623f23299b448b666.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 96 +++++++++++++++++++++++++++++++++++++++++++++++ stubs/audio.c | 12 ++++++ stubs/machine-init-done.c | 4 ++ stubs/monitor.c | 41 ++++++++++++++++++++ stubs/net-stub.c | 31 +++++++++++++++ stubs/replay.c | 14 +++++++ stubs/vl-stub.c | 79 ++++++++++++++++++++++++++++++++++++++ stubs/vmstate.c | 20 ++++++++++ stubs/xen-mapcache.c | 22 +++++++++++ 10 files changed, 324 insertions(+) create mode 100644 stubs/audio.c create mode 100644 stubs/net-stub.c create mode 100644 stubs/vl-stub.c create mode 100644 stubs/xen-mapcache.c diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 6feb66e..f129dfb 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -31,6 +31,7 @@ bool kvm_allowed; bool kvm_readonly_mem_allowed; bool kvm_ioeventfd_any_length_allowed; bool kvm_msi_use_devid; +bool kvm_halt_in_kernel_allowed; int kvm_destroy_vcpu(CPUState *cpu) { @@ -58,6 +59,10 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu) { } +void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu) +{ +} + int kvm_cpu_exec(CPUState *cpu) { abort(); diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index e2d23ed..9b55fb0 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -15,11 +15,107 @@ #include "cpu.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "translate-all.h" +#include "exec/ram_addr.h" + +bool parallel_cpus; void tb_flush(CPUState *cpu) { } +void tb_check_watchpoint(CPUState *cpu, uintptr_t retaddr) +{ +} + +void tb_invalidate_phys_range(ram_addr_t start, ram_addr_t end) +{ +} + +void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end) +{ +} + +void tb_invalidate_phys_page_fast(struct page_collection *pages, + tb_page_addr_t start, int len, + uintptr_t retaddr) +{ +} + +void tlb_init(CPUState *cpu) +{ +} + void tlb_set_dirty(CPUState *cpu, target_ulong vaddr) { } + +void tlb_flush(CPUState *cpu) +{ +} + +void tlb_flush_page(CPUState *cpu, target_ulong addr) +{ +} + +void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length) +{ +} + +void tcg_region_init(void) +{ +} + +void tcg_register_thread(void) +{ +} + +void tcg_flush_softmmu_tlb(CPUState *cs) +{ +} + +void cpu_loop_exit_noexc(CPUState *cpu) +{ + cpu->exception_index = -1; + cpu_loop_exit(cpu); +} + +void cpu_loop_exit(CPUState *cpu) +{ + cpu->can_do_io = 1; + siglongjmp(cpu->jmp_env, 1); +} + +void cpu_reloading_memory_map(void) +{ +} + +int cpu_exec(CPUState *cpu) +{ + return 0; +} + +void cpu_exec_step_atomic(CPUState *cpu) +{ +} + +bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc, bool will_exit) +{ + return false; +} + +void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) +{ + while (1) { + } +} + +struct page_collection * +page_collection_lock(tb_page_addr_t start, tb_page_addr_t end) +{ + return NULL; +} + +void page_collection_unlock(struct page_collection *set) +{ +} diff --git a/stubs/audio.c b/stubs/audio.c new file mode 100644 index 0000000..8ae3b0f --- /dev/null +++ b/stubs/audio.c @@ -0,0 +1,12 @@ +#include "qemu/osdep.h" +#include "audio/audio.h" + +AudioState *audio_state_by_name(const char *name) +{ + return NULL; +} + +const char *audio_get_id(QEMUSoundCard *card) +{ + return NULL; +} diff --git a/stubs/machine-init-done.c b/stubs/machine-init-done.c index cd8e813..3deabc9 100644 --- a/stubs/machine-init-done.c +++ b/stubs/machine-init-done.c @@ -6,3 +6,7 @@ bool machine_init_done = true; void qemu_add_machine_init_done_notifier(Notifier *notify) { } + +void qemu_remove_machine_init_done_notifier(Notifier *notify) +{ +} diff --git a/stubs/monitor.c b/stubs/monitor.c index c3e9a2e..17d2493 100644 --- a/stubs/monitor.c +++ b/stubs/monitor.c @@ -2,9 +2,19 @@ #include "qapi/error.h" #include "qapi/qapi-emit-events.h" #include "monitor/monitor.h" +#include "qapi/qapi-types-misc.h" +#include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-types-qom.h" +#include "qapi/qapi-commands-qdev.h" +#include "hw/qdev-core.h" +#include "sysemu/sysemu.h" +#include "sysemu/runstate.h" +#include "monitor/hmp.h" __thread Monitor *cur_mon; +#pragma weak hmp_handle_error + int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); @@ -27,3 +37,34 @@ void monitor_init_hmp(Chardev *chr, bool use_readline) void qapi_event_emit(QAPIEvent event, QDict *qdict) { } + +int monitor_get_cpu_index(void) +{ + return -ENOSYS; +} +int monitor_printf(Monitor *mon, const char *fmt, ...) +{ + return -ENOSYS; +} + +bool monitor_cur_is_qmp(void) +{ + return false; +} + +ObjectPropertyInfoList *qmp_device_list_properties(const char *typename, + Error **errp) +{ + return NULL; +} + +VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, + VMChangeStateHandler *cb, + void *opaque) +{ + return NULL; +} + +void hmp_handle_error(Monitor *mon, Error **errp) +{ +} 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 10b3925..c0b51cb 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -79,3 +79,17 @@ void replay_mutex_lock(void) void replay_mutex_unlock(void) { } + +bool replay_has_checkpoint(void) +{ + return false; +} + +int replay_get_instructions(void) +{ + return 0; +} + +void replay_account_executed_instructions(void) +{ +} diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c new file mode 100644 index 0000000..fff72be --- /dev/null +++ b/stubs/vl-stub.c @@ -0,0 +1,79 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/uuid.h" +#include "sysemu/sysemu.h" +#include "exec/cpu-common.h" +#include "exec/gdbstub.h" +#include "sysemu/replay.h" +#include "disas/disas.h" +#include "sysemu/runstate.h" + +bool tcg_allowed; +bool xen_allowed; +bool boot_strict; +bool qemu_uuid_set; + +int mem_prealloc; +int smp_cpus; +int vga_interface_type = VGA_NONE; +int smp_cores = 1; +int smp_threads = 1; +int icount_align_option; +int boot_menu; + +unsigned int max_cpus; +const uint32_t arch_type; +const char *mem_path; +uint8_t qemu_extra_params_fw[2]; +uint8_t *boot_splash_filedata; +size_t boot_splash_filedata_size; +struct syminfo *syminfos; + +ram_addr_t ram_size; +MachineState *current_machine; +QemuUUID qemu_uuid; + +int runstate_is_running(void) +{ + return 0; +} + +void runstate_set(RunState new_state) +{ +} + +void vm_state_notify(int running, RunState state) +{ +} + +bool qemu_vmstop_requested(RunState *r) +{ + return false; +} + +void qemu_system_debug_request(void) +{ +} + +char *qemu_find_file(int type, const char *name) +{ + return NULL; +} + +void gdb_set_stop_cpu(CPUState *cpu) +{ +} + +void replay_enable_events(void) +{ +} + +void replay_disable_events(void) +{ +} + +#ifdef TARGET_I386 +void x86_cpu_list(void) +{ +} +#endif diff --git a/stubs/vmstate.c b/stubs/vmstate.c index e1e89b8..a9824bc 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -1,8 +1,11 @@ #include "qemu/osdep.h" #include "migration/vmstate.h" +#include "migration/misc.h" const VMStateDescription vmstate_dummy = {}; +const VMStateInfo vmstate_info_timer; + int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, @@ -23,3 +26,20 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { return true; } + +void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_register_ram_global(MemoryRegion *mr) +{ +} + +bool migration_is_idle(void) +{ + return true; +} 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 Oct 24 09:08:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24BBC14ED for ; Thu, 24 Oct 2019 09:11:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF8572166E for ; Thu, 24 Oct 2019 09:11:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="OU8Gt1I2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF8572166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9U-000805-JM for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:11:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43572) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ89-0004wY-Fp for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ88-0003la-B9 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:05 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59148) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ88-0003ky-2E for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:04 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94rfp100053; Thu, 24 Oct 2019 09:09:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=jjY9+P56OTH91kPMrXn1P1IGxpR4BvnuLCD4lgkyjL0=; b=OU8Gt1I2X3OzIZRDzmcexA8Dr8eyF2pYD0CPjspvmOwnV3cikneP85DOP0fwPEYhPzrU 1J7WB+Jd/YR7FxIAMbXNZPNrb+qYAllfSsH8xVU9BB1FULSvYP4dpocbgEf7ruWCc6Is o/X9XMgNJc5kktxcGN6JzE0BQJybjoCGXQZHGl93IxcIBYRU/UKu5IokrxXLzUvjQfwY ngGIe78ggsVWHp57oZCNSVoTMbLNGH8E6oKm2wB73o/81iq1F1mIyo+WZXyOS7X8ML63 7JRyJQEHzjJ5e1X3Ganza05FJFnIowxlyyJxoCpI/Vxam9uVFLHYqNlbmM+KtLHGc5Qt bg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2vqteq2acd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O981nF093098; Thu, 24 Oct 2019 09:09:58 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2vtm244fbm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:09:58 +0000 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 x9O99v4I001673; Thu, 24 Oct 2019 09:09:57 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:56 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 05/49] multi-process: Add config option for multi-process QEMU Date: Thu, 24 Oct 2019 05:08:46 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 145fcab..135afa9 100755 --- a/configure +++ b/configure @@ -498,6 +498,7 @@ libxml2="" debug_mutex="no" libpmem="" default_devices="yes" +mpqemu="no" supported_cpu="no" supported_os="no" @@ -1529,6 +1530,10 @@ for opt do ;; --disable-xkbcommon) xkbcommon=no ;; + --enable-mpqemu) mpqemu=yes + ;; + --disable-mpqemu) mpqemu=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1813,6 +1818,7 @@ disabled with --disable-FEATURE, default is enabled if available: debug-mutex mutex debugging support libpmem libpmem support xkbcommon xkbcommon support + mpqemu multi-process QEMU support NOTE: The object files are built at the place where configure is launched EOF @@ -6439,6 +6445,7 @@ echo "capstone $capstone" echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" +echo "multiprocess QEMU $mpqemu" if test "$supported_cpu" = "no"; then echo @@ -7241,6 +7248,10 @@ if test "$libpmem" = "yes" ; then echo "CONFIG_LIBPMEM=y" >> $config_host_mak fi +if test "$mpqemu" = "yes" ; then + echo "CONFIG_MPQEMU=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi From patchwork Thu Oct 24 09:08:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC82314E5 for ; Thu, 24 Oct 2019 09:14:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A181420856 for ; Thu, 24 Oct 2019 09:14:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Rq7eSZnf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A181420856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZCq-0001So-9I for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:14:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43592) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8D-00054L-4M for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8A-0003nN-T6 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:08 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8A-0003mr-L6 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:06 -0400 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 x9O94LIE094836; Thu, 24 Oct 2019 09:10:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=djhRt41UYigUdh6RTBGKKZ8WWVHBf3mQ1k4IXTUECqQ=; b=Rq7eSZnfkK3mjNEcQxJ8tnmS/4auZNnd2qFKUVYCxqYpJvWT7ZdOWPC8931psR84BzJB zeofXBVSn8XktLRg8CPozkqnhV7hgIvQZlpXg6pfmsF9qtM1sX2lTYF5ynXdi+McCFN1 6CsgKwhIhDSJXgoczyg+B8fq2WE3lkgI3pfl4IaOsvQAsWDMoDTH2KuQIrbjF1Okbpyu 5t0zlqrjZmvnekfo0yHMm5p5oQSov7wGHIkOsc8cleJTrb5fo/KOwNOJA42EP1lIfenh M1MFhNSrMVRi3C07vh3fxbHYCiM8wAdEvZsQXnbRp0wKsBLOFVxaJ5KswkFPpt4eiS7e jw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r24kg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:01 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Lt5047136; Thu, 24 Oct 2019 09:10:00 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu665-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:00 +0000 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 x9O99x0K001696; Thu, 24 Oct 2019 09:10:00 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:09:59 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 06/49] multi-process: build system for remote device process Date: Thu, 24 Oct 2019 05:08:47 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 2 ++ Makefile.objs | 22 ++++++++++++++++++++ Makefile.target | 53 +++++++++++++++++++++++++++++++++++++++++++++++-- backends/Makefile.objs | 2 ++ block/Makefile.objs | 2 ++ hw/Makefile.objs | 7 +++++++ hw/block/Makefile.objs | 2 ++ hw/core/Makefile.objs | 16 +++++++++++++++ hw/nvram/Makefile.objs | 2 ++ hw/pci/Makefile.objs | 4 ++++ hw/scsi/Makefile.objs | 2 ++ migration/Makefile.objs | 2 ++ qom/Makefile.objs | 3 +++ remote/Makefile.objs | 1 + remote/remote-main.c | 37 ++++++++++++++++++++++++++++++++++ stubs/replay.c | 4 ++++ 16 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 remote/Makefile.objs create mode 100644 remote/remote-main.c diff --git a/Makefile b/Makefile index d20e7ff..c4d5048 100644 --- a/Makefile +++ b/Makefile @@ -437,6 +437,8 @@ dummy := $(call unnest-vars,, \ qom-obj-y \ io-obj-y \ common-obj-y \ + remote-pci-obj-y \ + remote-lsi-obj-y \ common-obj-m \ ui-obj-y \ ui-obj-m \ diff --git a/Makefile.objs b/Makefile.objs index abcbd89..c2ac261 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -21,6 +21,28 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ +######################################################### +# remote-pci-obj-y is common code used by remote devices + +remote-pci-obj-$(CONFIG_MPQEMU) += hw/ +remote-pci-obj-$(CONFIG_MPQEMU) += qom/ +remote-pci-obj-$(CONFIG_MPQEMU) += backends/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += migration/ +remote-pci-obj-$(CONFIG_MPQEMU) += remote/ + +remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o +remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o +remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o +remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o + +############################################################## +# remote-lsi-obj-y is code used to implement remote LSI device + +remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ + ####################################################################### # crypto-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index 5e91623..e454aae 100644 --- a/Makefile.target +++ b/Makefile.target @@ -36,7 +36,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= config-target.h: config-target.h-timestamp @@ -119,6 +124,18 @@ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o LIBS := $(libs_cpu) $(LIBS) +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/tcg-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o + ######################################################### # Linux user emulator target @@ -175,6 +192,17 @@ 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 += ioport.o +all-remote-pci-obj-y += cpus.o + +remote-pci-obj-y := +remote-lsi-obj-y := + include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,.., \ authz-obj-y \ @@ -186,7 +214,10 @@ dummy := $(call unnest-vars,.., \ qom-obj-y \ io-obj-y \ common-obj-y \ - common-obj-m) + common-obj-m \ + remote-pci-obj-y \ + remote-lsi-obj-y) + all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) @@ -195,8 +226,19 @@ all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) +all-remote-pci-obj-y += $(authz-obj-y) +all-remote-pci-obj-y += $(block-obj-y) +all-remote-pci-obj-y += $(crypto-obj-y) +all-remote-pci-obj-y += $(io-obj-y) +all-remote-pci-obj-y += $(chardev-obj-y) +all-remote-pci-obj-y += $(remote-pci-obj-y) + + +all-remote-lsi-obj-y += $(all-remote-pci-obj-y) $(remote-lsi-obj-y) + ifdef CONFIG_SOFTMMU $(QEMU_PROG_BUILD): config-devices.mak +$(SCSI_DEV_BUILD): config-devices.mak endif COMMON_LDADDS = ../libqemuutil.a @@ -209,6 +251,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 f069111..bd52cbc 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -17,3 +17,5 @@ endif common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO)) += vhost-user.o common-obj-$(CONFIG_LINUX) += hostmem-memfd.o + +remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o diff --git a/block/Makefile.objs b/block/Makefile.objs index e394fe0..adcc1b0 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -67,3 +67,5 @@ qcow.o-libs := -lz linux-aio.o-libs := -laio parallels.o-cflags := $(LIBXML2_CFLAGS) parallels.o-libs := $(LIBXML2_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += stream.o diff --git a/hw/Makefile.objs b/hw/Makefile.objs index ece6cc3..4e28053 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -43,3 +43,10 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) + +remote-pci-obj-$(CONFIG_MPQEMU) += core/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += pci/ +remote-pci-obj-$(CONFIG_MPQEMU) += nvram/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/ diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs index f5f643f..7286fbd 100644 --- a/hw/block/Makefile.objs +++ b/hw/block/Makefile.objs @@ -15,3 +15,5 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o obj-y += dataplane/ + +remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index fd0550d..9ef6b42 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -28,3 +28,19 @@ common-obj-$(CONFIG_SOFTMMU) += null-machine.o obj-$(CONFIG_SOFTMMU) += machine-qmp-cmds.o obj-$(CONFIG_SOFTMMU) += numa.o common-obj-$(CONFIG_SOFTMMU) += machine-hmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += bus.o +remote-pci-obj-$(CONFIG_MPQEMU) += irq.o +remote-pci-obj-$(CONFIG_MPQEMU) += hotplug.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine.o +remote-pci-obj-$(CONFIG_MPQEMU) += fw-path-provider.o +remote-pci-obj-$(CONFIG_MPQEMU) += reset.o +remote-pci-obj-$(CONFIG_MPQEMU) += sysbus.o +remote-pci-obj-$(CONFIG_MPQEMU) += loader.o +remote-pci-obj-$(CONFIG_MPQEMU) += nmi.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o +remote-pci-obj-$(CONFIG_MPQEMU) += numa.o +remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o 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 c78f2fb..955be54 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -12,3 +12,7 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o + +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o +remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs index 54b36ed..ef97770 100644 --- a/hw/scsi/Makefile.objs +++ b/hw/scsi/Makefile.objs @@ -13,3 +13,5 @@ obj-y += virtio-scsi.o virtio-scsi-dataplane.o obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-common.o vhost-scsi.o obj-$(CONFIG_VHOST_USER_SCSI) += vhost-scsi-common.o vhost-user-scsi.o endif + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi-generic.o scsi-bus.o lsi53c895a.o scsi-disk.o emulation.o diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 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 f9d7735..07e50e5 100644 --- a/qom/Makefile.objs +++ b/qom/Makefile.objs @@ -2,3 +2,6 @@ qom-obj-y = object.o container.o qom-qobject.o qom-obj-y += object_interfaces.o common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o +remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o diff --git a/remote/Makefile.objs b/remote/Makefile.objs new file mode 100644 index 0000000..a9b2256 --- /dev/null +++ b/remote/Makefile.objs @@ -0,0 +1 @@ +remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o diff --git a/remote/remote-main.c b/remote/remote-main.c new file mode 100644 index 0000000..cccad12 --- /dev/null +++ b/remote/remote-main.c @@ -0,0 +1,37 @@ +/* + * Remote device initialization + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include + +#include "qemu/module.h" + +int main(int argc, char *argv[]) +{ + module_call_init(MODULE_INIT_QOM); + + return 0; +} diff --git a/stubs/replay.c b/stubs/replay.c index c0b51cb..4a966ff 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -93,3 +93,7 @@ int replay_get_instructions(void) void replay_account_executed_instructions(void) { } + +void replay_add_blocker(Error *reason) +{ +} From patchwork Thu Oct 24 09:08:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208705 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B2AA112C for ; Thu, 24 Oct 2019 09:40:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4133020684 for ; Thu, 24 Oct 2019 09:40:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AS3kPjkg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4133020684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZbB-0002N0-VY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:40:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44312) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAG-0001Si-5d for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAE-0005BE-2q for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:16 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAD-0005Ag-QD for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:14 -0400 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 x9O94Md7094848; Thu, 24 Oct 2019 09:12:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=F/E41FhsIR2e21OD7DpZqakoxt8Wz7+Qliiw0Bdlxt4=; b=AS3kPjkgooLHwUyNncGazR/qm0hKD+BlEiL/1IN5RKzdPOeusv4yXrnp+UvdoRgoFHUx G3ZBGPDO+2U8jA+AznlEByFQFSTrn2zWF0TgTb2UhM3ullmfg018hg47zE9d5jIGzsMP 4v1DP/rK4axJzJ4BYicZduWNIOPvKUlIAewThWgiVbfIJgVRtAYOKkiyXAfiPmRzddiR VbGxwgD2YAqjB+Xe8L8BAbREfKrya9CsY+YdcMjE5WYWn1WLB3UX2+llp9cLCpvYwi66 EH5WNURHtqEVlRGHgfOXWKzGdiexFMTBeEumR1Q5gF5ff8oU1z5x+x4oSW/rLfr6+b27 YA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2vqu4r24ue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:07 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97j18170537; Thu, 24 Oct 2019 09:10:06 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2vtsk4857y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:06 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9A4Jk008991; Thu, 24 Oct 2019 09:10:04 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:04 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 07/49] multi-process: define mpqemu-link object Date: Thu, 24 Oct 2019 05:08:48 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Defines mpqemu-link object which forms the communication link between QEMU & emulation program. Adds functions to configure members of mpqemu-link object instance. Adds functions to send and receive messages over the communication channel. Adds GMainLoop to handle events received on the communication channel. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- v1 -> v2: - Use default context for main loop instead of a new context v2 -> v3: - Enabled multi-channel support in the communication link v3 -> v4: - Change the name of proxy-link to mpqemu-link - Use separate locks for sending and receiving messages include/io/mpqemu-link.h | 150 +++++++++++++++++++++++ io/Makefile.objs | 2 + io/mpqemu-link.c | 309 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 461 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h new file mode 100644 index 0000000..345c67e --- /dev/null +++ b/include/io/mpqemu-link.h @@ -0,0 +1,150 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#include +#include + +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK(obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** + * mpqemu_cmd_t: + * CONF_READ PCI config. space read + * CONF_WRITE PCI config. space write + * + * proc_cmd_t enum type to specify the command to be executed on the remote + * device. + */ +typedef enum { + INIT = 0, + CONF_READ, + CONF_WRITE, + MAX, +} mpqemu_cmd_t; + +/** + * MPQemuMsg: + * @cmd: The remote command + * @bytestream: Indicates if the data to be shared is structured (data1) + * or unstructured (data2) + * @size: Size of the data to be shared + * @data1: Structured data + * @fds: File descriptors to be shared with remote device + * @data2: Unstructured data + * + * MPQemuMsg Format of the message sent to the remote device from QEMU. + * + */ +typedef struct { + mpqemu_cmd_t cmd; + int bytestream; + size_t size; + + union { + uint64_t u64; + } data1; + + int fds[REMOTE_MAX_FDS]; + int num_fds; + + uint8_t *data2; +} MPQemuMsg; + +struct conf_data_msg { + uint32_t addr; + uint32_t val; + int l; +}; + +/** + * MPQemuChannel: + * @gsrc: GSource object to be used by loop + * @gpfd: GPollFD object containing the socket & events to monitor + * @sock: Socket to send/receive communication, same as the one in gpfd + * @send_lock: Mutex to synchronize access to the send stream + * @recv_lock: Mutex to synchronize access to the recv stream + * + * Defines the channel that make up the communication link + * between QEMU and remote process + */ + +typedef struct MPQemuChannel { + GSource gsrc; + GPollFD gpfd; + int sock; + QemuMutex send_lock; + QemuMutex recv_lock; +} MPQemuChannel; + +typedef void (*mpqemu_link_callback)(GIOCondition cond, MPQemuChannel *chan); + +/* + * MPQemuLinkState Instance info. of the communication + * link between QEMU and remote process. The Link could + * be made up of multiple channels. + * + * ctx GMainContext to be used for communication + * loop Main loop that would be used to poll for incoming data + * com Communication channel to transport control messages + * + */ + +typedef struct MPQemuLinkState { + Object obj; + + GMainContext *ctx; + GMainLoop *loop; + + MPQemuChannel *com; + + mpqemu_link_callback callback; +} MPQemuLinkState; + +MPQemuLinkState *mpqemu_link_create(void); +void mpqemu_link_finalize(MPQemuLinkState *s); + +void mpqemu_msg_send(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan); +int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan); + +void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd); +void mpqemu_destroy_channel(MPQemuChannel *chan); +void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback); +void mpqemu_start_coms(MPQemuLinkState *s); + +#endif diff --git a/io/Makefile.objs b/io/Makefile.objs index 9a20fce..5875ab0 100644 --- a/io/Makefile.objs +++ b/io/Makefile.objs @@ -10,3 +10,5 @@ io-obj-y += channel-util.o io-obj-y += dns-resolver.o io-obj-y += net-listener.o io-obj-y += task.o + +io-obj-$(CONFIG_MPQEMU) += mpqemu-link.o diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c new file mode 100644 index 0000000..b39f4d0 --- /dev/null +++ b/io/mpqemu-link.c @@ -0,0 +1,309 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/module.h" +#include "io/mpqemu-link.h" +#include "qemu/log.h" + +GSourceFuncs gsrc_funcs; + +static void mpqemu_link_inst_init(Object *obj) +{ + MPQemuLinkState *s = MPQEMU_LINK(obj); + + s->ctx = g_main_context_default(); + s->loop = g_main_loop_new(s->ctx, FALSE); +} + +static const TypeInfo mpqemu_link_info = { + .name = TYPE_MPQEMU_LINK, + .parent = TYPE_OBJECT, + .instance_size = sizeof(MPQemuLinkState), + .instance_init = mpqemu_link_inst_init, +}; + +static void mpqemu_link_register_types(void) +{ + type_register_static(&mpqemu_link_info); +} + +type_init(mpqemu_link_register_types) + +MPQemuLinkState *mpqemu_link_create(void) +{ + return MPQEMU_LINK(object_new(TYPE_MPQEMU_LINK)); +} + +void mpqemu_link_finalize(MPQemuLinkState *s) +{ + g_main_loop_unref(s->loop); + g_main_context_unref(s->ctx); + g_main_loop_quit(s->loop); + + mpqemu_destroy_channel(s->com); + + object_unref(OBJECT(s)); +} + +void mpqemu_msg_send(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan) +{ + int rc; + uint8_t *data; + union { + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr hdr; + struct cmsghdr *chdr; + int sock = chan->sock; + QemuMutex *lock = &chan->send_lock; + + struct iovec iov = { + .iov_base = (char *) msg, + .iov_len = MPQEMU_MSG_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(&u, 0, sizeof(u)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + + if (msg->num_fds > REMOTE_MAX_FDS) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__); + return; + } + + if (msg->num_fds > 0) { + size_t fdsize = msg->num_fds * sizeof(int); + + hdr.msg_control = &u; + hdr.msg_controllen = sizeof(u); + + chdr = CMSG_FIRSTHDR(&hdr); + chdr->cmsg_len = CMSG_LEN(fdsize); + chdr->cmsg_level = SOL_SOCKET; + chdr->cmsg_type = SCM_RIGHTS; + memcpy(CMSG_DATA(chdr), msg->fds, fdsize); + hdr.msg_controllen = CMSG_SPACE(fdsize); + } + + qemu_mutex_lock(lock); + + do { + rc = sendmsg(sock, &hdr, 0); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + + if (rc < 0) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s - sendmsg rc is %d, errno is %d," + " sock %d\n", __func__, rc, errno, sock); + qemu_mutex_unlock(lock); + return; + } + + if (msg->bytestream) { + data = msg->data2; + } else { + data = (uint8_t *)msg + MPQEMU_MSG_HDR_SIZE; + } + + do { + rc = write(sock, data, msg->size); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + + qemu_mutex_unlock(lock); +} + + +int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan) +{ + int rc; + uint8_t *data; + union { + char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr hdr; + struct cmsghdr *chdr; + size_t fdsize; + int sock = chan->sock; + QemuMutex *lock = &chan->recv_lock; + + struct iovec iov = { + .iov_base = (char *) msg, + .iov_len = MPQEMU_MSG_HDR_SIZE, + }; + + memset(&hdr, 0, sizeof(hdr)); + memset(&u, 0, sizeof(u)); + + hdr.msg_iov = &iov; + hdr.msg_iovlen = 1; + hdr.msg_control = &u; + hdr.msg_controllen = sizeof(u); + + qemu_mutex_lock(lock); + + do { + rc = recvmsg(sock, &hdr, 0); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + + if (rc < 0) { + qemu_log_mask(LOG_REMOTE_DEBUG, "%s - recvmsg rc is %d, errno is %d," + " sock %d\n", __func__, rc, errno, sock); + qemu_mutex_unlock(lock); + return rc; + } + + msg->num_fds = 0; + for (chdr = CMSG_FIRSTHDR(&hdr); chdr != NULL; + chdr = CMSG_NXTHDR(&hdr, chdr)) { + if ((chdr->cmsg_level == SOL_SOCKET) && + (chdr->cmsg_type == SCM_RIGHTS)) { + fdsize = chdr->cmsg_len - CMSG_LEN(0); + msg->num_fds = fdsize / sizeof(int); + if (msg->num_fds > REMOTE_MAX_FDS) { + /* + * TODO: Security issue detected. Sender never sends more + * than REMOTE_MAX_FDS. This condition should be signaled to + * the admin + */ + qemu_log_mask(LOG_REMOTE_DEBUG, "%s: Max FDs exceeded\n", __func__); + return -ERANGE; + } + + memcpy(msg->fds, CMSG_DATA(chdr), fdsize); + break; + } + } + + if (msg->size && msg->bytestream) { + msg->data2 = calloc(1, msg->size); + data = msg->data2; + } else { + data = (uint8_t *)&msg->data1; + } + + if (msg->size) { + do { + rc = read(sock, data, msg->size); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + } + + qemu_mutex_unlock(lock); + + return rc; +} + +static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) +{ + g_assert(timeout); + + *timeout = -1; + + return FALSE; +} + +static gboolean mpqemu_link_handler_check(GSource *gsrc) +{ + MPQemuChannel *chan = (MPQemuChannel *)gsrc; + + return chan->gpfd.events & chan->gpfd.revents; +} + +static gboolean mpqemu_link_handler_dispatch(GSource *gsrc, GSourceFunc func, + gpointer data) +{ + MPQemuLinkState *s = (MPQemuLinkState *)data; + MPQemuChannel *chan = (MPQemuChannel *)gsrc; + + s->callback(chan->gpfd.revents, chan); + + if ((chan->gpfd.revents & G_IO_HUP) || (chan->gpfd.revents & G_IO_ERR)) { + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback) +{ + s->callback = callback; +} + +void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd) +{ + MPQemuChannel *src; + + gsrc_funcs = (GSourceFuncs){ + .prepare = mpqemu_link_handler_prepare, + .check = mpqemu_link_handler_check, + .dispatch = mpqemu_link_handler_dispatch, + .finalize = NULL, + }; + + src = (MPQemuChannel *)g_source_new(&gsrc_funcs, sizeof(MPQemuChannel)); + + src->sock = fd; + qemu_mutex_init(&src->send_lock); + qemu_mutex_init(&src->recv_lock); + + g_source_set_callback(&src->gsrc, NULL, (gpointer)s, NULL); + src->gpfd.fd = fd; + src->gpfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR; + g_source_add_poll(&src->gsrc, &src->gpfd); + + *chan = src; +} + +void mpqemu_destroy_channel(MPQemuChannel *chan) +{ + g_source_unref(&chan->gsrc); + close(chan->sock); + qemu_mutex_destroy(&chan->send_lock); + qemu_mutex_destroy(&chan->recv_lock); +} + +void mpqemu_start_coms(MPQemuLinkState *s) +{ + + g_assert(g_source_attach(&s->com->gsrc, s->ctx)); + + g_main_loop_run(s->loop); +} From patchwork Thu Oct 24 09:08:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208713 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAE81112C for ; Thu, 24 Oct 2019 09:40:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7DC9721872 for ; Thu, 24 Oct 2019 09:40:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dzKhPrwb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DC9721872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZbp-00042W-9i for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:40:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44315) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAG-0001Te-KQ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAF-0005C7-C6 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:16 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:46804) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAF-0005BT-4M for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:15 -0400 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 x9O94Pfb116363; Thu, 24 Oct 2019 09:12:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=btour2UNUU7CDnNRKI6AE+S8OUCK/eeLSqRjU36nKl8=; b=dzKhPrwb9dtZda7tj96620UuOifJO9LUzWJp0slqY9T0HDXZC6XMmsGZeKpbNchLMvx7 RqEcLaO0hKhNlJFQnpqekOY4n1JFJYNe+ryrBtZAywTSMz/0l1oPj41swqtQG4yUjc2E xaNg0kxzdeNUKvBfWFHQzgbhyDPpw+g2Ayocp9vaYlkI+Jt0KaWYE50KWZnOkJclMWM4 RyVGZSSP17kuP/yhi4arNR9ZFgNH9V6dz/tCfJRokKNINqj0qBXKE67YUiSG4NXN4kZ9 tkho7Zq8x47ehjSalohik3QXRXxjoyyS280YjObttGS38YM5UWPo39rZeFljcqGBV4a8 vg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2vqswtte5n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:09 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O982R1093173; Thu, 24 Oct 2019 09:10:08 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2vtm244fsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:07 +0000 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 x9O9A7Bh001853; Thu, 24 Oct 2019 09:10:07 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:06 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 08/49] multi-process: add functions to synchronize proxy and remote endpoints Date: Thu, 24 Oct 2019 05:08:49 -0400 Message-Id: <823727c8cf4bbc563cecebd6a231bea77d81adeb.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v1 -> v2: - Added timeout to synchronization functions include/io/mpqemu-link.h | 9 +++++++++ io/mpqemu-link.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 345c67e..dee2dd3 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -30,7 +30,9 @@ #include #include +#include #include +#include #include "qom/object.h" #include "qemu/thread.h" @@ -147,4 +149,11 @@ void mpqemu_destroy_channel(MPQemuChannel *chan); void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback); void mpqemu_start_coms(MPQemuLinkState *s); +#define GET_REMOTE_WAIT eventfd(0, 0) +#define PUT_REMOTE_WAIT(wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + +uint64_t wait_for_remote(int efd); +void notify_proxy(int fd, uint64_t val); + #endif diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index b39f4d0..696aeb1 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -231,6 +231,46 @@ int mpqemu_msg_recv(MPQemuLinkState *s, MPQemuMsg *msg, MPQemuChannel *chan) return rc; } +uint64_t wait_for_remote(int efd) +{ + struct pollfd pfd = { .fd = efd, .events = POLLIN }; + uint64_t val; + int ret; + + ret = poll(&pfd, 1, 1000); + + switch (ret) { + case 0: + qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: Timed out\n"); + /* TODO: Kick-off error recovery */ + return ULLONG_MAX; + case -1: + qemu_log_mask(LOG_REMOTE_DEBUG, "Poll error wait_for_remote: %s\n", + strerror(errno)); + return ULLONG_MAX; + default: + if (read(efd, &val, sizeof(val)) == -1) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Error wait_for_remote: %s\n", + strerror(errno)); + return ULLONG_MAX; + } + } + + val = (val == ULLONG_MAX) ? val : (val - 1); + + return val; +} + +void notify_proxy(int efd, uint64_t val) +{ + val = (val == ULLONG_MAX) ? val : (val + 1); + + if (write(efd, &val, sizeof(val)) == -1) { + qemu_log_mask(LOG_REMOTE_DEBUG, "Error notify_proxy: %s\n", + strerror(errno)); + } +} + static gboolean mpqemu_link_handler_prepare(GSource *gsrc, gint *timeout) { g_assert(timeout); From patchwork Thu Oct 24 09:08:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8646A1575 for ; Thu, 24 Oct 2019 09:18:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A7FD205F4 for ; Thu, 24 Oct 2019 09:18:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="POX867tI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A7FD205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZFo-0000Py-PH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:18:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43632) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8R-0005mU-JU for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8P-0003vt-Hh for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:23 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8N-0003to-Fw for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:21 -0400 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 x9O94W41116471; Thu, 24 Oct 2019 09:10:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=oTKvfV0Lq4NRImdyTqVejIX9eQAO5e1RcIUXCvxfH9M=; b=POX867tIERsIh8cR7NfU1fdhfINwuCqkcwZkXKd2vkEUr9Q5x2B/9JPE28BpEbXlIXSA ERVBYf8e0oI2SnKtnxPfWuUw4dALjU/vv2KTPzMmFJnNgTmo0uCVfsizFjAkavyrKeW5 Mt6RMdn3nZxC9XULG+2Tnh4Onu3dYEM1vSYe9lHrAcHuF0lHUkNNM/laihYhnBHOqElh bfz/fqLpMAxBkzrAJWLSiRtRNiW3zjUp2OR1dVjIv16aFsJ+0swQQru5FtVL31kBCGyz OtPFv1rKtse5KQctVHLNg4jYQ/AauWwjKh2jPEMRMyhFaViSgGk4iYdZt5alj3oXcDqb IA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vqswttdx4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:13 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98ndQ076254; Thu, 24 Oct 2019 09:10:13 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2vtjkj2wdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:13 +0000 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 x9O9AAKP011533; Thu, 24 Oct 2019 09:10:10 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:09 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 09/49] multi-process: setup PCI host bridge for remote device Date: Thu, 24 Oct 2019 05:08:50 -0400 Message-Id: <21b8d0f06279f177f2daca8779ced48af14139ee.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 59 +++++++++++++++++++++++++++++++++ remote/Makefile.objs | 1 + remote/pcihost.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 include/remote/pcihost.h create mode 100644 remote/pcihost.c diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs index 955be54..90693a7 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -13,6 +13,6 @@ common-obj-$(CONFIG_PCI_EXPRESS) += pcie_port.o pcie_host.o common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o common-obj-$(CONFIG_ALL) += pci-stub.o -remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o +remote-pci-obj-$(CONFIG_MPQEMU) += pci.o pci_bridge.o pci_host.o pcie_host.o remote-pci-obj-$(CONFIG_MPQEMU) += msi.o msix.o remote-pci-obj-$(CONFIG_MPQEMU) += pcie.o diff --git a/include/remote/pcihost.h b/include/remote/pcihost.h new file mode 100644 index 0000000..b3c711d --- /dev/null +++ b/include/remote/pcihost.h @@ -0,0 +1,59 @@ +/* + * PCI Host for remote device + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef REMOTE_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..0f43057 --- /dev/null +++ b/remote/pcihost.c @@ -0,0 +1,85 @@ +/* + * Remote PCI host device + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" +#include "hw/pci/pcie_host.h" +#include "hw/qdev-properties.h" +#include "remote/pcihost.h" +#include "exec/memory.h" + +static const char *remote_host_root_bus_path(PCIHostState *host_bridge, + PCIBus *rootbus) +{ + return "0000:00"; +} + +static void remote_host_realize(DeviceState *dev, Error **errp) +{ + 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 Oct 24 09:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9085513B1 for ; Thu, 24 Oct 2019 09:21:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5513D2166E for ; Thu, 24 Oct 2019 09:21:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ZDcfhpQx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5513D2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36531 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZIt-0007H8-Q2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43676) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8Z-000606-5h for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8T-0003yQ-KD for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:31 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45092) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8R-0003vl-Gv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:24 -0400 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 x9O94TXh116427; Thu, 24 Oct 2019 09:10:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=mhpCvWcJlwl10DsVNcwPRXCMYKWhHr6XHVEdICeHCD0=; b=ZDcfhpQxFeKKCLLK8BPKsg7D9Xe53KUS9SB+Q0LTf+rIa5qcn+UQwzSn+6US5OhOhNMo A8MutuOBI/SRjFOJfgrM/Bpfy9zjdhIctRBEnqQ54Ej5oSNCGs+Ldyd6iMe8Hc/aNhme jHNZaroZGZ9dzDY36IoNrDOypusSjNSS/dV/BTflWdNJs7NYfnKteZOEWBCoJndOcB+6 zozHKeE7+CN0heO85S7b8BMc+MCvfge+o1xTeroJm3rpnt9Qiot+tunJximQsqGY5Sfk Mvn4HDZ7AVXPoETczQfHXluGA7bSoem2B6i6Oaar6W1pC3fxk4wEx6EOYF/6B8G8ToKE IQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2vqswttdxc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:16 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98K1e046918; Thu, 24 Oct 2019 09:10:16 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2vu0fnu6mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:16 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9ADNT009092; Thu, 24 Oct 2019 09:10:13 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:13 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 10/49] multi-process: setup a machine object for remote device process Date: Thu, 24 Oct 2019 05:08:51 -0400 Message-Id: <6df05bbf3cba4611b462879a7b937f40486cea0a.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 08c4181..129a8a6 100644 --- a/exec.c +++ b/exec.c @@ -192,7 +192,6 @@ typedef struct subpage_t { #define PHYS_SECTION_UNASSIGNED 0 static void io_mem_init(void); -static void memory_map_init(void); static void tcg_log_global_after_sync(MemoryListener *listener); static void tcg_commit(MemoryListener *listener); @@ -2989,7 +2988,7 @@ static void tcg_commit(MemoryListener *listener) tlb_flush(cpuas->cpu); } -static void memory_map_init(void) +void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); 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..a00732d --- /dev/null +++ b/include/remote/machine.h @@ -0,0 +1,46 @@ +/* + * Remote machine configuration + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef REMOTE_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..4ce197d --- /dev/null +++ b/remote/machine.c @@ -0,0 +1,118 @@ +/* + * Machine for remote device + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#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 cccad12..bf44310 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -28,10 +28,17 @@ #include #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 Oct 24 09:08:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07D371575 for ; Thu, 24 Oct 2019 09:18:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D0B84205F4 for ; Thu, 24 Oct 2019 09:18:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="p1kJjkMA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0B84205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZG4-0001NK-9N for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:18:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43662) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8W-0005tI-4m for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8T-0003yh-SE for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:28 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45142) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8T-0003xF-K5 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:25 -0400 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 x9O94N21116351; Thu, 24 Oct 2019 09:10:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=iyenuviZ+w1tsyev91pwSNK5GV+RaE3aFPM8eBuK4JQ=; b=p1kJjkMA/DNj0N3PDvwnlrYvnYjAyXGYFh9mpjozv+yPrtjByQNil8BfN00vSrAFv0d1 wfI55Vq0QDMnDdPkcEZXYfP+EC+5H2r+nwu5ir6fBBcpcyMVC+GwHvEdWkmu33lvvTkk dTNhq+beLLdAkM22KMG9O0eRKqiIUxk8yhDlSYeMRzMYNTiG4sfAAE+x1anvbzDV+8RT 3jHW0qrIv6J8AyYPrYjCGEVA4CuIVH0vn1Gg4rvCMS6ngjbS7D3wJOGjgab4Cl3g4gI7 lppze3ferVSDTp/eun+QGOtO+VZfs6DkyPCf0uwUZDwmYDKHsVhe1Fi++iBzzsauNj7J 2A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2vqswttdxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:18 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O982j8093151; Thu, 24 Oct 2019 09:10:17 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2vtm244g3d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:17 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9AHR2023250; Thu, 24 Oct 2019 09:10:17 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:16 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 11/49] multi-process: setup memory manager for remote device Date: Thu, 24 Oct 2019 05:08:52 -0400 Message-Id: <5bfab4fa2f7f12137d0030e08a494d9ac3e11f04.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=4 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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/mpqemu-link.h | 11 ++++++ include/remote/memory.h | 34 +++++++++++++++++ remote/memory.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 include/remote/memory.h create mode 100644 remote/memory.c diff --git a/Makefile.target b/Makefile.target index e454aae..547f10e 100644 --- a/Makefile.target +++ b/Makefile.target @@ -136,6 +136,8 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o + ######################################################### # Linux user emulator target diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index dee2dd3..7ef8207 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -36,6 +36,8 @@ #include "qom/object.h" #include "qemu/thread.h" +#include "exec/cpu-common.h" +#include "exec/hwaddr.h" #define TYPE_MPQEMU_LINK "mpqemu-link" #define MPQEMU_LINK(obj) \ @@ -49,6 +51,7 @@ * mpqemu_cmd_t: * CONF_READ PCI config. space read * CONF_WRITE PCI config. space write + * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -57,6 +60,7 @@ typedef enum { INIT = 0, CONF_READ, CONF_WRITE, + SYNC_SYSMEM, MAX, } mpqemu_cmd_t; @@ -74,12 +78,19 @@ typedef enum { * */ typedef struct { + hwaddr gpas[REMOTE_MAX_FDS]; + uint64_t sizes[REMOTE_MAX_FDS]; + ram_addr_t offsets[REMOTE_MAX_FDS]; +} sync_sysmem_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; union { uint64_t u64; + sync_sysmem_msg_t sync_sysmem; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/memory.h b/include/remote/memory.h new file mode 100644 index 0000000..0bb637f --- /dev/null +++ b/include/remote/memory.h @@ -0,0 +1,34 @@ +/* + * Memory manager for remote device + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef REMOTE_MEMORY_H +#define REMOTE_MEMORY_H + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "io/mpqemu-link.h" + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp); + +#endif diff --git a/remote/memory.c b/remote/memory.c new file mode 100644 index 0000000..a70027e --- /dev/null +++ b/remote/memory.c @@ -0,0 +1,99 @@ +/* + * Memory manager for remote device + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#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/mpqemu-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 = NULL; + mr->align = 0; + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, RAM_SHARED, fd, offset, + errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; + + g_free(name); +} + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) +{ + sync_sysmem_msg_t *sysmem_info = &msg->data1.sync_sysmem; + MemoryRegion *sysmem, *subregion, *next; + Error *local_err = NULL; + int region; + + sysmem = get_system_memory(); + + qemu_mutex_lock_iothread(); + + memory_region_transaction_begin(); + + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) { + if (subregion->ram) { + memory_region_del_subregion(sysmem, subregion); + remote_ram_destructor(subregion); + } + } + + 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 Oct 24 09:08:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B55A13B1 for ; Thu, 24 Oct 2019 09:45:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3C5F20684 for ; Thu, 24 Oct 2019 09:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Lo4AQ553" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3C5F20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZgT-0002xe-1J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:45:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44383) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAX-000286-SU for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAW-0005MP-My for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:33 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:33392) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAW-0005Jw-Ee for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:32 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94M1Y099578; Thu, 24 Oct 2019 09:12:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=Xh2odBnS5dKeeUhdClD/GLP4LQ+P8oTji3dSDPB7dIU=; b=Lo4AQ553ozsyLt95cFbKUOwZtQzdfqMu6X6asCC3EaFS7Qh5JG2vFMgTYWo3oGZmSZP0 rhua3whqy50M8LBJzb02LUvaZXwTHhKth//WcBsqHlHcj8+bBH76XLLVZUR5NTFmt0Qb YxAf5MuV3SXZA7TdWhzPCFeBDCTaMA8p4Z5XGtiroC5BNkZcRKDDSi0mTZtAEBbc042h CUCa3IznYtIBSkz/7l76WX/9DpFtUe2vwCmIhtNDLcx26eVueKqeqbXoz85canJTldBs R2ihhMhV7Z8TBse+rQ6rajPmuLANhSa7RpOi/31ZZgP9xAtx0a7l/J29R4IYYNeEtOZl aQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2ant-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:22 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LDH047145; Thu, 24 Oct 2019 09:10:22 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2vu0fnu6r2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:22 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9AKa7009131; Thu, 24 Oct 2019 09:10:20 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:19 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 12/49] multi-process: remote process initialization Date: Thu, 24 Oct 2019 05:08:53 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v1 -> v2: - Separate thread for message processing is removed v2 -> v3: - Added multi-channel support in the remote end remote/remote-main.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index bf44310..7689b57 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -26,6 +26,7 @@ #include "qemu-common.h" #include +#include #include "qemu/module.h" #include "remote/pcihost.h" @@ -33,12 +34,91 @@ #include "hw/boards.h" #include "hw/qdev-core.h" #include "qemu/main-loop.h" +#include "remote/memory.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/main-loop.h" +#include "sysemu/cpus.h" +#include "qemu-common.h" +#include "hw/pci/pci.h" +#include "qemu/thread.h" +#include "qemu/main-loop.h" +#include "qemu/config-file.h" +#include "sysemu/sysemu.h" +#include "block/block.h" + +static MPQemuLinkState *mpqemu_link; +PCIDevice *remote_pci_dev; + +static void process_msg(GIOCondition cond, MPQemuChannel *chan) +{ + MPQemuMsg *msg = NULL; + Error *err = NULL; + + if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) { + error_setg(&err, "socket closed, cond is %d", cond); + goto finalize_loop; + } + + msg = g_malloc0(sizeof(MPQemuMsg)); + + if (mpqemu_msg_recv(mpqemu_link, msg, chan) < 0) { + error_setg(&err, "Failed to receive message"); + goto finalize_loop; + } + + switch (msg->cmd) { + case INIT: + break; + case CONF_WRITE: + break; + case CONF_READ: + break; + default: + error_setg(&err, "Unknown command"); + goto finalize_loop; + } + + g_free(msg); + + return; + +finalize_loop: + error_report_err(err); + g_free(msg); + mpqemu_link_finalize(mpqemu_link); + mpqemu_link = NULL; +} int main(int argc, char *argv[]) { + Error *err = NULL; + module_call_init(MODULE_INIT_QOM); + bdrv_init_with_whitelist(); + + if (qemu_init_main_loop(&err)) { + error_report_err(err); + return -EBUSY; + } + + qemu_init_cpu_loop(); + + page_size_init(); + current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE))); + mpqemu_link = mpqemu_link_create(); + if (!mpqemu_link) { + printf("Could not create MPQemu link\n"); + return -1; + } + + mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO); + mpqemu_link_set_callback(mpqemu_link, process_msg); + + mpqemu_start_coms(mpqemu_link); + return 0; } From patchwork Thu Oct 24 09:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16C831575 for ; Thu, 24 Oct 2019 09:19:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF7DC205F4 for ; Thu, 24 Oct 2019 09:18:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gtjgqDVl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF7DC205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZGk-0002yd-DI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:18:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43692) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8b-00064V-6H for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8Z-00043T-66 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60432) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8Y-00041Y-TU for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:31 -0400 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 x9O94LIG094836; Thu, 24 Oct 2019 09:10:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=qYoZC9x0tbqOjuZQfNS9Uj1BU8a5ImRmaM0qKlTS+cI=; b=gtjgqDVl2cocU7a1jAKvQFpaDx3AedyCGc9nGISXyU54njc5N3VvFOXsylgflMhnDunN xQMHmpfIVH/YGynu1re1nWdfWB2tA6BupFRBlQY1MMi1yQbl2wFpcHM9+GQnZAiINBtR avSXmOd8VYLuT4CpxOdtTXo/W15mV6BWUhJMWJ6q3vskDLxLKvapJYRh1TmdN6X69scR HeneNbqL5VE2DbJhHGpvSdp7NEKsU9Yd5gamcLQV2Jg1KOaJni7cgaWouAivIb5cfhst kXYtknnF5iZe2ifscNgWw4Xy9PhKWg1/Bd5IBmdiUfMVLi/Vh6Yl3kzIAT1cDDhym3Pe Ow== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r24mv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:25 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98L4f047087; Thu, 24 Oct 2019 09:10:24 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu6sv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:24 +0000 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 x9O9AOsS002027; Thu, 24 Oct 2019 09:10:24 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:23 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 13/49] multi-process: introduce proxy object Date: Thu, 24 Oct 2019 05:08:54 -0400 Message-Id: <64276bb78fce32a6ddf4356bf29632af1ef2c785.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 247 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 81 ++++++++++++++ remote/remote-main.c | 28 +++++ 5 files changed, 359 insertions(+) create mode 100644 hw/proxy/Makefile.objs create mode 100644 hw/proxy/qemu-proxy.c create mode 100644 include/hw/proxy/qemu-proxy.h diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 4e28053..e016100 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -44,6 +44,8 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) +common-obj-$(CONFIG_MPQEMU) += proxy/ + remote-pci-obj-$(CONFIG_MPQEMU) += core/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += pci/ 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..baba4da --- /dev/null +++ b/hw/proxy/qemu-proxy.c @@ -0,0 +1,247 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "io/mpqemu-link.h" +#include "exec/memory.h" +#include "exec/cpu-common.h" +#include "exec/address-spaces.h" +#include "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); + +int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) +{ + char *args[3]; + pid_t rpid; + int fd[2] = {-1, -1}; + Error *local_error = NULL; + + if (pdev->managed) { + /* Child is forked by external program (such as libvirt). */ + return -1; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + error_setg(errp, "Unable to create unix socket."); + return -1; + } + /* TODO: Restrict the forked process' permissions and capabilities. */ + rpid = qemu_fork(&local_error); + + if (rpid == -1) { + error_setg(errp, "Unable to spawn emulation program."); + close(fd[0]); + close(fd[1]); + return -1; + } + + if (rpid == 0) { + close(fd[0]); + + args[0] = g_strdup(command); + args[1] = g_strdup_printf("%d", fd[1]); + args[2] = NULL; + execvp(args[0], (char *const *)args); + exit(1); + } + pdev->remote_pid = rpid; + pdev->rsocket = fd[0]; + + close(fd[1]); + + return 0; +} + +static int get_proxy_sock(PCIDevice *dev) +{ + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + return pdev->rsocket; +} + +static void set_proxy_sock(PCIDevice *dev, int socket) +{ + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + pdev->rsocket = socket; + pdev->managed = true; + +} + +static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, + unsigned int op) +{ + MPQemuMsg msg; + struct conf_data_msg conf_data; + int wait; + + memset(&msg, 0, sizeof(MPQemuMsg)); + conf_data.addr = addr; + conf_data.val = (op == CONF_WRITE) ? *val : 0; + conf_data.l = l; + + msg.data2 = (uint8_t *)malloc(sizeof(conf_data)); + if (!msg.data2) { + return -ENOMEM; + } + + memcpy(msg.data2, (const uint8_t *)&conf_data, sizeof(conf_data)); + msg.size = sizeof(conf_data); + 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; + } + + mpqemu_msg_send(dev->mpqemu_link, &msg, dev->mpqemu_link->com); + + if (op == CONF_READ) { + *val = (uint32_t)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } + + 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_proxy(PCIDevice *dev, char *command, Error **errp) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + Error *local_error = NULL; + + if (!pdev->managed) { + if (command) { + remote_spawn(pdev, command, &local_error); + } else { + return; + } + } else { + pdev->remote_pid = atoi(pdev->rid); + if (pdev->remote_pid == -1) { + error_setg(errp, "Remote PID is -1"); + return; + } + } + + pdev->mpqemu_link = mpqemu_link_create(); + + if (!pdev->mpqemu_link) { + error_setg(errp, "Failed to create proxy link"); + return; + } + + mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com, + pdev->socket); +} + +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(device); + PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev); + Error *local_err = NULL; + + if (k->realize) { + k->realize(dev, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + } + + dev->set_proxy_sock = set_proxy_sock; + dev->get_proxy_sock = get_proxy_sock; + dev->init_proxy = init_proxy; +} diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h new file mode 100644 index 0000000..3648a77 --- /dev/null +++ b/include/hw/proxy/qemu-proxy.h @@ -0,0 +1,81 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_PROXY_H +#define QEMU_PROXY_H + +#include "io/mpqemu-link.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV(obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_CLASS(klass) \ + 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; + + MPQemuLinkState *mpqemu_link; + + EventNotifier intr; + EventNotifier resample; + + pid_t remote_pid; + int rsocket; + int socket; + + char *rid; + + bool managed; + char *dev_id; + + QLIST_ENTRY(PCIProxyDev) next; + + void (*set_proxy_sock) (PCIDevice *dev, int socket); + int (*get_proxy_sock) (PCIDevice *dev); + + void (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd); + void (*proxy_ready) (PCIDevice *dev); + void (*init_proxy) (PCIDevice *pdev, char *command, Error **errp); + +} PCIProxyDev; + +typedef struct PCIProxyDevClass { + PCIDeviceClass parent_class; + + void (*realize)(PCIProxyDev *dev, Error **errp); + + char *command; +} PCIProxyDevClass; + +int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp); + + +#endif /* QEMU_PROXY_H */ diff --git a/remote/remote-main.c b/remote/remote-main.c index 7689b57..6c2eb91 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -50,6 +50,32 @@ static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; +static void process_config_write(MPQemuMsg *msg) +{ + struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + + qemu_mutex_lock_iothread(); + pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l); + qemu_mutex_unlock_iothread(); +} + +static void process_config_read(MPQemuMsg *msg) +{ + struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + uint32_t val; + int wait; + + wait = msg->fds[0]; + + qemu_mutex_lock_iothread(); + val = pci_default_read_config(remote_pci_dev, conf->addr, conf->l); + qemu_mutex_unlock_iothread(); + + notify_proxy(wait, val); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -71,8 +97,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case INIT: break; case CONF_WRITE: + process_config_write(msg); break; case CONF_READ: + process_config_read(msg); break; default: error_setg(&err, "Unknown command"); From patchwork Thu Oct 24 09:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC75B1575 for ; Thu, 24 Oct 2019 09:15:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A113E20856 for ; Thu, 24 Oct 2019 09:15:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="J++4Usou" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A113E20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZD0-0001uX-Et for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43709) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8e-0006DO-S2 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8d-00048X-FN for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:36 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60526) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8d-00047v-7G for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:35 -0400 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 x9O94MZF094876; Thu, 24 Oct 2019 09:10:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=1wStxT5X5J/1NrtwJSHlRWHuesG/QCz1a0AXOom2gDI=; b=J++4Usoua3CXQ+NICrhgBgOw6umnGeLxR7+s7HhVEPx6GIdrISRue3TU0aTOQYK53oO5 dKVxmNdSDjlSCZZ4ubpTjtzh3SNGbBU6mCa5sZUyhOG/hZ1A6aIFAUyG1STW23SHTK20 SsO9Hh62LSLk7FV/t49xaNSY06Tf6I0hZ/uSBkLUJ8rSF3FEmIcoaL/stzsR0QMH5tEI opTztVN+MpTTY9OpSdldQ5Du2iA9VEl3+DTKjaBQmTrKrKDsLIrhnksVdYoGp7MPmDar bfMGIbGO9OVJUnKnTZEdJYasdj2Z+lSRIjoBPDSIIP8RWm6kZp/Quk+VO0dHOz3UmPuu Zg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2vqu4r24n7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:30 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O9826M093134; Thu, 24 Oct 2019 09:10:29 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2vtm244gg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:29 +0000 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 x9O9ARXc011763; Thu, 24 Oct 2019 09:10:27 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:26 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 14/49] mutli-process: build remote command line args Date: Thu, 24 Oct 2019 05:08:55 -0400 Message-Id: <8d1ffc03424e664000eb65186bef0362cd1a5fd6.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 hw/proxy/qemu-proxy.c | 80 +++++++++++++++++++++++++++++++++---------- include/hw/proxy/qemu-proxy.h | 2 +- 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index baba4da..ca7dd1a 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -45,47 +45,89 @@ static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); +static int add_argv(char *command_str, char **argv, int argc) +{ + int max_args = 64; + + if (argc < max_args - 1) { + argv[argc++] = command_str; + argv[argc] = 0; + } else { + return 0; + } + + return argc; +} + +static int make_argv(char *command_str, char **argv, int argc) +{ + int max_args = 64; + + char *p2 = strtok(command_str, " "); + while (p2 && argc < max_args - 1) { + argv[argc++] = p2; + p2 = strtok(0, " "); + } + argv[argc] = 0; + + return argc; +} + int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) { - char *args[3]; pid_t rpid; int fd[2] = {-1, -1}; Error *local_error = NULL; + char *argv[64]; + int argc = 0, _argc; + char *sfd; + char *exec_dir; + int rc = -EINVAL; if (pdev->managed) { /* Child is forked by external program (such as libvirt). */ - return -1; + return rc; } if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { error_setg(errp, "Unable to create unix socket."); - return -1; + return rc; } + exec_dir = g_strdup_printf("%s/%s", qemu_get_exec_dir(), "qemu-scsi-dev"); + argc = add_argv(exec_dir, argv, argc); + sfd = g_strdup_printf("%d", fd[1]); + argc = add_argv(sfd, argv, argc); + _argc = argc; + argc = make_argv((char *)command, argv, argc); + /* TODO: Restrict the forked process' permissions and capabilities. */ rpid = qemu_fork(&local_error); if (rpid == -1) { error_setg(errp, "Unable to spawn emulation program."); close(fd[0]); - close(fd[1]); - return -1; + goto fail; } if (rpid == 0) { close(fd[0]); - - args[0] = g_strdup(command); - args[1] = g_strdup_printf("%d", fd[1]); - args[2] = NULL; - execvp(args[0], (char *const *)args); + execvp(argv[0], (char *const *)argv); exit(1); } pdev->remote_pid = rpid; - pdev->rsocket = fd[0]; + pdev->rsocket = fd[1]; + pdev->socket = fd[0]; + rc = 0; + +fail: close(fd[1]); - return 0; + for (int i = 0; i < _argc; i++) { + g_free(argv[i]); + } + + return rc; } static int get_proxy_sock(PCIDevice *dev) @@ -94,7 +136,7 @@ static int get_proxy_sock(PCIDevice *dev) pdev = PCI_PROXY_DEV(dev); - return pdev->rsocket; + return pdev->socket; } static void set_proxy_sock(PCIDevice *dev, int socket) @@ -103,7 +145,7 @@ static void set_proxy_sock(PCIDevice *dev, int socket) pdev = PCI_PROXY_DEV(dev); - pdev->rsocket = socket; + pdev->socket = socket; pdev->managed = true; } @@ -198,16 +240,16 @@ static void pci_proxy_dev_register_types(void) type_init(pci_proxy_dev_register_types) -static void init_proxy(PCIDevice *dev, char *command, Error **errp) +static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp) { PCIProxyDev *pdev = PCI_PROXY_DEV(dev); Error *local_error = NULL; if (!pdev->managed) { - if (command) { - remote_spawn(pdev, command, &local_error); - } else { - return; + if (need_spawn) { + if (!remote_spawn(pdev, command, &local_error)) { + return; + } } } else { pdev->remote_pid = atoi(pdev->rid); diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 3648a77..f97b103 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -63,7 +63,7 @@ typedef struct PCIProxyDev { void (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd); void (*proxy_ready) (PCIDevice *dev); - void (*init_proxy) (PCIDevice *pdev, char *command, Error **errp); + void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error **errp); } PCIProxyDev; From patchwork Thu Oct 24 09:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B9A71575 for ; Thu, 24 Oct 2019 09:22:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 612F0205F4 for ; Thu, 24 Oct 2019 09:22:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ESYCUCpL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 612F0205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZKB-0000W8-5Q for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:22:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43738) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8k-0006QC-6R for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8i-0004BX-2m for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:42 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59818) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8h-0004Ag-Qn for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:40 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94ooa100039; Thu, 24 Oct 2019 09:10:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=mKVNftuaCcncsIMdPR3nxOIkecEr4x+cuilsoxsQJ2I=; b=ESYCUCpL9y1kAaychHLoYWomtsRHwXh/Hrf84/O0AiXyhyM4ZLoCP7ed9jktRbju0ei2 dK8DcIWaUmyaAE8ww57MaXbPumfT39hVlWWtxXGqElwpgVlDTeihxPo98z6lHa5B6Vj7 B7og2CtJm9GdUJhOBYbG4YVNzFG06TJLc9DKK2gx8z8zPbTiJsfRQbiIYbEaqWfi2x0W VlBu3HqhnWhgVTULtc3IVIZVZRxRPfIUMH0xqHEB+v/QiPOB4TY223GpK/WQk5TPoDVb ys2j2Vk1pnUynQPafXlchubmaaJoXr7JrQagYvPNdI8YExShcCNT5zk5KxS71pHuDRJC rg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2vqteq2af0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:31 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jnv170518; Thu, 24 Oct 2019 09:10:31 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2vtsk4868n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:31 +0000 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 x9O9AToU011816; Thu, 24 Oct 2019 09:10:29 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:29 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 15/49] multi-process: PCI BAR read/write handling for proxy & remote endpoints Date: Thu, 24 Oct 2019 05:08:56 -0400 Message-Id: <91343147552944eb67fbb98bf619e7eeb98fe324.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Proxy device object implements handler for PCI BAR writes and reads. The handler uses BAR_WRITE/BAR_READ message to communicate to the remote process with the BAR address and value to be written/read. The remote process implements handler for BAR_WRITE/BAR_READ message. Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson --- hw/proxy/qemu-proxy.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 21 ++++++++++-- include/io/mpqemu-link.h | 12 +++++++ remote/remote-main.c | 73 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index ca7dd1a..e1f62d7 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -275,6 +275,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) PCIProxyDev *dev = PCI_PROXY_DEV(device); PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev); Error *local_err = NULL; + int r; if (k->realize) { k->realize(dev, &local_err); @@ -283,7 +284,83 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) } } + for (r = 0; r < PCI_NUM_REGIONS; r++) { + if (!dev->region[r].present) { + continue; + } + + dev->region[r].dev = dev; + + pci_register_bar(PCI_DEVICE(dev), r, dev->region[r].type, + &dev->region[r].mr); + } + dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; } + +static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, + bool write, hwaddr addr, uint64_t *val, + unsigned size, bool memory) +{ + MPQemuLinkState *mpqemu_link = dev->mpqemu_link; + MPQemuMsg msg; + int wait; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.data1.bar_access.addr = mr->addr + addr; + msg.data1.bar_access.size = size; + msg.data1.bar_access.memory = memory; + + if (write) { + msg.cmd = BAR_WRITE; + msg.data1.bar_access.val = *val; + } else { + wait = GET_REMOTE_WAIT; + + msg.cmd = BAR_READ; + msg.num_fds = 1; + msg.fds[0] = wait; + } + + mpqemu_msg_send(mpqemu_link, &msg, mpqemu_link->com); + + if (!write) { + *val = wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } +} + +void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + uint64_t val; + + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + + return val; +} + +const MemoryRegionOps proxy_default_ops = { + .read = proxy_default_bar_read, + .write = proxy_default_bar_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, +}; diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index f97b103..5f57822 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -36,7 +36,19 @@ #define PCI_PROXY_DEV_GET_CLASS(obj) \ OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) -typedef struct PCIProxyDev { +typedef struct PCIProxyDev PCIProxyDev; + +typedef struct ProxyMemoryRegion { + PCIProxyDev *dev; + MemoryRegion mr; + bool memory; + bool present; + uint8_t type; +} ProxyMemoryRegion; + +extern const MemoryRegionOps proxy_default_ops; + +struct PCIProxyDev { PCIDevice parent_dev; int n_mr_sections; @@ -65,7 +77,8 @@ typedef struct PCIProxyDev { void (*proxy_ready) (PCIDevice *dev); void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error **errp); -} PCIProxyDev; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; +}; typedef struct PCIProxyDevClass { PCIDeviceClass parent_class; @@ -77,5 +90,9 @@ typedef struct PCIProxyDevClass { int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp); +void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size); + +uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size); #endif /* QEMU_PROXY_H */ diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 7ef8207..89f04c5 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -52,6 +52,8 @@ * CONF_READ PCI config. space read * CONF_WRITE PCI config. space write * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM + * BAR_WRITE Writes to PCI BAR region + * BAR_READ Reads from PCI BAR region * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -61,6 +63,8 @@ typedef enum { CONF_READ, CONF_WRITE, SYNC_SYSMEM, + BAR_WRITE, + BAR_READ, MAX, } mpqemu_cmd_t; @@ -84,6 +88,13 @@ typedef struct { } sync_sysmem_msg_t; typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} bar_access_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -91,6 +102,7 @@ typedef struct { union { uint64_t u64; sync_sysmem_msg_t sync_sysmem; + bar_access_msg_t bar_access; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/remote/remote-main.c b/remote/remote-main.c index 6c2eb91..49b27d5 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -46,6 +46,7 @@ #include "qemu/config-file.h" #include "sysemu/sysemu.h" #include "block/block.h" +#include "exec/memattrs.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -76,6 +77,66 @@ static void process_config_read(MPQemuMsg *msg) PUT_REMOTE_WAIT(wait); } +/* TODO: confirm memtx attrs. */ +static void process_bar_write(MPQemuMsg *msg, Error **errp) +{ + bar_access_msg_t *bar_access = &msg->data1.bar_access; + AddressSpace *as = + bar_access->memory ? &address_space_memory : &address_space_io; + MemTxResult res; + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)&bar_access->val, bar_access->size, true); + + if (res != MEMTX_OK) { + error_setg(errp, "Could not perform address space write operation," + " inaccessible address: %lx.", bar_access->addr); + } +} + +static void process_bar_read(MPQemuMsg *msg, Error **errp) +{ + bar_access_msg_t *bar_access = &msg->data1.bar_access; + AddressSpace *as; + int wait = msg->fds[0]; + MemTxResult res; + uint64_t val = 0; + + as = bar_access->memory ? &address_space_memory : &address_space_io; + + assert(bar_access->size <= sizeof(uint64_t)); + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)&val, bar_access->size, false); + + if (res != MEMTX_OK) { + error_setg(errp, "Could not perform address space read operation," + " inaccessible address: %lx.", bar_access->addr); + val = (uint64_t)-1; + goto fail; + } + + switch (bar_access->size) { + case 4: + val = *((uint32_t *)&val); + break; + case 2: + val = *((uint16_t *)&val); + break; + case 1: + val = *((uint8_t *)&val); + break; + default: + error_setg(errp, "Invalid PCI BAR read size"); + return; + } + +fail: + notify_proxy(wait, val); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -102,6 +163,18 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case CONF_READ: process_config_read(msg); break; + case BAR_WRITE: + process_bar_write(msg, &err); + if (err) { + goto finalize_loop; + } + break; + case BAR_READ: + process_bar_read(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:08:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E41C14ED for ; Thu, 24 Oct 2019 09:18:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6397C205F4 for ; Thu, 24 Oct 2019 09:18:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fiRdT/MY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6397C205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZGC-0001dY-RI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43728) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8j-0006Nz-AP for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8h-0004B0-NN for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:41 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59810) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8h-0004AY-FS for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:39 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94n9I100030; Thu, 24 Oct 2019 09:10:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=vKjhWVPZm7/SLDQnb0NCXeve3bJ0wUWGN6XOviUNcXE=; b=fiRdT/MYEBcJ6SyQUs9/HaRa/p8XmWjEDP1rUYp+CUTDMgZSa+zYrfKtLn6o1Gi77gl/ mOQcR+hZly/5UriH74JVNHZGgYSQuIqYbTKp1MYplUQHRl6EypqTLbAxUi9hMPOR5KtH Zr3UfoQSQBxvgbZpdiUVHBI4mSuNvYQSTPj8teT/aJQCAWGWUj/rR4xVyQXFoxid7WUX LIyAubNKGJloot/u9zkE6FDM+WfQaet5i9+ghJG85z6qUUo7TcAycVjmZsjSnlVgnWFU xb7bqFvjZmiU+AQUIc/GAmUCznZ3Y1ae/qvzPiHs2qejAIzNQKtNUqwpBv+os7VMqgao +w== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2vqteq2af6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:33 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jh6170576; Thu, 24 Oct 2019 09:10:33 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2vtsk486ay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:32 +0000 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 x9O9AVUK011830; Thu, 24 Oct 2019 09:10:31 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:30 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 16/49] multi-process: Add LSI device proxy object Date: Thu, 24 Oct 2019 05:08:57 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 91 +++++++++++++++++++++++++++++++++++++ include/hw/proxy/proxy-lsi53c895a.h | 42 +++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 hw/proxy/proxy-lsi53c895a.c create mode 100644 include/hw/proxy/proxy-lsi53c895a.h 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..7734ae2 --- /dev/null +++ b/hw/proxy/proxy-lsi53c895a.c @@ -0,0 +1,91 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#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 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; + + dev->region[0].present = true; + dev->region[0].type = PCI_BASE_ADDRESS_SPACE_IO; + memory_region_init_io(&dev->region[0].mr, OBJECT(s), &proxy_default_ops, + &dev->region[0], "proxy-lsi-io", 256); + + dev->region[1].present = true; + dev->region[1].memory = true; + dev->region[1].type = PCI_BASE_ADDRESS_SPACE_MEMORY; + memory_region_init_io(&dev->region[1].mr, OBJECT(s), &proxy_default_ops, + &dev->region[1], "proxy-lsi-mmio", 0x400); + + dev->region[2].present = true; + dev->region[2].memory = true; + dev->region[2].type = PCI_BASE_ADDRESS_SPACE_MEMORY; + memory_region_init_io(&dev->region[2].mr, OBJECT(s), &proxy_default_ops, + &dev->region[2], "proxy-lsi-ram", 0x2000); +} + +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..8afb8f3 --- /dev/null +++ b/include/hw/proxy/proxy-lsi53c895a.h @@ -0,0 +1,42 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef 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 Oct 24 09:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208769 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BEC514E5 for ; Thu, 24 Oct 2019 09:55:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDCAC2166E for ; Thu, 24 Oct 2019 09:55:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iMSO5ukn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDCAC2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZpg-0002v5-4E for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:55:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44400) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAo-00038w-JZ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAi-0005SR-57 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:50 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:47214) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAh-0005Ri-Os for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:44 -0400 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 x9O94Uro116446; Thu, 24 Oct 2019 09:12:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=Pe3VOKrCO7qxFYb92+AfeM/0F75bASCede7NAa4YGKY=; b=iMSO5uknUnzsxDsqnlU4k+xvxrtuIBo/x9r7vKeJi4lHpM9vlflWlvN7cbqbLvZFTTwv jPH2Go8x2FsuTubBD8gTta+xhvZZo13ejjvCBs87MLdMzX8VAahKwBpGv27BGp0xpAxa EpM2AwhcJK06gsvVkjoRhOGLmIWG+V1D19vilB49MoO/whrb1ZTtaonhHkztYdq9hKbI WZ7m6cOfcNqdLS3012Q8/Co25s7nXZtC53No0ZFF+z28hDhXOX/xVkNu1iUrYIB2yp8N /VusxGNj8srZqQinGMJM0zxGdF9ncJj68HJyONZOeZOIXsoXodOjpAvdr33pHAHfHtNz sA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vqswtte7u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:35 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jdK170529; Thu, 24 Oct 2019 09:10:34 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2vtsk486dc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:34 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9AW83009276; Thu, 24 Oct 2019 09:10:32 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:32 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 17/49] multi-process: Synchronize remote memory Date: Thu, 24 Oct 2019 05:08:58 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=4 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v2 -> v3: - Refactored code to obtain fd from host address, added get_fd_from_hostaddr(). - Discovered a bug which results in invalid FDs (-1) being sent over to the remote process. Fixed this by checking if the FD value is valid before sending over to remote. Makefile.target | 1 + hw/proxy/memory-sync.c | 226 +++++++++++++++++++++++++++++++++++++++++ hw/proxy/qemu-proxy.c | 5 + include/hw/proxy/memory-sync.h | 51 ++++++++++ include/hw/proxy/qemu-proxy.h | 2 + remote/remote-main.c | 11 ++ 6 files changed, 296 insertions(+) create mode 100644 hw/proxy/memory-sync.c create mode 100644 include/hw/proxy/memory-sync.h diff --git a/Makefile.target b/Makefile.target index 547f10e..eb1ac34 100644 --- a/Makefile.target +++ b/Makefile.target @@ -122,6 +122,7 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o +obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o LIBS := $(libs_cpu) $(LIBS) remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c new file mode 100644 index 0000000..da24a25 --- /dev/null +++ b/hw/proxy/memory-sync.c @@ -0,0 +1,226 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#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/mpqemu-link.h" +#include "hw/proxy/memory-sync.h" + +static const TypeInfo remote_mem_sync_type_info = { + .name = TYPE_MEMORY_LISTENER, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteMemSync), +}; + +static void remote_mem_sync_register_types(void) +{ + type_register_static(&remote_mem_sync_type_info); +} + +type_init(remote_mem_sync_register_types) + +static void proxy_ml_begin(MemoryListener *listener) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + int mrs; + + for (mrs = 0; mrs < sync->n_mr_sections; mrs++) { + memory_region_unref(sync->mr_sections[mrs].mr); + } + + g_free(sync->mr_sections); + sync->mr_sections = NULL; + sync->n_mr_sections = 0; +} + +static int get_fd_from_hostaddr(uint64_t host, ram_addr_t *offset) +{ + MemoryRegion *mr; + ram_addr_t off; + + mr = memory_region_from_host((void *)(uintptr_t)host, &off); + + if (offset) { + *offset = off; + } + + return memory_region_get_fd(mr); +} + +static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size) +{ + bool merge; + int fd1, fd2; + + fd1 = get_fd_from_hostaddr(host, NULL); + + fd2 = get_fd_from_hostaddr(prev_host, NULL); + + merge = (fd1 == fd2); + + merge &= ((prev_host + size) == host); + + return merge; +} + +static void proxy_ml_region_addnop(MemoryListener *listener, + MemoryRegionSection *section) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + bool need_add = true; + uint64_t mrs_size, mrs_gpa, mrs_page; + uintptr_t mrs_host; + RAMBlock *mrs_rb; + MemoryRegionSection *prev_sec; + + if (!(memory_region_is_ram(section->mr) && + !memory_region_is_rom(section->mr))) { + return; + } + + mrs_rb = section->mr->ram_block; + mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb); + mrs_size = int128_get64(section->size); + mrs_gpa = section->offset_within_address_space; + mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + + if (get_fd_from_hostaddr(mrs_host, NULL) <= 0) { + return; + } + + mrs_host = mrs_host & ~(mrs_page - 1); + mrs_gpa = mrs_gpa & ~(mrs_page - 1); + mrs_size = ROUND_UP(mrs_size, mrs_page); + + if (sync->n_mr_sections) { + prev_sec = sync->mr_sections + (sync->n_mr_sections - 1); + uint64_t prev_gpa_start = prev_sec->offset_within_address_space; + uint64_t prev_size = int128_get64(prev_sec->size); + uint64_t prev_gpa_end = range_get_last(prev_gpa_start, prev_size); + uint64_t prev_host_start = + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) + + prev_sec->offset_within_region; + uint64_t prev_host_end = range_get_last(prev_host_start, prev_size); + + if (mrs_gpa <= (prev_gpa_end + 1)) { + if (mrs_gpa < prev_gpa_start) { + assert(0); + } + + if ((section->mr == prev_sec->mr) && + proxy_mrs_can_merge(mrs_host, prev_host_start, + (mrs_gpa - prev_gpa_start))) { + uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size); + need_add = false; + prev_sec->offset_within_address_space = + MIN(prev_gpa_start, mrs_gpa); + prev_sec->offset_within_region = + MIN(prev_host_start, mrs_host) - + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr); + prev_sec->size = int128_make64(max_end - MIN(prev_host_start, + mrs_host)); + } + } + } + + if (need_add) { + ++sync->n_mr_sections; + sync->mr_sections = g_renew(MemoryRegionSection, sync->mr_sections, + sync->n_mr_sections); + sync->mr_sections[sync->n_mr_sections - 1] = *section; + sync->mr_sections[sync->n_mr_sections - 1].fv = NULL; + memory_region_ref(section->mr); + } +} + +static void proxy_ml_commit(MemoryListener *listener) +{ + RemoteMemSync *sync = container_of(listener, RemoteMemSync, listener); + MPQemuMsg msg; + MemoryRegionSection section; + ram_addr_t offset; + uintptr_t host_addr; + int region; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.cmd = SYNC_SYSMEM; + msg.bytestream = 0; + msg.num_fds = sync->n_mr_sections; + msg.size = sizeof(msg.data1); + assert(msg.num_fds <= REMOTE_MAX_FDS); + + for (region = 0; region < sync->n_mr_sections; region++) { + section = sync->mr_sections[region]; + msg.data1.sync_sysmem.gpas[region] = + section.offset_within_address_space; + msg.data1.sync_sysmem.sizes[region] = int128_get64(section.size); + host_addr = (uintptr_t)memory_region_get_ram_ptr(section.mr) + + section.offset_within_region; + msg.fds[region] = get_fd_from_hostaddr(host_addr, &offset); + msg.data1.sync_sysmem.offsets[region] = offset; + } + mpqemu_msg_send(sync->mpqemu_link, &msg, sync->mpqemu_link->com); +} + +void deconfigure_memory_sync(RemoteMemSync *sync) +{ + memory_listener_unregister(&sync->listener); +} + +/* + * TODO: Memory Sync need not be instantianted once per every proxy device. + * All remote devices are going to get the exact same updates at the + * same time. It therefore makes sense to have a broadcast model. + * + * Broadcast model would involve running the MemorySync object in a + * thread. MemorySync would contain a list of mpqemu-link objects + * that need notification. proxy_ml_commit() could send the same + * message to all the links at the same time. + */ +void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link) +{ + sync->n_mr_sections = 0; + sync->mr_sections = NULL; + + sync->mpqemu_link = mpqemu_link; + + sync->listener.begin = proxy_ml_begin; + sync->listener.commit = proxy_ml_commit; + sync->listener.region_add = proxy_ml_region_addnop; + sync->listener.region_nop = proxy_ml_region_addnop; + sync->listener.priority = 10; + + memory_listener_register(&sync->listener, &address_space_memory); +} diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index e1f62d7..71770ca 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); @@ -268,6 +270,8 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); + + configure_memory_sync(pdev->sync, pdev->mpqemu_link); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) @@ -298,6 +302,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; + dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h new file mode 100644 index 0000000..cb94995 --- /dev/null +++ b/include/hw/proxy/memory-sync.h @@ -0,0 +1,51 @@ +/* + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MEMORY_SYNC_H +#define MEMORY_SYNC_H + +#include + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "exec/memory.h" +#include "io/mpqemu-link.h" + +#define TYPE_MEMORY_LISTENER "memory-listener" +#define REMOTE_MEM_SYNC(obj) \ + OBJECT_CHECK(RemoteMemSync, (obj), TYPE_MEMORY_LISTENER) + +typedef struct RemoteMemSync { + Object obj; + + MemoryListener listener; + + int n_mr_sections; + MemoryRegionSection *mr_sections; + + MPQemuLinkState *mpqemu_link; +} RemoteMemSync; + +void configure_memory_sync(RemoteMemSync *sync, MPQemuLinkState *mpqemu_link); +void deconfigure_memory_sync(RemoteMemSync *sync); + +#endif diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 5f57822..7475bba 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/mpqemu-link.h" +#include "hw/proxy/memory-sync.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -56,6 +57,7 @@ struct PCIProxyDev { MPQemuLinkState *mpqemu_link; + RemoteMemSync *sync; EventNotifier intr; EventNotifier resample; diff --git a/remote/remote-main.c b/remote/remote-main.c index 49b27d5..9fe4b87 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -47,6 +47,7 @@ #include "sysemu/sysemu.h" #include "block/block.h" #include "exec/memattrs.h" +#include "exec/address-spaces.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -175,6 +176,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; } break; + case SYNC_SYSMEM: + /* + * TODO: ensure no active DMA is happening when + * sysmem is being updated + */ + remote_sysmem_reconfig(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:08:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208613 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02FF11575 for ; Thu, 24 Oct 2019 09:22:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB8012166E for ; Thu, 24 Oct 2019 09:22:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NgDb0Wml" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB8012166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZJq-00009p-LV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:22:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43757) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8m-0006V5-Ad for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8j-0004D7-MV for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:44 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8j-0004CS-ED for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94MqV099563; Thu, 24 Oct 2019 09:10:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=H322vZf3D5PJotCo0iJUoqrU2l3/JouW4hAACvOd5bA=; b=NgDb0WmlYeCS+9SLVYmSuwnL7CufHFLtpvRC+uQvZDFG8gCfo1Nn9tOxV/My4To3R2a8 yHMa/lFA9E6ktq8l5YeWS3zgKdMGQoF2kkNOI1Br4BAJWSx8RW3oh991EfFVIyenn3Na pX6zUD6a/mO+qpQ1tXwqo6otC/Xqa7DrPBKhK1aghqEG4z3eSWm4F5UFDXrhmCCJf36Y fOMZXGh4uEVqf96n5ba6FVGhmmbelccNUXjGtY6rDF287YXsZK3LYCM7IG2nw2+IVFAb g1KLJ8Af6yfdrRsh4taiNY28lY4k961a7D0lvXxgMS+tWPDVPNr/vfXp/trHjqMwESnt gg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2afb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:36 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LtQ047136; Thu, 24 Oct 2019 09:10:35 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu71c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:35 +0000 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 x9O9AYNI002083; Thu, 24 Oct 2019 09:10:34 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:34 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 18/49] multi-process: create IOHUB object to handle irq Date: Thu, 24 Oct 2019 05:08:59 -0400 Message-Id: <4a2836f10199fd0dcc30bceab963e99d6d77d89d.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- Makefile.target | 1 + hw/proxy/Makefile.objs | 1 - hw/proxy/qemu-proxy.c | 54 ++++++++++++++ include/hw/pci/pci_ids.h | 3 + include/hw/proxy/qemu-proxy.h | 5 ++ include/io/mpqemu-link.h | 8 +++ include/remote/iohub.h | 63 +++++++++++++++++ include/remote/machine.h | 2 + remote/Makefile.objs | 1 + remote/iohub.c | 159 ++++++++++++++++++++++++++++++++++++++++++ remote/machine.c | 15 ++++ remote/remote-main.c | 4 ++ 12 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 include/remote/iohub.h create mode 100644 remote/iohub.c diff --git a/Makefile.target b/Makefile.target index eb1ac34..f16b74a 100644 --- a/Makefile.target +++ b/Makefile.target @@ -123,6 +123,7 @@ obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o +obj-$(CONFIG_MPQEMU) += hw/proxy/qemu-proxy.o LIBS := $(libs_cpu) $(LIBS) remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/kvm-stub.o diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs index f562f5a..ca89109 100644 --- a/hw/proxy/Makefile.objs +++ b/hw/proxy/Makefile.objs @@ -1,2 +1 @@ -common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o common-obj-$(CONFIG_MPQEMU) += proxy-lsi53c895a.o diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 71770ca..bd7dd35 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/mpqemu-link.h" @@ -44,6 +47,9 @@ #include "hw/proxy/qemu-proxy.h" #include "hw/proxy/memory-sync.h" #include "qom/object.h" +#include "qemu/event_notifier.h" +#include "sysemu/kvm.h" +#include "util/event_notifier-posix.c" static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); @@ -242,6 +248,53 @@ static void pci_proxy_dev_register_types(void) type_init(pci_proxy_dev_register_types) +static void proxy_intx_update(PCIDevice *pci_dev) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); + PCIINTxRoute route; + int pin = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + if (dev->irqfd.fd) { + dev->irqfd.flags = KVM_IRQFD_FLAG_DEASSIGN; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); + memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd)); + } + + route = pci_device_route_intx_to_irq(pci_dev, pin); + + dev->irqfd.fd = event_notifier_get_fd(&dev->intr); + dev->irqfd.resamplefd = event_notifier_get_fd(&dev->resample); + dev->irqfd.gsi = route.irq; + dev->irqfd.flags |= KVM_IRQFD_FLAG_RESAMPLE; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); +} + +static void setup_irqfd(PCIProxyDev *dev) +{ + PCIDevice *pci_dev = PCI_DEVICE(dev); + MPQemuMsg msg; + + event_notifier_init(&dev->intr, 0); + event_notifier_init(&dev->resample, 0); + + memset(&msg, 0, sizeof(MPQemuMsg)); + msg.cmd = SET_IRQFD; + msg.num_fds = 2; + msg.fds[0] = event_notifier_get_fd(&dev->intr); + msg.fds[1] = event_notifier_get_fd(&dev->resample); + msg.data1.set_irqfd.intx = + pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + msg.size = sizeof(msg.data1); + + mpqemu_msg_send(dev->mpqemu_link, &msg, dev->mpqemu_link->com); + + memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd)); + + proxy_intx_update(pci_dev); + + pci_device_set_intx_routing_notifier(pci_dev, proxy_intx_update); +} + static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **errp) { PCIProxyDev *pdev = PCI_PROXY_DEV(dev); @@ -272,6 +325,7 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e pdev->socket); configure_memory_sync(pdev->sync, pdev->mpqemu_link); + setup_irqfd(pdev); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) 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 7475bba..0fad7e3 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/mpqemu-link.h" #include "hw/proxy/memory-sync.h" +#include "qemu/event_notifier.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -58,6 +61,8 @@ struct PCIProxyDev { MPQemuLinkState *mpqemu_link; RemoteMemSync *sync; + struct kvm_irqfd irqfd; + EventNotifier intr; EventNotifier resample; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 89f04c5..1885ad7 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -54,6 +54,8 @@ * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * BAR_WRITE Writes to PCI BAR region * BAR_READ Reads from PCI BAR region + * SET_IRQFD Sets the IRQFD to be used to raise interrupts directly + * from remote device * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -65,6 +67,7 @@ typedef enum { SYNC_SYSMEM, BAR_WRITE, BAR_READ, + SET_IRQFD, MAX, } mpqemu_cmd_t; @@ -95,6 +98,10 @@ typedef struct { } bar_access_msg_t; typedef struct { + int intx; +} set_irqfd_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -103,6 +110,7 @@ typedef struct { uint64_t u64; sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; + set_irqfd_msg_t set_irqfd; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/iohub.h b/include/remote/iohub.h new file mode 100644 index 0000000..7ae41e9 --- /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/mpqemu-link.h" + +#define REMOTE_IOHUB_NB_PIRQS 8 + +#define REMOTE_IOHUB_DEV 31 +#define REMOTE_IOHUB_FUNC 0 + +#define TYPE_REMOTE_IOHUB_DEVICE "remote-iohub" +#define REMOTE_IOHUB_DEVICE(obj) \ + OBJECT_CHECK(RemoteIOHubState, (obj), TYPE_REMOTE_IOHUB_DEVICE) + +typedef struct 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, MPQemuMsg *msg); + +#endif diff --git a/include/remote/machine.h b/include/remote/machine.h index a00732d..0a16cc6 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..dad92c9 --- /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, MPQemuMsg *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 4ce197d..5b03167 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 9fe4b87..cede97c 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -48,6 +48,7 @@ #include "block/block.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" +#include "remote/iohub.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -186,6 +187,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; } break; + case SET_IRQFD: + process_set_irqfd_msg(remote_pci_dev, msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E429913B1 for ; Thu, 24 Oct 2019 09:21:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B84FA21906 for ; Thu, 24 Oct 2019 09:21:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="grzprsxu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B84FA21906 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZJG-0007na-D5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:21:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43760) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8m-0006Va-H7 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8l-0004E6-9o for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:44 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8l-0004DZ-1A for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:43 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94rfs100053; Thu, 24 Oct 2019 09:10:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=iMg6Ts1aZSw54dFDez9o2my5CKYdiynWWTJ9KPLx0Os=; b=grzprsxus2shgwvAgQfxmLcK8PlUhmzIdMbtXSJf2yy8EEtLRB+bD0ui1vTVPxSxMnD3 95iNidXWGFfmwP9Znqnm2Vrja7Gn+iVt05cvi3tncAqT4VsaHRPluFXpBBP0bIW8H6h/ NZRwIymfsThASdV6ZCKwz1LZ2PszKCG0VXjLER+wro5i73y8suYHg3/FV3IgTjmSa/en LErvtGyQdZHso50BkVnfvJtiqSwkLqDI04RS6Jx/kc4CPV/WM4gxepA7Kyme/+/JZMvm 4tNSKr57JZa00HH7zejPF88KGBMSQ/d4Zm2tV1MfsGfzQKN9o7MdkTxvCioYCW9mj8Yl FA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2vqteq2afh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:37 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O983a6093263; Thu, 24 Oct 2019 09:10:37 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2vtm244guh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:37 +0000 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 x9O9Aark002164; Thu, 24 Oct 2019 09:10:36 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:36 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 19/49] multi-process: configure remote side devices Date: Thu, 24 Oct 2019 05:09:00 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 39 ++++++++++++++++++++++++++++++++++++++- include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 4 ++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index bd7dd35..3b84055 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -50,8 +50,43 @@ #include "qemu/event_notifier.h" #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +#include "hw/boards.h" +#include "include/qemu/log.h" static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); +static void setup_irqfd(PCIProxyDev *dev); + +static void proxy_ready(PCIDevice *dev) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + + setup_irqfd(pdev); +} + +static void set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) +{ + QString *qstr; + MPQemuMsg msg; + const char *str; + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + qstr = qobject_to_json(QOBJECT(qdict)); + str = qstring_get_str(qstr); + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.data2 = (uint8_t *)str; + msg.cmd = cmd; + msg.bytestream = 1; + msg.size = qstring_get_length(qstr) + 1; + msg.num_fds = 0; + + mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + + return; +} static int add_argv(char *command_str, char **argv, int argc) { @@ -325,7 +360,6 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e pdev->socket); configure_memory_sync(pdev->sync, pdev->mpqemu_link); - setup_irqfd(pdev); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) @@ -357,6 +391,9 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); + + dev->set_remote_opts = set_remote_opts; + dev->proxy_ready = proxy_ready; } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 0fad7e3..80aadf9 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -28,6 +28,8 @@ #include "io/mpqemu-link.h" #include "hw/proxy/memory-sync.h" #include "qemu/event_notifier.h" +#include "hw/pci/pci.h" +#include "block/qdict.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 1885ad7..3145b0e 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -68,6 +68,10 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + DEV_OPTS, + DRIVE_OPTS, + DEVICE_ADD, + DEVICE_DEL, MAX, } mpqemu_cmd_t; From patchwork Thu Oct 24 09:09:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 647481575 for ; Thu, 24 Oct 2019 09:23:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2983D205F4 for ; Thu, 24 Oct 2019 09:23:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="hM4kCSpD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2983D205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZLV-0002Z7-Vh for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:23:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43785) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8p-0006eE-Iy for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8n-0004Gs-Nq for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:47 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45426) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8n-0004FI-EP for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:45 -0400 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 x9O94UAH116449; Thu, 24 Oct 2019 09:10:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=1Va1ADzHWzWfOMbelsFfjVosW32ccuuUc+geYkrKeOM=; b=hM4kCSpD0R2ieHtiYjNxHYzR4Y3dmrsTfQZP17qouXPpYnEHK8PsnTWzsCVZB6YsdKSs TmhZ43e7sOysTyFOsbpf3OP8/vhtpxB+zB1nF+SvhsixLoK5WFc4YrzwAgrith9aTUQ3 qiz/T7aI3XfgwIEpjnjAlylPub7apeTG2Ayf8v+7LVAvN+hryel+JHwZEMONgmjCwBzt 9sC7j2oWf+AAask/ywrylhGJyeYsggluh8nHkUPcN3lL5nU17iq5l/HnzkY8mMyB0cZ/ Q6MH9E6AVQS+BDja75ht12fXw9vA78OosFVNKkzY9cO7h/v0iqBdHL0JHrN0AFeAdmLM Pg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vqswttdyq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:40 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97iad170512; Thu, 24 Oct 2019 09:10:40 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2vtsk486kk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:39 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9AcGN009298; Thu, 24 Oct 2019 09:10:38 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:38 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 20/49] multi-process: add qdev_proxy_add to create proxy devices Date: Thu, 24 Oct 2019 05:09:01 -0400 Message-Id: <36de8c87e14b6623fd1a570c0c34dd0667ba8aec.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v1 -> v2: - parse socket and command suboptions of drive/device commands hw/proxy/qemu-proxy.c | 3 +- include/hw/proxy/qemu-proxy.h | 7 ++ include/monitor/qdev.h | 25 +++++ qdev-monitor.c | 254 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 288 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 3b84055..fc1c731 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -337,7 +337,8 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e if (!pdev->managed) { if (need_spawn) { - if (!remote_spawn(pdev, command, &local_error)) { + if (remote_spawn(pdev, command, &local_error)) { + fprintf(stderr, "remote spawn failed\n"); return; } } diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 80aadf9..ac61a9b 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -99,6 +99,13 @@ typedef struct PCIProxyDevClass { int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp); +typedef struct PCIProxyDevList { + QLIST_HEAD(, PCIProxyDev) devices; +} proxy_dev_list_t; + +extern QemuMutex proxy_list_lock; +extern proxy_dev_list_t proxy_dev_list; + void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, unsigned size); diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index eaa947d..0bc355a 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -1,13 +1,38 @@ #ifndef MONITOR_QDEV_H #define MONITOR_QDEV_H +#include "hw/proxy/qemu-proxy.h" + /*** monitor commands ***/ void hmp_info_qtree(Monitor *mon, const QDict *qdict); void hmp_info_qdm(Monitor *mon, const QDict *qdict); void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); +DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp); +void qdev_proxy_fire(void); + int qdev_device_help(QemuOpts *opts); +DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, + char *command, int rsocket, bool managed, + Error **errp); + +struct remote_process { + int rid; + int remote_pid; + unsigned int type; + int socket; + char *command; + QemuOpts *opts; + + QLIST_ENTRY(remote_process) next; +}; + +void remote_process_register(struct remote_process *p); + +struct remote_process *get_remote_process_type(unsigned int type); +struct remote_process *get_remote_process_rid(unsigned int rid); + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); void qdev_set_id(DeviceState *dev, const char *id); diff --git a/qdev-monitor.c b/qdev-monitor.c index 148df9c..eeff43e 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -35,6 +35,17 @@ #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" #include "migration/misc.h" +#include "hw/boards.h" +#include "hw/proxy/qemu-proxy.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" +#include "sysemu/sysemu.h" +#include "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/mpqemu-link.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -47,6 +58,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" }, @@ -562,6 +575,247 @@ void qdev_set_id(DeviceState *dev, const char *id) } } +static QLIST_HEAD(, remote_process) remote_processes; + +void remote_process_register(struct remote_process *p) +{ + QLIST_INSERT_HEAD(&remote_processes, p, next); +} + +struct remote_process *get_remote_process_rid(unsigned int rid) +{ + struct remote_process *p; + + QLIST_FOREACH(p, &remote_processes, next) { + if (rid == p->rid) { + return p; + } + } + return NULL; +} + +struct remote_process *get_remote_process_type(unsigned int type) +{ + struct remote_process *p; + + QLIST_FOREACH(p, &remote_processes, next) { + if (type == p->type) { + return p; + } + } + return NULL; +} + +#if defined(CONFIG_MPQEMU) + +static PCIProxyDev *get_proxy_object_rid(const char *rid) +{ + PCIProxyDev *entry; + if (!proxy_list_lock.initialized) { + QLIST_INIT(&proxy_dev_list.devices); + qemu_mutex_init(&proxy_list_lock); + } + + 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, char *bus, + char *command, int rsocket, bool managed, + Error **errp) +{ + DeviceState *ds; + PCIProxyDev *pdev, *old_pdev; + QemuOpts *proxy_opts; + const char *proxy_type; + Error *local_err = NULL; + QDict *qdict; + const char *str; + bool need_spawn = false; + bool remote_exists = false; + + if (strlen(rid) > MAX_RID_LENGTH) { + error_setg(errp, "rid %s is too long.", rid); + return NULL; + } + + old_pdev = get_proxy_object_rid(rid); + if (old_pdev) { + remote_exists = true; + if (old_pdev->dev_id) { + if (id) { + if (strncmp(id, old_pdev->dev_id, + strlen(old_pdev->dev_id)) == 0) { + return DEVICE(old_pdev); + } + } else { + /* check if device belongs to this proxy, use bus */ + if (bus) { + if (strncmp(bus, old_pdev->dev_id, + strlen(old_pdev->dev_id)) == 0) { + return DEVICE(old_pdev); + } + } + } + } + } + + proxy_opts = qemu_opts_create(&qemu_device_opts, NULL, 0, + errp); + + /* TODO: remove hardcoded type and add approptiate type identification. */ + proxy_type = TYPE_PROXY_LSI53C895A; + + qemu_opts_set_id(proxy_opts, (char *)rid); + qemu_opt_set(proxy_opts, "driver", proxy_type, &local_err); + + qdict = qemu_opts_to_qdict(proxy_opts, NULL); + str = qstring_get_str(qobject_to_json(QOBJECT(qdict))); + + ds = qdev_device_add(proxy_opts, &local_err); + if (!ds) { + error_setg(errp, "Could not create proxy device" + " with opts %s.", str); + qemu_opts_del(proxy_opts); + return NULL; + } + qdev_set_id(ds, qemu_opts_id(proxy_opts)); + + pdev = PCI_PROXY_DEV(ds); + if (!pdev) { + error_setg(errp, "qdev_device_add failed."); + qemu_opts_del(proxy_opts); + return NULL; + } + pdev->rid = g_strdup(rid); + if (old_pdev) { + pdev->rsocket = old_pdev->rsocket; + pdev->socket = old_pdev->socket; + pdev->remote_pid = old_pdev->remote_pid; + } else { + pdev->rsocket = managed ? rsocket : -1; + pdev->socket = managed ? rsocket : -1; + + } + pdev->managed = managed; + + /* With no libvirt, we will need to spawn. For now, every time. */ + if (!remote_exists) { + need_spawn = true; + } + + pdev->init_proxy(PCI_DEVICE(ds), command, need_spawn, errp); + + qemu_mutex_lock(&proxy_list_lock); + QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next); + qemu_mutex_unlock(&proxy_list_lock); + + qemu_opts_del(proxy_opts); + return ds; +} + +DeviceState *qdev_remote_add(QemuOpts *opts, bool device, Error **errp) +{ + PCIProxyDev *pdev = NULL; + DeviceState *dev; + const char *rid, *rsocket = NULL, *command = NULL; + QDict *qdict_new; + const char *id = NULL; + const char *driver = NULL; + const char *bus = NULL; + + if (!proxy_list_lock.initialized) { + QLIST_INIT(&proxy_dev_list.devices); + qemu_mutex_init(&proxy_list_lock); + } + + rid = qemu_opt_get(opts, "rid"); + if (!rid) { + error_setg(errp, "rdevice option needs rid specified."); + return NULL; + } + if (device) { + driver = qemu_opt_get(opts, "driver"); + /* TODO: properly identify the device class. */ + if (strncmp(driver, "lsi", 3) == 0) { + id = qemu_opts_id(opts); + if (!id) { + error_setg(errp, "qdev_remote_add option needs id specified."); + return NULL; + } + } + } + + rsocket = qemu_opt_get(opts, "socket"); + if (rsocket) { + if (strlen(rsocket) > MAX_RID_LENGTH) { + error_setg(errp, "Socket number is incorrect."); + return NULL; + } + } + /* + * TODO: verify command with known commands and on remote end. + * How else can we verify the binary we launch without libvirtd support? + */ + command = qemu_opt_get(opts, "command"); + if (!rsocket && !command) { + error_setg(errp, "rdevice option needs socket or command specified."); + return NULL; + } + + bus = qemu_opt_get(opts, "bus"); + dev = qdev_proxy_add(rid, id, (char *)bus, (char *)command, + rsocket ? atoi(rsocket) : -1, + rsocket ? true : false, errp); + if (!dev) { + error_setg(errp, "qdev_proxy_add error."); + return NULL; + } + + qdict_new = qemu_opts_to_qdict(opts, NULL); + + if (!qdict_new) { + error_setg(errp, "Could not parse rdevice options."); + return NULL; + } + + pdev = PCI_PROXY_DEV(dev); + if (!pdev->set_remote_opts) { + /* TODO: destroy proxy? */ + error_setg(errp, "set_remote_opts failed."); + return NULL; + } else { + if (id && !pdev->dev_id) { + pdev->dev_id = g_strdup(id); + } + pdev->set_remote_opts(PCI_DEVICE(pdev), qdict_new, + device ? DEV_OPTS : DRIVE_OPTS); + } + + return dev; +} +#endif /*defined(CONFIG_MPQEMU)*/ + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; From patchwork Thu Oct 24 09:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 35F511575 for ; Thu, 24 Oct 2019 09:24:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EEE2C205F4 for ; Thu, 24 Oct 2019 09:24:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qscR0CGO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEE2C205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZLo-00033H-TI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43794) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8q-0006hX-U9 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8p-0004Iq-7X for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:48 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60730) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8o-0004II-VM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:47 -0400 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 x9O94NgN094929; Thu, 24 Oct 2019 09:10:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=iFiVcwKNR9jUbmKD8dfsLaSdKBy0NIJkJ5X8IrIg8Y4=; b=qscR0CGO61yiRoBMBf9aD83cxNFlOLB/mg7ifGzPj8oBWhmXPXoBtGpssONBGRIJ8MpE wTbNSnFlSfjxfiaWWfY2Rj2Sbi/B/7ZfepXYhU6lP0x76qAIUZ6e6VO7qW/dSAvcDTHy oxUj0cXbomo26CwOiopXdsVO/JWdKj9tWBUoT2SmZv7fjNsFbLMpmXDzCHxTcqYQMSIE /PlhG4zNTMNfAHIpEgdAVi5jFfg2PsJW41G1q+mZUeG3Du0CizCAIDBvCV18sEypCg2R ULFBgg5ibtEXWk8CLTwzNAi6RNCeumcvP0aUEeip7U2117u6Ehuf0aseFlZkekFPDwtj zQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:42 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98mUY076167; Thu, 24 Oct 2019 09:10:41 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2vtjkj2xdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:41 +0000 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 x9O9Aeo4002203; Thu, 24 Oct 2019 09:10:40 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:40 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 21/49] multi-process: remote: add setup_devices and setup_drive msg processing Date: Thu, 24 Oct 2019 05:09:02 -0400 Message-Id: <3b01965059d7a258317081c2e9ebbd8d2feca872.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v1 -> v2: - for new command line suboptions with libvirtd support, clean the options before creating drives/devices - use default pci bus/address for now include/hw/qdev-core.h | 2 + qdev-monitor.c | 2 +- remote/remote-main.c | 231 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index aa123f8..19b117d 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -357,6 +357,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev); DeviceState *qdev_find_recursive(BusState *bus, const char *id); +DeviceState *find_device_state(const char *id, Error **errp); + /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn)(BusState *bus, void *opaque); typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); diff --git a/qdev-monitor.c b/qdev-monitor.c index eeff43e..e1d05e4 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -1025,7 +1025,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) object_unref(OBJECT(dev)); } -static DeviceState *find_device_state(const char *id, Error **errp) +DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; diff --git a/remote/remote-main.c b/remote/remote-main.c index cede97c..5b3ffd8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -49,6 +49,21 @@ #include "exec/memattrs.h" #include "exec/address-spaces.h" #include "remote/iohub.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qobject.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "monitor/qdev.h" +#include "qapi/qmp/qdict.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" +#include "block/block.h" +#include "qapi/qmp/qstring.h" +#include "hw/qdev-properties.h" +#include "hw/scsi/scsi.h" +#include "block/qdict.h" +#include "qapi/qmp/qlist.h" +#include "qemu/log.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -139,6 +154,200 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_device_add_msg(MPQemuMsg *msg) +{ + Error *local_err = NULL; + const char *json = (const char *)msg->data2; + int wait = msg->fds[0]; + QObject *qobj = NULL; + QDict *qdict = NULL; + QemuOpts *opts = NULL; + + qobj = qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict = qobject_to(QDict, qobj); + assert(qdict); + + opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); + if (local_err) { + goto fail; + } + + (void)qdev_device_add(opts, &local_err); + if (local_err) { + goto fail; + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + +static void process_device_del_msg(MPQemuMsg *msg) +{ + Error *local_err = NULL; + DeviceState *dev = NULL; + const char *json = (const char *)msg->data2; + int wait = msg->fds[0]; + QObject *qobj = NULL; + QDict *qdict = NULL; + const char *id; + + qobj = qobject_from_json(json, &local_err); + if (local_err) { + goto fail; + } + + qdict = qobject_to(QDict, qobj); + assert(qdict); + + id = qdict_get_try_str(qdict, "id"); + assert(id); + + dev = find_device_state(id, &local_err); + if (local_err) { + goto fail; + } + + if (dev) { + qdev_unplug(dev, &local_err); + } + +fail: + if (local_err) { + error_report_err(local_err); + /* TODO: communicate the exact error message to proxy */ + } + + notify_proxy(wait, 1); + + PUT_REMOTE_WAIT(wait); +} + +static int 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; + } + + qemu_opt_unset(opts, "rid"); + qemu_opt_unset(opts, "socket"); + qemu_opt_unset(opts, "remote"); + qemu_opt_unset(opts, "command"); + + if (drive_new(opts, IF_IDE, &local_error) == NULL) { + error_propagate(errp, local_error); + return -EINVAL; + } + + return 0; +} + +static int setup_drive(MPQemuMsg *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), &local_error); + if (!obj) { + error_propagate(errp, local_error); + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + if (init_drive(qdict, &local_error)) { + error_setg(errp, "init_drive failed in setup_drive."); + return rc; + } + + return 0; +} + +static int setup_device(MPQemuMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + QemuOpts *opts; + DeviceState *dev = NULL; + int rc = -EINVAL; + Error *local_error = NULL; + + if (!msg->data2) { + return rc; + } + + qstr = qstring_from_str((char *)msg->data2); + obj = qobject_from_json(qstring_get_str(qstr), &local_error); + if (!obj) { + error_setg(errp, "Could not get object!"); + return rc; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + return rc; + } + + g_assert(qdict_size(qdict) > 1); + + opts = qemu_opts_from_qdict(&qemu_device_opts, qdict, &local_error); + qemu_opt_unset(opts, "rid"); + qemu_opt_unset(opts, "socket"); + qemu_opt_unset(opts, "remote"); + qemu_opt_unset(opts, "command"); + /* + * TODO: use the bus and addr from the device options. For now + * we use default value. + */ + qemu_opt_unset(opts, "bus"); + qemu_opt_unset(opts, "addr"); + + dev = qdev_device_add(opts, &local_error); + if (!dev) { + error_setg(errp, "Could not add device %s.", + qstring_get_str(qobject_to_json(QOBJECT(qdict)))); + 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, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -184,11 +393,33 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) */ remote_sysmem_reconfig(msg, &err); if (err) { + error_report_err(err); goto finalize_loop; } break; case SET_IRQFD: process_set_irqfd_msg(remote_pci_dev, msg); + qdev_machine_creation_done(); + qemu_mutex_lock_iothread(); + qemu_run_machine_init_done_notifiers(); + qemu_mutex_unlock_iothread(); + + break; + case 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); + break; + case DEVICE_DEL: + process_device_del_msg(msg); break; default: error_setg(&err, "Unknown command"); From patchwork Thu Oct 24 09:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7792D1575 for ; Thu, 24 Oct 2019 09:24:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DDDA205F4 for ; Thu, 24 Oct 2019 09:24:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="S3mw7v6y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DDDA205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZMO-0003iV-2O for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:24:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43827) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8u-0006pz-Bw for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8t-0004LX-9W for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:52 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45484) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8t-0004Kw-1i for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:51 -0400 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 x9O94UAI116449; Thu, 24 Oct 2019 09:10:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=+wLS/h90eYFgBw7O1jMToozVxcnhmHzTmuArNonTSbc=; b=S3mw7v6yslRRgsKoHNN/BzUB8gS9CUNeHtSff0GQY96dgy//X+2cs5hkvUArYxPRaIzX XDsVjNXoAbK41W67sKqUPj2IY1btRZ+kchXahEPMHlspWYqAazDnuFCe3B+Ca1+AfdiI 2R4phdha7wj0gBwyhP3SF/hUStxguOvhK7fJsBkFx30iPEWMVimgTwyWsgHt1YN3zjoF nIrVPnYYGlet2PUep3Xqen87aX/Hc7wQk4W3KxDmKFAy+o+gaQrd8etz0iuuO7xdPAZK 06HXo01PNruud10fgVm5g9KGZtZ2uDJcrHgQ89BW5X7eMwt5gmnm5OHvfgPOc07RGWzs bw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vqswtte02-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:46 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98m3B076178; Thu, 24 Oct 2019 09:10:45 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2vtjkj2xjq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:45 +0000 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 x9O9AhQ0011882; Thu, 24 Oct 2019 09:10:43 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:43 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 22/49] multi-process: remote: use fd for socket from parent process Date: Thu, 24 Oct 2019 05:09:03 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 5b3ffd8..cb2829e 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -64,6 +64,7 @@ #include "block/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/log.h" +#include "qemu/cutils.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -440,6 +441,7 @@ finalize_loop: int main(int argc, char *argv[]) { Error *err = NULL; + int fd = -1; module_call_init(MODULE_INIT_QOM); @@ -462,7 +464,13 @@ int main(int argc, char *argv[]) return -1; } - mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO); + fd = qemu_parse_fd(argv[1]); + if (fd == -1) { + printf("Failed to parse fd for remote process.\n"); + return -EINVAL; + } + + mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); mpqemu_link_set_callback(mpqemu_link, process_msg); mpqemu_start_coms(mpqemu_link); From patchwork Thu Oct 24 09:09:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95FA71575 for ; Thu, 24 Oct 2019 09:25:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BDDF205F4 for ; Thu, 24 Oct 2019 09:25:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="N/Uob2or" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BDDF205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZMZ-00044M-PD for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43840) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ8w-0006vZ-Lu for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ8v-0004Nz-GI for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:54 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ8v-0004NI-8T for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:53 -0400 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 x9O94W6c116458; Thu, 24 Oct 2019 09:10:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=CfeS7iUSG1xTfxKr2e8mFCrwRrKlSOQSZckWDmK6o5k=; b=N/Uob2or97TR3xzlrHzsQPggk8JtEjnChajKXA3YMQ0ccN+RcN1QIX56IA8PVk1+9e3m brk1N/ZqXjyEna8Y5WrPny9yUbf/LAvekJYm5KarItW1AurvktTpM3gr3FTH3qQ5rXEG 3XHY4ncb1F07zIa3ID9qtS517PwLxtvs9+W13kyB2Yumvwhd/9NeqsE8dHmAxNL67oAV 5E1oX9I9oYW4qPjOJvsys3AUO/rgahmLhN94tDfNqE5H7EPah0DZUbsz9Whz0OzKm3ky zCv9i5kNCLvr+yxbZCUc2XsJp9Jf559fmgVrq5OOUl6+YsSRvCKzRubiv9e28TtW2bAS Rw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vqswtte07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:48 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97j1R170537; Thu, 24 Oct 2019 09:10:48 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2vtsk486v4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:47 +0000 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 x9O9AkAO002271; Thu, 24 Oct 2019 09:10:46 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:46 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 23/49] multi-process: remote: add create_done condition Date: Thu, 24 Oct 2019 05:09:04 -0400 Message-Id: <4f39a3190d10eef9341cc0b2b7a43f90ceeb17b2.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 cb2829e..80d8c02 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -68,6 +68,7 @@ static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; +bool create_done; static void process_config_write(MPQemuMsg *msg) { @@ -370,21 +371,31 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case INIT: break; case CONF_WRITE: - process_config_write(msg); + if (create_done) { + process_config_write(msg); + } + break; case CONF_READ: - process_config_read(msg); + if (create_done) { + process_config_read(msg); + } + break; case BAR_WRITE: - process_bar_write(msg, &err); - if (err) { - goto finalize_loop; + if (create_done) { + process_bar_write(msg, &err); + if (err) { + error_report_err(err); + } } break; case BAR_READ: - process_bar_read(msg, &err); - if (err) { - goto finalize_loop; + if (create_done) { + process_bar_read(msg, &err); + if (err) { + error_report_err(err); + } } break; case SYNC_SYSMEM: @@ -404,7 +415,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) qemu_mutex_lock_iothread(); qemu_run_machine_init_done_notifiers(); qemu_mutex_unlock_iothread(); - + create_done = true; break; case DRIVE_OPTS: if (setup_drive(msg, &err)) { From patchwork Thu Oct 24 09:09:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208649 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3E9F13B1 for ; Thu, 24 Oct 2019 09:27:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9DEE205F4 for ; Thu, 24 Oct 2019 09:27:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="rXL9PR2U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9DEE205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZPR-0007vQ-PJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:27:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43870) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ92-00079E-OY for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ91-0004RY-8n for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:00 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60128) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ91-0004R1-0b for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:10:59 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94M5L099569; Thu, 24 Oct 2019 09:10:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=2RV0rLeLn7ixv+eKg3++hWN0cSKoxiV00Wc1dRjZWg0=; b=rXL9PR2UXRB2lWaa9Vhe8OayNW7xZUgBzCxZ3XQW7b2gIHfVSdlqdVYKJMEF0autJ8hr EATLazjzeZc7bF6/M/pacrm6q+tkGcmLScrlu5CzlnxopPE/DRpnZvtvyJP/n63koD5h kwRZZY4SBupZ/5gzPa29Qky8UlEhZBJn1RpDEHKNj2ADsEbSOYiAtryhnHe+pRjK59RH 7yQriR/mAo7b+I02iFPoILs8ESL3QOww8jrDxqIIY3YbGCckgnXW2hEkPg+tt5GjPiJ4 rNrJVfn+ruEZe2WWdI1lKfpHESgofDgOecQRbLxbscqIVbYMwZDUBSSUBeT3kwxFulCM Eg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2aga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:50 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LEE047080; Thu, 24 Oct 2019 09:10:50 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu7cp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:50 +0000 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 x9O9Anwf002284; Thu, 24 Oct 2019 09:10:49 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:48 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 24/49] multi-process: add processing of remote drive and device command line Date: Thu, 24 Oct 2019 05:09:05 -0400 Message-Id: <14174d38d82e298f6c1d249b465be6735bcf53b2.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Add processing of command line options drive and device. After remote devices are created along with their proxies, signal the proxies to finish the configuration steps. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- v1 -> v2: - change command line option for remote process drive/device to use existing -drive/-device options - process drive and device options only after non-remote devices and drives are added vl.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/vl.c b/vl.c index 4489cfb..b19c57b 100644 --- a/vl.c +++ b/vl.c @@ -35,6 +35,11 @@ #include "sysemu/runstate.h" #include "sysemu/seccomp.h" #include "sysemu/tcg.h" +#include "qapi/qmp/qdict.h" +#include "block/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qlist.h" #ifdef CONFIG_SDL #if defined(__APPLE__) || defined(main) @@ -1136,11 +1141,45 @@ static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) #define MTD_OPTS "" #define SD_OPTS "" +#if defined(CONFIG_MPQEMU) +static int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, false /* this is drive */, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for drive."); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + +#if defined(CONFIG_MPQEMU) +static int pass; +#endif + static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) { BlockInterfaceType *block_default_type = opaque; +#if defined(CONFIG_MPQEMU) + const char *remote; + + remote = qemu_opt_get(opts, "remote"); + if (pass && remote) { + return rdrive_init_func(opaque, opts, errp); + } else { + if (!remote && !pass) { + drive_new(opts, *block_default_type, errp); + } + } + + return 0; +#else return drive_new(opts, *block_default_type, errp) == NULL; +#endif } static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) @@ -2199,10 +2238,35 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } +#if defined(CONFIG_MPQEMU) +static int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, true /* this is device */, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for device."); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; +#if defined(CONFIG_MPQEMU) + const char *remote; + + remote = qemu_opt_get(opts, "remote"); + if (remote) { + /* This will be a remote process */ + return rdevice_init_func(opaque, opts, errp); + } +#endif + dev = qdev_device_add(opts, errp); if (!dev) { return -1; @@ -4348,6 +4412,17 @@ int main(int argc, char **argv, char **envp) /* Check if IGD GFX passthrough. */ igd_gfx_passthru(); +#if defined(CONFIG_MPQEMU) + /* + * Parse the list for remote drives here as we launch PCIProxyDev here and + * need PCI host initialized. As a TODO: could defer init of PCIProxyDev instead. + */ + if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, + &machine_class->block_default_type, &error_fatal)) { + exit(0); + } +#endif + /* init generic devices */ rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), @@ -4405,6 +4480,9 @@ int main(int argc, char **argv, char **envp) qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); qemu_run_machine_init_done_notifiers(); +#if defined(CONFIG_MPQEMU) + qdev_proxy_fire(); +#endif if (rom_check_and_register_reset() != 0) { error_report("rom check and register reset failed"); exit(1); From patchwork Thu Oct 24 09:09:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208771 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 421B614ED for ; Thu, 24 Oct 2019 09:59:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0EA4520856 for ; Thu, 24 Oct 2019 09:59:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="eE01w91l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EA4520856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZtS-0001eS-LX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:58:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44441) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZB0-0003vk-Hz for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAz-0005eS-EM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:02 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:34638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAz-0005dN-6s for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:01 -0400 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 x9O94MaG094899; Thu, 24 Oct 2019 09:12:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=UCqtZIGXlcDh8wCI6QvJFE2Ebd8V/aXNkefNr+61NL8=; b=eE01w91ljJBc6g5mDv/SNn7a7dTTPKPygwZg1Q3XrJl0LUwTheM94hcXs18TIopxcdYg xmaqvmhkRapkXVo1L7pVT+EKdI1MMMgi+i7IJ3SZNrqpl0gEXS8SC100/JcQ09rTCaxV Drk1MwLKehVx9tUlwEXoBiBeQe3KnYMc9R0w/4SuHqp8FKTWlk0rSXFsPZ6j68oz5tbB YP53TwHBqI+76Gmt440BunCpxsRZgBAkZw9EPqZOeIUN3fvWoIa/NW5B7P6zOOZz5Nkq 7KpM88nRktFCwydeiBn1oyICB7rzq474JtFvHitJuai3218mMAzHzlhx7MiUhCKQP7Dz ug== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r24yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:53 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Ld5047105; Thu, 24 Oct 2019 09:10:53 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2vu0fnu7e7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:52 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9AqvV023684; Thu, 24 Oct 2019 09:10:52 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:51 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 25/49] multi-process: Introduce build flags to separate remote process code Date: Thu, 24 Oct 2019 05:09:06 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Introduce SCSI_PROCESS & REMOTE_PROCESS build flags to separate code that applies only to remote processes. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 Makefile.target | 4 ++++ rules.mak | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.target b/Makefile.target index f16b74a..0ca40f1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -255,6 +255,10 @@ ifdef CONFIG_DARWIN $(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@") endif +ifdef CONFIG_MPQEMU +$(SCSI_DEV_BUILD): REMOTE_FLAGS = -DREMOTE_PROCESS -DSCSI_PROCESS +endif + $(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS) $(call LINK, $(filter-out %.mak, $^)) ifdef CONFIG_DARWIN diff --git a/rules.mak b/rules.mak index 967295d..22e0c36 100644 --- a/rules.mak +++ b/rules.mak @@ -67,7 +67,7 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \ %.o: %.c $(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \ - $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \ + $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) $(REMOTE_FLAGS) \ -c -o $@ $<,"CC","$(TARGET_DIR)$@") %.o: %.rc $(call quiet-command,$(WINDRES) -I. -o $@ $<,"RC","$(TARGET_DIR)$@") From patchwork Thu Oct 24 09:09:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E2161575 for ; Thu, 24 Oct 2019 09:27:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E74F9205F4 for ; Thu, 24 Oct 2019 09:27:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gVakvjja" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E74F9205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZOh-00071E-Hq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:27:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43885) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ96-0007I0-SA for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ94-0004TU-LZ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:04 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ94-0004Sw-D1 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:02 -0400 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 x9O94MPp116313; Thu, 24 Oct 2019 09:10:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=sgMemPOl/4H/fHQ4UwUnEVHRG4sm2LyVV8+0h4UkJhY=; b=gVakvjja3oEUsWrzTRYx+cRzydQbqCG+fm9/AYKQYv5n1dk/a7VDCZastAhWdZL1WfH4 I9qxgROd2eUgrEtFgDgiF/e5S5ZAAOUcvNEaSVCSQ3jbkU4gvRCQEhk/iR1MHBx5FtVR vZk1irrdoeI5XGwU+8z6CD1VS6OrfRs7IUSn9E9jA5zNp+OaJR9zhxGBxh/ixmkrqlFh lX+h+V10n/5h+uXebQiK8GUyQLvnSQI8YafoZ/TgDReX/awGYzdLkn5Qst5NthnooA7I U2rfB3xgTXgZz5juMcU0sg5wY9t89nHLH4kRonHQiGpkuh4VDJFyjIO3suNNcoHuzLug +w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2vqswtte0s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:57 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Mr5047255; Thu, 24 Oct 2019 09:10:56 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu7h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:10:56 +0000 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 x9O9At7r002316; Thu, 24 Oct 2019 09:10:55 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:54 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 26/49] multi-process: refractor vl.c code to re-use in remote Date: Thu, 24 Oct 2019 05:09:07 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 Makefile.objs | 2 + remote/Makefile.objs | 1 + vl-parse.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 152 +------------------------------------------------ vl.h | 54 ++++++++++++++++++ 5 files changed, 216 insertions(+), 151 deletions(-) create mode 100644 vl-parse.c create mode 100644 vl.h diff --git a/Makefile.objs b/Makefile.objs index c2ac261..c23ccaa 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -104,6 +104,8 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS) common-obj-$(CONFIG_FDT) += device_tree.o +common-obj-y += vl-parse.o + ###################################################################### # qapi diff --git a/remote/Makefile.objs b/remote/Makefile.objs index cbb3065..c1349ad 100644 --- a/remote/Makefile.objs +++ b/remote/Makefile.objs @@ -2,3 +2,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o +remote-pci-obj-$(CONFIG_MPQEMU) +=../vl-parse.o diff --git a/vl-parse.c b/vl-parse.c new file mode 100644 index 0000000..4e2bd7c --- /dev/null +++ b/vl-parse.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "monitor/qdev.h" +#include "monitor/qdev.h" +#include "sysemu/sysemu.h" +#include "sysemu/runstate.h" +#include "qemu/option.h" +#include "qemu-options.h" +#include "sysemu/blockdev.h" + +#include "chardev/char.h" +#include "monitor/monitor.h" +#include "qemu/config-file.h" + +#include "sysemu/arch_init.h" + +#include "vl.h" + +/***********************************************************/ +/* QEMU Block devices */ + +static const QEMUOption qemu_options[] = { + { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, +#define QEMU_OPTIONS_GENERATE_OPTIONS +#include "qemu-options-wrapper.h" + { NULL }, +}; + +const QEMUOption *lookup_opt(int argc, char **argv, + const char **poptarg, int *poptind) +{ + const QEMUOption *popt; + int optind = *poptind; + char *r = argv[optind]; + const char *optarg; + + loc_set_cmdline(argv, optind, 1); + optind++; + /* Treat --foo the same as -foo. */ + if (r[1] == '-') { + r++; + } + popt = qemu_options; + if (!popt) { + error_report("No valide qemu_options"); + } + for (;;) { + if (!popt->name) { + error_report("invalid option*"); + exit(1); + popt++; + continue; + } + if (!strcmp(popt->name, r + 1)) { + break; + } + popt++; + } + if (popt->flags & HAS_ARG) { + if (optind >= argc) { + error_report("optind %d, argc %d", optind, argc); + error_report("requires an argument"); + exit(1); + } + optarg = argv[optind++]; + loc_set_cmdline(argv, optind - 2, 2); + } else { + optarg = NULL; + } + + *poptarg = optarg; + *poptind = optind; + + return popt; +} + +int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + BlockInterfaceType *block_default_type = opaque; + + if (!drive_new(opts, *block_default_type, errp)) { + error_report_err(*errp); + } + + return 0; +} + +#if defined(CONFIG_MPQEMU) +int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, false /* this is drive */, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for drive."); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + +#if defined(CONFIG_MPQEMU) +int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, true /* this is device */, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for device."); + return -1; + } + return 0; +} +#endif + +int device_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + const char *remote = NULL; + + remote = qemu_opt_get(opts, "rid"); + if (remote) { + return 0; + } + + dev = qdev_device_add(opts, errp); + if (!dev) { + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} diff --git a/vl.c b/vl.c index b19c57b..3fef694 100644 --- a/vl.c +++ b/vl.c @@ -40,6 +40,7 @@ #include "qapi/qmp/qstring.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" +#include "vl.h" #ifdef CONFIG_SDL #if defined(__APPLE__) || defined(main) @@ -1134,54 +1135,6 @@ static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp) /***********************************************************/ /* QEMU Block devices */ -#define HD_OPTS "media=disk" -#define CDROM_OPTS "media=cdrom" -#define FD_OPTS "" -#define PFLASH_OPTS "" -#define MTD_OPTS "" -#define SD_OPTS "" - -#if defined(CONFIG_MPQEMU) -static int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - DeviceState *dev; - - dev = qdev_remote_add(opts, false /* this is drive */, errp); - if (!dev) { - error_setg(errp, "qdev_remote_add failed for drive."); - return -1; - } - object_unref(OBJECT(dev)); - return 0; -} -#endif - -#if defined(CONFIG_MPQEMU) -static int pass; -#endif - -static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - BlockInterfaceType *block_default_type = opaque; - -#if defined(CONFIG_MPQEMU) - const char *remote; - - remote = qemu_opt_get(opts, "remote"); - if (pass && remote) { - return rdrive_init_func(opaque, opts, errp); - } else { - if (!remote && !pass) { - drive_new(opts, *block_default_type, errp); - } - } - - return 0; -#else - return drive_new(opts, *block_default_type, errp) == NULL; -#endif -} - static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) { if (qemu_opt_get(opts, "snapshot") == NULL) { @@ -1877,21 +1830,6 @@ static void help(int exitcode) exit(exitcode); } -#define HAS_ARG 0x0001 - -typedef struct QEMUOption { - const char *name; - int flags; - int index; - uint32_t arch_mask; -} QEMUOption; - -static const QEMUOption qemu_options[] = { - { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, -#define QEMU_OPTIONS_GENERATE_OPTIONS -#include "qemu-options-wrapper.h" - { NULL }, -}; typedef struct VGAInterfaceInfo { const char *opt_name; /* option name */ @@ -2238,43 +2176,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } -#if defined(CONFIG_MPQEMU) -static int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - DeviceState *dev; - - dev = qdev_remote_add(opts, true /* this is device */, errp); - if (!dev) { - error_setg(errp, "qdev_remote_add failed for device."); - return -1; - } - object_unref(OBJECT(dev)); - return 0; -} -#endif - -static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - DeviceState *dev; - -#if defined(CONFIG_MPQEMU) - const char *remote; - - remote = qemu_opt_get(opts, "remote"); - if (remote) { - /* This will be a remote process */ - return rdevice_init_func(opaque, opts, errp); - } -#endif - - dev = qdev_device_add(opts, errp); - if (!dev) { - return -1; - } - object_unref(OBJECT(dev)); - return 0; -} - static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; @@ -2604,46 +2505,6 @@ static void qemu_run_machine_init_done_notifiers(void) notifier_list_notify(&machine_init_done_notifiers, NULL); } -static const QEMUOption *lookup_opt(int argc, char **argv, - const char **poptarg, int *poptind) -{ - const QEMUOption *popt; - int optind = *poptind; - char *r = argv[optind]; - const char *optarg; - - loc_set_cmdline(argv, optind, 1); - optind++; - /* Treat --foo the same as -foo. */ - if (r[1] == '-') - r++; - popt = qemu_options; - for(;;) { - if (!popt->name) { - error_report("invalid option"); - exit(1); - } - if (!strcmp(popt->name, r + 1)) - break; - popt++; - } - if (popt->flags & HAS_ARG) { - if (optind >= argc) { - error_report("requires an argument"); - exit(1); - } - optarg = argv[optind++]; - loc_set_cmdline(argv, optind - 2, 2); - } else { - optarg = NULL; - } - - *poptarg = optarg; - *poptind = optind; - - return popt; -} - static MachineClass *select_machine(void) { GSList *machines = object_class_get_list(TYPE_MACHINE, false); @@ -4412,17 +4273,6 @@ int main(int argc, char **argv, char **envp) /* Check if IGD GFX passthrough. */ igd_gfx_passthru(); -#if defined(CONFIG_MPQEMU) - /* - * Parse the list for remote drives here as we launch PCIProxyDev here and - * need PCI host initialized. As a TODO: could defer init of PCIProxyDev instead. - */ - if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, - &machine_class->block_default_type, &error_fatal)) { - exit(0); - } -#endif - /* init generic devices */ rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), diff --git a/vl.h b/vl.h new file mode 100644 index 0000000..8c40fed --- /dev/null +++ b/vl.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef VL_H +#define VL_H + +/***********************************************************/ +/* QEMU Block devices */ + +#define HD_OPTS "media=disk" +#define CDROM_OPTS "media=cdrom" +#define FD_OPTS "" +#define PFLASH_OPTS "" +#define MTD_OPTS "" +#define SD_OPTS "" + + +#define HAS_ARG 0x0001 +typedef struct QEMUOption { + const char *name; + int flags; + int index; + uint32_t arch_mask; +} QEMUOption; + +const QEMUOption *lookup_opt(int argc, char **argv, + const char **poptarg, int *poptind); + +int drive_init_func(void *opaque, QemuOpts *opts, Error **errp); +int device_init_func(void *opaque, QemuOpts *opts, Error **errp); +int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp); +int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp); + +#endif /* VL_H */ + From patchwork Thu Oct 24 09:09:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79AEA13B1 for ; Thu, 24 Oct 2019 09:29:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C599205F4 for ; Thu, 24 Oct 2019 09:29:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dZxIjkC6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C599205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZQs-0001RB-R8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43905) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ99-0007Nn-OQ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ98-0004Vi-Ot for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:07 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:60984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ98-0004VB-FX for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:06 -0400 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 x9O94LRw094842; Thu, 24 Oct 2019 09:11:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=C7lsCetm1EC2M2RQ2S0xlTKBg1MaEOc5TwxwRSzkXS4=; b=dZxIjkC6uUykfd+L8O0XFIssUbqTtpDsoHb60n3urVaQskJLsXb9XdUBHEgqB0kfDOnG p2HAcNHDM6sG2CJeYjBBnNdZPXNB2M1m2wQUg+9U236PsVWwtnXjNNfeArZhSh2psh3V 4CK9Ei4U+nzi+rUhMMPc8Lo6lUmg5uvBnamWYRe1ZrlUQuRM3Q2yIeq/RuDMXtjsGH+9 G4IXZxoY3sicFtULvkV3QYr+W9eVoOegAXiLV6Q4fXQMK+uKJhrjm/OtqQ0Ck8OAnydw ue5fdfemullsPusyMYCgKjGMfTN5zEbJNkIcW+QpTBiPY76gup0qKQNspN7Qk/fMtKlY Dw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2vqu4r24q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:00 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jTc170559; Thu, 24 Oct 2019 09:11:00 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2vtsk487c2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:00 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9Awet023719; Thu, 24 Oct 2019 09:10:58 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:10:57 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 27/49] multi-process: add remote option Date: Thu, 24 Oct 2019 05:09:08 -0400 Message-Id: <191f2d86c1d329618c688c2e8ba964a9ff680d77.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 qemu-options.hx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index 996b6fb..4734e8e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -27,6 +27,27 @@ STEXI Display version information and exit ETEXI +DEF("remote", HAS_ARG, QEMU_OPTION_remote, + "-remote socket[,prop[=value][,...]]\n" + " add remote process\n" + " prop=value,... sets driver properties\n" + " use '-remote help' to print all possible properties\n", + QEMU_ARCH_ALL) +STEXI +@table @option +@item rid +@findex -rid +remote id +@item socket +@findex -socket +Remote process socket +@item command +@findex -command +Remote process command. + +@end table +ETEXI + DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ "-machine [type=]name[,prop[=value][,...]]\n" " selects emulated machine ('-machine help' for list)\n" From patchwork Thu Oct 24 09:09:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208663 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 952EA14E5 for ; Thu, 24 Oct 2019 09:33:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6B49C20684 for ; Thu, 24 Oct 2019 09:33:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="WeaC1lga" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B49C20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZUR-0005wi-Pv for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:33:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43927) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9C-0007Sm-67 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9A-0004Ws-LO for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:10 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:32780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9A-0004WG-DA for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:08 -0400 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 x9O94Vn4095033; Thu, 24 Oct 2019 09:11:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=WdNHLITfvrDzd4lPC3KUZPeX615xYutVUcbkqIUk008=; b=WeaC1lgaUhlIATNVILeX3FC1mw3nAaXQoEOnhzfOl+dSoZ8SV86aBii22cknfhfz+Z/p K5WUt9fROThLf22KIQsH2k/ppi6JViCIc7lLcLxB95oGq4L0PmpG8yoG33OHcoSS8gH3 K8R4RBkDz/rouIflsnkn/7Q4QjB5oNENfYde2NFCeacjWWK83CC17BX2+i0DQDPI8ijv TKegYJrvu7Cii6WquhAXOyry+mpQyoRIDwJmqYdHzyQfLL9JBK8mfujvRJCBHdtI5R+o s3k7saunynxtmHZXiF3FVvtkt1QeKsiQ1LXkq6QyqyCly5t/iBDE7/ZzoEMsg/ktRiM4 6w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24q7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:03 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98m8k076179; Thu, 24 Oct 2019 09:11:02 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2vtjkj2y70-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:02 +0000 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 x9O9B0oI012041; Thu, 24 Oct 2019 09:11:00 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:00 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 28/49] multi-process: add remote options parser Date: Thu, 24 Oct 2019 05:09:09 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 vl.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/vl.c b/vl.c index 3fef694..1417ff2 100644 --- a/vl.c +++ b/vl.c @@ -280,6 +280,28 @@ static QemuOptsList qemu_option_rom_opts = { }, }; +static QemuOptsList qemu_remote_opts = { + .name = "remote", + .head = QTAILQ_HEAD_INITIALIZER(qemu_remote_opts.head), + .desc = { + { + .name = "rid", + .type = QEMU_OPT_NUMBER, + .help = "id of the remote process" + },{ + .name = "socket", + .type = QEMU_OPT_NUMBER, + .help = "Socket for remote", + },{ + .name = "command", + .type = QEMU_OPT_STRING, + .help = "command to run", + }, + { /* end of list */ } + }, +}; + + static QemuOptsList qemu_machine_opts = { .name = "machine", .implied_opt_name = "type", @@ -347,6 +369,87 @@ static QemuOptsList qemu_boot_opts = { }, }; +#if defined(CONFIG_MPQEMU) +static int device_remote_add(void *opaque, QemuOpts *opts, Error **errp) +{ + unsigned int rid = *(unsigned int *)opaque; + const char *opt_rid = NULL; + struct remote_process *p = NULL;; + + opt_rid = qemu_opt_get(opts, "rid"); + if (!opt_rid) { + return 0; + } + + p = get_remote_process_rid(rid); + if (!p) { + return -EINVAL; + } + + if (atoi(opt_rid) == rid) { + qemu_opt_set(opts, "command", p->command, errp); + rdevice_init_func(opaque, opts, errp); + qemu_opts_del(opts); + } + return 0; +} + +static int parse_remote(void *opaque, QemuOpts *opts, Error **errp) +{ + int rid; + int socket; + char *c_sock; + const char *command = NULL; + struct remote_process r_proc; + + rid = atoi(qemu_opt_get(opts, "rid")); + if (rid < 0) { + error_setg(errp, "rid is required."); + return -1; + } + if (get_remote_process_rid(rid)) { + error_setg(errp, "There is already process with rid %d", rid); + goto cont_devices; + } + + c_sock = (char *)qemu_opt_get(opts, "socket"); + if (c_sock) { + socket = atoi(c_sock); + } else { + socket = -1; + } + + command = qemu_opt_get(opts, "command"); + + if (socket <= STDERR_FILENO && socket != -1) { + socket = -1; + } + + if (!command && socket < 0) { + error_setg(errp, "No correct socket or command defined for remote."); + return -1; + } + + if (rid < 0) { + error_setg(errp, "id option is required and must be non-negative"); + return -1; + } + r_proc.rid = rid; + r_proc.socket = socket; + r_proc.command = g_strdup(command); + remote_process_register(&r_proc); + + cont_devices: + if (qemu_opts_foreach(qemu_find_opts("device"), device_remote_add, + &rid, NULL)) { + error_setg(errp, "Could not process some of the remote devices."); + } + + return 0; +} + +#endif + static QemuOptsList qemu_add_fd_opts = { .name = "add-fd", .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), @@ -2826,6 +2929,7 @@ int main(int argc, char **argv, char **envp) qemu_add_opts(&qemu_icount_opts); qemu_add_opts(&qemu_semihosting_config_opts); qemu_add_opts(&qemu_fw_cfg_opts); + qemu_add_opts(&qemu_remote_opts); module_call_init(MODULE_INIT_OPTS); runstate_init(); @@ -3678,6 +3782,14 @@ int main(int argc, char **argv, char **envp) exit(1); #endif break; + case QEMU_OPTION_remote: + opts = qemu_opts_parse_noisily(qemu_find_opts("remote"), + optarg, false); + if (!opts) { + exit(1); + } + break; + case QEMU_OPTION_object: opts = qemu_opts_parse_noisily(qemu_find_opts("object"), optarg, true); @@ -4278,6 +4390,11 @@ int main(int argc, char **argv, char **envp) qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, &error_fatal); +#ifdef CONFIG_MPQEMU + qemu_opts_foreach(qemu_find_opts("remote"), + parse_remote, NULL, &error_fatal); +#endif + cpu_synchronize_all_post_init(); rom_reset_order_override(); From patchwork Thu Oct 24 09:09:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84F2414ED for ; Thu, 24 Oct 2019 10:02:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 596B3205F4 for ; Thu, 24 Oct 2019 10:02:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="QyFxe7Ky" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 596B3205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZxF-0002ND-P3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 06:02:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44471) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZBD-0004ij-L0 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZBB-0005ka-Jk for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:15 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:47760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZBB-0005k2-9D for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:13 -0400 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 x9O94TXq116427; Thu, 24 Oct 2019 09:13:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=+IofknBIwPgPORHY2P8DEFy8k8iedsHT13hsizFpthU=; b=QyFxe7KyNNRUOU+NmwAiF0WjCwtVDYquUWYmHkMHpijeCk0hbqtmZv9JCirtCrP6t6iA idnERzimuiuU11eNPOc7fKnSaORH91YApszhQp0c4wXWf6XGMqUjDMOhFjRFC6gllrf2 M9fCdOGcuQaZMrCFp256kndGP6NoYaLU6si0S0B0cktnKSyf3wI1TweDwUtJ8OWZ3WCg QqtXapgtuDzJLnFBn/ogv9bE2tgoN0DH/2CMEudwNB5PLAnLijDxzBgNQFgdWAPpd5Iy I8ka0VlzFJEdd8K1qu+lZC9SV0Q4k/QTdyXwfJhkumwz6qYBMA+XsZO4mnziA4a5P5YH 3A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vqswttebd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:13:06 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O991ZB077488; Thu, 24 Oct 2019 09:11:06 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2vtjkj2yaa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:06 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9B4CX009509; Thu, 24 Oct 2019 09:11:04 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:04 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 29/49] multi-process: add parse_cmdline in remote process Date: Thu, 24 Oct 2019 05:09:10 -0400 Message-Id: <57a23f03088dd5036cf432737ee11229a6ea9644.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 remote/Makefile.objs | 1 + remote/remote-main.c | 11 +++++ remote/remote-opts.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ remote/remote-opts.h | 31 ++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 remote/remote-opts.c create mode 100644 remote/remote-opts.h diff --git a/remote/Makefile.objs b/remote/Makefile.objs index c1349ad..a677fce 100644 --- a/remote/Makefile.objs +++ b/remote/Makefile.objs @@ -1,4 +1,5 @@ remote-pci-obj-$(CONFIG_MPQEMU) += remote-main.o +remote-pci-obj-$(CONFIG_MPQEMU) += remote-opts.o remote-pci-obj-$(CONFIG_MPQEMU) += pcihost.o remote-pci-obj-$(CONFIG_MPQEMU) += machine.o remote-pci-obj-$(CONFIG_MPQEMU) += iohub.o diff --git a/remote/remote-main.c b/remote/remote-main.c index 80d8c02..729f7e9 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -65,6 +65,7 @@ #include "qapi/qmp/qlist.h" #include "qemu/log.h" #include "qemu/cutils.h" +#include "remote-opts.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -469,6 +470,13 @@ int main(int argc, char *argv[]) current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE))); + qemu_add_opts(&qemu_device_opts); + qemu_add_opts(&qemu_drive_opts); + qemu_add_drive_opts(&qemu_legacy_drive_opts); + qemu_add_drive_opts(&qemu_common_drive_opts); + qemu_add_drive_opts(&qemu_drive_opts); + qemu_add_drive_opts(&bdrv_runtime_opts); + mpqemu_link = mpqemu_link_create(); if (!mpqemu_link) { printf("Could not create MPQemu link\n"); @@ -482,6 +490,9 @@ int main(int argc, char *argv[]) } mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); + + parse_cmdline(argc - 2, argv + 2, NULL); + mpqemu_link_set_callback(mpqemu_link, process_msg); mpqemu_start_coms(mpqemu_link); diff --git a/remote/remote-opts.c b/remote/remote-opts.c new file mode 100644 index 0000000..0ebe6b1 --- /dev/null +++ b/remote/remote-opts.c @@ -0,0 +1,115 @@ +/* + * Remote device initialization + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#include + +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu-common.h" + +#include "remote/pcihost.h" +#include "remote/machine.h" +#include "hw/boards.h" +#include "hw/qdev-core.h" +#include "qemu/main-loop.h" +#include "remote/memory.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu-options.h" +#include "sysemu/arch_init.h" + +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qobject.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "monitor/qdev.h" +#include "qapi/qmp/qdict.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" +#include "block/block.h" +#include "remote/remote-opts.h" +#include "include/qemu-common.h" + +#include "vl.h" +/* + * In remote process, we parse only subset of options. The code + * taken from vl.c to re-use in remote command line parser. + */ +void parse_cmdline(int argc, char **argv, char **envp) +{ + int optind; + const char *optarg; + MachineClass *mc; + + /* from vl.c */ + optind = 0; + + /* second pass of option parsing */ + + for (;;) { + if (optind >= argc) { + break; + } + if (argv[optind][0] != '-') { + loc_set_cmdline(argv, optind, 1); + drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); + } else { + const QEMUOption *popt; + + popt = lookup_opt(argc, argv, &optarg, &optind); + #ifndef REMOTE_PROCESS + if (!(popt->arch_mask & arch_type)) { + error_report("Option not supported for this target, %x arch_mask, %x arch_type", + popt->arch_mask, arch_type); + exit(1); + } + #endif + switch (popt->index) { + case QEMU_OPTION_drive: + if (drive_def(optarg) == NULL) { + fprintf(stderr, "Could not init drive\n"); + exit(1); + } + break; + default: + break; + } + } + } + mc = MACHINE_GET_CLASS(current_machine); + + mc->block_default_type = IF_IDE; + if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, + &mc->block_default_type, &error_fatal)) { + /* We printed help */ + exit(0); + } + + return; +} diff --git a/remote/remote-opts.h b/remote/remote-opts.h new file mode 100644 index 0000000..e15c29b --- /dev/null +++ b/remote/remote-opts.h @@ -0,0 +1,31 @@ +/* + * Remote device initialization + * + * Copyright 2019, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef REMOTE_OPTS_H +#define REMOTE_OPTS_H + +void parse_cmdline(int argc, char **argv, char **envp); + +#endif + From patchwork Thu Oct 24 09:09:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208661 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C62571575 for ; Thu, 24 Oct 2019 09:31:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C7E220684 for ; Thu, 24 Oct 2019 09:31:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="WlXgIuAs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C7E220684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZSl-00045d-WA for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:31:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43948) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9J-0007kH-MP for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9I-0004ax-91 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:17 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9I-0004aR-0Y for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:16 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94PLv099615; Thu, 24 Oct 2019 09:11:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=ebV6oC/8fSrgf06J90TefQwjgoQsuTXaEyR97j528Es=; b=WlXgIuAsgj1b+ry0nmPCphS1aNslFh66yufRnFiaSDJBui7PuHsUh9NoHJcWOL5oXAhk zkM3yoL+1oHFUckZEADgR4O3ipRRFzzxwdI3ZAQmLLX4+3x0h8SPnCjEFZULdPnUefLH AADpj5jLWiB03v8AYw4pYaPozgWhi1laT7VubqE1R71RMarq4VMjP+BMXAhNHNTQKioX Nbz6nbrP6u0YoXGylhSGKO3n6r3ficeqChRS1HulITduTRDG6Mfn2RJeM9Xg0CzSlXpD Ko0QPHuyao+DLizR02l9SvuM2cyAhZTaKggovsgn0K2HAogldipcOtqplYgldn57YLCs Sw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2ahf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:10 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98MBg047206; Thu, 24 Oct 2019 09:11:09 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2vu0fnu7y2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:09 +0000 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 x9O9B7lM012080; Thu, 24 Oct 2019 09:11:07 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:07 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 30/49] multi-process: send heartbeat messages to remote Date: Thu, 24 Oct 2019 05:09:11 -0400 Message-Id: <14c33104778e77fcf2e7f0df2a1dd96fbcaf49d7.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=931 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva In order to detect remote processes which are hung, the proxy periodically sends heartbeat messages to confirm if the remote process is alive Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hw/proxy/qemu-proxy.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 2 files changed, 102 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index fc1c731..691b991 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -53,14 +53,96 @@ #include "hw/boards.h" #include "include/qemu/log.h" +QEMUTimer *hb_timer; static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); static void setup_irqfd(PCIProxyDev *dev); +static void pci_dev_exit(PCIDevice *dev); +static void start_heartbeat_timer(void); +static void stop_heartbeat_timer(void); +static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx); +static void broadcast_msg(MPQemuMsg *msg, bool need_reply); + +static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx) +{ + /* TODO: Add proper handler. */ + printf("Child (pid %d) is dead? Signal is %d, Exit code is %d.\n", + siginfo->si_pid, siginfo->si_signo, siginfo->si_code); +} + +static void broadcast_msg(MPQemuMsg *msg, bool need_reply) +{ + PCIProxyDev *entry; + unsigned int pid; + int wait; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (need_reply) { + wait = eventfd(0, EFD_NONBLOCK); + msg->num_fds = 1; + msg->fds[0] = wait; + } + + mpqemu_msg_send(entry->mpqemu_link, msg, entry->mpqemu_link->com); + if (need_reply) { + pid = (uint32_t)wait_for_remote(wait); + close(wait); + /* TODO: Add proper handling. */ + if (pid) { + need_reply = 0; + } + } + } +} + +#define NOP_INTERVAL 1000000 + +static void remote_ping(void *opaque) +{ + MPQemuMsg msg; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.num_fds = 0; + msg.cmd = PROXY_PING; + msg.bytestream = 0; + msg.size = 0; + + broadcast_msg(&msg, true); + timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); + +} + +void start_heartbeat_timer(void) +{ + hb_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, + remote_ping, + &proxy_dev_list); + timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); + +} + +static void stop_heartbeat_timer(void) +{ + timer_del(hb_timer); + timer_free(hb_timer); +} + +static void set_sigchld_handler(void) +{ + struct sigaction sa_sigterm; + memset(&sa_sigterm, 0, sizeof(sa_sigterm)); + sa_sigterm.sa_sigaction = childsig_handler; + sa_sigterm.sa_flags = SA_SIGINFO | SA_NOCLDWAIT | SA_NOCLDSTOP; + sigaction(SIGCHLD, &sa_sigterm, NULL); +} static void proxy_ready(PCIDevice *dev) { PCIProxyDev *pdev = PCI_PROXY_DEV(dev); setup_irqfd(pdev); + set_sigchld_handler(); + start_heartbeat_timer(); } static void set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) @@ -259,6 +341,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->realize = pci_proxy_dev_realize; + k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; } @@ -397,6 +480,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->proxy_ready = proxy_ready; } +static void pci_dev_exit(PCIDevice *pdev) +{ + PCIProxyDev *entry, *sentry; + PCIProxyDev *dev = PCI_PROXY_DEV(pdev); + + stop_heartbeat_timer(); + + QLIST_FOREACH_SAFE(entry, &proxy_dev_list.devices, next, sentry) { + if (entry->remote_pid == dev->remote_pid) { + QLIST_REMOVE(entry, next); + } + } + + if (!QLIST_EMPTY(&proxy_dev_list.devices)) { + start_heartbeat_timer(); + } +} + static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, bool write, hwaddr addr, uint64_t *val, unsigned size, bool memory) diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 3145b0e..16a913b 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -72,6 +72,7 @@ typedef enum { DRIVE_OPTS, DEVICE_ADD, DEVICE_DEL, + PROXY_PING, MAX, } mpqemu_cmd_t; From patchwork Thu Oct 24 09:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2516112C for ; Thu, 24 Oct 2019 09:35:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 984EC20684 for ; Thu, 24 Oct 2019 09:35:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qWWeaH/p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 984EC20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZWK-0000QN-R5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43960) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9L-0007no-At for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9K-0004c0-6b for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:19 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:45944) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9J-0004bX-Uv for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:18 -0400 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 x9O94MUg116335; Thu, 24 Oct 2019 09:11:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=kNf0hq9f/SIPtu9i0nQfYDvJHnVFSoyJ64lIyw2OYHI=; b=qWWeaH/pusbSkeghnWLlVycQVBkIdJYIE5Vgq/UpUJuAXihND0F+xIfCNNZVlvZPpdY8 HdvOwibP2yRK9be/s02P3r0kow9xZxE9VWvLYvuv3rDZzHnZIEbjESZ/RUPM6qqCznrO g962N2YZZcHzGxXhMvkcHhYLS/3i5rnqLgERiDlU71zE9yfTGFhtS56uAbqHPol/dPpj Qldc/V9NqKb3qi7fT84siEwdFDJHQOsxjcP+hWDnvr1CxMziUc+bbOP79iZQNv7PlNd9 ar6qol8JymA+F9vJQS97+f60uQYeLmmKopjCXOQxb7wFZV5AKQ36Q6TXKQ4LJ20HTzEU zQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2vqswtte1w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:12 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O991ZG077488; Thu, 24 Oct 2019 09:11:12 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vtjkj2yh1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:12 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BAqk023822; Thu, 24 Oct 2019 09:11:10 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:10 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 31/49] multi-process: handle heartbeat messages in remote process Date: Thu, 24 Oct 2019 05:09:12 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva If the remote process is alive, it responds to proxy's heartbeat messages 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 729f7e9..27e4492 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -355,6 +355,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; Error *err = NULL; + int wait; if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) { error_setg(&err, "socket closed, cond is %d", cond); @@ -434,6 +435,11 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case DEVICE_DEL: process_device_del_msg(msg); break; + case PROXY_PING: + wait = msg->fds[0]; + notify_proxy(wait, (uint32_t)getpid()); + PUT_REMOTE_WAIT(wait); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:09:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 261EC13B1 for ; Thu, 24 Oct 2019 09:26:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F0096205F4 for ; Thu, 24 Oct 2019 09:26:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="llIZWlyM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0096205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZOC-0006Lu-MV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:26:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43978) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9R-0007yt-3t for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9P-0004ek-Ha for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:25 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9P-0004eD-8r for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:23 -0400 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 x9O94MsZ094853; Thu, 24 Oct 2019 09:11:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=l66KlTAWkx0rgCkIPA/MorNRjDtMjhAx90rI/SU9Rmw=; b=llIZWlyMiAoZv8TkzRvloRF3RBx3ujdDXKugadF0v+IiCVnJSwyao9pmTJhDG9eyhsGi sKEcjKvBA7B0TMLdv4UFBzcgf3u9ezk4nwIBa+fWQp8NqwuatBnztHFF11sLu7oYsvFZ UK8WdESP4it3TVIZ4oaA58cNGMdAUDdOwPmtrrxn1nOZ18I2oGwdqKw3AQ1KL/FiBQql N3oe3cYWF1ivBKraVuYNb37HVUVDLRz4xV8FPt0o7zcIryo+lQMTvLfpwGRAnqHhb4hZ kGL1GX4dSC6Scra0VDgoM7w38ljcxHuFIqGw0rxKxo5s4Y9sG66gpbcZTu/0dDc3aWvC SQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24r2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:16 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98mPR076184; Thu, 24 Oct 2019 09:11:15 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2vtjkj2ymu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:15 +0000 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 x9O9BDZr012107; Thu, 24 Oct 2019 09:11:13 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:13 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 32/49] multi-process: Use separate MMIO communication channel Date: Thu, 24 Oct 2019 05:09:13 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Using a separate communication channel for MMIO helps with improving Performance Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- New patch in v3 hw/proxy/qemu-proxy.c | 39 +++++++++++++++++++++++++++------------ include/hw/proxy/qemu-proxy.h | 1 + include/io/mpqemu-link.h | 7 +++++++ io/mpqemu-link.c | 2 ++ qdev-monitor.c | 1 + remote/remote-main.c | 18 +++++++++++++----- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 691b991..74aecd3 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -201,20 +201,22 @@ static int make_argv(char *command_str, char **argv, int argc) int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) { pid_t rpid; - int fd[2] = {-1, -1}; + int fd[2], mmio[2]; Error *local_error = NULL; char *argv[64]; int argc = 0, _argc; char *sfd; char *exec_dir; int rc = -EINVAL; + struct timeval timeout = {.tv_sec = 10, .tv_usec = 0}; if (pdev->managed) { /* Child is forked by external program (such as libvirt). */ return rc; } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) || + socketpair(AF_UNIX, SOCK_STREAM, 0, mmio)) { error_setg(errp, "Unable to create unix socket."); return rc; } @@ -222,6 +224,8 @@ int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) argc = add_argv(exec_dir, argv, argc); sfd = g_strdup_printf("%d", fd[1]); argc = add_argv(sfd, argv, argc); + sfd = g_strdup_printf("%d", mmio[1]); + argc = add_argv(sfd, argv, argc); _argc = argc; argc = make_argv((char *)command, argv, argc); @@ -231,22 +235,32 @@ int remote_spawn(PCIProxyDev *pdev, const char *command, Error **errp) if (rpid == -1) { error_setg(errp, "Unable to spawn emulation program."); close(fd[0]); + close(mmio[0]); goto fail; } if (rpid == 0) { close(fd[0]); + close(mmio[0]); execvp(argv[0], (char *const *)argv); exit(1); } pdev->remote_pid = rpid; pdev->rsocket = fd[1]; pdev->socket = fd[0]; + pdev->mmio_sock = mmio[0]; + + if (setsockopt(mmio[0], SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, + sizeof(timeout)) < 0) { + error_setg(errp, "Unable to set timeout for socket"); + goto fail; + } rc = 0; fail: close(fd[1]); + close(mmio[1]); for (int i = 0; i < _argc; i++) { g_free(argv[i]); @@ -443,6 +457,9 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); + mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio, + pdev->mmio_sock); + configure_memory_sync(pdev->sync, pdev->mpqemu_link); } @@ -503,8 +520,7 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, unsigned size, bool memory) { MPQemuLinkState *mpqemu_link = dev->mpqemu_link; - MPQemuMsg msg; - int wait; + MPQemuMsg msg, ret; memset(&msg, 0, sizeof(MPQemuMsg)); @@ -518,19 +534,18 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, msg.cmd = BAR_WRITE; msg.data1.bar_access.val = *val; } else { - wait = GET_REMOTE_WAIT; - msg.cmd = BAR_READ; - msg.num_fds = 1; - msg.fds[0] = wait; } - mpqemu_msg_send(mpqemu_link, &msg, mpqemu_link->com); + mpqemu_msg_send(mpqemu_link, &msg, mpqemu_link->mmio); - if (!write) { - *val = wait_for_remote(wait); - PUT_REMOTE_WAIT(wait); + if (write) { + return; } + + mpqemu_msg_recv(mpqemu_link, &ret, mpqemu_link->mmio); + + *val = ret.data1.mmio_ret.val; } void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index ac61a9b..5e858cc 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -71,6 +71,7 @@ struct PCIProxyDev { pid_t remote_pid; int rsocket; int socket; + int mmio_sock; char *rid; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 16a913b..4911eea 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -73,6 +73,7 @@ typedef enum { DEVICE_ADD, DEVICE_DEL, PROXY_PING, + MMIO_RETURN, MAX, } mpqemu_cmd_t; @@ -107,6 +108,10 @@ typedef struct { } set_irqfd_msg_t; typedef struct { + uint64_t val; +} mmio_ret_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -116,6 +121,7 @@ typedef struct { sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; set_irqfd_msg_t set_irqfd; + mmio_ret_msg_t mmio_ret; } data1; int fds[REMOTE_MAX_FDS]; @@ -170,6 +176,7 @@ typedef struct MPQemuLinkState { GMainLoop *loop; MPQemuChannel *com; + MPQemuChannel *mmio; mpqemu_link_callback callback; } MPQemuLinkState; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 696aeb1..d91936e 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -77,6 +77,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s) g_main_loop_quit(s->loop); mpqemu_destroy_channel(s->com); + mpqemu_destroy_channel(s->mmio); object_unref(OBJECT(s)); } @@ -344,6 +345,7 @@ void mpqemu_start_coms(MPQemuLinkState *s) { g_assert(g_source_attach(&s->com->gsrc, s->ctx)); + g_assert(g_source_attach(&s->mmio->gsrc, s->ctx)); g_main_loop_run(s->loop); } diff --git a/qdev-monitor.c b/qdev-monitor.c index e1d05e4..f38849e 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -711,6 +711,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, if (old_pdev) { pdev->rsocket = old_pdev->rsocket; pdev->socket = old_pdev->socket; + pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; } else { pdev->rsocket = managed ? rsocket : -1; diff --git a/remote/remote-main.c b/remote/remote-main.c index 27e4492..0a1326d 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -117,8 +117,8 @@ static void process_bar_write(MPQemuMsg *msg, Error **errp) static void process_bar_read(MPQemuMsg *msg, Error **errp) { bar_access_msg_t *bar_access = &msg->data1.bar_access; + MPQemuMsg ret = { 0 }; AddressSpace *as; - int wait = msg->fds[0]; MemTxResult res; uint64_t val = 0; @@ -152,9 +152,10 @@ static void process_bar_read(MPQemuMsg *msg, Error **errp) } fail: - notify_proxy(wait, val); - - PUT_REMOTE_WAIT(wait); + ret.cmd = MMIO_RETURN; + ret.data1.mmio_ret.val = val; + ret.size = sizeof(ret.data1); + mpqemu_msg_send(mpqemu_link, &ret, mpqemu_link->mmio); } static void process_device_add_msg(MPQemuMsg *msg) @@ -497,7 +498,14 @@ int main(int argc, char *argv[]) mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); - parse_cmdline(argc - 2, argv + 2, NULL); + fd = qemu_parse_fd(argv[2]); + if (fd == -1) { + printf("Failed to parse fd for remote process.\n"); + return -EINVAL; + } + mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd); + + parse_cmdline(argc - 3, argv + 3, NULL); mpqemu_link_set_callback(mpqemu_link, process_msg); From patchwork Thu Oct 24 09:09:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FFF2139A for ; Thu, 24 Oct 2019 10:06:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D999E205F4 for ; Thu, 24 Oct 2019 10:06:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="C2hi090u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D999E205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNa0T-0001Ax-8O for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 06:06:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZBO-0005Qw-Fy for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZBN-0005my-6S for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:26 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:34384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZBM-0005mk-Uq for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:25 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94s7L100066; Thu, 24 Oct 2019 09:13:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=yI2wGKXkkFdVlfFpbe0//221YQeG7qB/jqZ/0nHBlMY=; b=C2hi090uhSq4aOmMojHR/mpeWhpSYhOr9qFLtnqieTGBrTRdG/XvR5Me2jyG4SF8RA9G aUTf9c/6oqy20pmnk9uUnV+JzJx7opv4TjzcL7N4BwyJPTirRtkHEGGn+Eu4HWUZ+q4+ 3yiRtnkIkhZ+jZUxV/IpP+zthnPSfOpR8qgNl1Sv22DINnnrCjgifFEgPKXuRBy1DdG0 tQegBkS27Hw7xOzYGJtYRu4ZgQVBa7LjitWsVPSPSRhJsDtG7VoSG+rQY34sqcgvRqxv yvOEBrd9OEekNZG04h4jZ3zbG79+s7fHvHr1oiLtIkl/DqYiD4k/gbw5OcUHZTu4TWm7 6A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2vqteq2att-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:13:18 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97n26170844; Thu, 24 Oct 2019 09:11:18 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2vtsk4884n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:17 +0000 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 x9O9BGiU002536; Thu, 24 Oct 2019 09:11:16 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:16 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 33/49] multi-process: perform device reset in the remote process Date: Thu, 24 Oct 2019 05:09:14 -0400 Message-Id: <7579c5df98f9c09933685209395aa4a0e0ceb857.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Perform device reset in the remote process when QEMU performs device reset. This is required to reset the internal state (like registers, etc...) of emulated devices Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 hw/proxy/proxy-lsi53c895a.c | 6 ++++++ hw/proxy/qemu-proxy.c | 14 ++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 1 + remote/remote-main.c | 11 +++++++++++ 5 files changed, 34 insertions(+) diff --git a/hw/proxy/proxy-lsi53c895a.c b/hw/proxy/proxy-lsi53c895a.c index 7734ae2..f6bd8a1 100644 --- a/hw/proxy/proxy-lsi53c895a.c +++ b/hw/proxy/proxy-lsi53c895a.c @@ -57,6 +57,11 @@ static void proxy_lsi_realize(PCIProxyDev *dev, Error **errp) &dev->region[2], "proxy-lsi-ram", 0x2000); } +static void proxy_lsi_reset(DeviceState *dev) +{ + proxy_device_reset(dev); +} + static void proxy_lsi_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -74,6 +79,7 @@ static void proxy_lsi_class_init(ObjectClass *klass, void *data) set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->desc = "LSI Proxy Device"; + dc->reset = proxy_lsi_reset; } static const TypeInfo lsi_proxy_dev_type_info = { diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 74aecd3..5aada67 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -577,3 +577,17 @@ const MemoryRegionOps proxy_default_ops = { .max_access_size = 1, }, }; + +void proxy_device_reset(DeviceState *dev) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + MPQemuMsg msg; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.cmd = DEVICE_RESET; + + mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); +} diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 5e858cc..672303c 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -112,4 +112,6 @@ void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size); +void proxy_device_reset(DeviceState *dev); + #endif /* QEMU_PROXY_H */ diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 4911eea..6fcc6f5 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -74,6 +74,7 @@ typedef enum { DEVICE_DEL, PROXY_PING, MMIO_RETURN, + DEVICE_RESET, MAX, } mpqemu_cmd_t; diff --git a/remote/remote-main.c b/remote/remote-main.c index 0a1326d..4459d26 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -66,8 +66,11 @@ #include "qemu/log.h" #include "qemu/cutils.h" #include "remote-opts.h" +#include "monitor/monitor.h" +#include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link; + PCIDevice *remote_pci_dev; bool create_done; @@ -237,6 +240,11 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_device_reset_msg(MPQemuMsg *msg) +{ + qemu_devices_reset(); +} + static int init_drive(QDict *rqdict, Error **errp) { QemuOpts *opts; @@ -441,6 +449,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) notify_proxy(wait, (uint32_t)getpid()); PUT_REMOTE_WAIT(wait); break; + case DEVICE_RESET: + process_device_reset_msg(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:09:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EA7F14E5 for ; Thu, 24 Oct 2019 09:30:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33EAA20684 for ; Thu, 24 Oct 2019 09:30:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pTQ7XG7K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33EAA20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZSI-0003Ja-KB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:30:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43994) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9W-0008BY-Lu for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9U-0004hS-VV for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:30 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9U-0004gz-NO for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:28 -0400 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 x9O94M3M094924; Thu, 24 Oct 2019 09:11:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=oTCRPbeKTf2q9fkE6iDwaefSFhw8FReF4WhrJOU1zgs=; b=pTQ7XG7KLCULfnCfSGTcBvg15KLvagSPOzCqF7HTlO8Nz5iKeH5jd57FkDtdu0kVjArw VMEo5vdU8j6su3GgprgcHFSHME18OcecIj0uD3lCCTyAdZAi6DrwUsaHzcRrqjF3f+H9 VmKbyAqyaZCvCD+rn7deDFKscL1jxlFox83zKCyjll5To61YImAfMxtQ+pXhbG/GIwfm sP+8ng17nO4wTqcD8tpZD/pkW/U+4O2YuxpPBcMjPx+or151cmL5mtk8izxkrsQiPDe5 rodff8+TtFrc9hUrfjBQu03AlOFLIlDTi2V6EOkK0mEVGbMOAzYzpBEzihs9H5ga0lpa 0w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r24rm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:21 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LET047080; Thu, 24 Oct 2019 09:11:20 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu869-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:20 +0000 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 x9O9BJlG002559; Thu, 24 Oct 2019 09:11:19 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:19 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 34/49] multi-process/mon: choose HMP commands based on target Date: Thu, 24 Oct 2019 05:09:15 -0400 Message-Id: <15063eb2e3392e3d5ec8edb73f7a5fc55a7563e3.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=859 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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=942 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Add "targets" field to HMP command definition to select the targets which would be supported by each command Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 hmp-commands-info.hx | 10 ++++++++++ hmp-commands.hx | 20 ++++++++++++++++++++ scripts/hxtool | 44 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/hxtool diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 257ee7d..631cc76 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -19,6 +19,7 @@ ETEXI .params = "", .help = "show the version of QEMU", .cmd = hmp_info_version, + .targets = "scsi", .flags = "p", }, @@ -48,6 +49,7 @@ ETEXI .params = "", .help = "show the character devices", .cmd = hmp_info_chardev, + .targets = "scsi", .flags = "p", }, @@ -64,6 +66,7 @@ ETEXI .help = "show info of one block device or all block devices " "(-n: show named nodes; -v: show details)", .cmd = hmp_info_block, + .targets = "scsi", }, STEXI @@ -78,6 +81,7 @@ ETEXI .params = "", .help = "show block device statistics", .cmd = hmp_info_blockstats, + .targets = "scsi", }, STEXI @@ -92,6 +96,7 @@ ETEXI .params = "", .help = "show progress of ongoing block device operations", .cmd = hmp_info_block_jobs, + .targets = "scsi", }, STEXI @@ -167,6 +172,7 @@ ETEXI .params = "", .help = "show the command line history", .cmd = hmp_info_history, + .targets = "scsi", .flags = "p", }, @@ -224,6 +230,7 @@ ETEXI .params = "", .help = "show PCI info", .cmd = hmp_info_pci, + .targets = "scsi", }, STEXI @@ -630,6 +637,7 @@ ETEXI .params = "", .help = "show device tree", .cmd = hmp_info_qtree, + .targets = "scsi", }, STEXI @@ -644,6 +652,7 @@ ETEXI .params = "", .help = "show qdev device model list", .cmd = hmp_info_qdm, + .targets = "scsi", }, STEXI @@ -658,6 +667,7 @@ ETEXI .params = "[path]", .help = "show QOM composition tree", .cmd = hmp_info_qom_tree, + .targets = "scsi", .flags = "p", }, diff --git a/hmp-commands.hx b/hmp-commands.hx index cfcc044..6d9674b 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -49,6 +49,7 @@ ETEXI .params = "", .help = "quit the emulator", .cmd = hmp_quit, + .targets = "scsi", }, STEXI @@ -82,6 +83,7 @@ ETEXI .params = "device size", .help = "resize a block image", .cmd = hmp_block_resize, + .targets = "scsi", }, STEXI @@ -99,6 +101,7 @@ ETEXI .params = "device [speed [base]]", .help = "copy data from a backing file into a block device", .cmd = hmp_block_stream, + .targets = "scsi", }, STEXI @@ -113,6 +116,7 @@ ETEXI .params = "device speed", .help = "set maximum speed for a background block operation", .cmd = hmp_block_job_set_speed, + .targets = "scsi", }, STEXI @@ -129,6 +133,7 @@ ETEXI "\n\t\t\t if you want to abort the operation immediately" "\n\t\t\t instead of keep running until data is in sync)", .cmd = hmp_block_job_cancel, + .targets = "scsi", }, STEXI @@ -143,6 +148,7 @@ ETEXI .params = "device", .help = "stop an active background block operation", .cmd = hmp_block_job_complete, + .targets = "scsi", }, STEXI @@ -158,6 +164,7 @@ ETEXI .params = "device", .help = "pause an active background block operation", .cmd = hmp_block_job_pause, + .targets = "scsi", }, STEXI @@ -172,6 +179,7 @@ ETEXI .params = "device", .help = "resume a paused background block operation", .cmd = hmp_block_job_resume, + .targets = "scsi", }, STEXI @@ -186,6 +194,7 @@ ETEXI .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", .cmd = hmp_eject, + .targets = "scsi", }, STEXI @@ -200,6 +209,7 @@ ETEXI .params = "device", .help = "remove host block device", .cmd = hmp_drive_del, + .targets = "scsi", }, STEXI @@ -219,6 +229,7 @@ ETEXI .params = "device filename [format [read-only-mode]]", .help = "change a removable medium, optional format", .cmd = hmp_change, + .targets = "scsi", }, STEXI @@ -732,6 +743,7 @@ ETEXI .help = "add device, like -device on the command line", .cmd = hmp_device_add, .command_completion = device_add_completion, + .targets = "scsi", }, STEXI @@ -747,6 +759,7 @@ ETEXI .help = "remove device", .cmd = hmp_device_del, .command_completion = device_del_completion, + .targets = "scsi", }, STEXI @@ -1351,6 +1364,7 @@ ETEXI "The -c flag requests QEMU to compress backup data\n\t\t\t" "(if the target format supports it).\n\t\t\t", .cmd = hmp_drive_backup, + .targets = "scsi", }, STEXI @item drive_backup @@ -1368,6 +1382,7 @@ ETEXI "[,readonly=on|off][,copy-on-read=on|off]", .help = "add drive to PCI storage controller", .cmd = hmp_drive_add, + .targets = "scsi", }, STEXI @@ -1816,6 +1831,7 @@ ETEXI .help = "add chardev", .cmd = hmp_chardev_add, .command_completion = chardev_add_completion, + .targets = "scsi", }, STEXI @@ -1831,6 +1847,7 @@ ETEXI .params = "id args", .help = "change chardev", .cmd = hmp_chardev_change, + .targets = "scsi", }, STEXI @@ -1848,6 +1865,7 @@ ETEXI .help = "remove chardev", .cmd = hmp_chardev_remove, .command_completion = chardev_remove_completion, + .targets = "scsi", }, STEXI @@ -1864,6 +1882,7 @@ ETEXI .help = "send a break on chardev", .cmd = hmp_chardev_send_break, .command_completion = chardev_remove_completion, + .targets = "scsi", }, STEXI @@ -1938,6 +1957,7 @@ ETEXI .params = "[subcommand]", .help = "show various information about the system state", .cmd = hmp_info_help, + .targets = "scsi", .sub_table = hmp_info_cmds, .flags = "p", }, diff --git a/scripts/hxtool b/scripts/hxtool old mode 100644 new mode 100755 index 7d7c428..02fbbd8 --- a/scripts/hxtool +++ b/scripts/hxtool @@ -10,7 +10,14 @@ hxtoh() STEXI*|ETEXI*) flag=$(($flag^1)) ;; *) - test $flag -eq 1 && printf "%s\n" "$str" + # Skip line that has ".targets" as it is for multi-process targets based hmp + # commands generation. + echo $str | grep -q '.targets' + if [ $? -eq 0 ]; then + continue + else + test $flag -eq 1 && printf "%s\n" "$str" + fi ;; esac done @@ -53,16 +60,49 @@ hxtotexi() print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")" ;; *) - test $flag -eq 1 && printf '%s\n' "$str" + # Skip line that has ".targets" as it is for multi-process targets based hmp + # commands generation. + echo $str | grep -q '.targetss' + if [ $? -eq 0 ]; then + continue + else + test $flag -eq 1 && printf '%s\n' "$str" + fi ;; esac line=$((line+1)) done } +hxtoh_tgt() +{ + section="" + flag=1 + use_section=0 + while read -r str; do + # Print section if it has ".targets" and the second argument passed to the + # script, such as "scsi". + echo "$str" | grep -q -E ".targets.*$1" + if [ $? -eq 0 ]; then + use_section=1 + continue + fi + case $str in + HXCOMM*) + ;; + STEXI*|ETEXI*) flag=$(($flag^1)); test $use_section -eq 1 && printf '%s' "$section"; section=""; use_section=0 + ;; + *) + test $flag -eq 1 && section="${section} ${str} ${IFS}" + ;; + esac + done +} + case "$1" in "-h") hxtoh ;; "-t") hxtotexi ;; +"-tgt") hxtoh_tgt $2 ;; *) exit 1 ;; esac From patchwork Thu Oct 24 09:09:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208667 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCDBC112C for ; Thu, 24 Oct 2019 09:34:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A1E1F20684 for ; Thu, 24 Oct 2019 09:34:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ILJZx2ob" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1E1F20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZVv-0007xR-5D for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9Z-0008JG-S1 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9X-0004ix-AZ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33140) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9X-0004iC-24 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:31 -0400 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 x9O94c9W095089; Thu, 24 Oct 2019 09:11:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=T5OOYLIkRpz2xvOki3aoPhZhNWxOa5eqFQ9F3W4O0YI=; b=ILJZx2obXEPZXOPju8w4ns6/fJrjIZ6t9TUvzpJiuKCrgxsMBh17zs/HMtigJtJwBLne sUozRwE/j+UIBkj703+d/oGbSFfrvQLVADtatDox2ikrQvRLsORwJ9RLJBGBJJ8uoKRY QeCj8OexLO7xpBV7cgiWBKCtW0QW955aGgmcOLvXWJ78EpdOTEykHLcvJW2ZBVvPoR18 M4vKmc0DtpKsTOrkMrp7ixBX8BeZO8ysHvVgZqgNB6L7FJ0fTSDYuB8Ol28H5hhLclEZ 5JEN5dGycGeoohCGmrQaQFRKgSRleqIvUbfI1DMnORhM/pD88evNmlJXzIA5hCn54Z+4 +g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2vqu4r24ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:26 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O982Dx093152; Thu, 24 Oct 2019 09:11:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2vtm244js3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:25 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BM5T009687; Thu, 24 Oct 2019 09:11:22 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:22 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 35/49] multi-process/mon: stub functions to enable QMP module for remote process Date: Thu, 24 Oct 2019 05:09:16 -0400 Message-Id: <27bbba9ef0941b55540dbe662c96ee1e2a0c0807.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" QMP module doesn't need some functions to run independently on the remote processes. However, these functions are necessary for compilation. Therefore, these functions are stub'ed out. The stub functions raise an assert if QEMU is built in debug mode (--enable-debug). Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 accel/stubs/tcg-stub.c | 10 +++ configure | 4 ++ include/qemu-common.h | 8 +++ stubs/gdbstub.c | 21 +++++++ stubs/migration.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/monitor.c | 31 ++++++++++ stubs/net-stub.c | 69 +++++++++++++++++++++ stubs/qapi-misc.c | 41 +++++++++++++ stubs/qapi-target.c | 49 +++++++++++++++ stubs/ui-stub.c | 130 +++++++++++++++++++++++++++++++++++++++ stubs/vl-stub.c | 92 ++++++++++++++++++++++++++++ 11 files changed, 617 insertions(+) create mode 100644 stubs/migration.c create mode 100644 stubs/qapi-misc.c create mode 100644 stubs/qapi-target.c create mode 100644 stubs/ui-stub.c diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index 9b55fb0..c2d72fe 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -119,3 +119,13 @@ page_collection_lock(tb_page_addr_t start, tb_page_addr_t end) void page_collection_unlock(struct page_collection *set) { } + +void dump_exec_info(void) +{ + qemu_debug_assert(0); +} + +void dump_opcount_info(void) +{ + qemu_debug_assert(0); +} diff --git a/configure b/configure index 135afa9..aaf25eb 100755 --- a/configure +++ b/configure @@ -7252,6 +7252,10 @@ if test "$mpqemu" = "yes" ; then echo "CONFIG_MPQEMU=y" >> $config_host_mak fi +if test "$debug" = "yes" ; then + echo "CONFIG_DEBUG=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi diff --git a/include/qemu-common.h b/include/qemu-common.h index 8d84db9..277d145 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -10,6 +10,8 @@ #ifndef QEMU_COMMON_H #define QEMU_COMMON_H +#include + #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) /* Copyright string for -version arguments, About dialogs, etc */ @@ -129,4 +131,10 @@ void page_size_init(void); * returned. */ bool dump_in_progress(void); +#ifdef CONFIG_DEBUG +#define qemu_debug_assert(x) assert(x) +#else +#define qemu_debug_assert(x) +#endif + #endif diff --git a/stubs/gdbstub.c b/stubs/gdbstub.c index 2b7aee5..28c574a 100644 --- a/stubs/gdbstub.c +++ b/stubs/gdbstub.c @@ -1,6 +1,27 @@ #include "qemu/osdep.h" +#include "qemu-common.h" #include "exec/gdbstub.h" /* xml_builtin */ const char *const xml_builtin[][2] = { { NULL, NULL } }; + +#ifdef CONFIG_USER_ONLY + +int gdbserver_start(int port) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +#else + +int gdbserver_start(const char *device) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +#endif diff --git a/stubs/migration.c b/stubs/migration.c new file mode 100644 index 0000000..28ccf80 --- /dev/null +++ b/stubs/migration.c @@ -0,0 +1,162 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "migration/misc.h" +#include "migration/snapshot.h" +#include "qapi/qapi-types-migration.h" +#include "qapi/qapi-commands-migration.h" +#include "qapi/qapi-types-net.h" + +MigrationInfo *qmp_query_migrate(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params, + Error **errp) +{ + qemu_debug_assert(0); +} + +MigrationCapabilityStatusList *qmp_query_migrate_capabilities(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) +{ + qemu_debug_assert(0); +} + +MigrationParameters *qmp_query_migrate_parameters(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_migrate_start_postcopy(Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_cancel(Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_continue(MigrationStatus state, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_set_downtime(double value, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_set_speed(int64_t value, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_set_cache_size(int64_t value, Error **errp) +{ + qemu_debug_assert(0); +} + +int64_t qmp_query_migrate_cache_size(Error **errp) +{ + qemu_debug_assert(0); + + return 0; +} + +void qmp_migrate(const char *uri, bool has_blk, bool blk, + bool has_inc, bool inc, bool has_detach, bool detach, + bool has_resume, bool resume, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_incoming(const char *uri, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_recover(const char *uri, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_migrate_pause(Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_x_colo_lost_heartbeat(Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live, + Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_xen_set_replication(bool enable, bool primary, + bool has_failover, bool failover, + Error **errp) +{ + qemu_debug_assert(0); +} + +ReplicationStatus *qmp_query_xen_replication_status(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_xen_colo_do_checkpoint(Error **errp) +{ + qemu_debug_assert(0); +} + +COLOStatus *qmp_query_colo_status(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void migration_global_dump(Monitor *mon) +{ + qemu_debug_assert(0); +} + +int load_snapshot(const char *name, Error **errp) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +int save_snapshot(const char *name, Error **errp) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +AnnounceParameters *migrate_announce_params(void) +{ + qemu_debug_assert(0); + + return NULL; +} diff --git a/stubs/monitor.c b/stubs/monitor.c index 17d2493..8fc129f 100644 --- a/stubs/monitor.c +++ b/stubs/monitor.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qemu-common.h" #include "qapi/error.h" #include "qapi/qapi-emit-events.h" #include "monitor/monitor.h" @@ -10,6 +11,24 @@ #include "sysemu/sysemu.h" #include "sysemu/runstate.h" #include "monitor/hmp.h" +#include "monitor/qdev.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" + +#include "qapi/qapi-types-block-core.h" +#include "qapi/qapi-commands-block-core.h" + +#pragma weak cur_mon +#pragma weak monitor_vprintf +#pragma weak monitor_get_fd +#pragma weak monitor_init +#pragma weak qapi_event_emit +#pragma weak monitor_get_cpu_index +#pragma weak monitor_printf +#pragma weak monitor_cur_is_qmp +#pragma weak qmp_device_list_properties +#pragma weak monitor_init_qmp +#pragma weak monitor_init_hmp __thread Monitor *cur_mon; @@ -17,11 +36,13 @@ __thread Monitor *cur_mon; int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { + qemu_debug_assert(0); abort(); } int monitor_get_fd(Monitor *mon, const char *name, Error **errp) { + qemu_debug_assert(0); error_setg(errp, "only QEMU supports file descriptor passing"); return -1; } @@ -32,29 +53,39 @@ void monitor_init_qmp(Chardev *chr, bool pretty) void monitor_init_hmp(Chardev *chr, bool use_readline) { + qemu_debug_assert(0); } void qapi_event_emit(QAPIEvent event, QDict *qdict) { + qemu_debug_assert(0); } int monitor_get_cpu_index(void) { + qemu_debug_assert(0); + return -ENOSYS; } int monitor_printf(Monitor *mon, const char *fmt, ...) { + qemu_debug_assert(0); + return -ENOSYS; } bool monitor_cur_is_qmp(void) { + qemu_debug_assert(0); + return false; } ObjectPropertyInfoList *qmp_device_list_properties(const char *typename, Error **errp) { + qemu_debug_assert(0); + return NULL; } diff --git a/stubs/net-stub.c b/stubs/net-stub.c index cb2274b..962827e 100644 --- a/stubs/net-stub.c +++ b/stubs/net-stub.c @@ -2,6 +2,9 @@ #include "qemu-common.h" #include "net/net.h" +#include "qapi/qapi-commands-net.h" +#include "qapi/qapi-commands-rocker.h" + int qemu_find_net_clients_except(const char *id, NetClientState **ncs, NetClientDriver type, int max) { @@ -29,3 +32,69 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, return -ENOSYS; } +void qmp_set_link(const char *name, bool up, Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_netdev_del(const char *id, Error **errp) +{ + qemu_debug_assert(0); +} + +RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name, + Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_announce_self(AnnounceParameters *params, Error **errp) +{ + qemu_debug_assert(0); +} + +RockerSwitch *qmp_query_rocker(const char *name, Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +RockerOfDpaFlowList *qmp_query_rocker_of_dpa_flows(const char *name, + bool has_tbl_id, + uint32_t tbl_id, + Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +RockerOfDpaGroupList *qmp_query_rocker_of_dpa_groups(const char *name, + bool has_type, + uint8_t type, + Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp) +{ + qemu_debug_assert(0); +} + +void netdev_add(QemuOpts *opts, Error **errp) +{ + qemu_debug_assert(0); +} diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c new file mode 100644 index 0000000..3eeedd9 --- /dev/null +++ b/stubs/qapi-misc.c @@ -0,0 +1,41 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qapi/qapi-commands-misc.h" +#include "./qapi/qapi-types-dump.h" +#include "qapi/qapi-commands-dump.h" + +void qmp_dump_guest_memory(bool paging, const char *file, + bool has_detach, bool detach, + bool has_begin, int64_t begin, bool has_length, + int64_t length, bool has_format, + DumpGuestMemoryFormat format, Error **errp) +{ + qemu_debug_assert(0); +} + +DumpQueryResult *qmp_query_dump(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_xen_load_devices_state(const char *filename, Error **errp) +{ + qemu_debug_assert(0); +} + +bool dump_in_progress(void) +{ + qemu_debug_assert(0); + + return FALSE; +} diff --git a/stubs/qapi-target.c b/stubs/qapi-target.c new file mode 100644 index 0000000..b3a3ffc --- /dev/null +++ b/stubs/qapi-target.c @@ -0,0 +1,49 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qapi/qapi-types-misc-target.h" +#include "qapi/qapi-commands-misc-target.h" +#include "qapi/qapi-types-machine-target.h" +#include "qapi/qapi-commands-machine-target.h" + +void qmp_rtc_reset_reinjection(Error **errp) +{ + qemu_debug_assert(0); +} + +SevInfo *qmp_query_sev(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +SevLaunchMeasureInfo *qmp_query_sev_launch_measure(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +SevCapability *qmp_query_sev_capabilities(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} diff --git a/stubs/ui-stub.c b/stubs/ui-stub.c new file mode 100644 index 0000000..a5a63ea --- /dev/null +++ b/stubs/ui-stub.c @@ -0,0 +1,130 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "ui/console.h" +#include "ui/input.h" +#include "ui/qemu-spice.h" + +#include "qapi/qapi-types-ui.h" +#include "qapi/qapi-commands-ui.h" + +void qmp_screendump(const char *filename, bool has_device, const char *device, + bool has_head, int64_t head, Error **errp) +{ + qemu_debug_assert(0); +} + +VncInfo *qmp_query_vnc(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +VncInfo2List *qmp_query_vnc_servers(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +MouseInfoList *qmp_query_mice(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, + Error **errp) +{ + qemu_debug_assert(0); +} + +void qmp_input_send_event(bool has_device, const char *device, + bool has_head, int64_t head, + InputEventList *events, Error **errp) +{ + qemu_debug_assert(0); +} + +void vnc_display_open(const char *id, Error **errp) +{ + qemu_debug_assert(0); +} + +void vnc_display_add_client(const char *id, int csock, bool skipauth) +{ + qemu_debug_assert(0); +} + +void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) +{ + qemu_debug_assert(0); +} + +void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) +{ + qemu_debug_assert(0); +} + +void qemu_input_event_sync(void) +{ + qemu_debug_assert(0); +} + +void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, + uint32_t button_old, uint32_t button_new) +{ + qemu_debug_assert(0); +} + +#ifdef CONFIG_SPICE + +int using_spice; + +SpiceInfo *qmp_query_spice(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +int qemu_spice_migrate_info(const char *hostname, int port, int tls_port, + const char *subject) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +int qemu_spice_display_add_client(int csock, int skipauth, int tls) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +int qemu_spice_set_passwd(const char *passwd, bool fail_if_conn, + bool disconnect_if_conn) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +int qemu_spice_set_pw_expire(time_t expires) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +#endif + +int index_from_key(const char *key, size_t key_length) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c index fff72be..606f078 100644 --- a/stubs/vl-stub.c +++ b/stubs/vl-stub.c @@ -8,6 +8,12 @@ #include "disas/disas.h" #include "sysemu/runstate.h" +#include "qapi/qapi-commands-ui.h" +#include "qapi/qapi-commands-run-state.h" +#include "sysemu/watchdog.h" +#include "disas/disas.h" +#include "audio/audio.h" + bool tcg_allowed; bool xen_allowed; bool boot_strict; @@ -21,6 +27,8 @@ int smp_threads = 1; int icount_align_option; int boot_menu; +#pragma weak arch_type + unsigned int max_cpus; const uint32_t arch_type; const char *mem_path; @@ -33,6 +41,11 @@ ram_addr_t ram_size; MachineState *current_machine; QemuUUID qemu_uuid; +int singlestep; +const char *qemu_name; +int no_shutdown; +int autostart; + int runstate_is_running(void) { return 0; @@ -77,3 +90,82 @@ void x86_cpu_list(void) { } #endif + +void qemu_system_shutdown_request(ShutdownCause reason) +{ + qemu_debug_assert(0); +} + +void qemu_system_reset_request(ShutdownCause reason) +{ + qemu_debug_assert(0); +} + +void qemu_system_powerdown_request(void) +{ + qemu_debug_assert(0); +} + +void qemu_exit_preconfig_request(void) +{ + qemu_debug_assert(0); +} + +bool runstate_needs_reset(void) +{ + qemu_debug_assert(0); + + return FALSE; +} + +bool qemu_wakeup_suspend_enabled(void) +{ + qemu_debug_assert(0); + + return FALSE; +} + +void qemu_system_wakeup_request(WakeupReason reason, Error **errp) +{ + qemu_debug_assert(0); +} + +DisplayOptions *qmp_query_display_options(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +StatusInfo *qmp_query_status(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} + +void qmp_watchdog_set_action(WatchdogAction action, Error **errp) +{ + qemu_debug_assert(0); +} + +int select_watchdog_action(const char *p) +{ + qemu_debug_assert(0); + + return -1; +} + +void monitor_disas(Monitor *mon, CPUState *cpu, + target_ulong pc, int nb_insn, int is_physical) +{ + qemu_debug_assert(0); +} + +int wav_start_capture(AudioState *state, CaptureState *s, const char *path, + int freq, int bits, int nchannels) +{ + qemu_debug_assert(0); + + return -1; +} From patchwork Thu Oct 24 09:09:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08AD4139A for ; Thu, 24 Oct 2019 09:38:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1FDC20684 for ; Thu, 24 Oct 2019 09:38:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lqqpJ81d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1FDC20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZZy-0008BL-Du for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:38:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44023) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9b-0008Nt-Pi for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9Z-0004k4-05 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:35 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33178) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9Y-0004jK-M1 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:32 -0400 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 x9O94c9X095089; Thu, 24 Oct 2019 09:11:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=XK7s+/O+U8roh3eX64pnG1HxKvK+OEYT+3URSvPIhsE=; b=lqqpJ81dRYU4lUzOnKiq1oRS0Odvr8gvJR72dwEHzjUkXcqGkMNZ+vhmqsQcZobxb5r5 sNpgjzv/OpownSwE7djnJHCBc9rHn3VPa2EJ11Jrt2cnFkgFjdQK3ILMFymOLSNJ3i+q iiMYAgolN0BwvDClW4K2ehSokFuYcXrkwOXown2hLLNDXXR7ZxybZ7Z1BO2lgBN4vmqX s1J/fYubcdQrguCOtw6vyY16ATkplMIuV8wbIdh4ce/5+ygTTo+ajJJ3a3jbpLeqiWI7 DygMSRFmc5SWZQRu/QXkwa3aJY5UF72HL8HZQ4CzLJPpAIMLccG2EIrzMjcRKhkzzpOZ Iw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:27 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98mrj076119; Thu, 24 Oct 2019 09:11:27 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2vtjkj2yyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:27 +0000 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 x9O9BPHO002581; Thu, 24 Oct 2019 09:11:25 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:25 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 36/49] multi-process/mon: enable QMP module support in the remote process Date: Thu, 24 Oct 2019 05:09:17 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Build system changes to enable QMP module in the remote process Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 Makefile.objs | 9 +++++ Makefile.target | 34 +++++++++++++++++-- hmp-commands.hx | 5 +-- hw/core/Makefile.objs | 1 + monitor/Makefile.objs | 3 ++ monitor/misc.c | 84 +++++++++++++++++++++++++--------------------- monitor/monitor-internal.h | 38 +++++++++++++++++++++ qapi/Makefile.objs | 2 ++ qom/Makefile.objs | 1 + ui/Makefile.objs | 2 ++ 10 files changed, 137 insertions(+), 42 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index c23ccaa..c72db88 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -30,6 +30,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += backends/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += migration/ remote-pci-obj-$(CONFIG_MPQEMU) += remote/ +remote-pci-obj-$(CONFIG_MPQEMU) += monitor/ remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o @@ -42,6 +43,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o # remote-lsi-obj-y is code used to implement remote LSI device remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ +remote-lsi-obj-$(CONFIG_MPQEMU) += ui/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o ####################################################################### # crypto-obj-y is code used by both qemu system emulation and qemu-img @@ -112,6 +116,11 @@ common-obj-y += vl-parse.o common-obj-y += qapi/ endif +remote-pci-obj-$(CONFIG_MPQEMU) += qapi/ +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o +remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o + ####################################################################### # Target-independent parts used in system and user emulation common-obj-y += cpus-common.o diff --git a/Makefile.target b/Makefile.target index 0ca40f1..8010998 100644 --- a/Makefile.target +++ b/Makefile.target @@ -132,13 +132,31 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o -remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o + +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o ######################################################### # Linux user emulator target @@ -191,6 +209,10 @@ endif generated-files-y += hmp-commands.h hmp-commands-info.h generated-files-y += config-devices.h +ifdef CONFIG_MPQEMU +generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h +endif + endif # CONFIG_SOFTMMU dummy := $(call unnest-vars,,obj-y) @@ -275,10 +297,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@") +ifdef CONFIG_MPQEMU +hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) + +hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) +endif + clean: clean-target rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') - rm -f hmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp diff --git a/hmp-commands.hx b/hmp-commands.hx index 6d9674b..534f272 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -14,7 +14,8 @@ ETEXI .args_type = "name:S?", .params = "[cmd]", .help = "show the help", - .cmd = do_help_cmd, + .cmd = hmp_do_help_cmd, + .targets = "scsi", .flags = "p", }, @@ -618,7 +619,7 @@ ETEXI .args_type = "fmt:/,val:l", .params = "/fmt expr", .help = "print expression value (use $reg for CPU register access)", - .cmd = do_print, + .cmd = hmp_do_print, }, STEXI diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index 9ef6b42..721bc5f 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -44,3 +44,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o remote-pci-obj-$(CONFIG_MPQEMU) += numa.o remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index e91a858..11c42ec 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -1,3 +1,6 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o common-obj-y += qmp-cmds.o hmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o hmp-cmds.o diff --git a/monitor/misc.c b/monitor/misc.c index aef16f6..400ba06 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -176,12 +176,12 @@ int hmp_compare_cmd(const char *name, const char *list) return 0; } -static void do_help_cmd(Monitor *mon, const QDict *qdict) +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict) { help_cmd(mon, qdict_get_try_str(qdict, "name")); } -static void hmp_trace_event(Monitor *mon, const QDict *qdict) +void hmp_trace_event(Monitor *mon, const QDict *qdict) { const char *tp_name = qdict_get_str(qdict, "name"); bool new_state = qdict_get_bool(qdict, "option"); @@ -225,7 +225,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict) } #endif -static void hmp_info_help(Monitor *mon, const QDict *qdict) +void hmp_info_help(Monitor *mon, const QDict *qdict) { help_cmd(mon, "info"); } @@ -436,7 +436,7 @@ int monitor_get_cpu_index(void) return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX; } -static void hmp_info_registers(Monitor *mon, const QDict *qdict) +void hmp_info_registers(Monitor *mon, const QDict *qdict) { bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false); CPUState *cs; @@ -459,7 +459,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict) } #ifdef CONFIG_TCG -static void hmp_info_jit(Monitor *mon, const QDict *qdict) +void hmp_info_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { error_report("JIT information is only available with accel=tcg"); @@ -470,13 +470,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict) dump_drift_info(); } -static void hmp_info_opcount(Monitor *mon, const QDict *qdict) +void hmp_info_opcount(Monitor *mon, const QDict *qdict) { dump_opcount_info(); } #endif -static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) { int64_t max = qdict_get_try_int(qdict, "max", 10); bool mean = qdict_get_try_bool(qdict, "mean", false); @@ -487,7 +487,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) qsp_report(max, sort_by, coalesce); } -static void hmp_info_history(Monitor *mon, const QDict *qdict) +void hmp_info_history(Monitor *mon, const QDict *qdict) { MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); int i; @@ -507,7 +507,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict) } } -static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) +void hmp_info_cpustats(Monitor *mon, const QDict *qdict) { CPUState *cs = mon_get_cpu(); @@ -518,7 +518,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) cpu_dump_statistics(cs, 0); } -static void hmp_info_trace_events(Monitor *mon, const QDict *qdict) +void hmp_info_trace_events(Monitor *mon, const QDict *qdict) { const char *name = qdict_get_try_str(qdict, "name"); bool has_vcpu = qdict_haskey(qdict, "vcpu"); @@ -578,7 +578,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname, error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice"); } -static void hmp_logfile(Monitor *mon, const QDict *qdict) +void hmp_logfile(Monitor *mon, const QDict *qdict) { Error *err = NULL; @@ -588,7 +588,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict) } } -static void hmp_log(Monitor *mon, const QDict *qdict) +void hmp_log(Monitor *mon, const QDict *qdict) { int mask; const char *items = qdict_get_str(qdict, "items"); @@ -605,7 +605,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict) qemu_set_log(mask); } -static void hmp_singlestep(Monitor *mon, const QDict *qdict) +void hmp_singlestep(Monitor *mon, const QDict *qdict) { const char *option = qdict_get_try_str(qdict, "option"); if (!option || !strcmp(option, "on")) { @@ -617,7 +617,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict) } } -static void hmp_gdbserver(Monitor *mon, const QDict *qdict) +void hmp_gdbserver(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_try_str(qdict, "device"); if (!device) @@ -633,7 +633,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict) } } -static void hmp_watchdog_action(Monitor *mon, const QDict *qdict) +void hmp_watchdog_action(Monitor *mon, const QDict *qdict) { const char *action = qdict_get_str(qdict, "action"); if (select_watchdog_action(action) == -1) { @@ -775,7 +775,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, } } -static void hmp_memory_dump(Monitor *mon, const QDict *qdict) +void hmp_memory_dump(Monitor *mon, const QDict *qdict) { int count = qdict_get_int(qdict, "count"); int format = qdict_get_int(qdict, "format"); @@ -785,7 +785,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict) memory_dump(mon, count, format, size, addr, 0); } -static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) { int count = qdict_get_int(qdict, "count"); int format = qdict_get_int(qdict, "format"); @@ -815,7 +815,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp) return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region); } -static void hmp_gpa2hva(Monitor *mon, const QDict *qdict) +void hmp_gpa2hva(Monitor *mon, const QDict *qdict) { hwaddr addr = qdict_get_int(qdict, "addr"); Error *local_err = NULL; @@ -835,7 +835,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict) memory_region_unref(mr); } -static void hmp_gva2gpa(Monitor *mon, const QDict *qdict) +void hmp_gva2gpa(Monitor *mon, const QDict *qdict) { target_ulong addr = qdict_get_int(qdict, "addr"); MemTxAttrs attrs; @@ -890,7 +890,7 @@ out: return ret; } -static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) { hwaddr addr = qdict_get_int(qdict, "addr"); Error *local_err = NULL; @@ -917,7 +917,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) } #endif -static void do_print(Monitor *mon, const QDict *qdict) +void hmp_do_print(Monitor *mon, const QDict *qdict) { int format = qdict_get_int(qdict, "format"); hwaddr val = qdict_get_int(qdict, "val"); @@ -943,7 +943,7 @@ static void do_print(Monitor *mon, const QDict *qdict) monitor_printf(mon, "\n"); } -static void hmp_sum(Monitor *mon, const QDict *qdict) +void hmp_sum(Monitor *mon, const QDict *qdict) { uint32_t addr; uint16_t sum; @@ -963,7 +963,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict) static int mouse_button_state; -static void hmp_mouse_move(Monitor *mon, const QDict *qdict) +void hmp_mouse_move(Monitor *mon, const QDict *qdict) { int dx, dy, dz, button; const char *dx_str = qdict_get_str(qdict, "dx_str"); @@ -987,7 +987,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict) qemu_input_event_sync(); } -static void hmp_mouse_button(Monitor *mon, const QDict *qdict) +void hmp_mouse_button(Monitor *mon, const QDict *qdict) { static uint32_t bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, @@ -1004,7 +1004,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict) mouse_button_state = button_state; } -static void hmp_ioport_read(Monitor *mon, const QDict *qdict) +void hmp_ioport_read(Monitor *mon, const QDict *qdict) { int size = qdict_get_int(qdict, "size"); int addr = qdict_get_int(qdict, "addr"); @@ -1038,7 +1038,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict) suffix, addr, size * 2, val); } -static void hmp_ioport_write(Monitor *mon, const QDict *qdict) +void hmp_ioport_write(Monitor *mon, const QDict *qdict) { int size = qdict_get_int(qdict, "size"); int addr = qdict_get_int(qdict, "addr"); @@ -1060,7 +1060,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict) } } -static void hmp_boot_set(Monitor *mon, const QDict *qdict) +void hmp_boot_set(Monitor *mon, const QDict *qdict) { Error *local_err = NULL; const char *bootdevice = qdict_get_str(qdict, "bootdevice"); @@ -1073,7 +1073,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict) } } -static void hmp_info_mtree(Monitor *mon, const QDict *qdict) +void hmp_info_mtree(Monitor *mon, const QDict *qdict) { bool flatview = qdict_get_try_bool(qdict, "flatview", false); bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false); @@ -1086,7 +1086,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict) int64_t dev_time; -static void hmp_info_profile(Monitor *mon, const QDict *qdict) +void hmp_info_profile(Monitor *mon, const QDict *qdict) { static int64_t last_cpu_exec_time; int64_t cpu_exec_time; @@ -1103,7 +1103,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict) dev_time = 0; } #else -static void hmp_info_profile(Monitor *mon, const QDict *qdict) +void hmp_info_profile(Monitor *mon, const QDict *qdict) { monitor_printf(mon, "Internal profiler not compiled\n"); } @@ -1112,7 +1112,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict) /* Capture support */ static QLIST_HEAD (capture_list_head, CaptureState) capture_head; -static void hmp_info_capture(Monitor *mon, const QDict *qdict) +void hmp_info_capture(Monitor *mon, const QDict *qdict) { int i; CaptureState *s; @@ -1123,7 +1123,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict) } } -static void hmp_stopcapture(Monitor *mon, const QDict *qdict) +void hmp_stopcapture(Monitor *mon, const QDict *qdict) { int i; int n = qdict_get_int(qdict, "n"); @@ -1139,7 +1139,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict) } } -static void hmp_wavcapture(Monitor *mon, const QDict *qdict) +void hmp_wavcapture(Monitor *mon, const QDict *qdict) { const char *path = qdict_get_str(qdict, "path"); int freq = qdict_get_try_int(qdict, "freq", 44100); @@ -1192,7 +1192,7 @@ static void hmp_warn_acl(void) warn_acl = true; } -static void hmp_acl_show(Monitor *mon, const QDict *qdict) +void hmp_acl_show(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); QAuthZList *auth = find_auth(mon, aclname); @@ -1219,7 +1219,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict) } } -static void hmp_acl_reset(Monitor *mon, const QDict *qdict) +void hmp_acl_reset(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); QAuthZList *auth = find_auth(mon, aclname); @@ -1236,7 +1236,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict) monitor_printf(mon, "acl: removed all rules\n"); } -static void hmp_acl_policy(Monitor *mon, const QDict *qdict) +void hmp_acl_policy(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *policy = qdict_get_str(qdict, "policy"); @@ -1277,7 +1277,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match) } } -static void hmp_acl_add(Monitor *mon, const QDict *qdict) +void hmp_acl_add(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *match = qdict_get_str(qdict, "match"); @@ -1330,7 +1330,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict) } } -static void hmp_acl_remove(Monitor *mon, const QDict *qdict) +void hmp_acl_remove(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *match = qdict_get_str(qdict, "match"); @@ -1799,13 +1799,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) /* Please update hmp-commands.hx when adding or changing commands */ static HMPCommand hmp_info_cmds[] = { +#if defined(SCSI_PROCESS) +#include "hmp-scsi-commands-info.h" +#else #include "hmp-commands-info.h" +#endif { NULL, NULL, }, }; /* hmp_cmds and hmp_info_cmds would be sorted at runtime */ HMPCommand hmp_cmds[] = { +#if defined(SCSI_PROCESS) +#include "hmp-scsi-commands.h" +#else #include "hmp-commands.h" +#endif { NULL, NULL, }, }; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index d78f5ca..6ea7211 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -179,4 +179,42 @@ void help_cmd(Monitor *mon, const char *name); void handle_hmp_command(MonitorHMP *mon, const char *cmdline); int hmp_compare_cmd(const char *name, const char *list); +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict); +void hmp_trace_event(Monitor *mon, const QDict *qdict); +void hmp_info_help(Monitor *mon, const QDict *qdict); +void hmp_info_registers(Monitor *mon, const QDict *qdict); +void hmp_info_jit(Monitor *mon, const QDict *qdict); +void hmp_info_opcount(Monitor *mon, const QDict *qdict); +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict); +void hmp_info_history(Monitor *mon, const QDict *qdict); +void hmp_info_cpustats(Monitor *mon, const QDict *qdict); +void hmp_info_trace_events(Monitor *mon, const QDict *qdict); +void hmp_logfile(Monitor *mon, const QDict *qdict); +void hmp_log(Monitor *mon, const QDict *qdict); +void hmp_singlestep(Monitor *mon, const QDict *qdict); +void hmp_gdbserver(Monitor *mon, const QDict *qdict); +void hmp_watchdog_action(Monitor *mon, const QDict *qdict); +void hmp_memory_dump(Monitor *mon, const QDict *qdict); +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict); +void hmp_gpa2hva(Monitor *mon, const QDict *qdict); +void hmp_gva2gpa(Monitor *mon, const QDict *qdict); +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict); +void hmp_do_print(Monitor *mon, const QDict *qdict); +void hmp_sum(Monitor *mon, const QDict *qdict); +void hmp_mouse_move(Monitor *mon, const QDict *qdict); +void hmp_mouse_button(Monitor *mon, const QDict *qdict); +void hmp_ioport_read(Monitor *mon, const QDict *qdict); +void hmp_ioport_write(Monitor *mon, const QDict *qdict); +void hmp_boot_set(Monitor *mon, const QDict *qdict); +void hmp_info_mtree(Monitor *mon, const QDict *qdict); +void hmp_info_profile(Monitor *mon, const QDict *qdict); +void hmp_info_capture(Monitor *mon, const QDict *qdict); +void hmp_stopcapture(Monitor *mon, const QDict *qdict); +void hmp_wavcapture(Monitor *mon, const QDict *qdict); +void hmp_acl_show(Monitor *mon, const QDict *qdict); +void hmp_acl_reset(Monitor *mon, const QDict *qdict); +void hmp_acl_policy(Monitor *mon, const QDict *qdict); +void hmp_acl_add(Monitor *mon, const QDict *qdict); +void hmp_acl_remove(Monitor *mon, const QDict *qdict); + #endif diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index dd3f5e6..059ad08 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -30,3 +30,5 @@ obj-y += $(QAPI_TARGET_MODULES:%=qapi-events-%.o) obj-y += qapi-events.o obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o) obj-y += qapi-commands.o + +remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o) diff --git a/qom/Makefile.objs b/qom/Makefile.objs index 07e50e5..16603d7 100644 --- a/qom/Makefile.objs +++ b/qom/Makefile.objs @@ -5,3 +5,4 @@ common-obj-$(CONFIG_SOFTMMU) += qom-hmp-cmds.o qom-qmp-cmds.o remote-pci-obj-$(CONFIG_MPQEMU) += object.o qom-qobject.o container.o remote-pci-obj-$(CONFIG_MPQEMU) += object_interfaces.o +remote-pci-obj-$(CONFIG_MPQEMU) += qom-qmp-cmds.o qom-hmp-cmds.o diff --git a/ui/Makefile.objs b/ui/Makefile.objs index e6da6ff..c3ac572 100644 --- a/ui/Makefile.objs +++ b/ui/Makefile.objs @@ -68,3 +68,5 @@ console-gl.o-libs += $(OPENGL_LIBS) egl-helpers.o-libs += $(OPENGL_LIBS) egl-context.o-libs += $(OPENGL_LIBS) egl-headless.o-libs += $(OPENGL_LIBS) + +remote-lsi-obj-$(CONFIG_MPQEMU) += vnc-stubs.o From patchwork Thu Oct 24 09:09:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208731 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB262139A for ; Thu, 24 Oct 2019 09:42:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 712542166E for ; Thu, 24 Oct 2019 09:42:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="E23NGreU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 712542166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZdM-0007EE-UD for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:42:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44043) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9d-0008Qz-4d for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9b-0004lS-7H for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:36 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60738) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9a-0004kr-Tg for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:35 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94MZv099572; Thu, 24 Oct 2019 09:11:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=isX1KAndj6ulSnNqa6bQoDEYVpd7UGNGOW9edca/S74=; b=E23NGreUKUTLzPI0U1Z7zVOfn4B9I+n1rF+U/zHeAYiEWqk9UbkJUHQEDCwSNcWy2DJe oLDz226cvZqL5pxDMBYZqbuMn8dazP5ivQHymb9wMqsZ9at7CEqGUZ312nmQcw7UAvn2 dKWVp6MKYF/PpewMoof1KU4VWRy1ZwLYCeO0lqrTwkeOpiFZat0CL+AklZuAM9NHTIFM 1d4eNgZ+ah0Yz7Te39k2SH/HKolaOdG+LURxsOFgkZ0Uci9EikjI/lXxSIOOeT8atkqY 4xz3wqqNPy3XpZM2F3clqbn7PX3GGsV0r96eGmUicmHZp/jqmwXzUVLRR0ovWbW9mtCp Dg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2ajg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:29 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Mrl047226; Thu, 24 Oct 2019 09:11:29 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu8ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:29 +0000 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 x9O9BSCm002614; Thu, 24 Oct 2019 09:11:28 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:28 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 37/49] multi-process/mon: Refactor monitor/chardev functions out of vl.c Date: Thu, 24 Oct 2019 05:09:18 -0400 Message-Id: <0dd799b9be18a4ad4c888b403fee3f823516ee45.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Some of the initialization helper functions w.r.t monitor & chardev in vl.c are also used by the remote process. Therefore, these functions are refactored into shared files that both QEMU & remote process could use. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 v3 -> v4 - Moved monitor related functions to monitor.c and chardev functions to char.c chardev/char.c | 14 ++++++++ include/chardev/char.h | 1 + include/monitor/monitor.h | 2 ++ monitor/monitor.c | 83 +++++++++++++++++++++++++++++++++++++++++- remote/remote-main.c | 1 + remote/remote-opts.c | 1 + vl-parse.c | 35 +++++++++--------- vl.c | 91 ----------------------------------------------- 8 files changed, 119 insertions(+), 109 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 7b6b2cb..9f339ec 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -1168,4 +1168,18 @@ static void register_types(void) qemu_add_machine_init_done_notifier(&chardev_machine_done_notify); } +int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + Error *local_err = NULL; + + if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + exit(0); + } + return 0; +} + type_init(register_types); diff --git a/include/chardev/char.h b/include/chardev/char.h index 087b202..bad076c 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -290,4 +290,5 @@ GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms, /* console.c */ void qemu_chr_parse_vc(QemuOpts *opts, ChardevBackend *backend, Error **errp); +int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp); #endif diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index a81eeff..ed1963a 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -42,5 +42,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags); int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd); void monitor_fdset_dup_fd_remove(int dup_fd); int64_t monitor_fdset_dup_fd_find(int dup_fd); +void monitor_parse(const char *optarg, const char *mode, bool pretty); +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp); #endif /* MONITOR_H */ diff --git a/monitor/monitor.c b/monitor/monitor.c index 12898b6..18bcb57 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -33,7 +33,10 @@ #include "sysemu/qtest.h" #include "sysemu/sysemu.h" #include "trace.h" - +#include "qemu/cutils.h" +#include "qemu/option.h" +#include "qemu-options.h" +#include "qemu/config-file.h" /* * To prevent flooding clients, events can be throttled. The * throttling is calculated globally, rather than per-Monitor @@ -609,6 +612,84 @@ void monitor_init_globals_core(void) NULL); } +void monitor_parse(const char *optarg, const char *mode, bool pretty) +{ + static int monitor_device_index; + QemuOpts *opts; + const char *p; + char label[32]; + + if (strstart(optarg, "chardev:", &p)) { + snprintf(label, sizeof(label), "%s", p); + } else { + snprintf(label, sizeof(label), "compat_monitor%d", + monitor_device_index); + opts = qemu_chr_parse_compat(label, optarg, true); + if (!opts) { + error_report("parse error: %s", optarg); + exit(1); + } + } + + opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); + qemu_opt_set(opts, "mode", mode, &error_abort); + qemu_opt_set(opts, "chardev", label, &error_abort); + if (!strcmp(mode, "control")) { + qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); + } else { + assert(pretty == false); + } + monitor_device_index++; +} + +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + Chardev *chr; + bool qmp; + bool pretty = false; + const char *chardev; + const char *mode; + + mode = qemu_opt_get(opts, "mode"); + if (mode == NULL) { + mode = "readline"; + } + if (strcmp(mode, "readline") == 0) { + qmp = false; + } else if (strcmp(mode, "control") == 0) { + qmp = true; + } else { + error_setg(errp, "unknown monitor mode \"%s\"", mode); + return -1; + } + + if (!qmp && qemu_opt_get(opts, "pretty")) { + warn_report("'pretty' is deprecated for HMP monitors, it has no effect " + "and will be removed in future versions"); + } + if (qemu_opt_get_bool(opts, "pretty", 0)) { + pretty = true; + } + + chardev = qemu_opt_get(opts, "chardev"); + if (!chardev) { + error_report("chardev is required"); + exit(1); + } + chr = qemu_chr_find(chardev); + if (chr == NULL) { + error_setg(errp, "chardev \"%s\" not found", chardev); + return -1; + } + + if (qmp) { + monitor_init_qmp(chr, pretty); + } else { + monitor_init_hmp(chr, true); + } + return 0; +} + QemuOptsList qemu_mon_opts = { .name = "mon", .implied_opt_name = "chardev", diff --git a/remote/remote-main.c b/remote/remote-main.c index 4459d26..30182dc 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -67,6 +67,7 @@ #include "qemu/cutils.h" #include "remote-opts.h" #include "monitor/monitor.h" +#include "chardev/char.h" #include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index 0ebe6b1..7de6195 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -55,6 +55,7 @@ #include "block/block.h" #include "remote/remote-opts.h" #include "include/qemu-common.h" +#include "monitor/monitor.h" #include "vl.h" /* diff --git a/vl-parse.c b/vl-parse.c index 4e2bd7c..011a9ef 100644 --- a/vl-parse.c +++ b/vl-parse.c @@ -110,49 +110,50 @@ int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; } -#if defined(CONFIG_MPQEMU) -int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp) +int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; + const char *remote = NULL; - dev = qdev_remote_add(opts, false /* this is drive */, errp); + remote = qemu_opt_get(opts, "rid"); + if (remote) { + return 0; + } + + dev = qdev_device_add(opts, errp); if (!dev) { - error_setg(errp, "qdev_remote_add failed for drive."); return -1; } object_unref(OBJECT(dev)); return 0; } -#endif #if defined(CONFIG_MPQEMU) -int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) +int rdrive_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; - dev = qdev_remote_add(opts, true /* this is device */, errp); + dev = qdev_remote_add(opts, false /* this is drive */, errp); if (!dev) { - error_setg(errp, "qdev_remote_add failed for device."); + error_setg(errp, "qdev_remote_add failed for drive."); return -1; } + object_unref(OBJECT(dev)); return 0; } #endif -int device_init_func(void *opaque, QemuOpts *opts, Error **errp) +#if defined(CONFIG_MPQEMU) +int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; - const char *remote = NULL; - remote = qemu_opt_get(opts, "rid"); - if (remote) { - return 0; - } - - dev = qdev_device_add(opts, errp); + dev = qdev_remote_add(opts, true /* this is device */, errp); if (!dev) { + error_setg(errp, "qdev_remote_add failed for device."); return -1; } - object_unref(OBJECT(dev)); return 0; } +#endif + diff --git a/vl.c b/vl.c index 1417ff2..a6a0db8 100644 --- a/vl.c +++ b/vl.c @@ -2279,19 +2279,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } -static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - Error *local_err = NULL; - - if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - exit(0); - } - return 0; -} #ifdef CONFIG_VIRTFS static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) @@ -2300,84 +2287,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) } #endif -static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - Chardev *chr; - bool qmp; - bool pretty = false; - const char *chardev; - const char *mode; - - mode = qemu_opt_get(opts, "mode"); - if (mode == NULL) { - mode = "readline"; - } - if (strcmp(mode, "readline") == 0) { - qmp = false; - } else if (strcmp(mode, "control") == 0) { - qmp = true; - } else { - error_setg(errp, "unknown monitor mode \"%s\"", mode); - return -1; - } - - if (!qmp && qemu_opt_get(opts, "pretty")) { - warn_report("'pretty' is deprecated for HMP monitors, it has no effect " - "and will be removed in future versions"); - } - if (qemu_opt_get_bool(opts, "pretty", 0)) { - pretty = true; - } - - chardev = qemu_opt_get(opts, "chardev"); - if (!chardev) { - error_report("chardev is required"); - exit(1); - } - chr = qemu_chr_find(chardev); - if (chr == NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev); - return -1; - } - - if (qmp) { - monitor_init_qmp(chr, pretty); - } else { - monitor_init_hmp(chr, true); - } - return 0; -} - -static void monitor_parse(const char *optarg, const char *mode, bool pretty) -{ - static int monitor_device_index = 0; - QemuOpts *opts; - const char *p; - char label[32]; - - if (strstart(optarg, "chardev:", &p)) { - snprintf(label, sizeof(label), "%s", p); - } else { - snprintf(label, sizeof(label), "compat_monitor%d", - monitor_device_index); - opts = qemu_chr_parse_compat(label, optarg, true); - if (!opts) { - error_report("parse error: %s", optarg); - exit(1); - } - } - - opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); - qemu_opt_set(opts, "mode", mode, &error_abort); - qemu_opt_set(opts, "chardev", label, &error_abort); - if (!strcmp(mode, "control")) { - qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); - } else { - assert(pretty == false); - } - monitor_device_index++; -} - struct device_config { enum { DEV_USB, /* -usbdevice */ From patchwork Thu Oct 24 09:09:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D99F14E5 for ; Thu, 24 Oct 2019 09:30:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 035CE205F4 for ; Thu, 24 Oct 2019 09:30:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="S8/reBYo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 035CE205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZRj-0002Pv-BN for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:30:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44071) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9f-000054-LE for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9e-0004o0-GN for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:39 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33272) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9e-0004nQ-8c for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:38 -0400 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 x9O94LMx094844; Thu, 24 Oct 2019 09:11:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=R9sV97ruVWh3xNTYa4ewtCCK7oypj4YQjLeFW289P68=; b=S8/reBYoJALU3TiRGzqszc8w6epYK5DUJy0BMeJfexpbqaXHmQby475XTE1/0RidCM1U hJs7kOis2vJk5vcQRpk0AcNEKm2GLdcf7J9FFRi+omGRtPoWIwoOyziqfr4fcaxFXrsW 547JIRcpC+RqMtZXfgC4yQd8t94Au6JJgDSy6lhgagURctzWE+izYe/ul3fGBASj/sEr Qn5TPKAofqMFLWT4g68ovWohTDWvRn8H5PUG6dp8AlRNbvhlx3HDAPbzKN8XjmCqMjWT 3Btr240VjoJn8F+BbXwfXLQufev0l2TPpwqaVpJJ4Gt6fs4k6Cli2zNLJFp0OPzw3mn0 4w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24sa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:33 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98m3f076178; Thu, 24 Oct 2019 09:11:33 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2vtjkj306b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:32 +0000 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 x9O9BVol002630; Thu, 24 Oct 2019 09:11:31 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:31 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 38/49] multi-process/mon: Initialize QMP module for remote processes Date: Thu, 24 Oct 2019 05:09:19 -0400 Message-Id: <453f1f773d33c9b37d6d2777a303883bda16dba7.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 remote/remote-main.c | 11 +++++++++++ remote/remote-opts.c | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index 30182dc..341b7cf 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -69,6 +69,7 @@ #include "monitor/monitor.h" #include "chardev/char.h" #include "sysemu/reset.h" +#include "vl.h" static MPQemuLinkState *mpqemu_link; @@ -476,6 +477,8 @@ int main(int argc, char *argv[]) module_call_init(MODULE_INIT_QOM); + monitor_init_globals(); + bdrv_init_with_whitelist(); if (qemu_init_main_loop(&err)) { @@ -491,6 +494,8 @@ int main(int argc, char *argv[]) qemu_add_opts(&qemu_device_opts); qemu_add_opts(&qemu_drive_opts); + qemu_add_opts(&qemu_chardev_opts); + qemu_add_opts(&qemu_mon_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); qemu_add_drive_opts(&qemu_common_drive_opts); qemu_add_drive_opts(&qemu_drive_opts); @@ -521,6 +526,12 @@ int main(int argc, char *argv[]) mpqemu_link_set_callback(mpqemu_link, process_msg); + qemu_opts_foreach(qemu_find_opts("chardev"), + chardev_init_func, NULL, &error_fatal); + + qemu_opts_foreach(qemu_find_opts("mon"), + mon_init_func, NULL, &error_fatal); + mpqemu_start_coms(mpqemu_link); return 0; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index 7de6195..1b1824e 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -98,6 +98,16 @@ void parse_cmdline(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_qmp: + monitor_parse(optarg, "control", false); + break; + case QEMU_OPTION_monitor: + if (!strncmp(optarg, "stdio", 5)) { + warn_report("STDIO not supported in remote process"); + } else if (strncmp(optarg, "none", 4)) { + monitor_parse(optarg, "readline", false); + } + break; default: break; } From patchwork Thu Oct 24 09:09:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208665 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E7831864 for ; Thu, 24 Oct 2019 09:33:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 03C1E20684 for ; Thu, 24 Oct 2019 09:33:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="nH7SC+q6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03C1E20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZVB-0006jk-8A for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:33:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44122) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9p-0000RD-Fo for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9n-0004uO-Aw for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:49 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:46382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9l-0004rT-By for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:47 -0400 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 x9O94N2A116351; Thu, 24 Oct 2019 09:11:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=/ad2stwObBARiiY2DPYHk5A75OfLrnaBriLueQ+wnxU=; b=nH7SC+q6Ewvqmki0bQv6kuq40smmkhapJmTVfSKaY8YBZAr9yJs6vHq0+QUv1U7BjiEW yBJKxc16HgM3XmXTI4qDu4nUGaOxtUpQOyHG+KxRypbPlkdznZuqO9/MwjU3p63iY89z e7ZiBfnDKuPNl7COGHJZsyQ1oWGj/KGrdEWmkbODyVwH+GDXSIBtsqiXqKiHFdEA9jos Zo74IZCMwGAEB3wQJPT2vpSMRHTfNIeTJlXpcU78INONluzCDtTnMobtr18m8K99YD4w Tr5lmXwfwcfJth51djVSFECU0PmAXF7kctUHVnEggds1IjmmLgtMcYK/cLQpgG5xb70t fg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2vqswtte3h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:36 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jj3170600; Thu, 24 Oct 2019 09:11:36 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2vtsk488t9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:36 +0000 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 x9O9BYu2002648; Thu, 24 Oct 2019 09:11:34 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:34 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 39/49] multi-process: prevent duplicate memory initialization in remote Date: Thu, 24 Oct 2019 05:09:20 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" When multiple controllers are configured in a remote process, it's better for the memory to be managed by only one of the proxy objects for that process, in order to conserve file descriptors. Added "mem_int" flag for this purpose. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v3 hw/proxy/qemu-proxy.c | 13 ++++++++++++- include/hw/proxy/qemu-proxy.h | 1 + qdev-monitor.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 5aada67..623a6c5 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -350,6 +350,13 @@ static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val, config_op_send(PCI_PROXY_DEV(d), addr, &val, l, CONF_WRITE); } +static void pci_proxy_dev_inst_init(Object *obj) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(obj); + + dev->mem_init = false; +} + static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); @@ -364,6 +371,7 @@ static const TypeInfo pci_proxy_dev_type_info = { .name = TYPE_PCI_PROXY_DEV, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIProxyDev), + .instance_init = pci_proxy_dev_inst_init, .abstract = true, .class_size = sizeof(PCIProxyDevClass), .class_init = pci_proxy_dev_class_init, @@ -460,7 +468,10 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio, pdev->mmio_sock); - configure_memory_sync(pdev->sync, pdev->mpqemu_link); + if (!pdev->mem_init) { + pdev->mem_init = true; + configure_memory_sync(pdev->sync, pdev->mpqemu_link); + } } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 672303c..17e07ac 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -63,6 +63,7 @@ struct PCIProxyDev { MPQemuLinkState *mpqemu_link; RemoteMemSync *sync; + bool mem_init; struct kvm_irqfd irqfd; EventNotifier intr; diff --git a/qdev-monitor.c b/qdev-monitor.c index f38849e..2a2c10b 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -713,10 +713,10 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->socket = old_pdev->socket; pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; + pdev->mem_init = true; } else { pdev->rsocket = managed ? rsocket : -1; pdev->socket = managed ? rsocket : -1; - } pdev->managed = managed; From patchwork Thu Oct 24 09:09:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75121139A for ; Thu, 24 Oct 2019 09:38:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3A23521872 for ; Thu, 24 Oct 2019 09:38:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="oXEVFY3R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A23521872 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZZH-0006yX-2e for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:38:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44140) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9r-0000Y2-LN for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9p-0004vh-DS for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:51 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:60924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9n-0004ro-8h for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:48 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94M5P099569; Thu, 24 Oct 2019 09:11:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=2Q/cmWeIRc1SHebJ+dlA8HdCfrEYFIIgUk1kTs8jfCI=; b=oXEVFY3RrYH8Vmge+yg0CIchF9Y63AfhCoyW8X8owGiLAJKmUu/Q8QhRp/WWyiMi7Mc8 nyfSov6kMtRVAfP0SCHXAyPZJscHIrcnlUiw1f2zEZjDGOv3UeFSq41jFTLfQ4zmtkBp 09ouygl/DptuuVwLL8tDT/xJuHx1yPs4W2wguwCdlBBSiX/oh8D0CTMYExnOy5jCOuaM VGRwGULlhHq/g+bnaMPoWLVqn4hs/R1aXi/+vYYEiDCGYbuLEkBk+eafnBarkpp5BGSB 8swzWMuRN+KUyVqq4f5t0SQUT/X+/jtaOcOj6vJeQHmXHUBtNaUk8swi1K4OtKnCdJy5 pA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2vqteq2ak1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:40 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LlY047154; Thu, 24 Oct 2019 09:11:40 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2vu0fnu8kv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:39 +0000 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 x9O9Bba4012334; Thu, 24 Oct 2019 09:11:38 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:37 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 40/49] multi-process/mig: build migration module in the remote process Date: Thu, 24 Oct 2019 05:09:21 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add Makefile support to enable migration in remote process Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 Makefile.objs | 4 ++++ Makefile.target | 1 + migration/Makefile.objs | 12 +++++++++++- net/Makefile.objs | 2 ++ replay/Makefile.objs | 2 +- stubs/migration.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/net-stub.c | 21 +++++++++++++++++++++ stubs/qapi-misc.c | 2 ++ stubs/replay.c | 8 ++++++++ stubs/vl-stub.c | 22 ++++++++++++++++++++++ vl-parse.c | 3 +++ vl.c | 2 -- 12 files changed, 124 insertions(+), 4 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index c72db88..ebb1938 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -79,6 +79,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o common-obj-$(CONFIG_WIN32) += os-win32.o common-obj-$(CONFIG_POSIX) += os-posix.o +remote-pci-obj-$(CONFIG_POSIX) += os-posix.o + common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration/ @@ -110,6 +112,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o common-obj-y += vl-parse.o +remote-pci-obj-$(CONFIG_MPQEMU) += net/ + ###################################################################### # qapi diff --git a/Makefile.target b/Makefile.target index 8010998..b60a837 100644 --- a/Makefile.target +++ b/Makefile.target @@ -225,6 +225,7 @@ all-remote-pci-obj-y += memory.o all-remote-pci-obj-y += exec.o all-remote-pci-obj-y += ioport.o all-remote-pci-obj-y += cpus.o +all-remote-pci-obj-y += migration/ram.o remote-pci-obj-y := remote-lsi-obj-y := diff --git a/migration/Makefile.objs b/migration/Makefile.objs index 016b6ab..c9682c6 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -14,4 +14,14 @@ common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o rdma.o-libs := $(RDMA_LIBS) -remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o +remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o +remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o +remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o +remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o +remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o +remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o +remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o +remote-pci-obj-$(CONFIG_RDMA) += rdma.o +remote-pci-obj-$(CONFIG_MPQEMU) += block.o diff --git a/net/Makefile.objs b/net/Makefile.objs index c5d076d..a8ad986 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -30,3 +30,5 @@ common-obj-$(CONFIG_WIN32) += tap-win32.o vde.o-libs = $(VDE_LIBS) common-obj-$(CONFIG_CAN_BUS) += can/ + +remote-pci-obj-$(CONFIG_MPQEMU) += announce.o diff --git a/replay/Makefile.objs b/replay/Makefile.objs index cee6539..c64b968 100644 --- a/replay/Makefile.objs +++ b/replay/Makefile.objs @@ -6,4 +6,4 @@ common-obj-y += replay-input.o common-obj-y += replay-char.o common-obj-y += replay-snapshot.o common-obj-y += replay-net.o -common-obj-y += replay-audio.o \ No newline at end of file +common-obj-y += replay-audio.o diff --git a/stubs/migration.c b/stubs/migration.c index 28ccf80..dbd12db 100644 --- a/stubs/migration.c +++ b/stubs/migration.c @@ -6,6 +6,35 @@ #include "qapi/qapi-types-migration.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-types-net.h" +#include "net/filter.h" +#include "net/colo-compare.h" + +#pragma weak qmp_query_migrate_capabilities +#pragma weak qmp_query_migrate_parameters +#pragma weak migrate_announce_params +#pragma weak qmp_query_migrate +#pragma weak qmp_migrate_set_capabilities +#pragma weak qmp_migrate_set_parameters +#pragma weak qmp_migrate_incoming +#pragma weak qmp_migrate_recover +#pragma weak qmp_migrate_pause +#pragma weak qmp_migrate +#pragma weak qmp_migrate_cancel +#pragma weak qmp_migrate_continue +#pragma weak qmp_migrate_set_cache_size +#pragma weak qmp_query_migrate_cache_size +#pragma weak qmp_migrate_set_speed +#pragma weak qmp_migrate_set_downtime +#pragma weak qmp_migrate_start_postcopy +#pragma weak migration_global_dump +#pragma weak save_snapshot +#pragma weak qmp_xen_save_devices_state +#pragma weak load_snapshot +#pragma weak qmp_xen_set_replication +#pragma weak qmp_query_xen_replication_status +#pragma weak qmp_xen_colo_do_checkpoint +#pragma weak qmp_query_colo_status +#pragma weak qmp_x_colo_lost_heartbeat MigrationInfo *qmp_query_migrate(Error **errp) { @@ -160,3 +189,23 @@ AnnounceParameters *migrate_announce_params(void) return NULL; } + +void colo_notify_filters_event(int event, Error **errp) +{ + qemu_debug_assert(0); +} + +void colo_notify_compares_event(void *opaque, int event, Error **errp) +{ + qemu_debug_assert(0); +} + +void colo_compare_register_notifier(Notifier *notify) +{ + qemu_debug_assert(0); +} + +void colo_compare_unregister_notifier(Notifier *notify) +{ + qemu_debug_assert(0); +} diff --git a/stubs/net-stub.c b/stubs/net-stub.c index 962827e..ddfd1e4 100644 --- a/stubs/net-stub.c +++ b/stubs/net-stub.c @@ -5,6 +5,8 @@ #include "qapi/qapi-commands-net.h" #include "qapi/qapi-commands-rocker.h" +#pragma weak qmp_announce_self + int qemu_find_net_clients_except(const char *id, NetClientState **ncs, NetClientDriver type, int max) { @@ -98,3 +100,22 @@ void netdev_add(QemuOpts *opts, Error **errp) { qemu_debug_assert(0); } + +NetClientState *qemu_get_queue(NICState *nic) +{ + qemu_debug_assert(0); + + return NULL; +} + +ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) +{ + qemu_debug_assert(0); + + return 0; +} + +void qemu_foreach_nic(qemu_nic_foreach func, void *opaque) +{ + qemu_debug_assert(0); +} diff --git a/stubs/qapi-misc.c b/stubs/qapi-misc.c index 3eeedd9..824eac1 100644 --- a/stubs/qapi-misc.c +++ b/stubs/qapi-misc.c @@ -5,6 +5,8 @@ #include "./qapi/qapi-types-dump.h" #include "qapi/qapi-commands-dump.h" +#pragma weak qmp_xen_load_devices_state + void qmp_dump_guest_memory(bool paging, const char *file, bool has_detach, bool detach, bool has_begin, int64_t begin, bool has_length, diff --git a/stubs/replay.c b/stubs/replay.c index 4a966ff..6fcd995 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -1,4 +1,5 @@ #include "qemu/osdep.h" +#include "qemu-common.h" #include "sysemu/replay.h" ReplayMode replay_mode; @@ -97,3 +98,10 @@ void replay_account_executed_instructions(void) void replay_add_blocker(Error *reason) { } + +bool replay_can_snapshot(void) +{ + qemu_debug_assert(0); + + return false; +} diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c index 606f078..460d1f3 100644 --- a/stubs/vl-stub.c +++ b/stubs/vl-stub.c @@ -169,3 +169,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path, return -1; } + +void qemu_system_killed(int signal, pid_t pid) +{ + qemu_debug_assert(0); +} + +void qemu_system_reset(ShutdownCause reason) +{ + qemu_debug_assert(0); +} + +bool runstate_store(char *str, size_t size) +{ + qemu_debug_assert(0); + + return false; +} + +void qemu_add_exit_notifier(Notifier *notify) +{ + qemu_debug_assert(0); +} diff --git a/vl-parse.c b/vl-parse.c index 011a9ef..1c8ecbe 100644 --- a/vl-parse.c +++ b/vl-parse.c @@ -41,6 +41,9 @@ #include "vl.h" +int only_migratable; /* turn it off unless user states otherwise */ +bool enable_mlock; + /***********************************************************/ /* QEMU Block devices */ diff --git a/vl.c b/vl.c index a6a0db8..8a26d81 100644 --- a/vl.c +++ b/vl.c @@ -148,7 +148,6 @@ const char* keyboard_layout = NULL; ram_addr_t ram_size; const char *mem_path = NULL; int mem_prealloc = 0; /* force preallocation of physical target memory */ -bool enable_mlock = false; bool enable_cpu_pm = false; int nb_nics; NICInfo nd_table[MAX_NICS]; @@ -189,7 +188,6 @@ const char *prom_envs[MAX_PROM_ENVS]; int boot_menu; bool boot_strict; uint8_t *boot_splash_filedata; -int only_migratable; /* turn it off unless user states otherwise */ bool wakeup_suspend_enabled; int icount_align_option; From patchwork Thu Oct 24 09:09:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D756112C for ; Thu, 24 Oct 2019 09:47:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71ECD20856 for ; Thu, 24 Oct 2019 09:47:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="f+R//iSg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71ECD20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZin-0001GN-NW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:47:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44163) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9t-0000da-Qi for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9r-0004x8-MG for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:53 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:46438) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9q-0004vN-Ph for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:51 -0400 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 x9O94MeW116323; Thu, 24 Oct 2019 09:11:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=AuHjnsJfixi1mdGb5rDbogFCok+K7oOPW4/ApU4ZAuc=; b=f+R//iSgIf0Uwjcz4UzFDrEfpuSMnQnvjZ8YDkKoiYdOuz1xFmYpVsaoFEH5rHzTHhyA S3LLO6+thIH6jPzSn9upuE9ZWVUUpEVmd2ipHseFdRaxdJ6UnY9sGRQ9+dqXsh0puZpj 1eJRwuN7xPk1AQXnx2Rf6S9H/ZDFmEcdb5Qwb36SLBSWvvW3O5Vj0MF5qsWrryaLZyCt 0hkvURjG2HjR1/8Ovmfj6uPIE0ny4voHxtk1nMZYjFXbc4uCuBqp4K07kHwZotBiAOpV OgxZT23Izx3xQbzN+tp2rBCqu+0rlwMM7PvthOW/5m/TjDptxArqVzrpnReMDJl8ruxr sQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2vqswtte3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:44 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O982jm093151; Thu, 24 Oct 2019 09:11:44 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2vtm244kf2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:43 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9Bef1009868; Thu, 24 Oct 2019 09:11:41 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:40 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 41/49] multi-process/mig: Enable VMSD save in the Proxy object Date: Thu, 24 Oct 2019 05:09:22 -0400 Message-Id: <8b15ab3d4fe51b792897ffc87e221bfb9317a836.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Collect the VMSD from remote process on the source and save it to the channel leading to the destination Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 hw/proxy/qemu-proxy.c | 132 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 135 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 623a6c5..ce72e6a 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -52,6 +52,14 @@ #include "util/event_notifier-posix.c" #include "hw/boards.h" #include "include/qemu/log.h" +#include "io/channel.h" +#include "migration/qemu-file-types.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" +#include "migration/migration.h" +#include "migration/vmstate.h" QEMUTimer *hb_timer; static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); @@ -62,6 +70,9 @@ static void stop_heartbeat_timer(void); static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx); static void broadcast_msg(MPQemuMsg *msg, bool need_reply); +#define PAGE_SIZE getpagesize() +uint8_t *mig_data; + static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx) { /* TODO: Add proper handler. */ @@ -357,14 +368,135 @@ static void pci_proxy_dev_inst_init(Object *obj) dev->mem_init = false; } +typedef struct { + QEMUFile *rem; + PCIProxyDev *dev; +} proxy_mig_data; + +static void *proxy_mig_out(void *opaque) +{ + proxy_mig_data *data = opaque; + PCIProxyDev *dev = data->dev; + uint8_t byte; + uint64_t data_size = PAGE_SIZE; + + mig_data = g_malloc(data_size); + + while (true) { + byte = qemu_get_byte(data->rem); + mig_data[dev->migsize++] = byte; + if (dev->migsize == data_size) { + data_size += PAGE_SIZE; + mig_data = g_realloc(mig_data, data_size); + } + } + + return NULL; +} + +static int proxy_pre_save(void *opaque) +{ + PCIProxyDev *pdev = opaque; + proxy_mig_data *mig_data; + QEMUFile *f_remote; + MPQemuMsg msg = {0}; + QemuThread thread; + Error *err = NULL; + QIOChannel *ioc; + uint64_t size; + int fd[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + return -1; + } + + ioc = qio_channel_new_fd(fd[0], &err); + if (err) { + error_report_err(err); + return -1; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "PCIProxyDevice-mig"); + + f_remote = qemu_fopen_channel_input(ioc); + + pdev->migsize = 0; + + mig_data = g_malloc0(sizeof(proxy_mig_data)); + mig_data->rem = f_remote; + mig_data->dev = pdev; + + qemu_thread_create(&thread, "Proxy MIG_OUT", proxy_mig_out, mig_data, + QEMU_THREAD_DETACHED); + + msg.cmd = START_MIG_OUT; + msg.bytestream = 0; + msg.num_fds = 2; + msg.fds[0] = fd[1]; + msg.fds[1] = GET_REMOTE_WAIT; + + mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + size = wait_for_remote(msg.fds[1]); + PUT_REMOTE_WAIT(msg.fds[1]); + + assert(size != ULLONG_MAX); + + /* + * migsize is being update by a separate thread. Using volatile to + * instruct the compiler to fetch the value of this variable from + * memory during every read + */ + while (*((volatile uint64_t *)&pdev->migsize) < size) { + } + + qemu_thread_cancel(&thread); + + qemu_fclose(f_remote); + close(fd[1]); + + return 0; +} + +static int proxy_post_save(void *opaque) +{ + MigrationState *ms = migrate_get_current(); + PCIProxyDev *pdev = opaque; + uint64_t pos = 0; + + while (pos < pdev->migsize) { + qemu_put_byte(ms->to_dst_file, mig_data[pos]); + pos++; + } + + qemu_fflush(ms->to_dst_file); + + return 0; +} + +const VMStateDescription vmstate_pci_proxy_device = { + .name = "PCIProxyDevice", + .version_id = 2, + .minimum_version_id = 1, + .pre_save = proxy_pre_save, + .post_save = proxy_post_save, + .fields = (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev), + VMSTATE_UINT64(migsize, PCIProxyDev), + VMSTATE_END_OF_LIST() + } +}; + static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); k->realize = pci_proxy_dev_realize; k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; + + dc->vmsd = &vmstate_pci_proxy_device; } static const TypeInfo pci_proxy_dev_type_info = { diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 17e07ac..b122e6d 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -89,6 +89,8 @@ struct PCIProxyDev { void (*init_proxy) (PCIDevice *dev, char *command, bool need_spawn, Error **errp); ProxyMemoryRegion region[PCI_NUM_REGIONS]; + + uint64_t migsize; }; typedef struct PCIProxyDevClass { diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 6fcc6f5..0ed7750 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -75,6 +75,7 @@ typedef enum { PROXY_PING, MMIO_RETURN, DEVICE_RESET, + START_MIG_OUT, MAX, } mpqemu_cmd_t; From patchwork Thu Oct 24 09:09:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26021139A for ; Thu, 24 Oct 2019 09:37:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EEE5020684 for ; Thu, 24 Oct 2019 09:37:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="LZxAypPz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEE5020684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZYX-0005CJ-Ny for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:37:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44197) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZ9w-0000k5-Uc for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9v-0004zw-Ih for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:56 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33530) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9v-0004zG-AE for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:55 -0400 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 x9O94Md6094848; Thu, 24 Oct 2019 09:11:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=ZazKF5zASnYtKiQ2UrpEQ5g+M+DSQpkar+tDkJDYdyE=; b=LZxAypPz/dC9VxXmzbXcKai8tV1iNNUBlF5PKBeyeDUy3ZMmAMs/NVcxjcQNWJB16D6K 6XOOUdq7XcbfE+szaMExVK5axXOC0/VGtG6MrsvENBsFEA08LicV75hx1UvOXleTCkMU HsnP+NwLhxgDZh6q2VRDnmhui+FZfuDs8RwbaFi8o+JMJ33/xC3//MEWFY9pXT2+Y0k4 xvvECJB6oEBzWVggeAodu7VvSMqlNb4S/cjYrqtoE7MLrdZm3W0h8kzmrBBmqyd56MO4 Ii/QjFI2Vq/0l3oNy31AM9pFyqQI1SUkW2qBLOKF/Rb8d/l1oxwJCKTkBkNFE1goNhQT bA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2vqu4r24su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:48 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O982qm093212; Thu, 24 Oct 2019 09:11:47 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2vtm244km6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:47 +0000 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 x9O9Bjvd012361; Thu, 24 Oct 2019 09:11:45 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:44 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 42/49] multi-process/mig: Send VMSD of remote to the Proxy object Date: Thu, 24 Oct 2019 05:09:23 -0400 Message-Id: <98de5369e4279decf5a09c17c513497d6153ed64.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The remote process sends the VMSD to the Proxy object, on the source side Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 migration/savevm.c | 27 +++++++++++++++++++++++++++ migration/savevm.h | 2 ++ remote/remote-main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 8d95e26..0c84142 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2903,3 +2903,30 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd) return !(vmsd && vmsd->unmigratable); } + +int qemu_remote_savevm(QEMUFile *f) +{ + SaveStateEntry *se; + int ret; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->vmsd || !vmstate_save_needed(se->vmsd, se->opaque)) { + continue; + } + + save_section_header(f, se, QEMU_VM_SECTION_FULL); + + ret = vmstate_save(f, se, NULL); + if (ret) { + qemu_file_set_error(f, ret); + return ret; + } + + save_section_footer(f, se); + } + + qemu_put_byte(f, QEMU_VM_EOF); + qemu_fflush(f); + + return 0; +} diff --git a/migration/savevm.h b/migration/savevm.h index 51a4b9c..a6582ac 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -64,4 +64,6 @@ void qemu_loadvm_state_cleanup(void); int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); +int qemu_remote_savevm(QEMUFile *f); + #endif diff --git a/remote/remote-main.c b/remote/remote-main.c index 341b7cf..0284039 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -66,6 +66,16 @@ #include "qemu/log.h" #include "qemu/cutils.h" #include "remote-opts.h" +#include "qapi/error.h" +#include "io/channel-util.h" + +#include "io/channel.h" +#include "io/channel-socket.h" +#include "migration/qemu-file-types.h" +#include "migration/savevm.h" +#include "migration/qemu-file-channel.h" +#include "migration/qemu-file.h" + #include "monitor/monitor.h" #include "chardev/char.h" #include "sysemu/reset.h" @@ -362,6 +372,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp) return 0; } +static void process_start_mig_out(MPQemuMsg *msg) +{ + int wait = msg->fds[1]; + Error *err = NULL; + QIOChannel *ioc; + QEMUFile *f; + + ioc = qio_channel_new_fd(msg->fds[0], &err); + if (err) { + error_report_err(err); + return; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel"); + + f = qemu_fopen_channel_output(ioc); + + bdrv_drain_all(); + (void)bdrv_flush_all(); + + (void)qemu_remote_savevm(f); + + qemu_fflush(f); + + notify_proxy(wait, (uint64_t)qemu_ftell(f)); + PUT_REMOTE_WAIT(wait); + + qemu_fclose(f); +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -454,6 +494,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case DEVICE_RESET: process_device_reset_msg(msg); break; + case START_MIG_OUT: + process_start_mig_out(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Thu Oct 24 09:09:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 289E514ED for ; Thu, 24 Oct 2019 09:52:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2D8D2166E for ; Thu, 24 Oct 2019 09:52:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="GZKogrjV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2D8D2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZnI-0004ts-EO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:52:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44554) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZBs-0006rx-RW for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZBr-0005zY-On for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:56 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:34864) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZBr-0005z1-GQ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:13:55 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O94rg6100053; Thu, 24 Oct 2019 09:13:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=D/pJ3W/Qz9XHj2UuEyUytLHj665k521TrYBAmheGze8=; b=GZKogrjVclAuXGvEmw/PYM/HdkuoeOIkapBzA+RIBYwKckoZYnsP2L3qzHhzRhTvpcdV sG8OIPkkiSVU8PJwh8BRxmA7z2tEfoxIWmRxtsUTpGkVR3CwUelkPUJHqurG7AKvfwGK mfjh3QRUEWe2/g/Vxg/GHT5oahR9a5VwjQORtfdycCRooWWVaFUPnDN8VG3YoG+dBmvD 54AG1/MPgdmSC2OXqjYcOmxN+7lTNDDJnMGsrZssNG2/r0JUJ3qpggNV2RHlxBVVkehC GWpdNrQS8sM1ahjilH4hFghp7H2RFquUOYWPtOUwnnvNvQ2cawxe4ySWpGRBT42UdHc9 3g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2vqteq2av8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:13:50 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97kQ4170676; Thu, 24 Oct 2019 09:11:49 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2vtsk4898v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:49 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BmYO024517; Thu, 24 Oct 2019 09:11:48 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:47 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 43/49] multi-process/mig: Load VMSD in the proxy object Date: Thu, 24 Oct 2019 05:09:24 -0400 Message-Id: <78a6b0d7f11ff5fc14e2dcfe2f5db5a5e292e726.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 141.146.126.78 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva The Proxy object loads the VMSD of remote process in source and send it to the remote process in the destination Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 hw/proxy/qemu-proxy.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 2 files changed, 51 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index ce72e6a..c85ffb3 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -473,12 +473,62 @@ static int proxy_post_save(void *opaque) return 0; } +static int proxy_post_load(void *opaque, int version_id) +{ + MigrationIncomingState *mis = migration_incoming_get_current(); + PCIProxyDev *pdev = opaque; + QEMUFile *f_remote; + MPQemuMsg msg = {0}; + Error *err = NULL; + QIOChannel *ioc; + uint64_t size; + uint8_t byte; + int fd[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + return -1; + } + + ioc = qio_channel_new_fd(fd[0], &err); + if (err) { + error_report_err(err); + return -1; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "proxy-migration-channel"); + + f_remote = qemu_fopen_channel_output(ioc); + + msg.cmd = START_MIG_IN; + msg.bytestream = 0; + msg.num_fds = 1; + msg.fds[0] = fd[1]; + + mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); + + size = pdev->migsize; + + while (size) { + byte = qemu_get_byte(mis->from_src_file); + qemu_put_byte(f_remote, byte); + size--; + } + + qemu_fflush(f_remote); + qemu_fclose(f_remote); + + close(fd[1]); + + return 0; +} + const VMStateDescription vmstate_pci_proxy_device = { .name = "PCIProxyDevice", .version_id = 2, .minimum_version_id = 1, .pre_save = proxy_pre_save, .post_save = proxy_post_save, + .post_load = proxy_post_load, .fields = (VMStateField[]) { VMSTATE_PCI_DEVICE(parent_dev, PCIProxyDev), VMSTATE_UINT64(migsize, PCIProxyDev), diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 0ed7750..05dc55e 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -76,6 +76,7 @@ typedef enum { MMIO_RETURN, DEVICE_RESET, START_MIG_OUT, + START_MIG_IN, MAX, } mpqemu_cmd_t; From patchwork Thu Oct 24 09:09:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 522E51747 for ; Thu, 24 Oct 2019 09:41:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2823C2166E for ; Thu, 24 Oct 2019 09:41:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="CLRwokvA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2823C2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZcm-0006Ep-U4 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:41:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44237) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZA1-0000uU-Fn for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZ9z-00052e-KE for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33590) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZ9y-00051r-UJ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:11:59 -0400 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 x9O94MZL094876; Thu, 24 Oct 2019 09:11:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=N8PJ1VFLIRV6XErZ+8XozqEUwrGNVhMsDzQHeeVf7e8=; b=CLRwokvAAFypNPmna/GjuHSF2ECutc/tmUMIZRK43SVh9Kq3QCMG2FkqkEsgbdnBuSJC gjgBExn3nYQMX6F3U9PqbOGotR7rCDHKhoqZitEfdo3apIYl0VmM28PG2dqPoYexdv6p ZKirPeyPnWMAOSbf2kL+ZWEf0DoyvZI1EpOvEof7PLdvVT7IGBpqaNqNrKXOvRdJVDf7 Hh8AneCpqdyQ5kgY+q3gyxmYzkUEs7V5yvh6J/UEIKioXqjHpNSGYU1PkBSP63SGlXtP qScpvEWuM284KTL7AxcdS8JlMHTZf3anVVteZ+pph50E7uUYTiEVMcX83DcTv/mopplf Aw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24t4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:52 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98jLj076057; Thu, 24 Oct 2019 09:11:52 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2vtjkj30sy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:52 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BpZP024555; Thu, 24 Oct 2019 09:11:51 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:50 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 44/49] multi-process/mig: refactor runstate_check into common file Date: Thu, 24 Oct 2019 05:09:25 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva runstate_check file is refactored into vl-parse.c Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 Makefile.objs | 2 ++ include/sysemu/runstate.h | 2 ++ runstate.c | 36 ++++++++++++++++++++++++++++++++++++ stubs/runstate-check.c | 3 +++ vl-parse.c | 1 - vl.c | 10 ---------- 6 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 runstate.c diff --git a/Makefile.objs b/Makefile.objs index ebb1938..66fbee0 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -38,6 +38,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o +remote-pci-obj-$(CONFIG_MPQEMU) += runstate.o ############################################################## # remote-lsi-obj-y is code used to implement remote LSI device @@ -111,6 +112,7 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS) common-obj-$(CONFIG_FDT) += device_tree.o common-obj-y += vl-parse.o +common-obj-y += runstate.o remote-pci-obj-$(CONFIG_MPQEMU) += net/ diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index 0b41555..e89ebf8 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -4,6 +4,8 @@ #include "qapi/qapi-types-run-state.h" #include "qemu/notify.h" +extern RunState current_run_state; + bool runstate_check(RunState state); void runstate_set(RunState new_state); int runstate_is_running(void); diff --git a/runstate.c b/runstate.c new file mode 100644 index 0000000..273345a --- /dev/null +++ b/runstate.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/runstate.h" + +/***********************************************************/ +/* QEMU state */ + +RunState current_run_state = RUN_STATE_PRECONFIG; + +bool runstate_check(RunState state) +{ + return current_run_state == state; +} diff --git a/stubs/runstate-check.c b/stubs/runstate-check.c index 2ccda2b..3038bcb 100644 --- a/stubs/runstate-check.c +++ b/stubs/runstate-check.c @@ -1,6 +1,9 @@ #include "qemu/osdep.h" #include "sysemu/runstate.h" + +#pragma weak runstate_check + bool runstate_check(RunState state) { return state == RUN_STATE_PRELAUNCH; diff --git a/vl-parse.c b/vl-parse.c index 1c8ecbe..3bf1f0f 100644 --- a/vl-parse.c +++ b/vl-parse.c @@ -159,4 +159,3 @@ int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) return 0; } #endif - diff --git a/vl.c b/vl.c index 8a26d81..725429b 100644 --- a/vl.c +++ b/vl.c @@ -665,11 +665,6 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) return 0; } -/***********************************************************/ -/* QEMU state */ - -static RunState current_run_state = RUN_STATE_PRECONFIG; - /* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested = RUN_STATE__MAX; static QemuMutex vmstop_lock; @@ -777,11 +772,6 @@ static const RunStateTransition runstate_transitions_def[] = { static bool runstate_valid_transitions[RUN_STATE__MAX][RUN_STATE__MAX]; -bool runstate_check(RunState state) -{ - return current_run_state == state; -} - bool runstate_store(char *str, size_t size) { const char *state = RunState_str(current_run_state); From patchwork Thu Oct 24 09:09:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208755 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4353514E5 for ; Thu, 24 Oct 2019 09:51:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1960C20856 for ; Thu, 24 Oct 2019 09:51:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="kAA25MZV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1960C20856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZmb-0003Jq-DM for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:51:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44255) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZA3-0000zX-Nd for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZA2-00054O-2D for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:03 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZA1-00053j-Q6 for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:02 -0400 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 x9O94NgR094929; Thu, 24 Oct 2019 09:11:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=IJpExN9EMVkwIbWLHn4MVZ2YU5YiDpieBDAknwGb7+w=; b=kAA25MZVo7X0ITodjipGSB2TQPqivho5Pq3DYVcBbtro+gQxusNjhT8AWjuOCU6pOr+t gNTqCOs6ywZvrSLXLSwQuQSK5yleP3OQW67w/Y4P0KI1LRk3xxZZLa3Vb8Cj7ut51qUB YV4e9pmXKjyyvJMPaRF41XR87+TNEismmpgGxTwGb4elwhI1j8MwgV4G8cP4umHN72Vp WT5cXhlueI+sypIeuiLyno/fENYE3jt0c0XpIwwo6wk71XUMbTY5wpP/NDa4WOy06GPZ 2YwfG6EtteFzlnIbblNBwrYKawZkACr7k9KWnkYmztNXBSTMYK4xT0anKX8JLBVq40V8 uA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2vqu4r24tb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:56 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98lcb076078; Thu, 24 Oct 2019 09:11:56 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2vtjkj30xc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:56 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BsU4009911; Thu, 24 Oct 2019 09:11:54 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:54 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 45/49] multi-process/mig: Synchronize runstate of remote process Date: Thu, 24 Oct 2019 05:09:26 -0400 Message-Id: <5ef7500148d9c15b236f551f6af7b8a4a8d6e81d.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Synchronize the runstate of the remote process with that of QEMU Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 hw/proxy/qemu-proxy.c | 18 ++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 8 ++++++++ include/sysemu/runstate.h | 1 + qdev-monitor.c | 13 ++++++++++++- remote/remote-main.c | 4 ++++ remote/remote-opts.c | 5 +++++ runstate.c | 5 +++++ 8 files changed, 55 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index c85ffb3..eff299b 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -44,6 +44,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/qstring.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "hw/proxy/qemu-proxy.h" #include "hw/proxy/memory-sync.h" #include "qom/object.h" @@ -656,6 +657,19 @@ static void init_proxy(PCIDevice *dev, char *command, bool need_spawn, Error **e } } +static void proxy_vm_state_change(void *opaque, int running, RunState state) +{ + PCIProxyDev *dev = opaque; + MPQemuMsg msg = { 0 }; + + msg.cmd = RUNSTATE_SET; + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.data1.runstate.state = state; + + mpqemu_msg_send(dev->mpqemu_link, &msg, dev->mpqemu_link->com); +} + static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { PCIProxyDev *dev = PCI_PROXY_DEV(device); @@ -681,6 +695,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) &dev->region[r].mr); } + dev->vmcse = qemu_add_vm_change_state_handler(proxy_vm_state_change, dev); + dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; @@ -706,6 +722,8 @@ static void pci_dev_exit(PCIDevice *pdev) if (!QLIST_EMPTY(&proxy_dev_list.devices)) { start_heartbeat_timer(); } + + qemu_del_vm_change_state_handler(dev->vmcse); } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index b122e6d..7fe987d 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -90,6 +90,8 @@ struct PCIProxyDev { ProxyMemoryRegion region[PCI_NUM_REGIONS]; + VMChangeStateEntry *vmcse; + uint64_t migsize; }; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 05dc55e..f5a0bbb 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -39,6 +39,8 @@ #include "exec/cpu-common.h" #include "exec/hwaddr.h" +#include "qapi/qapi-types-run-state.h" + #define TYPE_MPQEMU_LINK "mpqemu-link" #define MPQEMU_LINK(obj) \ OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) @@ -77,6 +79,7 @@ typedef enum { DEVICE_RESET, START_MIG_OUT, START_MIG_IN, + RUNSTATE_SET, MAX, } mpqemu_cmd_t; @@ -115,6 +118,10 @@ typedef struct { } mmio_ret_msg_t; typedef struct { + RunState state; +} runstate_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -125,6 +132,7 @@ typedef struct { bar_access_msg_t bar_access; set_irqfd_msg_t set_irqfd; mmio_ret_msg_t mmio_ret; + runstate_msg_t runstate; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index e89ebf8..c7ad916 100644 --- a/include/sysemu/runstate.h +++ b/include/sysemu/runstate.h @@ -8,6 +8,7 @@ extern RunState current_run_state; bool runstate_check(RunState state); void runstate_set(RunState new_state); +void remote_runstate_set(RunState state); int runstate_is_running(void); bool runstate_needs_reset(void); bool runstate_store(char *str, size_t size); diff --git a/qdev-monitor.c b/qdev-monitor.c index 2a2c10b..c6aa35c 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -34,6 +34,7 @@ #include "qemu/qemu-print.h" #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "migration/misc.h" #include "hw/boards.h" #include "hw/proxy/qemu-proxy.h" @@ -641,7 +642,7 @@ void qdev_proxy_fire(void) } DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, - char *command, int rsocket, bool managed, + char *cmd, int rsocket, bool managed, Error **errp) { DeviceState *ds; @@ -653,6 +654,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, const char *str; bool need_spawn = false; bool remote_exists = false; + char *command; if (strlen(rid) > MAX_RID_LENGTH) { error_setg(errp, "rid %s is too long.", rid); @@ -725,6 +727,12 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, need_spawn = true; } + if (runstate_check(RUN_STATE_INMIGRATE)) { + command = g_strdup_printf("%s %s", cmd, "-incoming defer"); + } else { + command = g_strdup(cmd); + } + pdev->init_proxy(PCI_DEVICE(ds), command, need_spawn, errp); qemu_mutex_lock(&proxy_list_lock); @@ -732,6 +740,9 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, qemu_mutex_unlock(&proxy_list_lock); qemu_opts_del(proxy_opts); + + g_free(command); + return ds; } diff --git a/remote/remote-main.c b/remote/remote-main.c index 0284039..2de5ddf 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -45,6 +45,7 @@ #include "qemu/main-loop.h" #include "qemu/config-file.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "block/block.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" @@ -497,6 +498,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case START_MIG_OUT: process_start_mig_out(msg); break; + case RUNSTATE_SET: + remote_runstate_set(msg->data1.runstate.state); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index 1b1824e..d3ae221 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -56,8 +56,10 @@ #include "remote/remote-opts.h" #include "include/qemu-common.h" #include "monitor/monitor.h" +#include "sysemu/runstate.h" #include "vl.h" + /* * In remote process, we parse only subset of options. The code * taken from vl.c to re-use in remote command line parser. @@ -101,6 +103,9 @@ void parse_cmdline(int argc, char **argv, char **envp) case QEMU_OPTION_qmp: monitor_parse(optarg, "control", false); break; + case QEMU_OPTION_incoming: + remote_runstate_set(RUN_STATE_INMIGRATE); + break; case QEMU_OPTION_monitor: if (!strncmp(optarg, "stdio", 5)) { warn_report("STDIO not supported in remote process"); diff --git a/runstate.c b/runstate.c index 273345a..9c5c627 100644 --- a/runstate.c +++ b/runstate.c @@ -34,3 +34,8 @@ bool runstate_check(RunState state) { return current_run_state == state; } + +void remote_runstate_set(RunState state) +{ + current_run_state = state; +} From patchwork Thu Oct 24 09:09:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208757 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7474B14E5 for ; Thu, 24 Oct 2019 09:52:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4ABB020856 for ; Thu, 24 Oct 2019 09:52:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lRDGEXRY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ABB020856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZmv-00041j-US for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:52:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44593) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZC2-0007DQ-NM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:14:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZC1-00063O-Dr for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:14:06 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:35552) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZC1-000631-4y for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:14:05 -0400 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 x9O94NgV094929; Thu, 24 Oct 2019 09:13:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=KK1DDsl5LoYz0kHfRVhfRF7BswS0wwZQTtSacPGONAc=; b=lRDGEXRY8A5sg6k7cou/n+fqputxDSIURN9M7YbDtMfo6c6xKVXbtOpJVNVa8dppgZ8R nqpGp99V8qbHXe7AX+uKu9biw7g4xsoHM7pAJ+Mx/YHFzofmFMp5Ng98IHY5Q5a3vv7D R/As9aUK6edoi5GTodFX8RIwZql7c6cU6vw4xphQJMxZT97FrsvK0gDJsi8Jx0RIziTt Rm0c5AJq0orrMdjCWmsGBPCk8EvNX+p0h9HytCKhzwGLt/Plf7EcLMxyHI/LvJQGz4vg xUwaGqYdNhYVrj6AznQSbFE0Dv/66bfMZFEUu/8VxrM/BAusBtL8qgQmy97x1xws5+d3 qQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2vqu4r253u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:13:59 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98LXG047110; Thu, 24 Oct 2019 09:11:58 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2vu0fnu90t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:11:58 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9BwV3024589; Thu, 24 Oct 2019 09:11:58 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:11:57 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 46/49] multi-process/mig: Restore the VMSD in remote process Date: Thu, 24 Oct 2019 05:09:27 -0400 Message-Id: <43b9bcb5db6e427b7ddc66af243f28d75a854dbc.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva The remote process accepts the VMSD from Proxy object and restores it Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 migration/savevm.c | 36 ++++++++++++++++++++++++++++++++++++ migration/savevm.h | 1 + remote/remote-main.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 0c84142..d730cd1 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2930,3 +2930,39 @@ int qemu_remote_savevm(QEMUFile *f) return 0; } + +int qemu_remote_loadvm(QEMUFile *f) +{ + uint8_t section_type; + int ret = 0; + + qemu_mutex_lock_iothread(); + + while (true) { + section_type = qemu_get_byte(f); + + if (qemu_file_get_error(f)) { + ret = qemu_file_get_error(f); + break; + } + + switch (section_type) { + case QEMU_VM_SECTION_FULL: + ret = qemu_loadvm_section_start_full(f, NULL); + if (ret < 0) { + break; + } + break; + case QEMU_VM_EOF: + goto out; + default: + ret = -EINVAL; + goto out; + } + } + +out: + qemu_mutex_unlock_iothread(); + + return ret; +} diff --git a/migration/savevm.h b/migration/savevm.h index a6582ac..415b72c 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -65,5 +65,6 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); int qemu_remote_savevm(QEMUFile *f); +int qemu_remote_loadvm(QEMUFile *f); #endif diff --git a/remote/remote-main.c b/remote/remote-main.c index 2de5ddf..600c894 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -81,6 +81,7 @@ #include "chardev/char.h" #include "sysemu/reset.h" #include "vl.h" +#include "migration/misc.h" static MPQemuLinkState *mpqemu_link; @@ -403,6 +404,30 @@ static void process_start_mig_out(MPQemuMsg *msg) qemu_fclose(f); } +static int process_start_mig_in(MPQemuMsg *msg) +{ + Error *err = NULL; + QIOChannel *ioc; + QEMUFile *f; + int rc = -EINVAL; + + ioc = qio_channel_new_fd(msg->fds[0], &err); + if (err) { + error_report_err(err); + return rc; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "remote-migration-channel"); + + f = qemu_fopen_channel_input(ioc); + + rc = qemu_remote_loadvm(f); + + qemu_fclose(f); + + return rc; +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -498,6 +523,13 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case START_MIG_OUT: process_start_mig_out(msg); break; + case START_MIG_IN: + if (process_start_mig_in(msg)) + { + error_setg(&err, "Incoming migration failed."); + goto finalize_loop; + } + break; case RUNSTATE_SET: remote_runstate_set(msg->data1.runstate.state); break; @@ -569,6 +601,8 @@ int main(int argc, char *argv[]) } mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd); + migration_object_init(); + parse_cmdline(argc - 3, argv + 3, NULL); mpqemu_link_set_callback(mpqemu_link, process_msg); From patchwork Thu Oct 24 09:09:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05C02112C for ; Thu, 24 Oct 2019 09:36:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFA0D20679 for ; Thu, 24 Oct 2019 09:36:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="T7ipIBkP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CFA0D20679 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZY2-0003nV-Hb for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:36:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44278) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAA-0001FK-Jk for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZA9-00058N-3q for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:10 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZA8-00057q-Rw for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:09 -0400 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 x9O94MZM094876; Thu, 24 Oct 2019 09:12:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=gCWsykrT2ZYwtnVJc3JGpccSZ6Ixl2ZrCx98KSbpob0=; b=T7ipIBkPDjTApC0Ir+dPxrP0oYEqzLyBNE2Rr9bCHxp1Hq+DF6GSc9gyCaWZ0D4TFKj2 7Q/rq7WPmteWmnGSVRjfzf4GGSMUuon5Mfb+YwggZugRuO5rrmzebnx5ngE9zBvNHvap V9jvF5C0rn3n0k/iZBVM/x0wBg2AHeNia1QUigA45yiR7sOdZixutwaXhkpOWOWDa4bx QjVvbKjHULXPfN2GK6Pg3cW4Il78hMtIIMigNk47Psry+e2eFfHa7MhylV6luuCEMHk9 TMz/qPRec3omKJaJvuyM+BqsA+0AKUU/Cg/Q32FWCxZYSi6O80NpwXAJQdrcQevMEq/R wQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2vqu4r24u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:03 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O97jeA170529; Thu, 24 Oct 2019 09:12:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2vtsk489s5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:02 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x9O9C11F024604; Thu, 24 Oct 2019 09:12:01 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:12:00 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 47/49] multi-process: Enable support for multiple devices in remote Date: Thu, 24 Oct 2019 05:09:28 -0400 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Add support to allow multiple devices to be configured in the remote process Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New patch in v4 hw/proxy/qemu-proxy.c | 3 +++ include/hw/proxy/qemu-proxy.h | 3 +++ include/io/mpqemu-link.h | 1 + qdev-monitor.c | 2 ++ remote/remote-main.c | 34 ++++++++++++++++++++++++---------- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index eff299b..2231c36 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -176,6 +176,7 @@ static void set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) msg.bytestream = 1; msg.size = qstring_get_length(qstr) + 1; msg.num_fds = 0; + msg.id = pdev->id; mpqemu_msg_send(pdev->mpqemu_link, &msg, pdev->mpqemu_link->com); @@ -322,6 +323,7 @@ static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, msg.size = sizeof(conf_data); msg.cmd = op; msg.bytestream = 1; + msg.id = dev->id; if (op == CONF_WRITE) { msg.num_fds = 0; @@ -602,6 +604,7 @@ static void setup_irqfd(PCIProxyDev *dev) memset(&msg, 0, sizeof(MPQemuMsg)); msg.cmd = SET_IRQFD; + msg.id = dev->id; msg.num_fds = 2; msg.fds[0] = event_notifier_get_fd(&dev->intr); msg.fds[1] = event_notifier_get_fd(&dev->resample); diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 7fe987d..6a0a574 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -57,6 +57,9 @@ extern const MemoryRegionOps proxy_default_ops; struct PCIProxyDev { PCIDevice parent_dev; + uint64_t id; + uint64_t nr_devices; + int n_mr_sections; MemoryRegionSection *mr_sections; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index f5a0bbb..ba81515 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -124,6 +124,7 @@ typedef struct { typedef struct { mpqemu_cmd_t cmd; int bytestream; + uint64_t id; size_t size; union { diff --git a/qdev-monitor.c b/qdev-monitor.c index c6aa35c..70a7a5a 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -716,9 +716,11 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; pdev->mem_init = true; + pdev->id = old_pdev->nr_devices++; } else { pdev->rsocket = managed ? rsocket : -1; pdev->socket = managed ? rsocket : -1; + pdev->id = pdev->nr_devices++; } pdev->managed = managed; diff --git a/remote/remote-main.c b/remote/remote-main.c index 600c894..93b8500 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -85,7 +85,8 @@ static MPQemuLinkState *mpqemu_link; -PCIDevice *remote_pci_dev; +PCIDevice **remote_pci_devs; +uint64_t nr_devices; bool create_done; static void process_config_write(MPQemuMsg *msg) @@ -93,7 +94,8 @@ static void process_config_write(MPQemuMsg *msg) struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; qemu_mutex_lock_iothread(); - pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l); + pci_default_write_config(remote_pci_devs[msg->id], conf->addr, conf->val, + conf->l); qemu_mutex_unlock_iothread(); } @@ -106,7 +108,8 @@ static void process_config_read(MPQemuMsg *msg) wait = msg->fds[0]; qemu_mutex_lock_iothread(); - val = pci_default_read_config(remote_pci_dev, conf->addr, conf->l); + val = pci_default_read_config(remote_pci_devs[msg->id], conf->addr, + conf->l); qemu_mutex_unlock_iothread(); notify_proxy(wait, val); @@ -366,9 +369,17 @@ static int setup_device(MPQemuMsg *msg, Error **errp) qstring_get_str(qobject_to_json(QOBJECT(qdict)))); return rc; } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { - remote_pci_dev = PCI_DEVICE(dev); + if (nr_devices <= msg->id) { + nr_devices = msg->id + 1; + remote_pci_devs = g_realloc(remote_pci_devs, + nr_devices * sizeof(PCIDevice *)); + } + + remote_pci_devs[msg->id] = PCI_DEVICE(dev); } + qemu_opts_del(opts); return 0; @@ -489,12 +500,15 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) } break; case SET_IRQFD: - process_set_irqfd_msg(remote_pci_dev, msg); - qdev_machine_creation_done(); - qemu_mutex_lock_iothread(); - qemu_run_machine_init_done_notifiers(); - qemu_mutex_unlock_iothread(); - create_done = true; + process_set_irqfd_msg(remote_pci_devs[msg->id], msg); + + if (!create_done) { + qdev_machine_creation_done(); + qemu_mutex_lock_iothread(); + qemu_run_machine_init_done_notifiers(); + qemu_mutex_unlock_iothread(); + create_done = true; + } break; case DRIVE_OPTS: if (setup_drive(msg, &err)) { From patchwork Thu Oct 24 09:09:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208753 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DA1F112C for ; Thu, 24 Oct 2019 09:48:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E7F920856 for ; Thu, 24 Oct 2019 09:48:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pdAsZKFe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E7F920856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZjA-0002KZ-R6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:48:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44359) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAM-0001hh-Ne for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAH-0005DJ-3I for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:22 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAG-0005CW-LC for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:17 -0400 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 x9O94M3O094924; Thu, 24 Oct 2019 09:12:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=aLhYYnqHNgg2qQ9OE4Raa3cbjnLtF2zrEpib/HC1Dls=; b=pdAsZKFecqaKehj9wjdJFsnty5Gv9Pl0+e5f73TSdQIgCfSu5UM7kjij5rm03xaoMGz6 ++3mYcKJuiT5pnL+l/eb3wsr40uL0rWGXWh2Kkwr6BYlrgqSXBqVSKMX/2USTMAWdWaK t6PBjo1ozJPRVYqcKbVyjRP0GN1Bn2aFrNKlCehBE+0QCtKLftjp5NhFh5TqOO7UXK/O tXVZYh4P8dGBBtSY3W2uJCJ++V4R4xvkmP4XVTScHWYtWW2ca0zTRWV716EP4n646wuY hfRffmhorKW2qHVKMof01hfrHTitOyg2wszZTXo2H1oswkcX6AQfImru37p5GCxkcmZp sQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2vqu4r24ur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:11 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O983md093230; Thu, 24 Oct 2019 09:12:10 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2vtm244mfm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:09 +0000 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 x9O9C8VW003078; Thu, 24 Oct 2019 09:12:08 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:12:08 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 48/49] multi-process: add the concept description to docs/devel/qemu-multiprocess Date: Thu, 24 Oct 2019 05:09:29 -0400 Message-Id: <1ee67238bd543959c3218612bff4acca06d15baa.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: John G Johnson Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- v2 -> v3: - Updated with latest design of this project v3 -> v4: - Updated document to RST format docs/devel/index.rst | 1 + docs/devel/qemu-multiprocess.rst | 1102 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 1103 insertions(+) create mode 100644 docs/devel/qemu-multiprocess.rst diff --git a/docs/devel/index.rst b/docs/devel/index.rst index 1ec61fc..edd3fe3 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -22,3 +22,4 @@ Contents: decodetree secure-coding-practices tcg + multi-process diff --git a/docs/devel/qemu-multiprocess.rst b/docs/devel/qemu-multiprocess.rst new file mode 100644 index 0000000..2c42c6e --- /dev/null +++ b/docs/devel/qemu-multiprocess.rst @@ -0,0 +1,1102 @@ +Disaggregating QEMU +=================== + +QEMU is often used as the hypervisor for virtual machines running in the +Oracle cloud. Since one of the advantages of cloud computing is the +ability to run many VMs from different tenants in the same cloud +infrastructure, a guest that compromised its hypervisor could +potentially use the hypervisor's access privileges to access data it is +not authorized for. + +QEMU can be susceptible to security attack because it is a large, +monolithic program that provides many features to the VMs it services. +Many of these feature can be configured out of QEMU, but even a reduced +configuration QEMU has a large amount of code a guest can potentially +attack in order to gain additional privileges. + +QEMU services +------------- + +QEMU can be broadly described as providing three main services. One is a +VM control point, where VMs can be created, migrated, re-configured, and +destroyed. A second is to emulate the CPU instructions within the VM, +often accelerated by HW virtualization features such as Intel's VT +extensions. Finally, it provides IO services to the VM by emulating HW +IO devices, such as disk and network devices. + +A disaggregated QEMU +~~~~~~~~~~~~~~~~~~~~ + +A disaggregated QEMU involves separating QEMU services into separate +host processes. Each of these processes can be given only the privileges +it needs to provide its service, e.g., a disk service could be given +access only the the disk images it provides, and not be allowed to +access other files, or any network devices. An attacker who compromised +this service would not be able to use this exploit to access files or +devices beyond what the disk service was given access to. + +A QEMU control process would remain, but in disaggregated mode, it would +be a control point that executes the processes needed to support the VM +being created, but have no direct interfaces to the VM. During VM +execution, it would still provide the user interface to hot-plug devices +or live migrate the VM. + +A first step in creating a disaggregated QEMU is to separate IO services +from the main QEMU program, which would continue to provide CPU +emulation. i.e., the control process would also be the CPU emulation +process. In a later phase, CPU emulation could be separated from the +control process. + +Disaggregating IO services +-------------------------- + +Disaggregating IO services is a good place to begin QEMU disaggregating +for a couple of reasons. One is the sheer number of IO devices QEMU can +emulate provides a large surface of interfaces which could potentially +be exploited, and, indeed, have been a source of exploits in the past. +Another is the modular nature of QEMU device emulation code provides +interface points where the QEMU functions that perform device emulation +can be separated from the QEMU functions that manage the emulation of +guest CPU instructions. + +QEMU device emulation +~~~~~~~~~~~~~~~~~~~~~ + +QEMU uses a object oriented SW architecture for device emulation code. +Configured objects are all compiled into the QEMU binary, then objects +are instantiated by name when used by the guest VM. For example, the +code to emulate a device named "foo" is always present in QEMU, but its +instantiation code is only run when the device is included in the target +VM. (e.g., via the QEMU command line as *-device foo*) + +The object model is hierarchical, so device emulation code names its +parent object (such as "pci-device" for a PCI device) and QEMU will +instantiate a parent object before calling the device's instantiation +code. + +Current separation models +~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to separate the device emulation code from the CPU emulation +code, the device object code must run in a different process. There are +a couple of existing QEMU features that can run emulation code +separately from the main QEMU process. These are examined below. + +vhost user model +^^^^^^^^^^^^^^^^ + +Virtio guest device drivers can be connected to vhost user applications +in order to perform their IO operations. This model uses special virtio +device drivers in the guest and vhost user device objects in QEMU, but +once the QEMU vhost user code has configured the vhost user application, +mission-mode IO is performed by the application. The vhost user +application is a daemon process that can be contacted via a known UNIX +domain socket. + +vhost socket +'''''''''''' + +As mentioned above, one of the tasks of the vhost device object within +QEMU is to contact the vhost application and send it configuration +information about this device instance. As part of the configuration +process, the application can also be sent other file descriptors over +the socket, which then can be used by the vhost user application in +various ways, some of which are described below. + +vhost MMIO store acceleration +''''''''''''''''''''''''''''' + +VMs are often run using HW virtualization features via the KVM kernel +driver. This driver allows QEMU to accelerate the emulation of guest CPU +instructions by running the guest in a virtual HW mode. When the guest +executes instructions that cannot be executed by virtual HW mode, +execution returns to the KVM driver so it can inform QEMU to emulate the +instructions in SW. + +One of the events that can cause a return to QEMU is when a guest device +driver accesses an IO location. QEMU then dispatches the memory +operation to the corresponding QEMU device object. In the case of a +vhost user device, the memory operation would need to be sent over a +socket to the vhost application. This path is accelerated by the QEMU +virtio code by setting up an eventfd file descriptor that the vhost +application can directly receive MMIO store notifications from the KVM +driver, instead of needing them to be sent to the QEMU process first. + +vhost interrupt acceleration +'''''''''''''''''''''''''''' + +Another optimization used by the vhost application is the ability to +directly inject interrupts into the VM via the KVM driver, again, +bypassing the need to send the interrupt back to the QEMU process first. +The QEMU virtio setup code configures the KVM driver with an eventfd +that triggers the device interrupt in the guest when the eventfd is +written. This irqfd file descriptor is then passed to the vhost user +application program. + +vhost access to guest memory +'''''''''''''''''''''''''''' + +The vhost application is also allowed to directly access guest memory, +instead of needing to send the data as messages to QEMU. This is also +done with file descriptors sent to the vhost user application by QEMU. +These descriptors can be passed to ``mmap()`` by the vhost application +to map the guest address space into the vhost application. + +IOMMUs introduce another level of complexity, since the address given to +the guest virtio device to DMA to or from is not a guest physical +address. This case is handled by having vhost code within QEMU register +as a listener for IOMMU mapping changes. The vhost application maintains +a cache of IOMMMU translations: sending translation requests back to +QEMU on cache misses, and in turn receiving flush requests from QEMU +when mappings are purged. + +applicability to device separation +'''''''''''''''''''''''''''''''''' + +Much of the vhost model can be re-used by separated device emulation. In +particular, the ideas of using a socket between QEMU and the device +emulation application, using a file descriptor to inject interrupts into +the VM via KVM, and allowing the application to ``mmap()`` the guest +should be re used. + +There are, however, some notable differences between how a vhost +application works and the needs of separated device emulation. The most +basic is that vhost uses custom virtio device drivers which always +trigger IO with MMIO stores. A separated device emulation model must +work with existing IO device models and guest device drivers. MMIO loads +break vhost store acceleration since they are synchronous - guest +progress cannot continue until the load has been emulated. By contrast, +stores are asynchronous, the guest can continue after the store event +has been sent to the vhost application. + +Another difference is that in the vhost user model, a single daemon can +support multiple QEMU instances. This is contrary to the security regime +desired, in which the emulation application should only be allowed to +access the files or devices the VM it's running on behalf of can access. +#### qemu-io model + +Qemu-io is a test harness used to test changes to the QEMU block backend +object code. (e.g., the code that implements disk images for disk driver +emulation) Qemu-io is not a device emulation application per se, but it +does compile the QEMU block objects into a separate binary from the main +QEMU one. This could be useful for disk device emulation, since its +emulation applications will need to include the QEMU block objects. + +New separation model based on proxy objects +------------------------------------------- + +A different model based on proxy objects in the QEMU program +communicating with remote emulation programs could provide separation +while minimizing the changes needed to the device emulation code. The +rest of this section is a discussion of how a proxy object model would +work. + +Remote emulation processes +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The remote emulation process will run the QEMU object hierarchy without +modification. The device emulation objects will be also be based on the +QEMU code, because for anything but the simplest device, it would not be +a tractable to re-implement both the object model and the many device +backends that QEMU has. + +The processes will communicate with the QEMU process over UNIX domain +sockets. The processes can be executed either as standalone processes, +or be executed by QEMU. In both cases, the host backends the emulation +processes will provide are specified on its command line, as they would +be for QEMU. For example: + +:: + + disk-proc -blockdev driver=file,node-name=file0,filename=disk-file0 \ + -blockdev driver=qcow2,node-name=drive0,file=file0 + +would indicate process *disk-proc* uses a qcow2 emulated disk named +*file0* as its backend. + +Emulation processes may emulate more than one guest controller. A common +configuration might be to put all controllers of the same device class +(e.g., disk, network, etc.) in a single process, so that all backends of +the same type can be managed by a single QMP monitor. + +communication with QEMU +^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes will recognize a *-socket* argument that +specifies the path of a UNIX domain socket used to communicate with the +QEMU process. If no *-socket* argument is present, the process will use +file descriptor 0 to communicate with QEMU. For example, + +:: + + disk-proc -socket /tmp/disk0-sock + +will communicate with QEMU using the socket path */tmp/dik0-sock*. + +remote process QMP monitor +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes can be monitored via QMP, similar to QEMU +itself. The QMP monitor socket is specified the same as for a QEMU +process: + +:: + + disk-proc -qmp unix:/tmp/disk-mon,server + +can be monitored over the UNIX socket path */tmp/disk-mon*. + +QEMU command line +~~~~~~~~~~~~~~~~~ + +The QEMU command line options will need to be modified to indicate which +items are emulated by a separate program, and which remain emulated by +QEMU itself. + +identifying remote emulation processes +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Remote emulation processes will be identified to QEMU using a *-remote* +command line option. This option can either specify a command that QEMU +will execute, or can specify a UNIX domain socket that QEMU can use to +connect to an existing process. Both forms require a "id" option that +identifies the process to later *-device* options. The process version +is: + +:: + + -remote id=disk-proc,command="disk-proc " + +And the socket version is: + +:: + + -remote id=disk-proc,socket="/tmp/disk0-sock" + +In the latter case, the remote process must be given the same socket on +its command line when it is executed: + +:: + + disk-proc -socket /tmp/disk0-sock + +identifying devices emulated remotely +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Devices that are to be emulated in a separate process will be identify +the remote process with a "remote" option on their *-device* command +line specification. e.g., an LSI SCSI controller and disk can be +specified as: + +:: + + -device lsi53c895a,id=scsi0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + +If these devices are emulated by remote process "disk-proc," as +described in the previous section, the QEMU command line would be: + +:: + + -device lsi53c895a,id=scsi0,remote=disk-proc + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,remote=disk-proc + +Some devices are implicitly created by the machine object. e.g., the q35 +machine object will create its PCI bus, and attach an ich9-ahci IDE +controller to it. In this case, options will need to be added to the +*-machine* command line. e.g., + +:: + + -machine pc-q35,ide-remote=disk-proc + +will use the remote process with an "id" of "disk-proc" to emulate the +IDE controller and its disks. + +The disks themselves still need to be specified with *-remote* option, +as in the example above. e.g., + +:: + + -device ide-hd,drive=drive0,bus=ide.0,unit=0,remote=disk-proc + +QEMU management of remote processes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Each *-remote* instance on the QEMU command line will create a remote +process proxy instance in QEMU. They will be held on a *QList* that can +be searched for by its "id" property. The remote process proxy will also +establish a communication channel between QEMU and the remote process. +This can be done in one of two methods: direction execution of the +process by QEMU with ``fork()`` and ``exec()`` system calls, or by +connecting to an existing process. + +direct execution +^^^^^^^^^^^^^^^^ + +When the remote process is directly executed, the remote process proxy +will setup a communication channel between itself and the emulation +process. This channel will be created using ``socketpair()`` and the +remote process side of the pair will be given to the process as file +descriptor 0. + +connecting to an existing process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Some environments wish to deny QEMU the ability to execute ``fork()`` +and ``exec()`` In these case, emulation processes will be started before +QEMU, and a UNIX domain socket will be given to each emulation process +to communicate with QEMU over. After communication is established, the +socket will be unlinked from the file system space by the QEMU process. + +communication with emulation process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +primary socket +'''''''''''''' + +Whether the process was executed by QEMU or externally, there will be a +primary socket for communication between QEMU and the remote process. +This channel will handle configuration commands from QEMU to the +process, either from the QEMU command line, or from QMP commands that +affect the devices being emulated by the process. This channel will only +allow one message to be pending at a time; if additional messages +arrive, they must wait for previous ones to be acknowledged from the +remote side. + +secondary sockets +''''''''''''''''' + +The primary socket can pass the file descriptors of secondary sockets +for operations that occur in parallel with commands on the primary +channel. These include MMIO operations generated by the guest, interrupt +notifications generated by the devices being emulated, or *vmstate* for +live migration. These secondary sockets will be created at the behest of +the device proxies that require them. A disk device proxy wouldn't need +any secondary sockets, but a disk controller device proxy may need both +an MMIO socket and an interrupt socket. + +emulation process attached via QMP command +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +There will be a new "attach-process" QMP command to facilitate device +hot-plug. This command's arguments will be the same as the *-remote* +command line when it's used to attach to a remote process. i.e., it will +need an "id" argument so that hot-plugged devices can later find it, and +a "socket" argument to identify the UNIX domain socket that will be used +to communicate with QEMU. + +QEMU device proxy objects +~~~~~~~~~~~~~~~~~~~~~~~~~ + +QEMU has an object model based on sub-classes inherited from the +"object" super-class. The sub-classes that are of interest here are the +"device" and "bus" sub-classes whose child sub-classes make up the +device tree of a QEMU emulated system. + +The proxy object model will use device proxy objects to replace the +device emulation code within the QEMU process. These objects will live +in the same place in the object and bus hierarchies as the objects they +replace. i.e., the proxy object for an LSI SCSI controller will be a +sub-class of the "pci-device" class, and will have the same PCI bus +parent and the same SCSI bus child objects as the LSI controller object +it replaces. + +After the QEMU command line has been parsed, the remote devices will be +instantiated in the same manner as local devices are. (i.e., +``qdev_device_add()``). In order to distinguish them from regular +*-device* device objects, their class name will be the name of the class +it replaces, with "-proxy" appended. e.g., the "lsi53c895a" proxy class +will be "lsi53c895a-proxy." + +device JSON description +^^^^^^^^^^^^^^^^^^^^^^^ + +The remote process needs a JSON representation of the command line +options used to create the object. This JSON representation is used to +create the corresponding object in the emulation process. e.g., for an +LSI SCSI controller invoked as: + +:: + + -device lsi53c895a,id=scsi0,remote=lsi-scsi + +the proxy object would create a + +:: + + { "driver" : "lsi53c895a", "id" : "scsi0" } + +JSON description. The "driver" option is assigned to the device name +when the command line is parsed, so the "-proxy" appended by the command +line parsing code is removed. The "remote" option isn't needed in the +JSON description since it only applies to the proxy object in the QEMU +process. + +device object whitelist +^^^^^^^^^^^^^^^^^^^^^^^ + +Some device objects may not need a proxy. These are devices with no +direct guest interfaces. (e.g., no MMIO, PIO, or interrupts). There will +be a whitelist of such devices, and any devices on this list will not be +instantiated in QEMU. Their JSON representation will still be sent to +the remote process, so the object can be created there. + +object initialization +^^^^^^^^^^^^^^^^^^^^^ + +QEMU object initialization occurs in two phases. The first +initialization happens once per object class. (i.e., there can be many +SCSI disks in an emulated system, but the "scsi-hd" class has its +``class_init()`` function called only once) The second phase happens +when each object's ``instance_init()`` function is called to initialize +each instance of the object. + +All device objects are sub-classes of the "device" class, so they also +have a ``realize()`` function that is called after ``instance_init()`` +is called and after the object's static properties have been +initialized. Many device objects don't even provide an instance\_init() +function, and do all their per-instance work in ``realize()``. + +class\_init +''''''''''' + +The ``class_init()`` method of a proxy object will, in general behave +similarly to the object it replaces, including setting any static +properties and methods needed by the proxy. + +instance\_init / realize +'''''''''''''''''''''''' + +The ``instance_init()`` and ``realize()`` functions would only need to +perform tasks related to being a proxy, such are registering its own +MMIO handlers, or creating a child bus that other proxy devices can be +attached to later. + +Other tasks will are device-specific. For example, PCI device objects +will initialize the PCI config space in order to make a valid PCI device +tree within the QEMU process. + +address space registration +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Most devices are driven by guest device driver accesses to IO addresses +or ports. The QEMU device emulation code uses QEMU's memory region +function calls (such as ``memory_region_init_io()``) to add callback +functions that QEMU will invoke when the guest accesses the device's +areas of the IO address space. When a guest driver does access the +device, the VM will exit HW virtualization mode and return to QEMU, +which will then lookup and execute the corresponding callback function. + +A proxy object would need to mirror the memory region calls the actual +device emulator would perform in its initialization code, but with its +own callbacks. When invoked by QEMU as a result of a guest IO operation, +they will forward the operation to the device emulation process. + +PCI config space +^^^^^^^^^^^^^^^^ + +PCI devices also have a configuration space that can be accessed by the +guest driver. Guest accesses to this space is not handled by the device +emulation object, but by its PCI parent object. Much of this space is +read-only, but certain registers (especially BAR and MSI-related ones) +need to be propagated to the emulation process. + +PCI parent proxy +'''''''''''''''' + +One way to propagate guest PCI config accesses is to create a +"pci-device-proxy" class that can serve as the parent of a PCI device +proxy object. This class's parent would be "pci-device" and it would +override the PCI parent's ``config_read()`` and ``config_write()`` +methods with ones that forward these operations to the emulation +program. + +interrupt receipt +^^^^^^^^^^^^^^^^^ + +A proxy for a device that generates interrupts will need to create a +socket to receive interrupt indications from the emulation process. An +incoming interrupt indication would then be sent up to its bus parent to +be injected into the guest. For example, a PCI device object may use +``pci_set_irq()``. + +live migration +^^^^^^^^^^^^^^ + +The proxy will register to save and restore any *vmstate* it needs over +a live migration event. The device proxy does not need to manage the +remote device's *vmstate*; that will be handled by the remote process +proxy (see below). + +QEMU remote device operation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Generic device operations, such as DMA, will be performs by the remote +process proxy by sending messages to the remote process. + +DMA operations +^^^^^^^^^^^^^^ + +DMA operations would be handled much like vhost applications do. One of +the initial messages sent to the emulation process is a guest memory +table. Each entry in this table consists of a file descriptor and size +that the emulation process can ``mmap()`` to directly access guest +memory, similar to ``vhost_user_set_mem_table()``. Note guest memory +must be backed by file descriptors, such as when QEMU is given the +*-mem-path* command line option. + +IOMMU operations +^^^^^^^^^^^^^^^^ + +When the emulated system includes an IOMMU, the remote process proxy in +QEMU will need to create a socket for IOMMU requests from the emulation +process. It will handle those requests with an +``address_space_get_iotlb_entry()`` call. In order to handle IOMMU +unmaps, the remote process proxy will also register as a listener on the +device's DMA address space. When an IOMMU memory region is created +within the DMA address space, an IOMMU notifier for unmaps will be added +to the memory region that will forward unmaps to the emulation process +over the IOMMU socket. + +device hot-plug via QMP +^^^^^^^^^^^^^^^^^^^^^^^ + +An QMP "device\_add" command can add a device emulated by a remote +process. It needs to add a "remote" option to the command, just as the +*-device* command line option does. The remote process may either be one +started at QEMU startup, or be one added by the "add-process" QMP +command described above. In either case, the remote process proxy will +forward the new device's JSON description to the corresponding emulation +process. + +live migration +^^^^^^^^^^^^^^ + +The remote process proxy will also register for live migration +notifications with ``vmstate_register()``. When called to save state, +the proxy will send the remote process a secondary socket file +descriptor to save the remote process's device *vmstate* over. The +incoming byte stream length and data will be saved as the proxy's +*vmstate*. When the proxy is resumed on its new host, this *vmstate* +will be extracted, and a secondary socket file descriptor will be sent +to the new remote process through which it receives the *vmstate* in +order to restore the devices there. + +device emulation in remote process +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The parts of QEMU that the emulation program will need include the +object model; the memory emulation objects; the device emulation objects +of the targeted device, and any dependent devices; and, the device's +backends. It will also need code to setup the machine environment, +handle requests from the QEMU process, and route machine-level requests +(such as interrupts or IOMMU mappings) back to the QEMU process. + +initialization +'''''''''''''' + +The process initialization sequence will follow the same sequence +followed by QEMU. It will first initialize the backend objects, then +device emulation objects. The JSON descriptions sent by the QEMU process +will drive which objects need to be created. + +- address spaces + +Before the device objects are created, the initial address spaces and +memory regions must be configured with ``memory_map_init()``. This +creates a RAM memory region object (*system\_memory*) and an IO memory +region object (*system\_io*). + +- RAM + +RAM memory region creation will follow how ``pc_memory_init()`` creates +them, but must use ``memory_region_init_ram_from_fd()`` instead of +``memory_region_allocate_system_memory()``. The file descriptors needed +will be supplied by the guest memory table from above. Those RAM regions +would then be added to the *system\_memory* memory region with +``memory_region_add_subregion()``. + +- PCI + +IO initialization will be driven by the JSON descriptions sent from the +QEMU process. For a PCI device, a PCI bus will need to be created with +``pci_root_bus_new()``, and a PCI memory region will need to be created +and added to the *system\_memory* memory region with +``memory_region_add_subregion_overlap()``. The overlap version is +required for architectures where PCI memory overlaps with RAM memory. + +MMIO handling +''''''''''''' + +The device emulation objects will use ``memory_region_init_io()`` to +install their MMIO handlers, and ``pci_register_bar()`` to associate +those handlers with a PCI BAR, as they do within QEMU currently. + +In order to use ``address_space_rw()`` in the emulation process to +handle MMIO requests from QEMU, the PCI physical addresses must be the +same in the QEMU process and the device emulation process. In order to +accomplish that, guest BAR programming must also be forwarded from QEMU +to the emulation process. + +interrupt injection +''''''''''''''''''' + +When device emulation wants to inject an interrupt into the VM, the +request climbs the device's bus object hierarchy until the point where a +bus object knows how to signal the interrupt to the guest. The details +depend on the type of interrupt being raised. + +- PCI pin interrupts + +On x86 systems, there is an emulated IOAPIC object attached to the root +PCI bus object, and the root PCI object forwards interrupt requests to +it. The IOAPIC object, in turn, calls the KVM driver to inject the +corresponding interrupt into the VM. The simplest way to handle this in +an emulation process would be to setup the root PCI bus driver (via +``pci_bus_irqs()``) to send a interrupt request back to the QEMU +process, and have the device proxy object reflect it up the PCI tree +there. + +- PCI MSI/X interrupts + +PCI MSI/X interrupts are implemented in HW as DMA writes to a +CPU-specific PCI address. In QEMU on x86, a KVM APIC object receives +these DMA writes, then calls into the KVM driver to inject the interrupt +into the VM. A simple emulation process implementation would be to send +the MSI DMA address from QEMU as a message at initialization, then +install an address space handler at that address which forwards the MSI +message back to QEMU. + +DMA operations +'''''''''''''' + +When a emulation object wants to DMA into or out of guest memory, it +first must use dma\_memory\_map() to convert the DMA address to a local +virtual address. The emulation process memory region objects setup above +will be used to translate the DMA address to a local virtual address the +device emulation code can access. + +IOMMU +''''' + +When an IOMMU is in use in QEMU, DMA translation uses IOMMU memory +regions to translate the DMA address to a guest physical address before +that physical address can be translated to a local virtual address. The +emulation process will need similar functionality. + +- IOTLB cache + +The emulation process will maintain a cache of recent IOMMU translations +(the IOTLB). When the translate() callback of an IOMMU memory region is +invoked, the IOTLB cache will be searched for an entry that will map the +DMA address to a guest PA. On a cache miss, a message will be sent back +to QEMU requesting the corresponding translation entry, which be both be +used to return a guest address and be added to the cache. + +- IOTLB purge + +The IOMMU emulation will also need to act on unmap requests from QEMU. +These happen when the guest IOMMU driver purges an entry from the +guest's translation table. + +live migration +'''''''''''''' + +When a remote process receives a live migration indication from QEMU, it +will set up a channel using the received file descriptor with +``qio_channel_socket_new_fd()``. This channel will be used to create a +*QEMUfile* that can be passed to ``qemu_save_device_state()`` to send +the process's device state back to QEMU. This method will be reversed on +restore - the channel will be passed to ``qemu_loadvm_state()`` to +restore the device state. + +Accelerating device emulation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The messages that are required to be sent between QEMU and the emulation +process can add considerable latency to IO operations. The optimizations +described below attempt to ameliorate this effect by allowing the +emulation process to communicate directly with the kernel KVM driver. +The KVM file descriptors created wold be passed to the emulation process +via initialization messages, much like the guest memory table is done. +#### MMIO acceleration + +Vhost user applications can receive guest virtio driver stores directly +from KVM. The issue with the eventfd mechanism used by vhost user is +that it does not pass any data with the event indication, so it cannot +handle guest loads or guest stores that carry store data. This concept +could, however, be expanded to cover more cases. + +The expanded idea would require a new type of KVM device: +*KVM\_DEV\_TYPE\_USER*. This device has two file descriptors: a master +descriptor that QEMU can use for configuration, and a slave descriptor +that the emulation process can use to receive MMIO notifications. QEMU +would create both descriptors using the KVM driver, and pass the slave +descriptor to the emulation process via an initialization message. + +data structures +''''''''''''''' + +- guest physical range + +The guest physical range structure describes the address range that a +device will respond to. It includes the base and length of the range, as +well as which bus the range resides on (e.g., on an x86machine, it can +specify whether the range refers to memory or IO addresses). + +A device can have multiple physical address ranges it responds to (e.g., +a PCI device can have multiple BARs), so the structure will also include +an enumerated identifier to specify which of the device's ranges is +being referred to. + ++--------+----------------------------+ +| Name | Description | ++========+============================+ +| addr | range base address | ++--------+----------------------------+ +| len | range length | ++--------+----------------------------+ +| bus | addr type (memory or IO) | ++--------+----------------------------+ +| id | range ID (e.g., PCI BAR) | ++--------+----------------------------+ + +- MMIO request structure + +This structure describes an MMIO operation. It includes which guest +physical range the MMIO was within, the offset within that range, the +MMIO type (e.g., load or store), and its length and data. It also +includes a sequence number that can be used to reply to the MMIO, and +the CPU that issued the MMIO. + ++----------+------------------------+ +| Name | Description | ++==========+========================+ +| rid | range MMIO is within | ++----------+------------------------+ +| offset | offset withing *rid* | ++----------+------------------------+ +| type | e.g., load or store | ++----------+------------------------+ +| len | MMIO length | ++----------+------------------------+ +| data | store data | ++----------+------------------------+ +| seq | sequence ID | ++----------+------------------------+ + +- MMIO request queues + +MMIO request queues are FIFO arrays of MMIO request structures. There +are two queues: pending queue is for MMIOs that haven't been read by the +emulation program, and the sent queue is for MMIOs that haven't been +acknowledged. The main use of the second queue is to validate MMIO +replies from the emulation program. + +- scoreboard + +Each CPU in the VM is emulated in QEMU by a separate thread, so multiple +MMIOs may be waiting to be consumed by an emulation program and multiple +threads may be waiting for MMIO replies. The scoreboard would contain a +wait queue and sequence number for the per-CPU threads, allowing them to +be individually woken when the MMIO reply is received from the emulation +program. It also tracks the number of posted MMIO stores to the device +that haven't been replied to, in order to satisfy the PCI constraint +that a load to a device will not complete until all previous stores to +that device have been completed. + +- device shadow memory + +Some MMIO loads do not have device side-effects. These MMIOs can be +completed without sending a MMIO request to the emulation program if the +emulation program shares a shadow image of the device's memory image +with the KVM driver. + +The emulation program will ask the KVM driver to allocate memory for the +shadow image, and will then use ``mmap()`` to directly access it. The +emulation program can control KVM access to the shadow image by sending +KVM an access map telling it which areas of the image have no +side-effects (and can be completed immediately), and which require a +MMIO request to the emulation program. The access map can also inform +the KVM drive which size accesses are allowed to the image. + +master descriptor +''''''''''''''''' + +The master descriptor is used by QEMU to configure the new KVM device. +The descriptor would be returned by the KVM driver when QEMU issues a +*KVM\_CREATE\_DEVICE* ``ioctl()`` with a *KVM\_DEV\_TYPE\_USER* type. + +KVM\_DEV\_TYPE\_USER device ops + + +The *KVM\_DEV\_TYPE\_USER* operations vector will be registered by a +``kvm_register_device_ops()`` call when the KVM system in initialized by +``kvm_init()``. These device ops are called by the KVM driver when QEMU +executes certain ``ioctl()`` operations on its KVM file descriptor. They +include: + +- create + +This routine is called when QEMU issues a *KVM\_CREATE\_DEVICE* +``ioctl()`` on its per-VM file descriptor. It will allocate and +initialize a KVM user device specific data structure, and assign the +*kvm\_device* private field to it. + +- ioctl + +This routine is invoked when QEMU issues an ``ioctl()`` on the master +descriptor. The ``ioctl()`` commands supported are defined by the KVM +device type. *KVM\_DEV\_TYPE\_USER* ones will need several commands: + +*KVM\_DEV\_USER\_SLAVE\_FD* creates the slave file descriptor thatwill +be passed to the device emulation program. Only one slave can be created +by each master descriptor. The file operations performed by this +descriptor are described below. + +The *KVM\_DEV\_USER\_PA\_RANGE* command configures a guest physical +address range that the slave descriptor will receive MMIO notifications +for. The range is specified by a guest physical range structure +argument. For buses that assign addresses to devices dynamically, this +command can be executed while the guest is running, such as the case +when a guest changes a device's PCI BAR registers. + +*KVM\_DEV\_USER\_PA\_RANGE* will use ``kvm_io_bus_register_dev()`` to +register *kvm\_io\_device\_ops* callbacks to be invoked when the guest +performs a MMIO operation within the range. When a range is changed, +``kvm_io_bus_unregister_dev()`` is used to remove the previous +instantiation. + +*KVM\_DEV\_USER\_TIMEOUT* will configure a timeout value that specifies +how long KVM will wait for the emulation process to respond to a MMIO +indication. + +- destroy + +This routine is called when the VM instance is destroyed. It will need +to destroy the slave descriptor; and free any memory allocated by the +driver, as well as the *kvm\_device* structure itself. + +slave descriptor +'''''''''''''''' + +The slave descriptor will have its own file operations vector, which +responds to system calls on the descriptor performed by the device +emulation program. + +- read + +A read returns any pending MMIO requests from the KVM driver as MMIO +request structures. Multiple structures can be returned if there are +multiple MMIO operations pending. The MMIO requests are moved from the +pending queue to the sent queue, and if there are threads waiting for +space in the pending to add new MMIO operations, they will be woken +here. + +- write + +A write also consists of a set of MMIO requests. They are compared to +the MMIO requests in the sent queue. Matches are removed from the sent +queue, and any threads waiting for the reply are woken. If a store is +removed, then the number of posted stores in the per-CPU scoreboard is +decremented. When the number is zero, and a non side-effect load was +waiting for posted stores to complete, the load is continued. + +- ioctl + +There are several ioctl()s that can be performed on the slave +descriptor. + +A *KVM\_DEV\_USER\_SHADOW\_SIZE* ``ioctl()`` causes the KVM driver to +allocate memory for the shadow image. This memory can later be +``mmap()``\ ed by the emulation process to share the emulation's view of +device memory with the KVM driver. + +A *KVM\_DEV\_USER\_SHADOW\_CTRL* ``ioctl()`` controls access to the +shadow image. It will send the KVM driver a shadow control map, which +specifies which areas of the image can complete guest loads without +sending the load request to the emulation program. It will also specify +the size of load operations that are allowed. + +- poll + +An emulation program will use the ``poll()`` call with a *POLLIN* flag +to determine if there are MMIO requests waiting to be read. It will +return if the pending MMIO request queue is not empty. + +- mmap + +This call allows the emulation program to directly access the shadow +image allocated by the KVM driver. As device emulation updates device +memory, changes with no side-effects will be reflected in the shadow, +and the KVM driver can satisfy guest loads from the shadow image without +needing to wait for the emulation program. + +kvm\_io\_device ops +''''''''''''''''''' + +Each KVM per-CPU thread can handle MMIO operation on behalf of the guest +VM. KVM will use the MMIO's guest physical address to search for a +matching *kvm\_io\_device* to see if the MMIO can be handled by the KVM +driver instead of exiting back to QEMU. If a match is found, the +corresponding callback will be invoked. + +- read + +This callback is invoked when the guest performs a load to the device. +Loads with side-effects must be handled synchronously, with the KVM +driver putting the QEMU thread to sleep waiting for the emulation +process reply before re-starting the guest. Loads that do not have +side-effects may be optimized by satisfying them from the shadow image, +if there are no outstanding stores to the device by this CPU. PCI memory +ordering demands that a load cannot complete before all older stores to +the same device have been completed. + +- write + +Stores can be handled asynchronously unless the pending MMIO request +queue is full. In this case, the QEMU thread must sleep waiting for +space in the queue. Stores will increment the number of posted stores in +the per-CPU scoreboard, in order to implement the PCI ordering +constraint above. + +interrupt acceleration +^^^^^^^^^^^^^^^^^^^^^^ + +This performance optimization would work much like a vhost user +application does, where the QEMU process sets up *eventfds* that cause +the device's corresponding interrupt to be triggered by the KVM driver. +These irq file descriptors are sent to the emulation process at +initialization, and are used when the emulation code raises a device +interrupt. + +intx acceleration +''''''''''''''''' + +Traditional PCI pin interrupts are level based, so, in addition to an +irq file descriptor, a re-sampling file descriptor needs to be sent to +the emulation program. This second file descriptor allows multiple +devices sharing an irq to be notified when the interrupt has been +acknowledged by the guest, so they can re-trigger the interrupt if their +device has not de-asserted its interrupt. + +intx irq descriptor + + +The irq descriptors are created by the proxy object +``using event_notifier_init()`` to create the irq and re-sampling +*eventds*, and ``kvm_vm_ioctl(KVM_IRQFD)`` to bind them to an interrupt. +The interrupt route can be found with +``pci_device_route_intx_to_irq()``. + +intx routing changes + + +Intx routing can be changed when the guest programs the APIC the device +pin is connected to. The proxy object in QEMU will use +``pci_device_set_intx_routing_notifier()`` to be informed of any guest +changes to the route. This handler will broadly follow the VFIO +interrupt logic to change the route: de-assigning the existing irq +descriptor from its route, then assigning it the new route. (see +``vfio_intx_update()``) + +MSI/X acceleration +'''''''''''''''''' + +MSI/X interrupts are sent as DMA transactions to the host. The interrupt +data contains a vector that is programed by the guest, A device may have +multiple MSI interrupts associated with it, so multiple irq descriptors +may need to be sent to the emulation program. + +MSI/X irq descriptor + + +This case will also follow the VFIO example. For each MSI/X interrupt, +an *eventfd* is created, a virtual interrupt is allocated by +``kvm_irqchip_add_msi_route()``, and the virtual interrupt is bound to +the eventfd with ``kvm_irqchip_add_irqfd_notifier()``. + +MSI/X config space changes + + +The guest may dynamically update several MSI-related tables in the +device's PCI config space. These include per-MSI interrupt enables and +vector data. Additionally, MSIX tables exist in device memory space, not +config space. Much like the BAR case above, the proxy object must look +at guest config space programming to keep the MSI interrupt state +consistent between QEMU and the emulation program. + +-------------- + +Disaggregated CPU emulation +--------------------------- + +After IO services have been disaggregated, a second phase would be to +separate a process to handle CPU instruction emulation from the main +QEMU control function. There are no object separation points for this +code, so the first task would be to create one. + +Host access controls +-------------------- + +Separating QEMU relies on the host OS's access restriction mechanisms to +enforce that the differing processes can only access the objects they +are entitled to. There are a couple types of mechanisms usually provided +by general purpose OSs. + +Discretionary access control +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Discretionary access control allows each user to control who can access +their files. In Linux, this type of control is usually too coarse for +QEMU separation, since it only provides three separate access controls: +one for the same user ID, the second for users IDs with the same group +ID, and the third for all other user IDs. Each device instance would +need a separate user ID to provide access control, which is likely to be +unwieldy for dynamically created VMs. + +Mandatory access control +~~~~~~~~~~~~~~~~~~~~~~~~ + +Mandatory access control allows the OS to add an additional set of +controls on top of discretionary access for the OS to control. It also +adds other attributes to processes and files such as types, roles, and +categories, and can establish rules for how processes and files can +interact. + +Type enforcement +^^^^^^^^^^^^^^^^ + +Type enforcement assigns a *type* attribute to processes and files, and +allows rules to be written on what operations a process with a given +type can perform on a file with a given type. QEMU separation could take +advantage of type enforcement by running the emulation processes with +different types, both from the main QEMU process, and from the emulation +processes of different classes of devices. + +For example, guest disk images and disk emulation processes could have +types separate from the main QEMU process and non-disk emulation +processes, and the type rules could prevent processes other than disk +emulation ones from accessing guest disk images. Similarly, network +emulation processes can have a type separate from the main QEMU process +and non-network emulation process, and only that type can access the +host tun/tap device used to provide guest networking. + +Category enforcement +^^^^^^^^^^^^^^^^^^^^ + +Category enforcement assigns a set of numbers within a given range to +the process or file. The process is granted access to the file if the +process's set is a superset of the file's set. This enforcement can be +used to separate multiple instances of devices in the same class. + +For example, if there are multiple disk devices provides to a guest, +each device emulation process could be provisioned with a separate +category. The different device emulation processes would not be able to +access each other's backing disk images. + +Alternatively, categories could be used in lieu of the type enforcement +scheme described above. In this scenario, different categories would be +used to prevent device emulation processes in different classes from +accessing resources assigned to other classes. From patchwork Thu Oct 24 09:09:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 11208745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45743139A for ; Thu, 24 Oct 2019 09:43:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C26B20684 for ; Thu, 24 Oct 2019 09:43:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="nLPpK41x" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C26B20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZel-0000ns-QH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 24 Oct 2019 05:43:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44341) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNZAK-0001cX-BJ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNZAI-0005ER-KW for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:20 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:46860) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNZAI-0005Dm-Cp for qemu-devel@nongnu.org; Thu, 24 Oct 2019 05:12:18 -0400 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 x9O94W6h116458; Thu, 24 Oct 2019 09:12:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : in-reply-to : references; s=corp-2019-08-05; bh=r7WpmqWffIH6HHULKlFk3v2+hFIpg5LOj271aEKzH8Y=; b=nLPpK41xWCPsGSbQaSGx5asoFjnLZThq+UCC48IT181zAmE0GgdWFKr9VRbO1sX2dgL1 w4bodZ7fu4/Z0tBxu7wCBtwS52XIPR1ROQzH8pxFoAb+DoDdmnVH/F6p57cXtfKfgdw7 g6meytSu0Dj9P9V4mrNfEEdjEsfD9nUZgxq1ZXy+XQr7Ehk+fwGgLTB6uJJ3/M9Z01ys GbsV4erAxDknXk6gLJ+gyaS1Z1LDGXtOj3snIcFoxHi+2+lW6A082f15j7uV5miQzTOq Y/zSSzAf6Adw7bcFw5lrEuEYB0rqZUkFtef9eICB4ZzsU7k1d/1hB92W0qDPk/e2/TXf GQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2vqswtte60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:13 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x9O98Mrv047226; Thu, 24 Oct 2019 09:12:12 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2vu0fnu9av-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Oct 2019 09:12:12 +0000 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 x9O9CBuN003120; Thu, 24 Oct 2019 09:12:11 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 Oct 2019 02:12:11 -0700 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [RFC v4 PATCH 49/49] multi-process: add configure and usage information Date: Thu, 24 Oct 2019 05:09:30 -0400 Message-Id: <2736d12f29d2c9051966864b5d865ab0f392b8d1.1571905346.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910240089 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9419 signatures=668684 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-1908290000 definitions=main-1910240089 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: elena.ufimtseva@oracle.com, fam@euphon.net, john.g.johnson@oracle.com, kraxel@redhat.com, jag.raman@oracle.com, quintela@redhat.com, mst@redhat.com, armbru@redhat.com, kanth.ghatraju@oracle.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, rth@twiddle.net, kwolf@redhat.com, berrange@redhat.com, mreitz@redhat.com, ross.lagerwall@citrix.com, marcandre.lureau@gmail.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- docs/qemu-multiprocess.txt | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/qemu-multiprocess.txt diff --git a/docs/qemu-multiprocess.txt b/docs/qemu-multiprocess.txt new file mode 100644 index 0000000..c29f4df --- /dev/null +++ b/docs/qemu-multiprocess.txt @@ -0,0 +1,86 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +To enable support for multi-process add --enable-mpqemu +to the list of options for the "configure" script. + + +2) Usage +-------- + +To start qemu with devices intended to run in a separate emulation +process without libvirtd support, the following should be used on QEMU +command line. As of now, we only support the emulation of lsi53c895a +in a separate process + +* Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-file is required to facilitate this, as follows: + + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=4096M,share=on + +* The devices to be emulated in the separate process are defined as + before with addition of "rid" suboption that serves as a remote group + identificator. + + -device ,rid="remote process id" + + For exmaple, for non multi-process qemu: + -device lsi53c895a,id=scsi0 device + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0 + -drive id=drive0,file=data-disk.img + + and for multi-process qemu and no libvirt + support (i.e. QEMU forks child processes): + -device lsi53c895a,id=scsi0,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid="0" + +* The command-line options for the remote process is added to the "command" + suboption of the newly added "-remote" option. + + -remote [socket],rid=,command="..." + + The drives to be emulated by the remote process are specified as part of + this command sub-option. The device to be used to connect to the monitor + is also specified as part of this suboption. + + For example, the following option adds a drive and monitor to the remote + process: + -remote rid=0,command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" subtion which we are in the + process of fixing. To work around this issue, it requires additional + "comma" characters as illustrated above, and in the example below. + +* Example QEMU command-line to launch lsi53c895a in a remote process + + #/bin/sh + qemu-system-x86_64 \ + -name "OL7.4" \ + -machine q35,accel=kvm \ + -smp sockets=1,cores=1,threads=1 \ + -cpu host \ + -m 2048 \ + -object memory-backend-file,id=mem,mem-path=/dev/shm/,size=2G,share=on \ + -numa node,memdev=mem \ + -device virtio-scsi-pci,id=virtio_scsi_pci0 \ + -drive id=drive_image1,if=none,format=raw,file=/root/ol7.qcow2 \ + -device scsi-hd,id=image1,drive=drive_image1,bus=virtio_scsi_pci0.0 \ + -boot d \ + -monitor stdio \ + -vnc :0 \ + -device lsi53c895a,id=lsi0,remote,rid=8,command="qemu-scsi-dev" \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0,remote,rid=8,command="qemu-scsi-dev"\ + -remote rid=8,command="-drive id=drive_image2,,file=/root/remote-process-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + We could connect to the monitor using the following command: + socat /home/qmp-sock stdio + + After hotplugging disks to the remote process, please execute the + following command in the guest to refresh the list of storage devices: + rescan_scsi_bus.sh -a