From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593277913; cv=none; d=zohomail.com; s=zohoarc; b=PueaVOMNqqnPeOzXcTlBMx8mu+Qh093crfS1cU7Wtj/UASHZrsuuSD2YCMpb7MWAwWMDhBbGbrUSwWehYynVIzY0CejzTEOZIL+f1vYCm6Ap7ymYQpYj0iQL/79w/BL9gIBlgC9zjhY5jU0ksGmlXzELqcEcbAbtsx/o0aknLhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593277913; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tAxrbVcIg6MGwDaT6nMaA8zXyKZlC0a9nYDOqNZf6RY=; b=ftwIyEVvdo/RhSJjKkf1bC3/jySwdYmMxOH2IjiGIDAJN7nyM8yPculDO+Na0w1C6W0q+VI76b4iNzH9WwQaSx+K7NSZM7DXB98VS6KgNKBtiUYEAw2vRLy82ehA//GeNHBkLv3uHLCIrW1kDgWjYmfOKfwnC0PmHpqn/p7LIOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593277913177336.0802268964336; Sat, 27 Jun 2020 10:11:53 -0700 (PDT) Received: from localhost ([::1]:60546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEMp-00017Y-99 for importer@patchew.org; Sat, 27 Jun 2020 13:11:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELI-0007iQ-1G for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:16 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELF-00071D-Gz for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:15 -0400 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 05RH2Dpk172514; Sat, 27 Jun 2020 17:09:53 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 31wxrms97c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:09: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 05RH8FlA080816; Sat, 27 Jun 2020 17:09:53 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 31wv59aw9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:52 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RH9mQb030505; Sat, 27 Jun 2020 17:09:48 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:48 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=tAxrbVcIg6MGwDaT6nMaA8zXyKZlC0a9nYDOqNZf6RY=; b=vxtypc78Se7PvGAUsRnSMwlTewHFJr/X7bTVdzx92aXv/OObkMXi17LWet4ShCicdAgN LjeLxCNDWBiK8IspoUoB4t/nE99pG88ruBGRbLN+CNHK0CmAMG3Nexe9klcLij6n8S72 /NClR9cH7SM83icGfhmugTLf+gUs4/tX11SSqQVShaz7GDTZzQevHAlniH1/O4670czP oLd8izAXJ93WcCggUuFBfFThI47ycACEbue0GG4SNXdbF6H4NpSwVUvMHCJKsIS97dD7 Of9IY5szcbza2f+eleGh8YV8Rc+Nqb/yLLZ1M5FpuUN6WNfehQBXwMwf3InmvCNXbaIP dw== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 01/21] memory: alloc RAM from file at offset Date: Sat, 27 Jun 2020 10:09:23 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=3 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=3 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Allow RAM MemoryRegion to be created from an offset in a file, instead of allocating at offset of 0 by default. This is needed to synchronize RAM between QEMU & remote process. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Reviewed-by: Stefan Hajnoczi --- backends/hostmem-memfd.c | 2 +- exec.c | 11 +++++++---- hw/misc/ivshmem.c | 3 ++- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 3 ++- memory.c | 3 ++- util/mmap-alloc.c | 7 ++++--- util/oslib-posix.c | 2 +- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 1b5e4bfe0d..a862d010ab 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -56,7 +56,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) name =3D host_memory_backend_get_name(backend); memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, - backend->share, fd, errp); + backend->share, fd, 0, errp); g_free(name); } =20 diff --git a/exec.c b/exec.c index 21926dc9c7..afc42722b6 100644 --- a/exec.c +++ b/exec.c @@ -1854,6 +1854,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { void *area; @@ -1904,7 +1905,8 @@ static void *file_ram_alloc(RAMBlock *block, } =20 area =3D qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED, block->flags & RAM_PME= M); + block->flags & RAM_SHARED, block->flags & RAM_PME= M, + offset); if (area =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2336,7 +2338,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 =3D NULL; @@ -2389,7 +2391,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, new_block->used_length =3D size; new_block->max_length =3D size; new_block->flags =3D ram_flags; - new_block->host =3D file_ram_alloc(new_block, size, fd, !file_size, er= rp); + new_block->host =3D file_ram_alloc(new_block, size, fd, !file_size, of= fset, + errp); if (!new_block->host) { g_free(new_block); return NULL; @@ -2419,7 +2422,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, M= emoryRegion *mr, return NULL; } =20 - block =3D qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block =3D qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index a8dc9b377d..b3cffbd1e0 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -492,7 +492,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, = Error **errp) =20 /* mmap the region and map into the BAR2 */ memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), - "ivshmem.bar2", size, true, fd, &local_= err); + "ivshmem.bar2", size, true, fd, 0, + &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/include/exec/memory.h b/include/exec/memory.h index 7207025bd4..a8fc1c36db 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -902,6 +902,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, * @size: size of the region. * @share: %true if memory must be mmaped with the MAP_SHARED flag * @fd: the fd to mmap. + * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. * * Note that this function does not do anything to cause the data in the @@ -913,6 +914,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, uint64_t size, bool share, int fd, + ram_addr_t offset, Error **errp); #endif =20 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 7b5c24e928..ff0784a79c 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, Mem= oryRegion *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); =20 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 e786266b92..4f579858bc 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); =20 void qemu_ram_munmap(int fd, void *ptr, size_t size); =20 diff --git a/memory.c b/memory.c index 9200b20130..130760bd0f 100644 --- a/memory.c +++ b/memory.c @@ -1576,6 +1576,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, uint64_t size, bool share, int fd, + ram_addr_t offset, Error **errp) { Error *err =3D NULL; @@ -1585,7 +1586,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor =3D memory_region_destructor_ram; mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, offset, &err); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; if (err) { mr->size =3D int128_zero(); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 27dcccd8ec..a28f7025f0 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 =3D 0; @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, offset =3D QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guar= dptr; =20 ptr =3D mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags | map_sync_flags, fd, 0); + flags | map_sync_flags, fd, start); =20 if (ptr =3D=3D MAP_FAILED && map_sync_flags) { if (errno =3D=3D ENOTSUP) { @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, * we will remove these flags to handle compatibility. */ ptr =3D mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags, fd, 0); + flags, fd, start); } =20 if (ptr =3D=3D MAP_FAILED) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 39ddc77c85..132e7c46c6 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -222,7 +222,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 =3D QEMU_VMALLOC_ALIGN; - void *ptr =3D qemu_ram_mmap(-1, size, align, shared, false); + void *ptr =3D qemu_ram_mmap(-1, size, align, shared, false, 0); =20 if (ptr =3D=3D MAP_FAILED) { return NULL; --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278277; cv=none; d=zohomail.com; s=zohoarc; b=B/NBzLgOaDg125Z7BE+1AnYVZuaBR6s1Gs/WP6RboLHUtgsWFK1E7hpfT8+HC5GGri+njmy72qBYh7UTmhg38p++O55V6CjKbTN0/RHqeblxZ/FMPTQ+5+2fNrHC9E39wuJFA+9u0aD3P2D/wU8j33+8yxN4+U5vtHx3KF0XdK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278277; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ICCrsoaYtT7RrOkczbvWiPHbj3LGskbdwS8NVE4muDY=; b=ZESnsLhkNa9aprOpLWrXOc9XoCyZT9lS05gPpOhTUieagWhJz6Q2oNbqWVRbuKsFcTTounjEBrBKOprBcwKvYjCyYLd+xP3+yBc048lqsFtkOrmDBEt5qz6mvPpvEdYFDtdi3d71k8WFFo8/e2LqVqzdx1DQUo/ec8OjgHNr8zs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278277761506.7344809648073; Sat, 27 Jun 2020 10:17:57 -0700 (PDT) Received: from localhost ([::1]:58080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpESg-0003IQ-LE for importer@patchew.org; Sat, 27 Jun 2020 13:17:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELr-0000Td-6F for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:51 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELn-00070v-Mt for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:50 -0400 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 05RH3K7T035287; Sat, 27 Jun 2020 17:09:53 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 31wwhr9c8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:09:53 +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 05RH8RwH102275; Sat, 27 Jun 2020 17:09:52 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 31wwx17sa7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:52 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RH9o2Q030506; Sat, 27 Jun 2020 17:09:50 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:50 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=ICCrsoaYtT7RrOkczbvWiPHbj3LGskbdwS8NVE4muDY=; b=poEkl5TGHcr84fErBg0Rpjjlr28IVWm3KSZ/VuSZ+YJmSonSAb8Rj0KkT/x6pgEJNZ0k N2jIrt1dOIctb8R3ZSfC03felS4erCzfl0B8xP1FFC9+dNG9svKHO9lf/mXORMPxzomo d9OoTF5OMAzFMzAN9JVxjUIGqPRWFXjmZrS+/arCLlsYegmMUQsr+Etjsi6Z28vnqRCG EunNy9ix0VjgFmjpCFBDdRiaqoicC0t44ib6GIfaXvdUV98EYLmLya/Z9sM7dIGWQO4f +OyxwsswzME9YDCGlDWV0qU7ViyUprhfGuXujYdbPmWS2XY+YFPaxQdwx8ohYKAtZOgq +A== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 02/21] multi-process: Add config option for multi-process QEMU Date: Sat, 27 Jun 2020 10:09:24 -0700 Message-Id: <626a8bb28b71b4bd2a7e8f9defe4a6dc9aaf1907.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=1 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Add a configuration option to separate multi-process code Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Reviewed-by: Stefan Hajnoczi --- configure | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure b/configure index 4a22dcd563..591e3c62ba 100755 --- a/configure +++ b/configure @@ -519,6 +519,7 @@ fuzzing=3D"no" rng_none=3D"no" secret_keyring=3D"" libdaxctl=3D"" +mpqemu=3D"no" =20 supported_cpu=3D"no" supported_os=3D"no" @@ -1631,6 +1632,10 @@ for opt do ;; --disable-libdaxctl) libdaxctl=3Dno ;; + --enable-mpqemu) mpqemu=3Dyes + ;; + --disable-mpqemu) mpqemu=3Dno + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1933,6 +1938,8 @@ disabled with --disable-FEATURE, default is enabled i= f available: xkbcommon xkbcommon support rng-none dummy RNG, avoid using /dev/(u)random and getrandom() libdaxctl libdaxctl support + mpqemu multi-process QEMU support + =20 NOTE: The object files are built at the place where configure is launched EOF @@ -6999,6 +7006,7 @@ echo "fuzzing support $fuzzing" echo "gdb $gdb_bin" echo "rng-none $rng_none" echo "Linux keyring $secret_keyring" +echo "multiprocess QEMU $mpqemu" =20 if test "$supported_cpu" =3D "no"; then echo @@ -7856,6 +7864,9 @@ fi if test "$sheepdog" =3D "yes" ; then echo "CONFIG_SHEEPDOG=3Dy" >> $config_host_mak fi +if test "$mpqemu" =3D "yes" ; then + echo "CONFIG_MPQEMU=3Dy" >> $config_host_mak +fi if test "$fuzzing" =3D "yes" ; then if test "$have_fuzzer" =3D "yes"; then FUZZ_LDFLAGS=3D" -fsanitize=3Daddress,fuzzer" --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278183; cv=none; d=zohomail.com; s=zohoarc; b=BSYbRLp5dlhRmC/69oECSoCTMDRyY1UubHWzD5sE4CgNTg8ctPT2Nj7fXyvpkwWtxS/eAwsNOdNKhkqKXMCbecS5ROnfTktVLLtknFfWEE63fZWPnPRUmiFNEX/hS8oWY7ybeop2UW4IztJt5AI7Ty3Gnic0a1ZHexGURMZCVtY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278183; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8jBsexkvQxh83psMhsVyE2MFL9w6fHrXrON3V1SYqsw=; b=KKQObxXi32lDULH6yryeVgm2D1YnRRLI1dAjGcYtHEi4MVoPlGRb6Re4uZd6//Z9hKSQoBLVPwekpkk0PZfr2ibggiPRLSsLSM4IGhV+/Z66cQFZrGK7HluPk1Ih7CRJNwoNj+vPE9WGWU/YHuOC6W71oz5jgzUvixHW1L0vlvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278183957301.76525230910806; Sat, 27 Jun 2020 10:16:23 -0700 (PDT) Received: from localhost ([::1]:52338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpERC-0000v6-8o for importer@patchew.org; Sat, 27 Jun 2020 13:16:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEN2-00026c-0i for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:04 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEMz-0007PS-9u for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:03 -0400 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 05RH3CdX035248; Sat, 27 Jun 2020 17:11:54 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 31wwhr9cbu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:11:54 +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 05RH8Pch081756; Sat, 27 Jun 2020 17:09:53 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 31wv59aw9u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:53 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RH9qqh024140; Sat, 27 Jun 2020 17:09:52 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:51 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=8jBsexkvQxh83psMhsVyE2MFL9w6fHrXrON3V1SYqsw=; b=b9UG8can3i5WPminnuo10l14m3hGyGgKB71Re/Fy4qWdWZzm56icp4fFYk3aOv/Uqpa2 k4gZiMukbulQdiYgExGuITGs3DuHUFeSr4i/0UID3b7DpdzQSPayaQ1DnXSn/PmLrGbK ruwTjQUFlwwHpon7JwUpc8cNp1/woHdSFGCd06rcHCu+In91F/TlK+qU7zTkDwztOTB7 T5c/al3cGc97WozRSsQPXsvdAso9bLnX21ht5h2+TGnvD01eg63YFFV5dbD9ueGnkSVM xLU+NoKmKzfdMamBzpHw/x9FQb7Smc4LrDDayIRW7xV14Q37ChTuJ0FWg03RFbeLXFPB LQ== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 03/21] multi-process: setup PCI host bridge for remote device Date: Sat, 27 Jun 2020 10:09:25 -0700 Message-Id: <77bf485a3bbaeac83f3db50753fe45156ae7e882.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jagannathan Raman PCI host bridge is setup for the remote device process. It is implemented using remote-pcihost object. It is an extension of the PCI host bridge setup by QEMU. Remote-pcihost configures a PCI bus which could be used by the remote PCI device to latch on to. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 8 +++++ hw/pci-host/Makefile.objs | 1 + hw/pci-host/remote.c | 63 ++++++++++++++++++++++++++++++++++++ include/hw/pci-host/remote.h | 34 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 hw/pci-host/remote.c create mode 100644 include/hw/pci-host/remote.h diff --git a/MAINTAINERS b/MAINTAINERS index 1b40446c73..e46f1960bf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2938,6 +2938,14 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ =20 +Multi-process QEMU +M: Jagannathan Raman +M: Elena Ufimtseva +M: John G Johnson +S: Maintained +F: hw/pci-host/remote.c +F: include/hw/pci-host/remote.h + Build and test automation ------------------------- Build and test automation diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index e422e0aca0..daf900710d 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -18,6 +18,7 @@ common-obj-$(CONFIG_XEN_IGD_PASSTHROUGH) +=3D xen_igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) +=3D q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) +=3D gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) +=3D xilinx-pcie.o +common-obj-$(CONFIG_MPQEMU) +=3D remote.o =20 common-obj-$(CONFIG_PCI_EXPRESS_DESIGNWARE) +=3D designware.o obj-$(CONFIG_POWERNV) +=3D pnv_phb4.o pnv_phb4_pec.o diff --git a/hw/pci-host/remote.c b/hw/pci-host/remote.c new file mode 100644 index 0000000000..5ea9af4154 --- /dev/null +++ b/hw/pci-host/remote.c @@ -0,0 +1,63 @@ +/* + * Remote PCI host device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" +#include "hw/pci/pcie_host.h" +#include "hw/qdev-properties.h" +#include "hw/pci-host/remote.h" +#include "exec/memory.h" + +static const char *remote_pcihost_root_bus_path(PCIHostState *host_bridge, + PCIBus *rootbus) +{ + return "0000:00"; +} + +static void remote_pcihost_realize(DeviceState *dev, Error **errp) +{ + char *busname =3D g_strdup_printf("remote-pci-%ld", (unsigned long)get= pid()); + PCIHostState *pci =3D PCI_HOST_BRIDGE(dev); + RemotePCIHost *s =3D REMOTE_HOST_DEVICE(dev); + + pci->bus =3D pci_root_bus_new(DEVICE(s), busname, + s->mr_pci_mem, s->mr_sys_io, + 0, TYPE_PCIE_BUS); +} + +static void remote_pcihost_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIHostBridgeClass *hc =3D PCI_HOST_BRIDGE_CLASS(klass); + + hc->root_bus_path =3D remote_pcihost_root_bus_path; + dc->realize =3D remote_pcihost_realize; + + dc->user_creatable =3D false; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + dc->fw_name =3D "pci"; +} + +static const TypeInfo remote_pcihost_info =3D { + .name =3D TYPE_REMOTE_HOST_DEVICE, + .parent =3D TYPE_PCIE_HOST_BRIDGE, + .instance_size =3D sizeof(RemotePCIHost), + .class_init =3D remote_pcihost_class_init, +}; + +static void remote_pcihost_register(void) +{ + type_register_static(&remote_pcihost_info); +} + +type_init(remote_pcihost_register) diff --git a/include/hw/pci-host/remote.h b/include/hw/pci-host/remote.h new file mode 100644 index 0000000000..3df1b53c17 --- /dev/null +++ b/include/hw/pci-host/remote.h @@ -0,0 +1,34 @@ +/* + * PCI Host for remote device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_PCIHOST_H +#define REMOTE_PCIHOST_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "exec/memory.h" +#include "hw/pci/pcie_host.h" + +#define TYPE_REMOTE_HOST_DEVICE "remote-pcihost" +#define REMOTE_HOST_DEVICE(obj) \ + OBJECT_CHECK(RemotePCIHost, (obj), TYPE_REMOTE_HOST_DEVICE) + +typedef struct RemotePCIHost { + /*< private >*/ + PCIExpressHost parent_obj; + /*< public >*/ + + MemoryRegion *mr_pci_mem; + MemoryRegion *mr_sys_mem; + MemoryRegion *mr_sys_io; +} RemotePCIHost; + +#endif --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278324; cv=none; d=zohomail.com; s=zohoarc; b=ONcj+uM7BWJu5WIdrQu9TctJAVWJS8mDupdmAs5c5DKcVBHurkXAaVIzTT0QcPO3T0yNVT8+2/6S5TF2WCb6wbAQ4DgDjkSOtrIbEo1S3UG+Y6r46yk/ClVbrhOHbvnCxstaEjo/u5XhAssaQM70jOGKoYnSadizFSBVvSdMBrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278324; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XhxaWg4QsxSZZBdKA4EujWfXqG4S2H13WsNoHJUbqLQ=; b=FaCZNkeW6ScqtR1KwA3TvhAMxxcLVOFOdKKvPS8Xw9ZbHUBeri86+4GxWULqWB3y8FlnbkdIoY5YTcRQbNfYrKQXTA+2AB/JOLcxklEUuwCbz8QEjdA5nf7DYHEJJzkDIvLArRMIY6VjQG8Xe6By3P8IdpCe9NkNTYiKaKmEFT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278324240111.34303033874392; Sat, 27 Jun 2020 10:18:44 -0700 (PDT) Received: from localhost ([::1]:60922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpETS-0004Sr-V0 for importer@patchew.org; Sat, 27 Jun 2020 13:18:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEN3-00028v-4P for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:05 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:48162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEMz-0007PW-Pq for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:04 -0400 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 05RH2KqD156328; Sat, 27 Jun 2020 17:11:56 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 31wx2m9b11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:11: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 05RH8Hdf080915; Sat, 27 Jun 2020 17:09:56 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 31wv59awae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:56 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RH9sdG002820; Sat, 27 Jun 2020 17:09:54 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:53 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=XhxaWg4QsxSZZBdKA4EujWfXqG4S2H13WsNoHJUbqLQ=; b=jmacZJXq7FqeVezql+X7f06yH0uaptMs5fEAkdlhKSLacjO9i1OPqmvqHkXdx9dC6bol 9OXeps0urB3ucyee6T7cX5Ydp7UY5cClWFO2WA5JRup0gdd8ihPsyGCz6m7Ad7tPqA1n k/UgyhHjwjy9D2FUS/SBUXStBmksWheMnQ+6WasC+7IL3ZgPG2RgtTHawE6wDbEvf1t5 PX4wjt2/NIVXdBN00sLlwwkeD405Ye2Pwiy4hUgIu+zQ6rO1g2cq2qCDOqbVmw76fb7o DOg58anPNTEbgCQas35k3E6nGm6CbnAXdhl+iRMCzEbvbtaVEsNOoL9Ot/q2Rcl9Z1Si bA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 04/21] multi-process: setup a machine object for remote device process Date: Sat, 27 Jun 2020 10:09:26 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jagannathan Raman remote-machine object sets up various subsystems of the remote device process. Instantiate PCI host bridge object and initialize RAM, IO & PCI memory regions. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 2 ++ hw/i386/Makefile.objs | 1 + hw/i386/remote.c | 64 ++++++++++++++++++++++++++++++++++++++++ include/hw/i386/remote.h | 31 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 hw/i386/remote.c create mode 100644 include/hw/i386/remote.h diff --git a/MAINTAINERS b/MAINTAINERS index e46f1960bf..83aae5b441 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2945,6 +2945,8 @@ M: John G Johnson S: Maintained F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h +F: hw/i386/remote.c +F: include/hw/i386/remote.h =20 Build and test automation ------------------------- diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 6abc74551a..5ead266a15 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -14,6 +14,7 @@ obj-$(CONFIG_XEN) +=3D ../xenpv/ xen/ obj-$(CONFIG_VMPORT) +=3D vmport.o obj-$(CONFIG_VMMOUSE) +=3D vmmouse.o obj-$(CONFIG_PC) +=3D port92.o +obj-$(CONFIG_MPQEMU) +=3D remote.o =20 obj-y +=3D kvmvapic.o obj-$(CONFIG_ACPI) +=3D acpi-common.o diff --git a/hw/i386/remote.c b/hw/i386/remote.c new file mode 100644 index 0000000000..4d13abe9f3 --- /dev/null +++ b/hw/i386/remote.c @@ -0,0 +1,64 @@ +/* + * Machine for remote device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/i386/remote.h" +#include "exec/address-spaces.h" +#include "exec/memory.h" +#include "qapi/error.h" + +static void remote_machine_init(MachineState *machine) +{ + MemoryRegion *system_memory, *system_io, *pci_memory; + RemMachineState *s =3D REMOTE_MACHINE(machine); + RemotePCIHost *rem_host; + + system_memory =3D get_system_memory(); + system_io =3D get_system_io(); + + pci_memory =3D g_new(MemoryRegion, 1); + memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); + + rem_host =3D REMOTE_HOST_DEVICE(qdev_new(TYPE_REMOTE_HOST_DEVICE)); + + rem_host->mr_pci_mem =3D pci_memory; + rem_host->mr_sys_mem =3D system_memory; + rem_host->mr_sys_io =3D system_io; + + s->host =3D rem_host; + + object_property_add_child(OBJECT(s), "remote-device", OBJECT(rem_host)= ); + memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1= ); + + qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); +} + +static void remote_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->init =3D remote_machine_init; +} + +static const TypeInfo remote_machine =3D { + .name =3D TYPE_REMOTE_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(RemMachineState), + .class_init =3D remote_machine_class_init, +}; + +static void remote_machine_register_types(void) +{ + type_register_static(&remote_machine); +} + +type_init(remote_machine_register_types); diff --git a/include/hw/i386/remote.h b/include/hw/i386/remote.h new file mode 100644 index 0000000000..d118a940be --- /dev/null +++ b/include/hw/i386/remote.h @@ -0,0 +1,31 @@ +/* + * Remote machine configuration + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_MACHINE_H +#define REMOTE_MACHINE_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qom/object.h" +#include "hw/boards.h" +#include "hw/pci-host/remote.h" + +typedef struct RemMachineState { + MachineState parent_obj; + + RemotePCIHost *host; +} RemMachineState; + +#define TYPE_REMOTE_MACHINE "remote-machine" +#define REMOTE_MACHINE(obj) \ + OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE) + +#endif --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278258; cv=none; d=zohomail.com; s=zohoarc; b=AuB4ayG3Ml/ZCRpFv9hPxeu+eC4Ereiwc4h23tVmoIhhQXjc2p2nT7Rb0pG6LEoxq+3lprVNgBxFMbm1ti1BqfwzWwmmY/GCklOojEXUeqoAPr3/sUaNmzM2zG0Wap6nEHsAItf7D+qHfXnr4FuZ20IKzVXepS83YaZRbipwT4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G/fseAFPQfbAIJooU997W+O6g6K8cG3OMnwqRRi1KUQ=; b=euf1CA6A0/bpPENjif/zOIfKO9M2Ekej5/EyUXxvZTGfztK/EZLwMkrLl6h1T6L1iCDJo+lyywz2cMqrm7UHsX43o4J2FbjMP0klU8aJXh0YuKzM/B/f/nZP3ZCk3+tz12n5iA+iCTNwNZxI82dbbILrxiqgcS/Xb/HHZ6OYwnY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278258578541.1507894257901; Sat, 27 Jun 2020 10:17:38 -0700 (PDT) Received: from localhost ([::1]:57756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpESM-0003Ak-9p for importer@patchew.org; Sat, 27 Jun 2020 13:17:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENA-0002RN-Pd for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:12 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:53394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEN8-0007Rv-Rn for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:12 -0400 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 05RHC01n193134; Sat, 27 Jun 2020 17:12:00 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 31wxrms9ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:12:00 +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 05RH8RwI102275; Sat, 27 Jun 2020 17:09:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 31wwx17sce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:58 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RH9uPo030517; Sat, 27 Jun 2020 17:09:56 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:55 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=G/fseAFPQfbAIJooU997W+O6g6K8cG3OMnwqRRi1KUQ=; b=zb9Dzq9+iJdWiDLjza4dD9S+ZOGhS2AO3DPZ8N7ZU6ZiQfZL0SNB/GTMK/XsFLZ6ahph sXi+IREBprNDNm2J1ZBk2BiWHe6icxxM1OXsx7V0vBCRQuAsk9A8fwXy4cMHUVXiRkCm 63EKs1xYxa54IDOfnnnxbn8F2TrabTX7tLztIzbTTkchCxzeCsAx9usI9kfCg+9qKG2K 5HVJztAyC72pQyl0LXg/e0dixUcKNGreRPPhtQ31kY9HySyBsEiHjMeoB4DUN5UGqepP wQMAMErBI4PtT08NW4+O3x9P2x8q1mlMrZhzfIdf60rTDlSdo9EH/WVUH6dsvy819OOd pg== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 05/21] multi-process: add qio channel function to transmit Date: Sat, 27 Jun 2020 10:09:27 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=3 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=3 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva The entire array of the memory regions and file handlers. Will be used in the next patch. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- include/io/channel.h | 24 +++++++++++++++++++++++ io/channel.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index d4557f0930..c2e3eaeafc 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -779,5 +779,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, IOHandler *io_read, IOHandler *io_write, void *opaque); +/** + * qio_channel_writev_full_all: + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @fds: an array of file handles to send + * @nfds: number of file handles in @fds + * @errp: pointer to a NULL-initialized error object + * + * + * Behaves like qio_channel_writev_full but will attempt + * to send all data passed (file handles and memory regions). + * The function will wait for all requested data + * to be written, yielding from the current coroutine + * if required. + * + * Returns: 0 if all bytes were written, or -1 on error + */ + +int qio_channel_writev_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, size_t nfds, + Error **errp); =20 #endif /* QIO_CHANNEL_H */ diff --git a/io/channel.c b/io/channel.c index e4376eb0bc..22c10c5ccc 100644 --- a/io/channel.c +++ b/io/channel.c @@ -190,6 +190,51 @@ int qio_channel_writev_all(QIOChannel *ioc, return ret; } =20 +int qio_channel_writev_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, size_t nfds, + Error **errp) +{ + int ret =3D -1; + struct iovec *local_iov =3D g_new(struct iovec, niov); + struct iovec *local_iov_head =3D local_iov; + unsigned int nlocal_iov =3D niov; + + nlocal_iov =3D iov_copy(local_iov, nlocal_iov, + iov, niov, + 0, iov_size(iov, niov)); + + while (nlocal_iov > 0) { + ssize_t len; + len =3D qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, + nfds, errp); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_OUT); + } else { + qio_channel_wait(ioc, G_IO_OUT); + } + continue; + } + if (len < 0) { + goto cleanup; + } + + iov_discard_front(&local_iov, &nlocal_iov, len); + + if (len > 0) { + fds =3D NULL; + nfds =3D 0; + } + } + + ret =3D 0; + cleanup: + g_free(local_iov_head); + return ret; +} + ssize_t qio_channel_readv(QIOChannel *ioc, const struct iovec *iov, size_t niov, --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593277935; cv=none; d=zohomail.com; s=zohoarc; b=Sf2IjMgoA4q+PafHM0JLKq/433m+EPk6l77Z/ZxyIHv5jiD+tj8mOM22ONIccN0unXyB4G8CbWYrShqThVYBSx7dASbowqOTCLMbaKHulN9YRzhkuxxJ4MZ7LO5Sy4jjspeaWVXGjP3+ip+rkPBQ2AA33qE0NL4kd6Wo2J9G9Lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593277935; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JI2v9YgoXly9rGI8dNFJBhH/IYVdyUio6ib9fKlwgxI=; b=ZAD4L3gECYM0WuB9KI2VUXSSDa+DsT9PlM5nPyZPiFdGo3xKWSmdiP9PC3sVws0DxODHf0ST0oYJoDi/mS7PWsBhjLhQ4NE+cNaIJ4Zh/xWTazlPKUXJfVIk3wOfkMEX72laKZqQH7kQ8mrDC2Vt4hnx7PYtbCFBvnQ40O/F8rg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593277935508893.1981938831784; Sat, 27 Jun 2020 10:12:15 -0700 (PDT) Received: from localhost ([::1]:33922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpENB-0001mZ-Uf for importer@patchew.org; Sat, 27 Jun 2020 13:12:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELH-0007hl-DF for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:15 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELF-00070u-6P for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:15 -0400 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 05RH2VSK156352; Sat, 27 Jun 2020 17:10:00 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 31wx2m9ax7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:00 +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 05RH8Pci081756; Sat, 27 Jun 2020 17:10:00 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 31wv59awbe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:09:59 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RH9v5H002824; Sat, 27 Jun 2020 17:09:58 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:57 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=JI2v9YgoXly9rGI8dNFJBhH/IYVdyUio6ib9fKlwgxI=; b=C+5dRQACXkytUxWDaaJrForPx5q6y1EhJXh8YmvJ9/QPjvkSz0K1PfXad47OY3OCT2gn LaNNXW84B+v8XvWyAPyP0vcv0h8I4u3RmRFikHqicFSGN9Y92v8yb8JkQsGcmzuMgKsl EbXmC/nkNv6DYiND/yh379XmgITxT6QP7zYMxSY7Cf5qWTntf5Jhc8+5S+EQH2hCjAuH 9aLUXXPTQsEiKSc+LlmVczPgnL6zdHf9H8va2u456mrpre3i/8bC3PlQ8WtPGR+2gNnT kc6q1/Nocv+o+FE+uxxKfoncok4r7Ownl5CLmcykavwjtDALbOvVjKbZ49slbZ+8N7AT mg== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 06/21] multi-process: define MPQemuMsg format and transmission functions Date: Sat, 27 Jun 2020 10:09:28 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=3 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Elena Ufimtseva Defines MPQemuMsg, which is the message that is sent to the remote process. This message is sent over QIOChannel and is used to command the remote process to perform various tasks. Also defined the helper functions to send and receive messages over the QIOChannel Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 2 + include/io/mpqemu-link.h | 75 +++++++++++++++++++ io/Makefile.objs | 2 + io/mpqemu-link.c | 151 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 include/io/mpqemu-link.h create mode 100644 io/mpqemu-link.c diff --git a/MAINTAINERS b/MAINTAINERS index 83aae5b441..50a5fc53d6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2947,6 +2947,8 @@ F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h F: hw/i386/remote.c F: include/hw/i386/remote.h +F: io/mpqemu-link.c +F: include/io/mpqemu-link.h =20 Build and test automation ------------------------- diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h new file mode 100644 index 0000000000..1542e8ed07 --- /dev/null +++ b/include/io/mpqemu-link.h @@ -0,0 +1,75 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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" +#include "io/channel.h" + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data1.u64) + +/** + * MPQemuCmd: + * + * MPQemuCmd enum type to specify the command to be executed on the remote + * device. + */ +typedef enum { + INIT =3D 0, + MAX =3D INT_MAX, +} MPQemuCmd; + +/** + * Maximum size of data2 field in the message to be transmitted. + */ +#define MPQEMU_MSG_DATA_MAX 256 + +/** + * 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 { + int cmd; + int bytestream; + size_t size; + + union { + uint64_t u64; + } data1; + + int fds[REMOTE_MAX_FDS]; + int num_fds; + + /* Max size of data2 is MPQEMU_MSG_DATA_MAX */ + uint8_t *data2; +} MPQemuMsg; + +void mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc); +int mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc); + +bool mpqemu_msg_valid(MPQemuMsg *msg); + +#endif diff --git a/io/Makefile.objs b/io/Makefile.objs index 9a20fce4ed..5875ab0697 100644 --- a/io/Makefile.objs +++ b/io/Makefile.objs @@ -10,3 +10,5 @@ io-obj-y +=3D channel-util.o io-obj-y +=3D dns-resolver.o io-obj-y +=3D net-listener.o io-obj-y +=3D task.o + +io-obj-$(CONFIG_MPQEMU) +=3D mpqemu-link.o diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c new file mode 100644 index 0000000000..bfc542b5fd --- /dev/null +++ b/io/mpqemu-link.c @@ -0,0 +1,151 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/module.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/iov.h" +#include "qemu/error-report.h" + +void mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc) +{ + Error *local_err =3D NULL; + struct iovec send[2]; + int *fds =3D NULL; + size_t nfds =3D 0; + + send[0].iov_base =3D msg; + send[0].iov_len =3D MPQEMU_MSG_HDR_SIZE; + + send[1].iov_base =3D msg->bytestream ? msg->data2 : (void *)&msg->data= 1; + send[1].iov_len =3D msg->size; + + if (msg->num_fds) { + nfds =3D msg->num_fds; + fds =3D msg->fds; + } + + (void)qio_channel_writev_full_all(ioc, send, G_N_ELEMENTS(send), fds, = nfds, + &local_err); + if (local_err) { + error_report_err(local_err); + } +} + +static int mpqemu_readv(QIOChannel *ioc, struct iovec *iov, int **fds, + size_t *nfds, Error **errp) +{ + size_t size, len; + + size =3D iov->iov_len; + + while (size > 0) { + len =3D qio_channel_readv_full(ioc, iov, 1, fds, nfds, errp); + + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_IN); + } else { + qio_channel_wait(ioc, G_IO_IN); + } + continue; + } + + if (len <=3D 0) { + return -EIO; + } + + size -=3D len; + } + + return iov->iov_len; +} + +int mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc) +{ + Error *local_err =3D NULL; + int *fds =3D NULL; + struct iovec hdr, data; + size_t nfds =3D 0; + + hdr.iov_base =3D g_malloc0(MPQEMU_MSG_HDR_SIZE); + hdr.iov_len =3D MPQEMU_MSG_HDR_SIZE; + + if (mpqemu_readv(ioc, &hdr, &fds, &nfds, &local_err) < 0) { + return -EIO; + } + + memcpy(msg, hdr.iov_base, hdr.iov_len); + + free(hdr.iov_base); + if (msg->size > MPQEMU_MSG_DATA_MAX) { + error_report("The message size is more than MPQEMU_MSG_DATA_MAX %d= ", + MPQEMU_MSG_DATA_MAX); + return -EINVAL; + } + + data.iov_base =3D g_malloc0(msg->size); + data.iov_len =3D msg->size; + + if (mpqemu_readv(ioc, &data, NULL, NULL, &local_err) < 0) { + return -EIO; + } + + if (msg->bytestream) { + msg->data2 =3D calloc(1, msg->size); + memcpy(msg->data2, data.iov_base, msg->size); + } else { + memcpy((void *)&msg->data1, data.iov_base, msg->size); + } + + free(data.iov_base); + + if (nfds) { + msg->num_fds =3D nfds; + memcpy(msg->fds, fds, nfds * sizeof(int)); + } + + return 0; +} + +bool mpqemu_msg_valid(MPQemuMsg *msg) +{ + if (msg->cmd >=3D MAX && msg->cmd < 0) { + return false; + } + + if (msg->bytestream) { + if (!msg->data2) { + return false; + } + } else { + if (msg->data2) { + return false; + } + } + + /* Verify FDs. */ + if (msg->num_fds >=3D REMOTE_MAX_FDS) { + return false; + } + + if (msg->num_fds > 0) { + for (int i =3D 0; i < msg->num_fds; i++) { + if (fcntl(msg->fds[i], F_GETFL) =3D=3D -1) { + return false; + } + } + } + + return true; +} --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593277913; cv=none; d=zohomail.com; s=zohoarc; b=OjM8bS7lLU+B8MhyFNQw+pRa4gCCH4JOZklwD1d2r/rotBS4ma4rl/MAyDvTlfFsUqc9Aq9HWgbur4Vzw573h6MER1dMtJfq3dr+K/bHETlqQoNrP71Ex0vaVVsl8jHKXh6fzyWhjRUY1yK+DaY6pZCuJMUF/zc/Ol3u7HxUdBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593277913; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f38bVO2T0ONvo//Y6Y+Hxg6hHWZdhZGpu1r3zOSMW8c=; b=nCXbyAMnnMraFu0h33Mv2/6Uxb1On6L0VcixZpiV9oVY0khSKl4wfeMJnEHEGRqXItXHzySQKd9eiuD7jA0RInGAE+GCh95dyZQRbIKmtMM9xC/K7Fka0gwCL0GeS3Wy1heDhgqmVP7zSuAOZe5HkjlXii7pJF72kOP2dhVVn24= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593277913869197.44626354149318; Sat, 27 Jun 2020 10:11:53 -0700 (PDT) Received: from localhost ([::1]:60586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEMq-00018U-LV for importer@patchew.org; Sat, 27 Jun 2020 13:11:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELJ-0007is-4B for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:17 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELF-00071C-K2 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:16 -0400 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 05RH2ddK172581; Sat, 27 Jun 2020 17:10:02 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 31wxrms97w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:02 +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 05RH8PEb102161; Sat, 27 Jun 2020 17:10:01 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 31wwx17sea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:01 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RH9xf9030585; Sat, 27 Jun 2020 17:09:59 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:09:59 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=f38bVO2T0ONvo//Y6Y+Hxg6hHWZdhZGpu1r3zOSMW8c=; b=m2hpGBy41ciROyvLI+U6z8KFeBG/dH0BdsNTnxJX+R0RCTpjdxRNQJjsiY+anuCyXyEC qVTvxvWvUMzqLyu9UGr7yN4d4Zi6KbwBg8g/bguv3R/xP5lWy6VAL4Ms0q8eqi771+YV 41dPlJP7cj3fqzo5eHr6WR31KsHcPwOXTiPvRng1SA7UJZihZxVhQBUw6SOfB+1vsm7/ 0ZSEpWJ+vLgDQ5J5EaDgKWN9AWkmhuCEr0Z+Who0J6V4nqLH9qm5hL2UoyfGWPpxiFI2 rERylLaV0KZbxKyxHXs/0+ZUHZ70REOfrIDqQ8t91f1zK7ksRGOTiSJ3uoql2GPFKLRP yA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 07/21] multi-process: add co-routines to communicate with remote Date: Sat, 27 Jun 2020 10:09:29 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=15 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=15 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva process to avoid blocking the main loop during the message exchanges. To be used by proxy device. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- include/io/mpqemu-link.h | 16 +++++++++ io/mpqemu-link.c | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 1542e8ed07..52aa89656c 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -17,6 +17,7 @@ #include "qom/object.h" #include "qemu/thread.h" #include "io/channel.h" +#include "io/channel-socket.h" =20 #define REMOTE_MAX_FDS 8 =20 @@ -30,6 +31,7 @@ */ typedef enum { INIT =3D 0, + RET_MSG, MAX =3D INT_MAX, } MPQemuCmd; =20 @@ -67,6 +69,20 @@ typedef struct { uint8_t *data2; } MPQemuMsg; =20 +struct MPQemuRequest { + MPQemuMsg *msg; + QIOChannelSocket *sioc; + Coroutine *co; + bool finished; + int error; + long ret; +}; + +typedef struct MPQemuRequest MPQemuRequest; + +uint64_t mpqemu_msg_send_reply_co(MPQemuMsg *msg, QIOChannel *ioc, + Error **errp); + void mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc); int mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc); =20 diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index bfc542b5fd..c430b4d6a2 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -16,6 +16,8 @@ #include "qapi/error.h" #include "qemu/iov.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" +#include "io/channel-socket.h" =20 void mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc) { @@ -118,6 +120,82 @@ int mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc) return 0; } =20 +/* Use in proxy only as it clobbers fd handlers. */ +static void coroutine_fn mpqemu_msg_send_co(void *data) +{ + MPQemuRequest *req =3D (MPQemuRequest *)data; + MPQemuMsg msg_reply =3D {0}; + long ret =3D -EINVAL; + + if (!req->sioc) { + error_report("No channel available to send command %d", + req->msg->cmd); + atomic_mb_set(&req->finished, true); + req->error =3D -EINVAL; + return; + } + + req->co =3D qemu_coroutine_self(); + mpqemu_msg_send(req->msg, QIO_CHANNEL(req->sioc)); + + yield_until_fd_readable(req->sioc->fd); + + ret =3D mpqemu_msg_recv(&msg_reply, QIO_CHANNEL(req->sioc)); + if (ret < 0) { + error_report("ERROR: failed to get a reply for command %d, \ + errno %s, ret is %ld", + req->msg->cmd, strerror(errno), ret); + req->error =3D -errno; + } else { + if (!mpqemu_msg_valid(&msg_reply) || msg_reply.cmd !=3D RET_MSG) { + error_report("ERROR: Invalid reply received for command %d", + req->msg->cmd); + req->error =3D -EINVAL; + } else { + req->ret =3D msg_reply.data1.u64; + } + } + atomic_mb_set(&req->finished, true); +} + +/* + * Create if needed and enter co-routine to send the message to the + * remote channel ioc and wait for the reply. + * Resturns the value from the reply message, sets the error on failure. + */ + +uint64_t mpqemu_msg_send_reply_co(MPQemuMsg *msg, QIOChannel *ioc, + Error **errp) +{ + MPQemuRequest req =3D {0}; + uint64_t ret =3D UINT64_MAX; + + req.sioc =3D QIO_CHANNEL_SOCKET(ioc); + if (!req.sioc) { + return ret; + } + + req.msg =3D msg; + req.ret =3D 0; + req.finished =3D false; + + if (!req.co) { + req.co =3D qemu_coroutine_create(mpqemu_msg_send_co, &req); + } + + qemu_coroutine_enter(req.co); + while (!req.finished) { + aio_poll(qemu_get_aio_context(), false); + } + if (req.error) { + error_setg(errp, "Error exchanging message with remote process, "\ + "socket %d, error %d", req.sioc->fd, req.error); + } + ret =3D req.ret; + + return ret; +} + bool mpqemu_msg_valid(MPQemuMsg *msg) { if (msg->cmd >=3D MAX && msg->cmd < 0) { --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278380; cv=none; d=zohomail.com; s=zohoarc; b=XYgdFuTEjbjiC2qRqdYxFR+pgzbP+j3ro6T6rRwpxkQqVb9+yE2WERbRnZpPORGi2P2w08HyhNU4+3HRZf0stxi7COucVA3QIPhu1MDTp1Zkm976rizJ6SZcKJR7GrJxFEh/QjkscaNyKJj4HC6ooZvW1cYN9GE4NeMNoSfwZDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278380; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oL6SUAb8+PiyIJlETuoaL5WPbhF1wckiiQRfNXErwjU=; b=QkQAgSPS1r5G7hYZXvIMocbjdOeibQXT9i1MigBuliONpiDuOUA/OtiwVBGPKFJ0Q8G+/5KLAKff3EbnELFPiWop8y1bYZ2abSAGxx5/XR7x3W10GHQuq9+8Bui5DSEQjJju8gF9lTLFsCaO4rhnUjaf32EVKmRDsR1SYe1lEt8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278380434535.843516171859; Sat, 27 Jun 2020 10:19:40 -0700 (PDT) Received: from localhost ([::1]:37888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEUN-0006X7-0F for importer@patchew.org; Sat, 27 Jun 2020 13:19:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENC-0002U2-1B for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:14 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:48282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpEN9-0007S1-W4 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:13 -0400 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 05RHC44G177247; Sat, 27 Jun 2020 17:12:04 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 31wx2m9b17-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:12:04 +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 05RH8mPF172225; Sat, 27 Jun 2020 17:10:03 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 31wwehn4uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:03 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RHA2A7002843; Sat, 27 Jun 2020 17:10:02 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:01 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=oL6SUAb8+PiyIJlETuoaL5WPbhF1wckiiQRfNXErwjU=; b=xKE9/7JG4B7ZBHpb3gUNbusSUmizKUuwJ8G8Wcbm4hUbVFoSXfaR2f3IjACPT2dp1XNa 8uldDVIkGa/7pMfk54yQKRLpYS142tkARusiJlrLOnUK2IAO1tDq6mfWRonc6eqtGLj6 /x+SCF2lBfhPSmctspaz6FMV8lGB1WsJHbsl+22F5uxtbyNJomG5rsp3Vp20pBoOw3M9 XP5Y9zfyvcmm5TIKPW0b7CVHHCfg8X86bCvHtUlib54Y6rt+qsn/0iwRlMkkXIGB965Z +YxPiasre6fVybRBJJSqyfIktPeEqTLYvWUbbulXJ63E6IHm9bqTy5B/440mOr2efpof LA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 08/21] multi-process: Initialize communication channel at the remote end Date: Sat, 27 Jun 2020 10:09:30 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva Initialize the common QIOChannel at remote the end Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/i386/remote.c | 16 ++++++++++++++++ include/hw/i386/remote.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/hw/i386/remote.c b/hw/i386/remote.c index 4d13abe9f3..1a1becffe0 100644 --- a/hw/i386/remote.c +++ b/hw/i386/remote.c @@ -15,6 +15,7 @@ #include "exec/address-spaces.h" #include "exec/memory.h" #include "qapi/error.h" +#include "io/channel-util.h" =20 static void remote_machine_init(MachineState *machine) { @@ -42,6 +43,20 @@ static void remote_machine_init(MachineState *machine) qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); } =20 +static void remote_set_socket(Object *obj, const char *str, Error **errp) +{ + RemMachineState *s =3D REMOTE_MACHINE(obj); + Error *local_err =3D NULL; + int fd =3D atoi(str); + + s->ioc =3D qio_channel_new_fd(fd, &local_err); +} + +static void remote_instance_init(Object *obj) +{ + object_property_add_str(obj, "socket", NULL, remote_set_socket); +} + static void remote_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -53,6 +68,7 @@ static const TypeInfo remote_machine =3D { .name =3D TYPE_REMOTE_MACHINE, .parent =3D TYPE_MACHINE, .instance_size =3D sizeof(RemMachineState), + .instance_init =3D remote_instance_init, .class_init =3D remote_machine_class_init, }; =20 diff --git a/include/hw/i386/remote.h b/include/hw/i386/remote.h index d118a940be..0f8b861e7a 100644 --- a/include/hw/i386/remote.h +++ b/include/hw/i386/remote.h @@ -17,11 +17,13 @@ #include "qom/object.h" #include "hw/boards.h" #include "hw/pci-host/remote.h" +#include "io/channel.h" =20 typedef struct RemMachineState { MachineState parent_obj; =20 RemotePCIHost *host; + QIOChannel *ioc; } RemMachineState; =20 #define TYPE_REMOTE_MACHINE "remote-machine" --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278386; cv=none; d=zohomail.com; s=zohoarc; b=RIQ8cDXwsLHrHvbb6WM+hP1qhLBzK+S4urgxjeh6j9VFsgmY2isMLe9LHBW6Pbl8yI0edYyljEqB0pSxcUiSTVPlO6qilfaz3cQDXWVdgtxv68kHdH2kevDDA2PVbPYJtWWKHbfACRz2ddZw+sEsApXlq2E3WkqFRBp3Bf49TUY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278386; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4k9fx2q6kY1mKRKRGH07PEv7wgKf1PhBB3YTNZ5WUNg=; b=AntCH7Fwvd6QIXOrzfwZUK/wJx/pzZh/fvx0pxAa03ftIbbdMwNsszFn4R+6Hhl6FNlAi9+C3MpCk6npzgSdXc/kWRxK0651Yyg63MyV7HDCEgJ5JmsnfrM9E8EorL+7TtpGzXTHHUPzQ+VlqtkbxTGoLclndC3o90hAQ9mrjo4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278386152912.0958065052407; Sat, 27 Jun 2020 10:19:46 -0700 (PDT) Received: from localhost ([::1]:38400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEUS-0006jl-Tz for importer@patchew.org; Sat, 27 Jun 2020 13:19:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENC-0002Ul-9K for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:14 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENA-0007S3-50 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:13 -0400 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 05RH3JNh035284; Sat, 27 Jun 2020 17:12:05 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 31wwhr9cc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:12:05 +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 05RH8P04102197; Sat, 27 Jun 2020 17:10:04 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 31wwx17sgv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:04 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHA4LB024189; Sat, 27 Jun 2020 17:10:04 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:03 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=4k9fx2q6kY1mKRKRGH07PEv7wgKf1PhBB3YTNZ5WUNg=; b=gdh1Dc2kcpUC/hRHFJdsGY3uaPvsKnCVzVMgseZ/AbGhrfAGlD1na5+D9fs/95s0xoWz prvBj5GDrrj5p7Lp04YUWgKdChS2BvJWDnxpEM3HSVSuX80oBMj1TrYY3gxmEffsNX3r RMz0E/re3kJWp1BRD89Spl1GDl2YYTi00R0cZZVf/jWLSJ/orOiLce4489DoUR+u9as0 pmy/mr97KQ1e0dJCj0fDAiiZqDu6L8vGb5f23cEPgOItS8Ovc8DNsJDf5zkrrKXsa+gx UlewjrYx022HIGt+eiyIR0fgQXCDBoDMfcMryP1/Y4u9UjXMicRCj47tsZ6G1uFx5eOA BA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 09/21] multi-process: Initialize message handler in remote device Date: Sat, 27 Jun 2020 10:09:31 -0700 Message-Id: <6918de2756774d1c6e2c0f9105d8eeceff28938c.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=3 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Initializes the message handler function in the remote process. It is called whenever there's an event pending on QIOChannel that registers this function. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- MAINTAINERS | 1 + hw/i386/Makefile.objs | 1 + hw/i386/remote-msg.c | 52 ++++++++++++++++++++++++++++++++++++++++ hw/i386/remote.c | 4 ++++ include/hw/i386/remote.h | 3 +++ 5 files changed, 61 insertions(+) create mode 100644 hw/i386/remote-msg.c diff --git a/MAINTAINERS b/MAINTAINERS index 50a5fc53d6..e204b3e0c6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2949,6 +2949,7 @@ F: hw/i386/remote.c F: include/hw/i386/remote.h F: io/mpqemu-link.c F: include/io/mpqemu-link.h +F: hw/i386/remote-msg.c =20 Build and test automation ------------------------- diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 5ead266a15..83969585c1 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -15,6 +15,7 @@ obj-$(CONFIG_VMPORT) +=3D vmport.o obj-$(CONFIG_VMMOUSE) +=3D vmmouse.o obj-$(CONFIG_PC) +=3D port92.o obj-$(CONFIG_MPQEMU) +=3D remote.o +obj-$(CONFIG_MPQEMU) +=3D remote-msg.o =20 obj-y +=3D kvmvapic.o obj-$(CONFIG_ACPI) +=3D acpi-common.o diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c new file mode 100644 index 0000000000..58e24ab2ad --- /dev/null +++ b/hw/i386/remote-msg.c @@ -0,0 +1,52 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/i386/remote.h" +#include "io/channel.h" +#include "io/mpqemu-link.h" +#include "qapi/error.h" +#include "sysemu/runstate.h" + +gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, + gpointer opaque) +{ + Error *local_err =3D NULL; + MPQemuMsg msg =3D { 0 }; + + if (cond & G_IO_HUP) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } + + if (cond & (G_IO_ERR | G_IO_NVAL)) { + error_setg(&local_err, "Error %d while processing message from pro= xy \ + in remote process pid=3D%d", errno, getpid()); + return FALSE; + } + + if (mpqemu_msg_recv(&msg, ioc) < 0) { + return FALSE; + } + + if (!mpqemu_msg_valid(&msg)) { + error_report("Received invalid message from proxy \ + in remote process pid=3D%d", getpid()); + return TRUE; + } + + switch (msg.cmd) { + default: + error_setg(&local_err, "Unknown command (%d) received from proxy \ + in remote process pid=3D%d", msg.cmd, getpid()); + } + + if (msg.data2) { + free(msg.data2); + } + + if (local_err) { + error_report_err(local_err); + return FALSE; + } + + return TRUE; +} diff --git a/hw/i386/remote.c b/hw/i386/remote.c index 1a1becffe0..5342e884ad 100644 --- a/hw/i386/remote.c +++ b/hw/i386/remote.c @@ -16,6 +16,7 @@ #include "exec/memory.h" #include "qapi/error.h" #include "io/channel-util.h" +#include "io/channel.h" =20 static void remote_machine_init(MachineState *machine) { @@ -50,6 +51,9 @@ static void remote_set_socket(Object *obj, const char *st= r, Error **errp) int fd =3D atoi(str); =20 s->ioc =3D qio_channel_new_fd(fd, &local_err); + + qio_channel_add_watch(s->ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVA= L, + mpqemu_process_msg, NULL, NULL); } =20 static void remote_instance_init(Object *obj) diff --git a/include/hw/i386/remote.h b/include/hw/i386/remote.h index 0f8b861e7a..c3890e57ab 100644 --- a/include/hw/i386/remote.h +++ b/include/hw/i386/remote.h @@ -30,4 +30,7 @@ typedef struct RemMachineState { #define REMOTE_MACHINE(obj) \ OBJECT_CHECK(RemMachineState, (obj), TYPE_REMOTE_MACHINE) =20 +gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, + gpointer opaque); + #endif --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593277913; cv=none; d=zohomail.com; s=zohoarc; b=Osr8MVePPdzCyZOeo9kDYhUiYu+NAa/0PchMl5s+U5NFPUT9fq2Ofw7GPVNWY3keu3ym3O1n4Sugw2BHTrkqrtV0jUiG8ulOr7qKpFsWhPFr2y5IA72nIjyUFYn7qL2DRW3jph7OhAVUL8bfsuIqNaLQptFSjVVnaX+YQthmlhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593277913; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8nS+lvHP+H/Mu7fyhOjAkUglfr4oIYWJ3jvnpf316vs=; b=ffmX5CwVByIiHfkC1T3oFCnFvQj2g/wCN4CE1GJZSNhy92tdVNNJo1jHNxw543q7hLxmz3TgLe/uosbulufDx8JP23ZR4F+ckK90hDYvZo57+IVSEKAWhyzFHGMbK6Qc8x3HQn4dHXcM726vuO4vMFtA5Zoutc9I1kdXAXnGtVk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593277913208302.72261394057614; Sat, 27 Jun 2020 10:11:53 -0700 (PDT) Received: from localhost ([::1]:60484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEMo-000163-S9 for importer@patchew.org; Sat, 27 Jun 2020 13:11:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELK-0007k1-14 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:18 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELH-00071U-OM for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:17 -0400 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 05RH2FSL156318; Sat, 27 Jun 2020 17:10:08 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 31wx2m9axg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:08 +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 05RH8OwI171713; Sat, 27 Jun 2020 17:10:07 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 31wwehn4wk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:07 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RHA519002847; Sat, 27 Jun 2020 17:10:06 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:05 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=8nS+lvHP+H/Mu7fyhOjAkUglfr4oIYWJ3jvnpf316vs=; b=bLNgi+LlnMrQ4C4rVAwRMFQop5uq9j/gC4/BZT7zk+IWiBfjVxG4NNkb7WBtL31oC7jO +W2zoFSQkdT5TW1O+tPHN8Y0RbgbwvNXLN3eruddjsQVs1GGx3Ko0NlQzJ6Zb2wPri2D giFBkmG5y8TXpLHTDa7C1OsxXVP2WyH3/K9ApehgcyMKcNEjVnRnebj8it4gCQbX09rO rKf3vjOI0VJpbylc+pTeMOvrqmN+TrW7sty+v4waXPYuzQUVr1K65+mzNE4nI6Iigr1J VowHSZYIlExhN1BbxZdPWqp87gCD3+Bp9vU4s9r3iIP8YOKgtq+HvnaDnaykGQ8gdEj8 +g== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 10/21] multi-process: setup memory manager for remote device Date: Sat, 27 Jun 2020 10:09:32 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jagannathan Raman SyncSysMemMsg message format is defined. It is used to send file descriptors of the RAM regions to remote device. RAM on the remote device is configured with a set of file descriptors. Old RAM regions are deleted and new regions, each with an fd, is added to the RAM. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 2 ++ hw/i386/Makefile.objs | 1 + hw/i386/remote-memory.c | 58 +++++++++++++++++++++++++++++++++ include/hw/i386/remote-memory.h | 20 ++++++++++++ include/io/mpqemu-link.h | 13 ++++++++ io/mpqemu-link.c | 13 ++++++++ 6 files changed, 107 insertions(+) create mode 100644 hw/i386/remote-memory.c create mode 100644 include/hw/i386/remote-memory.h diff --git a/MAINTAINERS b/MAINTAINERS index e204b3e0c6..017c96eace 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2950,6 +2950,8 @@ F: include/hw/i386/remote.h F: io/mpqemu-link.c F: include/io/mpqemu-link.h F: hw/i386/remote-msg.c +F: include/hw/i386/remote-memory.h +F: hw/i386/remote-memory.c =20 Build and test automation ------------------------- diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 83969585c1..d85537713e 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -16,6 +16,7 @@ obj-$(CONFIG_VMMOUSE) +=3D vmmouse.o obj-$(CONFIG_PC) +=3D port92.o obj-$(CONFIG_MPQEMU) +=3D remote.o obj-$(CONFIG_MPQEMU) +=3D remote-msg.o +obj-$(CONFIG_MPQEMU) +=3D remote-memory.o =20 obj-y +=3D kvmvapic.o obj-$(CONFIG_ACPI) +=3D acpi-common.o diff --git a/hw/i386/remote-memory.c b/hw/i386/remote-memory.c new file mode 100644 index 0000000000..4fad426bbb --- /dev/null +++ b/hw/i386/remote-memory.c @@ -0,0 +1,58 @@ +/* + * Memory manager for remote device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/i386/remote-memory.h" +#include "exec/address-spaces.h" +#include "exec/ram_addr.h" +#include "qapi/error.h" + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) +{ + SyncSysmemMsg *sysmem_info =3D &msg->data1.sync_sysmem; + MemoryRegion *sysmem, *subregion, *next; + static unsigned int suffix; + Error *local_err =3D NULL; + char *name; + int region; + + sysmem =3D get_system_memory(); + + memory_region_transaction_begin(); + + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, n= ext) { + if (subregion->ram) { + memory_region_del_subregion(sysmem, subregion); + qemu_ram_free(subregion->ram_block); + } + } + + for (region =3D 0; region < msg->num_fds; region++) { + subregion =3D g_new(MemoryRegion, 1); + name =3D g_strdup_printf("remote-mem-%u", suffix++); + memory_region_init_ram_from_fd(subregion, OBJECT(sysmem), + name, sysmem_info->sizes[region], + RAM_SHARED, msg->fds[region], + sysmem_info->offsets[region], + &local_err); + g_free(name); + if (local_err) { + error_propagate(errp, local_err); + break; + } + + memory_region_add_subregion(sysmem, sysmem_info->gpas[region], + subregion); + } + + memory_region_transaction_commit(); +} diff --git a/include/hw/i386/remote-memory.h b/include/hw/i386/remote-memor= y.h new file mode 100644 index 0000000000..e2e479bb6f --- /dev/null +++ b/include/hw/i386/remote-memory.h @@ -0,0 +1,20 @@ +/* + * Memory manager for remote device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * 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/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 52aa89656c..c6d2b6bf8b 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -18,6 +18,8 @@ #include "qemu/thread.h" #include "io/channel.h" #include "io/channel-socket.h" +#include "exec/cpu-common.h" +#include "exec/hwaddr.h" =20 #define REMOTE_MAX_FDS 8 =20 @@ -28,13 +30,22 @@ * * MPQemuCmd enum type to specify the command to be executed on the remote * device. + * + * SYNC_SYSMEM Shares QEMU's RAM with remote device's RAM */ typedef enum { INIT =3D 0, + SYNC_SYSMEM, RET_MSG, MAX =3D INT_MAX, } MPQemuCmd; =20 +typedef struct { + hwaddr gpas[REMOTE_MAX_FDS]; + uint64_t sizes[REMOTE_MAX_FDS]; + off_t offsets[REMOTE_MAX_FDS]; +} SyncSysmemMsg; + /** * Maximum size of data2 field in the message to be transmitted. */ @@ -53,6 +64,7 @@ typedef enum { * MPQemuMsg Format of the message sent to the remote device from QEMU. * */ + typedef struct { int cmd; int bytestream; @@ -60,6 +72,7 @@ typedef struct { =20 union { uint64_t u64; + SyncSysmemMsg sync_sysmem; } data1; =20 int fds[REMOTE_MAX_FDS]; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index c430b4d6a2..5887c8c6c0 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -224,6 +224,19 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) } } } + /* Verify message specific fields. */ + switch (msg->cmd) { + case SYNC_SYSMEM: + if (msg->num_fds =3D=3D 0 || msg->bytestream) { + return false; + } + if (msg->size !=3D sizeof(msg->data1)) { + return false; + } + break; + default: + break; + } =20 return true; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278029; cv=none; d=zohomail.com; s=zohoarc; b=h11taaCuLM1D9oOxU3pWMZrknWFnxisx+q7GfzDKm74YbBpvC0nD+BGSQVNPXb1mzOrrkGFUcKkDB80E4yVKUjgUlyoAjbl/1WDY5T00FylRR4Gy9zRIc4O6U8W7f4abIaz9SNYjjHRs+9CiF6y9QBb5N3DWLM0bNeRx5998ilk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278029; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EiS8sV+XCqIOMkkXkmdM8pLFO1eLmi3z+cRUnsXjNuU=; b=I1ahIHMnoPD1Wnwc7hPGHXSmhG/Bf4J96W1R4rI2qug4MXb9qoOTIB0wh3qx2kyjwmOWqWdG3XNZmMLMiex8byI0RdmrNM9EBDIg9R3hh2N+LRHCLGZyRF9H+nx7viQUXkZl6tw/aG51g3JCrlRrSdnWYr60X+g6CQexUnysVqE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278029929466.9495474999901; Sat, 27 Jun 2020 10:13:49 -0700 (PDT) Received: from localhost ([::1]:40804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEOi-0004dT-Lh for importer@patchew.org; Sat, 27 Jun 2020 13:13:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELM-0007lv-Nd for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:20 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELJ-000722-5D for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:20 -0400 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 05RH3Cs1035251; Sat, 27 Jun 2020 17:10:09 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 31wwhr9c9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:09 +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 05RH7afU195405; Sat, 27 Jun 2020 17:10:09 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 31wu7s8y31-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:09 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RHA7b7002851; Sat, 27 Jun 2020 17:10:07 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:07 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=EiS8sV+XCqIOMkkXkmdM8pLFO1eLmi3z+cRUnsXjNuU=; b=suhNdEi3C/Z5JcJ21folmDhesdn4cdROHXFey4mvpLTPIpX++8YtT50KTgfkTkq8sELi Bysm6r5YOtzRPWHodVjiCbzGHQ3OoCtNB8zkOpZMaZ1LsTTE8JTJow3EnEUCX+j28sjO bYjI68iqfh7Lcu2kP9HPK/bYZ88Wm4zz/UfUi0xu2MV2Agjz5NcTsP80DOrB0C7P1ky0 49vCgxqEnnfL9BsSBsADOImQzbHarToGmcEq7i34pXZNK33W+2sFRmAa8cFzl4qb9Eid rD4JgUWRimWVgNDhoO33hPaAdYUbt/qv/53T67vXdE9+62Ri8Kirr7oZ/tgOOoK8YjAA XQ== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 11/21] multi-process: introduce proxy object Date: Sat, 27 Jun 2020 10:09:33 -0700 Message-Id: <91d295b59735fab5b46959b489b1384cc13bdb67.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Elena Ufimtseva Defines a PCI Device proxy object as a child of TYPE_PCI_DEVICE. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- MAINTAINERS | 2 ++ hw/pci/Makefile.objs | 1 + hw/pci/proxy.c | 70 ++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 43 ++++++++++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 hw/pci/proxy.c create mode 100644 include/hw/pci/proxy.h diff --git a/MAINTAINERS b/MAINTAINERS index 017c96eace..b48c3114c1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2952,6 +2952,8 @@ F: include/io/mpqemu-link.h F: hw/i386/remote-msg.c F: include/hw/i386/remote-memory.h F: hw/i386/remote-memory.c +F: hw/pci/proxy.c +F: include/hw/pci/proxy.h =20 Build and test automation ------------------------- diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs index c78f2fb24b..515dda506c 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -12,3 +12,4 @@ common-obj-$(CONFIG_PCI_EXPRESS) +=3D pcie_port.o pcie_ho= st.o =20 common-obj-$(call lnot,$(CONFIG_PCI)) +=3D pci-stub.o common-obj-$(CONFIG_ALL) +=3D pci-stub.o +obj-$(CONFIG_MPQEMU) +=3D proxy.o diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c new file mode 100644 index 0000000000..6d62399c52 --- /dev/null +++ b/hw/pci/proxy.c @@ -0,0 +1,70 @@ +/* + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/pci/proxy.h" +#include "hw/pci/pci.h" +#include "qapi/error.h" +#include "io/channel-util.h" +#include "hw/qdev-properties.h" +#include "monitor/monitor.h" + +static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) +{ + pdev->com =3D qio_channel_new_fd(fd, errp); +} + +static Property proxy_properties[] =3D { + DEFINE_PROP_STRING("fd", PCIProxyDev, fd), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) +{ + PCIProxyDev *dev =3D PCI_PROXY_DEV(device); + int proxyfd; + + if (dev->fd) { + proxyfd =3D monitor_fd_param(cur_mon, dev->fd, errp); + if (proxyfd =3D=3D -1) { + error_prepend(errp, "proxy: unable to parse proxyfd: "); + return; + } + proxy_set_socket(dev, proxyfd, errp); + } +} + +static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + k->realize =3D pci_proxy_dev_realize; + device_class_set_props(dc, proxy_properties); +} + +static const TypeInfo pci_proxy_dev_type_info =3D { + .name =3D TYPE_PCI_PROXY_DEV, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(PCIProxyDev), + .class_size =3D sizeof(PCIProxyDevClass), + .class_init =3D pci_proxy_dev_class_init, + .interfaces =3D (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) diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h new file mode 100644 index 0000000000..c1c7142fa2 --- /dev/null +++ b/include/hw/pci/proxy.h @@ -0,0 +1,43 @@ +/* + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef PROXY_H +#define PROXY_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/pci/pci.h" +#include "io/channel.h" + +#define TYPE_PCI_PROXY_DEV "pci-proxy-dev" + +#define PCI_PROXY_DEV(obj) \ + OBJECT_CHECK(PCIProxyDev, (obj), TYPE_PCI_PROXY_DEV) + +#define PCI_PROXY_DEV_CLASS(klass) \ + OBJECT_CLASS_CHECK(PCIProxyDevClass, (klass), TYPE_PCI_PROXY_D= EV) + +#define PCI_PROXY_DEV_GET_CLASS(obj) \ + OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) + +typedef struct PCIProxyDev { + PCIDevice parent_dev; + char *fd; + QIOChannel *com; +} PCIProxyDev; + +typedef struct PCIProxyDevClass { + PCIDeviceClass parent_class; + + void (*realize)(PCIProxyDev *dev, Error **errp); + + char *command; +} PCIProxyDevClass; + +#endif /* PROXY_H */ --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278056; cv=none; d=zohomail.com; s=zohoarc; b=UV7rr85z+sezaTp3LgF5vf77VdAi/k/UmNBA9VsQ7N7OhjxrdRltkslTnmIqZXLGNaK5GfkjRWknyOlLSdtivKjHYlk1sg63H9KHA6I/Mdg3VM6Sf3vSGmajqjjkQvZgF8Sjuc7FdDBn2FCtVGoeUZZBdq2XIgQHY0jqh0u3iD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278056; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DdiHkcF1a1OvCm4mH1Raimaz9o81BvEMG0ge/LUn5w4=; b=jAkWcdONBN98ccyFTQvVH2fSOw+a3JhLJ7S03bkYUcKWD9OAfs81dgU4BRVJ8LkcBRwMLMATFyEeKvtfC0kE6/U036oYfiYWvt3oejCAy7bjLPYkGNlBO0ZsL40MiGT7arxM85B0mDTctvGIjb0N106WERC0t8+kzqDObMPlqmA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278056646548.1595348263425; Sat, 27 Jun 2020 10:14:16 -0700 (PDT) Received: from localhost ([::1]:42548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEP9-0005Kz-9n for importer@patchew.org; Sat, 27 Jun 2020 13:14:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELO-0007sD-J8 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:22 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELM-00072c-8U for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:22 -0400 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 05RH2Drf172511; Sat, 27 Jun 2020 17:10:12 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 31wxrms98a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:12 +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 05RH8F09080786; Sat, 27 Jun 2020 17:10:11 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 31wv59awma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:11 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 05RHA9r0002924; Sat, 27 Jun 2020 17:10:09 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:09 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=DdiHkcF1a1OvCm4mH1Raimaz9o81BvEMG0ge/LUn5w4=; b=OQfhh2HYWLcbXAOASs+dasu7NqaY7a7CYfYCQGopJSQip0AB7GYf6RtuTUf9AzHNHdPn 08jg3+N1z4mNMC57SZgzw6+1sszaqqJL15LOQBbmpJ5no6N8zyz960E5utCCUvWKIb3q +d1hbJKg1JlJ6qRw3XGyUUNBAyNUzjqpmkQMQEVwYV+uFdR5fAz4Chldfu7vXckxeGX7 LMgCjGbcYjH8L51fJakuRJcuSV6z2Qkpk9vMhG2lFR8sfRFKKCV6FWpj8MbMpFqWZSgK 3yi2Sd6ZJNXaJIKBC92BqTSzMo6fMmN5uqHDuO97L0iAw9ONYwkoq0Utl+1HrnVlbVRJ YA== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 12/21] multi-process: Connect Proxy Object with device in the remote process Date: Sat, 27 Jun 2020 10:09:34 -0700 Message-Id: <20f42fce1b701586a23c9abdb3b53d080845e94a.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=1 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman Send a message to the remote process to connect PCI device with the corresponding Proxy object in QEMU Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- hw/i386/remote-msg.c | 39 +++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 28 ++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 1 + include/io/mpqemu-link.h | 1 + io/mpqemu-link.c | 8 ++++++++ 5 files changed, 77 insertions(+) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 58e24ab2ad..68f50866bb 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -6,6 +6,11 @@ #include "io/mpqemu-link.h" #include "qapi/error.h" #include "sysemu/runstate.h" +#include "io/channel-util.h" +#include "hw/pci/pci.h" + +static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, + Error **errp); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) @@ -34,6 +39,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, } =20 switch (msg.cmd) { + case CONNECT_DEV: + process_connect_dev_msg(&msg, ioc, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -50,3 +58,34 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOConditio= n cond, =20 return TRUE; } + +static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, + Error **errp) +{ + char *devid =3D (char *)msg->data2; + QIOChannel *dioc =3D NULL; + DeviceState *dev =3D NULL; + MPQemuMsg ret =3D { 0 }; + int rc =3D 0; + + g_assert(devid && (devid[msg->size - 1] =3D=3D '\0')); + + dev =3D qdev_find_recursive(sysbus_get_default(), devid); + if (!dev || !object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + rc =3D 0xff; + goto exit; + } + + dioc =3D qio_channel_new_fd(msg->fds[0], errp); + + qio_channel_add_watch(dioc, G_IO_IN | G_IO_HUP, mpqemu_process_msg, + (void *)dev, NULL); + +exit: + ret.cmd =3D RET_MSG; + ret.bytestream =3D 0; + ret.data1.u64 =3D rc; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, com); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 6d62399c52..16649ed0ec 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -15,10 +15,38 @@ #include "io/channel-util.h" #include "hw/qdev-properties.h" #include "monitor/monitor.h" +#include "io/mpqemu-link.h" =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { + DeviceState *dev =3D DEVICE(pdev); + MPQemuMsg msg =3D { 0 }; + int fds[2]; + Error *local_err =3D NULL; + pdev->com =3D qio_channel_new_fd(fd, errp); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) { + error_setg(errp, "Failed to create proxy channel with fd %d", fd); + return; + } + + msg.cmd =3D CONNECT_DEV; + msg.bytestream =3D 1; + msg.data2 =3D (uint8_t *)dev->id; + msg.size =3D strlen(dev->id) + 1; + msg.num_fds =3D 1; + msg.fds[0] =3D fds[1]; + + (void)mpqemu_msg_send_reply_co(&msg, pdev->com, &local_err); + if (local_err) { + error_setg(errp, "Failed to send DEV_CONNECT to the remote process= "); + close(fds[0]); + } else { + pdev->dev =3D qio_channel_new_fd(fds[0], errp); + } + + close(fds[1]); } =20 static Property proxy_properties[] =3D { diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h index c1c7142fa2..72dd7e0944 100644 --- a/include/hw/pci/proxy.h +++ b/include/hw/pci/proxy.h @@ -30,6 +30,7 @@ typedef struct PCIProxyDev { PCIDevice parent_dev; char *fd; QIOChannel *com; + QIOChannel *dev; } PCIProxyDev; =20 typedef struct PCIProxyDevClass { diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index c6d2b6bf8b..d620806c17 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -36,6 +36,7 @@ typedef enum { INIT =3D 0, SYNC_SYSMEM, + CONNECT_DEV, RET_MSG, MAX =3D INT_MAX, } MPQemuCmd; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 5887c8c6c0..54df3b254e 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -234,6 +234,14 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case CONNECT_DEV: + if ((msg->num_fds !=3D 1) || + (msg->fds[0] =3D=3D -1) || + (msg->fds[0] =3D=3D -1) || + !msg->bytestream) { + return false; + } + break; default: break; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278038; cv=none; d=zohomail.com; s=zohoarc; b=lUdU5+/OyU6Z8Q477MUyASdoDRuOvFGri5akqFzKlmPTx02B0eGkRNEs/+hP2b2xjfAEPRxpOveT/MMZ17EIy3VoEXCKnDNUtW/OBH0XHvKKZZZdkkj0ZLBleUcDPqftlOj3k8Q1Vbu9lc4xNspayAB3Seuz9kz/hmE1AwshU/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278038; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QWNGmCt4M4eOkFjbFAU1RTjyDzQBljVmuABqcrHbEqQ=; b=PQLvpHcdiugqOQY7meGGYShWWl4HMfYT9vyfizNq8Cd78CQbqkg2BuI458C4LQOH1B5SaF76CHhE1YrAxSPURQXW4deL2JcEu2jopAafB1o8HvOV4Xr1/wOuy5pfsN4JGZwwQ2dsl3tmQG5plujLuTzYTBU1QuU/xHoTyaLn/OU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278038696426.3951601046174; Sat, 27 Jun 2020 10:13:58 -0700 (PDT) Received: from localhost ([::1]:40964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEOq-0004hE-CX for importer@patchew.org; Sat, 27 Jun 2020 13:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELP-0007vq-K7 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:23 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:47030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELM-00072i-8D for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:23 -0400 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 05RH2ZtU156367; Sat, 27 Jun 2020 17:10:13 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 31wx2m9axn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10: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 05RH7atv195219; Sat, 27 Jun 2020 17:10:12 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 31wu7s8y44-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:12 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHABIG024202; Sat, 27 Jun 2020 17:10:11 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:11 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=QWNGmCt4M4eOkFjbFAU1RTjyDzQBljVmuABqcrHbEqQ=; b=Oe89Vxpm0OnZWICWa9mqkbCnvGpIwam0PNtn3nZZN1VYa/w029YxLEKVnG83n3rqo8vU RwGUO6HxQdgfAot3m2QIljLwYkl9kT/uwJ9rqGs6xzGB0Yxw6MJX/vehrXCu7JJv9o/s j0uvhB09W494JKNZsL6MDgYYZIAJuWA55/YNE0tCIqFvQIBZJAb9ZJY0rKmkVcMijl9y qC4NzBhT3CzGc5XzcIN2W/hZCQrOr3//TR1irdOjtQmHl30HUAbrr+hMP7TACsWkQ+ql cuhWK9TzHNTsVA4J2Czy2DwHNMhPy4/OFdDe0vbN/odBg334WUe+4eSV3anEWROt83yz WQ== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 13/21] multi-process: Forward PCI config space acceses to the remote process Date: Sat, 27 Jun 2020 10:09:35 -0700 Message-Id: <736d124ffb6c58e8061baba2503981f5e8b3f70b.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva The Proxy Object sends the PCI config space accesses as messages to the remote process over the communication channel TODO: Investigate if the local PCI config writes can be dropped. Without the proxy local PCI config space writes for the device, the driver in the guest times out on the probing. We have tried to only refer to the remote for the PCI config writes, but the driver timeout in the guest forced as to left this as it is (removing local PCI config only). Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- hw/i386/remote-msg.c | 54 ++++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 54 ++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 8 ++++++ io/mpqemu-link.c | 14 +++++++++++ 4 files changed, 130 insertions(+) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 68f50866bb..aa5780d521 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -11,10 +11,16 @@ =20 static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, Error **errp); +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg); +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) { + DeviceState *dev =3D (DeviceState *)opaque; + PCIDevice *pci_dev =3D PCI_DEVICE(dev); Error *local_err =3D NULL; MPQemuMsg msg =3D { 0 }; =20 @@ -42,6 +48,12 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOConditio= n cond, case CONNECT_DEV: process_connect_dev_msg(&msg, ioc, &local_err); break; + case PCI_CONFIG_WRITE: + process_config_write(ioc, pci_dev, &msg); + break; + case PCI_CONFIG_READ: + process_config_read(ioc, pci_dev, &msg); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -89,3 +101,45 @@ exit: =20 mpqemu_msg_send(&ret, com); } + +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg) +{ + struct conf_data_msg *conf =3D (struct conf_data_msg *)msg->data2; + MPQemuMsg ret =3D { 0 }; + + if (conf->addr >=3D PCI_CFG_SPACE_EXP_SIZE) { + error_report("Bad address received when writing PCI config, pid %d= ", + getpid()); + ret.data1.u64 =3D UINT64_MAX; + } else { + pci_default_write_config(dev, conf->addr, conf->val, conf->l); + } + + ret.cmd =3D RET_MSG; + ret.bytestream =3D 0; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} + +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg) +{ + struct conf_data_msg *conf =3D (struct conf_data_msg *)msg->data2; + MPQemuMsg ret =3D { 0 }; + + if (conf->addr >=3D PCI_CFG_SPACE_EXP_SIZE) { + error_report("Bad address received when reading PCI config, pid %d= ", + getpid()); + ret.data1.u64 =3D UINT64_MAX; + } else { + ret.data1.u64 =3D pci_default_read_config(dev, conf->addr, conf->l= ); + } + + ret.cmd =3D RET_MSG; + ret.bytestream =3D 0; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 16649ed0ec..8934070a20 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -16,6 +16,7 @@ #include "hw/qdev-properties.h" #include "monitor/monitor.h" #include "io/mpqemu-link.h" +#include "qemu/error-report.h" =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { @@ -69,12 +70,65 @@ static void pci_proxy_dev_realize(PCIDevice *device, Er= ror **errp) } } =20 +static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, + int l, unsigned int op) +{ + struct conf_data_msg conf_data; + MPQemuMsg msg =3D { 0 }; + long ret =3D -EINVAL; + Error *local_err =3D NULL; + + conf_data.addr =3D addr; + conf_data.val =3D (op =3D=3D PCI_CONFIG_WRITE) ? *val : 0; + conf_data.l =3D l; + + msg.data2 =3D (uint8_t *)&conf_data; + + msg.size =3D sizeof(conf_data); + msg.cmd =3D op; + msg.bytestream =3D 1; + + ret =3D mpqemu_msg_send_reply_co(&msg, pdev->dev, &local_err); + if (local_err) { + error_report("Failed to exchange PCI_CONFIG message with remote"); + } + if (op =3D=3D PCI_CONFIG_READ) { + *val =3D (uint32_t)ret; + } + + return ret; +} + +static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len) +{ + uint32_t val; + + (void)config_op_send(PCI_PROXY_DEV(d), addr, &val, len, PCI_CONFIG_REA= D); + + return val; +} + +static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t v= al, + int l) +{ + /* + * Some of the functions access the copy of the remote device + * PCI config space, therefore maintain it updated. + */ + pci_default_write_config(d, addr, val, l); + + (void)config_op_send(PCI_PROXY_DEV(d), addr, &val, l, PCI_CONFIG_WRITE= ); +} + static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); =20 k->realize =3D pci_proxy_dev_realize; + k->config_read =3D pci_proxy_read_config; + k->config_write =3D pci_proxy_write_config; + device_class_set_props(dc, proxy_properties); } =20 diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index d620806c17..bbd6f3db44 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -38,6 +38,8 @@ typedef enum { SYNC_SYSMEM, CONNECT_DEV, RET_MSG, + PCI_CONFIG_WRITE, + PCI_CONFIG_READ, MAX =3D INT_MAX, } MPQemuCmd; =20 @@ -47,6 +49,12 @@ typedef struct { off_t offsets[REMOTE_MAX_FDS]; } SyncSysmemMsg; =20 +struct conf_data_msg { + uint32_t addr; + uint32_t val; + int l; +}; + /** * Maximum size of data2 field in the message to be transmitted. */ diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 54df3b254e..19887611d0 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -242,6 +242,20 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case PCI_CONFIG_WRITE: + case PCI_CONFIG_READ: + if (msg->size !=3D sizeof(struct conf_data_msg)) { + return false; + } + if (!msg->bytestream) { + return false; + } + struct conf_data_msg *conf =3D (struct conf_data_msg *)msg->data2; + + if (conf->l !=3D 1 && conf->l !=3D 2 && conf->l !=3D 4) { + return false; + } + break; default: break; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278548; cv=none; d=zohomail.com; s=zohoarc; b=my0ANqPS6OQ7Dg/mKLprLYVff3PNh3e/H6hNTFRq8yRWs46JBC28Vsa7fcyS8gK0krxE7HZ6emLVLOSc378VdSljI6puH/Oy49LHV6BJDw5CX5s6OpEK1qi2ZuirobWp+OCFzrnSI1AhXQROJyc766hsJ0G0RPEHKXlA5E1W7PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278548; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XTYgyNRDCERo5huzGWcdWGWEwmbDb86jzsCSvpOa/8Y=; b=Bez8juNO/ExuzgIT0vVyS8w7l/d6jOSSGWdusJeYZHf6n+ptFI46sa1tmDmTDAmPFS1BV8/C2JXDfta64RRqtXfW1EgrK8dZz53T8ZmcAh0nEiHpAL//bNtT7SagvU5tlqFm+bU4bo9NguYvXaioUnqdJCuJgeSVOf6QPdm9DOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159327854819753.0427133978294; Sat, 27 Jun 2020 10:22:28 -0700 (PDT) Received: from localhost ([::1]:46026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEX4-0001cw-Kq for importer@patchew.org; Sat, 27 Jun 2020 13:22:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELl-0000Jz-BP for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:45 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35026) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELi-0007Bn-Vj for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:45 -0400 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 05RH3ALN035235; Sat, 27 Jun 2020 17:10:18 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 31wwhr9c9r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:18 +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 05RH8JiA081218; Sat, 27 Jun 2020 17:10:17 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 31wv59awqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:17 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAFk9030682; Sat, 27 Jun 2020 17:10:15 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:14 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=XTYgyNRDCERo5huzGWcdWGWEwmbDb86jzsCSvpOa/8Y=; b=QEBAH77GvxjAkXNh+F66Q9bTi217gY3Bbs+XUcoPazwUlEgkLmhyZeOgrW9Zi4vVSMce T0bO10x8WJ+hUo8xRdp19iGSmetqV4a6Pru6l+lJtt0szVl/2TaT4x8VINgEt9RcJ3j0 ttX8BkQEYxlvnwU/YxlxOeT0GtqJQ1Lc0HQPcGSxGBTTdUl8nD+P1ZybzaWx5ZT27Yl0 wc+3ruFNvOVZkr8qkGYIXL6bDoYXdf5AmLLZlzQtX7pxh/7isP9UK+T196gNHxPzg1ow S3QpYcWmhmj7nbohbQHF/2M9kxpHN0hig1ArAxYjzBZleInxvJzb8Z3MGxowK1+4dYe+ Uw== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 14/21] multi-process: PCI BAR read/write handling for proxy & remote endpoints Date: Sat, 27 Jun 2020 10:09:36 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman 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/i386/remote-msg.c | 95 ++++++++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 61 ++++++++++++++++++++++++++ include/hw/pci/proxy.h | 16 ++++++- include/io/mpqemu-link.h | 10 +++++ io/mpqemu-link.c | 6 +++ 5 files changed, 186 insertions(+), 2 deletions(-) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index aa5780d521..ffb4143736 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -8,6 +8,7 @@ #include "sysemu/runstate.h" #include "io/channel-util.h" #include "hw/pci/pci.h" +#include "exec/memattrs.h" =20 static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, Error **errp); @@ -15,6 +16,8 @@ static void process_config_write(QIOChannel *ioc, PCIDevi= ce *dev, MPQemuMsg *msg); static void process_config_read(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg); +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **err= p); +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp= ); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) @@ -54,6 +57,12 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOConditio= n cond, case PCI_CONFIG_READ: process_config_read(ioc, pci_dev, &msg); break; + case BAR_WRITE: + process_bar_write(ioc, &msg, &local_err); + break; + case BAR_READ: + process_bar_read(ioc, &msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -143,3 +152,89 @@ static void process_config_read(QIOChannel *ioc, PCIDe= vice *dev, =20 mpqemu_msg_send(&ret, ioc); } + +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **err= p) +{ + BarAccessMsg *bar_access =3D &msg->data1.bar_access; + AddressSpace *as =3D + bar_access->memory ? &address_space_memory : &address_space_io; + MPQemuMsg ret =3D { 0 }; + MemTxResult res; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + ret.data1.u64 =3D UINT64_MAX; + goto fail; + } + + res =3D address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&bar_access->val, bar_access->size, + true); + + if (res !=3D MEMTX_OK) { + error_setg(errp, "Could not perform address space write operation," + " inaccessible address: %lx in pid %d.", + bar_access->addr, getpid()); + ret.data1.u64 =3D -1; + } + +fail: + ret.cmd =3D RET_MSG; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} + +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) +{ + BarAccessMsg *bar_access =3D &msg->data1.bar_access; + MPQemuMsg ret =3D { 0 }; + AddressSpace *as; + MemTxResult res; + uint64_t val =3D 0; + + as =3D bar_access->memory ? &address_space_memory : &address_space_io; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + val =3D UINT64_MAX; + goto fail; + } + + res =3D address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&val, bar_access->size, false); + + if (res !=3D MEMTX_OK) { + error_setg(errp, "Could not perform address space read operation," + " inaccessible address: %lx in pid %d.", + bar_access->addr, getpid()); + val =3D UINT64_MAX; + goto fail; + } + + switch (bar_access->size) { + case 8: + /* Nothing to do as val is already 8 bytes long */ + break; + case 4: + val =3D *((uint32_t *)&val); + break; + case 2: + val =3D *((uint16_t *)&val); + break; + case 1: + val =3D *((uint8_t *)&val); + break; + default: + error_setg(errp, "Invalid PCI BAR read size in pid %d", + getpid()); + val =3D (uint64_t)-1; + } + +fail: + ret.cmd =3D RET_MSG; + ret.data1.u64 =3D val; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 8934070a20..fff021a06a 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -150,3 +150,64 @@ static void pci_proxy_dev_register_types(void) } =20 type_init(pci_proxy_dev_register_types) + +static void send_bar_access_msg(PCIProxyDev *pdev, MemoryRegion *mr, + bool write, hwaddr addr, uint64_t *val, + unsigned size, bool memory) +{ + MPQemuMsg msg =3D { 0 }; + long ret =3D -EINVAL; + Error *local_err =3D NULL; + + msg.bytestream =3D 0; + msg.size =3D sizeof(msg.data1); + msg.data1.bar_access.addr =3D mr->addr + addr; + msg.data1.bar_access.size =3D size; + msg.data1.bar_access.memory =3D memory; + + if (write) { + msg.cmd =3D BAR_WRITE; + msg.data1.bar_access.val =3D *val; + } else { + msg.cmd =3D BAR_READ; + } + + ret =3D mpqemu_msg_send_reply_co(&msg, pdev->com, &local_err); + if (local_err) { + error_report("Failed to send BAR command to the remote process."); + } + + if (!write) { + *val =3D ret; + } +} + +static void proxy_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyMemoryRegion *pmr =3D opaque; + + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +static uint64_t proxy_bar_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyMemoryRegion *pmr =3D opaque; + uint64_t val; + + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + + return val; +} + +const MemoryRegionOps proxy_mr_ops =3D { + .read =3D proxy_bar_read, + .write =3D proxy_bar_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 1, + }, +}; diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h index 72dd7e0944..4f9f9c4e15 100644 --- a/include/hw/pci/proxy.h +++ b/include/hw/pci/proxy.h @@ -26,12 +26,24 @@ #define PCI_PROXY_DEV_GET_CLASS(obj) \ OBJECT_GET_CLASS(PCIProxyDevClass, (obj), TYPE_PCI_PROXY_DEV) =20 -typedef struct PCIProxyDev { +typedef struct PCIProxyDev PCIProxyDev; + +typedef struct ProxyMemoryRegion { + PCIProxyDev *dev; + MemoryRegion mr; + bool memory; + bool present; + uint8_t type; +} ProxyMemoryRegion; + +struct PCIProxyDev { PCIDevice parent_dev; char *fd; QIOChannel *com; QIOChannel *dev; -} PCIProxyDev; + + ProxyMemoryRegion region[PCI_NUM_REGIONS]; +}; =20 typedef struct PCIProxyDevClass { PCIDeviceClass parent_class; diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index bbd6f3db44..0422213863 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -40,6 +40,8 @@ typedef enum { RET_MSG, PCI_CONFIG_WRITE, PCI_CONFIG_READ, + BAR_WRITE, + BAR_READ, MAX =3D INT_MAX, } MPQemuCmd; =20 @@ -55,6 +57,13 @@ struct conf_data_msg { int l; }; =20 +typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} BarAccessMsg; + /** * Maximum size of data2 field in the message to be transmitted. */ @@ -82,6 +91,7 @@ typedef struct { union { uint64_t u64; SyncSysmemMsg sync_sysmem; + BarAccessMsg bar_access; } data1; =20 int fds[REMOTE_MAX_FDS]; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 19887611d0..026e25dca4 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -256,6 +256,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case BAR_WRITE: + case BAR_READ: + if (msg->size !=3D sizeof(msg->data1)) { + return false; + } + break; default: break; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278447; cv=none; d=zohomail.com; s=zohoarc; b=i+iDQuUBP3kqIdVKzQcgukMJDNZwzE61zUlJOVZEaQ2rWWFvRbfoSd+fZ1Wq24dzp2j5FQRG0bpE90OzdFh/BnnliKx6z74VNIhvwsb/BWWwYUwbWGonTcIJE84LCUdYBenVXeVoTguysqqZ8b8zfdwUahqlKDXFs9UXOdLmG3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278447; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y7ekJC7/byWzfQ1GbquoCayN6CPei2g6xIsS38QAJbo=; b=hxefHVh1+VIBXL62I7pBe6W6dGIQ8GAGxTGa3J25x+IDNQ+OXJvlZGxDcAFKnCnUzaKJtYDSWJQ2n8vrbhapLW2Dxrv1/tRiuL+okXrq48befjEKLtjS1qm+vp0m4C+XGR8n8wH0l0NUrYw06lXQ/IlzPrwOqeSVBi7g3wQlpGE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278447183962.9076725388136; Sat, 27 Jun 2020 10:20:47 -0700 (PDT) Received: from localhost ([::1]:41214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEVR-0007t9-T8 for importer@patchew.org; Sat, 27 Jun 2020 13:20:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENQ-0002zn-MQ for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:31 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:36100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENO-0007UK-90 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:28 -0400 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 05RH3B5s035240; Sat, 27 Jun 2020 17:12:20 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 31wwhr9ccp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:12:20 +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 05RH8OZr171699; Sat, 27 Jun 2020 17:10:20 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 31wwehn50f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:20 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAIij030692; Sat, 27 Jun 2020 17:10:18 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:17 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=y7ekJC7/byWzfQ1GbquoCayN6CPei2g6xIsS38QAJbo=; b=NVc226qkHLEMx+Y16d5DvBhl49dDzuoq/neTkgVT0w2wbmR8qp6yv4+fHQplEtOagsfG ZhV+EcQKA0iQsZVKwqvYSOZKvLzO295L6NH8dtK4Q5f3dFzjy8TwUf2qtu7Dwn8xRogP GXcer6aoQ+SpKdPwDZVZi0u/eeXKDAzJqZpHMI18LvlHa8gPLdYdqIEXGlmkRqZDF1YA 28PtKdbxIzduFwFF0QPgfIFBB4a6JOeBdFZGTQxFHKX80zeeBt8XZF4/EBFSNmPhWLVH X15JQw8fhYkLbOeG9ym3SbfLyw5s0ulIbzhERsXETMTnnm2LORDHOFByib0pn5lBcKNu iw== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 15/21] multi-process: Synchronize remote memory Date: Sat, 27 Jun 2020 10:09:37 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=4 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=4 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jagannathan Raman Add memory-listener object which is used to keep the view of the RAM in sync between QEMU and remote process. A MemoryListener is registered for system-memory AddressSpace. The listener sends SYNC_SYSMEM message to the remote process when memory listener commits the changes to memory, the remote process receives the message and processes it in the handler for SYNC_SYSMEM message. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 2 + hw/i386/remote-msg.c | 4 + hw/pci/Makefile.objs | 1 + hw/pci/memory-sync.c | 214 +++++++++++++++++++++++++++++++++++ hw/pci/proxy.c | 4 + include/hw/pci/memory-sync.h | 30 +++++ include/hw/pci/proxy.h | 3 + 7 files changed, 258 insertions(+) create mode 100644 hw/pci/memory-sync.c create mode 100644 include/hw/pci/memory-sync.h diff --git a/MAINTAINERS b/MAINTAINERS index b48c3114c1..38d605445e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2954,6 +2954,8 @@ F: include/hw/i386/remote-memory.h F: hw/i386/remote-memory.c F: hw/pci/proxy.c F: include/hw/pci/proxy.h +F: hw/pci/memory-sync.c +F: include/hw/pci/memory-sync.h =20 Build and test automation ------------------------- diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index ffb4143736..48b153eaae 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -9,6 +9,7 @@ #include "io/channel-util.h" #include "hw/pci/pci.h" #include "exec/memattrs.h" +#include "hw/i386/remote-memory.h" =20 static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, Error **errp); @@ -63,6 +64,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, case BAR_READ: process_bar_read(ioc, &msg, &local_err); break; + case SYNC_SYSMEM: + remote_sysmem_reconfig(&msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs index 515dda506c..c90acd5a6e 100644 --- a/hw/pci/Makefile.objs +++ b/hw/pci/Makefile.objs @@ -13,3 +13,4 @@ common-obj-$(CONFIG_PCI_EXPRESS) +=3D pcie_port.o pcie_ho= st.o common-obj-$(call lnot,$(CONFIG_PCI)) +=3D pci-stub.o common-obj-$(CONFIG_ALL) +=3D pci-stub.o obj-$(CONFIG_MPQEMU) +=3D proxy.o +obj-$(CONFIG_MPQEMU) +=3D memory-sync.o diff --git a/hw/pci/memory-sync.c b/hw/pci/memory-sync.c new file mode 100644 index 0000000000..5f867974c4 --- /dev/null +++ b/hw/pci/memory-sync.c @@ -0,0 +1,214 @@ +/* + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.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/pci/memory-sync.h" + +static void proxy_ml_begin(MemoryListener *listener) +{ + RemoteMemSync *sync =3D container_of(listener, RemoteMemSync, listener= ); + int mrs; + + for (mrs =3D 0; mrs < sync->n_mr_sections; mrs++) { + memory_region_unref(sync->mr_sections[mrs].mr); + } + + g_free(sync->mr_sections); + sync->mr_sections =3D NULL; + sync->n_mr_sections =3D 0; +} + +static int get_fd_from_hostaddr(uint64_t host, ram_addr_t *offset) +{ + MemoryRegion *mr; + ram_addr_t off; + + /** + * Assumes that the host address is a valid address as it's + * coming from the MemoryListener system. In the case host + * address is not valid, the following call would return + * the default subregion of "system_memory" region, and + * not NULL. So it's not possible to check for NULL here. + */ + mr =3D memory_region_from_host((void *)(uintptr_t)host, &off); + + if (offset) { + *offset =3D 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 =3D get_fd_from_hostaddr(host, NULL); + + fd2 =3D get_fd_from_hostaddr(prev_host, NULL); + + merge =3D (fd1 =3D=3D fd2); + + merge &=3D ((prev_host + size) =3D=3D host); + + return merge; +} + +static bool try_merge(RemoteMemSync *sync, MemoryRegionSection *section) +{ + uint64_t mrs_size, mrs_gpa, mrs_page; + MemoryRegionSection *prev_sec; + bool merged =3D false; + uintptr_t mrs_host; + RAMBlock *mrs_rb; + + if (!sync->n_mr_sections) { + return false; + } + + mrs_rb =3D section->mr->ram_block; + mrs_page =3D (uint64_t)qemu_ram_pagesize(mrs_rb); + mrs_size =3D int128_get64(section->size); + mrs_gpa =3D section->offset_within_address_space; + mrs_host =3D (uintptr_t)memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + + if (get_fd_from_hostaddr(mrs_host, NULL) < 0) { + return true; + } + + mrs_host =3D mrs_host & ~(mrs_page - 1); + mrs_gpa =3D mrs_gpa & ~(mrs_page - 1); + mrs_size =3D ROUND_UP(mrs_size, mrs_page); + + if (sync->n_mr_sections) { + prev_sec =3D sync->mr_sections + (sync->n_mr_sections - 1); + uint64_t prev_gpa_start =3D prev_sec->offset_within_address_space; + uint64_t prev_size =3D int128_get64(prev_sec->size); + uint64_t prev_gpa_end =3D range_get_last(prev_gpa_start, prev_si= ze); + uint64_t prev_host_start =3D + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) + + prev_sec->offset_within_region; + uint64_t prev_host_end =3D range_get_last(prev_host_start, prev_si= ze); + + if (mrs_gpa <=3D (prev_gpa_end + 1)) { + g_assert(mrs_gpa > prev_gpa_start); + + if ((section->mr =3D=3D prev_sec->mr) && + proxy_mrs_can_merge(mrs_host, prev_host_start, + (mrs_gpa - prev_gpa_start))) { + uint64_t max_end =3D MAX(prev_host_end, mrs_host + mrs_siz= e); + merged =3D true; + prev_sec->offset_within_address_space =3D + MIN(prev_gpa_start, mrs_gpa); + prev_sec->offset_within_region =3D + MIN(prev_host_start, mrs_host) - + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr); + prev_sec->size =3D int128_make64(max_end - MIN(prev_host_s= tart, + mrs_host)); + } + } + } + + return merged; +} + +static void proxy_ml_region_addnop(MemoryListener *listener, + MemoryRegionSection *section) +{ + RemoteMemSync *sync =3D container_of(listener, RemoteMemSync, listener= ); + + if (!(memory_region_is_ram(section->mr) && + !memory_region_is_rom(section->mr))) { + return; + } + + if (try_merge(sync, section)) { + return; + } + + ++sync->n_mr_sections; + sync->mr_sections =3D g_renew(MemoryRegionSection, sync->mr_sections, + sync->n_mr_sections); + sync->mr_sections[sync->n_mr_sections - 1] =3D *section; + sync->mr_sections[sync->n_mr_sections - 1].fv =3D NULL; + memory_region_ref(section->mr); +} + +static void proxy_ml_commit(MemoryListener *listener) +{ + RemoteMemSync *sync =3D 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 =3D SYNC_SYSMEM; + msg.bytestream =3D 0; + msg.num_fds =3D sync->n_mr_sections; + msg.size =3D sizeof(msg.data1); + assert(msg.num_fds <=3D REMOTE_MAX_FDS); + + for (region =3D 0; region < sync->n_mr_sections; region++) { + section =3D sync->mr_sections[region]; + msg.data1.sync_sysmem.gpas[region] =3D + section.offset_within_address_space; + msg.data1.sync_sysmem.sizes[region] =3D int128_get64(section.size); + host_addr =3D (uintptr_t)memory_region_get_ram_ptr(section.mr) + + section.offset_within_region; + msg.fds[region] =3D get_fd_from_hostaddr(host_addr, &offset); + msg.data1.sync_sysmem.offsets[region] =3D offset; + } + mpqemu_msg_send(&msg, sync->ioc); +} + +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, QIOChannel *ioc) +{ + sync->n_mr_sections =3D 0; + sync->mr_sections =3D NULL; + + sync->ioc =3D ioc; + + sync->listener.begin =3D proxy_ml_begin; + sync->listener.commit =3D proxy_ml_commit; + sync->listener.region_add =3D proxy_ml_region_addnop; + sync->listener.region_nop =3D proxy_ml_region_addnop; + sync->listener.priority =3D 10; + + memory_listener_register(&sync->listener, &address_space_memory); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index fff021a06a..5ecbdd2dcf 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -17,6 +17,8 @@ #include "monitor/monitor.h" #include "io/mpqemu-link.h" #include "qemu/error-report.h" +#include "hw/pci/memory-sync.h" +#include "qom/object.h" =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { @@ -68,6 +70,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Erro= r **errp) } proxy_set_socket(dev, proxyfd, errp); } + + configure_memory_sync(&dev->sync, dev->com); } =20 static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, diff --git a/include/hw/pci/memory-sync.h b/include/hw/pci/memory-sync.h new file mode 100644 index 0000000000..3c9007f318 --- /dev/null +++ b/include/hw/pci/memory-sync.h @@ -0,0 +1,30 @@ +/* + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef MEMORY_SYNC_H +#define MEMORY_SYNC_H + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "exec/memory.h" +#include "io/channel.h" + +typedef struct RemoteMemSync { + MemoryListener listener; + + int n_mr_sections; + MemoryRegionSection *mr_sections; + + QIOChannel *ioc; +} RemoteMemSync; + +void configure_memory_sync(RemoteMemSync *sync, QIOChannel *ioc); +void deconfigure_memory_sync(RemoteMemSync *sync); + +#endif diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h index 4f9f9c4e15..a41a6aeaa5 100644 --- a/include/hw/pci/proxy.h +++ b/include/hw/pci/proxy.h @@ -14,6 +14,7 @@ =20 #include "hw/pci/pci.h" #include "io/channel.h" +#include "hw/pci/memory-sync.h" =20 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" =20 @@ -42,6 +43,8 @@ struct PCIProxyDev { QIOChannel *com; QIOChannel *dev; =20 + RemoteMemSync sync; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; =20 --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278141; cv=none; d=zohomail.com; s=zohoarc; b=No9krQfyFWHhbLu6ipL2Mn5y6ywYaeuWvXwXa15S5MX51Rr7zXB1gEpOoxfITjxg49qaPxH/gxuNtJnMsKaN3NaAokVsMtXtmGSfPl4O6KJseApp6eTdC9V5Xk8Kw1zGOj0J195Dvjq3TBp82rM+AgLlAsXKepwZSsFyjF3maAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l+7gfyV68JQOk8h/tWymxftbgp+GxipuiOLfq0mxBuo=; b=iCH2bga5dkuL1h7dD8UNRCMUTOFmsl+kxKPmnJSPTTrWS8wFK08pi0YoQMiGO1j0qW5mYpV5PQ3S29lbBzTxjKiyaCUqrP98+xqzugGnjSafkmtHBrSFRDMxrF3WC5UlN9hnobW+HJo1yw4wIgNE+m1u3fgJdRnqxz1b0NEqnE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278141780737.9771452820528; Sat, 27 Jun 2020 10:15:41 -0700 (PDT) Received: from localhost ([::1]:49474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEQU-00087L-Vh for importer@patchew.org; Sat, 27 Jun 2020 13:15:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELZ-0008K5-FL for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:33 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:52334) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELW-00079d-JI for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:33 -0400 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 05RH2ana172570; Sat, 27 Jun 2020 17:10:22 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 31wxrms98g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:22 +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 05RH8JiC081218; Sat, 27 Jun 2020 17:10:21 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 31wv59aws6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:21 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAKNL024367; Sat, 27 Jun 2020 17:10:20 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:20 -0700 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 : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=l+7gfyV68JQOk8h/tWymxftbgp+GxipuiOLfq0mxBuo=; b=e6PB4ObdyV9XuDmToN24dPL9oYkSOmeMnNHaked8GKTKeTgoHrmonXvycXf1Wv/Z7KYJ XXFeDI9zyIF9ZJ0TTIBnkccSyNJoKjTJ4uKs0K4ijZhRDMaf+cMdOSAfe0r0QZ6ELzvt YmKJXpzzzjo+J8+TjLI4gRjZx4GojVHaEEe9gjgBwMHXADOxpy06vvxMVn4YR8yhNjqS 2OEHo97Oja/VhLiY2xok7Es6B+xCpzFoj/XBAWTB+pHMYQiOe0ckCmatLgdB82Sz3dPM lLa2l/UgZcUcXt4r95g6LPqug6mxK8UyfrwKSwsCy709bcyYZGLbqCttKpe84UVjBspf TQ== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 16/21] multi-process: create IOHUB object to handle irq Date: Sat, 27 Jun 2020 10:09:38 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=1 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=1 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Jagannathan Raman IOHUB object is added to manage PCI IRQs. It uses KVM_IRQFD ioctl to create irqfd to injecting PCI interrupts to the guest. IOHUB object forwards the irqfd to the remote process. Remote process uses this fd to directly send interrupts to the guest, bypassing QEMU. Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva --- MAINTAINERS | 2 + hw/Makefile.objs | 1 + hw/i386/remote-msg.c | 4 + hw/i386/remote.c | 15 ++++ hw/pci/proxy.c | 52 +++++++++++++ hw/remote/Makefile.objs | 1 + hw/remote/iohub.c | 153 ++++++++++++++++++++++++++++++++++++++ include/hw/i386/remote.h | 2 + include/hw/pci/pci_ids.h | 3 + include/hw/pci/proxy.h | 8 ++ include/hw/remote/iohub.h | 50 +++++++++++++ include/io/mpqemu-link.h | 6 ++ io/mpqemu-link.c | 1 + 13 files changed, 298 insertions(+) create mode 100644 hw/remote/Makefile.objs create mode 100644 hw/remote/iohub.c create mode 100644 include/hw/remote/iohub.h diff --git a/MAINTAINERS b/MAINTAINERS index 38d605445e..f9ede7e094 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2956,6 +2956,8 @@ F: hw/pci/proxy.c F: include/hw/pci/proxy.h F: hw/pci/memory-sync.c F: include/hw/pci/memory-sync.h +F: hw/remote/iohub.c +F: include/hw/remote/iohub.h =20 Build and test automation ------------------------- diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 4cbe5e4e57..8caf659de0 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -40,6 +40,7 @@ devices-dirs-$(CONFIG_MEM_DEVICE) +=3D mem/ devices-dirs-$(CONFIG_NUBUS) +=3D nubus/ devices-dirs-y +=3D semihosting/ devices-dirs-y +=3D smbios/ +devices-dirs-y +=3D remote/ endif =20 common-obj-y +=3D $(devices-dirs-y) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 48b153eaae..67fee4bb57 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -10,6 +10,7 @@ #include "hw/pci/pci.h" #include "exec/memattrs.h" #include "hw/i386/remote-memory.h" +#include "hw/remote/iohub.h" =20 static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, Error **errp); @@ -67,6 +68,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, case SYNC_SYSMEM: remote_sysmem_reconfig(&msg, &local_err); break; + case SET_IRQFD: + process_set_irqfd_msg(pci_dev, &msg); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); diff --git a/hw/i386/remote.c b/hw/i386/remote.c index 5342e884ad..8e74a6f1af 100644 --- a/hw/i386/remote.c +++ b/hw/i386/remote.c @@ -17,12 +17,16 @@ #include "qapi/error.h" #include "io/channel-util.h" #include "io/channel.h" +#include "hw/pci/pci_host.h" +#include "hw/remote/iohub.h" =20 static void remote_machine_init(MachineState *machine) { MemoryRegion *system_memory, *system_io, *pci_memory; RemMachineState *s =3D REMOTE_MACHINE(machine); RemotePCIHost *rem_host; + PCIHostState *pci_host; + PCIDevice *pci_dev; =20 system_memory =3D get_system_memory(); system_io =3D get_system_io(); @@ -42,6 +46,17 @@ static void remote_machine_init(MachineState *machine) memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1= ); =20 qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); + + pci_host =3D PCI_HOST_BRIDGE(rem_host); + pci_dev =3D pci_create_simple_multifunction(pci_host->bus, + PCI_DEVFN(REMOTE_IOHUB_DEV, + REMOTE_IOHUB_FUNC), + true, TYPE_REMOTE_IOHUB_DEVI= CE); + + s->iohub =3D 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); } =20 static void remote_set_socket(Object *obj, const char *str, Error **errp) diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 5ecbdd2dcf..9d8559b6d4 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -19,6 +19,9 @@ #include "qemu/error-report.h" #include "hw/pci/memory-sync.h" #include "qom/object.h" +#include "qemu/event_notifier.h" +#include "sysemu/kvm.h" +#include "util/event_notifier-posix.c" =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { @@ -57,6 +60,53 @@ static Property proxy_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static void proxy_intx_update(PCIDevice *pci_dev) +{ + PCIProxyDev *dev =3D PCI_PROXY_DEV(pci_dev); + PCIINTxRoute route; + int pin =3D pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + if (dev->irqfd.fd) { + dev->irqfd.flags =3D KVM_IRQFD_FLAG_DEASSIGN; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); + memset(&dev->irqfd, 0, sizeof(struct kvm_irqfd)); + } + + route =3D pci_device_route_intx_to_irq(pci_dev, pin); + + dev->irqfd.fd =3D event_notifier_get_fd(&dev->intr); + dev->irqfd.resamplefd =3D event_notifier_get_fd(&dev->resample); + dev->irqfd.gsi =3D route.irq; + dev->irqfd.flags |=3D KVM_IRQFD_FLAG_RESAMPLE; + (void) kvm_vm_ioctl(kvm_state, KVM_IRQFD, &dev->irqfd); +} + +static void setup_irqfd(PCIProxyDev *dev) +{ + PCIDevice *pci_dev =3D PCI_DEVICE(dev); + MPQemuMsg msg; + + event_notifier_init(&dev->intr, 0); + event_notifier_init(&dev->resample, 0); + + memset(&msg, 0, sizeof(MPQemuMsg)); + msg.cmd =3D SET_IRQFD; + msg.num_fds =3D 2; + msg.fds[0] =3D event_notifier_get_fd(&dev->intr); + msg.fds[1] =3D event_notifier_get_fd(&dev->resample); + msg.data1.set_irqfd.intx =3D + pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + msg.size =3D sizeof(msg.data1); + + mpqemu_msg_send(&msg, dev->dev); + + 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 pci_proxy_dev_realize(PCIDevice *device, Error **errp) { PCIProxyDev *dev =3D PCI_PROXY_DEV(device); @@ -72,6 +122,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Err= or **errp) } =20 configure_memory_sync(&dev->sync, dev->com); + + setup_irqfd(dev); } =20 static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, diff --git a/hw/remote/Makefile.objs b/hw/remote/Makefile.objs new file mode 100644 index 0000000000..635ce5e0ab --- /dev/null +++ b/hw/remote/Makefile.objs @@ -0,0 +1 @@ +common-obj-$(CONFIG_MPQEMU) +=3D iohub.o diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c new file mode 100644 index 0000000000..9c6cfaecd4 --- /dev/null +++ b/hw/remote/iohub.c @@ -0,0 +1,153 @@ +/* + * Remote IO Hub + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/pci/pci.h" +#include "hw/pci/pci_ids.h" +#include "hw/pci/pci_bus.h" +#include "hw/remote/iohub.h" +#include "qemu/thread.h" +#include "hw/boards.h" +#include "hw/i386/remote.h" +#include "qemu/main-loop.h" + +static void remote_iohub_initfn(Object *obj) +{ + RemoteIOHubState *iohub =3D REMOTE_IOHUB_DEVICE(obj); + int slot, intx, pirq; + + memset(&iohub->irqfds, 0, sizeof(iohub->irqfds)); + memset(&iohub->resamplefds, 0, sizeof(iohub->resamplefds)); + + for (slot =3D 0; slot < PCI_SLOT_MAX; slot++) { + for (intx =3D 0; intx < PCI_NUM_PINS; intx++) { + iohub->irq_num[slot][intx] =3D (slot + intx) % 4 + 4; + } + } + + for (pirq =3D 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { + qemu_mutex_init(&iohub->irq_level_lock[pirq]); + iohub->irq_level[pirq] =3D 0; + event_notifier_init_fd(&iohub->irqfds[pirq], -1); + event_notifier_init_fd(&iohub->resamplefds[pirq], -1); + } +} + +static void remote_iohub_class_init(ObjectClass *klass, void *data) +{ + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + k->vendor_id =3D PCI_VENDOR_ID_ORACLE; + k->device_id =3D PCI_DEVICE_ID_REMOTE_IOHUB; +} + +static const TypeInfo remote_iohub_info =3D { + .name =3D TYPE_REMOTE_IOHUB_DEVICE, + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(RemoteIOHubState), + .instance_init =3D remote_iohub_initfn, + .class_init =3D remote_iohub_class_init, + .interfaces =3D (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 =3D qdev_get_parent_bus(&pci_dev->qdev); + PCIBus *pci_bus =3D PCI_BUS(bus); + PCIDevice *pci_iohub =3D + pci_bus->devices[PCI_DEVFN(REMOTE_IOHUB_DEV, REMOTE_IOHUB_FUNC)]; + RemoteIOHubState *iohub =3D 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 =3D opaque; + + assert(pirq >=3D 0); + assert(pirq < REMOTE_IOHUB_NB_PIRQS); + + qemu_mutex_lock(&iohub->irq_level_lock[pirq]); + + if (level) { + if (++iohub->irq_level[pirq] =3D=3D 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 =3D opaque; + RemoteIOHubState *iohub =3D token->iohub; + int pirq, s; + + pirq =3D token->pirq; + + s =3D event_notifier_test_and_clear(&iohub->resamplefds[pirq]); + + assert(s >=3D 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 =3D REMOTE_MACHINE(current_machine); + RemoteIOHubState *iohub =3D machine->iohub; + int pirq; + + g_assert(msg->data1.set_irqfd.intx < 4); + g_assert(msg->num_fds =3D=3D 2); + + pirq =3D remote_iohub_map_irq(pci_dev, msg->data1.set_irqfd.intx); + + if (event_notifier_get_fd(&iohub->irqfds[pirq]) !=3D -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 =3D iohub; + iohub->token[pirq].pirq =3D pirq; + + qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL, + &iohub->token[pirq]); +} diff --git a/include/hw/i386/remote.h b/include/hw/i386/remote.h index c3890e57ab..6af423ab54 100644 --- a/include/hw/i386/remote.h +++ b/include/hw/i386/remote.h @@ -18,12 +18,14 @@ #include "hw/boards.h" #include "hw/pci-host/remote.h" #include "io/channel.h" +#include "hw/remote/iohub.h" =20 typedef struct RemMachineState { MachineState parent_obj; =20 RemotePCIHost *host; QIOChannel *ioc; + RemoteIOHubState *iohub; } RemMachineState; =20 #define TYPE_REMOTE_MACHINE "remote-machine" diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 11f8ab7149..bd0c17dc78 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 =20 +#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 =20 diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h index a41a6aeaa5..e6f076ae95 100644 --- a/include/hw/pci/proxy.h +++ b/include/hw/pci/proxy.h @@ -12,9 +12,12 @@ #include "qemu/osdep.h" #include "qemu-common.h" =20 +#include + #include "hw/pci/pci.h" #include "io/channel.h" #include "hw/pci/memory-sync.h" +#include "qemu/event_notifier.h" =20 #define TYPE_PCI_PROXY_DEV "pci-proxy-dev" =20 @@ -45,6 +48,11 @@ struct PCIProxyDev { =20 RemoteMemSync sync; =20 + struct kvm_irqfd irqfd; + + EventNotifier intr; + EventNotifier resample; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; =20 diff --git a/include/hw/remote/iohub.h b/include/hw/remote/iohub.h new file mode 100644 index 0000000000..9aacf3e04c --- /dev/null +++ b/include/hw/remote/iohub.h @@ -0,0 +1,50 @@ +/* + * IO Hub for remote device + * + * Copyright =C2=A9 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOHUB_H +#define REMOTE_IOHUB_H + +#include "qemu/osdep.h" +#include "qemu-common.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/io/mpqemu-link.h b/include/io/mpqemu-link.h index 0422213863..a563b557ce 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -42,6 +42,7 @@ typedef enum { PCI_CONFIG_READ, BAR_WRITE, BAR_READ, + SET_IRQFD, MAX =3D INT_MAX, } MPQemuCmd; =20 @@ -64,6 +65,10 @@ typedef struct { bool memory; } BarAccessMsg; =20 +typedef struct { + int intx; +} SetIrqFdMsg; + /** * Maximum size of data2 field in the message to be transmitted. */ @@ -92,6 +97,7 @@ typedef struct { uint64_t u64; SyncSysmemMsg sync_sysmem; BarAccessMsg bar_access; + SetIrqFdMsg set_irqfd; } data1; =20 int fds[REMOTE_MAX_FDS]; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 026e25dca4..561ac0576f 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -258,6 +258,7 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) break; case BAR_WRITE: case BAR_READ: + case SET_IRQFD: if (msg->size !=3D sizeof(msg->data1)) { return false; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278609; cv=none; d=zohomail.com; s=zohoarc; b=H6P8OIyCS4pFy7utlWYjKv1fBmsioteLL3VLVaH428AAmPW2xsG78lUOrC4c7TZQID6TBym44Pd5L/opfX7yi5RtHyp6OqJrgvBOSGlWAkt3ZXg5voezUQryPu5bD9Sr8zp8i+v7w5/PRd6nukLaYUQJNaBbL/UlAgmLzxB9Lwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278609; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YF0bbzvQlbn//cFkHghHM30Yolv8Z4AkTDb8vO2GHIQ=; b=RMkS21+UC88Py+wuFgaseRb59+D3ZCETTDZgsluLXOncWZz4uCpttFRhMaeUWdKh1A/rytG3KxAA8gO/QUACn+o23gubIPXpow7xksRO4sTXqa9ZW9ngRfkF4GHoibgOxzko63LvGuULPNCjXiLTjJ1xH5m7eCe48DFAWdEk+yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278608995788.437851894103; Sat, 27 Jun 2020 10:23:28 -0700 (PDT) Received: from localhost ([::1]:48168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEY3-0002Wc-Nw for importer@patchew.org; Sat, 27 Jun 2020 13:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENY-00031l-4V for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:37 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:53580) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpENU-0007UW-8y for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:12:35 -0400 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 05RHCO8F193179; Sat, 27 Jun 2020 17:12:24 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 31wxrms9b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:12:24 +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 05RH8mPK172225; Sat, 27 Jun 2020 17:10:23 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 31wwehn512-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:23 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAM5Q024371; Sat, 27 Jun 2020 17:10:22 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:22 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=YF0bbzvQlbn//cFkHghHM30Yolv8Z4AkTDb8vO2GHIQ=; b=IKjXULXo5uHQCzEqwFg7fMb9iC8meEpozenoK5v3DG2B9n+buA7NZfszs6pyJi2w0H2/ mIQ7kgnAEeKHBsl96WSic1NzKHb8oY40sZQod3doJdbRpt7EonCSff63aYTfURl15zlK IMniNBvP3t2o3H8G7d1qlynPtS9oh+YQDYxR8MA0Fkjbq9MdNbc0QseHSWUgV6VwDFE+ mBCMDXYW9KbMXoThS25XUWq1fIyfKrYKS6R4Y2pgl8nHguAaa2hk4vl8WvVYOmEzxh6q sLaWoLdFxHwU8ay5X1v9Iefu4nh4h6iFekL3KkjM9WSKkVeOcSPjf1BTcK514SFPjJB6 8w== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 17/21] multi-process: Retrieve PCI info from remote process Date: Sat, 27 Jun 2020 10:09:39 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 cotscore=-2147483648 lowpriorityscore=0 suspectscore=3 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.85; envelope-from=elena.ufimtseva@oracle.com; helo=userp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Jagannathan Raman 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 --- hw/i386/remote-msg.c | 23 +++++++++++ hw/pci/proxy.c | 89 ++++++++++++++++++++++++++++++++++++++++ include/io/mpqemu-link.h | 9 ++++ io/mpqemu-link.c | 5 +++ 4 files changed, 126 insertions(+) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 67fee4bb57..9379ee6442 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -20,6 +20,8 @@ static void process_config_read(QIOChannel *ioc, PCIDevic= e *dev, MPQemuMsg *msg); static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **err= p); static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp= ); +static void process_get_pci_info_msg(QIOChannel *ioc, MPQemuMsg *msg, + PCIDevice *pci_dev); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) @@ -71,6 +73,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, case SET_IRQFD: process_set_irqfd_msg(pci_dev, &msg); break; + case GET_PCI_INFO: + process_get_pci_info_msg(ioc, &msg, pci_dev); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -246,3 +251,21 @@ fail: =20 mpqemu_msg_send(&ret, ioc); } + +static void process_get_pci_info_msg(QIOChannel *ioc, MPQemuMsg *msg, + PCIDevice *pci_dev) +{ + PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(pci_dev); + MPQemuMsg ret =3D { 0 }; + + ret.cmd =3D RET_MSG; + + ret.data1.ret_pci_info.vendor_id =3D pc->vendor_id; + ret.data1.ret_pci_info.device_id =3D pc->device_id; + ret.data1.ret_pci_info.class_id =3D pc->class_id; + ret.data1.ret_pci_info.subsystem_id =3D pc->subsystem_id; + + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 9d8559b6d4..449341e459 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -23,6 +23,8 @@ #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" =20 +static void probe_pci_info(PCIDevice *dev); + static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { DeviceState *dev =3D DEVICE(pdev); @@ -110,6 +112,7 @@ static void setup_irqfd(PCIProxyDev *dev) static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { PCIProxyDev *dev =3D PCI_PROXY_DEV(device); + uint8_t *pci_conf =3D device->config; int proxyfd; =20 if (dev->fd) { @@ -121,9 +124,14 @@ static void pci_proxy_dev_realize(PCIDevice *device, E= rror **errp) proxy_set_socket(dev, proxyfd, errp); } =20 + pci_conf[PCI_LATENCY_TIMER] =3D 0xff; + pci_conf[PCI_INTERRUPT_PIN] =3D 0x01; + configure_memory_sync(&dev->sync, dev->com); =20 setup_irqfd(dev); + + probe_pci_info(PCI_DEVICE(dev)); } =20 static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, @@ -267,3 +275,84 @@ const MemoryRegionOps proxy_mr_ops =3D { .max_access_size =3D 1, }, }; + +static void probe_pci_info(PCIDevice *dev) +{ + PCIDeviceClass *pc =3D PCI_DEVICE_GET_CLASS(dev); + DeviceClass *dc =3D DEVICE_CLASS(pc); + PCIProxyDev *pdev =3D PCI_PROXY_DEV(dev); + MPQemuMsg msg =3D { 0 }, ret =3D { 0 }; + uint32_t orig_val, new_val, class; + uint8_t type; + int i, size; + char *name; + Error *local_err =3D NULL; + + msg.bytestream =3D 0; + msg.size =3D 0; + msg.cmd =3D GET_PCI_INFO; + + ret.data1.u64 =3D mpqemu_msg_send_reply_co(&msg, pdev->dev, &local_er= r); + if (local_err) { + error_report("Error while sending GET_PCI_INFO message"); + } + + pc->vendor_id =3D ret.data1.ret_pci_info.vendor_id; + pc->device_id =3D ret.data1.ret_pci_info.device_id; + pc->class_id =3D ret.data1.ret_pci_info.class_id; + pc->subsystem_id =3D ret.data1.ret_pci_info.subsystem_id; + + config_op_send(pdev, PCI_CLASS_DEVICE, &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 =3D 0; i < 6; i++) { + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, + PCI_CONFIG_READ); + new_val =3D 0xffffffff; + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, + PCI_CONFIG_WRITE); + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, + PCI_CONFIG_READ); + size =3D (~(new_val & 0xFFFFFFF0)) + 1; + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, + PCI_CONFIG_WRITE); + type =3D (new_val & 0x1) ? + PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMO= RY; + + if (size) { + pdev->region[i].dev =3D pdev; + pdev->region[i].present =3D true; + if (type =3D=3D PCI_BASE_ADDRESS_SPACE_MEMORY) { + pdev->region[i].memory =3D true; + } + name =3D g_strdup_printf("bar-region-%d", i); + memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), + &proxy_mr_ops, &pdev->region[i], + name, size); + pci_register_bar(dev, i, type, &pdev->region[i].mr); + g_free(name); + } + } +} diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index a563b557ce..4b96cb8ccb 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -43,6 +43,7 @@ typedef enum { BAR_WRITE, BAR_READ, SET_IRQFD, + GET_PCI_INFO, MAX =3D INT_MAX, } MPQemuCmd; =20 @@ -69,6 +70,13 @@ typedef struct { int intx; } SetIrqFdMsg; =20 +typedef struct { + uint16_t vendor_id; + uint16_t device_id; + uint16_t class_id; + uint16_t subsystem_id; +} RetPCIInfoMsg; + /** * Maximum size of data2 field in the message to be transmitted. */ @@ -98,6 +106,7 @@ typedef struct { SyncSysmemMsg sync_sysmem; BarAccessMsg bar_access; SetIrqFdMsg set_irqfd; + RetPCIInfoMsg ret_pci_info; } data1; =20 int fds[REMOTE_MAX_FDS]; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 561ac0576f..d09b2a2f50 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -263,6 +263,11 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case GET_PCI_INFO: + if (msg->size) { + return false; + } + break; default: break; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278137; cv=none; d=zohomail.com; s=zohoarc; b=emnUS4dWZQU3seFq4PhIJxD/38Ti2y94RITX8FXgGw0QbiAu8mq8bjzRePyd2Fg3ZPJPQE360L7ByTGnYM9Xr0ZFinJWr/8Xm1aTSP0JPoXluS/e7b6rondYhBOctIv5kHy8X+FY8TJ2r2FkID4wo3e23eVlyqVziv3AxPJ0WC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278137; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qllWI9fa6u/yVyuNXQBhUrQQ+jCVeLWDkqwJoPYzt5Y=; b=itwlitr3oTwulQ3K+2MCWwETLmV+KDdlJuuMPGNWwzEbNIOznA0V0L9CkJNUaAY5DIdN2vE0bck9XanhlOCO2e6KXPMdMqfulTVS5BVcB4tCn/BuLlmRYWTE7DwGEqhSrMfdCdeebbr8lfguQ7i6H5LN1+ByrKoG5vMiREfEPLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278137071418.913151217223; Sat, 27 Jun 2020 10:15:37 -0700 (PDT) Received: from localhost ([::1]:49228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEQR-00081F-SU for importer@patchew.org; Sat, 27 Jun 2020 13:15:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELd-0008TN-As for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:37 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELb-0007BE-56 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:36 -0400 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 05RH31c2034862; Sat, 27 Jun 2020 17:10:25 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 31wwhr9c9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:25 +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 05RH8TPe171840; Sat, 27 Jun 2020 17:10:25 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 31wwehn51j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:25 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAOQG024377; Sat, 27 Jun 2020 17:10:24 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:23 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=qllWI9fa6u/yVyuNXQBhUrQQ+jCVeLWDkqwJoPYzt5Y=; b=WLMXje3U0az2a+XjwWVvflgV4zu8xwDth4JkYX8MKH2cHIpVvJMJ44z61gzbSOkGCPGH +092avTiK2HM3idvvT9F4VehKEtfSPVSPoboKRoNZapMU5bDeFDp0vYtz/k8Ku0XLS7r ndGF7yTcu/jabIhVGOy3rN8jdSt6tw32pUyFCcJ2b3SRqw8ZStQ6bbcBcAsxh0kfN0RO Sd/k5eCpw9E7sg5cdL+CFC11Fy2iHoBqnRxaj8LAKZZszGFfc7OPDsOlizsUw0EU+Tpp p4PmgVjWEJr+PDEBFANKuc027U3cZUI4veQdTw9I/3G86JowrgglwWqe/OCBDIIbe8gx jg== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 18/21] multi-process: heartbeat messages to remote Date: Sat, 27 Jun 2020 10:09:40 -0700 Message-Id: X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 mlxscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. The remote process responds to this heartbeat message to confirm it is alive. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva --- hw/i386/remote-msg.c | 14 ++++++++++ hw/pci/proxy.c | 58 ++++++++++++++++++++++++++++++++++++++++ include/hw/pci/proxy.h | 2 ++ include/io/mpqemu-link.h | 1 + io/mpqemu-link.c | 1 + 5 files changed, 76 insertions(+) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 9379ee6442..919bddc1d5 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -22,6 +22,7 @@ static void process_bar_write(QIOChannel *ioc, MPQemuMsg = *msg, Error **errp); static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp= ); static void process_get_pci_info_msg(QIOChannel *ioc, MPQemuMsg *msg, PCIDevice *pci_dev); +static void process_proxy_ping_msg(QIOChannel *ioc); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) @@ -76,6 +77,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, case GET_PCI_INFO: process_get_pci_info_msg(ioc, &msg, pci_dev); break; + case PROXY_PING: + process_proxy_ping_msg(ioc); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -269,3 +273,13 @@ static void process_get_pci_info_msg(QIOChannel *ioc, = MPQemuMsg *msg, =20 mpqemu_msg_send(&ret, ioc); } + +static void process_proxy_ping_msg(QIOChannel *ioc) +{ + MPQemuMsg ret =3D { 0 }; + + ret.cmd =3D RET_MSG; + ret.size =3D sizeof(ret.data1); + + mpqemu_msg_send(&ret, ioc); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index 449341e459..e2e9a13287 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -24,6 +24,8 @@ #include "util/event_notifier-posix.c" =20 static void probe_pci_info(PCIDevice *dev); +static void start_hb_timer(PCIProxyDev *dev); +static void pci_proxy_dev_exit(PCIDevice *pdev); =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { @@ -132,6 +134,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Er= ror **errp) setup_irqfd(dev); =20 probe_pci_info(PCI_DEVICE(dev)); + + start_hb_timer(dev); } =20 static int config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, @@ -192,6 +196,7 @@ static void pci_proxy_dev_class_init(ObjectClass *klass= , void *data) k->realize =3D pci_proxy_dev_realize; k->config_read =3D pci_proxy_read_config; k->config_write =3D pci_proxy_write_config; + k->exit =3D pci_proxy_dev_exit; =20 device_class_set_props(dc, proxy_properties); } @@ -356,3 +361,56 @@ static void probe_pci_info(PCIDevice *dev) } } } + +static void hb_msg(PCIProxyDev *dev) +{ + DeviceState *ds =3D DEVICE(dev); + MPQemuMsg msg =3D { 0 }; + long ret =3D -EINVAL; + Error *local_err =3D NULL; + + msg.cmd =3D PROXY_PING; + msg.bytestream =3D 0; + msg.size =3D 0; + + ret =3D mpqemu_msg_send_reply_co(&msg, dev->com, &local_err); + if (local_err) { + error_report("Lost contact with remote device %s, error code %ld", + ds->id, ret); + } +} + +#define NOP_INTERVAL 1000 + +static void remote_ping(void *opaque) +{ + PCIProxyDev *dev =3D opaque; + + hb_msg(dev); + + timer_mod(dev->hb_timer, + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); +} + +static void start_hb_timer(PCIProxyDev *dev) +{ + dev->hb_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, + remote_ping, + dev); + + timer_mod(dev->hb_timer, + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NOP_INTERVAL); +} + +static void stop_hb_timer(PCIProxyDev *dev) +{ + timer_del(dev->hb_timer); + timer_free(dev->hb_timer); +} + +static void pci_proxy_dev_exit(PCIDevice *pdev) +{ + PCIProxyDev *dev =3D PCI_PROXY_DEV(pdev); + + stop_hb_timer(dev); +} diff --git a/include/hw/pci/proxy.h b/include/hw/pci/proxy.h index e6f076ae95..037740309d 100644 --- a/include/hw/pci/proxy.h +++ b/include/hw/pci/proxy.h @@ -53,6 +53,8 @@ struct PCIProxyDev { EventNotifier intr; EventNotifier resample; =20 + QEMUTimer *hb_timer; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; =20 diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 4b96cb8ccb..676d7eb3ef 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -44,6 +44,7 @@ typedef enum { BAR_READ, SET_IRQFD, GET_PCI_INFO, + PROXY_PING, MAX =3D INT_MAX, } MPQemuCmd; =20 diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index d09b2a2f50..7452e55e17 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -264,6 +264,7 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) } break; case GET_PCI_INFO: + case PROXY_PING: if (msg->size) { return false; } --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278162; cv=none; d=zohomail.com; s=zohoarc; b=B5zZoX14uOy+bGtbGjx9iTbnKGDqLQvifI/iVE435pHQHZ8S7WtVHUpz0felVcWbQJmIgqShlLYyDKhdJ/3CZIRWm2Vxasx/yR3iUyzlc4NZHS7fTyNX75eRBuqewC4uWjcDTzMUULx/X4W69yPq6c1X8rL59C+W2fXWlJb1KNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278162; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cpmn/SmI/LwjRmXxyhxkyqCczzoytGmIVE3OSnHrYRI=; b=OoduvHl1LeVpblR5FAFsmKUKubo4EPaHBCp0Z/2JP60YATK+zUA48gK1m0FEgHW4B3fa7XzBej6yg+emlHl7CH0pIPIs9sC7AbvfMGvi8pAZmEd24zq+XVXn0wfuZzq0m4HUDJs+GBFhvbitfGoNEiF7CVYl7g1ULw1Vy0qqUbs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278162731994.012699107363; Sat, 27 Jun 2020 10:16:02 -0700 (PDT) Received: from localhost ([::1]:50982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEQr-0000Gl-DO for importer@patchew.org; Sat, 27 Jun 2020 13:16:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELe-0008VR-Cm for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:38 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELc-0007BI-7S for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:37 -0400 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 05RH31u6034898; Sat, 27 Jun 2020 17:10:28 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 31wwhr9ca1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:27 +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 05RH7dPX195436; Sat, 27 Jun 2020 17:10:27 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 31wu7s8yb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:27 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAPQu030702; Sat, 27 Jun 2020 17:10:26 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:25 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=cpmn/SmI/LwjRmXxyhxkyqCczzoytGmIVE3OSnHrYRI=; b=hAsU+TOeBA4Z0o2jnglUkUA2PFjPARx++lKiUiV45BJna8CHniwYB4N6D0a1nLI7U7wV Y3ocFgkMrXxdH+cmR2tNnyUD3lji4OQP9vwL+h0IYhtW4aSMphu1+5h2eRbxpDATKnuJ VChgbCSC2iHo2PxOe8lAU9m9u8fFbbTgQPGd3Hm0zz+2r1GVpfYAKecTUN+7K9556ln6 MzAHyW7YSg1MLDRIKqr1cr6VrR/dvCVZST6C/FqNOjobOLcVv9313h0tvKs+XEjBTBdb jnOeqbznqRzbsU+rLlICkc7UEldXRm8ouvVcLEfti22TryJopiEuwt3KR9gOL0mTAZat 2A== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 19/21] multi-process: perform device reset in the remote process Date: Sat, 27 Jun 2020 10:09:41 -0700 Message-Id: <609039447d2d5dc85f47a34c906e416b54341998.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1015 cotscore=-2147483648 mlxscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=156.151.31.86; envelope-from=elena.ufimtseva@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:03:10 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva 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 --- hw/i386/remote-msg.c | 16 ++++++++++++++++ hw/pci/proxy.c | 20 ++++++++++++++++++++ include/io/mpqemu-link.h | 1 + 3 files changed, 37 insertions(+) diff --git a/hw/i386/remote-msg.c b/hw/i386/remote-msg.c index 919bddc1d5..63d2be4701 100644 --- a/hw/i386/remote-msg.c +++ b/hw/i386/remote-msg.c @@ -11,6 +11,7 @@ #include "exec/memattrs.h" #include "hw/i386/remote-memory.h" #include "hw/remote/iohub.h" +#include "sysemu/reset.h" =20 static void process_connect_dev_msg(MPQemuMsg *msg, QIOChannel *com, Error **errp); @@ -23,6 +24,7 @@ static void process_bar_read(QIOChannel *ioc, MPQemuMsg *= msg, Error **errp); static void process_get_pci_info_msg(QIOChannel *ioc, MPQemuMsg *msg, PCIDevice *pci_dev); static void process_proxy_ping_msg(QIOChannel *ioc); +static void process_device_reset_msg(QIOChannel *ioc); =20 gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition cond, gpointer opaque) @@ -80,6 +82,9 @@ gboolean mpqemu_process_msg(QIOChannel *ioc, GIOCondition= cond, case PROXY_PING: process_proxy_ping_msg(ioc); break; + case DEVICE_RESET: + process_device_reset_msg(ioc); + break; default: error_setg(&local_err, "Unknown command (%d) received from proxy \ in remote process pid=3D%d", msg.cmd, getpid()); @@ -283,3 +288,14 @@ static void process_proxy_ping_msg(QIOChannel *ioc) =20 mpqemu_msg_send(&ret, ioc); } + +static void process_device_reset_msg(QIOChannel *ioc) +{ + MPQemuMsg ret =3D { 0 }; + + qemu_devices_reset(); + + ret.cmd =3D RET_MSG; + + mpqemu_msg_send(&ret, ioc); +} diff --git a/hw/pci/proxy.c b/hw/pci/proxy.c index e2e9a13287..9cba2bec65 100644 --- a/hw/pci/proxy.c +++ b/hw/pci/proxy.c @@ -26,6 +26,7 @@ static void probe_pci_info(PCIDevice *dev); static void start_hb_timer(PCIProxyDev *dev); static void pci_proxy_dev_exit(PCIDevice *pdev); +static void proxy_device_reset(DeviceState *dev); =20 static void proxy_set_socket(PCIProxyDev *pdev, int fd, Error **errp) { @@ -198,6 +199,8 @@ static void pci_proxy_dev_class_init(ObjectClass *klass= , void *data) k->config_write =3D pci_proxy_write_config; k->exit =3D pci_proxy_dev_exit; =20 + dc->reset =3D proxy_device_reset; + device_class_set_props(dc, proxy_properties); } =20 @@ -414,3 +417,20 @@ static void pci_proxy_dev_exit(PCIDevice *pdev) =20 stop_hb_timer(dev); } + +static void proxy_device_reset(DeviceState *dev) +{ + PCIProxyDev *pdev =3D PCI_PROXY_DEV(dev); + MPQemuMsg msg =3D { 0 }; + Error *local_err =3D NULL; + + msg.bytestream =3D 0; + msg.size =3D sizeof(msg.data1); + msg.cmd =3D DEVICE_RESET; + + (void)mpqemu_msg_send_reply_co(&msg, pdev->com, &local_err); + if (local_err) { + error_report("Failed to send DEVICE_RESET to the remote process"); + } + +} diff --git a/include/io/mpqemu-link.h b/include/io/mpqemu-link.h index 676d7eb3ef..29dce60035 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -45,6 +45,7 @@ typedef enum { SET_IRQFD, GET_PCI_INFO, PROXY_PING, + DEVICE_RESET, MAX =3D INT_MAX, } MPQemuCmd; =20 --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278429; cv=none; d=zohomail.com; s=zohoarc; b=A28k1H0PQkMh6vxtFmHOrfJQPAQOi3pJTg9erGK13shZKOcNgYKX5WqpY/S/il5kPM7Q00vXoBr4YqP/Im6hY+RlM1MMIvIVqP0gb8m2EhqX8GTTK6SFPQrfsDI3DTQJ6uxBzWs6oBLQOBjC0niPe0PxDtSqoDoxRhj5THecBoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278429; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z/rsBgQkNpcGa6zRzyZPIiFBUZ6dbnYEgnrbEpcW1Qw=; b=IFQ3jYFmeqYK3RisEUNCIukaXLhzd2oK9YqFspuql0hpfhTIaVItMf+cFcY3IHEvFr8KvMfrc9a8UnJwiMNn047dn9g8Um9ahE0GQNMpI225JYSy+VnVow9Lb3knVdOPSThEDPuIfqbSxEn9cCW6TvDPsXE6hYO02C2HOQ4uunE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278429011864.1890816095581; Sat, 27 Jun 2020 10:20:29 -0700 (PDT) Received: from localhost ([::1]:40012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpEV9-0007N8-Hr for importer@patchew.org; Sat, 27 Jun 2020 13:20:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELi-0000CF-CF for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:42 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:47256) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELd-0007BP-Jw for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:41 -0400 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 05RH2xLk156757; Sat, 27 Jun 2020 17:10:30 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 31wx2m9ay1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:29 +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 05RH8GFi080851; Sat, 27 Jun 2020 17:10:29 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3030.oracle.com with ESMTP id 31wv59awth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:29 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHASdx024380; Sat, 27 Jun 2020 17:10:28 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:27 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=Z/rsBgQkNpcGa6zRzyZPIiFBUZ6dbnYEgnrbEpcW1Qw=; b=Pam6rD5OFCma+7HexX1P72bhZe7Cobliw6mDLkB9Zy/BK3Tgp/4T4YwQrU8Ww2mOj8Ch dlEXcXpXm2GDnwOd0Gh5whpIFEbjwo7qGReMl0/cxxy0Vz3ZSllp7aELmSCX31pEP99e OFzbseEJvboxGVcOAccpiw3n4ZYprN+R/KPiiCof3UV+UAZd9oKMxQ0/vX1Cv/GozMxB 6Czpf77+UG3Jtg4nSDGp82nml/G0oN8k9QrWdxSqXmvIrd2+yFipqthray2lb5Q8eMtJ S/J73CE/qL8CJwSHGQRY+fFeBdeqVXWuFdGhQX59Jk2C0QCXWsTUK9IN6wmmvCIG+HSi 3A== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 20/21] multi-process: add the concept description to docs/devel/qemu-multiprocess Date: Sat, 27 Jun 2020 10:09:42 -0700 Message-Id: <0dfdf845d65ed4b3976b4bb7f884a1fa92b6f153.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 suspectscore=3 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: John G Johnson Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman --- MAINTAINERS | 1 + docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 957 +++++++++++++++++++++++++++++++++++ 3 files changed, 959 insertions(+) create mode 100644 docs/devel/multi-process.rst diff --git a/MAINTAINERS b/MAINTAINERS index f9ede7e094..a65a5dd279 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2958,6 +2958,7 @@ F: hw/pci/memory-sync.c F: include/hw/pci/memory-sync.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h +F: docs/devel/multi-process.rst =20 Build and test automation ------------------------- diff --git a/docs/devel/index.rst b/docs/devel/index.rst index bb8238c5d6..8ed4369632 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -28,3 +28,4 @@ Contents: reset s390-dasd-ipl clocks + multi-process diff --git a/docs/devel/multi-process.rst b/docs/devel/multi-process.rst new file mode 100644 index 0000000000..406728854c --- /dev/null +++ b/docs/devel/multi-process.rst @@ -0,0 +1,957 @@ +Multi-process QEMU +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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 attacks because it is a large, +monolithic program that provides many features to the VMs it services. +Many of these features can be configured out of QEMU, but even a reduced +configuration QEMU has a large amount of code a guest can potentially +attack. Separating 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 multi-process QEMU +~~~~~~~~~~~~~~~~~~~~ + +A multi-process 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 to 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 multi-process mode, 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 multi-process 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. + +Separating IO services +---------------------- + +Separating IO services into individual host processes is a good place to +begin 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. The devices emulated in the separate process are +referred to as remote devices. + +QEMU device emulation +~~~~~~~~~~~~~~~~~~~~~ + +QEMU uses an 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=3Dfile,node-name=3Dfile0,filename=3Ddisk-fi= le0 \ + -blockdev driver=3Dqcow2,node-name=3Ddrive0,file=3Dfile0 + +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 +^^^^^^^^^^^^^^^^^^^^^^^ + +The first argument to the remote emulation process will be a Unix domain +socket that connects with the Proxy object. This is a required argument. + +:: + + disk-proc + +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 +~~~~~~~~~~~~~~~~~ + +Each remote device emulated in a remote process on the host is +represented as a *-device* of type *pci-proxy-dev*. A socket +sub-option to this option specifies the Unix socket that connects +to the remote process. An *id* sub-option is required, and it should +be the same id as used in the remote process. + +:: + + qemu-system-x86_64 ... -device pci-proxy-dev,id=3Dlsi0,socket=3D3 + +can be used to add a device emulated in a remote process + + +QEMU management of remote processes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +QEMU is not aware of the type of type of the remote PCI device. It is +a pass through device as far as QEMU is concerned. + +communication with emulation process +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +primary channel +''''''''''''''' + +The primary channel (referred to as com in the code) is used to bootstrap +the remote process. It is also used to pass on device-agnostic commands +like reset. + +per-device channels +''''''''''''''''''' + +Each remote device communicates with QEMU using a dedicated communication +channel. The proxy object sets up this channel using the primary +channel during its initialization. + +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. + +It is worth noting that the same proxy object is used to mediate with +all types of remote PCI devices. + +object initialization +^^^^^^^^^^^^^^^^^^^^^ + +The Proxy device objects are initialized in the exact same manner in +which any other QEMU device would be initialized. + +In addition, the Proxy objects perform the following two tasks: +- Parses the "socket" sub option and connects to the remote process +using this channel +- Uses the "id" sub-option to connect to the emulated device on the +separate process + +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 be 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 | ++=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ +| 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 | ++=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ +| 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 that will +be passed to the device emulation program. Only one slave can be created +by each master descriptor. The file operations performed by this +descriptor are described below. + +The *KVM\_DEV\_USER\_PA\_RANGE* command configures a guest physical +address range that the slave descriptor will receive MMIO notifications +for. The range is specified by a guest physical range structure +argument. For buses that assign addresses to devices dynamically, this +command can be executed while the guest is running, such as the case +when a guest changes a device's PCI BAR registers. + +*KVM\_DEV\_USER\_PA\_RANGE* will use ``kvm_io_bus_register_dev()`` to +register *kvm\_io\_device\_ops* callbacks to be invoked when the guest +performs a MMIO operation within the range. When a range is changed, +``kvm_io_bus_unregister_dev()`` is used to remove the previous +instantiation. + +*KVM\_DEV\_USER\_TIMEOUT* will configure a timeout value that specifies +how long KVM will wait for the emulation process to respond to a MMIO +indication. + +- 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 programmed 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. --=20 2.25.GIT From nobody Thu Apr 25 00:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1593278309; cv=none; d=zohomail.com; s=zohoarc; b=Chtg+0JTWZp0e0dSfGYUmeIw0JgV7JPOhDYFdHjJ8d+UX54o9FVyNYae/6fXFyZXMau5Z0tmPINVmKZO5yx/V62yTb8ODU8ItuXM2t6xnKsCicROgnLP1ILc4o41z3efKFewi6/Vq8Fk7Kz/TAcKaSk7Z2rJA2dU35IVqVfYP+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593278309; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ezXrBDecdyhEbNw6sVUbJWXX77mydgDvHdKqtavWP0k=; b=nSvmt/kyEg9JwWkfo4FUlTBuRATx1jXAP+B4cGRKao8W2VoTzex266E1GrtIPYUSIOuVqDGFoju5nLIERX64B2/QcAbE3uEpR1CXGmGBGDEZDjJySDwSoMKaH8x2LSflxIHI+tNxU1zCWRMi1NEUVUeHFzSBOKO+1Ofq/47e/9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593278309611480.13881597989086; Sat, 27 Jun 2020 10:18:29 -0700 (PDT) Received: from localhost ([::1]:59526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpETE-0003rf-3a for importer@patchew.org; Sat, 27 Jun 2020 13:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELg-00007q-E8 for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:40 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:47260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpELd-0007BR-WA for qemu-devel@nongnu.org; Sat, 27 Jun 2020 13:10:40 -0400 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 05RH4OtZ157820; Sat, 27 Jun 2020 17:10:31 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 31wx2m9ay3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sat, 27 Jun 2020 17:10:31 +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 05RH8Qpg102219; Sat, 27 Jun 2020 17:10:31 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 31wwx17sut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 27 Jun 2020 17:10:31 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 05RHAUtg024383; Sat, 27 Jun 2020 17:10:30 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Jun 2020 10:10:30 -0700 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 : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=ezXrBDecdyhEbNw6sVUbJWXX77mydgDvHdKqtavWP0k=; b=duZW3cb6Y6GBpiZgBE8TZgtB4mHFR3W/bmNF7wxbFocogpWRwk/Popw+m/xPE32RBMWw xeDtr08lMsbUDmnNpqybK6jGPD7eoL4tJ1ClT+R2zQjEN2FQGD+UMnv6LC93PMhRg6v0 9WoKp77CWoGJ1PdDx3R28q8+c7CUpVkueuvqRiJ4PBEhcpHiwVUbk4ImJBGERxh61XyS cS/t4q4ld/c4sPt6FQm5QIJZz1bfL5ov/1/Ejjq+BuIl2n2f1QTMd1pffuYwo68ZsXhO MdKxd+RlnIGces/l2DN02fqY36W3FwLfy25VSum9cdDyqIkVQhxbL4JbEs+i5ieSeSGg YQ== From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v7 21/21] multi-process: add configure and usage information Date: Sat, 27 Jun 2020 10:09:43 -0700 Message-Id: <3624d64f8943aea7f9867c10159e15b42cac77ff.1593273671.git.elena.ufimtseva@oracle.com> X-Mailer: git-send-email 2.25.GIT In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=1 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9665 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 impostorscore=0 cotscore=-2147483648 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=1 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006270123 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=141.146.126.78; envelope-from=elena.ufimtseva@oracle.com; helo=aserp2120.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/27 13:10:09 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson --- MAINTAINERS | 2 + docs/multi-process.rst | 71 ++++++++++++++++++++++++++++ scripts/mpqemu-launcher-perf-mode.py | 67 ++++++++++++++++++++++++++ scripts/mpqemu-launcher.py | 47 ++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 docs/multi-process.rst create mode 100644 scripts/mpqemu-launcher-perf-mode.py create mode 100755 scripts/mpqemu-launcher.py diff --git a/MAINTAINERS b/MAINTAINERS index a65a5dd279..60c21d8210 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2959,6 +2959,8 @@ F: include/hw/pci/memory-sync.h F: hw/remote/iohub.c F: include/hw/remote/iohub.h F: docs/devel/multi-process.rst +F: scripts/mpqemu-launcher.py +F: scripts/mpqemu-launcher-perf-mode.py =20 Build and test automation ------------------------- diff --git a/docs/multi-process.rst b/docs/multi-process.rst new file mode 100644 index 0000000000..0fa643a511 --- /dev/null +++ b/docs/multi-process.rst @@ -0,0 +1,71 @@ +Multi-process QEMU +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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 +-------- + +Multi-process QEMU requires an orchestrator to launch. Please refer to a +light-weight python based orchestrator for mpqemu in +scripts/mpqemu-launcher.py to lauch QEMU in multi-process mode. + +Please refer to scripts/mpqemu-launcher-perf-mode.py for running the remote +process in performance mode. + +As of now, we only support the emulation of lsi53c895a in a separate proce= ss. + +Following is a description of command-line used to launch mpqemu. + +* Orchestrator: + + - The Orchestrator creates a unix socketpair + + - It launches the remote process and passes one of the + sockets to it via command-line. + + - It then launches QEMU and specifies the other socket as an option + to the Proxy device object + +* Remote Process: + + - QEMU can enter remote process mode by using the "remote" machine + option. The socket suboption specifies the channel in which the + remote process received messages + + - The remaining options are no different from how one launches QEMU with + devices. The only other requirement is each PCI device must have a + unique ID specified to it. This is needed to pair remote device with t= he + Proxy object. + + - Example command-line for the remote process is as follows: + + /usr/bin/qemu-system-x86_64 \ + -machine remote,socket=3D4 = \ + -device lsi53c895a,id=3Dlsi0 = \ + -drive id=3Ddrive_image2,file=3D/build/ol7-nvme-test-1.qcow2 = \ + -device scsi-hd,id=3Ddrive2,drive=3Ddrive_image2,bus=3Dlsi0.0,scsi-i= d=3D0 + +* QEMU: + + - Since parts of the RAM are shared between QEMU & remote process, a + memory-backend-memfd is required to facilitate this, as follows: + + -object memory-backend-memfd,id=3Dmem,size=3D2G + + - A "pci-proxy-dev" device is created for each of the PCI devices emulat= ed + in the remote process. A "socket" sub-option specifies the other end of + unix channel created by orchestrator. The "id" sub-option must be spec= ified + and should be the same as the "id" specified for the remote PCI device + + - Example commandline for QEMU is as follows: + + -device pci-proxy-dev,id=3Dlsi0,socket=3D3 diff --git a/scripts/mpqemu-launcher-perf-mode.py b/scripts/mpqemu-launcher= -perf-mode.py new file mode 100644 index 0000000000..583f65ca99 --- /dev/null +++ b/scripts/mpqemu-launcher-perf-mode.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import socket +import os +import subprocess +import time + +PROC_QEMU=3D'/usr/bin/qemu-system-x86_64' + +proxy_1, remote_1 =3D socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM) +proxy_2, remote_2 =3D socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM) + +remote_cmd_1 =3D [ PROC_QEMU, = \ + '-machine', 'remote,socket=3D'+str(remote_1.fileno()), = \ + '-device', 'lsi53c895a,id=3Dlsi1', = \ + '-drive', 'id=3Ddrive_image1,file=3D/test-1.qcow2', = \ + '-device', 'scsi-hd,id=3Ddrive1,drive=3Ddrive_image1,bus= =3Dlsi1.0,' \ + 'scsi-id=3D0', = \ + '-nographic', = \ + ] + +remote_cmd_2 =3D [ PROC_QEMU, = \ + '-machine', 'remote,socket=3D'+str(remote_2.fileno()), = \ + '-device', 'lsi53c895a,id=3Dlsi2', = \ + '-drive', 'id=3Ddrive_image2,file=3D/test-2.qcow2', = \ + '-device', 'scsi-hd,id=3Ddrive2,drive=3Ddrive_image2,bus= =3Dlsi2.0,' \ + 'scsi-id=3D0', = \ + '-nographic', = \ + ] + +proxy_cmd =3D [ PROC_QEMU, = \ + '-name', 'OL7.4', = \ + '-machine', 'q35,accel=3Dkvm', = \ + '-smp', 'sockets=3D1,cores=3D1,threads=3D1', = \ + '-m', '2048', = \ + '-object', 'memory-backend-memfd,id=3Dsysmem-file,size=3D2G'= , \ + '-numa', 'node,memdev=3Dsysmem-file', = \ + '-device', 'virtio-scsi-pci,id=3Dvirtio_scsi_pci0', = \ + '-drive', 'id=3Ddrive_image1,if=3Dnone,format=3Dqcow2,' = \ + 'file=3D/home/ol7-hdd-1.qcow2', = \ + '-device', 'scsi-hd,id=3Dimage1,drive=3Ddrive_image1,' = \ + 'bus=3Dvirtio_scsi_pci0.0', = \ + '-boot', 'd', = \ + '-vnc', ':0', = \ + '-device', 'pci-proxy-dev,id=3Dlsi1,fd=3D'+str(proxy_1.filen= o()), \ + '-device', 'pci-proxy-dev,id=3Dlsi2,fd=3D'+str(proxy_2.filen= o()), \ + ] + + +pid =3D os.fork(); +if pid =3D=3D 0: + # In remote_1 + print('Launching Remote process 1'); + process =3D subprocess.Popen(remote_cmd_1, pass_fds=3D[remote_1.fileno= ()]) + os._exit(0) + + +pid =3D os.fork(); +if pid =3D=3D 0: + # In remote_2 + print('Launching Remote process 2'); + process =3D subprocess.Popen(remote_cmd_2, pass_fds=3D[remote_2.fileno= ()]) + os._exit(0) + + +print('Launching Proxy process'); +process =3D subprocess.Popen(proxy_cmd, pass_fds=3D[proxy_1.fileno(), + proxy_2.fileno()]) diff --git a/scripts/mpqemu-launcher.py b/scripts/mpqemu-launcher.py new file mode 100755 index 0000000000..751b51eae7 --- /dev/null +++ b/scripts/mpqemu-launcher.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +import socket +import os +import subprocess +import time + +PROC_QEMU=3D'/usr/bin/qemu-system-x86_64' + +proxy, remote =3D socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM) + +remote_cmd =3D [ PROC_QEMU, = \ + '-machine', 'remote,socket=3D'+str(remote.fileno()), = \ + '-device', 'lsi53c895a,id=3Dlsi1', = \ + '-drive', 'id=3Ddrive_image1,file=3D/build/ol7-nvme-test-1.= qcow2', \ + '-device', 'scsi-hd,id=3Ddrive1,drive=3Ddrive_image1,bus=3D= lsi1.0,' \ + 'scsi-id=3D0', = \ + '-nographic', = \ + ] + +proxy_cmd =3D [ PROC_QEMU, = \ + '-name', 'OL7.4', = \ + '-machine', 'q35,accel=3Dkvm', = \ + '-smp', 'sockets=3D1,cores=3D1,threads=3D1', = \ + '-m', '2048', = \ + '-object', 'memory-backend-memfd,id=3Dsysmem-file,size=3D2G'= , \ + '-numa', 'node,memdev=3Dsysmem-file', = \ + '-device', 'virtio-scsi-pci,id=3Dvirtio_scsi_pci0', = \ + '-drive', 'id=3Ddrive_image1,if=3Dnone,format=3Dqcow2,' = \ + 'file=3D/home/ol7-hdd-1.qcow2', = \ + '-device', 'scsi-hd,id=3Dimage1,drive=3Ddrive_image1,' = \ + 'bus=3Dvirtio_scsi_pci0.0', = \ + '-boot', 'd', = \ + '-vnc', ':0', = \ + '-device', 'pci-proxy-dev,id=3Dlsi1,fd=3D'+str(proxy.fileno(= )), \ + ] + + +pid =3D os.fork(); + +if pid: + # In Proxy + print('Launching QEMU with Proxy object'); + process =3D subprocess.Popen(proxy_cmd, pass_fds=3D[proxy.fileno()]) +else: + # In remote + print('Launching Remote process'); + process =3D subprocess.Popen(remote_cmd, pass_fds=3D[remote.fileno()]) --=20 2.25.GIT