From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A54A6C4363A for ; Mon, 5 Oct 2020 18:57:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2362F20853 for ; Mon, 5 Oct 2020 18:57:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="A91B3kwo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2362F20853 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPVfY-0004aZ-7z for qemu-devel@archiver.kernel.org; Mon, 05 Oct 2020 14:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPVaE-0006gZ-M0 for qemu-devel@nongnu.org; Mon, 05 Oct 2020 14:51:38 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:56408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPVaB-000847-62 for qemu-devel@nongnu.org; Mon, 05 Oct 2020 14:51:38 -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 095InRwO184669; Mon, 5 Oct 2020 18:51:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=TxbYluq6P+wdVO3WejpM0UCI4Gev1IIpPMAx0KMXa60=; b=A91B3kwoQ5IJQB0Oy4UrOmc3KLqlPcOcfqQxIK5l4rz1/StGZgPIT2WrpBaZgiMJXZMu AvKO5OE0pHUtfGlH3tAm9obms9SdONpv7xKPsQqftUhQ50FIHhfe4jDNyh15aBMR45OT +Z705DzJyRaxdqWLXpUf70TBjgJQhQaDUSdAxUfnWJhAOpIqudXhRYbw6bIjQteJLW5Z ubGqa7z0cY0Q3P7dhqmK7Z38TFaexqL2tEZoxY8owql44nnILQm7XYH4EaN5xIyol4SE KBQn4EBAk9KYRnpRtQkwrQlZPsI1GebbarWYlryijIkGR4YiTw+IFFODZvgxQf53QS+s ww== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2120.oracle.com with ESMTP id 33xhxmq551-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 05 Oct 2020 18:51:27 +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 095IpDqn182601; Mon, 5 Oct 2020 18:51:26 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 33y2vkvf8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Oct 2020 18:51:26 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 095IpPnl001930; Mon, 5 Oct 2020 18:51:26 GMT Received: from flaka.hsd1.ca.comcast.net (/67.180.143.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Oct 2020 11:51:25 -0700 From: elena.ufimtseva@oracle.com To: qemu-devel@nongnu.org Subject: [PATCH v10 09/19] multi-process: setup memory manager for remote device Date: Mon, 5 Oct 2020 11:50:57 -0700 Message-Id: <206d07ba1eeedcd42bdfff8d828a086c7dc8fe93.1601923020.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: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9765 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 malwarescore=0 suspectscore=4 spamscore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010050136 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9765 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=4 phishscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 spamscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2010050136 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/10/05 12:40:53 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, 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=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no 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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Stefan Hajnoczi --- MAINTAINERS | 2 ++ hw/i386/meson.build | 1 + hw/i386/remote-memory.c | 58 +++++++++++++++++++++++++++++++++ include/hw/i386/remote-memory.h | 19 +++++++++++ include/io/mpqemu-link.h | 13 ++++++++ io/mpqemu-link.c | 11 +++++++ 6 files changed, 104 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 ac8eefaa3f..14b8c005fc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3050,6 +3050,8 @@ F: include/io/mpqemu-link.h F: hw/i386/remote-msg.c F: include/hw/i386/remote-obj.h F: hw/i386/remote-obj.c +F: include/hw/i386/remote-memory.h +F: hw/i386/remote-memory.c Build and test automation ------------------------- diff --git a/hw/i386/meson.build b/hw/i386/meson.build index 7b35f35d86..36e151c80a 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -26,6 +26,7 @@ i386_ss.add(when: 'CONFIG_PC', if_true: files( i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-msg.c')) i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-obj.c')) +i386_ss.add(when: 'CONFIG_MPQEMU', if_true: files('remote-memory.c')) subdir('kvm') subdir('xen') diff --git a/hw/i386/remote-memory.c b/hw/i386/remote-memory.c new file mode 100644 index 0000000000..27bc8a7674 --- /dev/null +++ b/hw/i386/remote-memory.c @@ -0,0 +1,58 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "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 = &msg->data.sync_sysmem; + MemoryRegion *sysmem, *subregion, *next; + static unsigned int suffix; + Error *local_err = NULL; + char *name; + int region; + + sysmem = get_system_memory(); + + memory_region_transaction_begin(); + + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) { + if (subregion->ram) { + memory_region_del_subregion(sysmem, subregion); + object_unparent(OBJECT(subregion)); + } + } + + for (region = 0; region < msg->num_fds; region++) { + subregion = g_new(MemoryRegion, 1); + name = g_strdup_printf("remote-mem-%u", suffix++); + memory_region_init_ram_from_fd(subregion, NULL, + 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-memory.h new file mode 100644 index 0000000000..aab3e4d85d --- /dev/null +++ b/include/hw/i386/remote-memory.h @@ -0,0 +1,19 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2020 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_MEMORY_H +#define REMOTE_MEMORY_H + +#include "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 3505e062dd..e33181ad80 100644 --- a/include/io/mpqemu-link.h +++ b/include/io/mpqemu-link.h @@ -14,6 +14,7 @@ #include "qom/object.h" #include "qemu/thread.h" #include "io/channel.h" +#include "exec/hwaddr.h" #define REMOTE_MAX_FDS 8 @@ -24,12 +25,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 { MPQEMU_CMD_INIT, + SYNC_SYSMEM, + RET_MSG, MPQEMU_CMD_MAX, } MPQemuCmd; +typedef struct { + hwaddr gpas[REMOTE_MAX_FDS]; + uint64_t sizes[REMOTE_MAX_FDS]; + off_t offsets[REMOTE_MAX_FDS]; +} SyncSysmemMsg; + /** * MPQemuMsg: * @cmd: The remote command @@ -40,12 +51,14 @@ typedef enum { * MPQemuMsg Format of the message sent to the remote device from QEMU. * */ + typedef struct { int cmd; size_t size; union { uint64_t u64; + SyncSysmemMsg sync_sysmem; } data; int fds[REMOTE_MAX_FDS]; diff --git a/io/mpqemu-link.c b/io/mpqemu-link.c index 42df2af229..8d966820a0 100644 --- a/io/mpqemu-link.c +++ b/io/mpqemu-link.c @@ -226,5 +226,16 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) } } + /* Verify message specific fields. */ + switch (msg->cmd) { + case SYNC_SYSMEM: + if (msg->num_fds == 0 || msg->size != sizeof(SyncSysmemMsg)) { + return false; + } + break; + default: + break; + } + return true; } -- 2.25.GIT