From patchwork Mon Feb 24 20:54:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=DiNWdT7e; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDxR2gZNz9sPg for ; Tue, 25 Feb 2020 08:00:59 +1100 (AEDT) Received: from localhost ([::1]:43018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KqX-0005A3-60 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:00:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50054) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Klx-0005nc-DW for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Klv-0002p9-Qr for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:13 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:43576) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Klv-0002mP-1G for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:11 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKsNiu032661; Mon, 24 Feb 2020 20:55: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-2020-01-29; bh=+KNQXGw+FOEATZ3vkQ3OTGzKbnHZBhe4ZmiQCe7+cw4=; b=DiNWdT7eTM4cWiyvgC//yGeNxHzqzJxrv2GXEwbJQncFTvpGxQnVXAcc/OKFnwf0/nGE 998GRQPtydI8D7Qc7erB+y27Xlunhqukf8vCZFPbDCdzElJcPzT9beLF1o05/+DHORUq Nr/O4gHhpa+SuQoBGXNuu4us1rXzmriE3NjJ51avRuff0XW4b3ERkgfTFYUULHOZzLGB Vvr0llmHx3o8hsHT583X8l3f7OiiTAvwL1npu5CdsstUO2q//pqCJJDdqvM7VbGnIFaN Y7CRycEN/LuhdzMruL1HXSimjW8l6Ye2Dua840kwi0ILgrKShbt0lmWsq59nE7SFET3k sQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2yauqua0hb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:55:59 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKptJU108463; Mon, 24 Feb 2020 20:55:59 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2ybe123ryh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:55:58 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKtune028202; Mon, 24 Feb 2020 20:55:56 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:55:56 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 01/50] multi-process: memory: alloc RAM from file at offset Date: Mon, 24 Feb 2020 15:54:52 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 bulkscore=0 clxscore=1011 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 Reviewed-by: Dr. David Alan Gilbert --- 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 c930040..e524185 100644 --- a/exec.c +++ b/exec.c @@ -1841,6 +1841,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { Error *err = NULL; @@ -1893,7 +1894,8 @@ static void *file_ram_alloc(RAMBlock *block, } area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED, block->flags & RAM_PMEM); + block->flags & RAM_SHARED, block->flags & RAM_PMEM, + offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2322,7 +2324,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) #ifdef CONFIG_POSIX RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp) + off_t offset, Error **errp) { RAMBlock *new_block; Error *local_err = NULL; @@ -2367,7 +2369,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, new_block->used_length = size; new_block->max_length = size; new_block->flags = ram_flags; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, + errp); if (!new_block->host) { g_free(new_block); return NULL; @@ -2397,7 +2400,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 5e59a3d..1b9f489 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp); + off_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); 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 aeaa8dc..131bc6c 100644 --- a/memory.c +++ b/memory.c @@ -1595,7 +1595,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, 0, &err); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; if (err) { mr->size = int128_zero(); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 27dcccd..a28f702 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 5a291cc..bd221dd 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 Mon Feb 24 20:54:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=iWZnQyrz; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDty2XyYz9sNg for ; Tue, 25 Feb 2020 07:58:50 +1100 (AEDT) Received: from localhost ([::1]:42844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KoS-0001PZ-7b for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 15:58:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50056) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Klx-0005ni-Dc for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Klw-0002pR-0p for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:13 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Klv-0002mw-1J for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:11 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrZj7164095; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=wZO3A2sTSI60a6rOgnl5OMupRv+gO+g6Ho8RtvDFics=; b=iWZnQyrzIpp1HQdyJc092xe49Gyj4EleomNOdJQ75g6pDWq4dP0flZVa7VayrYbKxhlI WajJE6tjdOC4fi9sQEXu+JCmSzP0CNro/Lf4j4pSKDH9Vua1eloQvnQJ5AIABT42Za73 YTtkNbdOSG+fnC4Xv55aCog7xoe0J10nAQcixyUEGqLTdV4euPUvPFXJ4st+oRGrlDja lYLMGaZRWt9HF9xyNXAhkOryoD/xl+41z1eprJyGTyMWrJTToYJNeEhrKGtG+XZjCzqn cEmHH06B1UqqZsJsew7nRkDL6culQIV2cgkBxCTRo5vQBjlU6hmdXWHbM40ydqAv3+0a qw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p929-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:01 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq7Wd088963; Mon, 24 Feb 2020 20:56:00 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dm9s7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:00 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKtwvp028220; Mon, 24 Feb 2020 20:55:58 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:55:58 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 02/50] multi-process: Refactor machine_init and exit notifiers Date: Mon, 24 Feb 2020 15:54:53 -0500 Message-Id: <5087037defe31df3abbcd677d206540247649b83.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Relocate machine_int and exit notifiers into common code Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/sysemu/sysemu.h | 2 ++ softmmu/vl.c | 42 ------------------------------------------ util/notify.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index dec64fc..2f37e2b 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -17,11 +17,13 @@ extern bool qemu_uuid_set; void qemu_add_exit_notifier(Notifier *notify); void qemu_remove_exit_notifier(Notifier *notify); +void qemu_run_exit_notifiers(void); extern bool machine_init_done; void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify); +void qemu_run_machine_init_done_notifiers(void); extern int autostart; diff --git a/softmmu/vl.c b/softmmu/vl.c index 92c7b3a..94a7b93 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -173,12 +173,6 @@ int icount_align_option; QemuUUID qemu_uuid; bool qemu_uuid_set; -static NotifierList exit_notifiers = - NOTIFIER_LIST_INITIALIZER(exit_notifiers); - -static NotifierList machine_init_done_notifiers = - NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); - bool xen_allowed; uint32_t xen_domid; enum xen_mode xen_mode = XEN_EMULATE; @@ -2324,21 +2318,6 @@ static MachineClass *machine_parse(const char *name, GSList *machines) return mc; } -void qemu_add_exit_notifier(Notifier *notify) -{ - notifier_list_add(&exit_notifiers, notify); -} - -void qemu_remove_exit_notifier(Notifier *notify) -{ - notifier_remove(notify); -} - -static void qemu_run_exit_notifiers(void) -{ - notifier_list_notify(&exit_notifiers, NULL); -} - static const char *pid_file; static Notifier qemu_unlink_pidfile_notifier; @@ -2349,27 +2328,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data) } } -bool machine_init_done; - -void qemu_add_machine_init_done_notifier(Notifier *notify) -{ - notifier_list_add(&machine_init_done_notifiers, notify); - if (machine_init_done) { - notify->notify(notify, NULL); - } -} - -void qemu_remove_machine_init_done_notifier(Notifier *notify) -{ - notifier_remove(notify); -} - -static void qemu_run_machine_init_done_notifiers(void) -{ - machine_init_done = true; - notifier_list_notify(&machine_init_done_notifiers, NULL); -} - static const QEMUOption *lookup_opt(int argc, char **argv, const char **poptarg, int *poptind) { diff --git a/util/notify.c b/util/notify.c index 76bab21..0e7479b 100644 --- a/util/notify.c +++ b/util/notify.c @@ -15,6 +15,15 @@ #include "qemu/osdep.h" #include "qemu/notify.h" +#include "sysemu/sysemu.h" + +bool machine_init_done; + +static NotifierList machine_init_done_notifiers = + NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); + +static NotifierList exit_notifiers = + NOTIFIER_LIST_INITIALIZER(exit_notifiers); void notifier_list_init(NotifierList *list) { @@ -74,3 +83,37 @@ int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data) } return ret; } + +void qemu_add_machine_init_done_notifier(Notifier *notify) +{ + notifier_list_add(&machine_init_done_notifiers, notify); + if (machine_init_done) { + notify->notify(notify, NULL); + } +} + +void qemu_remove_machine_init_done_notifier(Notifier *notify) +{ + notifier_remove(notify); +} + +void qemu_run_machine_init_done_notifiers(void) +{ + machine_init_done = true; + notifier_list_notify(&machine_init_done_notifiers, NULL); +} + +void qemu_add_exit_notifier(Notifier *notify) +{ + notifier_list_add(&exit_notifiers, notify); +} + +void qemu_remove_exit_notifier(Notifier *notify) +{ + notifier_remove(notify); +} + +void qemu_run_exit_notifiers(void) +{ + notifier_list_notify(&exit_notifiers, NULL); +} From patchwork Mon Feb 24 20:54:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=CPTSjCZb; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDrd0W3qz9sNg for ; Tue, 25 Feb 2020 07:56:49 +1100 (AEDT) Received: from localhost ([::1]:42356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmU-0005sX-Nq for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 15:56:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50053) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Klx-0005nT-Es for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Klw-0002pW-0s for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:13 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:43578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Klv-0002mR-1G for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:11 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrGAA032006; Mon, 24 Feb 2020 20:56:02 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-2020-01-29; bh=DWnK2tEiCnMsNUQ42mzfnKipe+sJE3pIp5q1h4XxRSY=; b=CPTSjCZb9tgQ4MMdFHmmRKZB3cBCinU+HPzDXFQ+Sdt8xnLLUQZjT8dIqsknrLtKgyeI D5lTjy0jobo+7/9vmfZJCvaaxJOV5gzoH8z+/DMQodQvzLWqyN5Jnqxoip7Tpw9NI/pz u/oCqGVbI04rUwy6K25TgstIh6vn6XoUcoQXbnOHQ/PeMTgMO+AsZxNRPSoa1+/hQ6yy PgGM+RNgmkWDxpSkquoo4Ev1iALEcoXRtLO4bxLL9fZhVc0xAfSvdb+eamfTb1JLNn/2 6AIx3j0TGsFSYjI0IoqisZJYRe3+DU2z8BABNE3NYZL8kjfQFavJPievxO0XnVVeCryq uw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2yauqua0hr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKptdA108379; Mon, 24 Feb 2020 20:56:02 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ybe123s3j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:02 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu04S007709; Mon, 24 Feb 2020 20:56:00 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:55:59 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 03/50] multi-process: add a command line option for debug file Date: Mon, 24 Feb 2020 15:54:54 -0500 Message-Id: <5b93441cf970aff1072c80ca6487bb36c02558a5.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 f4724f7..a039ddb 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -64,6 +64,7 @@ static inline bool qemu_log_separate(void) #define CPU_LOG_PLUGIN (1 << 18) /* LOG_STRACE is used for user-mode strace logging. */ #define LOG_STRACE (1 << 19) +#define LOG_REMOTE_DEBUG (1 << 20) /* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we diff --git a/util/log.c b/util/log.c index 2da6cb3..1f90e70 100644 --- a/util/log.c +++ b/util/log.c @@ -334,6 +334,8 @@ const QEMULogItem qemu_log_items[] = { #endif { LOG_STRACE, "strace", "log every user-mode syscall, its input, and its result" }, + { LOG_REMOTE_DEBUG, "rdebug", + "log remote debug" }, { 0, NULL, NULL }, }; From patchwork Mon Feb 24 20:54:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=UgQm5wis; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFcw0QXLz9sNg for ; Tue, 25 Feb 2020 08:31:44 +1100 (AEDT) Received: from localhost ([::1]:44008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LKH-0007Wn-UO for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:31:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51521) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Knw-0001Rx-5M for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:58:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Knr-0004rw-At for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:58:16 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:44124) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Knr-0004qT-2O for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:58:11 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqV3c017584; Mon, 24 Feb 2020 20:58: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-2020-01-29; bh=SdLE47JD6InZD5kyVt26ll1iDHLPsBDVoVpfCrCe9es=; b=UgQm5wisoTSpT4xx6p7gCxi5Pj0BMtE9VxbSZ4qhK2dCGhfh/X8fKbe3Vtt339leY6DP AGjIjveCoPQOW5e+Vb0Te3T02cHvq+Bdu+MePwgdrmE0i3G60C7nygH8Bai94rLf2zZh GHey18TlBghbjCsUTZzKUUVVY1+U1dJvthczkwSYNIlCzzIzr9ft3W1nc4BB+A6N46kL FhljtqHJ1EG88CVg/RwE0m8xaENkkp9pix98LV1XCOXZXbIIk9D0zxGRgDVz/PgZa0CJ akwf+2kGGmJJ7so1aMQB4A9IyLGGGafutePbROVfWyfrr12D29XF2NuU1zA9tu/xf6NN Pw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhys3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:58:03 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqoFH172448; Mon, 24 Feb 2020 20:56:03 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2ybdshkr6r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:03 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu1be007726; Mon, 24 Feb 2020 20:56:01 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:01 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 04/50] multi-process: Add stub functions to facilate build of multi-process Date: Mon, 24 Feb 2020 15:54:55 -0500 Message-Id: <965ba5bfe6f23afce2cbd3e9247692e132b1d990.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 | 97 +++++++++++++++++++++++++++++++++++++++++++++++ stubs/audio.c | 12 ++++++ stubs/machine-init-done.c | 4 ++ stubs/monitor.c | 41 ++++++++++++++++++++ stubs/net-stub.c | 31 +++++++++++++++ stubs/replay.c | 14 +++++++ stubs/vl-stub.c | 79 ++++++++++++++++++++++++++++++++++++++ stubs/vmstate.c | 19 ++++++++++ stubs/xen-mapcache.c | 22 +++++++++++ 10 files changed, 324 insertions(+) create mode 100644 stubs/audio.c create mode 100644 stubs/net-stub.c create mode 100644 stubs/vl-stub.c create mode 100644 stubs/xen-mapcache.c diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 82f118d..baa6b38 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 677191a..9b55fb0 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -11,14 +11,111 @@ */ #include "qemu/osdep.h" +#include "qemu-common.h" #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..a34dc87 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 *err) +{ +} 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 5974ec1..2e3feee 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -88,3 +88,17 @@ int replay_read_random(void *buf, size_t len) { return 0; } + +bool replay_has_checkpoint(void) +{ + return false; +} + +int replay_get_instructions(void) +{ + return 0; +} + +void replay_account_executed_instructions(void) +{ +} 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 cc4fe41..c7c015a 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -1,7 +1,9 @@ #include "qemu/osdep.h" #include "migration/vmstate.h" +#include "migration/misc.h" const VMStateDescription vmstate_dummy = {}; +const VMStateInfo vmstate_info_timer; int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, @@ -23,3 +25,20 @@ bool vmstate_check_only_migratable(const VMStateDescription *vmsd) { return true; } + +void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_unregister_ram(MemoryRegion *mr, DeviceState *dev) +{ +} + +void vmstate_register_ram_global(MemoryRegion *mr) +{ +} + +bool migration_is_idle(void) +{ + return true; +} 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 Mon Feb 24 20:54:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243464 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Ucg0/Pnk; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDrg3vJxz9sNg for ; Tue, 25 Feb 2020 07:56:51 +1100 (AEDT) Received: from localhost ([::1]:42370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmX-0005zi-Ae for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 15:56:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50095) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km0-0005sQ-3Z for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kly-0002ro-1P for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:16 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:43664) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Klx-0002qj-OU for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:13 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrdRc032164; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=4j44/db0z3X4bb/dwPNOT7ZOj0JyKc0JiRVxGFJ1CHM=; b=Ucg0/PnkUWn9NvDHAcQ7YXpEG98Gfo8vgoaoqb+soQ7J+go0xAHx0XXJ40jcUip/7gOq gDZpOVDX6oYeVlMU9PNLRfhPGyVQ0dR45cLAtDAocg/laUesusyHi+KFokjRwTrhEs3e ns0Pv7H8xa6cBjY71x1YOJEJXG/viytIF5Iz2vU+wiN1QRgWfPoVqMikzpac6k7hcUv+ lv/KhhgW8y3tyPDkYfA1nsxStGtwAoYMAAurz+NObGMi4W5FB9xFl8VIna350+ekOq1j oDcUPTFJAiyJNrvAIxj8LWRfCTo5iJOMQrtV9g8nHqfFuwRDgzis9tSV36rluLkIOspS NA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2yauqua0j1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:06 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq8T9089084; Mon, 24 Feb 2020 20:56:05 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2yby5dma30-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:05 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu36i029536; Mon, 24 Feb 2020 20:56:03 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:02 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 05/50] multi-process: Add config option for multi-process QEMU Date: Mon, 24 Feb 2020 15:54:56 -0500 Message-Id: <4d1ff53bed128a4d211448649bd3557e81774500.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 48d6f89..ab1e344 100755 --- a/configure +++ b/configure @@ -506,6 +506,7 @@ libpmem="" default_devices="yes" plugins="no" fuzzing="no" +mpqemu="no" supported_cpu="no" supported_os="no" @@ -1572,6 +1573,10 @@ for opt do ;; --disable-fuzzing) fuzzing=no ;; + --enable-mpqemu) mpqemu=yes + ;; + --disable-mpqemu) mpqemu=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1860,6 +1865,7 @@ disabled with --disable-FEATURE, default is enabled if available: debug-mutex mutex debugging support libpmem libpmem support xkbcommon xkbcommon support + mpqemu multi-process QEMU support NOTE: The object files are built at the place where configure is launched EOF @@ -6690,6 +6696,7 @@ echo "libudev $libudev" echo "default devices $default_devices" echo "plugin support $plugins" echo "fuzzing support $fuzzing" +echo "multiprocess QEMU $mpqemu" if test "$supported_cpu" = "no"; then echo @@ -7501,6 +7508,10 @@ if test "$libpmem" = "yes" ; then echo "CONFIG_LIBPMEM=y" >> $config_host_mak fi +if test "$mpqemu" = "yes" ; then + echo "CONFIG_MPQEMU=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi From patchwork Mon Feb 24 20:54:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=nidLenEi; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDxR5RZKz9sRG for ; Tue, 25 Feb 2020 08:00:59 +1100 (AEDT) Received: from localhost ([::1]:43014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KqX-00059V-H9 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:00:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50136) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km3-00060C-0d for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km0-0002vH-NG for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:18 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52644) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km0-0002st-EA for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:16 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrwDv164267; Mon, 24 Feb 2020 20:56:08 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=2Sv8kRe5boqvpwqshlB2kRRqiGqW/uKXB3bGdhdbmAc=; b=nidLenEia59pAf2iac/0/eI/+SQxiqrYKgVGzEVYz9voQcws+wrfWSYVZpAtJ+YUyO2R b36modhaOOqzWvkCCVIVOdEXhDXd7rxCmFZN1mtrFxl7ZXrOnD70N3O/Y10cWSoTNlFj UZHkKhsEdAGJH0j7umCaxnuEGKIVy8XNuQv4Dq81hoSNctaMbMw5jUovJe9+XHMN8BRK k7UF/R4YM4seHBuUKYfBak0pfX31WkUZeKqCuEStJYlPliEEtEhVUjBdnnWkvnz1j8+G u0e4FwiIQcofzUgj0TKA46aUKQvfdzsyE5CnRHkus4xuQp83Hx7xLGWd/XmOp1OcTXV2 Uw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p931-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:08 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqWXP016815; Mon, 24 Feb 2020 20:56:08 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6cmh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:07 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu4wx029541; Mon, 24 Feb 2020 20:56:04 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:04 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 06/50] multi-process: build system for remote device process Date: Mon, 24 Feb 2020 15:54:57 -0500 Message-Id: <6ef9a3f85252c3c2f1b6b69cd19ae2230d69db4a.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKrwDv164267 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 | 26 +++++++++++++++++++++ Makefile.target | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- accel/Makefile.objs | 2 ++ backends/Makefile.objs | 2 ++ block/Makefile.objs | 2 ++ hw/Makefile.objs | 7 ++++++ hw/block/Makefile.objs | 2 ++ hw/core/Makefile.objs | 18 +++++++++++++++ hw/nvram/Makefile.objs | 2 ++ hw/pci/Makefile.objs | 4 ++++ hw/scsi/Makefile.objs | 2 ++ migration/Makefile.objs | 2 ++ qom/Makefile.objs | 3 +++ remote/Makefile.objs | 1 + remote/remote-main.c | 23 +++++++++++++++++++ stubs/replay.c | 4 ++++ 17 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 remote/Makefile.objs create mode 100644 remote/remote-main.c diff --git a/Makefile b/Makefile index 15f8e53..f91dcb9 100644 --- a/Makefile +++ b/Makefile @@ -454,6 +454,8 @@ dummy := $(call unnest-vars,, \ qom-obj-y \ io-obj-y \ common-obj-y \ + remote-pci-obj-y \ + remote-lsi-obj-y \ common-obj-m \ trace-obj-y) diff --git a/Makefile.objs b/Makefile.objs index 8a1cbe8..c80e107 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -21,6 +21,32 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ +######################################################### +# remote-pci-obj-y is common code used by remote devices + +remote-pci-obj-$(CONFIG_MPQEMU) += hw/ +remote-pci-obj-$(CONFIG_MPQEMU) += qom/ +remote-pci-obj-$(CONFIG_MPQEMU) += backends/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += migration/ +remote-pci-obj-$(CONFIG_MPQEMU) += remote/ +remote-pci-obj-$(CONFIG_MPQEMU) += accel/ + +remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o +remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-monitor.o +remote-pci-obj-$(CONFIG_MPQEMU) += bootdevice.o +remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o + +############################################################## +# remote-lsi-obj-y is code used to implement remote LSI device + +remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ + +####################################################################### +# crypto-obj-y is code used by both qemu system emulation and qemu-img + crypto-obj-y = crypto/ io-obj-y = io/ diff --git a/Makefile.target b/Makefile.target index 2d43dc5..375fdaa 100644 --- a/Makefile.target +++ b/Makefile.target @@ -36,7 +36,17 @@ QEMU_PROG_BUILD = $(QEMU_PROG) endif endif +ifdef CONFIG_MPQEMU +SCSI_DEV_PROG=qemu-scsi-dev +SCSI_DEV_BUILD = $(SCSI_DEV_PROG) +endif + PROGS=$(QEMU_PROG) $(QEMU_PROGW) + +ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-) +PROGS += $(SCSI_DEV_PROG) +endif + STPFILES= config-target.h: config-target.h-timestamp @@ -121,6 +131,20 @@ LIBS := $(libs_cpu) $(LIBS) obj-$(CONFIG_PLUGIN) += plugins/ +ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-) +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 +endif + ######################################################### # Linux user emulator target @@ -178,6 +202,20 @@ 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) + +ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-) +all-remote-pci-obj-y += memory.o +all-remote-pci-obj-y += exec.o +all-remote-pci-obj-y += exec-vary.o +all-remote-pci-obj-y += ioport.o +all-remote-pci-obj-y += cpus.o +endif + +remote-pci-obj-y := +remote-lsi-obj-y := + include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,.., \ authz-obj-y \ @@ -188,7 +226,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) @@ -196,8 +237,19 @@ all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-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 @@ -210,6 +262,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/accel/Makefile.objs b/accel/Makefile.objs index 17e5ac6..e312dd4 100644 --- a/accel/Makefile.objs +++ b/accel/Makefile.objs @@ -3,3 +3,5 @@ obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_TCG) += tcg/ obj-y += stubs/ + +remote-pci-obj-$(CONFIG_MPQEMU) += accel.o diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 28a847c..947cde3 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -21,3 +21,5 @@ common-obj-$(CONFIG_LINUX) += hostmem-memfd.o common-obj-$(CONFIG_GIO) += dbus-vmstate.o dbus-vmstate.o-cflags = $(GIO_CFLAGS) dbus-vmstate.o-libs = $(GIO_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += hostmem.o diff --git a/block/Makefile.objs b/block/Makefile.objs index 3bcb35c..6398613 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -71,3 +71,5 @@ io_uring.o-cflags := $(LINUX_IO_URING_CFLAGS) io_uring.o-libs := $(LINUX_IO_URING_LIBS) parallels.o-cflags := $(LIBXML2_CFLAGS) parallels.o-libs := $(LIBXML2_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += stream.o diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 660e2b4..af9235b 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -44,3 +44,10 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) + +remote-pci-obj-$(CONFIG_MPQEMU) += core/ +remote-pci-obj-$(CONFIG_MPQEMU) += block/ +remote-pci-obj-$(CONFIG_MPQEMU) += pci/ +remote-pci-obj-$(CONFIG_MPQEMU) += nvram/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += scsi/ diff --git a/hw/block/Makefile.objs b/hw/block/Makefile.objs index 4b4a2b3..0b4644f 100644 --- a/hw/block/Makefile.objs +++ b/hw/block/Makefile.objs @@ -16,3 +16,5 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o obj-y += dataplane/ + +remote-pci-obj-$(CONFIG_MPQEMU) += block.o cdrom.o hd-geometry.o diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index 6215e7c..e3e8084 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -31,3 +31,21 @@ common-obj-$(CONFIG_OR_IRQ) += or-irq.o common-obj-$(CONFIG_SPLIT_IRQ) += split-irq.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o common-obj-$(CONFIG_GENERIC_LOADER) += generic-loader.o + +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev.o +remote-pci-obj-$(CONFIG_MPQEMU) += bus.o +remote-pci-obj-$(CONFIG_MPQEMU) += irq.o +remote-pci-obj-$(CONFIG_MPQEMU) += hotplug.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine.o +remote-pci-obj-$(CONFIG_MPQEMU) += fw-path-provider.o +remote-pci-obj-$(CONFIG_MPQEMU) += reset.o +remote-pci-obj-$(CONFIG_MPQEMU) += sysbus.o +remote-pci-obj-$(CONFIG_MPQEMU) += loader.o +remote-pci-obj-$(CONFIG_MPQEMU) += nmi.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-properties-system.o +remote-pci-obj-$(CONFIG_MPQEMU) += qdev-fw.o +remote-pci-obj-$(CONFIG_MPQEMU) += numa.o +remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o +remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o +remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o diff --git a/hw/nvram/Makefile.objs b/hw/nvram/Makefile.objs index f3ad921..4d2d809 100644 --- a/hw/nvram/Makefile.objs +++ b/hw/nvram/Makefile.objs @@ -6,3 +6,5 @@ common-obj-$(CONFIG_CHRP_NVRAM) += chrp_nvram.o common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o common-obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o obj-$(CONFIG_PSERIES) += spapr_nvram.o + +remote-pci-obj-$(CONFIG_MPQEMU) += fw_cfg.o 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 d3623d5..e7cdc76 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -14,3 +14,5 @@ common-obj-$(CONFIG_RDMA) += rdma.o common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o rdma.o-libs := $(RDMA_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o 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..7c0764a --- /dev/null +++ b/remote/remote-main.c @@ -0,0 +1,23 @@ +/* + * Remote device initialization + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include + +#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 2e3feee..9b53c0c 100644 --- a/stubs/replay.c +++ b/stubs/replay.c @@ -102,3 +102,7 @@ int replay_get_instructions(void) void replay_account_executed_instructions(void) { } + +void replay_add_blocker(Error *reason) +{ +} From patchwork Mon Feb 24 20:54:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=IdeKf6Bw; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF1y1xFDz9sPg for ; Tue, 25 Feb 2020 08:04:54 +1100 (AEDT) Received: from localhost ([::1]:43242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KuK-000214-0w for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:04:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50121) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km2-0005zG-GR for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km0-0002uK-At for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:18 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km0-0002sE-1j for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:16 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrgVA164183; Mon, 24 Feb 2020 20:56:08 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=nE7Z5dONy9c4i9FPkTxs3CicaKlqTAunrxR/XPUCevM=; b=IdeKf6Bwct3KLHv6zWFWQ/hKnBG5Cf8qwQrSDk2La4fAbBGAjrD4mMs8/ijHnR7mY5DU b3kI3QiHGz1YsEfhHBOGJ/cVL4j2ymeImEJW4HJjyJGeW06WiN1Q15iDzVIzKx61JKdl QBtgPAgSZw39Eo5oh/I3HhHimfJHVicZJ5X8EVBXdc6Cj4drRQybAdrQCFWbirD+zxh5 nd6HV7B7ZgQyiiehrGmCbLpinwQyQMRVJ9Ifk8NdzEcTkCELOiR0KpL8EUoYl1BbnBW/ V6MiIgZAei+OMYDgAFhF4hgLl1WODH3cAoU9yJZrYUzxei6GBJ+g1LYFrz+mtYkgUMBN jw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p932-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:08 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqjfd017311; Mon, 24 Feb 2020 20:56:08 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2ybduv6cn1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:08 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu7CP007766; Mon, 24 Feb 2020 20:56:07 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:07 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 07/50] multi-process: define mpqemu-link object Date: Mon, 24 Feb 2020 15:54:58 -0500 Message-Id: <20ec6f6666cc8adb211642156f5230e478143b81.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKrgVA164183 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Cleaned up included header files include/io/mpqemu-link.h | 138 ++++++++++++++++++++++ io/Makefile.objs | 2 + io/mpqemu-link.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 434 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h new file mode 100644 index 0000000..2f2dd83 --- /dev/null +++ b/include/io/mpqemu-link.h @@ -0,0 +1,138 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qom/object.h" +#include "qemu/thread.h" + +#define TYPE_MPQEMU_LINK "mpqemu-link" +#define MPQEMU_LINK(obj) \ + OBJECT_CHECK(MPQemuLinkState, (obj), TYPE_MPQEMU_LINK) + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/* + * TODO: Dont use mpqemu link object since it is + * not needed to be created via -object. + */ + +/** + * mpqemu_cmd_t: + * PCI_CONFIG_READ PCI configuration space read + * PCI_CONFIG_WRITE PCI configuration space write + * + * proc_cmd_t enum type to specify the command to be executed on the remote + * device. + */ +typedef enum { + INIT = 0, + PCI_CONFIG_READ, + PCI_CONFIG_WRITE, + MAX, +} mpqemu_cmd_t; + +/** + * MPQemuMsg: + * @cmd: The remote command + * @bytestream: Indicates if the data to be shared is structured (data1) + * or unstructured (data2) + * @size: Size of the data to be shared + * @data1: Structured data + * @fds: File descriptors to be shared with remote device + * @data2: Unstructured data + * + * MPQemuMsg Format of the message sent to the remote device from QEMU. + * + */ +typedef struct { + mpqemu_cmd_t cmd; + int bytestream; + size_t size; + + union { + uint64_t u64; + } data1; + + int fds[REMOTE_MAX_FDS]; + int num_fds; + + uint8_t *data2; +} MPQemuMsg; + +struct conf_data_msg { + uint32_t addr; + uint32_t val; + int l; +}; + +/** + * MPQemuChannel: + * @gsrc: GSource object to be used by loop + * @gpfd: GPollFD object containing the socket & events to monitor + * @sock: Socket to send/receive communication, same as the one in gpfd + * @send_lock: Mutex to synchronize access to the send stream + * @recv_lock: Mutex to synchronize access to the recv stream + * + * Defines the channel that make up the communication link + * between QEMU and remote process + */ + +typedef struct MPQemuChannel { + GSource gsrc; + GPollFD gpfd; + int sock; + QemuMutex send_lock; + QemuMutex recv_lock; +} MPQemuChannel; + +typedef void (*mpqemu_link_callback)(GIOCondition cond, MPQemuChannel *chan); + +/* + * MPQemuLinkState Instance info. of the communication + * link between QEMU and remote process. The Link could + * be made up of multiple channels. + * + * ctx GMainContext to be used for communication + * loop Main loop that would be used to poll for incoming data + * com Communication channel to transport control messages + * + */ + +typedef struct MPQemuLinkState { + Object obj; + + GMainContext *ctx; + GMainLoop *loop; + + MPQemuChannel *com; + + mpqemu_link_callback callback; +} MPQemuLinkState; + +MPQemuLinkState *mpqemu_link_create(void); +void mpqemu_link_finalize(MPQemuLinkState *s); + +void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan); +int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan); + +void mpqemu_init_channel(MPQemuLinkState *s, MPQemuChannel **chan, int fd); +void mpqemu_destroy_channel(MPQemuChannel *chan); +void mpqemu_link_set_callback(MPQemuLinkState *s, + mpqemu_link_callback callback); +void mpqemu_start_coms(MPQemuLinkState *s); + +#endif 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..bac120b --- /dev/null +++ b/io/mpqemu-link.c @@ -0,0 +1,294 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/module.h" +#include "io/mpqemu-link.h" +#include "qemu/log.h" + +GSourceFuncs gsrc_funcs; + +/* + * TODO: make all communications asynchronous and run in the main + * loop or existing IOThread. + */ + +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(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(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->bytestream) { + if (!msg->size) { + qemu_mutex_unlock(lock); + return -EINVAL; + } + + 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 Mon Feb 24 20:54:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Ucysf1QP; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDv15j39z9sPg for ; Tue, 25 Feb 2020 07:58:53 +1100 (AEDT) Received: from localhost ([::1]:42852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KoV-0001Rn-Lu for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 15:58:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50198) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km4-00063i-Rp for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km3-0002ys-C6 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:20 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:40968) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km3-0002xE-34 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:19 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqUse017543; Mon, 24 Feb 2020 20:56:12 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-2020-01-29; bh=qVGAGC6C18wJ+u7koWS8q2G+1agjZ5LGHLUEggWIpvg=; b=Ucysf1QPfWCGisyEL/FZGhAGVkKDpXcLEWm5jk3AU+Mq/83yu0OV0AHbWg2JK4igkFCD LyHV+15ln4vqkRQcC0PiA2aOu88xg1Ao7RoDAWI7VuVh+4/6cHHm5rtqOE7g5YxJ6VFY zvFVxYQQIM4oC7ecvJmZWaV/2aUrX1oE7i4EBscZydZfmpxyEXkgfzjT5awykB3zk1Hl lGSk34fWWdTpib5BO7qqtRpyv/j5mjgIJFM2+1uPqCqxbA9JyMBOt+BO/2ksoVAmxcXw yZXwqcZULi0INMW/WFuAwkTlUK6PYDA0ZJ2e7mAwfp+2x41W2+4Gqom7hTmC5bVDueIP Gg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yavxrhydm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:11 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqhVI017288; Mon, 24 Feb 2020 20:56:11 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6cq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:10 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKu84e029598; Mon, 24 Feb 2020 20:56:09 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:08 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 08/50] multi-process: add functions to synchronize proxy and remote endpoints Date: Mon, 24 Feb 2020 15:54:59 -0500 Message-Id: <3d013f0091ac6babb55f30cadf6ed806c322b7ce.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- include/io/mpqemu-link.h | 7 +++++++ io/mpqemu-link.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 2f2dd83..ae04fca 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -135,4 +135,11 @@ void mpqemu_link_set_callback(MPQemuLinkState *s, mpqemu_link_callback callback); void mpqemu_start_coms(MPQemuLinkState *s); +#define GET_REMOTE_WAIT eventfd(0, EFD_CLOEXEC) +#define PUT_REMOTE_WAIT(wait) close(wait) +#define PROXY_LINK_WAIT_DONE 1 + +uint64_t wait_for_remote(int efd); +void notify_proxy(int fd, uint64_t val); + #endif diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index bac120b..73b7032 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include #include "qemu/module.h" #include "io/mpqemu-link.h" @@ -216,6 +217,46 @@ int mpqemu_msg_recv(MPQemuMsg *msg, MPQemuChannel *chan) return rc; } +uint64_t wait_for_remote(int efd) +{ + struct pollfd pfd = { .fd = efd, .events = POLLIN }; + uint64_t val; + int ret; + + ret = poll(&pfd, 1, 1000); + + 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 Mon Feb 24 20:55:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=z9Oi3BGE; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDtz59B1z9sRG for ; Tue, 25 Feb 2020 07:58:51 +1100 (AEDT) Received: from localhost ([::1]:42848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KoT-0001QQ-HQ for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 15:58:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50163) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km3-00060w-IG for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km2-0002x3-4O for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:19 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52724) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km1-0002vk-Rd for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:18 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraG5164141; Mon, 24 Feb 2020 20:56: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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=KV8kDjxArLU2g0UIpoGF6YobT97Ym3GFYX9DX+iqJX4=; b=z9Oi3BGE6txObhVEznnHDpQ9w37OLW46z8bPctUqUZ1r8oXaqwHdN4TAMRqM3cVTnt91 BisQ0tnbV6pcvZXG6a73f2DqXp6JfLP76Ob0cV+P1kIu8K9sVXXXNUCQaZ+ULAZyKEhD Qtj6AbCheut5p8BaQZV3Kqrjwinh2BFxytQSDFe/WwcdHaPfZC40VME8tpFIxX4QcXzk l4hQa6ceEC9h3HHZ8Afd/3Xdw0vYJpd/sse5n3Bizm3FUyY6PvgTbNFz3Z/D66oeTi35 L7+OmVWffKdGzEl5O4eEcQndVlQNTNYZyyJm2ZDixo9X/ba/Dh2l8AoLl8O5q7C13Bnq LQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p93c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:13 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq8TA089084; Mon, 24 Feb 2020 20:56:12 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dmaja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:12 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuA5j028314; Mon, 24 Feb 2020 20:56:10 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:10 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 09/50] multi-process: setup PCI host bridge for remote device Date: Mon, 24 Feb 2020 15:55:00 -0500 Message-Id: <52ffd24f1ab55b596619a92b3b44d462fc235ee4.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKraG5164141 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Setting PCI bus name on the fly - Unable to grab the PCI bus name from object hierarchy as RemPCIHost have access to it during instantiation hw/pci/Makefile.objs | 2 +- include/remote/pcihost.h | 45 ++++++++++++++++++++++++++++++++++ remote/Makefile.objs | 1 + remote/pcihost.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 include/remote/pcihost.h create mode 100644 remote/pcihost.c 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..7aca9cc --- /dev/null +++ b/include/remote/pcihost.h @@ -0,0 +1,45 @@ +/* + * PCI Host for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_PCIHOST_H +#define REMOTE_PCIHOST_H + +#include +#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..dbe0819 --- /dev/null +++ b/remote/pcihost.c @@ -0,0 +1,64 @@ +/* + * Remote PCI host device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include +#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) +{ + char *busname = g_strdup_printf("remote-pci-%ld", (unsigned long)getpid()); + PCIHostState *pci = PCI_HOST_BRIDGE(dev); + RemPCIHost *s = REMOTE_HOST_DEVICE(dev); + + pci->bus = pci_root_bus_new(DEVICE(s), busname, + s->mr_pci_mem, s->mr_sys_io, + 0, TYPE_PCIE_BUS); +} + +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->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 Mon Feb 24 20:55:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=sNa/T9J2; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF533z5Sz9sNg for ; Tue, 25 Feb 2020 08:07:35 +1100 (AEDT) Received: from localhost ([::1]:43326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kwv-0006kn-DJ for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:07:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50249) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km6-00068n-OL for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km4-00030y-Sl for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:22 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52800) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km4-0002zN-Ge for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:20 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrajF164104; Mon, 24 Feb 2020 20:56: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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=QIN4OBnH8pfK/FQg/Ngm3RypA/DQPqJb+C20uwyiIM0=; b=sNa/T9J2Zx6yUkNSKIBXT1yBluwwIksfec48dOY/lbhun6iUHOdvwEdLA9nzMLCTytFn Y/H+YJ8Q8kDO6GYl5P+SLrjm3AGp6PX8Hwgge5Wm0fGBo68kgfyCQhO5ZZ7EMJrUi/tG tM3zi95QmgfPKXduR34a0Flks9HUhoh2oaRYD4QcDsmtko9Tfd8MVEvsIXgvAJErZ6C4 gn3lf4Zcu4BvNsUCO2Ae1PvBQJteg2imUTj/9QsEjoZFJjElysjj0mxmgCjB3pi31uzA U/T2gEb9HXrzgf5BRrWGB7F2Zh/3yTg2D/i9FILCP0mE32Rh+2pstrDnrB9Cf61Id3Kd VA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2ybvr4p93g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:14 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKpuFv108591; Mon, 24 Feb 2020 20:56:13 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2ybe123sm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:13 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuCvE029677; Mon, 24 Feb 2020 20:56:12 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:11 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 10/50] multi-process: setup a machine object for remote device process Date: Mon, 24 Feb 2020 15:55:01 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKrajF164104 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Refactor notifier code into a common file - Moved global initialization out of object specific code - Added a child property relationship between RemMachineState & RemPCIHost Makefile.objs | 1 + exec.c | 3 +- include/exec/address-spaces.h | 2 ++ include/remote/machine.h | 30 ++++++++++++++++ remote/Makefile.objs | 1 + remote/machine.c | 84 +++++++++++++++++++++++++++++++++++++++++++ remote/remote-main.c | 7 ++++ util/Makefile.objs | 2 ++ 8 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 include/remote/machine.h create mode 100644 remote/machine.c diff --git a/Makefile.objs b/Makefile.objs index c80e107..aad33fc 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -31,6 +31,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += migration/ remote-pci-obj-$(CONFIG_MPQEMU) += remote/ remote-pci-obj-$(CONFIG_MPQEMU) += accel/ +remote-pci-obj-$(CONFIG_MPQEMU) += util/ remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o diff --git a/exec.c b/exec.c index e524185..b4c9cc6 100644 --- a/exec.c +++ b/exec.c @@ -161,7 +161,6 @@ typedef struct subpage_t { #define PHYS_SECTION_UNASSIGNED 0 static void io_mem_init(void); -static void memory_map_init(void); static void tcg_log_global_after_sync(MemoryListener *listener); static void tcg_commit(MemoryListener *listener); @@ -3002,7 +3001,7 @@ static void tcg_commit(MemoryListener *listener) tlb_flush(cpuas->cpu); } -static void memory_map_init(void) +void memory_map_init(void) { system_memory = g_malloc(sizeof(*system_memory)); 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..7e9bdbe --- /dev/null +++ b/include/remote/machine.h @@ -0,0 +1,30 @@ +/* + * Remote machine configuration + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_MACHINE_H +#define REMOTE_MACHINE_H + +#include "qemu/osdep.h" +#include "qom/object.h" +#include "hw/boards.h" +#include "remote/pcihost.h" +#include "qemu/notify.h" + +typedef struct RemMachineState { + MachineState parent_obj; + + RemPCIHost *host; +} RemMachineState; + +#define TYPE_REMOTE_MACHINE "remote-machine" +#define REMOTE_MACHINE(obj) \ + OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE) + +#endif 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..97e4f19 --- /dev/null +++ b/remote/machine.c @@ -0,0 +1,84 @@ +/* + * Machine for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#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 "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 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; + + 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; + + object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host), + &error_abort); + if (error_abort) { + error_report_err(error_abort); + return; + } + + 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 7c0764a..ecf30e0 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -14,10 +14,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; } diff --git a/util/Makefile.objs b/util/Makefile.objs index 6b38b67..80b2067 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -60,3 +60,5 @@ util-obj-y += guest-random.o util-obj-$(CONFIG_GIO) += dbus.o dbus.o-cflags = $(GIO_CFLAGS) dbus.o-libs = $(GIO_LIBS) + +remote-pci-obj-$(CONFIG_MPQEMU) += notify.o From patchwork Mon Feb 24 20:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=F+7Y8qLK; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF0m4q75z9sNg for ; Tue, 25 Feb 2020 08:03:52 +1100 (AEDT) Received: from localhost ([::1]:43214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KtK-0000oE-GQ for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:03:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50248) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km6-00068d-My for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km4-00030n-Tp for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:22 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41026) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km4-0002zQ-HD for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:20 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqce8017751; Mon, 24 Feb 2020 20:56:15 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=WBrnbGpMhzlyGR4oqAtWQqui+tPjDdZ73FRvxPG/KUA=; b=F+7Y8qLKJBvQPb99fnsnDXdrUdrDepjYOYc2Z4hxWbF9NWEFJmhm1PzWniyBI4oUCY2N /SU7EhE3ij5aGviAd7zp8+Lyx5lcUpNu1sKMvgLoqdBqBrsGzSVh+xXYR6Ese/NfeIku jNqp76ZRaiG7XR1Nqm64bAyh5Ef2Yx8znSNPOP4Ia34/RvziarRbFG+enJccJEqNzlc5 J7v22lMz5VQrgeMSN7uqsTIcVQlkT/ctLrw5BhCAtlg1HC0qcE3PLk/zuZzgFAsNsHSt NUx9uCcgqPvds6seur39GUSYvZly8ckccPYm4wHOtMoERDkf+ZmSGpgS+06EpI2SsZna Kw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2yavxrhye0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:15 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqgd1090019; Mon, 24 Feb 2020 20:56:14 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2yby5dmapv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:14 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuD2c028264; Mon, 24 Feb 2020 20:56:13 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:13 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 11/50] multi-process: setup memory manager for remote device Date: Mon, 24 Feb 2020 15:55:02 -0500 Message-Id: <5085342396f18b6f265ab24d9d7910fea5333e80.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=4 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=4 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id 01OKqce8017751 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Refactored remote_ram_init_from_fd into common code Makefile.target | 2 ++ exec.c | 17 +++++++++++++ include/exec/ram_addr.h | 2 ++ include/io/mpqemu-link.h | 11 +++++++++ include/remote/memory.h | 20 +++++++++++++++ remote/memory.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 include/remote/memory.h create mode 100644 remote/memory.c diff --git a/Makefile.target b/Makefile.target index 375fdaa..cfd36c1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -143,6 +143,8 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o + +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o endif ######################################################### diff --git a/exec.c b/exec.c index b4c9cc6..8e77c4c 100644 --- a/exec.c +++ b/exec.c @@ -2410,6 +2410,23 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return block; } + +void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size, + ram_addr_t offset, Error **errp) +{ + char *name = g_strdup_printf("%d", fd); + + memory_region_init(mr, NULL, name, size); + mr->ram = true; + mr->terminates = true; + mr->destructor = NULL; + mr->align = 0; + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, RAM_SHARED, fd, offset, + errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; + + g_free(name); +} #endif static diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 1b9f489..d9d7314 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -122,6 +122,8 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, off_t offset, Error **errp); +void qemu_ram_init_from_fd(MemoryRegion *mr, int fd, uint64_t size, + ram_addr_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index ae04fca..78c0818 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -16,6 +16,8 @@ #include "qom/object.h" #include "qemu/thread.h" +#include "exec/cpu-common.h" +#include "exec/hwaddr.h" #define TYPE_MPQEMU_LINK "mpqemu-link" #define MPQEMU_LINK(obj) \ @@ -34,6 +36,7 @@ * mpqemu_cmd_t: * PCI_CONFIG_READ PCI configuration space read * PCI_CONFIG_WRITE PCI configuration space write + * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -42,6 +45,7 @@ typedef enum { INIT = 0, PCI_CONFIG_READ, PCI_CONFIG_WRITE, + SYNC_SYSMEM, MAX, } mpqemu_cmd_t; @@ -59,12 +63,19 @@ typedef enum { * */ typedef struct { + hwaddr gpas[REMOTE_MAX_FDS]; + uint64_t sizes[REMOTE_MAX_FDS]; + ram_addr_t offsets[REMOTE_MAX_FDS]; +} sync_sysmem_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; union { uint64_t u64; + sync_sysmem_msg_t sync_sysmem; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/memory.h b/include/remote/memory.h new file mode 100644 index 0000000..e2e479b --- /dev/null +++ b/include/remote/memory.h @@ -0,0 +1,20 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_MEMORY_H +#define REMOTE_MEMORY_H + +#include "qemu/osdep.h" +#include "exec/hwaddr.h" +#include "io/mpqemu-link.h" + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp); + +#endif diff --git a/remote/memory.c b/remote/memory.c new file mode 100644 index 0000000..2c8b7bb --- /dev/null +++ b/remote/memory.c @@ -0,0 +1,63 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#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" + +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); + qemu_ram_free(subregion->ram_block); + } + } + + for (region = 0; region < msg->num_fds; region++) { + subregion = g_new(MemoryRegion, 1); + qemu_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 Mon Feb 24 20:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=FxH2bkU2; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF4G36vvz9sNg for ; Tue, 25 Feb 2020 08:06:54 +1100 (AEDT) Received: from localhost ([::1]:43272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KvT-0004HN-Su for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:06:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50282) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Km9-0006Gi-TS for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km8-00034e-JV for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:25 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52872) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km8-00032j-Ad for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:24 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKral2164128; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=MxpNHjTs+jU27aG3D0nYtJNgO++of0qV7/YWLWpKgxs=; b=FxH2bkU2MVdwh+uuDWXPhMwsZ/h7KWcCMIVK6/E2pnkjyeloCS7AJp/MR6G8aHePQooS DIzjA9bBbB1I3CnSWXod4o5YIT7afRzMivYViYqLmO+ySyzni8cL85ehv8d2mic+hxIt I9EDBxxLK/aZhFBwd4vf+2yGaQBuiheeaJNTs9LWO9F5aXZREMEI3TVdyPAQF1aBdpvq RheKdqbnuRHVdR1FRvQa3TuDGgAggsq3z9Nh3A6fJ/N9DxXQN7T5uCDeNnJVJ5xd40vF eEJeJOIbeHnU8Sx7ezGPYGba37+p/DxAWQYJjBrRMg3LQXxPgEIDNY9lDFF0ZQPNI5Ye XQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p93r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:16 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqjfe017311; Mon, 24 Feb 2020 20:56:16 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2ybduv6cuu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:15 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuFN0028280; Mon, 24 Feb 2020 20:56:15 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:14 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 12/50] multi-process: remote process initialization Date: Mon, 24 Feb 2020 15:55:03 -0500 Message-Id: <264de034fcdc1000bada4a93ac7e0856fef591f2.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=3 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=3 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - We checked if we could use functions already defined in util/main-loop.c instead of using g_main_loop_run. However, we couldn't find a suitable function that's generic enough to do this. All of them have emulator code embedded in them which is not used by the remote process. We are therefore not making any change to this patch remote/remote-main.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index ecf30e0..56315cd 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -12,6 +12,7 @@ #include "qemu-common.h" #include +#include #include "qemu/module.h" #include "remote/pcihost.h" @@ -19,12 +20,96 @@ #include "hw/boards.h" #include "hw/qdev-core.h" #include "qemu/main-loop.h" +#include "remote/memory.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/main-loop.h" +#include "sysemu/cpus.h" +#include "qemu-common.h" +#include "hw/pci/pci.h" +#include "qemu/thread.h" +#include "qemu/main-loop.h" +#include "qemu/config-file.h" +#include "sysemu/sysemu.h" +#include "block/block.h" +#include "exec/ramlist.h" + +static MPQemuLinkState *mpqemu_link; +PCIDevice *remote_pci_dev; + +static void process_msg(GIOCondition cond, MPQemuChannel *chan) +{ + MPQemuMsg *msg = NULL; + Error *err = NULL; + + if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) { + goto finalize_loop; + } + + msg = g_malloc0(sizeof(MPQemuMsg)); + + if (mpqemu_msg_recv(msg, chan) < 0) { + error_setg(&err, "Failed to receive message"); + goto finalize_loop; + } + + switch (msg->cmd) { + case INIT: + break; + case PCI_CONFIG_WRITE: + break; + case PCI_CONFIG_READ: + break; + default: + error_setg(&err, "Unknown command"); + goto finalize_loop; + } + + g_free(msg->data2); + g_free(msg); + + return; + +finalize_loop: + if (err) { + error_report_err(err); + } + g_free(msg); + mpqemu_link_finalize(mpqemu_link); + mpqemu_link = NULL; +} int main(int argc, char *argv[]) { + Error *err = NULL; + module_call_init(MODULE_INIT_QOM); + bdrv_init_with_whitelist(); + + if (qemu_init_main_loop(&err)) { + error_report_err(err); + return -EBUSY; + } + + qemu_init_cpu_loop(); + + page_size_init(); + + qemu_mutex_init(&ram_list.mutex); + current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE))); + mpqemu_link = mpqemu_link_create(); + if (!mpqemu_link) { + printf("Could not create MPQemu link\n"); + return -1; + } + + mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO); + mpqemu_link_set_callback(mpqemu_link, process_msg); + + mpqemu_start_coms(mpqemu_link); + return 0; } From patchwork Mon Feb 24 20:55:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=KftiRQgA; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF5v4VVYz9sQt for ; Tue, 25 Feb 2020 08:08:19 +1100 (AEDT) Received: from localhost ([::1]:43334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kxd-0007pq-DM for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:08:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50297) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmB-0006JO-0v for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km8-00034t-Pk for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:26 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:52894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km8-00033s-Fe for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:24 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrgcg164180; Mon, 24 Feb 2020 20:56: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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=yKz45Eb+loFnirKzQAZdSGDq5E8OjxdEbf9hqkMJUVY=; b=KftiRQgAiBB3G4PqQCtCQ2UqI4y/Rp88L7HFMznptNHLHNGRFr7suQdbPVCapC8G/d6O nKDWsO80JrEQ1xH2d+pgrgD7iHKngYXzF0BJU/2w3qbnqUMSpEh9wmHenOWJU5M9aHJ6 /UC4PeAteah+GNq7jLV26KzCg70gkZa13/UYPJ9ll6Ur2Ee5fd/jn4Jmjd4HlxwnICiw ntrJ4yiDX3fQeks8GjWL85q4WKfDpfYtfj1VXZ4yoC26PiL87wOmsZxdPLz8TP0xYsq/ TD1YPeR2MPBIocQH7Syjp1JL2KyHHSadM81n7kNw2Sb9z974QiO9vhxCOWX+l42RTkqv PA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p93x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:19 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqfLZ090002; Mon, 24 Feb 2020 20:56:19 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dmayh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:18 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuGX3028367; Mon, 24 Feb 2020 20:56:16 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:16 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 13/50] multi-process: introduce proxy object Date: Mon, 24 Feb 2020 15:55:04 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKrgcg164180 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Switched to execv hw/Makefile.objs | 2 + hw/proxy/Makefile.objs | 1 + hw/proxy/qemu-proxy.c | 226 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 54 ++++++++++ include/io/mpqemu-link.h | 1 + remote/remote-main.c | 28 ++++++ 6 files changed, 312 insertions(+) create mode 100644 hw/proxy/Makefile.objs create mode 100644 hw/proxy/qemu-proxy.c create mode 100644 include/hw/proxy/qemu-proxy.h diff --git a/hw/Makefile.objs b/hw/Makefile.objs index af9235b..7b489b1 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -45,6 +45,8 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) +common-obj-$(CONFIG_MPQEMU) += proxy/ + remote-pci-obj-$(CONFIG_MPQEMU) += core/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += pci/ 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..828bbd7 --- /dev/null +++ b/hw/proxy/qemu-proxy.c @@ -0,0 +1,226 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "io/mpqemu-link.h" +#include "exec/memory.h" +#include "exec/cpu-common.h" +#include "exec/address-spaces.h" +#include "hw/pci/pci.h" +#include "qapi/qmp/qjson.h" +#include "qapi/qmp/qstring.h" +#include "hw/proxy/qemu-proxy.h" + +static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); + +static int remote_spawn(PCIProxyDev *pdev, const char *opts, + const char *exec_name, Error **errp) +{ + char *args[3]; + pid_t rpid; + int fd[2] = {-1, -1}; + Error *local_error = NULL; + int rc = -EINVAL; + + if (pdev->managed) { + /* Child is forked by external program (such as libvirt). */ + error_setg(errp, "Remote processed is managed and launched by external program"); + return -1; + } + + if (!exec_name) { + error_setg(errp, "The remote exec name is NULL."); + return rc; + } + + 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(exec_name); + args[1] = g_strdup_printf("%d", fd[1]); + args[2] = NULL; + execvp(args[0], (char *const *)args); + exit(1); + } + pdev->remote_pid = rpid; + + close(fd[1]); + + return 0; +} + +static int get_proxy_sock(PCIDevice *dev) +{ + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + return pdev->socket; +} + +static void set_proxy_sock(PCIDevice *dev, int socket) +{ + PCIProxyDev *pdev; + + pdev = PCI_PROXY_DEV(dev); + + pdev->socket = 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 == PCI_CONFIG_WRITE) ? *val : 0; + conf_data.l = l; + + msg.data2 = (uint8_t *)&conf_data; + if (!msg.data2) { + return -ENOMEM; + } + + msg.size = sizeof(conf_data); + msg.cmd = op; + msg.bytestream = 1; + + if (op == PCI_CONFIG_WRITE) { + msg.num_fds = 0; + } else { + /* TODO: Dont create fd each time for send. */ + wait = GET_REMOTE_WAIT; + msg.num_fds = 1; + msg.fds[0] = wait; + } + + mpqemu_msg_send(&msg, dev->mpqemu_link->com); + + if (op == PCI_CONFIG_READ) { + *val = (uint32_t)wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } + + 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, PCI_CONFIG_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, PCI_CONFIG_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, char *exec_name, + Error **errp) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + Error *local_error = NULL; + + if (!pdev->managed) { + if (command) { + remote_spawn(pdev, command, exec_name, &local_error); + } else { + return; + } + } 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..28b0114 --- /dev/null +++ b/include/hw/proxy/qemu-proxy.h @@ -0,0 +1,54 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef 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; + + MPQemuLinkState *mpqemu_link; + + pid_t remote_pid; + int socket; + + char *rid; + + bool managed; + + void (*set_proxy_sock) (PCIDevice *dev, int socket); + int (*get_proxy_sock) (PCIDevice *dev); + + void (*proxy_ready) (PCIDevice *dev); + void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name, + Error **errp); + +} PCIProxyDev; + +typedef struct PCIProxyDevClass { + PCIDeviceClass parent_class; + + void (*realize)(PCIProxyDev *dev, Error **errp); + + char *command; +} PCIProxyDevClass; + +#endif /* QEMU_PROXY_H */ diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 78c0818..5a2be48 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "sys/eventfd.h" #include "qom/object.h" #include "qemu/thread.h" #include "exec/cpu-common.h" diff --git a/remote/remote-main.c b/remote/remote-main.c index 56315cd..7b4cf2f 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -37,6 +37,32 @@ static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; +static void process_config_write(MPQemuMsg *msg) +{ + struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + + qemu_mutex_lock_iothread(); + pci_default_write_config(remote_pci_dev, conf->addr, conf->val, conf->l); + qemu_mutex_unlock_iothread(); +} + +static void process_config_read(MPQemuMsg *msg) +{ + struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + uint32_t val; + int wait; + + wait = msg->fds[0]; + + qemu_mutex_lock_iothread(); + val = pci_default_read_config(remote_pci_dev, conf->addr, conf->l); + qemu_mutex_unlock_iothread(); + + notify_proxy(wait, val); + + PUT_REMOTE_WAIT(wait); +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -57,8 +83,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case INIT: break; case PCI_CONFIG_WRITE: + process_config_write(msg); break; case PCI_CONFIG_READ: + process_config_read(msg); break; default: error_setg(&err, "Unknown command"); From patchwork Mon Feb 24 20:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=wrw6qbh5; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDzQ0TDDz9sPg for ; Tue, 25 Feb 2020 08:02:42 +1100 (AEDT) Received: from localhost ([::1]:43146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KsB-0007TJ-Rw for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:02:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50286) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmA-0006Hc-CV for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Km8-000351-TI for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:26 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Km8-000344-KO for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:24 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqZfx017693; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=wu/8BnjW53rP1bdYeOpLZbtZ/ZVmT9UqvX3vg1UFB94=; b=wrw6qbh5vsrgDl4IDNSVVJbc18ldx5Xav5K+54HiZBbieAIIYfbzEDIt2cNcx+Xh3Phv 1Ku6lpxBA0KShjWsW9j75cj+ppvLfTl+NJtLVf41P0zkrXfrrYpH+4U4LGdSz2jMLxHI FFRvPnTRLnQ1O94316nz/Xg9pBs+L8DlGZKmSKVCxN2Y7Umf9mmnUErE7fjch/ivnQU3 RkTevJAFjhVtnmzu71gA8F3iYsXNfJmT3aqblSLQR1ZEg4rf80PEDLXqA6piOKZjAv3k KmC3CaOqGWgEfzDsi7r3SFnS1md0+D7Sv5CwRjMrlYvO54NchYUsSnPYlidwJQfvMf8R DQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhyeg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:19 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq5M7171132; Mon, 24 Feb 2020 20:56:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2ybdshkrr6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:19 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuIwx008020; Mon, 24 Feb 2020 20:56:18 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:17 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 14/50] mutli-process: build remote command line args Date: Mon, 24 Feb 2020 15:55:05 -0500 Message-Id: <588dafeecd20f8562f4a0dd68fa4bafbd6ea18bb.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Added "exec" suboption to get the executable's name - Addressed feedback about variable names - Removed redundant check for spawning a process hw/proxy/qemu-proxy.c | 68 +++++++++++++++++++++++++++++++++---------- include/hw/proxy/qemu-proxy.h | 2 +- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 828bbd7..d792e86 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -19,19 +19,50 @@ static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); +static int add_argv(char *opts_str, char **argv, int argc) +{ + int max_args = 64; + + if (argc < max_args - 1) { + argv[argc++] = opts_str; + argv[argc] = 0; + } else { + return 0; + } + + return argc; +} + +static int make_argv(char *opts_str, char **argv, int argc) +{ + int max_args = 64; + + char *p2 = strtok(opts_str, " "); + while (p2 && argc < max_args - 1) { + argv[argc++] = p2; + p2 = strtok(0, " "); + } + argv[argc] = 0; + + return argc; +} + static int remote_spawn(PCIProxyDev *pdev, const char *opts, const char *exec_name, Error **errp) { - char *args[3]; pid_t rpid; int fd[2] = {-1, -1}; Error *local_error = NULL; + char *argv[64]; + int argc = 0; + char *sfd; + char *exec_dir; int rc = -EINVAL; if (pdev->managed) { /* Child is forked by external program (such as libvirt). */ error_setg(errp, "Remote processed is managed and launched by external program"); - return -1; + return rc; } if (!exec_name) { @@ -41,32 +72,38 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts, if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { error_setg(errp, "Unable to create unix socket."); - return -1; + return rc; } + exec_dir = g_strdup_printf("%s/%s", qemu_get_exec_dir(), exec_name); + argc = add_argv(exec_dir, argv, argc); + sfd = g_strdup_printf("%d", fd[1]); + argc = add_argv(sfd, argv, argc); + argc = make_argv((char *)opts, argv, argc); + /* TODO: Restrict the forked process' permissions and capabilities. */ rpid = qemu_fork(&local_error); if (rpid == -1) { error_setg(errp, "Unable to spawn emulation program."); close(fd[0]); - close(fd[1]); - return -1; + goto fail; } if (rpid == 0) { close(fd[0]); - args[0] = g_strdup(exec_name); - args[1] = g_strdup_printf("%d", fd[1]); - args[2] = NULL; - execvp(args[0], (char *const *)args); + rc = execv(argv[0], (char *const *)argv); exit(1); } pdev->remote_pid = rpid; + pdev->socket = fd[0]; + + rc = 0; +fail: close(fd[1]); - return 0; + return rc; } static int get_proxy_sock(PCIDevice *dev) @@ -177,16 +214,17 @@ static void pci_proxy_dev_register_types(void) type_init(pci_proxy_dev_register_types) static void init_proxy(PCIDevice *dev, char *command, char *exec_name, - Error **errp) + bool need_spawn, Error **errp) { PCIProxyDev *pdev = PCI_PROXY_DEV(dev); Error *local_error = NULL; if (!pdev->managed) { - if (command) { - remote_spawn(pdev, command, exec_name, &local_error); - } else { - return; + if (need_spawn) { + if (remote_spawn(pdev, command, exec_name, &local_error)) { + error_propagate(errp, local_error); + return; + } } } else { pdev->remote_pid = atoi(pdev->rid); diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 28b0114..29fa2e9 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -39,7 +39,7 @@ typedef struct PCIProxyDev { void (*proxy_ready) (PCIDevice *dev); void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name, - Error **errp); + bool need_spawn, Error **errp); } PCIProxyDev; From patchwork Mon Feb 24 20:55:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=wC4sjwpx; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RDxd5brvz9sNg for ; Tue, 25 Feb 2020 08:01:09 +1100 (AEDT) Received: from localhost ([::1]:43028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kqg-0005HL-Vy for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:01:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50387) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmD-0006OF-Dx for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmB-000386-Bl for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:29 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41192) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmB-00036F-07 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:27 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqWVd017609; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=WI0VOS/0TodogycTzWpFogQfyyLICEWu1pdK8KJq5vc=; b=wC4sjwpxSTH4HNqJS2pILuBIKxeWO/pWpGrljh0XE96gjf37vdS3MhezAebpGORFYylp epk8rOrp/NkYlXHf9RLBhiZp9RjJfqOJARgLdaDQ1N8TdbcYTY2925vJPAiHmX1/YofZ FqwUQ1IyRYvO3PwOgSSpjjVX/ViT68pemWX+O2xjuS1YiAiWJ+E5F8RPnMviTclpQsrZ HIQw+Lz0K11Eg+9fklHmDDRn/MPAnAfPsEMd8A1u6ZkkxuFlYDTohKAUK5Ru264YgD6u xEQJOTnhZDgnwS2Bem4Ort6vo9C9QUSIBm9WBFXI2Cs9zi7l+JhkW4eza9C6J5knj6lN TQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yavxrhyes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqE3k109205; Mon, 24 Feb 2020 20:56:21 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2ybe123t1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:21 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuJID028381; Mon, 24 Feb 2020 20:56:19 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:19 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 15/50] multi-process: PCI BAR read/write handling for proxy & remote endpoints Date: Mon, 24 Feb 2020 15:55:06 -0500 Message-Id: <28d7426190d8a88c7b93f5f5daf8cd1c6e017a76.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 | 65 ++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 22 +++++++++++-- include/io/mpqemu-link.h | 12 +++++++ remote/remote-main.c | 73 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+), 2 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index d792e86..b17d9bb 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -262,3 +262,68 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; } + +static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, + bool write, hwaddr addr, uint64_t *val, + unsigned size, bool memory) +{ + MPQemuLinkState *mpqemu_link = dev->mpqemu_link; + MPQemuMsg msg; + int wait; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.data1.bar_access.addr = mr->addr + addr; + msg.data1.bar_access.size = size; + msg.data1.bar_access.memory = memory; + + if (write) { + msg.cmd = BAR_WRITE; + msg.data1.bar_access.val = *val; + } else { + wait = GET_REMOTE_WAIT; + + msg.cmd = BAR_READ; + msg.num_fds = 1; + msg.fds[0] = wait; + } + + mpqemu_msg_send(&msg, mpqemu_link->com); + + if (!write) { + *val = wait_for_remote(wait); + PUT_REMOTE_WAIT(wait); + } +} + +void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + uint64_t val; + + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + + return val; +} + +const MemoryRegionOps proxy_default_ops = { + .read = proxy_default_bar_read, + .write = proxy_default_bar_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, +}; diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 29fa2e9..44e370e 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -22,7 +22,19 @@ #define PCI_PROXY_DEV_GET_CLASS(obj) \ OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) -typedef struct PCIProxyDev { +typedef struct PCIProxyDev PCIProxyDev; + +typedef struct ProxyMemoryRegion { + PCIProxyDev *dev; + MemoryRegion mr; + bool memory; + bool present; + uint8_t type; +} ProxyMemoryRegion; + +extern const MemoryRegionOps proxy_default_ops; + +struct PCIProxyDev { PCIDevice parent_dev; MPQemuLinkState *mpqemu_link; @@ -41,7 +53,8 @@ typedef struct PCIProxyDev { void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name, bool need_spawn, Error **errp); -} PCIProxyDev; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; +}; typedef struct PCIProxyDevClass { PCIDeviceClass parent_class; @@ -51,4 +64,9 @@ typedef struct PCIProxyDevClass { char *command; } PCIProxyDevClass; +void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size); + +uint64_t proxy_default_bar_read(void *opaque, hwaddr addr, unsigned size); + #endif /* QEMU_PROXY_H */ diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 5a2be48..1a7738e 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -38,6 +38,8 @@ * PCI_CONFIG_READ PCI configuration space read * PCI_CONFIG_WRITE PCI configuration space write * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM + * BAR_WRITE Writes to PCI BAR region + * BAR_READ Reads from PCI BAR region * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -47,6 +49,8 @@ typedef enum { PCI_CONFIG_READ, PCI_CONFIG_WRITE, SYNC_SYSMEM, + BAR_WRITE, + BAR_READ, MAX, } mpqemu_cmd_t; @@ -70,6 +74,13 @@ typedef struct { } sync_sysmem_msg_t; typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} bar_access_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -77,6 +88,7 @@ typedef struct { union { uint64_t u64; sync_sysmem_msg_t sync_sysmem; + bar_access_msg_t bar_access; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/remote/remote-main.c b/remote/remote-main.c index 7b4cf2f..acd8daf 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -33,6 +33,7 @@ #include "sysemu/sysemu.h" #include "block/block.h" #include "exec/ramlist.h" +#include "exec/memattrs.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -63,6 +64,66 @@ static void process_config_read(MPQemuMsg *msg) PUT_REMOTE_WAIT(wait); } +/* TODO: confirm memtx attrs. */ +static void process_bar_write(MPQemuMsg *msg, Error **errp) +{ + bar_access_msg_t *bar_access = &msg->data1.bar_access; + AddressSpace *as = + bar_access->memory ? &address_space_memory : &address_space_io; + MemTxResult res; + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (uint8_t *)&bar_access->val, bar_access->size, true); + + if (res != MEMTX_OK) { + error_setg(errp, "Could not perform address space write operation," + " inaccessible address: %lx.", bar_access->addr); + } +} + +static void process_bar_read(MPQemuMsg *msg, Error **errp) +{ + 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; @@ -88,6 +149,18 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case PCI_CONFIG_READ: process_config_read(msg); break; + case BAR_WRITE: + process_bar_write(msg, &err); + if (err) { + goto finalize_loop; + } + break; + case BAR_READ: + process_bar_read(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243500 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=SkMaJLVo; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF7l3hgjz9sNg for ; Tue, 25 Feb 2020 08:09:55 +1100 (AEDT) Received: from localhost ([::1]:43378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KzB-00026U-Di for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:09:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50399) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmE-0006Qx-Dw for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmC-0003A2-Du for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:30 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41218) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmC-00038M-4B for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:28 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqfaK017769; Mon, 24 Feb 2020 20:56:23 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=V18b2Y/tB/tfdr7XeGv9QQmUAm7T3jOAre8HMAsld8o=; b=SkMaJLVopjO463DsdQpFrTUlqcIpTxgl/LQ25f8p+/a0WIXoHC7dDWMwuDFSCxqdTxxv TTVMGOhFtxxxb27uzPVmaJ/VCB+OTcV7RHZD2t4Tl5qoCJNmtBO024vNy2m96qJHu7sL t4Sst/3TzJDIQLm8gS8Xu3L3o1UDvDJbhRztpBSEm6RGAOsvaW3xVYa4NI2OULPC8CxD CXT1lfnCk2xjtsOh5CVC23gricMS4lOARxKabJ0tcGiiylP+e9TaZpm1bwfXw5DnPxJT l3a/ZT2uVrkzbx0puhE5qfIPwgz3r2hdK6urMsbjjmHp1Ib5tH1tneQILEIHRVyWhV61 mA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yavxrhyeu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:23 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq65D108991; Mon, 24 Feb 2020 20:56:22 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2ybe123t2t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:22 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuLAf028318; Mon, 24 Feb 2020 20:56:21 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:21 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 16/50] multi-process: Synchronize remote memory Date: Mon, 24 Feb 2020 15:55:07 -0500 Message-Id: <52bdcfdf44bcc4cd8a1a707b9c22f545fe0f1491.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=4 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id 01OKqfaK017769 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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. TODO: No need to create object for remote memory listener. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- Makefile.target | 3 + hw/proxy/memory-sync.c | 212 +++++++++++++++++++++++++++++++++++++++++ hw/proxy/qemu-proxy.c | 5 + include/hw/proxy/memory-sync.h | 37 +++++++ include/hw/proxy/qemu-proxy.h | 5 + remote/remote-main.c | 11 +++ 6 files changed, 273 insertions(+) create mode 100644 hw/proxy/memory-sync.c create mode 100644 include/hw/proxy/memory-sync.h diff --git a/Makefile.target b/Makefile.target index cfd36c1..271d883 100644 --- a/Makefile.target +++ b/Makefile.target @@ -127,6 +127,9 @@ obj-$(CONFIG_TCG) += fpu/softfloat.o obj-y += target/$(TARGET_BASE_ARCH)/ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o +ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-) +obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o +endif LIBS := $(libs_cpu) $(LIBS) obj-$(CONFIG_PLUGIN) += plugins/ diff --git a/hw/proxy/memory-sync.c b/hw/proxy/memory-sync.c new file mode 100644 index 0000000..3edbb19 --- /dev/null +++ b/hw/proxy/memory-sync.c @@ -0,0 +1,212 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include +#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(&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 b17d9bb..d3a9d38 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -16,6 +16,8 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/qstring.h" #include "hw/proxy/qemu-proxy.h" +#include "hw/proxy/memory-sync.h" +#include "qom/object.h" static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); @@ -243,6 +245,8 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); + + configure_memory_sync(pdev->sync, pdev->mpqemu_link); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) @@ -261,6 +265,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->set_proxy_sock = set_proxy_sock; dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; + dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, diff --git a/include/hw/proxy/memory-sync.h b/include/hw/proxy/memory-sync.h new file mode 100644 index 0000000..d8329c9 --- /dev/null +++ b/include/hw/proxy/memory-sync.h @@ -0,0 +1,37 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef MEMORY_SYNC_H +#define MEMORY_SYNC_H + +#include + +#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 44e370e..c93ffe3 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -10,6 +10,7 @@ #define QEMU_PROXY_H #include "io/mpqemu-link.h" +#include "hw/proxy/memory-sync.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -37,8 +38,12 @@ extern const MemoryRegionOps proxy_default_ops; struct PCIProxyDev { PCIDevice parent_dev; + int n_mr_sections; + MemoryRegionSection *mr_sections; + MPQemuLinkState *mpqemu_link; + RemoteMemSync *sync; pid_t remote_pid; int socket; diff --git a/remote/remote-main.c b/remote/remote-main.c index acd8daf..9512a3b 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -34,6 +34,7 @@ #include "block/block.h" #include "exec/ramlist.h" #include "exec/memattrs.h" +#include "exec/address-spaces.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -161,6 +162,16 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; } break; + case SYNC_SYSMEM: + /* + * TODO: ensure no active DMA is happening when + * sysmem is being updated + */ + remote_sysmem_reconfig(msg, &err); + if (err) { + goto finalize_loop; + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=CdeNDz/b; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF4M0Nzrz9sPg for ; Tue, 25 Feb 2020 08:06:59 +1100 (AEDT) Received: from localhost ([::1]:43284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KvY-0004RL-FN for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:06:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50423) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmG-0006XM-Pq for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmE-0003CM-DN for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:32 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41338) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmE-0003BL-3y for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:30 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqUG3017513; Mon, 24 Feb 2020 20:56: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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=XkgDiRUc9I8z5UM0uQC8o7mvfjG2UMl9TsYhUav3JBY=; b=CdeNDz/b2sVcahG+b04m/mAVNl3SYfIYSM4Kh+VT8aoVfMiPWcaoPIv+7GzgEedeZoiO QwjtU9gGaSN8V5qQ7CM200sayjF1Sqrf4YT6ldU6YVsSS+uwwCx/ZLvHk42MSviBifOw HegvHIjIUFSGPyVS4LG4a6hgvDdG43dzxL/5UigxMHi45poi9WTeYrR2O0LzkSvNQ/jH B43GO6izEsTGpn4mivcuPkrQxXEkZWYOXvJrZ2bZX9JQeRDz3Z2/7At2cIU355cAR+bS uZPQZNj8Cx87g4Ya7koNXVwoQNghYBQQiC6Y1OoofYFW1dooBMSnYs6rMwSAsQTapu8J XQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhyf1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:24 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq6LT171346; Mon, 24 Feb 2020 20:56:24 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2ybdshkrvk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:24 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuMQG028496; Mon, 24 Feb 2020 20:56:23 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:22 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 17/50] multi-process: create IOHUB object to handle irq Date: Mon, 24 Feb 2020 15:55:08 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id 01OKqUG3017513 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Using event_notifier_test_and_clear - Using event_notifier_cleanup() - The token is not malloced Makefile.target | 1 + hw/Makefile.objs | 2 - hw/proxy/Makefile.objs | 1 - hw/proxy/qemu-proxy.c | 51 +++++++++++++++ include/hw/pci/pci_ids.h | 3 + include/hw/proxy/qemu-proxy.h | 8 +++ include/io/mpqemu-link.h | 8 +++ include/remote/iohub.h | 50 ++++++++++++++ include/remote/machine.h | 2 + remote/Makefile.objs | 1 + remote/iohub.c | 148 ++++++++++++++++++++++++++++++++++++++++++ remote/machine.c | 15 +++++ remote/remote-main.c | 4 ++ 13 files changed, 291 insertions(+), 3 deletions(-) delete mode 100644 hw/proxy/Makefile.objs create mode 100644 include/remote/iohub.h create mode 100644 remote/iohub.c diff --git a/Makefile.target b/Makefile.target index 271d883..c621d70 100644 --- a/Makefile.target +++ b/Makefile.target @@ -129,6 +129,7 @@ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o ifeq ($(TARGET_NAME)-$(CONFIG_MPQEMU)-$(CONFIG_USER_ONLY), x86_64-y-) obj-$(CONFIG_MPQEMU) += hw/proxy/memory-sync.o +obj-$(CONFIG_MPQEMU) += hw/proxy/qemu-proxy.o endif LIBS := $(libs_cpu) $(LIBS) diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 7b489b1..af9235b 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -45,8 +45,6 @@ endif common-obj-y += $(devices-dirs-y) obj-y += $(devices-dirs-y) -common-obj-$(CONFIG_MPQEMU) += proxy/ - remote-pci-obj-$(CONFIG_MPQEMU) += core/ remote-pci-obj-$(CONFIG_MPQEMU) += block/ remote-pci-obj-$(CONFIG_MPQEMU) += pci/ diff --git a/hw/proxy/Makefile.objs b/hw/proxy/Makefile.objs deleted file mode 100644 index eb81624..0000000 --- a/hw/proxy/Makefile.objs +++ /dev/null @@ -1 +0,0 @@ -common-obj-$(CONFIG_MPQEMU) += qemu-proxy.o diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index d3a9d38..0cf7dcc 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -18,6 +18,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); @@ -215,6 +218,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(&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, char *exec_name, bool need_spawn, Error **errp) { @@ -247,6 +297,7 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, pdev->socket); configure_memory_sync(pdev->sync, pdev->mpqemu_link); + setup_irqfd(pdev); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 11f8ab7..bd0c17d 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -192,6 +192,9 @@ #define PCI_DEVICE_ID_SUN_SIMBA 0x5000 #define PCI_DEVICE_ID_SUN_SABRE 0xa000 +#define PCI_VENDOR_ID_ORACLE 0x108e +#define PCI_DEVICE_ID_REMOTE_IOHUB 0xb000 + #define PCI_VENDOR_ID_CMD 0x1095 #define PCI_DEVICE_ID_CMD_646 0x0646 diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index c93ffe3..56aec0e 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -9,8 +9,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" @@ -44,6 +47,11 @@ struct PCIProxyDev { MPQemuLinkState *mpqemu_link; RemoteMemSync *sync; + struct kvm_irqfd irqfd; + + EventNotifier intr; + EventNotifier resample; + pid_t remote_pid; int socket; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 1a7738e..13c4b80 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -40,6 +40,8 @@ * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM * BAR_WRITE Writes to PCI BAR region * BAR_READ Reads from PCI BAR region + * SET_IRQFD Sets the IRQFD to be used to raise interrupts directly + * from remote device * * proc_cmd_t enum type to specify the command to be executed on the remote * device. @@ -51,6 +53,7 @@ typedef enum { SYNC_SYSMEM, BAR_WRITE, BAR_READ, + SET_IRQFD, MAX, } mpqemu_cmd_t; @@ -81,6 +84,10 @@ typedef struct { } bar_access_msg_t; typedef struct { + int intx; +} set_irqfd_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -89,6 +96,7 @@ typedef struct { uint64_t u64; sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; + set_irqfd_msg_t set_irqfd; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/include/remote/iohub.h b/include/remote/iohub.h new file mode 100644 index 0000000..7a488a8 --- /dev/null +++ b/include/remote/iohub.h @@ -0,0 +1,50 @@ +/* + * IO Hub for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_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 ResampleToken { + void *iohub; + int pirq; +} ResampleToken; + +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]; + ResampleToken token[REMOTE_IOHUB_NB_PIRQS]; + QemuMutex irq_level_lock[REMOTE_IOHUB_NB_PIRQS]; +} RemoteIOHubState; + +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 7e9bdbe..300394a 100644 --- a/include/remote/machine.h +++ b/include/remote/machine.h @@ -16,11 +16,13 @@ #include "hw/boards.h" #include "remote/pcihost.h" #include "qemu/notify.h" +#include "remote/iohub.h" typedef struct RemMachineState { MachineState parent_obj; RemPCIHost *host; + RemoteIOHubState *iohub; } RemMachineState; #define TYPE_REMOTE_MACHINE "remote-machine" 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..a991a4e --- /dev/null +++ b/remote/iohub.c @@ -0,0 +1,148 @@ +/* + * Remote IO Hub + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include + +#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; + int pirq, s; + + pirq = token->pirq; + + s = event_notifier_test_and_clear(&iohub->resamplefds[pirq]); + + 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; + int pirq = remote_iohub_map_irq(pci_dev, msg->data1.set_irqfd.intx); + + assert(msg->num_fds == 2); + + if (event_notifier_get_fd(&iohub->irqfds[pirq]) != -1) { + event_notifier_cleanup(&iohub->irqfds[pirq]); + event_notifier_cleanup(&iohub->resamplefds[pirq]); + memset(&iohub->token[pirq], 0, sizeof(ResampleToken)); + } + + event_notifier_init_fd(&iohub->irqfds[pirq], msg->fds[0]); + event_notifier_init_fd(&iohub->resamplefds[pirq], msg->fds[1]); + + iohub->token[pirq].iohub = iohub; + iohub->token[pirq].pirq = pirq; + + qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL, + &iohub->token[pirq]); +} diff --git a/remote/machine.c b/remote/machine.c index 97e4f19..d529f68 100644 --- a/remote/machine.c +++ b/remote/machine.c @@ -25,12 +25,16 @@ #include "qemu-common.h" #include "sysemu/sysemu.h" #include "qemu/notify.h" +#include "hw/pci/pci_host.h" +#include "remote/iohub.h" static void remote_machine_init(Object *obj) { RemMachineState *s = REMOTE_MACHINE(obj); RemPCIHost *rem_host; MemoryRegion *system_memory, *system_io, *pci_memory; + PCIHostState *pci_host; + PCIDevice *pci_dev; Error *error_abort = NULL; @@ -67,6 +71,17 @@ static void remote_machine_init(Object *obj) qemu_mutex_unlock_iothread(); qdev_init_nofail(DEVICE(rem_host)); + + pci_host = PCI_HOST_BRIDGE(rem_host); + pci_dev = pci_create_simple_multifunction(pci_host->bus, + PCI_DEVFN(REMOTE_IOHUB_DEV, + REMOTE_IOHUB_FUNC), + true, TYPE_REMOTE_IOHUB_DEVICE); + + s->iohub = REMOTE_IOHUB_DEVICE(pci_dev); + + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + s->iohub, REMOTE_IOHUB_NB_PIRQS); } static const TypeInfo remote_machine = { diff --git a/remote/remote-main.c b/remote/remote-main.c index 9512a3b..02d78a4 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -35,6 +35,7 @@ #include "exec/ramlist.h" #include "exec/memattrs.h" #include "exec/address-spaces.h" +#include "remote/iohub.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -172,6 +173,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; } break; + case SET_IRQFD: + process_set_irqfd_msg(remote_pci_dev, msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=uVWfQ9J+; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF1373wJz9sNg for ; Tue, 25 Feb 2020 08:04:07 +1100 (AEDT) Received: from localhost ([::1]:43226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KtY-0000sK-87 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:04:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50427) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmH-0006YO-7H for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmF-0003E3-QC for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:33 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53150) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmF-0003Cg-Gs for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:31 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraDM164120; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=wsUMHj1D4jty5Rx598x7CcBe8ardoTAET1n87QbPxi8=; b=uVWfQ9J+EA0snhB8o9lt2MW3277lYmCZHQpkFOSzl6NEg61qoVvqPEjbprFQ+qn8P9AB zUqo6jpizi/5j0+oFZL5yOkV8Eiu9Cg3s06XfwOfpuhH0lH8tNgIokrX7RMc5Upxyfv9 YrGHjMZaggFaQtzyxnrShSxpXAYGLxuNGlvsj5JbDmVvE7cqqPLbKDqn37uuLtb7yUAr wH1iiwa1AVHeVgVw7dL4oM1TGlv4C57vgzDbNQR0AALyuyDorCo429fxxi+2lZL37aKF +iJ8MUg1AH0x/m2mn4cpBe0k9apBe2FDvxFHwy3L5aMwC32s4Vju/c4r9osRhNKuAh9Q hA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2ybvr4p94e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:26 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKpuFw108591; Mon, 24 Feb 2020 20:56:25 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2ybe123t8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:25 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuO4R028344; Mon, 24 Feb 2020 20:56:24 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:24 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 18/50] multi-process: configure remote side devices Date: Mon, 24 Feb 2020 15:55:09 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Fixed qstr leak issue hw/proxy/qemu-proxy.c | 56 ++++++++++++++++++++++++++++++++++++++++++- include/hw/proxy/qemu-proxy.h | 3 +++ include/io/mpqemu-link.h | 9 +++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 0cf7dcc..3ba05d9 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -21,8 +21,60 @@ #include "qemu/event_notifier.h" #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +#include "hw/boards.h" +#include "include/qemu/log.h" static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); +static void setup_irqfd(PCIProxyDev *dev); + +static void proxy_ready(PCIDevice *dev) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + + setup_irqfd(pdev); +} + +static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) +{ + QString *qstr; + MPQemuMsg msg; + PCIProxyDev *pdev; + const char *str; + uint32_t reply = 0; + int rc = -EINVAL; + int wait; + + pdev = PCI_PROXY_DEV(dev); + + qstr = qobject_to_json(QOBJECT(qdict)); + str = qstring_get_str(qstr); + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.data2 = (uint8_t *)(str); + msg.cmd = cmd; + msg.bytestream = 1; + msg.size = qstring_get_length(qstr) + 1; + + + wait = eventfd(0, EFD_NONBLOCK); + msg.num_fds = 1; + msg.fds[0] = wait; + + mpqemu_msg_send(&msg, pdev->mpqemu_link->com); + + reply = (uint32_t)wait_for_remote(wait); + close(wait); + + /* TODO: Add proper handling if remote did not set options. */ + if (reply == REMOTE_OK) { + rc = 0; + } + + qobject_unref(qstr); + + return rc; +} static int add_argv(char *opts_str, char **argv, int argc) { @@ -297,7 +349,6 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, pdev->socket); configure_memory_sync(pdev->sync, pdev->mpqemu_link); - setup_irqfd(pdev); } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) @@ -317,6 +368,9 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->get_proxy_sock = get_proxy_sock; dev->init_proxy = init_proxy; dev->sync = REMOTE_MEM_SYNC(object_new(TYPE_MEMORY_LISTENER)); + + dev->set_remote_opts = set_remote_opts; + dev->proxy_ready = proxy_ready; } static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 56aec0e..cd8505a 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -14,6 +14,8 @@ #include "io/mpqemu-link.h" #include "hw/proxy/memory-sync.h" #include "qemu/event_notifier.h" +#include "hw/pci/pci.h" +#include "block/qdict.h" #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" @@ -62,6 +64,7 @@ struct PCIProxyDev { void (*set_proxy_sock) (PCIDevice *dev, int socket); int (*get_proxy_sock) (PCIDevice *dev); + int (*set_remote_opts) (PCIDevice *dev, QDict *qdict, unsigned int cmd); void (*proxy_ready) (PCIDevice *dev); void (*init_proxy) (PCIDevice *dev, char *command, char *exec_name, bool need_spawn, Error **errp); diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 13c4b80..90a8437 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -54,9 +54,18 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + DEV_OPTS, + DRIVE_OPTS, + DEVICE_ADD, + DEVICE_DEL, MAX, } mpqemu_cmd_t; +typedef enum { + REMOTE_OK = 0, + REMOTE_FAIL, +} mpqemu_reply_t; + /** * MPQemuMsg: * @cmd: The remote command From patchwork Mon Feb 24 20:55:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=wmNk/Wgz; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFDl5Xkwz9sPg for ; Tue, 25 Feb 2020 08:14:15 +1100 (AEDT) Received: from localhost ([::1]:43504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L3N-0002Pl-LA for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:14:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50467) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmK-0006eB-UX for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmJ-0003JU-Bb for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:36 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53226) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmJ-0003Gw-2x for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:35 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrwU2164256; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=4SZlFhVtJVgG0M7NJTDMTWsu3V+OuqTI1X5r4RalZJk=; b=wmNk/WgzqpX9t9skk4TH6jR6A3cqGXn7VOlND6R3R/RbPAXPDUKriXqd0/uDavYds2Kp CzF3eFwOvOEDCMItq0gMcPtvslJuqh/dM6aAbbuN5p2OBe5V936Zj+suD9nX5EngvYRx UsN32fqENj6CTkJsuCH5yT/bkNk4y9L+FPZKLMBUT8RphdVY4gEgr5SOOVAcL+afwpom Q/KPIlBPdu+NumUHfrt9drag/0g1FKibFnX+dE3AH2I9pNRDG57TbhAB36ImRCuMQ5sb BSao6wFWMakL7Kp+quvYpbf9O73LVDfrgT8jKGHNRz7Ig0ePwkbnuwIvdJ/6Do+Q999v ZA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2ybvr4p94u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:28 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKpv3Q108634; Mon, 24 Feb 2020 20:56:28 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2ybe123tby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:28 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuPPK029738; Mon, 24 Feb 2020 20:56:26 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:25 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 19/50] multi-process: Retrieve PCI info from remote process Date: Mon, 24 Feb 2020 15:55:10 -0500 Message-Id: <36605a80e00d5b6707dc8f13a5c528226c943692.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=3 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Retrieve PCI configuration info about the remote device and configure the Proxy PCI object based on the returned information Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- New Patch in v5. Removes per-device proxy and adds support for a generic proxy object hw/proxy/qemu-proxy.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++- include/io/mpqemu-link.h | 10 ++++++ remote/remote-main.c | 20 ++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 3ba05d9..c888677 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -26,12 +26,91 @@ static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); static void setup_irqfd(PCIProxyDev *dev); +static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, + unsigned int op); + +static void probe_pci_info(PCIDevice *dev) +{ + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); + DeviceClass *dc = DEVICE_CLASS(pc); + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + MPQemuLinkState *mpqemu_link = pdev->mpqemu_link; + MPQemuMsg msg, ret; + uint32_t orig_val, new_val, class; + uint8_t type; + int i, size; + char *name; + + memset(&msg, 0, sizeof(MPQemuMsg)); + msg.bytestream = 0; + msg.size = 0; + msg.cmd = GET_PCI_INFO; + mpqemu_msg_send(&msg, mpqemu_link->com); + + mpqemu_msg_recv(&ret, mpqemu_link->com); + + pc->vendor_id = ret.data1.ret_pci_info.vendor_id; + pc->device_id = ret.data1.ret_pci_info.device_id; + pc->class_id = ret.data1.ret_pci_info.class_id; + pc->subsystem_id = ret.data1.ret_pci_info.subsystem_id; + + config_op_send(pdev, 11, &class, 1, PCI_CONFIG_READ); + switch (class) { + case PCI_BASE_CLASS_BRIDGE: + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + break; + case PCI_BASE_CLASS_STORAGE: + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + break; + case PCI_BASE_CLASS_NETWORK: + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); + break; + case PCI_BASE_CLASS_INPUT: + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + break; + case PCI_BASE_CLASS_DISPLAY: + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + break; + case PCI_BASE_CLASS_PROCESSOR: + set_bit(DEVICE_CATEGORY_CPU, dc->categories); + break; + default: + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + break; + } + + for (i = 0; i < 6; i++) { + config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_READ); + new_val = 0xffffffff; + config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_WRITE); + config_op_send(pdev, 0x10 + (4 * i), &new_val, 4, PCI_CONFIG_READ); + size = (~(new_val & 0xFFFFFFF0)) + 1; + config_op_send(pdev, 0x10 + (4 * i), &orig_val, 4, PCI_CONFIG_WRITE); + type = (new_val & 0x1) ? + PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; + + if (size) { + pdev->region[i].dev = pdev; + pdev->region[i].present = true; + if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { + pdev->region[i].memory = true; + } + name = g_strdup_printf("bar-region-%d", i); + memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), + &proxy_default_ops, &pdev->region[i], + name, size); + pci_register_bar(dev, i, type, &pdev->region[i].mr); + g_free(name); + } + } +} static void proxy_ready(PCIDevice *dev) { PCIProxyDev *pdev = PCI_PROXY_DEV(dev); setup_irqfd(pdev); + probe_pci_info(dev); } static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) @@ -254,7 +333,6 @@ static const TypeInfo pci_proxy_dev_type_info = { .name = TYPE_PCI_PROXY_DEV, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIProxyDev), - .abstract = true, .class_size = sizeof(PCIProxyDevClass), .class_init = pci_proxy_dev_class_init, .interfaces = (InterfaceInfo[]) { @@ -355,8 +433,12 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { PCIProxyDev *dev = PCI_PROXY_DEV(device); PCIProxyDevClass *k = PCI_PROXY_DEV_GET_CLASS(dev); + uint8_t *pci_conf = device->config; Error *local_err = NULL; + pci_conf[PCI_LATENCY_TIMER] = 0xff; + pci_conf[PCI_INTERRUPT_PIN] = 0x01; + if (k->realize) { k->realize(dev, &local_err); if (local_err) { diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 90a8437..2ca89c5 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -58,6 +58,8 @@ typedef enum { DRIVE_OPTS, DEVICE_ADD, DEVICE_DEL, + GET_PCI_INFO, + RET_PCI_INFO, MAX, } mpqemu_cmd_t; @@ -96,6 +98,13 @@ typedef struct { int intx; } set_irqfd_msg_t; + typedef struct { + uint16_t vendor_id; + uint16_t device_id; + uint16_t class_id; + uint16_t subsystem_id; +} ret_pci_info_msg_t; + typedef struct { mpqemu_cmd_t cmd; int bytestream; @@ -106,6 +115,7 @@ typedef struct { sync_sysmem_msg_t sync_sysmem; bar_access_msg_t bar_access; set_irqfd_msg_t set_irqfd; + ret_pci_info_msg_t ret_pci_info; } data1; int fds[REMOTE_MAX_FDS]; diff --git a/remote/remote-main.c b/remote/remote-main.c index 02d78a4..0f830b8 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -126,6 +126,23 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg) +{ + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev); + MPQemuMsg ret = { 0 }; + + ret.cmd = RET_PCI_INFO; + + ret.data1.ret_pci_info.vendor_id = pc->vendor_id; + ret.data1.ret_pci_info.device_id = pc->device_id; + ret.data1.ret_pci_info.class_id = pc->class_id; + ret.data1.ret_pci_info.subsystem_id = pc->subsystem_id; + + ret.size = sizeof(ret.data1); + + mpqemu_msg_send(&ret, mpqemu_link->com); +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -145,6 +162,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) switch (msg->cmd) { case INIT: break; + case GET_PCI_INFO: + process_get_pci_info_msg(remote_pci_dev, msg); + break; case PCI_CONFIG_WRITE: process_config_write(msg); break; From patchwork Mon Feb 24 20:55:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=udsqpSyN; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFBv5YMcz9sPg for ; Tue, 25 Feb 2020 08:12:39 +1100 (AEDT) Received: from localhost ([::1]:43456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L1p-0007Fb-Is for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:12:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50449) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmJ-0006bL-M5 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmH-0003HT-Py for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:35 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmH-0003FZ-Gh for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:33 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKtGND165554; Mon, 24 Feb 2020 20:56:28 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-2020-01-29; bh=KTUDkY6I7G6/v4ESCvEvNYLdRjtFDA47GR9+7WL+PKE=; b=udsqpSyNogf5VkVVb+HUQi/O0O845VFPZAmA9QxkxMAPjPYhEaanMdQaLijzwLJiQ9CM hXFpKaqUifjfStpPBKmA8odFdaNiDlMkHmdBk+th8yv+yX+5U78YXxWeYjlfuHXWBefh GVa0PjQN9Cox9X749q7PnnrisgYi6z63rFconJRASWmU79dEayhCeJBs3ZtLSa9LqG2P JZSSbBNLf/hylpJIW70kxHouxGy6FfxrJJtuh8YVAblYZ9/0alyfe7EzFlv8c+1xJcrF x1qkO+SoQLUbRMXkv4RJpqDWnKHw/yBvLia1p/3LCEpMqKLESPd46iIVt0VFgSLOWV6y 1w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p94w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:28 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq7Wf088963; Mon, 24 Feb 2020 20:56:28 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2yby5dmbkw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:28 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuRkV028390; Mon, 24 Feb 2020 20:56:27 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:27 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 20/50] multi-process: add qdev_proxy_add to create proxy devices Date: Mon, 24 Feb 2020 15:55:11 -0500 Message-Id: <4566f166ac78c6a55365386c3a9f19cd0aa3a258.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Removed support for DRIVE_OPTS as it's managed by remote process - Addressed locking issues - Squashed fix to a previous patch include/hw/proxy/qemu-proxy.h | 10 +- include/monitor/qdev.h | 25 +++++ qdev-monitor.c | 245 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+), 1 deletion(-) diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index cd8505a..7c6bddd 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -58,8 +58,9 @@ struct PCIProxyDev { int socket; char *rid; - + char *dev_id; bool managed; + QLIST_ENTRY(PCIProxyDev) next; void (*set_proxy_sock) (PCIDevice *dev, int socket); int (*get_proxy_sock) (PCIDevice *dev); @@ -80,6 +81,13 @@ typedef struct PCIProxyDevClass { char *command; } PCIProxyDevClass; +typedef struct PCIProxyDevList { + QLIST_HEAD(, PCIProxyDev) devices; +} proxy_dev_list_t; + +extern QemuMutex proxy_list_lock; +extern proxy_dev_list_t proxy_dev_list; + void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, unsigned size); diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index eaa947d..d47a544 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, Error **errp); +void qdev_proxy_fire(void); + int qdev_device_help(QemuOpts *opts); +DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, + char *command, char *exec_name, int socket, + bool managed, Error **errp); + +struct remote_process { + int rid; + int remote_pid; + unsigned int type; + int socket; + char *command; + QemuOpts *opts; + + QLIST_ENTRY(remote_process) next; +}; + +void remote_process_register(struct remote_process *p); + +struct remote_process *get_remote_process_type(unsigned int type); +struct remote_process *get_remote_process_rid(unsigned int rid); + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); void qdev_set_id(DeviceState *dev, const char *id); diff --git a/qdev-monitor.c b/qdev-monitor.c index 8ce71a2..60557ed 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -38,6 +38,15 @@ #include "migration/misc.h" #include "migration/migration.h" #include "qemu/cutils.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 "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 @@ -50,6 +59,8 @@ typedef struct QDevAlias uint32_t arch_mask; } QDevAlias; +proxy_dev_list_t proxy_dev_list; + /* Please keep this table sorted by typename. */ static const QDevAlias qdev_alias_table[] = { { "e1000", "e1000-82540em" }, @@ -592,6 +603,240 @@ static bool should_hide_device(QemuOpts *opts) return true; } +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; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (strncmp(entry->rid, rid, strlen(entry->rid)) == 0) { + return entry; + } + } + + 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 *cmd, char *exec_name, int socket, + 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); + + proxy_type = TYPE_PCI_PROXY_DEV; + + 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->socket = old_pdev->socket; + pdev->remote_pid = old_pdev->remote_pid; + } else { + pdev->socket = managed ? socket : -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), cmd, exec_name, need_spawn, errp); + + QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next); + + qemu_opts_del(proxy_opts); + return ds; +} + +DeviceState *qdev_remote_add(QemuOpts *opts, Error **errp) +{ + PCIProxyDev *pdev = NULL; + DeviceState *dev; + const char *rid, *socket = NULL, *command = NULL; + QDict *qdict_new; + const char *id = NULL; + const char *driver = NULL; + const char *bus = NULL; + const char *exec_name = NULL; + + rid = qemu_opt_get(opts, "rid"); + if (!rid) { + error_setg(errp, "rdevice option needs rid specified."); + return NULL; + } + + 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; + } + } + + socket = qemu_opt_get(opts, "socket"); + if (socket) { + if (strlen(socket) > 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 (!socket && !command) { + error_setg(errp, "remote device needs socket or command specified."); + return NULL; + } + + exec_name = qemu_opt_get(opts, "exec"); + if (!exec_name && !socket) { + error_setg(errp, "exec name is not specified."); + return NULL; + } + + bus = qemu_opt_get(opts, "bus"); + dev = qdev_proxy_add(rid, id, (char *)bus, (char *)command, + (char *)exec_name, + socket ? atoi(socket) : -1, + socket ? 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); + } + if (pdev->set_remote_opts(PCI_DEVICE(pdev), qdict_new, + DEV_OPTS)) { + error_setg(errp, "Remote process was unable to set options"); + return NULL; + } + } + + return dev; +} +#endif /*defined(CONFIG_MPQEMU)*/ + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; From patchwork Mon Feb 24 20:55:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=JJerVPRa; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF634fghz9sQt for ; Tue, 25 Feb 2020 08:08:27 +1100 (AEDT) Received: from localhost ([::1]:43346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kxl-00089l-Fd for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:08:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50485) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmL-0006ga-QO for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmK-0003L3-6K for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:37 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41502) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmJ-0003J2-TZ for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:36 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKr9j5017946; Mon, 24 Feb 2020 20:56:31 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-2020-01-29; bh=A9lFt0ytBreS5j3MbmLpvKry6kuysj3rARiDXYdNt3E=; b=JJerVPRalwDjWXHtN+GOPE1fJ/i1kt8MFpSxkSwPLgaCIbfw8l8V73z1cHHKDwtMf5gS v4V8xQEmG2L4r1l4tExqRkwe3RMaqFt7lKQTDsyjPv0WtBjlsNf1OlspG/TL2eYFm6uB EuA5jLI8o2Ke7bevuBFSRl276Lsuqb81ugRu29sACjxhY/vXSkGl7dG9qQonFHFW9wzp 874CEhkou1sNKISZAXm+PyiQEl9T5iFqCKdWg6KQuFf5rfQUfFamSaYsmDzpdw5dGHlM /yeA5QTlVSCZZKQsx0guvEfKUJTnL+lalPBdsQISa3+rDrXoZpe109o8iDoB21SnMUIG wQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yavxrhyfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:31 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKptIp108399; Mon, 24 Feb 2020 20:56:30 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2ybe123tgx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:30 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuTYb028543; Mon, 24 Feb 2020 20:56:29 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:28 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 21/50] multi-process: remote: add setup_devices msg processing Date: Mon, 24 Feb 2020 15:55:12 -0500 Message-Id: <9598678238bde438ebbb4087d92f779c940ab9a4.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- include/hw/qdev-core.h | 2 + qdev-monitor.c | 2 +- remote/remote-main.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1405b8a..64a4d58 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -392,6 +392,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev); DeviceState *qdev_find_recursive(BusState *bus, const char *id); +DeviceState *find_device_state(const char *id, Error **errp); + /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ typedef int (qbus_walkerfn)(BusState *bus, void *opaque); typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); diff --git a/qdev-monitor.c b/qdev-monitor.c index 60557ed..ccd2ce0 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -1055,7 +1055,7 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp) object_unref(OBJECT(dev)); } -static DeviceState *find_device_state(const char *id, Error **errp) +DeviceState *find_device_state(const char *id, Error **errp) { Object *obj; diff --git a/remote/remote-main.c b/remote/remote-main.c index 0f830b8..3a67cb9 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -36,6 +36,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; @@ -143,6 +158,156 @@ static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg) mpqemu_msg_send(&ret, mpqemu_link->com); } +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 setup_device(MPQemuMsg *msg, Error **errp) +{ + QObject *obj; + QDict *qdict; + QString *qstr; + QemuOpts *opts = NULL; + DeviceState *dev = NULL; + int wait = -1; + int rc = -EINVAL; + Error *local_error = NULL; + + if (msg->num_fds == 1) { + wait = msg->fds[0]; + } else { + error_setg(errp, "Numebr of FDs is incorrect"); + return rc; + } + + 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!"); + goto device_failed; + } + + qdict = qobject_to(QDict, obj); + if (!qdict) { + error_setg(errp, "Could not get QDict"); + goto device_failed; + } + + 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"); + qemu_opt_unset(opts, "exec"); + /* + * 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)))); + goto device_failed; + } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + remote_pci_dev = PCI_DEVICE(dev); + } + + notify_proxy(wait, (uint32_t)REMOTE_OK); + qemu_opts_del(opts); + return 0; + + device_failed: + notify_proxy(wait, (uint32_t)REMOTE_FAIL); + qemu_opts_del(opts); + return rc; + +} + static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; @@ -190,11 +355,28 @@ 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 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 Mon Feb 24 20:55:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=nk+6brHs; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF4G61j5z9sQt for ; Tue, 25 Feb 2020 08:06:54 +1100 (AEDT) Received: from localhost ([::1]:43288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kva-0004bX-Pe for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:06:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50659) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmV-00076s-Mq for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmU-0003aE-LA for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:47 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41790) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmU-0003YI-Bx for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:46 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqWdf017600; Mon, 24 Feb 2020 20:56:41 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-2020-01-29; bh=aH/ojVyVEyKqh6zftKolf+OBhqt+5U2sgLUcxOuQt80=; b=nk+6brHs0RFk46A4V2ulhGQ5RPbU9K/uLhokuMaRJxDbX2Ij6KNbEUdhAiDLdT936Y1f aoRKplpz3d+lEveDmi8pLYmICwsHpgmOM0OC8cirlYQs74KGNM9y3ownETT3pfwrCNqY WghrpjUBwlB2VqhKJwNNUbYC2Kk5XFfQn3OzjFV1NdB86xWw1aG2paWme7Qh/RcGDL2l HIUhDmE6RMYkJq+rfJAEhLWQsPrr6UGtpFfqFAg8cHRip44vtAPdvpYEkycA9OTPe0KD SB/EKVM2T1/o362uDTOVXaM+Tal+xxnBOqQ+irjraZJOAy5XfVxnszlDJcY8mwMwrd7e XQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yavxrhygx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKucGi072891; Mon, 24 Feb 2020 20:56:40 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2ybduv6d72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:40 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuUng028530; Mon, 24 Feb 2020 20:56:30 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:30 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 22/50] multi-process: remote: use fd for socket from parent process Date: Mon, 24 Feb 2020 15:55:13 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 3a67cb9..455cfb6 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -51,6 +51,7 @@ #include "block/qdict.h" #include "qapi/qmp/qlist.h" #include "qemu/log.h" +#include "qemu/cutils.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -400,6 +401,7 @@ finalize_loop: int main(int argc, char *argv[]) { Error *err = NULL; + int fd = -1; module_call_init(MODULE_INIT_QOM); @@ -424,7 +426,13 @@ int main(int argc, char *argv[]) return -1; } - mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, STDIN_FILENO); + fd = qemu_parse_fd(argv[1]); + if (fd == -1) { + printf("Failed to parse fd for remote process.\n"); + return -EINVAL; + } + + mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); mpqemu_link_set_callback(mpqemu_link, process_msg); mpqemu_start_coms(mpqemu_link); From patchwork Mon Feb 24 20:55:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=FwzgAdqg; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFB23t0mz9sNg for ; Tue, 25 Feb 2020 08:11:54 +1100 (AEDT) Received: from localhost ([::1]:43438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L15-0005pI-SA for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:11:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50507) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmO-0006oh-6V for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmN-0003PN-3z for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:40 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:44328) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmM-0003OT-Rb for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:39 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKsmt1033177; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=zaDOAuNzb7bSFTKfgqg9CoM++Bom7NI1IY7I/uCiA4w=; b=FwzgAdqgdq2oRBXSuKp0zYKIvSK3DY6vCFhHC0qJ2UWIyIdoXxraL/j4ev9Qao3/+HcU geDT9O6Ow8qMm4RpZZlxHRQf+CFNqDcFI1aoFWm57Kl/caa+l8bPooc5Fu8X/up+rK/n 5kmPJDSRECHN+RyRasFAVAXHyEhFp9FZaXWS3kuyNHztlrdOBt/OjD26Eq3UYTMgQ07F lxz+piRCUGr623xUCJb4ky6umzf5xAeb7tZeAxNImNMZg1GAq3d1+P9h3DCtGEKJIOJm IqJBwzOwAoWAiNgEQDecedFANyodEzLOBWEqCWyAk8rSZSWqnZ80y+cgDCES+JQX3Zix gA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2yauqua0mu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:33 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq5Vx171254; Mon, 24 Feb 2020 20:56:33 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2ybdshks1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:33 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuW94028545; Mon, 24 Feb 2020 20:56:32 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:31 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 23/50] multi-process: remote: add create_done condition Date: Mon, 24 Feb 2020 15:55:14 -0500 Message-Id: <40aa4a8ee828c39081dcec67c029bb665ec3f0d4.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/remote/remote-main.c b/remote/remote-main.c index 455cfb6..ec1ce2c 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -55,6 +55,7 @@ static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; +bool create_done; static void process_config_write(MPQemuMsg *msg) { @@ -332,21 +333,29 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) process_get_pci_info_msg(remote_pci_dev, msg); break; case PCI_CONFIG_WRITE: - process_config_write(msg); + if (create_done) { + process_config_write(msg); + } break; case PCI_CONFIG_READ: - process_config_read(msg); + if (create_done) { + process_config_read(msg); + } break; case BAR_WRITE: - process_bar_write(msg, &err); - if (err) { - goto finalize_loop; + if (create_done) { + process_bar_write(msg, &err); + if (err) { + error_report_err(err); + } } break; case BAR_READ: - process_bar_read(msg, &err); - if (err) { - goto finalize_loop; + if (create_done) { + process_bar_read(msg, &err); + if (err) { + error_report_err(err); + } } break; case SYNC_SYSMEM: @@ -366,7 +375,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) qemu_mutex_lock_iothread(); qemu_run_machine_init_done_notifiers(); qemu_mutex_unlock_iothread(); - + create_done = true; break; case DEV_OPTS: if (setup_device(msg, &err)) { From patchwork Mon Feb 24 20:55:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Z/Ch88wT; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFFt1rtKz9sNg for ; Tue, 25 Feb 2020 08:15:14 +1100 (AEDT) Received: from localhost ([::1]:43528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L4K-0004kO-4z for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:15:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50649) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmV-00075i-93 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmU-0003Zb-2V for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:47 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53514) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmT-0003XD-Pm for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:46 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraCW164147; Mon, 24 Feb 2020 20:56:41 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-2020-01-29; bh=J8Xaz+gGxdaFRzPsqSOpPdy1ej1AcSmDgOKijRk3X8A=; b=Z/Ch88wTpt7hsotSbrTcWr1BnXETGUk2xpAgRC0DJbzk9hpfFGOkBarZphL426zkNN6p fyaVB1TdLgixuasWLupPgimSQ8K0YbltABMbYe4m4q5QlN7wLLRcU00XnwoLc/QZ24Ak 7JEEMerzqBrGZ/YZVWEH2ytN3h9IGYrCgmLAylsfHzggMs4Z/GRgSdVhK3qnH1TkU4QH t3BjRCGnsXRzE3fqMA4tkCFPYgtB74D8n/lptAqSy2UsFWflofe5LcD7kswgLQLFUgy0 KKwJFdVo0Vni0osRaotaOwkttiFIvlZxU5nIdmyQ+qP9XtQBpsO4iXcI+sJT4x1nK7P5 /Q== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p96g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKud0W073024; Mon, 24 Feb 2020 20:56:40 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 2ybduv6d8t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:40 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuX0j009417; Mon, 24 Feb 2020 20:56:33 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:33 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 24/50] multi-process: add processing of remote device command line Date: Mon, 24 Feb 2020 15:55:15 -0500 Message-Id: <48965605c3f49f453b4b4f107bb8c7171eec2af9.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Add processing of command line options for devices emulated in the remote process. After remote devices are created along with their proxies, signal the proxies to finish the configuration steps. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- softmmu/vl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/softmmu/vl.c b/softmmu/vl.c index 94a7b93..79a286c 100644 --- a/softmmu/vl.c +++ b/softmmu/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" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -2065,10 +2070,35 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } +#if defined(CONFIG_MPQEMU) +static int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for device."); + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} +#endif + static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) { DeviceState *dev; +#if defined(CONFIG_MPQEMU) + const char *remote; + + remote = qemu_opt_get(opts, "remote"); + if (remote) { + /* This will be a remote process */ + return rdevice_init_func(opaque, opts, errp); + } +#endif + dev = qdev_device_add(opts, errp); if (!dev && *errp) { error_report_err(*errp); @@ -4307,6 +4337,9 @@ void qemu_init(int argc, char **argv, char **envp) qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); qemu_run_machine_init_done_notifiers(); +#if defined(CONFIG_MPQEMU) + qdev_proxy_fire(); +#endif if (rom_check_and_register_reset() != 0) { error_report("rom check and register reset failed"); exit(1); From patchwork Mon Feb 24 20:55:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Zo8Hv2nW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFGr3PYNz9sNg for ; Tue, 25 Feb 2020 08:16:04 +1100 (AEDT) Received: from localhost ([::1]:43574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L58-0006AX-66 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:16:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmT-00071E-Em for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmS-0003WB-9N for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:45 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:44494) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmS-0003Us-1N for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:44 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKs0R8032257; Mon, 24 Feb 2020 20:56:38 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-2020-01-29; bh=EZK1vIqAmmv2oEtGngYljdKy4bVjvvklE07IGQo5YXU=; b=Zo8Hv2nW59hOfp2QaImCwPzydXaVP0FGmY5vTqtpeX5yxfzhCd+UQqNkPis5Y35A1fYr XmWnZ9UT9MNubZdM9TRi/VShh2P8cEJ0VLfwVP1Mu0bKWfHd8xUghp9Qqn4edIJzUEOw LbGQtB76cuxacviYPpGvSADj1AASCVRsUbOoc7olKnX7I8D4AoOkyHgnPwfZygu36Nr6 Yji3NpoXPYWi9B6Xa4UN0ffXsl7/hYifysrpL3IpjXqbV1DLrZc+eO8uJyXsNmLkJTfv RN/bBM0F3My0CelmRu2Qw9OZElA1HO+wlLJXHBBjICGG7JYDUfk+B4tjqy0XmsYc3W3p Hw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2yauqua0n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:38 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq6Vx088811; Mon, 24 Feb 2020 20:56:37 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dmc4f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:37 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuZkf028598; Mon, 24 Feb 2020 20:56:35 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:35 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 25/50] multi-process: Introduce build flags to separate remote process code Date: Mon, 24 Feb 2020 15:55:16 -0500 Message-Id: <97563464a4941fee2f4300c25f8f45fabec36b6b.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- Makefile.target | 4 ++++ rules.mak | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile.target b/Makefile.target index c621d70..035c23b 100644 --- a/Makefile.target +++ b/Makefile.target @@ -268,6 +268,10 @@ ifdef CONFIG_DARWIN $(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@") endif +ifdef CONFIG_MPQEMU +$(SCSI_DEV_BUILD): REMOTE_FLAGS = -DREMOTE_PROCESS -DSCSI_PROCESS +endif + $(SCSI_DEV_BUILD): $(all-remote-lsi-obj-y) $(COMMON_LDADDS) $(call LINK, $(filter-out %.mak, $^)) ifdef CONFIG_DARWIN diff --git a/rules.mak b/rules.mak index e39b073..6c8560f 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 Mon Feb 24 20:55:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=cykJKNqL; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF8Z2NNDz9sNg for ; Tue, 25 Feb 2020 08:10:38 +1100 (AEDT) Received: from localhost ([::1]:43404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kzs-0003gN-7X for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:10:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50648) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmV-00075f-7f for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmT-0003XU-Bz for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:47 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53504) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmT-0003WI-2F for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:45 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrnlt164218; Mon, 24 Feb 2020 20:56: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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=aocQH+1NHhM+rtmsJWLML75T23tu0x51c8jh12GV0c8=; b=cykJKNqLMgMBRyS3OFkw4VSIJJxeK2YzO2t7k/qm/dhsj/0cEZrxOxW/p1M7nH/6+Vqm FB7NhsijCMK2CZdvYZngowJGtVhimn+MXd+7VCBJmELtIyETSGHbPibNzpEplbaSuQej ck2VNcaEigLUDTdZvg4NKU0TLWyRx31dCSucBiC3nMqjjwEJ6Mq1UjX4APk5/WaTGAcD APeu5OjVK20MdujJ4GB5cevfgvmEoI2LAMs69aM2BgXyj05xxUhg7Bs/hAAedPJm1tMG DQQIxZiXaPQli/MHRlO859Abjf7vndjCOuDRgfitYyG1DtfhFkm858Qy72djkXf2ahPe jQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p967-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:39 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKudIV073056; Mon, 24 Feb 2020 20:56:39 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2ybduv6da8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:39 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKua2f028643; Mon, 24 Feb 2020 20:56:37 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:36 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 26/50] multi-process: refractor vl.c code Date: Mon, 24 Feb 2020 15:55:17 -0500 Message-Id: <0487097d8961daab47bf9f31e5fa669642d5499c.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by aserp2120.oracle.com id 01OKrnlt164218 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva To re-use for device initialization for remote emulated devices and parsing options for remote process. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- Makefile.objs | 5 ++ remote/Makefile.objs | 1 + softmmu/vl.c | 109 +----------------------------------------- vl-parse.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ vl.h | 42 +++++++++++++++++ 5 files changed, 179 insertions(+), 108 deletions(-) create mode 100644 vl-parse.c create mode 100644 vl.h diff --git a/Makefile.objs b/Makefile.objs index aad33fc..689a722 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -96,6 +96,11 @@ qemu-seccomp.o-libs := $(SECCOMP_LIBS) common-obj-$(CONFIG_FDT) += device_tree.o +common-obj-y += vl-parse.o + +####################################################################### +# qapi + common-obj-y += qapi/ endif # CONFIG_SOFTMMU 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/softmmu/vl.c b/softmmu/vl.c index 79a286c..b277de3 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -40,6 +40,7 @@ #include "qapi/qmp/qstring.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" +#include "vl.h" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -975,20 +976,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 "" - -static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - BlockInterfaceType *block_default_type = opaque; - - return drive_new(opts, *block_default_type, errp) == NULL; -} - static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp) { if (qemu_opt_get(opts, "snapshot") == NULL) { @@ -1694,21 +1681,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 */ @@ -2070,45 +2042,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, errp); - if (!dev) { - error_setg(errp, "qdev_remote_add failed for device."); - return -1; - } - object_unref(OBJECT(dev)); - return 0; -} -#endif - -static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - DeviceState *dev; - -#if defined(CONFIG_MPQEMU) - const char *remote; - - remote = qemu_opt_get(opts, "remote"); - if (remote) { - /* This will be a remote process */ - return rdevice_init_func(opaque, opts, errp); - } -#endif - - dev = qdev_device_add(opts, errp); - if (!dev && *errp) { - error_report_err(*errp); - return -1; - } else if (dev) { - object_unref(OBJECT(dev)); - } - return 0; -} - static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; @@ -2358,46 +2291,6 @@ static void qemu_unlink_pidfile(Notifier *n, void *data) } } -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); diff --git a/vl-parse.c b/vl-parse.c new file mode 100644 index 0000000..b76bc95 --- /dev/null +++ b/vl-parse.c @@ -0,0 +1,130 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/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("Not valid 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 rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + + dev = qdev_remote_add(opts, errp); + if (!dev) { + error_setg(errp, "qdev_remote_add failed for device."); + return -1; + } + return 0; +} +#endif + +int device_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + DeviceState *dev; + +#if defined(CONFIG_MPQEMU) + const char *remote = qemu_opt_get(opts, "rid"); + if (remote) { + return 0; + } +#endif + + dev = qdev_device_add(opts, errp); + if (!dev) { + return -1; + } + object_unref(OBJECT(dev)); + return 0; +} diff --git a/vl.h b/vl.h new file mode 100644 index 0000000..a171fab --- /dev/null +++ b/vl.h @@ -0,0 +1,42 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef 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); + +#if defined(CONFIG_MPQEMU) +int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp); +#endif + +#endif /* VL_H */ + From patchwork Mon Feb 24 20:55:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=lD7VSVmB; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFJr70Crz9sPg for ; Tue, 25 Feb 2020 08:17:48 +1100 (AEDT) Received: from localhost ([::1]:43602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L6o-0008PW-RH for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:17:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50655) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmV-00076G-FH for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmU-0003Zy-Ea for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:47 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53508) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmU-0003Wa-5b for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:46 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraCV164147; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=n6V5S01kaW9DM0TRseWApUxtUCbdgdHcMVr0wIVgh/g=; b=lD7VSVmBBJb9d0Y5lKKzVEO3nmq1xl36Drwqko4ipNixC0tIt6VRh6FRYbZD7qYu2zYQ wpecj3vWYn9y/Dq6eMd2WmW4p+n2tgeAjSN53xkPW406zCHbFAp396UwhCzN7JzhcGFO wZNKyg+KBVKcg8uTNdjOvucwVwdIYU0cZQxeM4yy0sSEo1lf17lM4MIGbU9CcvEVeGwR AAa3qVgWDtpMVxqMtcTrq6sDC4aBeUsFf6k/sVA0yQUcHO5P9sRtOqs17D+Q/HGNjWS6 C8B4As9CLmGa/WSUZOcUJqbg9akm+z+gudBivHDomDZpU8LzulX8+AUzmOxQquTpDjR8 dg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2ybvr4p96b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:40 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKpsOC108241; Mon, 24 Feb 2020 20:56:39 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ybe123tvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:39 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKucCo009446; Mon, 24 Feb 2020 20:56:38 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:38 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 27/50] multi-process: add remote option Date: Mon, 24 Feb 2020 15:55:18 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- qemu-options.hx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index ac315c1..2c5e97f 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 Mon Feb 24 20:55:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=TyJqx1TS; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFL45hrxz9sNg for ; Tue, 25 Feb 2020 08:18:52 +1100 (AEDT) Received: from localhost ([::1]:43622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L7q-0001SM-A3 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:18:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KmX-0007Ab-43 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmV-0003bi-Hn for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:49 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53550) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmV-0003a2-80 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:47 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKral6164128; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=I0MCFzsj7Hs8gCp2U945/nTXJZSYe2xsHlKItOC4YrQ=; b=TyJqx1TSD3H5xoi1hVy1f1VqqLBUpeUl7nPcR36pSblhuqbvpMS3vNHSVQLiEOYZ8lNy 22xoED6ylzORWpheXBlfDPWXvREW3Xg9p87UHXBm/XEm9RMEr954tsvIo7C66FdcpjfY QwE10UiTWXxnXnY/icV1YPC9T+/e3jQSpbEtUHeZO46uir9HI9Sg39bBxCt8ye/3H4xW 1l+8NQEb/hmFJhze5SXvFcTE1uF2CtcrjBmkm+BSRFvX8jfilM156ARcFW73hlIpK/9M 29NCCHrkpxi7VADEcPXVMB83jQ7d+NDVzGfV7aCCkqla8HF1RVY8ffLIap1PRA65h2Zm og== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p96p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:42 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq8cm089110; Mon, 24 Feb 2020 20:56:42 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2yby5dmce7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:42 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKueaa029940; Mon, 24 Feb 2020 20:56:40 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:39 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 28/50] multi-process: add remote options parser Date: Mon, 24 Feb 2020 15:55:19 -0500 Message-Id: <8ed88052f089814b70d32fcf17f0f963daa03c28.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- include/monitor/qdev.h | 1 + softmmu/vl.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ vl-parse.c | 31 +++++++++++++++ vl.h | 1 + 4 files changed, 138 insertions(+) diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index d47a544..f3a56fa 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -23,6 +23,7 @@ struct remote_process { unsigned int type; int socket; char *command; + char *exec; QemuOpts *opts; QLIST_ENTRY(remote_process) next; diff --git a/softmmu/vl.c b/softmmu/vl.c index b277de3..a8a6f35 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -253,6 +253,32 @@ 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", + },{ + .name = "exec", + .type = QEMU_OPT_STRING, + .help = "exec name", + }, + { /* end of list */ } + }, +}; + + static QemuOptsList qemu_machine_opts = { .name = "machine", .implied_opt_name = "type", @@ -314,6 +340,71 @@ static QemuOptsList qemu_boot_opts = { }, }; +#if defined(CONFIG_MPQEMU) +static int parse_remote(void *opaque, QemuOpts *opts, Error **errp) +{ + int rid; + int socket; + char *c_sock = NULL; + char *command = NULL; + char *exec = 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; + } + if (socket <= STDERR_FILENO && socket != -1) { + socket = -1; + } + + exec = (char *)qemu_opt_get(opts, "exec"); + + if (!exec && socket < 0) { + error_setg(errp, "No socket or exec defined for remote."); + return -1; + } + if (exec && (socket != -1)) { + error_setg(errp, "Both socket and exec are specified, " \ + "need only one of those."); + return -1; + } + + command = (char *)qemu_opt_get(opts, "command"); + if (!command && socket < 0) { + error_setg(errp, "Remote process command option is not specified."); + return -1; + } + + r_proc.rid = rid; + r_proc.socket = socket; + r_proc.command = g_strdup(command); + r_proc.exec = g_strdup(exec); + 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 -EINVAL; + } + + return 0; +} +#endif + static QemuOptsList qemu_add_fd_opts = { .name = "add-fd", .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head), @@ -2751,6 +2842,7 @@ void qemu_init(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(); @@ -3575,6 +3667,14 @@ void qemu_init(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); @@ -4170,6 +4270,11 @@ void qemu_init(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(); diff --git a/vl-parse.c b/vl-parse.c index b76bc95..1f6a3f0 100644 --- a/vl-parse.c +++ b/vl-parse.c @@ -85,6 +85,37 @@ const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +#if defined(CONFIG_MPQEMU) +int device_remote_add(void *opaque, QemuOpts *opts, Error **errp) +{ + unsigned int rid = 0; + const char *opt_rid = NULL; + struct remote_process *p = NULL; + + if (opaque) { + rid = *(unsigned int *)opaque; + } + opt_rid = qemu_opt_get(opts, "rid"); + if (!opt_rid) { + return 0; + } + + p = get_remote_process_rid(rid); + if (!p) { + error_setg(errp, "No process for rid %d", rid); + return -EINVAL; + } + + if (atoi(opt_rid) == rid) { + qemu_opt_set(opts, "command", p->command, errp); + qemu_opt_set(opts, "exec", p->exec, errp); + rdevice_init_func(opaque, opts, errp); + qemu_opts_del(opts); + } + return 0; +} +#endif + int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) { BlockInterfaceType *block_default_type = opaque; diff --git a/vl.h b/vl.h index a171fab..d84bf63 100644 --- a/vl.h +++ b/vl.h @@ -36,6 +36,7 @@ int device_init_func(void *opaque, QemuOpts *opts, Error **errp); #if defined(CONFIG_MPQEMU) int rdevice_init_func(void *opaque, QemuOpts *opts, Error **errp); +int device_remote_add(void *opaque, QemuOpts *opts, Error **errp); #endif #endif /* VL_H */ From patchwork Mon Feb 24 20:55:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243531 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=GYcAsqq9; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFNj5q5Gz9sQt for ; Tue, 25 Feb 2020 08:21:09 +1100 (AEDT) Received: from localhost ([::1]:43678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LA3-00052l-Ic for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:21:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50713) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kma-0007Ha-7K for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6KmY-0003fE-Qz for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:52 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:44720) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6KmY-0003eT-Hz for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:50 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrT3S032113; Mon, 24 Feb 2020 20:56:44 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=ZAut839gnnTM2391uTPPAt9hp4FxiFqDIO14yAEQRKI=; b=GYcAsqq9Hal8X4/PFytk955Co0882VnunpCDzc4G1wQwJtSBvep7etlMvW3GBrAHNkd6 5poH3rBmmMZtcyis1xbbSwmmUvH7M8tKbpjDxzOVDql9Jyogbkb33w+acBcPXCmqD0MQ FHJBkCZ0MdYzJWOb/ui4xRKRYHU4zFW85GjXrjKtxtCQ+N8LloLcMLiUretUcfskHomv GcZqCj1tpZsEHg1Xp2gtAzUmiALXD+gpO/L4bSKjKZEAFqqkF0Ofkw1HwyVz8xtEJS2r mKCx1dIJDH0yizJYdUGLHt9OYEVmPqYsvpHUDOrXRH/vN2IyB658WniJySqCxQJDwVND Rw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2yauqua0nx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:44 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq8LT089105; Mon, 24 Feb 2020 20:56:43 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dmchq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:43 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKufMJ028696; Mon, 24 Feb 2020 20:56:41 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:41 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 29/50] multi-process: add parse_cmdline in remote process Date: Mon, 24 Feb 2020 15:55:20 -0500 Message-Id: <713dcf76224660af4a5766d6ebdd5b478cd4fec7.1582576372.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-MIME-Autoconverted: from 8bit to quoted-printable by userp2130.oracle.com id 01OKrT3S032113 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- remote/Makefile.objs | 1 + remote/remote-main.c | 11 ++++++ remote/remote-opts.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ remote/remote-opts.h | 15 ++++++++ 4 files changed, 126 insertions(+) create mode 100644 remote/remote-opts.c create mode 100644 remote/remote-opts.h 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 ec1ce2c..872ff7e 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -52,6 +52,7 @@ #include "qapi/qmp/qlist.h" #include "qemu/log.h" #include "qemu/cutils.h" +#include "remote-opts.h" static MPQemuLinkState *mpqemu_link; PCIDevice *remote_pci_dev; @@ -429,6 +430,13 @@ int main(int argc, char *argv[]) current_machine = MACHINE(REMOTE_MACHINE(object_new(TYPE_REMOTE_MACHINE))); + qemu_add_opts(&qemu_device_opts); + qemu_add_opts(&qemu_drive_opts); + qemu_add_drive_opts(&qemu_legacy_drive_opts); + qemu_add_drive_opts(&qemu_common_drive_opts); + qemu_add_drive_opts(&qemu_drive_opts); + qemu_add_drive_opts(&bdrv_runtime_opts); + mpqemu_link = mpqemu_link_create(); if (!mpqemu_link) { printf("Could not create MPQemu link\n"); @@ -442,6 +450,9 @@ int main(int argc, char *argv[]) } mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); + + parse_cmdline(argc - 2, argv + 2, NULL); + mpqemu_link_set_callback(mpqemu_link, process_msg); mpqemu_start_coms(mpqemu_link); diff --git a/remote/remote-opts.c b/remote/remote-opts.c new file mode 100644 index 0000000..7e12700 --- /dev/null +++ b/remote/remote-opts.c @@ -0,0 +1,99 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include +#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..263d428 --- /dev/null +++ b/remote/remote-opts.h @@ -0,0 +1,15 @@ +/* + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_OPTS_H +#define REMOTE_OPTS_H + +void parse_cmdline(int argc, char **argv, char **envp); + +#endif + From patchwork Mon Feb 24 20:55:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=RzSn9zKt; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF8P11hZz9sNg for ; Tue, 25 Feb 2020 08:10:29 +1100 (AEDT) Received: from localhost ([::1]:43398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kzj-0003KS-1F for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:10:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50819) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmk-0007g3-1f for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmi-0003qu-Is for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:01 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmi-0003eG-9u for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:00 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraUh164125; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=ceaeBYb+TTIVt68VNOebp9OmXkjBwu41XUUu2Ljz5+k=; b=RzSn9zKtcSinxBc+MMSlknUr4z2zvVnfhu69fI5yX8RnUEe9c/NpM6dPbyVFC5N6oB17 gxZa5yBnYD/1dweMC9+wMFKHI2bdoeqDRMUsgeI7zhPlKpOpX6yRZupyr4ppKnNkBF3q HHnFlBOYuv1+JMQ2tKMCjIaH/9TGR8jad15jfHwGmyZxWXa4r44jBQBwllO4np8NLq0+ dRC6jOVFX5r4FXkguqP5Rw5N63cgcfcFbR6NP2KmH7U1gih1lsSjDkAfJxScmgPy0zp+ tqQudvMHYkJCTjYN8by5s+tTuekKqmIEcYFSt1gjnw9PHP9EBM5cailBKywZ0myc3shH wQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p974-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:45 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKuerU073146; Mon, 24 Feb 2020 20:56:45 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:45 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuhWv029971; Mon, 24 Feb 2020 20:56:43 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:42 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 30/50] multi-process: send heartbeat messages to remote Date: Mon, 24 Feb 2020 15:55:21 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=3 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=3 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Heart beat messages are sent asynchronously hw/proxy/qemu-proxy.c | 115 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 118 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index c888677..bcb24f7 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -24,11 +24,104 @@ #include "hw/boards.h" #include "include/qemu/log.h" +QEMUTimer *hb_timer; static void pci_proxy_dev_realize(PCIDevice *dev, Error **errp); static void setup_irqfd(PCIProxyDev *dev); +static void pci_dev_exit(PCIDevice *dev); +static void start_broadcast_timer(void); +static void stop_broadcast_timer(void); +static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx); +static void broadcast_init(void); static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, unsigned int op); +static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx) +{ + /* TODO: Add proper handler. */ + printf("Child (pid %d) is dead? Signal is %d, Exit code is %d.\n", + siginfo->si_pid, siginfo->si_signo, siginfo->si_code); +} + +static void remote_ping_handler(void *opaque) +{ + PCIProxyDev *pdev = opaque; + + if (!event_notifier_test_and_clear(&pdev->en_ping)) { + /* + * TODO: Is retry needed? Add the handling of the + * non-responsive process. How its done in case + * of managed process? + */ + printf("No reply from remote process, pid %d\n", pdev->remote_pid); + event_notifier_cleanup(&pdev->en_ping); + } +} + +static void broadcast_msg(void) +{ + MPQemuMsg msg; + PCIProxyDev *entry; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + if (event_notifier_get_fd(&entry->en_ping) == -1) { + continue; + } + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.num_fds = 1; + msg.cmd = PROXY_PING; + msg.bytestream = 0; + msg.size = 0; + msg.fds[0] = event_notifier_get_fd(&entry->en_ping); + + mpqemu_msg_send(&msg, entry->mpqemu_link->com); + } +} + +static void broadcast_init(void) +{ + PCIProxyDev *entry; + + QLIST_FOREACH(entry, &proxy_dev_list.devices, next) { + event_notifier_init(&entry->en_ping, 0); + qemu_set_fd_handler(event_notifier_get_fd(&entry->en_ping), + remote_ping_handler, NULL, entry); + } +} + +#define NOP_INTERVAL 1000000 + +static void remote_ping(void *opaque) +{ + broadcast_msg(); + timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); +} + +static void start_broadcast_timer(void) +{ + hb_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, + remote_ping, + &proxy_dev_list); + timer_mod(hb_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); + +} + +static void stop_broadcast_timer(void) +{ + timer_del(hb_timer); + timer_free(hb_timer); +} + +static void set_sigchld_handler(void) +{ + struct sigaction sa_sigterm; + memset(&sa_sigterm, 0, sizeof(sa_sigterm)); + sa_sigterm.sa_sigaction = childsig_handler; + sa_sigterm.sa_flags = SA_SIGINFO | SA_NOCLDWAIT | SA_NOCLDSTOP; + sigaction(SIGCHLD, &sa_sigterm, NULL); +} + static void probe_pci_info(PCIDevice *dev) { PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); @@ -111,6 +204,9 @@ static void proxy_ready(PCIDevice *dev) setup_irqfd(pdev); probe_pci_info(dev); + set_sigchld_handler(); + broadcast_init(); + start_broadcast_timer(); } static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) @@ -325,6 +421,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->realize = pci_proxy_dev_realize; + k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; } @@ -455,6 +552,24 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) dev->proxy_ready = proxy_ready; } +static void pci_dev_exit(PCIDevice *pdev) +{ + PCIProxyDev *entry, *sentry; + PCIProxyDev *dev = PCI_PROXY_DEV(pdev); + + stop_broadcast_timer(); + + QLIST_FOREACH_SAFE(entry, &proxy_dev_list.devices, next, sentry) { + if (entry->remote_pid == dev->remote_pid) { + QLIST_REMOVE(entry, next); + } + } + + if (!QLIST_EMPTY(&proxy_dev_list.devices)) { + start_broadcast_timer(); + } +} + static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, bool write, hwaddr addr, uint64_t *val, unsigned size, bool memory) diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 7c6bddd..f7666fb 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -55,6 +55,8 @@ struct PCIProxyDev { EventNotifier resample; pid_t remote_pid; + EventNotifier en_ping; + int socket; char *rid; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 2ca89c5..aaaf1a4 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -60,6 +60,7 @@ typedef enum { DEVICE_DEL, GET_PCI_INFO, RET_PCI_INFO, + PROXY_PING, MAX, } mpqemu_cmd_t; From patchwork Mon Feb 24 20:55:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=qpL8wzZs; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFR14wqwz9sNg for ; Tue, 25 Feb 2020 08:23:09 +1100 (AEDT) Received: from localhost ([::1]:43766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LBz-0000cU-HR for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:23:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50854) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kml-0007jd-Ix for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmk-0003uL-IE for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:03 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53648) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmk-0003fl-9Y for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:02 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrrEn164241; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=11GRFHKYicQAWpUGFaClGFpZjf42fOND2jTkHGMe8jM=; b=qpL8wzZsp4Ih/KG5BcpY2G5HDBrWqEoiY8K9k38YCpS+3SH4OrgQbhDjA9pRhv+odGSP o7ZyiZzMchg61A6UoMYs0sTbf3kK7K/1pIjAKyVwKI3S2x2kKBQsyZUoFSMjr4Nz3IcW 1T/XUudiqcSjkUSTrYbm3dq4WUcyc9UTFWJqk/27hKW/8NaOe2+hVaEQ9/99gvmLX7GF 3sePTXshKoscsQjagka5Vg31W+4RCmdOc6wRsbvRBMHmjVkhChIwVHGtjb2pSXd8bRNA OLvJUaRjJuguh4AFL+dbR+8ed0FGdPYYWkO6U9RgFkRD5A5iFgZuHxzSRITEtOCYHVfE Qw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ybvr4p978-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:47 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqOFK089544; Mon, 24 Feb 2020 20:56:46 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2yby5dmcrg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:46 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuiHg028708; Mon, 24 Feb 2020 20:56:44 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:44 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 31/50] multi-process: handle heartbeat messages in remote process Date: Mon, 24 Feb 2020 15:55:22 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/remote/remote-main.c b/remote/remote-main.c index 872ff7e..2c05d20 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -315,6 +315,7 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) { MPQemuMsg *msg = NULL; Error *err = NULL; + int wait; if ((cond & G_IO_HUP) || (cond & G_IO_ERR)) { goto finalize_loop; @@ -389,6 +390,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) case DEVICE_DEL: process_device_del_msg(msg); break; + case PROXY_PING: + wait = msg->fds[0]; + notify_proxy(wait, (uint32_t)getpid()); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=quXhbJVX; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFBw1skMz9sQt for ; Tue, 25 Feb 2020 08:12:40 +1100 (AEDT) Received: from localhost ([::1]:43460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L1q-0007Iu-2f for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:12:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50745) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmc-0007OG-RJ for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmb-0003h4-2z for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:54 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kma-0003gC-RP for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:53 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqWdh017600; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=Ir7O9f1JIYFBmWd17NtDMCFQCpbqhXj4vR6Wr4D9z1k=; b=quXhbJVXcqP/RfX+S4XWoyvq0LqixiN24cCOtLYWEieaxhAu8hHFg63i9rvPx1Ia6A+6 UlJHHE5G3ex0tyr5cqmDn/7stRZrTn4IQEMWIhsK3WTm8fdGX1W4YvsV5J8Ig7LicXrC /Y4sMCsj+lnnT2mCF9H3HWTrftd0bGNuhjcABb4Vzxw0UoX0K8cmwyhTs5xjlZREi1OT vixdF2SJmpzzTQJ2aVKI0rdrPu+bVuacjCQcrbIdkIyNaf99ayFd3sPq63uZ4i/8MKeF /rtG5FXsDfVl6IRGvIcoWS+zbdZvrNjTRYHwH7A9ORwtKrdCCnhAdT9jeG9VuYIbobsL og== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yavxrhyhs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:47 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKucBa072957; Mon, 24 Feb 2020 20:56:46 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2ybduv6dej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:46 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKukDk028703; Mon, 24 Feb 2020 20:56:46 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:45 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 32/50] multi-process: Use separate MMIO communication channel Date: Mon, 24 Feb 2020 15:55:23 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- hw/proxy/qemu-proxy.c | 51 ++++++++++++++++++++++++++++--------------- include/hw/proxy/qemu-proxy.h | 1 + include/io/mpqemu-link.h | 7 ++++++ io/mpqemu-link.c | 2 ++ qdev-monitor.c | 1 + remote/remote-main.c | 18 ++++++++++----- 6 files changed, 58 insertions(+), 22 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index bcb24f7..68517aa 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -283,13 +283,14 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts, const char *exec_name, Error **errp) { pid_t rpid; - int fd[2] = {-1, -1}; + int fd[2], mmio[2]; Error *local_error = NULL; char *argv[64]; int argc = 0; char *sfd; char *exec_dir; int rc = -EINVAL; + struct timeval timeout = {.tv_sec = 10, .tv_usec = 0}; if (pdev->managed) { /* Child is forked by external program (such as libvirt). */ @@ -302,7 +303,8 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts, return rc; } - if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) || + socketpair(AF_UNIX, SOCK_STREAM, 0, mmio)) { error_setg(errp, "Unable to create unix socket."); return rc; } @@ -310,6 +312,8 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts, argc = add_argv(exec_dir, argv, argc); sfd = g_strdup_printf("%d", fd[1]); argc = add_argv(sfd, argv, argc); + sfd = g_strdup_printf("%d", mmio[1]); + argc = add_argv(sfd, argv, argc); argc = make_argv((char *)opts, argv, argc); /* TODO: Restrict the forked process' permissions and capabilities. */ @@ -318,24 +322,35 @@ static int remote_spawn(PCIProxyDev *pdev, const char *opts, if (rpid == -1) { error_setg(errp, "Unable to spawn emulation program."); close(fd[0]); - goto fail; + close(fd[1]); + close(mmio[0]); + close(mmio[1]); + return rc; } if (rpid == 0) { close(fd[0]); + close(mmio[0]); rc = execv(argv[0], (char *const *)argv); exit(1); } pdev->remote_pid = rpid; pdev->socket = fd[0]; + pdev->mmio_sock = mmio[0]; - rc = 0; + rc = setsockopt(mmio[0], SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, + sizeof(timeout)); + if (rc < 0) { + close(fd[0]); + close(mmio[0]); -fail: - close(fd[1]); + error_setg(errp, "Unable to set timeout for socket"); - return rc; + return rc; + } + + return 0; } static int get_proxy_sock(PCIDevice *dev) @@ -523,6 +538,9 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->com, pdev->socket); + mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio, + pdev->mmio_sock); + configure_memory_sync(pdev->sync, pdev->mpqemu_link); } @@ -575,10 +593,10 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, unsigned size, bool memory) { MPQemuLinkState *mpqemu_link = dev->mpqemu_link; - MPQemuMsg msg; - int wait; + MPQemuMsg msg, ret; memset(&msg, 0, sizeof(MPQemuMsg)); + memset(&ret, 0, sizeof(MPQemuMsg)); msg.bytestream = 0; msg.size = sizeof(msg.data1); @@ -590,19 +608,18 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, msg.cmd = BAR_WRITE; msg.data1.bar_access.val = *val; } else { - wait = GET_REMOTE_WAIT; - msg.cmd = BAR_READ; - msg.num_fds = 1; - msg.fds[0] = wait; } - mpqemu_msg_send(&msg, mpqemu_link->com); + mpqemu_msg_send(&msg, mpqemu_link->mmio); - if (!write) { - *val = wait_for_remote(wait); - PUT_REMOTE_WAIT(wait); + if (write) { + return; } + + mpqemu_msg_recv(&ret, mpqemu_link->mmio); + + *val = ret.data1.mmio_ret.val; } void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index f7666fb..2a2c732 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -58,6 +58,7 @@ struct PCIProxyDev { EventNotifier en_ping; int socket; + int mmio_sock; char *rid; char *dev_id; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index aaaf1a4..3962630 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -61,6 +61,7 @@ typedef enum { GET_PCI_INFO, RET_PCI_INFO, PROXY_PING, + MMIO_RETURN, MAX, } mpqemu_cmd_t; @@ -107,6 +108,10 @@ typedef struct { } ret_pci_info_msg_t; typedef struct { + uint64_t val; +} mmio_ret_msg_t; + +typedef struct { mpqemu_cmd_t cmd; int bytestream; size_t size; @@ -117,6 +122,7 @@ typedef struct { bar_access_msg_t bar_access; set_irqfd_msg_t set_irqfd; ret_pci_info_msg_t ret_pci_info; + mmio_ret_msg_t mmio_ret; } data1; int fds[REMOTE_MAX_FDS]; @@ -171,6 +177,7 @@ typedef struct MPQemuLinkState { GMainLoop *loop; MPQemuChannel *com; + MPQemuChannel *mmio; mpqemu_link_callback callback; } MPQemuLinkState; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 73b7032..07a9be9 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -57,6 +57,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s) g_main_loop_quit(s->loop); mpqemu_destroy_channel(s->com); + mpqemu_destroy_channel(s->mmio); object_unref(OBJECT(s)); } @@ -330,6 +331,7 @@ void mpqemu_start_coms(MPQemuLinkState *s) { g_assert(g_source_attach(&s->com->gsrc, s->ctx)); + g_assert(g_source_attach(&s->mmio->gsrc, s->ctx)); g_main_loop_run(s->loop); } diff --git a/qdev-monitor.c b/qdev-monitor.c index ccd2ce0..27b2ddc 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -730,6 +730,7 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->rid = g_strdup(rid); if (old_pdev) { pdev->socket = old_pdev->socket; + pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; } else { pdev->socket = managed ? socket : -1; diff --git a/remote/remote-main.c b/remote/remote-main.c index 2c05d20..6cfc446 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -104,8 +104,8 @@ static void process_bar_write(MPQemuMsg *msg, Error **errp) static void process_bar_read(MPQemuMsg *msg, Error **errp) { bar_access_msg_t *bar_access = &msg->data1.bar_access; + MPQemuMsg ret = { 0 }; AddressSpace *as; - int wait = msg->fds[0]; MemTxResult res; uint64_t val = 0; @@ -139,9 +139,10 @@ static void process_bar_read(MPQemuMsg *msg, Error **errp) } fail: - notify_proxy(wait, val); - - PUT_REMOTE_WAIT(wait); + ret.cmd = MMIO_RETURN; + ret.data1.mmio_ret.val = val; + ret.size = sizeof(ret.data1); + mpqemu_msg_send(&ret, mpqemu_link->mmio); } static void process_get_pci_info_msg(PCIDevice *pci_dev, MPQemuMsg *msg) @@ -456,7 +457,14 @@ int main(int argc, char *argv[]) mpqemu_init_channel(mpqemu_link, &mpqemu_link->com, fd); - parse_cmdline(argc - 2, argv + 2, NULL); + fd = qemu_parse_fd(argv[2]); + if (fd == -1) { + printf("Failed to parse fd for remote process.\n"); + return -EINVAL; + } + mpqemu_init_channel(mpqemu_link, &mpqemu_link->mmio, fd); + + parse_cmdline(argc - 3, argv + 3, NULL); mpqemu_link_set_callback(mpqemu_link, process_msg); From patchwork Mon Feb 24 20:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=KWO5Wn5I; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFNj2Z5Tz9sNg for ; Tue, 25 Feb 2020 08:21:09 +1100 (AEDT) Received: from localhost ([::1]:43682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LA3-00053S-7n for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:21:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmf-0007TD-5E for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmd-0003jW-Pd for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:57 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmd-0003iN-GA for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:55 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqVl4017560; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=K4N24fAHtaqqUMoKG6qIOiC5sm1MjAK0vc1+m05x96Y=; b=KWO5Wn5Ihw2X+7X0A42sH7s02QQuM3n1BZuwtXANOGw5JW+li+EfcTbz2ShaJ1Ydi6Cl vP9ZiyhHfoY5ZnBm7xgP8zYYuvjXgNVzzH1+7vg+hAksUwkZVcpFlLUOV+JyKsLOVtki 5bgvFH2GgP/e/buh/T1/QVVf9d/i909t2wInDxjIgrMUsrCB4YiH6vTitnU+gbNbaVbR n66AntlYXpe6M0z6Yw6pcIfoqMCT2iw9n9rQt9bAn31KiQnenMtXhtEHq4R5UGZh39ci MXTU3GXPs9EwUYcUc+Wd4264TMG/CQrjorhJMKLL3Z0VfjHye/EO3iSdqkdD4PZVL+dC Iw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yavxrhyj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:50 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKunYN073464; Mon, 24 Feb 2020 20:56:49 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:49 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKulaE030045; Mon, 24 Feb 2020 20:56:47 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:47 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 33/50] multi-process: perform device reset in the remote process Date: Mon, 24 Feb 2020 15:55:24 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- V4 -> v5: - Device reset wait for remote hw/proxy/qemu-proxy.c | 25 +++++++++++++++++++++++++ include/io/mpqemu-link.h | 1 + remote/remote-main.c | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 68517aa..741f02a 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -431,14 +431,39 @@ static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val, config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE); } +static void proxy_device_reset(DeviceState *dev) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + MPQemuMsg msg; + int wait = -1; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.cmd = DEVICE_RESET; + + wait = eventfd(0, EFD_CLOEXEC); + msg.num_fds = 1; + msg.fds[0] = wait; + + mpqemu_msg_send(&msg, pdev->mpqemu_link->com); + + wait_for_remote(wait); + close(wait); +} + static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); k->realize = pci_proxy_dev_realize; k->exit = pci_dev_exit; k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; + + dc->reset = proxy_device_reset; } static const TypeInfo pci_proxy_dev_type_info = { diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 3962630..d2234ca 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -62,6 +62,7 @@ typedef enum { RET_PCI_INFO, PROXY_PING, MMIO_RETURN, + DEVICE_RESET, MAX, } mpqemu_cmd_t; diff --git a/remote/remote-main.c b/remote/remote-main.c index 6cfc446..5284ee9 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -53,8 +53,11 @@ #include "qemu/log.h" #include "qemu/cutils.h" #include "remote-opts.h" +#include "monitor/monitor.h" +#include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link; + PCIDevice *remote_pci_dev; bool create_done; @@ -241,6 +244,11 @@ fail: PUT_REMOTE_WAIT(wait); } +static void process_device_reset_msg(MPQemuMsg *msg) +{ + qemu_devices_reset(); +} + static int setup_device(MPQemuMsg *msg, Error **errp) { QObject *obj; @@ -395,6 +403,12 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) wait = msg->fds[0]; notify_proxy(wait, (uint32_t)getpid()); break; + case DEVICE_RESET: + process_device_reset_msg(msg); + if (msg->num_fds == 1) { + notify_proxy(msg->fds[0], 0); + } + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=uykGE8go; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFDm0nBzz9sNg for ; Tue, 25 Feb 2020 08:14:16 +1100 (AEDT) Received: from localhost ([::1]:43500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L3N-0002PL-VL for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:14:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50789) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmf-0007VN-Tn for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kme-0003jn-1Z for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:57 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:44798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmd-0003ih-OW for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:55 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrXG6032136; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=vpe0/c5G0MXd4JAhsy6/u+S1fhUP7KtMyY9f4+3J9y0=; b=uykGE8go7EUwEw0hPoulYcC8MArfUGyM7lglFb7LD0RmG/br2pOVg+YuNJxKoZbKSPvJ BxWcdiD7LkL0E1mA1Ed/ZkC623UJlHGbS19T6vz3uW4DtD4naD3+yejUVDBOCv7EHSrr /S8SKPcYUR6gCaVG8rBJyQoZKD+ZVKHgNQ5v3cNStnMt25fIYCl82bYJEZrwI3Ivbk2N 7ElRFkPzgSebxb7IQfWfV+ya3P5dwU9fyVF3Zh4lZJkQPV/dGTdHki/JtW68L66079yF oBJIjmQK+jUkl94GCLReh/WbLh5UxzVyGaDbvMHd+RMk9VVcDiQSKYiTa+VVVdyKXDAl Pg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2yauqua0pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:50 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq5u5171230; Mon, 24 Feb 2020 20:56:50 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2ybdshksbm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:50 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKunv2028718; Mon, 24 Feb 2020 20:56:49 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:49 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 34/50] multi-process/mon: choose HMP commands based on target Date: Mon, 24 Feb 2020 15:55:25 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=964 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- 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 dc23185..ecc6169 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 @@ -1940,6 +1959,7 @@ ETEXI .params = "[subcommand]", .help = "show various information about the system state", .cmd = hmp_info_help, + .targets = "scsi", .sub_table = hmp_info_cmds, .flags = "p", }, diff --git a/scripts/hxtool b/scripts/hxtool old mode 100644 new mode 100755 index 0003e7b..802cbd4 --- a/scripts/hxtool +++ b/scripts/hxtool @@ -10,7 +10,14 @@ hxtoh() STEXI*|ETEXI*|SRST*|ERST*) flag=$(($flag^1)) ;; *) - test $flag -eq 1 && printf "%s\n" "$str" + # Skip line that has ".targets" as it is for multi-process targets based hmp + # commands generation. + echo $str | grep -q '.targets' + if [ $? -eq 0 ]; then + continue + else + test $flag -eq 1 && printf "%s\n" "$str" + fi ;; esac done @@ -84,16 +91,49 @@ hxtotexi() print_texi_heading "$(expr "$str" : "ARCHHEADING(\(.*\),.*)")" ;; *) - 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 Mon Feb 24 20:55:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Zn4z+O7T; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RF64713dz9sNg for ; Tue, 25 Feb 2020 08:08:28 +1100 (AEDT) Received: from localhost ([::1]:43352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kxm-0008FP-Pt for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:08:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50812) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmi-0007ch-OQ for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmg-0003nF-1G for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:00 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmf-0003kw-OR for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:56:57 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqUPP017525; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=zLulNEkGTL6hvzFyUvsPGZwgerJXllkvju3Y73iqWZY=; b=Zn4z+O7TmUCpg2da5a3b0kOvAlJQlifth2YLeqTAP3P+U92jbm0loXaFeEAEUTO0at9n lgPxnIicAh9jrIcOnPbKxGXl5w0x66UJt15v8r+KZdtO44cgTQrcwvRWpFxolVXh8yHT nWR35Kt6xfTHLuTrW20iyRMxawYBEjs6OLxsp1c9XeAULfAsEsAztBmTYyl+XuOEY2Ay d6kDFCeyLhjlHNRFA9L2G9KmWW77DhPtBDnNugN8ii95xK0B4p9ekXav/WvMusxqNWOT P0T/LSTJ/V06UpLPqRslhx3XXTENQHgdRUzEEdcv/KN0U9j6EtmGi3al2+oJT32hZ7wr gQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhyj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:52 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq5mi171139; Mon, 24 Feb 2020 20:56:52 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 2ybdshkscj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:52 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuo60009640; Mon, 24 Feb 2020 20:56:50 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:50 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 35/50] multi-process/mon: stub functions to enable QMP module for remote process Date: Mon, 24 Feb 2020 15:55:26 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- accel/stubs/tcg-stub.c | 10 +++ configure | 4 ++ include/qemu-common.h | 8 +++ stubs/gdbstub.c | 23 +++++++ stubs/migration.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/monitor.c | 31 ++++++++++ stubs/net-stub.c | 69 +++++++++++++++++++++ stubs/qapi-misc.c | 41 +++++++++++++ stubs/qapi-target.c | 55 +++++++++++++++++ stubs/ui-stub.c | 130 +++++++++++++++++++++++++++++++++++++++ stubs/vl-stub.c | 92 ++++++++++++++++++++++++++++ 11 files changed, 625 insertions(+) create mode 100644 stubs/migration.c create mode 100644 stubs/qapi-misc.c create mode 100644 stubs/qapi-target.c create mode 100644 stubs/ui-stub.c 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 ab1e344..53a2a4b 100755 --- a/configure +++ b/configure @@ -7512,6 +7512,10 @@ if test "$mpqemu" = "yes" ; then echo "CONFIG_MPQEMU=y" >> $config_host_mak fi +if test "$debug" = "yes" ; then + echo "CONFIG_DEBUG=y" >> $config_host_mak +fi + if test "$bochs" = "yes" ; then echo "CONFIG_BOCHS=y" >> $config_host_mak fi diff --git a/include/qemu-common.h b/include/qemu-common.h index 082da59..09da824 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 */ @@ -135,4 +137,10 @@ void page_size_init(void); * returned. */ bool dump_in_progress(void); +#ifdef CONFIG_DEBUG +#define qemu_debug_assert(x) assert(x) +#else +#define qemu_debug_assert(x) +#endif + #endif diff --git a/stubs/gdbstub.c b/stubs/gdbstub.c index 2b7aee5..1e65b54 100644 --- a/stubs/gdbstub.c +++ b/stubs/gdbstub.c @@ -1,6 +1,29 @@ #include "qemu/osdep.h" +#include "qemu-common.h" #include "exec/gdbstub.h" /* xml_builtin */ +#pragma weak gdbserver_start + const char *const xml_builtin[][2] = { { NULL, NULL } }; + +#ifdef CONFIG_USER_ONLY + +int gdbserver_start(int port) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +#else + +int gdbserver_start(const char *device) +{ + qemu_debug_assert(0); + + return -ENOSYS; +} + +#endif 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 a34dc87..190445c 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..5d224e4 --- /dev/null +++ b/stubs/qapi-target.c @@ -0,0 +1,55 @@ +#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" + +#if defined(TARGET_I386) +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; +} +#endif + +#if defined(TARGET_S390X) || defined(TARGET_I386) || defined(TARGET_ARM) +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} +#endif + +#if defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) || defined(TARGET_S390X) || defined(TARGET_MIPS) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) +{ + qemu_debug_assert(0); + + return NULL; +} +#endif 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 Mon Feb 24 20:55:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Fq2d18Lk; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFNV4Tklz9sPg for ; Tue, 25 Feb 2020 08:20:58 +1100 (AEDT) Received: from localhost ([::1]:43670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L9s-0004nw-EI for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:20:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50955) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmv-0008Dz-Fr for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kms-00041K-Hz for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:13 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53812) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kms-0003oz-7n for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:10 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrs80164249; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=8H10FXJhajIDjcK+6FBBgZ/mlXMF4X+tNvJ1RJ7ZXbU=; b=Fq2d18Lk8moitLrA57DApmYBF260W37oj5RwSu1PLRK4hacaX807ynMVlbc6qbAwZYmQ ZB2xDg57WohI3K8yuF4/71UhNhffcRWhMJQGCH0/MzrEn+pI3uqRA/yiTzFMkA3H3db8 fjjw/0M4rlEfnQt2P1bHDqQS1vhnGZCQ8ddMTqYhxDr9afh4q6JYeWeOf/sK5zT9NmUl KcEAntoj2/N9a5G/FNVbpsVF7OLjRdC0I3VFvwLhcxHpTHBd+iIOb1vrosBdFpiEpOnL CKjQF1KifEEuya8tD96Ai8fwUT6GQ/l+WLhwdbcAjnDMci5L1msDt4gYBDcggE12tjVd xg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p97m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:53 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKurXs073518; Mon, 24 Feb 2020 20:56:53 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2ybduv6dj5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:52 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKuqfj028737; Mon, 24 Feb 2020 20:56:52 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:52 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 36/50] multi-process/mon: enable QMP module support in the remote process Date: Mon, 24 Feb 2020 15:55:27 -0500 Message-Id: <0de0baf0df7df660c67573d4d355543d00f23f07.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- Makefile.objs | 9 +++++ Makefile.target | 35 +++++++++++++++++-- hmp-commands.hx | 5 +-- hw/core/Makefile.objs | 1 + monitor/Makefile.objs | 4 +++ monitor/misc.c | 84 +++++++++++++++++++++++++--------------------- monitor/monitor-internal.h | 38 +++++++++++++++++++++ qapi/Makefile.objs | 2 ++ qom/Makefile.objs | 1 + ui/Makefile.objs | 2 ++ 10 files changed, 139 insertions(+), 42 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 689a722..4b5db09 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -32,6 +32,7 @@ remote-pci-obj-$(CONFIG_MPQEMU) += migration/ remote-pci-obj-$(CONFIG_MPQEMU) += remote/ remote-pci-obj-$(CONFIG_MPQEMU) += accel/ remote-pci-obj-$(CONFIG_MPQEMU) += util/ +remote-pci-obj-$(CONFIG_MPQEMU) += monitor/ remote-pci-obj-$(CONFIG_MPQEMU) += cpus-common.o remote-pci-obj-$(CONFIG_MPQEMU) += dma-helpers.o @@ -44,6 +45,9 @@ remote-pci-obj-$(CONFIG_MPQEMU) += iothread.o # remote-lsi-obj-y is code used to implement remote LSI device remote-lsi-obj-$(CONFIG_MPQEMU) += hw/ +remote-lsi-obj-$(CONFIG_MPQEMU) += ui/ + +remote-lsi-obj-$(CONFIG_MPQEMU) += device-hotplug.o ####################################################################### # crypto-obj-y is code used by both qemu system emulation and qemu-img @@ -105,6 +109,11 @@ common-obj-y += qapi/ endif # CONFIG_SOFTMMU +remote-pci-obj-$(CONFIG_MPQEMU) += qapi/ +remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o +remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += balloon.o + ####################################################################### # Target-independent parts used in system and user emulation common-obj-y += cpus-common.o diff --git a/Makefile.target b/Makefile.target index 035c23b..4ead5c3 100644 --- a/Makefile.target +++ b/Makefile.target @@ -142,13 +142,32 @@ remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/hax-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += accel/stubs/whpx-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/vl-stub.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/net-stub.o -remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/replay.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/xen-mapcache.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/audio.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/monitor.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/migration.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/ui-stub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/gdbstub.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += stubs/qapi-misc.o remote-pci-tgt-obj-$(CONFIG_MPQEMU) += remote/memory.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += arch_init.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += monitor/misc.o + +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-introspect.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block-core.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-block.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-commands-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-visit-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-machine-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-types-misc-target.o +remote-pci-tgt-obj-$(CONFIG_MPQEMU) += qapi/qapi-init-commands.o endif ######################################################### @@ -203,6 +222,10 @@ endif generated-files-y += hmp-commands.h hmp-commands-info.h generated-files-y += config-devices.h +ifdef CONFIG_MPQEMU +generated-files-y += hmp-scsi-commands.h hmp-scsi-commands-info.h +endif + endif # CONFIG_SOFTMMU dummy := $(call unnest-vars,,obj-y) @@ -288,10 +311,18 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@") +ifdef CONFIG_MPQEMU +hmp-scsi-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) + +hmp-scsi-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool + $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -tgt scsi < $< > $@) +endif + clean: clean-target rm -f *.a *~ $(PROGS) rm -f $(shell find . -name '*.[od]') - rm -f hmp-commands.h gdbstub-xml.c + rm -f hmp-commands.h gdbstub-xml.c hmp-scsi-commands.h hmp-scsi-commands-info.h rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp diff --git a/hmp-commands.hx b/hmp-commands.hx index ecc6169..a1932c4 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 e3e8084..251b77b 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -49,3 +49,4 @@ remote-pci-obj-$(CONFIG_MPQEMU) += numa.o remote-pci-obj-$(CONFIG_MPQEMU) += cpu.o remote-pci-obj-$(CONFIG_MPQEMU) += vmstate-if.o remote-pci-obj-$(CONFIG_MPQEMU) += resettable.o +remote-pci-obj-$(CONFIG_MPQEMU) += machine-qmp-cmds.o diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index 9244d90..48d8017 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -2,3 +2,7 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o common-obj-y += qmp-cmds.o qmp-cmds-control.o common-obj-y += hmp-cmds.o + +remote-pci-obj-$(CONFIG_MPQEMU) += monitor.o qmp.o hmp.o +remote-pci-obj-$(CONFIG_MPQEMU) += qmp-cmds.o qmp-cmds-control.o +remote-pci-obj-$(CONFIG_MPQEMU) += hmp-cmds.o diff --git a/monitor/misc.c b/monitor/misc.c index 6c41293..f1f09bf 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -177,12 +177,12 @@ int hmp_compare_cmd(const char *name, const char *list) return 0; } -static void do_help_cmd(Monitor *mon, const QDict *qdict) +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict) { help_cmd(mon, qdict_get_try_str(qdict, "name")); } -static void hmp_trace_event(Monitor *mon, const QDict *qdict) +void hmp_trace_event(Monitor *mon, const QDict *qdict) { const char *tp_name = qdict_get_str(qdict, "name"); bool new_state = qdict_get_bool(qdict, "option"); @@ -226,7 +226,7 @@ static void hmp_trace_file(Monitor *mon, const QDict *qdict) } #endif -static void hmp_info_help(Monitor *mon, const QDict *qdict) +void hmp_info_help(Monitor *mon, const QDict *qdict) { help_cmd(mon, "info"); } @@ -314,7 +314,7 @@ int monitor_get_cpu_index(void) return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX; } -static void hmp_info_registers(Monitor *mon, const QDict *qdict) +void hmp_info_registers(Monitor *mon, const QDict *qdict) { bool all_cpus = qdict_get_try_bool(qdict, "cpustate_all", false); CPUState *cs; @@ -337,7 +337,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict) } #ifdef CONFIG_TCG -static void hmp_info_jit(Monitor *mon, const QDict *qdict) +void hmp_info_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { error_report("JIT information is only available with accel=tcg"); @@ -348,13 +348,13 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict) dump_drift_info(); } -static void hmp_info_opcount(Monitor *mon, const QDict *qdict) +void hmp_info_opcount(Monitor *mon, const QDict *qdict) { dump_opcount_info(); } #endif -static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) { int64_t max = qdict_get_try_int(qdict, "max", 10); bool mean = qdict_get_try_bool(qdict, "mean", false); @@ -365,7 +365,7 @@ static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict) qsp_report(max, sort_by, coalesce); } -static void hmp_info_history(Monitor *mon, const QDict *qdict) +void hmp_info_history(Monitor *mon, const QDict *qdict) { MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); int i; @@ -385,7 +385,7 @@ static void hmp_info_history(Monitor *mon, const QDict *qdict) } } -static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) +void hmp_info_cpustats(Monitor *mon, const QDict *qdict) { CPUState *cs = mon_get_cpu(); @@ -396,7 +396,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict *qdict) cpu_dump_statistics(cs, 0); } -static void hmp_info_trace_events(Monitor *mon, const QDict *qdict) +void hmp_info_trace_events(Monitor *mon, const QDict *qdict) { const char *name = qdict_get_try_str(qdict, "name"); bool has_vcpu = qdict_haskey(qdict, "vcpu"); @@ -456,7 +456,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname, error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", "spice"); } -static void hmp_logfile(Monitor *mon, const QDict *qdict) +void hmp_logfile(Monitor *mon, const QDict *qdict) { Error *err = NULL; @@ -466,7 +466,7 @@ static void hmp_logfile(Monitor *mon, const QDict *qdict) } } -static void hmp_log(Monitor *mon, const QDict *qdict) +void hmp_log(Monitor *mon, const QDict *qdict) { int mask; const char *items = qdict_get_str(qdict, "items"); @@ -483,7 +483,7 @@ static void hmp_log(Monitor *mon, const QDict *qdict) qemu_set_log(mask); } -static void hmp_singlestep(Monitor *mon, const QDict *qdict) +void hmp_singlestep(Monitor *mon, const QDict *qdict) { const char *option = qdict_get_try_str(qdict, "option"); if (!option || !strcmp(option, "on")) { @@ -495,7 +495,7 @@ static void hmp_singlestep(Monitor *mon, const QDict *qdict) } } -static void hmp_gdbserver(Monitor *mon, const QDict *qdict) +void hmp_gdbserver(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_try_str(qdict, "device"); if (!device) @@ -511,7 +511,7 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict) } } -static void hmp_watchdog_action(Monitor *mon, const QDict *qdict) +void hmp_watchdog_action(Monitor *mon, const QDict *qdict) { const char *action = qdict_get_str(qdict, "action"); if (select_watchdog_action(action) == -1) { @@ -653,7 +653,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, } } -static void hmp_memory_dump(Monitor *mon, const QDict *qdict) +void hmp_memory_dump(Monitor *mon, const QDict *qdict) { int count = qdict_get_int(qdict, "count"); int format = qdict_get_int(qdict, "format"); @@ -663,7 +663,7 @@ static void hmp_memory_dump(Monitor *mon, const QDict *qdict) memory_dump(mon, count, format, size, addr, 0); } -static void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) { int count = qdict_get_int(qdict, "count"); int format = qdict_get_int(qdict, "format"); @@ -693,7 +693,7 @@ static void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, Error **errp) return qemu_map_ram_ptr(mrs.mr->ram_block, mrs.offset_within_region); } -static void hmp_gpa2hva(Monitor *mon, const QDict *qdict) +void hmp_gpa2hva(Monitor *mon, const QDict *qdict) { hwaddr addr = qdict_get_int(qdict, "addr"); Error *local_err = NULL; @@ -713,7 +713,7 @@ static void hmp_gpa2hva(Monitor *mon, const QDict *qdict) memory_region_unref(mr); } -static void hmp_gva2gpa(Monitor *mon, const QDict *qdict) +void hmp_gva2gpa(Monitor *mon, const QDict *qdict) { target_ulong addr = qdict_get_int(qdict, "addr"); MemTxAttrs attrs; @@ -768,7 +768,7 @@ out: return ret; } -static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) { hwaddr addr = qdict_get_int(qdict, "addr"); Error *local_err = NULL; @@ -795,7 +795,7 @@ static void hmp_gpa2hpa(Monitor *mon, const QDict *qdict) } #endif -static void do_print(Monitor *mon, const QDict *qdict) +void hmp_do_print(Monitor *mon, const QDict *qdict) { int format = qdict_get_int(qdict, "format"); hwaddr val = qdict_get_int(qdict, "val"); @@ -821,7 +821,7 @@ static void do_print(Monitor *mon, const QDict *qdict) monitor_printf(mon, "\n"); } -static void hmp_sum(Monitor *mon, const QDict *qdict) +void hmp_sum(Monitor *mon, const QDict *qdict) { uint32_t addr; uint16_t sum; @@ -841,7 +841,7 @@ static void hmp_sum(Monitor *mon, const QDict *qdict) static int mouse_button_state; -static void hmp_mouse_move(Monitor *mon, const QDict *qdict) +void hmp_mouse_move(Monitor *mon, const QDict *qdict) { int dx, dy, dz, button; const char *dx_str = qdict_get_str(qdict, "dx_str"); @@ -865,7 +865,7 @@ static void hmp_mouse_move(Monitor *mon, const QDict *qdict) qemu_input_event_sync(); } -static void hmp_mouse_button(Monitor *mon, const QDict *qdict) +void hmp_mouse_button(Monitor *mon, const QDict *qdict) { static uint32_t bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, @@ -882,7 +882,7 @@ static void hmp_mouse_button(Monitor *mon, const QDict *qdict) mouse_button_state = button_state; } -static void hmp_ioport_read(Monitor *mon, const QDict *qdict) +void hmp_ioport_read(Monitor *mon, const QDict *qdict) { int size = qdict_get_int(qdict, "size"); int addr = qdict_get_int(qdict, "addr"); @@ -916,7 +916,7 @@ static void hmp_ioport_read(Monitor *mon, const QDict *qdict) suffix, addr, size * 2, val); } -static void hmp_ioport_write(Monitor *mon, const QDict *qdict) +void hmp_ioport_write(Monitor *mon, const QDict *qdict) { int size = qdict_get_int(qdict, "size"); int addr = qdict_get_int(qdict, "addr"); @@ -938,7 +938,7 @@ static void hmp_ioport_write(Monitor *mon, const QDict *qdict) } } -static void hmp_boot_set(Monitor *mon, const QDict *qdict) +void hmp_boot_set(Monitor *mon, const QDict *qdict) { Error *local_err = NULL; const char *bootdevice = qdict_get_str(qdict, "bootdevice"); @@ -951,7 +951,7 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict) } } -static void hmp_info_mtree(Monitor *mon, const QDict *qdict) +void hmp_info_mtree(Monitor *mon, const QDict *qdict) { bool flatview = qdict_get_try_bool(qdict, "flatview", false); bool dispatch_tree = qdict_get_try_bool(qdict, "dispatch_tree", false); @@ -964,7 +964,7 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict) int64_t dev_time; -static void hmp_info_profile(Monitor *mon, const QDict *qdict) +void hmp_info_profile(Monitor *mon, const QDict *qdict) { static int64_t last_cpu_exec_time; int64_t cpu_exec_time; @@ -981,7 +981,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict) dev_time = 0; } #else -static void hmp_info_profile(Monitor *mon, const QDict *qdict) +void hmp_info_profile(Monitor *mon, const QDict *qdict) { monitor_printf(mon, "Internal profiler not compiled\n"); } @@ -990,7 +990,7 @@ static void hmp_info_profile(Monitor *mon, const QDict *qdict) /* Capture support */ static QLIST_HEAD (capture_list_head, CaptureState) capture_head; -static void hmp_info_capture(Monitor *mon, const QDict *qdict) +void hmp_info_capture(Monitor *mon, const QDict *qdict) { int i; CaptureState *s; @@ -1001,7 +1001,7 @@ static void hmp_info_capture(Monitor *mon, const QDict *qdict) } } -static void hmp_stopcapture(Monitor *mon, const QDict *qdict) +void hmp_stopcapture(Monitor *mon, const QDict *qdict) { int i; int n = qdict_get_int(qdict, "n"); @@ -1017,7 +1017,7 @@ static void hmp_stopcapture(Monitor *mon, const QDict *qdict) } } -static void hmp_wavcapture(Monitor *mon, const QDict *qdict) +void hmp_wavcapture(Monitor *mon, const QDict *qdict) { const char *path = qdict_get_str(qdict, "path"); int freq = qdict_get_try_int(qdict, "freq", 44100); @@ -1070,7 +1070,7 @@ static void hmp_warn_acl(void) warn_acl = true; } -static void hmp_acl_show(Monitor *mon, const QDict *qdict) +void hmp_acl_show(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); QAuthZList *auth = find_auth(mon, aclname); @@ -1097,7 +1097,7 @@ static void hmp_acl_show(Monitor *mon, const QDict *qdict) } } -static void hmp_acl_reset(Monitor *mon, const QDict *qdict) +void hmp_acl_reset(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); QAuthZList *auth = find_auth(mon, aclname); @@ -1114,7 +1114,7 @@ static void hmp_acl_reset(Monitor *mon, const QDict *qdict) monitor_printf(mon, "acl: removed all rules\n"); } -static void hmp_acl_policy(Monitor *mon, const QDict *qdict) +void hmp_acl_policy(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *policy = qdict_get_str(qdict, "policy"); @@ -1155,7 +1155,7 @@ static QAuthZListFormat hmp_acl_get_format(const char *match) } } -static void hmp_acl_add(Monitor *mon, const QDict *qdict) +void hmp_acl_add(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *match = qdict_get_str(qdict, "match"); @@ -1208,7 +1208,7 @@ static void hmp_acl_add(Monitor *mon, const QDict *qdict) } } -static void hmp_acl_remove(Monitor *mon, const QDict *qdict) +void hmp_acl_remove(Monitor *mon, const QDict *qdict) { const char *aclname = qdict_get_str(qdict, "aclname"); const char *match = qdict_get_str(qdict, "match"); @@ -1678,13 +1678,21 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) /* Please update hmp-commands.hx when adding or changing commands */ static HMPCommand hmp_info_cmds[] = { +#if defined(SCSI_PROCESS) +#include "hmp-scsi-commands-info.h" +#else #include "hmp-commands-info.h" +#endif { NULL, NULL, }, }; /* hmp_cmds and hmp_info_cmds would be sorted at runtime */ HMPCommand hmp_cmds[] = { +#if defined(SCSI_PROCESS) +#include "hmp-scsi-commands.h" +#else #include "hmp-commands.h" +#endif { NULL, NULL, }, }; diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 3e6baba..26349cb 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -183,4 +183,42 @@ int hmp_compare_cmd(const char *name, const char *list); void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, Error **errp); +void hmp_do_help_cmd(Monitor *mon, const QDict *qdict); +void hmp_trace_event(Monitor *mon, const QDict *qdict); +void hmp_info_help(Monitor *mon, const QDict *qdict); +void hmp_info_registers(Monitor *mon, const QDict *qdict); +void hmp_info_jit(Monitor *mon, const QDict *qdict); +void hmp_info_opcount(Monitor *mon, const QDict *qdict); +void hmp_info_sync_profile(Monitor *mon, const QDict *qdict); +void hmp_info_history(Monitor *mon, const QDict *qdict); +void hmp_info_cpustats(Monitor *mon, const QDict *qdict); +void hmp_info_trace_events(Monitor *mon, const QDict *qdict); +void hmp_logfile(Monitor *mon, const QDict *qdict); +void hmp_log(Monitor *mon, const QDict *qdict); +void hmp_singlestep(Monitor *mon, const QDict *qdict); +void hmp_gdbserver(Monitor *mon, const QDict *qdict); +void hmp_watchdog_action(Monitor *mon, const QDict *qdict); +void hmp_memory_dump(Monitor *mon, const QDict *qdict); +void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict); +void hmp_gpa2hva(Monitor *mon, const QDict *qdict); +void hmp_gva2gpa(Monitor *mon, const QDict *qdict); +void hmp_gpa2hpa(Monitor *mon, const QDict *qdict); +void hmp_do_print(Monitor *mon, const QDict *qdict); +void hmp_sum(Monitor *mon, const QDict *qdict); +void hmp_mouse_move(Monitor *mon, const QDict *qdict); +void hmp_mouse_button(Monitor *mon, const QDict *qdict); +void hmp_ioport_read(Monitor *mon, const QDict *qdict); +void hmp_ioport_write(Monitor *mon, const QDict *qdict); +void hmp_boot_set(Monitor *mon, const QDict *qdict); +void hmp_info_mtree(Monitor *mon, const QDict *qdict); +void hmp_info_profile(Monitor *mon, const QDict *qdict); +void hmp_info_capture(Monitor *mon, const QDict *qdict); +void hmp_stopcapture(Monitor *mon, const QDict *qdict); +void hmp_wavcapture(Monitor *mon, const QDict *qdict); +void hmp_acl_show(Monitor *mon, const QDict *qdict); +void hmp_acl_reset(Monitor *mon, const QDict *qdict); +void hmp_acl_policy(Monitor *mon, const QDict *qdict); +void hmp_acl_add(Monitor *mon, const QDict *qdict); +void hmp_acl_remove(Monitor *mon, const QDict *qdict); + #endif diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 20fcc37..a8a3925 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -31,3 +31,5 @@ obj-y += qapi-events.o obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o) obj-y += qapi-commands.o obj-y += qapi-init-commands.o + +remote-pci-obj-$(CONFIG_MPQEMU) += $(QAPI_COMMON_MODULES:%=qapi-commands-%.o) 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 Mon Feb 24 20:55:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=N677A8OJ; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFCR2V8Lz9sNg for ; Tue, 25 Feb 2020 08:13:07 +1100 (AEDT) Received: from localhost ([::1]:43468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L2H-0008Fp-6C for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:13:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50953) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmv-0008DW-BK for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmt-00043O-Sr for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:13 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53860) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmt-0003rQ-K4 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:11 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrc4v164161; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=9X7Pc2ZocSKqtiQftvMeCX7+aWMcRNW3e1Cm6e3tmIg=; b=N677A8OJTjDoHTxuwUSCxHwnJ+NTM2RK+fq9Pcuxl9TNMkQgvFcJCrGsdBAX9orQewNz bKHIECPmhBC3rJ0sDttissAx5eAWlTOawW0Dg5J8Wq8AkH1IJw1fPOgp9/Dl3X7DDnqa x94QkM6dU8RcsQ3i9ZMXcCiJB86bHaCLeVeNgyHgpv6OBZqHb9k2YQOHOGfjWBrVuO+w 1Et2E1rGBVZhRaL5rxsIBphWngn4Bzo0BD+szHGzm6X/K06AsOHCDG1QodQEOkcfBYar hLh89bD2XYyAhbAdlp82AsE3pNaoECcKFOrnq7UrAYDlKf17XWNJWd3GhD0Ik7SsA4Ve 6A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p97t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:56 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKueuf073151; Mon, 24 Feb 2020 20:56:56 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:55 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKurRA030067; Mon, 24 Feb 2020 20:56:54 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:53 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 37/50] multi-process/mon: Refactor monitor/chardev functions out of vl.c Date: Mon, 24 Feb 2020 15:55:28 -0500 Message-Id: <67a859b87b37fa5ecab72d561e327e80941fc705.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 Reviewed-by: Dr. David Alan Gilbert --- chardev/char.c | 14 ++++++++++++++ include/chardev/char.h | 1 + include/monitor/monitor.h | 2 ++ monitor/monitor.c | 40 ++++++++++++++++++++++++++++++++++++++- remote/remote-main.c | 1 + remote/remote-opts.c | 1 + softmmu/vl.c | 48 ----------------------------------------------- 7 files changed, 58 insertions(+), 49 deletions(-) diff --git a/chardev/char.c b/chardev/char.c index 8723756..1d03ea0 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -1189,4 +1189,18 @@ static void register_types(void) qemu_add_machine_init_done_notifier(&chardev_machine_done_notify); } +int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + Error *local_err = NULL; + + if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + exit(0); + } + return 0; +} + type_init(register_types); diff --git a/include/chardev/char.h b/include/chardev/char.h index 00589a6..e370320 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 b7bdd2b..d92bf1c 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -45,5 +45,7 @@ int monitor_fdset_get_fd(int64_t fdset_id, int flags); int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd); void monitor_fdset_dup_fd_remove(int dup_fd); int64_t monitor_fdset_dup_fd_find(int dup_fd); +void monitor_parse(const char *optarg, const char *mode, bool pretty); +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp); #endif /* MONITOR_H */ diff --git a/monitor/monitor.c b/monitor/monitor.c index c1a6c44..5759b84 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,41 @@ void monitor_init_globals_core(void) NULL); } +int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) +{ + return monitor_init_opts(opts, errp); +} + +void monitor_parse(const char *optarg, const char *mode, bool pretty) +{ + static int monitor_device_index; + QemuOpts *opts; + const char *p; + char label[32]; + + if (strstart(optarg, "chardev:", &p)) { + snprintf(label, sizeof(label), "%s", p); + } else { + snprintf(label, sizeof(label), "compat_monitor%d", + monitor_device_index); + opts = qemu_chr_parse_compat(label, optarg, true); + if (!opts) { + error_report("parse error: %s", optarg); + exit(1); + } + } + + opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); + qemu_opt_set(opts, "mode", mode, &error_abort); + qemu_opt_set(opts, "chardev", label, &error_abort); + if (!strcmp(mode, "control")) { + qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); + } else { + assert(pretty == false); + } + monitor_device_index++; +} + int monitor_init_opts(QemuOpts *opts, Error **errp) { Chardev *chr; diff --git a/remote/remote-main.c b/remote/remote-main.c index 5284ee9..23fc0df 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -54,6 +54,7 @@ #include "qemu/cutils.h" #include "remote-opts.h" #include "monitor/monitor.h" +#include "chardev/char.h" #include "sysemu/reset.h" static MPQemuLinkState *mpqemu_link; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index 7e12700..565e641 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -39,6 +39,7 @@ #include "block/block.h" #include "remote/remote-opts.h" #include "include/qemu-common.h" +#include "monitor/monitor.h" #include "vl.h" /* diff --git a/softmmu/vl.c b/softmmu/vl.c index a8a6f35..4a4f52c 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2133,19 +2133,6 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } -static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - Error *local_err = NULL; - - if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) { - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - exit(0); - } - return 0; -} #ifdef CONFIG_VIRTFS static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) @@ -2154,41 +2141,6 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) } #endif -static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) -{ - return monitor_init_opts(opts, errp); -} - -static void monitor_parse(const char *optarg, const char *mode, bool pretty) -{ - static int monitor_device_index = 0; - QemuOpts *opts; - const char *p; - char label[32]; - - if (strstart(optarg, "chardev:", &p)) { - snprintf(label, sizeof(label), "%s", p); - } else { - snprintf(label, sizeof(label), "compat_monitor%d", - monitor_device_index); - opts = qemu_chr_parse_compat(label, optarg, true); - if (!opts) { - error_report("parse error: %s", optarg); - exit(1); - } - } - - opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal); - qemu_opt_set(opts, "mode", mode, &error_abort); - qemu_opt_set(opts, "chardev", label, &error_abort); - if (!strcmp(mode, "control")) { - qemu_opt_set_bool(opts, "pretty", pretty, &error_abort); - } else { - assert(pretty == false); - } - monitor_device_index++; -} - struct device_config { enum { DEV_USB, /* -usbdevice */ From patchwork Mon Feb 24 20:55:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=kvIchio4; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFT53wnjz9sNg for ; Tue, 25 Feb 2020 08:24:57 +1100 (AEDT) Received: from localhost ([::1]:43812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LDj-0004EQ-Ax for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:24:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50885) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmn-0007pM-BF for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmm-0003wQ-2k for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:05 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kml-0003vM-Ps for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:04 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrQVM032081; Mon, 24 Feb 2020 20:56: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-2020-01-29; bh=kNFIpLb5KqA13nmBN7fGm+89ZBH0qWuchoDbUdd84xU=; b=kvIchio4+AHvgs6csXqgac69kxcaowpGanOObtQ5ZKE86G/qqUkw2c6I/pkTD5f2pxKR UHYSc9Mf1TN++KV24uSvG12lv1oKLZ2VtEYHiUHeIwniQkizQAXlNWwDPdThLQ2+aU07 LX/qB9YO2r5sOYLJtRdJoUOJCGiL6QL+FezxfysQwmJYvC6/CjeJQnxyPp7drwxNbgdu hEN7OaiqFQo+bX9Nj+EB1qM+H4tcNJ+BtZZg+vNF264my3ovsisA9onjrpB8jk1N5at8 n8LT+eK846BfHrJuzAppk67PKqoLv5QN4Q7m272SIaq4nH/VHnsOU37sezgsEVyk0bYl bA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2yauqua0q5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKufLC073328; Mon, 24 Feb 2020 20:56:57 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dnr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:57 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKutDM030075; Mon, 24 Feb 2020 20:56:55 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:55 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 38/50] multi-process/mon: Initialize QMP module for remote processes Date: Mon, 24 Feb 2020 15:55:29 -0500 Message-Id: <5dde2ceee2e0867302b411857baaa3b6d99668e6.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- 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 23fc0df..58d9905 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -56,6 +56,7 @@ #include "monitor/monitor.h" #include "chardev/char.h" #include "sysemu/reset.h" +#include "vl.h" static MPQemuLinkState *mpqemu_link; @@ -436,6 +437,8 @@ int main(int argc, char *argv[]) module_call_init(MODULE_INIT_QOM); + monitor_init_globals(); + bdrv_init_with_whitelist(); if (qemu_init_main_loop(&err)) { @@ -453,6 +456,8 @@ int main(int argc, char *argv[]) qemu_add_opts(&qemu_device_opts); qemu_add_opts(&qemu_drive_opts); + qemu_add_opts(&qemu_chardev_opts); + qemu_add_opts(&qemu_mon_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); qemu_add_drive_opts(&qemu_common_drive_opts); qemu_add_drive_opts(&qemu_drive_opts); @@ -483,6 +488,12 @@ int main(int argc, char *argv[]) mpqemu_link_set_callback(mpqemu_link, process_msg); + qemu_opts_foreach(qemu_find_opts("chardev"), + chardev_init_func, NULL, &error_fatal); + + qemu_opts_foreach(qemu_find_opts("mon"), + mon_init_func, NULL, &error_fatal); + mpqemu_start_coms(mpqemu_link); return 0; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index 565e641..e22ad5c 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -82,6 +82,16 @@ void parse_cmdline(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_qmp: + monitor_parse(optarg, "control", false); + break; + case QEMU_OPTION_monitor: + if (!strncmp(optarg, "stdio", 5)) { + warn_report("STDIO not supported in remote process"); + } else if (strncmp(optarg, "none", 4)) { + monitor_parse(optarg, "readline", false); + } + break; default: break; } From patchwork Mon Feb 24 20:55:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=FzqvCtzW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFQc4GJqz9sQt for ; Tue, 25 Feb 2020 08:22:48 +1100 (AEDT) Received: from localhost ([::1]:43754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LBe-0000FE-B2 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:22:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50985) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmy-0008LT-Bd for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmx-00046k-4a for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:16 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:53952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmw-0003wV-So for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:15 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKra5g164127; Mon, 24 Feb 2020 20:57:00 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-2020-01-29; bh=myWcMfhqdAjSR8DPI97VT7FmO1ksEv3G863ka95yyYA=; b=FzqvCtzWqarBraJ7cSrwP8UoNkyL2seuFi6pe/9ufXzd6v1jQJygyK5w/dzahaS3oK3y nAW0yJObdw3y51DwrLMNycbrVNdMSAoMs1yu8auOnv1QSigW417qSllHJamTClwPorhB Gr7zLb4pNVKKgl1QsxRVDRdlW37h3Gali6tL5oI5ZsUZRj3CZPjHqwDZHtHrEyf+AYGd HUaPkBpkozVaqZO7Mxof+A6fTsXNjpr4l6q+cg6lZjch6Cxwyq9sDcdfHY8LMJ+SiUQ+ TCOzhXKAd/Jcs5mrKdytpbXKw/r4R18HaKRGT1Ejd00vyuDef+SWTmydrcI5Roz6rhkD rg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2ybvr4p989-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqKQl171766; Mon, 24 Feb 2020 20:56:59 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2ybdshksj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:56:58 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuvc5030086; Mon, 24 Feb 2020 20:56:57 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:56 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 39/50] multi-process: prevent duplicate memory initialization in remote Date: Mon, 24 Feb 2020 15:55:30 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- 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 741f02a..b1b9282 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -453,6 +453,13 @@ static void proxy_device_reset(DeviceState *dev) close(wait); } +static void pci_proxy_dev_inst_init(Object *obj) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(obj); + + dev->mem_init = false; +} + static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); @@ -470,6 +477,7 @@ static const TypeInfo pci_proxy_dev_type_info = { .name = TYPE_PCI_PROXY_DEV, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIProxyDev), + .instance_init = pci_proxy_dev_inst_init, .class_size = sizeof(PCIProxyDevClass), .class_init = pci_proxy_dev_class_init, .interfaces = (InterfaceInfo[]) { @@ -566,7 +574,10 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, mpqemu_init_channel(pdev->mpqemu_link, &pdev->mpqemu_link->mmio, pdev->mmio_sock); - configure_memory_sync(pdev->sync, pdev->mpqemu_link); + if (!pdev->mem_init) { + pdev->mem_init = true; + configure_memory_sync(pdev->sync, pdev->mpqemu_link); + } } static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) diff --git a/include/hw/proxy/qemu-proxy.h b/include/hw/proxy/qemu-proxy.h index 2a2c732..5de8129 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -49,6 +49,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 27b2ddc..f120509 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -732,9 +732,9 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, pdev->socket = old_pdev->socket; pdev->mmio_sock = old_pdev->mmio_sock; pdev->remote_pid = old_pdev->remote_pid; + pdev->mem_init = true; } else { pdev->socket = managed ? socket : -1; - } pdev->managed = managed; From patchwork Mon Feb 24 20:55:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243542 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=0V2S+LAn; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFWG5Xypz9sNg for ; Tue, 25 Feb 2020 08:26:50 +1100 (AEDT) Received: from localhost ([::1]:43850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LFX-0007JQ-U1 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:26:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51030) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn1-0008UN-K2 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmz-00048q-J4 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:19 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:54000) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmz-0003y0-Ak for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:17 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraUi164125; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=exSdLszfLnd9sxniF987sr8s2/2hVw2ZjwI3nI6ER98=; b=0V2S+LAnVJwDPhljo4U0v7K5Y7l/RYHS6T3XzaOVxiSOHGfulWgh7hxvlXX9Buihc2HW op2pYqCVcEJ8Xq0G8mqkr1+72U8ttvkFv/cZJpEpjQhfIsUKlOgp0i9Njyan7bJ25RbF YRIBRBwwiuwwYRu5gYrCGpokO6kLVL1zJyhQhEIn3bBDfkMZMqXL1LHX7mtuY/kqBUJd KZiKGTe/xLk03tVa1bMXhUHTYnv/VP87mCKo3+NbuOaIgLl2mNXyKqhJm9Yv1JreW4Ly 6QBR5hI3bx64HYOLYz7lC6W9U8XbAKVXQfgH6DBoCTxa8tkVxUdZGnPGyaXvaXCWVZDB JA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p98s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:01 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKudIX073056; Mon, 24 Feb 2020 20:57:00 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dtp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:00 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKuwdR030091; Mon, 24 Feb 2020 20:56:58 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:58 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 40/50] multi-process/mig: build migration module in the remote process Date: Mon, 24 Feb 2020 15:55:31 -0500 Message-Id: <96a495711764282ff90504cec6734eff563ceb4d.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- Makefile.objs | 4 +++- Makefile.target | 1 + migration/Makefile.objs | 13 ++++++++++++- net/Makefile.objs | 2 ++ softmmu/vl.c | 2 -- stubs/migration.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ stubs/net-stub.c | 21 +++++++++++++++++++++ stubs/qapi-misc.c | 2 ++ stubs/replay.c | 8 ++++++++ stubs/vl-stub.c | 24 ++++++++++++++++++++++++ vl-parse.c | 3 +++ 11 files changed, 125 insertions(+), 4 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 4b5db09..65009da 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -74,6 +74,8 @@ common-obj-y += qdev-monitor.o device-hotplug.o common-obj-$(CONFIG_WIN32) += os-win32.o common-obj-$(CONFIG_POSIX) += os-posix.o +remote-pci-obj-$(CONFIG_POSIX) += os-posix.o + common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += accel/ @@ -104,11 +106,11 @@ common-obj-y += vl-parse.o ####################################################################### # qapi - common-obj-y += qapi/ endif # CONFIG_SOFTMMU +remote-pci-obj-$(CONFIG_MPQEMU) += net/ remote-pci-obj-$(CONFIG_MPQEMU) += qapi/ remote-pci-obj-$(CONFIG_MPQEMU) += blockdev-nbd.o remote-pci-obj-$(CONFIG_MPQEMU) += job-qmp.o diff --git a/Makefile.target b/Makefile.target index 4ead5c3..4012ae5 100644 --- a/Makefile.target +++ b/Makefile.target @@ -240,6 +240,7 @@ all-remote-pci-obj-y += exec.o all-remote-pci-obj-y += exec-vary.o all-remote-pci-obj-y += ioport.o all-remote-pci-obj-y += cpus.o +all-remote-pci-obj-y += migration/ram.o endif remote-pci-obj-y := diff --git a/migration/Makefile.objs b/migration/Makefile.objs index e7cdc76..21f9d8d 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -15,4 +15,15 @@ common-obj-$(CONFIG_LIVE_BLOCK_MIGRATION) += block.o rdma.o-libs := $(RDMA_LIBS) -remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o vmstate.o qjson.o vmstate-types.o +remote-pci-obj-$(CONFIG_MPQEMU) += migration.o socket.o fd.o exec.o +remote-pci-obj-$(CONFIG_MPQEMU) += tls.o channel.o savevm.o +remote-pci-obj-$(CONFIG_MPQEMU) += colo.o colo-failover.o +remote-pci-obj-$(CONFIG_MPQEMU) += vmstate.o vmstate-types.o page_cache.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file.o global_state.o +remote-pci-obj-$(CONFIG_MPQEMU) += qemu-file-channel.o +remote-pci-obj-$(CONFIG_MPQEMU) += xbzrle.o postcopy-ram.o +remote-pci-obj-$(CONFIG_MPQEMU) += qjson.o +remote-pci-obj-$(CONFIG_MPQEMU) += block-dirty-bitmap.o +remote-pci-obj-$(CONFIG_RDMA) += rdma.o +remote-pci-obj-$(CONFIG_MPQEMU) += block.o +remote-pci-obj-$(CONFIG_MPQEMU) += multifd.o 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/softmmu/vl.c b/softmmu/vl.c index 4a4f52c..42d5682 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -128,7 +128,6 @@ const char* keyboard_layout = NULL; ram_addr_t ram_size; const char *mem_path = NULL; int mem_prealloc = 0; /* force preallocation of physical target memory */ -bool enable_mlock = false; bool enable_cpu_pm = false; int nb_nics; NICInfo nd_table[MAX_NICS]; @@ -168,7 +167,6 @@ const char *prom_envs[MAX_PROM_ENVS]; int boot_menu; bool boot_strict; uint8_t *boot_splash_filedata; -int only_migratable; /* turn it off unless user states otherwise */ bool wakeup_suspend_enabled; int icount_align_option; 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 9b53c0c..6fc7850 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; @@ -106,3 +107,10 @@ void replay_account_executed_instructions(void) void replay_add_blocker(Error *reason) { } + +bool replay_can_snapshot(void) +{ + qemu_debug_assert(0); + + return false; +} diff --git a/stubs/vl-stub.c b/stubs/vl-stub.c index 606f078..5f308c1 100644 --- a/stubs/vl-stub.c +++ b/stubs/vl-stub.c @@ -14,6 +14,8 @@ #include "disas/disas.h" #include "audio/audio.h" +#pragma weak qemu_add_exit_notifier + bool tcg_allowed; bool xen_allowed; bool boot_strict; @@ -169,3 +171,25 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path, return -1; } + +void qemu_system_killed(int signal, pid_t pid) +{ + qemu_debug_assert(0); +} + +void qemu_system_reset(ShutdownCause reason) +{ + qemu_debug_assert(0); +} + +bool runstate_store(char *str, size_t size) +{ + qemu_debug_assert(0); + + return false; +} + +void qemu_add_exit_notifier(Notifier *notify) +{ + qemu_debug_assert(0); +} diff --git a/vl-parse.c b/vl-parse.c index 1f6a3f0..423f4a0 100644 --- a/vl-parse.c +++ b/vl-parse.c @@ -27,6 +27,9 @@ #include "vl.h" +int only_migratable; /* turn it off unless user states otherwise */ +bool enable_mlock; + /***********************************************************/ /* QEMU Block devices */ From patchwork Mon Feb 24 20:55:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=C8/eDHw+; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFJ14LDlz9sNg for ; Tue, 25 Feb 2020 08:17:05 +1100 (AEDT) Received: from localhost ([::1]:43586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L66-000745-1l for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:17:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51034) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn1-0008Up-PW for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn0-00049S-9n for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:19 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:54012) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kn0-0003yH-0d for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:18 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrk6m164205; Mon, 24 Feb 2020 20:57:02 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-2020-01-29; bh=qDYoW1AXMZqQa0NU/wGw7heCo/JWH/fuX33lk6JC2lc=; b=C8/eDHw+7CzGJb79ZLNS3sjiwMnvrzC1/QzeCcG3qQtrXU3FbLhcaTU8vsqdPOM16aqy va6nOEUXnShHL7bqYmwTXEtoZoLkDlcwyLfv4btZjR31Rh4I+MSAtpY4ZxnNEVHxvx5L b1zBQeUispft940of32oAUr5lBSL7cCoHPJDNuYgpw82XArgJcJNNUBG3H5pQTvBjHiI Hi8jSw1mDXUrEjMoc7l31WziLIxeLz3ZUu0O3Lu8bxHXLJBmxMDd4IacoRLIjvtAIwia s7Ez8gBm7HzeL78nL48fN2KrG+hYu3z+/uQCLEJ+ND2fMvBajViu3Iq1rwzhwY1OacL4 wg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2ybvr4p98x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:02 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKucmE072901; Mon, 24 Feb 2020 20:57:02 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2ybduv6dv4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:02 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKv0Uf030099; Mon, 24 Feb 2020 20:57:00 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:56:59 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 41/50] multi-process/mig: Enable VMSD save in the Proxy object Date: Mon, 24 Feb 2020 15:55:32 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- v4 -> v5: - Using qemu_file_shutdown() instead of qemu_thread_cancel(). Removed patch which introduced qemu_thread_cancel() hw/proxy/qemu-proxy.c | 135 ++++++++++++++++++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 + include/io/mpqemu-link.h | 1 + 3 files changed, 138 insertions(+) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index b1b9282..19f0dbb 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -23,6 +23,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); @@ -35,6 +43,9 @@ static void broadcast_init(void); static int config_op_send(PCIProxyDev *dev, uint32_t addr, uint32_t *val, int l, unsigned int op); +#define PAGE_SIZE qemu_real_host_page_size +uint8_t *mig_data; + static void childsig_handler(int sig, siginfo_t *siginfo, void *ctx) { /* TODO: Add proper handler. */ @@ -460,6 +471,129 @@ 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); + + if (qemu_file_get_error(data->rem)) { + break; + } + + 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(&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_file_shutdown(f_remote); + + 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); @@ -471,6 +605,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) k->config_write = pci_proxy_write_config; dc->reset = proxy_device_reset; + 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 5de8129..537c227 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -75,6 +75,8 @@ struct PCIProxyDev { 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 d2234ca..b42c003 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -63,6 +63,7 @@ typedef enum { PROXY_PING, MMIO_RETURN, DEVICE_RESET, + START_MIG_OUT, MAX, } mpqemu_cmd_t; From patchwork Mon Feb 24 20:55:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=gNfQKp5s; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFKq6sdxz9sNg for ; Tue, 25 Feb 2020 08:18:39 +1100 (AEDT) Received: from localhost ([::1]:43614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L7d-0001Dz-RF for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:18:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50927) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmt-00089D-LY for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kms-00040R-BI for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:11 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kms-0003zI-2F for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:10 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrMsA032061; Mon, 24 Feb 2020 20:57:04 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-2020-01-29; bh=lmaqRAdO5l0CBs7Nbf1bisuy3QrUQnsM4khCkN3guhY=; b=gNfQKp5s98ZytpVHET8y9aNqcVQzoa9W5LYMXkXJENkXtbdtvgxoYI66XAaV2tjJTYRs vbmWCRtZ38AltjuLIFCoAS4/Pa3o7mKu3nqgKP+2u/NhFL5zJo66YxNGa5d+edkmnFkb lKx30IMKfeyqdOW+rHwbXW2e0qCwVSNzYBDJlAgPQLLCNG+bBd4bSPbKpMotN+9tSmt3 OERbVmEJf+0vmW59sUnQ7aL0/My6hRrjwtEKn9JGh7kdhatpfTeaWEtvIjAnHXiNYOJn eKbyFidvCIupo7nqsAHGuyVEardrNMJMyt37m7mAk79qtHkJoUmS8m0ESFFFeYf/DOwE 3g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2yauqua0r5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:04 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKueug073151; Mon, 24 Feb 2020 20:57:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2ybduv6dwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:03 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKv1Cu028884; Mon, 24 Feb 2020 20:57:01 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:01 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 42/50] multi-process/mig: Send VMSD of remote to the Proxy object Date: Mon, 24 Feb 2020 15:55:33 -0500 Message-Id: <74d6f7b67720a31a53c25164f8d9769c32d8c643.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- 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 1d4220e..09af14d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2942,3 +2942,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 ba64a7e..0491d3a 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -65,4 +65,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 58d9905..e97eb76 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -53,6 +53,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" @@ -322,6 +332,36 @@ static int setup_device(MPQemuMsg *msg, Error **errp) } +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; @@ -411,6 +451,9 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) notify_proxy(msg->fds[0], 0); } break; + case START_MIG_OUT: + process_start_mig_out(msg); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; From patchwork Mon Feb 24 20:55:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Vv9oZXb0; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFGm4ChTz9sNg for ; Tue, 25 Feb 2020 08:16:00 +1100 (AEDT) Received: from localhost ([::1]:43570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L54-00063G-Fg for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:15:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50925) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmt-00088z-Ij for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kms-00040k-Ct for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:11 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42542) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kms-0003za-42 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:10 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqcnW017744; Mon, 24 Feb 2020 20:57:05 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-2020-01-29; bh=0B1eKZbJOs4Nl5F0dscdR1L40vi/ljBXpJqgDQFRAwQ=; b=Vv9oZXb0GeHp71ZaCdHjE6yoEf/BrRA61FgRrSgIjma0ZiByv5kP6xgsh7R9icq7AMNf NZnTQ+DceZTYhkAXON3MVFjUVCyX1NU894ExlvgmIKqMyXvO6K4zMMaDoe6wbgWhYMUE /u4xAYq3wYDyiSAjSla0rSxMdI2HJSb71dMtFUIlnv9RGKFeYmzD63TPxzoFyV7v8Ykp auwd8lRT52wjRInBdGy77m1m2aLckkINOSqo1/4IqDLGFrh+hZBfC8MmngAh2+6dvHLA aU3HzKZDZqPDYlcifkEbMxS5nRgT9YC94CDrbXIhOq/lyTmCW2giA2HCwyr5bVtgc3dc cA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 2yavxrhyky-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:04 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKucBb072957; Mon, 24 Feb 2020 20:57:04 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 2ybduv6dxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:04 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKv3h1028883; Mon, 24 Feb 2020 20:57:03 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:03 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 43/50] multi-process/mig: Load VMSD in the proxy object Date: Mon, 24 Feb 2020 15:55:34 -0500 Message-Id: <728f5cdb2108ccfd0916c1efcc8c7dab99daf6ad.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240154 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- 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 19f0dbb..1649f60 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -581,12 +581,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(&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 b42c003..01371fc 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -64,6 +64,7 @@ typedef enum { MMIO_RETURN, DEVICE_RESET, START_MIG_OUT, + START_MIG_IN, MAX, } mpqemu_cmd_t; From patchwork Mon Feb 24 20:55:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=wPejLVWQ; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFYP0p5Vz9sPg for ; Tue, 25 Feb 2020 08:28:41 +1100 (AEDT) Received: from localhost ([::1]:43916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LHL-0002W4-0b for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:28:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51080) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn5-0000DG-KE for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn4-0004CN-8x for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:23 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:54132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kn3-00042p-W6 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:22 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKraG9164141; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=r33JqoYyvd7qRET/DSaqmHS6AvTJ0RmaWoQwJRwosSY=; b=wPejLVWQJV0EispF7OgFGpqA8zm6wRQeDTIdM/mf7smtF3048/87zIK1fG2upe+p0fK6 h7JguyfHvUAXKYbO7rL/G5hndPqKXLWHXdeHVltCb+jRkkiXtNn23lIft3s8qm4+kDcI /sXFFzu0vB2pFnwLoFnql0TfgxdV80El5kOaWcUL4On2odH5opytvEc2tEXouwlfHym0 Udtfn3+FDYJvgPUDkgAhukf5QqiQQnS74dFKJ4MZsQJbdHGuSHDW2e0gh8/clMN3x0LJ Zg5mWbwWQuqy2dmCuMEAdC+tuowE9fhF5eHLPFv3ihsqFhnWmVYMnTz2FsJXe6Nefl7m VQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2ybvr4p99a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:07 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqoFK172448; Mon, 24 Feb 2020 20:57:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2ybdshkss5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:06 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKv42U028905; Mon, 24 Feb 2020 20:57:05 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:04 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 44/50] multi-process/mig: refactor runstate_check into common file Date: Mon, 24 Feb 2020 15:55:35 -0500 Message-Id: <99597f15a6e42c34b5a2e7f88430ed56c89feb76.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- Makefile.objs | 2 ++ include/sysemu/runstate.h | 2 ++ runstate.c | 36 ++++++++++++++++++++++++++++++++++++ softmmu/vl.c | 10 ---------- stubs/runstate-check.c | 3 +++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 runstate.c diff --git a/Makefile.objs b/Makefile.objs index 65009da..cf2200d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -40,6 +40,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 @@ -103,6 +104,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 ####################################################################### # qapi diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h index f760094..ece939f 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/softmmu/vl.c b/softmmu/vl.c index 42d5682..d95ee2f 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -620,11 +620,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; @@ -732,11 +727,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); 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; From patchwork Mon Feb 24 20:55:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243533 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=DLVOPyR9; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFQZ373sz9sQt for ; Tue, 25 Feb 2020 08:22:45 +1100 (AEDT) Received: from localhost ([::1]:43740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LBb-00005m-Ql for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:22:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50973) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmx-0008Io-AX for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmv-00044r-K7 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:15 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42630) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmv-00043u-Bn for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:13 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqUdo017508; Mon, 24 Feb 2020 20:57:08 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-2020-01-29; bh=rETKtHDkshwrTeRqU0486Rf1Kao7HcbWs/Qtqu1xgj4=; b=DLVOPyR9oZ0zN6yz0+5q/UIQzZI7COWpFQ+o+jAWj44DCLmnN+No/7XiDqfHQvb80pc9 zzgfVUA8EbLyGZUl2pQM49LSWEBWmtVex1T8z0hWWw4XFcAsiMAVeh7k2Cd821GhtFdb TpTfdaclGH8cxiC9xc0LcK52URdYZe8KjCUoRldNrXsw8lX0Md0m5Z7cBn/RFu41p4Jc jKkN9kVIMHnXuhY09/LQES3vW+oT5SGqfVcyRX0SdB6zlKY2v6xfl/sK28JgHslWYK6C vJCYK8nwlOSPDeo4L9+NuUORmiF1da20EdRufs6nB3JbuHvS8WXB5PFOD0chGOdRWiFI Hw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhymg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:08 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq8GI171412; Mon, 24 Feb 2020 20:57:08 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2ybdshkst4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:07 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKv6jU030206; Mon, 24 Feb 2020 20:57:06 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:06 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 45/50] multi-process/mig: Synchronize runstate of remote process Date: Mon, 24 Feb 2020 15:55:36 -0500 Message-Id: <6d523c1692a465383fa5e1e380d67d8eea73ae0e.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- hw/proxy/qemu-proxy.c | 26 ++++++++++++++++++++++++++ include/hw/proxy/qemu-proxy.h | 2 ++ include/io/mpqemu-link.h | 8 ++++++++ include/sysemu/runstate.h | 1 + qdev-monitor.c | 11 ++++++++++- remote/remote-main.c | 5 +++++ remote/remote-opts.c | 5 +++++ runstate.c | 5 +++++ 8 files changed, 62 insertions(+), 1 deletion(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 1649f60..5876957 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -15,6 +15,7 @@ #include "hw/pci/pci.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qstring.h" +#include "sysemu/runstate.h" #include "hw/proxy/qemu-proxy.h" #include "hw/proxy/memory-sync.h" #include "qom/object.h" @@ -765,6 +766,27 @@ static void init_proxy(PCIDevice *dev, char *command, char *exec_name, } } +static void proxy_vm_state_change(void *opaque, int running, RunState state) +{ + PCIProxyDev *dev = opaque; + MPQemuMsg msg = { 0 }; + int wait = -1; + + msg.cmd = RUNSTATE_SET; + msg.bytestream = 0; + msg.size = sizeof(msg.data1); + msg.data1.runstate.state = state; + + wait = eventfd(0, EFD_CLOEXEC); + msg.num_fds = 1; + msg.fds[0] = wait; + + mpqemu_msg_send(&msg, dev->mpqemu_link->com); + + wait_for_remote(wait); + close(wait); +} + static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { PCIProxyDev *dev = PCI_PROXY_DEV(device); @@ -782,6 +804,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) } } + 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; @@ -807,6 +831,8 @@ static void pci_dev_exit(PCIDevice *pdev) if (!QLIST_EMPTY(&proxy_dev_list.devices)) { start_broadcast_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 537c227..6784298 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -76,6 +76,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 01371fc..beb8293 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -20,6 +20,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) @@ -65,6 +67,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; @@ -126,6 +133,7 @@ typedef struct { set_irqfd_msg_t set_irqfd; ret_pci_info_msg_t ret_pci_info; 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 ece939f..8c5810f 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 f120509..8efa1a8 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -35,6 +35,7 @@ #include "qemu/option_int.h" #include "sysemu/block-backend.h" #include "sysemu/sysemu.h" +#include "sysemu/runstate.h" #include "migration/misc.h" #include "migration/migration.h" #include "qemu/cutils.h" @@ -674,6 +675,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 = NULL; if (strlen(rid) > MAX_RID_LENGTH) { error_setg(errp, "rid %s is too long.", rid); @@ -743,11 +745,18 @@ DeviceState *qdev_proxy_add(const char *rid, const char *id, char *bus, need_spawn = true; } - pdev->init_proxy(PCI_DEVICE(ds), cmd, exec_name, need_spawn, errp); + 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, exec_name, need_spawn, errp); QLIST_INSERT_HEAD(&proxy_dev_list.devices, pdev, next); qemu_opts_del(proxy_opts); + return ds; } diff --git a/remote/remote-main.c b/remote/remote-main.c index e97eb76..0260c7c 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -31,6 +31,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/ramlist.h" #include "exec/memattrs.h" @@ -454,6 +455,10 @@ 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); + notify_proxy(msg->fds[0], 0); + break; default: error_setg(&err, "Unknown command"); goto finalize_loop; diff --git a/remote/remote-opts.c b/remote/remote-opts.c index e22ad5c..839baf1 100644 --- a/remote/remote-opts.c +++ b/remote/remote-opts.c @@ -40,8 +40,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. @@ -85,6 +87,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 Mon Feb 24 20:55:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=snUzxX27; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFFJ1Fr8z9sQt for ; Tue, 25 Feb 2020 08:14:43 +1100 (AEDT) Received: from localhost ([::1]:43514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6L3o-0003Sm-Kl for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:14:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51003) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kmz-0008Pu-P1 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kmy-00047u-Iv for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:17 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45340) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmy-000478-9s for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:16 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrgSd032171; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=0bgtJYi5Q+wqi1vj3BeRoc/5jB6JYG14IQlZmOpXzdM=; b=snUzxX27V0itBBRYmJGEsjo/W75fvVRQyfI1qtQ14w4b90fxai6sN61xLwz0xL+GlzEy F8mNZdFwXtsITViHsVzKKb+W2W9LALHdG2T0YQUwq5cHM/0szTv32hVZklCtl4ocOEfh mW6xR7+S3Yb7z6N3UjnFbG5F+q4QmG+fuTvdEmvyVdM57vP5Y4//eHqW8Qks8tv9EPUl Huro0jo6beW14yvyoO9MDXutRg6hK2ZRw3fKGHr5y3YRsXVyH3/EWqKrqeNC+0Gn5xxK H7Aam4K8QDyfnoTWl5PBb1Zq4omp2bYJURFFtlSJqxDviwVhQsx7arspjvYOHWHNycyf ng== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2yauqua0rq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:10 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq5fO171086; Mon, 24 Feb 2020 20:57:10 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2ybdshksuk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:09 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKv8VW030212; Mon, 24 Feb 2020 20:57:08 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:07 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 46/50] multi-process/mig: Restore the VMSD in remote process Date: Mon, 24 Feb 2020 15:55:37 -0500 Message-Id: <68144e5a0cdc4a16c1fe63f4a7482191f86b7c0f.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- migration/savevm.c | 36 ++++++++++++++++++++++++++++++++++++ migration/savevm.h | 1 + remote/remote-main.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 09af14d..e95ea4a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2969,3 +2969,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 0491d3a..8741c66 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -66,5 +66,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 0260c7c..ab4ad0b 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -68,6 +68,7 @@ #include "chardev/char.h" #include "sysemu/reset.h" #include "vl.h" +#include "migration/misc.h" static MPQemuLinkState *mpqemu_link; @@ -363,6 +364,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; @@ -455,6 +480,12 @@ 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); notify_proxy(msg->fds[0], 0); @@ -532,6 +563,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 Mon Feb 24 20:55:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243543 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=Cg0yzKu6; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFWJ0BkGz9sPg for ; Tue, 25 Feb 2020 08:26:52 +1100 (AEDT) Received: from localhost ([::1]:43858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LFZ-0007TP-RR for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:26:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51128) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6KnC-0000KP-99 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn9-0004Fc-Qd for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:30 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:54250) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kn9-00047p-80 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:27 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrwcL164272; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=+1jeGUAaUlIqzn5k0+XSLH8Faol3m+U3usz3h4qw4NQ=; b=Cg0yzKu6onqOwRbX6sj4cz2eIZrIqDNqdfIegCuN22l0pIynxeFyI4zZNMMCfrfteQvg 1gJ1J7G9fHyEVrHNSVksrKWBpDVI8oaxiHxyCYJ+Zr6AayHYL0SdwarkQ52ohHjMQ3/0 LADoIo3wXJeYuRsaR1Jd+8hWrREdHLMmjSq6K/Bk7i8/EvAB2pG9YDxyR3KFECKC+6Ue +R1KHLcvTF6ffrsPv6xTMQYrV2uKCdpcBUKRb+b/Sd0qG9fumn0O3W2K4IWNQ6g8N7QU u6TzNuc9VsDTvgEl7GIeokNsrINUZmlnvcpOl5w8D/56x9vID5CDBf+6H0HzAyjKg02P /w== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2ybvr4p99s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:11 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKpxwk108725; Mon, 24 Feb 2020 20:57:10 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ybe123v1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:10 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKv9p1009755; Mon, 24 Feb 2020 20:57:09 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:09 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 47/50] multi-process: Enable support for multiple devices in remote Date: Mon, 24 Feb 2020 15:55:38 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 suspectscore=1 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- hw/proxy/qemu-proxy.c | 4 ++- include/hw/proxy/qemu-proxy.h | 3 +++ include/io/mpqemu-link.h | 1 + qdev-monitor.c | 2 ++ remote/remote-main.c | 62 +++++++++++++++++++++++++++++++++++-------- 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 5876957..4d4eff4 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -242,7 +242,7 @@ static int set_remote_opts(PCIDevice *dev, QDict *qdict, unsigned int cmd) msg.cmd = cmd; msg.bytestream = 1; msg.size = qstring_get_length(qstr) + 1; - + msg.id = pdev->id; wait = eventfd(0, EFD_NONBLOCK); msg.num_fds = 1; @@ -404,6 +404,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 == PCI_CONFIG_WRITE) { msg.num_fds = 0; @@ -710,6 +711,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 6784298..5ff3aec 100644 --- a/include/hw/proxy/qemu-proxy.h +++ b/include/hw/proxy/qemu-proxy.h @@ -43,6 +43,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 beb8293..722f08c 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 8efa1a8..cda2545 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -735,8 +735,10 @@ 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->socket = managed ? socket : -1; + pdev->id = pdev->nr_devices++; } pdev->managed = managed; diff --git a/remote/remote-main.c b/remote/remote-main.c index ab4ad0b..20d160e 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -72,15 +72,23 @@ static MPQemuLinkState *mpqemu_link; -PCIDevice *remote_pci_dev; +PCIDevice **remote_pci_devs; +uint64_t nr_devices; +#define MAX_REMOTE_DEVICES 256 + bool create_done; static void process_config_write(MPQemuMsg *msg) { struct conf_data_msg *conf = (struct conf_data_msg *)msg->data2; + if (msg->id > nr_devices) { + return; + } + 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(); } @@ -92,8 +100,13 @@ static void process_config_read(MPQemuMsg *msg) wait = msg->fds[0]; + if (msg->id > nr_devices) { + return; + } + 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); @@ -282,6 +295,13 @@ static int setup_device(MPQemuMsg *msg, Error **errp) } if (!msg->data2) { + error_setg(errp, "Message data is empty"); + return rc; + } + + if (msg->id > MAX_REMOTE_DEVICES) { + error_setg(errp, "id of the device is larger than max number of "\ + "devices per remote process."); return rc; } @@ -319,8 +339,15 @@ static int setup_device(MPQemuMsg *msg, Error **errp) qstring_get_str(qobject_to_json(QOBJECT(qdict)))); goto device_failed; } + 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); } notify_proxy(wait, (uint32_t)REMOTE_OK); @@ -405,11 +432,17 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) goto finalize_loop; } + if (msg->id > MAX_REMOTE_DEVICES) { + error_setg(&err, "id of the device is larger than max number of "\ + "devices per remote process."); + goto finalize_loop; + } + switch (msg->cmd) { case INIT: break; case GET_PCI_INFO: - process_get_pci_info_msg(remote_pci_dev, msg); + process_get_pci_info_msg(remote_pci_devs[msg->id], msg); break; case PCI_CONFIG_WRITE: if (create_done) { @@ -449,12 +482,19 @@ 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; + if (msg->id > nr_devices) { + error_setg(&err, "incorrect device id in the message"); + goto finalize_loop; + } + 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 DEV_OPTS: if (setup_device(msg, &err)) { From patchwork Mon Feb 24 20:55:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=urlHjnbc; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFSp3MTpz9sNg for ; Tue, 25 Feb 2020 08:24:42 +1100 (AEDT) Received: from localhost ([::1]:43794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LDU-0003iY-6w for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:24:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51029) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn1-0008UL-Ja for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn0-00049M-8k for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:19 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42754) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kmz-00048W-W1 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:18 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqU5j017507; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=FTEBWYd3NkF4WCDTS27/EbKwH/jwO+R30SR6MGMPsuc=; b=urlHjnbcCX+++wQbiLgsYEI+U4NGu3K44Nci2gu82cG5jZboqS7sg5rVQVDThdiGeS1f E/Sfw66OE73VeZQ0oYYgp5KrZu4hYog2I9U+v3X1NMDdDNTW9Cj5Lhl+HAYn38bdEgav SPcXLDzHc9SU8HV49JQKRDY34Gr9VsCCoh8jLnDktna2MKjJ+Ep6aSuTyRuFkioZMGJm WJHIDz1kpBN3NHZ34+aEnlyZFYI2gvoXj0UJVisv1IPz9oybf0dRTzea/XKBDhAI8i4m RgZvyY2E28qE7rRmyrXAFfIlBkez4IJMktaZO6BPdl/hpcv1iw40vJLYaJc+X39u+xwk JQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2yavxrhyn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:13 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq54u171131; Mon, 24 Feb 2020 20:57:12 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2ybdshkswv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:12 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01OKvBxq028925; Mon, 24 Feb 2020 20:57:11 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:10 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 48/50] multi-process: Validate incoming commands from Proxy Date: Mon, 24 Feb 2020 15:55:39 -0500 Message-Id: <00737a41c9bc4993ad47e5d4387ac14f1892be40.1582576372.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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=1 spamscore=0 malwarescore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=1 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Elena Ufimtseva Validate the incoming commands to confirm that they would not cause any errors in the remote process. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- hw/proxy/qemu-proxy.c | 6 +++- include/io/mpqemu-link.h | 2 ++ io/mpqemu-link.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++- remote/remote-main.c | 4 +++ 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/hw/proxy/qemu-proxy.c b/hw/proxy/qemu-proxy.c index 4d4eff4..7330094 100644 --- a/hw/proxy/qemu-proxy.c +++ b/hw/proxy/qemu-proxy.c @@ -868,7 +868,11 @@ static void send_bar_access_msg(PCIProxyDev *dev, MemoryRegion *mr, mpqemu_msg_recv(&ret, mpqemu_link->mmio); - *val = ret.data1.mmio_ret.val; + if (!mpqemu_msg_valid(&ret)) { + *val = 0; + } else { + *val = ret.data1.mmio_ret.val; + } } void proxy_default_bar_write(void *opaque, hwaddr addr, uint64_t val, diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 722f08c..2f44f31 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -213,4 +213,6 @@ void mpqemu_start_coms(MPQemuLinkState *s); uint64_t wait_for_remote(int efd); void notify_proxy(int fd, uint64_t val); +bool mpqemu_msg_valid(MPQemuMsg *msg); + #endif diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 07a9be9..298bb58 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -65,7 +65,7 @@ void mpqemu_link_finalize(MPQemuLinkState *s) void mpqemu_msg_send(MPQemuMsg *msg, MPQemuChannel *chan) { int rc; - uint8_t *data; + uint8_t *data = NULL; union { char control[CMSG_SPACE(REMOTE_MAX_FDS * sizeof(int))]; struct cmsghdr align; @@ -335,3 +335,76 @@ void mpqemu_start_coms(MPQemuLinkState *s) g_main_loop_run(s->loop); } + +bool mpqemu_msg_valid(MPQemuMsg *msg) +{ + if (msg->cmd >= MAX) { + return false; + } + + if (msg->bytestream) { + if (!msg->data2) { + return false; + } + } else { + if (msg->data2) { + return false; + } + } + + /* Verify FDs. */ + if (msg->num_fds >= REMOTE_MAX_FDS) { + return false; + } + if (msg->num_fds > 0) { + for (int i = 0; i < msg->num_fds; i++) { + if (fcntl(msg->fds[i], F_GETFL) == -1) { + return false; + } + } + } + + /* Verify ID size. */ + if (msg->id >= UINT64_MAX) { + return false; + } + + /* Verify message specific fields. */ + switch (msg->cmd) { + case SYNC_SYSMEM: + if (msg->num_fds == 0 || msg->bytestream != 0) { + return false; + } + if (msg->size != sizeof(msg->data1)) { + return false; + } + break; + case PCI_CONFIG_WRITE: + case PCI_CONFIG_READ: + if (msg->size != sizeof(struct conf_data_msg)) { + return false; + } + break; + case BAR_WRITE: + case BAR_READ: + case SET_IRQFD: + case MMIO_RETURN: + case DEVICE_RESET: + case RUNSTATE_SET: + if (msg->size != sizeof(msg->data1)) { + return false; + } + break; + case PROXY_PING: + case START_MIG_OUT: + case START_MIG_IN: + if (msg->size != 0) { + return false; + } + break; + default: + break; + } + + return true; +} diff --git a/remote/remote-main.c b/remote/remote-main.c index 20d160e..c4aa3e0 100644 --- a/remote/remote-main.c +++ b/remote/remote-main.c @@ -435,6 +435,10 @@ static void process_msg(GIOCondition cond, MPQemuChannel *chan) if (msg->id > MAX_REMOTE_DEVICES) { error_setg(&err, "id of the device is larger than max number of "\ "devices per remote process."); + } + + if (!mpqemu_msg_valid(msg)) { + error_setg(&err, "Message is not valid"); goto finalize_loop; } From patchwork Mon Feb 24 20:55:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=HkE9u0K3; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFYV66k5z9sPg for ; Tue, 25 Feb 2020 08:28:46 +1100 (AEDT) Received: from localhost ([::1]:43920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LHQ-0002c0-N4 for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:28:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51103) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn8-0000I4-Hi for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn2-0004BF-Qf for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:26 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42880) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kn2-0004AO-AV for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:20 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKqVl6017560; Mon, 24 Feb 2020 20:57: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-2020-01-29; bh=87I1QnO09GKKUgHYtyPtROG38iDeSIHcv7rYYAocJrA=; b=HkE9u0K3FaeihOUxbJiQXezZc60CCEVDQYDJCrQM5i4+l69zJ3EHT9vBM5MIi5x2UGhY JNX6+DIe+2oICegf3e/7YeyRS+K5tRwKJPS0wwg8+zgHrAFTqwUR0gtFIjzppEmEhSHw 61dlhdXlp2+Dofd55zV6B0xHRzBZ1Xrc8TIW1MB/TZmq1gdYtfCuNX/AcuDNjkkzgQNy i9SePl7tdYKDCOg/pGbiv3F5sJPdmb7Diyfdk8Mj5gjg2JWnDhwNoiq3tErEB1wvsIz+ 2uyc0VCwRKjbTXynUHSWq2+s12cHlFvy/ZqLpgrviFitU7p1n7l6vfo89/+CefRvpEkA Gg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2yavxrhyn8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:14 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq7Lg109025; Mon, 24 Feb 2020 20:57:14 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ybe123v44-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:13 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKvC8Y009849; Mon, 24 Feb 2020 20:57:12 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:12 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 49/50] multi-process: add the concept description to docs/devel/qemu-multiprocess Date: Mon, 24 Feb 2020 15:55:40 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 suspectscore=3 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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 --- 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 4dc2ca8..1a95871 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -25,3 +25,4 @@ Contents: tcg-plugins bitops reset + multi-process diff --git a/docs/devel/qemu-multiprocess.rst b/docs/devel/qemu-multiprocess.rst new file mode 100644 index 0000000..477e246 --- /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. Disaggregating QEMU reduces the attack surface by aiding to +limit each component in the system to only access the resources that +it needs to perform its job. + +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, but will +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/disk0-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,rid=0,exec="disc-proc",command="" + +And the socket version is: + +:: + + -remote id=disk-proc,rid=0,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 identify +the remote process with a "rid" 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,rid=0 + -device scsi-hd,drive=drive0,bus=scsi0.0,scsi-id=0,rid=0 + +Some devices are implicitly created by the machine object. e.g., the q35 +machine object will create its PCI bus, and attach an ich9-ahci IDE +controller to it. In this case, options will need to be added to the +*-machine* command line. e.g., + +:: + + -machine pc-q35,ide-remote=disk-proc + +will use the remote process with an "id" of "disk-proc" to emulate the +IDE controller and its disks. + +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 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The command "device-add" QMP command facilitates device hot-plug that is +tp. 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 performed 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 will also have "rid" 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 would 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 Mon Feb 24 20:55:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 1243539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2020-01-29 header.b=z+i7Lu4Q; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48RFSt2T4Dz9sNg for ; Tue, 25 Feb 2020 08:24:46 +1100 (AEDT) Received: from localhost ([::1]:43798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6LDX-0003oI-Ps for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2020 16:24:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51068) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6Kn4-0000AA-IM for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6Kn3-0004BW-45 for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:22 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45512) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6Kn2-0004Aq-RZ for qemu-devel@nongnu.org; Mon, 24 Feb 2020 15:57:21 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKrXG9032136; Mon, 24 Feb 2020 20:57:15 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-2020-01-29; bh=gmyHrbZBFH56LM7a/G7epr+zPv1pFhtt2NM9agSpkqY=; b=z+i7Lu4QvzoowhqpGlSQRE6dIH3/kwSm4xpz/JumZPZ6pvJslB87/q7gaIS20zFi8ULO y+MTAJHPjka78wLLI+d/r4WVKOVVQyADIY+S7holi1UgrHmAegOQProCTyfyZish5lZT ynyB4S4H4XjoXXzC04DfUdV40lxhy+thvRDmstLkgtwVST/0mFcYP31wXwYmg6VpInbL gizD4JojC4zk9HVQpxTkOfhaRIBdR9MjhlLtTwoBW7egBlDaVYT05pTGY0KCTadHOEFI cXZOZsXyaCKojWc3c6HsoHauRhMr03geQ9E1UgTZrXXikthedm5hW6sBENXaOdouc0AT Bw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2yauqua0sc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:15 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01OKq65G108991; Mon, 24 Feb 2020 20:57:15 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ybe123v5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 24 Feb 2020 20:57:15 +0000 Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01OKvEYT009858; Mon, 24 Feb 2020 20:57:14 GMT Received: from jaraman-bur-1.us.oracle.com (/10.152.33.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 24 Feb 2020 12:57:13 -0800 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v5 50/50] multi-process: add configure and usage information Date: Mon, 24 Feb 2020 15:55:41 -0500 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=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9541 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 bulkscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002240153 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, swapnil.ingle@nutanix.com, 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, felipe@nutanix.com, thuth@redhat.com, ehabkost@redhat.com, konrad.wilk@oracle.com, dgilbert@redhat.com, liran.alon@oracle.com, stefanha@redhat.com, thanos.makatos@nutanix.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+incoming=patchwork.ozlabs.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..f156177 --- /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 example, 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 are added to the "command" + suboption of the newly added "-remote" option. + + -remote [socket],rid=0,exec="...",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,exec="qemu-scsi-dev",command="-drive id=drive0,,file=data-disk.img -monitor unix:/home/qmp-sock,,server,,nowait" + + Note: There's an issue with this "command" sub-option 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,exec="qemu-scsi-dev",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