From patchwork Tue Jan 19 20:28:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030801 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 09BA5C433E0 for ; Tue, 19 Jan 2021 20:59:27 +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 40CBA22CE3 for ; Tue, 19 Jan 2021 20:59:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 40CBA22CE3 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]:59038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y61-0000k4-57 for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:59:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcl-0000re-Hk for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:11 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcf-0000DO-Bq for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:11 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNZTU002862; Tue, 19 Jan 2021 20:28:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=1D3Xl+6bA0dO7YKjq3v4RngZZ+PutAtTeViShVttDX0=; b=XYGvAVa1QPhEX0qnqEUIRmNRQweigFRsNOJGEfD7N992ZnEzGjx+BmWixrT4r0meN0YP RkO/NtFVsYOG5gbpNe2hkQOABocmkKfkHZfe3rplc7XlskpwECQXeoyEuLnjvt6mcDHv l2os/dOuNOjRj4J1Rs8nsShHUYu38OPT/hj03nPus44jhQofFDtpx1l4uuUYrsufo6ke B+gAmxb6OmgPswJ9kPSnZXaYfLO8AiOfhE6S/bzYHQWb+MBrEdH1az2VHs8p+D/lHjuS 89Vp9y01hIM+mjj3tIS3wUw4zCSYDq/1ZeiNtA6C49qJst7az4etA887tGK1vSUHdvOq nA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 363xyhtar2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:50 +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 10JKPj0x175988; Tue, 19 Jan 2021 20:28:49 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2057.outbound.protection.outlook.com [104.47.37.57]) by aserp3020.oracle.com with ESMTP id 3661er93wg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OTWRl+Xn7PCzBIqSqDOtpIBPwnhab5DvbrhJNuMr6+EI6pXZtfuaHUO3w+6glsUiHuwpMi+G9qh+4irUnS2u9OzHh2unk8XRp1deL+7hsgQbqVo42h8w8ddQkT6B47bAC5Go3Q9CbO8HFyrGzIHrnvYYbxxk2L8wqz8VVMbqq0Y/z3x731Zx5kQ52GlyI0fEqxxM0rwZ+LFe3dR144er0Eh9gOQqGMzoakSG035NerkaC+CTfr5R83hETINm3FmxQsNtVu338q7QETxIWaXM9FhIVfLHV+s2bH/UfGNK+9M1Br/uI3mnZWDIdXuPvOynem3lnl7UCDQdnGf5D+1gzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1D3Xl+6bA0dO7YKjq3v4RngZZ+PutAtTeViShVttDX0=; b=RZqbdgr0JTGNWCEgK/ms9KQA6b/eq/x6D5PXho2TnjYbJRORyp/GFjkR8XNLoL+ATJDLCMhAFae3J+BJbQXkW9kTENfJYGC06wsGtZxErfPVMW/35BYpTaRUe2bYvEKUQqJQHWLl+mEJ+Mi4ArlnLA9NHLdFFNu161q0VNNHmnQ/1OXB90MZdgvmObzG6Tdmvo5PWs/e8O0yhpU8n1OBncO0w4STS72c2cMVKbHGIM8zXseNoBCpisPQSW+9yNi93SUkbe6HHMfJ+vSQARkLzw8a5cgp13SZajjcukLmjKa/7WkXCITP+hdxp0H7q5WjUbMxmMS5G/3rjvo6iNBCFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1D3Xl+6bA0dO7YKjq3v4RngZZ+PutAtTeViShVttDX0=; b=GI8hm5FkMpHVMNu5MN7sBKkzYpR5vErWmYIcP0IP5JjRHkeX+S7YSIVY8vUsT1O7qgWTCa3USfBg5iYLBGt87xzmpgJq7l1OsxEY0Ph5NMZz/6L4zNJuSmRiIqz54jNm1Q3DQz2C+L/DdtukP0o2RhprlDPoKx/i4Ill4EpgRz8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:28:46 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:28:46 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 01/20] multi-process: add the concept description to docs/devel/qemu-multiprocess Date: Tue, 19 Jan 2021 15:28:18 -0500 Message-Id: <32d4ecfc33e9d1dc875ea39f9cfb4d990c8a4934.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3469bde-408e-4aae-e373-08d8bcb8d24e X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M63s6hxm1Q8wEm//RXBEsoitl1KKLNMJFLKb/uCn7B4ED1Qj8W1PWAMyARrrFG212Tbic5lD7udDT7IGIZqbPs5HvHAG36ffgdGmrpxb5VRg3fSrGpWmIfDrlrO2j3M0mQY8nzJmoTcNm3UhtVIS8/n+PY9h9VkJYfTwlemT4Efbqd02U9LW27HI51ydZL/6g/ly3mWz08uqGaG9wYX5xOaeRO3sjNrVDv8B3lJD4xAL7LnuMC++Yr9H9mUM4XyttNZY8fkyrUYYSsOVZeDjkr3gliPyvx/X7Pd7oum7VQfEMaSweyjoUpaAnxlx3AkxDrI+aVGbQpCPu0QBS55eigYf1AOLfqLnZ2SiSryesTuMHY5cwN/jjWGj4X0j82N/ZEWD5EtBSyui5uTkqMBM7fFJmcT6vD2VV0h+8+Y9d3An0kMZoV7dmnSyIIC2soD8c6PtJRbbEikL5Owpes/JWg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(30864003)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: bPoZnIRwwNjWNF51+ZwO+3+n92xYuUdLk9P6+C5ehuBJ+VJ1etqYS5SdakBlcxaHaDmcrskpOVaBMJ5GZ0Ibpxxw5XTPrJZb0w/yUmTmqLfOZwjZj61XP2FZ9gRLJvhdofFBysiDK1XtMDxq1l+L6Tw0OysIBO1OMPtPbqGcvalspILIEvhPdcIZV5xSLx+/bQfcsVlwKrFfsbuNvI1laI8iDsBNNdZ88whLsvAJu/KR6OIKqcevLYFKalZqd5+Z4iTyiNflcOst6NA7PV7lwrCZwVZhTQc6qTVqjA0oJuRgQYlEswrb+zB9ZXum4iikZFIzFWoJ4/DtG59d9ocJCs0U6S37F6RW64SrxKBM+bErkcUgEQVH+o3Z+NR0fae3Dg3svco0ok+HWnp07qFXnETgWbxeaghnY7/OYcO7XZZkhOhR5IHohPykMsonCF2CzI7fbnahu/1AwcjtHp8Vd+LN/uEJVuH9kDQ7g9r0rZikyUaqyVFsNi5A9D/RQ22U6HE8CAKRPTlw7UsHbY0veZJaAGiK50+ul20RsJNx2GUCF2uolTbfwZ7eO+yhUOIs/mnXCG9yX2FtKp0IRb3OsTWdf2ogH4V0IZNuponh1/VMwCykGcJ64PL/lo4TAXM91FwxbW/yFJj79Raw31PpykET5RQ/DGqMkhYNQb6rfG/VhfYG21CJkX8VIA9kfhoMSyUSVNJGYWbsKAqkMGLxJExMTSMmX3TRjyC4LzJ79NZWhSPctly+5eQYf7qc+SymFuMJf4jHb4NmWueY9924ACKTcoPyn8rjXobFKrN5NeERyOfUvZk4zHLRwavwpIUnB5YKK4T3tZbGUF2ckD+WlLqDIYCU+dDg+isE8v8nMJ0FyL+Q8CEQ0mMRqMAmyyVHkH5f+6EEKZ4M+39Y9bQa+RxLje0s2Dhd12OO4rgzIo3KtW/HcdQbp3nKMV4p6MZ/whCxLR6K+mUg3du7+qyNqFJT25CPqyXW6KuTcfMm938= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3469bde-408e-4aae-e373-08d8bcb8d24e X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:28:46.4033 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HCcLro7DOlqLFFDWCGRB9HlYqHTGFlTaSxGTHH2VIZNdf4yGvvd6AY0F082SBUnhrZxLjwDWrD4OfeI9mmOAWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: John G Johnson Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- docs/devel/index.rst | 1 + docs/devel/multi-process.rst | 966 +++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 7 + 3 files changed, 974 insertions(+) create mode 100644 docs/devel/multi-process.rst diff --git a/docs/devel/index.rst b/docs/devel/index.rst index ea0e1e1..5ccaf8b 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -36,3 +36,4 @@ Contents: clocks qom block-coroutine-wrapper + multi-process diff --git a/docs/devel/multi-process.rst b/docs/devel/multi-process.rst new file mode 100644 index 0000000..6969932 --- /dev/null +++ b/docs/devel/multi-process.rst @@ -0,0 +1,966 @@ +This is the design document for multi-process QEMU. It does not +necessarily reflect the status of the current implementation, which +may lack features or be considerably different from what is described +in this document. This document is still useful as a description of +the goals and general direction of this feature. + +Please refer to the following wiki for latest details: +https://wiki.qemu.org/Features/MultiProcessQEMU + +Multi-process QEMU +=================== + +QEMU is often used as the hypervisor for virtual machines running in the +Oracle cloud. Since one of the advantages of cloud computing is the +ability to run many VMs from different tenants in the same cloud +infrastructure, a guest that compromised its hypervisor could +potentially use the hypervisor's access privileges to access data it is +not authorized for. + +QEMU can be susceptible to security 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=file,node-name=file0,filename=disk-file0 \ + -blockdev driver=qcow2,node-name=drive0,file=file0 + +would indicate process *disk-proc* uses a qcow2 emulated disk named +*file0* as its backend. + +Emulation processes may emulate more than one guest controller. A common +configuration might be to put all controllers of the same device class +(e.g., disk, network, etc.) in a single process, so that all backends of +the same type can be managed by a single QMP monitor. + +communication with QEMU +^^^^^^^^^^^^^^^^^^^^^^^ + +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=lsi0,socket=3 + +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 | ++========+============================+ +| addr | range base address | ++--------+----------------------------+ +| len | range length | ++--------+----------------------------+ +| bus | addr type (memory or IO) | ++--------+----------------------------+ +| id | range ID (e.g., PCI BAR) | ++--------+----------------------------+ + +- MMIO request structure + +This structure describes an MMIO operation. It includes which guest +physical range the MMIO was within, the offset within that range, the +MMIO type (e.g., load or store), and its length and data. It also +includes a sequence number that can be used to reply to the MMIO, and +the CPU that issued the MMIO. + ++----------+------------------------+ +| Name | Description | ++==========+========================+ +| rid | range MMIO is within | ++----------+------------------------+ +| offset | offset withing *rid* | ++----------+------------------------+ +| type | e.g., load or store | ++----------+------------------------+ +| len | MMIO length | ++----------+------------------------+ +| data | store data | ++----------+------------------------+ +| seq | sequence ID | ++----------+------------------------+ + +- MMIO request queues + +MMIO request queues are FIFO arrays of MMIO request structures. There +are two queues: pending queue is for MMIOs that haven't been read by the +emulation program, and the sent queue is for MMIOs that haven't been +acknowledged. The main use of the second queue is to validate MMIO +replies from the emulation program. + +- scoreboard + +Each CPU in the VM is emulated in QEMU by a separate thread, so multiple +MMIOs may be waiting to be consumed by an emulation program and multiple +threads may be waiting for MMIO replies. The scoreboard would contain a +wait queue and sequence number for the per-CPU threads, allowing them to +be individually woken when the MMIO reply is received from the emulation +program. It also tracks the number of posted MMIO stores to the device +that haven't been replied to, in order to satisfy the PCI constraint +that a load to a device will not complete until all previous stores to +that device have been completed. + +- device shadow memory + +Some MMIO loads do not have device side-effects. These MMIOs can be +completed without sending a MMIO request to the emulation program if the +emulation program shares a shadow image of the device's memory image +with the KVM driver. + +The emulation program will ask the KVM driver to allocate memory for the +shadow image, and will then use ``mmap()`` to directly access it. The +emulation program can control KVM access to the shadow image by sending +KVM an access map telling it which areas of the image have no +side-effects (and can be completed immediately), and which require a +MMIO request to the emulation program. The access map can also inform +the KVM drive which size accesses are allowed to the image. + +master descriptor +^^^^^^^^^^^^^^^^^ + +The master descriptor is used by QEMU to configure the new KVM device. +The descriptor would be returned by the KVM driver when QEMU issues a +*KVM\_CREATE\_DEVICE* ``ioctl()`` with a *KVM\_DEV\_TYPE\_USER* type. + +KVM\_DEV\_TYPE\_USER device ops + + +The *KVM\_DEV\_TYPE\_USER* operations vector will be registered by a +``kvm_register_device_ops()`` call when the KVM system in initialized by +``kvm_init()``. These device ops are called by the KVM driver when QEMU +executes certain ``ioctl()`` operations on its KVM file descriptor. They +include: + +- create + +This routine is called when QEMU issues a *KVM\_CREATE\_DEVICE* +``ioctl()`` on its per-VM file descriptor. It will allocate and +initialize a KVM user device specific data structure, and assign the +*kvm\_device* private field to it. + +- ioctl + +This routine is invoked when QEMU issues an ``ioctl()`` on the master +descriptor. The ``ioctl()`` commands supported are defined by the KVM +device type. *KVM\_DEV\_TYPE\_USER* ones will need several commands: + +*KVM\_DEV\_USER\_SLAVE\_FD* creates the slave file descriptor 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. diff --git a/MAINTAINERS b/MAINTAINERS index 3216387..56f1904 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3182,6 +3182,13 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ +Multi-process QEMU +M: Elena Ufimtseva +M: Jagannathan Raman +M: John G Johnson +S: Maintained +F: docs/devel/multi-process.rst + Build and test automation ------------------------- Build and test automation From patchwork Tue Jan 19 20:28:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030759 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 3FD10C433E6 for ; Tue, 19 Jan 2021 20:45:48 +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 5179623107 for ; Tue, 19 Jan 2021 20:45:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5179623107 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]:54870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xso-00037W-5u for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:45:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcj-0000nM-4e for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:09 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcf-0000DN-BL for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:08 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUw8002764; Tue, 19 Jan 2021 20:28:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=oApzKfjFWBVZxSOptENDI7tXlTD9jnhg+UQVZ1f7qlA=; b=kozAwTrvIVLQZlgmKeldvg4+mtbEcozJS7X6B+OeHo4TRgTFS7m4DTXg8HsgsN9h+i6B uu3/BroG0lO4ZSrQ+vIPsSEJQIhTNNxc+wJ5RrrI717ZQCmPkQr7YgYETgHOdQTbVTAb 0EnXR/EehxIqQFfKpD0Wzcsn9UZKu2DEt+1wOV68+gDeR1EpZA9rUAqT+2v3xyGqQ8wK o/YU4gvjG3AOgPxirtBc8fCgeW4MosEIiIUhXVnckNT/Xax+xrQdSjiu4lWdC1EJIV43 eh43BMDYJ7Eio6NYLwIJyxtcjpf867O9+EmuWAFVJxc4bQCV5ozj1p9lOmE5AISammaA ZA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 363xyhtar8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:52 +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 10JKPj59175885; Tue, 19 Jan 2021 20:28:51 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2054.outbound.protection.outlook.com [104.47.37.54]) by aserp3020.oracle.com with ESMTP id 3661er93yk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nTLm3nBZA3CmmVjk6O2S3L5SLspLf33hGVlUpNYxDng5bIlQZ0eFWJ54PvTKSS2lbtS2csxtXppyiskyfpI67wxnikfHvyDruXQ42c418hJ1bmI1BxyDcEwCnywehUoT7/M/Vh8t22bIvIZc5A8Yir2SVbRSCHmRQIhrPUMi8NomrzGIqJ8EU8CUHeaDbNk3Ewso5XEL5mujtDwy5G4zwJwlFoOQltPNWQWbSHy3oMOGKmWbCrEhc3siuUGbHamkxJaoQ/0krbLXubsGQ7mpXaNbKzgbz2wZCH5V/gr5mFAfNqbNclYU0IeeWnUHyomJGq4tbchy/fxee2ePAju3BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oApzKfjFWBVZxSOptENDI7tXlTD9jnhg+UQVZ1f7qlA=; b=CKRWLz6XWTlYkTDup8Bo8Faw+Z8ARCeCSfyMfJPbWTFuCFap7KNchyX8yj19H+Pdj/tg4V2q7o3UKq8/vP/4tFtMJSdG3XTvI8CfRbGU6f243DDPvIPlCE2ObmjDx4XGghCrZi1LEQ3xByPa2Vv1nKP9DsDxv8Hu1+AebdyqxRVH9oDGdoz1cmOr+1lW5jyFq+PX5ugiUiwSw18fDCUxa7UB09e1+TtzP4Q4KxbcwZXHw4Uvr1/lP5Jj69Bz7MjDDbihemjkzrxqAxbQM+/kLz5Ea9PL0psKX8jJaT7SkQ3Fqk8UB/Kk+Yts87828lsOH05XfLarEF144BMwTM4fHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oApzKfjFWBVZxSOptENDI7tXlTD9jnhg+UQVZ1f7qlA=; b=qauGtdqe25f3BROsN/iSX4MRPxPba9qNKhJ/sNaBaV2dBAPO8pN7hjcoGK/awnUOytegFjFNO5K0YBDmDlvE0q5BzEvIHIJINspnqPYRD6sb9y4FcJAtRnf9X4hFbYeQJzRN0ABMov/PvaXQD1joxDr18ddl7YZXyf8oGx6kisY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:28:49 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:28:49 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 02/20] multi-process: add configure and usage information Date: Tue, 19 Jan 2021 15:28:19 -0500 Message-Id: <3d3cb1e2dffce3949dcd965fff4a3870913438f5.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcfb7d75-a9c9-4e4f-a7a7-08d8bcb8d425 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LuGgGP+1mUBoZygoUIxJD23Fdn0FPYQUV39BvZTc87pPrZkOLH1BOAVJWibgWyfv+7jDv40fIhzAJH06bplIcnkCh8DPBno9TEYWoh970o3YQs9Wa5vAaX9aN7KhGU9MQzgk3gGHGbhCg5xDgQg92YyW5k9jnl/kwJKtUlRvUQ0z1OLtEumKKxZic60g+15Y0hm7XjOubap1Rdq6gXP7cyz5DEpmC9Lc/GHVUvmK70CWP3KLIudS/FlLvf3LJ1csZ7sjdD2Mm0Tpw+2saryq8T472tQ58wgpLowQfBGg8KFaQWyAHw76JXxARNgtuy0IqSp14oV4vZGsaQEiRXWCAvPFx28D1oYdjlfMrM1cjpJ8/acukkcGm82lT6J2kEGeDyNe3lzMJucTo6N4VEsdhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: aCcVqxJklXIANp4Uz4RSZoE2d3m4fqUvlcPCu+O3VHSZICSJ2g6aViT58tWOIHD2MBjQmsNpEJ18rhmezDzzOpl9fbpSbkwQvJU00NE4ALKh1+fZzS4Gn/kK8WuyF9UfaXil1JSnqztY9Y/OwGbhFfUCyrgIA0klojy9gdSJ6lJ3syeC1GQ8kA6tXjl72lyt/xjV/167RDoQR1r28usoyIbV3J5DH/XU3/AolMpn+CT7VdV1qoBzYjtP6KKWRRNmRK9eHGyXVVxZByjm7bBA6YUuL3vOZqM1JSFi0HBk2KChJ+SHdLE018edj+fY0pwoa2NBICUAqOJQSGWuQjB/pN8QSNVk56jp9KiBPvRKlrL2l8A1q5lvwI1acO7B6JkkJWserGnE7tePSbgnHGfMOK2VYY6xb9PI83A4pD7+npsW8AoBN3LcMZnRnzDB+u4GVfvWiQ6UhTfgwFMrCqwaKmaIT36AuF90i24H2vma85INmlXrI81hq2eH3JWSZMyAK+tk6UvMLJU009ujApCuH3evvRAVrDFHTafNIlwj1PlMd0f0ewMO3WJQZwrqvIO9O8xi6BA4BAw1uImbhurj9VkHzwFQrDi66w8dAaW8fg/juZ6JyeZQmeHT7/uCMQBoC017YHeLynYka1b3dKiM0GaLUHGyXhbIZ/5ebSKXASCdy2JRwICtzZ+nMKblhx8yMrRgUqqCx+AMR4nVOgrzcAEG4x2UKt73Q7bZLKyQMPXYg1VEGuj329ZFSbwfXdaygb7Uf0W79mlULuPT93XdqSOIJLGyfljHowMCEJELYC8m0BJweldXYmhxu/qcYj2a3achSTaTufmFX/veaW32S2oEoFTipwe10ZotLIELEYT+BNjkA7y4Raw8+Mjx54b5YE4kXknYs8fMzV1mlEOpJakI4KPmhKqn+JPlK8wJWZ5Ss8GoPlUxsBDAf+1CvDWPcEWsECqrJf8C4+ZiOBnTsTckdSv+uqJP1zAZG1wdBT0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcfb7d75-a9c9-4e4f-a7a7-08d8bcb8d425 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:28:49.4295 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mr9+1Gc/3gppqI62B++hzyMTxYzFruwmfigRDhXzQR4WVFwP8IU0oYmTQainO/DuZCLJYFhRCsAW1us7NFcTzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: Elena Ufimtseva Adds documentation explaining the command-line arguments needed to use multi-process. Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Reviewed-by: Stefan Hajnoczi --- docs/multi-process.rst | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 65 insertions(+) create mode 100644 docs/multi-process.rst diff --git a/docs/multi-process.rst b/docs/multi-process.rst new file mode 100644 index 0000000..46bb0ca --- /dev/null +++ b/docs/multi-process.rst @@ -0,0 +1,64 @@ +Multi-process QEMU +================== + +This document describes how to configure and use multi-process qemu. +For the design document refer to docs/devel/qemu-multiprocess. + +1) Configuration +---------------- + +multi-process is enabled by default for targets that enable KVM + + +2) Usage +-------- + +Multi-process QEMU requires an orchestrator to launch. + +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 orchestrator creates a "remote-object" with details about + the device and the file descriptor for the device + + - The remaining options are no different from how one launches QEMU with + devices. + + - Example command-line for the remote process is as follows: + + /usr/bin/qemu-system-x86_64 \ + -machine x-remote \ + -device lsi53c895a,id=lsi0 \ + -drive id=drive_image2,file=/build/ol7-nvme-test-1.qcow2 \ + -device scsi-hd,id=drive2,drive=drive_image2,bus=lsi0.0,scsi-id=0 \ + -object x-remote-object,id=robj1,devid=lsi1,fd=4, + +* 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=mem,size=2G + + - A "x-pci-proxy-dev" device is created for each of the PCI devices emulated + in the remote process. A "socket" sub-option specifies the other end of + unix channel created by orchestrator. The "id" sub-option must be specified + and should be the same as the "id" specified for the remote PCI device + + - Example commandline for QEMU is as follows: + + -device x-pci-proxy-dev,id=lsi0,socket=3 diff --git a/MAINTAINERS b/MAINTAINERS index 56f1904..654358b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3188,6 +3188,7 @@ M: Jagannathan Raman M: John G Johnson S: Maintained F: docs/devel/multi-process.rst +F: docs/multi-process.rst Build and test automation ------------------------- From patchwork Tue Jan 19 20:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030725 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 B5010C433E0 for ; Tue, 19 Jan 2021 20:36:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DD4923104 for ; Tue, 19 Jan 2021 20:36:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DD4923104 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]:55202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xjg-0008Cr-RJ for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:36:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcj-0000pB-Tv for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:09 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcf-0000DX-BQ for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:09 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUZe002814; Tue, 19 Jan 2021 20:28:55 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 : content-type : mime-version; s=corp-2020-01-29; bh=LnLOzmDa5T3JMJMlHyI2N+DKckhRbqWiYe6fNdWlaZg=; b=xFdca+Boc2gaGEV48gODMvOAuTAyWf0FI+pcI9SUrMKbG14M50n8lT5lXCb5BDyIiWgl jynl+NrnM2JtHgP8QRMNz8rJJxWSVVEYyB1RO46FR6IEFJBKfU936WWpUv98N0SzSM9k fQyvjU5KaMbvGKfbNq/M00+hY69EN6uIYC6+j8vY04pfSTy7jyfgQPIWOzm6LIVKb1j1 QO3B3Z4aqatdlJafzAcy+Dmjik6BMY0FjkgDLxpqFEa+ZMpZED/0g6PHE2+ynVX1UuUq pUQqPxqUG8S1dhVsLntTOhN99AWJgp5VwxLiHAuiMbnQAWgtSocP0NUxDXxuNBPHh3TW 5w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 363xyhtarg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:55 +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 10JKPji9175906; Tue, 19 Jan 2021 20:28:54 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2054.outbound.protection.outlook.com [104.47.37.54]) by aserp3020.oracle.com with ESMTP id 3661er941y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PjyC5mZsixRYjI3AeZgcbJn+mcDpYJkG30oOMcu3AUqJMjk3xzD/37tP1VTbWMRbTVquw3CFQOJCmJvnWx37wGAiMXJDT5VxJdgvUOCpQ3pVnRjAYC176q/oNE14wuKVDySjflwail++10TDRCuBSbRT8024s7VGirdX5OxQLcgTbgS825DcvCUFoNV/F4eu88s1Lw1oGeaDwQtU/onfDfzQmCYIZ9EG97wsIMqHa1V+6WLsC+L3JEYDCNifDHmF3Nf/B/nSS3XtV0R5yWrsycZ+TUX4A0xS5rDvFQjvUE5Jllev2AfX9fWxBivvYj7SCtZeeqzxxDG4ppBYMHgsuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LnLOzmDa5T3JMJMlHyI2N+DKckhRbqWiYe6fNdWlaZg=; b=TPxg3zkx6ttvsSjMtWNLFN6r14GlsmkMD5kCNE/csn4TOYoobiIwrvUb+qucOrn6DYknhSQZk+C7jaabrQVf+p7aqOyfumbEiAffiLGBJEufQoxfmuXDLrHRggorTzZvVwcLeZkAyaxLaEyo+WOmcNSJLILCQfjH3DM5QthWzJVLaWKR2Genyb3iG6/27nTgLz3uv0BmNSGg6IO+BpYCrBqXjFaM0ggC6NPnYCu0jgJhBP6K7ZPzlV96rVag1vRu30b3X+m/+hfXK4efAHddRp+1sMrvAGvUO+EeVGpdtpzG3zZxUQodUfRoI/fPq9LDCAJp+EXcrX81tVYqVg4rkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LnLOzmDa5T3JMJMlHyI2N+DKckhRbqWiYe6fNdWlaZg=; b=IIFJkCwtxKNuQD6zZwlRTs16NKF0iw+PY47IXC2TpMGvK9a+FtoKKdgqkpSEVdfCUdpUwwfpvgHRDWqAgFug6A9WDBffQN/xxe7O42WJYZ4JGKniHCeGoe0GjQ8wEFFPnosssVSHNDLMLqyE6v3SVo8L1IfjGShJKPNnlI7Bfv4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:28:52 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:28:52 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 03/20] memory: alloc RAM from file at offset Date: Tue, 19 Jan 2021 15:28:20 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8b645323-ad7b-4e10-6069-08d8bcb8d5e7 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1079; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ygGfce37kjLXI4kGtV9nOki09QL6ExQOk+HwjwBWgtm7wZnWM6H/x1eNh9OqllQFQ6IW6aCIZNX4sUyq1+iW2AiLe3fz2k9jvZM2I87qtTlJY68CtsFXyUjMX+broM4xnnn/+pyKIaFkW+QlIr3eaV9LeUn9HRAG1GTfu2lJMYJOiigP3kCsLagtMOBgRUVxkLUGIWQcirRDuobG+nogp+QFp5K93oESeAigmwIVzdXzB+tCA20EtRDKfnatJC+lvt8lfV5b9mRuDqS8S4P3LPVfMB7jtRJMUyzHRiteDR9+JIliRgKp/jQGWAZIluuj6xbrGoA1ZzSShSHj3p7Z27V2nqHpCTiIiuFnjSklFeSf001U+XXiCxZ0cY74xVaLEL+eXCghhF5uEUd1AcM36w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: L1YUEJ7Op4JJtFiDIe0g+vq4sQe/B/TX4NDTdGJYwJFU1FapUR5ZklF3sSEHXIoJkigiLmdWric/xTkSouqBYFCsOXi1xK2u54zB33H5oTXaDuKi+BdxqG6bjRdZ/2XEokuMoh/8whFOODG3RZWZKf5SxhigCIuJRqrhYOr+qu60+3ZoxWq4xuCzTAr1fW0/1cviIwzuzOynqP0A4FxjDzo/JWvJxNwj1n8K9mn4Jh9qrG/UPSh9p8LX2fviY+ijPMocsS+mfJ/Yt4Ch95iobP/gXuGzOBcQ3Z85gIuJHcT/GcrXUasisn7AhMPTo9byk83F0CfOjpHL1Cnoc9zxiiuYE4tbbExSsQPxDHdZYc+9fJSZSTqScHIKgsHTTin5tygE5C3YBvE6gUQXQlb8dGMPKir9Z92wb1CMyfjS8icxfIdSP6skknpoAWvv/asRZurQVKtUd1iOmrcu5vw0IpWyokHa4F/puSSElATmM/FJ2g/hTiAraVyBIMmcbS/S/mS8kfL/umpO77LheUCmzlQxgSz79Z/zeCncsgCUV99AypSrUnl8P1HE36KA93Dzs61QrCqnfi4gF+uZ0UiYIMcTYo5ggnyANJ0ZkJfrOhMTd02+UhmXRvK/pq1KDnGsuBBmzY3Vl4qAYBprBkXlizrQ53d3gapF+7b+NIF96vyewksunqHvgqYVnQ3LZofhLZvd/A+FuXmVNMe4yyfMY8bFmHNFiA/JqauOjaMo6bKq6r6t1YBkcIHXp6ymSPw/In8Tl0ZAPVUMn2KbtTjrc0WIzxlBXrWGQd5C2/eaNDl5PEkFSJT9sXWamU624pyNhtha4uHhZrAsZuVTvHYsJyYjD2uL9b2YRKB0Bs2vhoA5/JFdc/35gbJg0pevKSjOycIH8VEapWwrJM8GWX7Wd/lvr5bN8l3gPxD1TOEpDkCAbCepQePOa/nS6DVFXryyTDkeldThODshOGE8nORdSgxKKlQN7hBmefPBeEtSAEY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b645323-ad7b-4e10-6069-08d8bcb8d5e7 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:28:52.3508 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hOYeRK58dmt8ygsk+Hon7aXH+jYZtJs/CqI66xUTrhhg5W7S6vL0irc0WZhizCmPAGVMgqRINMFPijXb/SXQGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 --- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 2 +- include/qemu/mmap-alloc.h | 4 +++- backends/hostmem-memfd.c | 2 +- hw/misc/ivshmem.c | 3 ++- softmmu/memory.c | 3 ++- softmmu/physmem.c | 11 +++++++---- util/mmap-alloc.c | 7 ++++--- util/oslib-posix.c | 2 +- 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 521d990..a9d2b66 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -990,6 +990,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 @@ -1001,6 +1002,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, uint64_t size, bool share, int fd, + ram_addr_t offset, Error **errp); #endif diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index c6d2ef1..d465a48 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -121,7 +121,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp); + off_t offset, Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index e786266..b096ffb 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -16,6 +16,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path); * otherwise, the alignment in use will be determined by QEMU. * @shared: map has RAM_SHARED flag. * @is_pmem: map has RAM_PMEM flag. + * @map_offset: map starts at offset of map_offset from the start of fd * * Return: * On success, return a pointer to the mapped area. @@ -25,7 +26,8 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared, - bool is_pmem); + bool is_pmem, + off_t map_offset); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index e5626d4..69b0ae3 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -55,7 +55,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) name = 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); } diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 0505b52..603e992 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -495,7 +495,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) /* 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/softmmu/memory.c b/softmmu/memory.c index 333e1ed..fa65f45 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1609,6 +1609,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 = NULL; @@ -1618,7 +1619,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, offset, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 6301f4f..31afdf6 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1461,6 +1461,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + off_t offset, Error **errp) { void *area; @@ -1511,7 +1512,8 @@ static void *file_ram_alloc(RAMBlock *block, } area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED, block->flags & RAM_PMEM); + block->flags & RAM_SHARED, block->flags & RAM_PMEM, + offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -1943,7 +1945,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) #ifdef CONFIG_POSIX RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, uint32_t ram_flags, int fd, - Error **errp) + off_t offset, Error **errp) { RAMBlock *new_block; Error *local_err = NULL; @@ -1996,7 +1998,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, new_block->used_length = size; new_block->max_length = size; new_block->flags = ram_flags; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset, + errp); if (!new_block->host) { g_free(new_block); return NULL; @@ -2026,7 +2029,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp); + block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 27dcccd..ddffa0d 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 map_offset) { int flags; int map_sync_flags = 0; @@ -147,7 +148,7 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags | map_sync_flags, fd, 0); + flags | map_sync_flags, fd, map_offset); if (ptr == MAP_FAILED && map_sync_flags) { if (errno == ENOTSUP) { @@ -172,7 +173,7 @@ void *qemu_ram_mmap(int fd, * we will remove these flags to handle compatibility. */ ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, - flags, fd, 0); + flags, fd, map_offset); } if (ptr == MAP_FAILED) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 359c52d..3041e9f 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -230,7 +230,7 @@ void *qemu_memalign(size_t alignment, size_t size) void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, shared, false); + void *ptr = qemu_ram_mmap(-1, size, align, shared, false, 0); if (ptr == MAP_FAILED) { return NULL; From patchwork Tue Jan 19 20:28:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030737 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 EA880C433E0 for ; Tue, 19 Jan 2021 20:39:03 +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 225B123107 for ; Tue, 19 Jan 2021 20:39:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 225B123107 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]:36030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xmI-0003Y9-7b for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:39:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcm-0000tv-JJ for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:12 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xci-0000E4-HA for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:12 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNaJt002873; Tue, 19 Jan 2021 20:28:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=S6YIy5eSZef2MabxG1ZplSDUOQ10N7agnUBJJ/wuMMM=; b=x1zRb+FwuUWFYYOn22WdwwFnPLcEkrlt0RJ8FCgumFaY/3pGT1snUHs/D8iKbGMbbeKr qlK9LywwiKNZr36viYGMoTLT5Z5x/R6qdOytGhPN8utj1gtEk20JKzJu05rnsTv5gocp pKqUj78sKSXlyNt5hLz0RTzTTbNkFfz+0/QGNOiv9AN6yv9q2EsrGHpJxdvmNDSb5yZk IPexDr9LgraCsNPjeVLQjFdPK6xrNvNrOeW1oWB5BJd8HxuLxdIGeSnpCDViqvJtNVOQ AiXLpXvbDd6E13b28P561cn0P34O1QmCRjp7Ua8PlXEGP3k2rD1JyaXYbOfZPaKD9PRf 6g== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 363xyhtarw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:58 +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 10JKPkEP176110; Tue, 19 Jan 2021 20:28:57 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2050.outbound.protection.outlook.com [104.47.37.50]) by aserp3020.oracle.com with ESMTP id 3661er945j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:28:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZE34CkYNz0FxB6u0zVdTXYVmfFr6ONUCXTCc24h/8aN9Jhm+NR5hsUF8QZlR9BlksymAFc/QT+59LW9mO4Ivr2reytArwbRmXj/EtOlgjJEIDBItyBJ6z1limrrDoTYM0oua9kMiSn7qmyHg/jb0cmCNS0kMHeDgfhUNOpv00QNPUDKo4UbYUsrK+1+DUorf2cyILXQ2hUrI1c9zTI2C9+q7eCDzS7jPqlz5IsJwOFWFGcHxFailFnRSKkNpkITezQqv0FhNu/1RxbSHZ79dWsWad/SAUhub/rTTlc8Ineypvp52APB+OliPjzzohIRJh9A/WE0heng1Rl67ZMk45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S6YIy5eSZef2MabxG1ZplSDUOQ10N7agnUBJJ/wuMMM=; b=JvP8Qn85/pifF2tAyfztFhcc4avP9Nk84bKWlREDzeFOXUFZx8wYbpn27Ukof7B6naQfNa1TTNbEfCFprmLU42Tvbs9CJzk9SArTTylEUeOCh3J9Hu2yOhUJvq7IUf48v/COq92+RBr/1HVR6yifG5B1wPa3kdLefOO996db67KegOHfPgnwOfeelcmF7w2lOIwsyN91GMocOv3PvpspYe9qzr/6pNYr7JEn7aZOOQbzI1z3/MQg6P+KkeiOb0f3bh2Hmy3ezq/3xVarzixQD8DTEsegQ1I7GmDuwMfOubt3bLVE71lYr8JnOUYsTA+sCQAeerlgZ94HG8OxwdgcEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S6YIy5eSZef2MabxG1ZplSDUOQ10N7agnUBJJ/wuMMM=; b=aBQDDcVbdDMxB4BpnOioz+4b06XVZBoRPvW7zeUaEOG2bxIhPx4yb9dj/W1bRv039yjKfvPkUQ3QrMgrD+KlWHvR/z6Y+LFpijBPkHmLRVuOOHFLk/8rdZmLnfDqeE0SpSPlHTNH0DgvH0Ems7ZfYPbxOXrtzTswqUQfuIVgntw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:28:55 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:28:55 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 04/20] multi-process: Add config option for multi-process QEMU Date: Tue, 19 Jan 2021 15:28:21 -0500 Message-Id: <595551af14a90aa2bae9d0b9ee049a9af1379681.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ae761f1-766d-4f8a-7031-08d8bcb8d7a5 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7f+QnmrtcJ3mqoQFztBDjN2TB203fEohIbxyaQQm6JP+Cp/CTaujiIxXMVMnyq8/pkP9xuNF+USz26bjy53fzNfX42+dwKjNUUrpY1+KrLdoTSsoKMc7NHt4jHWuFo2dtHGsRja6shdOMc1Xz3815MAPnSTJzG2dJ34Mvo76TdN0HMqCTHKK3gzZ1unPWfU5IovHZaHVn+cvSn/xiRByUQqtWeMyB+GQGCXMu8vVmv/OlI3XbfuKBqzzgpu/D2ba9Vwxjd2vhQaX4KLG+0C/t/Qt9BVU3SS03s6GgkX9M4OsfNPqN9dk9KZ5rrXre5JQQ/FlTRkQEGQh8LwIH+NoJ5aRHtqHxRjwuCWm8SMPmbBn1nmdyyh+nCXOfryYfbgBiRIVMDuFgPJFVLAingYQqA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uw89i+pLz58Pcj2nzbOoNfs2BJSW8sNW+2RRVuC+v8YjkxWoqt0b0W4GsPXuYI2gz2A9sua0fpUHxUmaIptaK37eOB05kbc8ULqXgvl/Dw6heuogu4bgik11TukgZ5naaihG5qxvelsmsyMaYzqI4Myd2e1WpGVPZyX7D6cVX1iRMfVZFJ09FE/IRu4RLHbsEf8gDJFN5VB6n0nOuGhdYLu6I5nb84nx+alDfEcj983/KqnRqXhyC5DsM3YLg5OJ/OjEuSl17jUpHPJr13t3CkBgrtkFsNbP3eQK++RoMDKN/2x50Zy863LFKP6+6sL4T5h5tpnkevsqsG71wjSnRvVkPgfS6lyfrc+Qrptje19/BzB52lH0FQIw3nawLrOBZMjxFxjoT2mCu+cd87el9IOWWy+Y94qkbhjita4Mb6FHb2td6Y3McUNd00JdrQiW39IaGthhjV7Afp00GBo5qGVpDIdQbmYBbkcUhvfjZ0hi6mdo6TN2O4RgRRHOwe85ij4jICwtuNlC8L8LynWRdm9n7IV/tJ4EV6Px0z0XuJ4gc5/1VL3SW+hTThAr7+z1ifgzwhHuoLS+nXXpVgNEbbn9tMnyvLvrrfArautGGLPsiPN6VTiv33scZFMyScmjY1nVon91YF99/XQXokqNgMwKKt6rPRQMioHmD3IFioe+rMhH8Qe8irHqXDT5KgoEfFx9AGH9pWhQNEUdVLN97PVHgWQbb/FcAXanFn8wTH/pYj6q3pTvmLCcefOp75dxo0PFp2erDIEl6fgMtLlsBC7SGkKfATVubEmndVFjY/TjJrlEvq3rM4H9UToysedMlo4XDsuUCv0PqUi/rB21pm66ODdpyJ+zjWzs6+BqxD3PkSx6P3xVYXS6dyM1Cyh1hM1BE3vjDmvxgXSFgTfGXvy5m8HxAeP/OzxMbORM7y9yrSlb9C49V9GZRruLKEsNJ9qpN+7NTvv0w5w9gW9KxJlfjM5uaeSF6yRI/l3pKkE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ae761f1-766d-4f8a-7031-08d8bcb8d7a5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:28:55.3081 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o7FjalWf5kBmTCo7oLmQqa4w/w9hes4h/C8tA3rqvzLWOmAmTmyxKEFVF15pb2Bj1KRkyrSpjin0jVCSEQ88Uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" Add configuration options to enable or disable multiprocess QEMU code Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Signed-off-by: Elena Ufimtseva Reviewed-by: Stefan Hajnoczi --- configure | 10 ++++++++++ meson.build | 4 +++- Kconfig.host | 4 ++++ hw/Kconfig | 1 + hw/remote/Kconfig | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 hw/remote/Kconfig diff --git a/configure b/configure index 9f016b0..1c1ab0f 100755 --- a/configure +++ b/configure @@ -461,6 +461,7 @@ skip_meson=no gettext="auto" fuse="auto" fuse_lseek="auto" +multiprocess="no" malloc_trim="auto" @@ -806,6 +807,7 @@ Linux) linux="yes" linux_user="yes" vhost_user=${default_feature:-yes} + multiprocess=${default_feature:-yes} ;; esac @@ -1558,6 +1560,10 @@ for opt do ;; --disable-fuse-lseek) fuse_lseek="disabled" ;; + --enable-multiprocess) multiprocess="yes" + ;; + --disable-multiprocess) multiprocess="no" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1897,6 +1903,7 @@ disabled with --disable-FEATURE, default is enabled if available libdaxctl libdaxctl support fuse FUSE block device export fuse-lseek SEEK_HOLE/SEEK_DATA support for FUSE exports + multiprocess Multiprocess QEMU support NOTE: The object files are built at the place where configure is launched EOF @@ -6135,6 +6142,9 @@ fi if test "$have_mlockall" = "yes" ; then echo "HAVE_MLOCKALL=y" >> $config_host_mak fi +if test "$multiprocess" = "yes" ; then + echo "CONFIG_MULTIPROCESS_ALLOWED=y" >> $config_host_mak +fi if test "$fuzzing" = "yes" ; then # If LIB_FUZZING_ENGINE is set, assume we are running on OSS-Fuzz, and the # needed CFLAGS have already been provided diff --git a/meson.build b/meson.build index 3d88985..01e25bc 100644 --- a/meson.build +++ b/meson.build @@ -1194,7 +1194,8 @@ host_kconfig = \ ('CONFIG_VHOST_KERNEL' in config_host ? ['CONFIG_VHOST_KERNEL=y'] : []) + \ (have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \ ('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \ - ('CONFIG_PVRDMA' in config_host ? ['CONFIG_PVRDMA=y'] : []) + ('CONFIG_PVRDMA' in config_host ? ['CONFIG_PVRDMA=y'] : []) + \ + ('CONFIG_MULTIPROCESS_ALLOWED' in config_host ? ['CONFIG_MULTIPROCESS_ALLOWED=y'] : []) ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_ARCH' ] @@ -2508,6 +2509,7 @@ summary_info += {'rng-none': config_host.has_key('CONFIG_RNG_NONE')} summary_info += {'Linux keyring': config_host.has_key('CONFIG_SECRET_KEYRING')} summary_info += {'FUSE exports': fuse.found()} summary_info += {'FUSE lseek': fuse_lseek.found()} +summary_info += {'Multiprocess QEMU': config_host.has_key('CONFIG_MULTIPROCESS_ALLOWED')} summary(summary_info, bool_yn: true) if not supported_cpus.contains(cpu) diff --git a/Kconfig.host b/Kconfig.host index a9a55a9..24255ef 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -37,3 +37,7 @@ config VIRTFS config PVRDMA bool + +config MULTIPROCESS_ALLOWED + bool + imply MULTIPROCESS diff --git a/hw/Kconfig b/hw/Kconfig index 5ad3c6b..525fb52 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -27,6 +27,7 @@ source pci-host/Kconfig source pcmcia/Kconfig source pci/Kconfig source rdma/Kconfig +source remote/Kconfig source rtc/Kconfig source scsi/Kconfig source sd/Kconfig diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig new file mode 100644 index 0000000..5484446 --- /dev/null +++ b/hw/remote/Kconfig @@ -0,0 +1,3 @@ +config MULTIPROCESS + bool + depends on PCI && KVM From patchwork Tue Jan 19 20:28:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030723 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 17421C433E0 for ; Tue, 19 Jan 2021 20:33:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CCF923104 for ; Tue, 19 Jan 2021 20:33:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CCF923104 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]:47194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xgi-0004sc-9X for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:33:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcp-00011s-Tl for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:15 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xci-0000E8-Tc for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:15 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUow002794; Tue, 19 Jan 2021 20:29:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=as6s5hO3AJDOzJBWkCCgDpzZPYcwFCq5Zq3lZo67axk=; b=G3/+ny1y0VqZack8S9rM+S6YbQLevCwnfmRkJcEzHW6J1SRf2CRcvmVKMKWlUXXcaPHj F0QyeVlw1EU+IF5cruodqlR+9bkp0brnRCGmCQtHFCpad8Ndd0BPu6DckfPmtNXD+6vR dDgG2+tTLekk0bY8PbOXO+Y6r/0m6GQatgoXGEpLY//BGnPRgDsz8N7j8Wsa79Tbpabg DieaOX09uN4fso5K8P+OGWxV+l9eYM34o2XpRyIShMvDb4/eCzDJ6gBP3A9vb76k+amY ys/GkCk9C49NPPwisrUS4vcQ5zBdYVLOy4jjuwSwHxmhaL/Syb9K4V2gmjC5DAux+VpR 6w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 363xyhtasa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:01 +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 10JKPfCn128678; Tue, 19 Jan 2021 20:29:00 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2059.outbound.protection.outlook.com [104.47.37.59]) by userp3030.oracle.com with ESMTP id 3661njtab6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TOchjXeWNFl9VNx9Bx7rWThTkID3/ZLRa501nnMU9BaJR6Ke2TGP0n+b2eeVv/D6meK0KliYXq1Si8AkmLq/3M+2v/dv1NnxS9vZ5D+Bg9rMJl4HgXZYZUd47zZYimbiVIAviiGWpyeaqejC+QMKEVoZrUb+g5iW0vCI1xLd/cFUKMjkaiaG5cZpX9FHjziFM5hiKRu3boUx4VKPbkd8UCL6qhPhQiS2ynQ4vfKs0c+qQYgVo3BJCcOMVIQxo61uXMwwrk4vHMQ7pRb3zePylyRtVZcr3ctzPCgMcCfqmGEb+84X3gbX25NvnXGRQPtZwI89tQ5Al4Oba9TkT6Y56Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=as6s5hO3AJDOzJBWkCCgDpzZPYcwFCq5Zq3lZo67axk=; b=c73yc5XXy2WXuIZGJygdcVvrlGGj++fRjWpD76Woka66syMcf+EEyotkpFS4LpuwrX6LxLO00dwJgpS9qgZ43BB/i3yoJzs1OxMOQuKKeQDCUaJvnRC79PQaJPLMkgFo0rdZGOZ9aZy/kOzHfRJpzTbW4hXUQ3CBP7Q5A4KXCTQvvg4vXqDHj33Ss3Yl3X7LDqDyWy5PM104bDU8MqcKOuFwBr/NRKh+q20i4otzLawoymV0o3psgQDkWyN4D3hxrjWHfktbklbRupmuL9nRD5HdzE5fg1PCV07V5UO2Yhxj3Ha7aDSEk/vbJos1uW8VJ7lDTUfykqZVi4wAPQCk4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=as6s5hO3AJDOzJBWkCCgDpzZPYcwFCq5Zq3lZo67axk=; b=EYHr953XtZMhwdlx6lU7EpsOtTLASw3M/ejUxjdM9M20IDWpPmCKzQCDFJHWZOzeTYxNKoSazEgxSUUAFQuehccb6a16XuJHMURJeYI7UmA11aO0ImcgWGQI/+zKIVOQDWlK7mzaTKBS532MB+ReNVIPs/CGDcy/1HAHaJs+D5Y= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:28:58 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:28:58 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 05/20] multi-process: setup PCI host bridge for remote device Date: Tue, 19 Jan 2021 15:28:22 -0500 Message-Id: <0da166349ebd79f7ecf0d1c6b42caaa7a90d6113.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ae73e6a-b68a-4f12-950e-08d8bcb8d96b X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:510; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3sViHgNwnSEGbqjNXKGxHxl9/3hWPo0T8B7i+ztwvVCBLvdWVq1CqgkZkaRBboHOMhT79rODVYm54rtMM9G75q7g5FOcFWPUN9cRBFYDNGj7/k6erCXalkloTR5Zms7ZOOHJgNtOMP/Q1o0nTFUydUNbkcyB3SUsax+sswcqVNIJhWfiWs0qlwXRU3YRUTV1TvDOLbGI0gdMkXs0G7BnN4GrKt0CKgYDA3hkHbtql1somnoluCNltSFYk/OpGLRgIihBPqnqDujBWGFyR4XciWROrFDdeVAYieTLmulB9jd6aDyjRRJhS3KPGTFhnoeFZKsewq1MTwlMNjBvCTRMlZA74J06DKB4MEfnHqqwe3c5lzvLZ+GxjamuPaQE9K/O X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?1HOnDllqVwVlhiZk8fuVdj7w67xF7K?= =?utf-8?q?ShbR6VCS36AOFJqdBqeodZK3iXgfQFmlQXPGfQnpC9NJz0cg5xZ/fvhtor6NCAM7d?= =?utf-8?q?7aoMBwM9I3Z8MCc6lcbkMCGOcr2VCyjw17Qhr91mPYcAXwZZS5xpL37J3Ib7I8Msa?= =?utf-8?q?MoZJvw+mmHJjkDR32N84f5dAPa1gPEbT8nfFoY50K8zKAE7uYc0/ajaO9Xabf4kIq?= =?utf-8?q?iGvs+GFNQsuJO+r9kreBS36z2L/sF+ctGClGHmmQ5RWbma2tAFliEKAOtJY9+jKIB?= =?utf-8?q?BDnV4TEN+pfQT6toKjxlWNZYuV36rYhsWDM2ck+jQ5asFTJhSumrlKOYYkUFSfGh+?= =?utf-8?q?55xsrqKKnxdQeJFFoESoJbcyQ0hjjOL2KxhlQpgHea71qFxvHb205vnX3lTC5HVaO?= =?utf-8?q?1FAJXQ0FK2L+faUPiKOzeu23mAZndo+yHOmINDNCzwzIwoUan9xgxsnSKHx/ESUK/?= =?utf-8?q?VV7QoWq8HsFGrRDPyP6oDb0zDAlbbi9Jx+U2hzt9qyMT9iX/F1P91EX0m4yY71Yr/?= =?utf-8?q?M9hlCP7re2lh3b8oz2brGg7j2YuA7Ntmu2Ao7YjoGtUor7DDQ0/nrV8q/ATr6WsdG?= =?utf-8?q?s1PVKyuGXF98mKdO9iI0tPWcs7LbrgGOeAZis5+tQvjsiOSEOcKvfFZ7vZiCRZPVy?= =?utf-8?q?2UbXIgs0RbbwZwHe2x4zwt37YVUwBJ4qeFCBDrvjFsrjdbl/be4SAC737eeowJ4pu?= =?utf-8?q?wDBHPhueoxQop4c/SO4aaj+cGzhbrBvlLzOkCKRuNRXcWeflJhoLK/ENE2cZ2RnMY?= =?utf-8?q?6eo9ByI92Aaf4HjVyoQNAHBmnkt6k8+DQqBn/K7RTNH+d0uaRMSdgpefAS4sG11ft?= =?utf-8?q?oguSfPXUkIzkUdbQ6bX02AK9559IYdAsT5I/KbeqqVZS8FEnu0KOFs55E5jnFK91R?= =?utf-8?q?U2aMZVWF3HoqWEA83hVJKqaPD1FR2xmPxgkNWNVFE3km0mqbPFSr123fm/32xP0?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ae73e6a-b68a-4f12-950e-08d8bcb8d96b X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:28:58.2744 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /oitP9AbRBkIPgN0tm5w9YV7KJkDgKTAJp9YZbcmTbgncAisDYTIpSy9pd7xflmf28Ijao1/trVpVDTAyo3Cfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 Reviewed-by: Stefan Hajnoczi --- include/hw/pci-host/remote.h | 29 +++++++++++++++++ hw/pci-host/remote.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 ++ hw/pci-host/Kconfig | 3 ++ hw/pci-host/meson.build | 1 + hw/remote/Kconfig | 1 + 6 files changed, 111 insertions(+) create mode 100644 include/hw/pci-host/remote.h create mode 100644 hw/pci-host/remote.c diff --git a/include/hw/pci-host/remote.h b/include/hw/pci-host/remote.h new file mode 100644 index 0000000..06b8a83 --- /dev/null +++ b/include/hw/pci-host/remote.h @@ -0,0 +1,29 @@ +/* + * PCI Host for remote device + * + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_PCIHOST_H +#define REMOTE_PCIHOST_H + +#include "exec/memory.h" +#include "hw/pci/pcie_host.h" + +#define TYPE_REMOTE_PCIHOST "remote-pcihost" +OBJECT_DECLARE_SIMPLE_TYPE(RemotePCIHost, REMOTE_PCIHOST) + +struct RemotePCIHost { + /*< private >*/ + PCIExpressHost parent_obj; + /*< public >*/ + + MemoryRegion *mr_pci_mem; + MemoryRegion *mr_sys_io; +}; + +#endif diff --git a/hw/pci-host/remote.c b/hw/pci-host/remote.c new file mode 100644 index 0000000..eee4544 --- /dev/null +++ b/hw/pci-host/remote.c @@ -0,0 +1,75 @@ +/* + * Remote PCI host device + * + * Unlike PCI host devices that model physical hardware, the purpose + * of this PCI host is to host multi-process QEMU devices. + * + * Multi-process QEMU extends the PCI host of a QEMU machine into a + * remote process. Any PCI device attached to the remote process is + * visible in the QEMU guest. This allows existing QEMU device models + * to be reused in the remote process. + * + * This PCI host is purely a container for PCI devices. It's fake in the + * sense that the guest never sees this PCI host and has no way of + * accessing it. Its job is just to provide the environment that QEMU + * PCI device models need when running in a remote process. + * + * Copyright © 2018, 2021 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/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) +{ + PCIHostState *pci = PCI_HOST_BRIDGE(dev); + RemotePCIHost *s = REMOTE_PCIHOST(dev); + + pci->bus = pci_root_bus_new(DEVICE(s), "remote-pci", + s->mr_pci_mem, s->mr_sys_io, + 0, TYPE_PCIE_BUS); +} + +static void remote_pcihost_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); + + hc->root_bus_path = remote_pcihost_root_bus_path; + dc->realize = remote_pcihost_realize; + + dc->user_creatable = false; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + dc->fw_name = "pci"; +} + +static const TypeInfo remote_pcihost_info = { + .name = TYPE_REMOTE_PCIHOST, + .parent = TYPE_PCIE_HOST_BRIDGE, + .instance_size = sizeof(RemotePCIHost), + .class_init = remote_pcihost_class_init, +}; + +static void remote_pcihost_register(void) +{ + type_register_static(&remote_pcihost_info); +} + +type_init(remote_pcihost_register) diff --git a/MAINTAINERS b/MAINTAINERS index 654358b..db50cbf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3189,6 +3189,8 @@ M: John G Johnson S: Maintained F: docs/devel/multi-process.rst F: docs/multi-process.rst +F: hw/pci-host/remote.c +F: include/hw/pci-host/remote.h Build and test automation ------------------------- diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig index eb03f04..8b8c763 100644 --- a/hw/pci-host/Kconfig +++ b/hw/pci-host/Kconfig @@ -65,3 +65,6 @@ config PCI_POWERNV select PCI_EXPRESS select MSI_NONBROKEN select PCIE_PORT + +config REMOTE_PCIHOST + bool diff --git a/hw/pci-host/meson.build b/hw/pci-host/meson.build index da9d1a9..1847c69 100644 --- a/hw/pci-host/meson.build +++ b/hw/pci-host/meson.build @@ -9,6 +9,7 @@ pci_ss.add(when: 'CONFIG_PCI_EXPRESS_XILINX', if_true: files('xilinx-pcie.c')) pci_ss.add(when: 'CONFIG_PCI_I440FX', if_true: files('i440fx.c')) pci_ss.add(when: 'CONFIG_PCI_SABRE', if_true: files('sabre.c')) pci_ss.add(when: 'CONFIG_XEN_IGD_PASSTHROUGH', if_true: files('xen_igd_pt.c')) +pci_ss.add(when: 'CONFIG_REMOTE_PCIHOST', if_true: files('remote.c')) # PPC devices pci_ss.add(when: 'CONFIG_PREP_PCI', if_true: files('prep.c')) diff --git a/hw/remote/Kconfig b/hw/remote/Kconfig index 5484446..504fd6a 100644 --- a/hw/remote/Kconfig +++ b/hw/remote/Kconfig @@ -1,3 +1,4 @@ config MULTIPROCESS bool depends on PCI && KVM + select REMOTE_PCIHOST From patchwork Tue Jan 19 20:28:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030807 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 B48D4C433E0 for ; Tue, 19 Jan 2021 21:03:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2558522D71 for ; Tue, 19 Jan 2021 21:03:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2558522D71 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]:38304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y9z-000475-49 for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:03:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcp-0000zV-05 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:15 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcm-0000Eq-RU for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:14 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOBJa003091; Tue, 19 Jan 2021 20:29:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=N0GNGvHs9TRNBlocD9sV2QNxgHrdfPGGDai8hIri/+M=; b=ySF3qomnfqrjEgzwO6kr3ykfywBGTw39tUzp8l8bZbsUsADSiWczxGjxhf70LwsW9qtx iSwhOfJqHVae9oLL5Xxo44qSIwzc6wuCIeXJO1LVHWMy4xTPlPURBgN+4TBXU67uNMwi nezbwia/bgRcza6norXNqK6Gu8zjduADmcVIIx/4JpaVc4ppY2d5+2mqRsn3VZ+awEh6 PFo8qFj/bYDWlR+tWYPORBBVR/6u+u6RTOnlBJzWIhakEkP9CX/EGC4xJFrI3EIdhk1W wBY4BPxv5z3Zqz03TmWucMcgenQoQCo5e3eMfQGpckZbIcMb0gzqZP4jjEWyz5XgQ+OJ hA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 363xyhtasf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:04 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKQbKw117373; Tue, 19 Jan 2021 20:29:03 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2056.outbound.protection.outlook.com [104.47.37.56]) by aserp3030.oracle.com with ESMTP id 3649qpu8ww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCOn5urEWxcZ6GVMyv3Os5K6KT4zmXeabX9BOFBZ9Th6jZkTGZHDMBA/Y9EhtxZiY87muI0EnQ5l/QO+UGQAhJSYN9oQmK+8qX24U2LwlMdVWFSFvc5Y+Ge/k8fQgbUeczrtX5HtU/4pCDVd8tSPurqeMzSL8+0EJSZ25Xy/AO8X12yf4TSK9KKznK4/4z+6E6qPtwQx0k9uim+NvjhXGg8sJjxiWKQyfMpi4JZ+KU+dQjCZCLAfX1jX426QE9uPARqtI/nYzsRyiAzBKK3Q8rMpG3Sspws/I9x8DB1rfAaDQlB5IAimyEkeDCqdr3fLeJCT++vEIcR+YG74HqKLPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N0GNGvHs9TRNBlocD9sV2QNxgHrdfPGGDai8hIri/+M=; b=DWgdrtpnHQAxFWGsI9UjvL0rh7HPEhx7fncmMMZ7Zk1y4TBH2eOrLMiFDKdMNQ5TpdJZzkVhfh8mvEIN9Pmo2VS4Ja9CkxkAf1pApzM7FAdssVzwI/y+lGxECVfwo8N07YIBQGj5LFiiqAVb9Y3XslGJP3HnC28CucJ5vpWcyKviL//B3PX9dV0ahdUYKxhUI0vkXuvmLbfD9p/7PoiepWK/m1eOqm9/Pkgl/6UelW+lDbPEns9ZCR9jp8qG6u5DKQAdqZ8N4e0eT1CQ7cE3W8m/wZcKx/clgKXFztfR+LRPlZjSexww0vqQ1PQViXzMNjV5Zm7iUcq5WKthSy6yTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N0GNGvHs9TRNBlocD9sV2QNxgHrdfPGGDai8hIri/+M=; b=BERnFXd5LzLY/N+gvmlTNDRxfMqfE/sTer0A1AWnwv7GhW9eOyVOCKkoaYPDUF4l4YoLcy7wXo3MDCQc4xhrAJDqPgIJ4fMuIysmtKlv7oSuJ8u4OB9eqwopvM3gOmcZFybtQHM6cvuClXkrdPMvHaG9z/6Oi4N0EWhToSZxjh4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:01 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:01 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 06/20] multi-process: setup a machine object for remote device process Date: Tue, 19 Jan 2021 15:28:23 -0500 Message-Id: <696cb01059efb127949c475bf2234f8d74b79bf5.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:28:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2dafabe0-221f-4076-6807-08d8bcb8db2a X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tKUWp/lRhvjcT4L274Z63ppjAo2LLNyr1mdAWZsES0s4JO+q4N9tSYrEumi+JMZV12X3LO/AoGRhCtFyFMEhT4MOQCcFcTk0y273hayljUQHch7apJ80llfiCp5KEe4Sr69K5f3uQ3KtmfWjwVe26sO96hz5J54sGWxUXYP7X3Cmlckc+ykatDZnsWLXkzCEXPMBOOIsABkhV9EQZ91NpdVu0ReUb3S3L/C/0JTtCd6kqQJstiehlOJ2cnLnq9xJsIBkuN9vPsK27HLkYkorh6aDCE1b2+PBLwlWPtrEJq7Q+N9JGtKjIaoLLGSm7tSbQTVJqG1ZNbDj/YCSCNuxCmm0xzw6CknMZV8otoUo5uoU0bYx7+7lFOmheZKzo12YNRonleLQtqVeE9z9+qrh8Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?sRy78K/1Tg3FSGULv6+q7xN/xdCWUc?= =?utf-8?q?ewM654zprFJik4UTsa0Qi8HaHPowOB66duLEMTClMnuVjbtOw/b8JwuS/CPOzOP3N?= =?utf-8?q?opLR32itfKkcXHA7NgCzU1HgA2maIKECOWSA8ofPOLWKjP8Uek9k64Ic7awqIJmoN?= =?utf-8?q?5pCH+ZfI1/QGWyuFFxRoBDg5hE21j+5+RPhPbAHXtVIHQztKwDSxeZhaiQWryNgYM?= =?utf-8?q?IF5A2O7Uj55JgnkW2idBKo8TjiLAGOCYGf/ciipVy+Ko+Zfeu89mw9yUp+IY4ghP5?= =?utf-8?q?mFV1xTT31lOSI/jRgXfAFqk6j+h75Ddk0bICOEfLxec1n4BEO6Dxt06Q3Q71fAZNe?= =?utf-8?q?JLlna9vkPiBB7+EgLe72Dncmg8eU9M7W/jf1b+DdwJqX4RpUs2vM4USkjpQHXH55t?= =?utf-8?q?USNFP0ytK/ARDriNHtlFHpyllfydISmnkI+JwOSBROi/CjxsMcL87FmJDltILwvbY?= =?utf-8?q?gYlllfodkiRyN5mEeJl3sUEnLhJpLoCoZY0LjRvCabkQf03cvRENo4eixd3RZi7wo?= =?utf-8?q?2MnCj8mRy/sE2A6IhpWMJM0LX92GHJkdUgtfTkOIc+wnjIZssG9mZ0MEbL0VMNlJL?= =?utf-8?q?ZQlORY5v9QnFH8SgpJPZzNga55+jl8ukx6l4a8a2FVE5VkkwU5WdDRdbtLnnf+8c7?= =?utf-8?q?FdK+PXkC+h3Y4ub18071Fwmu3cOVwi/4+r52wMoFgwYddDoGe+0pWHKd4EHECAsyU?= =?utf-8?q?xwDvJl0s88yW+A9goLIeccTaPyEH+g+M7KGEaWJJ6gvEnbfrl//IA0HYKiWkwrpCd?= =?utf-8?q?HnHQgHyMXaUoVW3xLr1yfSO0YdNouedRnhpifolp9VJ5a1d8ZAIlhaaffDnJzzfJv?= =?utf-8?q?C1xGeJiBlLFJ4MMVwcoNAtOo9Siii8Y6oRFkqM31lNw6hctuoHchuChZLKqqh9I4J?= =?utf-8?q?ritWZcrk8cRic/eIGghBSjGQHsKfQeyV5bmDv83nLm/iZDTYIlzZHQZhWVOX6p4?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dafabe0-221f-4076-6807-08d8bcb8db2a X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:01.3147 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o4Xkg2Sh/D1FGYoFR0y94djvv7FwzsATylNIS8wCmBwaIOTiTlwvQjXLLSykepikfvNSDG8BzsCw2xFBWUtyKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" x-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 Reviewed-by: Stefan Hajnoczi --- include/hw/pci-host/remote.h | 1 + include/hw/remote/machine.h | 27 +++++++++++++++++ hw/remote/machine.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 ++ hw/meson.build | 1 + hw/remote/meson.build | 5 ++++ 6 files changed, 106 insertions(+) create mode 100644 include/hw/remote/machine.h create mode 100644 hw/remote/machine.c create mode 100644 hw/remote/meson.build diff --git a/include/hw/pci-host/remote.h b/include/hw/pci-host/remote.h index 06b8a83..3dcf6aa 100644 --- a/include/hw/pci-host/remote.h +++ b/include/hw/pci-host/remote.h @@ -24,6 +24,7 @@ struct RemotePCIHost { MemoryRegion *mr_pci_mem; MemoryRegion *mr_sys_io; + MemoryRegion *mr_sys_mem; }; #endif diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h new file mode 100644 index 0000000..bdfbca4 --- /dev/null +++ b/include/hw/remote/machine.h @@ -0,0 +1,27 @@ +/* + * Remote machine configuration + * + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_MACHINE_H +#define REMOTE_MACHINE_H + +#include "qom/object.h" +#include "hw/boards.h" +#include "hw/pci-host/remote.h" + +struct RemoteMachineState { + MachineState parent_obj; + + RemotePCIHost *host; +}; + +#define TYPE_REMOTE_MACHINE "x-remote-machine" +OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) + +#endif diff --git a/hw/remote/machine.c b/hw/remote/machine.c new file mode 100644 index 0000000..9519a6c --- /dev/null +++ b/hw/remote/machine.c @@ -0,0 +1,70 @@ +/* + * Machine for remote device + * + * This machine type is used by the remote device process in multi-process + * QEMU. QEMU device models depend on parent busses, interrupt controllers, + * memory regions, etc. The remote machine type offers this environment so + * that QEMU device models can be used as remote devices. + * + * Copyright © 2018, 2021 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/remote/machine.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; + RemoteMachineState *s = REMOTE_MACHINE(machine); + RemotePCIHost *rem_host; + + system_memory = get_system_memory(); + system_io = get_system_io(); + + pci_memory = g_new(MemoryRegion, 1); + memory_region_init(pci_memory, NULL, "pci", UINT64_MAX); + + rem_host = REMOTE_PCIHOST(qdev_new(TYPE_REMOTE_PCIHOST)); + + rem_host->mr_pci_mem = pci_memory; + rem_host->mr_sys_mem = system_memory; + rem_host->mr_sys_io = system_io; + + s->host = rem_host; + + object_property_add_child(OBJECT(s), "remote-pcihost", 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 = MACHINE_CLASS(oc); + + mc->init = remote_machine_init; + mc->desc = "Experimental remote machine"; +} + +static const TypeInfo remote_machine = { + .name = TYPE_REMOTE_MACHINE, + .parent = TYPE_MACHINE, + .instance_size = sizeof(RemoteMachineState), + .class_init = 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/MAINTAINERS b/MAINTAINERS index db50cbf..3f01a02 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3191,6 +3191,8 @@ F: docs/devel/multi-process.rst F: docs/multi-process.rst F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h +F: hw/remote/machine.c +F: include/hw/remote/machine.h Build and test automation ------------------------- diff --git a/hw/meson.build b/hw/meson.build index 010de72..e615d72 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -56,6 +56,7 @@ subdir('moxie') subdir('nios2') subdir('openrisc') subdir('ppc') +subdir('remote') subdir('riscv') subdir('rx') subdir('s390x') diff --git a/hw/remote/meson.build b/hw/remote/meson.build new file mode 100644 index 0000000..197b038 --- /dev/null +++ b/hw/remote/meson.build @@ -0,0 +1,5 @@ +remote_ss = ss.source_set() + +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) + +softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) From patchwork Tue Jan 19 20:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030823 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 CD162C433E0 for ; Tue, 19 Jan 2021 21:08:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2106522D08 for ; Tue, 19 Jan 2021 21:08:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2106522D08 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]:47298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yF4-00087Z-Gn for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:08:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcr-00016R-Pt for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:17 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:37668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcp-0000FX-RM for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:17 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOoFS146175; Tue, 19 Jan 2021 20:29:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=tITNisM76d2ptiLo4WZ9Z0oHxop9K3Kuk+IOTcDyeg0=; b=RBPL1WeYf8CU2yEPWnUZqVGHB+C+1qoWDXD2U2RxqLlPh+wL5oz3qd2GaFbTyjYkdwmI nbCtJYsSOZzjDWhHTlEU+edvFgABVsctFVSl45tN7lbbaSMyT78T0X/jRiVga+THGRvV zEoNUB+M9dD/VusKoQGQpA9XUayW/PJNgqY4FFW9Yia3zjoM99Ml/q+hzpQwIQeGaJg/ JN6U9Oe8LUEAuy5V8IhTivEheUjlH9Y3OJ9o7ccTatavfe7PkLEO6OeCNK3pZiwh7y4w YJQ3mYQIwgexkX2XqJX26hpFkJxgHsd8nR7IOR1eNff+jOOHjDQGJmAAx3bAwwgRRt8a 7Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 363nnak4v7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:07 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKPdR2128405; Tue, 19 Jan 2021 20:29:06 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2056.outbound.protection.outlook.com [104.47.37.56]) by userp3030.oracle.com with ESMTP id 3661njtaer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aJaqONV53O9/ICXc+2ezyY7p24CEBzwL8F9Liu2hjbONebhVhN3m8zLbzLLP3dNqlOaMHI25qbb+T6V2rd68JdEzpoUyBDi8MxHMbUMf/w4Yoe3D8WNiMl9+tEQAHHh0FgJsZAXZ+NqcMsFgzn7eJPRqBSWdolkEkDz+5fEPqTNE99kPWh39Oxx3GZ8SF9rJ1nNNbXatTVxUilWyGyA05zGWve4gBGiZwqL/j+JyYzHQHF1wp+QK20P8FL4VsKXcpq5d34Bu2mxETtaLI1G++98AmvubuH+J400tWK0RsPHOZRczWFcm+ZOvTXgaxUF0vt0O1Y3+d5nte2ebp+tuQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tITNisM76d2ptiLo4WZ9Z0oHxop9K3Kuk+IOTcDyeg0=; b=inQe13LTUDqaJzBVHOfWmd7LZ0kPq38UbFROorSaryoOIDuhpX9/iwLR12/BKdBh2sTSdPDepeW1mPFLrtmD/wi752lxatZKBlvgquCtFAwc/j/HuOmnloj09CEOJ4DXwUsmTCaFc6ypxiXXbjKeyiEzmJTesbBUl1WWcCrq+OIk55pmgyTCEsEGn69lvIJh1ANDezNtkp09enkPmTspCixpaikih3b3TtnwiaTQj13aNRNRC0RDGueYfx/eBTjP5oIxdWq5SUddjznolDKIOQ+UoFZs80nydCSzmhlWk1T3Qt9kCT1dxe2NJZbMDbDbeT7yf8cT3SRup1DrNTDm3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tITNisM76d2ptiLo4WZ9Z0oHxop9K3Kuk+IOTcDyeg0=; b=ew6l7VBwWAXaTAvU/1qdRoI6MFkEdEKm0xXZEbP1WCcGKx44nMh4WjOLFFiyc4WF4Lr25xsEPnJxTKJha16K9ehrzaY93fd7HmsFdXs6YNT3vJzucp++lzphOLyr1IIc6qDaU81iGWahVP6s86nPCJqO6DdmiogI5CiCojZPw88= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:04 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:04 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 07/20] io: add qio_channel_writev_full_all helper Date: Tue, 19 Jan 2021 15:28:24 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91371649-b44b-4526-4208-08d8bcb8dd00 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: okD2umQcyXEup6iLSd7sj44opLyC0KdSOBNQkEYy3zjLfShfL4sh5sAPaGYTGKnRghqEAx+nVROvnjqzXCowY1NkK9Yf1V/roUPSgG/tUoiHXHpB28qgmQsjYvp9U+FnU63P/xiZCP/ZVUPGlR4u/LneWzV5MDtItIN7eontt80wESqQu5IF6NmQh6HUoskkLdH6qCDjhi0Q7t8FDBVhBDYpik3NUi9HrsmfYNs7bU6n3uhSKsVZUzOP8h/qnSQl/H6OigZ+fK1su4H3C8bIa4K4VrtYkXpZKPUnAqY7359oXWL/UjlmPPEM8diOzhqDSXeTYXloSQhsyIAhj16Lhn+xuizgmBH6f4TAoAd12j7MB0ep/6OTyXF/Y9wxi3nZPkaK37MAmMzsUdv9y0YtSg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?T7F0yJ1SuhAEeK6vResk3jH4Kv+lrQ?= =?utf-8?q?krQqwET+N1ick676dUTCXQN8IE8pv9A1T6tcBtlEy8lWojGUShssZwpYcUT4LyNZF?= =?utf-8?q?XVdbMyiC/GK33srNTptUkkAGcWOk+k720GVZxI5tVCXykkzX4xidJwcP4xDroDFKp?= =?utf-8?q?XVqzT3ORupH/NemOtn/XvBoJYk+GqbBgewR/oLXblNw0T1wPLZ1z1niZ+4wHdePOr?= =?utf-8?q?VtAehLAsX+PXLbX2aDSUvazrx9jiuIdWxR8gckq5px6r/b+uyFtzGS3pJeRdgf+ER?= =?utf-8?q?S0z8HEHOJryGrHBEUtFE2Aa7hAyqLX0AZ6j6t59eUtYIOXxcn9r82wTHUzbskumBd?= =?utf-8?q?IsHczP+H5IDnktrjdg8TWjfB6Mo/V267IudvP/21WYesPGbBRjB+yJI5rajrPV88J?= =?utf-8?q?PLDyxYAEIs5jkjhtqkZkFnqBet9HD7D7FIOFPAuR8yfmH31VM3DW56S2/li1lfzSL?= =?utf-8?q?QTQznvn6HVyLkN899R2OK37BJA5KDlhbE+rjdUfK5a9Bsf82tpaY/khAr8bKfzBN3?= =?utf-8?q?iumrOs95nWAzdB+TvKgGb1MmA9NXb0HgSkLYXL46APYWUyyFlskxURu7ajoXwwLYA?= =?utf-8?q?mj+ohzUtgKhIIhrILfzrW5KsMUTLFJ3bwWwisKr9RsA3EXTOEMO1AqqGsWJw8TW09?= =?utf-8?q?HLTsTGhXzEpRWr8rPH1zlKHXRwQPDuAqtTlVcVcyPApjbXkn7h8f8UbkCTKKJlHCl?= =?utf-8?q?q6b4a1LviCp7JbIWmCe8gb8U/Brf6gaFzv2c91eUQr75ShnV3vUUzPI3EL3DGxXxM?= =?utf-8?q?t/YTMTbaDR7ehl6H4yjwdhtaPVwjO9l7MqnYCEUk4zXZh4umoJxhvFc1cYXeVMYra?= =?utf-8?q?I+Z7b3/K9aqB8icBbvbL1QGxR2tzwnsb5C6cf9Ds+tVpjBGyIhY5aNH+x4tAfunPZ?= =?utf-8?q?7BWZn7NiWz2bYqbNZ0aAPEFfuHr4FoJMKbhDHvTz6lUhlYnJa3Wg8/W1X5iGHrI?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91371649-b44b-4526-4208-08d8bcb8dd00 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:04.2969 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: McquHyhaz2uADogOJY0wobJZsgVn1w+4q7vdDhcAFpbBcX6WM8UOVmJeHFBw8QDdNiuhBQEpxCtnYt4y99e77A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.79; envelope-from=jag.raman@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: Elena Ufimtseva Adds qio_channel_writev_full_all() to transmit both data and FDs. Refactors existing code to use this helper. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi Acked-by: Daniel P. Berrangé --- include/io/channel.h | 25 +++++++++++++++++++++++++ io/channel.c | 15 ++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/io/channel.h b/include/io/channel.h index ab9ea77..19e76fc 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -777,4 +777,29 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, 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); + #endif /* QIO_CHANNEL_H */ diff --git a/io/channel.c b/io/channel.c index 93d449d..0d4b8b5 100644 --- a/io/channel.c +++ b/io/channel.c @@ -157,6 +157,15 @@ int qio_channel_writev_all(QIOChannel *ioc, size_t niov, Error **errp) { + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); +} + +int qio_channel_writev_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, size_t nfds, + Error **errp) +{ int ret = -1; struct iovec *local_iov = g_new(struct iovec, niov); struct iovec *local_iov_head = local_iov; @@ -168,7 +177,8 @@ int qio_channel_writev_all(QIOChannel *ioc, while (nlocal_iov > 0) { ssize_t len; - len = qio_channel_writev(ioc, local_iov, nlocal_iov, errp); + len = qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, nfds, + errp); if (len == QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_OUT); @@ -182,6 +192,9 @@ int qio_channel_writev_all(QIOChannel *ioc, } iov_discard_front(&local_iov, &nlocal_iov, len); + + fds = NULL; + nfds = 0; } ret = 0; From patchwork Tue Jan 19 20:28:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030741 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 5670BC433E0 for ; Tue, 19 Jan 2021 20:41:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC68E23107 for ; Tue, 19 Jan 2021 20:41:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC68E23107 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]:44996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xoy-0007D1-Nv for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:41:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xct-0001Az-Oi for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:19 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:37678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcq-0000Ff-B5 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:19 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOdug145832; Tue, 19 Jan 2021 20:29:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=ePz+Sq/1iKB95Td8WDMunIy7n00tgRQZ8WBpCySIWts=; b=O5CuA9OEQGl2ZGVdr3fHq01D0KG/b/mwrer4FJNRgQdDrDA0ql6rtp34KgRsiJgXgNQE 245dxU8pVOxRkc0xMPcreBDUt17qGQUPQpFQLu4+YYjBt2SosP+UoU60Axdrq+28SNsV buK1yiNemX9k2D95SWbYsTGR8pJy7SUzMIonK57a9KoP5zAQPGbFSR1UcXYK5i8Ax8pC HH3rDivB5kt1kcTCe77P9zMQHJ6Zh/CBdQhw7KZh+afsmuXvUu3mmJ9nybas5UIblFc8 vTPBA7ssD2SlbjVcTMCM6RSloth7wehGmdOJWM2KL5zSbdSmb/KPj7Kr1qxeUHCHDxC6 sQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2130.oracle.com with ESMTP id 363nnak4vc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:10 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKPdEV128381; Tue, 19 Jan 2021 20:29:09 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2055.outbound.protection.outlook.com [104.47.37.55]) by userp3030.oracle.com with ESMTP id 3661njtag6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oKEVPSKRgl/Z6IHScyMj0yp6k1fDpdc9WrrB+t78xovLvm1CaYw7BYHHY3JpA211qB8wnIxFUHYoIkw2E3CFasNpTOR0DKu8j2h8AmEl7btUuSIEcoJc17iJ7gw+mmU4gewclp0DGqBY7ZSPUubfCMEFAqJK0QuxwN1WabWZIMB35HcfRh3mGT+RdDwBib2wZ0+oCZeA3YZ4xD4pChE9WF0NAAVV7tqWVgs8ol3TT4yQsv8sebZK0G7e5xNN3CVPWj3tLKoyx0vPVjKXPVpy8L9Qd6Amd/LfCbJfRx1KSIDrvBSCC2QF97X1SDiqzqLD0JhOqx4k/l8V7Xb51/tLOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ePz+Sq/1iKB95Td8WDMunIy7n00tgRQZ8WBpCySIWts=; b=UdayMUBvXezG01vmFEETAPyEwh0At/c74wkR4C5uEstT35EkHQTywJCgtBpXCkB0chkD0SirOW/6zP7BvxFDhkCK9G2BuTLEKxTvM3OpcH0MsffMDA06sklwYyLDfZCU2tm+5TyxOQQXU1ogI78TwXjFbG7zMRJ1V/GVfD0Abx0/d1tyb3oXXJqCpVmiaimf5KjZloPiUJDFcSB/JlrtnEuJ55L6aUncmg4RZN0VbgJLuWUeGt2xPeNtUNu2pdeD508sUvGhdk1+AYpVJQzdvPhAYhnsb+jmKZStDM1k2SnIoxZLAMmVvTd1lC94mPzLLO6v+hHsiTJz+qWREXjLSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ePz+Sq/1iKB95Td8WDMunIy7n00tgRQZ8WBpCySIWts=; b=jAka+Tk4UBF6Zcue3WG/zPqG4yZbnLbh4T0ucdOpVzY04iQHSrk3TcEiLYkFqDgyFeR41p14294b0ZrAV/liWgMwKtEpE/2ccL1C1kpMVHSq9Gx7AV+sp7r4sWEFNvJU25LkukwB2j7dGSu9wQZmQ/3FSfOLd2vcVefmKifvvx4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:07 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:07 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 08/20] io: add qio_channel_readv_full_all_eof & qio_channel_readv_full_all helpers Date: Tue, 19 Jan 2021 15:28:25 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e0597f7-f19e-440a-782d-08d8bcb8dec7 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fAWQONvNC04lLAb0EwVor56ZK4YbITQsEvF/cJy3gQV3KR6jm4lN/h+ujaLV+MWDrlCieYKq19QLllWqqMk3ZCUNsBBOMsVdW9na10QqgCGA25gTegXpL8es3EzpA9e2V4Q41OWzDY/JI8ebOYAjwz79Ytq1EWCqWDzVxNMuXP9U44lsor+zSkBI3PWuVWG9LqQ8Cj3CbeIF0OCo0GiE/wRDf8ZdV7gWXetg92VsWOR0/BtDF8mpmglnI84slOorNdf+/N1UvBvWAXBN+uh7SuxGVfxh/Y3hUOmM5Ne9moQFlTlNUAl2BSNmb/RBzJ2YDZUuDgZHt0m7QjLR7MxgFj/1Kxnv+pYV2ZBq7E1cvq6yoGTFZVkqm+Y14XDSJS8e X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5CWnVd9C06nGGpvwWr1nrOlAkFZ0piaS7ag35+WGWaZCcNsKiqPut4YlbA35ox3PPe2Cwg9q2kzFJYKuyPxK8NAsS5N24ANY3KfxxGxzFitjvnho+4YTYYHXRRCCARLC+JNut5ViRjyeMK7n6XlDIErZUtQXikMJzXTXQDz3TNIWaGbHkv91/1bQyTLMGvLA4Lzu95yJ4skU/co9ksXh9PbrlSQ6FjzX0+jwAIqIri4biG9cmzt4dtOt0g+/dMZf9UtM9UefLYu+pKqMALsLTsATA3K2dYhEYQB27tt24rdwKzkM4XnJXeRBaH5yXxe7dGzX28pQ/ZEEACWqsv7BRp3UsFn5IaHce4jjLuGeJxms2qfty+iXgUkqQdU6QGZ4rMZ1VJl3EwBt3EidCKcRcZsA0TW77FcSyN9zPdOOSKblH/AL4W8Qgmbnht3/Y/yuQtMu3Um7hotCEppJpDPIbADqI3fdPJGts3cdyYnE2OR7w/QWF+7xRkrMyYAg+pYYtWoYzxo5g6sgoljzBU5fvNcyBwT1gQ9D/c63gsMcekUHVK10FJ1FWRZwDTF370zeYBtacE7Y8vADJ6CoRXCr/WiZ+KK9gltmxr2TFQos+dqiRyY235rrrMy7j4s0JWqiNHDlOmuW63gquQZGIjFbpczk0ZB2gEZcMtOr8na8Qi0HbKYdHQiogk1SqKTl39NOt2jlLhQQ8kkVT08/4a5gTIPNQRM9NvWdctoqgFKwE9dWOQHtvxLNliwtluZTQu3hFsIbvxTr7HxiF4szeuqvuEf+VNaeQzMnBCpGjOVT3wlngiE9vTv/z2eLdnHN+CjeTPRhxv6AnrIWmgXyICbDQ85vUkVPR7eaByD2KEdMdmOuPLrRhySL6yQnK/ij+BVsgN/7f5urc1uzRgAAnFtrNwXmkDBMqN65Nr5Iffn4kTDI5+jwgP4VByUNS8Gkq6sBCvZePp+XZXzozC52R4GBr0nJGbeUFg6YTKcv6Ca1VeM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e0597f7-f19e-440a-782d-08d8bcb8dec7 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:07.2352 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z9Ri+mvP9cnDCzmu/I/R+wJMLtZWXXoSWIYs8CoP3seut7+AjfBInCW+soFkYnUWcX4peTlCBZ2KPTFBHSP97A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.79; envelope-from=jag.raman@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: Elena Ufimtseva Adds qio_channel_readv_full_all_eof() and qio_channel_readv_full_all() to read both data and FDs. Refactors existing code to use these helpers. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman --- include/io/channel.h | 53 ++++++++++++++++++++++++++ io/channel.c | 106 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 138 insertions(+), 21 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 19e76fc..8898897 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -778,6 +778,59 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, void *opaque); /** + * qio_channel_readv_full_all_eof: + * @ioc: the channel object + * @iov: the array of memory regions to read data to + * @niov: the length of the @iov array + * @fds: an array of file handles to read + * @nfds: number of file handles in @fds + * @errp: pointer to a NULL-initialized error object + * + * + * Performs same function as qio_channel_readv_all_eof. + * Additionally, attempts to read file descriptors shared + * over the channel. The function will wait for all + * requested data to be read, yielding from the current + * coroutine if required. data refers to both file + * descriptors and the iovs. + * + * Returns: 1 if all bytes were read, 0 if end-of-file + * occurs without data, or -1 on error + */ + +int qio_channel_readv_full_all_eof(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, size_t *nfds, + Error **errp); + +/** + * qio_channel_readv_full_all: + * @ioc: the channel object + * @iov: the array of memory regions to read data to + * @niov: the length of the @iov array + * @fds: an array of file handles to read + * @nfds: number of file handles in @fds + * @errp: pointer to a NULL-initialized error object + * + * + * Performs same function as qio_channel_readv_all_eof. + * Additionally, attempts to read file descriptors shared + * over the channel. The function will wait for all + * requested data to be read, yielding from the current + * coroutine if required. data refers to both file + * descriptors and the iovs. + * + * Returns: 0 if all bytes were read, or -1 on error + */ + +int qio_channel_readv_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, size_t *nfds, + Error **errp); + +/** * qio_channel_writev_full_all: * @ioc: the channel object * @iov: the array of memory regions to write data from diff --git a/io/channel.c b/io/channel.c index 0d4b8b5..b12db9d 100644 --- a/io/channel.c +++ b/io/channel.c @@ -92,19 +92,47 @@ int qio_channel_readv_all_eof(QIOChannel *ioc, size_t niov, Error **errp) { + return qio_channel_readv_full_all_eof(ioc, iov, niov, NULL, NULL, errp); +} + +int qio_channel_readv_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + return qio_channel_readv_full_all(ioc, iov, niov, NULL, NULL, errp); +} + +int qio_channel_readv_full_all_eof(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, size_t *nfds, + Error **errp) +{ int ret = -1; struct iovec *local_iov = g_new(struct iovec, niov); struct iovec *local_iov_head = local_iov; unsigned int nlocal_iov = niov; + int **local_fds = fds; + size_t *local_nfds = nfds; bool partial = false; + if (nfds) { + *nfds = 0; + } + + if (fds) { + *fds = NULL; + } + nlocal_iov = iov_copy(local_iov, nlocal_iov, iov, niov, 0, iov_size(iov, niov)); - while (nlocal_iov > 0) { + while ((nlocal_iov > 0) || local_fds) { ssize_t len; - len = qio_channel_readv(ioc, local_iov, nlocal_iov, errp); + len = qio_channel_readv_full(ioc, local_iov, nlocal_iov, local_fds, + local_nfds, errp); if (len == QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_IN); @@ -112,20 +140,53 @@ int qio_channel_readv_all_eof(QIOChannel *ioc, qio_channel_wait(ioc, G_IO_IN); } continue; - } else if (len < 0) { - goto cleanup; - } else if (len == 0) { - if (partial) { - error_setg(errp, - "Unexpected end-of-file before all bytes were read"); - } else { - ret = 0; + } + + if (len <= 0) { + size_t fd_idx; + + if (!len && !niov && (nfds && *nfds)) { + break; + } + + if (!partial && (!nfds || !(*nfds))) { + ret = len; + goto cleanup; } + + error_prepend(errp, + "Unexpected end-of-file before all data were read."); + + if (!nfds || !(*nfds)) { + goto cleanup; + } + + /* + * If (len < 0) and fds are returned, it's not clear if the + * returned fds are valid to be closed. Just free'ing the + * allocated memory for fds in this case + */ + fd_idx = *nfds; + while (fd_idx && !len) { + close((*fds)[fd_idx - 1]); + fd_idx--; + } + + g_free(*fds); + *fds = NULL; + *nfds = 0; + goto cleanup; } partial = true; - iov_discard_front(&local_iov, &nlocal_iov, len); + + if (nlocal_iov) { + iov_discard_front(&local_iov, &nlocal_iov, len); + } + + local_fds = NULL; + local_nfds = NULL; } ret = 1; @@ -135,20 +196,23 @@ int qio_channel_readv_all_eof(QIOChannel *ioc, return ret; } -int qio_channel_readv_all(QIOChannel *ioc, - const struct iovec *iov, - size_t niov, - Error **errp) +int qio_channel_readv_full_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, size_t *nfds, + Error **errp) { - int ret = qio_channel_readv_all_eof(ioc, iov, niov, errp); + int ret = qio_channel_readv_full_all_eof(ioc, iov, niov, fds, nfds, errp); if (ret == 0) { - ret = -1; - error_setg(errp, - "Unexpected end-of-file before all bytes were read"); - } else if (ret == 1) { - ret = 0; + error_prepend(errp, + "Unexpected end-of-file before all data were read."); + return -1; } + if (ret == 1) { + return 0; + } + return ret; } From patchwork Tue Jan 19 20:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030827 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 7D9E4C433DB for ; Tue, 19 Jan 2021 21:11:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E68AD22D08 for ; Tue, 19 Jan 2021 21:11:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E68AD22D08 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]:55234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yI1-0003LM-0w for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:11:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcx-0001LN-Py for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:23 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:56116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xcv-0000Gg-6u for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:23 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKODbI131269; Tue, 19 Jan 2021 20:29:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=VQKJ1H6MuV/ngL6Cq9KGXuymdjJIz35iesfj/KKtBXA=; b=dhBZVMmoKwfDOc46zo0dazxSfjljc2imx7w/GO5KaNP3PPZA3KP3+OcO2crxQWPbaJzV K83yvJ5gAIxCerdahSXKYa7h/sy763dY1diNR0FCreIttR+jxw+QqKnyEccRlPe5bGGU le3boXYJ5vtwHTSIK03UZEb7JhXqlcVWYEzcoOlCSvVL3paMIjCgYAP2evq/Gkg0gfUH BsNfELLz/IMAHRUnME6mZm4fDsfJrhTSCW+2YUZWUAZBAg1JyN4Lq9DLw6Q7Szi1ptEl O/yCnIbzkrcKhOZUJZ0of8cgTMiZHNfzpNCHlRkDrUTgmL56QDD6E2l7Q3TCH0te8nx8 ew== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 363r3ktxn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29: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 10JKPdbS128387; Tue, 19 Jan 2021 20:29:12 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2055.outbound.protection.outlook.com [104.47.36.55]) by userp3030.oracle.com with ESMTP id 3661njtajg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8pL65LgV8Q5zhb4B1WdTLJ0GCjNVWCJZvneAejoRBf5w1cruLXyVeZ1G8A4p8UyT2LiDHEsOuNByGQFOTEuzdvzI1K7KNey4JVlST32e3db9jpbBm6UHFoAFbr2qTQzNWy794Ax7q06ElYe1XplK4iHfqz2ie92uk78vHHO9mf/xd09s5AWhkoLRRh9HCYVAFs2lvbdqMxqlzulkWFxuBJ31TfeNpziStbWXDwGVF+Gr4vZk482naVIeS3hwnGF3OsSLqTIIXWh/4WinI9pZ+QfjV076EuliTUf1MuwgqJ3JVZhAciumMFiCs2IW9fj4VccwkmISZnFPmOaITAoCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VQKJ1H6MuV/ngL6Cq9KGXuymdjJIz35iesfj/KKtBXA=; b=dFWybTz5kbLvLBR1IKB0CIK6wVDpNlxV37MTU1kO6//ctrg0n70/mtlFHC/9P6QgYOdlW+4ils6UOxkHCjqb6TEd/hxxklxiirraIpAzDaVE5cQpgh0C14zklonchcBwweEUGb0AD/G6OVUxX8vTxtOz+WC3b7X6H+d+DZEeAN4NOUHNTzat8JE/2LH8LzTp0ljE55LEz5pmWjZFcpD97oLQorSAJpyOyziPcS+hEUAfxJdeCXRFbY16U6rAdxTxh9uHch0kM2VcqLpMZuYDYBLObRYoAKBp6TS4Vd6woJ9kxWtwzOKAc6ivm594aD8EEEPP28+1erZ3Mrhd4VAF7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VQKJ1H6MuV/ngL6Cq9KGXuymdjJIz35iesfj/KKtBXA=; b=CK0ASR7VlklQpknsIEl95RKJ+PjXRnZA2Ml2ltD8NO6QD0/zApo8usXuGn2oHJBw0n3N6RSgMAXKkQMhU6AQP2rdV3oSFiYFOgRfHovamT4CRHxB3BmpXwPq/+VItsskERNXNVf7bLwfGzFcuDYuMinnsK2jPL8pTpJSeIRiTNM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:10 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:10 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 09/20] multi-process: define MPQemuMsg format and transmission functions Date: Tue, 19 Jan 2021 15:28:26 -0500 Message-Id: <918f6170a4d564c1672085d841d3d8bb213311de.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2f7300be-aa55-4355-0e5f-08d8bcb8e087 X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Auz2/ZkWs+lPNzOHWlURhQ0Fxm27ny+vC1i7L/1j83VoGQhz+uRuHSax3dCY3D6rUO+I/KaHy/XUOwkYt83QRzcwgq1UCNaHbJeEDo//UI4EEGmnllVEoSzPC6oveXow6UsLo52DL0TaeTQ6ikOl9rushS8RpzxgrZ2WxiyU79uApbRygaxszUNCBj+l8nJ12ey5Ml3GgpDnkrSCbINQ69xk6Hjk/zFG9VojJvLne+wYBUZHvmffYRQ7yLmzck2HVn5zlyxeqoaaX3ehz1J0XinZA4io+VIKBiKloBtGTx395KQaWX4ZzBBTolghJ/S02facIrtQBUyNFqF+8V05Oazh3ITPsxwMeGRRbiXT41tjiWT1MfKvaJT/5FQYCWNiEe4y7n3VPXx3yzCLKiQCkcZOHtKrkmgn7z6BTp0NPXSZDOA2Sn3Bo7KFD8UvP6uficVdc4PI+JjZ00oFc6RDGLyCVT83j9/vexSBvRAhgw+hk36AVZIfJ65F0af+XHrRq/bg3412l6i6UIErFg/fQw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(6916009)(30864003)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?CBrZyAQ7MNOgm8Kk9KHn7jDl02+uoo?= =?utf-8?q?jQgZ85XQg6xoOhnXe3NGp0SxOQ6o0NjqXwCJLypdcJdVqbOGhURvcWmiLMI1+3L3W?= =?utf-8?q?ZfJ9aUIK7DifdhiMNOkkoqIvPwxOs3Oh4oic1UMD27OL3L1Xts3f3so17wPON0bI8?= =?utf-8?q?8NGdWyTx9c2kNgRwQC402fdO3tWCzL7HVkQGZELyJduttGjybXbXzdzwhmRhzG5RL?= =?utf-8?q?Y9zqDlyKY2KkVgL53OGz1v3JD/5W2weqa2rvZ0pb/m5z24yhttvoP6SsdXU1EAJTG?= =?utf-8?q?+6XsVZjC/vOOO64nx/I/qypw2EaNy++WeRvRmeunQivNA/ve5rdYbOkrG7dxw1f9T?= =?utf-8?q?/i6/ILT8b4JB8IjRoqJNTjkpxwwnPVuiSiRrPsXCRJgQHeWuvvG55ETo5XRF5AeNl?= =?utf-8?q?/cGeNb5OTwT7A/50gPfY0NQ+hVfApDmkGPJD7uyFpkl3jhu0gmm1P13GNjZBnSzJB?= =?utf-8?q?Ld1Bm780v8pgQ2dD41o58atcmc851tmZb5uildw4b7/SrjcT2vV49xJFntR/bQi/r?= =?utf-8?q?k2JrRIDkP/cc3J2b2uTjzsXJ06avdjFqYcWEEF7oPc7r65XEAKiHNMR7KCi/1hhqg?= =?utf-8?q?cGAXwCrDmmtrDNrbTUHuKVQivJ8EZ2w7pmYXsv0VWWb6/f0XsLAc+YPWOOsnGqQFz?= =?utf-8?q?MX2sWeC2b/r04chRGbunNaXObOv1rGcHVXz8dIx9OMmzByA7Wez6CM9/xEdOcj00h?= =?utf-8?q?Gmvc1OWzxmF7aJC6p/8oZv9mGBUnfnHoq4v9R4nn9cAw/wGAlsaeyxLSta+DfZDYr?= =?utf-8?q?/AqpQ7V+xPE9T1mk8yu/N+91gnomMOVMCHosCDkuFFWxHWz96bGMUw4YK2nKdHV9G?= =?utf-8?q?G2p0926dWrbjmr8HTACQ5gqYLXWacxnoACic/PsatMK7KDDCko5aDtN62AYFdZwX0?= =?utf-8?q?VzVpXf/lGx84vL6yzaTp+wElzDvrwTZBJOqQisSlqWDiCf7wENsouIEcNVp5kBU?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f7300be-aa55-4355-0e5f-08d8bcb8e087 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:10.2005 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OUha6EaZyPfU1bSBQjhyUxuXMS2fUywsOOKKTwNVtvYr8fZeS7+5o++GdYBJztwJVofDFceR5QK30otRQIIfRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.78; envelope-from=jag.raman@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: 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. Define transmission functions used by proxy and by remote. Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Signed-off-by: Elena Ufimtseva Reviewed-by: Stefan Hajnoczi --- meson.build | 1 + hw/remote/trace.h | 1 + include/hw/remote/mpqemu-link.h | 63 ++++++++++++ include/sysemu/iothread.h | 6 ++ hw/remote/mpqemu-link.c | 205 ++++++++++++++++++++++++++++++++++++++++ iothread.c | 6 ++ MAINTAINERS | 2 + hw/remote/meson.build | 1 + hw/remote/trace-events | 4 + 9 files changed, 289 insertions(+) create mode 100644 hw/remote/trace.h create mode 100644 include/hw/remote/mpqemu-link.h create mode 100644 hw/remote/mpqemu-link.c create mode 100644 hw/remote/trace-events diff --git a/meson.build b/meson.build index 01e25bc..0b353a6 100644 --- a/meson.build +++ b/meson.build @@ -1754,6 +1754,7 @@ if have_system 'net', 'softmmu', 'ui', + 'hw/remote', ] endif trace_events_subdirs += [ diff --git a/hw/remote/trace.h b/hw/remote/trace.h new file mode 100644 index 0000000..5d5e3ac --- /dev/null +++ b/hw/remote/trace.h @@ -0,0 +1 @@ +#include "trace/trace-hw_remote.h" diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h new file mode 100644 index 0000000..cac699c --- /dev/null +++ b/include/hw/remote/mpqemu-link.h @@ -0,0 +1,63 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef MPQEMU_LINK_H +#define MPQEMU_LINK_H + +#include "qom/object.h" +#include "qemu/thread.h" +#include "io/channel.h" + +#define REMOTE_MAX_FDS 8 + +#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data.u64) + +/** + * MPQemuCmd: + * + * MPQemuCmd enum type to specify the command to be executed on the remote + * device. + * + * This uses a private protocol between QEMU and the remote process. vfio-user + * protocol would supersede this in the future. + * + */ +typedef enum { + MPQEMU_CMD_MAX, +} MPQemuCmd; + +/** + * MPQemuMsg: + * @cmd: The remote command + * @size: Size of the data to be shared + * @data: Structured data + * @fds: File descriptors to be shared with remote device + * + * MPQemuMsg Format of the message sent to the remote device from QEMU. + * + */ +typedef struct { + int cmd; + size_t size; + + union { + uint64_t u64; + } data; + + int fds[REMOTE_MAX_FDS]; + int num_fds; +} MPQemuMsg; + +bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); +bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); + +bool mpqemu_msg_valid(MPQemuMsg *msg); + +#endif diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index 0c5284d..f177142 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -57,4 +57,10 @@ IOThread *iothread_create(const char *id, Error **errp); void iothread_stop(IOThread *iothread); void iothread_destroy(IOThread *iothread); +/* + * Returns true if executing withing IOThread context, + * false otherwise. + */ +bool qemu_in_iothread(void); + #endif /* IOTHREAD_H */ diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c new file mode 100644 index 0000000..b3d380e --- /dev/null +++ b/hw/remote/mpqemu-link.c @@ -0,0 +1,205 @@ +/* + * Communication channel between QEMU and remote device process + * + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/module.h" +#include "hw/remote/mpqemu-link.h" +#include "qapi/error.h" +#include "qemu/iov.h" +#include "qemu/error-report.h" +#include "qemu/main-loop.h" +#include "io/channel.h" +#include "sysemu/iothread.h" +#include "trace.h" + +/* + * Send message over the ioc QIOChannel. + * This function is safe to call from: + * - main loop in co-routine context. Will block the main loop if not in + * co-routine context; + * - vCPU thread with no co-routine context and if the channel is not part + * of the main loop handling; + * - IOThread within co-routine context, outside of co-routine context + * will block IOThread; + * Returns true if no errors were encountered, false otherwise. + */ +bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp) +{ + ERRP_GUARD(); + bool iolock = qemu_mutex_iothread_locked(); + bool iothread = qemu_in_iothread(); + struct iovec send[2] = {0}; + int *fds = NULL; + size_t nfds = 0; + bool ret = false; + + send[0].iov_base = msg; + send[0].iov_len = MPQEMU_MSG_HDR_SIZE; + + send[1].iov_base = (void *)&msg->data; + send[1].iov_len = msg->size; + + if (msg->num_fds) { + nfds = msg->num_fds; + fds = msg->fds; + } + + /* + * Dont use in IOThread out of co-routine context as + * it will block IOThread. + */ + assert(qemu_in_coroutine() || !iothread); + + /* + * Skip unlocking/locking iothread lock when the IOThread is running + * in co-routine context. Co-routine context is asserted above + * for IOThread case. + * Also skip lock handling while in a co-routine in the main context. + */ + if (iolock && !iothread && !qemu_in_coroutine()) { + qemu_mutex_unlock_iothread(); + } + + if (!qio_channel_writev_full_all(ioc, send, G_N_ELEMENTS(send), + fds, nfds, errp)) { + ret = true; + } else { + trace_mpqemu_send_io_error(msg->cmd, msg->size, nfds); + } + + if (iolock && !iothread && !qemu_in_coroutine()) { + /* See above comment why skip locking here. */ + qemu_mutex_lock_iothread(); + } + + return ret; +} + +/* + * Read message from the ioc QIOChannel. + * This function is safe to call from: + * - From main loop in co-routine context. Will block the main loop if not in + * co-routine context; + * - From vCPU thread with no co-routine context and if the channel is not part + * of the main loop handling; + * - From IOThread within co-routine context, outside of co-routine context + * will block IOThread; + */ +static ssize_t mpqemu_read(QIOChannel *ioc, void *buf, size_t len, int **fds, + size_t *nfds, Error **errp) +{ + ERRP_GUARD(); + struct iovec iov = { .iov_base = buf, .iov_len = len }; + bool iolock = qemu_mutex_iothread_locked(); + bool iothread = qemu_in_iothread(); + int ret = -1; + + /* + * Dont use in IOThread out of co-routine context as + * it will block IOThread. + */ + assert(qemu_in_coroutine() || !iothread); + + if (iolock && !iothread && !qemu_in_coroutine()) { + qemu_mutex_unlock_iothread(); + } + + ret = qio_channel_readv_full_all_eof(ioc, &iov, 1, fds, nfds, errp); + + if (iolock && !iothread && !qemu_in_coroutine()) { + qemu_mutex_lock_iothread(); + } + + return (ret <= 0) ? ret : iov.iov_len; +} + +bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp) +{ + ERRP_GUARD(); + g_autofree int *fds = NULL; + size_t nfds = 0; + ssize_t len; + bool ret = false; + + len = mpqemu_read(ioc, msg, MPQEMU_MSG_HDR_SIZE, &fds, &nfds, errp); + if (len <= 0) { + goto fail; + } else if (len != MPQEMU_MSG_HDR_SIZE) { + error_setg(errp, "Message header corrupted"); + goto fail; + } + + if (msg->size > sizeof(msg->data)) { + error_setg(errp, "Invalid size for message"); + goto fail; + } + + if (!msg->size) { + goto copy_fds; + } + + len = mpqemu_read(ioc, &msg->data, msg->size, NULL, NULL, errp); + if (len <= 0) { + goto fail; + } + if (len != msg->size) { + error_setg(errp, "Unable to read full message"); + goto fail; + } + +copy_fds: + msg->num_fds = nfds; + if (nfds > G_N_ELEMENTS(msg->fds)) { + error_setg(errp, + "Overflow error: received %zu fds, more than max of %d fds", + nfds, REMOTE_MAX_FDS); + goto fail; + } + if (nfds) { + memcpy(msg->fds, fds, nfds * sizeof(int)); + } + + ret = true; + +fail: + if (*errp) { + trace_mpqemu_recv_io_error(msg->cmd, msg->size, nfds); + } + while (*errp && nfds) { + close(fds[nfds - 1]); + nfds--; + } + + return ret; +} + +bool mpqemu_msg_valid(MPQemuMsg *msg) +{ + if (msg->cmd >= MPQEMU_CMD_MAX && msg->cmd < 0) { + return false; + } + + /* Verify FDs. */ + if (msg->num_fds >= REMOTE_MAX_FDS) { + return false; + } + + if (msg->num_fds > 0) { + for (int i = 0; i < msg->num_fds; i++) { + if (fcntl(msg->fds[i], F_GETFL) == -1) { + return false; + } + } + } + + return true; +} diff --git a/iothread.c b/iothread.c index 69eff9e..f606871 100644 --- a/iothread.c +++ b/iothread.c @@ -375,3 +375,9 @@ IOThread *iothread_by_id(const char *id) { return IOTHREAD(object_resolve_path_type(id, TYPE_IOTHREAD, NULL)); } + +bool qemu_in_iothread(void) +{ + return qemu_get_current_aio_context() == qemu_get_aio_context() ? + false : true; +} diff --git a/MAINTAINERS b/MAINTAINERS index 3f01a02..ae3172a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3193,6 +3193,8 @@ F: hw/pci-host/remote.c F: include/hw/pci-host/remote.h F: hw/remote/machine.c F: include/hw/remote/machine.h +F: hw/remote/mpqemu-link.c +F: include/hw/remote/mpqemu-link.h Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 197b038..a2b2fc0 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -1,5 +1,6 @@ remote_ss = ss.source_set() remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) diff --git a/hw/remote/trace-events b/hw/remote/trace-events new file mode 100644 index 0000000..0b23974 --- /dev/null +++ b/hw/remote/trace-events @@ -0,0 +1,4 @@ +# multi-process trace events + +mpqemu_send_io_error(int cmd, int size, int nfds) "send command %d size %d, %d file descriptors to remote process" +mpqemu_recv_io_error(int cmd, int size, int nfds) "failed to receive %d size %d, %d file descriptors to remote process" From patchwork Tue Jan 19 20:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030785 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 F2B69C433DB for ; Tue, 19 Jan 2021 20:51:41 +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 5D92822D08 for ; Tue, 19 Jan 2021 20:51:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D92822D08 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]:38136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xyW-0008Kf-9T for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:51:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xet-0003Va-Gl for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:23 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xer-0000dF-3d for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:23 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKODTi131286; Tue, 19 Jan 2021 20:31:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=KRxZkeXCGOGB5WtxKQKW3/m4SU9GrTHotzpmkhTwWDM=; b=SVzgdcWeylJdSTkwQzNKwa6+/iA/1bYRqR34rwSHQTZC/UXKxUGm8EMrNA2y7NScGIs0 X22B3CRJ2m8bAj20TlZgEyFC7U9PYbfsW15s2zvJbrXUYvOEewdRdfz4FIZ8voyzwSU+ hyZHK7ApHYLVubS6KOA1oC+tOip5HZtH25LmpAwlGYI58FA3cXVUdSk5of+I0xAaSbZd Ggef317nDKl25Vgktw315j1mFMucw6iQjJkkhNHU68y88Icz3OuYk9mJAnyk9MCLJ+XP sGwSitufEotgvOJ9josZFcMcQacXBaZ/aK78oen2Ie8csX3lI3Zvo24wf4lOlhYQe0KD 9A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 363r3ktxwr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:15 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKPkEY176110; Tue, 19 Jan 2021 20:29:15 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2054.outbound.protection.outlook.com [104.47.36.54]) by aserp3020.oracle.com with ESMTP id 3661er94nc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iS1gT1/qRXWWWaV6OopRTVkh6p7hyHjuQQyStlg8o/9ED9V89p/0gmiBHMv+NWD2yMVlLcRf9jxtfCupFhSdSl0O+4XzV9sN0vey/JKUAXkFUg+gJG6+1o9mpYIUKgg6ylSYGrlXNxtwQ3sutvCHEpQLHFLJ8skV+zv0AJ/bV5vdIxvYJOcUM1Afire+oWhNKvduYT6xKdeLJuozK4XRNjsom73n5mfriyX+eNxhdbUS3v/1AMv4hiaZDDjF4nlevGyYuD0t1tfjpoGHIHbxihkQHDH+9boil6/rDRufrHywOsMg3RUt+AFDh189hYF5qgXYaUxmlUOIKN70jiBAwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KRxZkeXCGOGB5WtxKQKW3/m4SU9GrTHotzpmkhTwWDM=; b=BKqGyL9/syz928DnQaHI2SGJmlRaYZeUnOzB6hExEfAQ3tiU038ZGXbzV8NNtYHR61Jf1O1a6OyewKzKgPAk3lMgpvANdBIImtb9CSF3yo0DqINDlgWUlo++4AdNm1aU1+fpV4R3nj8AK+YaOYAMPQrGofaYMV8vsgNZKbRGluHg5Qu0VCFWST5RQrXOvn0DsvLaSBuq+1iLtZz4IGWCY+kJplY7hFiHAwpt2Xw8PwcLNj8muPmVXzvB9j5cz8d14X3kre9i2sGE4zrmwfd4kBzBrXhQqN6RXvUFfECpz8ZeQrFWGyP6H70rvEgRaIRfWfqD/jlMa/EcmlYPKtAcpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KRxZkeXCGOGB5WtxKQKW3/m4SU9GrTHotzpmkhTwWDM=; b=qbnz6f3NOQwO5xP3HHZlZhtBIro+nOd1bUyOd1AqeYC83op00Qh4MROptsWQfnsn0yRbuXde2+B6eMgUykL/3zGIUHqgEj+CgZI0BLJplCNGEAx6LpeQ5hDdpwOKmkgwEke5MKnhH0JVMEhwHu6cfyuguvkbM8y2loAvmXuDV4o= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:13 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:13 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 10/20] multi-process: Initialize message handler in remote device Date: Tue, 19 Jan 2021 15:28:27 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95899e30-52e2-4e3e-6718-08d8bcb8e250 X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ILlko1oB8K6LNsSQhjaei5hiWRr6m7dbDMtMh89ZnAWkoCrZ7prDFm8Z0Y0s0xzG3Chw2YXbW7sVjtdtYOdqPiFOXv84xbXdFtFoLZ8Y92uut7j0fzYEEJ1/uV2fLQiFnXlt7jV87NBiIzCtwqa/bs2JfvEWCX8h18mf5DrIj6DrNra07GvjdDIQ17w+fQFbcEIPLmjbhyIe+Y7lnNAuyQjf7g7sfukxWOZu0WiLRAcxWtJVni2QfNopGo2Et8p7A+StxLGCVO83nGRPpSJ8Ecrz7K/KWW5gesn/5mK94vokEFXgwOPn07LzINY5YA9x3MQlJmTzhTBX4BovKhLdAytx+Zh6oPHL++cNB6/qCIRQctpLzUUcws8COL4kz49AWYJ0avmSDWRI0byb2u8e3LWE4PnMuyrreSbgHAGKVpbze4Lk/KEOOD2DLJEZw3Yuph2cQuRvbC9VJZHdzQu9JoAFm4miESFXJ7LP6c3G9Bm2DrtTC+AxpZIY4SZNfv0lZNmy9CA3njx2xryjwsyVzA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(15650500001)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?FSjsknd3JtmsrcW1el/7BqpVLN8n2l?= =?utf-8?q?tvtZ6faC5H+ze6BGUa8f8Amz3YMR++0fU7gBo/GN3lxtvPoGh2Pxjer2BlwufuYiP?= =?utf-8?q?/Bozbv8gEu3mLisA+60In0JH5sW4rN/HT80DrtysC/i8vp7WJiOHD34m2bpkyi848?= =?utf-8?q?RIWM8j8QX5+g3Ewdw5BF9eQVNzdwy3exQjUrFWRuqw+lhjpaKXuyl1mbHatBYXSel?= =?utf-8?q?VOPQUtYHtLiMddTq2hVEFqvi1r+nJcAqGDLpsTwueZlvKSr+8PYVA4ssWF/6afjMs?= =?utf-8?q?RuZ+ED/GgrgzNijoWACpbFRLIDWZShhQFa9q+ECzvQqXlLiR87S/3/pikCYMhbxQ2?= =?utf-8?q?g7VHbdzzRTewpg5Z128oi/TDJJD4pM3RGF7x7dqd6gsrekH6Obe1PBHEwFuaTPxJA?= =?utf-8?q?dxja8J61t3E9d1IZTKKA0Snc4ncwMjDsTTL1Y4CqX90ugo+Bje8eIrzYsKPxfFuqj?= =?utf-8?q?xRkGAKHcFS9tueT2tk1BcQ/mHP8P15v/VDcoDXAVb7kHlmk4YSmoWplHj84z/G/vh?= =?utf-8?q?NcxOpFPghuzcz/F5ReE7l/+sL0RAf/JieL5SDhjKmBCbkzPICgRwHfP5bkYA468ji?= =?utf-8?q?FDj7K35sMRqorsMtDD6zv8yvYJGI4QorauSzRVCWZBEYBtFgJ37bwIb58l0kB5/d9?= =?utf-8?q?gj7wGMjTa4AD4WVrVBxLGQazkdab0ftCLFS9vDo1i/imAJ8fNQEm5tBDubXy6vHBq?= =?utf-8?q?kS9w23ijmCS+13/606JEErPYIU9FiuNYqzV7UsYMw9DyFf8AKxGdJP7ji/Xe9LrW1?= =?utf-8?q?rNuL1C8l0JSciOns5laI8yN5Ou5Y35Yxo8hYHmLNceJ31YUd2BtGnYaazbXaTF6To?= =?utf-8?q?QfiapackxxQFMAHiUbm74O0IYdVAP+6T07eibfl7szn0/5MpZYKVTUZ5eBCEgsb7Q?= =?utf-8?q?vm2pSpUcO7VWPDHAE1zdOWMpoMZsSN5YiWNAH1DybBmpTfMNbn2UDdOe/4PSFac?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95899e30-52e2-4e3e-6718-08d8bcb8e250 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:13.3637 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wOeEqWnSeVD4V5b+YUDDynKe/7PCZ8Z3+2B5x1fqsoD4fIL8s8kbuS/8xM6xEJ0YyumKtp+T03BOTvcbW/TESQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.78; envelope-from=jag.raman@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/machine.h | 9 +++++++ hw/remote/message.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + 4 files changed, 68 insertions(+) create mode 100644 hw/remote/message.c diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index bdfbca4..b92b2ce 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -14,6 +14,7 @@ #include "qom/object.h" #include "hw/boards.h" #include "hw/pci-host/remote.h" +#include "io/channel.h" struct RemoteMachineState { MachineState parent_obj; @@ -21,7 +22,15 @@ struct RemoteMachineState { RemotePCIHost *host; }; +/* Used to pass to co-routine device and ioc. */ +typedef struct RemoteCommDev { + PCIDevice *dev; + QIOChannel *ioc; +} RemoteCommDev; + #define TYPE_REMOTE_MACHINE "x-remote-machine" OBJECT_DECLARE_SIMPLE_TYPE(RemoteMachineState, REMOTE_MACHINE) +void coroutine_fn mpqemu_remote_msg_loop_co(void *data); + #endif diff --git a/hw/remote/message.c b/hw/remote/message.c new file mode 100644 index 0000000..36e2d4f --- /dev/null +++ b/hw/remote/message.c @@ -0,0 +1,57 @@ +/* + * Copyright © 2020, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "hw/remote/machine.h" +#include "io/channel.h" +#include "hw/remote/mpqemu-link.h" +#include "qapi/error.h" +#include "sysemu/runstate.h" + +void coroutine_fn mpqemu_remote_msg_loop_co(void *data) +{ + g_autofree RemoteCommDev *com = (RemoteCommDev *)data; + PCIDevice *pci_dev = NULL; + Error *local_err = NULL; + + assert(com->ioc); + + pci_dev = com->dev; + for (; !local_err;) { + MPQemuMsg msg = {0}; + + if (!mpqemu_msg_recv(&msg, com->ioc, &local_err)) { + break; + } + + if (!mpqemu_msg_valid(&msg)) { + error_setg(&local_err, "Received invalid message from proxy" + "in remote process pid="FMT_pid"", + getpid()); + break; + } + + switch (msg.cmd) { + default: + error_setg(&local_err, + "Unknown command (%d) received for device %s" + " (pid="FMT_pid")", + msg.cmd, DEVICE(pci_dev)->id, getpid()); + } + } + + if (local_err) { + error_report_err(local_err); + qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR); + } else { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} diff --git a/MAINTAINERS b/MAINTAINERS index ae3172a..205b188 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3195,6 +3195,7 @@ F: hw/remote/machine.c F: include/hw/remote/machine.h F: hw/remote/mpqemu-link.c F: include/hw/remote/mpqemu-link.h +F: hw/remote/message.c Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index a2b2fc0..9f5c57f 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -2,5 +2,6 @@ remote_ss = ss.source_set() remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) From patchwork Tue Jan 19 20:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030791 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 2A7E0C433DB for ; Tue, 19 Jan 2021 20:54:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B8BA206EC for ; Tue, 19 Jan 2021 20:54:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B8BA206EC 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]:46846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y1M-0003tk-LT for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:54:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xf3-0003Yo-Vd for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:60596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xex-0000dn-0N for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:33 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUZR002769; Tue, 19 Jan 2021 20:31:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=XKBNF9uGeJ7f26QobJG1N2YFvLXFgKmylzQFDd0xfbk=; b=LL2ux5oW8hE/fZB0vF6KdsC2wtw0bKnklFsH41p6x8RC9I8UZRtpGqH38jhY+XzKGj6D h8DMPkEUQZQCVeqpdWy+O5gMqkSQRP5eiJQ5Dqf1tMSlQaHnkIoUnXppGPSorI6a7pFJ KkavRyCusUfkb31wtuD57RttTpha2/wwG0b3yWQMCEg5YQtWBQy6sZtaYpUp+Hu+mICQ 7uczkmpKYu8Z98n7Hrirm/WyABdFPvlInz/7roFoD5HO9RYl/bQnkytlaFH1MIY6lfpV cR4FVsAxo/MFKrWhl/o/3SVQN75MmW419yihT8E9yyKjpf+r91tcScwZyRWEE1xqbxwV zw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 363xyhtb36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:19 +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 10JKQc33117492; Tue, 19 Jan 2021 20:29:18 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2058.outbound.protection.outlook.com [104.47.36.58]) by aserp3030.oracle.com with ESMTP id 3649qpu94c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lBjkRCvOGZYjT/FJg3W6n5f6mPrX4Ar6Da/ertltyKDCD9moN0e77Rh0E2rNjEDN76LSKYQt2JG6R4Mi70ejj9kbBoHHpnNj41xUFCut9n80TLOEJ/SVuWd+xOlh1MyTYd8Kyzvw0X5NH90vQ7Ogh4Qa1GzWlj8YQuyGwKdN5iQSp/xDjAGgufhxspYt3IgTo7/5uL3OKMgAAkpJ6lTwv/n35EOt3JGGHp+H+Yg9kAA8WR1noYmtpYxyl6kB+Pv6Xvz05jSP4gashYJ09bzxqF7sVleTehK9B/79/9KQBp7+O30Y8pC5mG97UmMPJ1kev8mJBRFje5DDJv7Faev6HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XKBNF9uGeJ7f26QobJG1N2YFvLXFgKmylzQFDd0xfbk=; b=fouyUuMtUIP0qkkKdHJEazjvvyvjf2LU3yBQS2Y/pLtfpZkoUj3cvznA/0XIbBUeXTThBhPINBWBSpLKv+F1WnCaXYjtmAgh2dwdp5bRH7Dyseo/s5oDq5c8wg3+uo1/13/2snf/NCJltmi3NPJFl+yNoL3Awxb/L5dyaOgenfzx0sCBQkmGJbAyvq7QR1IQM9cyWciLf9MqN3aj3trLvqIYGrqzu7FutUM06AVmHj4v+/2U7/CbdJ0ii1b4vrWZLkMrk42jkOn3y2yvbZCo5CTMXVQbale4M5tDW4OIsPoB8JpIjHjCzWe1ICVOQR1gwymdDpu17YMWUdjYn7ydBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XKBNF9uGeJ7f26QobJG1N2YFvLXFgKmylzQFDd0xfbk=; b=Y3doxnX/7Zm0yPw6lHmE0gAjH+4I3VZCn+zv8dpK2gZRzubp622b78qe+lXDzOjiIJP/enSBqoeEqo9PmyOMXYlLVuuNRU7Dop3i87KAsVmNmCw0tJcFs23FZsqBBWkdrMLKBkzoCpN0ou2aik7+zzdrvL/Olx7YGi7c60VAUNw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:16 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:16 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 11/20] multi-process: Associate fd of a PCIDevice with its object Date: Tue, 19 Jan 2021 15:28:28 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a23f748d-513e-4627-9781-08d8bcb8e42b X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:346; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CGR0ZbHMsNFn94GH9gS3o8j1Zj5/gt8d96HbTZJUm8VHvyH4FKhDXFewXza+Evm9NBStfWDcC+ZQGwpzea7XIm5STbTcHGkg7P0LdsOFpDFpA7/G3s0VSKtBYn8Q4mQUnbhTZ1y+fYOJRNOpvGCPcmJCzJzIGJ08lLwNbg+kzmrj68CIgaECZzqZzWFgO0h04oheORi0JPniYwMWsgfen8jSwbq9Lxa8Thf/OEO82rqafoJKUQ099pUU29CYai6ORrfVF8qZsf5/isDgPEouVvsDn+DHbviuBj6BzBS833ZL4CgbFdsUqtYQ96i7gtady1AYxqss8xvI+FutSvhaifdtu8ATjcmEpZgwWwamv+TTTi0oI5Tg/5v7h/dBd9ryK/gJteFsu8qNyhNkCXRa6s/CQudUwF7f6jy2aIrcTmKT5cSjs0YqtfO8m7ce4KFJD1DcP20y6nvDgTdk1xLUpbwa+ThFQuD4X2jet5k9NA4BuBcyaKYVksPgnz4njm1okiVkFUZ8Nm03IURhy39azw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?DLehPQ3n4mqs5ErEOtCeJmeKpjbf+P?= =?utf-8?q?9XOzSRenjI8ROJQvefVF7bIhgS9vzol1byYItw+F6l/2kbygw5B/mgoZf5w9KrMpp?= =?utf-8?q?ilvTL/4oHm8x8zAAerQxBucJS6gEoyf1x5nq0Z05GDaBmzk7646/yuAz/uIzGH1Ou?= =?utf-8?q?7l2PKZZ2k+GXiQdF7WL276gYE6v54EA3qLLFcA+z1x1OjGamJ3zgf6fvhiVkoDh/a?= =?utf-8?q?P9NjpuVe2q3egzs5m6BjKYfLm9t/SuazvuybCPebU+K3L/8QdI8WWSx4Z+2WIFl9x?= =?utf-8?q?LVfCXjoCxLCYRR3gNYqR7FqrMEMpOJwv6Y/Q02yCORyIFkzeoxJ77kP2bJBIj2x7Z?= =?utf-8?q?Am4ZWc2QDXd6b4Ss+eAtiAOXkVoALTtTMGPpHcz03eorLc46SCloXB5AABvVi3dKC?= =?utf-8?q?gPac9Uy9EKf3bMv+02Tm4iCJBdbrlrdHeBcq7IpIW8kpHH5x3QIMF155ShX4KDWba?= =?utf-8?q?71TzYON8IKxJTzS0KZ+WbhU1rIHwpXfUEmt0jp0k/Ccc5D0JO9985bz+dXlmopA6Q?= =?utf-8?q?ySrWI2CEMwJH04KRQLXWya/yjXp3y3/+tszJTsueEpGpFV7qf8TKL6UJN3PeRdAOa?= =?utf-8?q?ejc+eeXwTFNdo/y6xgQucq6JH8uLsgdq+UvrR+Vp64OX52ynvSf4BU0Api+8MnMH4?= =?utf-8?q?nhfVEbeBJMI4EG8DkX4VHKHOr7f3dBFllwwC/lCbn2OR5RqYKOTFEu2x43P5gQgsQ?= =?utf-8?q?3NPHOWXoE9/aJx78rU9lz6DBncPtsK/UR5+1U/u7idLfRqbvCdsyogKzYc7SnA9xi?= =?utf-8?q?CKxsdFKRp2qLK6Espa+Uwe0RiPo5+jIElw+H/JohiSsUUgT4Hf3dyPtzNIl70tl4g?= =?utf-8?q?3Au3r3EWO/bLHn7RNW1EC9sAPZQBihY9Mz5+Yf1jGphmISY+kwnFjN/8iGRsK7ECO?= =?utf-8?q?5CwVg1bQMqKXzfXYy7J4EOhwvmkj11VBEr6KOy/ox7fGmB4rzVm0nFwATIWayHM?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a23f748d-513e-4627-9781-08d8bcb8e42b X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:16.2650 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bqHEX0SkUHhjmwACSkEC9LXQGQi4GgobwOByWSHnyICKFYBX1GveyqeV90Ze90yUIHg9aOCb6hekzl246SO1YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" Associate the file descriptor for a PCIDevice in remote process with DeviceState object. Signed-off-by: Elena Ufimtseva Signed-off-by: John G Johnson Signed-off-by: Jagannathan Raman Reviewed-by: Stefan Hajnoczi --- hw/remote/remote-obj.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/remote/meson.build | 1 + 3 files changed, 205 insertions(+) create mode 100644 hw/remote/remote-obj.c diff --git a/hw/remote/remote-obj.c b/hw/remote/remote-obj.c new file mode 100644 index 0000000..4f21254 --- /dev/null +++ b/hw/remote/remote-obj.c @@ -0,0 +1,203 @@ +/* + * Copyright © 2020, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL-v2, version 2 or later. + * + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/error-report.h" +#include "qemu/notify.h" +#include "qom/object_interfaces.h" +#include "hw/qdev-core.h" +#include "io/channel.h" +#include "hw/qdev-core.h" +#include "hw/remote/machine.h" +#include "io/channel-util.h" +#include "qapi/error.h" +#include "sysemu/sysemu.h" +#include "hw/pci/pci.h" +#include "qemu/sockets.h" +#include "monitor/monitor.h" + +#define TYPE_REMOTE_OBJECT "x-remote-object" +OBJECT_DECLARE_TYPE(RemoteObject, RemoteObjectClass, REMOTE_OBJECT) + +struct RemoteObjectClass { + ObjectClass parent_class; + + unsigned int nr_devs; + unsigned int max_devs; +}; + +struct RemoteObject { + /* private */ + Object parent; + + Notifier machine_done; + + int32_t fd; + char *devid; + + QIOChannel *ioc; + + DeviceState *dev; + DeviceListener listener; +}; + +static void remote_object_set_fd(Object *obj, const char *str, Error **errp) +{ + RemoteObject *o = REMOTE_OBJECT(obj); + int fd = -1; + + fd = monitor_fd_param(monitor_cur(), str, errp); + if (fd == -1) { + error_prepend(errp, "Could not parse remote object fd %s:", str); + return; + } + + if (!fd_is_socket(fd)) { + error_setg(errp, "File descriptor '%s' is not a socket", str); + close(fd); + return; + } + + o->fd = fd; +} + +static void remote_object_set_devid(Object *obj, const char *str, Error **errp) +{ + RemoteObject *o = REMOTE_OBJECT(obj); + + g_free(o->devid); + + o->devid = g_strdup(str); +} + +static void remote_object_unrealize_listener(DeviceListener *listener, + DeviceState *dev) +{ + RemoteObject *o = container_of(listener, RemoteObject, listener); + + if (o->dev == dev) { + object_unref(OBJECT(o)); + } +} + +static void remote_object_machine_done(Notifier *notifier, void *data) +{ + RemoteObject *o = container_of(notifier, RemoteObject, machine_done); + DeviceState *dev = NULL; + QIOChannel *ioc = NULL; + Coroutine *co = NULL; + RemoteCommDev *comdev = NULL; + Error *err = NULL; + + dev = qdev_find_recursive(sysbus_get_default(), o->devid); + if (!dev || !object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + error_report("%s is not a PCI device", o->devid); + return; + } + + ioc = qio_channel_new_fd(o->fd, &err); + if (!ioc) { + error_report_err(err); + return; + } + qio_channel_set_blocking(ioc, false, NULL); + + o->dev = dev; + + o->listener.unrealize = remote_object_unrealize_listener; + device_listener_register(&o->listener); + + /* co-routine should free this. */ + comdev = g_new0(RemoteCommDev, 1); + *comdev = (RemoteCommDev) { + .ioc = ioc, + .dev = PCI_DEVICE(dev), + }; + + co = qemu_coroutine_create(mpqemu_remote_msg_loop_co, comdev); + qemu_coroutine_enter(co); +} + +static void remote_object_init(Object *obj) +{ + RemoteObjectClass *k = REMOTE_OBJECT_GET_CLASS(obj); + RemoteObject *o = REMOTE_OBJECT(obj); + + if (k->nr_devs >= k->max_devs) { + error_report("Reached maximum number of devices: %u", k->max_devs); + return; + } + + o->ioc = NULL; + o->fd = -1; + o->devid = NULL; + + k->nr_devs++; + + o->machine_done.notify = remote_object_machine_done; + qemu_add_machine_init_done_notifier(&o->machine_done); +} + +static void remote_object_finalize(Object *obj) +{ + RemoteObjectClass *k = REMOTE_OBJECT_GET_CLASS(obj); + RemoteObject *o = REMOTE_OBJECT(obj); + + device_listener_unregister(&o->listener); + + if (o->ioc) { + qio_channel_shutdown(o->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + qio_channel_close(o->ioc, NULL); + } + + object_unref(OBJECT(o->ioc)); + + k->nr_devs--; + g_free(o->devid); +} + +static void remote_object_class_init(ObjectClass *klass, void *data) +{ + RemoteObjectClass *k = REMOTE_OBJECT_CLASS(klass); + + /* + * Limit number of supported devices to 1. This is done to avoid devices + * from one VM accessing the RAM of another VM. This is done until we + * start using separate address spaces for individual devices. + */ + k->max_devs = 1; + k->nr_devs = 0; + + object_class_property_add_str(klass, "fd", NULL, remote_object_set_fd); + object_class_property_add_str(klass, "devid", NULL, + remote_object_set_devid); +} + +static const TypeInfo remote_object_info = { + .name = TYPE_REMOTE_OBJECT, + .parent = TYPE_OBJECT, + .instance_size = sizeof(RemoteObject), + .instance_init = remote_object_init, + .instance_finalize = remote_object_finalize, + .class_size = sizeof(RemoteObjectClass), + .class_init = remote_object_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void register_types(void) +{ + type_register_static(&remote_object_info); +} + +type_init(register_types); diff --git a/MAINTAINERS b/MAINTAINERS index 205b188..6e60215 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3196,6 +3196,7 @@ F: include/hw/remote/machine.h F: hw/remote/mpqemu-link.c F: include/hw/remote/mpqemu-link.h F: hw/remote/message.c +F: hw/remote/remote-obj.c Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 9f5c57f..71d0a56 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -3,5 +3,6 @@ remote_ss = ss.source_set() remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) From patchwork Tue Jan 19 20:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030727 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 C2D80C433DB for ; Tue, 19 Jan 2021 20:37:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 23AC623107 for ; Tue, 19 Jan 2021 20:37:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 23AC623107 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]:59114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xkL-0001Qz-7i for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:37:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xd5-0001cE-W9 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:32 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xd3-0000IR-FM for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:31 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNZBZ002868; Tue, 19 Jan 2021 20:29:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=QY5nIxO44go0zceRhgbLvvjkODdNL2qmvBtMCjdho/M=; b=UIoRLPcM5k0wfmK+lb10txFugf9RrNMv1F4ZG9+LPnY9tfuNY7N6y420BLHuRkAgEqJx es9WjCh14ZJ7mmVKq7Sa1HDvKvPEabK7jytKDoK8L8k7mlilRFWqzC9LYvKPGCvqsm78 XGfjHanH/dX63Cd7iuXHb+d7IuzV9xOyJYEo86WRb1qW6M6HupsQoYF89QqjWaBTD+KP zFXBrKRnAV8mLPTiGYHE91ii1w+f4q+IRnKe61g8TmIY7HeQLprFOaqT8ejzekZAzlYT 5orlvMf4u9ZwPD111pQUp9hD47IZDE1gee6IXBuLAolJ1+EEKdPfqEigtwfh9Yj4Som6 gg== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 363xyhtate-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:21 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKQbYD106679; Tue, 19 Jan 2021 20:29:21 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2051.outbound.protection.outlook.com [104.47.36.51]) by userp3020.oracle.com with ESMTP id 3661kht8c9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=egii90h5CGjvjGK6xmIaHWciGQbXK2WdSjnOy3LTzkn5O7UjS01WV80cp9xdDvzz8WIWodYydsYuFOSi3BXhdVe62kvOZhmfkeTTWhAKEzyDGFURsI9/fz+lH7U89O/r6tnUxsHZSdY64oxsFtAdWyPzTmOfJOaaMVEvwDD7Iur6zikoDmaM1ciLmuYlsX5aU6yjF6EVbHOu7LfVDvmhk2eEPIxqVN56jBW7zqBl++xeLOjYL4HErwYrZ3vG6toOrieh1xF8Wu6vWoa6Bik+z8O8urMpRokme9yxFjacjpKHQnvCMDZVA81Eik8ZjxpF5z5/MFVTDfaWP+Kvlsh4GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QY5nIxO44go0zceRhgbLvvjkODdNL2qmvBtMCjdho/M=; b=fwq5KYCOW8muKtB0QcSq3MGK6e8/odfSq3IQIXg1zkTt5XNKeUhjVlX0CZ/CqWR/v3brVUzGtlxnqT3ShDRTzcZA5ghXy0hZ+uFPhRg/uTwNwCTGAc9waYCXjZhZ4VMmByFxrhC+2sbjsc1t97T/QdnqCsRG5AazlNN8o4lKrGMQuTn4bGPjUWawz16/baqjliPtjUFWCI9n4vDxdtdKrk0GsT9tbJt/MuHZFrquUHwvG4D814kGyWaJvLzKTelffWzTLCrREq01Js9tv8Sw/oHQBffJTwgXjFn1NKbxEnM7cB3hHsAJHMVYY9f0engPxXLS7nYcoJUbc+Etsw5smw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QY5nIxO44go0zceRhgbLvvjkODdNL2qmvBtMCjdho/M=; b=zyU3T8EjJ2/yU7ujWfyjT2YiBk0UKGmtqs5XgPCBNhNCObKEgVnjmVKcUkWpi7x9CCwX7IWZJQ1BI0/OC1HFzypHc9KBaXYc78S4Dvh3f3ymet3xRfAeF50mqAIwm7JoDBsFSvqP1REWBltKu44lyjdSbAlahiXMCimpnjxVvxk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:19 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:19 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 12/20] multi-process: setup memory manager for remote device Date: Tue, 19 Jan 2021 15:28:29 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a1328a9-c7cd-4bab-0224-08d8bcb8e5ed X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M883akLRhpeV/53VXDSvI5oZmdytEKHrf2L12ol1HN8YN+MKVp7VlXPQFce9fqdqSCJIj5tr6MnwtqB/PtB7DPF9UWZoBgdW+IKF9xe7+hTR/lbcGxC9HL5eM6edQz8agnV6s/QGaiNu0NqfZ3do/jffQRUrg8mFiv34anQQYEo0cPJiCIxL7xEl4hY/zDUZQqOP6vfQ7ewih23a/XzXj2HGxP9qz33fZirNM1JsXPeaIsm+sARSb4vnh3+hef1LX/Yb2ZTlN5xyhk8TtaGriiEWvhaC0+/6eK2b9dLcTKV7sgnIwOgqCcM6VubVpU/wAqV6tdvC9gz3jMHX+W1iiqpHoOMMoI8U54CjtcosHV84k9dcynQ+DxQcLJJ5FA7ieIEl1LkhOs2zyIGQ6J3P3kSTlHU07Ki9phoki7XR5LdGrYfI0aJh+3bYYiyoYlNRgDm+A1TNA+iPPeIQU03xGb7vgBIXLhnYiqrwbuXCQx0EHNgfzJMkwckIF4bsX6FjkwCQNpNURPQJHJt+nrzJxg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ZXWQDM/cqo73Qg8TLkD0nq0xAMDnF4?= =?utf-8?q?BdYUG99nTpxcn++RPt9V1fVXHCYGovEv/sxBJYBhy/QIHv8/fRtRcHYy8YWCuXhfa?= =?utf-8?q?bPbzIkk3G+A1URujIEOhqLRYFUgkqxvvPjX/sN1L70nxdgHC1W3FQNEJV/QjeM9iY?= =?utf-8?q?bZpihFxDlgQSjWDRfP8bViopbP2NiYeCBCQoLlIVAwvjgsr0ubDF7HzCPi5GBxleL?= =?utf-8?q?ZZ0LC8S1rNRnOaTNC1+LTsykWB6wcG6SbLg5vLVCmxUtoEGz5OdsfowAOHbjYOroT?= =?utf-8?q?Ere4Imy9dlT0cTs3siqn0vfsz/OUpgfoFQMzK+RS+0nwC5Hqyrt2CCZQUnxoMoRzQ?= =?utf-8?q?oFd9sdGedXDfPwuqFxe/lSDVboRbz4zxwMDPV6HCMQfBzik9OqTfSyVZR45o0yUC3?= =?utf-8?q?iGr0DFWZAILuiN0LwfpXoccep/U62Ch4sM+98itTEDp0/ob5tkvLmYEjf4XbHht5y?= =?utf-8?q?ZaG7NH7+g7EaLbS4i7ruUmj51b7RaMHYSzA/LW/xHVxZnUMWDJP6S9kL+XpF0ocPM?= =?utf-8?q?OOANlfYuEiyUkPSOuKyFCCalVQh1Toy3v4HNAh7szW8R7Q3bvnLEB90emnV9zeGvV?= =?utf-8?q?5cKukyFmhWw6sjad0FBJ5mqcI7ShYpTOKDSicINoddEBWAJrEO2GVhOVlGuQ11g44?= =?utf-8?q?PxNvAU/poAGnNxUoMKIAaRnFQYwN1YTXEnZ6fzW0mz8Wa0QIMFrpwgakEL4ucJXBh?= =?utf-8?q?f+9EIThrlOy5QWlhF7UjN9i//rIR3uYOqh7oeoYaqYiqUhIP77KucsRAdlKl+vxBu?= =?utf-8?q?u0H1PyXFickc5PsT41MFF92mDie5e/md1SfxzrTiSWISJs84F4xgLuLSbSY4MeqEc?= =?utf-8?q?69IMN/m0jLGYOqTR7aKKM64DqWLhkYvVMjYwaqd6EPX1xeSzNBBamxruPxQEajWBV?= =?utf-8?q?/tGObxdMHwOFysf2CvjyP3L+ZZx3t0iIZ09Pv8tA2hxE2t+vXrVVHkXlKafi+6k?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a1328a9-c7cd-4bab-0224-08d8bcb8e5ed X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:19.2363 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z0yhGfHcf4FJHswzL2uDd5aIOWM95EjfiHNatp/r10fhqCwxlC8OQ1mb1MCW7e93JvaAv4a8vipm4c/9JcCkPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 --- include/hw/remote/memory.h | 19 ++++++++++++ include/hw/remote/mpqemu-link.h | 10 +++++++ hw/remote/memory.c | 65 +++++++++++++++++++++++++++++++++++++++++ hw/remote/mpqemu-link.c | 11 +++++++ MAINTAINERS | 2 ++ hw/remote/meson.build | 2 ++ 6 files changed, 109 insertions(+) create mode 100644 include/hw/remote/memory.h create mode 100644 hw/remote/memory.c diff --git a/include/hw/remote/memory.h b/include/hw/remote/memory.h new file mode 100644 index 0000000..bc2e309 --- /dev/null +++ b/include/hw/remote/memory.h @@ -0,0 +1,19 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2021 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 "hw/remote/mpqemu-link.h" + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp); + +#endif diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index cac699c..6ee5bc5 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/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 @@ -30,9 +31,16 @@ * */ typedef enum { + MPQEMU_CMD_SYNC_SYSMEM, 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 @@ -43,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/hw/remote/memory.c b/hw/remote/memory.c new file mode 100644 index 0000000..32085b1 --- /dev/null +++ b/hw/remote/memory.c @@ -0,0 +1,65 @@ +/* + * Memory manager for remote device + * + * Copyright © 2018, 2021 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/remote/memory.h" +#include "exec/address-spaces.h" +#include "exec/ram_addr.h" +#include "qapi/error.h" + +static void remote_sysmem_reset(void) +{ + MemoryRegion *sysmem, *subregion, *next; + + sysmem = get_system_memory(); + + QTAILQ_FOREACH_SAFE(subregion, &sysmem->subregions, subregions_link, next) { + if (subregion->ram) { + memory_region_del_subregion(sysmem, subregion); + object_unparent(OBJECT(subregion)); + } + } +} + +void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) +{ + ERRP_GUARD(); + SyncSysmemMsg *sysmem_info = &msg->data.sync_sysmem; + MemoryRegion *sysmem, *subregion; + static unsigned int suffix; + int region; + + sysmem = get_system_memory(); + + remote_sysmem_reset(); + + for (region = 0; region < msg->num_fds; region++) { + g_autofree char *name; + 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], + true, msg->fds[region], + sysmem_info->offsets[region], + errp); + + if (*errp) { + g_free(subregion); + remote_sysmem_reset(); + return; + } + + memory_region_add_subregion(sysmem, sysmem_info->gpas[region], + subregion); + + } +} diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index b3d380e..4b25649 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -201,5 +201,16 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) } } + /* Verify message specific fields. */ + switch (msg->cmd) { + case MPQEMU_CMD_SYNC_SYSMEM: + if (msg->num_fds == 0 || msg->size != sizeof(SyncSysmemMsg)) { + return false; + } + break; + default: + break; + } + return true; } diff --git a/MAINTAINERS b/MAINTAINERS index 6e60215..27216b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3197,6 +3197,8 @@ F: hw/remote/mpqemu-link.c F: include/hw/remote/mpqemu-link.h F: hw/remote/message.c F: hw/remote/remote-obj.c +F: include/hw/remote/memory.h +F: hw/remote/memory.c Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 71d0a56..64da16c 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -5,4 +5,6 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) +specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) + softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) From patchwork Tue Jan 19 20:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030739 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 F06C0C433E0 for ; Tue, 19 Jan 2021 20:40:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 051CF23107 for ; Tue, 19 Jan 2021 20:40:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 051CF23107 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]:40078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xny-0005DQ-1A for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:40:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xf8-0003Zy-Vd for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:39 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:60726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xf2-0000eG-0B for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:37 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOU4Y003527; Tue, 19 Jan 2021 20:31:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=aq4qgM/9ZUvfZcUCOWu4yZOFwO9YwtwroNXUeqyYPFM=; b=QadsxWVI8H1JUN5QwhMbEwEK4cyTUsImNmXe+UC2ZBiX51Cv/rOAZatGnrWDdJliz+xW FuTU6XaaMPK0RAgIi7VpQ0+5b0BN/HBDC0e3fHKwUxSximKzieUYC6IG6cKMx+DCf5lm 4Luc/vJkqXUvgDAy1z0cGXI21L5A6B/OeA/S/86zPKcnz//KsCL0sCYYqYUGQWMqUe19 Y4Z3ZOyr2xiZDMk/4PV3EgI5uYEBJxs7a3rSzGkZXT9LqUvOrFUU2YLObI9mN/7D6lM/ i1Dhshjnpbw8Wzy/CA8us/o83byZgDBwbeTph5YVFHscr0FJuG0xeZ/OhG0Eo0oClbXw Bg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 363xyhtb3j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:25 +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 10JKQcIu117505; Tue, 19 Jan 2021 20:29:24 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2056.outbound.protection.outlook.com [104.47.36.56]) by aserp3030.oracle.com with ESMTP id 3649qpu97n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=glb/gM4Lq4ODyOJroAnZrG/kqCtxGU+gV6ora60FPGR2HV9aiAn4cUlGTBporL6WKikqGxpsVkQcbLdWJi3QCCRJt4T0MJlbuF2FlvRlekSr0ljK7m0BNuuOQcTL8ySjB03kBUTVSFmiEg6o3wUHYlYSiVSvuu9dp2z9ySTeTXMghxJtg3WxGupHcMmgXoqYU0vqyt9yc6pryG9OI3EpqGhuNj0dS9ApWiLedNXTxIPPyACJ6p7ATo5qMaaxvq/dRh0t+btQFkXCH+DkKNpzUuMXtfhCj0EJK/zaK4X8ghzoNXDQrO/0XDpzw6hRdnKot6rQfI34Di5413a+A40z0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aq4qgM/9ZUvfZcUCOWu4yZOFwO9YwtwroNXUeqyYPFM=; b=SpNjVl/iNsjZrMwC1wIzkMFzw3lk4lSw2f7FsLoT1gU1s4budf4EeKXBQj6DXhPgAnpzFBQF+dhWyPdivTVtCMWsEkAUcP2EKjdAXVd83a4O07Mpm6Ig32lmLzTGS9KAySMP4Qc2lUQF+hxe4D2GwhdNMoPnpIevLvQ/FK1EdtmZm+HD2WFGwE3ZYqOylH89Afq18D8Kg4/xFhOkLGmvr2sjZhUXr6urPyiXH/S27j7UmoHA0egr/B9vHtYXJJQl8xJA5KtyMdk63pT0qaaoG4WrLLaw6FM42FEVUVJ//o5Ar+PXIRBZL0lbnJcugUZvVDXaPc32Yb6q/Tt575l6KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aq4qgM/9ZUvfZcUCOWu4yZOFwO9YwtwroNXUeqyYPFM=; b=Dp+NOBs3EhJkbrEqjYDONeuSZ7SupU79sDQlfc2CUsjfbZ6dlApX/f0s00Bngi/0p+JLOcrI3RY7yvRUcD9tVtykGXG41A8wWTgxyVq2fA6y8ART781h4vgG9KvSTNQMaI5Vyl3pUT5VEr3yw1Dkag2T7zC1q5Ic4ZimIfLAuAE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:22 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:22 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 13/20] multi-process: introduce proxy object Date: Tue, 19 Jan 2021 15:28:30 -0500 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a6b421c-811f-41fd-cc1e-08d8bcb8e7af X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:525; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nGp1aZknmH9hliLna8Uc4d9zQNArETudgghyzVE15yKJVUjqu9NcU2HmWjHLNGdlXjRXsb8uGr4iXgpfLKQOnkQbk3yEGLlG+N8upD6rTUMNVruuncuRhyS/o8V46i4FijUVecK9uhlEiY0Z6VI4pinQ+eQ9c92PrTczb/z2DaDbC1u2Bhw2CM5ZPclMOnQW+kJPMTRS8JGY+4v/ccNrellJUnTMe8Dnz//L7AWg+ut8C6l0yfk4vTOOvL0LldrL5D8tY9aWFwoQOZQxb2RLsxYhlfANtbCI7Gpi0pCZTUtXLPcm+Wl/O+qeSYUdRr6aF/MnQ2h6G9SyCr5wWE0XztNZLggEhCr8SL6ORd8STlx1Yb/Ez2/AazKbavwRuFex+2RqvF8WEThru1lEwYlrBGxjEXFbnC3ATY1uQu9DBZCkoMU1QK7I1y0xWx4IqmrhROhRqr64yFkRA+jiv3rp51UjutI3XyuJUP9o0vi9kNUJNrnjb6POD43F9nDSREDTNNcjVOXNiXliyvLcp84bcw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?fT2wRAKgdHOz0h8CUPFTUPnIlkQcos?= =?utf-8?q?0N24V0UKbUwJxybhwCSJ1rqRh4PA22raoKTTWDGNXGnZ3T375f73JW9K7wZayW0Gr?= =?utf-8?q?SnXbpP9ZFGuysvDy4pBVutJMS66KRJc9Q7zFHpDAKQoQWfnSO48WSd/sliqZxMudc?= =?utf-8?q?rxF6UoMxJWYUXTw9paQ5AYxcC5MaxNkog7a2NZID+QOe9TDdnwxhO9FAcHElhVoO0?= =?utf-8?q?fsOCyghdYDNvglV0ixWZbkhLtHda6BpQBSH1w6596Ua3pht9Vg+yRWay2AAeU20Vb?= =?utf-8?q?TcIF9zuGt6iFl6+2UHvqh7y2j6e8BgpkX1XdRL3DdEIs22Y+Fo6/hv1S7/2qoqmem?= =?utf-8?q?+4riuhM4zJRjRLNzTUkGIsYGCbvHdNChRRHxhZygXCtWCxXHoJkF4lTGsh9WG9U1T?= =?utf-8?q?RK8IcAb8blgR3IC5wYYEl48QJZYHZGvPV2iEKwvAJb7TCgTsLKk6KnrVtwopEiCmV?= =?utf-8?q?7oXr9TQmNiEw3vDgjpda1XlMeqLG6df3dzMnOUXAUTSFAYh5OPHLG+YOwVmCejMsc?= =?utf-8?q?BRG/eYVTddESg61UWt+ypfMqv0Xw2B1SZ9bWvrPS24WxAq7qnGAJagO88iim0Arb1?= =?utf-8?q?veMo5FOKHVJnIX/DyR20CC7hNOYYgFIjAdoQrfD3NUMTqptrLM+uz/+oAX4WVfwoe?= =?utf-8?q?tjJG4szNJwL8WhyX3I/7Iuqq6QVcX5Uq9oW2teKTmPhe/u2NVpFjjkVgtx0kImaAq?= =?utf-8?q?hUAB4DdTaP8/n6Aw1PUDJRtcCXUjq+ddnHNQi23QVocmn6NiKjgWydUEuTbCbU12A?= =?utf-8?q?v5TQZq+hk+MunKKeYdRX+Q+ykxtUmj9EdkPyM/zME+8eL0ztVoWzxJ9QBplCxitUB?= =?utf-8?q?VD5qXupQwT8cnjTv3Yms2Qt0acYJK3xLIlC9Fbg0dGe0glDAH4mZmjAT4OKdz87ZW?= =?utf-8?q?BU76WfoLAbgRRFt5L/TR4GSQy+xhwaleE1otvK/2wB3fWlY8oyjSAJUfJ3txoyc?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a6b421c-811f-41fd-cc1e-08d8bcb8e7af X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:22.1976 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: k3JfOy0i96sDNL6j/MVSW2lHZ7bWcnXehrqGJJy2N3jSqMgSAuEfw6xFEVd4wJjNkEpbGx8uOTTXif5gjbEaGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/proxy.h | 33 ++++++++++++++++ hw/remote/proxy.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/remote/meson.build | 1 + 4 files changed, 135 insertions(+) create mode 100644 include/hw/remote/proxy.h create mode 100644 hw/remote/proxy.c diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h new file mode 100644 index 0000000..faa9c4d --- /dev/null +++ b/include/hw/remote/proxy.h @@ -0,0 +1,33 @@ +/* + * Copyright © 2018, 2021 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 PROXY_H +#define PROXY_H + +#include "hw/pci/pci.h" +#include "io/channel.h" + +#define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" +OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) + +struct PCIProxyDev { + PCIDevice parent_dev; + char *fd; + + /* + * Mutex used to protect the QIOChannel fd from + * the concurrent access by the VCPUs since proxy + * blocks while awaiting for the replies from the + * process remote. + */ + QemuMutex io_mutex; + QIOChannel *ioc; + Error *migration_blocker; +}; + +#endif /* PROXY_H */ diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c new file mode 100644 index 0000000..cd5b071 --- /dev/null +++ b/hw/remote/proxy.c @@ -0,0 +1,99 @@ +/* + * Copyright © 2018, 2021 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/remote/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" +#include "migration/blocker.h" +#include "qemu/sockets.h" + +static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) +{ + ERRP_GUARD(); + PCIProxyDev *dev = PCI_PROXY_DEV(device); + int fd; + + if (!dev->fd) { + error_setg(errp, "fd parameter not specified for %s", + DEVICE(device)->id); + return; + } + + fd = monitor_fd_param(monitor_cur(), dev->fd, errp); + if (fd == -1) { + error_prepend(errp, "proxy: unable to parse fd %s: ", dev->fd); + return; + } + + if (!fd_is_socket(fd)) { + error_setg(errp, "proxy: fd %d is not a socket", fd); + close(fd); + return; + } + + dev->ioc = qio_channel_new_fd(fd, errp); + + error_setg(&dev->migration_blocker, "%s does not support migration", + TYPE_PCI_PROXY_DEV); + migrate_add_blocker(dev->migration_blocker, errp); + + qemu_mutex_init(&dev->io_mutex); + qio_channel_set_blocking(dev->ioc, true, NULL); +} + +static void pci_proxy_dev_exit(PCIDevice *pdev) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(pdev); + + if (dev->ioc) { + qio_channel_close(dev->ioc, NULL); + } + + migrate_del_blocker(dev->migration_blocker); + + error_free(dev->migration_blocker); +} + +static Property proxy_properties[] = { + DEFINE_PROP_STRING("fd", PCIProxyDev, fd), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->realize = pci_proxy_dev_realize; + k->exit = pci_proxy_dev_exit; + device_class_set_props(dc, proxy_properties); +} + +static const TypeInfo pci_proxy_dev_type_info = { + .name = TYPE_PCI_PROXY_DEV, + .parent = TYPE_PCI_DEVICE, + .instance_size = sizeof(PCIProxyDev), + .class_init = pci_proxy_dev_class_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + +static void pci_proxy_dev_register_types(void) +{ + type_register_static(&pci_proxy_dev_type_info); +} + +type_init(pci_proxy_dev_register_types) diff --git a/MAINTAINERS b/MAINTAINERS index 27216b3..ee04d82 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3199,6 +3199,8 @@ F: hw/remote/message.c F: hw/remote/remote-obj.c F: include/hw/remote/memory.h F: hw/remote/memory.c +F: hw/remote/proxy.c +F: include/hw/remote/proxy.h Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 64da16c..569cd20 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -4,6 +4,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('machine.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) From patchwork Tue Jan 19 20:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030799 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 94AC8C433DB for ; Tue, 19 Jan 2021 20:58:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2DCD22CE3 for ; Tue, 19 Jan 2021 20:58:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2DCD22CE3 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]:55430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y55-0007fa-KS for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:58:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xf9-0003a9-2b for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:39 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:60784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xf5-0000fg-2h for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:38 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUs9002789; Tue, 19 Jan 2021 20:31:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=fcOYsIut7P+7V3lCOwx9r74mhX1CARiekYFi7+KIyC8=; b=sTfDBjLkgWDZp8V+lif4M6JwD0wpGdEJ3se50XPuH31zeKuHy3SI36TGhPGLyTKjwRfw OpMQkOhg+QKPeam1+r0hBfg4lGgnZ+9EfeboUqk7KsFpGY1mVPFn9ED783T6pvv66F5C 3mLVmjyhVIGeVuLXWWwZnR3Q584lVglf0Byh23ITK8xSDwrnG4wygLOH9Xy6HMQPDUjk BNTJJ/SUSPdcRCLhBIih0uKPmxigLkKSTBRUWv38ocg7vkruejqKsdTuaZZbG1ov3Pqg nFiXUz3rDEjeQGtd53NrNotWtuaYh7csH7M/bROIE5cQ8DIAHqi1UYjyfsVGzT1IyB0r 1w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 363xyhtb3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:28 +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 10JKPc7P128314; Tue, 19 Jan 2021 20:29:28 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2054.outbound.protection.outlook.com [104.47.37.54]) by userp3030.oracle.com with ESMTP id 3661njtast-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H42Y8RRUNogi3SPZs9hSvNXcUg0JLVb3YylZAUAsbVoidCCVWUhXpA9DGjG2ZHjIbcf/kyM4pKUpAh00aevMsLEZ6pW6v86MHpa2nkiKpzHkSIj6+j1cuQ3Lt6mahxYYu23/hpTbvO679G/su2jlcFUCGNo6EGMWvnThraLszeRImbtjzvuzu9qWEEIZa5K9ivCywQoiazWRFMnLi+FS1Tvf8SsijWa/Ay8OkzCV+JHEjo1LdZJbzat4XogNnsmDJKf0LxMuE28/dUNv1ij3sf/Bk9p2kiYWJLF9EftxuBvl4caDCJA483QbUqxUSigwpz0pOqYX8KXPIikcA4KJ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fcOYsIut7P+7V3lCOwx9r74mhX1CARiekYFi7+KIyC8=; b=lIEBG8b8wTkaql6LdOxY/MLRIj+3tLxmUD0Sw2X8QgVCnUx1BsqI4aGzbXRDIMPnHRmUIKepcFABELa5UcFyG3xTVbdVNNDQ72o9a7Iu2CqjFe0CwqC92e9dUfDtFlSJz2xk4Z0Lh60XprI75VNjd7cnEuhsFkfV/OxBilpTzc+yLxFuccQWVn6/dpaJfj3k4JNG7JPcOaRA8pSbslLjD+oq33Up2yJeFPfWfAgES76yHe26/KVikt3+A4y9Pf+GQC8PYSqMETzbQzzniovgYex1yVFE3C1S9PLLz3nhnIprP6J6RxB+ohSic1nnEsXfoyZaeD/r8NeCDkjZidUxKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fcOYsIut7P+7V3lCOwx9r74mhX1CARiekYFi7+KIyC8=; b=xj0me+IjqNKW3NJu2ozs/a7CpVP5zwNmgrzhzpjs2GaboO+PMsNQkhZ3YkmICRCP8Eiuhq00VOoCuhw8IBnlFEqmzRPg7gRjOwaY+OSn0fLefte18mhGs/Bu5XSugKtqKUwAOlrNDDtxyGdhaWiok09VMK7j9vAS4vHuHBnMcvE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:25 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:25 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 14/20] multi-process: add proxy communication functions Date: Tue, 19 Jan 2021 15:28:31 -0500 Message-Id: <9ee013428a49194a17f16952ad579f7e057b531c.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d1f22f5-eab7-43c4-c584-08d8bcb8e977 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ay5/3Tr5CmZ5ZGjUu0EgtNsybckk1pClp6qQm0/2XE/j1LGWmJjjOdTK06XZxZL0qrC/Gd6uFohn2EQfaLbrvdPa17URqlbPbbWqUY81KML4ooptRXnr6SN5JlU4oZKTIinTbCqDh58OihNFlVFmkB109UcJQxv7tfI9U86YFKaPDgr+V6+lmwd2QWp4awRlp3WaHTCzyIThNkf7rvdODpmn5wzFDkGAJrC6M93c6oJ5ippV6alcxgM4Wnmr1eBSdUpIezMzA4OazsVBBRgf44Qjl1HKfhRBVgo395wjcDsXYc4c3OxwaLd4wxNxnG1dG022P+SFxHLVfdHRm75J1KhDkTpRFBsfoLEfMb+Eh7Hcw+CQ/IyF20U/4CGlsqw/hqTPMO7Lev6bLczOGeXBjQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UhnH3DBA3LMgVs28iHJiwLPwNQQZ4GogmXAVUwQN5xumsRaOHjOnqum1PSgJMnc18nh8SKLZq2bpOpmY+lTmonvF51i5CQfzDY1na/Rq3lcN3+SKmQ2GV7OHppRmhQYsmIkSAQdsBJwYCEU9hozLBjn6MkN095cacD6+ByDhvtG4ep9iMclIblV18iw13h5GEClTB2/EJxfP5TrAv7cWwbJn+TF256wU0KaZIy+dez1Jyp3rNe6tYRsSav80wxSjtFpS4XyJrmIPLZIt30A9jHcQ+CHN06TD9hKBglQW5C9nHpDZ/2hjQApAz1TftMy6AZaSxR5V5q2Lll9ylP4FdjWhcSnByHhpeHsD0f7whOPO32urSvO+87iYDAzRze05mLNU5IRrkIWtB+R+eGzHl1g1udbwtub8UK3YWxVt/TV77Niwcs6DmKE61KHd6G0dZKNP4wvRReCa+4MTPNBx9V2Fb6l5GhhUKILtFu9HrjVkVv7uxGF3UmhJHTht3bmu+4+NDNR8uwbe6nUaWyxg2fVEmW8PXuBqtNzSHGaqfbxvAZdSma6qI1A2go8/sWdGdbA1XiCrWx3/Qf2TiYn5G40hTYmIsuzJjdgGTHsSQXMNe1Y8xFFaosXGBgHkKFKhBRUKMEoB+lZ6gT62nvMbfsTnpKXIdytVrbV7uYo3Ceeg5L5by9E6aTbGU0Fv2D2zsa7Q7ooEFFuYAlA5/wxoS8HjdSTWVz0iYLe6m3mLcE31YyeTUNxS3lsqEGqc9L2XQXZh1rpEpalVk/GtOSfaLKKaTdplooOVbrEDFEP4SyOw330LyL0omaNTprHUrlFI/aXG7fKI0Jya3Y98pPCXeWd109rN8cKD/Cp9lhjaK6s77DRTxLVCWMu0mzCaBMh0ZfY3vh1weaJgcxSNxoFkePIHqQ/c+ATCHAhIzTfqP+6rf/GjgXzfqoPTqE2KFxINNizr8/I4C3H8Ct5H1Y2KccGkXtvneoP5d7bJ2pkTsxo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d1f22f5-eab7-43c4-c584-08d8bcb8e977 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:25.2248 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /v0jf8dQ308Uo/ymnb0LISJNNTVOUAYQiT0h4Bs362cjof4K+UDTwCPa1kovoDUrl0ompj4Pp8oCohvpXUbyuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: Elena Ufimtseva Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Reviewed-by: Stefan Hajnoczi --- include/hw/remote/mpqemu-link.h | 4 ++++ hw/remote/mpqemu-link.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index 6ee5bc5..1b35d40 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -15,6 +15,8 @@ #include "qemu/thread.h" #include "io/channel.h" #include "exec/hwaddr.h" +#include "io/channel-socket.h" +#include "hw/remote/proxy.h" #define REMOTE_MAX_FDS 8 @@ -68,6 +70,8 @@ typedef struct { bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp); +uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, + Error **errp); bool mpqemu_msg_valid(MPQemuMsg *msg); #endif diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 4b25649..88d1f9b 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -182,6 +182,40 @@ fail: return ret; } +/* + * Send msg and wait for a reply with command code RET_MSG. + * Returns the message received of size u64 or UINT64_MAX + * on error. + * Called from VCPU thread in non-coroutine context. + * Used by the Proxy object to communicate to remote processes. + */ +uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, + Error **errp) +{ + ERRP_GUARD(); + MPQemuMsg msg_reply = {0}; + uint64_t ret = UINT64_MAX; + + assert(!qemu_in_coroutine()); + + QEMU_LOCK_GUARD(&pdev->io_mutex); + if (!mpqemu_msg_send(msg, pdev->ioc, errp)) { + return ret; + } + + if (!mpqemu_msg_recv(&msg_reply, pdev->ioc, errp)) { + return ret; + } + + if (!mpqemu_msg_valid(&msg_reply)) { + error_setg(errp, "ERROR: Invalid reply received for command %d", + msg->cmd); + return ret; + } + + return msg_reply.data.u64; +} + bool mpqemu_msg_valid(MPQemuMsg *msg) { if (msg->cmd >= MPQEMU_CMD_MAX && msg->cmd < 0) { From patchwork Tue Jan 19 20:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030755 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 2F89DC433E6 for ; Tue, 19 Jan 2021 20:45:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7097523107 for ; Tue, 19 Jan 2021 20:45:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7097523107 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]:54426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xsi-0002vK-DJ for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:45:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xdF-0001nk-SM for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:41 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58318) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xdC-0000LX-BS for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:41 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNUio002770; Tue, 19 Jan 2021 20:29:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=RdD2os6t3PSYJEZeInDV3U76ZlcxnwkHmDA1IYMV3bY=; b=vUF6GasC4uEWgvqJogVHMuOlhE5eLrrbjia8qkpXrbhgiJORouczDY8lDdBSLyiyqymI 9xGUnF/JDJWIHbBBkBQ8LQUtJtoFeSVqdICPkQ+dIwsqAOyo44n9kG3WSf2QL59PggxZ cvDkVdlwd0yV37AivLzMlhsiIs/YUqH/oGz9RZl3vRO2rOHAOzGHhbnJoThuqGI4sdTo JLEvbYZANzBOyA0E2t3TU1KydSUsXVreH7Fvr93rJTKOoE3rGoidz+b7cGUWr5zHo/RR 7psb4mIM1eZm2p+jW+TOthsbplh2oG5NxZ4c3tFTpCfTd1qCpOQ8l5zrRWVH7LCL8pYI xA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 363xyhtaud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29: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 10JKPjmO175968; Tue, 19 Jan 2021 20:29:30 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2051.outbound.protection.outlook.com [104.47.37.51]) by aserp3020.oracle.com with ESMTP id 3661er950v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=obMmSyWlvLrdcDbiXy/A5Vk8nWWWvrQpL8t6zvG8AX3YpCYo8mt74Kn82z0dkuoFs6hx6CEIshAHFdDHpNZ2kkpE2Nq4ddg8XZZWloeEpzUgm4ZNxHD9aXcep9w+vKXeSMtos+ORcYMj40s5aPVp5wE7DTy/67RX/b9rkxLTDxnmZfnGsCZuF3C0OUS1VJ3RcILWGjxKhwZtvdC57ZukZ5NN/BL2Rnu099iewchl7ni+Rv0ve5MsHBDLtP1tV/nh9a9twI2ok+b7sZWrMBcrb00OKuZpJhN2Vybhaug89DaZahI30veVrvAE36elqBV4zc2e4FhLeqJyZAy60X6pHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RdD2os6t3PSYJEZeInDV3U76ZlcxnwkHmDA1IYMV3bY=; b=bU+PtgRIXGX++JMdXrS6A2yHzFgqN4FIhlpw1KajAd5sU3OpEKReJcqOraCtoy+qmqABJN8v2+qjFrcKWcai68AF5QLV1CyUtuSFnSeC2giv1OZf5YBjD8dNSQh8grQuKMA1WEVV+8c7o0oiPx6VLBQnEFG0pdLqBrgyPxheKvZm5nTZoE8KdBH25AaqTTemJKzas8ciGDHCh2vYRfwwIb6xiESkjpg6ScscUpsqDyUDgEcshRF4lsd6sNGcCIC4Bsx2cjWYHkrniibj6LDuGdsoyMoRe0QXy93peY5nkSbMIouJbjZOM/SAZbHKvGUDGv3hydbh+LOipA6cPr0C7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RdD2os6t3PSYJEZeInDV3U76ZlcxnwkHmDA1IYMV3bY=; b=madxR3fn8I1sH6OXdmjfSU+r+mjETpkVNA2RTZvEWW2DFzhv1myfEEeTvs/od1rbY2HgLadPG8A7oa+oVADoC6wrGWz7HznqmslnbA0z9nAc74AA562ikm2P8niSIkJOux6TZ+jJourbWN5EThRgJ1UsLPtZUUHnUSyYQ41VN+I= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:28 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:28 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 15/20] multi-process: Forward PCI config space acceses to the remote process Date: Tue, 19 Jan 2021 15:28:32 -0500 Message-Id: <78a1ad3a2174de5e2f8bbe74947c057ef0ec230a.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cf621153-ab67-4bf9-03fb-08d8bcb8eb44 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:421; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6avvBL0mDYaMSp+sJdRDo2WukUFihO+nQKi1+njzQfDK7eVyE+Cc+xIifQ5NdJsbPWdOLR/w0zPisDLt7XjC7yb5OdEgCaBmcVy24elIqtV0dR9t/ibYVDaCe2DJiR2OX7EBLj2MVQwNa3IRXV40U5YNIZ8rPh4O+yU6ahQKAlGIjZOVipyK1Ia9Kii6BX+9FHzZQTXA1f9OSFnQcVdIyu3cVnU8ImHU/LoZ7/OTzBUi70uWmrZjIGb18zY1NJVMwUQEpobl+nr/+xkaG5vwTyCvEMCjHj5n6kMikt8jEvPBhUCwjMmKGYi8RvgEX9kOA8fdCLTF45XtufTVi87GZ65VviQOIv2NrpeNlTSeXzG8Znz1y1AV8BjJpdyxM+UWESq3JmbXJL73SN//IDYgmA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: fEHrRz21DjHz+C2qmjNht7upu1F92QFtjiJhmrsY4/0HIrJFGWkZVmy8JOAL0NGGfbde0sO9FcGzrgDly6H3ibG9b420xJVIwJbb/aoW2tYCTOT2aTNtSplrAE6R6oN30FsCxY3iIpWBttRstuFm0s8U0ItPUHilnTi4P3iM1P4qu3+A48nXLLgGuQUFHlbyO87j+Fb4rHQC38GS68J18oymY0ySDGeLeVyGelVi5Rbu11Y2kkf1Hb85IVoO0Wz0iQ71Qywd/9w1RHXhYNmCME8FASckO8VXFOz/Bb7ZZMImZREKeDfK8CoJs65UpCCF5Izj59zJMGAgQ002TCabgSp8vx2ptM0E6eav1wWYxFSAQMzF3L6pfyb0K7JBtACsMkEVkuwtp1eN5hmB4zqRzi+ylMWQ2NUtf+J2+kULh9Up+935V1h2RxVRi2jNKZw4C8MCFF1+fZmeAazA9PIjvXWK2o+zahax5E8CPLEnAA4edqWcYpUgHbYXB0bt3WC7JLUyqqmGAzMjHPOR0Q3l9TuGt5wnlHfYMnb6Oeuxebf45/rQF2GDb44QUGRriFeBkadxQad7sdZ0QRx+FfFI0eES8nxPCqpWZj2D5P0BOsSscizbOJ3M0x2P0h4RvhJwVKqEmHzmHXnl6nxmp+/otiYIdl5rV7ajF6JPl96JHpic5Lq37/KIUYPoUtaikLPE+fQtFJFu1kyJy1vtXHCeqjhRvRCwRpNiNPDyMBeKpmSqWZp8mP13mK0Di9ms5cfd7K6IYtI9ERWV3BoohSlR8/l2nmDeTYlWPveMn+2vCJ++L1cCvD5xisojA0cYjYFhm8duDuJxUfjZPOempmAPAH4smdwyo9SW7CbDwb1M2FZI8UmBD2YqTDCB4+8jtKkQuGS7QhbpUpbtENNXcHOUP4notzo3MjFx6BIAtbZe3tpJYhe2bRMKB0tAcRbM5rNuDhXKvqIGmHKJyPVC23nfemA1mGpwvKo8G5MvQLxF2T4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf621153-ab67-4bf9-03fb-08d8bcb8eb44 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:28.2021 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5bo6BxzVBpO1CESpA5kyQklu3Gh5PfWNyNT2za3Qysoq1BLGS+B6C+vy2O1pJNTCLoY6F9TUbNN6dN6fzXXYIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: Elena Ufimtseva The Proxy Object sends the PCI config space accesses as messages to the remote process over the communication channel Signed-off-by: Elena Ufimtseva Signed-off-by: Jagannathan Raman Signed-off-by: John G Johnson Reviewed-by: Stefan Hajnoczi --- include/hw/remote/mpqemu-link.h | 10 +++++++ hw/remote/message.c | 60 +++++++++++++++++++++++++++++++++++++++++ hw/remote/mpqemu-link.c | 8 +++++- hw/remote/proxy.c | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 1 deletion(-) diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index 1b35d40..7bc0bdd 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -34,6 +34,9 @@ */ typedef enum { MPQEMU_CMD_SYNC_SYSMEM, + MPQEMU_CMD_RET, + MPQEMU_CMD_PCI_CFGWRITE, + MPQEMU_CMD_PCI_CFGREAD, MPQEMU_CMD_MAX, } MPQemuCmd; @@ -43,6 +46,12 @@ typedef struct { off_t offsets[REMOTE_MAX_FDS]; } SyncSysmemMsg; +typedef struct { + uint32_t addr; + uint32_t val; + int len; +} PciConfDataMsg; + /** * MPQemuMsg: * @cmd: The remote command @@ -60,6 +69,7 @@ typedef struct { union { uint64_t u64; + PciConfDataMsg pci_conf_data; SyncSysmemMsg sync_sysmem; } data; diff --git a/hw/remote/message.c b/hw/remote/message.c index 36e2d4f..636bd16 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -15,6 +15,12 @@ #include "hw/remote/mpqemu-link.h" #include "qapi/error.h" #include "sysemu/runstate.h" +#include "hw/pci/pci.h" + +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg, Error **errp); +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg, Error **errp); void coroutine_fn mpqemu_remote_msg_loop_co(void *data) { @@ -40,6 +46,12 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) } switch (msg.cmd) { + case MPQEMU_CMD_PCI_CFGWRITE: + process_config_write(com->ioc, pci_dev, &msg, &local_err); + break; + case MPQEMU_CMD_PCI_CFGREAD: + process_config_read(com->ioc, pci_dev, &msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s" @@ -55,3 +67,51 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } } + +static void process_config_write(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg, Error **errp) +{ + ERRP_GUARD(); + PciConfDataMsg *conf = (PciConfDataMsg *)&msg->data.pci_conf_data; + MPQemuMsg ret = { 0 }; + + if ((conf->addr + sizeof(conf->val)) > pci_config_size(dev)) { + error_setg(errp, "Bad address for PCI config write, pid "FMT_pid".", + getpid()); + ret.data.u64 = UINT64_MAX; + } else { + pci_default_write_config(dev, conf->addr, conf->val, conf->len); + } + + ret.cmd = MPQEMU_CMD_RET; + ret.size = sizeof(ret.data.u64); + + if (!mpqemu_msg_send(&ret, ioc, NULL)) { + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", + getpid()); + } +} + +static void process_config_read(QIOChannel *ioc, PCIDevice *dev, + MPQemuMsg *msg, Error **errp) +{ + ERRP_GUARD(); + PciConfDataMsg *conf = (PciConfDataMsg *)&msg->data.pci_conf_data; + MPQemuMsg ret = { 0 }; + + if ((conf->addr + sizeof(conf->val)) > pci_config_size(dev)) { + error_setg(errp, "Bad address for PCI config read, pid "FMT_pid".", + getpid()); + ret.data.u64 = UINT64_MAX; + } else { + ret.data.u64 = pci_default_read_config(dev, conf->addr, conf->len); + } + + ret.cmd = MPQEMU_CMD_RET; + ret.size = sizeof(ret.data.u64); + + if (!mpqemu_msg_send(&ret, ioc, NULL)) { + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", + getpid()); + } +} diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 88d1f9b..5bd6a9d 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -207,7 +207,7 @@ uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev, return ret; } - if (!mpqemu_msg_valid(&msg_reply)) { + if (!mpqemu_msg_valid(&msg_reply) || msg_reply.cmd != MPQEMU_CMD_RET) { error_setg(errp, "ERROR: Invalid reply received for command %d", msg->cmd); return ret; @@ -242,6 +242,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case MPQEMU_CMD_PCI_CFGWRITE: + case MPQEMU_CMD_PCI_CFGREAD: + if (msg->size != sizeof(PciConfDataMsg)) { + return false; + } + break; default: break; } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index cd5b071..2b14394 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -17,6 +17,8 @@ #include "monitor/monitor.h" #include "migration/blocker.h" #include "qemu/sockets.h" +#include "hw/remote/mpqemu-link.h" +#include "qemu/error-report.h" static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { @@ -65,6 +67,56 @@ static void pci_proxy_dev_exit(PCIDevice *pdev) error_free(dev->migration_blocker); } +static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, + int len, unsigned int op) +{ + MPQemuMsg msg = { 0 }; + uint64_t ret = -EINVAL; + Error *local_err = NULL; + + msg.cmd = op; + msg.data.pci_conf_data.addr = addr; + msg.data.pci_conf_data.val = (op == MPQEMU_CMD_PCI_CFGWRITE) ? *val : 0; + msg.data.pci_conf_data.len = len; + msg.size = sizeof(PciConfDataMsg); + + ret = mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); + if (local_err) { + error_report_err(local_err); + } + + if (ret == UINT64_MAX) { + error_report("Failed to perform PCI config %s operation", + (op == MPQEMU_CMD_PCI_CFGREAD) ? "READ" : "WRITE"); + } + + if (op == MPQEMU_CMD_PCI_CFGREAD) { + *val = (uint32_t)ret; + } +} + +static uint32_t pci_proxy_read_config(PCIDevice *d, uint32_t addr, int len) +{ + uint32_t val; + + config_op_send(PCI_PROXY_DEV(d), addr, &val, len, MPQEMU_CMD_PCI_CFGREAD); + + return val; +} + +static void pci_proxy_write_config(PCIDevice *d, uint32_t addr, uint32_t val, + int len) +{ + /* + * Some of the functions access the copy of remote device's PCI config + * space which is cached in the proxy device. Therefore, maintain + * it updated. + */ + pci_default_write_config(d, addr, val, len); + + config_op_send(PCI_PROXY_DEV(d), addr, &val, len, MPQEMU_CMD_PCI_CFGWRITE); +} + static Property proxy_properties[] = { DEFINE_PROP_STRING("fd", PCIProxyDev, fd), DEFINE_PROP_END_OF_LIST(), @@ -77,6 +129,9 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) k->realize = pci_proxy_dev_realize; k->exit = pci_proxy_dev_exit; + k->config_read = pci_proxy_read_config; + k->config_write = pci_proxy_write_config; + device_class_set_props(dc, proxy_properties); } From patchwork Tue Jan 19 20:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030783 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 C1589C433E6 for ; Tue, 19 Jan 2021 20:49:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A7D622CE3 for ; Tue, 19 Jan 2021 20:49:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A7D622CE3 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]:35560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1xwr-00078K-Vp for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:49:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfF-0003dr-0M for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:45 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:39520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfA-0000gB-SY for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:44 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOpKO146203; Tue, 19 Jan 2021 20:31:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=WWJvgtB3AelazeMKJ9LuGJwKpRD2TFnza0WlANweXA0=; b=G/nPFqKt0pcgBKC9fljsiwYy0kaeg18LXxGCyVW6Ry1SrHdumVmaphD/IfW6MeZemGyi YfKwM2awl32uLzw/4McREJAGw54LMb3GXnYTDKYMhJocDRq24j9T7g3Z3W07tJbG6MJT KAj9nmjoD7RsKmyX9N2rQ1LBlT1l/ID7tzusB4fD93rf3nUA4fqK5/jLnOLAKC0UZm28 lYt9lyqkfHGbcBQW4GO6NpgMs+H4kT7BFm599sFLpTbUmDJE6I9GYdE5WI/yEQXwyqwy lIYR8+GIxpu8BjP8YdbjWIMftueYO7HbHNiPiO6HWmoHy7YCDJtHBNZcVDIXqlVgs6EF /g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 363nnak561-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:35 +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 10JKQb6b106592; Tue, 19 Jan 2021 20:29:34 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2053.outbound.protection.outlook.com [104.47.37.53]) by userp3020.oracle.com with ESMTP id 3661kht8h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=az9DeAkOvOHDWQxluhwRdbuTfhb1p7azdFk3RkSvvf34v6jroO6kV+G6O45X8uMgGBnXkJjfdwxfUkoOUATETPPk44+gytXi89misUQg/LMtpTcwB/MYSJNlP0SsccMZ93b4SJM/bsC4BXwVWQgqbOa6HvAinIZc7gQhVsK0bgDyJEqbuRCXfWLlmBs5UiUfqb+0kEfNGJKDZWfBmEvrB/eanYwF/x8XXMsl01BrKJzOT8SDg3BQMYbs7kUSJjAEk25+QVRe7aPBhEhjADDbBvX1HUOGrbqnug4+ufo0YHWqOJvpcmj6pWyfyr4S/Wdd4x5rLj/ePu/E607KBoazkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WWJvgtB3AelazeMKJ9LuGJwKpRD2TFnza0WlANweXA0=; b=bw5fSh0rhuiLEsFGwjywofkFHeO5EGkLnM2c6l842z9I66D/cmrLOCucmW0PCSTWAnkqJUsX8jceDF6vWTXFe3zL7+J8cgvVO+FqlSjfHv8zNykkuHaSSjCE2Chee9QDolCQEjiiOCav/oB3DlmHAGTluBvxJwrmaXXEbF2oQj0CO7cxANuYmtOOpnwJeP/feR/pBpcRjCtnBMSqk3jOBFIcZdFsly0tk5Sl1WW7SYdTZuVDVCHzV/xr0O2VPYhg1fXPOUn7V0iw56ZXEybasb9qFIEHZnLOLaLCwUFI7U6lp1XZdHT2XF89W8UOuuiU+4vuyjQGnA6PZYS8wDKndQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WWJvgtB3AelazeMKJ9LuGJwKpRD2TFnza0WlANweXA0=; b=ehYNJa2iZG8pH0fLdfNvzU+M0NErOTI2073Vmcm4jY06fnZz5WwmCPrOgJ5QffoZnV6LuPO7VLGi7v6RR5EGS6ZPl/grH7RPa10ciCHMVTPW6FnTIOMoEXtat5B8SIWAG+DQeUsgiWMCu6XX5jfZDztnZF/gCxC167u0bWZpIM4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:31 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:31 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 16/20] multi-process: PCI BAR read/write handling for proxy & remote endpoints Date: Tue, 19 Jan 2021 15:28:33 -0500 Message-Id: <009f187044136fd5316fc0ffa652379364cdcfb6.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e51b66ed-cc50-4763-ef3e-08d8bcb8ed57 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DIdF5zKbEMqxU+qMHBydY/ZI5AASJUeX/BS+1GTU7lyOCEb8cf4OmOwmx2kounsX4nLviVZOEAltGYdgHws+3Oj7zl53Y8IXSpCmS3WVo8qsKF5jXimZ6FhY7SbP7+h4b157a+V3ZRM5KXhEJTY0YUX0aoM3Vb6CZUOcAIz26hZ/BMRZz6NvvHkDxAsTRsvM4Rnc/yHib61tumpilEbnyXKp4NLiIJwAr0CjUao76tcg8SzUsmngZgJEFG0oQ5lLGj/4nrxKa2x8BmfqTZNLKaggX+cKYSBp/NvkYVLqJV8dUVe1wZN6jAPCzO3DrB0qXXbLRkMyIB+jgq4KQKLtt77rp4nvhjS8E+qlUEPZC9RjxqWvMUm9PAxBVVcWGf7f58w5q5tiCbznMeU2bNyK7A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(6666004)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KDfbD7J87OD0Wu8G+8XuQXyiCBPpcHmKc6GUgZeNeuZrbM4q3KThJUCdkPwPAX1Dv6kaKZe3LF83lpmvPZjeJAqhhXA9b8Jf8CIDBUdfMqXg7fx5N3m3xV+1jG8wZCa0HvhcngZhtNOtJW0rdYyDuNbt2p0rvZGXtx38DCSGOfN6W0uSlxQ2BiaApp4mTixbYLVgFIvnqh/fB8M1XjbugsB/762V7qOVpDL9Z14Krg9byk+apzQVLjeL2cUx8tNjyLN6/LGGYwfUKuoYCdTuI6d9QG9lDgPCcilQ90ofCJxhw31YoCR9KYMlB5mkEClB78zQqJQqb/KuNDbunwRqvxZlco0U0/oBntHgx9g+GgQ9/qzj6xWDSxEA6j0rTpkKlaZbNjvXQYK/QHoT/15EZEmKBv2Fe6hnnjCh+Nggjl4cY1vKYQKmDAhmjyqNqWV23xC3hGWnwcZ0HRjxjis488wWRMTYvBpSc5RipAFsHLsN/Dsf3FmHunjLhYwQmZ0fR3+ZkCAtt21iBY5n4hSZz/PGcCS9/1kRSQh8SLSN4woAsECtwgS3/xEP1AHaUTzw/JrNVxWg5sr2n+iB0e6UlnOHXX9CDGljCgPDfMuTUS3wRCiY5kIGVeLOnZkr1Do0IO/+XHgU4Gx44N1YuBPhSUmTUKPO7Y+XsMW+K6Udmi9/Knlk36wrQagZoDggDE2y9NPs2ySzz1qNwYWz2Ekm8G52GGhCUM31qiQE/gxKINZJCZqe7UKUyNHnU9d6zEnBFN8vY5XwY/Cg5iWsQhkDxMRQaoFQ91SwwM6uxddoKj6rBBIw2WS5UwZxq+mKt1t3M+SJojgWdRqbbMXNijnn9kYEuf8fOj4gwMv40JX8SGbXqKPZJQXsgD8GAVXQbBh6YoXp+UngzlMwKnKNrvsDBxwucuRuneEk7tsMGquliexK6AaL+05tN8YEV4jo60AwvaPdr9A5TZugnA77KETIHKhdbL8zc+D4jLO9sdF4wbM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e51b66ed-cc50-4763-ef3e-08d8bcb8ed57 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:31.6971 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 79hhuDCSufziJPRotHON2lKaKlN22kqRJJxj8sO604v4xFCF+QpcZ6zKm6npvKTJYOjAwPaLG6+60aw7jMtZag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.79; envelope-from=jag.raman@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/mpqemu-link.h | 10 +++++ include/hw/remote/proxy.h | 9 +++++ hw/remote/message.c | 83 +++++++++++++++++++++++++++++++++++++++++ hw/remote/mpqemu-link.c | 6 +++ hw/remote/proxy.c | 60 +++++++++++++++++++++++++++++ 5 files changed, 168 insertions(+) diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index 7bc0bdd..6303e62 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -37,6 +37,8 @@ typedef enum { MPQEMU_CMD_RET, MPQEMU_CMD_PCI_CFGWRITE, MPQEMU_CMD_PCI_CFGREAD, + MPQEMU_CMD_BAR_WRITE, + MPQEMU_CMD_BAR_READ, MPQEMU_CMD_MAX, } MPQemuCmd; @@ -52,6 +54,13 @@ typedef struct { int len; } PciConfDataMsg; +typedef struct { + hwaddr addr; + uint64_t val; + unsigned size; + bool memory; +} BarAccessMsg; + /** * MPQemuMsg: * @cmd: The remote command @@ -71,6 +80,7 @@ typedef struct { uint64_t u64; PciConfDataMsg pci_conf_data; SyncSysmemMsg sync_sysmem; + BarAccessMsg bar_access; } data; int fds[REMOTE_MAX_FDS]; diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h index faa9c4d..ea7fa4f 100644 --- a/include/hw/remote/proxy.h +++ b/include/hw/remote/proxy.h @@ -15,6 +15,14 @@ #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) +typedef struct ProxyMemoryRegion { + PCIProxyDev *dev; + MemoryRegion mr; + bool memory; + bool present; + uint8_t type; +} ProxyMemoryRegion; + struct PCIProxyDev { PCIDevice parent_dev; char *fd; @@ -28,6 +36,7 @@ struct PCIProxyDev { QemuMutex io_mutex; QIOChannel *ioc; Error *migration_blocker; + ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; #endif /* PROXY_H */ diff --git a/hw/remote/message.c b/hw/remote/message.c index 636bd16..f2e8445 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -16,11 +16,14 @@ #include "qapi/error.h" #include "sysemu/runstate.h" #include "hw/pci/pci.h" +#include "exec/memattrs.h" static void process_config_write(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); static void process_config_read(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp); void coroutine_fn mpqemu_remote_msg_loop_co(void *data) { @@ -52,6 +55,12 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) case MPQEMU_CMD_PCI_CFGREAD: process_config_read(com->ioc, pci_dev, &msg, &local_err); break; + case MPQEMU_CMD_BAR_WRITE: + process_bar_write(com->ioc, &msg, &local_err); + break; + case MPQEMU_CMD_BAR_READ: + process_bar_read(com->ioc, &msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s" @@ -115,3 +124,77 @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, getpid()); } } + +static void process_bar_write(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) +{ + ERRP_GUARD(); + BarAccessMsg *bar_access = &msg->data.bar_access; + AddressSpace *as = + bar_access->memory ? &address_space_memory : &address_space_io; + MPQemuMsg ret = { 0 }; + MemTxResult res; + uint64_t val; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + ret.data.u64 = UINT64_MAX; + goto fail; + } + + val = cpu_to_le64(bar_access->val); + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&val, bar_access->size, true); + + if (res != MEMTX_OK) { + error_setg(errp, "Bad address %"PRIx64" for mem write, pid "FMT_pid".", + bar_access->addr, getpid()); + ret.data.u64 = -1; + } + +fail: + ret.cmd = MPQEMU_CMD_RET; + ret.size = sizeof(ret.data.u64); + + if (!mpqemu_msg_send(&ret, ioc, NULL)) { + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", + getpid()); + } +} + +static void process_bar_read(QIOChannel *ioc, MPQemuMsg *msg, Error **errp) +{ + ERRP_GUARD(); + BarAccessMsg *bar_access = &msg->data.bar_access; + MPQemuMsg ret = { 0 }; + AddressSpace *as; + MemTxResult res; + uint64_t val = 0; + + as = bar_access->memory ? &address_space_memory : &address_space_io; + + if (!is_power_of_2(bar_access->size) || + (bar_access->size > sizeof(uint64_t))) { + val = UINT64_MAX; + goto fail; + } + + res = address_space_rw(as, bar_access->addr, MEMTXATTRS_UNSPECIFIED, + (void *)&val, bar_access->size, false); + + if (res != MEMTX_OK) { + error_setg(errp, "Bad address %"PRIx64" for mem read, pid "FMT_pid".", + bar_access->addr, getpid()); + val = UINT64_MAX; + } + +fail: + ret.cmd = MPQEMU_CMD_RET; + ret.data.u64 = le64_to_cpu(val); + ret.size = sizeof(ret.data.u64); + + if (!mpqemu_msg_send(&ret, ioc, NULL)) { + error_prepend(errp, "Error returning code to proxy, pid "FMT_pid": ", + getpid()); + } +} diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 5bd6a9d..bcb32e0 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -248,6 +248,12 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case MPQEMU_CMD_BAR_WRITE: + case MPQEMU_CMD_BAR_READ: + if ((msg->size != sizeof(BarAccessMsg)) || (msg->num_fds != 0)) { + return false; + } + break; default: break; } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 2b14394..22eb422 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -152,3 +152,63 @@ static void pci_proxy_dev_register_types(void) } 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 = { 0 }; + long ret = -EINVAL; + Error *local_err = NULL; + + msg.size = sizeof(BarAccessMsg); + msg.data.bar_access.addr = mr->addr + addr; + msg.data.bar_access.size = size; + msg.data.bar_access.memory = memory; + + if (write) { + msg.cmd = MPQEMU_CMD_BAR_WRITE; + msg.data.bar_access.val = *val; + } else { + msg.cmd = MPQEMU_CMD_BAR_READ; + } + + ret = mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); + if (local_err) { + error_report_err(local_err); + } + + if (!write) { + *val = ret; + } +} + +static void proxy_bar_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + + send_bar_access_msg(pmr->dev, &pmr->mr, true, addr, &val, size, + pmr->memory); +} + +static uint64_t proxy_bar_read(void *opaque, hwaddr addr, unsigned size) +{ + ProxyMemoryRegion *pmr = opaque; + uint64_t val; + + send_bar_access_msg(pmr->dev, &pmr->mr, false, addr, &val, size, + pmr->memory); + + return val; +} + +const MemoryRegionOps proxy_mr_ops = { + .read = proxy_bar_read, + .write = proxy_bar_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 1, + .max_access_size = 8, + }, +}; From patchwork Tue Jan 19 20:28:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030833 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 C7752C433E0 for ; Tue, 19 Jan 2021 21:14: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 3BA2A22D08 for ; Tue, 19 Jan 2021 21:14:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BA2A22D08 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]:59412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1yKG-0005FC-Ds for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:14:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xdO-0001uc-Jo for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:51 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:58390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xdH-0000MC-QP for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:29:50 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKNU3F002768; Tue, 19 Jan 2021 20:29:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=CtNthRMi/yWg7bExLKMplw2bOO/xThH7uzCl9jlatto=; b=VUuYmkxpKtjFkfoa1V3SpcrBiK63s/QvP5fjWopq2L7Cq3PHAmN11ymMcc67oTwfyYm1 u0H8FWptjh5/pyIn7YuR2WG6eK1XncwxCU4l9PTedSIYD7aCL6JhVQ0U2yNxWQWZ6GhP 7JvTZza3cPql6G0OW7/q/asBDeiAxYy1zAhROkm/E64qiFbU48ZBfzlJ8mEBH0eNjONa kVE85/mWdED3nb1EdI5plG7YVxxFF0CgFA5fZqwuOJgb9StI8EQjzZ/MxtN5LrExbNAi 7wgQT4O1vXm63aoluaEdQOTX8Tp1Q6Rhv1gfOgo4JsJmKH8XeqqHokfP6q/2kWUcDIN6 3Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 363xyhtaut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:37 +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 10JKPd65128344; Tue, 19 Jan 2021 20:29:37 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2051.outbound.protection.outlook.com [104.47.37.51]) by userp3030.oracle.com with ESMTP id 3661njtax2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dAlu0wIM3SasIX+gkE7TPxDk2CZMWph7J9eIBi6eTuaw8mgY7NVMJPI53DHzDF/i0a3Y4m0kTqcxSA+g3wV3OG7WdAy6TvQxCeabo42+BsFmJBcJEAnsm4V3821jXITidq42URBpWesM0yFW8pVL1Otko3yaI4Ya5koWIlA1J/gUN/6Dlhkt8fcpRhSWWiObwzWS1jHFNS+5j56S3f10L0kbAN9JJb1I3Ahyug8G8t0Bgdq9cJIOuyLr7UCdSMyRr2DXQEV0oXFuAYaCtbWXjO2sIEJdlCp2UMH0Tdxh60c4fE3V1AAvsh1BPkLikml3wqVG1nH++9OGzpxPLfY/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CtNthRMi/yWg7bExLKMplw2bOO/xThH7uzCl9jlatto=; b=kptZA0RZFakOOjZ1LevtSGzRiM00Qx6aOr4l5H3BQIzN/Gjc+K1baAYekQ0kCDNlW2ScT1a01RKWtN4WeLM64fbmjKoEmXwZJQNA8tviXHZMLB31qJ+coD8ZG7EtQ1Ph9f9UdILU++GHYgTa0hBs2MbAJetd8a8z11bYauTjtMPq7ERKIHp7YXUBFhdx+gqb24UsSoy10v3oJVteLclN2Mg2s7ytAQrg3Vj9We9X8mjVCQbFM2S2QkBfsjNLc6wuFYbLJYw+S4Tx6Iv2odrahH/4BN5cFgXDL2WXxHPtXDNBh0eC55vON/XyGxhnmX70VzmT/8yCxr7TugVaDfxDuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CtNthRMi/yWg7bExLKMplw2bOO/xThH7uzCl9jlatto=; b=FfwmmneexVf/Vhhelvp4HlcTVNqP+kImKy0s0pA7zSm+3589z3hJqfDKbhfdQ0EactTMDaRnTbd3e11fJfPkMER2KJzwCJDVWyPWvJRzFuQ2N71w8whKIRLrXfNZZLRCf+PWoxi/BFUpNoK7HdIfRhJSgw8o9N+CjhH+oEcnXiE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:34 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:34 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 17/20] multi-process: Synchronize remote memory Date: Tue, 19 Jan 2021 15:28:34 -0500 Message-Id: <405327dc36bf3aa6e7234a9996be1598801bc0a5.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7625addf-4fbf-49fc-4c6c-08d8bcb8ef1f X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6QyUNllI6cgzyv7UQFhLi1oPvbPRHQkbyiBa1z6u80mS+KQHlJ8x8ftZDU/DN5lv7FSr3bqYuV+sZAyoOp4nwOvbBgogIAKf4EFmzBe9vhSe0E23ex1T4bQwSTizmdeIEXgpf8otWYkBDlyIWEs70noiL3gFpsfgVB8JZHeISH8HGS16qoTkX8IuRD5bT3X/VLnGqg8oFoLXXtq/5grYNSE6vCabEwFB2lru00rSjXk7yJHfqKlhhMFpBTDHi7VpPr3omKExhCWJL3ZwjEOt91mdoHrOmGTGBpsHeKZgm2yFgy3gmhFWxsG3ZVzqMzJraB/YnQWemLEnqg+R8cGR60MpDA6zqk1dOpn14st8/wrK6Oc47rywheGQgiCj4u19 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(30864003)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?9z9JJ4Ld5oOxSFuyxW23EyTULDuz5S?= =?utf-8?q?dbvdpHoVClg0w0dXCDuRoiM1UMeU2U6xb63FW91q0KspzYQVfOTnUm1/G3u0lD3hw?= =?utf-8?q?wJSNJNvEKRg1SDkyKSpuWVwP9gzi5YBOGZvCMVCICQEhv9Y5z/n4UCvvlgfElG6uF?= =?utf-8?q?9e0Ts8x80FKud1GUBtsbFHYlIgl52oxABTjfL2UyVjgaqD1TzUnnsGPafmPXu9fyu?= =?utf-8?q?eH1AikL1AJebY0oGVtVii5D3J/YyvPPR6NB8yNA3WvhKrWKX7E6iQT7qzBH1E0Rr1?= =?utf-8?q?dHbYLVQjsbhLhbDbOvI+8cyzE4wAUu+lEh4NUSwatSHjwuYqVASHAGqTgRTFIGX/Y?= =?utf-8?q?bF9SIoFwatYG2ZodBIb3lUJbN2VBoxvSUielO+asWPuL4xaSRXiFIU0m/cxBq3ruz?= =?utf-8?q?c2DQZ/+F97BqJHcDX+2gn5HTzOON7moGwo7j/An+LmkM+THf5MU6JCJaXL2f1KfnA?= =?utf-8?q?3DmItsZ4qD7yu751sMGIZ7+EZzD9boZ69hw/EGY1Ok1qXlxnZNYrOQqJPPObQhfUg?= =?utf-8?q?qvD/ymBgo3EjKsms70u3U3wtcXMGYxSHkeBYt/POTP1Z9l/8HlyL3AKqtMGir5+Xy?= =?utf-8?q?8TCoQsace35f1gJ7yNsMBhL/AxL+sUjOEb36ZVbeZDG89HMaATfwTPTVCC6kA7khN?= =?utf-8?q?EoKKSzikT5yLf+zMaCMG+kPdWydYRTVmFJOYGImS9ARLfqNpXfa5RvFtpHE33uZNs?= =?utf-8?q?/59vO05NdeLt63Lbng9XzRIig55n8vIfihCGV2FUO8kznsIBDyJcsal67As5iimC6?= =?utf-8?q?oU7hYbaqbC5tF3RN7W3fvJPm6vzbq2KCTgKvzLPJdlv8Rqrl7QKuXf1Ow/Tkb4ksX?= =?utf-8?q?S3pihcap7TN9qTDPh7C9Ft9eusdyFcoENz3viNavR8onP81Hh3iH8HijLPrbuq5/R?= =?utf-8?q?RhY70HFgdDJxkaIGVhkses0Hy48GLgqIFDH1qq1SnoQNE6arXoUe8PJ1iky+5HE?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7625addf-4fbf-49fc-4c6c-08d8bcb8ef1f X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:34.6404 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +AcpTR/2Hn0Pvc+xTEiEr5qc+fpHrtTUDJjmbg62YTjE7ZMAFoX2JuGHRG+FkpEPprchTVDrHyw/A16y3lHVhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=156.151.31.86; envelope-from=jag.raman@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" Add ProxyMemoryListener 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/proxy-memory-listener.h | 28 ++++ include/hw/remote/proxy.h | 2 + hw/remote/message.c | 4 + hw/remote/proxy-memory-listener.c | 227 ++++++++++++++++++++++++++++++ hw/remote/proxy.c | 6 + MAINTAINERS | 2 + hw/remote/meson.build | 1 + 7 files changed, 270 insertions(+) create mode 100644 include/hw/remote/proxy-memory-listener.h create mode 100644 hw/remote/proxy-memory-listener.c diff --git a/include/hw/remote/proxy-memory-listener.h b/include/hw/remote/proxy-memory-listener.h new file mode 100644 index 0000000..c4f3efb --- /dev/null +++ b/include/hw/remote/proxy-memory-listener.h @@ -0,0 +1,28 @@ +/* + * Copyright © 2018, 2021 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 PROXY_MEMORY_LISTENER_H +#define PROXY_MEMORY_LISTENER_H + +#include "exec/memory.h" +#include "io/channel.h" + +typedef struct ProxyMemoryListener { + MemoryListener listener; + + int n_mr_sections; + MemoryRegionSection *mr_sections; + + QIOChannel *ioc; +} ProxyMemoryListener; + +void proxy_memory_listener_configure(ProxyMemoryListener *proxy_listener, + QIOChannel *ioc); +void proxy_memory_listener_deconfigure(ProxyMemoryListener *proxy_listener); + +#endif diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h index ea7fa4f..12888b4 100644 --- a/include/hw/remote/proxy.h +++ b/include/hw/remote/proxy.h @@ -11,6 +11,7 @@ #include "hw/pci/pci.h" #include "io/channel.h" +#include "hw/remote/proxy-memory-listener.h" #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) @@ -36,6 +37,7 @@ struct PCIProxyDev { QemuMutex io_mutex; QIOChannel *ioc; Error *migration_blocker; + ProxyMemoryListener proxy_listener; ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; diff --git a/hw/remote/message.c b/hw/remote/message.c index f2e8445..25341d8 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -17,6 +17,7 @@ #include "sysemu/runstate.h" #include "hw/pci/pci.h" #include "exec/memattrs.h" +#include "hw/remote/memory.h" static void process_config_write(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); @@ -61,6 +62,9 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) case MPQEMU_CMD_BAR_READ: process_bar_read(com->ioc, &msg, &local_err); break; + case MPQEMU_CMD_SYNC_SYSMEM: + remote_sysmem_reconfig(&msg, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s" diff --git a/hw/remote/proxy-memory-listener.c b/hw/remote/proxy-memory-listener.c new file mode 100644 index 0000000..af1fa6f --- /dev/null +++ b/hw/remote/proxy-memory-listener.c @@ -0,0 +1,227 @@ +/* + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" + +#include "qemu/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 "qapi/error.h" +#include "hw/remote/mpqemu-link.h" +#include "hw/remote/proxy-memory-listener.h" + +/* + * TODO: get_fd_from_hostaddr(), proxy_mrs_can_merge() and + * proxy_memory_listener_commit() defined below perform tasks similar to the + * functions defined in vhost-user.c. These functions are good candidates + * for refactoring. + * + */ + +static void proxy_memory_listener_reset(MemoryListener *listener) +{ + ProxyMemoryListener *proxy_listener = container_of(listener, + ProxyMemoryListener, + listener); + int mrs; + + for (mrs = 0; mrs < proxy_listener->n_mr_sections; mrs++) { + memory_region_unref(proxy_listener->mr_sections[mrs].mr); + } + + g_free(proxy_listener->mr_sections); + proxy_listener->mr_sections = NULL; + proxy_listener->n_mr_sections = 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 = memory_region_from_host((void *)(uintptr_t)host, &off); + + if (offset) { + *offset = off; + } + + return memory_region_get_fd(mr); +} + +static bool proxy_mrs_can_merge(uint64_t host, uint64_t prev_host, size_t size) +{ + if (((prev_host + size) != host)) { + return false; + } + + if (get_fd_from_hostaddr(host, NULL) != + get_fd_from_hostaddr(prev_host, NULL)) { + return false; + } + + return true; +} + +static bool try_merge(ProxyMemoryListener *proxy_listener, + MemoryRegionSection *section) +{ + uint64_t mrs_size, mrs_gpa, mrs_page; + MemoryRegionSection *prev_sec; + bool merged = false; + uintptr_t mrs_host; + RAMBlock *mrs_rb; + + if (!proxy_listener->n_mr_sections) { + return false; + } + + mrs_rb = section->mr->ram_block; + mrs_page = (uint64_t)qemu_ram_pagesize(mrs_rb); + mrs_size = int128_get64(section->size); + mrs_gpa = section->offset_within_address_space; + mrs_host = (uintptr_t)memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + + if (get_fd_from_hostaddr(mrs_host, NULL) < 0) { + return true; + } + + mrs_host = mrs_host & ~(mrs_page - 1); + mrs_gpa = mrs_gpa & ~(mrs_page - 1); + mrs_size = ROUND_UP(mrs_size, mrs_page); + + prev_sec = proxy_listener->mr_sections + + (proxy_listener->n_mr_sections - 1); + uint64_t prev_gpa_start = prev_sec->offset_within_address_space; + uint64_t prev_size = int128_get64(prev_sec->size); + uint64_t prev_gpa_end = range_get_last(prev_gpa_start, prev_size); + uint64_t prev_host_start = + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr) + + prev_sec->offset_within_region; + uint64_t prev_host_end = range_get_last(prev_host_start, prev_size); + + if (mrs_gpa <= (prev_gpa_end + 1)) { + g_assert(mrs_gpa > prev_gpa_start); + + if ((section->mr == prev_sec->mr) && + proxy_mrs_can_merge(mrs_host, prev_host_start, + (mrs_gpa - prev_gpa_start))) { + uint64_t max_end = MAX(prev_host_end, mrs_host + mrs_size); + merged = true; + prev_sec->offset_within_address_space = + MIN(prev_gpa_start, mrs_gpa); + prev_sec->offset_within_region = + MIN(prev_host_start, mrs_host) - + (uintptr_t)memory_region_get_ram_ptr(prev_sec->mr); + prev_sec->size = int128_make64(max_end - MIN(prev_host_start, + mrs_host)); + } + } + + return merged; +} + +static void proxy_memory_listener_region_addnop(MemoryListener *listener, + MemoryRegionSection *section) +{ + ProxyMemoryListener *proxy_listener = container_of(listener, + ProxyMemoryListener, + listener); + + if (!memory_region_is_ram(section->mr) || + memory_region_is_rom(section->mr)) { + return; + } + + if (try_merge(proxy_listener, section)) { + return; + } + + ++proxy_listener->n_mr_sections; + proxy_listener->mr_sections = g_renew(MemoryRegionSection, + proxy_listener->mr_sections, + proxy_listener->n_mr_sections); + proxy_listener->mr_sections[proxy_listener->n_mr_sections - 1] = *section; + proxy_listener->mr_sections[proxy_listener->n_mr_sections - 1].fv = NULL; + memory_region_ref(section->mr); +} + +static void proxy_memory_listener_commit(MemoryListener *listener) +{ + ProxyMemoryListener *proxy_listener = container_of(listener, + ProxyMemoryListener, + listener); + MPQemuMsg msg; + MemoryRegionSection *section; + ram_addr_t offset; + uintptr_t host_addr; + int region; + Error *local_err = NULL; + + memset(&msg, 0, sizeof(MPQemuMsg)); + + msg.cmd = MPQEMU_CMD_SYNC_SYSMEM; + msg.num_fds = proxy_listener->n_mr_sections; + msg.size = sizeof(SyncSysmemMsg); + if (msg.num_fds > REMOTE_MAX_FDS) { + error_report("Number of fds is more than %d", REMOTE_MAX_FDS); + return; + } + + for (region = 0; region < proxy_listener->n_mr_sections; region++) { + section = &proxy_listener->mr_sections[region]; + msg.data.sync_sysmem.gpas[region] = + section->offset_within_address_space; + msg.data.sync_sysmem.sizes[region] = int128_get64(section->size); + host_addr = (uintptr_t)memory_region_get_ram_ptr(section->mr) + + section->offset_within_region; + msg.fds[region] = get_fd_from_hostaddr(host_addr, &offset); + msg.data.sync_sysmem.offsets[region] = offset; + } + if (!mpqemu_msg_send(&msg, proxy_listener->ioc, &local_err)) { + error_report_err(local_err); + } +} + +void proxy_memory_listener_deconfigure(ProxyMemoryListener *proxy_listener) +{ + memory_listener_unregister(&proxy_listener->listener); + + proxy_memory_listener_reset(&proxy_listener->listener); +} + +void proxy_memory_listener_configure(ProxyMemoryListener *proxy_listener, + QIOChannel *ioc) +{ + proxy_listener->n_mr_sections = 0; + proxy_listener->mr_sections = NULL; + + proxy_listener->ioc = ioc; + + proxy_listener->listener.begin = proxy_memory_listener_reset; + proxy_listener->listener.commit = proxy_memory_listener_commit; + proxy_listener->listener.region_add = proxy_memory_listener_region_addnop; + proxy_listener->listener.region_nop = proxy_memory_listener_region_addnop; + proxy_listener->listener.priority = 10; + + memory_listener_register(&proxy_listener->listener, + &address_space_memory); +} diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 22eb422..472b2df 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -19,6 +19,8 @@ #include "qemu/sockets.h" #include "hw/remote/mpqemu-link.h" #include "qemu/error-report.h" +#include "hw/remote/proxy-memory-listener.h" +#include "qom/object.h" static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { @@ -52,6 +54,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) qemu_mutex_init(&dev->io_mutex); qio_channel_set_blocking(dev->ioc, true, NULL); + + proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); } static void pci_proxy_dev_exit(PCIDevice *pdev) @@ -65,6 +69,8 @@ static void pci_proxy_dev_exit(PCIDevice *pdev) migrate_del_blocker(dev->migration_blocker); error_free(dev->migration_blocker); + + proxy_memory_listener_deconfigure(&dev->proxy_listener); } static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, diff --git a/MAINTAINERS b/MAINTAINERS index ee04d82..5e48a26 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3201,6 +3201,8 @@ F: include/hw/remote/memory.h F: hw/remote/memory.c F: hw/remote/proxy.c F: include/hw/remote/proxy.h +F: hw/remote/proxy-memory-listener.c +F: include/hw/remote/proxy-memory-listener.h Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 569cd20..7f11be4 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -7,5 +7,6 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) +specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) softmmu_ss.add_all(when: 'CONFIG_MULTIPROCESS', if_true: remote_ss) From patchwork Tue Jan 19 20:28:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030789 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 8070BC433E6 for ; Tue, 19 Jan 2021 20:53:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E97F722CE3 for ; Tue, 19 Jan 2021 20:53:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E97F722CE3 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]:44606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y0g-0002zJ-Vl for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:53:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfM-0003j8-UA for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:52 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:58194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfH-0000gh-Qg for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:52 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOVtc131398; Tue, 19 Jan 2021 20:31:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=BXRIbQx5WB+xFmNtc+iUxvKCUVvNcKmkSoo00eBRgjg=; b=qHpAEeKX1dYiyDtZMGcTVwdfgEqF444d5vRQI7EYlNqsZ0XeRHdFiP/9LdIKqprA++w2 9PTu0NGlXfF9zOn43OsqYrysnC8/8rG6U5euZQzwXvC7hJHMQ3wFExV5s9a57QjJKR/g rkoHVddPXDleUEkmqiq0CVfLPGTZyjOBJbm4dlT+jibNpiDPMrhocY6ltI6OKIvzmCPX 5pD2w0ngWXjIhpEy0DgIZJT8JCns70eC55AEFhhKLMa+NY3WYNSVSVzBzul7869XOjOp B/2F8dDWvLKIANJMMBWs2rozlu0XkSd66kC8uGQpgQXtcTZ3U0sFwLbZ80m4xYucB1dR 7g== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 363r3ktxyc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:40 +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 10JKQbUF117465; Tue, 19 Jan 2021 20:29:40 GMT Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2052.outbound.protection.outlook.com [104.47.37.52]) by aserp3030.oracle.com with ESMTP id 3649qpu9dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IA0/3HECIYBqQvdOFTBou+YlCbJ3FE0vUOZbeeQchMLg6hp5fMk/CYDid/GYAAaDDrlmz/EbYi0wKbCybrl5xzXceMPrLed/e+aVsMXGqmreESYGx3VQdZvH1lj3EacxUCBkG0cIU3NVWn19iYyoQOBObDESEiA83h6oKsHuACt1RzH/6kov6G3qhbYwCDQSGGqQYy/V87Cp4v5MX+q+1zOevDfMdT/3oI4758dFlMi9tqt+pX1WTE+XFtO85BSH7ZNE31tPPiH9oN95ivDkyzDmzLtdzFZAWnSX8WlBF7u7iJdxcKUtOW006ALC7NlFuKkX2R32XQekNEzIexLhKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BXRIbQx5WB+xFmNtc+iUxvKCUVvNcKmkSoo00eBRgjg=; b=oK4Za8AOc5zEbr+NBMX0t3TbrKjqZy8OKdZ5vrtFexB2N5zWmOqmkvJ/gcCQFXl4l9fLraiuDhnGAQw/SfErKo5lG1DAoz2ZRMhbQkjczH9mTJGO88D1SdI6xIFEEaJFjQWG3aXr2PBuL5jU1hEU419Gn0shnAYMlLsuW7JKYsk3eZkqH9sRBQMFU/mFYInAIRbQWYxDsFYC/gqNYP825/ARfx+ESTtuRIHTmoMRvFt8Vnvj7kT/bHO+Gg0BpQa11Q33ETI0qeRXnKEMTvkwo3fuOytMVZvx9sFS2swl8NS4HCw6mV0CtaFcqVUp+cp6GOz8+f0aRfjw8XkjhGEYqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BXRIbQx5WB+xFmNtc+iUxvKCUVvNcKmkSoo00eBRgjg=; b=NQr9iNkE4rIGmLBVrwGF4lm9+vxijlU1GV72vBIrpfq3iiKScLOepGu21JeGAQ2IzlhgSlOqTFOF4z1GTSih2I68/TI38zkS3H5Kis0lhAkglA4T6/EK+zpHJ3bFCI9UGtL3TCpP2LPBCIo2amYo8iHGcdZZ3wcS+akzBH5GJJ0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3349.namprd10.prod.outlook.com (2603:10b6:a03:155::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:37 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:37 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 18/20] multi-process: create IOHUB object to handle irq Date: Tue, 19 Jan 2021 15:28:35 -0500 Message-Id: <7cbe8162242af38a3a5c5557254bb1c51ac4a257.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8deaa436-ad8c-4189-8b8f-08d8bcb8f0e2 X-MS-TrafficTypeDiagnostic: BYAPR10MB3349: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a0usr3x1jE5GUJvuGtfh7iG2+Sgg1619WErNDHIHTY2UkYmJugmGMcApMlfkzc3UYAOPSfx0DhWGSZFhbXyDtG0I72FwmiZr0irMKoQi5d0Clpqgfu8I4/+GDh8B7db8fPl0F98SUCtkoNWynxvwWU2gVwwqo4iGepgKphYVxj+UyWGEqwIcNBB0RTfzOEaCqB/1wFvzg+6/DobcvgOdow2BZc6GK6/kmmL1iC2lpWkBrLBN8zVDGuW9udUOH5qSUAom2DgbcwIPu6c4WnSg3yw9RBwWhTdYjf5nB+/2mynQAZ0213+n6QA+mBLWG7C7MCq7y3d955LB4qldHYCKGLC0eMwYn6ns1lQJk28wJcM3VMhohKnAetfF/ToNeUwQVJRG/cP3tcnYc5O7IYk1Sw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(39860400002)(396003)(366004)(136003)(346002)(376002)(7696005)(52116002)(2906002)(6486002)(5660300002)(7416002)(36756003)(66476007)(66556008)(478600001)(6916009)(956004)(2616005)(4326008)(66946007)(30864003)(26005)(186003)(16526019)(8676002)(86362001)(8936002)(107886003)(316002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?RdB5N4q76P1r62gK8ZZvX+SVzx/Osn?= =?utf-8?q?wlIlruw65QalZq2cUDrAShX6kZKGjmBqvMacfcw3fJ7OWHoIWDmvJOZAuTEZ396/9?= =?utf-8?q?9bIaqqKVb1fRX+gndNSntV/Jl8Gt08ViYXKUh9ccU2GB9QW+RnYA+gsObAiUmkycW?= =?utf-8?q?nHbVqZTRk2Qd94dnVqK14X9P7aOrCDqa3/NTym6j0HqD9npHdLX+Pc85To7C79R7L?= =?utf-8?q?tjAfH3pFV9Nkps/NCS7s8B74zhbugOy9OGUq7/i78rlMtN1EuSHtwUUy0B1lm8Kye?= =?utf-8?q?aE4KLSCJ60xhkr4ycr6ZW1Jjdap+jCdaUKEn3vxzDWaHYBbL6wSG4l5/xSXYh72gG?= =?utf-8?q?u/pE6IQGBjdzisI6hjO4xao1MORPMohk7GtoLnakb3E2hHDjZQp3Ak3HprT2Rixjb?= =?utf-8?q?o55ydwf/VuLFI6A7pCDkgOOrbPMnxnhfIVg3Ea5gISsfp43d2NXFneGXEsLOjjksV?= =?utf-8?q?5xohlSa1eezMGxXLT2u9LU0mvcg0eoVG3bwL0o8OYDTPTzXPh+pNPLtW6lcSzLE/+?= =?utf-8?q?cqUSHIlYN/KD+WDC9WuWpAsq8kLRTY5b9z5liJzY7gjnjZShJv0a7K2Nr4FY+0Muj?= =?utf-8?q?juRYBtrgzXgKWbh0iTN8ExL8aeMY07JPkl9b4f+EH7brMO1yZhEaI4M76dMFQfJJ4?= =?utf-8?q?sMOTdZQF1g8pSAi86T0TnA+7cMACH/nr6jymKhkfIRRSB17vsnibmwjfqaD9zyPZr?= =?utf-8?q?o9xk9NH68MNDuLwDOyCeYrybgwefn/gVDpxTyz8PdwtLPLVKGdOJrnmRmUwMJm+xg?= =?utf-8?q?gvXaERS3k2sguhWAMJ6xj00GfSuC8Yl67jJrn/zTDCFiAe63XPBsdXG8tE+xvCCso?= =?utf-8?q?yc1A4fTTUMav9X5vTr5CGijJtj1UHFW6XDs1zSFnxm+Yj9cKtQxxBtNuQ1HciSob3?= =?utf-8?q?iXgynAlIVEuzyvS97GgW2d243NYh7UZewXrRybqEb0kYXAJsUyA1b4btlvudzQY?= =?utf-8?q?=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8deaa436-ad8c-4189-8b8f-08d8bcb8f0e2 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:37.6367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BQat3Mfxt9uo6SODvkhxnw1uhxXMUA2bohxv7bYI27gP1HSe0Z1+FteR7th8zaUw98/idlhBUp5AS2FIMcC9mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3349 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.78; envelope-from=jag.raman@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 Reviewed-by: Stefan Hajnoczi --- include/hw/pci/pci_ids.h | 3 + include/hw/remote/iohub.h | 42 ++++++++++++++ include/hw/remote/machine.h | 2 + include/hw/remote/mpqemu-link.h | 1 + include/hw/remote/proxy.h | 4 ++ hw/remote/iohub.c | 119 ++++++++++++++++++++++++++++++++++++++++ hw/remote/machine.c | 10 ++++ hw/remote/message.c | 4 ++ hw/remote/mpqemu-link.c | 5 ++ hw/remote/proxy.c | 56 +++++++++++++++++++ MAINTAINERS | 2 + hw/remote/meson.build | 1 + 12 files changed, 249 insertions(+) create mode 100644 include/hw/remote/iohub.h create mode 100644 hw/remote/iohub.c diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h index 11f8ab7..bd0c17d 100644 --- a/include/hw/pci/pci_ids.h +++ b/include/hw/pci/pci_ids.h @@ -192,6 +192,9 @@ #define PCI_DEVICE_ID_SUN_SIMBA 0x5000 #define PCI_DEVICE_ID_SUN_SABRE 0xa000 +#define PCI_VENDOR_ID_ORACLE 0x108e +#define PCI_DEVICE_ID_REMOTE_IOHUB 0xb000 + #define PCI_VENDOR_ID_CMD 0x1095 #define PCI_DEVICE_ID_CMD_646 0x0646 diff --git a/include/hw/remote/iohub.h b/include/hw/remote/iohub.h new file mode 100644 index 0000000..0bf98e0 --- /dev/null +++ b/include/hw/remote/iohub.h @@ -0,0 +1,42 @@ +/* + * IO Hub for remote device + * + * Copyright © 2018, 2021 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef REMOTE_IOHUB_H +#define REMOTE_IOHUB_H + +#include "hw/pci/pci.h" +#include "qemu/event_notifier.h" +#include "qemu/thread-posix.h" +#include "hw/remote/mpqemu-link.h" + +#define REMOTE_IOHUB_NB_PIRQS PCI_DEVFN_MAX + +typedef struct ResampleToken { + void *iohub; + int pirq; +} ResampleToken; + +typedef struct RemoteIOHubState { + PCIDevice d; + 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); + +void remote_iohub_init(RemoteIOHubState *iohub); +void remote_iohub_finalize(RemoteIOHubState *iohub); + +#endif diff --git a/include/hw/remote/machine.h b/include/hw/remote/machine.h index b92b2ce..2a2a33c 100644 --- a/include/hw/remote/machine.h +++ b/include/hw/remote/machine.h @@ -15,11 +15,13 @@ #include "hw/boards.h" #include "hw/pci-host/remote.h" #include "io/channel.h" +#include "hw/remote/iohub.h" struct RemoteMachineState { MachineState parent_obj; RemotePCIHost *host; + RemoteIOHubState iohub; }; /* Used to pass to co-routine device and ioc. */ diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index 6303e62..71d206f 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -39,6 +39,7 @@ typedef enum { MPQEMU_CMD_PCI_CFGREAD, MPQEMU_CMD_BAR_WRITE, MPQEMU_CMD_BAR_READ, + MPQEMU_CMD_SET_IRQFD, MPQEMU_CMD_MAX, } MPQemuCmd; diff --git a/include/hw/remote/proxy.h b/include/hw/remote/proxy.h index 12888b4..741def7 100644 --- a/include/hw/remote/proxy.h +++ b/include/hw/remote/proxy.h @@ -12,6 +12,7 @@ #include "hw/pci/pci.h" #include "io/channel.h" #include "hw/remote/proxy-memory-listener.h" +#include "qemu/event_notifier.h" #define TYPE_PCI_PROXY_DEV "x-pci-proxy-dev" OBJECT_DECLARE_SIMPLE_TYPE(PCIProxyDev, PCI_PROXY_DEV) @@ -38,6 +39,9 @@ struct PCIProxyDev { QIOChannel *ioc; Error *migration_blocker; ProxyMemoryListener proxy_listener; + int virq; + EventNotifier intr; + EventNotifier resample; ProxyMemoryRegion region[PCI_NUM_REGIONS]; }; diff --git a/hw/remote/iohub.c b/hw/remote/iohub.c new file mode 100644 index 0000000..e4ff131 --- /dev/null +++ b/hw/remote/iohub.c @@ -0,0 +1,119 @@ +/* + * Remote IO Hub + * + * Copyright © 2018, 2021 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/pci/pci.h" +#include "hw/pci/pci_ids.h" +#include "hw/pci/pci_bus.h" +#include "qemu/thread.h" +#include "hw/boards.h" +#include "hw/remote/machine.h" +#include "hw/remote/iohub.h" +#include "qemu/main-loop.h" + +void remote_iohub_init(RemoteIOHubState *iohub) +{ + int pirq; + + memset(&iohub->irqfds, 0, sizeof(iohub->irqfds)); + memset(&iohub->resamplefds, 0, sizeof(iohub->resamplefds)); + + for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { + qemu_mutex_init(&iohub->irq_level_lock[pirq]); + iohub->irq_level[pirq] = 0; + event_notifier_init_fd(&iohub->irqfds[pirq], -1); + event_notifier_init_fd(&iohub->resamplefds[pirq], -1); + } +} + +void remote_iohub_finalize(RemoteIOHubState *iohub) +{ + int pirq; + + for (pirq = 0; pirq < REMOTE_IOHUB_NB_PIRQS; pirq++) { + qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq]), + NULL, NULL, NULL); + event_notifier_cleanup(&iohub->irqfds[pirq]); + event_notifier_cleanup(&iohub->resamplefds[pirq]); + qemu_mutex_destroy(&iohub->irq_level_lock[pirq]); + } +} + +int remote_iohub_map_irq(PCIDevice *pci_dev, int intx) +{ + return pci_dev->devfn; +} + +void remote_iohub_set_irq(void *opaque, int pirq, int level) +{ + RemoteIOHubState *iohub = opaque; + + assert(pirq >= 0); + assert(pirq < PCI_DEVFN_MAX); + + QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); + + if (level) { + if (++iohub->irq_level[pirq] == 1) { + event_notifier_set(&iohub->irqfds[pirq]); + } + } else if (iohub->irq_level[pirq] > 0) { + iohub->irq_level[pirq]--; + } +} + +static void intr_resample_handler(void *opaque) +{ + ResampleToken *token = opaque; + RemoteIOHubState *iohub = token->iohub; + int pirq, s; + + pirq = token->pirq; + + s = event_notifier_test_and_clear(&iohub->resamplefds[pirq]); + + assert(s >= 0); + + QEMU_LOCK_GUARD(&iohub->irq_level_lock[pirq]); + + if (iohub->irq_level[pirq]) { + event_notifier_set(&iohub->irqfds[pirq]); + } +} + +void process_set_irqfd_msg(PCIDevice *pci_dev, MPQemuMsg *msg) +{ + RemoteMachineState *machine = REMOTE_MACHINE(current_machine); + RemoteIOHubState *iohub = &machine->iohub; + int pirq, intx; + + intx = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + pirq = remote_iohub_map_irq(pci_dev, intx); + + if (event_notifier_get_fd(&iohub->irqfds[pirq]) != -1) { + qemu_set_fd_handler(event_notifier_get_fd(&iohub->resamplefds[pirq]), + NULL, NULL, NULL); + event_notifier_cleanup(&iohub->irqfds[pirq]); + event_notifier_cleanup(&iohub->resamplefds[pirq]); + memset(&iohub->token[pirq], 0, sizeof(ResampleToken)); + } + + event_notifier_init_fd(&iohub->irqfds[pirq], msg->fds[0]); + event_notifier_init_fd(&iohub->resamplefds[pirq], msg->fds[1]); + + iohub->token[pirq].iohub = iohub; + iohub->token[pirq].pirq = pirq; + + qemu_set_fd_handler(msg->fds[1], intr_resample_handler, NULL, + &iohub->token[pirq]); +} diff --git a/hw/remote/machine.c b/hw/remote/machine.c index 9519a6c..c0ab4f5 100644 --- a/hw/remote/machine.c +++ b/hw/remote/machine.c @@ -20,12 +20,15 @@ #include "exec/address-spaces.h" #include "exec/memory.h" #include "qapi/error.h" +#include "hw/pci/pci_host.h" +#include "hw/remote/iohub.h" static void remote_machine_init(MachineState *machine) { MemoryRegion *system_memory, *system_io, *pci_memory; RemoteMachineState *s = REMOTE_MACHINE(machine); RemotePCIHost *rem_host; + PCIHostState *pci_host; system_memory = get_system_memory(); system_io = get_system_io(); @@ -45,6 +48,13 @@ static void remote_machine_init(MachineState *machine) memory_region_add_subregion_overlap(system_memory, 0x0, pci_memory, -1); qdev_realize(DEVICE(rem_host), sysbus_get_default(), &error_fatal); + + pci_host = PCI_HOST_BRIDGE(rem_host); + + remote_iohub_init(&s->iohub); + + pci_bus_irqs(pci_host->bus, remote_iohub_set_irq, remote_iohub_map_irq, + &s->iohub, REMOTE_IOHUB_NB_PIRQS); } static void remote_machine_class_init(ObjectClass *oc, void *data) diff --git a/hw/remote/message.c b/hw/remote/message.c index 25341d8..adab040 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -18,6 +18,7 @@ #include "hw/pci/pci.h" #include "exec/memattrs.h" #include "hw/remote/memory.h" +#include "hw/remote/iohub.h" static void process_config_write(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); @@ -65,6 +66,9 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) case MPQEMU_CMD_SYNC_SYSMEM: remote_sysmem_reconfig(&msg, &local_err); break; + case MPQEMU_CMD_SET_IRQFD: + process_set_irqfd_msg(pci_dev, &msg); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s" diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index bcb32e0..4342245 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -254,6 +254,11 @@ bool mpqemu_msg_valid(MPQemuMsg *msg) return false; } break; + case MPQEMU_CMD_SET_IRQFD: + if (msg->size || (msg->num_fds != 2)) { + return false; + } + break; default: break; } diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 472b2df..555b310 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -21,6 +21,57 @@ #include "qemu/error-report.h" #include "hw/remote/proxy-memory-listener.h" #include "qom/object.h" +#include "qemu/event_notifier.h" +#include "sysemu/kvm.h" +#include "util/event_notifier-posix.c" + +static void proxy_intx_update(PCIDevice *pci_dev) +{ + PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); + PCIINTxRoute route; + int pin = pci_get_byte(pci_dev->config + PCI_INTERRUPT_PIN) - 1; + + if (dev->virq != -1) { + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &dev->intr, dev->virq); + dev->virq = -1; + } + + route = pci_device_route_intx_to_irq(pci_dev, pin); + + dev->virq = route.irq; + + if (dev->virq != -1) { + kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, &dev->intr, + &dev->resample, dev->virq); + } +} + +static void setup_irqfd(PCIProxyDev *dev) +{ + PCIDevice *pci_dev = PCI_DEVICE(dev); + MPQemuMsg msg; + Error *local_err = NULL; + + event_notifier_init(&dev->intr, 0); + event_notifier_init(&dev->resample, 0); + + memset(&msg, 0, sizeof(MPQemuMsg)); + msg.cmd = MPQEMU_CMD_SET_IRQFD; + msg.num_fds = 2; + msg.fds[0] = event_notifier_get_fd(&dev->intr); + msg.fds[1] = event_notifier_get_fd(&dev->resample); + msg.size = 0; + + if (!mpqemu_msg_send(&msg, dev->ioc, &local_err)) { + error_report_err(local_err); + } + + dev->virq = -1; + + 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) { @@ -56,6 +107,8 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) qio_channel_set_blocking(dev->ioc, true, NULL); proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); + + setup_irqfd(dev); } static void pci_proxy_dev_exit(PCIDevice *pdev) @@ -71,6 +124,9 @@ static void pci_proxy_dev_exit(PCIDevice *pdev) error_free(dev->migration_blocker); proxy_memory_listener_deconfigure(&dev->proxy_listener); + + event_notifier_cleanup(&dev->intr); + event_notifier_cleanup(&dev->resample); } static void config_op_send(PCIProxyDev *pdev, uint32_t addr, uint32_t *val, diff --git a/MAINTAINERS b/MAINTAINERS index 5e48a26..a15a04f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3203,6 +3203,8 @@ F: hw/remote/proxy.c F: include/hw/remote/proxy.h F: hw/remote/proxy-memory-listener.c F: include/hw/remote/proxy-memory-listener.h +F: hw/remote/iohub.c +F: include/hw/remote/iohub.h Build and test automation ------------------------- diff --git a/hw/remote/meson.build b/hw/remote/meson.build index 7f11be4..e6a5574 100644 --- a/hw/remote/meson.build +++ b/hw/remote/meson.build @@ -5,6 +5,7 @@ remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('mpqemu-link.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('message.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('remote-obj.c')) remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy.c')) +remote_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('iohub.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('memory.c')) specific_ss.add(when: 'CONFIG_MULTIPROCESS', if_true: files('proxy-memory-listener.c')) From patchwork Tue Jan 19 20:28:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030797 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 53224C433E0 for ; Tue, 19 Jan 2021 20:57:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AEA3206EC for ; Tue, 19 Jan 2021 20:57:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AEA3206EC 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]:53326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y4Y-0006mE-LZ for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 15:57:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfN-0003lD-Up for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:54 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:58208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfI-0000gn-Is for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:53 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKODQX131263; Tue, 19 Jan 2021 20:31:43 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 : content-type : mime-version; s=corp-2020-01-29; bh=7jnkcNyheTPt6IRP9OYMrxjVugSN4Ups5Art0ZB0UDA=; b=i/0BBNT3+inA1zL1Z900VfZUhbOEOHWKMSQGFXQmkt6TR54sJwtBZbduXgJISlFCutL3 uensJjnEPlgODk/V5HP+TKZUxLExrIIynNeeqgHLDPoE8wDBAwhRsLEi0OzdhCn0JMRl GlitcCBAs3oTQlF7II9JYIW7IHuakXRi0gXez7iQJgnlCYQ72BySHtuGftK/Y6k2/kBi N88z6Z0MvsPddlrlT6j5Fv66OWg+ZGpQWsKImwFE8+0D62WW3U5hEW8j9azf52/VQZMH kDAQqSgzqe8rzIXykVtogqTjwdZhqWEtiuBJ7m7GIm/2gpmAipC+npD/PnYVMlJRUzoX 0A== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 363r3ktxyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:42 +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 10JKQbJg117482; Tue, 19 Jan 2021 20:29:42 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2057.outbound.protection.outlook.com [104.47.36.57]) by aserp3030.oracle.com with ESMTP id 3649qpu9f9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=crsiyoWOawMRmU9P/98As1oqYfha2RmlMFd20O8ibJqq0IxnpPMSsRyKLTgcVGX/IoIr3NfTOR+Bp36kB2mJNGXBKQmrRxdKGuxtmw0iSOoP19OCN/9f3JRU/NHUWHKVZ2hL2E44GD5E+6YKur1PGPtQQAK0+gz3WxTUTfOh2FWGD+H//bOwnLNRxqOvZ0AcrwOk/NOx7TWu4H6tmFybwJ3U7gpK1w/DOc4ux118wa4Eg4JZPw9DYfS0zU0b/MRmGH/HZjNz8XTHKkWqDbAI1AMpHd6dZcfvfJ9W/MzYc9UmVsZ4wBU/oUtMvRgDQv8sMi57PYwGtmxU7BuAXZKwaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7jnkcNyheTPt6IRP9OYMrxjVugSN4Ups5Art0ZB0UDA=; b=CfIIV+DpHZUxemJ0Rjf5NfQOYn48Jj2c9ldr5c3Y4K5JLiW23v7DEBeaQ1bLDNvIx8uQeLQzwwsBL7nh2dBV4upqBDqYSxMupIXhNrPTu1/ocJsVsEP35x6+eI3mGusglzXJss6ci9goiOX86pNHwgNY7XAHPkEkyx35YleY3kBuZOc+gJEMbJttcUsZR27ngUVH0hM062WvbNTwtE8ly+m6qAbI/kZS74jqVnqiXuwNxWfFce3ch8OoV+WU16IRT86scjQQx0cjtKzr1fcaV5gaS0gM6AJkZRZX8TfI9MBG5zdI0MUpe1uU9+rMPjPr7e1ypsJSztuJUtZhSKcAjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7jnkcNyheTPt6IRP9OYMrxjVugSN4Ups5Art0ZB0UDA=; b=lqOv1hKTOT2oVvfrqZUMkUTNCjNMGu9cN6swLN+U2mctqPnp7NSH0HipVfjxJwqtuZWVVqEgWPZjJ1H2+VqBX9D1tb3cJBexMVml0qnn1Jfs49SrZ++2fl6/Rw6V/pCpjYo0GgX3OOAMC1RKK7Xir12cVzszc2cVdNXiGUFto+Y= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:40 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:40 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 19/20] multi-process: Retrieve PCI info from remote process Date: Tue, 19 Jan 2021 15:28:36 -0500 Message-Id: <1a6ebf4554e61d92b1cb81923442e1f8db9d18b4.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 841be3ee-5b63-4bf9-0fd2-08d8bcb8f2aa X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1728; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I34yl+IxBYoRVID8p8+K09e/bZeG6YZi1pJka7N7wz/dQQVjW2qC5z1OrHxwsAbi0L7AzhctumpbVZXq8D60GFKLhKaYpwGVM5/jHWwu25tRgx/TFjzAuIdXa5LmJ5LPCcaO8fXwKPGdKdSJ0RBvopmy5+AwEgOOrL+3N74P0iYPkNL4Xky67t8pCXajnfhMaIu52U/nh9bo/3a2gJ/5a/OAyATRVwQBBafoU3OBGGUYzTK7q95ZcTnMXYSaNXGmHIpzZ5u4YpPoLgkokJMWjhALcXgNuhr+QAkl6gbg4H21BU+NweOTolMEPdI2+oURJHUsQwRfb9xesppM93yPslm76CPwOsbK0WVGEN+4cxfCDbyv5gxkaBezmadcAUew73KYFP7Zp02cJO/DdP8XxK61PHq9FRRYUxmVnXfIGyKdSt1Tvv5nEd+khtKn2YhnSPWtM725Rgi/JVQFvCbIcTMRNeAsk6swHa6X6MK1o/MDxd4FDeARTVuYZifhr56kBdYNxzVq8J60QdECHRB5PA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: quc0kvJjE8CUZHa5J0xPzGeFX9kb2mSOZZduXAjG03OVeTkHqfkg6nzhVQeyPOWYgZNV2+2kVhRRnOXeuhrYab6n59m9uqySyqRge7wf89SmS/tZZMxHHzbkzYKIczrqRrh1cfwTEpKkPMe4ygUdp6E+5rdjR8EGqIzK/it2MOHj8xd9JDaKDg/OoyWQxnPxXqql9bKbePYLSOjI8+GB4l+yr0gTBj4s8rejYdBk3bIn+d4eBN4+sm5vJfyogrl10/xrKfX0EX0+bN2SLtCEAPdSRksKsCesLA/v6g6UAczHCmVJco7DVBaSy6ZnyvC3VXlVFe2EFLJ6W5Zpe9VW8Rh+FIiDY5svyT2nb2Tt2tXEIYUYTtbItbOW9f5TV7OHz6eVaW6Pu/rygiibb93zZm28GJAcXL1GMRstPstfxRkYQYy9NkS6H4gqfQ0NGnfyL0E6wobvdMyfmXY4W0NS6YNNOQhu22qUNzki/i0FPFCnegUt9qx5c1D2faFAUezcqvsXtZIOwJiWsjfZtVlbPFcKNfmpXP0jyMOKQVmADbMEz2GIOZDhupdmKAovnyHrosH9VvPF6GWqTBQsg+Zzqnps3MQXF7Zqx7mjwEfCOf1ymZ3QjQrdmaw5nvwuFQMNJDM57aMsF9mX6xHZfBt6R0pTltLUURXcLphEeu5QSY2ObDRTJP7im88K4FXeip3AH2bmFTX1ZVW/iyNb2VlhjxyaY8iAGzklzepoPgzUr0nrSfjzV/CKJHHqql5VuwfKJkimUJtqRP8xhJH2qs4+BHpfz4GtPeVgkyMmrHJ9djfnEzRPMrTRI1N4n9gDUtbkUktU1SbxoNTftipzb1H+RDz/Z0B540NB3GI3YgNOdGrgsQR5WsxbG2VyzmfqsWKoR04/lJJLOwHQK5W3rShQqYAl1ME4Cb/KAweMeysgNFeDNeYlRgSy7X0AJDZHoXJBrIAFGkjxEyoZgrlLl6UJAt2sfyEhpQbi2B8jSRystrI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 841be3ee-5b63-4bf9-0fd2-08d8bcb8f2aa X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:40.5939 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: McjrWRB9f2QkE3Eh8h9G0pAACB7/c1vqdkLVHdZ+UnqgHSyBkRFmR8TDdj4ttI4z3ntRl7Ma+UxWn6s/MreivA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 suspectscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.78; envelope-from=jag.raman@oracle.com; helo=aserp2120.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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" 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 Reviewed-by: Stefan Hajnoczi --- hw/remote/proxy.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 555b310..a082709 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -25,6 +25,8 @@ #include "sysemu/kvm.h" #include "util/event_notifier-posix.c" +static void probe_pci_info(PCIDevice *dev, Error **errp); + static void proxy_intx_update(PCIDevice *pci_dev) { PCIProxyDev *dev = PCI_PROXY_DEV(pci_dev); @@ -77,6 +79,7 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) { ERRP_GUARD(); PCIProxyDev *dev = PCI_PROXY_DEV(device); + uint8_t *pci_conf = device->config; int fd; if (!dev->fd) { @@ -106,9 +109,14 @@ static void pci_proxy_dev_realize(PCIDevice *device, Error **errp) qemu_mutex_init(&dev->io_mutex); qio_channel_set_blocking(dev->ioc, true, NULL); + pci_conf[PCI_LATENCY_TIMER] = 0xff; + pci_conf[PCI_INTERRUPT_PIN] = 0x01; + proxy_memory_listener_configure(&dev->proxy_listener, dev->ioc); setup_irqfd(dev); + + probe_pci_info(PCI_DEVICE(dev), errp); } static void pci_proxy_dev_exit(PCIDevice *pdev) @@ -274,3 +282,79 @@ const MemoryRegionOps proxy_mr_ops = { .max_access_size = 8, }, }; + +static void probe_pci_info(PCIDevice *dev, Error **errp) +{ + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); + uint32_t orig_val, new_val, base_class, val; + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + DeviceClass *dc = DEVICE_CLASS(pc); + uint8_t type; + int i, size; + + config_op_send(pdev, PCI_VENDOR_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); + pc->vendor_id = (uint16_t)val; + + config_op_send(pdev, PCI_DEVICE_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); + pc->device_id = (uint16_t)val; + + config_op_send(pdev, PCI_CLASS_DEVICE, &val, 2, MPQEMU_CMD_PCI_CFGREAD); + pc->class_id = (uint16_t)val; + + config_op_send(pdev, PCI_SUBSYSTEM_ID, &val, 2, MPQEMU_CMD_PCI_CFGREAD); + pc->subsystem_id = (uint16_t)val; + + base_class = pc->class_id >> 4; + switch (base_class) { + case PCI_BASE_CLASS_BRIDGE: + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + break; + case PCI_BASE_CLASS_STORAGE: + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + break; + case PCI_BASE_CLASS_NETWORK: + set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); + break; + case PCI_BASE_CLASS_INPUT: + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); + break; + case PCI_BASE_CLASS_DISPLAY: + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + break; + case PCI_BASE_CLASS_PROCESSOR: + set_bit(DEVICE_CATEGORY_CPU, dc->categories); + break; + default: + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + break; + } + + for (i = 0; i < PCI_NUM_REGIONS; i++) { + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, + MPQEMU_CMD_PCI_CFGREAD); + new_val = 0xffffffff; + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, + MPQEMU_CMD_PCI_CFGWRITE); + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &new_val, 4, + MPQEMU_CMD_PCI_CFGREAD); + size = (~(new_val & 0xFFFFFFF0)) + 1; + config_op_send(pdev, PCI_BASE_ADDRESS_0 + (4 * i), &orig_val, 4, + MPQEMU_CMD_PCI_CFGWRITE); + type = (new_val & 0x1) ? + PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; + + if (size) { + g_autofree char *name; + pdev->region[i].dev = pdev; + pdev->region[i].present = true; + if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { + pdev->region[i].memory = true; + } + name = g_strdup_printf("bar-region-%d", i); + memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), + &proxy_mr_ops, &pdev->region[i], + name, size); + pci_register_bar(dev, i, type, &pdev->region[i].mr); + } + } +} From patchwork Tue Jan 19 20:28:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jag Raman X-Patchwork-Id: 12030803 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, 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 47626C433E0 for ; Tue, 19 Jan 2021 21:00:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7C585206EC for ; Tue, 19 Jan 2021 21:00:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C585206EC 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]:33188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1y7R-0001ir-DG for qemu-devel@archiver.kernel.org; Tue, 19 Jan 2021 16:00:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfQ-0003lz-Dm for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:58 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:39744) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1xfM-0000hA-JM for qemu-devel@nongnu.org; Tue, 19 Jan 2021 15:31:56 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10JKOoaI146183; Tue, 19 Jan 2021 20:31:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : mime-version; s=corp-2020-01-29; bh=avhCUAWKFINROFhFn9XLD6ifdtWA62J3LcL6MBR+IHI=; b=n4doiIOXVQNuijAnrdH6mL6Q7ei5Od6MfpzyAyPV+aJUtIwVZ8OOD7Q+b4a8Sq0QT4bu gDTDxL9VQ2gxkEqbXJGcbgC7fDD+6Bn8FyMKSv1VCdHLSB3bKhrk9AZ1yq6ykrQH5m3R cf9w7cCDAvGyE3cdmy6uVhZUrQV9NlJKBL0LCMf/l1emfYElaYy7xnmTtanS8IzLcWTx N1TGWEwNiinNCM6gRF+XNCupnIQrnVfvKyha2s/dZnxpG28V9fihhccLbi4EdToezPr+ fx0brcyjrAXock1osQaid1JOKECfyLrMBSt2ae9qYE82A9QDT6ooTb5JGOONNFso+25U 0w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 363nnak56r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:31:46 +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 10JKPjRi175932; Tue, 19 Jan 2021 20:29:46 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2055.outbound.protection.outlook.com [104.47.36.55]) by aserp3020.oracle.com with ESMTP id 3661er95bb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 20:29:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gt1EfhbQo94zIIQN2DFdKjcmr5ZKTc9e2TAp5UMzM675rGXUvDpugZSbMCccuh0JUmxJ/RKMkDS5fYG2U0lqld6Hu6ncyNob27nNFh9Yx41k8zKk+q0rBpAf6Xqppa71JwiOPmxOVrdFifOsMJleAQfBwgslf7Q0fWMnUYTgtEG+2IQSghpnLCzs4RR/nbNeuYT6aD07kUf7nVEAiU2/CY9IBaZ1jZ13mS7727+IOJG+kM7UjD3ctjMh7qSUjiDo1lxD1ms82cP60nZ7GbK38R+WZ/Ns6XsaHE4WO23yZDqH7r2laycJVQ5CdC9BvQDzRtg8xeoFWl8pYTGVInsJBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=avhCUAWKFINROFhFn9XLD6ifdtWA62J3LcL6MBR+IHI=; b=Tj8s9Pb9sYQrbAlBV5cwInm84Z/kLjXIK4O3tiXaVNSbEXqsKYBDzmkdr9rC8wARJNI9P0oG3K1wRre24yGKwYNOHmqLhrnb8HH8rpyTpVkKiqATdEN8Cb88LJfz7biV3fWewuJAXiQDtfFThZBT6KG0QeOKlexdBOt6v+lmhKU/236QmwFCj8+4/mDfBSk/5IOVwAbpOLjnGK1T0C+rJg7WVoT7PcL89M/R+rW3J2XKENOOL4o+TQ7vpvJQn+VvZInpvNV7YHp032Kx5aduPcJkBXYvEx89PGoaPn5UES284ZUYidaL8MLBIk9rbJqP90VeVuL2+O4OKJpEIRhCtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=avhCUAWKFINROFhFn9XLD6ifdtWA62J3LcL6MBR+IHI=; b=eNrBLTBsLRmJpCD2+zXUxESB4ThQurwH/ma0euVYRPOzjGEueTHwDu1CPPnMNZ3eMZq8dHf48Xmum4y4jmZHfxcIrGBYj5wLs8kNw9B5r4mSWI0VOYtAe4Luz/EmPUsQqzsq49nnaCixurB3i/9FlmM9Cmw46o7L5QAANhK4ICc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) by BYAPR10MB3351.namprd10.prod.outlook.com (2603:10b6:a03:14d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Tue, 19 Jan 2021 20:29:43 +0000 Received: from BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b]) by BYAPR10MB2744.namprd10.prod.outlook.com ([fe80::5cf0:3e26:c005:341b%7]) with mapi id 15.20.3763.014; Tue, 19 Jan 2021 20:29:43 +0000 From: Jagannathan Raman To: qemu-devel@nongnu.org Subject: [PATCH v20 20/20] multi-process: perform device reset in the remote process Date: Tue, 19 Jan 2021 15:28:37 -0500 Message-Id: <2163ccd87119eaaef550a06748908f23420ea67b.1611081587.git.jag.raman@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-Originating-IP: [209.17.40.38] X-ClientProxiedBy: DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) To BYAPR10MB2744.namprd10.prod.outlook.com (2603:10b6:a02:ae::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from jaraman-bur-1.us.oracle.com (209.17.40.38) by DM6PR01CA0007.prod.exchangelabs.com (2603:10b6:5:296::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 19 Jan 2021 20:29:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5a998a45-8fcb-4923-8bc3-08d8bcb8f46c X-MS-TrafficTypeDiagnostic: BYAPR10MB3351: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:279; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ctbPPMcPnRibN8xGJJRqg6NAlZfDBw9G1TUMd4O77CEU53t7CwMhBj05n+7JobtKp1T7cmX2rxzZfxMDAcSjWTSLdu+KQS+lYHAFGqVlzKTTR8Qf3Ei3OklNyt1cIV8fBx1keJxTowkY61AQrs4qM88NG7h8Mu7ts/lbSsSrY9HFBT4GpjoSEMMJmVcEXdtjAwrhm2Zq9d0a2Ex8b9xBwpAYTxOtQqgBDZc0qPvFDShK9Qgv5nHHt1Z1Aina9brh0INN0segNrw5U+WkvOijQRu87O38FAIMdqvq0qDOyUbY6yk8pkWEBAjrettTVT3GhAglAEyC6tLGHYn7eiQ/Ay1kCs94siQl7rkAcsWANtuMelGVVnwZJFsw3nkWdkm8bk8QuJIursGB5zo4tTAcSbqNPyrMTU/Yj9W4XVkrbtqNdIB07t81qBFlll3Ip5LyqFevex/OiDj2gua/YUP3dtfA7GQw2iIEurNkQzNLSqR9WwlPWsoc8RFOHxdps1oJiS2uZBXnmPPUXneZzPUtrA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2744.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(39860400002)(366004)(136003)(376002)(346002)(86362001)(2906002)(6666004)(6916009)(36756003)(4326008)(8676002)(52116002)(66476007)(66556008)(316002)(8936002)(66946007)(6486002)(107886003)(956004)(5660300002)(478600001)(7696005)(16526019)(26005)(186003)(7416002)(2616005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: IaaXTdUfcePfTaUkDRai4Qy8p8PRR4+ESv9WNxPYik+J8JN1K9FeyeJpbcMzdYEpNcSGTQc/9dIoUCXC9IR4MsABqw0apvIqaM/diu+m7PKKEnUfbBx2gKFmj03nq+ovIgW568xm9tVWi8nKvFlPue8kOLYhLOitWWGuHSjiDVf3xNT2ZkpqDCKgORRdle1Tidk346/qHL0jTbh4//rIFUIlRd+nv0G6QJw1a80muGgNS/SC0gwsvydoPeIE1Z187QTJDnZXppYGPOMA2K/+Tr0XxKrrd121GR2p7NGmLdGK+eGJ0Ijr3CxNNIMXo1BCZpLpqSVTfqwbCw4r7NJnJ2RkG9OJt/oJVPnxQNLoyL0o2Cm8W8braIyRRGDaRxGhZ7X+fkHmHvKZ4WLMA9b3xnXQTceoWrVfYt66p7CLr3/nn04A5aDTMbrTYvZ+LZhY6eNIlVmgq/Xb9miNweeqkXT78w9fg7IPGtmJ1toXhXTdNew2IePWF2umdvxCP622MgtH5wacIsT/ZOyy1TgMO9gysfjpUpInAGBB3jt4MCSP8NTwmHKj1mWqHc/+G1+sTAJAuT7m3QUEmNwJEWU4xYg+mppVFSgf9zmxs2FKruurkUcVTQFfjsytkGoIT1NcLSy9zMczGLMrlljkszNkOnqcKT/axPVnytooOZDlytZQnN1mcUjYMKt52q3nTuLAv4rykQbv0ssyiKGfHxkkLOtiSJpljfTehDx3i5nxvxS0d4ghx8DHVDdSAvcu3kh4quoT4ESdAy+0IwaGVrUnITxJSxiOEya8V9WeqS40BSq/rxniLEzPp2JP/SLuJfChwLvzYAyoX7DRIOur+NpQrWVqsO6y8xKkRJZrI02bQT0gurmCN0PaVgUALpKd21ynhmcg5AqQiI/WM7oTzezekG9chC3AEhdy4MofMtiKdCsF+CzTVlnTMIj4ZsRVP6b6dFyi/BxqUqGAW3f3kDvUCWBrespRhD9mlLoqvUjmM2E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a998a45-8fcb-4923-8bc3-08d8bcb8f46c X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2744.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2021 20:29:43.6242 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bilKR7pTrFGjUPOrOc8aSAb2oQcLjgAZZ9SpRMFzKRVzHneVhVldbpty2a3RUtOBdk8SPOCF0JUzGBnV71Rzug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3351 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9869 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 impostorscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190113 Received-SPF: pass client-ip=141.146.126.79; envelope-from=jag.raman@oracle.com; helo=aserp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-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, alex.williamson@redhat.com, stefanha@redhat.com, thanos.makatos@nutanix.com, 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: 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 Reviewed-by: Stefan Hajnoczi --- include/hw/remote/mpqemu-link.h | 1 + hw/remote/message.c | 22 ++++++++++++++++++++++ hw/remote/proxy.c | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/hw/remote/mpqemu-link.h b/include/hw/remote/mpqemu-link.h index 71d206f..4ec0915 100644 --- a/include/hw/remote/mpqemu-link.h +++ b/include/hw/remote/mpqemu-link.h @@ -40,6 +40,7 @@ typedef enum { MPQEMU_CMD_BAR_WRITE, MPQEMU_CMD_BAR_READ, MPQEMU_CMD_SET_IRQFD, + MPQEMU_CMD_DEVICE_RESET, MPQEMU_CMD_MAX, } MPQemuCmd; diff --git a/hw/remote/message.c b/hw/remote/message.c index adab040..11d7298 100644 --- a/hw/remote/message.c +++ b/hw/remote/message.c @@ -19,6 +19,7 @@ #include "exec/memattrs.h" #include "hw/remote/memory.h" #include "hw/remote/iohub.h" +#include "sysemu/reset.h" static void process_config_write(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); @@ -26,6 +27,8 @@ static void process_config_read(QIOChannel *ioc, PCIDevice *dev, MPQemuMsg *msg, Error **errp); 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_device_reset_msg(QIOChannel *ioc, PCIDevice *dev, + Error **errp); void coroutine_fn mpqemu_remote_msg_loop_co(void *data) { @@ -69,6 +72,9 @@ void coroutine_fn mpqemu_remote_msg_loop_co(void *data) case MPQEMU_CMD_SET_IRQFD: process_set_irqfd_msg(pci_dev, &msg); break; + case MPQEMU_CMD_DEVICE_RESET: + process_device_reset_msg(com->ioc, pci_dev, &local_err); + break; default: error_setg(&local_err, "Unknown command (%d) received for device %s" @@ -206,3 +212,19 @@ fail: getpid()); } } + +static void process_device_reset_msg(QIOChannel *ioc, PCIDevice *dev, + Error **errp) +{ + DeviceClass *dc = DEVICE_GET_CLASS(dev); + DeviceState *s = DEVICE(dev); + MPQemuMsg ret = { 0 }; + + if (dc->reset) { + dc->reset(s); + } + + ret.cmd = MPQEMU_CMD_RET; + + mpqemu_msg_send(&ret, ioc, errp); +} diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index a082709..4fa4be0 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -26,6 +26,7 @@ #include "util/event_notifier-posix.c" static void probe_pci_info(PCIDevice *dev, Error **errp); +static void proxy_device_reset(DeviceState *dev); static void proxy_intx_update(PCIDevice *pci_dev) { @@ -202,6 +203,8 @@ static void pci_proxy_dev_class_init(ObjectClass *klass, void *data) k->config_read = pci_proxy_read_config; k->config_write = pci_proxy_write_config; + dc->reset = proxy_device_reset; + device_class_set_props(dc, proxy_properties); } @@ -358,3 +361,19 @@ static void probe_pci_info(PCIDevice *dev, Error **errp) } } } + +static void proxy_device_reset(DeviceState *dev) +{ + PCIProxyDev *pdev = PCI_PROXY_DEV(dev); + MPQemuMsg msg = { 0 }; + Error *local_err = NULL; + + msg.cmd = MPQEMU_CMD_DEVICE_RESET; + msg.size = 0; + + mpqemu_msg_send_and_await_reply(&msg, pdev, &local_err); + if (local_err) { + error_report_err(local_err); + } + +}